Title: [264014] trunk
Revision
264014
Author
[email protected]
Date
2020-07-07 04:31:27 -0700 (Tue, 07 Jul 2020)

Log Message

[Win] Implement Pasteboard::writeCustomData for Web Inspector Console tab
https://bugs.webkit.org/show_bug.cgi?id=213986

Reviewed by Fujii Hironori.

Source/WebCore:

Implement Pasteboard::writeCustomData and Pasteboard::typesSafeForBindings.
This fixes the issue which we cannot copy text in WebInspector's Console tab.

We enable some existing testcases for pasteboard.

* platform/Pasteboard.h:
* platform/PasteboardCustomData.cpp:
(WebCore::PasteboardCustomData::fromPersistenceDecoder): Construct PasteboardCustomData from WTF::Persistence::Decoder.
(WebCore::PasteboardCustomData::fromSharedBuffer): Use fromPersistenceDecoder function to implement.
* platform/PasteboardCustomData.h:
* platform/win/ClipboardUtilitiesWin.cpp:
(WebCore::createGlobalData): Add uint8_t* variant.
* platform/win/ClipboardUtilitiesWin.h:
* platform/win/PasteboardWin.cpp:
(WebCore::Pasteboard::finishCreatingPasteboard): Register new clipboard format CustomDataClipboardFormat.
(WebCore::Pasteboard::readPasteboardCustomData): Helper function to read PasteboardCustomData from the pasteboard.
(WebCore::Pasteboard::typesSafeForBindings): Implemented.
(WebCore::Pasteboard::readOrigin): Implemented.
(WebCore::Pasteboard::readStringInCustomData): Implemented.
(WebCore::Pasteboard::writeCustomData): Implemented.

Source/WebKit:

* Shared/WebPreferencesDefaultValues.h: Turn DEFAULT_CUSTOM_PASTEBOARD_DATA_ENABLED on for Windows

LayoutTests:

Now pasteboard tests related to custom data pass.

* platform/win/TestExpectations:

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (264013 => 264014)


--- trunk/LayoutTests/ChangeLog	2020-07-07 11:08:21 UTC (rev 264013)
+++ trunk/LayoutTests/ChangeLog	2020-07-07 11:31:27 UTC (rev 264014)
@@ -1,3 +1,14 @@
+2020-07-07  Tomoki Imai  <[email protected]>
+
+        [Win] Implement Pasteboard::writeCustomData for Web Inspector Console tab
+        https://bugs.webkit.org/show_bug.cgi?id=213986
+
+        Reviewed by Fujii Hironori.
+
+        Now pasteboard tests related to custom data pass.
+
+        * platform/win/TestExpectations:
+
 2020-07-07  Philippe Normand  <[email protected]>
 
         [GStreamer] OGV/VP8 video not playing on minibrowser (neither epiphany)

Modified: trunk/LayoutTests/platform/win/TestExpectations (264013 => 264014)


--- trunk/LayoutTests/platform/win/TestExpectations	2020-07-07 11:08:21 UTC (rev 264013)
+++ trunk/LayoutTests/platform/win/TestExpectations	2020-07-07 11:31:27 UTC (rev 264014)
@@ -1186,8 +1186,6 @@
 [ Debug ] editing/selection/4983858.html [ Skip ] # Debug Assertion
 [ Debug ] editing/selection/4975120.html [ Skip ] # Debug Assertion
 
-# Custom pasteboard data is not supported on Windows.
-editing/pasteboard/clipboard-customData.html [ Skip ]
 http/tests/security/clipboard/copy-paste-url-across-origin-sanitizes-url.html [ Skip ]
 http/tests/security/clipboard/copy-paste-html-across-origin-sanitizes-html.html [ Skip ]
 http/tests/security/clipboard/copy-paste-html-cross-origin-iframe-across-origin.html [ Skip ]

Modified: trunk/Source/WebCore/ChangeLog (264013 => 264014)


