Commit 80e4879a authored by Michael Thiessen's avatar Michael Thiessen Committed by Commit Bot

Make ShouldOverrideUrlLoadingInternal more readable (4 of N)

No functional changes intended, please revert if things break.

This function is a large, and hard to follow. I'm hoping to break out a
bunch of functions that are clearer about what they're doing and make
ordering clearer.

In this CL, I do change how the DISABLE_EXTERNAL_INTENT_REQUESTS flag
works to make it more correct, but that shouldn't affect users.

Bug: 1006927
Change-Id: I8757fb70803d48d23e32b3ec62b3eeb3b89b64d0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1824119
Commit-Queue: Michael Thiessen <mthiesse@chromium.org>
Reviewed-by: default avatarYaron Friedman <yfriedman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#699943}
parent ce978ac8
...@@ -411,6 +411,15 @@ public class ExternalNavigationHandler { ...@@ -411,6 +411,15 @@ public class ExternalNavigationHandler {
return false; return false;
} }
private boolean externalIntentRequestsDisabled() {
// TODO(changwan): check if we need to handle URL even when external intent is off.
if (CommandLine.getInstance().hasSwitch(ChromeSwitches.DISABLE_EXTERNAL_INTENT_REQUESTS)) {
Log.w(TAG, "External intent handling is disabled by a command-line flag.");
return true;
}
return false;
}
private @OverrideUrlLoadingResult int shouldOverrideUrlLoadingInternal( private @OverrideUrlLoadingResult int shouldOverrideUrlLoadingInternal(
ExternalNavigationParams params, Intent intent, boolean hasBrowserFallbackUrl, ExternalNavigationParams params, Intent intent, boolean hasBrowserFallbackUrl,
String browserFallbackUrl) { String browserFallbackUrl) {
...@@ -419,10 +428,6 @@ public class ExternalNavigationHandler { ...@@ -419,10 +428,6 @@ public class ExternalNavigationHandler {
return OverrideUrlLoadingResult.NO_OVERRIDE; return OverrideUrlLoadingResult.NO_OVERRIDE;
} }
int pageTransitionCore = params.getPageTransition() & PageTransition.CORE_MASK;
boolean isLink = pageTransitionCore == PageTransition.LINK;
boolean isFormSubmit = pageTransitionCore == PageTransition.FORM_SUBMIT;
boolean isFromIntent = (params.getPageTransition() & PageTransition.FROM_API) != 0;
boolean isExternalProtocol = !UrlUtilities.isAcceptedScheme(params.getUrl()); boolean isExternalProtocol = !UrlUtilities.isAcceptedScheme(params.getUrl());
if (isInternalPdfDownload(isExternalProtocol, params)) { if (isInternalPdfDownload(isExternalProtocol, params)) {
...@@ -435,18 +440,28 @@ public class ExternalNavigationHandler { ...@@ -435,18 +440,28 @@ public class ExternalNavigationHandler {
return OverrideUrlLoadingResult.OVERRIDE_WITH_ASYNC_ACTION; return OverrideUrlLoadingResult.OVERRIDE_WITH_ASYNC_ACTION;
} }
// This should come after file intents, but before any returns of
// OVERRIDE_WITH_EXTERNAL_INTENT.
if (externalIntentRequestsDisabled()) return OverrideUrlLoadingResult.NO_OVERRIDE;
int pageTransitionCore = params.getPageTransition() & PageTransition.CORE_MASK;
boolean isLink = pageTransitionCore == PageTransition.LINK;
boolean isFormSubmit = pageTransitionCore == PageTransition.FORM_SUBMIT;
boolean isFromIntent = (params.getPageTransition() & PageTransition.FROM_API) != 0;
// http://crbug.com/149218: We want to show the intent picker for ordinary links, providing // http://crbug.com/149218: We want to show the intent picker for ordinary links, providing
// the link is not an incoming intent from another application, unless it's a redirect (see // the link is not an incoming intent from another application, unless it's a redirect (see
// below). // below).
boolean linkNotFromIntent = isLink && !isFromIntent; boolean linkNotFromIntent = isLink && !isFromIntent;
boolean isOnEffectiveIntentRedirect = params.getRedirectHandler() == null ? false boolean isOnEffectiveIntentRedirect = params.getRedirectHandler() == null
? false
: params.getRedirectHandler().isOnEffectiveIntentRedirectChain(); : params.getRedirectHandler().isOnEffectiveIntentRedirectChain();
// http://crbug.com/170925: We need to show the intent picker when we receive an intent from // http://crbug.com/170925: We need to show the intent picker when we receive an intent from
// another app that 30x redirects to a YouTube/Google Maps/Play Store/Google+ URL etc. // another app that 30x redirects to a YouTube/Google Maps/Play Store/Google+ URL etc.
boolean incomingIntentRedirect = (isLink && isFromIntent && params.isRedirect()) boolean incomingIntentRedirect =
|| isOnEffectiveIntentRedirect; (isLink && isFromIntent && params.isRedirect()) || isOnEffectiveIntentRedirect;
// Don't stay in Chrome for Custom Tabs redirecting to Instant Apps. // Don't stay in Chrome for Custom Tabs redirecting to Instant Apps.
if (handleCCTRedirectsToInstantApps(params, isExternalProtocol, incomingIntentRedirect)) { if (handleCCTRedirectsToInstantApps(params, isExternalProtocol, incomingIntentRedirect)) {
...@@ -474,13 +489,6 @@ public class ExternalNavigationHandler { ...@@ -474,13 +489,6 @@ public class ExternalNavigationHandler {
if (isYoutubePairingCode(params)) return OverrideUrlLoadingResult.NO_OVERRIDE; if (isYoutubePairingCode(params)) return OverrideUrlLoadingResult.NO_OVERRIDE;
// TODO(changwan): check if we need to handle URL even when external intent is off.
if (CommandLine.getInstance().hasSwitch(
ChromeSwitches.DISABLE_EXTERNAL_INTENT_REQUESTS)) {
Log.w(TAG, "External intent handling is disabled by a command-line flag.");
return OverrideUrlLoadingResult.NO_OVERRIDE;
}
// http://crbug.com/647569 : Stay in a PWA window for a URL within the same scope. // http://crbug.com/647569 : Stay in a PWA window for a URL within the same scope.
@WebappScopePolicy.NavigationDirective @WebappScopePolicy.NavigationDirective
int webappScopePolicyDirective = mDelegate.applyWebappScopePolicyForUrl(params.getUrl()); int webappScopePolicyDirective = mDelegate.applyWebappScopePolicyForUrl(params.getUrl());
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment