Changeset 271685 in webkit


Ignore:
Timestamp:
Jan 20, 2021 7:29:56 PM (18 months ago)
Author:
Wenson Hsieh
Message:

[macOS] Include an origin identifier when writing promised image data to the drag pasteboard
https://bugs.webkit.org/show_bug.cgi?id=220782

Reviewed by Megan Gardner.

Source/WebKit:

Add plumbing in WebKit to serialize and write the pasteboard origin identifier via custom data when dragging an
image with promised data on macOS. In the case where we're dragging an image into a contenteditable area in a
document with the *same* pasteboard origin, this allows us to avoid sanitizing the web archive data upon
handling the drop.

Test: DragAndDropTests.ProvideImageDataForMultiplePasteboards

  • UIProcess/Cocoa/WebPageProxyCocoa.mm:

(WebKit::WebPageProxy::setPromisedDataForImage):

  • UIProcess/Cocoa/WebViewImpl.h:
  • UIProcess/Cocoa/WebViewImpl.mm:

(WebKit::WebViewImpl::setPromisedDataForImage):

If specified, write the origin to the drag pasteboard by creating a new PasteboardCustomData object, setting
its origin, and then serializing the custom data object into an NSData.

  • UIProcess/PageClient.h:
  • UIProcess/WebPageProxy.h:
  • UIProcess/WebPageProxy.messages.in:
  • UIProcess/mac/PageClientImplMac.h:
  • UIProcess/mac/PageClientImplMac.mm:

(WebKit::PageClientImpl::setPromisedDataForImage):

  • UIProcess/mac/WebPageProxyMac.mm:

(WebKit::WebPageProxy::setPromisedDataForImage):

  • WebProcess/WebCoreSupport/mac/WebDragClientMac.mm:

(WebKit::WebDragClient::declareAndWriteDragImage):

Source/WebKitLegacy/mac:

See WebKit ChangeLog for more details.

  • Misc/WebNSPasteboardExtras.mm:

(-[NSPasteboard _web_declareAndWriteDragImageForElement:URL:title:archive:source:]):

Tools:

Make a slight adjustment to an existing API test, to verify that custom pasteboard data is serialized when
dragging an image element.

  • TestWebKitAPI/Tests/mac/DragAndDropTestsMac.mm:
