[Clipboard API] Refactor Pasteboard item reading functions to work on both iOS and...
authorwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 10 Oct 2019 01:27:14 +0000 (01:27 +0000)
committerwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 10 Oct 2019 01:27:14 +0000 (01:27 +0000)
https://bugs.webkit.org/show_bug.cgi?id=202647

Reviewed by Tim Horton.

Source/WebCore:

Moves some pasteboard helper functions out of iOS-specific code, and into platform-agnostic code. See below for
more details. There is no change in behavior, as nothing exercises these new pasteboard functions on macOS yet.

* SourcesCocoa.txt:
* WebCore.xcodeproj/project.pbxproj:
* platform/Pasteboard.cpp:
(WebCore::Pasteboard::allPasteboardItemInfo const):
(WebCore::Pasteboard::pasteboardItemInfo const):
(WebCore::Pasteboard::readString):
(WebCore::Pasteboard::readBuffer):
(WebCore::Pasteboard::readURL):

Add some new helpers on Pasteboard to read Strings, data, and URLs from the platform pasteboard. These forward
to the platform strategy which, in WebKit2, are currently implemented using sync IPC, but could be changed in
the future to be fully asynchronous.

* platform/Pasteboard.h:
(WebCore::Pasteboard::name const):

Expose a cross-platform name() getter on Pasteboard. On non-Cocoa platforms, this simply returns the empty
string, but on macOS and iOS, this returns the platform pasteboard name, which is stored in m_pasteboardName.

* platform/PasteboardItemInfo.h:
(WebCore::PasteboardItemInfo::pathForContentType const):
(WebCore::PasteboardItemInfo::contentTypeForHighestFidelityItem const):
(WebCore::PasteboardItemInfo::encode const):
(WebCore::PasteboardItemInfo::decode):

Adds a couple of new members to PasteboardItemInfo (which represents metadata about a given item in the platform
pasteboard). These are changeCount (which is self explanatory), and webSafeTypesByFidelity, which is a list of
types in fidelity order which contains the list of pasteboard types that are safe to expose to bindings. These
may include types such as "text/plain", "text/html", "text/uri-list", and "image/png".

To distinguish this list from the existing contentTypesByFidelity list, I've also renamed contentTypesByFidelity
to platformTypesByFidelity, to make it more obvious that this other list of types are platform-specific, and not
generally safe to expose to the web.

* platform/PasteboardStrategy.h:
* platform/PlatformPasteboard.h:

Move several helpers out into platform-agnostic code.

* platform/cocoa/PasteboardCocoa.mm:
(WebCore::Pasteboard::fileContentState):
* platform/cocoa/PlatformPasteboardCocoa.mm: Added.

Add a new file to contain the implementation of PlatformPasteboard::allPasteboardItemInfo, which is the same
across Cocoa platforms.

(WebCore::PlatformPasteboard::allPasteboardItemInfo):
* platform/ios/PasteboardIOS.mm:
(WebCore::Pasteboard::readRespectingUTIFidelities):
* platform/ios/PlatformPasteboardIOS.mm:
(WebCore::PlatformPasteboard::informationForItemAtIndex):
(WebCore::PlatformPasteboard::readBuffer const):
(WebCore::PlatformPasteboard::readString const):
(WebCore::PlatformPasteboard::readURL const):

Additionally refactor all methods on PlatformPasteboard that take pasteboard item indices as signed integers
(`int`) to receive `size_t` values instead.

(WebCore::PlatformPasteboard::allPasteboardItemInfo): Deleted.
* platform/libwpe/PasteboardLibWPE.cpp:
(WebCore::Pasteboard::readString):
(WebCore::Pasteboard::read):
* platform/libwpe/PlatformPasteboardLibWPE.cpp:
(WebCore::PlatformPasteboard::readString const):

Add an implementation stub for WPE.

* platform/mac/PlatformPasteboardMac.mm:
(WebCore::modernPasteboardTypeForWebSafeMIMEType):
(WebCore::webSafeMIMETypeForModernPasteboardType):

Add helpers to convert between modern NSPasteboardTypes and web-safe types. While some logic exists today on
macOS to convert between legacy pasteboard types and web-safe types, conversion between the modern pasteboard
types and web-safe types are needed since NSPasteboardItem's types only support NSPasteboardTypes and
dynamically declared types that match the format of a universal type identfier (for instance, "com.foo.bar").

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

Implement all of these helpers by looking up the NSPasteboardItem at the given item index and querying it for
data for non-legacy pasteboard types.

(WebCore::PlatformPasteboard::itemAtIndex const):

Source/WebKit:

Refactor iOS-specific pasteboard functions to be platform-agnostic. See WebCore ChangeLog for more details.

* UIProcess/Cocoa/WebPasteboardProxyCocoa.mm:
(WebKit::WebPasteboardProxy::allPasteboardItemInfo):
(WebKit::WebPasteboardProxy::informationForItemAtIndex):
(WebKit::WebPasteboardProxy::getPasteboardItemsCount):
(WebKit::WebPasteboardProxy::readStringFromPasteboard):
(WebKit::WebPasteboardProxy::readURLFromPasteboard):
(WebKit::WebPasteboardProxy::readBufferFromPasteboard):
(WebKit::WebPasteboardProxy::writeURLToPasteboard):
(WebKit::WebPasteboardProxy::writeWebContentToPasteboard):
(WebKit::WebPasteboardProxy::writeImageToPasteboard):
(WebKit::WebPasteboardProxy::writeStringToPasteboard):
* UIProcess/WebPasteboardProxy.cpp:
(WebKit::WebPasteboardProxy::allPasteboardItemInfo):
(WebKit::WebPasteboardProxy::informationForItemAtIndex):
(WebKit::WebPasteboardProxy::getPasteboardItemsCount):
(WebKit::WebPasteboardProxy::readStringFromPasteboard):
(WebKit::WebPasteboardProxy::readURLFromPasteboard):
(WebKit::WebPasteboardProxy::readBufferFromPasteboard):
* UIProcess/WebPasteboardProxy.h:
* UIProcess/WebPasteboardProxy.messages.in:
* UIProcess/wpe/WebPasteboardProxyWPE.cpp:
* WebProcess/WebCoreSupport/WebPlatformStrategies.cpp:
(WebKit::WebPlatformStrategies::informationForItemAtIndex):
(WebKit::WebPlatformStrategies::readBufferFromPasteboard):
(WebKit::WebPlatformStrategies::readURLFromPasteboard):
(WebKit::WebPlatformStrategies::readStringFromPasteboard):
(WebKit::WebPlatformStrategies::writeToPasteboard):
(WebKit::WebPlatformStrategies::updateSupportedTypeIdentifiers):
* WebProcess/WebCoreSupport/WebPlatformStrategies.h:

Source/WebKitLegacy/mac:

Refactor iOS-specific pasteboard functions to be platform-agnostic. See WebCore ChangeLog for more details.

* WebCoreSupport/WebPlatformStrategies.h:
* WebCoreSupport/WebPlatformStrategies.mm:
(WebPlatformStrategies::informationForItemAtIndex):
(WebPlatformStrategies::allPasteboardItemInfo):
(WebPlatformStrategies::getPasteboardItemsCount):
(WebPlatformStrategies::readBufferFromPasteboard):
(WebPlatformStrategies::readURLFromPasteboard):
(WebPlatformStrategies::readStringFromPasteboard):
(WebPlatformStrategies::writeToPasteboard):
(WebPlatformStrategies::updateSupportedTypeIdentifiers):

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

26 files changed:
Source/WebCore/ChangeLog
Source/WebCore/SourcesCocoa.txt
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/platform/Pasteboard.cpp
Source/WebCore/platform/Pasteboard.h
Source/WebCore/platform/PasteboardItemInfo.h
Source/WebCore/platform/PasteboardStrategy.h
Source/WebCore/platform/PlatformPasteboard.h
Source/WebCore/platform/cocoa/PasteboardCocoa.mm
Source/WebCore/platform/cocoa/PlatformPasteboardCocoa.mm [new file with mode: 0644]
Source/WebCore/platform/ios/PasteboardIOS.mm
Source/WebCore/platform/ios/PlatformPasteboardIOS.mm
Source/WebCore/platform/libwpe/PasteboardLibWPE.cpp
Source/WebCore/platform/libwpe/PlatformPasteboardLibWPE.cpp
Source/WebCore/platform/mac/PlatformPasteboardMac.mm
Source/WebKit/ChangeLog
Source/WebKit/UIProcess/Cocoa/WebPasteboardProxyCocoa.mm
Source/WebKit/UIProcess/WebPasteboardProxy.cpp
Source/WebKit/UIProcess/WebPasteboardProxy.h
Source/WebKit/UIProcess/WebPasteboardProxy.messages.in
Source/WebKit/UIProcess/wpe/WebPasteboardProxyWPE.cpp
Source/WebKit/WebProcess/WebCoreSupport/WebPlatformStrategies.cpp
Source/WebKit/WebProcess/WebCoreSupport/WebPlatformStrategies.h
Source/WebKitLegacy/mac/ChangeLog
Source/WebKitLegacy/mac/WebCoreSupport/WebPlatformStrategies.h
Source/WebKitLegacy/mac/WebCoreSupport/WebPlatformStrategies.mm

