Skip to content

Commit 72ce720

Browse files
[Attachment Support] Don't Blob-convert images and attachments with https:, http: or data: urls
https://bugs.webkit.org/show_bug.cgi?id=181143 <rdar://problem/36200381> Reviewed by Tim Horton. Source/WebCore: Clients such as Mail would expect pasting or dropping an image with src="https://.../" to result in the source URL being preserved (i.e. staying as remote images) instead of creating image attachments out of them. This patch hooks into the shouldConvertToBlob() check added in r226272 so that it applies to attachment element replacement as well. Test: WKAttachmentTests.DoNotInsertDataURLImagesAsAttachments * editing/cocoa/WebContentReaderCocoa.mm: (WebCore::shouldConvertToBlob): (WebCore::replaceRichContentWithAttachments): Tools: Add a new API test to ensure that a copied image with a data URL does not get pasted as an attachment when attachment elements are enabled. * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * TestWebKitAPI/Tests/WebKitCocoa/WKAttachmentTests.mm: (TestWebKitAPI::TEST): git-svn-id: http://svn.webkit.org/repository/webkit/trunk@226340 268f45cc-cd09-0410-ab3c-d52691b4dbfc
1 parent 829d81e commit 72ce720

File tree

6 files changed

+74
-10
lines changed

6 files changed

+74
-10
lines changed

Source/WebCore/ChangeLog

+19
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
1+
2018-01-02 Wenson Hsieh <[email protected]>
2+
3+
[Attachment Support] Don't Blob-convert images and attachments with https:, http: or data: urls
4+
https://bugs.webkit.org/show_bug.cgi?id=181143
5+
<rdar://problem/36200381>
6+
7+
Reviewed by Tim Horton.
8+
9+
Clients such as Mail would expect pasting or dropping an image with src="https://..." to result in the source
10+
URL being preserved (i.e. staying as remote images) instead of creating image attachments out of them. This
11+
patch hooks into the shouldConvertToBlob() check added in r226272 so that it applies to attachment element
12+
replacement as well.
13+
14+
Test: WKAttachmentTests.DoNotInsertDataURLImagesAsAttachments
15+
16+
* editing/cocoa/WebContentReaderCocoa.mm:
17+
(WebCore::shouldConvertToBlob):
18+
(WebCore::replaceRichContentWithAttachments):
19+
120
2018-01-02 Brady Eidson <[email protected]>
221

322
Identify MessagePorts by a globally unique MessagePortIdentifier.

Source/WebCore/editing/cocoa/WebContentReaderCocoa.mm

+11-7
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,12 @@ static FragmentAndResources createFragment(Frame& frame, NSAttributedString *str
175175
bool m_didDisableImage { false };
176176
};
177177

