Title: [227135] trunk
Revision
227135
Author
[email protected]
Date
2018-01-18 00:24:46 -0800 (Thu, 18 Jan 2018)

Log Message

[iOS] Specify -[NSURL _title] for the associated URL when copying an image element
https://bugs.webkit.org/show_bug.cgi?id=181783
<rdar://problem/35785445>

Reviewed by Ryosuke Niwa.

Source/WebCore:

Always specify the -[NSURL _title] to be either the title specified in a PasteboardImage's inner PasteboardURL,
or if no title is specified, fall back to the user-visible URL string. This is because at least one internal
client always tries to use the -_title property to determine the title of a pasted URL, or if none is specified,
the -suggestedName. Since we need to set suggestedName to the preferred file name of the copied image and we
don't want the suggested name to become the title of the link, we need to explicitly set the link title.

In doing so, this patch also fixes a bug wherein we forget to set the _title of the NSURL we're registering to
an NSItemProvider.

Tests:  ActionSheetTests.CopyImageElementWithHREFAndTitle (new)
        ActionSheetTests.CopyImageElementWithHREF (modified)

* platform/ios/PlatformPasteboardIOS.mm:
(WebCore::PlatformPasteboard::write):

Tools:

Augments an existing API test and adds a new test to make sure that the resulting NSItemProvider's NSURL when
copying an image contains a relevant title.

* TestWebKitAPI/Tests/ios/ActionSheetTests.mm:
(TestWebKitAPI::TEST):
* TestWebKitAPI/ios/DataInteractionSimulator.mm:
* TestWebKitAPI/ios/UIKitSPI.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (227134 => 227135)


--- trunk/Source/WebCore/ChangeLog	2018-01-18 07:30:51 UTC (rev 227134)
+++ trunk/Source/WebCore/ChangeLog	2018-01-18 08:24:46 UTC (rev 227135)
@@ -1,3 +1,26 @@
+2018-01-18  Wenson Hsieh  <[email protected]>
+
+        [iOS] Specify -[NSURL _title] for the associated URL when copying an image element
+        https://bugs.webkit.org/show_bug.cgi?id=181783
+        <rdar://problem/35785445>
+
+        Reviewed by Ryosuke Niwa.
+
+        Always specify the -[NSURL _title] to be either the title specified in a PasteboardImage's inner PasteboardURL,
+        or if no title is specified, fall back to the user-visible URL string. This is because at least one internal
+        client always tries to use the -_title property to determine the title of a pasted URL, or if none is specified,
+        the -suggestedName. Since we need to set suggestedName to the preferred file name of the copied image and we
+        don't want the suggested name to become the title of the link, we need to explicitly set the link title.
+
+        In doing so, this patch also fixes a bug wherein we forget to set the _title of the NSURL we're registering to
+        an NSItemProvider.
+
+        Tests:  ActionSheetTests.CopyImageElementWithHREFAndTitle (new)
+                ActionSheetTests.CopyImageElementWithHREF (modified)
+
+        * platform/ios/PlatformPasteboardIOS.mm:
+        (WebCore::PlatformPasteboard::write):
+
 2018-01-17  Jer Noble  <[email protected]>
 
         WebVTT served via HLS never results in cues

Modified: trunk/Source/WebCore/platform/ios/PlatformPasteboardIOS.mm (227134 => 227135)


--- trunk/Source/WebCore/platform/ios/PlatformPasteboardIOS.mm	2018-01-18 07:30:51 UTC (rev 227134)
+++ trunk/Source/WebCore/platform/ios/PlatformPasteboardIOS.mm	2018-01-18 08:24:46 UTC (rev 227135)
@@ -32,6 +32,7 @@
 #import "SharedBuffer.h"
 #import "URL.h"
 #import "UTIUtilities.h"
+#import "WebCoreNSURLExtras.h"
 #import "WebItemProviderPasteboard.h"
 #import <MobileCoreServices/MobileCoreServices.h>
 #import <UIKit/UIImage.h>
@@ -346,9 +347,10 @@
     // FIXME: When writing a PasteboardImage, we currently always place the image data at a higer fidelity than the
     // associated image URL. However, in the case of an image enclosed by an anchor, we might want to consider the
     // the URL (i.e. the anchor's href attribute) to be a higher fidelity representation.
