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

Changeset 265702 in webkit


Ignore:
Timestamp:
Aug 14, 2020, 1:41:11 PM (6 years ago)
Author:
Kate Cheney
Message:

Convert SharedMemory::Handle to SharedMemory::IPCHandle WebPage image/pasteboard functions
https://bugs.webkit.org/show_bug.cgi?id=215478
<rdar://problem/67024582>

Reviewed by Chris Dumez.

Convert SharedMemory::Handle objects to SharedMemory::IPCHandle
objects which automatically verify the size of data being sent.

We can remove the additional size parameter being sent in many IPC
messages along with the handle, now that both are stored in the
IPCHandle struct.

  • UIProcess/Cocoa/WebPageProxyCocoa.mm:

(WebKit::WebPageProxy::setPromisedDataForImage):

  • UIProcess/Cocoa/WebPasteboardProxyCocoa.mm:

(WebKit::WebPasteboardProxy::getPasteboardBufferForType):
No longer need size check, this is done in the IPCHandle::decode()
function.
(WebKit::WebPasteboardProxy::setPasteboardBufferForType):
(WebKit::WebPasteboardProxy::readBufferFromPasteboard):

  • UIProcess/WebPageProxy.h:
  • UIProcess/WebPageProxy.messages.in:
  • UIProcess/WebPasteboardProxy.cpp:

(WebKit::WebPasteboardProxy::readBufferFromPasteboard):

  • UIProcess/WebPasteboardProxy.h:
  • UIProcess/WebPasteboardProxy.messages.in:
  • UIProcess/ios/WebPageProxyIOS.mm:

(WebKit::WebPageProxy::saveImageToLibrary):

  • UIProcess/mac/WebPageProxyMac.mm:

(WebKit::WebPageProxy::dataSelectionForPasteboard):
No longer need size check, this is done in the IPCHandle::decode()
function.
(WebKit::WebPageProxy::setPromisedDataForImage):

  • WebProcess/Plugins/PDF/PDFPlugin.mm:

(WebKit::PDFPlugin::writeItemsToPasteboard):

  • WebProcess/WebCoreSupport/WebPlatformStrategies.cpp:

(WebKit::WebPlatformStrategies::bufferForType):
(WebKit::WebPlatformStrategies::setBufferForType):
(WebKit::WebPlatformStrategies::readBufferFromPasteboard):
No longer need size check, this is done in the IPCHandle::decode()
function.

  • WebProcess/WebCoreSupport/mac/WebDragClientMac.mm:

(WebKit::WebDragClient::declareAndWriteDragImage):

  • WebProcess/WebPage/WebPage.h:
  • WebProcess/WebPage/WebPage.messages.in:
  • WebProcess/WebPage/ios/WebPageIOS.mm:

(WebKit::WebPage::getDataSelectionForPasteboard):
(WebKit::WebPage::performActionOnElement):

  • WebProcess/WebPage/mac/WebPageMac.mm:

(WebKit::WebPage::getDataSelectionForPasteboard):