178+
179+
static bool shouldConvertToBlob(const URL& url)
180+
{
181+
return !(url.protocolIsInHTTPFamily() || url.protocolIsData());
182+
}
183+
178184
static bool shouldReplaceRichContentWithAttachments()
179185
{
180186
#if ENABLE(ATTACHMENT_ELEMENT)
@@ -217,8 +223,11 @@ static void replaceRichContentWithAttachments(DocumentFragment& fragment, const
217223

218224
// FIXME: Handle resources in subframe archives.
219225
HashMap<AtomicString, Ref<Blob>> urlToBlobMap;
220-
for (const Ref<ArchiveResource>& subresource : subresources)
221-
urlToBlobMap.set(subresource->url().string(), Blob::create(subresource->data(), subresource->mimeType()));
226+
for (const Ref<ArchiveResource>& subresource : subresources) {
227+
auto& url = subresource->url();
228+
if (shouldConvertToBlob(url))
229+
urlToBlobMap.set(url.string(), Blob::create(subresource->data(), subresource->mimeType()));
230+
}
222231

223232
Vector<Ref<Element>> elementsToRemove;
224233
Vector<AttachmentReplacementInfo> attachmentReplacementInfo;
@@ -353,11 +362,6 @@ static String markupForFragmentInDocument(Ref<DocumentFragment>&& fragment, Docu
353362
return createMarkup(range.get(), nullptr, AnnotateForInterchange, false, ResolveNonLocalURLs);
354363
}
355364

356-
static bool shouldConvertToBlob(const URL& url)
357-
{
358-
return !(url.protocolIsInHTTPFamily() || url.protocolIsData());
359-
}
360-
361365
static String sanitizeMarkupWithArchive(Document& destinationDocument, MarkupAndArchive& markupAndArchive, const std::function<bool(const String)>& canShowMIMETypeAsHTML)
362366
{
363367
auto page = createPageForSanitizingWebContent();

Tools/ChangeLog

+15
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
2018-01-02 Wenson Hsieh <[email protected]>
2+
3+
[Attachment Support] Don't Blob-convert images and attachments with https:, http: or data: urls
4+
https://bugs.webkit.org/show_bug.cgi?id=181143
5+
<rdar://problem/36200381>
6+
7+
Reviewed by Tim Horton.
8+
9+
Add a new API test to ensure that a copied image with a data URL does not get pasted as an attachment when
10+
attachment elements are enabled.
11+
12+
* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
13+
* TestWebKitAPI/Tests/WebKitCocoa/WKAttachmentTests.mm:
14+
(TestWebKitAPI::TEST):
15+
116
2018-01-02 Jiewen Tan <[email protected]>
217

318
Update Credential Management API for WebAuthentication

Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj

+7-3
Original file line numberDiff line numberDiff line change
@@ -738,6 +738,7 @@
738738
F486B1D01F67952300F34BDD /* DataTransfer-setDragImage.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = F486B1CF1F6794FF00F34BDD /* DataTransfer-setDragImage.html */; };
739739
F4A32EC41F05F3850047C544 /* dragstart-change-selection-offscreen.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = F4A32EC31F05F3780047C544 /* dragstart-change-selection-offscreen.html */; };
740740
F4A32ECB1F0643370047C544 /* contenteditable-in-iframe.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = F4A32ECA1F0642F40047C544 /* contenteditable-in-iframe.html */; };
741+
F4A9202F1FEE34E900F59590 /* apple-data-url.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = F4A9202E1FEE34C800F59590 /* apple-data-url.html */; };
741742
F4AB578A1F65165400DB0DA1 /* custom-draggable-div.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = F4AB57891F65164B00DB0DA1 /* custom-draggable-div.html */; };
742743
F4B825D81EF4DBFB006E417F /* compressed-files.zip in Copy Resources */ = {isa = PBXBuildFile; fileRef = F4B825D61EF4DBD4006E417F /* compressed-files.zip */; };
743744
F4BFA68E1E4AD08000154298 /* DragAndDropPasteboardTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = F4BFA68C1E4AD08000154298 /* DragAndDropPasteboardTests.mm */; };
@@ -833,6 +834,7 @@
833834
1C2B81871C8925A000A5529F /* Ahem.ttf in Copy Resources */,
834835
1A63479F183D72A4005B1707 /* all-content-in-one-iframe.html in Copy Resources */,
835836
C25CCA0D1E5141840026CB8A /* AllAhem.svg in Copy Resources */,
837+
F4A9202F1FEE34E900F59590 /* apple-data-url.html in Copy Resources */,
836838
F46A095A1ED8A6E600D4AA55 /* apple.gif in Copy Resources */,
837839
5C9E59411D3EB5AC00E3C62E /* ApplicationCache.db in Copy Resources */,
838840
5C9E59421D3EB5AC00E3C62E /* ApplicationCache.db-shm in Copy Resources */,
@@ -1841,6 +1843,7 @@
18411843
F493247C1F44DF8D006F4336 /* UIKitSPI.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = UIKitSPI.h; sourceTree = "<group>"; };
18421844
F4A32EC31F05F3780047C544 /* dragstart-change-selection-offscreen.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = "dragstart-change-selection-offscreen.html"; sourceTree = "<group>"; };
18431845
F4A32ECA1F0642F40047C544 /* contenteditable-in-iframe.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = "contenteditable-in-iframe.html"; sourceTree = "<group>"; };
1846+
F4A9202E1FEE34C800F59590 /* apple-data-url.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "apple-data-url.html"; sourceTree = "<group>"; };
18441847
F4AB57891F65164B00DB0DA1 /* custom-draggable-div.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "custom-draggable-div.html"; sourceTree = "<group>"; };
18451848
F4B825D61EF4DBD4006E417F /* compressed-files.zip */ = {isa = PBXFileReference; lastKnownFileType = archive.zip; path = "compressed-files.zip"; sourceTree = "<group>"; };
18461849
F4BFA68C1E4AD08000154298 /* DragAndDropPasteboardTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DragAndDropPasteboardTests.mm; sourceTree = "<group>"; };
@@ -2297,6 +2300,7 @@
22972300
isa = PBXGroup;
22982301
children = (
22992302
C25CCA0C1E5140E50026CB8A /* AllAhem.svg */,
2303+
F4A9202E1FEE34C800F59590 /* apple-data-url.html */,
23002304
F47D30EB1ED28619000482E1 /* apple.gif */,
23012305
5C9E593E1D3EB1DE00E3C62E /* ApplicationCache.db */,
23022306
5C9E593F1D3EB1DE00E3C62E /* ApplicationCache.db-shm */,
@@ -3220,7 +3224,6 @@
32203224
7C83DED41D0A590C00FEBCF3 /* HashSet.cpp in Sources */,
32213225
7C83DEE01D0A590C00FEBCF3 /* IntegerToStringConversion.cpp in Sources */,
32223226
7A0509411FB9F06400B33FB8 /* JSONValue.cpp in Sources */,
3223-
FE05FB061FE84FB700093230 /* PoisonedUniquePtr.cpp in Sources */,
32243227
531C1D8E1DF8EF72006E979F /* LEBDecoder.cpp in Sources */,
32253228
A57D54F91F3397B400A97AA7 /* LifecycleLogger.cpp in Sources */,
32263229
93E2C5551FD3204100E1DF6A /* LineEnding.cpp in Sources */,
@@ -3240,6 +3243,9 @@
32403243
FE05FAEF1FE0645B00093230 /* Poisoned.cpp in Sources */,
32413244
FE05FAEC1FDB510A00093230 /* PoisonedRef.cpp in Sources */,
32423245
FE05FAED1FDB510E00093230 /* PoisonedRefPtr.cpp in Sources */,
3246+
FE05FB061FE84FB700093230 /* PoisonedUniquePtr.cpp in Sources */,
3247+
FEC8F4EB1FE9F5AF0056FD8A /* PoisonedUniquePtrForNonTriviallyDestructibleArrays.cpp in Sources */,
3248+
FEC8F4E71FE9C9050056FD8A /* PoisonedUniquePtrForTriviallyDestructibleArrays.cpp in Sources */,
32433249
53EC25411E96FD87000831B9 /* PriorityQueue.cpp in Sources */,
32443250
7C83DF131D0A590C00FEBCF3 /* RedBlackTree.cpp in Sources */,
32453251
7C83DF141D0A590C00FEBCF3 /* Ref.cpp in Sources */,
@@ -3257,7 +3263,6 @@
32573263
7C83DF321D0A590C00FEBCF3 /* StringBuilder.cpp in Sources */,
32583264
7CD4C26E1E2C0E6E00929470 /* StringConcatenate.cpp in Sources */,
32593265
7C83DF361D0A590C00FEBCF3 /* StringHasher.cpp in Sources */,
3260-
FEC8F4E71FE9C9050056FD8A /* PoisonedUniquePtrForTriviallyDestructibleArrays.cpp in Sources */,
32613266
7C83DF371D0A590C00FEBCF3 /* StringImpl.cpp in Sources */,
32623267
7C83DF381D0A590C00FEBCF3 /* StringOperators.cpp in Sources */,
32633268
7C83DF3A1D0A590C00FEBCF3 /* StringView.cpp in Sources */,
@@ -3266,7 +3271,6 @@
32663271
9329AA291DE3F81E003ABD07 /* TextBreakIterator.cpp in Sources */,
32673272
E3DEA8111F0A589000CBC2E8 /* ThreadGroup.cpp in Sources */,
32683273
E38A0D351FD50CC300E98C8B /* Threading.cpp in Sources */,
3269-
FEC8F4EB1FE9F5AF0056FD8A /* PoisonedUniquePtrForNonTriviallyDestructibleArrays.cpp in Sources */,
32703274
5311BD5E1EA9490E00525281 /* ThreadMessages.cpp in Sources */,
32713275
0F2C20B81DCD545000542D9E /* Time.cpp in Sources */,
32723276
7C83E03B1D0A602700FEBCF3 /* UtilitiesCocoa.mm in Sources */,

