[iOS] REGRESSION (r218144) -[WKContentView targetForAction:withSender:] returns the...
authormitz@apple.com <mitz@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 31 Aug 2017 04:07:34 +0000 (04:07 +0000)
committermitz@apple.com <mitz@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 31 Aug 2017 04:07:34 +0000 (04:07 +0000)
https://bugs.webkit.org/show_bug.cgi?id=176077
<rdar://problem/34145200>

Reviewed by Sam Weinig.

Source/WebKit:

Test: TestWebKitAPI/Tests/WebKitCocoa/WKContentViewTargetForAction.mm

* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView targetForAction:withSender:]): Override and forward WKContentView actions to
  -[WKContentView targetForActionForWebView:withSender:].
* UIProcess/ios/WKContentViewInteraction.h: Declare -targetForActionForWebView:withSender:.
* UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView targetForAction:withSender:]): Forward to the WKWebView.
(-[WKContentView targetForActionForWebView:withSender:]): Call super’s
  -targetForAction:withSender:.

Tools:

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/WebKitCocoa/WKContentViewTargetForAction.mm: Added.
(-[TestWKContentViewTargetForActionView testAction:]):
(TEST):
* TestWebKitAPI/ios/UIKitSPI.h:

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

Source/WebKit/ChangeLog
Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm
Source/WebKit/UIProcess/ios/WKContentViewInteraction.h
Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm
Tools/ChangeLog
Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
Tools/TestWebKitAPI/Tests/WebKitCocoa/WKContentViewTargetForAction.mm [new file with mode: 0644]

index 54850e8..a3572b5 100644 (file)
@@ -1,3 +1,22 @@
+2017-08-30  Dan Bernstein  <mitz@apple.com>
+
+        [iOS] REGRESSION (r218144) -[WKContentView targetForAction:withSender:] returns the content view for actions implemented only by the WKWebView, causing a crash
+        https://bugs.webkit.org/show_bug.cgi?id=176077
+        <rdar://problem/34145200>
+
+        Reviewed by Sam Weinig.
+
+        Test: TestWebKitAPI/Tests/WebKitCocoa/WKContentViewTargetForAction.mm
+
+        * UIProcess/API/Cocoa/WKWebView.mm:
+        (-[WKWebView targetForAction:withSender:]): Override and forward WKContentView actions to
+          -[WKContentView targetForActionForWebView:withSender:].
+        * UIProcess/ios/WKContentViewInteraction.h: Declare -targetForActionForWebView:withSender:.
+        * UIProcess/ios/WKContentViewInteraction.mm:
+        (-[WKContentView targetForAction:withSender:]): Forward to the WKWebView.
+        (-[WKContentView targetForActionForWebView:withSender:]): Call super’s
+          -targetForAction:withSender:.
+
 2017-08-30  Brent Fulgham  <bfulgham@apple.com>
 
         Fix whitespace and formatting
index 1a1f60d..b57738e 100644 (file)
@@ -1253,6 +1253,19 @@ FOR_EACH_WKCONTENTVIEW_ACTION(FORWARD_ACTION_TO_WKCONTENTVIEW)
     return [super canPerformAction:action withSender:sender];
 }
 
