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 { ...@@ -125,6 +125,13 @@ public class ExternalNavigationHandler {
boolean isFromIntent = (params.getPageTransition() & PageTransition.FROM_API) != 0; boolean isFromIntent = (params.getPageTransition() & PageTransition.FROM_API) != 0;
boolean isForwardBackNavigation = boolean isForwardBackNavigation =
(params.getPageTransition() & PageTransition.FORWARD_BACK) != 0; (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, // 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 // generated, keyword, keyword generated. See below for exception to typed URL and
...@@ -167,9 +174,15 @@ public class ExternalNavigationHandler { ...@@ -167,9 +174,15 @@ public class ExternalNavigationHandler {
// following a form submit. // following a form submit.
boolean isRedirectFromFormSubmit = isFormSubmit && params.isRedirect(); boolean isRedirectFromFormSubmit = isFormSubmit && params.isRedirect();
if (!typedRedirectToExternalProtocol) {
if (!linkNotFromIntent && !incomingIntentRedirect && !isRedirectFromFormSubmit) { if (!linkNotFromIntent && !incomingIntentRedirect && !isRedirectFromFormSubmit) {
return OverrideUrlLoadingResult.NO_OVERRIDE; 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, // Don't override navigation from a chrome:* url to http or https. For example,
// when clicking a link in bookmarks or most visited. When navigating from such a // when clicking a link in bookmarks or most visited. When navigating from such a
...@@ -270,7 +283,7 @@ public class ExternalNavigationHandler { ...@@ -270,7 +283,7 @@ public class ExternalNavigationHandler {
// Make sure webkit can handle it internally before checking for specialized // Make sure webkit can handle it internally before checking for specialized
// handlers. If webkit can't handle it internally, we need to call // handlers. If webkit can't handle it internally, we need to call
// startActivityIfNeeded or startActivity. // startActivityIfNeeded or startActivity.
if (UrlUtilities.isAcceptedScheme(params.getUrl())) { if (!isExternalProtocol) {
if (!mDelegate.isSpecializedHandlerAvailable(intent)) { if (!mDelegate.isSpecializedHandlerAvailable(intent)) {
return OverrideUrlLoadingResult.NO_OVERRIDE; return OverrideUrlLoadingResult.NO_OVERRIDE;
} else if (params.getReferrerUrl() != null && isLink) { } else if (params.getReferrerUrl() != null && isLink) {
......
...@@ -176,10 +176,16 @@ public class TabRedirectHandler { ...@@ -176,10 +176,16 @@ public class TabRedirectHandler {
*/ */
public boolean shouldStayInChrome() { public boolean shouldStayInChrome() {
return mIsInitialIntentHeadingToChrome return mIsInitialIntentHeadingToChrome
|| mInitialNavigationType == NAVIGATION_TYPE_FROM_USER_TYPING
|| mInitialNavigationType == NAVIGATION_TYPE_FROM_LINK_WITHOUT_USER_GESTURE; || 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. * @return whether we should stay in Chrome or not.
*/ */
......
...@@ -381,7 +381,7 @@ public class ExternalNavigationHandlerTest extends InstrumentationTestCase { ...@@ -381,7 +381,7 @@ public class ExternalNavigationHandlerTest extends InstrumentationTestCase {
@SmallTest @SmallTest
public void testTypedRedirectToExternalProtocol() { public void testTypedRedirectToExternalProtocol() {
// http://crbug.com/331571 reverted http://crbug.com/169549 // http://crbug.com/169549
check("market://1234", check("market://1234",
null, /* referrer */ null, /* referrer */
false, /* incognito */ false, /* incognito */
...@@ -390,8 +390,8 @@ public class ExternalNavigationHandlerTest extends InstrumentationTestCase { ...@@ -390,8 +390,8 @@ public class ExternalNavigationHandlerTest extends InstrumentationTestCase {
true, true,
false, false,
null, null,
OverrideUrlLoadingResult.NO_OVERRIDE, OverrideUrlLoadingResult.OVERRIDE_WITH_EXTERNAL_INTENT,
IGNORE); START_ACTIVITY);
// http://crbug.com/143118 // http://crbug.com/143118
check("market://1234", check("market://1234",
null, /* referrer */ null, /* referrer */
...@@ -656,10 +656,10 @@ public class ExternalNavigationHandlerTest extends InstrumentationTestCase { ...@@ -656,10 +656,10 @@ public class ExternalNavigationHandlerTest extends InstrumentationTestCase {
PageTransition.TYPED, NO_REDIRECT, true, false, redirectHandler, PageTransition.TYPED, NO_REDIRECT, true, false, redirectHandler,
OverrideUrlLoadingResult.NO_OVERRIDE, IGNORE); 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 */ check(INTENT_URL_WITH_FALLBACK_URL_WITHOUT_PACKAGE_NAME, null, /* referrer */
false, /* incognito */ false, /* incognito */
PageTransition.TYPED, REDIRECT, true, false, redirectHandler, PageTransition.LINK, NO_REDIRECT, true, false, redirectHandler,
OverrideUrlLoadingResult.OVERRIDE_WITH_CLOBBERING_TAB, IGNORE); OverrideUrlLoadingResult.OVERRIDE_WITH_CLOBBERING_TAB, IGNORE);
// Now the user opens a link. // Now the user opens a link.
......
...@@ -213,12 +213,12 @@ public class TabRedirectHandlerTest extends InstrumentationTestCase { ...@@ -213,12 +213,12 @@ public class TabRedirectHandlerTest extends InstrumentationTestCase {
TabRedirectHandler handler = new TabRedirectHandler(mContext); TabRedirectHandler handler = new TabRedirectHandler(mContext);
handler.updateIntent(sYtIntent); handler.updateIntent(sYtIntent);
assertFalse(handler.isOnNavigation()); assertFalse(handler.isOnNavigation());
assertFalse(handler.shouldStayInChrome()); assertFalse(handler.isNavigationFromUserTyping());
handler.updateNewUrlLoading(PageTransition.TYPED, false, false, 0, 0); handler.updateNewUrlLoading(PageTransition.TYPED, false, false, 0, 0);
assertTrue(handler.shouldStayInChrome()); assertTrue(handler.isNavigationFromUserTyping());
handler.updateNewUrlLoading(PageTransition.LINK, false, false, 0, 1); handler.updateNewUrlLoading(PageTransition.LINK, false, false, 0, 1);
assertTrue(handler.shouldStayInChrome()); assertTrue(handler.isNavigationFromUserTyping());
assertTrue(handler.isOnNavigation()); assertTrue(handler.isOnNavigation());
assertEquals(0, handler.getLastCommittedEntryIndexBeforeStartingNavigation()); assertEquals(0, handler.getLastCommittedEntryIndexBeforeStartingNavigation());
...@@ -226,7 +226,7 @@ public class TabRedirectHandlerTest extends InstrumentationTestCase { ...@@ -226,7 +226,7 @@ public class TabRedirectHandlerTest extends InstrumentationTestCase {
SystemClock.sleep(1); SystemClock.sleep(1);
handler.updateNewUrlLoading( handler.updateNewUrlLoading(
PageTransition.LINK, false, true, SystemClock.elapsedRealtime(), 2); PageTransition.LINK, false, true, SystemClock.elapsedRealtime(), 2);
assertFalse(handler.shouldStayInChrome()); assertFalse(handler.isNavigationFromUserTyping());
assertTrue(handler.isOnNavigation()); assertTrue(handler.isOnNavigation());
assertEquals(2, handler.getLastCommittedEntryIndexBeforeStartingNavigation()); 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