Changeset 261792 in webkit


Ignore:
Timestamp:
May 17, 2020 1:35:41 AM (4 years ago)
Author:
Carlos Garcia Campos
Message:

[GTK] Move to new Pasteboard API
https://bugs.webkit.org/show_bug.cgi?id=177633

Reviewed by Adrian Perez de Castro.

Source/WebCore:

Add support for custom data and remove the support for unknown data types that is currently unused.

  • editing/gtk/EditorGtk.cpp:

(WebCore::Editor::writeSelectionToPasteboard): Set the contentOrigin.

  • editing/gtk/WebContentReaderGtk.cpp:

(WebCore::shouldReplaceSubresourceURL): Helper to decide whether to replace the subresource URL.
(WebCore::WebContentMarkupReader::readHTML): Create a fragment for HTML sanitizing it if needed.

  • platform/Pasteboard.h:
  • platform/PasteboardCustomData.h:

(WebCore::PasteboardCustomData::gtkType): Mime type name for GTK custom pasteboard data.

  • platform/SharedBuffer.h:
  • platform/glib/SharedBufferGlib.cpp:

(WebCore::SharedBuffer::createGBytes const): Create a GBytes wrapping the SharedBuffer data.

  • platform/gtk/PasteboardGtk.cpp:

(WebCore::Pasteboard::writeString):
(WebCore::Pasteboard::write):
(WebCore::Pasteboard::read):
(WebCore::Pasteboard::hasData):
(WebCore::Pasteboard::typesSafeForBindings):
(WebCore::Pasteboard::typesForLegacyUnsafeBindings):
(WebCore::Pasteboard::readOrigin):
(WebCore::Pasteboard::readString):
(WebCore::Pasteboard::readStringInCustomData):
(WebCore::Pasteboard::fileContentState):
(WebCore::Pasteboard::writeCustomData):

  • platform/gtk/SelectionData.cpp:

(WebCore::SelectionData::clearAllExceptFilenames):

  • platform/gtk/SelectionData.h:

(WebCore::SelectionData::setCustomData):
(WebCore::SelectionData::customData const):
(WebCore::SelectionData::hasCustomData const):
(WebCore::SelectionData::clearCustomData):

Source/WebKit:

Enable custom pasteboard data.

  • Shared/WebPreferencesDefaultValues.h:
  • Shared/gtk/ArgumentCodersGtk.cpp:

(IPC::ArgumentCoder<SelectionData>::encode):
(IPC::ArgumentCoder<SelectionData>::decode):

  • UIProcess/WebPasteboardProxy.cpp:
  • UIProcess/gtk/ClipboardGtk3.cpp:

(WebKit::Clipboard::write): Add support for writing URI list and custom data.

  • UIProcess/gtk/ClipboardGtk4.cpp:

(WebKit::Clipboard::write): Ditto.

  • UIProcess/gtk/WebPasteboardProxyGtk.cpp:

(WebKit::WebPasteboardProxy::typesSafeForDOMToReadAndWrite):
(WebKit::WebPasteboardProxy::writeCustomData):

LayoutTests:

Update text expectations.

  • platform/gtk/TestExpectations:
  • platform/gtk/editing/pasteboard/data-transfer-get-data-on-paste-rich-text-expected.txt: Added.
