Title: [235574] trunk
Revision
235574
Author
[email protected]
Date
2018-08-31 16:18:30 -0700 (Fri, 31 Aug 2018)

Log Message

[iOS] Consolidate the implementations of readString, stringForType, and readURL in PlatformPasteboardIOS.mm
https://bugs.webkit.org/show_bug.cgi?id=189054
<rdar://problem/43819779>

Reviewed by Tim Horton.

Source/WebCore:

Remove redundant and unnecessary logic for reading from the pasteboard on iOS.

* platform/PlatformPasteboard.h:
* platform/ios/PlatformPasteboardIOS.mm:
(WebCore::PlatformPasteboard::stringForType const):

This currently grabs a string corresponding to the given type from the first item in the pasteboard. Make
stringForType instead call readString with pasteboard item index 0.

(WebCore::PlatformPasteboard::count const):
(WebCore::PlatformPasteboard::readBuffer const):
(WebCore::PlatformPasteboard::readString const):

Make readString with "public.url" call readURL.

(WebCore::PlatformPasteboard::readURL const):

Remove logic for reading URLs from the pasteboard as property lists deserialized from properly lists. This was
added in r223195 due to fix a case "when UIPasteboard serializes NSURL as a plist" when grabbing pasteboard data
using -valuesForPasteboardType:inItemSet:. However, this case only arises in non-UI applications (i.e. when
UIApplicationInitialize() has not been invoked); this is currently exercised by the test CopyURL.ValidURL, but
doesn't really correspond to a real-world use case, since all UI applications where a user would be able to
paste in a web view already invoke UIApplicationInitialize().

Instead of handling the case where the pasteboard contains a property list that has not been coerced to an
NSURL, simply remove the code from PlatformPasteboard::readURL and allow UIKit to perform the coercion when
running the test.

(WebCore::PlatformPasteboard::count): Deleted.
(WebCore::PlatformPasteboard::readBuffer): Deleted.
(WebCore::PlatformPasteboard::readString): Deleted.
(WebCore::PlatformPasteboard::readURL): Deleted.

Mark these functions as `const`.

* platform/wpe/PlatformPasteboardWPE.cpp:
(WebCore::PlatformPasteboard::readString const):
(WebCore::PlatformPasteboard::readString): Deleted.

Mark this function as const.

Tools:

See WebCore/ChangeLog for more detail.

* TestWebKitAPI/Tests/WebKitCocoa/CopyURL.mm:
(createWebViewWithCustomPasteboardDataEnabled):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (235573 => 235574)


--- trunk/Source/WebCore/ChangeLog	2018-08-31 23:14:06 UTC (rev 235573)
+++ trunk/Source/WebCore/ChangeLog	2018-08-31 23:18:30 UTC (rev 235574)
@@ -1,3 +1,52 @@
+2018-08-31  Wenson Hsieh  <[email protected]>
+
+        [iOS] Consolidate the implementations of readString, stringForType, and readURL in PlatformPasteboardIOS.mm
+        https://bugs.webkit.org/show_bug.cgi?id=189054
+        <rdar://problem/43819779>
+
+        Reviewed by Tim Horton.
+
+        Remove redundant and unnecessary logic for reading from the pasteboard on iOS.
+
+        * platform/PlatformPasteboard.h:
+        * platform/ios/PlatformPasteboardIOS.mm:
+        (WebCore::PlatformPasteboard::stringForType const):
+
+        This currently grabs a string corresponding to the given type from the first item in the pasteboard. Make
+        stringForType instead call readString with pasteboard item index 0.
+
+        (WebCore::PlatformPasteboard::count const):
+        (WebCore::PlatformPasteboard::readBuffer const):
+        (WebCore::PlatformPasteboard::readString const):
+
+        Make readString with "public.url" call readURL.
+
+        (WebCore::PlatformPasteboard::readURL const):
+
+        Remove logic for reading URLs from the pasteboard as property lists deserialized from properly lists. This was
+        added in r223195 due to fix a case "when UIPasteboard serializes NSURL as a plist" when grabbing pasteboard data
+        using -valuesForPasteboardType:inItemSet:. However, this case only arises in non-UI applications (i.e. when
+        UIApplicationInitialize() has not been invoked); this is currently exercised by the test CopyURL.ValidURL, but
+        doesn't really correspond to a real-world use case, since all UI applications where a user would be able to
+        paste in a web view already invoke UIApplicationInitialize().
+
+        Instead of handling the case where the pasteboard contains a property list that has not been coerced to an
+        NSURL, simply remove the code from PlatformPasteboard::readURL and allow UIKit to perform the coercion when
+        running the test.
+
+        (WebCore::PlatformPasteboard::count): Deleted.
+        (WebCore::PlatformPasteboard::readBuffer): Deleted.
+        (WebCore::PlatformPasteboard::readString): Deleted.
+        (WebCore::PlatformPasteboard::readURL): Deleted.
+
+        Mark these functions as `const`.
+
+        * platform/wpe/PlatformPasteboardWPE.cpp:
+        (WebCore::PlatformPasteboard::readString const):
+        (WebCore::PlatformPasteboard::readString): Deleted.
+
+        Mark this function as const.
+
 2018-08-31  Jer Noble  <[email protected]>
 
         Compilation error in FormData.cpp: incomplete type 'WebCore::SharedBuffer'

