Changeset 242181 in webkit


Ignore:
Timestamp:
Feb 27, 2019 4:50:30 PM (5 years ago)
Author:
beidson@apple.com
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:]):

Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r242176 r242181  
     12019-02-27  Brady Eidson  <beidson@apple.com>
     2
     3        Universal links from Google search results pages don't open the app.
     4        <rdar://problem/46887179> and https://bugs.webkit.org/show_bug.cgi?id=195126
     5
     6        Reviewed by Geoffrey Garen.
     7
     8        Covered by new API tests.
     9
     10        * loader/DocumentLoader.cpp:
     11        (WebCore::DocumentLoader::shouldOpenExternalURLsPolicyToPropagate const): Propagate the external URL policy from
     12          an iframe if it is from the same security origin as the main frame.
     13
    1142019-02-27  Zalan Bujtas  <zalan@apple.com>
    215
  • trunk/Source/WebCore/loader/DocumentLoader.cpp

    r241932 r242181  
    20772077ShouldOpenExternalURLsPolicy DocumentLoader::shouldOpenExternalURLsPolicyToPropagate() const
    20782078{
    2079     if (!m_frame || !m_frame->isMainFrame())
     2079    if (!m_frame)
    20802080        return ShouldOpenExternalURLsPolicy::ShouldNotAllow;
    20812081
    2082     return m_shouldOpenExternalURLsPolicy;
     2082    if (m_frame->isMainFrame())
     2083        return m_shouldOpenExternalURLsPolicy;
     2084
     2085    if (auto* currentDocument = document()) {
     2086        if (originsMatch(currentDocument->securityOrigin(), currentDocument->topOrigin()))
     2087            return m_shouldOpenExternalURLsPolicy;
     2088    }
     2089
     2090    return ShouldOpenExternalURLsPolicy::ShouldNotAllow;
    20832091}
    20842092
  • trunk/Tools/ChangeLog

    r242180 r242181  
     12019-02-27  Brady Eidson  <beidson@apple.com>
     2
     3        Universal links from Google search results pages don't open the app.
     4        <rdar://problem/46887179> and https://bugs.webkit.org/show_bug.cgi?id=195126
     5
     6        Reviewed by Geoffrey Garen.
     7
     8        * TestWebKitAPI/Tests/WebKitCocoa/ShouldOpenExternalURLsInNewWindowActions.mm:
     9        * TestWebKitAPI/cocoa/TestNavigationDelegate.h:
     10        * TestWebKitAPI/cocoa/TestNavigationDelegate.mm:
     11        (-[TestNavigationDelegate webView:decidePolicyForNavigationAction:decisionHandler:]):
     12
    1132019-02-27  Chris Dumez  <cdumez@apple.com>
    214
  • trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ShouldOpenExternalURLsInNewWindowActions.mm

    r221505 r242181  
    2929
    3030#import "PlatformUtilities.h"
     31#import "TestNavigationDelegate.h"
     32#import "TestURLSchemeHandler.h"
    3133#import <WebKit/WKNavigationActionPrivate.h>
    3234#import <WebKit/WKWebViewPrivate.h>
     
    251253};
    252254
     255
     256
     257static const char* iframeBytes = R"schemeresource(
     258<script>
     259top.location.href = "externalScheme://someotherhost/foo";
     260</script>
     261)schemeresource";
     262
     263static const char* mainFrameBytes = R"schemeresource(
     264<script>
     265function clicked() {
     266    var iframe = document.createElement('iframe');
     267    iframe.src = "custom://firsthost/iframe.html";
     268    document.body.appendChild(iframe);
     269}
     270</script>
     271
     272<a style="display: block; height: 100%" onclick="clicked();">Click to start iframe dance</a>
     273)schemeresource";
     274
     275TEST(WebKit, IFrameWithSameOriginAsMainFramePropagates)
     276{
     277    auto schemeHandler = adoptNS([[TestURLSchemeHandler alloc] init]);
     278    auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
     279    [configuration setURLSchemeHandler:schemeHandler.get() forURLScheme:@"custom"];
     280
     281    [schemeHandler setStartURLSchemeTaskHandler:^(WKWebView *, id<WKURLSchemeTask> task) {
     282        NSURL *requestURL = [task request].URL;
     283       
     284        NSString *responseText = nil;
     285        if ([[task request].URL.absoluteString containsString:@"iframe.html"])
     286            responseText = [NSString stringWithUTF8String:iframeBytes];
     287        else if ([[task request].URL.absoluteString containsString:@"mainframe.html"])
     288            responseText = [NSString stringWithUTF8String:mainFrameBytes];
     289
     290        auto response = adoptNS([[NSURLResponse alloc] initWithURL:requestURL MIMEType:@"text/html" expectedContentLength:[responseText length] textEncodingName:nil]);
     291        [task didReceiveResponse:response.get()];
     292        [task didReceiveData:[responseText dataUsingEncoding:NSUTF8StringEncoding]];
     293        [task didFinish];
     294    }];
     295
     296    auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
     297    auto navigationDelegate = adoptNS([[TestNavigationDelegate alloc] init]);
     298    [webView setNavigationDelegate:navigationDelegate.get()];
     299
     300    [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"custom://firsthost/mainframe.html"]]];
     301    [navigationDelegate waitForDidFinishNavigation];
     302   
     303    // Install the decidePolicyListener
     304    static bool openAppLinks;
     305    static bool externalSchemes;
     306    static bool finished = false;
     307    navigationDelegate.get().decidePolicyForNavigationAction = ^(WKNavigationAction *action, void (^decisionHandler)(WKNavigationActionPolicy)) {
     308        if (!action.targetFrame.mainFrame) {
     309            decisionHandler(WKNavigationActionPolicyAllow);
     310            return;
     311        }
     312
     313        openAppLinks = [action _shouldOpenAppLinks];
     314        externalSchemes = [action _shouldOpenExternalSchemes];
     315       
     316        decisionHandler(WKNavigationActionPolicyCancel);
     317        finished = true;
     318    };
     319   
     320    // Click the link
     321    NSPoint clickPoint = NSMakePoint(100, 100);
     322    [[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]];
     323    [[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]];
     324
     325    TestWebKitAPI::Util::run(&finished);
     326   
     327    ASSERT_TRUE(openAppLinks);
     328    ASSERT_TRUE(externalSchemes);
     329};
     330
    253331#endif
    254332
  • trunk/Tools/TestWebKitAPI/cocoa/TestNavigationDelegate.h

    r231208 r242181  
    3333@interface TestNavigationDelegate : NSObject <WKNavigationDelegate>
    3434
     35@property (nonatomic, copy) void (^decidePolicyForNavigationAction)(WKNavigationAction *, void (^)(WKNavigationActionPolicy));
    3536@property (nonatomic, copy) void (^didFailProvisionalNavigation)(WKWebView *, WKNavigation *, NSError *);
    3637@property (nonatomic, copy) void (^didStartProvisionalNavigation)(WKWebView *, WKNavigation *);
  • trunk/Tools/TestWebKitAPI/cocoa/TestNavigationDelegate.mm

    r237266 r242181  
    3333
    3434@implementation TestNavigationDelegate
     35
     36- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler
     37{
     38    if (_decidePolicyForNavigationAction)
     39        _decidePolicyForNavigationAction(navigationAction, decisionHandler);
     40    else
     41        decisionHandler(WKNavigationActionPolicyAllow);
     42}
    3543
    3644- (void)webView:(WKWebView *)webView didStartProvisionalNavigation:(WKNavigation *)navigation
Note: See TracChangeset for help on using the changeset viewer.