Don't write file URLs to iOS Pasteboard
authormegan_gardner@apple.com <megan_gardner@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 19 Jul 2017 23:57:38 +0000 (23:57 +0000)
committermegan_gardner@apple.com <megan_gardner@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 19 Jul 2017 23:57:38 +0000 (23:57 +0000)
https://bugs.webkit.org/show_bug.cgi?id=174647
<rdar://problem/33199730>

Reviewed by Wenson Hsieh.

Source/WebCore:

Tests updated to reflect the changes. We are no longer vending file URLs in Drag & Drop and Copy/Paste.

* editing/ios/EditorIOS.mm:
(WebCore::Editor::writeImageToPasteboard):
* platform/ios/PlatformPasteboardIOS.mm:
(WebCore::PlatformPasteboard::write):

Tools:

Updating tests to reflect the lack of file URLs for images.

* TestWebKitAPI/Tests/ios/DataInteractionTests.mm:
(checkTypeIdentifierAndIsNotOtherTypeIdentifier):
(checkEstimatedSize):
(TestWebKitAPI::TEST):

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

Source/WebCore/ChangeLog
Source/WebCore/editing/ios/EditorIOS.mm
Source/WebCore/platform/ios/PlatformPasteboardIOS.mm
Tools/ChangeLog
Tools/TestWebKitAPI/Tests/ios/DataInteractionTests.mm

index d9ee1db..2ce776d 100644 (file)
@@ -1,3 +1,18 @@
+2017-07-19  Megan Gardner  <megan_gardner@apple.com>
+
+        Don't write file URLs to iOS Pasteboard
+        https://bugs.webkit.org/show_bug.cgi?id=174647
+        <rdar://problem/33199730>
+
+        Reviewed by Wenson Hsieh.
+
+        Tests updated to reflect the changes. We are no longer vending file URLs in Drag & Drop and Copy/Paste.
+
+        * editing/ios/EditorIOS.mm:
+        (WebCore::Editor::writeImageToPasteboard):
+        * platform/ios/PlatformPasteboardIOS.mm:
+        (WebCore::PlatformPasteboard::write):
+
 2017-07-19  Myles C. Maxfield  <mmaxfield@apple.com>
 
         Setting the minimum font size preference doesn’t affect absolute line-height values, so lines overlap