Modified: trunk/Source/WebCore/platform/PlatformPasteboard.h (235573 => 235574)


--- trunk/Source/WebCore/platform/PlatformPasteboard.h	2018-08-31 23:14:06 UTC (rev 235573)
+++ trunk/Source/WebCore/platform/PlatformPasteboard.h	2018-08-31 23:18:30 UTC (rev 235574)
@@ -91,10 +91,10 @@
     WEBCORE_EXPORT void write(const PasteboardImage&);
     WEBCORE_EXPORT void write(const String& pasteboardType, const String&);
     WEBCORE_EXPORT void write(const PasteboardURL&);
-    WEBCORE_EXPORT RefPtr<SharedBuffer> readBuffer(int index, const String& pasteboardType);
-    WEBCORE_EXPORT String readString(int index, const String& pasteboardType);
-    WEBCORE_EXPORT URL readURL(int index, String& title);
-    WEBCORE_EXPORT int count();
+    WEBCORE_EXPORT RefPtr<SharedBuffer> readBuffer(int index, const String& pasteboardType) const;
+    WEBCORE_EXPORT String readString(int index, const String& pasteboardType) const;
+    WEBCORE_EXPORT URL readURL(int index, String& title) const;
+    WEBCORE_EXPORT int count() const;
     WEBCORE_EXPORT int numberOfFiles() const;
 
     WEBCORE_EXPORT long write(const PasteboardCustomData&);

Modified: trunk/Source/WebCore/platform/ios/PlatformPasteboardIOS.mm (235573 => 235574)


--- trunk/Source/WebCore/platform/ios/PlatformPasteboardIOS.mm	2018-08-31 23:14:06 UTC (rev 235573)
+++ trunk/Source/WebCore/platform/ios/PlatformPasteboardIOS.mm	2018-08-31 23:18:30 UTC (rev 235574)
@@ -202,17 +202,8 @@
 
 String PlatformPasteboard::stringForType(const String& type) const
 {
-    auto value = retainPtr([m_pasteboard valuesForPasteboardType:type inItemSet:[NSIndexSet indexSetWithIndex:0]].firstObject);
-    String result;
-    if ([value isKindOfClass:[NSURL class]])
-        result = [(NSURL *)value absoluteString];
+    auto result = readString(0, type);
 
-    else if ([value isKindOfClass:[NSAttributedString class]])
-        result = [(NSAttributedString *)value string];
-
-    else if ([value isKindOfClass:[NSString class]])
-        result = (NSString *)value;
-
     if (pasteboardMayContainFilePaths(m_pasteboard.get()) && type == String { kUTTypeURL }) {
         if (!Pasteboard::canExposeURLToDOMWhenPasteboardContainsFiles(result))
             result = { };
@@ -607,12 +598,12 @@
 
 #endif
 
-int PlatformPasteboard::count()
+int PlatformPasteboard::count() const
 {
     return [m_pasteboard numberOfItems];
 }
 
-RefPtr<SharedBuffer> PlatformPasteboard::readBuffer(int index, const String& type)
+RefPtr<SharedBuffer> PlatformPasteboard::readBuffer(int index, const String& type) const
 {
     NSIndexSet *indexSet = [NSIndexSet indexSetWithIndex:index];
 
@@ -623,19 +614,18 @@
     return SharedBuffer::create([pasteboardItem.get() objectAtIndex:0]);
 }
 
-String PlatformPasteboard::readString(int index, const String& type)
+String PlatformPasteboard::readString(int index, const String& type) const
 {
+    if (type == String(kUTTypeURL)) {
+        String title;
+        return readURL(index, title);
+    }
+
     NSIndexSet *indexSet = [NSIndexSet indexSetWithIndex:index];
+    auto value = retainPtr([m_pasteboard valuesForPasteboardType:type inItemSet:indexSet].firstObject ?: [m_pasteboard dataForPasteboardType:type inItemSet:indexSet].firstObject);
+    if (!value)
+        return { };
 
-    NSArray *pasteboardValues = [m_pasteboard valuesForPasteboardType:type inItemSet:indexSet];
-    if (!pasteboardValues.count) {
-        NSArray<NSData *> *pasteboardData = [m_pasteboard dataForPasteboardType:type inItemSet:indexSet];
-        if (!pasteboardData.count)
-            return { };
-        pasteboardValues = pasteboardData;
-    }
-
-    RetainPtr<id> value = [pasteboardValues objectAtIndex:0];
     if ([value isKindOfClass:[NSData class]])
         value = adoptNS([[NSString alloc] initWithData:(NSData *)value.get() encoding:NSUTF8StringEncoding]);
     
@@ -649,45 +639,22 @@
             return value.get();
         if ([value isKindOfClass:[NSAttributedString class]])
             return [(NSAttributedString *)value string];
-    } else if (type == String(kUTTypeURL)) {
-        ASSERT([value isKindOfClass:[NSURL class]] || [value isKindOfClass:[NSString class]]);
-        if ([value isKindOfClass:[NSString class]])
-            value = [NSURL URLWithString:value.get()];
-        if ([value isKindOfClass:[NSURL class]] && allowReadingURLAtIndex((NSURL *)value, index))
-            return [(NSURL *)value absoluteString];
     }
 
     return String();
 }
 
-URL PlatformPasteboard::readURL(int index, String& title)
+URL PlatformPasteboard::readURL(int index, String& title) const
 {
-    NSIndexSet *indexSet = [NSIndexSet indexSetWithIndex:index];
-    RetainPtr<NSArray> pasteboardItem = [m_pasteboard valuesForPasteboardType:(__bridge NSString *)kUTTypeURL inItemSet:indexSet];
+    id value = [m_pasteboard valuesForPasteboardType:(__bridge NSString *)kUTTypeURL inItemSet:[NSIndexSet indexSetWithIndex:index]].firstObject;
+    if (!value)
+        return { };
 
-    if (![pasteboardItem count])
+    ASSERT([value isKindOfClass:[NSURL class]]);
+    if (![value isKindOfClass:[NSURL class]])
         return { };
 
-    id value = [pasteboardItem objectAtIndex:0];
-    NSURL *url = ""
-    if ([value isKindOfClass:[NSData class]]) {
-        id plist = [NSPropertyListSerialization propertyListWithData:(NSData *)value options:NSPropertyListImmutable format:NULL error:NULL];
-        if (![plist isKindOfClass:[NSArray class]])
-            return { };
-        NSArray *plistArray = (NSArray *)plist;
-        if (plistArray.count < 2)
-            return { };
-        if (plistArray.count == 2)
-            url = "" URLWithString:plistArray[0]];
-        else // The first string is the relative URL.
-            url = "" URLWithString:plistArray[0] relativeToURL:[NSURL URLWithString:plistArray[1]]];
-    } else {
-        ASSERT([value isKindOfClass:[NSURL class]]);
-        if (![value isKindOfClass:[NSURL class]])
-            return { };
-        url = "" *)value;
-    }
-
+    NSURL *url = "" *)value;
     if (!allowReadingURLAtIndex(url, index))
         return { };
 

