Don't convert pasted content to use blob URL in WebKit1
authorrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 20 Dec 2017 00:07:31 +0000 (00:07 +0000)
committerrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 20 Dec 2017 00:07:31 +0000 (00:07 +0000)
https://bugs.webkit.org/show_bug.cgi?id=180969

Reviewed by Wenson Hsieh.

Source/WebCore:

Turns out that some WebKit1 clients are relying on being able to see the original URLs of the pasted content;
e.g. not storing content referenced by HTTP/HTTPS protocol as opposed to local files.

This patch restores the behavior prior to r223440 and r222839 for WebKit1 clients by overriding resources in
DocumentLoader instead of converting URLs used in the pasted contents by blob URLs. In addition, this patch
disables the pasteboard sanitization and custom data transfer types for WebKit1 clients as the feature poses
a compatibility concern for WebKit1 clients.

Tests: WebKitLegacy.AccessingImageInPastedRTFD
       WebKitLegacy.AccessingImageInPastedWebArchive

* editing/cocoa/WebContentReaderCocoa.mm:
(WebCore::createFragmentAndAddResources):
(WebCore::WebContentReader::readWebArchive):
* page/DeprecatedGlobalSettings.cpp:
(WebCore::DeprecatedGlobalSettings::defaultCustomPasteboardDataEnabled):

Tools:

Added API tests to make sure we can access the images in the pasted content.

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/WebKitCocoa/paste-rtfd.html:
* TestWebKitAPI/Tests/WebKitLegacy/mac: Added.
* TestWebKitAPI/Tests/WebKitLegacy/mac/AccessingPastedImage.mm: Added.
(writeRTFDToPasteboard):
(-[SubresourceForBlobURLFrameLoadDelegate webView:didFinishLoadForFrame:]):
(-[SubresourceForBlobURLFrameLoadDelegate webView:runJavaScriptAlertPanelWithMessage:initiatedByFrame:]):
(TestWebKitAPI::TEST):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@226156 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/editing/cocoa/WebContentReaderCocoa.mm
Source/WebCore/page/DeprecatedGlobalSettings.cpp
Tools/ChangeLog
Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
Tools/TestWebKitAPI/Tests/WebKitCocoa/paste-rtfd.html
Tools/TestWebKitAPI/Tests/WebKitLegacy/mac/AccessingPastedImage.mm [new file with mode: 0644]

index 7d4bff3981c93dcf51b777bc240e63317a7f1e19..23e13ad1cf3e6c19e9410d07ea0c919567840558 100644 (file)
@@ -1,3 +1,27 @@
+2017-12-19  Ryosuke Niwa  <rniwa@webkit.org>
+
+        Don't convert pasted content to use blob URL in WebKit1
+        https://bugs.webkit.org/show_bug.cgi?id=180969
+
+        Reviewed by Wenson Hsieh.
+
+        Turns out that some WebKit1 clients are relying on being able to see the original URLs of the pasted content;
+        e.g. not storing content referenced by HTTP/HTTPS protocol as opposed to local files.
+
+        This patch restores the behavior prior to r223440 and r222839 for WebKit1 clients by overriding resources in
+        DocumentLoader instead of converting URLs used in the pasted contents by blob URLs. In addition, this patch
+        disables the pasteboard sanitization and custom data transfer types for WebKit1 clients as the feature poses
+        a compatibility concern for WebKit1 clients.
+
+        Tests: WebKitLegacy.AccessingImageInPastedRTFD
+               WebKitLegacy.AccessingImageInPastedWebArchive
+
+        * editing/cocoa/WebContentReaderCocoa.mm:
+        (WebCore::createFragmentAndAddResources):
+        (WebCore::WebContentReader::readWebArchive):
+        * page/DeprecatedGlobalSettings.cpp:
+        (WebCore::DeprecatedGlobalSettings::defaultCustomPasteboardDataEnabled):
+
 2017-12-19  Jer Noble  <jer.noble@apple.com>
 
         Playing media elements which call "pause(); play()" will have the play promise rejected.
