Changeset 289541 in webkit


Ignore:
Timestamp:
Feb 10, 2022, 9:04:20 AM (4 years ago)
Author:
Megan Gardner
Message:

Mail attachment switched to TIFF and balloons in size after markup.
https://bugs.webkit.org/show_bug.cgi?id=236405
rdar://87358910

Reviewed by Wenson Hsieh.

When pulling data from the webprocess to pass to the Sharing Service
for markup, we would convert it to TIFF format. This would cause files
to increase in size, and lose their original formatting, as well as outright
break PDFs. Instead we should be pulling the data from the attachment, which
already exists in the UI process and is the source of truth for that data anyways.
This allows us to give the correct type to the sharing service, and we should
take the data back as the same original type when getting the data back from
markup.

  • UIProcess/API/APIAttachment.cpp:

(API::Attachment::enclosingImageData const):

  • UIProcess/API/APIAttachment.h:
  • UIProcess/API/Cocoa/APIAttachmentCocoa.mm:

(API::Attachment::enclosingImageNSData const):

  • UIProcess/mac/WKSharingServicePickerDelegate.mm:

(-[WKSharingServicePickerDelegate sharingService:didShareItems:]):

  • UIProcess/mac/WebContextMenuProxyMac.mm:

(WebKit::WebContextMenuProxyMac::setupServicesMenu):

Location:
trunk/Source/WebKit
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r289528 r289541  
     12022-02-10  Megan Gardner  <megan_gardner@apple.com>
     2
     3        Mail attachment switched to TIFF and balloons in size after markup.
     4        https://bugs.webkit.org/show_bug.cgi?id=236405
     5        rdar://87358910
     6
     7        Reviewed by Wenson Hsieh.
     8
     9        When pulling data from the webprocess to pass to the Sharing Service
     10        for markup, we would convert it to TIFF format. This would cause files
     11        to increase in size, and lose their original formatting, as well as outright
     12        break PDFs. Instead we should be pulling the data from the attachment, which
     13        already exists in the UI process and is the source of truth for that data anyways.
     14        This allows us to give the correct type to the sharing service, and we should
     15        take the data back as the same original type when getting the data back from
     16        markup.
     17
     18        * UIProcess/API/APIAttachment.cpp:
     19        (API::Attachment::enclosingImageData const):
     20        * UIProcess/API/APIAttachment.h:
     21        * UIProcess/API/Cocoa/APIAttachmentCocoa.mm:
     22        (API::Attachment::enclosingImageNSData const):
     23        * UIProcess/mac/WKSharingServicePickerDelegate.mm:
     24        (-[WKSharingServicePickerDelegate sharingService:didShareItems:]):
     25        * UIProcess/mac/WebContextMenuProxyMac.mm:
     26        (WebKit::WebContextMenuProxyMac::setupServicesMenu):
     27
    1282022-02-10  Carlos Garcia Campos  <cgarcia@igalia.com>
    229
  • trunk/Source/WebKit/UIProcess/API/APIAttachment.h

    r287021 r289541  
    8585
    8686    RefPtr<WebCore::FragmentedSharedBuffer> enclosingImageData() const;
     87#if PLATFORM(COCOA)
     88    NSData *enclosingImageNSData() const;
     89#endif
    8790    std::optional<uint64_t> fileSizeForDisplay() const;
    8891
  • trunk/Source/WebKit/UIProcess/API/Cocoa/APIAttachmentCocoa.mm

    r287021 r289541  
    155155}
    156156
     157NSData *Attachment::enclosingImageNSData() const
     158{
     159    if (!m_hasEnclosingImage)
     160        return nil;
     161
     162    auto fileWrapper = this->fileWrapper();
     163
     164    if (![fileWrapper isRegularFile])
     165        return nil;
     166
     167    return fileWrapper.regularFileContents;
     168}
     169
    157170bool Attachment::isEmpty() const
    158171{
  • trunk/Source/WebKit/UIProcess/mac/WKSharingServicePickerDelegate.mm

    r287034 r289541  
    150150        ALLOW_DEPRECATED_DECLARATIONS_BEGIN
    151151        WeakPtr weakPage = _menuProxy->page();
    152         [itemProvider loadDataRepresentationForTypeIdentifier:(NSString *)kUTTypeData completionHandler:[weakPage, attachmentID = _attachmentID](NSData *data, NSError *error) {
     152        NSString *itemUTI = itemProvider.registeredTypeIdentifiers.firstObject;
     153        [itemProvider loadDataRepresentationForTypeIdentifier:itemUTI completionHandler:[weakPage, attachmentID = _attachmentID, itemUTI](NSData *data, NSError *error) {
    153154            RefPtr webPage = weakPage.get();
    154155           
     
    164165           
    165166            auto attachment = wrapper(apiAttachment);
    166             [attachment setData:data newContentType:String(NSPasteboardTypeTIFF)];
     167            [attachment setData:data newContentType:itemUTI];
    167168            webPage->didInvalidateDataForAttachment(*apiAttachment.get());
    168169        }];
  • trunk/Source/WebKit/UIProcess/mac/WebContextMenuProxyMac.mm

    r288541 r289541  
    213213    NSArray *items = nil;
    214214    if (hasControlledImage) {
    215         RefPtr<ShareableBitmap> image = m_context.controlledImage();
    216         if (!image)
    217             return;
    218 
    219         auto cgImage = image->makeCGImage();
    220         auto nsImage = adoptNS([[NSImage alloc] initWithCGImage:cgImage.get() size:image->size()]);
    221 
    222 ALLOW_DEPRECATED_DECLARATIONS_BEGIN
    223         auto itemProvider = adoptNS([[NSItemProvider alloc] initWithItem:[nsImage TIFFRepresentation] typeIdentifier:(__bridge NSString *)kUTTypeTIFF]);
    224 ALLOW_DEPRECATED_DECLARATIONS_END
     215        auto attachment = page()->attachmentForIdentifier(m_context.controlledImageAttachmentID());
     216        RetainPtr<NSItemProvider> itemProvider;
     217        if (attachment)
     218            itemProvider = adoptNS([[NSItemProvider alloc] initWithItem:attachment->enclosingImageNSData() typeIdentifier:attachment->utiType()]);
     219        else {
     220            RefPtr<ShareableBitmap> image = m_context.controlledImage();
     221            if (!image)
     222                return;
     223            auto cgImage = image->makeCGImage();
     224            auto nsImage = adoptNS([[NSImage alloc] initWithCGImage:cgImage.get() size:image->size()]);
     225
     226            ALLOW_DEPRECATED_DECLARATIONS_BEGIN
     227            itemProvider = adoptNS([[NSItemProvider alloc] initWithItem:[nsImage TIFFRepresentation] typeIdentifier:(__bridge NSString *)kUTTypeTIFF]);
     228            ALLOW_DEPRECATED_DECLARATIONS_END
     229        }
    225230        items = @[ itemProvider.get() ];
     231       
    226232    } else if (!m_context.controlledSelectionData().isEmpty()) {
    227233        auto selectionData = adoptNS([[NSData alloc] initWithBytes:static_cast<const void*>(m_context.controlledSelectionData().data()) length:m_context.controlledSelectionData().size()]);
Note: See TracChangeset for help on using the changeset viewer.