Location:
trunk
Files:
1 added
19 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r261785 r261792  
     12020-05-17  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        [GTK] Move to new Pasteboard API
     4        https://bugs.webkit.org/show_bug.cgi?id=177633
     5
     6        Reviewed by Adrian Perez de Castro.
     7
     8        Update text expectations.
     9
     10        * platform/gtk/TestExpectations:
     11        * platform/gtk/editing/pasteboard/data-transfer-get-data-on-paste-rich-text-expected.txt: Added.
     12
    1132020-05-16  Andy Estes  <aestes@apple.com>
    214
  • trunk/LayoutTests/platform/gtk/TestExpectations

    r261744 r261792  
    10761076webkit.org/b/180370 fast/images/animated-image-mp4-crash.html [ Skip ]
    10771077
    1078 # GTK ought to support the new modern pasteboard API
    1079 webkit.org/b/177633 editing/pasteboard/copy-without-selection.html [ Failure ]
    1080 webkit.org/b/177633 editing/pasteboard/copying-html-strips-javascript-url-and-event-handler.html [ Failure ]
    1081 webkit.org/b/177633 editing/pasteboard/data-transfer-get-data-on-copying-pasting-malformed-url-in-same-document.html [ Failure ]
    1082 webkit.org/b/177633 editing/pasteboard/data-transfer-get-data-on-paste-custom.html [ Failure ]
    1083 webkit.org/b/177633 editing/pasteboard/data-transfer-get-data-on-paste-plain-text.html [ Failure ]
    1084 webkit.org/b/177633 editing/pasteboard/data-transfer-get-data-on-paste-rich-text.html [ Failure ]
    1085 webkit.org/b/177633 editing/pasteboard/data-transfer-get-data-on-pasting-html-uses-blob-url.html [ Failure ]
    1086 webkit.org/b/177633 editing/pasteboard/data-transfer-items-add-custom-data.html [ Failure ]
    1087 webkit.org/b/177633 editing/pasteboard/data-transfer-set-data-ignore-copied-malformed-url-in-null-origin.html [ Failure ]
    1088 webkit.org/b/177633 editing/pasteboard/data-transfer-set-data-sanitize-url-when-copying-in-null-origin.html [ Failure ]
    1089 webkit.org/b/177633 editing/pasteboard/data-transfer-set-data-sanitizes-html-when-copying-in-null-origin.html [ Failure ]
    1090 webkit.org/b/177633 editing/pasteboard/data-transfer-set-data-sanitizes-html-when-copying.html [ Failure ]
    1091 webkit.org/b/177633 editing/pasteboard/datatransfer-items-paste-plaintext.html [ Skip ]
    1092 webkit.org/b/177633 editing/pasteboard/dataTransfer-types-pasting-plaintext.html [ Failure ]
    1093 webkit.org/b/177633 editing/pasteboard/onpaste-text-html-types.html [ Failure ]
    1094 webkit.org/b/177633 editing/pasteboard/pasting-empty-html-falls-back-to-text.html [ Failure ]
    1095 webkit.org/b/177633 http/tests/security/clipboard/copy-paste-html-cross-origin-iframe-across-origin.html [ Skip ]
    1096 webkit.org/b/177633 http/tests/security/clipboard/copy-paste-html-cross-origin-iframe-in-same-origin.html [ Skip ]
    1097 webkit.org/b/177633 http/tests/security/clipboard/copy-paste-html-across-origin-sanitizes-html.html [ Failure ]
    1098 webkit.org/b/177633 http/tests/security/clipboard/copy-paste-url-across-origin-sanitizes-url.html [ Failure ]
    1099 webkit.org/b/177633 http/tests/security/clipboard/copy-paste-html-across-origin-strips-mso-list.html [ Failure ]
    1100 webkit.org/b/177633 editing/pasteboard/copy-paste-across-shadow-boundaries-with-style-2.html [ Crash ]
    1101 webkit.org/b/177633 editing/pasteboard/paste-text-with-style.html [ Failure Pass ]
    1102 webkit.org/b/177633 editing/pasteboard/paste-without-nesting.html [ Failure Pass ]
    1103 webkit.org/b/177633 editing/async-clipboard/clipboard-change-data-while-writing.html [ Failure ]
    1104 webkit.org/b/177633 editing/async-clipboard/clipboard-read-text-from-platform.html [ Failure ]
    1105 webkit.org/b/177633 editing/async-clipboard/clipboard-change-data-while-getting-type.html [ Timeout ]
    1106 webkit.org/b/177633 editing/async-clipboard/clipboard-change-data-while-reading.html [ Timeout ]
    1107 webkit.org/b/177633 editing/async-clipboard/clipboard-get-type-with-old-items.html [ Timeout ]
    1108 webkit.org/b/177633 editing/async-clipboard/clipboard-read-basic.html [ Timeout ]
    1109 webkit.org/b/177633 editing/async-clipboard/clipboard-read-text-same-origin.html [ Timeout ]
    1110 webkit.org/b/177633 editing/async-clipboard/clipboard-write-basic.html [ Timeout ]
    1111 webkit.org/b/177633 editing/async-clipboard/clipboard-write-items-twice.html [ Timeout ]
    1112 webkit.org/b/177633 editing/async-clipboard/clipboard-write-text.html [ Timeout ]
    1113 webkit.org/b/177633 editing/async-clipboard/clipboard-item-get-type-basic.html [ Failure ]
    1114 webkit.org/b/177633 editing/async-clipboard/clipboard-read-text.html [ Failure ]
    1115 webkit.org/b/177633 editing/async-clipboard/sanitize-when-reading-markup.html [ Failure ]
     1078# GTK ought to support async clipboard
     1079webkit.org/b/211979 editing/async-clipboard/clipboard-change-data-while-writing.html [ Failure ]
     1080webkit.org/b/211979 editing/async-clipboard/clipboard-read-text-from-platform.html [ Failure ]
     1081webkit.org/b/211979 editing/async-clipboard/clipboard-change-data-while-getting-type.html [ Timeout ]
     1082webkit.org/b/211979 editing/async-clipboard/clipboard-change-data-while-reading.html [ Timeout ]
     1083webkit.org/b/211979 editing/async-clipboard/clipboard-get-type-with-old-items.html [ Timeout ]
     1084webkit.org/b/211979 editing/async-clipboard/clipboard-read-basic.html [ Timeout ]
     1085webkit.org/b/211979 editing/async-clipboard/clipboard-read-text-same-origin.html [ Timeout ]
     1086webkit.org/b/211979 editing/async-clipboard/clipboard-write-basic.html [ Timeout ]
     1087webkit.org/b/211979 editing/async-clipboard/clipboard-write-items-twice.html [ Timeout ]
     1088webkit.org/b/211979 editing/async-clipboard/clipboard-write-text.html [ Timeout ]
     1089webkit.org/b/211979 editing/async-clipboard/clipboard-item-get-type-basic.html [ Failure ]
     1090webkit.org/b/211979 editing/async-clipboard/clipboard-read-text.html [ Failure ]
     1091webkit.org/b/211979 editing/async-clipboard/sanitize-when-reading-markup.html [ Failure ]
     1092webkit.org/b/211979 editing/async-clipboard/sanitize-when-writing-image.html [ Failure ]
    11161093
    11171094webkit.org/b/180062 fast/text/user-installed-fonts [ Skip ]
     
    11931170# Server cookie not handled with platform WebSockets API
    11941171webkit.org/b/200165 imported/w3c/web-platform-tests/websockets/cookies/007.html [ Failure ]
    1195 
    1196 # No Mac system fonts in WebKitGTK
    1197 editing/pasteboard/paste-cocoa-writer-markup-with-system-fonts.html [ Failure ]
    1198 
    1199 # We don't use Cocoa
    1200 editing/pasteboard/paste-cocoa-writer-markup-with-webkit-standard-font-family.html [ Failure ]
    12011172
    12021173webkit.org/b/205857 media/encrypted-media/mock-MediaKeySession-generateRequest.html [ Skip ]
     
    15221493webkit.org/b/210926 fast/mediastream/getDisplayMedia-max-constraints2.html [ Skip ]
    15231494webkit.org/b/210926 fast/mediastream/getDisplayMedia-max-constraints3.html [ Skip ]
     1495
     1496webkit.org/b/199224 editing/pasteboard/copy-paste-across-shadow-boundaries-with-style-2.html [ Crash ]
    15241497
    15251498#////////////////////////////////////////////////////////////////////////////////////////
     
    36333606webkit.org/b/74282 editing/pasteboard/emacs-ctrl-k-with-move.html [ Failure ]
    36343607
    3635 webkit.org/b/81320 editing/pasteboard/copy-two-pasteboard-types-both-work.html [ Failure ]
    3636 
    36373608webkit.org/b/84679 css3/zoom-coords.xhtml [ Failure ]
    36383609
     
    42904261webkit.org/b/189564 http/tests/xmlhttprequest/url-with-credentials.html [ Failure ]
    42914262
    4292 webkit.org/b/189737 editing/pasteboard/4930986-1-paste-as-quotation.html [ Failure ]
    4293 webkit.org/b/189737 editing/pasteboard/4930986-2-paste-as-quotation.html [ Failure ]
    4294 webkit.org/b/189737 editing/pasteboard/4930986-3-paste-as-quotation.html [ Failure ]
    4295 
    42964263webkit.org/b/189739 svg/gradients/spreadMethodClose2.svg [ ImageOnlyFailure ]
    42974264
     
    45984565webkit.org/b/207678 imported/w3c/web-platform-tests/url/a-element-xhtml.xhtml [ Failure ]
    45994566webkit.org/b/207678 imported/w3c/web-platform-tests/url/a-element.html [ Failure ]
     4567
     4568webkit.org/b/211981 editing/pasteboard/data-transfer-get-data-on-pasting-html-uses-blob-url.html [ Failure ]
    46004569
    46014570#////////////////////////////////////////////////////////////////////////////////////////
  • trunk/Source/WebCore/ChangeLog

    r261791 r261792  
     12020-05-17  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        [GTK] Move to new Pasteboard API
     4        https://bugs.webkit.org/show_bug.cgi?id=177633
     5
     6        Reviewed by Adrian Perez de Castro.
     7
     8        Add support for custom data and remove the support for unknown data types that is currently unused.
     9
     10        * editing/gtk/EditorGtk.cpp:
     11        (WebCore::Editor::writeSelectionToPasteboard): Set the contentOrigin.
     12        * editing/gtk/WebContentReaderGtk.cpp:
     13        (WebCore::shouldReplaceSubresourceURL): Helper to decide whether to replace the subresource URL.
     14        (WebCore::WebContentMarkupReader::readHTML): Create a fragment for HTML sanitizing it if needed.
     15        * platform/Pasteboard.h:
     16        * platform/PasteboardCustomData.h:
     17        (WebCore::PasteboardCustomData::gtkType): Mime type name for GTK custom pasteboard data.
     18        * platform/SharedBuffer.h:
     19        * platform/glib/SharedBufferGlib.cpp:
     20        (WebCore::SharedBuffer::createGBytes const): Create a GBytes wrapping the SharedBuffer data.
     21        * platform/gtk/PasteboardGtk.cpp:
     22        (WebCore::Pasteboard::writeString):
     23        (WebCore::Pasteboard::write):
     24        (WebCore::Pasteboard::read):
     25        (WebCore::Pasteboard::hasData):
     26        (WebCore::Pasteboard::typesSafeForBindings):
     27        (WebCore::Pasteboard::typesForLegacyUnsafeBindings):
     28        (WebCore::Pasteboard::readOrigin):
     29        (WebCore::Pasteboard::readString):
     30        (WebCore::Pasteboard::readStringInCustomData):
     31        (WebCore::Pasteboard::fileContentState):
     32        (WebCore::Pasteboard::writeCustomData):
     33        * platform/gtk/SelectionData.cpp:
     34        (WebCore::SelectionData::clearAllExceptFilenames):
     35        * platform/gtk/SelectionData.h:
     36        (WebCore::SelectionData::setCustomData):
     37        (WebCore::SelectionData::customData const):
     38        (WebCore::SelectionData::hasCustomData const):
     39        (WebCore::SelectionData::clearCustomData):
     40
    1412020-05-16  Simon Fraser  <simon.fraser@apple.com>
    242
  • trunk/Source/WebCore/editing/gtk/EditorGtk.cpp

    r261554 r261792  
    111111    pasteboardContent.markup = serializePreservingVisualAppearance(m_document.selection().selection(), ResolveURLs::YesExcludingLocalFileURLsForPrivacy,
    112112        m_document.settings().selectionAcrossShadowBoundariesEnabled() ? SerializeComposedTree::Yes : SerializeComposedTree::No);
     113    pasteboardContent.contentOrigin = m_document.originIdentifierForPasteboard();
    113114    pasteboard.write(pasteboardContent);
    114115}
  • trunk/Source/WebCore/editing/gtk/WebContentReaderGtk.cpp

    r261684 r261792  
    8686}
    8787
    88 bool WebContentMarkupReader::readHTML(const String&)
     88static bool shouldReplaceSubresourceURL(const URL& url)
    8989{
    90     return false;
     90    return !(url.protocolIsInHTTPFamily() || url.protocolIsData());
     91}
     92
     93bool WebContentMarkupReader::readHTML(const String& string)
     94{
     95    if (!frame.document())
     96        return false;
     97
     98    if (shouldSanitize()) {
     99        markup = sanitizeMarkup(string, MSOListQuirks::Disabled, Function<void(DocumentFragment&)> { [](DocumentFragment& fragment) {
     100            removeSubresourceURLAttributes(fragment, [](const URL& url) {
     101                return shouldReplaceSubresourceURL(url);
     102            });
     103        } });
     104    } else
     105        markup = string;
     106
     107    return !markup.isEmpty();
    91108}
    92109
  • trunk/Source/WebCore/platform/Pasteboard.h

    r261554 r261792  
    8888#endif
    8989#if PLATFORM(GTK)
     90    String contentOrigin;
    9091    bool canSmartCopyOrDelete;
    9192    String text;
  • trunk/Source/WebCore/platform/PasteboardCustomData.h

    r251100 r261792  
    7676#if PLATFORM(COCOA)
    7777    WEBCORE_EXPORT static const char* cocoaType();
     78#elif PLATFORM(GTK)
     79    static const char* gtkType() { return "org.webkitgtk.WebKit.custom-pasteboard-data"; }
    7880#endif
    7981
  • trunk/Source/WebCore/platform/SharedBuffer.h

    r256223 r261792  
    9797#if USE(GLIB)
    9898    static Ref<SharedBuffer> create(GBytes*);
     99    GRefPtr<GBytes> createGBytes() const;
    99100#endif
    100101
  • trunk/Source/WebCore/platform/glib/SharedBufferGlib.cpp

    r240437 r261792  
    3939}
    4040
     41GRefPtr<GBytes> SharedBuffer::createGBytes() const
     42{
     43    ref();
     44    GRefPtr<GBytes> bytes = adoptGRef(g_bytes_new_with_free_func(data(), size(), [](gpointer data) {
     45        static_cast<SharedBuffer*>(data)->deref();
     46    }, const_cast<SharedBuffer*>(this)));
     47    return bytes;
     48}
     49
    4150RefPtr<SharedBuffer> SharedBuffer::createFromReadingFile(const String& filePath)
    4251{
  • trunk/Source/WebCore/platform/gtk/PasteboardGtk.cpp

    r261554 r261792  
    117117        break;
    118118    case ClipboardDataTypeUnknown:
    119         m_selectionData->setUnknownTypeData(type, data);
    120         break;
    121119    case ClipboardDataTypeImage:
    122120        break;
     
    188186        data.setMarkup(pasteboardContent.markup);
    189187        data.setCanSmartReplace(pasteboardContent.canSmartCopyOrDelete);
     188        PasteboardCustomData customData;
     189        customData.setOrigin(pasteboardContent.contentOrigin);
     190        data.setCustomData(customData.createSharedBuffer());
    190191        platformStrategies()->pasteboardStrategy()->writeToClipboard(m_name, WTFMove(data));
    191192    }
     
    264265        return;
    265266    }
     267
     268    reader.contentOrigin = readOrigin();
    266269
    267270    auto types = platformStrategies()->pasteboardStrategy()->types(m_name);
     
    307310{
    308311    if (m_selectionData)
    309         return m_selectionData->hasText() || m_selectionData->hasMarkup() || m_selectionData->hasURIList() || m_selectionData->hasImage() || m_selectionData->hasUnknownTypeData();
     312        return m_selectionData->hasText() || m_selectionData->hasMarkup() || m_selectionData->hasURIList() || m_selectionData->hasImage();
    310313    return !platformStrategies()->pasteboardStrategy()->types(m_name).isEmpty();
    311314}
    312315
    313 Vector<String> Pasteboard::typesSafeForBindings(const String&)
    314 {
    315     notImplemented(); // webkit.org/b/177633: [GTK] Move to new Pasteboard API
    316     return { };
     316Vector<String> Pasteboard::typesSafeForBindings(const String& origin)
     317{
     318    if (m_selectionData)
     319        return { };
     320
     321    return platformStrategies()->pasteboardStrategy()->typesSafeForDOMToReadAndWrite(m_name, origin);
    317322}
    318323
     
    337342    }
    338343
    339     for (auto& key : m_selectionData->unknownTypes().keys())
    340         types.append(key);
    341 
    342344    return types;
    343345}
     
    345347String Pasteboard::readOrigin()
    346348{
    347     notImplemented(); // webkit.org/b/177633: [GTK] Move to new Pasteboard API
     349    if (m_selectionData)
     350        return { };
     351
     352    // FIXME: cache custom data?
     353    if (auto buffer = platformStrategies()->pasteboardStrategy()->readBufferFromClipboard(m_name, PasteboardCustomData::gtkType()))
     354        return PasteboardCustomData::fromSharedBuffer(*buffer).origin();
     355
    348356    return { };
    349357}
     
    369377        return m_selectionData->text();
    370378    case ClipboardDataTypeUnknown:
    371         return m_selectionData->unknownTypeData(type);
    372379    case ClipboardDataTypeImage:
    373380        break;
     
    377384}
    378385
    379 String Pasteboard::readStringInCustomData(const String&)
    380 {
    381     notImplemented(); // webkit.org/b/177633: [GTK] Move to new Pasteboard API
     386String Pasteboard::readStringInCustomData(const String& type)
     387{
     388    if (m_selectionData)
     389        return { };
     390
     391    // FIXME: cache custom data?
     392    if (auto buffer = platformStrategies()->pasteboardStrategy()->readBufferFromClipboard(m_name, PasteboardCustomData::gtkType()))
     393        return PasteboardCustomData::fromSharedBuffer(*buffer).readStringInCustomData(type);
     394
    382395    return { };
    383396}
     
    389402
    390403    auto types = platformStrategies()->pasteboardStrategy()->types(m_name);
    391     if (types.contains("text/uri-list"_s))
    392         return FileContentState::MayContainFilePaths;
     404    if (types.contains("text/uri-list"_s)) {
     405        auto filePaths = platformStrategies()->pasteboardStrategy()->readFilePathsFromClipboard(m_name);
     406        if (!filePaths.isEmpty())
     407            return FileContentState::MayContainFilePaths;
     408    }
    393409
    394410    auto result = types.findMatching([](const String& type) {
     
    402418}
    403419
    404 void Pasteboard::writeCustomData(const Vector<PasteboardCustomData>&)
    405 {
     420void Pasteboard::writeCustomData(const Vector<PasteboardCustomData>& data)
     421{
     422    if (m_selectionData)
     423        return;
     424
     425    platformStrategies()->pasteboardStrategy()->writeCustomData(data, m_name);
    406426}
    407427
  • trunk/Source/WebCore/platform/gtk/SelectionData.cpp

    r261554 r261792  
    121121    clearURL();
    122122    clearImage();
     123    clearCustomData();
    123124
    124     m_unknownTypeData.clear();
    125125    m_canSmartReplace = false;
    126126}
  • trunk/Source/WebCore/platform/gtk/SelectionData.h

    r238771 r261792  
    2020
    2121#include "Image.h"
     22#include "SharedBuffer.h"
    2223#include <wtf/HashMap.h>
    2324#include <wtf/RefCounted.h>
     
    6364    void clearImage() { m_image = nullptr; }
    6465
    65     void setUnknownTypeData(const String& type, const String& data) { m_unknownTypeData.set(type, data); }
    66     String unknownTypeData(const String& type) const { return m_unknownTypeData.get(type); }
    67     const HashMap<String, String>& unknownTypes() const { return m_unknownTypeData; }
    68     bool hasUnknownTypeData() const { return !m_unknownTypeData.isEmpty(); }
    69 
    7066    void setCanSmartReplace(bool canSmartReplace) { m_canSmartReplace = canSmartReplace; }
    7167    bool canSmartReplace() const { return m_canSmartReplace; }
     68
     69    void setCustomData(Ref<SharedBuffer>&& buffer) { m_customData = WTFMove(buffer); }
     70    SharedBuffer* customData() const { return m_customData.get(); }
     71    bool hasCustomData() const { return !!m_customData; }
     72    void clearCustomData() { m_customData = nullptr; }
    7273
    7374    void clearAll();
     
    8182    Vector<String> m_filenames;
    8283    RefPtr<Image> m_image;
    83     HashMap<String, String> m_unknownTypeData;
    8484    bool m_canSmartReplace { false };
     85    RefPtr<SharedBuffer> m_customData;
    8586};
    8687
  • trunk/Source/WebKit/ChangeLog

    r261785 r261792  
     12020-05-17  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        [GTK] Move to new Pasteboard API
     4        https://bugs.webkit.org/show_bug.cgi?id=177633
     5
     6        Reviewed by Adrian Perez de Castro.
     7
     8        Enable custom pasteboard data.
     9
     10        * Shared/WebPreferencesDefaultValues.h:
     11        * Shared/gtk/ArgumentCodersGtk.cpp:
     12        (IPC::ArgumentCoder<SelectionData>::encode):
     13        (IPC::ArgumentCoder<SelectionData>::decode):
     14        * UIProcess/WebPasteboardProxy.cpp:
     15        * UIProcess/gtk/ClipboardGtk3.cpp:
     16        (WebKit::Clipboard::write): Add support for writing URI list and custom data.
     17        * UIProcess/gtk/ClipboardGtk4.cpp:
     18        (WebKit::Clipboard::write): Ditto.
     19        * UIProcess/gtk/WebPasteboardProxyGtk.cpp:
     20        (WebKit::WebPasteboardProxy::typesSafeForDOMToReadAndWrite):
     21        (WebKit::WebPasteboardProxy::writeCustomData):
     22
    1232020-05-16  Andy Estes  <aestes@apple.com>
    224
  • trunk/Source/WebKit/Shared/WebPreferencesDefaultValues.h

    r261599 r261792  
    239239#endif
    240240
    241 #if PLATFORM(COCOA)
     241#if PLATFORM(COCOA) || PLATFORM(GTK)
    242242#define DEFAULT_CUSTOM_PASTEBOARD_DATA_ENABLED true
     243#else
     244#define DEFAULT_CUSTOM_PASTEBOARD_DATA_ENABLED false
     245#endif
     246
     247#if PLATFORM(COCOA)
    243248#define DEFAULT_ASYNC_CLIPBOARD_API_ENABLED true
    244249#else
    245 #define DEFAULT_CUSTOM_PASTEBOARD_DATA_ENABLED false
    246250#define DEFAULT_ASYNC_CLIPBOARD_API_ENABLED false
    247251#endif
  • trunk/Source/WebKit/Shared/gtk/ArgumentCodersGtk.cpp

    r260025 r261792  
    9393        encodeImage(encoder, *selection.image());
    9494
    95     bool hasUnknownTypeData = selection.hasUnknownTypeData();
    96     encoder << hasUnknownTypeData;
    97     if (hasUnknownTypeData)
    98         encoder << selection.unknownTypes();
     95    bool hasCustomData = selection.hasCustomData();
     96    encoder << hasCustomData;
     97    if (hasCustomData)
     98        encoder << RefPtr<SharedBuffer>(selection.customData());
    9999
    100100    bool canSmartReplace = selection.canSmartReplace();
     
    156156    }
    157157
    158     bool hasUnknownTypeData;
    159     if (!decoder.decode(hasUnknownTypeData))
    160         return false;
    161     if (hasUnknownTypeData) {
    162         HashMap<String, String> unknownTypes;
    163         if (!decoder.decode(unknownTypes))
    164             return false;
    165 
    166         auto end = unknownTypes.end();
    167         for (auto it = unknownTypes.begin(); it != end; ++it)
    168             selection.setUnknownTypeData(it->key, it->value);
     158    bool hasCustomData;
     159    if (!decoder.decode(hasCustomData))
     160        return false;
     161    if (hasCustomData) {
     162        RefPtr<SharedBuffer> buffer;
     163        if (!decoder.decode(buffer))
     164            return false;
     165        selection.setCustomData(Ref<SharedBuffer>(*buffer));
    169166    }
    170167
  • trunk/Source/WebKit/UIProcess/WebPasteboardProxy.cpp

    r260793 r261792  
    8080#if !PLATFORM(COCOA)
    8181
     82#if !PLATFORM(GTK)
    8283void WebPasteboardProxy::typesSafeForDOMToReadAndWrite(IPC::Connection&, const String&, const String&, CompletionHandler<void(Vector<String>&&)>&& completionHandler)
    8384{
     
    8990    completionHandler(0);
    9091}
     92#endif
    9193
    9294void WebPasteboardProxy::allPasteboardItemInfo(IPC::Connection&, const String&, int64_t, CompletionHandler<void(Optional<Vector<WebCore::PasteboardItemInfo>>&&)>&& completionHandler)
  • trunk/Source/WebKit/UIProcess/gtk/ClipboardGtk3.cpp

    r261554 r261792  
    3131#include "WebPasteboardProxy.h"
    3232#include <WebCore/GRefPtrGtk.h>
     33#include <WebCore/PasteboardCustomData.h>
    3334#include <WebCore/SelectionData.h>
    3435#include <WebCore/SharedBuffer.h>
     
    156157};
    157158
    158 enum ClipboardTargetType { Markup, Text, Image, SmartPaste };
     159enum ClipboardTargetType { Markup, Text, Image, URIList, SmartPaste, Custom };
    159160
    160161void Clipboard::write(Ref<WebCore::SelectionData>&& selectionData)
     
    163164
    164165    GRefPtr<GtkTargetList> list = adoptGRef(gtk_target_list_new(nullptr, 0));
     166    if (selectionData->hasURIList())
     167        gtk_target_list_add(list.get(), gdk_atom_intern_static_string("text/uri-list"), 0, ClipboardTargetType::URIList);
    165168    if (selectionData->hasMarkup())
    166169        gtk_target_list_add(list.get(), gdk_atom_intern_static_string("text/html"), 0, ClipboardTargetType::Markup);
     
    171174    if (selectionData->canSmartReplace())
    172175        gtk_target_list_add(list.get(), gdk_atom_intern_static_string("application/vnd.webkitgtk.smartpaste"), 0, ClipboardTargetType::SmartPaste);
     176    if (selectionData->hasCustomData())
     177        gtk_target_list_add(list.get(), gdk_atom_intern_static_string(WebCore::PasteboardCustomData::gtkType()), 0, ClipboardTargetType::Custom);
    173178
    174179    int numberOfTargets;
     
    200205                break;
    201206            }
     207            case ClipboardTargetType::URIList: {
     208                CString uriList = selectionData.uriList().utf8();
     209                gtk_selection_data_set(selection, gdk_atom_intern_static_string("text/uri-list"), 8, reinterpret_cast<const guchar*>(uriList.data()), uriList.length());
     210                break;
     211            }
    202212            case ClipboardTargetType::SmartPaste:
    203213                gtk_selection_data_set_text(selection, "", -1);
     214                break;
     215            case ClipboardTargetType::Custom:
     216                if (selectionData.hasCustomData()) {
     217                    auto* buffer = selectionData.customData();
     218                    gtk_selection_data_set(selection, gdk_atom_intern_static_string(WebCore::PasteboardCustomData::gtkType()), 8, reinterpret_cast<const guchar*>(buffer->data()), buffer->size());
     219                }
    204220                break;
    205221            }
  • trunk/Source/WebKit/UIProcess/gtk/ClipboardGtk4.cpp

    r261555 r261792  
    3030
    3131#include "WebPasteboardProxy.h"
     32#include <WebCore/PasteboardCustomData.h>
    3233#include <WebCore/SelectionData.h>
    3334#include <WebCore/SharedBuffer.h>
     
    165166    }
    166167
     168    if (selectionData->hasURIList()) {
     169        CString uriList = selectionData->uriList().utf8();
     170        GRefPtr<GBytes> bytes = adoptGRef(g_bytes_new(uriList.data(), uriList.length()));
     171        providers.append(gdk_content_provider_new_for_bytes("text/uri-list", bytes.get()));
     172    }
     173
    167174    if (selectionData->hasImage()) {
    168175        GRefPtr<GdkPixbuf> pixbuf = adoptGRef(selectionData->image()->getGdkPixbuf());
     
    178185    }
    179186
     187    if (selectionData->hasCustomData()) {
     188        GRefPtr<GBytes> bytes = selectionData->customData()->createGBytes();
     189        providers.append(gdk_content_provider_new_for_bytes(WebCore::PasteboardCustomData::gtkType(), bytes.get()));
     190    }
     191
    180192    if (providers.isEmpty()) {
    181193        clear();
  • trunk/Source/WebKit/UIProcess/gtk/WebPasteboardProxyGtk.cpp

    r261554 r261792  
    3131#include "WebFrameProxy.h"
    3232#include "WebSelectionData.h"
     33#include <WebCore/Pasteboard.h>
     34#include <WebCore/PasteboardCustomData.h>
     35#include <WebCore/PasteboardItemInfo.h>
    3336#include <WebCore/PlatformPasteboard.h>
    3437#include <WebCore/SharedBuffer.h>
     38#include <wtf/ListHashSet.h>
    3539#include <wtf/SetForScope.h>
    3640
     
    8589}
    8690
     91void WebPasteboardProxy::typesSafeForDOMToReadAndWrite(IPC::Connection&, const String& pasteboardName, const String& origin, CompletionHandler<void(Vector<String>&&)>&& completionHandler)
     92{
     93    auto& clipboard = Clipboard::get(pasteboardName);
     94    clipboard.readBuffer(PasteboardCustomData::gtkType(), [&clipboard, origin, completionHandler = WTFMove(completionHandler)](IPC::SharedBufferDataReference&& buffer) mutable {
     95        ListHashSet<String> domTypes;
     96        if (auto dataBuffer = buffer.buffer()) {
     97            auto customData = PasteboardCustomData::fromSharedBuffer(*dataBuffer);
     98            if (customData.origin() == origin) {
     99                for (auto& type : customData.orderedTypes())
     100                    domTypes.add(type);
     101            }
     102        }
     103
     104        clipboard.formats([domTypes = WTFMove(domTypes), completionHandler = WTFMove(completionHandler)](Vector<String>&& formats) mutable {
     105            for (const auto& format : formats) {
     106                if (format == PasteboardCustomData::gtkType())
     107                    continue;
     108
     109                if (Pasteboard::isSafeTypeForDOMToReadAndWrite(format))
     110                    domTypes.add(format);
     111            }
     112
     113            completionHandler(copyToVector(domTypes));
     114        });
     115    });
     116}
     117
     118void WebPasteboardProxy::writeCustomData(IPC::Connection&, const Vector<PasteboardCustomData>& data, const String& pasteboardName, CompletionHandler<void(int64_t)>&& completionHandler)
     119{
     120    if (data.isEmpty() || data.size() > 1) {
     121        // We don't support more than one custom item in the clipboard.
     122        completionHandler(0);
     123        return;
     124    }
     125
     126    auto selectionData = SelectionData::create();
     127    const auto& customData = data[0];
     128    customData.forEachPlatformStringOrBuffer([&selectionData] (auto& type, auto& stringOrBuffer) {
     129        if (WTF::holds_alternative<String>(stringOrBuffer)) {
     130            if (type == "text/plain"_s)
     131                selectionData->setText(WTF::get<String>(stringOrBuffer));
     132            else if (type == "text/html"_s)
     133                selectionData->setMarkup(WTF::get<String>(stringOrBuffer));
     134            else if (type == "text/uri-list"_s)
     135                selectionData->setURIList(WTF::get<String>(stringOrBuffer));
     136        }
     137    });
     138
     139    if (customData.hasSameOriginCustomData() || !customData.origin().isEmpty())
     140        selectionData->setCustomData(customData.createSharedBuffer());
     141
     142    Clipboard::get(pasteboardName).write(WTFMove(selectionData));
     143    completionHandler(0);
     144}
     145
    87146} // namespace WebKit
Note: See TracChangeset for help on using the changeset viewer.