index 17de1697adcbca34ea6839908d69ac5c68a2cad0..6fb68ac9578f2933b967be7b6d4ddf5e15bb68cb 100644 (file)
@@ -31,6 +31,7 @@
 #import "BlobURL.h"
 #import "CachedResourceLoader.h"
 #import "DOMURL.h"
+#import "DeprecatedGlobalSettings.h"
 #import "Document.h"
 #import "DocumentFragment.h"
 #import "DocumentLoader.h"
@@ -265,6 +266,14 @@ RefPtr<DocumentFragment> createFragmentAndAddResources(Frame& frame, NSAttribute
     if (!fragmentAndResources.fragment)
         return nullptr;
 
+    if (!DeprecatedGlobalSettings::customPasteboardDataEnabled()) {
+        if (DocumentLoader* loader = frame.loader().documentLoader()) {
+            for (auto& resource : fragmentAndResources.resources)
+                loader->addArchiveResource(resource.copyRef());
+        }
+        return WTFMove(fragmentAndResources.fragment);
+    }
+
     HashMap<AtomicString, AtomicString> blobURLMap;
     for (const Ref<ArchiveResource>& subresource : fragmentAndResources.resources) {
         auto blob = Blob::create(subresource->data(), subresource->mimeType());
@@ -366,6 +375,13 @@ bool WebContentReader::readWebArchive(SharedBuffer& buffer)
     });
     if (!result)
         return false;
+    
+    if (!DeprecatedGlobalSettings::customPasteboardDataEnabled()) {
+        fragment = createFragmentFromMarkup(*frame.document(), result->markup, result->mainResource->url(), DisallowScriptingAndPluginContent);
+        if (DocumentLoader* loader = frame.loader().documentLoader())
+            loader->addAllArchiveResources(result->archive.get());
+        return true;
+    }
 
     if (!shouldSanitize()) {
         fragment = createFragmentFromMarkup(*frame.document(), result->markup, result->mainResource->url(), DisallowScriptingAndPluginContent);
index 4afc6fa8ad2dc4bd367057afa624eeb08943b9b6..05bb11df5b1ceaf858754160b633d00b4a9b250c 100644 (file)
@@ -86,6 +86,8 @@ bool DeprecatedGlobalSettings::gCustomPasteboardDataEnabled = false;
 
 bool DeprecatedGlobalSettings::defaultCustomPasteboardDataEnabled()
 {
+    if (!isInWebProcess())
+        return false;
 #if PLATFORM(IOS) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 110300
     return IOSApplication::isMobileSafari() || dyld_get_program_sdk_version() >= DYLD_IOS_VERSION_11_3;
 #elif PLATFORM(MAC) && __MAC_OS_X_VERSION_MAX_ALLOWED >= 101300
index b5367f8a3d1ff402a05a19dbb23fcb157d7df86a..7bd646fa955e053ee2a009967f764b73113b083d 100644 (file)
@@ -1,3 +1,21 @@
+2017-12-19  Ryosuke Niwa  <rniwa@webkit.org>
+
+        Don't convert pasted content to use blob URL in WebKit1
+        https://bugs.webkit.org/show_bug.cgi?id=180969
+
+        Reviewed by Wenson Hsieh.
+
+        Added API tests to make sure we can access the images in the pasted content.
+
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+        * TestWebKitAPI/Tests/WebKitCocoa/paste-rtfd.html:
+        * TestWebKitAPI/Tests/WebKitLegacy/mac: Added.
+        * TestWebKitAPI/Tests/WebKitLegacy/mac/AccessingPastedImage.mm: Added.
+        (writeRTFDToPasteboard):
+        (-[SubresourceForBlobURLFrameLoadDelegate webView:didFinishLoadForFrame:]):
+        (-[SubresourceForBlobURLFrameLoadDelegate webView:runJavaScriptAlertPanelWithMessage:initiatedByFrame:]):
+        (TestWebKitAPI::TEST):
+
 2017-12-19  Daniel Bates  <dabates@apple.com>
 
         Implement InlineTextBox painting using marker subranges
index 70ffd7119a0ba5dc80017de014110b9810b93ebf..0778b05d3eacffa51e9276fc5a905b32c51ab1a3 100644 (file)
                9B7D740F1F8378770006C432 /* paste-rtfd.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 9B7D740E1F8377E60006C432 /* paste-rtfd.html */; };
                9BD4239A1E04BD9800200395 /* AttributedSubstringForProposedRangeWithImage.mm in Sources */ = {isa = PBXBuildFile; fileRef = 9BD423991E04BD9800200395 /* AttributedSubstringForProposedRangeWithImage.mm */; };
                9BD4239C1E04C01C00200395 /* chinese-character-with-image.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 9BD4239B1E04BFD000200395 /* chinese-character-with-image.html */; };