Location:
trunk/Source/WebKit
Files:
17 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r265688 r265702  
     12020-08-14  Kate Cheney  <katherine_cheney@apple.com>
     2
     3        Convert SharedMemory::Handle to SharedMemory::IPCHandle WebPage image/pasteboard functions
     4        https://bugs.webkit.org/show_bug.cgi?id=215478
     5        <rdar://problem/67024582>
     6
     7        Reviewed by Chris Dumez.
     8
     9        Convert SharedMemory::Handle objects to SharedMemory::IPCHandle
     10        objects which automatically verify the size of data being sent.
     11
     12        We can remove the additional size parameter being sent in many IPC
     13        messages along with the handle, now that both are stored in the
     14        IPCHandle struct.
     15
     16        * UIProcess/Cocoa/WebPageProxyCocoa.mm:
     17        (WebKit::WebPageProxy::setPromisedDataForImage):
     18        * UIProcess/Cocoa/WebPasteboardProxyCocoa.mm:
     19        (WebKit::WebPasteboardProxy::getPasteboardBufferForType):
     20        No longer need size check, this is done in the IPCHandle::decode()
     21        function.
     22        (WebKit::WebPasteboardProxy::setPasteboardBufferForType):
     23        (WebKit::WebPasteboardProxy::readBufferFromPasteboard):
     24        * UIProcess/WebPageProxy.h:
     25        * UIProcess/WebPageProxy.messages.in:
     26        * UIProcess/WebPasteboardProxy.cpp:
     27        (WebKit::WebPasteboardProxy::readBufferFromPasteboard):
     28        * UIProcess/WebPasteboardProxy.h:
     29        * UIProcess/WebPasteboardProxy.messages.in:
     30        * UIProcess/ios/WebPageProxyIOS.mm:
     31        (WebKit::WebPageProxy::saveImageToLibrary):
     32        * UIProcess/mac/WebPageProxyMac.mm:
     33        (WebKit::WebPageProxy::dataSelectionForPasteboard):
     34        No longer need size check, this is done in the IPCHandle::decode()
     35        function.
     36        (WebKit::WebPageProxy::setPromisedDataForImage):
     37        * WebProcess/Plugins/PDF/PDFPlugin.mm:
     38        (WebKit::PDFPlugin::writeItemsToPasteboard):
     39        * WebProcess/WebCoreSupport/WebPlatformStrategies.cpp:
     40        (WebKit::WebPlatformStrategies::bufferForType):
     41        (WebKit::WebPlatformStrategies::setBufferForType):
     42        (WebKit::WebPlatformStrategies::readBufferFromPasteboard):
     43        No longer need size check, this is done in the IPCHandle::decode()
     44        function.
     45        * WebProcess/WebCoreSupport/mac/WebDragClientMac.mm:
     46        (WebKit::WebDragClient::declareAndWriteDragImage):
     47        * WebProcess/WebPage/WebPage.h:
     48        * WebProcess/WebPage/WebPage.messages.in:
     49        * WebProcess/WebPage/ios/WebPageIOS.mm:
     50        (WebKit::WebPage::getDataSelectionForPasteboard):
     51        (WebKit::WebPage::performActionOnElement):
     52        * WebProcess/WebPage/mac/WebPageMac.mm:
     53        (WebKit::WebPage::getDataSelectionForPasteboard):
     54
    1552020-08-14  Wenson Hsieh  <wenson_hsieh@apple.com>
    256
  • trunk/Source/WebKit/UIProcess/Cocoa/WebPageProxyCocoa.mm

    r264283 r265702  
    218218#if PLATFORM(IOS_FAMILY)
    219219
    220 void WebPageProxy::setPromisedDataForImage(const String&, const SharedMemory::Handle&, uint64_t, const String&, const String&, const String&, const String&, const String&, const SharedMemory::Handle&, uint64_t)
     220void WebPageProxy::setPromisedDataForImage(const String&, const SharedMemory::IPCHandle&, const String&, const String&, const String&, const String&, const String&, const SharedMemory::IPCHandle&)
    221221{
    222222    notImplemented();
  • trunk/Source/WebKit/UIProcess/Cocoa/WebPasteboardProxyCocoa.mm

    r265410 r265702  
    196196}
    197197
    198 void WebPasteboardProxy::getPasteboardBufferForType(IPC::Connection& connection, const String& pasteboardName, const String& pasteboardType, CompletionHandler<void(SharedMemory::Handle&&, uint64_t)>&& completionHandler)
    199 {
    200     MESSAGE_CHECK_COMPLETION(!pasteboardType.isEmpty(), completionHandler({ }, 0));
    201 
    202     if (!canAccessPasteboardData(connection, pasteboardName))
    203         return completionHandler({ }, 0);
     198void WebPasteboardProxy::getPasteboardBufferForType(IPC::Connection& connection, const String& pasteboardName, const String& pasteboardType, CompletionHandler<void(SharedMemory::IPCHandle&&)>&& completionHandler)
     199{
     200    MESSAGE_CHECK_COMPLETION(!pasteboardType.isEmpty(), completionHandler({ }));
     201
     202    if (!canAccessPasteboardData(connection, pasteboardName))
     203        return completionHandler({ });
    204204
    205205    RefPtr<SharedBuffer> buffer = PlatformPasteboard(pasteboardName).bufferForType(pasteboardType);
    206206    if (!buffer)
    207         return completionHandler({ }, 0);
     207        return completionHandler({ });
    208208    uint64_t size = buffer->size();
    209209    if (!size)
    210         return completionHandler({ }, 0);
     210        return completionHandler({ });
    211211    RefPtr<SharedMemory> sharedMemoryBuffer = SharedMemory::allocate(size);
    212212    if (!sharedMemoryBuffer)
    213         return completionHandler({ }, 0);
     213        return completionHandler({ });
    214214    memcpy(sharedMemoryBuffer->data(), buffer->data(), size);
    215215    SharedMemory::Handle handle;
    216216    sharedMemoryBuffer->createHandle(handle, SharedMemory::Protection::ReadOnly);
    217     completionHandler(WTFMove(handle), size);
     217    completionHandler(SharedMemory::IPCHandle { WTFMove(handle), size });
    218218}
    219219
     
    320320}
    321321
    322 void WebPasteboardProxy::setPasteboardBufferForType(IPC::Connection& connection, const String& pasteboardName, const String& pasteboardType, const SharedMemory::Handle& handle, uint64_t size, CompletionHandler<void(int64_t)>&& completionHandler)
     322void WebPasteboardProxy::setPasteboardBufferForType(IPC::Connection& connection, const String& pasteboardName, const String& pasteboardType, const SharedMemory::IPCHandle& ipcHandle, CompletionHandler<void(int64_t)>&& completionHandler)
    323323{
    324324    MESSAGE_CHECK_COMPLETION(!pasteboardName.isEmpty(), completionHandler(0));
     
    326326
    327327    auto previousChangeCount = PlatformPasteboard(pasteboardName).changeCount();
    328     if (handle.isNull()) {
     328    if (ipcHandle.handle.isNull()) {
    329329        auto newChangeCount = PlatformPasteboard(pasteboardName).setBufferForType(nullptr, pasteboardType);
    330330        didModifyContentsOfPasteboard(connection, pasteboardName, previousChangeCount, newChangeCount);
     
    332332    }
    333333
    334     // SharedMemory::Handle::size() is rounded up to the nearest page.
    335     MESSAGE_CHECK_COMPLETION(size <= handle.size(), completionHandler(0));
    336 
    337     RefPtr<SharedMemory> sharedMemoryBuffer = SharedMemory::map(handle, SharedMemory::Protection::ReadOnly);
     334    RefPtr<SharedMemory> sharedMemoryBuffer = SharedMemory::map(ipcHandle.handle, SharedMemory::Protection::ReadOnly);
    338335    if (!sharedMemoryBuffer)
    339336        return completionHandler(0);
    340     auto buffer = SharedBuffer::create(static_cast<unsigned char *>(sharedMemoryBuffer->data()), static_cast<size_t>(size));
     337    auto buffer = SharedBuffer::create(static_cast<unsigned char *>(sharedMemoryBuffer->data()), static_cast<size_t>(ipcHandle.dataSize));
    341338    auto newChangeCount = PlatformPasteboard(pasteboardName).setBufferForType(buffer.ptr(), pasteboardType);
    342339    didModifyContentsOfPasteboard(connection, pasteboardName, previousChangeCount, newChangeCount);
     
    416413}
    417414
    418 void WebPasteboardProxy::readBufferFromPasteboard(IPC::Connection& connection, size_t index, const String& pasteboardType, const String& pasteboardName, CompletionHandler<void(SharedMemory::Handle&&, uint64_t size)>&& completionHandler)
    419 {
    420     MESSAGE_CHECK_COMPLETION(!pasteboardType.isEmpty(), completionHandler({ }, 0));
    421 
    422     if (!canAccessPasteboardData(connection, pasteboardName))
    423         return completionHandler({ }, 0);
     415void WebPasteboardProxy::readBufferFromPasteboard(IPC::Connection& connection, size_t index, const String& pasteboardType, const String& pasteboardName, CompletionHandler<void(SharedMemory::IPCHandle&&)>&& completionHandler)
     416{
     417    MESSAGE_CHECK_COMPLETION(!pasteboardType.isEmpty(), completionHandler({ }));
     418
     419    if (!canAccessPasteboardData(connection, pasteboardName))
     420        return completionHandler({ });
    424421
    425422    RefPtr<SharedBuffer> buffer = PlatformPasteboard(pasteboardName).readBuffer(index, pasteboardType);
    426423    if (!buffer)
    427         return completionHandler({ }, 0);
     424        return completionHandler({ });
    428425    uint64_t size = buffer->size();
    429426    if (!size)
    430         return completionHandler({ }, 0);
     427        return completionHandler({ });
    431428    RefPtr<SharedMemory> sharedMemoryBuffer = SharedMemory::allocate(size);
    432429    if (!sharedMemoryBuffer)
    433         return completionHandler({ }, 0);
     430        return completionHandler({ });
    434431    memcpy(sharedMemoryBuffer->data(), buffer->data(), size);
    435432    SharedMemory::Handle handle;
    436433    sharedMemoryBuffer->createHandle(handle, SharedMemory::Protection::ReadOnly);
    437     completionHandler(WTFMove(handle), size);
     434    completionHandler(SharedMemory::IPCHandle { WTFMove(handle), size });
    438435}
    439436
  • trunk/Source/WebKit/UIProcess/WebPageProxy.h

    r265623 r265702  
    792792    void stopInteraction();
    793793    void performActionOnElement(uint32_t action);
    794     void saveImageToLibrary(const SharedMemory::Handle& imageHandle, uint64_t imageSize);
     794    void saveImageToLibrary(const SharedMemory::IPCHandle& imageHandle);
    795795    void focusNextFocusedElement(bool isForward, CompletionHandler<void()>&& = [] { });
    796796    void setFocusedElementValue(const String&);
     
    11731173#if PLATFORM(COCOA)
    11741174    void startDrag(const WebCore::DragItem&, const ShareableBitmap::Handle& dragImageHandle);
    1175     void setPromisedDataForImage(const String& pasteboardName, const SharedMemory::Handle& imageHandle, uint64_t imageSize, const String& filename, const String& extension,
    1176                          const String& title, const String& url, const String& visibleURL, const SharedMemory::Handle& archiveHandle, uint64_t archiveSize);
     1175    void setPromisedDataForImage(const String& pasteboardName, const SharedMemory::IPCHandle& imageHandle, const String& filename, const String& extension,
     1176        const String& title, const String& url, const String& visibleURL, const SharedMemory::IPCHandle& archiveHandle);
    11771177#endif
    11781178#if PLATFORM(GTK)
  • trunk/Source/WebKit/UIProcess/WebPageProxy.messages.in

    r265228 r265702  
    182182    InterpretKeyEvent(struct WebKit::EditorState state, bool isCharEvent) -> (bool handled) Synchronous
    183183    DidReceivePositionInformation(struct WebKit::InteractionInformationAtPosition information)
    184     SaveImageToLibrary(WebKit::SharedMemory::Handle handle, uint64_t size)
     184    SaveImageToLibrary(WebKit::SharedMemory::IPCHandle handle)
    185185    ShowPlaybackTargetPicker(bool hasVideo, WebCore::IntRect elementRect, enum:uint8_t WebCore::RouteSharingPolicy policy, String routingContextUID)
    186186    CommitPotentialTapFailed()
     
    314314#if PLATFORM(COCOA) && ENABLE(DRAG_SUPPORT)
    315315    StartDrag(struct WebCore::DragItem dragItem, WebKit::ShareableBitmap::Handle dragImage)
    316     SetPromisedDataForImage(String pasteboardName, WebKit::SharedMemory::Handle imageHandle, uint64_t imageSize, String filename, String extension, String title, String url, String visibleURL, WebKit::SharedMemory::Handle archiveHandle, uint64_t archiveSize)
     316    SetPromisedDataForImage(String pasteboardName, WebKit::SharedMemory::IPCHandle imageHandle, String filename, String extension, String title, String url, String visibleURL, WebKit::SharedMemory::IPCHandle archiveHandle)
    317317#endif
    318318#if PLATFORM(GTK) && ENABLE(DRAG_SUPPORT)
  • trunk/Source/WebKit/UIProcess/WebPasteboardProxy.cpp

    r261792 r265702  
    112112}
    113113
    114 void WebPasteboardProxy::readBufferFromPasteboard(IPC::Connection&, size_t, const String&, const String&, CompletionHandler<void(SharedMemory::Handle&&, uint64_t size)>&& completionHandler)
     114void WebPasteboardProxy::readBufferFromPasteboard(IPC::Connection&, size_t, const String&, const String&, CompletionHandler<void(SharedMemory::IPCHandle&&)>&& completionHandler)
    115115{
    116     completionHandler({ }, 0);
     116    completionHandler({ });
    117117}
    118118
  • trunk/Source/WebKit/UIProcess/WebPasteboardProxy.h

    r261802 r265702  
    9898    void getPasteboardStringForType(IPC::Connection&, const String& pasteboardName, const String& pasteboardType, CompletionHandler<void(String&&)>&&);
    9999    void getPasteboardStringsForType(IPC::Connection&, const String& pasteboardName, const String& pasteboardType, CompletionHandler<void(Vector<String>&&)>&&);
    100     void getPasteboardBufferForType(IPC::Connection&, const String& pasteboardName, const String& pasteboardType, CompletionHandler<void(SharedMemory::Handle&&, uint64_t)>&&);
     100    void getPasteboardBufferForType(IPC::Connection&, const String& pasteboardName, const String& pasteboardType, CompletionHandler<void(SharedMemory::IPCHandle&&)>&&);
    101101    void getPasteboardChangeCount(const String& pasteboardName, CompletionHandler<void(int64_t)>&&);
    102102    void getPasteboardColor(IPC::Connection&, const String& pasteboardName, CompletionHandler<void(WebCore::Color&&)>&&);
     
    107107    void setPasteboardColor(IPC::Connection&, const String&, const WebCore::Color&, CompletionHandler<void(int64_t)>&&);
    108108    void setPasteboardStringForType(IPC::Connection&, const String& pasteboardName, const String& pasteboardType, const String&, CompletionHandler<void(int64_t)>&&);
    109     void setPasteboardBufferForType(IPC::Connection&, const String& pasteboardName, const String& pasteboardType, const SharedMemory::Handle&, uint64_t size, CompletionHandler<void(int64_t)>&&);
     109    void setPasteboardBufferForType(IPC::Connection&, const String& pasteboardName, const String& pasteboardType, const SharedMemory::IPCHandle&, CompletionHandler<void(int64_t)>&&);
    110110#endif
    111111
    112112    void readStringFromPasteboard(IPC::Connection&, size_t index, const String& pasteboardType, const String& pasteboardName, CompletionHandler<void(String&&)>&&);
    113113    void readURLFromPasteboard(IPC::Connection&, size_t index, const String& pasteboardName, CompletionHandler<void(String&& url, String&& title)>&&);
    114     void readBufferFromPasteboard(IPC::Connection&, size_t index, const String& pasteboardType, const String& pasteboardName, CompletionHandler<void(SharedMemory::Handle&&, uint64_t size)>&&);
     114    void readBufferFromPasteboard(IPC::Connection&, size_t index, const String& pasteboardType, const String& pasteboardName, CompletionHandler<void(SharedMemory::IPCHandle&&)>&&);
    115115    void getPasteboardItemsCount(IPC::Connection&, const String& pasteboardName, CompletionHandler<void(uint64_t)>&&);
    116116    void informationForItemAtIndex(IPC::Connection&, size_t index, const String& pasteboardName, int64_t changeCount, CompletionHandler<void(Optional<WebCore::PasteboardItemInfo>&&)>&&);
  • trunk/Source/WebKit/UIProcess/WebPasteboardProxy.messages.in

    r261802 r265702  
    3737    ReadStringFromPasteboard(uint64_t index, String pasteboardType, String pasteboardName) -> (String string) Synchronous WantsConnection
    3838    ReadURLFromPasteboard(uint64_t index, String pasteboardName) -> (String url, String title) Synchronous WantsConnection
    39     ReadBufferFromPasteboard(uint64_t index, String pasteboardType, String pasteboardName) -> (WebKit::SharedMemory::Handle handle, uint64_t size) Synchronous WantsConnection
     39    ReadBufferFromPasteboard(uint64_t index, String pasteboardType, String pasteboardName) -> (WebKit::SharedMemory::IPCHandle handle) Synchronous WantsConnection
    4040    ContainsStringSafeForDOMToReadForType(String type, String pasteboardName) -> (bool result) Synchronous WantsConnection
    4141
     
    4747    GetPasteboardStringForType(String pasteboardName, String pasteboardType) -> (String string) Synchronous WantsConnection
    4848    GetPasteboardStringsForType(String pasteboardName, String pasteboardType) -> (Vector<String> strings) Synchronous WantsConnection
    49     GetPasteboardBufferForType(String pasteboardName, String pasteboardType) -> (WebKit::SharedMemory::Handle handle, uint64_t size) Synchronous WantsConnection
     49    GetPasteboardBufferForType(String pasteboardName, String pasteboardType) -> (WebKit::SharedMemory::IPCHandle handle) Synchronous WantsConnection
    5050    GetPasteboardChangeCount(String pasteboardName) -> (int64_t changeCount) Synchronous
    5151    GetPasteboardColor(String pasteboardName) -> (WebCore::Color color) Synchronous WantsConnection
     
    5656    SetPasteboardColor(String pasteboardName, WebCore::Color color) -> (int64_t changeCount) Synchronous WantsConnection
    5757    SetPasteboardStringForType(String pasteboardName, String pasteboardType, String string) -> (int64_t changeCount) Synchronous WantsConnection
    58     SetPasteboardBufferForType(String pasteboardName, String pasteboardType, WebKit::SharedMemory::Handle handle, uint64_t size) -> (int64_t changeCount) Synchronous WantsConnection
     58    SetPasteboardBufferForType(String pasteboardName, String pasteboardType, WebKit::SharedMemory::IPCHandle handle) -> (int64_t changeCount) Synchronous WantsConnection
    5959    ContainsURLStringSuitableForLoading(String pasteboardName) -> (bool result) Synchronous WantsConnection
    6060    URLStringSuitableForLoading(String pasteboardName) -> (String url, String title) Synchronous WantsConnection
  • trunk/Source/WebKit/UIProcess/ios/WebPageProxyIOS.mm

    r265228 r265702  
    667667}
    668668
    669 void WebPageProxy::saveImageToLibrary(const SharedMemory::Handle& imageHandle, uint64_t imageSize)
    670 {
    671     MESSAGE_CHECK(!imageHandle.isNull());
    672     // SharedMemory::Handle::size() is rounded up to the nearest page.
    673     MESSAGE_CHECK(imageSize && imageSize <= imageHandle.size());
    674 
    675     auto sharedMemoryBuffer = SharedMemory::map(imageHandle, SharedMemory::Protection::ReadOnly);
     669void WebPageProxy::saveImageToLibrary(const SharedMemory::IPCHandle& imageHandle)
     670{
     671    MESSAGE_CHECK(!imageHandle.handle.isNull());
     672
     673    auto sharedMemoryBuffer = SharedMemory::map(imageHandle.handle, SharedMemory::Protection::ReadOnly);
    676674    if (!sharedMemoryBuffer)
    677675        return;
    678676
    679     auto buffer = SharedBuffer::create(static_cast<unsigned char*>(sharedMemoryBuffer->data()), static_cast<size_t>(imageSize));
     677    auto buffer = SharedBuffer::create(static_cast<unsigned char*>(sharedMemoryBuffer->data()), static_cast<size_t>(imageHandle.dataSize));
    680678    pageClient().saveImageToLibrary(WTFMove(buffer));
    681679}
  • trunk/Source/WebKit/UIProcess/mac/WebPageProxyMac.mm

    r265158 r265702  
    250250    if (!hasRunningProcess())
    251251        return nullptr;
    252     SharedMemory::Handle handle;
     252
     253    SharedMemory::IPCHandle ipcHandle;
    253254    uint64_t size = 0;
    254255    const Seconds messageTimeout(20);
    255     sendSync(Messages::WebPage::GetDataSelectionForPasteboard(pasteboardType), Messages::WebPage::GetDataSelectionForPasteboard::Reply(handle, size), messageTimeout);
    256     MESSAGE_CHECK_WITH_RETURN_VALUE(!handle.isNull(), nullptr);
    257     // SharedMemory::Handle::size() is rounded up to the nearest page.
    258     MESSAGE_CHECK_WITH_RETURN_VALUE(size <= handle.size(), nullptr);
    259 
    260     auto sharedMemoryBuffer = SharedMemory::map(handle, SharedMemory::Protection::ReadOnly);
     256    sendSync(Messages::WebPage::GetDataSelectionForPasteboard(pasteboardType), Messages::WebPage::GetDataSelectionForPasteboard::Reply(ipcHandle), messageTimeout);
     257    MESSAGE_CHECK_WITH_RETURN_VALUE(!ipcHandle.handle.isNull(), nullptr);
     258
     259    auto sharedMemoryBuffer = SharedMemory::map(ipcHandle.handle, SharedMemory::Protection::ReadOnly);
    261260    if (!sharedMemoryBuffer)
    262261        return nullptr;
     
    284283#if ENABLE(DRAG_SUPPORT)
    285284
    286 void WebPageProxy::setPromisedDataForImage(const String& pasteboardName, const SharedMemory::Handle& imageHandle, uint64_t imageSize, const String& filename, const String& extension,
    287                                    const String& title, const String& url, const String& visibleURL, const SharedMemory::Handle& archiveHandle, uint64_t archiveSize)
     285void WebPageProxy::setPromisedDataForImage(const String& pasteboardName, const SharedMemory::IPCHandle& imageHandle, const String& filename, const String& extension,
     286    const String& title, const String& url, const String& visibleURL, const SharedMemory::IPCHandle& archiveHandle)
    288287{
    289288    MESSAGE_CHECK_URL(url);
    290289    MESSAGE_CHECK_URL(visibleURL);
    291     MESSAGE_CHECK(!imageHandle.isNull());
    292     // SharedMemory::Handle::size() is rounded up to the nearest page.
    293     MESSAGE_CHECK(imageSize && imageSize <= imageHandle.size());
    294 
    295     auto sharedMemoryImage = SharedMemory::map(imageHandle, SharedMemory::Protection::ReadOnly);
     290    MESSAGE_CHECK(!imageHandle.handle.isNull());
     291
     292    auto sharedMemoryImage = SharedMemory::map(imageHandle.handle, SharedMemory::Protection::ReadOnly);
    296293    if (!sharedMemoryImage)
    297294        return;
    298295
    299     auto imageBuffer = SharedBuffer::create(static_cast<unsigned char*>(sharedMemoryImage->data()), static_cast<size_t>(imageSize));
     296    auto imageBuffer = SharedBuffer::create(static_cast<unsigned char*>(sharedMemoryImage->data()), static_cast<size_t>(imageHandle.dataSize));
    300297    RefPtr<SharedBuffer> archiveBuffer;
    301298
    302     if (!archiveHandle.isNull()) {
    303         // SharedMemory::Handle::size() is rounded up to the nearest page.
    304         MESSAGE_CHECK(archiveSize && archiveSize <= archiveHandle.size());
    305         auto sharedMemoryArchive = SharedMemory::map(archiveHandle, SharedMemory::Protection::ReadOnly);
     299    if (!archiveHandle.handle.isNull()) {
     300        auto sharedMemoryArchive = SharedMemory::map(archiveHandle.handle, SharedMemory::Protection::ReadOnly);
    306301        if (!sharedMemoryArchive)
    307302            return;
    308         archiveBuffer = SharedBuffer::create(static_cast<unsigned char*>(sharedMemoryArchive->data()), static_cast<size_t>(archiveSize));
     303        archiveBuffer = SharedBuffer::create(static_cast<unsigned char*>(sharedMemoryArchive->data()), static_cast<size_t>(archiveHandle.dataSize));
    309304    }
    310305    pageClient().setPromisedDataForImage(pasteboardName, WTFMove(imageBuffer), ResourceResponseBase::sanitizeSuggestedFilename(filename), extension, title, url, visibleURL, WTFMove(archiveBuffer));
  • trunk/Source/WebKit/WebProcess/Plugins/PDF/PDFPlugin.mm

    r264990 r265702  
    24502450            memcpy(sharedMemory->data(), buffer->data(), buffer->size());
    24512451            sharedMemory->createHandle(handle, SharedMemory::Protection::ReadOnly);
    2452             webProcess.parentProcessConnection()->sendSync(Messages::WebPasteboardProxy::SetPasteboardBufferForType(pasteboardName, type, handle, buffer->size()), Messages::WebPasteboardProxy::SetPasteboardBufferForType::Reply(newChangeCount), 0);
     2452            webProcess.parentProcessConnection()->sendSync(Messages::WebPasteboardProxy::SetPasteboardBufferForType(pasteboardName, type, SharedMemory::IPCHandle { WTFMove(handle), buffer->size() }), Messages::WebPasteboardProxy::SetPasteboardBufferForType::Reply(newChangeCount), 0);
    24532453        }
    24542454    }
  • trunk/Source/WebKit/WebProcess/WebCoreSupport/WebPlatformStrategies.cpp

    r265410 r265702  
    133133
    134134    // Fallback to messaging the UI process for native pasteboard content.
    135     SharedMemory::Handle handle;
    136     uint64_t size { 0 };
    137     WebProcess::singleton().parentProcessConnection()->sendSync(Messages::WebPasteboardProxy::GetPasteboardBufferForType(pasteboardName, pasteboardType), Messages::WebPasteboardProxy::GetPasteboardBufferForType::Reply(handle, size), 0);
    138     if (handle.isNull())
     135    SharedMemory::IPCHandle ipcHandle;
     136    WebProcess::singleton().parentProcessConnection()->sendSync(Messages::WebPasteboardProxy::GetPasteboardBufferForType(pasteboardName, pasteboardType), Messages::WebPasteboardProxy::GetPasteboardBufferForType::Reply(ipcHandle), 0);
     137    if (ipcHandle.handle.isNull())
    139138        return nullptr;
    140     // SharedMemory::Handle::size() is rounded up to the nearest page.
    141     if (!size || size > handle.size())
    142         return nullptr;
    143     RefPtr<SharedMemory> sharedMemoryBuffer = SharedMemory::map(handle, SharedMemory::Protection::ReadOnly);
    144     return SharedBuffer::create(static_cast<unsigned char *>(sharedMemoryBuffer->data()), size);
     139    RefPtr<SharedMemory> sharedMemoryBuffer = SharedMemory::map(ipcHandle.handle, SharedMemory::Protection::ReadOnly);
     140    return SharedBuffer::create(static_cast<unsigned char *>(sharedMemoryBuffer->data()), ipcHandle.dataSize);
    145141}
    146142
     
    217213    }
    218214    int64_t newChangeCount { 0 };
    219     WebProcess::singleton().parentProcessConnection()->sendSync(Messages::WebPasteboardProxy::SetPasteboardBufferForType(pasteboardName, pasteboardType, handle, buffer ? buffer->size() : 0), Messages::WebPasteboardProxy::SetPasteboardBufferForType::Reply(newChangeCount), 0);
     215    WebProcess::singleton().parentProcessConnection()->sendSync(Messages::WebPasteboardProxy::SetPasteboardBufferForType(pasteboardName, pasteboardType, SharedMemory::IPCHandle { WTFMove(handle), buffer ? buffer->size() : 0 }), Messages::WebPasteboardProxy::SetPasteboardBufferForType::Reply(newChangeCount), 0);
    220216    return newChangeCount;
    221217}
     
    405401RefPtr<WebCore::SharedBuffer> WebPlatformStrategies::readBufferFromPasteboard(size_t index, const String& pasteboardType, const String& pasteboardName)
    406402{
    407     SharedMemory::Handle handle;
    408     uint64_t size { 0 };
    409     WebProcess::singleton().parentProcessConnection()->sendSync(Messages::WebPasteboardProxy::ReadBufferFromPasteboard(index, pasteboardType, pasteboardName), Messages::WebPasteboardProxy::ReadBufferFromPasteboard::Reply(handle, size), 0);
    410     if (handle.isNull())
     403    SharedMemory::IPCHandle ipcHandle;
     404    WebProcess::singleton().parentProcessConnection()->sendSync(Messages::WebPasteboardProxy::ReadBufferFromPasteboard(index, pasteboardType, pasteboardName), Messages::WebPasteboardProxy::ReadBufferFromPasteboard::Reply(ipcHandle), 0);
     405    if (ipcHandle.handle.isNull())
    411406        return nullptr;
    412 #if OS(DARWIN) || OS(WINDOWS)
    413     // SharedMemory::Handle::size() is rounded up to the nearest page.
    414     if (!size || size > handle.size())
    415         return nullptr;
    416 #else
    417     if (!size)
    418         return nullptr;
    419 #endif
    420     RefPtr<SharedMemory> sharedMemoryBuffer = SharedMemory::map(handle, SharedMemory::Protection::ReadOnly);
    421     return SharedBuffer::create(static_cast<unsigned char *>(sharedMemoryBuffer->data()), size);
     407
     408    RefPtr<SharedMemory> sharedMemoryBuffer = SharedMemory::map(ipcHandle.handle, SharedMemory::Protection::ReadOnly);
     409    return SharedBuffer::create(static_cast<unsigned char *>(sharedMemoryBuffer->data()), ipcHandle.dataSize);
    422410}
    423411
  • trunk/Source/WebKit/WebProcess/WebCoreSupport/mac/WebDragClientMac.mm

    r261442 r265702  
    182182    }
    183183
    184     m_page->send(Messages::WebPageProxy::SetPromisedDataForImage(pasteboardName, imageHandle, imageSize, filename, extension, title, String([[response URL] absoluteString]), WTF::userVisibleString(url), archiveHandle, archiveSize));
     184    m_page->send(Messages::WebPageProxy::SetPromisedDataForImage(pasteboardName, SharedMemory::IPCHandle { WTFMove(imageHandle), imageSize }, filename, extension, title, String([[response URL] absoluteString]), WTF::userVisibleString(url), SharedMemory::IPCHandle { WTFMove(archiveHandle), archiveSize }));
    185185}
    186186
  • trunk/Source/WebKit/WebProcess/WebPage/WebPage.h

    r265623 r265702  
    863863    void readSelectionFromPasteboard(const String& pasteboardName, CompletionHandler<void(bool&&)>&&);
    864864    void getStringSelectionForPasteboard(CompletionHandler<void(String&&)>&&);
    865     void getDataSelectionForPasteboard(const String pasteboardType, CompletionHandler<void(SharedMemory::Handle&&, uint64_t)>&&);
     865    void getDataSelectionForPasteboard(const String pasteboardType, CompletionHandler<void(SharedMemory::IPCHandle&&)>&&);
    866866    void shouldDelayWindowOrderingEvent(const WebKit::WebMouseEvent&, CompletionHandler<void(bool)>&&);
    867867    void acceptsFirstMouse(int eventNumber, const WebKit::WebMouseEvent&, CompletionHandler<void(bool)>&&);
  • trunk/Source/WebKit/WebProcess/WebPage/WebPage.messages.in

    r265623 r265702  
    435435    RegisterUIProcessAccessibilityTokens(IPC::DataReference elemenToken, IPC::DataReference windowToken)
    436436    GetStringSelectionForPasteboard() -> (String stringValue) Synchronous
    437     GetDataSelectionForPasteboard(String pasteboardType) -> (WebKit::SharedMemory::Handle handle, uint64_t size) Synchronous
     437    GetDataSelectionForPasteboard(String pasteboardType) -> (WebKit::SharedMemory::IPCHandle ipcHandle) Synchronous
    438438    ReadSelectionFromPasteboard(String pasteboardName) -> (bool result) Synchronous
    439439
  • trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm

    r265515 r265702  
    590590}
    591591
    592 void WebPage::getDataSelectionForPasteboard(const String, CompletionHandler<void(SharedMemory::Handle&&, uint64_t)>&& completionHandler)
     592void WebPage::getDataSelectionForPasteboard(const String, CompletionHandler<void(SharedMemory::IPCHandle&&)>&& completionHandler)
    593593{
    594594    notImplemented();
    595     completionHandler({ }, 0);
     595    completionHandler({ });
    596596}
    597597
     
    30053005        SharedMemory::Handle handle;
    30063006        sharedMemoryBuffer->createHandle(handle, SharedMemory::Protection::ReadOnly);
    3007         send(Messages::WebPageProxy::SaveImageToLibrary(handle, bufferSize));
     3007        send(Messages::WebPageProxy::SaveImageToLibrary(SharedMemory::IPCHandle { WTFMove(handle), bufferSize }));
    30083008    }
    30093009}
  • trunk/Source/WebKit/WebProcess/WebPage/mac/WebPageMac.mm

    r265176 r265702  
    557557}
    558558
    559 void WebPage::getDataSelectionForPasteboard(const String pasteboardType, CompletionHandler<void(SharedMemory::Handle&&, uint64_t)>&& completionHandler)
     559void WebPage::getDataSelectionForPasteboard(const String pasteboardType, CompletionHandler<void(SharedMemory::IPCHandle&&)>&& completionHandler)
    560560{
    561561    auto& frame = m_page->focusController().focusedOrMainFrame();
    562562    if (frame.selection().isNone())
    563         return completionHandler({ }, 0);
     563        return completionHandler({ });
    564564
    565565    RefPtr<SharedBuffer> buffer = frame.editor().dataSelectionForPasteboard(pasteboardType);
    566566    if (!buffer)
    567         return completionHandler({ }, 0);
     567        return completionHandler({ });
    568568    uint64_t size = buffer->size();
    569569    RefPtr<SharedMemory> sharedMemoryBuffer = SharedMemory::allocate(size);
     
    571571    SharedMemory::Handle handle;
    572572    sharedMemoryBuffer->createHandle(handle, SharedMemory::Protection::ReadOnly);
    573     completionHandler(WTFMove(handle), size);
     573    completionHandler(SharedMemory::IPCHandle { WTFMove(handle), size });
    574574}
    575575
Note: See TracChangeset for help on using the changeset viewer.