Tools/TestWebKitAPI/Tests/WebKitCocoa/WKAttachmentTests.mm

+19
Original file line numberDiff line numberDiff line change
@@ -893,6 +893,25 @@ void platformCopyPNG()
893893
}
894894
}
895895

896+
TEST(WKAttachmentTests, DoNotInsertDataURLImagesAsAttachments)
897+
{
898+
auto webContentSourceView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)]);
899+
[webContentSourceView synchronouslyLoadTestPageNamed:@"apple-data-url"];
900+
[webContentSourceView selectAll:nil];
901+
[webContentSourceView _synchronouslyExecuteEditCommand:@"Copy" argument:nil];
902+
903+
auto webView = webViewForTestingAttachments();
904+
{
905+
ObserveAttachmentUpdatesForScope observer(webView.get());
906+
[webView _synchronouslyExecuteEditCommand:@"Paste" argument:nil];
907+
EXPECT_EQ(0U, observer.observer().inserted.count);
908+
}
909+
910+
EXPECT_FALSE([webView stringByEvaluatingJavaScript:@"Boolean(document.querySelector('attachment'))"].boolValue);
911+
EXPECT_EQ(1990, [webView stringByEvaluatingJavaScript:@"document.querySelector('img').src.length"].integerValue);
912+
EXPECT_WK_STREQ("This is an apple", [webView stringByEvaluatingJavaScript:@"document.body.textContent"]);
913+
}
914+
896915
#pragma mark - Platform-specific tests
897916