+               9BD5111C1FE8E11600D2B630 /* AccessingPastedImage.mm in Sources */ = {isa = PBXBuildFile; fileRef = 9BD5111B1FE8E11600D2B630 /* AccessingPastedImage.mm */; };
                9BD6D3A21F7B218300BD4962 /* sunset-in-cupertino-100px.tiff in Copy Resources */ = {isa = PBXBuildFile; fileRef = 9BD6D3A11F7B202100BD4962 /* sunset-in-cupertino-100px.tiff */; };
                9BD6D3A31F7B218300BD4962 /* sunset-in-cupertino-200px.png in Copy Resources */ = {isa = PBXBuildFile; fileRef = 9BD6D3A01F7B202000BD4962 /* sunset-in-cupertino-200px.png */; };
                9BD6D3A41F7B218300BD4962 /* sunset-in-cupertino-400px.gif in Copy Resources */ = {isa = PBXBuildFile; fileRef = 9BD6D39F1F7B202000BD4962 /* sunset-in-cupertino-400px.gif */; };
                9B7D740E1F8377E60006C432 /* paste-rtfd.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = "paste-rtfd.html"; sourceTree = "<group>"; };
                9BD423991E04BD9800200395 /* AttributedSubstringForProposedRangeWithImage.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = AttributedSubstringForProposedRangeWithImage.mm; sourceTree = "<group>"; };
                9BD4239B1E04BFD000200395 /* chinese-character-with-image.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "chinese-character-with-image.html"; sourceTree = "<group>"; };
+               9BD5111B1FE8E11600D2B630 /* AccessingPastedImage.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = AccessingPastedImage.mm; sourceTree = "<group>"; };
                9BD6D39E1F7B201E00BD4962 /* sunset-in-cupertino-600px.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = "sunset-in-cupertino-600px.jpg"; sourceTree = "<group>"; };
                9BD6D39F1F7B202000BD4962 /* sunset-in-cupertino-400px.gif */ = {isa = PBXFileReference; lastKnownFileType = image.gif; path = "sunset-in-cupertino-400px.gif"; sourceTree = "<group>"; };
                9BD6D3A01F7B202000BD4962 /* sunset-in-cupertino-200px.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "sunset-in-cupertino-200px.png"; sourceTree = "<group>"; };
                                CD9E292B1C90A71F000BB800 /* RequiresUserActionForPlayback.mm */,
                                51C8E1A41F26AC5400BF731B /* ResourceLoadStatistics.mm */,
                                A180C0F91EE67DF000468F47 /* RunOpenPanel.mm */,
+                               51EB12931FDF050500A5A1BD /* ServiceWorkerBasic.mm */,
                                37BCA61B1B596BA9002012CA /* ShouldOpenExternalURLsInNewWindowActions.mm */,
                                2D9A53AE1B31FA8D0074D5AA /* ShrinkToFit.mm */,
-                               51EB12931FDF050500A5A1BD /* ServiceWorkerBasic.mm */,
                                2DFF7B6C1DA487AF00814614 /* SnapshotStore.mm */,
                                515BE1701D428BD100DD7C68 /* StoreBlobThenDelete.mm */,
                                5CB40B4D1F4B98BE007DC7B9 /* UIDelegate.mm */,
                        path = darwin;
                        sourceTree = "<group>";
                };
