Title: [242181] trunk
Revision
242181
Author
beid...@apple.com
Date
2019-02-27 16:50:30 -0800 (Wed, 27 Feb 2019)

Log Message

Universal links from Google search results pages don't open the app.
<rdar://problem/46887179> and https://bugs.webkit.org/show_bug.cgi?id=195126

Reviewed by Geoffrey Garen.

Source/WebCore:

Covered by new API tests.

* loader/DocumentLoader.cpp:
(WebCore::DocumentLoader::shouldOpenExternalURLsPolicyToPropagate const): Propagate the external URL policy from
  an iframe if it is from the same security origin as the main frame.

Tools:

* TestWebKitAPI/Tests/WebKitCocoa/ShouldOpenExternalURLsInNewWindowActions.mm:
* TestWebKitAPI/cocoa/TestNavigationDelegate.h:
* TestWebKitAPI/cocoa/TestNavigationDelegate.mm:
(-[TestNavigationDelegate webView:decidePolicyForNavigationAction:decisionHandler:]):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (242180 => 242181)


--- trunk/Source/WebCore/ChangeLog	2019-02-28 00:47:42 UTC (rev 242180)
+++ trunk/Source/WebCore/ChangeLog	2019-02-28 00:50:30 UTC (rev 242181)
@@ -1,3 +1,16 @@
+2019-02-27  Brady Eidson  <beid...@apple.com>
+
+        Universal links from Google search results pages don't open the app.
+        <rdar://problem/46887179> and https://bugs.webkit.org/show_bug.cgi?id=195126
+
+        Reviewed by Geoffrey Garen.
+
+        Covered by new API tests.
+
+        * loader/DocumentLoader.cpp:
+        (WebCore::DocumentLoader::shouldOpenExternalURLsPolicyToPropagate const): Propagate the external URL policy from
+          an iframe if it is from the same security origin as the main frame.
+
 2019-02-27  Zalan Bujtas  <za...@apple.com>
 
         [ContentChangeObserver] Move DOMTimer schedule handling from global to ContentChangeObserver class

Modified: trunk/Source/WebCore/loader/DocumentLoader.cpp (242180 => 242181)


--- trunk/Source/WebCore/loader/DocumentLoader.cpp	2019-02-28 00:47:42 UTC (rev 242180)
+++ trunk/Source/WebCore/loader/DocumentLoader.cpp	2019-02-28 00:50:30 UTC (rev 242181)
@@ -2076,10 +2076,18 @@
 
 ShouldOpenExternalURLsPolicy DocumentLoader::shouldOpenExternalURLsPolicyToPropagate() const
 {
-    if (!m_frame || !m_frame->isMainFrame())
+    if (!m_frame)
         return ShouldOpenExternalURLsPolicy::ShouldNotAllow;
 
-    return m_shouldOpenExternalURLsPolicy;
+    if (m_frame->isMainFrame())
+        return m_shouldOpenExternalURLsPolicy;
+
+    if (auto* currentDocument = document()) {
+        if (originsMatch(currentDocument->securityOrigin(), currentDocument->topOrigin()))
+            return m_shouldOpenExternalURLsPolicy;
+    }
+
+    return ShouldOpenExternalURLsPolicy::ShouldNotAllow;
 }
 
 void DocumentLoader::becomeMainResourceClient()

Modified: trunk/Tools/ChangeLog (242180 => 242181)


--- trunk/Tools/ChangeLog	2019-02-28 00:47:42 UTC (rev 242180)
+++ trunk/Tools/ChangeLog	2019-02-28 00:50:30 UTC (rev 242181)
@@ -1,3 +1,15 @@
+2019-02-27  Brady Eidson  <beid...@apple.com>
+
+        Universal links from Google search results pages don't open the app.
+        <rdar://problem/46887179> and https://bugs.webkit.org/show_bug.cgi?id=195126
+
+        Reviewed by Geoffrey Garen.
+
+        * TestWebKitAPI/Tests/WebKitCocoa/ShouldOpenExternalURLsInNewWindowActions.mm:
+        * TestWebKitAPI/cocoa/TestNavigationDelegate.h:
+        * TestWebKitAPI/cocoa/TestNavigationDelegate.mm:
+        (-[TestNavigationDelegate webView:decidePolicyForNavigationAction:decisionHandler:]):
+
 2019-02-27  Chris Dumez  <cdu...@apple.com>
 
         Flaky API Test: TestWebKitAPI.ProcessSwap.NumberOfCachedProcesses

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ShouldOpenExternalURLsInNewWindowActions.mm (242180 => 242181)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ShouldOpenExternalURLsInNewWindowActions.mm	2019-02-28 00:47:42 UTC (rev 242180)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ShouldOpenExternalURLsInNewWindowActions.mm	2019-02-28 00:50:30 UTC (rev 242181)
@@ -28,6 +28,8 @@
 #if PLATFORM(MAC)
 
 #import "PlatformUtilities.h"
+#import "TestNavigationDelegate.h"
+#import "TestURLSchemeHandler.h"
 #import <WebKit/WKNavigationActionPrivate.h>
 #import <WebKit/WKWebViewPrivate.h>
 #import <wtf/RetainPtr.h>
@@ -250,6 +252,82 @@
     ASSERT_FALSE([action _shouldOpenAppLinks]);
 };
 