898917
#if PLATFORM(MAC)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<body>
2+
This is an apple<img src="data:image/gif;base64,R0lGODlhNABAAMQfAGJiYvLz9ImKitvb2/39/cnJyaSkpOPj49TU1MHBwbW1terq7Lu7u/X19uXm5+3u7+fo6eDg4e/w8t7e3/n5+RcXF87Oz/f398fHx9fX16+vr9HR0fDw8Pj4+MzMzAAAACH5BAEAAB8ALAAAAAA0AEAAQAX/4CeOZGme5iFUlYC+cCwKD7FAxxElAiTDnATAcCEYj8aABiBIDCIbjQCgqBEojUCjQSEEpoXTAUCQLB4PiZoTaG/fjcuFgj1kBrnIZDLoDzIIgRsTAgYmBk8TEQ4OEGdpbBQLDAUQEA55e32AGxsWHh4FBRgJCQgFAhQoCwIDlgsSFxyFOnt8foAInp+jpQkMwArCGsQaCg0KBgEoDwAAHoHRgroW1aEYpL7A28LDxcUGGgalhi8IAAgYoOvrn5/soL2lwcThEBQAAz/7JxYAXVcCPNjggp/BEwIYOHNmwMHBErMSEMgCR47FC3EwwnlzocOFBxMy3NHkp88EBwU///gjcKCRo0cPOEhwM6fDgUGWMuHKtQvUBgBhThhQ4CBCSwhoJDToQKxljlq4BPHCNo+bggXEXnwZMNMAupJ/ckm9RvUXg27dvqllkEFADxMQAKirZs3Du1CiRpX1ZfasN3EGAlsYIIADv3MCDnBowKEAQwSGSRzAMEVABIwTmCB4yHkEQQMACQDY0LmzgAlXZF0ac6D0QwUJOAxAkMArgAyuT3gQ5zYwBh8jBmhgoG9EBgYG3BbSQHpfBAEKjHSYTt3jxQ4BH3DB2EaLnAYLIgC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