Title: [295337] trunk/Source/WebKit
Revision
295337
Author
[email protected]
Date
2022-06-07 04:00:50 -0700 (Tue, 07 Jun 2022)

Log Message

SharedBuffer should be copied when moved over IPC
https://bugs.webkit.org/show_bug.cgi?id=240902
<rdar://93881913>

Reviewed by Jer Noble.

Have SharedBuffer and FragmentedSharedBuffer IPC serializers always perform a copy
Make DrawToPDF use SharedBuffer directly rather than SharedBufferReference.
Replace use of IPCHandle with SharedBuffer in clipboard IPC methods.

The SharedBuffer serializer ultimately does the same thing and it allows for simpler code.

* Source/WebKit/Shared/WebCoreArgumentCoders.cpp:
(IPC::decodeSharedBuffer):
* Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView createPDFWithConfiguration:completionHandler:]):
* Source/WebKit/UIProcess/Cocoa/WebPasteboardProxyCocoa.mm:
(WebKit::WebPasteboardProxy::getPasteboardBufferForType):
(WebKit::WebPasteboardProxy::setPasteboardBufferForType):
(WebKit::WebPasteboardProxy::readBufferFromPasteboard):
* Source/WebKit/UIProcess/WebPageProxy.cpp:
(WebKit::CompletionHandler<void):
(WebKit::WebPageProxy::drawPagesToPDF):
(WebKit::WebPageProxy::drawToPDF):
* Source/WebKit/UIProcess/WebPageProxy.h:
* Source/WebKit/UIProcess/WebPasteboardProxy.cpp:
(WebKit::WebPasteboardProxy::readBufferFromPasteboard):
* Source/WebKit/UIProcess/WebPasteboardProxy.h:
* Source/WebKit/UIProcess/WebPasteboardProxy.messages.in:
* Source/WebKit/UIProcess/gtk/WebPasteboardProxyGtk.cpp:
(WebKit::WebPasteboardProxy::readBuffer):
* Source/WebKit/UIProcess/ios/WKContentView.mm:
(-[WKContentView _wk_pageCountForPrintFormatter:]):
* Source/WebKit/UIProcess/ios/WebPageProxyIOS.mm:
(WebKit::WebPageProxy::drawToPDFiOS):
* Source/WebKit/UIProcess/mac/WebPageProxyMac.mm:
(WebKit::WebPageProxy::dataSelectionForPasteboard):
* Source/WebKit/WebProcess/Plugins/PDF/PDFPlugin.mm:
(WebKit::PDFPlugin::writeItemsToPasteboard):
* Source/WebKit/WebProcess/WebCoreSupport/WebPlatformStrategies.cpp:
(WebKit::WebPlatformStrategies::bufferForType):
(WebKit::WebPlatformStrategies::setBufferForType):
(WebKit::WebPlatformStrategies::readBufferFromClipboard):
(WebKit::WebPlatformStrategies::readBufferFromPasteboard):
* Source/WebKit/WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::drawToPDF):
(WebKit::WebPage::drawPagesToPDF):
* Source/WebKit/WebProcess/WebPage/WebPage.h:
* Source/WebKit/WebProcess/WebPage/WebPage.messages.in:
* Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm:
(WebKit::WebPage::getDataSelectionForPasteboard):
(WebKit::WebPage::drawToPDFiOS):
* Source/WebKit/WebProcess/WebPage/mac/WebPageMac.mm:
(WebKit::WebPage::getDataSelectionForPasteboard):

Canonical link: https://commits.webkit.org/251356@main

Modified Paths

Diff

Modified: trunk/Source/WebKit/Shared/WebCoreArgumentCoders.cpp (295336 => 295337)


--- trunk/Source/WebKit/Shared/WebCoreArgumentCoders.cpp	2022-06-07 09:36:12 UTC (rev 295336)
+++ trunk/Source/WebKit/Shared/WebCoreArgumentCoders.cpp	2022-06-07 11:00:50 UTC (rev 295337)
@@ -239,7 +239,7 @@
     if (sharedMemoryBuffer->size() < bufferSize)
         return false;
 
-    buffer = sharedMemoryBuffer->createSharedBuffer(bufferSize);
+    buffer = SharedBuffer::create(static_cast<unsigned char*>(sharedMemoryBuffer->data()), bufferSize);
 #endif
 
     return true;

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm (295336 => 295337)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm	2022-06-07 09:36:12 UTC (rev 295336)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm	2022-06-07 11:00:50 UTC (rev 295337)
@@ -54,7 +54,6 @@
 #import "ResourceLoadDelegate.h"
 #import "SafeBrowsingWarning.h"
 #import "SessionStateCoding.h"
-#import "SharedBufferReference.h"
 #import "UIDelegate.h"
 #import "VideoFullscreenManagerProxy.h"
 #import "ViewGestureController.h"
@@ -1741,13 +1740,13 @@
     if (pdfConfiguration && !CGRectIsNull(pdfConfiguration.rect))
         floatRect = WebCore::FloatRect(pdfConfiguration.rect);
 
-    _page->drawToPDF(frameID, floatRect, [handler = makeBlockPtr(completionHandler)](const IPC::SharedBufferReference& pdfData) {
-        if (pdfData.isEmpty()) {
+    _page->drawToPDF(frameID, floatRect, [handler = makeBlockPtr(completionHandler)](RefPtr<WebCore::SharedBuffer>&& pdfData) {
+        if (!pdfData || pdfData->isEmpty()) {
             handler(nil, createNSError(WKErrorUnknown).get());
             return;
         }
 
-        auto data = ""
+        auto data = ""
         handler((NSData *)data.get(), nil);
     });
 }

Modified: trunk/Source/WebKit/UIProcess/Cocoa/WebPasteboardProxyCocoa.mm (295336 => 295337)


--- trunk/Source/WebKit/UIProcess/Cocoa/WebPasteboardProxyCocoa.mm	2022-06-07 09:36:12 UTC (rev 295336)
+++ trunk/Source/WebKit/UIProcess/Cocoa/WebPasteboardProxyCocoa.mm	2022-06-07 11:00:50 UTC (rev 295337)
@@ -29,6 +29,7 @@
 #import "Connection.h"
 #import "PasteboardAccessIntent.h"
 #import "SandboxExtension.h"
+#import "WebCoreArgumentCoders.h"
 #import "WebPageProxy.h"
 #import "WebPreferences.h"
 #import "WebProcessMessages.h"
@@ -215,7 +216,7 @@
     });
 }
 
