WebKit Bugzilla
Attachment 348524 Details for
Bug 189054
: [iOS] Consolidate the implementations of readString, stringForType, and readURL in PlatformPasteboardIOS.mm
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Patch
bug-189054-20180830120433.patch (text/plain), 10.65 KB, created by
Wenson Hsieh
on 2018-08-30 12:04:33 PDT
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
Wenson Hsieh
Created:
2018-08-30 12:04:33 PDT
Size:
10.65 KB
patch
obsolete
>Subversion Revision: 235504 >diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog >index c51e78029b05e1f42f7de62fa1f3243f3df2041e..8097f2e5626b66c8ed533e2470cdf4450379165b 100644 >--- a/Source/WebCore/ChangeLog >+++ b/Source/WebCore/ChangeLog >@@ -1,3 +1,46 @@ >+2018-08-30 Wenson Hsieh <wenson_hsieh@apple.com> >+ >+ [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 NOBODY (OOPS!). >+ >+ 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`. >+ > 2018-08-30 Zalan Bujtas <zalan@apple.com> > > [LFC][Floating] Move containing block constraint logic from FloatAvoider to FloatingContext >diff --git a/Source/WebCore/platform/PlatformPasteboard.h b/Source/WebCore/platform/PlatformPasteboard.h >index 211c7839bb7d4d363a307599cedcdecb8baef344..dc650c33350a87d97cf50984eb6e534502138d76 100644 >--- a/Source/WebCore/platform/PlatformPasteboard.h >+++ b/Source/WebCore/platform/PlatformPasteboard.h >@@ -91,10 +91,10 @@ public: > 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&); >diff --git a/Source/WebCore/platform/ios/PlatformPasteboardIOS.mm b/Source/WebCore/platform/ios/PlatformPasteboardIOS.mm >index 3db68b5d8a804261f829f867bda1a4875fcc3e66..e02893ed6e4a6b01e728221bf6f1d418fb2155b0 100644 >--- a/Source/WebCore/platform/ios/PlatformPasteboardIOS.mm >+++ b/Source/WebCore/platform/ios/PlatformPasteboardIOS.mm >@@ -202,16 +202,7 @@ static bool pasteboardMayContainFilePaths(id<AbstractPasteboard> pasteboard) > > 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]; >- >- else if ([value isKindOfClass:[NSAttributedString class]]) >- result = [(NSAttributedString *)value string]; >- >- else if ([value isKindOfClass:[NSString class]]) >- result = (NSString *)value; >+ auto result = readString(0, type); > > if (pasteboardMayContainFilePaths(m_pasteboard.get()) && type == String { kUTTypeURL }) { > if (!Pasteboard::canExposeURLToDOMWhenPasteboardContainsFiles(result)) >@@ -607,12 +598,12 @@ long PlatformPasteboard::write(const PasteboardCustomData&) > > #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 @@ RefPtr<SharedBuffer> PlatformPasteboard::readBuffer(int index, const String& typ > return SharedBuffer::create([pasteboardItem.get() objectAtIndex:0]); > } > >-String PlatformPasteboard::readString(int index, const String& type) >+String PlatformPasteboard::readString(int index, const String& type) const > { >- NSIndexSet *indexSet = [NSIndexSet indexSetWithIndex:index]; >- >- 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; >+ if (type == String(kUTTypeURL)) { >+ String title; >+ return readURL(index, title); > } > >- RetainPtr<id> value = [pasteboardValues objectAtIndex:0]; >+ 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 { }; >+ > if ([value isKindOfClass:[NSData class]]) > value = adoptNS([[NSString alloc] initWithData:(NSData *)value.get() encoding:NSUTF8StringEncoding]); > >@@ -649,45 +639,22 @@ String PlatformPasteboard::readString(int index, const String& type) > 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]; >- >- if (![pasteboardItem count]) >+ id value = [m_pasteboard valuesForPasteboardType:(__bridge NSString *)kUTTypeURL inItemSet:[NSIndexSet indexSetWithIndex:index]].firstObject; >+ if (!value) > return { }; > >- id value = [pasteboardItem objectAtIndex:0]; >- NSURL *url = nil; >- 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 = [NSURL URLWithString:plistArray[0]]; >- else // The first string is the relative URL. >- url = [NSURL URLWithString:plistArray[0] relativeToURL:[NSURL URLWithString:plistArray[1]]]; >- } else { >- ASSERT([value isKindOfClass:[NSURL class]]); >- if (![value isKindOfClass:[NSURL class]]) >- return { }; >- url = (NSURL *)value; >- } >+ ASSERT([value isKindOfClass:[NSURL class]]); >+ if (![value isKindOfClass:[NSURL class]]) >+ return { }; > >+ NSURL *url = (NSURL *)value; > if (!allowReadingURLAtIndex(url, index)) > return { }; > >diff --git a/Tools/ChangeLog b/Tools/ChangeLog >index 09ea6b915195c18d78f1fa29ebb30efded4bf21a..9878ecce1c65694ae9566c8aea50a4d5c5b6b0ea 100644 >--- a/Tools/ChangeLog >+++ b/Tools/ChangeLog >@@ -1,3 +1,16 @@ >+2018-08-30 Wenson Hsieh <wenson_hsieh@apple.com> >+ >+ [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 NOBODY (OOPS!). >+ >+ See WebCore/ChangeLog for more detail. >+ >+ * TestWebKitAPI/Tests/WebKitCocoa/CopyURL.mm: >+ (createWebViewWithCustomPasteboardDataEnabled): >+ > 2018-08-30 Wenson Hsieh <wenson_hsieh@apple.com> > > [iOS] TestWebKitAPI.PasteImage tests are flaky failures >diff --git a/Tools/TestWebKitAPI/Tests/WebKitCocoa/CopyURL.mm b/Tools/TestWebKitAPI/Tests/WebKitCocoa/CopyURL.mm >index d88fa54b4ee71052ecf31f1a16526335957861e9..6acdee3c437664171d6464732dbb6e77f92498fb 100644 >--- a/Tools/TestWebKitAPI/Tests/WebKitCocoa/CopyURL.mm >+++ b/Tools/TestWebKitAPI/Tests/WebKitCocoa/CopyURL.mm >@@ -34,6 +34,7 @@ > #import <wtf/text/WTFString.h> > > #if PLATFORM(IOS) >+#import "UIKitSPI.h" > #include <MobileCoreServices/MobileCoreServices.h> > #endif > >@@ -59,6 +60,10 @@ NSString *readURLFromPasteboard() > > 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);
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 189054
:
348340
|
348341
|
348524
|
348526