-    if (!pasteboardImage.url.url.isEmpty()) {
-        if (NSURL *nsURL = pasteboardImage.url.url)
-            [representationsToRegister addRepresentingObject:nsURL];
+    auto& pasteboardURL = pasteboardImage.url;
+    if (NSURL *nsURL = pasteboardURL.url) {
+        nsURL._title = pasteboardURL.title.isEmpty() ? userVisibleString(pasteboardURL.url) : (NSString *)pasteboardURL.title;
+        [representationsToRegister addRepresentingObject:nsURL];
     }
 
     registerItemToPasteboard(representationsToRegister.get(), m_pasteboard.get());

Modified: trunk/Tools/ChangeLog (227134 => 227135)


--- trunk/Tools/ChangeLog	2018-01-18 07:30:51 UTC (rev 227134)
+++ trunk/Tools/ChangeLog	2018-01-18 08:24:46 UTC (rev 227135)
@@ -1,3 +1,19 @@
+2018-01-18  Wenson Hsieh  <[email protected]>
+
+        [iOS] Specify -[NSURL _title] for the associated URL when copying an image element
+        https://bugs.webkit.org/show_bug.cgi?id=181783
+        <rdar://problem/35785445>
+
+        Reviewed by Ryosuke Niwa.
+
+        Augments an existing API test and adds a new test to make sure that the resulting NSItemProvider's NSURL when
+        copying an image contains a relevant title.
+
+        * TestWebKitAPI/Tests/ios/ActionSheetTests.mm:
+        (TestWebKitAPI::TEST):
+        * TestWebKitAPI/ios/DataInteractionSimulator.mm:
+        * TestWebKitAPI/ios/UIKitSPI.h:
+
 2018-01-17  Carlos Garcia Campos  <[email protected]>
 
         WebDriver: ignore the driver in selenium test names when getting expectations

Modified: trunk/Tools/TestWebKitAPI/Tests/ios/ActionSheetTests.mm (227134 => 227135)


--- trunk/Tools/TestWebKitAPI/Tests/ios/ActionSheetTests.mm	2018-01-18 07:30:51 UTC (rev 227134)
+++ trunk/Tools/TestWebKitAPI/Tests/ios/ActionSheetTests.mm	2018-01-18 08:24:46 UTC (rev 227135)
@@ -164,6 +164,47 @@
     [copyAction runActionWithElementInfo:copyElement.get()];
 }
 
