Skip to content

Commit 239abfa

Browse files
[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): git-svn-id: http://svn.webkit.org/repository/webkit/trunk@226097 268f45cc-cd09-0410-ab3c-d52691b4dbfc
1 parent d59e726 commit 239abfa

File tree

6 files changed

+79
-9
lines changed

6 files changed

+79
-9
lines changed

Source/WebCore/ChangeLog

+31
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,34 @@
1+
2017-12-18 Wenson Hsieh <[email protected]>
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+
132
2017-12-18 Chris Dumez <[email protected]>
233

334
Default scope used when registering a service worker is wrong

Source/WebCore/editing/markup.cpp

+12-6
Original file line numberDiff line numberDiff line change
@@ -371,15 +371,19 @@ String StyledMarkupAccumulator::stringValueForRange(const Node& node, const Rang
371371
return nodeValue;
372372
}
373373

374-
void StyledMarkupAccumulator::appendCustomAttributes(StringBuilder& out, const Element&element, Namespaces* namespaces)
374+
void StyledMarkupAccumulator::appendCustomAttributes(StringBuilder& out, const Element& element, Namespaces* namespaces)
375375
{
376376
#if ENABLE(ATTACHMENT_ELEMENT)
377377
if (!is<HTMLAttachmentElement>(element))
378378
return;
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);
385389
UNUSED_PARAM(element);
@@ -764,11 +768,13 @@ Ref<DocumentFragment> createFragmentFromMarkup(Document& document, const String&
764768

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
774780
if (!baseURL.isEmpty() && baseURL != blankURL() && baseURL != document.baseURL())

Source/WebCore/html/HTMLAttachmentElement.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,6 @@ void HTMLAttachmentElement::setFile(RefPtr<File>&& file, UpdateDisplayAttributes
120120
{
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) {
127125
setAttributeWithoutSynchronization(HTMLNames::titleAttr, m_file->name());

Source/WebCore/rendering/HitTestResult.cpp

+6-1
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,12 @@ URL HitTestResult::absoluteAttachmentURL() const
356356
if (!attachmentFile)
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
362367

Tools/ChangeLog

+15
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
2017-12-18 Wenson Hsieh <[email protected]>
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+
116
2017-12-18 Wenson Hsieh <[email protected]>
217

318
[Attachment Support] Support representing pasted or dropped content using attachment elements

Tools/TestWebKitAPI/Tests/WebKitCocoa/WKAttachmentTests.mm

+15
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,11 @@ - (void)waitForAttachmentElementSizeToBecome:(CGSize)expectedSize
224224
}
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
{
229234
return [self stringByEvaluatingJavaScript:[NSString stringWithFormat:@"document.querySelector('%@').getAttribute('%@')", querySelector, attributeName]];
@@ -425,6 +430,8 @@ void platformCopyPNG()
425430

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

430437
TEST(WKAttachmentTests, AttachmentUpdatesWhenInsertingAndDeletingNewline)
@@ -490,6 +497,8 @@ void platformCopyPNG()
490497
[webView expectUpdatesAfterCommand:@"ToggleItalic" withArgument:nil expectedRemovals:@[] expectedInsertions:@[]];
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.
495504
[webView expectUpdatesAfterCommand:@"InsertText" withArgument:@"foo" expectedRemovals:@[attachment.get()] expectedInsertions:@[]];
@@ -511,6 +520,8 @@ void platformCopyPNG()
511520
[webView expectUpdatesAfterCommand:@"InsertUnorderedList" withArgument:nil expectedRemovals:@[] expectedInsertions:@[]];
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

516527
TEST(WKAttachmentTests, AttachmentUpdatesWhenInsertingRichMarkup)
@@ -523,6 +534,8 @@ void platformCopyPNG()
523534
attachment = observer.observer().inserted[0];
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());
528541
[webView stringByEvaluatingJavaScript:@"document.querySelector('attachment').remove()"];
@@ -555,6 +568,8 @@ void platformCopyPNG()
555568
observer.expectAttachmentUpdates(@[], @[attachment.get()]);
556569
}
557570
[attachment expectRequestedDataToBe:testHTMLData()];
571+
EXPECT_FALSE([webView hasAttribute:@"webkitattachmentbloburl" forQuerySelector:@"attachment"]);
572+
EXPECT_FALSE([webView hasAttribute:@"webkitattachmentpath" forQuerySelector:@"attachment"]);
558573
}
559574

560575
TEST(WKAttachmentTests, AttachmentDataForEmptyFile)

0 commit comments

Comments
 (0)