Title: [226156] trunk
Revision
226156
Author
[email protected]
Date
2017-12-19 16:07:31 -0800 (Tue, 19 Dec 2017)

Log Message

Don't convert pasted content to use blob URL in WebKit1
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):

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (226155 => 226156)


--- trunk/Source/WebCore/ChangeLog	2017-12-20 00:06:43 UTC (rev 226155)
+++ trunk/Source/WebCore/ChangeLog	2017-12-20 00:07:31 UTC (rev 226156)
@@ -1,3 +1,27 @@
+2017-12-19  Ryosuke Niwa  <[email protected]>
+
+        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  <[email protected]>
 
         Playing media elements which call "pause(); play()" will have the play promise rejected.

Modified: trunk/Source/WebCore/editing/cocoa/WebContentReaderCocoa.mm (226155 => 226156)


--- trunk/Source/WebCore/editing/cocoa/WebContentReaderCocoa.mm	2017-12-20 00:06:43 UTC (rev 226155)
+++ trunk/Source/WebCore/editing/cocoa/WebContentReaderCocoa.mm	2017-12-20 00:07:31 UTC (rev 226156)
@@ -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 @@
     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 @@
     });
     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);

Modified: trunk/Source/WebCore/page/DeprecatedGlobalSettings.cpp (226155 => 226156)


--- trunk/Source/WebCore/page/DeprecatedGlobalSettings.cpp	2017-12-20 00:06:43 UTC (rev 226155)
+++ trunk/Source/WebCore/page/DeprecatedGlobalSettings.cpp	2017-12-20 00:07:31 UTC (rev 226156)
@@ -86,6 +86,8 @@
 
 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

Modified: trunk/Tools/ChangeLog (226155 => 226156)


--- trunk/Tools/ChangeLog	2017-12-20 00:06:43 UTC (rev 226155)
+++ trunk/Tools/ChangeLog	2017-12-20 00:07:31 UTC (rev 226156)
@@ -1,3 +1,21 @@
+2017-12-19  Ryosuke Niwa  <[email protected]>
+
+        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  <[email protected]>
 
         Implement InlineTextBox painting using marker subranges

Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (226155 => 226156)


--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2017-12-20 00:06:43 UTC (rev 226155)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2017-12-20 00:07:31 UTC (rev 226156)
@@ -570,6 +570,7 @@
 		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 */; };
@@ -1567,6 +1568,7 @@
 		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>"; };
@@ -2102,9 +2104,9 @@
 				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 */,
@@ -2270,6 +2272,14 @@
 			path = darwin;
 			sourceTree = "<group>";
 		};
+		9BD5111A1FE8E10200D2B630 /* mac */ = {
+			isa = PBXGroup;
+			children = (
+				9BD5111B1FE8E11600D2B630 /* AccessingPastedImage.mm */,
+			);
+			path = mac;
+			sourceTree = "<group>";
+		};
 		A13EBB441B87332B00097110 /* WebProcessPlugIn */ = {
 			isa = PBXGroup;
 			children = (
@@ -2980,6 +2990,7 @@
 			isa = PBXGroup;
 			children = (
 				CDC8E4991BC728C000594FEC /* ios */,
+				9BD5111A1FE8E10200D2B630 /* mac */,
 			);
 			path = WebKitLegacy;
 			sourceTree = "<group>";
@@ -3195,7 +3206,6 @@
 				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 */,
@@ -3213,7 +3223,6 @@
 				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 */,
@@ -3222,6 +3231,8 @@
 				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 */,
@@ -3276,6 +3287,7 @@
 				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 */,
@@ -3425,7 +3437,6 @@
 				5C0BF8931DD599BD00B00328 /* IsNavigationActionTrusted.mm in Sources */,
 				5C69BDD51F82A7EF000F4F4B /* _javascript_DuringNavigation.mm in Sources */,
 				7CCE7EAD1A411A3400447C4C /* _javascript_Test.cpp in Sources */,
-				51EB12941FDF052500A5A1BD /* ServiceWorkerBasic.mm in Sources */,
 				7CCE7EA51A411A0800447C4C /* _javascript_TestMac.mm in Sources */,
 				7CCE7EC41A411A7E00447C4C /* JSWrapperForNodeInWebFrame.mm in Sources */,
 				7CCE7F061A411AE600447C4C /* LayoutMilestonesWithAllContentInFrame.cpp in Sources */,
@@ -3518,6 +3529,7 @@
 				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 */,

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/paste-rtfd.html (226155 => 226156)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/paste-rtfd.html	2017-12-20 00:06:43 UTC (rev 226155)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/paste-rtfd.html	2017-12-20 00:07:31 UTC (rev 226156)
@@ -24,7 +24,10 @@
 
 function notifyLoaded()
 {
-    webkit.messageHandlers.testHandler.postMessage('loaded');
+    if (window.webkit)
+        webkit.messageHandlers.testHandler.postMessage('loaded');
+    else
+        alert('loaded');
 }
 
 </script>

Added: trunk/Tools/TestWebKitAPI/Tests/WebKitLegacy/mac/AccessingPastedImage.mm (0 => 226156)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitLegacy/mac/AccessingPastedImage.mm	                        (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitLegacy/mac/AccessingPastedImage.mm	2017-12-20 00:07:31 UTC (rev 226156)
@@ -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 = ""
+
+    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 = ""
+
+    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
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to