Title: [293638] trunk
Revision
293638
Author
[email protected]
Date
2022-04-29 17:18:38 -0700 (Fri, 29 Apr 2022)

Log Message

[Mail compose] Images with data URLs should be pasted or dropped as attachments
https://bugs.webkit.org/show_bug.cgi?id=239911
rdar://91658665

Reviewed by Tim Horton.

Source/WebCore:

Effectively revert the changes in r226340, which prevented data-URL and http-family-URL images from being
converted into attachments when pasting or dropping into Mail compose. The original intent behind this change
may have been to save Mail storage space (in the server and in the on-disk cache) by excluding remote images,
but this was changed in r291261 due to being a regression in behavior compared to legacy WebKit compose
behavior, which creates attachments when pasting or dropping both data and remote images.

Furthermore, the space-saving rationale never really made sense for image data URLs, which are encoded in base
64, since this base 64 representation is always going to be larger than the raw binary representation that we
would otherwise use for a normal attachment.

Test: WKAttachmentTests.InsertDataURLImagesAsAttachments

* editing/cocoa/WebContentReaderCocoa.mm:
(WebCore::shouldReplaceSubresourceURLWithBlobDuringSanitization):

Remove the argument flag enum altogether, and rename this method to clarify that it is just about blob URL
replacement for sanitizing pasted/dropped fragments (rather than attachment replacement).

(WebCore::replaceRichContentWithAttachments):
(WebCore::sanitizeMarkupWithArchive):
(WebCore::WebContentReader::readHTML):
(WebCore::WebContentMarkupReader::readHTML):
(WebCore::shouldReplaceSubresourceURL): Deleted.

Tools:

Adjust expectations for an existing API test.

* TestWebKitAPI/Tests/WebKitCocoa/WKAttachmentTests.mm:
(TestWebKitAPI::TEST):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (293637 => 293638)


--- trunk/Source/WebCore/ChangeLog	2022-04-29 23:23:13 UTC (rev 293637)
+++ trunk/Source/WebCore/ChangeLog	2022-04-30 00:18:38 UTC (rev 293638)
@@ -1,3 +1,35 @@
+2022-04-29  Wenson Hsieh  <[email protected]>
+
+        [Mail compose] Images with data URLs should be pasted or dropped as attachments
+        https://bugs.webkit.org/show_bug.cgi?id=239911
+        rdar://91658665
+
+        Reviewed by Tim Horton.
+
+        Effectively revert the changes in r226340, which prevented data-URL and http-family-URL images from being
+        converted into attachments when pasting or dropping into Mail compose. The original intent behind this change
+        may have been to save Mail storage space (in the server and in the on-disk cache) by excluding remote images,
+        but this was changed in r291261 due to being a regression in behavior compared to legacy WebKit compose
+        behavior, which creates attachments when pasting or dropping both data and remote images.
+
+        Furthermore, the space-saving rationale never really made sense for image data URLs, which are encoded in base
+        64, since this base 64 representation is always going to be larger than the raw binary representation that we
+        would otherwise use for a normal attachment.
+
+        Test: WKAttachmentTests.InsertDataURLImagesAsAttachments
+
+        * editing/cocoa/WebContentReaderCocoa.mm:
+        (WebCore::shouldReplaceSubresourceURLWithBlobDuringSanitization):
+
+        Remove the argument flag enum altogether, and rename this method to clarify that it is just about blob URL
+        replacement for sanitizing pasted/dropped fragments (rather than attachment replacement).
+
+        (WebCore::replaceRichContentWithAttachments):
+        (WebCore::sanitizeMarkupWithArchive):
+        (WebCore::WebContentReader::readHTML):
+        (WebCore::WebContentMarkupReader::readHTML):
+        (WebCore::shouldReplaceSubresourceURL): Deleted.
+
 2022-04-29  Devin Rousso  <[email protected]>
 
         increase transient activation duration to 5s

Modified: trunk/Source/WebCore/editing/cocoa/WebContentReaderCocoa.mm (293637 => 293638)


--- trunk/Source/WebCore/editing/cocoa/WebContentReaderCocoa.mm	2022-04-29 23:23:13 UTC (rev 293637)
+++ trunk/Source/WebCore/editing/cocoa/WebContentReaderCocoa.mm	2022-04-30 00:18:38 UTC (rev 293638)
@@ -200,16 +200,9 @@
     bool m_didDisableImage { false };
 };
 
-enum class ReplacementMethod : bool { BlobURL, Attachment };
-static bool shouldReplaceSubresourceURL(const URL& url, ReplacementMethod replacementType = ReplacementMethod::BlobURL)
+static bool shouldReplaceSubresourceURLWithBlobDuringSanitization(const URL& url)
 {
-    if (url.protocolIsData())
-        return false;
-
-    if (url.protocolIsInHTTPFamily())
-        return replacementType == ReplacementMethod::Attachment;
-
-    return true;
+    return !url.protocolIsData() && !url.protocolIsInHTTPFamily();
 }
 
 static bool shouldReplaceRichContentWithAttachments()
@@ -301,11 +294,8 @@
 
     // FIXME: Handle resources in subframe archives.
     HashMap<AtomString, Ref<ArchiveResource>> urlToResourceMap;