Modified: trunk/Source/WebCore/platform/wpe/PlatformPasteboardWPE.cpp (235573 => 235574)


--- trunk/Source/WebCore/platform/wpe/PlatformPasteboardWPE.cpp	2018-08-31 23:14:06 UTC (rev 235573)
+++ trunk/Source/WebCore/platform/wpe/PlatformPasteboardWPE.cpp	2018-08-31 23:18:30 UTC (rev 235574)
@@ -58,7 +58,7 @@
     wpe_pasteboard_string_vector_free(&pasteboardTypes);
 }
 
-String PlatformPasteboard::readString(int, const String& type)
+String PlatformPasteboard::readString(int, const String& type) const
 {
     struct wpe_pasteboard_string string = { nullptr, 0 };
     wpe_pasteboard_get_string(m_pasteboard, type.utf8().data(), &string);

Modified: trunk/Tools/ChangeLog (235573 => 235574)


--- trunk/Tools/ChangeLog	2018-08-31 23:14:06 UTC (rev 235573)
+++ trunk/Tools/ChangeLog	2018-08-31 23:18:30 UTC (rev 235574)
@@ -1,3 +1,16 @@
+2018-08-31  Wenson Hsieh  <[email protected]>
+
+        [iOS] Consolidate the implementations of readString, stringForType, and readURL in PlatformPasteboardIOS.mm
+        https://bugs.webkit.org/show_bug.cgi?id=189054
+        <rdar://problem/43819779>
+
+        Reviewed by Tim Horton.
+
+        See WebCore/ChangeLog for more detail.
+
+        * TestWebKitAPI/Tests/WebKitCocoa/CopyURL.mm:
+        (createWebViewWithCustomPasteboardDataEnabled):
+
 2018-08-31  Commit Queue  <[email protected]>
 
         Unreviewed, rolling out r235565.

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/CopyURL.mm (235573 => 235574)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/CopyURL.mm	2018-08-31 23:14:06 UTC (rev 235573)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/CopyURL.mm	2018-08-31 23:18:30 UTC (rev 235574)
@@ -34,6 +34,7 @@
 #import <wtf/text/WTFString.h>
 
 #if PLATFORM(IOS)
+#import "UIKitSPI.h"
 #include <MobileCoreServices/MobileCoreServices.h>
 #endif
 
@@ -59,6 +60,10 @@
 
 static RetainPtr<TestWKWebView> createWebViewWithCustomPasteboardDataEnabled()
 {
+#if PLATFORM(IOS)
+    UIApplicationInitialize();
+#endif
+
     auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 400, 400)]);
     auto preferences = (WKPreferencesRef)[[webView configuration] preferences];
     WKPreferencesSetDataTransferItemsEnabled(preferences, true);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to