Title: [211175] trunk/Source
Revision
211175
Author
wenson_hs...@apple.com
Date
2017-01-25 15:50:12 -0800 (Wed, 25 Jan 2017)

Log Message

Introduce an item-provider-based pasteboard wrapper
https://bugs.webkit.org/show_bug.cgi?id=167410

Reviewed by Enrica Casucci.

Source/WebCore:

Introduces WebItemProviderPasteboard, a pasteboard-like object backed by a number of item providers. No new
tests, since there is no behavior change.

* WebCore.xcodeproj/project.pbxproj:
* platform/ios/AbstractPasteboard.h: Copied from Source/WebCore/platform/spi/ios/UIKitSPI.h.
* platform/ios/WebItemProviderPasteboard.h: Copied from Source/WebCore/platform/spi/ios/UIKitSPI.h.
* platform/ios/WebItemProviderPasteboard.mm: Added.
(isRichTextType):
(isStringType):
(isURLType):
(isColorType):
(isImageType):
(+[WebItemProviderPasteboard sharedInstance]):
(-[WebItemProviderPasteboard init]):
(-[WebItemProviderPasteboard dealloc]):
(-[WebItemProviderPasteboard pasteboardTypes]):
(-[WebItemProviderPasteboard setItemProviders:]):
(-[WebItemProviderPasteboard numberOfItems]):
(-[WebItemProviderPasteboard setItems:]):
(-[WebItemProviderPasteboard dataForPasteboardType:inItemSet:]):
(-[WebItemProviderPasteboard valuesForPasteboardType:inItemSet:]):
(-[WebItemProviderPasteboard changeCount]):
(-[WebItemProviderPasteboard itemProviderAtIndex:]):
* platform/spi/ios/UIKitSPI.h:

Source/WTF:

Adds an additional feature flag.

* wtf/FeatureDefines.h:

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (211174 => 211175)


--- trunk/Source/WTF/ChangeLog	2017-01-25 23:43:01 UTC (rev 211174)
+++ trunk/Source/WTF/ChangeLog	2017-01-25 23:50:12 UTC (rev 211175)
@@ -1,3 +1,14 @@
+2017-01-25  Wenson Hsieh  <wenson_hs...@apple.com>
+
+        Introduce an item-provider-based pasteboard wrapper
+        https://bugs.webkit.org/show_bug.cgi?id=167410
+
+        Reviewed by Enrica Casucci.
+
+        Adds an additional feature flag.
+
+        * wtf/FeatureDefines.h:
+
 2017-01-25  Konstantin Tokarev  <annu...@yandex.ru>
 
         Removed leftovers of pre-2015 VisualStudio support

Modified: trunk/Source/WTF/wtf/FeatureDefines.h (211174 => 211175)


--- trunk/Source/WTF/wtf/FeatureDefines.h	2017-01-25 23:43:01 UTC (rev 211174)
+++ trunk/Source/WTF/wtf/FeatureDefines.h	2017-01-25 23:50:12 UTC (rev 211175)
@@ -783,6 +783,10 @@
 #define ENABLE_KEYBOARD_CODE_ATTRIBUTE 0
 #endif
 
+#if !defined(ENABLE_DATA_INTERACTION)
+#define ENABLE_DATA_INTERACTION 0
+#endif
+
 /* Asserts, invariants for macro definitions */
 
 #if ENABLE(VIDEO_TRACK) && !ENABLE(VIDEO)

Modified: trunk/Source/WebCore/ChangeLog (211174 => 211175)