Location:
trunk
Files:
15 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r271679 r271685  
     12021-01-20  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        [macOS] Include an origin identifier when writing promised image data to the drag pasteboard
     4        https://bugs.webkit.org/show_bug.cgi?id=220782
     5
     6        Reviewed by Megan Gardner.
     7
     8        Add plumbing in WebKit to serialize and write the pasteboard origin identifier via custom data when dragging an
     9        image with promised data on macOS. In the case where we're dragging an image into a contenteditable area in a
     10        document with the *same* pasteboard origin, this allows us to avoid sanitizing the web archive data upon
     11        handling the drop.
     12
     13        Test: DragAndDropTests.ProvideImageDataForMultiplePasteboards
     14
     15        * UIProcess/Cocoa/WebPageProxyCocoa.mm:
     16        (WebKit::WebPageProxy::setPromisedDataForImage):
     17        * UIProcess/Cocoa/WebViewImpl.h:
     18        * UIProcess/Cocoa/WebViewImpl.mm:
     19        (WebKit::WebViewImpl::setPromisedDataForImage):
     20
     21        If specified, write the origin to the drag pasteboard by creating a new `PasteboardCustomData` object, setting
     22        its origin, and then serializing the custom data object into an `NSData`.
     23
     24        * UIProcess/PageClient.h:
     25        * UIProcess/WebPageProxy.h:
     26        * UIProcess/WebPageProxy.messages.in:
     27        * UIProcess/mac/PageClientImplMac.h:
     28        * UIProcess/mac/PageClientImplMac.mm:
     29        (WebKit::PageClientImpl::setPromisedDataForImage):
     30        * UIProcess/mac/WebPageProxyMac.mm:
     31        (WebKit::WebPageProxy::setPromisedDataForImage):
     32        * WebProcess/WebCoreSupport/mac/WebDragClientMac.mm:
     33        (WebKit::WebDragClient::declareAndWriteDragImage):
     34
    1352021-01-20  Kenneth Russell  <kbr@chromium.org>
    236
  • trunk/Source/WebKit/UIProcess/Cocoa/WebPageProxyCocoa.mm

    r271493 r271685  
    211211#if PLATFORM(IOS_FAMILY)
    212212
    213 void WebPageProxy::setPromisedDataForImage(const String&, const SharedMemory::IPCHandle&, const String&, const String&, const String&, const String&, const String&, const SharedMemory::IPCHandle&)
     213void WebPageProxy::setPromisedDataForImage(const String&, const SharedMemory::IPCHandle&, const String&, const String&, const String&, const String&, const String&, const SharedMemory::IPCHandle&, const String&)
    214214{
    215215    notImplemented();
  • trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.h

    r266654 r271685  
    487487    void startDrag(const WebCore::DragItem&, const ShareableBitmap::Handle& image);
    488488    void setFileAndURLTypes(NSString *filename, NSString *extension, NSString *title, NSString *url, NSString *visibleURL, NSPasteboard *);
    489     void setPromisedDataForImage(WebCore::Image*, NSString *filename, NSString *extension, NSString *title, NSString *url, NSString *visibleURL, WebCore::SharedBuffer* archiveBuffer, NSString *pasteboardName);
     489    void setPromisedDataForImage(WebCore::Image*, NSString *filename, NSString *extension, NSString *title, NSString *url, NSString *visibleURL, WebCore::SharedBuffer* archiveBuffer, NSString *pasteboardName, NSString *pasteboardOrigin);
    490490    void pasteboardChangedOwner(NSPasteboard *);
    491491    void provideDataForPasteboard(NSPasteboard *, NSString *type);
  • trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm

    r271493 r271685  
    43304330}
    43314331
    4332 void WebViewImpl::setPromisedDataForImage(WebCore::Image* image, NSString *filename, NSString *extension, NSString *title, NSString *url, NSString *visibleURL, WebCore::SharedBuffer* archiveBuffer, NSString *pasteboardName)
     4332void WebViewImpl::setPromisedDataForImage(WebCore::Image* image, NSString *filename, NSString *extension, NSString *title, NSString *url, NSString *visibleURL, WebCore::SharedBuffer* archiveBuffer, NSString *pasteboardName, NSString *originIdentifier)
    43334333{
    43344334    NSPasteboard *pasteboard = [NSPasteboard pasteboardWithName:pasteboardName];
     
    43374337    if (image && !image->uti().isEmpty() && image->data() && !image->data()->isEmpty())
    43384338        [types addObject:image->uti()];
     4339
     4340    RetainPtr<NSData> customDataBuffer;
     4341    if (originIdentifier.length) {
     4342        [types addObject:@(PasteboardCustomData::cocoaType())];
     4343        PasteboardCustomData customData;
     4344        customData.setOrigin(originIdentifier);
     4345        customDataBuffer = customData.createSharedBuffer()->createNSData();
     4346    }
    43394347
    43404348    [types addObjectsFromArray:archiveBuffer ? PasteboardTypes::forImagesWithArchive() : PasteboardTypes::forImages()];
     
    43494357        [pasteboard setData:nsData.get() forType:PasteboardTypes::WebArchivePboardType];
    43504358    }
     4359
     4360    if (customDataBuffer)
     4361        [pasteboard setData:customDataBuffer.get() forType:@(PasteboardCustomData::cocoaType())];
    43514362
    43524363    m_promisedImage = image;
  • trunk/Source/WebKit/UIProcess/PageClient.h

    r271660 r271685  
    309309
    310310#if USE(APPKIT)
    311     virtual void setPromisedDataForImage(const String& pasteboardName, Ref<WebCore::SharedBuffer>&& imageBuffer, const String& filename, const String& extension, const String& title, const String& url, const String& visibleUrl, RefPtr<WebCore::SharedBuffer>&& archiveBuffer) = 0;
     311    virtual void setPromisedDataForImage(const String& pasteboardName, Ref<WebCore::SharedBuffer>&& imageBuffer, const String& filename, const String& extension, const String& title, const String& url, const String& visibleURL, RefPtr<WebCore::SharedBuffer>&& archiveBuffer, const String& originIdentifier) = 0;
    312312#endif
    313313
  • trunk/Source/WebKit/UIProcess/WebPageProxy.h

    r271660 r271685  
    11741174    void startDrag(const WebCore::DragItem&, const ShareableBitmap::Handle& dragImageHandle);
    11751175    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);
     1176        const String& title, const String& url, const String& visibleURL, const SharedMemory::IPCHandle& archiveHandle, const String& originIdentifier);
    11771177#endif
    11781178#if PLATFORM(GTK)
  • trunk/Source/WebKit/UIProcess/WebPageProxy.messages.in

    r271378 r271685  
    308308#if PLATFORM(COCOA) && ENABLE(DRAG_SUPPORT)
    309309    StartDrag(struct WebCore::DragItem dragItem, WebKit::ShareableBitmap::Handle dragImage)
    310     SetPromisedDataForImage(String pasteboardName, WebKit::SharedMemory::IPCHandle imageHandle, String filename, String extension, String title, String url, String visibleURL, WebKit::SharedMemory::IPCHandle archiveHandle)
     310    SetPromisedDataForImage(String pasteboardName, WebKit::SharedMemory::IPCHandle imageHandle, String filename, String extension, String title, String url, String visibleURL, WebKit::SharedMemory::IPCHandle archiveHandle, String originIdentifier)
    311311#endif
    312312#if PLATFORM(GTK) && ENABLE(DRAG_SUPPORT)
  • trunk/Source/WebKit/UIProcess/mac/PageClientImplMac.h

    r266654 r271685  
    102102    void startDrag(const WebCore::DragItem&, const ShareableBitmap::Handle& image) override;
    103103    void setPromisedDataForImage(const String& pasteboardName, Ref<WebCore::SharedBuffer>&& imageBuffer, const String& filename, const String& extension, const String& title,
    104         const String& url, const String& visibleUrl, RefPtr<WebCore::SharedBuffer>&& archiveBuffer) override;
     104        const String& url, const String& visibleURL, RefPtr<WebCore::SharedBuffer>&& archiveBuffer, const String& originIdentifier) override;
    105105    void updateSecureInputState() override;
    106106    void resetSecureInputState() override;
  • trunk/Source/WebKit/UIProcess/mac/PageClientImplMac.mm

    r268376 r271685  
    400400}
    401401
    402 void PageClientImpl::setPromisedDataForImage(const String& pasteboardName, Ref<SharedBuffer>&& imageBuffer, const String& filename, const String& extension, const String& title, const String& url, const String& visibleURL, RefPtr<SharedBuffer>&& archiveBuffer)
     402void PageClientImpl::setPromisedDataForImage(const String& pasteboardName, Ref<SharedBuffer>&& imageBuffer, const String& filename, const String& extension, const String& title, const String& url, const String& visibleURL, RefPtr<SharedBuffer>&& archiveBuffer, const String& originIdentifier)
    403403{
    404404    auto image = BitmapImage::create();
    405405    image->setData(WTFMove(imageBuffer), true);
    406     m_impl->setPromisedDataForImage(image.ptr(), filename, extension, title, url, visibleURL, archiveBuffer.get(), pasteboardName);
     406    m_impl->setPromisedDataForImage(image.ptr(), filename, extension, title, url, visibleURL, archiveBuffer.get(), pasteboardName, originIdentifier);
    407407}
    408408
  • trunk/Source/WebKit/UIProcess/mac/WebPageProxyMac.mm

    r271187 r271685  
    263263
    264264void WebPageProxy::setPromisedDataForImage(const String& pasteboardName, const SharedMemory::IPCHandle& imageHandle, const String& filename, const String& extension,
    265     const String& title, const String& url, const String& visibleURL, const SharedMemory::IPCHandle& archiveHandle)
     265    const String& title, const String& url, const String& visibleURL, const SharedMemory::IPCHandle& archiveHandle, const String& originIdentifier)
    266266{
    267267    MESSAGE_CHECK_URL(url);
     
    282282        archiveBuffer = SharedBuffer::create(static_cast<unsigned char*>(sharedMemoryArchive->data()), static_cast<size_t>(archiveHandle.dataSize));
    283283    }
    284     pageClient().setPromisedDataForImage(pasteboardName, WTFMove(imageBuffer), ResourceResponseBase::sanitizeSuggestedFilename(filename), extension, title, url, visibleURL, WTFMove(archiveBuffer));
     284    pageClient().setPromisedDataForImage(pasteboardName, WTFMove(imageBuffer), ResourceResponseBase::sanitizeSuggestedFilename(filename), extension, title, url, visibleURL, WTFMove(archiveBuffer), originIdentifier);
    285285}
    286286
  • trunk/Source/WebKit/WebProcess/WebCoreSupport/mac/WebDragClientMac.mm

    r265702 r271685  
    182182    }
    183183
    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 }));
     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 }, element.document().originIdentifierForPasteboard()));
    185185}
    186186
  • trunk/Source/WebKitLegacy/mac/ChangeLog

    r271607 r271685  
     12021-01-20  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        [macOS] Include an origin identifier when writing promised image data to the drag pasteboard
     4        https://bugs.webkit.org/show_bug.cgi?id=220782
     5
     6        Reviewed by Megan Gardner.
     7
     8        See WebKit ChangeLog for more details.
     9
     10        * Misc/WebNSPasteboardExtras.mm:
     11        (-[NSPasteboard _web_declareAndWriteDragImageForElement:URL:title:archive:source:]):
     12
    1132021-01-19  Keith Rollin  <krollin@apple.com>
    214
  • trunk/Source/WebKitLegacy/mac/Misc/WebNSPasteboardExtras.mm

    r260485 r271685  
    4444#import <WebCore/LegacyNSPasteboardTypes.h>
    4545#import <WebCore/MIMETypeRegistry.h>
     46#import <WebCore/PasteboardCustomData.h>
    4647#import <WebCore/RenderAttachment.h>
    4748#import <WebCore/RenderImage.h>
     
    283284    NSString *extension = @"";
    284285    RetainPtr<NSMutableArray> types = adoptNS([[NSMutableArray alloc] initWithObjects:legacyFilesPromisePasteboardType(), nil]);
     286    NSString *originIdentifier = core(element)->document().originIdentifierForPasteboard();
     287    RetainPtr<NSData> customDataBuffer;
     288    if (originIdentifier.length) {
     289        [types addObject:@(PasteboardCustomData::cocoaType())];
     290        PasteboardCustomData customData;
     291        customData.setOrigin(originIdentifier);
     292        customDataBuffer = customData.createSharedBuffer()->createNSData();
     293    }
     294
    285295    if (auto* renderer = core(element)->renderer()) {
    286296        if (is<RenderImage>(*renderer)) {
     
    305315
    306316    [self _web_writeImage:nil element:element URL:URL title:title archive:archive types:types.get() source:source];
     317    if (customDataBuffer)
     318        [self setData:customDataBuffer.get() forType:@(PasteboardCustomData::cocoaType())];
    307319
    308320    NSArray *extensions = [[NSArray alloc] initWithObjects:extension, nil];
  • trunk/Tools/ChangeLog

    r271683 r271685  
     12021-01-20  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        [macOS] Include an origin identifier when writing promised image data to the drag pasteboard
     4        https://bugs.webkit.org/show_bug.cgi?id=220782
     5
     6        Reviewed by Megan Gardner.
     7
     8        Make a slight adjustment to an existing API test, to verify that custom pasteboard data is serialized when
     9        dragging an image element.
     10
     11        * TestWebKitAPI/Tests/mac/DragAndDropTestsMac.mm:
     12
    1132021-01-20  Jonathan Bedard  <jbedard@apple.com>
    214
  • trunk/Tools/TestWebKitAPI/Tests/mac/DragAndDropTestsMac.mm

    r265480 r271685  
    2929#import "InstanceMethodSwizzler.h"
    3030#import "PlatformUtilities.h"
     31#import <WebCore/PasteboardCustomData.h>
    3132#import <WebKit/WKPreferencesPrivate.h>
    3233#import <WebKit/WKWebViewPrivate.h>
     
    189190    EXPECT_TRUE(NSEqualSizes(imageFromDragPasteboard.size, imageFromUniquePasteboard.size));
    190191    EXPECT_FALSE(NSEqualSizes(NSZeroSize, imageFromUniquePasteboard.size));
     192    EXPECT_GT([dragPasteboard dataForType:@(WebCore::PasteboardCustomData::cocoaType())].length, 0u);
    191193}
    192194
Note: See TracChangeset for help on using the changeset viewer.