Commit c781ba9a authored by mariakhomenko's avatar mariakhomenko Committed by Commit bot

Instant Apps: check for instant apps start action.

In addition to the intent package, check for instant apps start action.
We still route the intent to instant apps, even if the package isn't set
based on action and category.

BUG=675757

Review-Url: https://codereview.chromium.org/2597463002
Cr-Commit-Position: refs/heads/master@{#439890}
parent 3e4d1fa0
......@@ -48,9 +48,13 @@ public class ExternalNavigationHandler {
@VisibleForTesting
static final String EXTRA_BROWSER_FALLBACK_URL = "browser_fallback_url";
// Supervisor package name
@VisibleForTesting
static final Object SUPERVISOR_PKG = "com.google.android.instantapps.supervisor";
static final String SUPERVISOR_PKG = "com.google.android.instantapps.supervisor";
@VisibleForTesting
static final String[] SUPERVISOR_START_ACTIONS = {
"com.google.android.instantapps.START",
"com.google.android.instantapps.nmr1.INSTALL",
"com.google.android.instantapps.nmr1.VIEW" };
// An extra that may be specified on an intent:// URL that contains an encoded value for the
// referrer field passed to the market:// URL in the case where the app is not present.
......@@ -455,8 +459,7 @@ public class ExternalNavigationHandler {
}
}
boolean isDirectInstantAppsIntent = isExternalProtocol
&& SUPERVISOR_PKG.equals(intent.getPackage());
boolean isDirectInstantAppsIntent = isExternalProtocol && isIntentToInstantApp(intent);
boolean shouldProxyForInstantApps = isDirectInstantAppsIntent
&& mDelegate.isSerpReferrer(params.getTab());
if (shouldProxyForInstantApps) {
......@@ -535,6 +538,23 @@ public class ExternalNavigationHandler {
return OverrideUrlLoadingResult.NO_OVERRIDE;
}
/**
* Checks whether {@param intent} is for an Instant App. Considers both package and actions that
* would resolve to Supervisor.
* @return Whether the given intent is going to open an Instant App.
*/
private boolean isIntentToInstantApp(Intent intent) {
if (SUPERVISOR_PKG.equals(intent.getPackage())) return true;
String intentAction = intent.getAction();
for (String action: SUPERVISOR_START_ACTIONS) {
if (action.equals(intentAction)) {
return true;
}
}
return false;
}
/**
* Clobber the current tab with fallback URL.
*
......
......@@ -615,6 +615,19 @@ public class ExternalNavigationHandlerTest extends NativeLibraryTestBase {
START_OTHER_ACTIVITY);
assertFalse(mDelegate.startActivityIntent.hasExtra(
InstantAppsHandler.IS_GOOGLE_SEARCH_REFERRER));
// Check that Supervisor is detected by action even without package
for (String action : ExternalNavigationHandler.SUPERVISOR_START_ACTIONS) {
String intentWithoutPackage = "intent://buzzfeed.com/tasty#Intent;scheme=http;"
+ "action=" + action + ";"
+ "S.com.google.android.instantapps.FALLBACK_PACKAGE="
+ "com.android.chrome;S.com.google.android.instantapps.INSTANT_APP_PACKAGE="
+ "com.yelp.android;S.android.intent.extra.REFERRER_NAME="
+ "https%3A%2F%2Fwww.google.com;end";
mDelegate.setIsSerpReferrer(false);
checkUrl(intentWithoutPackage)
.expecting(OverrideUrlLoadingResult.NO_OVERRIDE, IGNORE);
}
}
@SmallTest
......
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