+- (id)targetForAction:(SEL)action withSender:(id)sender
+{
+    #define FORWARD_TARGETFORACTION_TO_WKCONTENTVIEW(_action) \
+        if (action == @selector(_action:) && self.usesStandardContentView) \
+            return [_contentView targetForActionForWebView:action withSender:sender];
+
+    FOR_EACH_WKCONTENTVIEW_ACTION(FORWARD_TARGETFORACTION_TO_WKCONTENTVIEW)
+
+    #undef FORWARD_TARGETFORACTION_TO_WKCONTENTVIEW
+
+    return [super targetForAction:action withSender:sender];
+}
+
 static inline CGFloat floorToDevicePixel(CGFloat input, float deviceScaleFactor)
 {
     return CGFloor(input * deviceScaleFactor) / deviceScaleFactor;
index 2de6207..60a9f77 100644 (file)
@@ -288,6 +288,7 @@ struct WKAutoCorrectionData {
 - (BOOL)becomeFirstResponderForWebView;
 - (BOOL)resignFirstResponderForWebView;
 - (BOOL)canPerformActionForWebView:(SEL)action withSender:(id)sender;
+- (id)targetForActionForWebView:(SEL)action withSender:(id)sender;
 
 #define DECLARE_WKCONTENTVIEW_ACTION_FOR_WEB_VIEW(_action) \
     - (void)_action ## ForWebView:(id)sender;
index d32f8d4..f223e1c 100644 (file)
@@ -2165,6 +2165,16 @@ FOR_EACH_WKCONTENTVIEW_ACTION(FORWARD_ACTION_TO_WKWEBVIEW)
     return [super canPerformAction:action withSender:sender];
 }
 
+- (id)targetForAction:(SEL)action withSender:(id)sender
+{
+    return [_webView targetForAction:action withSender:sender];
+}
+
+- (id)targetForActionForWebView:(SEL)action withSender:(id)sender
+{
+    return [super targetForAction:action withSender:sender];
+}
+
 - (void)_resetShowingTextStyle:(NSNotification *)notification
 {
     _showingTextStyleOptions = NO;
index d7b9a7e..afafef0 100644 (file)
@@ -1,3 +1,17 @@
+2017-08-30  Dan Bernstein  <mitz@apple.com>
+
+        [iOS] REGRESSION (r218144) -[WKContentView targetForAction:withSender:] returns the content view for actions implemented only by the WKWebView, causing a crash
+        https://bugs.webkit.org/show_bug.cgi?id=176077
+        <rdar://problem/34145200>
+
+        Reviewed by Sam Weinig.
+
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+        * TestWebKitAPI/Tests/WebKitCocoa/WKContentViewTargetForAction.mm: Added.
+        (-[TestWKContentViewTargetForActionView testAction:]):
+        (TEST):
+        * TestWebKitAPI/ios/UIKitSPI.h:
+
 2017-08-30  Carlos Alberto Lopez Perez  <clopez@igalia.com>
 
         [GTK] install-dependencies script should install CUPS headers
index 6b2e51c..a0faa5e 100644 (file)
                33DC8912141955FE00747EF7 /* simple-iframe.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 33DC890E1419539300747EF7 /* simple-iframe.html */; };
                33DC89141419579F00747EF7 /* LoadCanceledNoServerRedirectCallback_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 33DC89131419579F00747EF7 /* LoadCanceledNoServerRedirectCallback_Bundle.cpp */; };
                33E79E06137B5FD900E32D99 /* mouse-move-listener.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 33E79E05137B5FCE00E32D99 /* mouse-move-listener.html */; };
+               370CE22A1F57343400E7410B /* WKContentViewTargetForAction.mm in Sources */ = {isa = PBXBuildFile; fileRef = 370CE2291F57343400E7410B /* WKContentViewTargetForAction.mm */; };
                374B7A601DF36EEE00ACCB6C /* BundleEditingDelegate.mm in Sources */ = {isa = PBXBuildFile; fileRef = 374B7A5E1DF36EEE00ACCB6C /* BundleEditingDelegate.mm */; };
                374B7A611DF371CF00ACCB6C /* BundleEditingDelegatePlugIn.mm in Sources */ = {isa = PBXBuildFile; fileRef = 374B7A5F1DF36EEE00ACCB6C /* BundleEditingDelegatePlugIn.mm */; };
                375E0E171D66674400EFEC2C /* WKNSNumber.mm in Sources */ = {isa = PBXBuildFile; fileRef = 375E0E151D66674400EFEC2C /* WKNSNumber.mm */; };
                33DC8910141953A300747EF7 /* LoadCanceledNoServerRedirectCallback.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = LoadCanceledNoServerRedirectCallback.cpp; sourceTree = "<group>"; };
                33DC89131419579F00747EF7 /* LoadCanceledNoServerRedirectCallback_Bundle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = LoadCanceledNoServerRedirectCallback_Bundle.cpp; sourceTree = "<group>"; };
                33E79E05137B5FCE00E32D99 /* mouse-move-listener.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "mouse-move-listener.html"; sourceTree = "<group>"; };
+               370CE2291F57343400E7410B /* WKContentViewTargetForAction.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = WKContentViewTargetForAction.mm; sourceTree = "<group>"; };
                3722C8681461E03E00C45D00 /* RenderedImageFromDOMRange.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = RenderedImageFromDOMRange.mm; sourceTree = "<group>"; };
                374B7A5E1DF36EEE00ACCB6C /* BundleEditingDelegate.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = BundleEditingDelegate.mm; sourceTree = "<group>"; };
                374B7A5F1DF36EEE00ACCB6C /* BundleEditingDelegatePlugIn.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = BundleEditingDelegatePlugIn.mm; sourceTree = "<group>"; };
                                1F83571A1D3FFB0E00E3967B /* WKBackForwardList.mm */,
                                5CE354D81E70D9C300BEFE3B /* WKContentExtensionStore.mm */,
                                2D838B1E1EEF3A5B009B980E /* WKContentViewEditingActions.mm */,