--- trunk/Source/WebCore/ChangeLog	2017-01-25 23:43:01 UTC (rev 211174)
+++ trunk/Source/WebCore/ChangeLog	2017-01-25 23:50:12 UTC (rev 211175)
@@ -1,3 +1,35 @@
+2017-01-25  Wenson Hsieh  <wenson_hs...@apple.com>
+
+        Introduce an item-provider-based pasteboard wrapper
+        https://bugs.webkit.org/show_bug.cgi?id=167410
+
+        Reviewed by Enrica Casucci.
+
+        Introduces WebItemProviderPasteboard, a pasteboard-like object backed by a number of item providers. No new
+        tests, since there is no behavior change.
+
+        * WebCore.xcodeproj/project.pbxproj:
+        * platform/ios/AbstractPasteboard.h: Copied from Source/WebCore/platform/spi/ios/UIKitSPI.h.
+        * platform/ios/WebItemProviderPasteboard.h: Copied from Source/WebCore/platform/spi/ios/UIKitSPI.h.
+        * platform/ios/WebItemProviderPasteboard.mm: Added.
+        (isRichTextType):
+        (isStringType):
+        (isURLType):
+        (isColorType):
+        (isImageType):
+        (+[WebItemProviderPasteboard sharedInstance]):
+        (-[WebItemProviderPasteboard init]):
+        (-[WebItemProviderPasteboard dealloc]):
+        (-[WebItemProviderPasteboard pasteboardTypes]):
+        (-[WebItemProviderPasteboard setItemProviders:]):
+        (-[WebItemProviderPasteboard numberOfItems]):
+        (-[WebItemProviderPasteboard setItems:]):
+        (-[WebItemProviderPasteboard dataForPasteboardType:inItemSet:]):
+        (-[WebItemProviderPasteboard valuesForPasteboardType:inItemSet:]):
+        (-[WebItemProviderPasteboard changeCount]):
+        (-[WebItemProviderPasteboard itemProviderAtIndex:]):
+        * platform/spi/ios/UIKitSPI.h:
+
 2017-01-25  Konstantin Tokarev  <annu...@yandex.ru>
 
         Removed leftovers of pre-2015 VisualStudio support

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (211174 => 211175)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2017-01-25 23:43:01 UTC (rev 211174)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2017-01-25 23:50:12 UTC (rev 211175)
@@ -6506,6 +6506,9 @@
 		F478755519983AFF0024A287 /* ScrollSnapAnimatorState.mm in Sources */ = {isa = PBXBuildFile; fileRef = F478755319983AFF0024A287 /* ScrollSnapAnimatorState.mm */; };
 		F47A5E3E195B8C8A00483100 /* StyleScrollSnapPoints.h in Headers */ = {isa = PBXBuildFile; fileRef = F47A5E3B195B8C8A00483100 /* StyleScrollSnapPoints.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		F47A5E3F195B8E4800483100 /* StyleScrollSnapPoints.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F47A5E3A195B8C8A00483100 /* StyleScrollSnapPoints.cpp */; };
+		F48223101E3869B80066FC79 /* WebItemProviderPasteboard.mm in Sources */ = {isa = PBXBuildFile; fileRef = F482230E1E3869B80066FC79 /* WebItemProviderPasteboard.mm */; };
+		F48223111E3869B80066FC79 /* WebItemProviderPasteboard.h in Headers */ = {isa = PBXBuildFile; fileRef = F482230F1E3869B80066FC79 /* WebItemProviderPasteboard.h */; };
+		F48223131E386E240066FC79 /* AbstractPasteboard.h in Headers */ = {isa = PBXBuildFile; fileRef = F48223121E386E240066FC79 /* AbstractPasteboard.h */; };
 		F4BFB9851E1DDF9B00862C24 /* DumpEditingHistory.js in Copy Scripts */ = {isa = PBXBuildFile; fileRef = F48389831E1DDF2B0076B7EA /* DumpEditingHistory.js */; };
 		F4BFB9861E1DDF9B00862C24 /* EditingHistoryUtil.js in Copy Scripts */ = {isa = PBXBuildFile; fileRef = F48389841E1DDF2B0076B7EA /* EditingHistoryUtil.js */; };
 		F50664F7157F52DC00AC226F /* FormController.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F50664F5157F52DC00AC226F /* FormController.cpp */; };