index 985784e..83252d6 100644 (file)
@@ -1,3 +1,100 @@
+2019-10-09  Wenson Hsieh  <wenson_hsieh@apple.com>
+
+        [Clipboard API] Refactor Pasteboard item reading functions to work on both iOS and macOS
+        https://bugs.webkit.org/show_bug.cgi?id=202647
+
+        Reviewed by Tim Horton.
+
+        Moves some pasteboard helper functions out of iOS-specific code, and into platform-agnostic code. See below for
+        more details. There is no change in behavior, as nothing exercises these new pasteboard functions on macOS yet.
+
+        * SourcesCocoa.txt:
+        * WebCore.xcodeproj/project.pbxproj:
+        * platform/Pasteboard.cpp:
+        (WebCore::Pasteboard::allPasteboardItemInfo const):
+        (WebCore::Pasteboard::pasteboardItemInfo const):
+        (WebCore::Pasteboard::readString):
+        (WebCore::Pasteboard::readBuffer):
+        (WebCore::Pasteboard::readURL):
+
+        Add some new helpers on Pasteboard to read Strings, data, and URLs from the platform pasteboard. These forward
+        to the platform strategy which, in WebKit2, are currently implemented using sync IPC, but could be changed in
+        the future to be fully asynchronous.
+
+        * platform/Pasteboard.h:
+        (WebCore::Pasteboard::name const):
+
+        Expose a cross-platform name() getter on Pasteboard. On non-Cocoa platforms, this simply returns the empty
+        string, but on macOS and iOS, this returns the platform pasteboard name, which is stored in m_pasteboardName.
+
+        * platform/PasteboardItemInfo.h:
+        (WebCore::PasteboardItemInfo::pathForContentType const):
+        (WebCore::PasteboardItemInfo::contentTypeForHighestFidelityItem const):
+        (WebCore::PasteboardItemInfo::encode const):
+        (WebCore::PasteboardItemInfo::decode):
+
+        Adds a couple of new members to PasteboardItemInfo (which represents metadata about a given item in the platform
+        pasteboard). These are changeCount (which is self explanatory), and webSafeTypesByFidelity, which is a list of
+        types in fidelity order which contains the list of pasteboard types that are safe to expose to bindings. These
+        may include types such as "text/plain", "text/html", "text/uri-list", and "image/png".
+
+        To distinguish this list from the existing contentTypesByFidelity list, I've also renamed contentTypesByFidelity
+        to platformTypesByFidelity, to make it more obvious that this other list of types are platform-specific, and not
+        generally safe to expose to the web.
+
+        * platform/PasteboardStrategy.h:
+        * platform/PlatformPasteboard.h:
+
+        Move several helpers out into platform-agnostic code.
+
+        * platform/cocoa/PasteboardCocoa.mm:
+        (WebCore::Pasteboard::fileContentState):
+        * platform/cocoa/PlatformPasteboardCocoa.mm: Added.
+
+        Add a new file to contain the implementation of PlatformPasteboard::allPasteboardItemInfo, which is the same
+        across Cocoa platforms.
+
+        (WebCore::PlatformPasteboard::allPasteboardItemInfo):
+        * platform/ios/PasteboardIOS.mm:
+        (WebCore::Pasteboard::readRespectingUTIFidelities):
+        * platform/ios/PlatformPasteboardIOS.mm:
+        (WebCore::PlatformPasteboard::informationForItemAtIndex):
+        (WebCore::PlatformPasteboard::readBuffer const):
+        (WebCore::PlatformPasteboard::readString const):
+        (WebCore::PlatformPasteboard::readURL const):
+
+        Additionally refactor all methods on PlatformPasteboard that take pasteboard item indices as signed integers
+        (`int`) to receive `size_t` values instead.
+
+        (WebCore::PlatformPasteboard::allPasteboardItemInfo): Deleted.
+        * platform/libwpe/PasteboardLibWPE.cpp:
+        (WebCore::Pasteboard::readString):
+        (WebCore::Pasteboard::read):
+        * platform/libwpe/PlatformPasteboardLibWPE.cpp:
+        (WebCore::PlatformPasteboard::readString const):
+
+        Add an implementation stub for WPE.
+
+        * platform/mac/PlatformPasteboardMac.mm:
+        (WebCore::modernPasteboardTypeForWebSafeMIMEType):
+        (WebCore::webSafeMIMETypeForModernPasteboardType):
+
+        Add helpers to convert between modern NSPasteboardTypes and web-safe types. While some logic exists today on
+        macOS to convert between legacy pasteboard types and web-safe types, conversion between the modern pasteboard
+        types and web-safe types are needed since NSPasteboardItem's types only support NSPasteboardTypes and
+        dynamically declared types that match the format of a universal type identfier (for instance, "com.foo.bar").
+
+        (WebCore::PlatformPasteboard::readBuffer const):
+        (WebCore::PlatformPasteboard::readString const):
+        (WebCore::PlatformPasteboard::readURL const):
+        (WebCore::PlatformPasteboard::count const):
+        (WebCore::PlatformPasteboard::informationForItemAtIndex):
+
+        Implement all of these helpers by looking up the NSPasteboardItem at the given item index and querying it for
+        data for non-legacy pasteboard types.
+
+        (WebCore::PlatformPasteboard::itemAtIndex const):
+
 2019-10-09  Daniel Bates  <dabates@apple.com>
 
         Add support for CompactPointerTuple<..., OptionSet<...>>
index a0692a8..0957943 100644 (file)
@@ -198,6 +198,7 @@ platform/cocoa/MIMETypeRegistryCocoa.mm
 platform/cocoa/NetworkExtensionContentFilter.mm
 platform/cocoa/ParentalControlsContentFilter.mm
 platform/cocoa/PasteboardCocoa.mm
+platform/cocoa/PlatformPasteboardCocoa.mm
 platform/cocoa/PlaybackSessionModelMediaElement.mm
 platform/cocoa/RuntimeApplicationChecksCocoa.mm
 platform/cocoa/ScrollController.mm
index 6709bf5..4955404 100644 (file)
                F44EBBDA1DB5DD9D00277334 /* StaticRange.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = StaticRange.cpp; sourceTree = "<group>"; };
                F45C231B1995B73B00A6E2E3 /* AxisScrollSnapOffsets.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = AxisScrollSnapOffsets.cpp; sourceTree = "<group>"; };
                F45C231C1995B73B00A6E2E3 /* AxisScrollSnapOffsets.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AxisScrollSnapOffsets.h; sourceTree = "<group>"; };
+               F4628A9E234D3BBF00BC884C /* PlatformPasteboardCocoa.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = PlatformPasteboardCocoa.mm; sourceTree = "<group>"; };
                F46729251E0DE5AB00ACC3D8 /* ScrollSnapOffsetsInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ScrollSnapOffsetsInfo.h; sourceTree = "<group>"; };
                F478755219983AFF0024A287 /* ScrollSnapAnimatorState.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ScrollSnapAnimatorState.h; sourceTree = "<group>"; };
                F478755319983AFF0024A287 /* ScrollSnapAnimatorState.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ScrollSnapAnimatorState.mm; sourceTree = "<group>"; };
                                A18890AD1AA13F250026C301 /* ParentalControlsContentFilter.h */,
                                A18890AC1AA13F250026C301 /* ParentalControlsContentFilter.mm */,
                                9BED2CAF1F7CC06200666018 /* PasteboardCocoa.mm */,
+                               F4628A9E234D3BBF00BC884C /* PlatformPasteboardCocoa.mm */,
                                52B0D4BD1C57FD1E0077CE53 /* PlatformView.h */,
                                CDA29A081CBD99F400901CCF /* PlaybackSessionInterface.h */,
                                CDA29A0A1CBD9A7400901CCF /* PlaybackSessionModel.h */,
index 555ec28..8f9bab8 100644 (file)
@@ -98,4 +98,29 @@ Vector<String> Pasteboard::readAllStrings(const String& type)
 
 #endif
 
+Vector<PasteboardItemInfo> Pasteboard::allPasteboardItemInfo() const
+{
+    return platformStrategies()->pasteboardStrategy()->allPasteboardItemInfo(name());
+}
+
+PasteboardItemInfo Pasteboard::pasteboardItemInfo(size_t index) const
+{
+    return platformStrategies()->pasteboardStrategy()->informationForItemAtIndex(index, name());
+}
+
+String Pasteboard::readString(size_t index, const String& type)
+{
+    return platformStrategies()->pasteboardStrategy()->readStringFromPasteboard(index, type, name());
+}
+
+RefPtr<WebCore::SharedBuffer> Pasteboard::readBuffer(size_t index, const String& type)
+{
+    return platformStrategies()->pasteboardStrategy()->readBufferFromPasteboard(index, type, name());
+}
+
+URL Pasteboard::readURL(size_t index, String& title)
+{
+    return platformStrategies()->pasteboardStrategy()->readURLFromPasteboard(index, name(), title);
+}
+
 };
index fb860e1..6987ed2 100644 (file)
@@ -265,11 +265,16 @@ public:
 #if PLATFORM(COCOA)
     static bool shouldTreatCocoaTypeAsFile(const String&);
     WEBCORE_EXPORT static NSArray *supportedFileUploadPasteboardTypes();
-    const String& name() const { return m_pasteboardName; }
     long changeCount() const;
     const PasteboardCustomData& readCustomData();
 #endif
 
+#if PLATFORM(COCOA)
+    const String& name() const { return m_pasteboardName; }
+#else
+    const String& name() const { return emptyString(); }
+#endif
+
 #if PLATFORM(WIN)
     COMPtr<IDataObject> dataObject() const { return m_dataObject; }
     void setExternalDataObject(IDataObject*);
@@ -279,6 +284,13 @@ public:
     void writeImageToDataObject(Element&, const URL&); // FIXME: Layering violation.
 #endif
 
+    Vector<PasteboardItemInfo> allPasteboardItemInfo() const;
+    PasteboardItemInfo pasteboardItemInfo(size_t index) const;
+
+    String readString(size_t index, const String& type);
+    RefPtr<WebCore::SharedBuffer> readBuffer(size_t index, const String& type);
+    URL readURL(size_t index, String& title);
+
 private:
 #if PLATFORM(IOS_FAMILY)
     bool respectsUTIFidelities() const;
