Changeset 226097 in webkit


Ignore:
Timestamp:
Dec 18, 2017 9:38:47 PM (6 years ago)
Author:
Wenson Hsieh
Message:

[Attachment Support] The 'webkitattachmentbloburl' attribute should not persist after markup serialization
https://bugs.webkit.org/show_bug.cgi?id=180924
<rdar://problem/36099093>

Reviewed by Tim Horton.

Source/WebCore:

Work towards dragging Blob-backed attachment elements as files on iOS and Mac. It doesn't make sense for the
attachment blob URL to stick around on the element after markup serialization, so this patch removes logic that
eagerly sets the blob URL upon setting an attachment's File. Instead, we just append this attribute when
generating markup.

This patch also augments existing WKAttachmentTests to ensure that these attributes are not present.

  • editing/markup.cpp:

(WebCore::StyledMarkupAccumulator::appendCustomAttributes):
(WebCore::createFragmentFromMarkup):

  • html/HTMLAttachmentElement.cpp:

(WebCore::HTMLAttachmentElement::setFile):

  • rendering/HitTestResult.cpp:

Fixes a related issue where an attachment is backed by Blob data (and not a file path) would specify "file:///"
as its attachment file path in DragController when starting a drag. Instead, if there is no file path, fall back
to the blob URL.

This will be tested in a future patch once a WK2 dragging simulator for Mac is implemented, and support for
dragging out Blob-backed attachments as (platform) files is implemented.

(WebCore::HitTestResult::absoluteAttachmentURL const):

Tools:

Tweaks some existing tests to check that temporary attachment serialization attributes don't stick around on the
attachment elements.

  • TestWebKitAPI/Tests/WebKitCocoa/WKAttachmentTests.mm:

(-[TestWKWebView hasAttribute:forQuerySelector:]):
(TestWebKitAPI::TEST):

Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r226096 r226097  
     12017-12-18  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        [Attachment Support] The 'webkitattachmentbloburl' attribute should not persist after markup serialization
     4        https://bugs.webkit.org/show_bug.cgi?id=180924
     5        <rdar://problem/36099093>
     6
     7        Reviewed by Tim Horton.
     8
     9        Work towards dragging Blob-backed attachment elements as files on iOS and Mac. It doesn't make sense for the
     10        attachment blob URL to stick around on the element after markup serialization, so this patch removes logic that
     11        eagerly sets the blob URL upon setting an attachment's File. Instead, we just append this attribute when
     12        generating markup.
     13
     14        This patch also augments existing WKAttachmentTests to ensure that these attributes are not present.
     15
     16        * editing/markup.cpp:
     17        (WebCore::StyledMarkupAccumulator::appendCustomAttributes):
     18        (WebCore::createFragmentFromMarkup):
     19        * html/HTMLAttachmentElement.cpp:
     20        (WebCore::HTMLAttachmentElement::setFile):
     21        * rendering/HitTestResult.cpp:
     22
     23        Fixes a related issue where an attachment is backed by Blob data (and not a file path) would specify "file:///"
     24        as its attachment file path in DragController when starting a drag. Instead, if there is no file path, fall back
     25        to the blob URL.
     26
     27        This will be tested in a future patch once a WK2 dragging simulator for Mac is implemented, and support for
     28        dragging out Blob-backed attachments as (platform) files is implemented.
     29
     30        (WebCore::HitTestResult::absoluteAttachmentURL const):
     31
    1322017-12-18  Chris Dumez  <cdumez@apple.com>
    233
  • trunk/Source/WebCore/editing/markup.cpp

    r224755 r226097  
    372372}
    373373
    374 void StyledMarkupAccumulator::appendCustomAttributes(StringBuilder& out, const Element&element, Namespaces* namespaces)
     374void StyledMarkupAccumulator::appendCustomAttributes(StringBuilder& out, const Element& element, Namespaces* namespaces)
    375375{
    376376#if ENABLE(ATTACHMENT_ELEMENT)
     
    379379   
    380380    const HTMLAttachmentElement& attachment = downcast<HTMLAttachmentElement>(element);
    381     if (attachment.file())
    382         appendAttribute(out, element, Attribute(webkitattachmentpathAttr, attachment.file()->path()), namespaces);
     381    if (auto* file = attachment.file()) {
     382        // These attributes are only intended for File deserialization, and are removed from the generated attachment
     383        // element after we've deserialized and set its backing File.
     384        appendAttribute(out, element, { webkitattachmentpathAttr, file->path() }, namespaces);
     385        appendAttribute(out, element, { webkitattachmentbloburlAttr, { file->url() }}, namespaces);
     386    }
    383387#else
    384388    UNUSED_PARAM(out);
     
    765769    for (auto& attachment : attachments) {
    766770        auto attachmentPath = attachment->attachmentPath();
    767         if (attachmentPath.isEmpty())
    768             attachment->setFile(File::deserialize({ }, attachment->blobURL(), attachment->attachmentType(), attachment->attachmentTitle()));
    769         else
     771        auto blobURL = attachment->blobURL();
     772        if (!attachmentPath.isEmpty())
    770773            attachment->setFile(File::create(attachmentPath));
     774        else if (!blobURL.isEmpty())
     775            attachment->setFile(File::deserialize({ }, blobURL, attachment->attachmentType(), attachment->attachmentTitle()));
    771776        attachment->removeAttribute(webkitattachmentpathAttr);
     777        attachment->removeAttribute(webkitattachmentbloburlAttr);
    772778    }
    773779#endif
  • trunk/Source/WebCore/html/HTMLAttachmentElement.cpp

    r226085 r226097  
    121121    m_file = WTFMove(file);
    122122
    123     setAttributeWithoutSynchronization(HTMLNames::webkitattachmentbloburlAttr, m_file ? m_file->url() : emptyString());
    124 
    125123    if (updateAttributes == UpdateDisplayAttributes::Yes) {
    126124        if (m_file) {
  • trunk/Source/WebCore/rendering/HitTestResult.cpp

    r225837 r226097  
    357357        return URL();
    358358   
    359     return URL::fileURLWithFileSystemPath(attachmentFile->path());
     359    auto filepath = attachmentFile->path();
     360    if (!filepath.isEmpty())
     361        return URL::fileURLWithFileSystemPath(filepath);
     362
     363    ASSERT(attachmentFile->url().protocolIsBlob());
     364    return attachmentFile->url();
    360365}
    361366#endif
  • trunk/Tools/ChangeLog

    r226093 r226097  
     12017-12-18  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        [Attachment Support] The 'webkitattachmentbloburl' attribute should not persist after markup serialization
     4        https://bugs.webkit.org/show_bug.cgi?id=180924
     5        <rdar://problem/36099093>
     6
     7        Reviewed by Tim Horton.
     8
     9        Tweaks some existing tests to check that temporary attachment serialization attributes don't stick around on the
     10        attachment elements.
     11
     12        * TestWebKitAPI/Tests/WebKitCocoa/WKAttachmentTests.mm:
     13        (-[TestWKWebView hasAttribute:forQuerySelector:]):
     14        (TestWebKitAPI::TEST):
     15
    1162017-12-18  Wenson Hsieh  <wenson_hsieh@apple.com>
    217
  • trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKAttachmentTests.mm

    r226093 r226097  
    225225}
    226226
     227- (BOOL)hasAttribute:(NSString *)attributeName forQuerySelector:(NSString *)querySelector
     228{
     229    return [self stringByEvaluatingJavaScript:[NSString stringWithFormat:@"document.querySelector('%@').hasAttribute('%@')", querySelector, attributeName]].boolValue;
     230}
     231
    227232- (NSString *)valueOfAttribute:(NSString *)attributeName forQuerySelector:(NSString *)querySelector
    228233{
     
    426431    [firstAttachment expectRequestedDataToBe:nil];
    427432    [secondAttachment expectRequestedDataToBe:testImageData()];
     433    EXPECT_FALSE([webView hasAttribute:@"webkitattachmentbloburl" forQuerySelector:@"attachment"]);
     434    EXPECT_FALSE([webView hasAttribute:@"webkitattachmentpath" forQuerySelector:@"attachment"]);
    428435}
    429436
     
    491498    [webView expectUpdatesAfterCommand:@"ToggleUnderline" withArgument:nil expectedRemovals:@[] expectedInsertions:@[]];
    492499    [attachment expectRequestedDataToBe:testHTMLData()];
     500    EXPECT_FALSE([webView hasAttribute:@"webkitattachmentbloburl" forQuerySelector:@"attachment"]);
     501    EXPECT_FALSE([webView hasAttribute:@"webkitattachmentpath" forQuerySelector:@"attachment"]);
    493502
    494503    // Inserting text should delete the current selection, removing the attachment in the process.
     
    512521    [webView expectUpdatesAfterCommand:@"InsertUnorderedList" withArgument:nil expectedRemovals:@[] expectedInsertions:@[]];
    513522    [attachment expectRequestedDataToBe:testHTMLData()];
     523    EXPECT_FALSE([webView hasAttribute:@"webkitattachmentbloburl" forQuerySelector:@"attachment"]);
     524    EXPECT_FALSE([webView hasAttribute:@"webkitattachmentpath" forQuerySelector:@"attachment"]);
    514525}
    515526
     
    524535        observer.expectAttachmentUpdates(@[ ], @[attachment.get()]);
    525536    }
     537    EXPECT_FALSE([webView hasAttribute:@"webkitattachmentbloburl" forQuerySelector:@"attachment"]);
     538    EXPECT_FALSE([webView hasAttribute:@"webkitattachmentpath" forQuerySelector:@"attachment"]);
    526539    {
    527540        ObserveAttachmentUpdatesForScope observer(webView.get());
     
    556569    }
    557570    [attachment expectRequestedDataToBe:testHTMLData()];
     571    EXPECT_FALSE([webView hasAttribute:@"webkitattachmentbloburl" forQuerySelector:@"attachment"]);
     572    EXPECT_FALSE([webView hasAttribute:@"webkitattachmentpath" forQuerySelector:@"attachment"]);
    558573}
    559574
Note: See TracChangeset for help on using the changeset viewer.