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.externalnav; | 5 package org.chromium.chrome.browser.externalnav; |
6 | 6 |
7 import android.content.ActivityNotFoundException; | 7 import android.content.ActivityNotFoundException; |
8 import android.content.ComponentName; | 8 import android.content.ComponentName; |
9 import android.content.Intent; | 9 import android.content.Intent; |
10 import android.content.pm.ResolveInfo; | 10 import android.content.pm.ResolveInfo; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 private static final String SMS_SCHEME = "sms"; | 52 private static final String SMS_SCHEME = "sms"; |
53 | 53 |
54 private static final String PLAY_PACKAGE_PARAM = "id"; | 54 private static final String PLAY_PACKAGE_PARAM = "id"; |
55 private static final String PLAY_REFERRER_PARAM = "referrer"; | 55 private static final String PLAY_REFERRER_PARAM = "referrer"; |
56 private static final String PLAY_APP_PATH = "/store/apps/details"; | 56 private static final String PLAY_APP_PATH = "/store/apps/details"; |
57 private static final String PLAY_HOSTNAME = "play.google.com"; | 57 private static final String PLAY_HOSTNAME = "play.google.com"; |
58 | 58 |
59 @VisibleForTesting | 59 @VisibleForTesting |
60 static final String EXTRA_BROWSER_FALLBACK_URL = "browser_fallback_url"; | 60 static final String EXTRA_BROWSER_FALLBACK_URL = "browser_fallback_url"; |
61 | 61 |
62 @VisibleForTesting | |
63 static final String SUPERVISOR_PKG = "com.google.android.instantapps.supervi
sor"; | |
64 @VisibleForTesting | |
65 static final String[] SUPERVISOR_START_ACTIONS = { | |
66 "com.google.android.instantapps.START", | |
67 "com.google.android.instantapps.nmr1.INSTALL", | |
68 "com.google.android.instantapps.nmr1.VIEW" }; | |
69 | |
70 // An extra that may be specified on an intent:// URL that contains an encod
ed value for the | 62 // An extra that may be specified on an intent:// URL that contains an encod
ed value for the |
71 // referrer field passed to the market:// URL in the case where the app is n
ot present. | 63 // referrer field passed to the market:// URL in the case where the app is n
ot present. |
72 @VisibleForTesting | 64 @VisibleForTesting |
73 static final String EXTRA_MARKET_REFERRER = "market_referrer"; | 65 static final String EXTRA_MARKET_REFERRER = "market_referrer"; |
74 | 66 |
75 private final ExternalNavigationDelegate mDelegate; | 67 private final ExternalNavigationDelegate mDelegate; |
76 | 68 |
77 /** | 69 /** |
78 * Result types for checking if we should override URL loading. | 70 * Result types for checking if we should override URL loading. |
79 * NOTE: this enum is used in UMA, do not reorder values. Changes should be
append only. | 71 * NOTE: this enum is used in UMA, do not reorder values. Changes should be
append only. |
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
463 if (previousIntent != null | 455 if (previousIntent != null |
464 && resolversSubsetOf(resolvingInfos, | 456 && resolversSubsetOf(resolvingInfos, |
465 mDelegate.queryIntentActivities(previousInte
nt))) { | 457 mDelegate.queryIntentActivities(previousInte
nt))) { |
466 if (DEBUG) Log.i(TAG, "NO_OVERRIDE: Same host, no new re
solvers"); | 458 if (DEBUG) Log.i(TAG, "NO_OVERRIDE: Same host, no new re
solvers"); |
467 return OverrideUrlLoadingResult.NO_OVERRIDE; | 459 return OverrideUrlLoadingResult.NO_OVERRIDE; |
468 } | 460 } |
469 } | 461 } |
470 } | 462 } |
471 } | 463 } |
472 | 464 |
473 boolean isDirectInstantAppsIntent = isExternalProtocol && isIntentToInst
antApp(intent); | 465 boolean isDirectInstantAppsIntent = |
| 466 isExternalProtocol && InstantAppsHandler.isIntentToInstantApp(in
tent); |
474 boolean shouldProxyForInstantApps = isDirectInstantAppsIntent | 467 boolean shouldProxyForInstantApps = isDirectInstantAppsIntent |
475 && mDelegate.isSerpReferrer(params.getTab()); | 468 && mDelegate.isSerpReferrer(params.getTab()); |
476 if (shouldProxyForInstantApps) { | 469 if (shouldProxyForInstantApps) { |
477 intent.putExtra(InstantAppsHandler.IS_GOOGLE_SEARCH_REFERRER, true); | 470 intent.putExtra(InstantAppsHandler.IS_GOOGLE_SEARCH_REFERRER, true); |
478 } else if (isDirectInstantAppsIntent) { | 471 } else if (isDirectInstantAppsIntent) { |
479 // For security reasons, we disable all intent:// URLs to Instant Ap
ps that are | 472 // For security reasons, we disable all intent:// URLs to Instant Ap
ps that are |
480 // not coming from SERP. | 473 // not coming from SERP. |
481 if (DEBUG) Log.i(TAG, "NO_OVERRIDE: Intent URL to an Instant App"); | 474 if (DEBUG) Log.i(TAG, "NO_OVERRIDE: Intent URL to an Instant App"); |
482 return OverrideUrlLoadingResult.NO_OVERRIDE; | 475 return OverrideUrlLoadingResult.NO_OVERRIDE; |
483 } else { | 476 } else { |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
586 return OverrideUrlLoadingResult.OVERRIDE_WITH_EXTERNAL_INTENT; | 579 return OverrideUrlLoadingResult.OVERRIDE_WITH_EXTERNAL_INTENT; |
587 } | 580 } |
588 } catch (ActivityNotFoundException ex) { | 581 } catch (ActivityNotFoundException ex) { |
589 // ignore the error on devices that does not have Play Store install
ed. | 582 // ignore the error on devices that does not have Play Store install
ed. |
590 if (DEBUG) Log.i(TAG, "NO_OVERRIDE: Play Store not installed"); | 583 if (DEBUG) Log.i(TAG, "NO_OVERRIDE: Play Store not installed"); |
591 return OverrideUrlLoadingResult.NO_OVERRIDE; | 584 return OverrideUrlLoadingResult.NO_OVERRIDE; |
592 } | 585 } |
593 } | 586 } |
594 | 587 |
595 /** | 588 /** |
596 * Checks whether {@param intent} is for an Instant App. Considers both pack
age and actions that | |
597 * would resolve to Supervisor. | |
598 * @return Whether the given intent is going to open an Instant App. | |
599 */ | |
600 private boolean isIntentToInstantApp(Intent intent) { | |
601 if (SUPERVISOR_PKG.equals(intent.getPackage())) return true; | |
602 | |
603 String intentAction = intent.getAction(); | |
604 for (String action: SUPERVISOR_START_ACTIONS) { | |
605 if (action.equals(intentAction)) { | |
606 return true; | |
607 } | |
608 } | |
609 return false; | |
610 } | |
611 | |
612 /** | |
613 * Clobber the current tab with fallback URL. | 589 * Clobber the current tab with fallback URL. |
614 * | 590 * |
615 * @param browserFallbackUrl The fallback URL. | 591 * @param browserFallbackUrl The fallback URL. |
616 * @param params The external navigation params. | 592 * @param params The external navigation params. |
617 * @return {@link OverrideUrlLoadingResult} if the tab was clobbered, or we
launched an | 593 * @return {@link OverrideUrlLoadingResult} if the tab was clobbered, or we
launched an |
618 * intent. | 594 * intent. |
619 */ | 595 */ |
620 private OverrideUrlLoadingResult clobberCurrentTabWithFallbackUrl( | 596 private OverrideUrlLoadingResult clobberCurrentTabWithFallbackUrl( |
621 String browserFallbackUrl, ExternalNavigationParams params) { | 597 String browserFallbackUrl, ExternalNavigationParams params) { |
622 // If the fallback URL is a link to Play Store, send the user to Play St
ore app | 598 // If the fallback URL is a link to Play Store, send the user to Play St
ore app |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
691 if (defaultSmsPackageName == null) return null; | 667 if (defaultSmsPackageName == null) return null; |
692 // Makes sure that the default SMS app actually resolves the intent. | 668 // Makes sure that the default SMS app actually resolves the intent. |
693 for (ResolveInfo resolveInfo : resolvingComponentNames) { | 669 for (ResolveInfo resolveInfo : resolvingComponentNames) { |
694 if (defaultSmsPackageName.equals(resolveInfo.activityInfo.packageNam
e)) { | 670 if (defaultSmsPackageName.equals(resolveInfo.activityInfo.packageNam
e)) { |
695 return defaultSmsPackageName; | 671 return defaultSmsPackageName; |
696 } | 672 } |
697 } | 673 } |
698 return null; | 674 return null; |
699 } | 675 } |
700 } | 676 } |
OLD | NEW |