-void WebPasteboardProxy::getPasteboardBufferForType(IPC::Connection& connection, const String& pasteboardName, const String& pasteboardType, std::optional<PageIdentifier> pageID, CompletionHandler<void(SharedMemory::IPCHandle&&)>&& completionHandler)
+void WebPasteboardProxy::getPasteboardBufferForType(IPC::Connection& connection, const String& pasteboardName, const String& pasteboardType, std::optional<PageIdentifier> pageID, CompletionHandler<void(RefPtr<WebCore::SharedBuffer>&&)>&& completionHandler)
 {
     MESSAGE_CHECK_COMPLETION(!pasteboardType.isEmpty(), completionHandler({ }));
 
@@ -226,21 +227,7 @@
     MESSAGE_CHECK_COMPLETION(dataOwner, completionHandler({ }));
 
     PlatformPasteboard::performAsDataOwner(*dataOwner, [&] {
-        auto buffer = PlatformPasteboard(pasteboardName).bufferForType(pasteboardType);
-        if (!buffer)
-            return completionHandler({ });
-        uint64_t size = buffer->size();
-        if (!size)
-            return completionHandler({ });
-        SharedMemory::Handle handle;
-        {
-            auto sharedMemoryBuffer = SharedMemory::copyBuffer(*buffer);
-            if (!sharedMemoryBuffer)
-                return completionHandler({ });
-            if (!sharedMemoryBuffer->createHandle(handle, SharedMemory::Protection::ReadOnly))
-                return completionHandler({ });
-        }
-        completionHandler(SharedMemory::IPCHandle { WTFMove(handle), size });
+        completionHandler(PlatformPasteboard(pasteboardName).bufferForType(pasteboardType));
     });
 }
 
@@ -401,7 +388,7 @@
     });
 }
 
-void WebPasteboardProxy::setPasteboardBufferForType(IPC::Connection& connection, const String& pasteboardName, const String& pasteboardType, const SharedMemory::IPCHandle& ipcHandle, std::optional<PageIdentifier> pageID, CompletionHandler<void(int64_t)>&& completionHandler)
+void WebPasteboardProxy::setPasteboardBufferForType(IPC::Connection& connection, const String& pasteboardName, const String& pasteboardType, RefPtr<SharedBuffer>&& buffer, std::optional<PageIdentifier> pageID, CompletionHandler<void(int64_t)>&& completionHandler)
 {
     MESSAGE_CHECK_COMPLETION(!pasteboardName.isEmpty(), completionHandler(0));
     MESSAGE_CHECK_COMPLETION(!pasteboardType.isEmpty(), completionHandler(0));
@@ -411,17 +398,12 @@
 
     PlatformPasteboard::performAsDataOwner(*dataOwner, [&] {
         auto previousChangeCount = PlatformPasteboard(pasteboardName).changeCount();
-        if (ipcHandle.handle.isNull()) {
+        if (!buffer) {
             auto newChangeCount = PlatformPasteboard(pasteboardName).setBufferForType(nullptr, pasteboardType);
             didModifyContentsOfPasteboard(connection, pasteboardName, previousChangeCount, newChangeCount);
             return completionHandler(newChangeCount);
         }
-
-        auto sharedMemoryBuffer = SharedMemory::map(ipcHandle.handle, SharedMemory::Protection::ReadOnly);
-        if (!sharedMemoryBuffer)
-            return completionHandler(0);
-        auto buffer = sharedMemoryBuffer->createSharedBuffer(ipcHandle.dataSize);
-        auto newChangeCount = PlatformPasteboard(pasteboardName).setBufferForType(buffer.ptr(), pasteboardType);
+        auto newChangeCount = PlatformPasteboard(pasteboardName).setBufferForType(buffer.get(), pasteboardType);
         didModifyContentsOfPasteboard(connection, pasteboardName, previousChangeCount, newChangeCount);
         completionHandler(newChangeCount);
     });
@@ -539,7 +521,7 @@
     });
 }
 
-void WebPasteboardProxy::readBufferFromPasteboard(IPC::Connection& connection, std::optional<size_t> index, const String& pasteboardType, const String& pasteboardName, std::optional<PageIdentifier> pageID, CompletionHandler<void(SharedMemory::IPCHandle&&)>&& completionHandler)
+void WebPasteboardProxy::readBufferFromPasteboard(IPC::Connection& connection, std::optional<size_t> index, const String& pasteboardType, const String& pasteboardName, std::optional<PageIdentifier> pageID, CompletionHandler<void(RefPtr<SharedBuffer>&&)>&& completionHandler)
 {
     MESSAGE_CHECK_COMPLETION(!pasteboardType.isEmpty(), completionHandler({ }));
 
@@ -550,21 +532,7 @@
     MESSAGE_CHECK_COMPLETION(dataOwner, completionHandler({ }));
 
     PlatformPasteboard::performAsDataOwner(*dataOwner, [&] {
-        auto buffer = PlatformPasteboard(pasteboardName).readBuffer(index, pasteboardType);
-        if (!buffer)
-            return completionHandler({ });
-        uint64_t size = buffer->size();
-        if (!size)
-            return completionHandler({ });
-        SharedMemory::Handle handle;
-        {
-            auto sharedMemoryBuffer = SharedMemory::copyBuffer(*buffer);
-            if (!sharedMemoryBuffer)
-                return completionHandler({ });
-            if (!sharedMemoryBuffer->createHandle(handle, SharedMemory::Protection::ReadOnly))
-                return completionHandler({ });
-        }
-        completionHandler(SharedMemory::IPCHandle { WTFMove(handle), size });
+        completionHandler(PlatformPasteboard(pasteboardName).readBuffer(index, pasteboardType));
     });
 }
 

Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.cpp (295336 => 295337)


--- trunk/Source/WebKit/UIProcess/WebPageProxy.cpp	2022-06-07 09:36:12 UTC (rev 295336)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.cpp	2022-06-07 11:00:50 UTC (rev 295337)
@@ -4514,9 +4514,10 @@
     sendWithAsyncReply(Messages::WebPage::GetSamplingProfilerOutput(), WTFMove(callback));
 }
 