+
+
+static const char* iframeBytes = R"schemeresource(
+<script>
+top.location.href = ""
+</script>
+)schemeresource";
+
+static const char* mainFrameBytes = R"schemeresource(
+<script>
+function clicked() {
+    var iframe = document.createElement('iframe');
+    iframe.src = ""
+    document.body.appendChild(iframe);
+}
+</script>
+
+<a style="display: block; height: 100%" _onclick_="clicked();">Click to start iframe dance</a>
+)schemeresource";
+
+TEST(WebKit, IFrameWithSameOriginAsMainFramePropagates)
+{
+    auto schemeHandler = adoptNS([[TestURLSchemeHandler alloc] init]);
+    auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
+    [configuration setURLSchemeHandler:schemeHandler.get() forURLScheme:@"custom"];
+
+    [schemeHandler setStartURLSchemeTaskHandler:^(WKWebView *, id<WKURLSchemeTask> task) {
+        NSURL *requestURL = [task request].URL;
+        
+        NSString *responseText = nil;
+        if ([[task request].URL.absoluteString containsString:@"iframe.html"])
+            responseText = [NSString stringWithUTF8String:iframeBytes];
+        else if ([[task request].URL.absoluteString containsString:@"mainframe.html"])
+            responseText = [NSString stringWithUTF8String:mainFrameBytes];
+
+        auto response = adoptNS([[NSURLResponse alloc] initWithURL:requestURL MIMEType:@"text/html" expectedContentLength:[responseText length] textEncodingName:nil]);
+        [task didReceiveResponse:response.get()];
+        [task didReceiveData:[responseText dataUsingEncoding:NSUTF8StringEncoding]];
+        [task didFinish];
+    }];
+
+    auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
+    auto navigationDelegate = adoptNS([[TestNavigationDelegate alloc] init]);
+    [webView setNavigationDelegate:navigationDelegate.get()];
+
+    [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"custom://firsthost/mainframe.html"]]];
+    [navigationDelegate waitForDidFinishNavigation];
+    
+    // Install the decidePolicyListener
+    static bool openAppLinks;
+    static bool externalSchemes;
+    static bool finished = false;
+    navigationDelegate.get().decidePolicyForNavigationAction = ^(WKNavigationAction *action, void (^decisionHandler)(WKNavigationActionPolicy)) {
+        if (!action.targetFrame.mainFrame) {
+            decisionHandler(WKNavigationActionPolicyAllow);
+            return;
+        }
+
+        openAppLinks = [action _shouldOpenAppLinks];
+        externalSchemes = [action _shouldOpenExternalSchemes];
+        
+        decisionHandler(WKNavigationActionPolicyCancel);
+        finished = true;
+    };
+    
+    // Click the link
+    NSPoint clickPoint = NSMakePoint(100, 100);
+    [[webView hitTest:clickPoint] mouseDown:[NSEvent mouseEventWithType:NSEventTypeLeftMouseDown location:clickPoint modifierFlags:0 timestamp:0 windowNumber:[webView.get().window windowNumber] context:nil eventNumber:0 clickCount:1 pressure:1]];
+    [[webView hitTest:clickPoint] mouseUp:[NSEvent mouseEventWithType:NSEventTypeLeftMouseUp location:clickPoint modifierFlags:0 timestamp:0 windowNumber:[webView.get().window windowNumber] context:nil eventNumber:0 clickCount:1 pressure:1]];
+
+    TestWebKitAPI::Util::run(&finished);
+    
+    ASSERT_TRUE(openAppLinks);
+    ASSERT_TRUE(externalSchemes);
+};
+
 #endif
 
 #endif

Modified: trunk/Tools/TestWebKitAPI/cocoa/TestNavigationDelegate.h (242180 => 242181)


--- trunk/Tools/TestWebKitAPI/cocoa/TestNavigationDelegate.h	2019-02-28 00:47:42 UTC (rev 242180)
+++ trunk/Tools/TestWebKitAPI/cocoa/TestNavigationDelegate.h	2019-02-28 00:50:30 UTC (rev 242181)
@@ -32,6 +32,7 @@
 
 @interface TestNavigationDelegate : NSObject <WKNavigationDelegate>
 
+@property (nonatomic, copy) void (^decidePolicyForNavigationAction)(WKNavigationAction *, void (^)(WKNavigationActionPolicy));
 @property (nonatomic, copy) void (^didFailProvisionalNavigation)(WKWebView *, WKNavigation *, NSError *);
 @property (nonatomic, copy) void (^didStartProvisionalNavigation)(WKWebView *, WKNavigation *);
 @property (nonatomic, copy) void (^didFinishNavigation)(WKWebView *, WKNavigation *);

Modified: trunk/Tools/TestWebKitAPI/cocoa/TestNavigationDelegate.mm (242180 => 242181)


--- trunk/Tools/TestWebKitAPI/cocoa/TestNavigationDelegate.mm	2019-02-28 00:47:42 UTC (rev 242180)
+++ trunk/Tools/TestWebKitAPI/cocoa/TestNavigationDelegate.mm	2019-02-28 00:50:30 UTC (rev 242181)
@@ -33,6 +33,14 @@
 
 @implementation TestNavigationDelegate
 
+- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler
+{
+    if (_decidePolicyForNavigationAction)
+        _decidePolicyForNavigationAction(navigationAction, decisionHandler);
+    else
+        decisionHandler(WKNavigationActionPolicyAllow);
+}
+
 - (void)webView:(WKWebView *)webView didStartProvisionalNavigation:(WKNavigation *)navigation
 {
     if (_didStartProvisionalNavigation)
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to