Title: [239511] trunk
Revision
239511
Author
wenson_hs...@apple.com
Date
2018-12-21 11:40:41 -0800 (Fri, 21 Dec 2018)

Log Message

Setting the file wrapper and content type of an attachment to a PDF should update its image
https://bugs.webkit.org/show_bug.cgi?id=192984
<rdar://problem/46798028>

Reviewed by Tim Horton.

Source/WebCore:

Allow PDF data to be used to update enclosing image elements when setting the file wrapper for an attachment.
Covered by a new API test: WKAttachmentTests.SetFileWrapperForPDFImageAttachment.

* html/HTMLAttachmentElement.cpp:
(WebCore::mimeTypeIsSuitableForInlineImageAttachment):
(WebCore::HTMLAttachmentElement::updateEnclosingImageWithData):

Tools:

Add an API test to verify that setting the file wrapper for a _WKAttachment with an enclosing image element with
PDF data correctly updates the image element.

* TestWebKitAPI/Tests/WebKitCocoa/WKAttachmentTests.mm:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (239510 => 239511)


--- trunk/Source/WebCore/ChangeLog	2018-12-21 19:37:40 UTC (rev 239510)
+++ trunk/Source/WebCore/ChangeLog	2018-12-21 19:40:41 UTC (rev 239511)
@@ -1,3 +1,18 @@
+2018-12-21  Wenson Hsieh  <wenson_hs...@apple.com>
+
+        Setting the file wrapper and content type of an attachment to a PDF should update its image
+        https://bugs.webkit.org/show_bug.cgi?id=192984
+        <rdar://problem/46798028>
+
+        Reviewed by Tim Horton.
+
+        Allow PDF data to be used to update enclosing image elements when setting the file wrapper for an attachment.
+        Covered by a new API test: WKAttachmentTests.SetFileWrapperForPDFImageAttachment.
+
+        * html/HTMLAttachmentElement.cpp:
+        (WebCore::mimeTypeIsSuitableForInlineImageAttachment):
+        (WebCore::HTMLAttachmentElement::updateEnclosingImageWithData):
+
 2018-12-21  Justin Michaud  <justin_mich...@apple.com>
 
         Repeated background images with zero size should display the background color

Modified: trunk/Source/WebCore/html/HTMLAttachmentElement.cpp (239510 => 239511)


--- trunk/Source/WebCore/html/HTMLAttachmentElement.cpp	2018-12-21 19:37:40 UTC (rev 239510)
+++ trunk/Source/WebCore/html/HTMLAttachmentElement.cpp	2018-12-21 19:40:41 UTC (rev 239511)
@@ -226,6 +226,11 @@
         renderer->invalidate();
 }
 
+static bool mimeTypeIsSuitableForInlineImageAttachment(const String& mimeType)
+{
+    return MIMETypeRegistry::isSupportedImageMIMEType(mimeType) || MIMETypeRegistry::isPDFMIMEType(mimeType);
+}
+
 void HTMLAttachmentElement::updateEnclosingImageWithData(const String& contentType, Ref<SharedBuffer>&& data)
 {
     auto* hostElement = shadowHost();
@@ -238,7 +243,7 @@
         mimeType = MIMETypeFromUTI(contentType);
 #endif
 
-    if (!MIMETypeRegistry::isSupportedImageMIMEType(mimeType))
+    if (!mimeTypeIsSuitableForInlineImageAttachment(mimeType))
         return;
 
     hostElement->setAttributeWithoutSynchronization(HTMLNames::srcAttr, DOMURL::createObjectURL(document(), Blob::create(WTFMove(data), mimeType)));

Modified: trunk/Tools/ChangeLog (239510 => 239511)


--- trunk/Tools/ChangeLog	2018-12-21 19:37:40 UTC (rev 239510)
+++ trunk/Tools/ChangeLog	2018-12-21 19:40:41 UTC (rev 239511)
@@ -1,3 +1,16 @@
+2018-12-21  Wenson Hsieh  <wenson_hs...@apple.com>
+
+        Setting the file wrapper and content type of an attachment to a PDF should update its image
+        https://bugs.webkit.org/show_bug.cgi?id=192984
+        <rdar://problem/46798028>
+
+        Reviewed by Tim Horton.
+
+        Add an API test to verify that setting the file wrapper for a _WKAttachment with an enclosing image element with
+        PDF data correctly updates the image element.
+
+        * TestWebKitAPI/Tests/WebKitCocoa/WKAttachmentTests.mm:
+
 2018-12-21  Michael Catanzaro  <mcatanz...@igalia.com>
 
         Add JSCOnly to bot dashboard

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKAttachmentTests.mm (239510 => 239511)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKAttachmentTests.mm	2018-12-21 19:37:40 UTC (rev 239510)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKAttachmentTests.mm	2018-12-21 19:40:41 UTC (rev 239511)
@@ -1505,6 +1505,18 @@
     EXPECT_WK_STREQ([attachment uniqueIdentifier], [webView stringByEvaluatingJavaScript:@"document.body.cloneNode(true).querySelector('attachment').uniqueIdentifier"]);
 }
 
+TEST(WKAttachmentTests, SetFileWrapperForPDFImageAttachment)
+{
+    auto webView = webViewForTestingAttachments();
+    [webView evaluateJavaScript:@"document.body.appendChild()" completionHandler:nil];
+    NSString *identifier = [webView stringByEvaluatingJavaScript:@"const i = document.createElement('img'); document.body.appendChild(i); HTMLAttachmentElement.getAttachmentIdentifier(i)"];
+    _WKAttachment *attachment = [webView _attachmentForIdentifier:identifier];
+
+    auto pdfFile = adoptNS([[NSFileWrapper alloc] initRegularFileWithContents:testPDFData()]);
+    [attachment setFileWrapper:pdfFile.get() contentType:(__bridge NSString *)kUTTypePDF completion:nil];
+    [webView waitForImageElementSizeToBecome:CGSizeMake(130, 29)];
+}
+
 #pragma mark - Platform-specific tests
 
 #if PLATFORM(MAC)
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to