--- trunk/Source/WebCore/ChangeLog	2020-07-07 11:08:21 UTC (rev 264013)
+++ trunk/Source/WebCore/ChangeLog	2020-07-07 11:31:27 UTC (rev 264014)
@@ -1,3 +1,32 @@
+2020-07-07  Tomoki Imai  <[email protected]>
+
+        [Win] Implement Pasteboard::writeCustomData for Web Inspector Console tab
+        https://bugs.webkit.org/show_bug.cgi?id=213986
+
+        Reviewed by Fujii Hironori.
+
+        Implement Pasteboard::writeCustomData and Pasteboard::typesSafeForBindings.
+        This fixes the issue which we cannot copy text in WebInspector's Console tab.
+
+        We enable some existing testcases for pasteboard.
+
+        * platform/Pasteboard.h:
+        * platform/PasteboardCustomData.cpp:
+        (WebCore::PasteboardCustomData::fromPersistenceDecoder): Construct PasteboardCustomData from WTF::Persistence::Decoder.
+        (WebCore::PasteboardCustomData::fromSharedBuffer): Use fromPersistenceDecoder function to implement.
+        * platform/PasteboardCustomData.h:
+        * platform/win/ClipboardUtilitiesWin.cpp:
+        (WebCore::createGlobalData): Add uint8_t* variant.
+        * platform/win/ClipboardUtilitiesWin.h:
+        * platform/win/PasteboardWin.cpp:
+        (WebCore::Pasteboard::finishCreatingPasteboard): Register new clipboard format CustomDataClipboardFormat.
+        (WebCore::Pasteboard::readPasteboardCustomData): Helper function to read PasteboardCustomData from the pasteboard.
+        (WebCore::Pasteboard::typesSafeForBindings): Implemented.
+        (WebCore::Pasteboard::readOrigin): Implemented.
+        (WebCore::Pasteboard::readStringInCustomData): Implemented.
+        (WebCore::Pasteboard::writeCustomData): Implemented.
+
+
 2020-07-06  Simon Fraser  <[email protected]>
 
         High CPU usage on Stash search results pages

Modified: trunk/Source/WebCore/platform/Pasteboard.h (264013 => 264014)


--- trunk/Source/WebCore/platform/Pasteboard.h	2020-07-07 11:08:21 UTC (rev 264013)
+++ trunk/Source/WebCore/platform/Pasteboard.h	2020-07-07 11:31:27 UTC (rev 264014)
@@ -315,6 +315,7 @@
     void writeRangeToDataObject(Range&, Frame&); // FIXME: Layering violation.
     void writeURLToDataObject(const URL&, const String&);
     void writePlainTextToDataObject(const String&, SmartReplaceOption);
+    Optional<PasteboardCustomData> readPasteboardCustomData();
 #endif
 
 #if PLATFORM(COCOA)

Modified: trunk/Source/WebCore/platform/PasteboardCustomData.cpp (264013 => 264014)


--- trunk/Source/WebCore/platform/PasteboardCustomData.cpp	2020-07-07 11:08:21 UTC (rev 264013)
+++ trunk/Source/WebCore/platform/PasteboardCustomData.cpp	2020-07-07 11:31:27 UTC (rev 264014)
@@ -92,12 +92,11 @@
     return SharedBuffer::create(encoder.buffer(), encoder.bufferSize());
 }
 
-PasteboardCustomData PasteboardCustomData::fromSharedBuffer(const SharedBuffer& buffer)
+PasteboardCustomData PasteboardCustomData::fromPersistenceDecoder(WTF::Persistence::Decoder&& decoder)
 {
     constexpr unsigned maxSupportedDataSerializationVersionNumber = 1;
 
     PasteboardCustomData result;
-    auto decoder = buffer.decoder();
     Optional<unsigned> version;
     decoder >> version;
     if (!version || *version > maxSupportedDataSerializationVersionNumber)
@@ -125,6 +124,11 @@
     return result;
 }
 