+TEST(ActionSheetTests, CopyImageElementWithHREFAndTitle)
+{
+    UIApplicationInitialize();
+    [UIPasteboard generalPasteboard].items = @[ ];
+
+    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]);
+    auto observer = adoptNS([[ActionSheetObserver alloc] init]);
+    [webView setUIDelegate:observer.get()];
+    [webView synchronouslyLoadTestPageNamed:@"image-in-link-and-input"];
+    [webView stringByEvaluatingJavaScript:@"document.querySelector('a').setAttribute('title', 'hello world')"];
+
+    presentActionSheetAndChooseAction(webView.get(), observer.get(), CGPointMake(100, 50), _WKElementActionTypeCopy);
+
+    __block bool done = false;
+    __block RetainPtr<NSItemProvider> itemProvider;
+    [webView _doAfterNextPresentationUpdate:^() {
+        NSArray <NSString *> *pasteboardTypes = [[UIPasteboard generalPasteboard] pasteboardTypes];
+        EXPECT_EQ(2UL, pasteboardTypes.count);
+        EXPECT_WK_STREQ((NSString *)kUTTypePNG, pasteboardTypes.firstObject);
+        EXPECT_WK_STREQ((NSString *)kUTTypeURL, pasteboardTypes.lastObject);
+        NSArray <NSItemProvider *> *itemProviders = [[UIPasteboard generalPasteboard] itemProviders];
+        EXPECT_EQ(1UL, itemProviders.count);
+        itemProvider = itemProviders.firstObject;
+        EXPECT_EQ(2UL, [itemProvider registeredTypeIdentifiers].count);
+        EXPECT_WK_STREQ((NSString *)kUTTypePNG, [itemProvider registeredTypeIdentifiers].firstObject);
+        EXPECT_WK_STREQ((NSString *)kUTTypeURL, [itemProvider registeredTypeIdentifiers].lastObject);
+        done = true;
+    }];
+    TestWebKitAPI::Util::run(&done);
+
+    __block bool doneLoading = false;
+    [itemProvider loadObjectOfClass:[NSURL class] completionHandler:^(id <NSItemProviderReading> result, NSError *) {
+        EXPECT_TRUE([result isKindOfClass:[NSURL class]]);
+        NSURL *url = "" *)result;
+        EXPECT_WK_STREQ("https://www.apple.com/", url.absoluteString);
+        EXPECT_WK_STREQ("hello world", url._title);
+        doneLoading = true;
+    }];
+    TestWebKitAPI::Util::run(&doneLoading);
+}
+
 TEST(ActionSheetTests, CopyImageElementWithHREF)
 {
     UIApplicationInitialize();
@@ -177,6 +218,7 @@
     presentActionSheetAndChooseAction(webView.get(), observer.get(), CGPointMake(100, 50), _WKElementActionTypeCopy);
 
     __block bool done = false;
+    __block RetainPtr<NSItemProvider> itemProvider;
     [webView _doAfterNextPresentationUpdate:^() {
         NSArray <NSString *> *pasteboardTypes = [[UIPasteboard generalPasteboard] pasteboardTypes];
         EXPECT_EQ(2UL, pasteboardTypes.count);
@@ -184,13 +226,23 @@
         EXPECT_WK_STREQ((NSString *)kUTTypeURL, pasteboardTypes.lastObject);
         NSArray <NSItemProvider *> *itemProviders = [[UIPasteboard generalPasteboard] itemProviders];
         EXPECT_EQ(1UL, itemProviders.count);
-        NSItemProvider *itemProvider = itemProviders.firstObject;
-        EXPECT_EQ(2UL, itemProvider.registeredTypeIdentifiers.count);
-        EXPECT_WK_STREQ((NSString *)kUTTypePNG, itemProvider.registeredTypeIdentifiers.firstObject);
-        EXPECT_WK_STREQ((NSString *)kUTTypeURL, itemProvider.registeredTypeIdentifiers.lastObject);
+        itemProvider = itemProviders.firstObject;
+        EXPECT_EQ(2UL, [itemProvider registeredTypeIdentifiers].count);
+        EXPECT_WK_STREQ((NSString *)kUTTypePNG, [itemProvider registeredTypeIdentifiers].firstObject);
+        EXPECT_WK_STREQ((NSString *)kUTTypeURL, [itemProvider registeredTypeIdentifiers].lastObject);
         done = true;
     }];
     TestWebKitAPI::Util::run(&done);
+
+    __block bool doneLoading = false;
+    [itemProvider loadObjectOfClass:[NSURL class] completionHandler:^(id <NSItemProviderReading> result, NSError *) {
+        EXPECT_TRUE([result isKindOfClass:[NSURL class]]);
+        NSURL *url = "" *)result;
+        EXPECT_WK_STREQ("https://www.apple.com/", url.absoluteString);
+        EXPECT_WK_STREQ("https://www.apple.com/", url._title);
+        doneLoading = true;
+    }];
+    TestWebKitAPI::Util::run(&doneLoading);
 }
 
 TEST(ActionSheetTests, CopyImageElementWithoutHREF)

Modified: trunk/Tools/TestWebKitAPI/ios/UIKitSPI.h (227134 => 227135)


--- trunk/Tools/TestWebKitAPI/ios/UIKitSPI.h	2018-01-18 07:30:51 UTC (rev 227134)
+++ trunk/Tools/TestWebKitAPI/ios/UIKitSPI.h	2018-01-18 08:24:46 UTC (rev 227135)
@@ -91,4 +91,8 @@
 @end
 #endif
 
+@interface NSURL (UIKitSPI)
+@property (nonatomic, copy, setter=_setTitle:) NSString *_title;
+@end
+
 #endif // PLATFORM(IOS)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to