⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 264014 in webkit


Ignore:
Timestamp:
Jul 7, 2020, 4:31:27 AM (6 years ago)
Author:
Tomoki Imai
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:
Location:
trunk
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r264013 r264014  
     12020-07-07  Tomoki Imai  <Tomoki.Imai@sony.com>
     2
     3        [Win] Implement Pasteboard::writeCustomData for Web Inspector Console tab
     4        https://bugs.webkit.org/show_bug.cgi?id=213986
     5
     6        Reviewed by Fujii Hironori.
     7
     8        Now pasteboard tests related to custom data pass.
     9
     10        * platform/win/TestExpectations:
     11
    1122020-07-07  Philippe Normand  <pnormand@igalia.com>
    213
  • trunk/LayoutTests/platform/win/TestExpectations

    r264000 r264014  
    11871187[ Debug ] editing/selection/4975120.html [ Skip ] # Debug Assertion
    11881188
    1189 # Custom pasteboard data is not supported on Windows.
    1190 editing/pasteboard/clipboard-customData.html [ Skip ]
    11911189http/tests/security/clipboard/copy-paste-url-across-origin-sanitizes-url.html [ Skip ]
    11921190http/tests/security/clipboard/copy-paste-html-across-origin-sanitizes-html.html [ Skip ]
  • trunk/Source/WebCore/ChangeLog

    r264008 r264014  
     12020-07-07  Tomoki Imai  <Tomoki.Imai@sony.com>
     2
     3        [Win] Implement Pasteboard::writeCustomData for Web Inspector Console tab
     4        https://bugs.webkit.org/show_bug.cgi?id=213986
     5
     6        Reviewed by Fujii Hironori.
     7
     8        Implement Pasteboard::writeCustomData and Pasteboard::typesSafeForBindings.
     9        This fixes the issue which we cannot copy text in WebInspector's Console tab.
     10
     11        We enable some existing testcases for pasteboard.
     12
     13        * platform/Pasteboard.h:
     14        * platform/PasteboardCustomData.cpp:
     15        (WebCore::PasteboardCustomData::fromPersistenceDecoder): Construct PasteboardCustomData from WTF::Persistence::Decoder.
     16        (WebCore::PasteboardCustomData::fromSharedBuffer): Use fromPersistenceDecoder function to implement.
     17        * platform/PasteboardCustomData.h:
     18        * platform/win/ClipboardUtilitiesWin.cpp:
     19        (WebCore::createGlobalData): Add uint8_t* variant.
     20        * platform/win/ClipboardUtilitiesWin.h:
     21        * platform/win/PasteboardWin.cpp:
     22        (WebCore::Pasteboard::finishCreatingPasteboard): Register new clipboard format CustomDataClipboardFormat.
     23        (WebCore::Pasteboard::readPasteboardCustomData): Helper function to read PasteboardCustomData from the pasteboard.
     24        (WebCore::Pasteboard::typesSafeForBindings): Implemented.
     25        (WebCore::Pasteboard::readOrigin): Implemented.
     26        (WebCore::Pasteboard::readStringInCustomData): Implemented.
     27        (WebCore::Pasteboard::writeCustomData): Implemented.
     28
     29
    1302020-07-06  Simon Fraser  <simon.fraser@apple.com>
    231
  • trunk/Source/WebCore/platform/Pasteboard.h

    r262507 r264014  
    316316    void writeURLToDataObject(const URL&, const String&);
    317317    void writePlainTextToDataObject(const String&, SmartReplaceOption);
     318    Optional<PasteboardCustomData> readPasteboardCustomData();
    318319#endif
    319320
  • trunk/Source/WebCore/platform/PasteboardCustomData.cpp

    r259922 r264014  
    9393}
    9494
    95 PasteboardCustomData PasteboardCustomData::fromSharedBuffer(const SharedBuffer& buffer)
     95PasteboardCustomData PasteboardCustomData::fromPersistenceDecoder(WTF::Persistence::Decoder&& decoder)
    9696{
    9797    constexpr unsigned maxSupportedDataSerializationVersionNumber = 1;
    9898
    9999    PasteboardCustomData result;
    100     auto decoder = buffer.decoder();
    101100    Optional<unsigned> version;
    102101    decoder >> version;
     
    124123
    125124    return result;
     125}
     126
     127PasteboardCustomData PasteboardCustomData::fromSharedBuffer(const SharedBuffer& buffer)
     128{
     129    return fromPersistenceDecoder(buffer.decoder());
    126130}
    127131
  • trunk/Source/WebCore/platform/PasteboardCustomData.h

    r261792 r264014  
    3030#include <wtf/Variant.h>
    3131#include <wtf/Vector.h>
     32#include <wtf/persistence/PersistentCoders.h>
    3233#include <wtf/text/WTFString.h>
    3334
     
    6263    WEBCORE_EXPORT Ref<SharedBuffer> createSharedBuffer() const;
    6364    WEBCORE_EXPORT static PasteboardCustomData fromSharedBuffer(const SharedBuffer&);
     65    WEBCORE_EXPORT static PasteboardCustomData fromPersistenceDecoder(WTF::Persistence::Decoder&&);
    6466
    6567    String readString(const String& type) const;
  • trunk/Source/WebCore/platform/win/ClipboardUtilitiesWin.cpp

    r258869 r264014  
    216216}
    217217
     218HGLOBAL createGlobalData(const uint8_t* data, size_t length)
     219{
     220    HGLOBAL vm = ::GlobalAlloc(GPTR, length + 1);
     221    if (!vm)
     222        return 0;
     223    uint8_t* buffer = static_cast<uint8_t*>(GlobalLock(vm));
     224    memcpy(buffer, data, length);
     225    buffer[length] = 0;
     226    GlobalUnlock(vm);
     227    return vm;
     228}
     229
    218230static String getFullCFHTML(IDataObject* data)
    219231{
  • trunk/Source/WebCore/platform/win/ClipboardUtilitiesWin.h

    r238771 r264014  
    3939HGLOBAL createGlobalData(const Vector<char>&);
    4040HGLOBAL createGlobalData(const URL& url, const String& title);
     41HGLOBAL createGlobalData(const uint8_t*, size_t);
    4142
    4243FORMATETC* urlWFormat();
  • trunk/Source/WebCore/platform/win/PasteboardWin.cpp

    r262209 r264014  
    6565static UINT BookmarkClipboardFormat = 0;
    6666static UINT WebSmartPasteFormat = 0;
     67static UINT CustomDataClipboardFormat = 0;
    6768
    6869static LRESULT CALLBACK PasteboardOwnerWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
     
    136137    BookmarkClipboardFormat = ::RegisterClipboardFormat(L"UniformResourceLocatorW");
    137138    WebSmartPasteFormat = ::RegisterClipboardFormat(L"WebKit Smart Paste Format");
     139    CustomDataClipboardFormat = ::RegisterClipboardFormat(L"WebKit Custom Data Format");
    138140}
    139141
     
    241243}
    242244
    243 Vector<String> Pasteboard::typesSafeForBindings(const String&)
    244 {
    245     notImplemented();
    246     return { };
     245Optional<PasteboardCustomData> Pasteboard::readPasteboardCustomData()
     246{
     247    if (::IsClipboardFormatAvailable(CustomDataClipboardFormat) && ::OpenClipboard(m_owner)) {
     248        if (HANDLE cbData = ::GetClipboardData(CustomDataClipboardFormat)) {
     249            size_t size = GlobalSize(cbData);
     250            auto data = static_cast<uint8_t*>(GlobalLock(cbData));
     251            auto customData = PasteboardCustomData::fromPersistenceDecoder({data, size});
     252
     253            GlobalUnlock(cbData);
     254            ::CloseClipboard();
     255
     256            return customData;
     257        }
     258        ::CloseClipboard();
     259    }
     260
     261    return WTF::nullopt;
     262}
     263
     264Vector<String> Pasteboard::typesSafeForBindings(const String& origin)
     265{
     266    ListHashSet<String> domPasteboardTypes;
     267
     268    Optional<PasteboardCustomData> customData = readPasteboardCustomData();
     269
     270    if (customData && customData->origin() == origin) {
     271        for (const auto& type : customData->orderedTypes())
     272            domPasteboardTypes.add(type);
     273    }
     274
     275    domPasteboardTypes.add("text/plain");
     276    domPasteboardTypes.add("text/uri-list");
     277    domPasteboardTypes.add("text/html");
     278
     279    return copyToVector(domPasteboardTypes);
    247280}
    248281
     
    281314String Pasteboard::readOrigin()
    282315{
    283     notImplemented();
     316    Optional<PasteboardCustomData> customData = readPasteboardCustomData();
     317
     318    if (customData)
     319        return customData->origin();
     320
    284321    return { };
    285322}
     
    305342}
    306343
    307 String Pasteboard::readStringInCustomData(const String&)
    308 {
    309     notImplemented();
     344String Pasteboard::readStringInCustomData(const String& type)
     345{
     346    Optional<PasteboardCustomData> customData = readPasteboardCustomData();
     347
     348    if (customData)
     349        return customData->readStringInCustomData(type);
     350
    310351    return { };
    311352}
     
    10831124}
    10841125
    1085 void Pasteboard::writeCustomData(const Vector<PasteboardCustomData>&)
    1086 {
     1126void Pasteboard::writeCustomData(const Vector<PasteboardCustomData>& data)
     1127{
     1128    if (data.isEmpty() || data.size() > 1) {
     1129        // We don't support more than one custom item in the clipboard.
     1130        return;
     1131    }
     1132
     1133    clear();
     1134
     1135    if (::OpenClipboard(m_owner)) {
     1136        const auto& customData = data.first();
     1137        customData.forEachPlatformStringOrBuffer([](auto& type, auto& stringOrBuffer) {
     1138            if (WTF::holds_alternative<String>(stringOrBuffer)) {
     1139                ClipboardDataType dataType = clipboardTypeFromMIMEType(type);
     1140
     1141                String str = WTF::get<String>(stringOrBuffer);
     1142                replaceNewlinesWithWindowsStyleNewlines(str);
     1143                HGLOBAL cbData = createGlobalData(str);
     1144
     1145                if (dataType == ClipboardDataTypeText) {
     1146                    if (cbData && !::SetClipboardData(CF_UNICODETEXT, cbData))
     1147                        ::GlobalFree(cbData);
     1148                } else if (dataType == ClipboardDataTypeURL) {
     1149                    if (cbData && !::SetClipboardData(BookmarkClipboardFormat, cbData))
     1150                        ::GlobalFree(cbData);
     1151                } else if (dataType == ClipboardDataTypeTextHTML) {
     1152                    if (cbData && !::SetClipboardData(HTMLClipboardFormat, cbData))
     1153                        ::GlobalFree(cbData);
     1154                }
     1155            }
     1156        });
     1157
     1158        if (customData.hasSameOriginCustomData() || !customData.origin().isEmpty()) {
     1159            auto sharedBuffer = customData.createSharedBuffer();
     1160            HGLOBAL cbData = createGlobalData(reinterpret_cast<const uint8_t*>(sharedBuffer->data()), sharedBuffer->size());
     1161            if (cbData && !::SetClipboardData(CustomDataClipboardFormat, cbData))
     1162                ::GlobalFree(cbData);
     1163        }
     1164
     1165        ::CloseClipboard();
     1166    }
    10871167}
    10881168
  • trunk/Source/WebKit/ChangeLog

    r264008 r264014  
     12020-07-07  Tomoki Imai  <Tomoki.Imai@sony.com>
     2
     3        [Win] Implement Pasteboard::writeCustomData for Web Inspector Console tab
     4        https://bugs.webkit.org/show_bug.cgi?id=213986
     5
     6        Reviewed by Fujii Hironori.
     7
     8        * Shared/WebPreferencesDefaultValues.h: Turn DEFAULT_CUSTOM_PASTEBOARD_DATA_ENABLED on for Windows
     9
    1102020-07-06  Simon Fraser  <simon.fraser@apple.com>
    211
  • trunk/Source/WebKit/Shared/WebPreferencesDefaultValues.h

    r263977 r264014  
    253253#endif
    254254
    255 #if PLATFORM(COCOA) || PLATFORM(GTK)
     255#if PLATFORM(COCOA) || PLATFORM(GTK) || PLATFORM(WIN)
    256256#define DEFAULT_CUSTOM_PASTEBOARD_DATA_ENABLED true
    257257#else
Note: See TracChangeset for help on using the changeset viewer.