Title: [289541] trunk/Source/WebKit
Revision
289541
Author
[email protected]
Date
2022-02-10 09:04:20 -0800 (Thu, 10 Feb 2022)

Log 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):

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (289540 => 289541)


--- trunk/Source/WebKit/ChangeLog	2022-02-10 17:02:40 UTC (rev 289540)
+++ trunk/Source/WebKit/ChangeLog	2022-02-10 17:04:20 UTC (rev 289541)
@@ -1,3 +1,30 @@
+2022-02-10  Megan Gardner  <[email protected]>
+
+        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):
+
 2022-02-10  Carlos Garcia Campos  <[email protected]>
 
         [GTK][WPE] Refactor the XDGDBusProxy launcher to simplify it and fix some issues

Modified: trunk/Source/WebKit/UIProcess/API/APIAttachment.h (289540 => 289541)


--- trunk/Source/WebKit/UIProcess/API/APIAttachment.h	2022-02-10 17:02:40 UTC (rev 289540)
+++ trunk/Source/WebKit/UIProcess/API/APIAttachment.h	2022-02-10 17:04:20 UTC (rev 289541)
@@ -84,6 +84,9 @@
     bool isEmpty() const;
 
     RefPtr<WebCore::FragmentedSharedBuffer> enclosingImageData() const;
+#if PLATFORM(COCOA)
+    NSData *enclosingImageNSData() const;
+#endif
     std::optional<uint64_t> fileSizeForDisplay() const;
 
     void setHasEnclosingImage(bool hasEnclosingImage) { m_hasEnclosingImage = hasEnclosingImage; }

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/APIAttachmentCocoa.mm (289540 => 289541)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/APIAttachmentCocoa.mm	2022-02-10 17:02:40 UTC (rev 289540)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/APIAttachmentCocoa.mm	2022-02-10 17:04:20 UTC (rev 289541)
@@ -154,6 +154,19 @@
     return WebCore::SharedBuffer::create(data);
 }
 
+NSData *Attachment::enclosingImageNSData() const
+{
+    if (!m_hasEnclosingImage)
+        return nil;
+
+    auto fileWrapper = this->fileWrapper();
+
+    if (![fileWrapper isRegularFile])
+        return nil;
+
+    return fileWrapper.regularFileContents;
+}
+
 bool Attachment::isEmpty() const
 {
     return !m_fileWrapper && !m_fileWrapperGenerator;

Modified: trunk/Source/WebKit/UIProcess/mac/WKSharingServicePickerDelegate.mm (289540 => 289541)


--- trunk/Source/WebKit/UIProcess/mac/WKSharingServicePickerDelegate.mm	2022-02-10 17:02:40 UTC (rev 289540)
+++ trunk/Source/WebKit/UIProcess/mac/WKSharingServicePickerDelegate.mm	2022-02-10 17:04:20 UTC (rev 289541)
@@ -149,7 +149,8 @@
         
         ALLOW_DEPRECATED_DECLARATIONS_BEGIN
         WeakPtr weakPage = _menuProxy->page();
-        [itemProvider loadDataRepresentationForTypeIdentifier:(NSString *)kUTTypeData completionHandler:[weakPage, attachmentID = _attachmentID](NSData *data, NSError *error) {
+        NSString *itemUTI = itemProvider.registeredTypeIdentifiers.firstObject;
+        [itemProvider loadDataRepresentationForTypeIdentifier:itemUTI completionHandler:[weakPage, attachmentID = _attachmentID, itemUTI](NSData *data, NSError *error) {
             RefPtr webPage = weakPage.get();
             
             if (!webPage)
@@ -163,7 +164,7 @@
                 return;
             
             auto attachment = wrapper(apiAttachment);
-            [attachment setData:data newContentType:String(NSPasteboardTypeTIFF)];
+            [attachment setData:data newContentType:itemUTI];
             webPage->didInvalidateDataForAttachment(*apiAttachment.get());
         }];
         ALLOW_DEPRECATED_DECLARATIONS_END

Modified: trunk/Source/WebKit/UIProcess/mac/WebContextMenuProxyMac.mm (289540 => 289541)


--- trunk/Source/WebKit/UIProcess/mac/WebContextMenuProxyMac.mm	2022-02-10 17:02:40 UTC (rev 289540)
+++ trunk/Source/WebKit/UIProcess/mac/WebContextMenuProxyMac.mm	2022-02-10 17:04:20 UTC (rev 289541)
@@ -212,17 +212,23 @@
     bool hasControlledImage = m_context.controlledImage();
     NSArray *items = nil;
     if (hasControlledImage) {
-        RefPtr<ShareableBitmap> image = m_context.controlledImage();
-        if (!image)
-            return;
+        auto attachment = page()->attachmentForIdentifier(m_context.controlledImageAttachmentID());
+        RetainPtr<NSItemProvider> itemProvider;
+        if (attachment)
+            itemProvider = adoptNS([[NSItemProvider alloc] initWithItem:attachment->enclosingImageNSData() typeIdentifier:attachment->utiType()]);
+        else {
+            RefPtr<ShareableBitmap> image = m_context.controlledImage();
+            if (!image)
+                return;
+            auto cgImage = image->makeCGImage();
+            auto nsImage = adoptNS([[NSImage alloc] initWithCGImage:cgImage.get() size:image->size()]);
 
-        auto cgImage = image->makeCGImage();
-        auto nsImage = adoptNS([[NSImage alloc] initWithCGImage:cgImage.get() size:image->size()]);
-
-ALLOW_DEPRECATED_DECLARATIONS_BEGIN
-        auto itemProvider = adoptNS([[NSItemProvider alloc] initWithItem:[nsImage TIFFRepresentation] typeIdentifier:(__bridge NSString *)kUTTypeTIFF]);
-ALLOW_DEPRECATED_DECLARATIONS_END
+            ALLOW_DEPRECATED_DECLARATIONS_BEGIN
+            itemProvider = adoptNS([[NSItemProvider alloc] initWithItem:[nsImage TIFFRepresentation] typeIdentifier:(__bridge NSString *)kUTTypeTIFF]);
+            ALLOW_DEPRECATED_DECLARATIONS_END
+        }
         items = @[ itemProvider.get() ];
+        
     } else if (!m_context.controlledSelectionData().isEmpty()) {
         auto selectionData = adoptNS([[NSData alloc] initWithBytes:static_cast<const void*>(m_context.controlledSelectionData().data()) length:m_context.controlledSelectionData().size()]);
         auto selection = adoptNS([[NSAttributedString alloc] initWithRTFD:selectionData.get() documentAttributes:nil]);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to