Commit 63990472 authored by Michael Thiessen's avatar Michael Thiessen Committed by Commit Bot

Clean up WebApk logic in ExternalNavigationHandler

This CL does three things:
1. It moves unrelated logic out of launchWebApkIfSoleIntentHandler()
2. It unifies the browser fallback URL handling path.
3. It avoids unnecessarily calling isValidWebApk on a lot of packages

There is a functional change here: we no longer require an intent URL
to specify a package for its fallback URL to be handled by a WebApk.
(The package could have been any package, even unrelated to the WebApk)

Bug: 1006927
Change-Id: I1dd4bf26e40706a37900377e280623aa5ae129fc
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1837478Reviewed-by: default avatarPeter Kotwicz <pkotwicz@chromium.org>
Reviewed-by: default avatarYaron Friedman <yfriedman@chromium.org>
Commit-Queue: Michael Thiessen <mthiesse@chromium.org>
Cr-Commit-Position: refs/heads/master@{#705129}
parent 87018823
...@@ -47,13 +47,6 @@ interface ExternalNavigationDelegate { ...@@ -47,13 +47,6 @@ interface ExternalNavigationDelegate {
*/ */
int countSpecializedHandlers(List<ResolveInfo> infos); int countSpecializedHandlers(List<ResolveInfo> infos);
/**
* Returns the package name of the first valid WebAPK in {@link infos}.
* @param infos ResolveInfos to search.
* @return The package name of the first valid WebAPK. Null if no valid WebAPK was found.
*/
String findFirstWebApkPackageName(List<ResolveInfo> infos);
/** /**
* Start an activity for the intent. Used for intents that must be handled externally. * Start an activity for the intent. Used for intents that must be handled externally.
* @param intent The intent we want to send. * @param intent The intent we want to send.
...@@ -163,4 +156,10 @@ interface ExternalNavigationDelegate { ...@@ -163,4 +156,10 @@ interface ExternalNavigationDelegate {
* @return Whether the Intent points to an app that we trust and that launched Chrome. * @return Whether the Intent points to an app that we trust and that launched Chrome.
*/ */
boolean isIntentForTrustedCallingApp(Intent intent); boolean isIntentForTrustedCallingApp(Intent intent);
/**
* @param packageName The package to check.
* @return Whether the package is a valid WebAPK package.
*/
boolean isValidWebApk(String packageName);
} }
...@@ -298,11 +298,6 @@ public class ExternalNavigationDelegateImpl implements ExternalNavigationDelegat ...@@ -298,11 +298,6 @@ public class ExternalNavigationDelegateImpl implements ExternalNavigationDelegat
return !getSpecializedHandlersWithFilter(handlers, packageName).isEmpty(); return !getSpecializedHandlersWithFilter(handlers, packageName).isEmpty();
} }
@Override
public String findFirstWebApkPackageName(List<ResolveInfo> infos) {
return WebApkValidator.findFirstWebApkPackage(mApplicationContext, infos);
}
@Override @Override
public void startActivity(Intent intent, boolean proxy) { public void startActivity(Intent intent, boolean proxy) {
try { try {
...@@ -644,4 +639,9 @@ public class ExternalNavigationDelegateImpl implements ExternalNavigationDelegat ...@@ -644,4 +639,9 @@ public class ExternalNavigationDelegateImpl implements ExternalNavigationDelegat
public boolean isIntentForTrustedCallingApp(Intent intent) { public boolean isIntentForTrustedCallingApp(Intent intent) {
return false; return false;
} }
@Override
public boolean isValidWebApk(String packageName) {
return WebApkValidator.isValidWebApk(ContextUtils.getApplicationContext(), packageName);
}
} }
...@@ -8,6 +8,7 @@ import android.annotation.SuppressLint; ...@@ -8,6 +8,7 @@ import android.annotation.SuppressLint;
import android.content.Context; import android.content.Context;
import android.content.ContextWrapper; import android.content.ContextWrapper;
import android.content.Intent; import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.ActivityInfo; import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo; import android.content.pm.ResolveInfo;
...@@ -1599,6 +1600,14 @@ public class ExternalNavigationHandlerTest { ...@@ -1599,6 +1600,14 @@ public class ExternalNavigationHandlerTest {
return ri; return ri;
} }
private static ResolveInfo newSpecializedResolveInfo(
String packageName, IntentActivity activity) {
ResolveInfo info = newResolveInfo(packageName);
info.filter = new IntentFilter(Intent.ACTION_VIEW);
info.filter.addDataAuthority(activity.mUrlPrefix, null);
return info;
}
private static WebappInfo newWebappInfoFromScope(String scope) { private static WebappInfo newWebappInfoFromScope(String scope) {
Intent webappIntent = WebappTestHelper.createMinimalWebappIntent("" /* id */, "" /* url */); Intent webappIntent = WebappTestHelper.createMinimalWebappIntent("" /* id */, "" /* url */);
webappIntent.putExtra(ShortcutHelper.EXTRA_SCOPE, scope); webappIntent.putExtra(ShortcutHelper.EXTRA_SCOPE, scope);
...@@ -1660,7 +1669,8 @@ public class ExternalNavigationHandlerTest { ...@@ -1660,7 +1669,8 @@ public class ExternalNavigationHandlerTest {
} }
for (IntentActivity intentActivity : mIntentActivities) { for (IntentActivity intentActivity : mIntentActivities) {
if (dataString.startsWith(intentActivity.urlPrefix())) { if (dataString.startsWith(intentActivity.urlPrefix())) {
list.add(newResolveInfo(intentActivity.packageName())); list.add(newSpecializedResolveInfo(
intentActivity.packageName(), intentActivity));
} }
} }
if (!list.isEmpty()) return list; if (!list.isEmpty()) return list;
...@@ -1716,17 +1726,6 @@ public class ExternalNavigationHandlerTest { ...@@ -1716,17 +1726,6 @@ public class ExternalNavigationHandlerTest {
return count; return count;
} }
@Override
public String findFirstWebApkPackageName(List<ResolveInfo> infos) {
List<IntentActivity> matchingIntentActivities = findMatchingIntentActivities(infos);
for (IntentActivity intentActivity : matchingIntentActivities) {
if (intentActivity.isWebApk()) {
return intentActivity.packageName();
}
}
return null;
}
private ArrayList<IntentActivity> findMatchingIntentActivities(List<ResolveInfo> infos) { private ArrayList<IntentActivity> findMatchingIntentActivities(List<ResolveInfo> infos) {
ArrayList<IntentActivity> outList = new ArrayList<IntentActivity>(); ArrayList<IntentActivity> outList = new ArrayList<IntentActivity>();
for (ResolveInfo info : infos) { for (ResolveInfo info : infos) {
...@@ -1823,6 +1822,16 @@ public class ExternalNavigationHandlerTest { ...@@ -1823,6 +1822,16 @@ public class ExternalNavigationHandlerTest {
return mIsCallingAppTrusted; return mIsCallingAppTrusted;
} }
@Override
public boolean isValidWebApk(String packageName) {
for (IntentActivity activity : mIntentActivities) {
if (activity.packageName().equals(packageName)) {
return activity.isWebApk();
}
}
return false;
}
public void reset() { public void reset() {
startActivityIntent = null; startActivityIntent = null;
startIncognitoIntentCalled = false; startIncognitoIntentCalled = false;
......
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