WebKit Bugzilla
New
Browse
Search+
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
[patch]
Patch
wkgtk-pasteboard-custom-data.diff (text/plain), 35.24 KB, created by
Carlos Garcia Campos
on 2020-05-16 05:11:17 PDT
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
Carlos Garcia Campos
Created:
2020-05-16 05:11:17 PDT
Size:
35.24 KB
patch
obsolete
>diff --git a/LayoutTests/ChangeLog b/LayoutTests/ChangeLog >index 0991b695c3dd..394c6a15fff1 100644 >--- a/LayoutTests/ChangeLog >+++ b/LayoutTests/ChangeLog >@@ -1,3 +1,15 @@ >+2020-05-16 Carlos Garcia Campos <cgarcia@igalia.com> >+ >+ [GTK] Move to new Pasteboard API >+ https://bugs.webkit.org/show_bug.cgi?id=177633 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ Update text expectations. >+ >+ * platform/gtk/TestExpectations: >+ * platform/gtk/editing/pasteboard/data-transfer-get-data-on-paste-rich-text-expected.txt: Added. >+ > 2020-05-16 Yusuke Suzuki <ysuzuki@apple.com> > > [JSC] Make OutOfMemory error as instance of RangeError >diff --git a/LayoutTests/platform/gtk/TestExpectations b/LayoutTests/platform/gtk/TestExpectations >index 88ddd681a65f..6d953ffdefe7 100644 >--- a/LayoutTests/platform/gtk/TestExpectations >+++ b/LayoutTests/platform/gtk/TestExpectations >@@ -1075,44 +1075,21 @@ webkit.org/b/180370 fast/images/animated-image-mp4.html [ Skip ] > webkit.org/b/180370 http/tests/images/image-supports-video.html [ Skip ] > webkit.org/b/180370 fast/images/animated-image-mp4-crash.html [ Skip ] > >-# GTK ought to support the new modern pasteboard API >-webkit.org/b/177633 editing/pasteboard/copy-without-selection.html [ Failure ] >-webkit.org/b/177633 editing/pasteboard/copying-html-strips-javascript-url-and-event-handler.html [ Failure ] >-webkit.org/b/177633 editing/pasteboard/data-transfer-get-data-on-copying-pasting-malformed-url-in-same-document.html [ Failure ] >-webkit.org/b/177633 editing/pasteboard/data-transfer-get-data-on-paste-custom.html [ Failure ] >-webkit.org/b/177633 editing/pasteboard/data-transfer-get-data-on-paste-plain-text.html [ Failure ] >-webkit.org/b/177633 editing/pasteboard/data-transfer-get-data-on-paste-rich-text.html [ Failure ] >-webkit.org/b/177633 editing/pasteboard/data-transfer-get-data-on-pasting-html-uses-blob-url.html [ Failure ] >-webkit.org/b/177633 editing/pasteboard/data-transfer-items-add-custom-data.html [ Failure ] >-webkit.org/b/177633 editing/pasteboard/data-transfer-set-data-ignore-copied-malformed-url-in-null-origin.html [ Failure ] >-webkit.org/b/177633 editing/pasteboard/data-transfer-set-data-sanitize-url-when-copying-in-null-origin.html [ Failure ] >-webkit.org/b/177633 editing/pasteboard/data-transfer-set-data-sanitizes-html-when-copying-in-null-origin.html [ Failure ] >-webkit.org/b/177633 editing/pasteboard/data-transfer-set-data-sanitizes-html-when-copying.html [ Failure ] >-webkit.org/b/177633 editing/pasteboard/datatransfer-items-paste-plaintext.html [ Skip ] >-webkit.org/b/177633 editing/pasteboard/dataTransfer-types-pasting-plaintext.html [ Failure ] >-webkit.org/b/177633 editing/pasteboard/onpaste-text-html-types.html [ Failure ] >-webkit.org/b/177633 editing/pasteboard/pasting-empty-html-falls-back-to-text.html [ Failure ] >-webkit.org/b/177633 http/tests/security/clipboard/copy-paste-html-cross-origin-iframe-across-origin.html [ Skip ] >-webkit.org/b/177633 http/tests/security/clipboard/copy-paste-html-cross-origin-iframe-in-same-origin.html [ Skip ] >-webkit.org/b/177633 http/tests/security/clipboard/copy-paste-html-across-origin-sanitizes-html.html [ Failure ] >-webkit.org/b/177633 http/tests/security/clipboard/copy-paste-url-across-origin-sanitizes-url.html [ Failure ] >-webkit.org/b/177633 http/tests/security/clipboard/copy-paste-html-across-origin-strips-mso-list.html [ Failure ] >-webkit.org/b/177633 editing/pasteboard/copy-paste-across-shadow-boundaries-with-style-2.html [ Crash ] >-webkit.org/b/177633 editing/pasteboard/paste-text-with-style.html [ Failure Pass ] >-webkit.org/b/177633 editing/pasteboard/paste-without-nesting.html [ Failure Pass ] >-webkit.org/b/177633 editing/async-clipboard/clipboard-change-data-while-writing.html [ Failure ] >-webkit.org/b/177633 editing/async-clipboard/clipboard-read-text-from-platform.html [ Failure ] >-webkit.org/b/177633 editing/async-clipboard/clipboard-change-data-while-getting-type.html [ Timeout ] >-webkit.org/b/177633 editing/async-clipboard/clipboard-change-data-while-reading.html [ Timeout ] >-webkit.org/b/177633 editing/async-clipboard/clipboard-get-type-with-old-items.html [ Timeout ] >-webkit.org/b/177633 editing/async-clipboard/clipboard-read-basic.html [ Timeout ] >-webkit.org/b/177633 editing/async-clipboard/clipboard-read-text-same-origin.html [ Timeout ] >-webkit.org/b/177633 editing/async-clipboard/clipboard-write-basic.html [ Timeout ] >-webkit.org/b/177633 editing/async-clipboard/clipboard-write-items-twice.html [ Timeout ] >-webkit.org/b/177633 editing/async-clipboard/clipboard-write-text.html [ Timeout ] >-webkit.org/b/177633 editing/async-clipboard/clipboard-item-get-type-basic.html [ Failure ] >-webkit.org/b/177633 editing/async-clipboard/clipboard-read-text.html [ Failure ] >-webkit.org/b/177633 editing/async-clipboard/sanitize-when-reading-markup.html [ Failure ] >+# GTK ought to support async clipboard >+webkit.org/b/211979 editing/async-clipboard/clipboard-change-data-while-writing.html [ Failure ] >+webkit.org/b/211979 editing/async-clipboard/clipboard-read-text-from-platform.html [ Failure ] >+webkit.org/b/211979 editing/async-clipboard/clipboard-change-data-while-getting-type.html [ Timeout ] >+webkit.org/b/211979 editing/async-clipboard/clipboard-change-data-while-reading.html [ Timeout ] >+webkit.org/b/211979 editing/async-clipboard/clipboard-get-type-with-old-items.html [ Timeout ] >+webkit.org/b/211979 editing/async-clipboard/clipboard-read-basic.html [ Timeout ] >+webkit.org/b/211979 editing/async-clipboard/clipboard-read-text-same-origin.html [ Timeout ] >+webkit.org/b/211979 editing/async-clipboard/clipboard-write-basic.html [ Timeout ] >+webkit.org/b/211979 editing/async-clipboard/clipboard-write-items-twice.html [ Timeout ] >+webkit.org/b/211979 editing/async-clipboard/clipboard-write-text.html [ Timeout ] >+webkit.org/b/211979 editing/async-clipboard/clipboard-item-get-type-basic.html [ Failure ] >+webkit.org/b/211979 editing/async-clipboard/clipboard-read-text.html [ Failure ] >+webkit.org/b/211979 editing/async-clipboard/sanitize-when-reading-markup.html [ Failure ] >+webkit.org/b/211979 editing/async-clipboard/sanitize-when-writing-image.html [ Failure ] > > webkit.org/b/180062 fast/text/user-installed-fonts [ Skip ] > >@@ -1193,12 +1170,6 @@ webkit.org/b/200162 http/tests/websocket/tests/hybi/inspector/ [ Skip ] > # Server cookie not handled with platform WebSockets API > webkit.org/b/200165 imported/w3c/web-platform-tests/websockets/cookies/007.html [ Failure ] > >-# No Mac system fonts in WebKitGTK >-editing/pasteboard/paste-cocoa-writer-markup-with-system-fonts.html [ Failure ] >- >-# We don't use Cocoa >-editing/pasteboard/paste-cocoa-writer-markup-with-webkit-standard-font-family.html [ Failure ] >- > webkit.org/b/205857 media/encrypted-media/mock-MediaKeySession-generateRequest.html [ Skip ] > webkit.org/b/205860 media/encrypted-media/mock-MediaKeySession-remove.html [ Skip ] > >@@ -1522,6 +1493,8 @@ webkit.org/b/210926 fast/mediastream/getDisplayMedia-max-constraints1.html [ Ski > webkit.org/b/210926 fast/mediastream/getDisplayMedia-max-constraints2.html [ Skip ] > webkit.org/b/210926 fast/mediastream/getDisplayMedia-max-constraints3.html [ Skip ] > >+webkit.org/b/199224 editing/pasteboard/copy-paste-across-shadow-boundaries-with-style-2.html [ Crash ] >+ > #//////////////////////////////////////////////////////////////////////////////////////// > # End of Crashing tests > #//////////////////////////////////////////////////////////////////////////////////////// >@@ -3632,8 +3605,6 @@ webkit.org/b/62204 svg/W3C-SVG-1.1/animate-elem-04-t.svg [ Failure ] > > webkit.org/b/74282 editing/pasteboard/emacs-ctrl-k-with-move.html [ Failure ] > >-webkit.org/b/81320 editing/pasteboard/copy-two-pasteboard-types-both-work.html [ Failure ] >- > webkit.org/b/84679 css3/zoom-coords.xhtml [ Failure ] > > webkit.org/b/84694 fast/events/selectstart-by-double-triple-clicks.html [ Failure ] >@@ -4289,10 +4260,6 @@ webkit.org/b/189345 http/tests/media/clearkey/collect-webkit-media-session.html > > webkit.org/b/189564 http/tests/xmlhttprequest/url-with-credentials.html [ Failure ] > >-webkit.org/b/189737 editing/pasteboard/4930986-1-paste-as-quotation.html [ Failure ] >-webkit.org/b/189737 editing/pasteboard/4930986-2-paste-as-quotation.html [ Failure ] >-webkit.org/b/189737 editing/pasteboard/4930986-3-paste-as-quotation.html [ Failure ] >- > webkit.org/b/189739 svg/gradients/spreadMethodClose2.svg [ ImageOnlyFailure ] > > webkit.org/b/189994 fast/files/xhr-response-blob.html [ Failure ] >@@ -4598,6 +4565,8 @@ webkit.org/b/207678 imported/w3c/web-platform-tests/url/a-element-origin.html [ > webkit.org/b/207678 imported/w3c/web-platform-tests/url/a-element-xhtml.xhtml [ Failure ] > webkit.org/b/207678 imported/w3c/web-platform-tests/url/a-element.html [ Failure ] > >+webkit.org/b/211981 editing/pasteboard/data-transfer-get-data-on-pasting-html-uses-blob-url.html [ Failure ] >+ > #//////////////////////////////////////////////////////////////////////////////////////// > # End of non-crashing, non-flaky tests failing > #//////////////////////////////////////////////////////////////////////////////////////// >diff --git a/LayoutTests/platform/gtk/editing/pasteboard/data-transfer-get-data-on-paste-rich-text-expected.txt b/LayoutTests/platform/gtk/editing/pasteboard/data-transfer-get-data-on-paste-rich-text-expected.txt >new file mode 100644 >index 000000000000..13d2c865fcc2 >--- /dev/null >+++ b/LayoutTests/platform/gtk/editing/pasteboard/data-transfer-get-data-on-paste-rich-text-expected.txt >@@ -0,0 +1,7 @@ >+Rich text >+{ >+ "paste": { >+ "text/html": "<span style=\"...\"\">Rich text</span>", >+ "text/plain": "Rich text" >+ } >+} >diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog >index d0f6c212bd68..bb603dac3574 100644 >--- a/Source/WebCore/ChangeLog >+++ b/Source/WebCore/ChangeLog >@@ -1,3 +1,43 @@ >+2020-05-16 Carlos Garcia Campos <cgarcia@igalia.com> >+ >+ [GTK] Move to new Pasteboard API >+ https://bugs.webkit.org/show_bug.cgi?id=177633 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ 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): >+ > 2020-05-15 Antti Koivisto <antti@apple.com> > > Nullptr crash in MediaQueryMatcher::evaluateAll >diff --git a/Source/WebCore/editing/gtk/EditorGtk.cpp b/Source/WebCore/editing/gtk/EditorGtk.cpp >index bef9ff6005ee..99aa11922c32 100644 >--- a/Source/WebCore/editing/gtk/EditorGtk.cpp >+++ b/Source/WebCore/editing/gtk/EditorGtk.cpp >@@ -110,6 +110,7 @@ void Editor::writeSelectionToPasteboard(Pasteboard& pasteboard) > pasteboardContent.text = selectedTextForDataTransfer(); > pasteboardContent.markup = serializePreservingVisualAppearance(m_document.selection().selection(), ResolveURLs::YesExcludingLocalFileURLsForPrivacy, > m_document.settings().selectionAcrossShadowBoundariesEnabled() ? SerializeComposedTree::Yes : SerializeComposedTree::No); >+ pasteboardContent.contentOrigin = m_document.originIdentifierForPasteboard(); > pasteboard.write(pasteboardContent); > } > >diff --git a/Source/WebCore/editing/gtk/WebContentReaderGtk.cpp b/Source/WebCore/editing/gtk/WebContentReaderGtk.cpp >index 8ad95f7117c3..d609f22c84f0 100644 >--- a/Source/WebCore/editing/gtk/WebContentReaderGtk.cpp >+++ b/Source/WebCore/editing/gtk/WebContentReaderGtk.cpp >@@ -85,9 +85,26 @@ bool WebContentReader::readURL(const URL&, const String&) > return false; > } > >-bool WebContentMarkupReader::readHTML(const String&) >+static bool shouldReplaceSubresourceURL(const URL& url) > { >- return false; >+ return !(url.protocolIsInHTTPFamily() || url.protocolIsData()); >+} >+ >+bool WebContentMarkupReader::readHTML(const String& string) >+{ >+ if (!frame.document()) >+ return false; >+ >+ if (shouldSanitize()) { >+ markup = sanitizeMarkup(string, MSOListQuirks::Disabled, Function<void(DocumentFragment&)> { [](DocumentFragment& fragment) { >+ removeSubresourceURLAttributes(fragment, [](const URL& url) { >+ return shouldReplaceSubresourceURL(url); >+ }); >+ } }); >+ } else >+ markup = string; >+ >+ return !markup.isEmpty(); > } > > } // namespace WebCore >diff --git a/Source/WebCore/platform/Pasteboard.h b/Source/WebCore/platform/Pasteboard.h >index 01db5995520b..fcff54cefaab 100644 >--- a/Source/WebCore/platform/Pasteboard.h >+++ b/Source/WebCore/platform/Pasteboard.h >@@ -87,6 +87,7 @@ struct PasteboardWebContent { > Vector<RefPtr<SharedBuffer>> clientData; > #endif > #if PLATFORM(GTK) >+ String contentOrigin; > bool canSmartCopyOrDelete; > String text; > String markup; >diff --git a/Source/WebCore/platform/PasteboardCustomData.h b/Source/WebCore/platform/PasteboardCustomData.h >index f9c0e9aa7214..cf89a60ccff1 100644 >--- a/Source/WebCore/platform/PasteboardCustomData.h >+++ b/Source/WebCore/platform/PasteboardCustomData.h >@@ -75,6 +75,8 @@ public: > > #if PLATFORM(COCOA) > WEBCORE_EXPORT static const char* cocoaType(); >+#elif PLATFORM(GTK) >+ static const char* gtkType() { return "org.webkitgtk.WebKit.custom-pasteboard-data"; } > #endif > > void forEachType(Function<void(const String&)>&&) const; >diff --git a/Source/WebCore/platform/SharedBuffer.h b/Source/WebCore/platform/SharedBuffer.h >index b683ca7d3289..0a8fe701b19b 100644 >--- a/Source/WebCore/platform/SharedBuffer.h >+++ b/Source/WebCore/platform/SharedBuffer.h >@@ -96,6 +96,7 @@ public: > > #if USE(GLIB) > static Ref<SharedBuffer> create(GBytes*); >+ GRefPtr<GBytes> createGBytes() const; > #endif > > #if USE(GSTREAMER) >diff --git a/Source/WebCore/platform/glib/SharedBufferGlib.cpp b/Source/WebCore/platform/glib/SharedBufferGlib.cpp >index c7473575307f..8a8c10b7024c 100644 >--- a/Source/WebCore/platform/glib/SharedBufferGlib.cpp >+++ b/Source/WebCore/platform/glib/SharedBufferGlib.cpp >@@ -38,6 +38,15 @@ Ref<SharedBuffer> SharedBuffer::create(GBytes* bytes) > return adoptRef(*new SharedBuffer(bytes)); > } > >+GRefPtr<GBytes> SharedBuffer::createGBytes() const >+{ >+ ref(); >+ GRefPtr<GBytes> bytes = adoptGRef(g_bytes_new_with_free_func(data(), size(), [](gpointer data) { >+ static_cast<SharedBuffer*>(data)->deref(); >+ }, const_cast<SharedBuffer*>(this))); >+ return bytes; >+} >+ > RefPtr<SharedBuffer> SharedBuffer::createFromReadingFile(const String& filePath) > { > if (filePath.isEmpty()) >diff --git a/Source/WebCore/platform/gtk/PasteboardGtk.cpp b/Source/WebCore/platform/gtk/PasteboardGtk.cpp >index 33f1815898f6..154439c9151b 100644 >--- a/Source/WebCore/platform/gtk/PasteboardGtk.cpp >+++ b/Source/WebCore/platform/gtk/PasteboardGtk.cpp >@@ -116,8 +116,6 @@ void Pasteboard::writeString(const String& type, const String& data) > m_selectionData->setText(data); > break; > case ClipboardDataTypeUnknown: >- m_selectionData->setUnknownTypeData(type, data); >- break; > case ClipboardDataTypeImage: > break; > } >@@ -187,6 +185,9 @@ void Pasteboard::write(const PasteboardWebContent& pasteboardContent) > data.setText(pasteboardContent.text); > data.setMarkup(pasteboardContent.markup); > data.setCanSmartReplace(pasteboardContent.canSmartCopyOrDelete); >+ PasteboardCustomData customData; >+ customData.setOrigin(pasteboardContent.contentOrigin); >+ data.setCustomData(customData.createSharedBuffer()); > platformStrategies()->pasteboardStrategy()->writeToClipboard(m_name, WTFMove(data)); > } > } >@@ -264,6 +265,8 @@ void Pasteboard::read(PasteboardWebContentReader& reader, WebContentReadingPolic > return; > } > >+ reader.contentOrigin = readOrigin(); >+ > auto types = platformStrategies()->pasteboardStrategy()->types(m_name); > if (types.contains("text/html"_s)) { > auto buffer = platformStrategies()->pasteboardStrategy()->readBufferFromClipboard(m_name, "text/html"_s); >@@ -306,14 +309,16 @@ void Pasteboard::read(PasteboardFileReader& reader) > bool Pasteboard::hasData() > { > if (m_selectionData) >- return m_selectionData->hasText() || m_selectionData->hasMarkup() || m_selectionData->hasURIList() || m_selectionData->hasImage() || m_selectionData->hasUnknownTypeData(); >+ return m_selectionData->hasText() || m_selectionData->hasMarkup() || m_selectionData->hasURIList() || m_selectionData->hasImage(); > return !platformStrategies()->pasteboardStrategy()->types(m_name).isEmpty(); > } > >-Vector<String> Pasteboard::typesSafeForBindings(const String&) >+Vector<String> Pasteboard::typesSafeForBindings(const String& origin) > { >- notImplemented(); // webkit.org/b/177633: [GTK] Move to new Pasteboard API >- return { }; >+ if (m_selectionData) >+ return { }; >+ >+ return platformStrategies()->pasteboardStrategy()->typesSafeForDOMToReadAndWrite(m_name, origin); > } > > Vector<String> Pasteboard::typesForLegacyUnsafeBindings() >@@ -336,15 +341,18 @@ Vector<String> Pasteboard::typesForLegacyUnsafeBindings() > types.append("URL"_s); > } > >- for (auto& key : m_selectionData->unknownTypes().keys()) >- types.append(key); >- > return types; > } > > String Pasteboard::readOrigin() > { >- notImplemented(); // webkit.org/b/177633: [GTK] Move to new Pasteboard API >+ if (m_selectionData) >+ return { }; >+ >+ // FIXME: cache custom data? >+ if (auto buffer = platformStrategies()->pasteboardStrategy()->readBufferFromClipboard(m_name, PasteboardCustomData::gtkType())) >+ return PasteboardCustomData::fromSharedBuffer(*buffer).origin(); >+ > return { }; > } > >@@ -368,7 +376,6 @@ String Pasteboard::readString(const String& type) > case ClipboardDataTypeText: > return m_selectionData->text(); > case ClipboardDataTypeUnknown: >- return m_selectionData->unknownTypeData(type); > case ClipboardDataTypeImage: > break; > } >@@ -376,9 +383,15 @@ String Pasteboard::readString(const String& type) > return { }; > } > >-String Pasteboard::readStringInCustomData(const String&) >+String Pasteboard::readStringInCustomData(const String& type) > { >- notImplemented(); // webkit.org/b/177633: [GTK] Move to new Pasteboard API >+ if (m_selectionData) >+ return { }; >+ >+ // FIXME: cache custom data? >+ if (auto buffer = platformStrategies()->pasteboardStrategy()->readBufferFromClipboard(m_name, PasteboardCustomData::gtkType())) >+ return PasteboardCustomData::fromSharedBuffer(*buffer).readStringInCustomData(type); >+ > return { }; > } > >@@ -388,8 +401,11 @@ Pasteboard::FileContentState Pasteboard::fileContentState() > return m_selectionData->filenames().isEmpty() ? FileContentState::NoFileOrImageData : FileContentState::MayContainFilePaths; > > auto types = platformStrategies()->pasteboardStrategy()->types(m_name); >- if (types.contains("text/uri-list"_s)) >- return FileContentState::MayContainFilePaths; >+ if (types.contains("text/uri-list"_s)) { >+ auto filePaths = platformStrategies()->pasteboardStrategy()->readFilePathsFromClipboard(m_name); >+ if (!filePaths.isEmpty()) >+ return FileContentState::MayContainFilePaths; >+ } > > auto result = types.findMatching([](const String& type) { > return MIMETypeRegistry::isSupportedImageMIMEType(type); >@@ -401,8 +417,12 @@ void Pasteboard::writeMarkup(const String&) > { > } > >-void Pasteboard::writeCustomData(const Vector<PasteboardCustomData>&) >+void Pasteboard::writeCustomData(const Vector<PasteboardCustomData>& data) > { >+ if (m_selectionData) >+ return; >+ >+ platformStrategies()->pasteboardStrategy()->writeCustomData(data, m_name); > } > > void Pasteboard::write(const Color&) >diff --git a/Source/WebCore/platform/gtk/SelectionData.cpp b/Source/WebCore/platform/gtk/SelectionData.cpp >index 10605517d019..ea4e4cdee550 100644 >--- a/Source/WebCore/platform/gtk/SelectionData.cpp >+++ b/Source/WebCore/platform/gtk/SelectionData.cpp >@@ -120,8 +120,8 @@ void SelectionData::clearAllExceptFilenames() > clearURIList(); > clearURL(); > clearImage(); >+ clearCustomData(); > >- m_unknownTypeData.clear(); > m_canSmartReplace = false; > } > >diff --git a/Source/WebCore/platform/gtk/SelectionData.h b/Source/WebCore/platform/gtk/SelectionData.h >index 1b858ef9dee5..b8b148cece3e 100644 >--- a/Source/WebCore/platform/gtk/SelectionData.h >+++ b/Source/WebCore/platform/gtk/SelectionData.h >@@ -19,6 +19,7 @@ > #pragma once > > #include "Image.h" >+#include "SharedBuffer.h" > #include <wtf/HashMap.h> > #include <wtf/RefCounted.h> > #include <wtf/URL.h> >@@ -62,14 +63,14 @@ public: > bool hasImage() const { return m_image; } > void clearImage() { m_image = nullptr; } > >- void setUnknownTypeData(const String& type, const String& data) { m_unknownTypeData.set(type, data); } >- String unknownTypeData(const String& type) const { return m_unknownTypeData.get(type); } >- const HashMap<String, String>& unknownTypes() const { return m_unknownTypeData; } >- bool hasUnknownTypeData() const { return !m_unknownTypeData.isEmpty(); } >- > void setCanSmartReplace(bool canSmartReplace) { m_canSmartReplace = canSmartReplace; } > bool canSmartReplace() const { return m_canSmartReplace; } > >+ void setCustomData(Ref<SharedBuffer>&& buffer) { m_customData = WTFMove(buffer); } >+ SharedBuffer* customData() const { return m_customData.get(); } >+ bool hasCustomData() const { return !!m_customData; } >+ void clearCustomData() { m_customData = nullptr; } >+ > void clearAll(); > void clearAllExceptFilenames(); > >@@ -80,8 +81,8 @@ private: > String m_uriList; > Vector<String> m_filenames; > RefPtr<Image> m_image; >- HashMap<String, String> m_unknownTypeData; > bool m_canSmartReplace { false }; >+ RefPtr<SharedBuffer> m_customData; > }; > > } // namespace WebCore >diff --git a/Source/WebKit/ChangeLog b/Source/WebKit/ChangeLog >index ed74fd8c578f..f10749868127 100644 >--- a/Source/WebKit/ChangeLog >+++ b/Source/WebKit/ChangeLog >@@ -1,3 +1,25 @@ >+2020-05-16 Carlos Garcia Campos <cgarcia@igalia.com> >+ >+ [GTK] Move to new Pasteboard API >+ https://bugs.webkit.org/show_bug.cgi?id=177633 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ 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): >+ > 2020-05-16 Yury Semikhatsky <yurys@chromium.org> > > [GTK] Do not leak pages created by window.open >diff --git a/Source/WebKit/Shared/WebPreferencesDefaultValues.h b/Source/WebKit/Shared/WebPreferencesDefaultValues.h >index b3255b2c78d5..a82f6b5635b6 100644 >--- a/Source/WebKit/Shared/WebPreferencesDefaultValues.h >+++ b/Source/WebKit/Shared/WebPreferencesDefaultValues.h >@@ -238,11 +238,15 @@ > #define DEFAULT_DATALIST_ELEMENT_ENABLED true > #endif > >-#if PLATFORM(COCOA) >+#if PLATFORM(COCOA) || PLATFORM(GTK) > #define DEFAULT_CUSTOM_PASTEBOARD_DATA_ENABLED true >-#define DEFAULT_ASYNC_CLIPBOARD_API_ENABLED true > #else > #define DEFAULT_CUSTOM_PASTEBOARD_DATA_ENABLED false >+#endif >+ >+#if PLATFORM(COCOA) >+#define DEFAULT_ASYNC_CLIPBOARD_API_ENABLED true >+#else > #define DEFAULT_ASYNC_CLIPBOARD_API_ENABLED false > #endif > >diff --git a/Source/WebKit/Shared/gtk/ArgumentCodersGtk.cpp b/Source/WebKit/Shared/gtk/ArgumentCodersGtk.cpp >index fc8eb5dd7135..39275446014d 100644 >--- a/Source/WebKit/Shared/gtk/ArgumentCodersGtk.cpp >+++ b/Source/WebKit/Shared/gtk/ArgumentCodersGtk.cpp >@@ -92,10 +92,10 @@ void ArgumentCoder<SelectionData>::encode(Encoder& encoder, const SelectionData& > if (hasImage) > encodeImage(encoder, *selection.image()); > >- bool hasUnknownTypeData = selection.hasUnknownTypeData(); >- encoder << hasUnknownTypeData; >- if (hasUnknownTypeData) >- encoder << selection.unknownTypes(); >+ bool hasCustomData = selection.hasCustomData(); >+ encoder << hasCustomData; >+ if (hasCustomData) >+ encoder << RefPtr<SharedBuffer>(selection.customData()); > > bool canSmartReplace = selection.canSmartReplace(); > encoder << canSmartReplace; >@@ -155,17 +155,14 @@ bool ArgumentCoder<SelectionData>::decode(Decoder& decoder, SelectionData& selec > selection.setImage(image.get()); > } > >- bool hasUnknownTypeData; >- if (!decoder.decode(hasUnknownTypeData)) >+ bool hasCustomData; >+ if (!decoder.decode(hasCustomData)) > return false; >- if (hasUnknownTypeData) { >- HashMap<String, String> unknownTypes; >- if (!decoder.decode(unknownTypes)) >+ if (hasCustomData) { >+ RefPtr<SharedBuffer> buffer; >+ if (!decoder.decode(buffer)) > return false; >- >- auto end = unknownTypes.end(); >- for (auto it = unknownTypes.begin(); it != end; ++it) >- selection.setUnknownTypeData(it->key, it->value); >+ selection.setCustomData(Ref<SharedBuffer>(*buffer)); > } > > bool canSmartReplace; >diff --git a/Source/WebKit/UIProcess/WebPasteboardProxy.cpp b/Source/WebKit/UIProcess/WebPasteboardProxy.cpp >index c144e7917c97..7bb2280342f3 100644 >--- a/Source/WebKit/UIProcess/WebPasteboardProxy.cpp >+++ b/Source/WebKit/UIProcess/WebPasteboardProxy.cpp >@@ -79,6 +79,7 @@ WebProcessProxy* WebPasteboardProxy::webProcessProxyForConnection(IPC::Connectio > > #if !PLATFORM(COCOA) > >+#if !PLATFORM(GTK) > void WebPasteboardProxy::typesSafeForDOMToReadAndWrite(IPC::Connection&, const String&, const String&, CompletionHandler<void(Vector<String>&&)>&& completionHandler) > { > completionHandler({ }); >@@ -88,6 +89,7 @@ void WebPasteboardProxy::writeCustomData(IPC::Connection&, const Vector<WebCore: > { > completionHandler(0); > } >+#endif > > void WebPasteboardProxy::allPasteboardItemInfo(IPC::Connection&, const String&, int64_t, CompletionHandler<void(Optional<Vector<WebCore::PasteboardItemInfo>>&&)>&& completionHandler) > { >diff --git a/Source/WebKit/UIProcess/gtk/ClipboardGtk3.cpp b/Source/WebKit/UIProcess/gtk/ClipboardGtk3.cpp >index e3915cf04529..913d33994eb8 100644 >--- a/Source/WebKit/UIProcess/gtk/ClipboardGtk3.cpp >+++ b/Source/WebKit/UIProcess/gtk/ClipboardGtk3.cpp >@@ -30,6 +30,7 @@ > > #include "WebPasteboardProxy.h" > #include <WebCore/GRefPtrGtk.h> >+#include <WebCore/PasteboardCustomData.h> > #include <WebCore/SelectionData.h> > #include <WebCore/SharedBuffer.h> > #include <gtk/gtk.h> >@@ -155,13 +156,15 @@ struct WriteAsyncData { > Clipboard& clipboard; > }; > >-enum ClipboardTargetType { Markup, Text, Image, SmartPaste }; >+enum ClipboardTargetType { Markup, Text, Image, URIList, SmartPaste, Custom }; > > void Clipboard::write(Ref<WebCore::SelectionData>&& selectionData) > { > SetForScope<WebFrameProxy*> frameWritingToClipboard(m_frameWritingToClipboard, WebPasteboardProxy::singleton().primarySelectionOwner()); > > GRefPtr<GtkTargetList> list = adoptGRef(gtk_target_list_new(nullptr, 0)); >+ if (selectionData->hasURIList()) >+ gtk_target_list_add(list.get(), gdk_atom_intern_static_string("text/uri-list"), 0, ClipboardTargetType::URIList); > if (selectionData->hasMarkup()) > gtk_target_list_add(list.get(), gdk_atom_intern_static_string("text/html"), 0, ClipboardTargetType::Markup); > if (selectionData->hasImage()) >@@ -170,6 +173,8 @@ void Clipboard::write(Ref<WebCore::SelectionData>&& selectionData) > gtk_target_list_add_text_targets(list.get(), ClipboardTargetType::Text); > if (selectionData->canSmartReplace()) > gtk_target_list_add(list.get(), gdk_atom_intern_static_string("application/vnd.webkitgtk.smartpaste"), 0, ClipboardTargetType::SmartPaste); >+ if (selectionData->hasCustomData()) >+ gtk_target_list_add(list.get(), gdk_atom_intern_static_string(WebCore::PasteboardCustomData::gtkType()), 0, ClipboardTargetType::Custom); > > int numberOfTargets; > GtkTargetEntry* table = gtk_target_table_new_from_list(list.get(), &numberOfTargets); >@@ -199,9 +204,20 @@ void Clipboard::write(Ref<WebCore::SelectionData>&& selectionData) > } > break; > } >+ case ClipboardTargetType::URIList: { >+ CString uriList = selectionData.uriList().utf8(); >+ gtk_selection_data_set(selection, gdk_atom_intern_static_string("text/uri-list"), 8, reinterpret_cast<const guchar*>(uriList.data()), uriList.length()); >+ break; >+ } > case ClipboardTargetType::SmartPaste: > gtk_selection_data_set_text(selection, "", -1); > break; >+ case ClipboardTargetType::Custom: >+ if (selectionData.hasCustomData()) { >+ auto* buffer = selectionData.customData(); >+ gtk_selection_data_set(selection, gdk_atom_intern_static_string(WebCore::PasteboardCustomData::gtkType()), 8, reinterpret_cast<const guchar*>(buffer->data()), buffer->size()); >+ } >+ break; > } > }, > [](GtkClipboard* clipboard, gpointer userData) { >diff --git a/Source/WebKit/UIProcess/gtk/ClipboardGtk4.cpp b/Source/WebKit/UIProcess/gtk/ClipboardGtk4.cpp >index 821cc6cfea48..13d372fb435e 100644 >--- a/Source/WebKit/UIProcess/gtk/ClipboardGtk4.cpp >+++ b/Source/WebKit/UIProcess/gtk/ClipboardGtk4.cpp >@@ -29,6 +29,7 @@ > #if USE(GTK4) > > #include "WebPasteboardProxy.h" >+#include <WebCore/PasteboardCustomData.h> > #include <WebCore/SelectionData.h> > #include <WebCore/SharedBuffer.h> > #include <gtk/gtk.h> >@@ -164,6 +165,12 @@ void Clipboard::write(Ref<WebCore::SelectionData>&& selectionData) > providers.append(gdk_content_provider_new_for_bytes("text/html", bytes.get())); > } > >+ if (selectionData->hasURIList()) { >+ CString uriList = selectionData->uriList().utf8(); >+ GRefPtr<GBytes> bytes = adoptGRef(g_bytes_new(uriList.data(), uriList.length())); >+ providers.append(gdk_content_provider_new_for_bytes("text/uri-list", bytes.get())); >+ } >+ > if (selectionData->hasImage()) { > GRefPtr<GdkPixbuf> pixbuf = adoptGRef(selectionData->image()->getGdkPixbuf()); > providers.append(gdk_content_provider_new_typed(GDK_TYPE_PIXBUF, pixbuf.get())); >@@ -177,6 +184,11 @@ void Clipboard::write(Ref<WebCore::SelectionData>&& selectionData) > providers.append(gdk_content_provider_new_for_bytes("application/vnd.webkitgtk.smartpaste", bytes.get())); > } > >+ if (selectionData->hasCustomData()) { >+ GRefPtr<GBytes> bytes = selectionData->customData()->createGBytes(); >+ providers.append(gdk_content_provider_new_for_bytes(WebCore::PasteboardCustomData::gtkType(), bytes.get())); >+ } >+ > if (providers.isEmpty()) { > clear(); > return; >diff --git a/Source/WebKit/UIProcess/gtk/WebPasteboardProxyGtk.cpp b/Source/WebKit/UIProcess/gtk/WebPasteboardProxyGtk.cpp >index 0a132ec55232..c6dd4625b0da 100644 >--- a/Source/WebKit/UIProcess/gtk/WebPasteboardProxyGtk.cpp >+++ b/Source/WebKit/UIProcess/gtk/WebPasteboardProxyGtk.cpp >@@ -30,8 +30,12 @@ > #include "SharedBufferDataReference.h" > #include "WebFrameProxy.h" > #include "WebSelectionData.h" >+#include <WebCore/Pasteboard.h> >+#include <WebCore/PasteboardCustomData.h> >+#include <WebCore/PasteboardItemInfo.h> > #include <WebCore/PlatformPasteboard.h> > #include <WebCore/SharedBuffer.h> >+#include <wtf/ListHashSet.h> > #include <wtf/SetForScope.h> > > namespace WebKit { >@@ -84,4 +88,59 @@ void WebPasteboardProxy::didDestroyFrame(WebFrameProxy* frame) > m_primarySelectionOwner = nullptr; > } > >+void WebPasteboardProxy::typesSafeForDOMToReadAndWrite(IPC::Connection&, const String& pasteboardName, const String& origin, CompletionHandler<void(Vector<String>&&)>&& completionHandler) >+{ >+ auto& clipboard = Clipboard::get(pasteboardName); >+ clipboard.readBuffer(PasteboardCustomData::gtkType(), [&clipboard, origin, completionHandler = WTFMove(completionHandler)](IPC::SharedBufferDataReference&& buffer) mutable { >+ ListHashSet<String> domTypes; >+ if (auto dataBuffer = buffer.buffer()) { >+ auto customData = PasteboardCustomData::fromSharedBuffer(*dataBuffer); >+ if (customData.origin() == origin) { >+ for (auto& type : customData.orderedTypes()) >+ domTypes.add(type); >+ } >+ } >+ >+ clipboard.formats([domTypes = WTFMove(domTypes), completionHandler = WTFMove(completionHandler)](Vector<String>&& formats) mutable { >+ for (const auto& format : formats) { >+ if (format == PasteboardCustomData::gtkType()) >+ continue; >+ >+ if (Pasteboard::isSafeTypeForDOMToReadAndWrite(format)) >+ domTypes.add(format); >+ } >+ >+ completionHandler(copyToVector(domTypes)); >+ }); >+ }); >+} >+ >+void WebPasteboardProxy::writeCustomData(IPC::Connection&, const Vector<PasteboardCustomData>& data, const String& pasteboardName, CompletionHandler<void(int64_t)>&& completionHandler) >+{ >+ if (data.isEmpty() || data.size() > 1) { >+ // We don't support more than one custom item in the clipboard. >+ completionHandler(0); >+ return; >+ } >+ >+ auto selectionData = SelectionData::create(); >+ const auto& customData = data[0]; >+ customData.forEachPlatformStringOrBuffer([&selectionData] (auto& type, auto& stringOrBuffer) { >+ if (WTF::holds_alternative<String>(stringOrBuffer)) { >+ if (type == "text/plain"_s) >+ selectionData->setText(WTF::get<String>(stringOrBuffer)); >+ else if (type == "text/html"_s) >+ selectionData->setMarkup(WTF::get<String>(stringOrBuffer)); >+ else if (type == "text/uri-list"_s) >+ selectionData->setURIList(WTF::get<String>(stringOrBuffer)); >+ } >+ }); >+ >+ if (customData.hasSameOriginCustomData() || !customData.origin().isEmpty()) >+ selectionData->setCustomData(customData.createSharedBuffer()); >+ >+ Clipboard::get(pasteboardName).write(WTFMove(selectionData)); >+ completionHandler(0); >+} >+ > } // namespace WebKit
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Flags:
aperez
:
review+
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 177633
: 399547