- Revision
- 286861
- Author
- drou...@apple.com
- Date
- 2021-12-10 11:02:55 -0800 (Fri, 10 Dec 2021)
Log Message
Add a way to write a `SharedBuffer` to the Pasteboard
https://bugs.webkit.org/show_bug.cgi?id=234065
Reviewed by Wenson Hsieh.
In order to match the WK1 implementation of `-pasteFont:` <https://webkit.org/b/191379>, we
need to be able to write a `SharedBuffer` (with an associated type) to the font pasteboard.
Create a `struct PasteboardBuffer` to wrap the `SharedBuffer` and `String type` (and a
`String contentOrigin` on Cocoa platforms, which is used to decide whether to show a "Paste"
callout to the user as a gate on crossorigin content sharing) in a single object.
Though it isn't used in this patch, `-pasteFont:` <https://webkit.org/b/191379> will use
this to write RTF data (which contains the necessary font data).
No change in behavior.
* platform/Pasteboard.h:
* platform/Pasteboard.cpp:
* platform/libwpe/PasteboardLibWPE.cpp:
(WebCore::Pasteboard::write):
* platform/gtk/PasteboardGtk.cpp:
(WebCore::Pasteboard::write):
* platform/ios/PasteboardIOS.mm:
(WebCore::Pasteboard::write):
* platform/mac/PasteboardMac.mm:
(WebCore::Pasteboard::write):
* platform/win/PasteboardWin.cpp:
(WebCore::Pasteboard::write):
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (286860 => 286861)
--- trunk/Source/WebCore/ChangeLog 2021-12-10 19:00:44 UTC (rev 286860)
+++ trunk/Source/WebCore/ChangeLog 2021-12-10 19:02:55 UTC (rev 286861)
@@ -1,3 +1,35 @@
+2021-12-10 Devin Rousso <drou...@apple.com>
+
+ Add a way to write a `SharedBuffer` to the Pasteboard
+ https://bugs.webkit.org/show_bug.cgi?id=234065
+
+ Reviewed by Wenson Hsieh.
+
+ In order to match the WK1 implementation of `-pasteFont:` <https://webkit.org/b/191379>, we
+ need to be able to write a `SharedBuffer` (with an associated type) to the font pasteboard.
+
+ Create a `struct PasteboardBuffer` to wrap the `SharedBuffer` and `String type` (and a
+ `String contentOrigin` on Cocoa platforms, which is used to decide whether to show a "Paste"
+ callout to the user as a gate on crossorigin content sharing) in a single object.
+
+ Though it isn't used in this patch, `-pasteFont:` <https://webkit.org/b/191379> will use
+ this to write RTF data (which contains the necessary font data).
+
+ No change in behavior.
+
+ * platform/Pasteboard.h:
+ * platform/Pasteboard.cpp:
+ * platform/libwpe/PasteboardLibWPE.cpp:
+ (WebCore::Pasteboard::write):
+ * platform/gtk/PasteboardGtk.cpp:
+ (WebCore::Pasteboard::write):
+ * platform/ios/PasteboardIOS.mm:
+ (WebCore::Pasteboard::write):
+ * platform/mac/PasteboardMac.mm:
+ (WebCore::Pasteboard::write):
+ * platform/win/PasteboardWin.cpp:
+ (WebCore::Pasteboard::write):
+
2021-12-10 Patrick Griffis <pgrif...@igalia.com>
CSP: Prevent nonce-hijacking
Modified: trunk/Source/WebCore/platform/Pasteboard.cpp (286860 => 286861)
--- trunk/Source/WebCore/platform/Pasteboard.cpp 2021-12-10 19:00:44 UTC (rev 286860)
+++ trunk/Source/WebCore/platform/Pasteboard.cpp 2021-12-10 19:02:55 UTC (rev 286861)
@@ -38,6 +38,10 @@
PasteboardImage::PasteboardImage() = default;
PasteboardImage::~PasteboardImage() = default;
+// Making this non-inline so that WebKit 2's decoding doesn't have to include SharedBuffer.h.
+PasteboardBuffer::PasteboardBuffer() = default;
+PasteboardBuffer::~PasteboardBuffer() = default;
+
bool Pasteboard::isSafeTypeForDOMToReadAndWrite(const String& type)
{
return type == "text/plain" || type == "text/html" || type == "text/uri-list";
Modified: trunk/Source/WebCore/platform/Pasteboard.h (286860 => 286861)
--- trunk/Source/WebCore/platform/Pasteboard.h 2021-12-10 19:00:44 UTC (rev 286860)
+++ trunk/Source/WebCore/platform/Pasteboard.h 2021-12-10 19:02:55 UTC (rev 286861)
@@ -135,6 +135,17 @@
FloatSize imageSize;
};
+struct PasteboardBuffer {
+ WEBCORE_EXPORT PasteboardBuffer();
+ WEBCORE_EXPORT ~PasteboardBuffer();
+
+#if PLATFORM(COCOA)
+ String contentOrigin;
+#endif
+ String type;
+ RefPtr<SharedBuffer> data;
+};
+
// For reading from the pasteboard.
class PasteboardWebContentReader {
@@ -223,6 +234,7 @@
virtual WEBCORE_EXPORT void write(const PasteboardURL&);
virtual WEBCORE_EXPORT void writeTrustworthyWebURLsPboardType(const PasteboardURL&);
virtual WEBCORE_EXPORT void write(const PasteboardImage&);
+ virtual WEBCORE_EXPORT void write(const PasteboardBuffer&);
virtual WEBCORE_EXPORT void write(const PasteboardWebContent&);
virtual WEBCORE_EXPORT void writeCustomData(const Vector<PasteboardCustomData>&);
Modified: trunk/Source/WebCore/platform/gtk/PasteboardGtk.cpp (286860 => 286861)
--- trunk/Source/WebCore/platform/gtk/PasteboardGtk.cpp 2021-12-10 19:00:44 UTC (rev 286860)
+++ trunk/Source/WebCore/platform/gtk/PasteboardGtk.cpp 2021-12-10 19:02:55 UTC (rev 286861)
@@ -183,6 +183,10 @@
}
}
+void Pasteboard::write(const PasteboardBuffer&)
+{
+}
+
void Pasteboard::write(const PasteboardWebContent& pasteboardContent)
{
if (m_selectionData) {
Modified: trunk/Source/WebCore/platform/ios/PasteboardIOS.mm (286860 => 286861)
--- trunk/Source/WebCore/platform/ios/PasteboardIOS.mm 2021-12-10 19:00:44 UTC (rev 286860)
+++ trunk/Source/WebCore/platform/ios/PasteboardIOS.mm 2021-12-10 19:02:55 UTC (rev 286861)
@@ -128,6 +128,10 @@
platformStrategies()->pasteboardStrategy()->writeToPasteboard(pasteboardImage, m_pasteboardName, context());
}
+void Pasteboard::write(const PasteboardBuffer&)
+{
+}
+
void Pasteboard::writePlainText(const String& text, SmartReplaceOption)
{
// FIXME: We vend "public.text" here for backwards compatibility with pre-iOS 11 apps. In the future, we should stop vending this UTI,
Modified: trunk/Source/WebCore/platform/libwpe/PasteboardLibWPE.cpp (286860 => 286861)
--- trunk/Source/WebCore/platform/libwpe/PasteboardLibWPE.cpp 2021-12-10 19:00:44 UTC (rev 286860)
+++ trunk/Source/WebCore/platform/libwpe/PasteboardLibWPE.cpp 2021-12-10 19:02:55 UTC (rev 286861)
@@ -123,6 +123,10 @@
{
}
+void Pasteboard::write(const PasteboardBuffer&)
+{
+}
+
void Pasteboard::write(const PasteboardWebContent& content)
{
platformStrategies()->pasteboardStrategy()->writeToPasteboard(content);
Modified: trunk/Source/WebCore/platform/mac/PasteboardMac.mm (286860 => 286861)
--- trunk/Source/WebCore/platform/mac/PasteboardMac.mm 2021-12-10 19:00:44 UTC (rev 286860)
+++ trunk/Source/WebCore/platform/mac/PasteboardMac.mm 2021-12-10 19:02:55 UTC (rev 286861)
@@ -298,6 +298,20 @@
writeFileWrapperAsRTFDAttachment(fileWrapper(pasteboardImage), m_pasteboardName, m_changeCount, context());
}
+void Pasteboard::write(const PasteboardBuffer& pasteboardBuffer)
+{
+ ASSERT(!pasteboardBuffer.type.isEmpty());
+ ASSERT(pasteboardBuffer.data);
+
+ m_changeCount = platformStrategies()->pasteboardStrategy()->setTypes({ pasteboardBuffer.type, PasteboardCustomData::cocoaType() }, m_pasteboardName, context());
+
+ m_changeCount = platformStrategies()->pasteboardStrategy()->setBufferForType(pasteboardBuffer.data.get(), pasteboardBuffer.type, m_pasteboardName, context());
+
+ PasteboardCustomData pasteboardCustomData;
+ pasteboardCustomData.setOrigin(pasteboardBuffer.contentOrigin);
+ m_changeCount = platformStrategies()->pasteboardStrategy()->setBufferForType(pasteboardCustomData.createSharedBuffer().ptr(), PasteboardCustomData::cocoaType(), m_pasteboardName, context());
+}
+
bool Pasteboard::canSmartReplace()
{
Vector<String> types;
Modified: trunk/Source/WebCore/platform/win/PasteboardWin.cpp (286860 => 286861)
--- trunk/Source/WebCore/platform/win/PasteboardWin.cpp 2021-12-10 19:00:44 UTC (rev 286860)
+++ trunk/Source/WebCore/platform/win/PasteboardWin.cpp 2021-12-10 19:02:55 UTC (rev 286861)
@@ -1118,6 +1118,10 @@
{
}
+void Pasteboard::write(const PasteboardBuffer&)
+{
+}
+
void Pasteboard::writeCustomData(const Vector<PasteboardCustomData>& data)
{
if (data.isEmpty() || data.size() > 1) {