Commit 9d9a3a0f authored by Michael Thiessen's avatar Michael Thiessen Committed by Commit Bot

Make ShouldOverrideUrlLoadingInternal more readable (10 of 10)

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.

Bug: 1006927
Change-Id: Icd6c09563e577153829c8243758b8c98aff1b6c7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1837872
Commit-Queue: Michael Thiessen <mthiesse@chromium.org>
Reviewed-by: default avatarTed Choc <tedchoc@chromium.org>
Cr-Commit-Position: refs/heads/master@{#705190}
parent 72459deb
......@@ -669,6 +669,24 @@ public class ExternalNavigationHandler {
return OverrideUrlLoadingResult.NO_OVERRIDE;
}
/**
* If some third-party app launched Chrome with an intent, and the URL got redirected, and the
* user explicitly chose Chrome over other intent handlers, stay in Chrome unless there was a
* new intent handler after redirection or Chrome cannot handle it any more.
* Custom tabs are an exception to this rule, since at no point, the user sees an intent picker
* and "picking Chrome" is handled inside the support library.
*/
private boolean shouldKeepIntentRedirectInChrome(ExternalNavigationParams params,
boolean incomingIntentRedirect, Intent targetIntent, boolean isExternalProtocol) {
if (params.getRedirectHandler() != null && incomingIntentRedirect && !isExternalProtocol
&& !params.getRedirectHandler().isFromCustomTabIntent()
&& !params.getRedirectHandler().hasNewResolver(targetIntent)) {
if (DEBUG) Log.i(TAG, "Custom tab redirect no handled");
return true;
}
return false;
}
/**
* Returns whether the activity belongs to a WebAPK and the URL is within the scope of the
* WebAPK. The WebAPK's main activity is a bouncer that redirects to WebApkActivity in Chrome.
......@@ -689,6 +707,22 @@ public class ExternalNavigationHandler {
return false;
}
private boolean launchExternalIntent(Intent targetIntent, boolean shouldProxyForInstantApps) {
try {
if (!mDelegate.startActivityIfNeeded(targetIntent, shouldProxyForInstantApps)) {
if (DEBUG) Log.i(TAG, "The current Activity was the only targeted Activity.");
return false;
}
} catch (ActivityNotFoundException e) {
// The targeted app must have been uninstalled/disabled since we queried for Activities
// to handle this intent.
if (DEBUG) Log.i(TAG, "Activity not found.");
return false;
}
if (DEBUG) Log.i(TAG, "startActivityIfNeeded");
return true;
}
private @OverrideUrlLoadingResult int shouldOverrideUrlLoadingInternal(
ExternalNavigationParams params, Intent targetIntent,
@Nullable String browserFallbackUrl) {
......@@ -805,18 +839,9 @@ public class ExternalNavigationHandler {
targetIntent, params, browserFallbackUrl, shouldProxyForInstantApps);
}
// Some third-party app launched Chrome with an intent, and the URL got redirected. The
// user has explicitly chosen Chrome over other intent handlers, so stay in Chrome
// unless there was a new intent handler after redirection or Chrome cannot handle it
// any more.
// Custom tabs are an exception to this rule, since at no point, the user sees an intent
// picker and "picking Chrome" is handled inside the support library.
if (params.getRedirectHandler() != null && incomingIntentRedirect) {
if (!isExternalProtocol && !params.getRedirectHandler().isFromCustomTabIntent()
&& !params.getRedirectHandler().hasNewResolver(targetIntent)) {
if (DEBUG) Log.i(TAG, "Custom tab redirect no handled");
return OverrideUrlLoadingResult.NO_OVERRIDE;
}
if (shouldKeepIntentRedirectInChrome(
params, incomingIntentRedirect, targetIntent, isExternalProtocol)) {
return OverrideUrlLoadingResult.NO_OVERRIDE;
}
if (shouldStayInWebApkCCT(params, resolvingInfos)) {
......@@ -827,18 +852,9 @@ public class ExternalNavigationHandler {
} else if (launchWebApkIfSoleIntentHandler(resolvingInfos, targetIntent)) {
return OverrideUrlLoadingResult.OVERRIDE_WITH_EXTERNAL_INTENT;
}
try {
if (mDelegate.startActivityIfNeeded(targetIntent, shouldProxyForInstantApps)) {
// Assume the browser can handle it if there's no activity for this intent.
if (DEBUG) Log.i(TAG, "startActivityIfNeeded");
return OverrideUrlLoadingResult.OVERRIDE_WITH_EXTERNAL_INTENT;
}
} catch (ActivityNotFoundException e) {
if (DEBUG) Log.i(TAG, "Activity not found.");
return OverrideUrlLoadingResult.NO_OVERRIDE;
if (launchExternalIntent(targetIntent, shouldProxyForInstantApps)) {
return OverrideUrlLoadingResult.OVERRIDE_WITH_EXTERNAL_INTENT;
}
return OverrideUrlLoadingResult.NO_OVERRIDE;
}
......
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