-static CompletionHandler<void(const std::optional<IPC::SharedBufferReference>& data)> toAPIDataCallback(CompletionHandler<void(API::Data*)>&& callback)
+template <typename T>
+static CompletionHandler<void(T data)> toAPIDataCallbackT(CompletionHandler<void(API::Data*)>&& callback)
 {
-    return [callback = WTFMove(callback)] (const std::optional<IPC::SharedBufferReference>& data) mutable {
+    return [callback = WTFMove(callback)] (T data) mutable {
         if (!data) {
             callback(nullptr);
             return;
@@ -4525,6 +4526,9 @@
     };
 }
 
+auto* toAPIDataCallback = toAPIDataCallbackT<const std::optional<IPC::SharedBufferReference>&>;
+auto* toAPIDataSharedBufferCallback = toAPIDataCallbackT<RefPtr<WebCore::SharedBuffer>&&>;
+
 #if ENABLE(MHTML)
 void WebPageProxy::getContentsAsMHTMLData(CompletionHandler<void(API::Data*)>&& callback)
 {
@@ -9157,7 +9161,7 @@
 
 uint64_t WebPageProxy::drawPagesToPDF(WebFrameProxy* frame, const PrintInfo& printInfo, uint32_t first, uint32_t count, CompletionHandler<void(API::Data*)>&& callback)
 {
-    return sendWithAsyncReply(Messages::WebPage::DrawPagesToPDF(frame->frameID(), printInfo, first, count), toAPIDataCallback(WTFMove(callback)), printingSendOptions(m_isPerformingDOMPrintOperation));
+    return sendWithAsyncReply(Messages::WebPage::DrawPagesToPDF(frame->frameID(), printInfo, first, count), toAPIDataSharedBufferCallback(WTFMove(callback)), printingSendOptions(m_isPerformingDOMPrintOperation));
 }
 #elif PLATFORM(GTK)
 void WebPageProxy::drawPagesForPrinting(WebFrameProxy* frame, const PrintInfo& printInfo, CompletionHandler<void(API::Error*)>&& callback)
@@ -9173,7 +9177,7 @@
 #endif
 
 #if PLATFORM(COCOA)
-void WebPageProxy::drawToPDF(FrameIdentifier frameID, const std::optional<FloatRect>& rect, CompletionHandler<void(const IPC::SharedBufferReference&)>&& callback)
+void WebPageProxy::drawToPDF(FrameIdentifier frameID, const std::optional<FloatRect>& rect, CompletionHandler<void(RefPtr<SharedBuffer>&&)>&& callback)
 {
     if (!hasRunningProcess()) {
         callback({ });

Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.h (295336 => 295337)


--- trunk/Source/WebKit/UIProcess/WebPageProxy.h	2022-06-07 09:36:12 UTC (rev 295336)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.h	2022-06-07 11:00:50 UTC (rev 295337)
@@ -1432,10 +1432,10 @@
 #if PLATFORM(COCOA)
     uint64_t drawRectToImage(WebFrameProxy*, const PrintInfo&, const WebCore::IntRect&, const WebCore::IntSize&, CompletionHandler<void(const WebKit::ShareableBitmap::Handle&)>&&);
     uint64_t drawPagesToPDF(WebFrameProxy*, const PrintInfo&, uint32_t first, uint32_t count, CompletionHandler<void(API::Data*)>&&);
-    void drawToPDF(WebCore::FrameIdentifier, const std::optional<WebCore::FloatRect>&, CompletionHandler<void(const IPC::SharedBufferReference&)>&&);
+    void drawToPDF(WebCore::FrameIdentifier, const std::optional<WebCore::FloatRect>&, CompletionHandler<void(RefPtr<WebCore::SharedBuffer>&&)>&&);
 #if PLATFORM(IOS_FAMILY)
     size_t computePagesForPrintingiOS(WebCore::FrameIdentifier, const PrintInfo&);
-    uint64_t drawToPDFiOS(WebCore::FrameIdentifier, const PrintInfo&, size_t pageCount, CompletionHandler<void(const IPC::SharedBufferReference&)>&&);
+    uint64_t drawToPDFiOS(WebCore::FrameIdentifier, const PrintInfo&, size_t pageCount, CompletionHandler<void(RefPtr<WebCore::SharedBuffer>&&)>&&);
 #endif
 #elif PLATFORM(GTK)
     void drawPagesForPrinting(WebFrameProxy*, const PrintInfo&, CompletionHandler<void(API::Error*)>&&);

Modified: trunk/Source/WebKit/UIProcess/WebPasteboardProxy.cpp (295336 => 295337)


--- trunk/Source/WebKit/UIProcess/WebPasteboardProxy.cpp	2022-06-07 09:36:12 UTC (rev 295336)
+++ trunk/Source/WebKit/UIProcess/WebPasteboardProxy.cpp	2022-06-07 11:00:50 UTC (rev 295337)
@@ -111,7 +111,7 @@
     completionHandler({ }, { });
 }
 
-void WebPasteboardProxy::readBufferFromPasteboard(IPC::Connection&, std::optional<size_t>, const String&, const String&, std::optional<WebCore::PageIdentifier>, CompletionHandler<void(SharedMemory::IPCHandle&&)>&& completionHandler)
+void WebPasteboardProxy::readBufferFromPasteboard(IPC::Connection&, std::optional<size_t>, const String&, const String&, std::optional<WebCore::PageIdentifier>, CompletionHandler<void(RefPtr<WebCore::SharedBuffer>&&)>&& completionHandler)
 {
     completionHandler({ });
 }

Modified: trunk/Source/WebKit/UIProcess/WebPasteboardProxy.h (295336 => 295337)


--- trunk/Source/WebKit/UIProcess/WebPasteboardProxy.h	2022-06-07 09:36:12 UTC (rev 295336)
+++ trunk/Source/WebKit/UIProcess/WebPasteboardProxy.h	2022-06-07 11:00:50 UTC (rev 295337)
@@ -45,6 +45,7 @@
 struct PasteboardItemInfo;
 struct PasteboardURL;
 struct PasteboardWebContent;
+class SharedBuffer;
 }
 
 namespace WebKit {
@@ -95,7 +96,7 @@
     void getPasteboardPathnamesForType(IPC::Connection&, const String& pasteboardName, const String& pasteboardType, std::optional<WebCore::PageIdentifier>, CompletionHandler<void(Vector<String>&& pathnames, Vector<SandboxExtension::Handle>&&)>&&);
     void getPasteboardStringForType(IPC::Connection&, const String& pasteboardName, const String& pasteboardType, std::optional<WebCore::PageIdentifier>, CompletionHandler<void(String&&)>&&);
     void getPasteboardStringsForType(IPC::Connection&, const String& pasteboardName, const String& pasteboardType, std::optional<WebCore::PageIdentifier>, CompletionHandler<void(Vector<String>&&)>&&);
-    void getPasteboardBufferForType(IPC::Connection&, const String& pasteboardName, const String& pasteboardType, std::optional<WebCore::PageIdentifier>, CompletionHandler<void(SharedMemory::IPCHandle&&)>&&);
+    void getPasteboardBufferForType(IPC::Connection&, const String& pasteboardName, const String& pasteboardType, std::optional<WebCore::PageIdentifier>, CompletionHandler<void(RefPtr<WebCore::SharedBuffer>&&)>&&);
     void getPasteboardChangeCount(IPC::Connection&, const String& pasteboardName, std::optional<WebCore::PageIdentifier>, CompletionHandler<void(int64_t)>&&);
     void getPasteboardColor(IPC::Connection&, const String& pasteboardName, std::optional<WebCore::PageIdentifier>, CompletionHandler<void(WebCore::Color&&)>&&);
     void getPasteboardURL(IPC::Connection&, const String& pasteboardName, std::optional<WebCore::PageIdentifier>, CompletionHandler<void(const String&)>&&);
@@ -104,12 +105,12 @@
     void setPasteboardURL(IPC::Connection&, const WebCore::PasteboardURL&, const String& pasteboardName, std::optional<WebCore::PageIdentifier>, CompletionHandler<void(int64_t)>&&);
     void setPasteboardColor(IPC::Connection&, const String&, const WebCore::Color&, std::optional<WebCore::PageIdentifier>, CompletionHandler<void(int64_t)>&&);
     void setPasteboardStringForType(IPC::Connection&, const String& pasteboardName, const String& pasteboardType, const String&, std::optional<WebCore::PageIdentifier>, CompletionHandler<void(int64_t)>&&);
-    void setPasteboardBufferForType(IPC::Connection&, const String& pasteboardName, const String& pasteboardType, const SharedMemory::IPCHandle&, std::optional<WebCore::PageIdentifier>, CompletionHandler<void(int64_t)>&&);
+    void setPasteboardBufferForType(IPC::Connection&, const String& pasteboardName, const String& pasteboardType, RefPtr<WebCore::SharedBuffer>&&, std::optional<WebCore::PageIdentifier>, CompletionHandler<void(int64_t)>&&);
 #endif
 
     void readStringFromPasteboard(IPC::Connection&, size_t index, const String& pasteboardType, const String& pasteboardName, std::optional<WebCore::PageIdentifier>, CompletionHandler<void(String&&)>&&);
     void readURLFromPasteboard(IPC::Connection&, size_t index, const String& pasteboardName, std::optional<WebCore::PageIdentifier>, CompletionHandler<void(String&& url, String&& title)>&&);
-    void readBufferFromPasteboard(IPC::Connection&, std::optional<size_t> index, const String& pasteboardType, const String& pasteboardName, std::optional<WebCore::PageIdentifier>, CompletionHandler<void(SharedMemory::IPCHandle&&)>&&);
+    void readBufferFromPasteboard(IPC::Connection&, std::optional<size_t> index, const String& pasteboardType, const String& pasteboardName, std::optional<WebCore::PageIdentifier>, CompletionHandler<void(RefPtr<WebCore::SharedBuffer>&&)>&&);
     void getPasteboardItemsCount(IPC::Connection&, const String& pasteboardName, std::optional<WebCore::PageIdentifier>, CompletionHandler<void(uint64_t)>&&);
     void informationForItemAtIndex(IPC::Connection&, size_t index, const String& pasteboardName, int64_t changeCount, std::optional<WebCore::PageIdentifier>, CompletionHandler<void(std::optional<WebCore::PasteboardItemInfo>&&)>&&);
     void allPasteboardItemInfo(IPC::Connection&, const String& pasteboardName, int64_t changeCount, std::optional<WebCore::PageIdentifier>, CompletionHandler<void(std::optional<Vector<WebCore::PasteboardItemInfo>>&&)>&&);
@@ -124,7 +125,7 @@
     void getTypes(const String& pasteboardName, CompletionHandler<void(Vector<String>&&)>&&);
     void readText(const String& pasteboardName, CompletionHandler<void(String&&)>&&);
     void readFilePaths(const String& pasteboardName, CompletionHandler<void(Vector<String>&&)>&&);
-    void readBuffer(const String& pasteboardName, const String& pasteboardType, CompletionHandler<void(IPC::SharedBufferReference&&)>&&);
+    void readBuffer(const String& pasteboardName, const String& pasteboardType, CompletionHandler<void(RefPtr<WebCore::SharedBuffer>&&)>&&);
     void writeToClipboard(const String& pasteboardName, WebCore::SelectionData&&);
     void clearClipboard(const String& pasteboardName);
 

Modified: trunk/Source/WebKit/UIProcess/WebPasteboardProxy.messages.in (295336 => 295337)


--- trunk/Source/WebKit/UIProcess/WebPasteboardProxy.messages.in	2022-06-07 09:36:12 UTC (rev 295336)
+++ trunk/Source/WebKit/UIProcess/WebPasteboardProxy.messages.in	2022-06-07 11:00:50 UTC (rev 295337)
@@ -36,7 +36,7 @@
     GetPasteboardItemsCount(String pasteboardName, std::optional<WebCore::PageIdentifier> pageID) -> (uint64_t itemsCount) Synchronous WantsConnection
     ReadStringFromPasteboard(uint64_t index, String pasteboardType, String pasteboardName, std::optional<WebCore::PageIdentifier> pageID) -> (String string) Synchronous WantsConnection
     ReadURLFromPasteboard(uint64_t index, String pasteboardName, std::optional<WebCore::PageIdentifier> pageID) -> (String url, String title) Synchronous WantsConnection
-    ReadBufferFromPasteboard(std::optional<uint64_t> index, String pasteboardType, String pasteboardName, std::optional<WebCore::PageIdentifier> pageID) -> (WebKit::SharedMemory::IPCHandle handle) Synchronous WantsConnection
+    ReadBufferFromPasteboard(std::optional<uint64_t> index, String pasteboardType, String pasteboardName, std::optional<WebCore::PageIdentifier> pageID) -> (RefPtr<WebCore::SharedBuffer> buffer) Synchronous WantsConnection
     ContainsStringSafeForDOMToReadForType(String type, String pasteboardName, std::optional<WebCore::PageIdentifier> pageID) -> (bool result) Synchronous WantsConnection
 
 #if PLATFORM(COCOA)
@@ -46,7 +46,7 @@
     GetPasteboardPathnamesForType(String pasteboardName, String pasteboardType, std::optional<WebCore::PageIdentifier> pageID) -> (Vector<String> pathnames, Vector<WebKit::SandboxExtension::Handle> sandboxExtensions) Synchronous WantsConnection
     GetPasteboardStringForType(String pasteboardName, String pasteboardType, std::optional<WebCore::PageIdentifier> pageID) -> (String string) Synchronous WantsConnection
     GetPasteboardStringsForType(String pasteboardName, String pasteboardType, std::optional<WebCore::PageIdentifier> pageID) -> (Vector<String> strings) Synchronous WantsConnection
-    GetPasteboardBufferForType(String pasteboardName, String pasteboardType, std::optional<WebCore::PageIdentifier> pageID) -> (WebKit::SharedMemory::IPCHandle handle) Synchronous WantsConnection
+    GetPasteboardBufferForType(String pasteboardName, String pasteboardType, std::optional<WebCore::PageIdentifier> pageID) -> (RefPtr<WebCore::SharedBuffer> buffer) Synchronous WantsConnection
     GetPasteboardChangeCount(String pasteboardName, std::optional<WebCore::PageIdentifier> pageID) -> (int64_t changeCount) Synchronous WantsConnection
     GetPasteboardColor(String pasteboardName, std::optional<WebCore::PageIdentifier> pageID) -> (WebCore::Color color) Synchronous WantsConnection
     GetPasteboardURL(String pasteboardName, std::optional<WebCore::PageIdentifier> pageID) -> (String urlString) Synchronous WantsConnection
@@ -55,7 +55,7 @@
     SetPasteboardURL(struct WebCore::PasteboardURL pasteboardURL, String pasteboardName, std::optional<WebCore::PageIdentifier> pageID) -> (int64_t changeCount) Synchronous WantsConnection
     SetPasteboardColor(String pasteboardName, WebCore::Color color, std::optional<WebCore::PageIdentifier> pageID) -> (int64_t changeCount) Synchronous WantsConnection
     SetPasteboardStringForType(String pasteboardName, String pasteboardType, String string, std::optional<WebCore::PageIdentifier> pageID) -> (int64_t changeCount) Synchronous WantsConnection
-    SetPasteboardBufferForType(String pasteboardName, String pasteboardType, WebKit::SharedMemory::IPCHandle handle, std::optional<WebCore::PageIdentifier> pageID) -> (int64_t changeCount) Synchronous WantsConnection
+    SetPasteboardBufferForType(String pasteboardName, String pasteboardType, RefPtr<WebCore::SharedBuffer> buffer, std::optional<WebCore::PageIdentifier> pageID) -> (int64_t changeCount) Synchronous WantsConnection
     ContainsURLStringSuitableForLoading(String pasteboardName, std::optional<WebCore::PageIdentifier> pageID) -> (bool result) Synchronous WantsConnection
     URLStringSuitableForLoading(String pasteboardName, std::optional<WebCore::PageIdentifier> pageID) -> (String url, String title) Synchronous WantsConnection
 #endif
@@ -64,7 +64,7 @@
     GetTypes(String pasteboardName) -> (Vector<String> types) Synchronous
     ReadText(String pasteboardName) -> (String text) Synchronous
     ReadFilePaths(String pasteboardName) -> (Vector<String> types) Synchronous
-    ReadBuffer(String pasteboardName, String pasteboardType) -> (IPC::SharedBufferReference data) Synchronous
+    ReadBuffer(String pasteboardName, String pasteboardType) -> (RefPtr<WebCore::SharedBuffer> buffer) Synchronous
     WriteToClipboard(String pasteboardName, WebCore::SelectionData pasteboardContent)
     ClearClipboard(String pasteboardName)
 #endif

Modified: trunk/Source/WebKit/UIProcess/gtk/WebPasteboardProxyGtk.cpp (295336 => 295337)


--- trunk/Source/WebKit/UIProcess/gtk/WebPasteboardProxyGtk.cpp	2022-06-07 09:36:12 UTC (rev 295336)
+++ trunk/Source/WebKit/UIProcess/gtk/WebPasteboardProxyGtk.cpp	2022-06-07 11:00:50 UTC (rev 295337)
@@ -55,10 +55,10 @@
     Clipboard::get(pasteboardName).readFilePaths(WTFMove(completionHandler));
 }
 
-void WebPasteboardProxy::readBuffer(const String& pasteboardName, const String& pasteboardType, CompletionHandler<void(IPC::SharedBufferReference&&)>&& completionHandler)
+void WebPasteboardProxy::readBuffer(const String& pasteboardName, const String& pasteboardType, CompletionHandler<void(RefPtr<SharedBuffer>&&)>&& completionHandler)
 {
     Clipboard::get(pasteboardName).readBuffer(pasteboardType.utf8().data(), [completionHandler = WTFMove(completionHandler)](auto&& buffer) mutable {
-        completionHandler(IPC::SharedBufferReference(WTFMove(buffer)));
+        completionHandler(WTFMove(buffer));
     });
 }
 

Modified: trunk/Source/WebKit/UIProcess/ios/WKContentView.mm (295336 => 295337)


--- trunk/Source/WebKit/UIProcess/ios/WKContentView.mm	2022-06-07 09:36:12 UTC (rev 295336)
+++ trunk/Source/WebKit/UIProcess/ios/WKContentView.mm	2022-06-07 11:00:50 UTC (rev 295337)
@@ -931,11 +931,11 @@
         _pdfPrintCompletionSemaphore = makeUnique<BinarySemaphore>();
 
     // Begin generating the PDF in expectation of a (eventual) request for the drawn data.
-    _pdfPrintCallbackID = _page->drawToPDFiOS(frameID, printInfo, pageCount, [retainedSelf = retainPtr(self)](const IPC::SharedBufferReference& pdfData) {
-        if (pdfData.isEmpty())
+    _pdfPrintCallbackID = _page->drawToPDFiOS(frameID, printInfo, pageCount, [retainedSelf = retainPtr(self)](RefPtr<WebCore::SharedBuffer>&& pdfData) {
+        if (!pdfData || pdfData->isEmpty())
             retainedSelf->_printedDocument = nullptr;
         else {
-            auto data = ""
+            auto data = ""
             auto dataProvider = adoptCF(CGDataProviderCreateWithCFData(data.get()));
             retainedSelf->_printedDocument = adoptCF(CGPDFDocumentCreateWithProvider(dataProvider.get()));
         }

Modified: trunk/Source/WebKit/UIProcess/ios/WebPageProxyIOS.mm (295336 => 295337)


--- trunk/Source/WebKit/UIProcess/ios/WebPageProxyIOS.mm	2022-06-07 09:36:12 UTC (rev 295336)
+++ trunk/Source/WebKit/UIProcess/ios/WebPageProxyIOS.mm	2022-06-07 11:00:50 UTC (rev 295337)
@@ -1058,7 +1058,7 @@
     return pageCount;
 }
 
-uint64_t WebPageProxy::drawToPDFiOS(FrameIdentifier frameID, const PrintInfo& printInfo, size_t pageCount, CompletionHandler<void(const IPC::SharedBufferReference&)>&& completionHandler)
+uint64_t WebPageProxy::drawToPDFiOS(FrameIdentifier frameID, const PrintInfo& printInfo, size_t pageCount, CompletionHandler<void(RefPtr<WebCore::SharedBuffer>&&)>&& completionHandler)
 {
     if (!hasRunningProcess()) {
         completionHandler({ });

Modified: trunk/Source/WebKit/UIProcess/mac/WebPageProxyMac.mm (295336 => 295337)


--- trunk/Source/WebKit/UIProcess/mac/WebPageProxyMac.mm	2022-06-07 09:36:12 UTC (rev 295336)
+++ trunk/Source/WebKit/UIProcess/mac/WebPageProxyMac.mm	2022-06-07 11:00:50 UTC (rev 295337)
@@ -224,15 +224,10 @@
     if (!hasRunningProcess())
         return nullptr;
 
-    SharedMemory::IPCHandle ipcHandle;
+    RefPtr<WebCore::SharedBuffer> buffer;
     const Seconds messageTimeout(20);
-    sendSync(Messages::WebPage::GetDataSelectionForPasteboard(pasteboardType), Messages::WebPage::GetDataSelectionForPasteboard::Reply(ipcHandle), messageTimeout);
-    MESSAGE_CHECK_WITH_RETURN_VALUE(!ipcHandle.handle.isNull(), nullptr);
-
-    auto sharedMemoryBuffer = SharedMemory::map(ipcHandle.handle, SharedMemory::Protection::ReadOnly);
-    if (!sharedMemoryBuffer)
-        return nullptr;
-    return sharedMemoryBuffer->createSharedBuffer(ipcHandle.dataSize);
+    sendSync(Messages::WebPage::GetDataSelectionForPasteboard(pasteboardType), Messages::WebPage::GetDataSelectionForPasteboard::Reply(buffer), messageTimeout);
+    return buffer;
 }
 
 bool WebPageProxy::readSelectionFromPasteboard(const String& pasteboardName)

Modified: trunk/Source/WebKit/WebProcess/Plugins/PDF/PDFPlugin.mm (295336 => 295337)


--- trunk/Source/WebKit/WebProcess/Plugins/PDF/PDFPlugin.mm	2022-06-07 09:36:12 UTC (rev 295336)
+++ trunk/Source/WebKit/WebProcess/Plugins/PDF/PDFPlugin.mm	2022-06-07 11:00:50 UTC (rev 295337)
@@ -2567,15 +2567,8 @@
             auto plainTextString = adoptNS([[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]);
             webProcess.parentProcessConnection()->sendSync(Messages::WebPasteboardProxy::SetPasteboardStringForType(pasteboardName, type, plainTextString.get(), pageIdentifier), Messages::WebPasteboardProxy::SetPasteboardStringForType::Reply(newChangeCount), 0);
         } else {
-            SharedMemory::Handle handle;
             auto buffer = SharedBuffer::create(data);
-            {
-                auto sharedMemory = SharedMemory::copyBuffer(buffer.get());
-                if (!sharedMemory)
-                    continue;
-                sharedMemory->createHandle(handle, SharedMemory::Protection::ReadOnly);
-            }
-            webProcess.parentProcessConnection()->sendSync(Messages::WebPasteboardProxy::SetPasteboardBufferForType(pasteboardName, type, SharedMemory::IPCHandle { WTFMove(handle), buffer->size() }, pageIdentifier), Messages::WebPasteboardProxy::SetPasteboardBufferForType::Reply(newChangeCount), 0);
+            webProcess.parentProcessConnection()->sendSync(Messages::WebPasteboardProxy::SetPasteboardBufferForType(pasteboardName, type, WTFMove(buffer), pageIdentifier), Messages::WebPasteboardProxy::SetPasteboardBufferForType::Reply(newChangeCount), 0);
         }
     }
 }

Modified: trunk/Source/WebKit/WebProcess/WebCoreSupport/WebPlatformStrategies.cpp (295336 => 295337)


--- trunk/Source/WebKit/WebProcess/WebCoreSupport/WebPlatformStrategies.cpp	2022-06-07 09:36:12 UTC (rev 295336)
+++ trunk/Source/WebKit/WebProcess/WebCoreSupport/WebPlatformStrategies.cpp	2022-06-07 11:00:50 UTC (rev 295337)
@@ -140,14 +140,9 @@
         return SharedBuffer::create(WTFMove(overrideBuffer));
 
     // Fallback to messaging the UI process for native pasteboard content.
-    SharedMemory::IPCHandle ipcHandle;
-    WebProcess::singleton().parentProcessConnection()->sendSync(Messages::WebPasteboardProxy::GetPasteboardBufferForType(pasteboardName, pasteboardType, pageIdentifier(context)), Messages::WebPasteboardProxy::GetPasteboardBufferForType::Reply(ipcHandle), 0);
-    if (ipcHandle.handle.isNull())
-        return nullptr;
-    RefPtr<SharedMemory> sharedMemoryBuffer = SharedMemory::map(ipcHandle.handle, SharedMemory::Protection::ReadOnly);
-    if (!sharedMemoryBuffer)
-        return nullptr;
-    return sharedMemoryBuffer->createSharedBuffer(ipcHandle.dataSize);
+    RefPtr<WebCore::SharedBuffer> buffer;
+    WebProcess::singleton().parentProcessConnection()->sendSync(Messages::WebPasteboardProxy::GetPasteboardBufferForType(pasteboardName, pasteboardType, pageIdentifier(context)), Messages::WebPasteboardProxy::GetPasteboardBufferForType::Reply(buffer), 0);
+    return buffer;
 }
 
 void WebPlatformStrategies::getPathnamesForType(Vector<String>& pathnames, const String& pasteboardType, const String& pasteboardName, const PasteboardContext* context)
@@ -212,15 +207,10 @@
 int64_t WebPlatformStrategies::setBufferForType(SharedBuffer* buffer, const String& pasteboardType, const String& pasteboardName, const PasteboardContext* context)
 {
     SharedMemory::Handle handle;
-    if (buffer && buffer->size()) {
-        auto sharedMemoryBuffer = SharedMemory::copyBuffer(*buffer);
-        // FIXME: Null check prevents crashing, but it is not great that we will have empty pasteboard content for this type,
-        // because we've already set the types.
-        if (sharedMemoryBuffer)
-            sharedMemoryBuffer->createHandle(handle, SharedMemory::Protection::ReadOnly);
-    }
+    // FIXME: Null check prevents crashing, but it is not great that we will have empty pasteboard content for this type,
+    // because we've already set the types.
     int64_t newChangeCount { 0 };
-    WebProcess::singleton().parentProcessConnection()->sendSync(Messages::WebPasteboardProxy::SetPasteboardBufferForType(pasteboardName, pasteboardType, SharedMemory::IPCHandle { WTFMove(handle), buffer ? buffer->size() : 0 }, pageIdentifier(context)), Messages::WebPasteboardProxy::SetPasteboardBufferForType::Reply(newChangeCount), 0);
+    WebProcess::singleton().parentProcessConnection()->sendSync(Messages::WebPasteboardProxy::SetPasteboardBufferForType(pasteboardName, pasteboardType, buffer ? RefPtr { buffer } : SharedBuffer::create(), pageIdentifier(context)), Messages::WebPasteboardProxy::SetPasteboardBufferForType::Reply(newChangeCount), 0);
     return newChangeCount;
 }
 
@@ -326,10 +316,9 @@
 
 RefPtr<SharedBuffer> WebPlatformStrategies::readBufferFromClipboard(const String& pasteboardName, const String& pasteboardType)
 {
-
-    IPC::SharedBufferReference data;
-    WebProcess::singleton().parentProcessConnection()->sendSync(Messages::WebPasteboardProxy::ReadBuffer(pasteboardName, pasteboardType), Messages::WebPasteboardProxy::ReadBuffer::Reply(data), 0);
-    return data.unsafeBuffer();
+    RefPtr<SharedBuffer> buffer;
+    WebProcess::singleton().parentProcessConnection()->sendSync(Messages::WebPasteboardProxy::ReadBuffer(pasteboardName, pasteboardType), Messages::WebPasteboardProxy::ReadBuffer::Reply(buffer), 0);
+    return buffer;
 }
 
 void WebPlatformStrategies::writeToClipboard(const String& pasteboardName, SelectionData&& selectionData)
@@ -423,15 +412,9 @@
     if (WebPasteboardOverrides::sharedPasteboardOverrides().getDataForOverride(pasteboardName, pasteboardType, overrideBuffer))
         return SharedBuffer::create(WTFMove(overrideBuffer));
 
-    SharedMemory::IPCHandle ipcHandle;
-    WebProcess::singleton().parentProcessConnection()->sendSync(Messages::WebPasteboardProxy::ReadBufferFromPasteboard(index, pasteboardType, pasteboardName, pageIdentifier(context)), Messages::WebPasteboardProxy::ReadBufferFromPasteboard::Reply(ipcHandle), 0);
-    if (ipcHandle.handle.isNull())
-        return nullptr;
-
-    RefPtr<SharedMemory> sharedMemoryBuffer = SharedMemory::map(ipcHandle.handle, SharedMemory::Protection::ReadOnly);
-    if (!sharedMemoryBuffer)
-        return nullptr;
-    return sharedMemoryBuffer->createSharedBuffer(ipcHandle.dataSize);
+    RefPtr<WebCore::SharedBuffer> buffer;
+    WebProcess::singleton().parentProcessConnection()->sendSync(Messages::WebPasteboardProxy::ReadBufferFromPasteboard(index, pasteboardType, pasteboardName, pageIdentifier(context)), Messages::WebPasteboardProxy::ReadBufferFromPasteboard::Reply(buffer), 0);
+    return buffer;
 }
 
 URL WebPlatformStrategies::readURLFromPasteboard(size_t index, const String& pasteboardName, String& title, const PasteboardContext* context)

Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp (295336 => 295337)


--- trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp	2022-06-07 09:36:12 UTC (rev 295336)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp	2022-06-07 11:00:50 UTC (rev 295337)
@@ -5631,7 +5631,7 @@
 }
 
 #if PLATFORM(COCOA)
-void WebPage::drawToPDF(FrameIdentifier frameID, const std::optional<FloatRect>& rect, CompletionHandler<void(const IPC::SharedBufferReference&)>&& completionHandler)
+void WebPage::drawToPDF(FrameIdentifier frameID, const std::optional<FloatRect>& rect, CompletionHandler<void(RefPtr<WebCore::SharedBuffer>&&)>&& completionHandler)
 {
     auto& frameView = *m_page->mainFrame().view();
     IntSize snapshotSize;
@@ -5656,7 +5656,7 @@
     frameView.setLayoutViewportOverrideRect(originalLayoutViewportOverrideRect);
     frameView.setPaintBehavior(originalPaintBehavior);
 
-    completionHandler(IPC::SharedBufferReference(SharedBuffer::create(pdfData.get())));
+    completionHandler(SharedBuffer::create(pdfData.get()));
 }
 
 void WebPage::drawRectToImage(FrameIdentifier frameID, const PrintInfo& printInfo, const IntRect& rect, const WebCore::IntSize& imageSize, CompletionHandler<void(const WebKit::ShareableBitmap::Handle&)>&& completionHandler)
@@ -5706,12 +5706,12 @@
     completionHandler(handle);
 }
 
-void WebPage::drawPagesToPDF(FrameIdentifier frameID, const PrintInfo& printInfo, uint32_t first, uint32_t count, CompletionHandler<void(const IPC::SharedBufferReference&)>&& callback)
+void WebPage::drawPagesToPDF(FrameIdentifier frameID, const PrintInfo& printInfo, uint32_t first, uint32_t count, CompletionHandler<void(RefPtr<WebCore::SharedBuffer>&&)>&& callback)
 {
     PrintContextAccessScope scope { *this };
     RetainPtr<CFMutableDataRef> pdfPageData;
     drawPagesToPDFImpl(frameID, printInfo, first, count, pdfPageData);
-    callback(IPC::SharedBufferReference(SharedBuffer::create(pdfPageData.get())));
+    callback(SharedBuffer::create(pdfPageData.get()));
 }
 
 void WebPage::drawPagesToPDFImpl(FrameIdentifier frameID, const PrintInfo& printInfo, uint32_t first, uint32_t count, RetainPtr<CFMutableDataRef>& pdfPageData)

Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPage.h (295336 => 295337)


--- trunk/Source/WebKit/WebProcess/WebPage/WebPage.h	2022-06-07 09:36:12 UTC (rev 295336)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPage.h	2022-06-07 11:00:50 UTC (rev 295337)
@@ -216,6 +216,7 @@
 class ResourceResponse;
 class SelectionData;
 class SelectionGeometry;
+class SharedBuffer;
 class FragmentedSharedBuffer;
 class SubstituteData;
 class TextCheckingRequest;
@@ -966,7 +967,7 @@
 
     void readSelectionFromPasteboard(const String& pasteboardName, CompletionHandler<void(bool&&)>&&);
     void getStringSelectionForPasteboard(CompletionHandler<void(String&&)>&&);
-    void getDataSelectionForPasteboard(const String pasteboardType, CompletionHandler<void(SharedMemory::IPCHandle&&)>&&);
+    void getDataSelectionForPasteboard(const String pasteboardType, CompletionHandler<void(RefPtr<WebCore::SharedBuffer>&&)>&&);
     void shouldDelayWindowOrderingEvent(const WebKit::WebMouseEvent&, CompletionHandler<void(bool)>&&);
     bool performNonEditingBehaviorForSelector(const String&, WebCore::KeyboardEvent*);
 
@@ -1040,7 +1041,7 @@
 
 #if PLATFORM(COCOA)
     void drawRectToImage(WebCore::FrameIdentifier, const PrintInfo&, const WebCore::IntRect&, const WebCore::IntSize&, CompletionHandler<void(const WebKit::ShareableBitmap::Handle&)>&&);
-    void drawPagesToPDF(WebCore::FrameIdentifier, const PrintInfo&, uint32_t first, uint32_t count, CompletionHandler<void(const IPC::SharedBufferReference&)>&&);
+    void drawPagesToPDF(WebCore::FrameIdentifier, const PrintInfo&, uint32_t first, uint32_t count, CompletionHandler<void(RefPtr<WebCore::SharedBuffer>&&)>&&);
     void drawPagesToPDFImpl(WebCore::FrameIdentifier, const PrintInfo&, uint32_t first, uint32_t count, RetainPtr<CFMutableDataRef>& pdfPageData);
 #endif
 
@@ -1049,7 +1050,7 @@
     void drawToPDFiOS(WebCore::FrameIdentifier, const PrintInfo&, size_t, Messages::WebPage::DrawToPDFiOSAsyncReply&&);
 #endif
 
-    void drawToPDF(WebCore::FrameIdentifier, const std::optional<WebCore::FloatRect>&, CompletionHandler<void(const IPC::SharedBufferReference&)>&&);
+    void drawToPDF(WebCore::FrameIdentifier, const std::optional<WebCore::FloatRect>&, CompletionHandler<void(RefPtr<WebCore::SharedBuffer>&&)>&&);
 
 #if PLATFORM(GTK)
     void drawPagesForPrinting(WebCore::FrameIdentifier, const PrintInfo&, CompletionHandler<void(const WebCore::ResourceError&)>&&);

Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPage.messages.in (295336 => 295337)


--- trunk/Source/WebKit/WebProcess/WebPage/WebPage.messages.in	2022-06-07 09:36:12 UTC (rev 295336)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPage.messages.in	2022-06-07 11:00:50 UTC (rev 295337)
@@ -437,12 +437,12 @@
     ComputePagesForPrinting(WebCore::FrameIdentifier frameID, struct WebKit::PrintInfo printInfo) -> (Vector<WebCore::IntRect> pageRects, double totalScaleFactorForPrinting, WebCore::RectEdges<float> computedPageMargin)
 #if PLATFORM(COCOA)
     DrawRectToImage(WebCore::FrameIdentifier frameID, struct WebKit::PrintInfo printInfo, WebCore::IntRect rect, WebCore::IntSize imageSize) -> (WebKit::ShareableBitmap::Handle image)
-    DrawPagesToPDF(WebCore::FrameIdentifier frameID, struct WebKit::PrintInfo printInfo, uint32_t first, uint32_t count) -> (IPC::SharedBufferReference data)
+    DrawPagesToPDF(WebCore::FrameIdentifier frameID, struct WebKit::PrintInfo printInfo, uint32_t first, uint32_t count) -> (RefPtr<WebCore::SharedBuffer> data)
 #if PLATFORM(IOS_FAMILY)
     ComputePagesForPrintingiOS(WebCore::FrameIdentifier frameID, struct WebKit::PrintInfo printInfo) -> (size_t pageCount) Synchronous
-    DrawToPDFiOS(WebCore::FrameIdentifier frameID, struct WebKit::PrintInfo printInfo, size_t pageCount) -> (IPC::SharedBufferReference data)
+    DrawToPDFiOS(WebCore::FrameIdentifier frameID, struct WebKit::PrintInfo printInfo, size_t pageCount) -> (RefPtr<WebCore::SharedBuffer> data)
 #endif
-    DrawToPDF(WebCore::FrameIdentifier frameID, std::optional<WebCore::FloatRect> rect) -> (IPC::SharedBufferReference data)
+    DrawToPDF(WebCore::FrameIdentifier frameID, std::optional<WebCore::FloatRect> rect) -> (RefPtr<WebCore::SharedBuffer> data)
 #endif
 #if PLATFORM(GTK)
     DrawPagesForPrinting(WebCore::FrameIdentifier frameID, struct WebKit::PrintInfo printInfo) -> (WebCore::ResourceError error)
@@ -471,7 +471,7 @@
     SetMainFrameIsScrollable(bool isScrollable)
     RegisterUIProcessAccessibilityTokens(IPC::DataReference elemenToken, IPC::DataReference windowToken)
     GetStringSelectionForPasteboard() -> (String stringValue) Synchronous
-    GetDataSelectionForPasteboard(String pasteboardType) -> (WebKit::SharedMemory::IPCHandle ipcHandle) Synchronous
+    GetDataSelectionForPasteboard(String pasteboardType) -> (RefPtr<WebCore::SharedBuffer> buffer) Synchronous
     ReadSelectionFromPasteboard(String pasteboardName) -> (bool result) Synchronous
     ReplaceSelectionWithPasteboardData(Vector<String> types, IPC::DataReference data)
 

Modified: trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm (295336 => 295337)


--- trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm	2022-06-07 09:36:12 UTC (rev 295336)
+++ trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm	2022-06-07 11:00:50 UTC (rev 295337)
@@ -620,7 +620,7 @@
     completionHandler({ });
 }
 
