Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(47)

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/tab/InterceptNavigationDelegateImpl.java

Issue 1636573004: Dont cache activity for external navigation handling (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Nit Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.chrome.browser.tab; 5 package org.chromium.chrome.browser.tab;
6 6
7 import org.chromium.base.VisibleForTesting; 7 import org.chromium.base.VisibleForTesting;
8 import org.chromium.chrome.R; 8 import org.chromium.chrome.R;
9 import org.chromium.chrome.browser.ChromeActivity;
10 import org.chromium.chrome.browser.ChromeApplication; 9 import org.chromium.chrome.browser.ChromeApplication;
11 import org.chromium.chrome.browser.datausage.DataUseTabUIManager; 10 import org.chromium.chrome.browser.datausage.DataUseTabUIManager;
12 import org.chromium.chrome.browser.externalnav.ExternalNavigationHandler; 11 import org.chromium.chrome.browser.externalnav.ExternalNavigationHandler;
13 import org.chromium.chrome.browser.externalnav.ExternalNavigationHandler.Overrid eUrlLoadingResult; 12 import org.chromium.chrome.browser.externalnav.ExternalNavigationHandler.Overrid eUrlLoadingResult;
14 import org.chromium.chrome.browser.externalnav.ExternalNavigationParams; 13 import org.chromium.chrome.browser.externalnav.ExternalNavigationParams;
15 import org.chromium.chrome.browser.tabmodel.TabModel.TabLaunchType; 14 import org.chromium.chrome.browser.tabmodel.TabModel.TabLaunchType;
16 import org.chromium.components.navigation_interception.InterceptNavigationDelega te; 15 import org.chromium.components.navigation_interception.InterceptNavigationDelega te;
17 import org.chromium.components.navigation_interception.NavigationParams; 16 import org.chromium.components.navigation_interception.NavigationParams;
18 import org.chromium.content_public.browser.NavigationController; 17 import org.chromium.content_public.browser.NavigationController;
19 import org.chromium.content_public.browser.WebContents; 18 import org.chromium.content_public.browser.WebContents;
20 import org.chromium.content_public.common.ConsoleMessageLevel; 19 import org.chromium.content_public.common.ConsoleMessageLevel;
21 20
22 /** 21 /**
23 * Class that controls navigations and allows to intercept them. It is used on A ndroid to 'convert' 22 * Class that controls navigations and allows to intercept them. It is used on A ndroid to 'convert'
24 * certain navigations to Intents to 3rd party applications and to "pause" navig ations when data use 23 * certain navigations to Intents to 3rd party applications and to "pause" navig ations when data use
25 * tracking has ended. 24 * tracking has ended.
26 */ 25 */
27 public class InterceptNavigationDelegateImpl implements InterceptNavigationDeleg ate { 26 public class InterceptNavigationDelegateImpl implements InterceptNavigationDeleg ate {
28 private final ChromeActivity mActivity;
29 private final Tab mTab; 27 private final Tab mTab;
30 private final ExternalNavigationHandler mExternalNavHandler; 28 private final ExternalNavigationHandler mExternalNavHandler;
31 private final AuthenticatorNavigationInterceptor mAuthenticatorHelper; 29 private final AuthenticatorNavigationInterceptor mAuthenticatorHelper;
32 private ExternalNavigationHandler.OverrideUrlLoadingResult mLastOverrideUrlL oadingResult = 30 private ExternalNavigationHandler.OverrideUrlLoadingResult mLastOverrideUrlL oadingResult =
33 ExternalNavigationHandler.OverrideUrlLoadingResult.NO_OVERRIDE; 31 ExternalNavigationHandler.OverrideUrlLoadingResult.NO_OVERRIDE;
34 32
35 /** 33 /**
36 * Whether forward history should be cleared after navigation is committed. 34 * Whether forward history should be cleared after navigation is committed.
37 */ 35 */
38 private boolean mClearAllForwardHistoryRequired; 36 private boolean mClearAllForwardHistoryRequired;
39 private boolean mShouldClearRedirectHistoryForTabClobbering; 37 private boolean mShouldClearRedirectHistoryForTabClobbering;
40 38
41 /** 39 /**
42 * Default constructor of {@link InterceptNavigationDelegateImpl}. 40 * Default constructor of {@link InterceptNavigationDelegateImpl}.
43 */ 41 */
44 public InterceptNavigationDelegateImpl(ChromeActivity activity, Tab tab) { 42 public InterceptNavigationDelegateImpl(Tab tab) {
45 this(new ExternalNavigationHandler(activity), activity, tab); 43 this(new ExternalNavigationHandler(tab), tab);
46 } 44 }
47 45
48 /** 46 /**
49 * Constructs a new instance of {@link InterceptNavigationDelegateImpl} with the given 47 * Constructs a new instance of {@link InterceptNavigationDelegateImpl} with the given
50 * {@link ExternalNavigationHandler}. 48 * {@link ExternalNavigationHandler}.
51 */ 49 */
52 public InterceptNavigationDelegateImpl(ExternalNavigationHandler externalNav Handler, 50 public InterceptNavigationDelegateImpl(ExternalNavigationHandler externalNav Handler, Tab tab) {
53 ChromeActivity activity, Tab tab) {
54 mActivity = activity;
55 mTab = tab; 51 mTab = tab;
56 mExternalNavHandler = externalNavHandler; 52 mExternalNavHandler = externalNavHandler;
57 mAuthenticatorHelper = ((ChromeApplication) mTab.getApplicationContext() ) 53 mAuthenticatorHelper = ((ChromeApplication) mTab.getApplicationContext() )
58 .createAuthenticatorNavigationInterceptor(mTab); 54 .createAuthenticatorNavigationInterceptor(mTab);
59 } 55 }
60 56
61 public boolean shouldIgnoreNewTab(String url, boolean incognito) { 57 public boolean shouldIgnoreNewTab(String url, boolean incognito) {
62 if (mAuthenticatorHelper != null && mAuthenticatorHelper.handleAuthentic atorUrl(url)) { 58 if (mAuthenticatorHelper != null && mAuthenticatorHelper.handleAuthentic atorUrl(url)) {
63 return true; 59 return true;
64 } 60 }
(...skipping 16 matching lines...) Expand all
81 String url = navigationParams.url; 77 String url = navigationParams.url;
82 78
83 if (mAuthenticatorHelper != null && mAuthenticatorHelper.handleAuthentic atorUrl(url)) { 79 if (mAuthenticatorHelper != null && mAuthenticatorHelper.handleAuthentic atorUrl(url)) {
84 return true; 80 return true;
85 } 81 }
86 82
87 TabRedirectHandler tabRedirectHandler = mTab.getTabRedirectHandler(); 83 TabRedirectHandler tabRedirectHandler = mTab.getTabRedirectHandler();
88 tabRedirectHandler.updateNewUrlLoading(navigationParams.pageTransitionTy pe, 84 tabRedirectHandler.updateNewUrlLoading(navigationParams.pageTransitionTy pe,
89 navigationParams.isRedirect, 85 navigationParams.isRedirect,
90 navigationParams.hasUserGesture || navigationParams.hasUserGestu reCarryover, 86 navigationParams.hasUserGesture || navigationParams.hasUserGestu reCarryover,
91 mActivity.getLastUserInteractionTime(), getLastCommittedEntryInd ex()); 87 mTab.getActivity().getLastUserInteractionTime(), getLastCommitte dEntryIndex());
92 boolean shouldCloseTab = shouldCloseContentsOnOverrideUrlLoadingAndLaunc hIntent(); 88 boolean shouldCloseTab = shouldCloseContentsOnOverrideUrlLoadingAndLaunc hIntent();
93 boolean isInitialTabLaunchInBackground = 89 boolean isInitialTabLaunchInBackground =
94 mTab.getLaunchType() == TabLaunchType.FROM_LONGPRESS_BACKGROUND && shouldCloseTab; 90 mTab.getLaunchType() == TabLaunchType.FROM_LONGPRESS_BACKGROUND && shouldCloseTab;
95 // http://crbug.com/448977: If a new tab is closed by this overriding, w e should open an 91 // http://crbug.com/448977: If a new tab is closed by this overriding, w e should open an
96 // Intent in a new tab when Chrome receives it again. 92 // Intent in a new tab when Chrome receives it again.
97 ExternalNavigationParams params = new ExternalNavigationParams.Builder( 93 ExternalNavigationParams params = new ExternalNavigationParams.Builder(
98 url, mTab.isIncognito(), navigationParams.referrer, 94 url, mTab.isIncognito(), navigationParams.referrer,
99 navigationParams.pageTransitionType, 95 navigationParams.pageTransitionType,
100 navigationParams.isRedirect) 96 navigationParams.isRedirect)
101 .setTab(mTab) 97 .setTab(mTab)
(...skipping 22 matching lines...) Expand all
124 if (!shouldCloseTab && navigationParams.isMainFrame) { 120 if (!shouldCloseTab && navigationParams.isMainFrame) {
125 onOverrideUrlLoadingAndLaunchIntent(); 121 onOverrideUrlLoadingAndLaunchIntent();
126 } 122 }
127 return true; 123 return true;
128 case NO_OVERRIDE: 124 case NO_OVERRIDE:
129 default: 125 default:
130 if (navigationParams.isExternalProtocol) { 126 if (navigationParams.isExternalProtocol) {
131 logBlockedNavigationToDevToolsConsole(url); 127 logBlockedNavigationToDevToolsConsole(url);
132 return true; 128 return true;
133 } 129 }
134 return DataUseTabUIManager.shouldOverrideUrlLoading(mActivity, m Tab, url, 130 return DataUseTabUIManager.shouldOverrideUrlLoading(mTab.getActi vity(), mTab, url,
135 navigationParams.pageTransitionType, navigationParams.re ferrer); 131 navigationParams.pageTransitionType, navigationParams.re ferrer);
136 } 132 }
137 } 133 }
138 134
139 /** 135 /**
140 * Updates navigation history if navigation is canceled due to intent handle r. We go back to the 136 * Updates navigation history if navigation is canceled due to intent handle r. We go back to the
141 * last committed entry index which was saved before the navigation, and rem ove the empty 137 * last committed entry index which was saved before the navigation, and rem ove the empty
142 * entries from the navigation history. See crbug.com/426679 138 * entries from the navigation history. See crbug.com/426679
143 */ 139 */
144 public void maybeUpdateNavigationHistory() { 140 public void maybeUpdateNavigationHistory() {
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 198
203 // Before leaving Chrome, close the empty child tab. 199 // Before leaving Chrome, close the empty child tab.
204 // If a new tab is created through JavaScript open to load this 200 // If a new tab is created through JavaScript open to load this
205 // url, we would like to close it as we will load this url in a 201 // url, we would like to close it as we will load this url in a
206 // different Activity. 202 // different Activity.
207 if (shouldCloseContentsOnOverrideUrlLoadingAndLaunchIntent()) { 203 if (shouldCloseContentsOnOverrideUrlLoadingAndLaunchIntent()) {
208 if (mTab.getLaunchType() == TabLaunchType.FROM_EXTERNAL_APP) { 204 if (mTab.getLaunchType() == TabLaunchType.FROM_EXTERNAL_APP) {
209 // Moving task back before closing the tab allows back button to function better 205 // Moving task back before closing the tab allows back button to function better
210 // when Chrome was an intermediate link redirector between two a pps. 206 // when Chrome was an intermediate link redirector between two a pps.
211 // crbug.com/487938. 207 // crbug.com/487938.
212 mActivity.moveTaskToBack(true); 208 mTab.getActivity().moveTaskToBack(true);
213 } 209 }
214 mActivity.getTabModelSelector().closeTab(mTab); 210 mTab.getTabModelSelector().closeTab(mTab);
215 } else if (mTab.getTabRedirectHandler().isOnNavigation()) { 211 } else if (mTab.getTabRedirectHandler().isOnNavigation()) {
216 int lastCommittedEntryIndexBeforeNavigation = mTab.getTabRedirectHan dler() 212 int lastCommittedEntryIndexBeforeNavigation = mTab.getTabRedirectHan dler()
217 .getLastCommittedEntryIndexBeforeStartingNavigation(); 213 .getLastCommittedEntryIndexBeforeStartingNavigation();
218 if (getLastCommittedEntryIndex() > lastCommittedEntryIndexBeforeNavi gation) { 214 if (getLastCommittedEntryIndex() > lastCommittedEntryIndexBeforeNavi gation) {
219 // http://crbug/426679 : we want to go back to the last committe d entry index which 215 // http://crbug/426679 : we want to go back to the last committe d entry index which
220 // was saved before this navigation, and remove the empty entrie s from the 216 // was saved before this navigation, and remove the empty entrie s from the
221 // navigation history. 217 // navigation history.
222 mClearAllForwardHistoryRequired = true; 218 mClearAllForwardHistoryRequired = true;
223 mTab.getWebContents().getNavigationController().goToNavigationIn dex( 219 mTab.getWebContents().getNavigationController().goToNavigationIn dex(
224 lastCommittedEntryIndexBeforeNavigation); 220 lastCommittedEntryIndexBeforeNavigation);
225 } 221 }
226 } 222 }
227 } 223 }
228 224
229 private void logBlockedNavigationToDevToolsConsole(String url) { 225 private void logBlockedNavigationToDevToolsConsole(String url) {
230 int resId = mExternalNavHandler.canExternalAppHandleUrl(url) 226 int resId = mExternalNavHandler.canExternalAppHandleUrl(url)
231 ? R.string.blocked_navigation_warning 227 ? R.string.blocked_navigation_warning
232 : R.string.unreachable_navigation_warning; 228 : R.string.unreachable_navigation_warning;
233 mTab.getWebContents().addMessageToDevToolsConsole( 229 mTab.getWebContents().addMessageToDevToolsConsole(
234 ConsoleMessageLevel.WARNING, mTab.getApplicationContext().getStr ing(resId, url)); 230 ConsoleMessageLevel.WARNING, mTab.getApplicationContext().getStr ing(resId, url));
235 } 231 }
236 } 232 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698