index d1d2308..3b397c3 100644 (file)
@@ -66,18 +66,20 @@ Optional<PresentationSize> PresentationSize::decode(Decoder& decoder)
 
 struct PasteboardItemInfo {
     Vector<String> pathsForFileUpload;
-    Vector<String> contentTypesForFileUpload;
-    Vector<String> contentTypesByFidelity;
+    Vector<String> platformTypesForFileUpload;
+    Vector<String> platformTypesByFidelity;
     String suggestedFileName;
     PresentationSize preferredPresentationSize;
     bool isNonTextType { false };
     bool containsFileURLAndFileUploadContent { false };
+    Vector<String> webSafeTypesByFidelity;
+    int changeCount { 0 };
     PasteboardItemPresentationStyle preferredPresentationStyle { PasteboardItemPresentationStyle::Unspecified };
 
     String pathForContentType(const String& type) const
     {
-        ASSERT(pathsForFileUpload.size() == contentTypesForFileUpload.size());
-        auto index = contentTypesForFileUpload.find(type);
+        ASSERT(pathsForFileUpload.size() == platformTypesForFileUpload.size());
+        auto index = platformTypesForFileUpload.find(type);
         if (index == notFound)
             return { };
 
@@ -104,10 +106,10 @@ struct PasteboardItemInfo {
 
     String contentTypeForHighestFidelityItem() const
     {
-        if (contentTypesForFileUpload.isEmpty())
+        if (platformTypesForFileUpload.isEmpty())
             return { };
 
-        return contentTypesForFileUpload.first();
+        return platformTypesForFileUpload.first();
     }
 
     String pathForHighestFidelityItem() const
@@ -125,7 +127,7 @@ struct PasteboardItemInfo {
 template<class Encoder>
 void PasteboardItemInfo::encode(Encoder& encoder) const
 {
-    encoder << pathsForFileUpload << contentTypesForFileUpload << contentTypesByFidelity << suggestedFileName << preferredPresentationSize << isNonTextType << containsFileURLAndFileUploadContent;
+    encoder << pathsForFileUpload << platformTypesForFileUpload << platformTypesByFidelity << suggestedFileName << preferredPresentationSize << isNonTextType << containsFileURLAndFileUploadContent << webSafeTypesByFidelity << changeCount;
     encoder.encodeEnum(preferredPresentationStyle);
 }
 
@@ -136,10 +138,10 @@ Optional<PasteboardItemInfo> PasteboardItemInfo::decode(Decoder& decoder)
     if (!decoder.decode(result.pathsForFileUpload))
         return WTF::nullopt;
 
-    if (!decoder.decode(result.contentTypesForFileUpload))
+    if (!decoder.decode(result.platformTypesForFileUpload))
         return WTF::nullopt;
 
-    if (!decoder.decode(result.contentTypesByFidelity))
+    if (!decoder.decode(result.platformTypesByFidelity))
         return WTF::nullopt;
 
     if (!decoder.decode(result.suggestedFileName))
@@ -154,6 +156,12 @@ Optional<PasteboardItemInfo> PasteboardItemInfo::decode(Decoder& decoder)
     if (!decoder.decode(result.containsFileURLAndFileUploadContent))
         return WTF::nullopt;
 
+    if (!decoder.decode(result.webSafeTypesByFidelity))
+        return WTF::nullopt;
+
+    if (!decoder.decode(result.changeCount))
+        return WTF::nullopt;
+
     if (!decoder.decodeEnum(result.preferredPresentationStyle))
         return WTF::nullopt;
 
index dc16f0f..577caf8 100644 (file)
@@ -46,12 +46,6 @@ public:
     virtual void writeToPasteboard(const PasteboardWebContent&, const String& pasteboardName) = 0;
     virtual void writeToPasteboard(const PasteboardImage&, const String& pasteboardName) = 0;
     virtual void writeToPasteboard(const String& pasteboardType, const String&, const String& pasteboardName) = 0;
-    virtual int getPasteboardItemsCount(const String& pasteboardName) = 0;
-    virtual String readStringFromPasteboard(int index, const String& pasteboardType, const String& pasteboardName) = 0;
-    virtual RefPtr<SharedBuffer> readBufferFromPasteboard(int index, const String& pasteboardType, const String& pasteboardName) = 0;
-    virtual URL readURLFromPasteboard(int index, const String& pasteboardName, String& title) = 0;
-    virtual Vector<PasteboardItemInfo> allPasteboardItemInfo(const String& pasteboardName) = 0;
-    virtual PasteboardItemInfo informationForItemAtIndex(int index, const String& pasteboardName) = 0;
     virtual void updateSupportedTypeIdentifiers(const Vector<String>& identifiers, const String& pasteboardName) = 0;
 #endif // PLATFORM(IOS_FAMILY)
 #if PLATFORM(COCOA)
@@ -73,6 +67,12 @@ public:
     virtual long setColor(const Color&, const String& pasteboardName) = 0;
     virtual long setStringForType(const String&, const String& pasteboardType, const String& pasteboardName) = 0;
 #endif
+    virtual String readStringFromPasteboard(size_t index, const String& pasteboardType, const String& pasteboardName) = 0;
+    virtual RefPtr<SharedBuffer> readBufferFromPasteboard(size_t index, const String& pasteboardType, const String& pasteboardName) = 0;
+    virtual URL readURLFromPasteboard(size_t index, const String& pasteboardName, String& title) = 0;
+    virtual PasteboardItemInfo informationForItemAtIndex(size_t index, const String& pasteboardName) = 0;
+    virtual Vector<PasteboardItemInfo> allPasteboardItemInfo(const String& pasteboardName) = 0;
+    virtual int getPasteboardItemsCount(const String& pasteboardName) = 0;
 
     virtual Vector<String> typesSafeForDOMToReadAndWrite(const String& pasteboardName, const String& origin) = 0;
     virtual long writeCustomData(const PasteboardCustomData&, const String& pasteboardName) = 0;
@@ -84,7 +84,6 @@ public:
 
 #if USE(LIBWPE)
     virtual void getTypes(Vector<String>& types) = 0;
-    virtual String readStringFromPasteboard(int index, const String& pasteboardType) = 0;
     virtual void writeToPasteboard(const PasteboardWebContent&) = 0;
     virtual void writeToPasteboard(const String& pasteboardType, const String&) = 0;
 #endif
index e033150..df0393e 100644 (file)
@@ -33,6 +33,7 @@
 
 #if PLATFORM(MAC)
 OBJC_CLASS NSPasteboard;
+OBJC_CLASS NSPasteboardItem;
 #endif
 
 #if PLATFORM(IOS_FAMILY)
@@ -59,10 +60,10 @@ public:
     WEBCORE_EXPORT explicit PlatformPasteboard(const String& pasteboardName);
 #if PLATFORM(IOS_FAMILY) || USE(LIBWPE)
     WEBCORE_EXPORT PlatformPasteboard();
-    WEBCORE_EXPORT Vector<PasteboardItemInfo> allPasteboardItemInfo();
-    WEBCORE_EXPORT PasteboardItemInfo informationForItemAtIndex(int index);
     WEBCORE_EXPORT void updateSupportedTypeIdentifiers(const Vector<String>& types);
 #endif
+    WEBCORE_EXPORT PasteboardItemInfo informationForItemAtIndex(size_t index);
+    WEBCORE_EXPORT Vector<PasteboardItemInfo> allPasteboardItemInfo();
     WEBCORE_EXPORT static String uniqueName();
 
     WEBCORE_EXPORT static String platformPasteboardTypeForSafeTypeForDOMToReadAndWrite(const String& domType);
@@ -90,9 +91,9 @@ 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) const;
-    WEBCORE_EXPORT String readString(int index, const String& pasteboardType) const;
-    WEBCORE_EXPORT URL readURL(int index, String& title) const;
+    WEBCORE_EXPORT RefPtr<SharedBuffer> readBuffer(size_t index, const String& pasteboardType) const;
+    WEBCORE_EXPORT String readString(size_t index, const String& pasteboardType) const;
+    WEBCORE_EXPORT URL readURL(size_t index, String& title) const;
     WEBCORE_EXPORT int count() const;
     WEBCORE_EXPORT int numberOfFiles() const;
 
@@ -110,6 +111,10 @@ private:
 #endif
 
 #if PLATFORM(MAC)
+    NSPasteboardItem *itemAtIndex(size_t index) const;
+#endif
+
+#if PLATFORM(MAC)
     RetainPtr<NSPasteboard> m_pasteboard;
 #endif
 #if PLATFORM(IOS_FAMILY)
index 2647480..c0fba4b 100644 (file)
@@ -148,7 +148,7 @@ Pasteboard::FileContentState Pasteboard::fileContentState()
         // If the item can't be treated as an attachment, it's very likely that the content being dropped is just
         // an inline piece of text, with no files in the pasteboard (and therefore, no risk of leaking file paths
         // to web content). In cases such as these, we should not suppress DataTransfer access.
-        auto items = platformStrategies()->pasteboardStrategy()->allPasteboardItemInfo(m_pasteboardName);
+        auto items = allPasteboardItemInfo();
         mayContainFilePaths = items.size() != 1 || notFound != items.findMatching([] (auto& item) {
             return item.canBeTreatedAsAttachmentOrFile() || item.isNonTextType || item.containsFileURLAndFileUploadContent;
         });
diff --git a/Source/WebCore/platform/cocoa/PlatformPasteboardCocoa.mm b/Source/WebCore/platform/cocoa/PlatformPasteboardCocoa.mm
new file mode 100644 (file)
index 0000000..3495433
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2019 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 "PlatformPasteboard.h"
+
+#import "PasteboardItemInfo.h"
+
+namespace WebCore {
+
+Vector<PasteboardItemInfo> PlatformPasteboard::allPasteboardItemInfo()
+{
+    Vector<PasteboardItemInfo> itemInfo;
+    int numberOfItems = count();
+    itemInfo.reserveInitialCapacity(numberOfItems);
+    for (NSInteger itemIndex = 0; itemIndex < numberOfItems; ++itemIndex)
+        itemInfo.uncheckedAppend(informationForItemAtIndex(itemIndex));
+    return itemInfo;
+}
+
+} // namespace WebCore
index 0271b93..e1ce2f3 100644 (file)
@@ -355,7 +355,7 @@ void Pasteboard::readRespectingUTIFidelities(PasteboardWebContentReader& reader,
         // Try to read data from each type identifier that this pasteboard item supports, and WebKit also recognizes. Type identifiers are
         // read in order of fidelity, as specified by each pasteboard item.
         ReaderResult result = ReaderResult::DidNotReadType;
-        for (auto& type : info.contentTypesByFidelity) {
+        for (auto& type : info.platformTypesByFidelity) {
             if (!isTypeAllowedByReadingPolicy(type, policy))
                 continue;
 
index d8c56f9..916daeb 100644 (file)
@@ -116,17 +116,9 @@ static PasteboardItemPresentationStyle pasteboardItemPresentationStyle(UIPreferr
 
 #endif // PASTEBOARD_SUPPORTS_PRESENTATION_STYLE_AND_TEAM_DATA
 
-Vector<PasteboardItemInfo> PlatformPasteboard::allPasteboardItemInfo()
+PasteboardItemInfo PlatformPasteboard::informationForItemAtIndex(size_t index)
 {
-    Vector<PasteboardItemInfo> itemInfo;
-    for (NSInteger itemIndex = 0; itemIndex < [m_pasteboard numberOfItems]; ++itemIndex)
-        itemInfo.append(informationForItemAtIndex(itemIndex));
-    return itemInfo;
-}
-
-PasteboardItemInfo PlatformPasteboard::informationForItemAtIndex(int index)
-{
-    if (index >= [m_pasteboard numberOfItems])
+    if (index >= static_cast<NSUInteger>([m_pasteboard numberOfItems]))
         return { };
 
     PasteboardItemInfo info;
@@ -140,15 +132,15 @@ PasteboardItemInfo PlatformPasteboard::informationForItemAtIndex(int index)
         for (NSURL *url in urls)
             info.pathsForFileUpload.uncheckedAppend(url.path);
 
-        info.contentTypesForFileUpload.reserveInitialCapacity(fileTypes.count);
+        info.platformTypesForFileUpload.reserveInitialCapacity(fileTypes.count);
         for (NSString *fileType in fileTypes)
-            info.contentTypesForFileUpload.uncheckedAppend(fileType);
+            info.platformTypesForFileUpload.uncheckedAppend(fileType);
     } else {
         NSArray *fileTypes = itemProvider.web_fileUploadContentTypes;
-        info.contentTypesForFileUpload.reserveInitialCapacity(fileTypes.count);
+        info.platformTypesForFileUpload.reserveInitialCapacity(fileTypes.count);
         info.pathsForFileUpload.reserveInitialCapacity(fileTypes.count);
         for (NSString *fileType in fileTypes) {
-            info.contentTypesForFileUpload.uncheckedAppend(fileType);
+            info.platformTypesForFileUpload.uncheckedAppend(fileType);
             info.pathsForFileUpload.uncheckedAppend({ });
         }
     }
@@ -168,9 +160,9 @@ PasteboardItemInfo PlatformPasteboard::informationForItemAtIndex(int index)
     info.containsFileURLAndFileUploadContent = itemProvider.web_containsFileURLAndFileUploadContent;
     info.suggestedFileName = itemProvider.suggestedName;
     NSArray<NSString *> *registeredTypeIdentifiers = itemProvider.registeredTypeIdentifiers;
-    info.contentTypesByFidelity.reserveInitialCapacity(registeredTypeIdentifiers.count);
+    info.platformTypesByFidelity.reserveInitialCapacity(registeredTypeIdentifiers.count);
     for (NSString *typeIdentifier in registeredTypeIdentifiers) {
-        info.contentTypesByFidelity.uncheckedAppend(typeIdentifier);
+        info.platformTypesByFidelity.uncheckedAppend(typeIdentifier);
         CFStringRef cfTypeIdentifier = (CFStringRef)typeIdentifier;
         if (!UTTypeIsDeclared(cfTypeIdentifier))
             continue;
@@ -190,17 +182,14 @@ PasteboardItemInfo PlatformPasteboard::informationForItemAtIndex(int index)
         info.isNonTextType = true;
     }
 
+    info.changeCount = changeCount();
+
     return info;
 }
 
 #else
 
-PasteboardItemInfo PlatformPasteboard::informationForItemAtIndex(int)
-{
-    return { };
-}
-
-Vector<PasteboardItemInfo> PlatformPasteboard::allPasteboardItemInfo()
+PasteboardItemInfo PlatformPasteboard::informationForItemAtIndex(size_t)
 {
     return { };
 }
@@ -656,7 +645,7 @@ Vector<String> PlatformPasteboard::allStringsForType(const String& type) const
     return strings;
 }
 
-RefPtr<SharedBuffer> PlatformPasteboard::readBuffer(int index, const String& type) const
+RefPtr<SharedBuffer> PlatformPasteboard::readBuffer(size_t index, const String& type) const
 {
     NSIndexSet *indexSet = [NSIndexSet indexSetWithIndex:index];
 
@@ -667,7 +656,7 @@ RefPtr<SharedBuffer> PlatformPasteboard::readBuffer(int index, const String& typ
     return SharedBuffer::create([pasteboardItem.get() objectAtIndex:0]);
 }
 
-String PlatformPasteboard::readString(int index, const String& type) const
+String PlatformPasteboard::readString(size_t index, const String& type) const
 {
     if (type == String(kUTTypeURL)) {
         String title;
@@ -697,7 +686,7 @@ String PlatformPasteboard::readString(int index, const String& type) const
     return String();
 }
 
-URL PlatformPasteboard::readURL(int index, String& title) const
+URL PlatformPasteboard::readURL(size_t index, String& title) const
 {
     id value = [m_pasteboard valuesForPasteboardType:(__bridge NSString *)kUTTypeURL inItemSet:[NSIndexSet indexSetWithIndex:index]].firstObject;
     if (!value)
index f8a61ec..43ba9e4 100644 (file)
@@ -72,7 +72,7 @@ String Pasteboard::readOrigin()
 
 String Pasteboard::readString(const String& type)
 {
-    return platformStrategies()->pasteboardStrategy()->readStringFromPasteboard(0, type);
+    return platformStrategies()->pasteboardStrategy()->readStringFromPasteboard(0, type, name());
 }
 
 String Pasteboard::readStringInCustomData(const String&)
@@ -96,7 +96,7 @@ void Pasteboard::clear(const String&)
 
 void Pasteboard::read(PasteboardPlainText& text)
 {
-    text.text = platformStrategies()->pasteboardStrategy()->readStringFromPasteboard(0, "text/plain;charset=utf-8");
+    text.text = platformStrategies()->pasteboardStrategy()->readStringFromPasteboard(0, "text/plain;charset=utf-8", name());
 }
 
 void Pasteboard::read(PasteboardWebContentReader&, WebContentReadingPolicy)
index 0fdb75d..e540c35 100644 (file)
@@ -60,7 +60,7 @@ void PlatformPasteboard::getTypes(Vector<String>& types)
     wpe_pasteboard_string_vector_free(&pasteboardTypes);
 }
 
-String PlatformPasteboard::readString(int, const String& type) const
+String PlatformPasteboard::readString(size_t, const String& type) const
 {
     struct wpe_pasteboard_string string = { nullptr, 0 };
     wpe_pasteboard_get_string(m_pasteboard, type.utf8().data(), &string);
index 0cb1dd8..194addb 100644 (file)
@@ -384,6 +384,116 @@ long PlatformPasteboard::setStringForType(const String& string, const String& pa
     return changeCount();
 }
 
+static NSPasteboardType modernPasteboardTypeForWebSafeMIMEType(const String& webSafeType)
+{
+    if (webSafeType == "text/plain"_s)
+        return NSPasteboardTypeString;
+    if (webSafeType == "text/html"_s)
+        return NSPasteboardTypeHTML;
+    if (webSafeType == "text/uri-list"_s)
+        return NSPasteboardTypeURL;
+    if (webSafeType == "image/png"_s)
+        return NSPasteboardTypePNG;
+    return nil;
+}
+
+enum class ContainsFileURL { No, Yes };
+static String webSafeMIMETypeForModernPasteboardType(NSPasteboardType platformType, ContainsFileURL containsFileURL)
+{
+    if ([platformType isEqual:NSPasteboardTypeString] && containsFileURL == ContainsFileURL::No)
+        return "text/plain"_s;
+    if ([platformType isEqual:NSPasteboardTypeHTML] || [platformType isEqual:NSPasteboardTypeRTF] || [platformType isEqual:NSPasteboardTypeRTFD])
+        return "text/html"_s;
+    if ([platformType isEqual:NSPasteboardTypeURL] && containsFileURL == ContainsFileURL::No)
+        return "text/uri-list"_s;
+    if ([platformType isEqual:NSPasteboardTypePNG] || [platformType isEqual:NSPasteboardTypeTIFF])
+        return "image/png"_s;
+    return { };
+}
+
+RefPtr<SharedBuffer> PlatformPasteboard::readBuffer(size_t index, const String& type) const
+{
+    NSPasteboardItem *item = itemAtIndex(index);
+    if (!item)
+        return { };
+
+    auto platformType = modernPasteboardTypeForWebSafeMIMEType(type);
+    if (!platformType)
+        return nullptr;
+
+    if (NSData *data = [item dataForType:platformType]) {
+        auto nsData = adoptNS(data.copy);
+        return SharedBuffer::create(nsData.get());
+    }
+
+    return nullptr;
+}
+
+String PlatformPasteboard::readString(size_t index, const String& type) const
+{
+    NSPasteboardItem *item = itemAtIndex(index);
+    if (!item)
+        return { };
+
+    auto platformType = modernPasteboardTypeForWebSafeMIMEType(type);
+    if (!platformType)
+        return { };
+
+    return [item stringForType:platformType];
+}
+
+URL PlatformPasteboard::readURL(size_t index, String& title) const
+{
+    title = emptyString();
+
+    NSPasteboardItem *item = itemAtIndex(index);
+    if (!item)
+        return { };
+
+    RetainPtr<NSURL> url;
+    if (id propertyList = [item propertyListForType:NSPasteboardTypeURL])
+        url = adoptNS([[NSURL alloc] initWithPasteboardPropertyList:propertyList ofType:NSPasteboardTypeURL]);
+    else if (NSString *absoluteString = [item stringForType:NSPasteboardTypeURL])
+        url = [NSURL URLWithString:absoluteString];
+    return { [url isFileURL] ? nil : url.get() };
+}
+
+int PlatformPasteboard::count() const
+{
+    return [m_pasteboard pasteboardItems].count;
+}
+
+PasteboardItemInfo PlatformPasteboard::informationForItemAtIndex(size_t index)
+{
+    NSPasteboardItem *item = itemAtIndex(index);
+    if (!item)
+        return { };
+
+    PasteboardItemInfo info;
+    NSArray<NSPasteboardType> *platformTypes = [item types];
+    auto containsFileURL = [platformTypes containsObject:NSPasteboardTypeFileURL] ? ContainsFileURL::Yes : ContainsFileURL::No;
+    ListHashSet<String> webSafeTypes;
+    info.platformTypesByFidelity.reserveInitialCapacity(platformTypes.count);
+    for (NSPasteboardType type in platformTypes) {
+        info.platformTypesByFidelity.uncheckedAppend(type);
+        auto webSafeType = webSafeMIMETypeForModernPasteboardType(type, containsFileURL);
+        if (webSafeType.isEmpty())
+            continue;
+
+        webSafeTypes.add(WTFMove(webSafeType));
+    }
+    info.containsFileURLAndFileUploadContent = containsFileURL == ContainsFileURL::Yes;
+    info.webSafeTypesByFidelity = copyToVector(webSafeTypes);
+    info.changeCount = changeCount();
+    return info;
+}
+
+NSPasteboardItem *PlatformPasteboard::itemAtIndex(size_t index) const
+{
+    NSArray<NSPasteboardItem *> *items = [m_pasteboard pasteboardItems];
+    return index >= items.count ? nil : items[index];
+}
+
 }
 
 #endif // PLATFORM(MAC)
index fd557a6..4d2c0d1 100644 (file)
@@ -1,3 +1,42 @@
+2019-10-09  Wenson Hsieh  <wenson_hsieh@apple.com>
+
+        [Clipboard API] Refactor Pasteboard item reading functions to work on both iOS and macOS
+        https://bugs.webkit.org/show_bug.cgi?id=202647
+
+        Reviewed by Tim Horton.
+
+        Refactor iOS-specific pasteboard functions to be platform-agnostic. See WebCore ChangeLog for more details.
+
+        * UIProcess/Cocoa/WebPasteboardProxyCocoa.mm:
+        (WebKit::WebPasteboardProxy::allPasteboardItemInfo):
+        (WebKit::WebPasteboardProxy::informationForItemAtIndex):
+        (WebKit::WebPasteboardProxy::getPasteboardItemsCount):
+        (WebKit::WebPasteboardProxy::readStringFromPasteboard):
+        (WebKit::WebPasteboardProxy::readURLFromPasteboard):
+        (WebKit::WebPasteboardProxy::readBufferFromPasteboard):
+        (WebKit::WebPasteboardProxy::writeURLToPasteboard):
+        (WebKit::WebPasteboardProxy::writeWebContentToPasteboard):
+        (WebKit::WebPasteboardProxy::writeImageToPasteboard):
+        (WebKit::WebPasteboardProxy::writeStringToPasteboard):
+        * UIProcess/WebPasteboardProxy.cpp:
+        (WebKit::WebPasteboardProxy::allPasteboardItemInfo):
+        (WebKit::WebPasteboardProxy::informationForItemAtIndex):
+        (WebKit::WebPasteboardProxy::getPasteboardItemsCount):
+        (WebKit::WebPasteboardProxy::readStringFromPasteboard):
+        (WebKit::WebPasteboardProxy::readURLFromPasteboard):
+        (WebKit::WebPasteboardProxy::readBufferFromPasteboard):
+        * UIProcess/WebPasteboardProxy.h:
+        * UIProcess/WebPasteboardProxy.messages.in:
+        * UIProcess/wpe/WebPasteboardProxyWPE.cpp:
+        * WebProcess/WebCoreSupport/WebPlatformStrategies.cpp:
+        (WebKit::WebPlatformStrategies::informationForItemAtIndex):
+        (WebKit::WebPlatformStrategies::readBufferFromPasteboard):
+        (WebKit::WebPlatformStrategies::readURLFromPasteboard):
+        (WebKit::WebPlatformStrategies::readStringFromPasteboard):
+        (WebKit::WebPlatformStrategies::writeToPasteboard):
+        (WebKit::WebPlatformStrategies::updateSupportedTypeIdentifiers):
+        * WebProcess/WebCoreSupport/WebPlatformStrategies.h:
+
 2019-10-09  John Wilander  <wilander@apple.com>
 
         IsLoggedIn: Add as experimental feature
index de395da..0a18174 100644 (file)
@@ -180,41 +180,34 @@ void WebPasteboardProxy::writeCustomData(const WebCore::PasteboardCustomData& da
     completionHandler(PlatformPasteboard(pasteboardName).write(data));
 }
 
-#if PLATFORM(IOS_FAMILY)
-
-void WebPasteboardProxy::writeURLToPasteboard(const PasteboardURL& url, const String& pasteboardName)
-{
-    PlatformPasteboard(pasteboardName).write(url);
-}
-
-void WebPasteboardProxy::writeWebContentToPasteboard(const WebCore::PasteboardWebContent& content, const String& pasteboardName)
+void WebPasteboardProxy::allPasteboardItemInfo(const String& pasteboardName, CompletionHandler<void(Vector<PasteboardItemInfo>&&)>&& completionHandler)
 {
-    PlatformPasteboard(pasteboardName).write(content);
+    completionHandler(PlatformPasteboard(pasteboardName).allPasteboardItemInfo());
 }
 
-void WebPasteboardProxy::writeImageToPasteboard(const WebCore::PasteboardImage& pasteboardImage, const String& pasteboardName)
+void WebPasteboardProxy::informationForItemAtIndex(size_t index, const String& pasteboardName, CompletionHandler<void(PasteboardItemInfo&&)>&& completionHandler)
 {
-    PlatformPasteboard(pasteboardName).write(pasteboardImage);
+    completionHandler(PlatformPasteboard(pasteboardName).informationForItemAtIndex(index));
 }
 
-void WebPasteboardProxy::writeStringToPasteboard(const String& pasteboardType, const String& text, const String& pasteboardName)
+void WebPasteboardProxy::getPasteboardItemsCount(const String& pasteboardName, CompletionHandler<void(uint64_t)>&& completionHandler)
 {
-    PlatformPasteboard(pasteboardName).write(pasteboardType, text);
+    completionHandler(PlatformPasteboard(pasteboardName).count());
 }
 
-void WebPasteboardProxy::readStringFromPasteboard(uint64_t index, const String& pasteboardType, const String& pasteboardName, CompletionHandler<void(String&&)>&& completionHandler)
+void WebPasteboardProxy::readStringFromPasteboard(size_t index, const String& pasteboardType, const String& pasteboardName, CompletionHandler<void(String&&)>&& completionHandler)
 {
     completionHandler(PlatformPasteboard(pasteboardName).readString(index, pasteboardType));
 }
 
-void WebPasteboardProxy::readURLFromPasteboard(uint64_t index, const String& pasteboardName, CompletionHandler<void(String&& url, String&& title)>&& completionHandler)
+void WebPasteboardProxy::readURLFromPasteboard(size_t index, const String& pasteboardName, CompletionHandler<void(String&& url, String&& title)>&& completionHandler)
 {
     String title;
     String url = PlatformPasteboard(pasteboardName).readURL(index, title);
     completionHandler(WTFMove(url), WTFMove(title));
 }
 
-void WebPasteboardProxy::readBufferFromPasteboard(uint64_t index, const String& pasteboardType, const String& pasteboardName, CompletionHandler<void(SharedMemory::Handle&&, uint64_t size)>&& completionHandler)
+void WebPasteboardProxy::readBufferFromPasteboard(size_t index, const String& pasteboardType, const String& pasteboardName, CompletionHandler<void(SharedMemory::Handle&&, uint64_t size)>&& completionHandler)
 {
     RefPtr<SharedBuffer> buffer = PlatformPasteboard(pasteboardName).readBuffer(index, pasteboardType);
     if (!buffer)
@@ -231,19 +224,26 @@ void WebPasteboardProxy::readBufferFromPasteboard(uint64_t index, const String&
     completionHandler(WTFMove(handle), size);
 }
 
-void WebPasteboardProxy::getPasteboardItemsCount(const String& pasteboardName, CompletionHandler<void(uint64_t)>&& completionHandler)
+#if PLATFORM(IOS_FAMILY)
+
+void WebPasteboardProxy::writeURLToPasteboard(const PasteboardURL& url, const String& pasteboardName)
 {
-    completionHandler(PlatformPasteboard(pasteboardName).count());
+    PlatformPasteboard(pasteboardName).write(url);
 }
 
-void WebPasteboardProxy::allPasteboardItemInfo(const String& pasteboardName, CompletionHandler<void(Vector<PasteboardItemInfo>&&)>&& completionHandler)
+void WebPasteboardProxy::writeWebContentToPasteboard(const WebCore::PasteboardWebContent& content, const String& pasteboardName)
 {
-    completionHandler(PlatformPasteboard(pasteboardName).allPasteboardItemInfo());
+    PlatformPasteboard(pasteboardName).write(content);
 }
 
-void WebPasteboardProxy::informationForItemAtIndex(int index, const String& pasteboardName, CompletionHandler<void(PasteboardItemInfo&&)>&& completionHandler)
+void WebPasteboardProxy::writeImageToPasteboard(const WebCore::PasteboardImage& pasteboardImage, const String& pasteboardName)
 {
-    completionHandler(PlatformPasteboard(pasteboardName).informationForItemAtIndex(index));
+    PlatformPasteboard(pasteboardName).write(pasteboardImage);
+}
+
+void WebPasteboardProxy::writeStringToPasteboard(const String& pasteboardType, const String& text, const String& pasteboardName)
+{
+    PlatformPasteboard(pasteboardName).write(pasteboardType, text);
 }
 
 void WebPasteboardProxy::updateSupportedTypeIdentifiers(const Vector<String>& identifiers, const String& pasteboardName)
@@ -251,6 +251,6 @@ void WebPasteboardProxy::updateSupportedTypeIdentifiers(const Vector<String>& id
     PlatformPasteboard(pasteboardName).updateSupportedTypeIdentifiers(identifiers);
 }
 
-#endif
+#endif // PLATFORM(IOS_FAMILY)
 
 } // namespace WebKit
index 7bff934..0febdc1 100644 (file)
 #include "config.h"
 #include "WebPasteboardProxy.h"
 
+#include "SharedMemory.h"
 #include "WebPasteboardProxyMessages.h"
 #include "WebProcessProxy.h"
 #include <mutex>
+#include <wtf/CompletionHandler.h>
 #include <wtf/NeverDestroyed.h>
 
 namespace WebKit {
@@ -73,6 +75,40 @@ void WebPasteboardProxy::writeCustomData(const WebCore::PasteboardCustomData&, c
     completionHandler(0);
 }
 
-#endif
+void WebPasteboardProxy::allPasteboardItemInfo(const String&, CompletionHandler<void(Vector<PasteboardItemInfo>&&)>&& completionHandler)
+{
+    completionHandler({ });
+}
+
+void WebPasteboardProxy::informationForItemAtIndex(size_t, const String&, CompletionHandler<void(PasteboardItemInfo&&)>&& completionHandler)
+{
+    completionHandler({ });
+}
+
+void WebPasteboardProxy::getPasteboardItemsCount(const String&, CompletionHandler<void(uint64_t)>&& completionHandler)
+{
+    completionHandler(0);
+}
+
+void WebPasteboardProxy::readURLFromPasteboard(size_t, const String&, CompletionHandler<void(String&& url, String&& title)>&& completionHandler)
+{
+    completionHandler({ }, { });
+}
+
+void WebPasteboardProxy::readBufferFromPasteboard(size_t, const String&, const String&, CompletionHandler<void(SharedMemory::Handle&&, uint64_t size)>&& completionHandler)
+{
+    completionHandler({ }, 0);
+}
+
+#if !PLATFORM(WPE)
+
+void WebPasteboardProxy::readStringFromPasteboard(size_t, const String&, const String&, CompletionHandler<void(String&&)>&& completionHandler)
+{
+    completionHandler({ });
+}
+
+#endif // !PLATFORM(WPE)
+
+#endif // !PLATFORM(COCOA)
 
 } // namespace WebKit
index 0e0e215..adbc226 100644 (file)
@@ -73,12 +73,6 @@ private:
     void writeWebContentToPasteboard(const WebCore::PasteboardWebContent&, const String& pasteboardName);
     void writeImageToPasteboard(const WebCore::PasteboardImage&, const String& pasteboardName);
     void writeStringToPasteboard(const String& pasteboardType, const String&, const String& pasteboardName);
-    void readStringFromPasteboard(uint64_t index, const String& pasteboardType, const String& pasteboardName, CompletionHandler<void(String&&)>&&);
-    void readURLFromPasteboard(uint64_t index, const String& pasteboardName, CompletionHandler<void(String&& url, String&& title)>&&);
-    void readBufferFromPasteboard(uint64_t index, const String& pasteboardType, const String& pasteboardName, CompletionHandler<void(SharedMemory::Handle&&, uint64_t size)>&&);
-    void getPasteboardItemsCount(const String& pasteboardName, CompletionHandler<void(uint64_t)>&&);
-    void allPasteboardItemInfo(const String& pasteboardName, CompletionHandler<void(Vector<WebCore::PasteboardItemInfo>&&)>&&);
-    void informationForItemAtIndex(int index, const String& pasteboardName, CompletionHandler<void(WebCore::PasteboardItemInfo&&)>&&);
     void updateSupportedTypeIdentifiers(const Vector<String>& identifiers, const String& pasteboardName);
 #endif
 #if PLATFORM(COCOA)
@@ -101,6 +95,13 @@ private:
     void setPasteboardBufferForType(const String& pasteboardName, const String& pasteboardType, const SharedMemory::Handle&, uint64_t size, CompletionHandler<void(uint64_t)>&&);
 #endif
 
+    void readStringFromPasteboard(size_t index, const String& pasteboardType, const String& pasteboardName, CompletionHandler<void(String&&)>&&);
+    void readURLFromPasteboard(size_t index, const String& pasteboardName, CompletionHandler<void(String&& url, String&& title)>&&);
+    void readBufferFromPasteboard(size_t index, const String& pasteboardType, const String& pasteboardName, CompletionHandler<void(SharedMemory::Handle&&, uint64_t size)>&&);
+    void getPasteboardItemsCount(const String& pasteboardName, CompletionHandler<void(uint64_t)>&&);
+    void informationForItemAtIndex(size_t index, const String& pasteboardName, CompletionHandler<void(WebCore::PasteboardItemInfo&&)>&&);
+    void allPasteboardItemInfo(const String& pasteboardName, CompletionHandler<void(Vector<WebCore::PasteboardItemInfo>&&)>&&);
+
     void writeCustomData(const WebCore::PasteboardCustomData&, const String& pasteboardName, CompletionHandler<void(uint64_t)>&&);
     void typesSafeForDOMToReadAndWrite(const String& pasteboardName, const String& origin, CompletionHandler<void(Vector<String>&&)>&&);
 
@@ -114,7 +115,6 @@ private:
 
 #if USE(LIBWPE)
     void getPasteboardTypes(CompletionHandler<void(Vector<String>&&)>&&);
-    void readStringFromPasteboard(uint64_t index, const String& pasteboardType, CompletionHandler<void(String&&)>&&);
     void writeWebContentToPasteboard(const WebCore::PasteboardWebContent&);
     void writeStringToPasteboard(const String& pasteboardType, const String&);
 #endif
index d3ea3ba..691d025 100644 (file)
@@ -26,17 +26,17 @@ messages -> WebPasteboardProxy {
     WriteWebContentToPasteboard(struct WebCore::PasteboardWebContent content, String pasteboardName)
     WriteImageToPasteboard(struct WebCore::PasteboardImage pasteboardImage, String pasteboardName)
     WriteStringToPasteboard(String pasteboardType, String text, String pasteboardName)
-    ReadStringFromPasteboard(uint64_t index, String pasteboardType, String pasteboardName) -> (String string) Synchronous
-    ReadURLFromPasteboard(uint64_t index, String pasteboardName) -> (String url, String title) Synchronous
-    ReadBufferFromPasteboard(uint64_t index, String pasteboardType, String pasteboardName) -> (WebKit::SharedMemory::Handle handle, uint64_t size) Synchronous
-    GetPasteboardItemsCount(String pasteboardName) -> (uint64_t itemsCount) Synchronous
-    AllPasteboardItemInfo(String pasteboardName) -> (Vector<WebCore::PasteboardItemInfo> allInfo) Synchronous
-    InformationForItemAtIndex(uint64_t index, String pasteboardName) -> (struct WebCore::PasteboardItemInfo info) Synchronous
     UpdateSupportedTypeIdentifiers(Vector<String> identifiers, String pasteboardName)
 #endif
 
     WriteCustomData(struct WebCore::PasteboardCustomData data, String pasteboardName) -> (uint64_t changeCount) Synchronous
     TypesSafeForDOMToReadAndWrite(String pasteboardName, String origin) -> (Vector<String> types) Synchronous
+    AllPasteboardItemInfo(String pasteboardName) -> (Vector<WebCore::PasteboardItemInfo> allInfo) Synchronous
+    InformationForItemAtIndex(uint64_t index, String pasteboardName) -> (struct WebCore::PasteboardItemInfo info) Synchronous
+    GetPasteboardItemsCount(String pasteboardName) -> (uint64_t itemsCount) Synchronous
+    ReadStringFromPasteboard(uint64_t index, String pasteboardType, String pasteboardName) -> (String string) Synchronous
+    ReadURLFromPasteboard(uint64_t index, String pasteboardName) -> (String url, String title) Synchronous
+    ReadBufferFromPasteboard(uint64_t index, String pasteboardType, String pasteboardName) -> (WebKit::SharedMemory::Handle handle, uint64_t size) Synchronous
 
 #if PLATFORM(COCOA)
     # Pasteboard messages.
@@ -66,7 +66,6 @@ messages -> WebPasteboardProxy {
 
 #if USE(LIBWPE)
     GetPasteboardTypes() -> (Vector<String> types) Synchronous
-    ReadStringFromPasteboard(uint64_t index, String pasteboardType) -> (String string) Synchronous
     WriteWebContentToPasteboard(struct WebCore::PasteboardWebContent content)
     WriteStringToPasteboard(String pasteboardType, String text)
 #endif
index a9ba6f9..5293e32 100644 (file)
@@ -40,7 +40,7 @@ void WebPasteboardProxy::getPasteboardTypes(CompletionHandler<void(Vector<String
     completionHandler(WTFMove(pasteboardTypes));
 }
 
-void WebPasteboardProxy::readStringFromPasteboard(uint64_t index, const String& pasteboardType, CompletionHandler<void(String&&)>&& completionHandler)
+void WebPasteboardProxy::readStringFromPasteboard(size_t index, const String& pasteboardType, const String&, CompletionHandler<void(String&&)>&& completionHandler)
 {
     completionHandler(PlatformPasteboard().readString(index, pasteboardType));
 }
index f1fe4b6..5544a25 100644 (file)
@@ -265,56 +265,10 @@ void WebPlatformStrategies::writeToPasteboard(const String& pasteboardType, cons
     WebProcess::singleton().parentProcessConnection()->send(Messages::WebPasteboardProxy::WriteStringToPasteboard(pasteboardType, text, pasteboardName), 0);
 }
 
-int WebPlatformStrategies::getPasteboardItemsCount(const String& pasteboardName)
-{
-    uint64_t itemsCount { 0 };
-    WebProcess::singleton().parentProcessConnection()->sendSync(Messages::WebPasteboardProxy::GetPasteboardItemsCount(pasteboardName), Messages::WebPasteboardProxy::GetPasteboardItemsCount::Reply(itemsCount), 0);
-    return itemsCount;
-}
-
-Vector<PasteboardItemInfo> WebPlatformStrategies::allPasteboardItemInfo(const String& pasteboardName)
-{
-    Vector<PasteboardItemInfo> allInfo;
-    WebProcess::singleton().parentProcessConnection()->sendSync(Messages::WebPasteboardProxy::AllPasteboardItemInfo(pasteboardName), Messages::WebPasteboardProxy::AllPasteboardItemInfo::Reply(allInfo), 0);
-    return allInfo;
-}
-
-PasteboardItemInfo WebPlatformStrategies::informationForItemAtIndex(int index, const String& pasteboardName)
-{
-    PasteboardItemInfo info;
-    WebProcess::singleton().parentProcessConnection()->sendSync(Messages::WebPasteboardProxy::InformationForItemAtIndex(index, pasteboardName), Messages::WebPasteboardProxy::InformationForItemAtIndex::Reply(info), 0);
-    return info;
-}
-
 void WebPlatformStrategies::updateSupportedTypeIdentifiers(const Vector<String>& identifiers, const String& pasteboardName)
 {
     WebProcess::singleton().parentProcessConnection()->send(Messages::WebPasteboardProxy::UpdateSupportedTypeIdentifiers(identifiers, pasteboardName), 0);
 }
-
-RefPtr<WebCore::SharedBuffer> WebPlatformStrategies::readBufferFromPasteboard(int index, const String& pasteboardType, const String& pasteboardName)
-{
-    SharedMemory::Handle handle;
-    uint64_t size { 0 };
-    WebProcess::singleton().parentProcessConnection()->sendSync(Messages::WebPasteboardProxy::ReadBufferFromPasteboard(index, pasteboardType, pasteboardName), Messages::WebPasteboardProxy::ReadBufferFromPasteboard::Reply(handle, size), 0);
-    if (handle.isNull())
-        return nullptr;
-    RefPtr<SharedMemory> sharedMemoryBuffer = SharedMemory::map(handle, SharedMemory::Protection::ReadOnly);
-    return SharedBuffer::create(static_cast<unsigned char *>(sharedMemoryBuffer->data()), size);
-}
-
-URL WebPlatformStrategies::readURLFromPasteboard(int index, const String& pasteboardName, String& title)
-{
-    String urlString;
-    WebProcess::singleton().parentProcessConnection()->sendSync(Messages::WebPasteboardProxy::ReadURLFromPasteboard(index, pasteboardName), Messages::WebPasteboardProxy::ReadURLFromPasteboard::Reply(urlString, title), 0);
-    return URL({ }, urlString);
-}
-
-String WebPlatformStrategies::readStringFromPasteboard(int index, const String& pasteboardType, const String& pasteboardName)
-{
-    String value;
-    WebProcess::singleton().parentProcessConnection()->sendSync(Messages::WebPasteboardProxy::ReadStringFromPasteboard(index, pasteboardType, pasteboardName), Messages::WebPasteboardProxy::ReadStringFromPasteboard::Reply(value), 0);
-    return value;
-}
 #endif // PLATFORM(IOS_FAMILY)
 
 #endif // PLATFORM(COCOA)
@@ -345,13 +299,6 @@ void WebPlatformStrategies::getTypes(Vector<String>& types)
     WebProcess::singleton().parentProcessConnection()->sendSync(Messages::WebPasteboardProxy::GetPasteboardTypes(), Messages::WebPasteboardProxy::GetPasteboardTypes::Reply(types), 0);
 }
 
-String WebPlatformStrategies::readStringFromPasteboard(int index, const String& pasteboardType)
-{
-    String value;
-    WebProcess::singleton().parentProcessConnection()->sendSync(Messages::WebPasteboardProxy::ReadStringFromPasteboard(index, pasteboardType), Messages::WebPasteboardProxy::ReadStringFromPasteboard::Reply(value), 0);
-    return value;
-}
-
 void WebPlatformStrategies::writeToPasteboard(const WebCore::PasteboardWebContent& content)
 {
     WebProcess::singleton().parentProcessConnection()->send(Messages::WebPasteboardProxy::WriteWebContentToPasteboard(content), 0);
@@ -378,4 +325,50 @@ long WebPlatformStrategies::writeCustomData(const WebCore::PasteboardCustomData&
     return newChangeCount;
 }
 
+int WebPlatformStrategies::getPasteboardItemsCount(const String& pasteboardName)
+{
+    uint64_t itemsCount { 0 };
+    WebProcess::singleton().parentProcessConnection()->sendSync(Messages::WebPasteboardProxy::GetPasteboardItemsCount(pasteboardName), Messages::WebPasteboardProxy::GetPasteboardItemsCount::Reply(itemsCount), 0);
+    return itemsCount;
+}
+
+Vector<PasteboardItemInfo> WebPlatformStrategies::allPasteboardItemInfo(const String& pasteboardName)
+{
+    Vector<PasteboardItemInfo> allInfo;
+    WebProcess::singleton().parentProcessConnection()->sendSync(Messages::WebPasteboardProxy::AllPasteboardItemInfo(pasteboardName), Messages::WebPasteboardProxy::AllPasteboardItemInfo::Reply(allInfo), 0);
+    return allInfo;
+}
+
+PasteboardItemInfo WebPlatformStrategies::informationForItemAtIndex(size_t index, const String& pasteboardName)
+{
+    PasteboardItemInfo info;
+    WebProcess::singleton().parentProcessConnection()->sendSync(Messages::WebPasteboardProxy::InformationForItemAtIndex(index, pasteboardName), Messages::WebPasteboardProxy::InformationForItemAtIndex::Reply(info), 0);
+    return info;
+}
+
+RefPtr<WebCore::SharedBuffer> WebPlatformStrategies::readBufferFromPasteboard(size_t index, const String& pasteboardType, const String& pasteboardName)
+{
+    SharedMemory::Handle handle;
+    uint64_t size { 0 };
+    WebProcess::singleton().parentProcessConnection()->sendSync(Messages::WebPasteboardProxy::ReadBufferFromPasteboard(index, pasteboardType, pasteboardName), Messages::WebPasteboardProxy::ReadBufferFromPasteboard::Reply(handle, size), 0);
+    if (handle.isNull())
+        return nullptr;
+    RefPtr<SharedMemory> sharedMemoryBuffer = SharedMemory::map(handle, SharedMemory::Protection::ReadOnly);
+    return SharedBuffer::create(static_cast<unsigned char *>(sharedMemoryBuffer->data()), size);
+}
+
+URL WebPlatformStrategies::readURLFromPasteboard(size_t index, const String& pasteboardName, String& title)
+{
+    String urlString;
+    WebProcess::singleton().parentProcessConnection()->sendSync(Messages::WebPasteboardProxy::ReadURLFromPasteboard(index, pasteboardName), Messages::WebPasteboardProxy::ReadURLFromPasteboard::Reply(urlString, title), 0);
+    return URL({ }, urlString);
+}
+
+String WebPlatformStrategies::readStringFromPasteboard(size_t index, const String& pasteboardType, const String& pasteboardName)
+{
+    String value;
+    WebProcess::singleton().parentProcessConnection()->sendSync(Messages::WebPasteboardProxy::ReadStringFromPasteboard(index, pasteboardType, pasteboardName), Messages::WebPasteboardProxy::ReadStringFromPasteboard::Reply(value), 0);
+    return value;
+}
+
 } // namespace WebKit
index f7f1041..0702359 100644 (file)
@@ -50,12 +50,6 @@ private:
     void writeToPasteboard(const WebCore:: PasteboardURL&, const String& pasteboardName) override;
     void writeToPasteboard(const WebCore::PasteboardImage&, const String& pasteboardName) override;
     void writeToPasteboard(const String& pasteboardType, const String&, const String& pasteboardName) override;
-    int getPasteboardItemsCount(const String& pasteboardName) override;
-    String readStringFromPasteboard(int index, const String& pasteboardType, const String& pasteboardName) override;
-    RefPtr<WebCore::SharedBuffer> readBufferFromPasteboard(int index, const String& pasteboardType, const String& pasteboardName) override;
-    URL readURLFromPasteboard(int index, const String& pasteboardName, String& title) override;
-    Vector<WebCore::PasteboardItemInfo> allPasteboardItemInfo(const String& pasteboardName) override;
-    WebCore::PasteboardItemInfo informationForItemAtIndex(int index, const String& pasteboardName) override;
     void updateSupportedTypeIdentifiers(const Vector<String>& identifiers, const String& pasteboardName) override;
 #endif
 #if PLATFORM(COCOA)
@@ -83,11 +77,16 @@ private:
 #endif
 #if USE(LIBWPE)
     void getTypes(Vector<String>& types) override;
-    String readStringFromPasteboard(int index, const String& pasteboardType) override;
     void writeToPasteboard(const WebCore::PasteboardWebContent&) override;
     void writeToPasteboard(const String& pasteboardType, const String&) override;
 #endif
 
+    String readStringFromPasteboard(size_t index, const String& pasteboardType, const String& pasteboardName) override;
+    RefPtr<WebCore::SharedBuffer> readBufferFromPasteboard(size_t index, const String& pasteboardType, const String& pasteboardName) override;
+    URL readURLFromPasteboard(size_t index, const String& pasteboardName, String& title) override;
+    int getPasteboardItemsCount(const String& pasteboardName) override;
+    WebCore::PasteboardItemInfo informationForItemAtIndex(size_t index, const String& pasteboardName) override;
+    Vector<WebCore::PasteboardItemInfo> allPasteboardItemInfo(const String& pasteboardName) override;
     Vector<String> typesSafeForDOMToReadAndWrite(const String& pasteboardName, const String& origin) override;
     long writeCustomData(const WebCore::PasteboardCustomData&, const String&) override;
 };
index 389ac03..4ba71fb 100644 (file)
@@ -1,3 +1,23 @@
+2019-10-09  Wenson Hsieh  <wenson_hsieh@apple.com>
+
+        [Clipboard API] Refactor Pasteboard item reading functions to work on both iOS and macOS
+        https://bugs.webkit.org/show_bug.cgi?id=202647
+
+        Reviewed by Tim Horton.
+
+        Refactor iOS-specific pasteboard functions to be platform-agnostic. See WebCore ChangeLog for more details.
+
+        * WebCoreSupport/WebPlatformStrategies.h:
+        * WebCoreSupport/WebPlatformStrategies.mm:
+        (WebPlatformStrategies::informationForItemAtIndex):
+        (WebPlatformStrategies::allPasteboardItemInfo):
+        (WebPlatformStrategies::getPasteboardItemsCount):
+        (WebPlatformStrategies::readBufferFromPasteboard):
+        (WebPlatformStrategies::readURLFromPasteboard):
+        (WebPlatformStrategies::readStringFromPasteboard):
+        (WebPlatformStrategies::writeToPasteboard):
+        (WebPlatformStrategies::updateSupportedTypeIdentifiers):
+
 2019-10-08  Antti Koivisto  <antti@apple.com>
 
         [CSS Shadow Parts] Enable by default
index d160a83..9f00399 100644 (file)
@@ -51,14 +51,14 @@ private:
     void writeToPasteboard(const WebCore::PasteboardWebContent&, const String& pasteboardName) override;
     void writeToPasteboard(const WebCore::PasteboardImage&, const String& pasteboardName) override;
     void writeToPasteboard(const String& pasteboardType, const String&, const String& pasteboardName) override;
-    int getPasteboardItemsCount(const String& pasteboardName) override;
-    String readStringFromPasteboard(int index, const String& pasteboardType, const String& pasteboardName) override;
-    RefPtr<WebCore::SharedBuffer> readBufferFromPasteboard(int index, const String& pasteboardType, const String& pasteboardName) override;
-    URL readURLFromPasteboard(int index, const String& pasteboardName, String& title) override;
-    Vector<WebCore::PasteboardItemInfo> allPasteboardItemInfo(const String& pasteboardName) override;
-    WebCore::PasteboardItemInfo informationForItemAtIndex(int index, const String& pasteboardName) override;
     void updateSupportedTypeIdentifiers(const Vector<String>& identifiers, const String& pasteboardName) override;
 #endif
+    String readStringFromPasteboard(size_t index, const String& pasteboardType, const String& pasteboardName) override;
+    RefPtr<WebCore::SharedBuffer> readBufferFromPasteboard(size_t index, const String& pasteboardType, const String& pasteboardName) override;
+    URL readURLFromPasteboard(size_t index, const String& pasteboardName, String& title) override;
+    int getPasteboardItemsCount(const String& pasteboardName) override;
+    WebCore::PasteboardItemInfo informationForItemAtIndex(size_t index, const String& pasteboardName) override;
+    Vector<WebCore::PasteboardItemInfo> allPasteboardItemInfo(const String& pasteboardName) override;
     int getNumberOfFiles(const String& pasteboardName) override;
     void getTypes(Vector<String>& types, const String& pasteboardName) override;
     RefPtr<WebCore::SharedBuffer> bufferForType(const String& pasteboardType, const String& pasteboardName) override;
index f67720e..98d324c 100644 (file)
@@ -173,60 +173,60 @@ long WebPlatformStrategies::writeCustomData(const WebCore::PasteboardCustomData&
     return PlatformPasteboard(pasteboardName).write(data);
 }
 
-#if PLATFORM(IOS_FAMILY)
-
-void WebPlatformStrategies::writeToPasteboard(const PasteboardURL& url, const String& pasteboardName)
+WebCore::PasteboardItemInfo WebPlatformStrategies::informationForItemAtIndex(size_t index, const String& pasteboardName)
 {
-    PlatformPasteboard(pasteboardName).write(url);
+    return PlatformPasteboard(pasteboardName).informationForItemAtIndex(index);
 }
 
-void WebPlatformStrategies::writeToPasteboard(const WebCore::PasteboardWebContent& content, const String& pasteboardName)
+Vector<WebCore::PasteboardItemInfo> WebPlatformStrategies::allPasteboardItemInfo(const String& pasteboardName)
 {
-    PlatformPasteboard(pasteboardName).write(content);
+    return PlatformPasteboard(pasteboardName).allPasteboardItemInfo();
 }
 
-void WebPlatformStrategies::writeToPasteboard(const WebCore::PasteboardImage& image, const String& pasteboardName)
+int WebPlatformStrategies::getPasteboardItemsCount(const String& pasteboardName)
 {
-    PlatformPasteboard(pasteboardName).write(image);
+    return PlatformPasteboard(pasteboardName).count();
 }
 
-void WebPlatformStrategies::writeToPasteboard(const String& pasteboardType, const String& text, const String& pasteboardName)
+RefPtr<WebCore::SharedBuffer> WebPlatformStrategies::readBufferFromPasteboard(size_t index, const String& type, const String& pasteboardName)
 {
-    PlatformPasteboard(pasteboardName).write(pasteboardType, text);
+    return PlatformPasteboard(pasteboardName).readBuffer(index, type);
 }
 
-int WebPlatformStrategies::getPasteboardItemsCount(const String& pasteboardName)
+URL WebPlatformStrategies::readURLFromPasteboard(size_t index, const String& pasteboardName, String& title)
 {
-    return PlatformPasteboard(pasteboardName).count();
+    return PlatformPasteboard(pasteboardName).readURL(index, title);
 }
 
-void WebPlatformStrategies::updateSupportedTypeIdentifiers(const Vector<String>& identifiers, const String& pasteboardName)
+String WebPlatformStrategies::readStringFromPasteboard(size_t index, const String& type, const String& pasteboardName)
 {
-    PlatformPasteboard(pasteboardName).updateSupportedTypeIdentifiers(identifiers);
+    return PlatformPasteboard(pasteboardName).readString(index, type);
 }
 
-RefPtr<WebCore::SharedBuffer> WebPlatformStrategies::readBufferFromPasteboard(int index, const String& type, const String& pasteboardName)
+#if PLATFORM(IOS_FAMILY)
+
+void WebPlatformStrategies::writeToPasteboard(const PasteboardURL& url, const String& pasteboardName)
 {
-    return PlatformPasteboard(pasteboardName).readBuffer(index, type);
+    PlatformPasteboard(pasteboardName).write(url);
 }
 
-URL WebPlatformStrategies::readURLFromPasteboard(int index, const String& pasteboardName, String& title)
+void WebPlatformStrategies::writeToPasteboard(const WebCore::PasteboardWebContent& content, const String& pasteboardName)
 {
-    return PlatformPasteboard(pasteboardName).readURL(index, title);
+    PlatformPasteboard(pasteboardName).write(content);
 }
 
-String WebPlatformStrategies::readStringFromPasteboard(int index, const String& type, const String& pasteboardName)
+void WebPlatformStrategies::writeToPasteboard(const WebCore::PasteboardImage& image, const String& pasteboardName)
 {
-    return PlatformPasteboard(pasteboardName).readString(index, type);
+    PlatformPasteboard(pasteboardName).write(image);
 }
 
-Vector<WebCore::PasteboardItemInfo> WebPlatformStrategies::allPasteboardItemInfo(const String& pasteboardName)
+void WebPlatformStrategies::writeToPasteboard(const String& pasteboardType, const String& text, const String& pasteboardName)
 {
-    return PlatformPasteboard(pasteboardName).allPasteboardItemInfo();
+    PlatformPasteboard(pasteboardName).write(pasteboardType, text);
 }
 
-WebCore::PasteboardItemInfo WebPlatformStrategies::informationForItemAtIndex(int index, const String& pasteboardName)
+void WebPlatformStrategies::updateSupportedTypeIdentifiers(const Vector<String>& identifiers, const String& pasteboardName)
 {
-    return PlatformPasteboard(pasteboardName).informationForItemAtIndex(index);
+    PlatformPasteboard(pasteboardName).updateSupportedTypeIdentifiers(identifiers);
 }
 #endif // PLATFORM(IOS_FAMILY)