+               9BD5111A1FE8E10200D2B630 /* mac */ = {
+                       isa = PBXGroup;
+                       children = (
+                               9BD5111B1FE8E11600D2B630 /* AccessingPastedImage.mm */,
+                       );
+                       path = mac;
+                       sourceTree = "<group>";
+               };
                A13EBB441B87332B00097110 /* WebProcessPlugIn */ = {
                        isa = PBXGroup;
                        children = (
                        isa = PBXGroup;
                        children = (
                                CDC8E4991BC728C000594FEC /* ios */,
+                               9BD5111A1FE8E10200D2B630 /* mac */,
                        );
                        path = WebKitLegacy;
                        sourceTree = "<group>";
                                7C83DEA91D0A590C00FEBCF3 /* CString.cpp in Sources */,
                                7C83DEAD1D0A590C00FEBCF3 /* Deque.cpp in Sources */,
                                1AF7B21F1D6CD14D008C126C /* EnumTraits.cpp in Sources */,
-                               FE05FAED1FDB510E00093230 /* PoisonedRefPtr.cpp in Sources */,
                                AD7C434D1DD2A54E0026888B /* Expected.cpp in Sources */,
                                9310CD381EF708FB0050FFE0 /* Function.cpp in Sources */,
                                6BFD294C1D5E6C1D008EC968 /* HashCountedSet.cpp in Sources */,
                                7C83DEED1D0A590C00FEBCF3 /* MathExtras.cpp in Sources */,
                                7C83DEEF1D0A590C00FEBCF3 /* MD5.cpp in Sources */,
                                7C83DEF11D0A590C00FEBCF3 /* MediaTime.cpp in Sources */,
-                               FE05FAEC1FDB510A00093230 /* PoisonedRef.cpp in Sources */,
                                7C83DEF61D0A590C00FEBCF3 /* MetaAllocator.cpp in Sources */,
                                7C83DEFE1D0A590C00FEBCF3 /* NakedPtr.cpp in Sources */,
                                A57D54F31F338C3600A97AA7 /* NeverDestroyed.cpp in Sources */,
                                7C83DF021D0A590C00FEBCF3 /* OSObjectPtr.cpp in Sources */,
                                7C83DF591D0A590C00FEBCF3 /* ParkingLot.cpp in Sources */,
                                FE05FAEF1FE0645B00093230 /* Poisoned.cpp in Sources */,
+                               FE05FAEC1FDB510A00093230 /* PoisonedRef.cpp in Sources */,
+                               FE05FAED1FDB510E00093230 /* PoisonedRefPtr.cpp in Sources */,
                                53EC25411E96FD87000831B9 /* PriorityQueue.cpp in Sources */,
                                7C83DF131D0A590C00FEBCF3 /* RedBlackTree.cpp in Sources */,
                                7C83DF141D0A590C00FEBCF3 /* Ref.cpp in Sources */,
                                7CCE7EE41A411AE600447C4C /* AboutBlankLoad.cpp in Sources */,
                                7CCE7EB31A411A7E00447C4C /* AcceptsFirstMouse.mm in Sources */,
                                2E205BA41F527746005952DD /* AccessibilityTestsIOS.mm in Sources */,
+                               9BD5111C1FE8E11600D2B630 /* AccessingPastedImage.mm in Sources */,
                                F45B63FE1F19D410009D38B9 /* ActionSheetTests.mm in Sources */,
                                37E7DD641EA06FF2009B396D /* AdditionalReadAccessAllowedURLs.mm in Sources */,
                                7A909A7D1D877480007E10F8 /* AffineTransform.cpp in Sources */,
                                5C0BF8931DD599BD00B00328 /* IsNavigationActionTrusted.mm in Sources */,
                                5C69BDD51F82A7EF000F4F4B /* JavaScriptDuringNavigation.mm in Sources */,
                                7CCE7EAD1A411A3400447C4C /* JavaScriptTest.cpp in Sources */,
-                               51EB12941FDF052500A5A1BD /* ServiceWorkerBasic.mm in Sources */,
                                7CCE7EA51A411A0800447C4C /* JavaScriptTestMac.mm in Sources */,
                                7CCE7EC41A411A7E00447C4C /* JSWrapperForNodeInWebFrame.mm in Sources */,
                                7CCE7F061A411AE600447C4C /* LayoutMilestonesWithAllContentInFrame.cpp in Sources */,
                                7CCE7F121A411AE600447C4C /* ScrollPinningBehaviors.cpp in Sources */,
                                CE06DF9B1E1851F200E570C9 /* SecurityOrigin.cpp in Sources */,
                                5769C50B1D9B0002000847FB /* SerializedCryptoKeyWrap.mm in Sources */,
+                               51EB12941FDF052500A5A1BD /* ServiceWorkerBasic.mm in Sources */,
                                7CCE7ECB1A411A7E00447C4C /* SetAndUpdateCacheModel.mm in Sources */,
                                7CCE7ECC1A411A7E00447C4C /* SetDocumentURI.mm in Sources */,
                                7C83E0521D0A641800FEBCF3 /* SharedBuffer.cpp in Sources */,
index 2bdb24f061522d952a52c5c5940959c2b8a8a81f..1e53e8c5f4dc10b6e465a07c40498c30ae53e31e 100644 (file)
@@ -24,7 +24,10 @@ editor.addEventListener('paste', (event) => {
 
 function notifyLoaded()
 {
-    webkit.messageHandlers.testHandler.postMessage('loaded');
+    if (window.webkit)
+        webkit.messageHandlers.testHandler.postMessage('loaded');
+    else
+        alert('loaded');
 }
 
 </script>
diff --git a/Tools/TestWebKitAPI/Tests/WebKitLegacy/mac/AccessingPastedImage.mm b/Tools/TestWebKitAPI/Tests/WebKitLegacy/mac/AccessingPastedImage.mm
new file mode 100644 (file)
index 0000000..503c224
--- /dev/null
@@ -0,0 +1,158 @@
+/*
+ * Copyright (C) 2017 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "config.h"
+#import "PlatformUtilities.h"
+#import "WTFStringUtilities.h"
+
+#import <WebKit/DOM.h>
+#import <WebKit/WebViewPrivate.h>
+
+#if PLATFORM(IOS)
+#include <MobileCoreServices/MobileCoreServices.h>
+#endif
+
+#if PLATFORM(MAC)
+
+static void writeRTFDToPasteboard(NSData *data)
+{
+    [[NSPasteboard generalPasteboard] declareTypes:@[NSRTFDPboardType] owner:nil];
+    [[NSPasteboard generalPasteboard] setData:data forType:NSRTFDPboardType];
+}
+#else
+
+@interface NSAttributedString ()
+- (id)initWithRTF:(NSData *)data documentAttributes:(NSDictionary **)dict;
+- (id)initWithRTFD:(NSData *)data documentAttributes:(NSDictionary **)dict;
+- (NSData *)RTFFromRange:(NSRange)range documentAttributes:(NSDictionary *)dict;
+- (NSData *)RTFDFromRange:(NSRange)range documentAttributes:(NSDictionary *)dict;
+- (BOOL)containsAttachments;
+@end
+
+static void writeRTFDToPasteboard(NSData *data)
+{
+    [[UIPasteboard generalPasteboard] setItems:@[@{ (NSString *)kUTTypeFlatRTFD : data}]];
+}
+#endif
+
+@interface SubresourceForBlobURLFrameLoadDelegate : NSObject <WebFrameLoadDelegate, WebUIDelegate> {
+}
+@end
+
+static bool didFinishLoad = false;
+static bool didAlert = false;
+
+@implementation SubresourceForBlobURLFrameLoadDelegate
+
+- (void)webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame
+{
+    didFinishLoad = true;
+}
+
+- (void)webView:(WebView *)sender runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WebFrame *)frame
+{
+    didAlert = true;
+}
+
+@end
+
+namespace TestWebKitAPI {
+
+TEST(WebKitLegacy, AccessingImageInPastedRTFD)
+{
+    auto webView = adoptNS([[WebView alloc] initWithFrame:NSMakeRect(0, 0, 400, 400) frameName:nil groupName:nil]);
+    auto delegate = adoptNS([[SubresourceForBlobURLFrameLoadDelegate alloc] init]);
+    [webView.get() setFrameLoadDelegate:delegate.get()];
+    [webView.get() setUIDelegate:delegate.get()];
+
+    auto *mainFrame = webView.get().mainFrame;
+    [[webView.get() mainFrame] loadRequest:[NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"paste-rtfd" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]]];
+    Util::run(&didFinishLoad);
+    [webView.get() setEditable:YES];
+
+    auto *pngData = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"sunset-in-cupertino-200px" ofType:@"png" inDirectory:@"TestWebKitAPI.resources"]];
+    auto attachment = adoptNS([[NSTextAttachment alloc] initWithData:pngData ofType:(NSString *)kUTTypePNG]);
+    NSAttributedString *string = [NSAttributedString attributedStringWithAttachment:attachment.get()];
+    NSData *RTFDData = [string RTFDFromRange:NSMakeRange(0, [string length]) documentAttributes:@{ }];
+
+    writeRTFDToPasteboard(RTFDData);
+    [webView paste:nil];
+    Util::run(&didAlert);
+
+    DOMDocument *document = [mainFrame DOMDocument];
+    DOMElement *documentElement = document.documentElement;
+    DOMHTMLImageElement *image = (DOMHTMLImageElement *)[documentElement querySelector:@"img"];
+    NSURL *url = image.absoluteImageURL;
+
+    EXPECT_EQ(200, image.width);
+    EXPECT_WK_STREQ("webkit-fake-url", url.scheme);
+
+    WebResource *webResource = [mainFrame.dataSource subresourceForURL:url];
+    EXPECT_TRUE(webResource);
+    EXPECT_TRUE(webResource.data);
+    EXPECT_WK_STREQ("image/png", webResource.MIMEType);
+}
+
+TEST(WebKitLegacy, AccessingImageInPastedWebArchive)
+{
+    auto sourceWebView = adoptNS([[WebView alloc] initWithFrame:NSMakeRect(0, 0, 400, 400) frameName:nil groupName:nil]);
+    auto destinationWebView = adoptNS([[WebView alloc] initWithFrame:NSMakeRect(0, 0, 400, 400) frameName:nil groupName:nil]);
+    auto delegate = adoptNS([[SubresourceForBlobURLFrameLoadDelegate alloc] init]);
+    [sourceWebView.get() setFrameLoadDelegate:delegate.get()];
+    [sourceWebView.get() setUIDelegate:delegate.get()];
+    [destinationWebView.get() setFrameLoadDelegate:delegate.get()];
+    [destinationWebView.get() setUIDelegate:delegate.get()];
+
+    [[sourceWebView.get() mainFrame] loadRequest:[NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"image-and-contenteditable" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]]];
+    Util::run(&didFinishLoad);
+    [sourceWebView.get() setEditable:YES];
+
+    didFinishLoad = false;
+    [[destinationWebView.get() mainFrame] loadRequest:[NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"paste-rtfd" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]]];
+    Util::run(&didFinishLoad);
+    [destinationWebView.get() setEditable:YES];
+
+    [sourceWebView stringByEvaluatingJavaScriptFromString:@"document.body.focus(); document.execCommand('selectAll');"];
+    [sourceWebView copy:nil];
+
+    [destinationWebView paste:nil];
+    Util::run(&didAlert);
+
+    auto *mainFrame = destinationWebView.get().mainFrame;
+    DOMDocument *document = [mainFrame DOMDocument];
+    DOMElement *documentElement = document.documentElement;
+    DOMHTMLImageElement *image = (DOMHTMLImageElement *)[documentElement querySelector:@"img"];
+    NSURL *url = image.absoluteImageURL;
+
+    EXPECT_EQ(200, image.width);
+    EXPECT_WK_STREQ("file", url.scheme);
+
+    WebResource *webResource = [mainFrame.dataSource subresourceForURL:url];
+    EXPECT_TRUE(webResource);
+    EXPECT_TRUE(webResource.data);
+    EXPECT_WK_STREQ("image/png", webResource.MIMEType);
+}
+
+} // namespace TestWebKitAPI