Commit 1fbd0951 authored by jaekyun's avatar jaekyun Committed by Commit bot

Allow an Intent navigation even when a user types if a URL is server redirect...

Allow an Intent navigation even when a user types if a URL is server redirect and has an external protocol

BUG=487282

Review URL: https://codereview.chromium.org/1136443004

Cr-Commit-Position: refs/heads/master@{#329588}
parent ace586e7
......@@ -125,6 +125,13 @@ public class ExternalNavigationHandler {
boolean isFromIntent = (params.getPageTransition() & PageTransition.FROM_API) != 0;
boolean isForwardBackNavigation =
(params.getPageTransition() & PageTransition.FORWARD_BACK) != 0;
boolean isExternalProtocol = !UrlUtilities.isAcceptedScheme(params.getUrl());
// http://crbug.com/169549 : If you type in a URL that then redirects in server side to an
// link that cannot be rendered by the browser, we want to show the intent picker.
boolean isTyped = pageTransitionCore == PageTransition.TYPED;
boolean typedRedirectToExternalProtocol = isTyped && params.isRedirect()
&& isExternalProtocol;
// We do not want to show the intent picker for core types typed, bookmarks, auto toplevel,
// generated, keyword, keyword generated. See below for exception to typed URL and
......@@ -167,8 +174,14 @@ public class ExternalNavigationHandler {
// following a form submit.
boolean isRedirectFromFormSubmit = isFormSubmit && params.isRedirect();
if (!linkNotFromIntent && !incomingIntentRedirect && !isRedirectFromFormSubmit) {
return OverrideUrlLoadingResult.NO_OVERRIDE;
if (!typedRedirectToExternalProtocol) {
if (!linkNotFromIntent && !incomingIntentRedirect && !isRedirectFromFormSubmit) {
return OverrideUrlLoadingResult.NO_OVERRIDE;
}
if (params.getRedirectHandler() != null
&& params.getRedirectHandler().isNavigationFromUserTyping()) {
return OverrideUrlLoadingResult.NO_OVERRIDE;
}
}
// Don't override navigation from a chrome:* url to http or https. For example,
......@@ -270,7 +283,7 @@ public class ExternalNavigationHandler {
// Make sure webkit can handle it internally before checking for specialized
// handlers. If webkit can't handle it internally, we need to call
// startActivityIfNeeded or startActivity.
if (UrlUtilities.isAcceptedScheme(params.getUrl())) {
if (!isExternalProtocol) {
if (!mDelegate.isSpecializedHandlerAvailable(intent)) {
return OverrideUrlLoadingResult.NO_OVERRIDE;
} else if (params.getReferrerUrl() != null && isLink) {
......
......@@ -176,10 +176,16 @@ public class TabRedirectHandler {
*/
public boolean shouldStayInChrome() {
return mIsInitialIntentHeadingToChrome
|| mInitialNavigationType == NAVIGATION_TYPE_FROM_USER_TYPING
|| mInitialNavigationType == NAVIGATION_TYPE_FROM_LINK_WITHOUT_USER_GESTURE;
}
/**
* @return whether navigation is from a user's typing or not.
*/
public boolean isNavigationFromUserTyping() {
return mInitialNavigationType == NAVIGATION_TYPE_FROM_USER_TYPING;
}
/**
* @return whether we should stay in Chrome or not.
*/
......
......@@ -381,7 +381,7 @@ public class ExternalNavigationHandlerTest extends InstrumentationTestCase {
@SmallTest
public void testTypedRedirectToExternalProtocol() {
// http://crbug.com/331571 reverted http://crbug.com/169549
// http://crbug.com/169549
check("market://1234",
null, /* referrer */
false, /* incognito */
......@@ -390,8 +390,8 @@ public class ExternalNavigationHandlerTest extends InstrumentationTestCase {
true,
false,
null,
OverrideUrlLoadingResult.NO_OVERRIDE,
IGNORE);
OverrideUrlLoadingResult.OVERRIDE_WITH_EXTERNAL_INTENT,
START_ACTIVITY);
// http://crbug.com/143118
check("market://1234",
null, /* referrer */
......@@ -656,10 +656,10 @@ public class ExternalNavigationHandlerTest extends InstrumentationTestCase {
PageTransition.TYPED, NO_REDIRECT, true, false, redirectHandler,
OverrideUrlLoadingResult.NO_OVERRIDE, IGNORE);
redirectHandler.updateNewUrlLoading(PageTransition.TYPED, true, false, 0, 0);
redirectHandler.updateNewUrlLoading(PageTransition.LINK, false, false, 0, 0);
check(INTENT_URL_WITH_FALLBACK_URL_WITHOUT_PACKAGE_NAME, null, /* referrer */
false, /* incognito */
PageTransition.TYPED, REDIRECT, true, false, redirectHandler,
PageTransition.LINK, NO_REDIRECT, true, false, redirectHandler,
OverrideUrlLoadingResult.OVERRIDE_WITH_CLOBBERING_TAB, IGNORE);
// Now the user opens a link.
......
......@@ -213,12 +213,12 @@ public class TabRedirectHandlerTest extends InstrumentationTestCase {
TabRedirectHandler handler = new TabRedirectHandler(mContext);
handler.updateIntent(sYtIntent);
assertFalse(handler.isOnNavigation());
assertFalse(handler.shouldStayInChrome());
assertFalse(handler.isNavigationFromUserTyping());
handler.updateNewUrlLoading(PageTransition.TYPED, false, false, 0, 0);
assertTrue(handler.shouldStayInChrome());
assertTrue(handler.isNavigationFromUserTyping());
handler.updateNewUrlLoading(PageTransition.LINK, false, false, 0, 1);
assertTrue(handler.shouldStayInChrome());
assertTrue(handler.isNavigationFromUserTyping());
assertTrue(handler.isOnNavigation());
assertEquals(0, handler.getLastCommittedEntryIndexBeforeStartingNavigation());
......@@ -226,7 +226,7 @@ public class TabRedirectHandlerTest extends InstrumentationTestCase {
SystemClock.sleep(1);
handler.updateNewUrlLoading(
PageTransition.LINK, false, true, SystemClock.elapsedRealtime(), 2);
assertFalse(handler.shouldStayInChrome());
assertFalse(handler.isNavigationFromUserTyping());
assertTrue(handler.isOnNavigation());
assertEquals(2, handler.getLastCommittedEntryIndexBeforeStartingNavigation());
......
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