| OLD | NEW |
| 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.document; | 5 package org.chromium.chrome.browser.document; |
| 6 | 6 |
| 7 import android.annotation.SuppressLint; | 7 import android.annotation.SuppressLint; |
| 8 import android.annotation.TargetApi; | 8 import android.annotation.TargetApi; |
| 9 import android.app.Activity; | 9 import android.app.Activity; |
| 10 import android.app.ActivityManager; | 10 import android.app.ActivityManager; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 import org.chromium.chrome.browser.ChromeApplication; | 32 import org.chromium.chrome.browser.ChromeApplication; |
| 33 import org.chromium.chrome.browser.ChromeTabbedActivity; | 33 import org.chromium.chrome.browser.ChromeTabbedActivity; |
| 34 import org.chromium.chrome.browser.IntentHandler; | 34 import org.chromium.chrome.browser.IntentHandler; |
| 35 import org.chromium.chrome.browser.IntentHandler.TabOpenType; | 35 import org.chromium.chrome.browser.IntentHandler.TabOpenType; |
| 36 import org.chromium.chrome.browser.ShortcutHelper; | 36 import org.chromium.chrome.browser.ShortcutHelper; |
| 37 import org.chromium.chrome.browser.ShortcutSource; | 37 import org.chromium.chrome.browser.ShortcutSource; |
| 38 import org.chromium.chrome.browser.UrlConstants; | 38 import org.chromium.chrome.browser.UrlConstants; |
| 39 import org.chromium.chrome.browser.WarmupManager; | 39 import org.chromium.chrome.browser.WarmupManager; |
| 40 import org.chromium.chrome.browser.WebappAuthenticator; | 40 import org.chromium.chrome.browser.WebappAuthenticator; |
| 41 import org.chromium.chrome.browser.customtabs.CustomTabActivity; | 41 import org.chromium.chrome.browser.customtabs.CustomTabActivity; |
| 42 import org.chromium.chrome.browser.externalnav.IntentWithGesturesHandler; |
| 42 import org.chromium.chrome.browser.firstrun.FirstRunFlowSequencer; | 43 import org.chromium.chrome.browser.firstrun.FirstRunFlowSequencer; |
| 43 import org.chromium.chrome.browser.metrics.LaunchHistogram; | 44 import org.chromium.chrome.browser.metrics.LaunchHistogram; |
| 44 import org.chromium.chrome.browser.metrics.LaunchMetrics; | 45 import org.chromium.chrome.browser.metrics.LaunchMetrics; |
| 45 import org.chromium.chrome.browser.multiwindow.MultiWindowUtils; | 46 import org.chromium.chrome.browser.multiwindow.MultiWindowUtils; |
| 46 import org.chromium.chrome.browser.notifications.NotificationUIManager; | 47 import org.chromium.chrome.browser.notifications.NotificationUIManager; |
| 47 import org.chromium.chrome.browser.partnercustomizations.HomepageManager; | 48 import org.chromium.chrome.browser.partnercustomizations.HomepageManager; |
| 48 import org.chromium.chrome.browser.partnercustomizations.PartnerBrowserCustomiza
tions; | 49 import org.chromium.chrome.browser.partnercustomizations.PartnerBrowserCustomiza
tions; |
| 49 import org.chromium.chrome.browser.preferences.ChromePreferenceManager; | 50 import org.chromium.chrome.browser.preferences.ChromePreferenceManager; |
| 50 import org.chromium.chrome.browser.preferences.DocumentModeManager; | 51 import org.chromium.chrome.browser.preferences.DocumentModeManager; |
| 51 import org.chromium.chrome.browser.tab.Tab; | 52 import org.chromium.chrome.browser.tab.Tab; |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 } | 248 } |
| 248 | 249 |
| 249 @Override | 250 @Override |
| 250 public void processWebSearchIntent(String query) { | 251 public void processWebSearchIntent(String query) { |
| 251 assert false; | 252 assert false; |
| 252 } | 253 } |
| 253 | 254 |
| 254 @Override | 255 @Override |
| 255 public void processUrlViewIntent(String url, String referer, String headers, | 256 public void processUrlViewIntent(String url, String referer, String headers, |
| 256 IntentHandler.TabOpenType tabOpenType, String externalAppId, | 257 IntentHandler.TabOpenType tabOpenType, String externalAppId, |
| 257 int tabIdToBringToFront, Intent intent) { | 258 int tabIdToBringToFront, boolean hasUserGesture, Intent intent) { |
| 258 assert false; | 259 assert false; |
| 259 } | 260 } |
| 260 | 261 |
| 261 /** | 262 /** |
| 262 * Handles launching a {@link CustomTabActivity}, which will sit on top of a
client's activity | 263 * Handles launching a {@link CustomTabActivity}, which will sit on top of a
client's activity |
| 263 * in the same task. | 264 * in the same task. |
| 264 * @return True if the intent is handled here. | 265 * @return True if the intent is handled here. |
| 265 */ | 266 */ |
| 266 private boolean handleCustomTabActivityIntent() { | 267 private boolean handleCustomTabActivityIntent() { |
| 267 if (getIntent() == null || !getIntent().hasExtra(CustomTabsIntent.EXTRA_
SESSION)) { | 268 if (getIntent() == null || !getIntent().hasExtra(CustomTabsIntent.EXTRA_
SESSION)) { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 293 @TargetApi(Build.VERSION_CODES.LOLLIPOP) | 294 @TargetApi(Build.VERSION_CODES.LOLLIPOP) |
| 294 private void handleDocumentActivityIntent() { | 295 private void handleDocumentActivityIntent() { |
| 295 if (getIntent() == null || mIntentHandler.shouldIgnoreIntent(this, getIn
tent())) { | 296 if (getIntent() == null || mIntentHandler.shouldIgnoreIntent(this, getIn
tent())) { |
| 296 Log.e(TAG, "Ignoring intent: " + getIntent()); | 297 Log.e(TAG, "Ignoring intent: " + getIntent()); |
| 297 mIsFinishNeeded = true; | 298 mIsFinishNeeded = true; |
| 298 return; | 299 return; |
| 299 } | 300 } |
| 300 | 301 |
| 301 maybePrefetchDnsInBackground(); | 302 maybePrefetchDnsInBackground(); |
| 302 | 303 |
| 304 boolean hasUserGesture = |
| 305 IntentWithGesturesHandler.getInstance().getUserGestureAndClear(g
etIntent()); |
| 306 |
| 303 // Increment the Tab ID counter at this point since this Activity may no
t appear in | 307 // Increment the Tab ID counter at this point since this Activity may no
t appear in |
| 304 // getAppTasks() when DocumentTabModelSelector is initialized. This can
potentially happen | 308 // getAppTasks() when DocumentTabModelSelector is initialized. This can
potentially happen |
| 305 // when Chrome is launched via the GSA/e200 search box and they relinqui
sh their task. | 309 // when Chrome is launched via the GSA/e200 search box and they relinqui
sh their task. |
| 306 TabIdManager.getInstance().incrementIdCounterTo(getTaskId() + 1); | 310 TabIdManager.getInstance().incrementIdCounterTo(getTaskId() + 1); |
| 307 | 311 |
| 308 // Handle MAIN Intent actions, usually fired when the user starts Chrome
via the launcher. | 312 // Handle MAIN Intent actions, usually fired when the user starts Chrome
via the launcher. |
| 309 // Some launchers start Chrome by firing a VIEW Intent with an empty URL
(crbug.com/459349); | 313 // Some launchers start Chrome by firing a VIEW Intent with an empty URL
(crbug.com/459349); |
| 310 // treat it as a MAIN Intent. | 314 // treat it as a MAIN Intent. |
| 311 String url = IntentHandler.getUrlFromIntent(getIntent()); | 315 String url = IntentHandler.getUrlFromIntent(getIntent()); |
| 312 if ((url == null && TextUtils.equals(getIntent().getAction(), Intent.ACT
ION_VIEW)) | 316 if ((url == null && TextUtils.equals(getIntent().getAction(), Intent.ACT
ION_VIEW)) |
| 313 || TextUtils.equals(getIntent().getAction(), Intent.ACTION_MAIN)
) { | 317 || TextUtils.equals(getIntent().getAction(), Intent.ACTION_MAIN)
) { |
| 314 handleMainDocumentIntent(); | 318 handleMainDocumentIntent(); |
| 315 return; | 319 return; |
| 316 } | 320 } |
| 317 | 321 |
| 318 // Sometimes an Intent requests that the current Document get clobbered. | 322 // Sometimes an Intent requests that the current Document get clobbered. |
| 319 if (clobberCurrentDocument(url)) return; | 323 if (clobberCurrentDocument(url, hasUserGesture)) return; |
| 320 | 324 |
| 321 // Try to retarget existing Documents before creating a new one. | 325 // Try to retarget existing Documents before creating a new one. |
| 322 boolean incognito = IntentUtils.safeGetBooleanExtra(getIntent(), | 326 boolean incognito = IntentUtils.safeGetBooleanExtra(getIntent(), |
| 323 IntentHandler.EXTRA_OPEN_NEW_INCOGNITO_TAB, false); | 327 IntentHandler.EXTRA_OPEN_NEW_INCOGNITO_TAB, false); |
| 324 boolean append = IntentUtils.safeGetBooleanExtra( | 328 boolean append = IntentUtils.safeGetBooleanExtra( |
| 325 getIntent(), IntentHandler.EXTRA_APPEND_TASK, false); | 329 getIntent(), IntentHandler.EXTRA_APPEND_TASK, false); |
| 326 boolean reuse = IntentUtils.safeGetBooleanExtra( | 330 boolean reuse = IntentUtils.safeGetBooleanExtra( |
| 327 getIntent(), BookmarkUtils.REUSE_URL_MATCHING_TAB_ELSE_NEW_TAB,
false); | 331 getIntent(), BookmarkUtils.REUSE_URL_MATCHING_TAB_ELSE_NEW_TAB,
false); |
| 328 boolean affiliated = IntentUtils.safeGetBooleanExtra( | 332 boolean affiliated = IntentUtils.safeGetBooleanExtra( |
| 329 getIntent(), IntentHandler.EXTRA_OPEN_IN_BG, false); | 333 getIntent(), IntentHandler.EXTRA_OPEN_IN_BG, false); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 379 launchDocumentInstance(ChromeLauncherActivity.this, false, async
Params); | 383 launchDocumentInstance(ChromeLauncherActivity.this, false, async
Params); |
| 380 | 384 |
| 381 if (mIsFinishNeeded) finish(); | 385 if (mIsFinishNeeded) finish(); |
| 382 } | 386 } |
| 383 }, INITIAL_DOCUMENT_ACTIVITY_LAUNCH_TIMEOUT_MS); | 387 }, INITIAL_DOCUMENT_ACTIVITY_LAUNCH_TIMEOUT_MS); |
| 384 } | 388 } |
| 385 | 389 |
| 386 /** | 390 /** |
| 387 * If necessary, attempts to clobber the current DocumentActivity's tab with
the given URL. | 391 * If necessary, attempts to clobber the current DocumentActivity's tab with
the given URL. |
| 388 * @param url URL to display. | 392 * @param url URL to display. |
| 393 * @param hasUserGesture Whether the intent is launched from a previous user
gesture. |
| 389 * @return Whether or not the clobber was successful. | 394 * @return Whether or not the clobber was successful. |
| 390 */ | 395 */ |
| 391 private boolean clobberCurrentDocument(String url) { | 396 private boolean clobberCurrentDocument(String url, boolean hasUserGesture) { |
| 392 boolean shouldOpenNewTab = IntentUtils.safeGetBooleanExtra( | 397 boolean shouldOpenNewTab = IntentUtils.safeGetBooleanExtra( |
| 393 getIntent(), Browser.EXTRA_CREATE_NEW_TAB, false); | 398 getIntent(), Browser.EXTRA_CREATE_NEW_TAB, false); |
| 394 String applicationId = | 399 String applicationId = |
| 395 IntentUtils.safeGetStringExtra(getIntent(), Browser.EXTRA_APPLIC
ATION_ID); | 400 IntentUtils.safeGetStringExtra(getIntent(), Browser.EXTRA_APPLIC
ATION_ID); |
| 396 if (shouldOpenNewTab || !getPackageName().equals(applicationId)) return
false; | 401 if (shouldOpenNewTab || !getPackageName().equals(applicationId)) return
false; |
| 397 | 402 |
| 398 // Check if there's a Tab that can be clobbered. | 403 // Check if there's a Tab that can be clobbered. |
| 399 int tabId = ChromeApplication.getDocumentTabModelSelector().getCurrentTa
bId(); | 404 int tabId = ChromeApplication.getDocumentTabModelSelector().getCurrentTa
bId(); |
| 400 if (tabId == Tab.INVALID_TAB_ID) return false; | 405 if (tabId == Tab.INVALID_TAB_ID) return false; |
| 401 | 406 |
| 402 // Try to clobber the page. | 407 // Try to clobber the page. |
| 408 LoadUrlParams params = new LoadUrlParams( |
| 409 url, PageTransition.LINK | PageTransition.FROM_API); |
| 410 params.setHasUserGesture(hasUserGesture); |
| 403 AsyncTabCreationParams data = | 411 AsyncTabCreationParams data = |
| 404 new AsyncTabCreationParams(new LoadUrlParams(url), new Intent(ge
tIntent())); | 412 new AsyncTabCreationParams(params, new Intent(getIntent())); |
| 405 AsyncTabCreationParamsManager.add(tabId, data); | 413 AsyncTabCreationParamsManager.add(tabId, data); |
| 406 if (!relaunchTask(tabId)) { | 414 if (!relaunchTask(tabId)) { |
| 407 // Were not able to clobber, will fall through to handle in a new do
cument. | 415 // Were not able to clobber, will fall through to handle in a new do
cument. |
| 408 AsyncTabCreationParamsManager.remove(tabId); | 416 AsyncTabCreationParamsManager.remove(tabId); |
| 409 return false; | 417 return false; |
| 410 } | 418 } |
| 411 | 419 |
| 412 return true; | 420 return true; |
| 413 } | 421 } |
| 414 | 422 |
| (...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 834 return true; | 842 return true; |
| 835 } | 843 } |
| 836 | 844 |
| 837 /** | 845 /** |
| 838 * Send the number of times an exception was caught when trying to move a ta
sk back to front. | 846 * Send the number of times an exception was caught when trying to move a ta
sk back to front. |
| 839 */ | 847 */ |
| 840 public static void sendExceptionCount() { | 848 public static void sendExceptionCount() { |
| 841 sMoveToFrontExceptionHistogram.commitHistogram(); | 849 sMoveToFrontExceptionHistogram.commitHistogram(); |
| 842 } | 850 } |
| 843 } | 851 } |
| OLD | NEW |