-    for (auto& subresource : subresources) {
-        auto& url = ""
-        if (shouldReplaceSubresourceURL(url, ReplacementMethod::Attachment))
-            urlToResourceMap.set(url.string(), subresource.copyRef());
-    }
+    for (auto& subresource : subresources)
+        urlToResourceMap.set(subresource->url().string(), subresource.copyRef());
 
     Vector<SerializedAttachmentData> serializedAttachmentData;
     for (auto& attachment : descendantsOfType<HTMLAttachmentElement>(fragment)) {
@@ -466,7 +456,7 @@
     HashMap<AtomString, AtomString> blobURLMap;
     for (const Ref<ArchiveResource>& subresource : markupAndArchive.archive->subresources()) {
         auto& subresourceURL = subresource->url();
-        if (!shouldReplaceSubresourceURL(subresourceURL))
+        if (!shouldReplaceSubresourceURLWithBlobDuringSanitization(subresourceURL))
             continue;
         auto blob = Blob::create(&destinationDocument, subresource->data().copyData(), subresource->mimeType());
         String blobURL = DOMURL::createObjectURL(destinationDocument, blob);
@@ -484,7 +474,7 @@
             continue;
 
         auto subframeURL = subframeMainResource->url();
-        if (!shouldReplaceSubresourceURL(subframeURL))
+        if (!shouldReplaceSubresourceURLWithBlobDuringSanitization(subframeURL))
             continue;
 
         MarkupAndArchive subframeContent = { String::fromUTF8(subframeMainResource->data().makeContiguous()->data(), subframeMainResource->data().size()),
@@ -590,7 +580,7 @@
     if (RuntimeEnabledFeatures::sharedFeatures().customPasteboardDataEnabled() && shouldSanitize()) {
         markup = sanitizeMarkup(stringOmittingMicrosoftPrefix, msoListQuirksForMarkup(), WTF::Function<void (DocumentFragment&)> { [] (DocumentFragment& fragment) {
             removeSubresourceURLAttributes(fragment, [] (const URL& url) {
-                return shouldReplaceSubresourceURL(url);
+                return shouldReplaceSubresourceURLWithBlobDuringSanitization(url);
             });
         } });
     } else
@@ -609,7 +599,7 @@
     if (shouldSanitize()) {
         markup = sanitizeMarkup(rawHTML, msoListQuirksForMarkup(), WTF::Function<void (DocumentFragment&)> { [] (DocumentFragment& fragment) {
             removeSubresourceURLAttributes(fragment, [] (const URL& url) {
-                return shouldReplaceSubresourceURL(url);
+                return shouldReplaceSubresourceURLWithBlobDuringSanitization(url);
             });
         } });
     } else

Modified: trunk/Tools/ChangeLog (293637 => 293638)


--- trunk/Tools/ChangeLog	2022-04-29 23:23:13 UTC (rev 293637)
+++ trunk/Tools/ChangeLog	2022-04-30 00:18:38 UTC (rev 293638)
@@ -1,3 +1,16 @@
+2022-04-29  Wenson Hsieh  <[email protected]>
+
+        [Mail compose] Images with data URLs should be pasted or dropped as attachments
+        https://bugs.webkit.org/show_bug.cgi?id=239911
+        rdar://91658665
+
+        Reviewed by Tim Horton.
+
+        Adjust expectations for an existing API test.
+
+        * TestWebKitAPI/Tests/WebKitCocoa/WKAttachmentTests.mm:
+        (TestWebKitAPI::TEST):
+
 2022-04-29  Simon Fraser  <[email protected]>
 
         REGRESSION (249864@main): [ iOS ] TestWebKitAPI.ScrollViewScrollabilityTests.ScrollableWithOverflowHiddenAndShrunkUI is failing

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKAttachmentTests.mm (293637 => 293638)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKAttachmentTests.mm	2022-04-29 23:23:13 UTC (rev 293637)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKAttachmentTests.mm	2022-04-30 00:18:38 UTC (rev 293638)
@@ -1191,7 +1191,7 @@
     }
 }
 
-TEST(WKAttachmentTests, DoNotInsertDataURLImagesAsAttachments)
+TEST(WKAttachmentTests, InsertDataURLImagesAsAttachments)
 {
     auto webContentSourceView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)]);
     [webContentSourceView synchronouslyLoadTestPageNamed:@"apple-data-url"];
@@ -1198,15 +1198,18 @@
     [webContentSourceView selectAll:nil];
     [webContentSourceView _synchronouslyExecuteEditCommand:@"Copy" argument:nil];
 
+    RetainPtr<_WKAttachment> pastedAttachment;
     auto webView = webViewForTestingAttachments();
     {
         ObserveAttachmentUpdatesForScope observer(webView.get());
         [webView _synchronouslyExecuteEditCommand:@"Paste" argument:nil];
-        EXPECT_EQ(0U, observer.observer().inserted.count);
+        EXPECT_EQ(1U, observer.observer().inserted.count);
+        pastedAttachment = observer.observer().inserted.firstObject;
     }
 
-    EXPECT_FALSE([webView stringByEvaluatingJavaScript:@"Boolean(document.querySelector('attachment'))"].boolValue);
-    EXPECT_EQ(1990, [webView stringByEvaluatingJavaScript:@"document.querySelector('img').src.length"].integerValue);
+    RetainPtr info = [pastedAttachment info];
+    EXPECT_WK_STREQ("image/gif", [info contentType]);
+    EXPECT_GT([info data].length, 0U);
     EXPECT_WK_STREQ("This is an apple", [webView stringByEvaluatingJavaScript:@"document.body.textContent"]);
 }
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to