Chromium Code Reviews| Index: chrome/android/java/src/org/chromium/chrome/browser/externalnav/ExternalNavigationHandler.java |
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/externalnav/ExternalNavigationHandler.java b/chrome/android/java/src/org/chromium/chrome/browser/externalnav/ExternalNavigationHandler.java |
| index 12df01599ab826178c9058edf669d472ec2cf0a3..e159c91f33872c017d128a996c6640d2faeecdb3 100644 |
| --- a/chrome/android/java/src/org/chromium/chrome/browser/externalnav/ExternalNavigationHandler.java |
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/externalnav/ExternalNavigationHandler.java |
| @@ -108,13 +108,38 @@ public class ExternalNavigationHandler { |
| return OverrideUrlLoadingResult.NO_OVERRIDE; |
| } |
| - // http://crbug/331571 : Do not override a navigation started from user typing. |
| - // http://crbug/424029 : Need to stay in Chrome for an intent heading explicitly to Chrome. |
| - if (params.getRedirectHandler() != null |
| - && params.getRedirectHandler().shouldStayInChrome()) { |
| + Intent intent; |
| + // perform generic parsing of the URI to turn it into an Intent. |
| + try { |
| + intent = Intent.parseUri(params.getUrl(), Intent.URI_INTENT_SCHEME); |
| + } catch (URISyntaxException ex) { |
| + Log.w(TAG, "Bad URI " + params.getUrl() + ": " + ex.getMessage()); |
| return OverrideUrlLoadingResult.NO_OVERRIDE; |
| } |
| + boolean hasBrowserFallbackUrl = false; |
| + String browserFallbackUrl = intent.getStringExtra(EXTRA_BROWSER_FALLBACK_URL); |
| + if (browserFallbackUrl != null |
| + && UrlUtilities.isValidForIntentFallbackNavigation(browserFallbackUrl)) { |
| + hasBrowserFallbackUrl = true; |
| + } |
| + |
| + if (params.getRedirectHandler() != null) { |
| + // http://crbug/331571 : Do not override a navigation started from user typing. |
| + // http://crbug/424029 : Need to stay in Chrome for an intent heading explicitly to |
| + // Chrome. |
| + if (params.getRedirectHandler().shouldStayInChrome()) { |
| + if (hasBrowserFallbackUrl) { |
| + return clobberCurrentTabWithFallbackUrl(browserFallbackUrl, params); |
| + } else { |
| + return OverrideUrlLoadingResult.NO_OVERRIDE; |
| + } |
| + } else if (params.getRedirectHandler().shouldNotOverrideUrlLoading()) { |
| + // For instance, if this is a chained fallback URL, we ignore it. |
| + return OverrideUrlLoadingResult.NO_OVERRIDE; |
| + } |
| + } |
| + |
| // 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 |
| // below). |
| @@ -148,10 +173,9 @@ public class ExternalNavigationHandler { |
| if (params.getUrl().startsWith(SCHEME_WTAI_MC)) { |
| // wtai://wp/mc;number |
| // number=string(phone-number) |
| - Intent intent = new Intent(Intent.ACTION_VIEW, |
| + mDelegate.startActivity(new Intent(Intent.ACTION_VIEW, |
| Uri.parse(WebView.SCHEME_TEL |
| - + params.getUrl().substring(SCHEME_WTAI_MC.length()))); |
| - mDelegate.startActivity(intent); |
| + + params.getUrl().substring(SCHEME_WTAI_MC.length())))); |
| return OverrideUrlLoadingResult.OVERRIDE_WITH_EXTERNAL_INTENT; |
| } else if (params.getUrl().startsWith(SCHEME_WTAI)) { |
| // TODO: handle other WTAI schemes. |
| @@ -183,36 +207,11 @@ public class ExternalNavigationHandler { |
| return OverrideUrlLoadingResult.NO_OVERRIDE; |
| } |
| - Intent intent; |
| - // perform generic parsing of the URI to turn it into an Intent. |
| - try { |
| - intent = Intent.parseUri(params.getUrl(), Intent.URI_INTENT_SCHEME); |
| - } catch (URISyntaxException ex) { |
| - Log.w(TAG, "Bad URI " + params.getUrl() + ": " + ex.getMessage()); |
| - return OverrideUrlLoadingResult.NO_OVERRIDE; |
| - } |
| - |
| - boolean hasBrowserFallbackUrl = false; |
| - String browserFallbackUrl = intent.getStringExtra(EXTRA_BROWSER_FALLBACK_URL); |
| - if (browserFallbackUrl != null |
| - && UrlUtilities.isValidForIntentFallbackNavigation(browserFallbackUrl)) { |
| - hasBrowserFallbackUrl = true; |
| - } |
| - |
| // check whether the intent can be resolved. If not, we will see |
| // whether we can download it from the Market. |
| if (!mDelegate.canResolveActivity(intent)) { |
| if (hasBrowserFallbackUrl) { |
| - // NOTE: any further redirection from fall-back URL should not override URL loading. |
| - // Otherwise, it can be used in chain for fingerprinting multiple app installation |
| - // status in one shot. In order to prevent this scenario, we notify redirection |
| - // handler that redirection from the current navigation should stay in Chrome. |
| - if (params.getRedirectHandler() != null) { |
| - params.getRedirectHandler() |
| - .setShouldStayInChromeUntilNewUrlLoading(); |
| - } |
| - return mDelegate.clobberCurrentTab(browserFallbackUrl, params.getReferrerUrl(), |
| - params.getTab()); |
| + return clobberCurrentTabWithFallbackUrl(browserFallbackUrl, params); |
| } |
| String packagename = intent.getPackage(); |
| if (packagename != null) { |
| @@ -339,6 +338,27 @@ public class ExternalNavigationHandler { |
| } |
| /** |
| + * Clobber the current tab with fallback URL. |
| + * |
| + * @param browserFallbackUrl The fallback URL. |
| + * @param params The external navigation params. |
| + * @return {@link OverrideUrlLoadingResult} (if the tab was clobbered, or we launched an |
| + *intent.) |
|
Maria
2015/03/27 00:12:59
indent 8 on second line and don't need parenthesis
Changwan Ryu
2015/03/27 02:09:50
Done.
|
| + */ |
| + private OverrideUrlLoadingResult clobberCurrentTabWithFallbackUrl( |
| + String browserFallbackUrl, ExternalNavigationParams params) { |
| + // NOTE: any further redirection from fall-back URL should not override URL loading. |
| + // Otherwise, it can be used in chain for fingerprinting multiple app installation |
| + // status in one shot. In order to prevent this scenario, we notify redirection |
| + // handler that redirection from the current navigation should stay in Chrome. |
| + if (params.getRedirectHandler() != null) { |
| + params.getRedirectHandler().setShouldNotOverrideUrlLoadingUntilNewUrlLoading(); |
| + } |
| + return mDelegate.clobberCurrentTab( |
| + browserFallbackUrl, params.getReferrerUrl(), params.getTab()); |
| + } |
| + |
| + /** |
| * @return Whether the |url| could be handled by an external application on the system. |
| */ |
| public boolean canExternalAppHandleUrl(String url) { |