+PasteboardCustomData PasteboardCustomData::fromSharedBuffer(const SharedBuffer& buffer)
+{
+    return fromPersistenceDecoder(buffer.decoder());
+}
+
 void PasteboardCustomData::writeString(const String& type, const String& value)
 {
     addOrMoveEntryToEnd(type).platformData = { value };

Modified: trunk/Source/WebCore/platform/PasteboardCustomData.h (264013 => 264014)


--- trunk/Source/WebCore/platform/PasteboardCustomData.h	2020-07-07 11:08:21 UTC (rev 264013)
+++ trunk/Source/WebCore/platform/PasteboardCustomData.h	2020-07-07 11:31:27 UTC (rev 264014)
@@ -29,6 +29,7 @@
 #include <wtf/HashMap.h>
 #include <wtf/Variant.h>
 #include <wtf/Vector.h>
+#include <wtf/persistence/PersistentCoders.h>
 #include <wtf/text/WTFString.h>
 
 namespace WebCore {
@@ -61,6 +62,7 @@
 
     WEBCORE_EXPORT Ref<SharedBuffer> createSharedBuffer() const;
     WEBCORE_EXPORT static PasteboardCustomData fromSharedBuffer(const SharedBuffer&);
+    WEBCORE_EXPORT static PasteboardCustomData fromPersistenceDecoder(WTF::Persistence::Decoder&&);
 
     String readString(const String& type) const;
     RefPtr<SharedBuffer> readBuffer(const String& type) const;

Modified: trunk/Source/WebCore/platform/win/ClipboardUtilitiesWin.cpp (264013 => 264014)


--- trunk/Source/WebCore/platform/win/ClipboardUtilitiesWin.cpp	2020-07-07 11:08:21 UTC (rev 264013)
+++ trunk/Source/WebCore/platform/win/ClipboardUtilitiesWin.cpp	2020-07-07 11:31:27 UTC (rev 264014)
@@ -215,6 +215,18 @@
     return vm;
 }
 
+HGLOBAL createGlobalData(const uint8_t* data, size_t length)
+{
+    HGLOBAL vm = ::GlobalAlloc(GPTR, length + 1);
+    if (!vm)
+        return 0;
+    uint8_t* buffer = static_cast<uint8_t*>(GlobalLock(vm));
+    memcpy(buffer, data, length);
+    buffer[length] = 0;
+    GlobalUnlock(vm);
+    return vm;
+}
+
 static String getFullCFHTML(IDataObject* data)
 {
     STGMEDIUM store;

Modified: trunk/Source/WebCore/platform/win/ClipboardUtilitiesWin.h (264013 => 264014)


--- trunk/Source/WebCore/platform/win/ClipboardUtilitiesWin.h	2020-07-07 11:08:21 UTC (rev 264013)
+++ trunk/Source/WebCore/platform/win/ClipboardUtilitiesWin.h	2020-07-07 11:31:27 UTC (rev 264014)
@@ -38,6 +38,7 @@
 HGLOBAL createGlobalData(const String&);
 HGLOBAL createGlobalData(const Vector<char>&);
 HGLOBAL createGlobalData(const URL& url, const String& title);
+HGLOBAL createGlobalData(const uint8_t*, size_t);
 
 FORMATETC* urlWFormat();
 FORMATETC* urlFormat();

Modified: trunk/Source/WebCore/platform/win/PasteboardWin.cpp (264013 => 264014)


--- trunk/Source/WebCore/platform/win/PasteboardWin.cpp	2020-07-07 11:08:21 UTC (rev 264013)
+++ trunk/Source/WebCore/platform/win/PasteboardWin.cpp	2020-07-07 11:31:27 UTC (rev 264014)
@@ -64,6 +64,7 @@
 static UINT HTMLClipboardFormat = 0;
 static UINT BookmarkClipboardFormat = 0;
 static UINT WebSmartPasteFormat = 0;
+static UINT CustomDataClipboardFormat = 0;
 
 static LRESULT CALLBACK PasteboardOwnerWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
 {
@@ -135,6 +136,7 @@
     HTMLClipboardFormat = ::RegisterClipboardFormat(L"HTML Format");
     BookmarkClipboardFormat = ::RegisterClipboardFormat(L"UniformResourceLocatorW");
     WebSmartPasteFormat = ::RegisterClipboardFormat(L"WebKit Smart Paste Format");
+    CustomDataClipboardFormat = ::RegisterClipboardFormat(L"WebKit Custom Data Format");
 }
 
 Pasteboard::Pasteboard()
@@ -240,12 +242,43 @@
         results.add("text/plain");
 }
 
-Vector<String> Pasteboard::typesSafeForBindings(const String&)
+Optional<PasteboardCustomData> Pasteboard::readPasteboardCustomData()
 {
-    notImplemented();
-    return { };
+    if (::IsClipboardFormatAvailable(CustomDataClipboardFormat) && ::OpenClipboard(m_owner)) {
+        if (HANDLE cbData = ::GetClipboardData(CustomDataClipboardFormat)) {
+            size_t size = GlobalSize(cbData);
+            auto data = ""
+            auto customData = PasteboardCustomData::fromPersistenceDecoder({data, size});
+
+            GlobalUnlock(cbData);
+            ::CloseClipboard();
+
+            return customData;
+        }
+        ::CloseClipboard();
+    }
+
+    return WTF::nullopt;
 }
 
+Vector<String> Pasteboard::typesSafeForBindings(const String& origin)
+{
+    ListHashSet<String> domPasteboardTypes;
+
+    Optional<PasteboardCustomData> customData = readPasteboardCustomData();
+
+    if (customData && customData->origin() == origin) {
+        for (const auto& type : customData->orderedTypes())
+            domPasteboardTypes.add(type);
+    }
+
+    domPasteboardTypes.add("text/plain");
+    domPasteboardTypes.add("text/uri-list");
+    domPasteboardTypes.add("text/html");
+
+    return copyToVector(domPasteboardTypes);
+}
+
 Vector<String> Pasteboard::typesForLegacyUnsafeBindings()
 {
     ListHashSet<String> results;
@@ -280,7 +313,11 @@
 
 String Pasteboard::readOrigin()
 {
-    notImplemented();
+    Optional<PasteboardCustomData> customData = readPasteboardCustomData();
+
+    if (customData)
+        return customData->origin();
+
     return { };
 }
 
@@ -304,9 +341,13 @@
     return "";
 }
 
-String Pasteboard::readStringInCustomData(const String&)
+String Pasteboard::readStringInCustomData(const String& type)
 {
-    notImplemented();
+    Optional<PasteboardCustomData> customData = readPasteboardCustomData();
+
+    if (customData)
+        return customData->readStringInCustomData(type);
+
     return { };
 }
 
@@ -1082,8 +1123,47 @@
 {
 }
 
-void Pasteboard::writeCustomData(const Vector<PasteboardCustomData>&)
+void Pasteboard::writeCustomData(const Vector<PasteboardCustomData>& data)
 {
+    if (data.isEmpty() || data.size() > 1) {
+        // We don't support more than one custom item in the clipboard.
+        return;
+    }
+
+    clear();
+
+    if (::OpenClipboard(m_owner)) {
+        const auto& customData = data.first();
+        customData.forEachPlatformStringOrBuffer([](auto& type, auto& stringOrBuffer) {
+            if (WTF::holds_alternative<String>(stringOrBuffer)) {
+                ClipboardDataType dataType = clipboardTypeFromMIMEType(type);
+
+                String str = WTF::get<String>(stringOrBuffer);
+                replaceNewlinesWithWindowsStyleNewlines(str);
+                HGLOBAL cbData = createGlobalData(str);
+
+                if (dataType == ClipboardDataTypeText) {
+                    if (cbData && !::SetClipboardData(CF_UNICODETEXT, cbData))
+                        ::GlobalFree(cbData);
+                } else if (dataType == ClipboardDataTypeURL) {
+                    if (cbData && !::SetClipboardData(BookmarkClipboardFormat, cbData))
+                        ::GlobalFree(cbData);
+                } else if (dataType == ClipboardDataTypeTextHTML) {
+                    if (cbData && !::SetClipboardData(HTMLClipboardFormat, cbData))
+                        ::GlobalFree(cbData);
+                }
+            }
+        });
+
+        if (customData.hasSameOriginCustomData() || !customData.origin().isEmpty()) {
+            auto sharedBuffer = customData.createSharedBuffer();
+            HGLOBAL cbData = createGlobalData(reinterpret_cast<const uint8_t*>(sharedBuffer->data()), sharedBuffer->size());
+            if (cbData && !::SetClipboardData(CustomDataClipboardFormat, cbData))
+                ::GlobalFree(cbData);
+        }
+
+        ::CloseClipboard();
+    }
 }
 
 void Pasteboard::write(const Color&)

Modified: trunk/Source/WebKit/ChangeLog (264013 => 264014)


--- trunk/Source/WebKit/ChangeLog	2020-07-07 11:08:21 UTC (rev 264013)
+++ trunk/Source/WebKit/ChangeLog	2020-07-07 11:31:27 UTC (rev 264014)
@@ -1,3 +1,12 @@
+2020-07-07  Tomoki Imai  <[email protected]>
+
+        [Win] Implement Pasteboard::writeCustomData for Web Inspector Console tab
+        https://bugs.webkit.org/show_bug.cgi?id=213986
+
+        Reviewed by Fujii Hironori.
+
+        * Shared/WebPreferencesDefaultValues.h: Turn DEFAULT_CUSTOM_PASTEBOARD_DATA_ENABLED on for Windows
+
 2020-07-06  Simon Fraser  <[email protected]>
 
         High CPU usage on Stash search results pages

Modified: trunk/Source/WebKit/Shared/WebPreferencesDefaultValues.h (264013 => 264014)


--- trunk/Source/WebKit/Shared/WebPreferencesDefaultValues.h	2020-07-07 11:08:21 UTC (rev 264013)
+++ trunk/Source/WebKit/Shared/WebPreferencesDefaultValues.h	2020-07-07 11:31:27 UTC (rev 264014)
@@ -252,7 +252,7 @@
 #define DEFAULT_INPUT_TYPE_WEEK_ENABLED false
 #endif
 
-#if PLATFORM(COCOA) || PLATFORM(GTK)
+#if PLATFORM(COCOA) || PLATFORM(GTK) || PLATFORM(WIN)
 #define DEFAULT_CUSTOM_PASTEBOARD_DATA_ENABLED true
 #else
 #define DEFAULT_CUSTOM_PASTEBOARD_DATA_ENABLED false
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to