Title: [238954] trunk
Revision
238954
Author
wenson_hs...@apple.com
Date
2018-12-07 10:37:58 -0800 (Fri, 07 Dec 2018)

Log Message

[Attachment Support] Cloned attachment elements lose their unique identifiers
https://bugs.webkit.org/show_bug.cgi?id=192483

Reviewed by Tim Horton.

Source/WebCore:

This patch adds logic to ensure that the unique identifier of a cloned attachment element is the same as the
unique identifier of the original attachment element. If the cloned attachment is inserted into the same
document as the original attachment, then we will exercise the same codepath for copied-and-pasted attachments,
and assign a new unique identifier to the attachment element, while creating a new `_WKAttachment` in the client
that's backed by the same `NSFileWrapper`.

Test: WKAttachmentTests.AttachmentIdentifierOfClonedAttachment

* html/HTMLAttachmentElement.cpp:
(WebCore::HTMLAttachmentElement::copyNonAttributePropertiesFromElement):
* html/HTMLAttachmentElement.h:

Tools:

Introduce a new API test.

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

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (238953 => 238954)


--- trunk/Source/WebCore/ChangeLog	2018-12-07 18:33:43 UTC (rev 238953)
+++ trunk/Source/WebCore/ChangeLog	2018-12-07 18:37:58 UTC (rev 238954)
@@ -1,3 +1,22 @@
+2018-12-07  Wenson Hsieh  <wenson_hs...@apple.com>
+
+        [Attachment Support] Cloned attachment elements lose their unique identifiers
+        https://bugs.webkit.org/show_bug.cgi?id=192483
+
+        Reviewed by Tim Horton.
+
+        This patch adds logic to ensure that the unique identifier of a cloned attachment element is the same as the
+        unique identifier of the original attachment element. If the cloned attachment is inserted into the same
+        document as the original attachment, then we will exercise the same codepath for copied-and-pasted attachments,
+        and assign a new unique identifier to the attachment element, while creating a new `_WKAttachment` in the client
+        that's backed by the same `NSFileWrapper`.
+
+        Test: WKAttachmentTests.AttachmentIdentifierOfClonedAttachment
+
+        * html/HTMLAttachmentElement.cpp:
+        (WebCore::HTMLAttachmentElement::copyNonAttributePropertiesFromElement):
+        * html/HTMLAttachmentElement.h:
+
 2018-12-07  Rob Buis  <rb...@igalia.com>
 
         Merge parseAccessControlExposeHeadersAllowList into parseAccessControlAllowList

Modified: trunk/Source/WebCore/html/HTMLAttachmentElement.cpp (238953 => 238954)


--- trunk/Source/WebCore/html/HTMLAttachmentElement.cpp	2018-12-07 18:33:43 UTC (rev 238953)
+++ trunk/Source/WebCore/html/HTMLAttachmentElement.cpp	2018-12-07 18:37:58 UTC (rev 238954)
@@ -86,6 +86,12 @@
     return identifier;
 }
 
+void HTMLAttachmentElement::copyNonAttributePropertiesFromElement(const Element& source)
+{
+    m_uniqueIdentifier = downcast<HTMLAttachmentElement>(source).uniqueIdentifier();
+    HTMLElement::copyNonAttributePropertiesFromElement(source);
+}
+
 URL HTMLAttachmentElement::archiveResourceURL(const String& identifier)
 {
     auto resourceURL = URL({ }, "applewebdata://attachment/"_s);

Modified: trunk/Source/WebCore/html/HTMLAttachmentElement.h (238953 => 238954)


--- trunk/Source/WebCore/html/HTMLAttachmentElement.h	2018-12-07 18:33:43 UTC (rev 238953)
+++ trunk/Source/WebCore/html/HTMLAttachmentElement.h	2018-12-07 18:37:58 UTC (rev 238954)
@@ -52,6 +52,8 @@
     const String& uniqueIdentifier() const { return m_uniqueIdentifier; }
     void setUniqueIdentifier(const String& uniqueIdentifier) { m_uniqueIdentifier = uniqueIdentifier; }
 
+    void copyNonAttributePropertiesFromElement(const Element&) final;
+
     WEBCORE_EXPORT void updateAttributes(std::optional<uint64_t>&& newFileSize, const String& newContentType, const String& newFilename);
     WEBCORE_EXPORT void updateEnclosingImageWithData(const String& contentType, Ref<SharedBuffer>&& data);
 

Modified: trunk/Tools/ChangeLog (238953 => 238954)


--- trunk/Tools/ChangeLog	2018-12-07 18:33:43 UTC (rev 238953)
+++ trunk/Tools/ChangeLog	2018-12-07 18:37:58 UTC (rev 238954)
@@ -1,3 +1,15 @@
+2018-12-07  Wenson Hsieh  <wenson_hs...@apple.com>
+
+        [Attachment Support] Cloned attachment elements lose their unique identifiers
+        https://bugs.webkit.org/show_bug.cgi?id=192483
+
+        Reviewed by Tim Horton.
+
+        Introduce a new API test.
+
+        * TestWebKitAPI/Tests/WebKitCocoa/WKAttachmentTests.mm:
+        (TestWebKitAPI::TEST):
+
 2018-12-06  Jonathan Bedard  <jbed...@apple.com>
 
         Consecutive DumpRenderTree crashes are happening again on WinCairo BuildBots since r238903

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKAttachmentTests.mm (238953 => 238954)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKAttachmentTests.mm	2018-12-07 18:33:43 UTC (rev 238953)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKAttachmentTests.mm	2018-12-07 18:37:58 UTC (rev 238954)
@@ -1488,6 +1488,13 @@
     EXPECT_WK_STREQ("application/zip", pastedArchiveInfo.contentType);
 }
 
+TEST(WKAttachmentTests, AttachmentIdentifierOfClonedAttachment)
+{
+    auto webView = webViewForTestingAttachments();
+    auto attachment = retainPtr([webView synchronouslyInsertAttachmentWithFilename:@"attachment.pdf" contentType:@"application/pdf" data:testPDFData()]);
+    EXPECT_WK_STREQ([attachment uniqueIdentifier], [webView stringByEvaluatingJavaScript:@"document.body.cloneNode(true).querySelector('attachment').uniqueIdentifier"]);
+}
+
 #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