Replace -[WKWebView adjustedDataInteractionItemProviders:] with a UI delegate method
authorwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 2 Mar 2017 07:43:41 +0000 (07:43 +0000)
committerwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 2 Mar 2017 07:43:41 +0000 (07:43 +0000)
https://bugs.webkit.org/show_bug.cgi?id=169013

Reviewed by Dan Bernstein.

Source/WebKit2:

Rather than introduce new SPI on WKWebView directly, we should follow convention and add the hook to the private
version of the UI delegate.

* UIProcess/API/Cocoa/WKUIDelegatePrivate.h:
* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView _adjustedDataInteractionItemProviders:]): Deleted.
* UIProcess/API/Cocoa/WKWebViewPrivate.h:

Tools:

Adjusts TestWebKitAPI for changes in WebKit2. See Source/WebKit2/ChangeLog for more details.

* TestWebKitAPI/Tests/ios/DataInteractionTests.mm:
(TestWebKitAPI::TEST):
(-[CustomItemProviderWebView _adjustedDataInteractionItemProviders:]): Deleted.
* TestWebKitAPI/ios/DataInteractionSimulator.h:
* TestWebKitAPI/ios/DataInteractionSimulator.mm:
(-[DataInteractionSimulator initWithWebView:]):
(-[DataInteractionSimulator dealloc]):
(-[DataInteractionSimulator _webView:adjustedDataInteractionItemProviders:]):

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

Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/API/Cocoa/WKUIDelegatePrivate.h
Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm
Source/WebKit2/UIProcess/API/Cocoa/WKWebViewPrivate.h
Tools/ChangeLog
Tools/TestWebKitAPI/Tests/ios/DataInteractionTests.mm
Tools/TestWebKitAPI/ios/DataInteractionSimulator.h
Tools/TestWebKitAPI/ios/DataInteractionSimulator.mm

index d255a73..d25b217 100644 (file)
@@ -1,3 +1,18 @@
+2017-03-01  Wenson Hsieh  <wenson_hsieh@apple.com>
+
+        Replace -[WKWebView adjustedDataInteractionItemProviders:] with a UI delegate method
+        https://bugs.webkit.org/show_bug.cgi?id=169013
+
+        Reviewed by Dan Bernstein.
+
+        Rather than introduce new SPI on WKWebView directly, we should follow convention and add the hook to the private
+        version of the UI delegate.
+
+        * UIProcess/API/Cocoa/WKUIDelegatePrivate.h:
+        * UIProcess/API/Cocoa/WKWebView.mm:
+        (-[WKWebView _adjustedDataInteractionItemProviders:]): Deleted.
+        * UIProcess/API/Cocoa/WKWebViewPrivate.h:
+
 2017-03-01  Alex Christensen  <achristensen@webkit.org>
 
         Unreviewed, rolling out r213259.
index 1183434..361a5ca 100644 (file)
@@ -30,6 +30,7 @@
 #import <WebKit/WKSecurityOrigin.h>
 #import <WebKit/_WKActivatedElementInfo.h>
 
+@class UIItemProvider;
 @class UIScrollView;
 @class UIViewController;
 @class _WKContextMenuElementInfo;
@@ -86,6 +87,7 @@ struct UIEdgeInsets;
 - (UIViewController *)_presentingViewControllerForWebView:(WKWebView *)webView WK_API_AVAILABLE(ios(10.0));
 - (void)_webView:(WKWebView *)webView getAlternateURLFromImage:(UIImage *)image completionHandler:(void (^)(NSURL *alternateURL, NSDictionary *userInfo))completionHandler WK_API_AVAILABLE(ios(WK_IOS_TBA));
 - (NSURL *)_webView:(WKWebView *)webView alternateURLFromImage:(UIImage *)image userInfo:(NSDictionary **)userInfo WK_API_AVAILABLE(ios(WK_IOS_TBA));
