diff options
Diffstat (limited to 'ios')
-rw-r--r-- | ios/web/public/web_state/ui/crw_web_delegate.h | 17 | ||||
-rw-r--r-- | ios/web/shell/view_controller.mm | 2 | ||||
-rw-r--r-- | ios/web/web_state/ui/crw_web_controller.mm | 59 |
3 files changed, 40 insertions, 38 deletions
diff --git a/ios/web/public/web_state/ui/crw_web_delegate.h b/ios/web/public/web_state/ui/crw_web_delegate.h index 680d853..4814866 100644 --- a/ios/web/public/web_state/ui/crw_web_delegate.h +++ b/ios/web/public/web_state/ui/crw_web_delegate.h @@ -60,9 +60,10 @@ typedef void (^SSLErrorCallback)(BOOL); - (void)goDelta:(int)delta; // Opens a URL with the given parameters. - (void)openURLWithParams:(const web::WebState::OpenURLParams&)params; -// Called when a link to an external app needs to be opened. Returns YES iff -// |url| is launched in an external app. -- (BOOL)openExternalURL:(const GURL&)url; +// Called when an external app needs to be opened, it also passes |linkClicked| +// to track if this call was a result of user action or not. Returns YES iff +// |URL| is launched in an external app. +- (BOOL)openExternalURL:(const GURL&)URL linkClicked:(BOOL)linkClicked; // This method is called when a network request has an issue with the SSL // connection to present it to the user. The user will decide if the request @@ -165,15 +166,17 @@ typedef void (^SSLErrorCallback)(BOOL); - (BOOL)webController:(CRWWebController*)webController shouldOpenExternalURL:(const GURL&)URL; -// Called when |url| is deemed suitable to be opened in a matching native app. -// Needs to return whether |url| was opened in a matching native app. +// Called when |URL| is deemed suitable to be opened in a matching native app. +// Needs to return whether |URL| was opened in a matching native app. +// Also triggering user action |linkClicked| is passed to use it when needed. // The return value indicates if the native app was launched, not if a native // app was found. // TODO(shreyasv): Instead of having the CRWWebDelegate handle an external URL, // provide a hook/API to steal a URL navigation. That way the logic to determine // a URL as triggering a native app launch can also be moved. -- (BOOL)urlTriggersNativeAppLaunch:(const GURL&)url - sourceURL:(const GURL&)sourceURL; +- (BOOL)urlTriggersNativeAppLaunch:(const GURL&)URL + sourceURL:(const GURL&)sourceURL + linkClicked:(BOOL)linkClicked; // Called to ask the delegate for a controller to display the given url, // which contained content that the UIWebView couldn't display. Returns diff --git a/ios/web/shell/view_controller.mm b/ios/web/shell/view_controller.mm index 370b1d5..c3be325 100644 --- a/ios/web/shell/view_controller.mm +++ b/ios/web/shell/view_controller.mm @@ -285,7 +285,7 @@ NSString* const kWebShellAddressFieldAccessibilityLabel = @"Address field"; } - (void)openURLWithParams:(const web::WebState::OpenURLParams&)params { } -- (BOOL)openExternalURL:(const GURL&)url { +- (BOOL)openExternalURL:(const GURL&)URL linkClicked:(BOOL)linkClicked { return NO; } diff --git a/ios/web/web_state/ui/crw_web_controller.mm b/ios/web/web_state/ui/crw_web_controller.mm index 43caea72..8739d22 100644 --- a/ios/web/web_state/ui/crw_web_controller.mm +++ b/ios/web/web_state/ui/crw_web_controller.mm @@ -402,10 +402,11 @@ typedef void (^ViewportStateCompletion)(const web::PageViewportState*); - (BOOL)shouldOpenURL:(const GURL&)url mainDocumentURL:(const GURL&)mainDocumentURL linkClicked:(BOOL)linkClicked; -// Called when |url| needs to be opened in a matching native app. +// Called when |URL| needs to be opened in a matching native app. // Returns YES if the url was succesfully opened in the native app. -- (BOOL)urlTriggersNativeAppLaunch:(const GURL&)url - sourceURL:(const GURL&)sourceURL; +- (BOOL)urlTriggersNativeAppLaunch:(const GURL&)URL + sourceURL:(const GURL&)sourceURL + linkClicked:(BOOL)linkClicked; // Best guess as to whether the request is a main frame request. This method // should not be assumed correct for security evaluations, as it is possible to // spoof. @@ -2714,7 +2715,7 @@ const NSTimeInterval kSnapshotOverlayTransition = 0.5; // also because there would be nothing shown in that new tab; it would // remain on about:blank (see crbug.com/240178) if ([CRWWebController webControllerCanShow:requestURL] || - ![_delegate openExternalURL:requestURL]) { + ![_delegate openExternalURL:requestURL linkClicked:isLinkClick]) { web::NewWindowInfo windowInfo = *_externalRequest; dispatch_async(dispatch_get_main_queue(), ^{ [self openPopupWithInfo:windowInfo]; @@ -2724,25 +2725,18 @@ const NSTimeInterval kSnapshotOverlayTransition = 0.5; return NO; } - BOOL shouldCheckNativeApp = [self shouldClosePageOnNativeApplicationLoad]; - - // Check if the link navigation leads to a launch of an external app. - // TODO(shreyasv): Change this such that handling/stealing of link navigations - // is delegated to the WebDelegate and the logic around external app launching - // is moved there as well. - if (shouldCheckNativeApp || isLinkClick) { - // Check If the URL is handled by a native app. - if ([self urlTriggersNativeAppLaunch:requestURL - sourceURL:[self currentNavigationURL]]) { - // External app has been launched successfully. Stop the current page - // load operation (e.g. notifying all observers) and record the URL so - // that errors reported following the 'NO' reply can be safely ignored. - if ([self shouldClosePageOnNativeApplicationLoad]) - [_delegate webPageOrderedClose]; - [self stopLoading]; - [_openedApplicationURL addObject:request.URL]; - return NO; - } + // Check If the URL is handled by a native app. + if ([self urlTriggersNativeAppLaunch:requestURL + sourceURL:[self currentNavigationURL] + linkClicked:isLinkClick]) { + // External app has been launched successfully. Stop the current page + // load operation (e.g. notifying all observers) and record the URL so + // that errors reported following the 'NO' reply can be safely ignored. + if ([self shouldClosePageOnNativeApplicationLoad]) + [_delegate webPageOrderedClose]; + [self stopLoading]; + [_openedApplicationURL addObject:request.URL]; + return NO; } // The WebDelegate may instruct the CRWWebController to stop loading, and @@ -2768,7 +2762,7 @@ const NSTimeInterval kSnapshotOverlayTransition = 0.5; if ([self isPutativeMainFrameRequest:request targetFrame:targetFrame]) [self stopLoading]; - if ([_delegate openExternalURL:requestURL]) { + if ([_delegate openExternalURL:requestURL linkClicked:isLinkClick]) { // Record the URL so that errors reported following the 'NO' reply can be // safely ignored. [_openedApplicationURL addObject:request.URL]; @@ -3646,12 +3640,17 @@ const NSTimeInterval kSnapshotOverlayTransition = 0.5; [_delegate webController:self shouldOpenExternalURL:requestURL]; } -- (BOOL)urlTriggersNativeAppLaunch:(const GURL&)url - sourceURL:(const GURL&)sourceURL { - return - [_delegate respondsToSelector:@selector(urlTriggersNativeAppLaunch: - sourceURL:)] && - [_delegate urlTriggersNativeAppLaunch:url sourceURL:sourceURL]; +- (BOOL)urlTriggersNativeAppLaunch:(const GURL&)URL + sourceURL:(const GURL&)sourceURL + linkClicked:(BOOL)linkClicked { + if (![_delegate respondsToSelector:@selector(urlTriggersNativeAppLaunch: + sourceURL: + linkClicked:)]) { + return NO; + } + return [_delegate urlTriggersNativeAppLaunch:URL + sourceURL:sourceURL + linkClicked:linkClicked]; } - (CGFloat)headerHeight { |