Index: chrome/android/java/src/org/chromium/chrome/browser/externalnav/ExternalNavigationDelegateImpl.java |
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/externalnav/ExternalNavigationDelegateImpl.java b/chrome/android/java/src/org/chromium/chrome/browser/externalnav/ExternalNavigationDelegateImpl.java |
index f6946ecb7d8311c7477d287bd830b1ed745a7a3f..afa999df4ff669fa93a3078b20be5a446d6b642c 100644 |
--- a/chrome/android/java/src/org/chromium/chrome/browser/externalnav/ExternalNavigationDelegateImpl.java |
+++ b/chrome/android/java/src/org/chromium/chrome/browser/externalnav/ExternalNavigationDelegateImpl.java |
@@ -12,7 +12,6 @@ import android.content.DialogInterface.OnCancelListener; |
import android.content.DialogInterface.OnClickListener; |
import android.content.Intent; |
import android.content.IntentFilter; |
-import android.content.pm.ActivityInfo; |
import android.content.pm.PackageManager; |
import android.content.pm.ResolveInfo; |
import android.net.Uri; |
@@ -45,6 +44,7 @@ import org.chromium.content_public.common.Referrer; |
import org.chromium.ui.base.PageTransition; |
import org.chromium.ui.base.WindowAndroid; |
import org.chromium.ui.base.WindowAndroid.PermissionCallback; |
+import org.chromium.webapk.lib.client.WebApkValidator; |
import java.util.List; |
@@ -227,31 +227,41 @@ public class ExternalNavigationDelegateImpl implements ExternalNavigationDelegat |
@Override |
public boolean isSpecializedHandlerAvailable(List<ResolveInfo> infos) { |
- return isPackageSpecializedHandler(infos, null); |
+ return countSpecializedHandlers(infos) > 0; |
} |
- static boolean isPackageSpecializedHandler(List<ResolveInfo> handlers, |
- String packageName) { |
- if (handlers == null || handlers.size() == 0) return false; |
- for (ResolveInfo resolveInfo : handlers) { |
- IntentFilter filter = resolveInfo.filter; |
+ @Override |
+ public int countSpecializedHandlers(List<ResolveInfo> infos) { |
+ return countSpecializedHandlersWithFilter(infos, null); |
+ } |
+ |
+ static int countSpecializedHandlersWithFilter(List<ResolveInfo> infos, |
+ String filterPackageName) { |
+ if (infos == null) { |
+ return 0; |
+ } |
+ |
+ int count = 0; |
+ for (ResolveInfo info : infos) { |
+ IntentFilter filter = info.filter; |
if (filter == null) { |
- // No intent filter matches this intent? |
- // Error on the side of staying in the browser, ignore |
+ // Error on the side of classifying ResolveInfo as generic. |
continue; |
} |
if (filter.countDataAuthorities() == 0 && filter.countDataPaths() == 0) { |
- // Generic handler, skip |
+ // Don't count generic handlers. |
continue; |
} |
- if (TextUtils.isEmpty(packageName)) return true; |
- ActivityInfo activityInfo = resolveInfo.activityInfo; |
- if (activityInfo == null) continue; |
- if (!activityInfo.packageName.equals(packageName)) continue; |
- return true; |
- } |
- return false; |
+ if (!TextUtils.isEmpty(filterPackageName) |
+ && (info.activityInfo == null |
+ || !info.activityInfo.packageName.equals(filterPackageName))) { |
+ continue; |
+ } |
+ |
+ ++count; |
+ } |
+ return count; |
} |
/** |
@@ -268,7 +278,7 @@ public class ExternalNavigationDelegateImpl implements ExternalNavigationDelegat |
try { |
List<ResolveInfo> handlers = context.getPackageManager().queryIntentActivities( |
intent, PackageManager.GET_RESOLVED_FILTER); |
- return isPackageSpecializedHandler(handlers, packageName); |
+ return countSpecializedHandlersWithFilter(handlers, packageName) > 0; |
} catch (RuntimeException e) { |
logTransactionTooLargeOrRethrow(e, intent); |
} |
@@ -276,6 +286,14 @@ public class ExternalNavigationDelegateImpl implements ExternalNavigationDelegat |
} |
@Override |
+ public String findValidWebApkPackageName(List<ResolveInfo> infos) { |
+ String webApkPackageName = WebApkValidator.findWebApkPackage(infos); |
+ return WebApkValidator.isValidWebApk(mApplicationContext, webApkPackageName) |
+ ? webApkPackageName |
+ : null; |
+ } |
+ |
+ @Override |
public String getPackageName() { |
return mApplicationContext.getPackageName(); |
} |