+- (NSArray<UIItemProvider *> *)_webView:(WKWebView *)webView adjustedDataInteractionItemProviders:(NSArray<UIItemProvider *> *)originalItemProviders WK_API_AVAILABLE(ios(WK_IOS_TBA));
 #else
 - (NSMenu *)_webView:(WKWebView *)webView contextMenu:(NSMenu *)menu forElement:(_WKContextMenuElementInfo *)element WK_API_AVAILABLE(macosx(10.12));
 - (NSMenu *)_webView:(WKWebView *)webView contextMenu:(NSMenu *)menu forElement:(_WKContextMenuElementInfo *)element userInfo:(id <NSSecureCoding>)userInfo WK_API_AVAILABLE(macosx(10.12));
index 64bb2c3..a6986d2 100644 (file)
@@ -3726,11 +3726,6 @@ static int32_t activeOrientation(WKWebView *webView)
 {
 }
 
-- (NSArray *)_adjustedDataInteractionItemProviders:(NSArray *)originalItemProviders
-{
-    return originalItemProviders;
-}
-
 #endif
 
 - (void)_didRelaunchProcess
index 1586133..10dba6a 100644 (file)
@@ -188,8 +188,6 @@ typedef NS_ENUM(NSInteger, _WKImmediateActionType) {
 - (void)_accessibilityRetrieveSpeakSelectionContent;
 - (void)_accessibilityDidGetSpeakSelectionContent:(NSString *)content;
 
-- (NSArray *)_adjustedDataInteractionItemProviders:(NSArray *)originalItemProviders WK_API_AVAILABLE(ios(WK_IOS_TBA));
-
 #else
 @property (readonly) NSColor *_pageExtendedBackgroundColor;
 @property (nonatomic, setter=_setDrawsBackground:) BOOL _drawsBackground;
index 263d105..83812cb 100644 (file)
@@ -1,3 +1,21 @@
+2017-03-01  Wenson Hsieh  <wenson_hsieh@apple.com>
+
+        Replace -[WKWebView adjustedDataInteractionItemProviders:] with a UI delegate method
+        https://bugs.webkit.org/show_bug.cgi?id=169013
+
+        Reviewed by Dan Bernstein.
+
+        Adjusts TestWebKitAPI for changes in WebKit2. See Source/WebKit2/ChangeLog for more details.
+
+        * TestWebKitAPI/Tests/ios/DataInteractionTests.mm:
+        (TestWebKitAPI::TEST):
+        (-[CustomItemProviderWebView _adjustedDataInteractionItemProviders:]): Deleted.
+        * TestWebKitAPI/ios/DataInteractionSimulator.h:
+        * TestWebKitAPI/ios/DataInteractionSimulator.mm:
+        (-[DataInteractionSimulator initWithWebView:]):
+        (-[DataInteractionSimulator dealloc]):
+        (-[DataInteractionSimulator _webView:adjustedDataInteractionItemProviders:]):
+
 2017-03-01  Per Arne Vollan  <pvollan@apple.com>
 
         [Win] DRT should not dispatch messages after test is done.
index 020ee09..016b2a3 100644 (file)
@@ -34,7 +34,6 @@
 #import <MobileCoreServices/MobileCoreServices.h>
 #import <UIKit/UIItemProvider_Private.h>
 #import <WebKit/WKWebViewConfigurationPrivate.h>
-#import <WebKit/WKWebViewPrivate.h>
 
 @implementation TestWKWebView (DataInteractionTests)
 
 
 @end
 
-@interface CustomItemProviderWebView : TestWKWebView
-@property (nonatomic) BlockPtr<NSArray *(NSArray *)> convertItemProvidersBlock;
-@end
-
-@implementation CustomItemProviderWebView
-
-- (NSArray *)_adjustedDataInteractionItemProviders:(NSArray *)originalItemProviders
-{
-    if (!self.convertItemProvidersBlock)
-        return [super _adjustedDataInteractionItemProviders:originalItemProviders];
-
-    return self.convertItemProvidersBlock(originalItemProviders);
-}
-
-@end
-
 static NSValue *makeCGRectValue(CGFloat x, CGFloat y, CGFloat width, CGFloat height)
 {
     return [NSValue valueWithCGRect:CGRectMake(x, y, width, height)];
@@ -272,12 +255,13 @@ TEST(DataInteractionTests, AttachmentElementItemProviders)
 {
     RetainPtr<WKWebViewConfiguration> configuration = [WKWebViewConfiguration testwebkitapi_configurationWithTestPlugInClassName:@"BundleEditingDelegatePlugIn"];
     [configuration _setAttachmentElementEnabled:YES];
-    auto webView = adoptNS([[CustomItemProviderWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500) configuration:configuration.get()]);
+    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500) configuration:configuration.get()]);
+    auto dataInteractionSimulator = adoptNS([[DataInteractionSimulator alloc] initWithWebView:webView.get()]);
     [webView synchronouslyLoadTestPageNamed:@"attachment-element"];
 
     NSString *injectedTypeIdentifier = @"org.webkit.data";
     __block RetainPtr<NSString> injectedString;
