Commit 95e38b56 authored by Colin Blundell's avatar Colin Blundell Committed by Commit Bot

[Android] Dedupe more code between ExternalNavigationDelegate impls

This CL dedupes the identical matchResolveInfoExceptWildCardHost()
methods of //chrome and //weblayer's ExternalNavigationDelegate impls
into ExternalNavigationHandler. This deduping is a preq for removing
a bunch of methods from the ExternalNavigationDelegate interface.

Bug: 1071390
Change-Id: I0a7d126f08a50397b1e042a3a347cccbf6a7984a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2154190Reviewed-by: default avatarMichael Thiessen <mthiesse@chromium.org>
Commit-Queue: Colin Blundell <blundell@chromium.org>
Cr-Commit-Position: refs/heads/master@{#760064}
parent f04d874c
...@@ -12,7 +12,6 @@ import android.content.DialogInterface; ...@@ -12,7 +12,6 @@ import android.content.DialogInterface;
import android.content.DialogInterface.OnCancelListener; import android.content.DialogInterface.OnCancelListener;
import android.content.DialogInterface.OnClickListener; import android.content.DialogInterface.OnClickListener;
import android.content.Intent; import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo; import android.content.pm.ResolveInfo;
import android.net.Uri; import android.net.Uri;
...@@ -53,6 +52,7 @@ import org.chromium.components.embedder_support.util.UrlConstants; ...@@ -53,6 +52,7 @@ import org.chromium.components.embedder_support.util.UrlConstants;
import org.chromium.components.embedder_support.util.UrlUtilities; import org.chromium.components.embedder_support.util.UrlUtilities;
import org.chromium.components.embedder_support.util.UrlUtilitiesJni; import org.chromium.components.embedder_support.util.UrlUtilitiesJni;
import org.chromium.components.external_intents.ExternalNavigationDelegate; import org.chromium.components.external_intents.ExternalNavigationDelegate;
import org.chromium.components.external_intents.ExternalNavigationHandler;
import org.chromium.components.external_intents.ExternalNavigationHandler.OverrideUrlLoadingResult; import org.chromium.components.external_intents.ExternalNavigationHandler.OverrideUrlLoadingResult;
import org.chromium.components.external_intents.ExternalNavigationParams; import org.chromium.components.external_intents.ExternalNavigationParams;
import org.chromium.components.external_intents.RedirectHandlerImpl; import org.chromium.components.external_intents.RedirectHandlerImpl;
...@@ -68,7 +68,6 @@ import org.chromium.ui.base.PermissionCallback; ...@@ -68,7 +68,6 @@ import org.chromium.ui.base.PermissionCallback;
import org.chromium.webapk.lib.client.WebApkValidator; import org.chromium.webapk.lib.client.WebApkValidator;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator;
import java.util.List; import java.util.List;
/** /**
...@@ -233,7 +232,8 @@ public class ExternalNavigationDelegateImpl implements ExternalNavigationDelegat ...@@ -233,7 +232,8 @@ public class ExternalNavigationDelegateImpl implements ExternalNavigationDelegat
} }
for (ResolveInfo info : infos) { for (ResolveInfo info : infos) {
if (!matchResolveInfoExceptWildCardHost(info, filterPackageName)) { if (!ExternalNavigationHandler.matchResolveInfoExceptWildCardHost(
info, filterPackageName)) {
continue; continue;
} }
...@@ -251,37 +251,6 @@ public class ExternalNavigationDelegateImpl implements ExternalNavigationDelegat ...@@ -251,37 +251,6 @@ public class ExternalNavigationDelegateImpl implements ExternalNavigationDelegat
return result; return result;
} }
private static boolean matchResolveInfoExceptWildCardHost(
ResolveInfo info, String filterPackageName) {
IntentFilter intentFilter = info.filter;
if (intentFilter == null) {
// Error on the side of classifying ResolveInfo as generic.
return false;
}
if (intentFilter.countDataAuthorities() == 0 && intentFilter.countDataPaths() == 0) {
// Don't count generic handlers.
return false;
}
boolean isWildCardHost = false;
Iterator<IntentFilter.AuthorityEntry> it = intentFilter.authoritiesIterator();
while (it != null && it.hasNext()) {
IntentFilter.AuthorityEntry entry = it.next();
if ("*".equals(entry.getHost())) {
isWildCardHost = true;
break;
}
}
if (isWildCardHost) {
return false;
}
if (!TextUtils.isEmpty(filterPackageName)
&& (info.activityInfo == null
|| !info.activityInfo.packageName.equals(filterPackageName))) {
return false;
}
return true;
}
/** /**
* Check whether the given package is a specialized handler for the given intent * Check whether the given package is a specialized handler for the given intent
* *
......
...@@ -7,6 +7,7 @@ package org.chromium.components.external_intents; ...@@ -7,6 +7,7 @@ package org.chromium.components.external_intents;
import android.content.ActivityNotFoundException; import android.content.ActivityNotFoundException;
import android.content.ComponentName; import android.content.ComponentName;
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;
...@@ -40,6 +41,7 @@ import java.lang.annotation.RetentionPolicy; ...@@ -40,6 +41,7 @@ import java.lang.annotation.RetentionPolicy;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator;
import java.util.List; import java.util.List;
/** /**
...@@ -1119,6 +1121,39 @@ public class ExternalNavigationHandler { ...@@ -1119,6 +1121,39 @@ public class ExternalNavigationHandler {
|| intent.getSelector().filterEquals(other.getSelector())); || intent.getSelector().filterEquals(other.getSelector()));
} }
// TODO(crbug.com/1071390): Make this method private once its consumers have been moved into
// this class.
public static boolean matchResolveInfoExceptWildCardHost(
ResolveInfo info, String filterPackageName) {
IntentFilter intentFilter = info.filter;
if (intentFilter == null) {
// Error on the side of classifying ResolveInfo as generic.
return false;
}
if (intentFilter.countDataAuthorities() == 0 && intentFilter.countDataPaths() == 0) {
// Don't count generic handlers.
return false;
}
boolean isWildCardHost = false;
Iterator<IntentFilter.AuthorityEntry> it = intentFilter.authoritiesIterator();
while (it != null && it.hasNext()) {
IntentFilter.AuthorityEntry entry = it.next();
if ("*".equals(entry.getHost())) {
isWildCardHost = true;
break;
}
}
if (isWildCardHost) {
return false;
}
if (!TextUtils.isEmpty(filterPackageName)
&& (info.activityInfo == null
|| !info.activityInfo.packageName.equals(filterPackageName))) {
return false;
}
return true;
}
private void recordIntentActionMetrics(Intent intent) { private void recordIntentActionMetrics(Intent intent) {
String action = intent.getAction(); String action = intent.getAction();
@StandardActions @StandardActions
......
...@@ -8,7 +8,6 @@ import android.Manifest.permission; ...@@ -8,7 +8,6 @@ import android.Manifest.permission;
import android.app.Activity; import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo; import android.content.pm.ResolveInfo;
import android.net.Uri; import android.net.Uri;
...@@ -30,6 +29,7 @@ import org.chromium.base.task.PostTask; ...@@ -30,6 +29,7 @@ import org.chromium.base.task.PostTask;
import org.chromium.components.embedder_support.util.UrlConstants; import org.chromium.components.embedder_support.util.UrlConstants;
import org.chromium.components.embedder_support.util.UrlUtilitiesJni; import org.chromium.components.embedder_support.util.UrlUtilitiesJni;
import org.chromium.components.external_intents.ExternalNavigationDelegate; import org.chromium.components.external_intents.ExternalNavigationDelegate;
import org.chromium.components.external_intents.ExternalNavigationHandler;
import org.chromium.components.external_intents.ExternalNavigationHandler.OverrideUrlLoadingResult; import org.chromium.components.external_intents.ExternalNavigationHandler.OverrideUrlLoadingResult;
import org.chromium.components.external_intents.ExternalNavigationParams; import org.chromium.components.external_intents.ExternalNavigationParams;
import org.chromium.content_public.browser.LoadUrlParams; import org.chromium.content_public.browser.LoadUrlParams;
...@@ -42,7 +42,6 @@ import org.chromium.ui.base.PageTransition; ...@@ -42,7 +42,6 @@ import org.chromium.ui.base.PageTransition;
import org.chromium.ui.base.PermissionCallback; import org.chromium.ui.base.PermissionCallback;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator;
import java.util.List; import java.util.List;
/** /**
...@@ -187,7 +186,8 @@ public class ExternalNavigationDelegateImpl implements ExternalNavigationDelegat ...@@ -187,7 +186,8 @@ public class ExternalNavigationDelegateImpl implements ExternalNavigationDelegat
} }
for (ResolveInfo info : infos) { for (ResolveInfo info : infos) {
if (!matchResolveInfoExceptWildCardHost(info, filterPackageName)) { if (!ExternalNavigationHandler.matchResolveInfoExceptWildCardHost(
info, filterPackageName)) {
continue; continue;
} }
...@@ -200,37 +200,6 @@ public class ExternalNavigationDelegateImpl implements ExternalNavigationDelegat ...@@ -200,37 +200,6 @@ public class ExternalNavigationDelegateImpl implements ExternalNavigationDelegat
return result; return result;
} }
private static boolean matchResolveInfoExceptWildCardHost(
ResolveInfo info, String filterPackageName) {
IntentFilter intentFilter = info.filter;
if (intentFilter == null) {
// Error on the side of classifying ResolveInfo as generic.
return false;
}
if (intentFilter.countDataAuthorities() == 0 && intentFilter.countDataPaths() == 0) {
// Don't count generic handlers.
return false;
}
boolean isWildCardHost = false;
Iterator<IntentFilter.AuthorityEntry> it = intentFilter.authoritiesIterator();
while (it != null && it.hasNext()) {
IntentFilter.AuthorityEntry entry = it.next();
if ("*".equals(entry.getHost())) {
isWildCardHost = true;
break;
}
}
if (isWildCardHost) {
return false;
}
if (!TextUtils.isEmpty(filterPackageName)
&& (info.activityInfo == null
|| !info.activityInfo.packageName.equals(filterPackageName))) {
return false;
}
return true;
}
/** /**
* Check whether the given package is a specialized handler for the given intent * Check whether the given package is a specialized handler for the given intent
* *
......
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