index c57eff2..8f10b11 100644 (file)
@@ -207,8 +207,12 @@ void Editor::writeImageToPasteboard(Pasteboard& pasteboard, Element& imageElemen
     ASSERT(cachedImage);
 
     auto imageSourceURL = imageElement.document().completeURL(stripLeadingAndTrailingHTMLSpaces(imageElement.imageSourceURL()));
-    pasteboardImage.url.url = url.isEmpty() ? imageSourceURL : url;
-    pasteboardImage.url.title = title;
+
+    auto pasteboardImageURL = url.isEmpty() ? imageSourceURL : url;
+    if (!pasteboardImageURL.isLocalFile()) {
+        pasteboardImage.url.url = pasteboardImageURL;
+        pasteboardImage.url.title = title;
+    }
     pasteboardImage.suggestedName = imageSourceURL.lastPathComponent();
     pasteboardImage.imageSize = image->size();
     pasteboardImage.resourceMIMEType = pasteboard.resourceMIMEType(cachedImage->response().mimeType());
index 2c323f6..e88dde8 100644 (file)
@@ -325,7 +325,8 @@ void PlatformPasteboard::write(const PasteboardImage& pasteboardImage)
     RetainPtr<NSMutableDictionary> representations = adoptNS([[NSMutableDictionary alloc] init]);
     if (!pasteboardImage.resourceMIMEType.isNull()) {
         [representations setObject:pasteboardImage.resourceData->createNSData().get() forKey:pasteboardImage.resourceMIMEType];
-        [representations setObject:(NSURL *)pasteboardImage.url.url forKey:(NSString *)kUTTypeURL];
+        if (!pasteboardImage.url.url.isNull())
+            [representations setObject:(NSURL *)pasteboardImage.url.url forKey:(NSString *)kUTTypeURL];
     }
 
     // Explicitly cast m_pasteboard to UIPasteboard * to work around rdar://problem/33383354.
index 4fe8bdb..39ac797 100644 (file)
@@ -1,3 +1,18 @@
+2017-07-19  Megan Gardner  <megan_gardner@apple.com>
+
+        Don't write file URLs to iOS Pasteboard
+        https://bugs.webkit.org/show_bug.cgi?id=174647
+        <rdar://problem/33199730>
+
+        Reviewed by Wenson Hsieh.
+
+        Updating tests to reflect the lack of file URLs for images.
+
+        * TestWebKitAPI/Tests/ios/DataInteractionTests.mm:
+        (checkTypeIdentifierAndIsNotOtherTypeIdentifier):
+        (checkEstimatedSize):
+        (TestWebKitAPI::TEST):
+
 2017-07-19  Brady Eidson  <beidson@apple.com>
 
         iBooks sometimes crashes when closing a book.
index bcdb3cc..ad29208 100644 (file)
@@ -114,6 +114,13 @@ static void checkTypeIdentifierPrecedesOtherTypeIdentifier(DataInteractionSimula
     EXPECT_TRUE([registeredTypes indexOfObject:firstType] < [registeredTypes indexOfObject:secondType]);
 }
 
+static void checkTypeIdentifierAndIsNotOtherTypeIdentifier(DataInteractionSimulator *simulator, NSString *firstType, NSString *secondType)
+{
+    NSArray *registeredTypes = [simulator.sourceItemProviders.firstObject registeredTypeIdentifiers];
+    EXPECT_TRUE([registeredTypes containsObject:firstType]);
+    EXPECT_FALSE([registeredTypes containsObject:secondType]);
+}
+
 static void checkTypeIdentifierIsRegisteredAtIndex(DataInteractionSimulator *simulator, NSString *type, NSUInteger index)
 {
     NSArray *registeredTypes = [simulator.sourceItemProviders.firstObject registeredTypeIdentifiers];
@@ -121,6 +128,13 @@ static void checkTypeIdentifierIsRegisteredAtIndex(DataInteractionSimulator *sim
     EXPECT_WK_STREQ(type.UTF8String, [registeredTypes[index] UTF8String]);
 }
 
+static void checkEstimatedSize(DataInteractionSimulator *simulator, CGSize estimatedSize)
+{
+    UIItemProvider *sourceItemProvider = [simulator sourceItemProviders].firstObject;
+    EXPECT_EQ(estimatedSize.width, sourceItemProvider.estimatedDisplayedSize.width);
+    EXPECT_EQ(estimatedSize.height, sourceItemProvider.estimatedDisplayedSize.height);
+}
+
 static void checkSuggestedNameAndEstimatedSize(DataInteractionSimulator *simulator, NSString *suggestedName, CGSize estimatedSize)
 {
     UIItemProvider *sourceItemProvider = [simulator sourceItemProviders].firstObject;
@@ -166,8 +180,8 @@ TEST(DataInteractionTests, ImageToContentEditable)
     EXPECT_TRUE([observedEventNames containsObject:DataInteractionOverEventName]);
     EXPECT_TRUE([observedEventNames containsObject:DataInteractionPerformOperationEventName]);
     checkSelectionRectsWithLogging(@[ makeCGRectValue(1, 201, 215, 174) ], [dataInteractionSimulator finalSelectionRects]);
-    checkTypeIdentifierPrecedesOtherTypeIdentifier(dataInteractionSimulator.get(), (NSString *)kUTTypePNG, (NSString *)kUTTypeFileURL);
-    checkSuggestedNameAndEstimatedSize(dataInteractionSimulator.get(), @"icon.png", { 215, 174 });
+    checkTypeIdentifierAndIsNotOtherTypeIdentifier(dataInteractionSimulator.get(), (NSString *)kUTTypePNG, (NSString *)kUTTypeFileURL);
+    checkEstimatedSize(dataInteractionSimulator.get(), { 215, 174 });
 }
 
 TEST(DataInteractionTests, CanStartDragOnEnormousImage)
@@ -190,16 +204,14 @@ TEST(DataInteractionTests, ImageToTextarea)
     RetainPtr<DataInteractionSimulator> dataInteractionSimulator = adoptNS([[DataInteractionSimulator alloc] initWithWebView:webView.get()]);
     [dataInteractionSimulator runFrom:CGPointMake(100, 50) to:CGPointMake(100, 300)];
 
-    NSURL *imageURL = [NSURL fileURLWithPath:[webView editorValue]];
-    EXPECT_WK_STREQ("icon.png", imageURL.lastPathComponent);
+    EXPECT_WK_STREQ("", [webView editorValue]);
 
     NSArray *observedEventNames = [dataInteractionSimulator observedEventNames];
     EXPECT_TRUE([observedEventNames containsObject:DataInteractionEnterEventName]);
     EXPECT_TRUE([observedEventNames containsObject:DataInteractionOverEventName]);
     EXPECT_TRUE([observedEventNames containsObject:DataInteractionPerformOperationEventName]);
-
-    checkTypeIdentifierPrecedesOtherTypeIdentifier(dataInteractionSimulator.get(), (NSString *)kUTTypePNG, (NSString *)kUTTypeFileURL);
-    checkSuggestedNameAndEstimatedSize(dataInteractionSimulator.get(), @"icon.png", { 215, 174 });
+    checkTypeIdentifierAndIsNotOtherTypeIdentifier(dataInteractionSimulator.get(), (NSString *)kUTTypePNG, (NSString *)kUTTypeFileURL);
+    checkEstimatedSize(dataInteractionSimulator.get(), { 215, 174 });
 }
 
 TEST(DataInteractionTests, ImageInLinkToInput)
@@ -225,9 +237,8 @@ TEST(DataInteractionTests, ImageInLinkWithoutHREFToInput)
     RetainPtr<DataInteractionSimulator> dataInteractionSimulator = adoptNS([[DataInteractionSimulator alloc] initWithWebView:webView.get()]);
     [dataInteractionSimulator runFrom:CGPointMake(100, 50) to:CGPointMake(100, 300)];
 
-    NSURL *imageURL = [NSURL fileURLWithPath:[webView editorValue]];
-    EXPECT_WK_STREQ("icon.png", imageURL.lastPathComponent);
-    checkSuggestedNameAndEstimatedSize(dataInteractionSimulator.get(), @"icon.png", { 215, 174 });
+    EXPECT_WK_STREQ("", [webView editorValue]);
+    checkEstimatedSize(dataInteractionSimulator.get(), { 215, 174 });
     checkTypeIdentifierIsRegisteredAtIndex(dataInteractionSimulator.get(), (NSString *)kUTTypePNG, 0);
 }
 
@@ -1003,8 +1014,8 @@ TEST(DataInteractionTests, LargeImageToTargetDiv)
     RetainPtr<DataInteractionSimulator> dataInteractionSimulator = adoptNS([[DataInteractionSimulator alloc] initWithWebView:webView.get()]);
     [dataInteractionSimulator runFrom:CGPointMake(200, 400) to:CGPointMake(200, 150)];
     EXPECT_WK_STREQ("PASS", [webView stringByEvaluatingJavaScript:@"target.textContent"].UTF8String);
-    checkTypeIdentifierPrecedesOtherTypeIdentifier(dataInteractionSimulator.get(), (NSString *)kUTTypePNG, (NSString *)kUTTypeFileURL);
-    checkSuggestedNameAndEstimatedSize(dataInteractionSimulator.get(), @"large-red-square.png", { 2000, 2000 });
+    checkTypeIdentifierAndIsNotOtherTypeIdentifier(dataInteractionSimulator.get(), (NSString *)kUTTypePNG, (NSString *)kUTTypeFileURL);
+    checkEstimatedSize(dataInteractionSimulator.get(), { 2000, 2000 });
 }
 
 TEST(DataInteractionTests, LinkWithEmptyHREF)