-    [webView setConvertItemProvidersBlock:^NSArray *(NSArray *originalItemProviders)
+    [dataInteractionSimulator setConvertItemProvidersBlock:^NSArray *(NSArray *originalItemProviders)
     {
         for (UIItemProvider *provider in originalItemProviders) {
             NSData *injectedData = [provider copyDataRepresentationForTypeIdentifier:injectedTypeIdentifier error:nil];
@@ -289,7 +273,6 @@ TEST(DataInteractionTests, AttachmentElementItemProviders)
         return originalItemProviders;
     }];
 
-    auto dataInteractionSimulator = adoptNS([[DataInteractionSimulator alloc] initWithWebView:webView.get()]);
     [dataInteractionSimulator runFrom:CGPointMake(50, 50) to:CGPointMake(50, 400)];
 
     EXPECT_WK_STREQ("hello", [injectedString UTF8String]);
index a1bb308..b6069f9 100644 (file)
@@ -28,6 +28,7 @@
 #import "TestWKWebView.h"
 #import <UIKit/UIItemProvider.h>
 #import <UIKit/UIKit.h>
+#import <WebKit/WKUIDelegatePrivate.h>
 #import <WebKit/_WKTestingDelegate.h>
 #import <wtf/BlockPtr.h>
 
@@ -48,7 +49,7 @@ typedef NS_ENUM(NSInteger, DataInteractionPhase) {
     DataInteractionPerforming = 4
 };
 
-@interface DataInteractionSimulator : NSObject<_WKTestingDelegate> {
+@interface DataInteractionSimulator : NSObject<_WKTestingDelegate, WKUIDelegatePrivate> {
     RetainPtr<TestWKWebView> _webView;
     RetainPtr<MockDataInteractionSession> _dataInteractionSession;
     RetainPtr<MockDataInteractionInfo> _dataInteractionInfo;
@@ -66,6 +67,7 @@ typedef NS_ENUM(NSInteger, DataInteractionPhase) {
 - (instancetype)initWithWebView:(TestWKWebView *)webView;
 - (void)runFrom:(CGPoint)startLocation to:(CGPoint)endLocation;
 
+@property (nonatomic) BlockPtr<NSArray *(NSArray *)> convertItemProvidersBlock;
 @property (nonatomic, strong) UIItemProvider *externalItemProvider;
 @property (nonatomic, readonly) NSArray *observedEventNames;
 @property (nonatomic, readonly) NSArray *finalSelectionRects;
index 00369b5..1c1f07d 100644 (file)
@@ -59,6 +59,7 @@ static NSArray *dataInteractionEventNames()
     if (self = [super init]) {
         _webView = webView;
         [_webView _setTestingDelegate:self];
+        [_webView setUIDelegate:self];
     }
     return self;
 }
@@ -68,6 +69,9 @@ static NSArray *dataInteractionEventNames()
     if ([_webView _testingDelegate] == self)
         [_webView _setTestingDelegate:nil];
 
+    if ([_webView UIDelegate] == self)
+        [_webView setUIDelegate:nil];
+
     [super dealloc];
 }
 
@@ -212,6 +216,13 @@ static NSArray *dataInteractionEventNames()
     _isDoneWithCurrentRun = true;
 }
 
+#pragma mark - WKUIDelegatePrivate
+
+- (NSArray<UIItemProvider *>*)_webView:(WKWebView *)webView adjustedDataInteractionItemProviders:(NSArray<UIItemProvider *>*)originalItemProviders
+{
+    return self.convertItemProvidersBlock ? self.convertItemProvidersBlock(originalItemProviders) : originalItemProviders;
+}
+
 @end
 
 #endif // ENABLE(DATA_INTERACTION)