-void WebPage::getDataSelectionForPasteboard(const String, CompletionHandler<void(SharedMemory::IPCHandle&&)>&& completionHandler)
+void WebPage::getDataSelectionForPasteboard(const String, CompletionHandler<void(RefPtr<SharedBuffer>&&)>&& completionHandler)
 {
     notImplemented();
     completionHandler({ });
@@ -4372,13 +4372,13 @@
         auto pdfData = pdfSnapshotAtSize(snapshotRect, snapshotSize, 0);
 
         frameView.setLayoutViewportOverrideRect(originalLayoutViewportOverrideRect);
-        reply(IPC::SharedBufferReference(SharedBuffer::create(pdfData.get())));
+        reply(SharedBuffer::create(pdfData.get()));
         return;
     }
 
     RetainPtr<CFMutableDataRef> pdfPageData;
     drawPagesToPDFImpl(frameID, printInfo, 0, pageCount, pdfPageData);
-    reply(IPC::SharedBufferReference(SharedBuffer::create(pdfPageData.get())));
+    reply(SharedBuffer::create(pdfPageData.get()));
 
     endPrinting();
 }

Modified: trunk/Source/WebKit/WebProcess/WebPage/mac/WebPageMac.mm (295336 => 295337)


--- trunk/Source/WebKit/WebProcess/WebPage/mac/WebPageMac.mm	2022-06-07 09:36:12 UTC (rev 295336)
+++ trunk/Source/WebKit/WebProcess/WebPage/mac/WebPageMac.mm	2022-06-07 11:00:50 UTC (rev 295337)
@@ -500,7 +500,7 @@
     completionHandler(frame.editor().stringSelectionForPasteboard());
 }
 
-void WebPage::getDataSelectionForPasteboard(const String pasteboardType, CompletionHandler<void(SharedMemory::IPCHandle&&)>&& completionHandler)
+void WebPage::getDataSelectionForPasteboard(const String pasteboardType, CompletionHandler<void(RefPtr<SharedBuffer>&&)>&& completionHandler)
 {
     auto& frame = m_page->focusController().focusedOrMainFrame();
     if (frame.selection().isNone())
@@ -509,14 +509,7 @@
     auto buffer = frame.editor().dataSelectionForPasteboard(pasteboardType);
     if (!buffer)
         return completionHandler({ });
-    SharedMemory::Handle handle;
-    {
-        auto sharedMemoryBuffer = SharedMemory::copyBuffer(*buffer);
-        if (!sharedMemoryBuffer)
-            return completionHandler({ });
-        sharedMemoryBuffer->createHandle(handle, SharedMemory::Protection::ReadOnly);
-    }
-    completionHandler(SharedMemory::IPCHandle { WTFMove(handle), buffer->size() });
+    completionHandler(buffer.releaseNonNull());
 }
 
 WKAccessibilityWebPageObject* WebPage::accessibilityRemoteObject()
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to