@@ -14558,6 +14561,9 @@
 		F478755319983AFF0024A287 /* ScrollSnapAnimatorState.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ScrollSnapAnimatorState.mm; sourceTree = "<group>"; };
 		F47A5E3A195B8C8A00483100 /* StyleScrollSnapPoints.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = StyleScrollSnapPoints.cpp; sourceTree = "<group>"; };
 		F47A5E3B195B8C8A00483100 /* StyleScrollSnapPoints.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StyleScrollSnapPoints.h; sourceTree = "<group>"; };
+		F482230E1E3869B80066FC79 /* WebItemProviderPasteboard.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebItemProviderPasteboard.mm; sourceTree = "<group>"; };
+		F482230F1E3869B80066FC79 /* WebItemProviderPasteboard.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebItemProviderPasteboard.h; sourceTree = "<group>"; };
+		F48223121E386E240066FC79 /* AbstractPasteboard.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AbstractPasteboard.h; sourceTree = "<group>"; };
 		F48389831E1DDF2B0076B7EA /* DumpEditingHistory.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode._javascript_; name = DumpEditingHistory.js; path = Scripts/DumpEditingHistory.js; sourceTree = "<group>"; };
 		F48389841E1DDF2B0076B7EA /* EditingHistoryUtil.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode._javascript_; name = EditingHistoryUtil.js; path = Scripts/EditingHistoryUtil.js; sourceTree = "<group>"; };
 		F50664F5157F52DC00AC226F /* FormController.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = FormController.cpp; sourceTree = "<group>"; };
@@ -19772,6 +19778,7 @@
 		A59E3C1B11580F340072928E /* ios */ = {
 			isa = PBXGroup;
 			children = (
+				F48223121E386E240066FC79 /* AbstractPasteboard.h */,
 				A148328B187F506800DA63A6 /* wak */,
 				2655414B1489AA2B000DFC5D /* CursorIOS.cpp */,
 				A1ED778A1BE3293F00DC1791 /* Device.cpp */,
@@ -19836,6 +19843,8 @@
 				3FBC4AF2189881560046EE38 /* WebVideoFullscreenInterfaceAVKit.h */,
 				3FBC4AF1189881560046EE38 /* WebVideoFullscreenInterfaceAVKit.mm */,
 				E453903C0EAFD637003695C8 /* WidgetIOS.mm */,
+				F482230E1E3869B80066FC79 /* WebItemProviderPasteboard.mm */,
+				F482230F1E3869B80066FC79 /* WebItemProviderPasteboard.h */,
 			);
 			path = ios;
 			sourceTree = "<group>";
@@ -25233,6 +25242,7 @@
 				CE799FA81C6A50570097B518 /* ContentSecurityPolicyMediaListDirective.h in Headers */,
 				CE6DADFA1C591E6A003F6A88 /* ContentSecurityPolicyResponseHeaders.h in Headers */,
 				CE799FA01C6A4C160097B518 /* ContentSecurityPolicySource.h in Headers */,
+				F48223131E386E240066FC79 /* AbstractPasteboard.h in Headers */,
 				CE799F981C6A46BC0097B518 /* ContentSecurityPolicySourceList.h in Headers */,
 				CE799FAC1C6A50660097B518 /* ContentSecurityPolicySourceListDirective.h in Headers */,
 				41D015CA0F4B5C71004A662F /* ContentType.h in Headers */,
@@ -27767,6 +27777,7 @@
 				414B82051D6DF0E50077EBE3 /* StructuredClone.h in Headers */,
 				BC5EB6A30E81DC4F00B25965 /* StyleBackgroundData.h in Headers */,
 				BC5EB67B0E81D3BE00B25965 /* StyleBoxData.h in Headers */,
+				F48223111E3869B80066FC79 /* WebItemProviderPasteboard.h in Headers */,
 				8386A96D19F61B2E00E1EC4A /* StyleBuilder.h in Headers */,
 				83B9687B19F8AB83004EF7AF /* StyleBuilderConverter.h in Headers */,
 				835D363719FF6193004C93AB /* StyleBuilderCustom.h in Headers */,
@@ -29227,6 +29238,7 @@
 				9418278E1D8CAF9200492764 /* CSSPendingSubstitutionValue.cpp in Sources */,
 				977B3862122883E900B81FF8 /* CSSPreloadScanner.cpp in Sources */,
 				A80E6D050A1989CA007FB8C5 /* CSSPrimitiveValue.cpp in Sources */,
+				F48223101E3869B80066FC79 /* WebItemProviderPasteboard.mm in Sources */,
 				A80E6CF70A1989CA007FB8C5 /* CSSProperty.cpp in Sources */,
 				78D02BC5154A18DF00B62D05 /* CSSPropertyAnimation.cpp in Sources */,
 				1ABA76CA11D20E50004C201C /* CSSPropertyNames.cpp in Sources */,

Copied: trunk/Source/WebCore/platform/ios/AbstractPasteboard.h (from rev 211174, trunk/Source/WebCore/platform/spi/ios/UIKitSPI.h) (0 => 211175)


--- trunk/Source/WebCore/platform/ios/AbstractPasteboard.h	                        (rev 0)
+++ trunk/Source/WebCore/platform/ios/AbstractPasteboard.h	2017-01-25 23:50:12 UTC (rev 211175)
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2017 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 <Foundation/Foundation.h>
+
+@protocol AbstractPasteboard <NSObject>
+@required
+
+@property (readonly, nonatomic) NSInteger numberOfItems;
+
+- (NSArray<NSString *> *)pasteboardTypes;
+- (void)setItems:(NSArray *)items;
+- (NSArray *)dataForPasteboardType:(NSString *)pasteboardType inItemSet:(NSIndexSet *)itemSet;
+- (NSArray *)valuesForPasteboardType:(NSString *)pasteboardType inItemSet:(NSIndexSet *)itemSet;
+- (NSInteger)changeCount;
+
+@end

Copied: trunk/Source/WebCore/platform/ios/WebItemProviderPasteboard.h (from rev 211174, trunk/Source/WebCore/platform/spi/ios/UIKitSPI.h) (0 => 211175)


--- trunk/Source/WebCore/platform/ios/WebItemProviderPasteboard.h	                        (rev 0)
+++ trunk/Source/WebCore/platform/ios/WebItemProviderPasteboard.h	2017-01-25 23:50:12 UTC (rev 211175)
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2017 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 "AbstractPasteboard.h"
+
+#if ENABLE(DATA_INTERACTION)
+
+OBJC_CLASS UIItemProvider;
+
+NS_ASSUME_NONNULL_BEGIN
+
+WEBCORE_EXPORT @interface WebItemProviderPasteboard : NSObject<AbstractPasteboard>
+
++ (instancetype)sharedInstance;
+
+- (UIItemProvider *)itemProviderAtIndex:(NSInteger)index;
+
+@property (copy, nonatomic, nullable) NSArray<UIItemProvider *> *itemProviders;
+@property (readonly, nonatomic) NSInteger numberOfItems;
+@property (readonly, nonatomic) NSInteger changeCount;
+
+@end
+
+NS_ASSUME_NONNULL_END
+
+#endif // ENABLE(DATA_INTERACTION)

Added: trunk/Source/WebCore/platform/ios/WebItemProviderPasteboard.mm (0 => 211175)


--- trunk/Source/WebCore/platform/ios/WebItemProviderPasteboard.mm	                        (rev 0)
+++ trunk/Source/WebCore/platform/ios/WebItemProviderPasteboard.mm	2017-01-25 23:50:12 UTC (rev 211175)
@@ -0,0 +1,210 @@
+/*
+ * Copyright (C) 2017 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.
+ */
+
+#include "config.h"
+#import "WebItemProviderPasteboard.h"
+
+#if ENABLE(DATA_INTERACTION)
+
+#import "SoftLinking.h"
+#import "UIKitSPI.h"
+#import <MobileCoreServices/MobileCoreServices.h>
+#import <UIKit/UIColor.h>
+#import <UIKit/UIImage.h>
+
+SOFT_LINK_FRAMEWORK(UIKit)
+SOFT_LINK_CLASS(UIKit, UIColor)
+SOFT_LINK_CLASS(UIKit, UIImage)
+SOFT_LINK_CLASS(UIKit, UIItemProvider)
+
+#define MATCHES_UTI_TYPE(type, suffix) [type isEqualToString:(__bridge NSString *)kUTType ## suffix]
+#define MATCHES_UIKIT_TYPE(type, suffix) [type isEqualToString:@"com.apple.uikit. ## suffix ##"]
+
+static BOOL isRichTextType(NSString *type)
+{
+    return MATCHES_UTI_TYPE(type, RTF) || MATCHES_UTI_TYPE(type, RTFD) || MATCHES_UTI_TYPE(type, HTML);
+}
+
+static BOOL isStringType(NSString *type)
+{
+    return MATCHES_UTI_TYPE(type, Text) || MATCHES_UTI_TYPE(type, UTF8PlainText) || MATCHES_UTI_TYPE(type, UTF16PlainText);
+}
+
+static BOOL isURLType(NSString *type)
+{
+    return MATCHES_UTI_TYPE(type, URL);
+}
+
+static BOOL isColorType(NSString *type)
+{
+    return MATCHES_UIKIT_TYPE(type, color);
+}
+
+static BOOL isImageType(NSString *type)
+{
+    return MATCHES_UTI_TYPE(type, PNG) || MATCHES_UTI_TYPE(type, JPEG) || MATCHES_UTI_TYPE(type, GIF) || MATCHES_UIKIT_TYPE(type, image);
+}
+
+@interface WebItemProviderPasteboard ()
+
+@property (nonatomic) NSInteger numberOfItems;
+@property (nonatomic) NSInteger changeCount;
+
+@end
+
+@implementation WebItemProviderPasteboard
+
++ (instancetype)sharedInstance
+{
+    static WebItemProviderPasteboard *sharedPasteboard = nil;
+    static dispatch_once_t onceToken;
+    dispatch_once(&onceToken, ^() {
+        sharedPasteboard = [[WebItemProviderPasteboard alloc] init];
+    });
+    return sharedPasteboard;
+}
+
+- (instancetype)init
+{
+    if (self = [super init]) {
+        _itemProviders = [[NSArray alloc] init];
+        _changeCount = 0;
+    }
+    return self;
+}
+
+- (void)dealloc
+{
+    [super dealloc];
+    [_itemProviders release];
+}
+
+- (NSArray<NSString *> *)pasteboardTypes
+{
+    NSMutableSet<NSString *> *allTypes = [NSMutableSet set];
+    for (UIItemProvider *provider in _itemProviders)
+        [allTypes addObjectsFromArray:provider.registeredTypeIdentifiers];
+    return allTypes.allObjects;
+}
+
+- (void)setItemProviders:(NSArray<UIItemProvider *> *)itemProviders
+{
+    itemProviders = itemProviders ?: [NSArray array];
+    if (_itemProviders == itemProviders || [_itemProviders isEqualToArray:itemProviders])
+        return;
+    _itemProviders = [itemProviders copy];
+    _changeCount++;
+}
+
+- (NSInteger)numberOfItems
+{
+    return _itemProviders.count;
+}
+
+- (void)setItems:(NSArray *)items
+{
+    NSMutableArray *providers = [[NSMutableArray alloc] init];
+    for (NSDictionary *item in items) {
+        if (!item.count)
+            continue;
+        UIItemProvider *itemProvider = [[getUIItemProviderClass() alloc] init];
+        for (NSString *typeIdentifier in item) {
+            [itemProvider registerDataRepresentationForTypeIdentifier:typeIdentifier loadHandler:^(UIItemProviderDataLoadCompletionBlock completionBlock, NSDictionary *) {
+                completionBlock(item[typeIdentifier], nil);
+            }];
+        }
+        [providers addObject:itemProvider];
+    }
+    _changeCount++;
+    _itemProviders = providers;
+}
+
+- (NSArray *)dataForPasteboardType:(NSString *)pasteboardType inItemSet:(NSIndexSet *)itemSet
+{
+    __block NSMutableArray *values = [NSMutableArray array];
+    [itemSet enumerateIndexesUsingBlock:^(NSUInteger index, BOOL *) {
+        UIItemProvider *provider = [self itemProviderAtIndex:index];
+        if (!provider)
+            return;
+
+        NSData *data = "" copyDataRepresentationForTypeIdentifier:pasteboardType options:nil error:nil];
+        if (data)
+            [values addObject:data];
+    }];
+
+    return values;
+}
+
+- (NSArray *)valuesForPasteboardType:(NSString *)pasteboardType inItemSet:(NSIndexSet *)itemSet
+{
+    __block NSMutableArray *values = [NSMutableArray array];
+    [itemSet enumerateIndexesUsingBlock:^(NSUInteger index, BOOL *) {
+        UIItemProvider *provider = [self itemProviderAtIndex:index];
+        if (!provider)
+            return;
+
+        if (isRichTextType(pasteboardType) && [provider canInstantiateObjectOfClass:[NSAttributedString class]]) {
+            [values addObject:[provider instantiateObjectOfClass:[NSAttributedString class] options:nil error:nil]];
+            return;
+        }
+
+        if (isStringType(pasteboardType) && [provider canInstantiateObjectOfClass:[NSString class]]) {
+            [values addObject:[provider instantiateObjectOfClass:[NSString class] options:nil error:nil]];
+            return;
+        }
+
+        if (isColorType(pasteboardType) && [provider canInstantiateObjectOfClass:[getUIColorClass() class]]) {
+            [values addObject:[provider instantiateObjectOfClass:[getUIColorClass() class] options:nil error:nil]];
+            return;
+        }
+
+        if (isURLType(pasteboardType) && [provider canInstantiateObjectOfClass:[NSURL class]]) {
+            [values addObject:[provider instantiateObjectOfClass:[NSURL class] options:nil error:nil]];
+            return;
+        }
+
+        if (isImageType(pasteboardType) && [provider canInstantiateObjectOfClass:[getUIImageClass() class]]) {
+            [values addObject:[provider instantiateObjectOfClass:[getUIImageClass() class] options:nil error:nil]];
+            return;
+        }
+
+        WTFLogAlways("Failed to instantiate object for type: '%s' at index: %tu", pasteboardType.UTF8String, index);
+    }];
+    return values;
+}
+
+- (NSInteger)changeCount
+{
+    return _changeCount;
+}
+
+- (UIItemProvider *)itemProviderAtIndex:(NSInteger)index
+{
+    return 0 <= index && index < (NSInteger)_itemProviders.count ? _itemProviders[index] : nil;
+}
+
+@end
+
+#endif // ENABLE(DATA_INTERACTION)

Modified: trunk/Source/WebCore/platform/spi/ios/UIKitSPI.h (211174 => 211175)


--- trunk/Source/WebCore/platform/spi/ios/UIKitSPI.h	2017-01-25 23:43:01 UTC (rev 211174)
+++ trunk/Source/WebCore/platform/spi/ios/UIKitSPI.h	2017-01-25 23:50:12 UTC (rev 211175)
@@ -30,6 +30,10 @@
 #import <UIKit/UIScreen_Private.h>
 #import <UIKit/UIViewController_Private.h>
 
+#if ENABLE(DATA_INTERACTION)
+#import <UIKit/UIItemProvider_Private.h>
+#endif
+
 #else
 
 #import <UIKit/UIKit.h>
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to