| 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; |
| 11 import android.app.ActivityManager.AppTask; | 11 import android.app.ActivityManager.AppTask; |
| 12 import android.app.ActivityManager.RecentTaskInfo; | 12 import android.app.ActivityManager.RecentTaskInfo; |
| 13 import android.app.ActivityOptions; | 13 import android.app.ActivityOptions; |
| 14 import android.app.Notification; | 14 import android.app.Notification; |
| 15 import android.app.PendingIntent; | 15 import android.app.PendingIntent; |
| 16 import android.app.SearchManager; | 16 import android.app.SearchManager; |
| 17 import android.content.ClipData; | 17 import android.content.ClipData; |
| 18 import android.content.Context; | 18 import android.content.Context; |
| 19 import android.content.Intent; | 19 import android.content.Intent; |
| 20 import android.content.pm.PackageManager; | 20 import android.content.pm.PackageManager; |
| 21 import android.net.Uri; | 21 import android.net.Uri; |
| 22 import android.os.Build; | 22 import android.os.Build; |
| 23 import android.os.Bundle; | 23 import android.os.Bundle; |
| 24 import android.os.StrictMode; |
| 24 import android.os.TransactionTooLargeException; | 25 import android.os.TransactionTooLargeException; |
| 25 import android.provider.Browser; | 26 import android.provider.Browser; |
| 26 import android.support.customtabs.CustomTabsIntent; | 27 import android.support.customtabs.CustomTabsIntent; |
| 27 import android.text.TextUtils; | 28 import android.text.TextUtils; |
| 28 | 29 |
| 29 import org.chromium.base.ApiCompatibilityUtils; | 30 import org.chromium.base.ApiCompatibilityUtils; |
| 30 import org.chromium.base.ApplicationStatus; | 31 import org.chromium.base.ApplicationStatus; |
| 31 import org.chromium.base.CommandLineInitUtil; | 32 import org.chromium.base.CommandLineInitUtil; |
| 32 import org.chromium.base.Log; | 33 import org.chromium.base.Log; |
| 33 import org.chromium.base.TraceEvent; | 34 import org.chromium.base.TraceEvent; |
| 34 import org.chromium.chrome.browser.ChromeApplication; | 35 import org.chromium.chrome.browser.ChromeApplication; |
| 36 import org.chromium.chrome.browser.ChromeSwitches; |
| 35 import org.chromium.chrome.browser.ChromeTabbedActivity; | 37 import org.chromium.chrome.browser.ChromeTabbedActivity; |
| 38 import org.chromium.chrome.browser.ChromeVersionInfo; |
| 36 import org.chromium.chrome.browser.IntentHandler; | 39 import org.chromium.chrome.browser.IntentHandler; |
| 37 import org.chromium.chrome.browser.IntentHandler.TabOpenType; | 40 import org.chromium.chrome.browser.IntentHandler.TabOpenType; |
| 38 import org.chromium.chrome.browser.ShortcutHelper; | 41 import org.chromium.chrome.browser.ShortcutHelper; |
| 39 import org.chromium.chrome.browser.ShortcutSource; | 42 import org.chromium.chrome.browser.ShortcutSource; |
| 40 import org.chromium.chrome.browser.UrlConstants; | 43 import org.chromium.chrome.browser.UrlConstants; |
| 41 import org.chromium.chrome.browser.WarmupManager; | 44 import org.chromium.chrome.browser.WarmupManager; |
| 42 import org.chromium.chrome.browser.customtabs.CustomTabActivity; | 45 import org.chromium.chrome.browser.customtabs.CustomTabActivity; |
| 43 import org.chromium.chrome.browser.externalnav.IntentWithGesturesHandler; | 46 import org.chromium.chrome.browser.externalnav.IntentWithGesturesHandler; |
| 44 import org.chromium.chrome.browser.firstrun.FirstRunFlowSequencer; | 47 import org.chromium.chrome.browser.firstrun.FirstRunFlowSequencer; |
| 45 import org.chromium.chrome.browser.metrics.LaunchHistogram; | 48 import org.chromium.chrome.browser.metrics.LaunchHistogram; |
| (...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 } | 272 } |
| 270 | 273 |
| 271 @Override | 274 @Override |
| 272 public void processUrlViewIntent(String url, String referer, String headers, | 275 public void processUrlViewIntent(String url, String referer, String headers, |
| 273 IntentHandler.TabOpenType tabOpenType, String externalAppId, | 276 IntentHandler.TabOpenType tabOpenType, String externalAppId, |
| 274 int tabIdToBringToFront, boolean hasUserGesture, Intent intent) { | 277 int tabIdToBringToFront, boolean hasUserGesture, Intent intent) { |
| 275 assert false; | 278 assert false; |
| 276 } | 279 } |
| 277 | 280 |
| 278 /** | 281 /** |
| 282 * @return Whether or not a Custom Tab will be used for the incoming Intent. |
| 283 */ |
| 284 private boolean isIntentHandledByHerb() { |
| 285 if (ChromeVersionInfo.isStableBuild() || ChromeVersionInfo.isBetaBuild()
) return false; |
| 286 |
| 287 // Allowing disk access for preferences while prototyping. |
| 288 String flavor = null; |
| 289 StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads(); |
| 290 try { |
| 291 flavor = ChromePreferenceManager.getInstance(this).getHerbFlavor(); |
| 292 } finally { |
| 293 StrictMode.setThreadPolicy(oldPolicy); |
| 294 } |
| 295 Log.d(TAG, "Herb flavor: " + flavor); |
| 296 if (TextUtils.isEmpty(flavor)) return false; |
| 297 |
| 298 // Only VIEW Intents are rerouted to Custom Tabs. |
| 299 if (!TextUtils.equals(getIntent().getAction(), Intent.ACTION_VIEW)) retu
rn false; |
| 300 |
| 301 if (TextUtils.equals(flavor, ChromeSwitches.HERB_FLAVOR_ANISE) |
| 302 || TextUtils.equals(flavor, ChromeSwitches.HERB_FLAVOR_BASIL)) { |
| 303 // Only Intents without NEW_TASK and NEW_DOCUMENT will trigger a Cus
tom Tab. |
| 304 boolean isSameTask = (getIntent().getFlags() & Intent.FLAG_ACTIVITY_
NEW_TASK) == 0; |
| 305 boolean isSameDocument = |
| 306 (getIntent().getFlags() & Intent.FLAG_ACTIVITY_NEW_DOCUMENT)
== 0; |
| 307 Log.d(TAG, "Herb Intent proprties -- SAME TASK: " |
| 308 + isSameTask + ", SAME DOCUMENT: " + isSameDocument); |
| 309 return isSameTask && isSameDocument; |
| 310 } else if (TextUtils.equals(flavor, ChromeSwitches.HERB_FLAVOR_CHIVE)) { |
| 311 // Chive sends all View Intents to the main browser. |
| 312 return false; |
| 313 } else if (TextUtils.equals(flavor, ChromeSwitches.HERB_FLAVOR_DILL)) { |
| 314 // Dill always opens View Intents in Custom Tabs -- even home screen
shortcuts. |
| 315 return true; |
| 316 } else { |
| 317 assert false; |
| 318 return false; |
| 319 } |
| 320 } |
| 321 |
| 322 /** |
| 279 * @return Whether the intent sent is for launching a Custom Tab. | 323 * @return Whether the intent sent is for launching a Custom Tab. |
| 280 */ | 324 */ |
| 281 private boolean isCustomTabIntent() { | 325 private boolean isCustomTabIntent() { |
| 282 if (getIntent() == null || !getIntent().hasExtra(CustomTabsIntent.EXTRA_
SESSION)) { | 326 if (getIntent() == null || (!getIntent().hasExtra(CustomTabsIntent.EXTRA
_SESSION) |
| 327 && !isIntentHandledByHerb())) { |
| 283 return false; | 328 return false; |
| 284 } | 329 } |
| 285 | 330 |
| 286 String url = IntentHandler.getUrlFromIntent(getIntent()); | 331 String url = IntentHandler.getUrlFromIntent(getIntent()); |
| 287 if (url == null) return false; | 332 if (url == null) return false; |
| 288 | 333 |
| 289 if (!ChromePreferenceManager.getInstance(this).getCustomTabsEnabled()) r
eturn false; | 334 if (!ChromePreferenceManager.getInstance(this).getCustomTabsEnabled()) r
eturn false; |
| 290 return true; | 335 return true; |
| 291 } | 336 } |
| 292 | 337 |
| (...skipping 531 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 824 return true; | 869 return true; |
| 825 } | 870 } |
| 826 | 871 |
| 827 /** | 872 /** |
| 828 * Send the number of times an exception was caught when trying to move a ta
sk back to front. | 873 * Send the number of times an exception was caught when trying to move a ta
sk back to front. |
| 829 */ | 874 */ |
| 830 public static void sendExceptionCount() { | 875 public static void sendExceptionCount() { |
| 831 sMoveToFrontExceptionHistogram.commitHistogram(); | 876 sMoveToFrontExceptionHistogram.commitHistogram(); |
| 832 } | 877 } |
| 833 } | 878 } |
| OLD | NEW |