+                               370CE2291F57343400E7410B /* WKContentViewTargetForAction.mm */,
                                51D124971E763AF8002B2820 /* WKHTTPCookieStore.mm */,
                                375E0E151D66674400EFEC2C /* WKNSNumber.mm */,
                                37B47E2E1D64E7CA005F4EFF /* WKObject.mm */,
                                C07E6CAD13FD67650038B22B /* mac */,
                                C08587F913FEC39B001EF4E5 /* TestWebKitAPI */,
                                440A1D3614A01000008A66F2 /* WebCore */,
-                               CDC8E4981BC728AE00594FEC /* WebKitLegacy */,
                                BC9096411255616000083756 /* WebKit */,
                                1ABC3DEC1899BE55004F0626 /* WebKit Cocoa */,
                                BC3C4C6F14575B1D0025FB62 /* WebKit Objective-C */,
+                               CDC8E4981BC728AE00594FEC /* WebKitLegacy */,
                                BC9096461255618900083756 /* WTF */,
                        );
                        path = Tests;
                                7C54A4BE1AA11CCA00380F78 /* WKBundleFileHandle.cpp in Sources */,
                                5CE354D91E70DA5C00BEFE3B /* WKContentExtensionStore.mm in Sources */,
                                2D838B1F1EEF3A5C009B980E /* WKContentViewEditingActions.mm in Sources */,
+                               370CE22A1F57343400E7410B /* WKContentViewTargetForAction.mm in Sources */,
                                51D124981E763B02002B2820 /* WKHTTPCookieStore.mm in Sources */,
                                7CCE7F1D1A411AE600447C4C /* WKImageCreateCGImageCrash.cpp in Sources */,
                                375E0E171D66674400EFEC2C /* WKNSNumber.mm in Sources */,
diff --git a/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKContentViewTargetForAction.mm b/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKContentViewTargetForAction.mm
new file mode 100644 (file)
index 0000000..6248dd9
--- /dev/null
@@ -0,0 +1,63 @@
+/*
+ * 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 "config.h"
+
+#if PLATFORM(IOS)
+
+#import "PlatformUtilities.h"
+#import "Test.h"
+#import "TestWKWebView.h"
+#import <WebKit/WebKit.h>
+#import <wtf/RetainPtr.h>
+
+@interface TestWKContentViewTargetForActionView : TestWKWebView
+@end
+
+@implementation TestWKContentViewTargetForActionView
+
+- (void)testAction:(id)sender
+{
+}
+
+@end
+
+TEST(WebKit2, WKContentViewTargetForAction)
+{
+    auto webView = adoptNS([[TestWKContentViewTargetForActionView alloc] init]);
+    [webView synchronouslyLoadTestPageNamed:@"rich-and-plain-text"];
+    [webView becomeFirstResponder];
+    [webView stringByEvaluatingJavaScript:@"selectPlainText()"];
+
+    // FIXME: Once this test is running in an application, it should instead use
+    // -[UIApplication sendAction:to:from:forEvent:] and verify that the action is dispatched to the
+    // right responder.
+    UIView *contentView = [webView valueForKey:@"_currentContentView"];
+    EXPECT_EQ([webView targetForAction:@selector(copy:) withSender:nil], contentView);
+    EXPECT_EQ([contentView targetForAction:@selector(copy:) withSender:nil], contentView);
+    EXPECT_EQ([webView targetForAction:@selector(testAction:) withSender:nil], webView.get());
+}
+
+#endif