AndroidX Webkit: new ProxyRule class and return unmodifiable lists
Creates a ProxyRule class in ProxyConfig to hold two Strings: scheme
filter and proxy URL.
Methods getProxyRules() and getBypassRules() return unmodifiable lists.
Bug: 138331218
Test: ./gradlew webkit:connectedCheck
Change-Id: If476cade8e8eb444a588a6e8302f59e77ca90264
diff --git a/webkit/api/1.1.0-alpha03.txt b/webkit/api/1.1.0-alpha03.txt
index 44938cf..2936afa 100644
--- a/webkit/api/1.1.0-alpha03.txt
+++ b/webkit/api/1.1.0-alpha03.txt
@@ -3,7 +3,7 @@
public final class ProxyConfig {
method public java.util.List<java.lang.String!> getBypassRules();
- method public java.util.List<androidx.core.util.Pair<java.lang.String!,java.lang.String!>!> getProxyRules();
+ method public java.util.List<androidx.webkit.ProxyConfig.ProxyRule!> getProxyRules();
field public static final String MATCH_ALL_SCHEMES = "*";
field public static final String MATCH_HTTP = "http";
field public static final String MATCH_HTTPS = "https";
@@ -22,6 +22,11 @@
method public androidx.webkit.ProxyConfig.Builder removeImplicitRules();
}
+ public static final class ProxyConfig.ProxyRule {
+ method public String getSchemeFilter();
+ method public String getUrl();
+ }
+
public abstract class ProxyController {
method public abstract void clearProxyOverride(java.util.concurrent.Executor, Runnable);
method @RequiresFeature(name=androidx.webkit.WebViewFeature.PROXY_OVERRIDE, enforcement="androidx.webkit.WebViewFeature#isFeatureSupported") public static androidx.webkit.ProxyController getInstance();
diff --git a/webkit/api/current.txt b/webkit/api/current.txt
index 44938cf..2936afa 100644
--- a/webkit/api/current.txt
+++ b/webkit/api/current.txt
@@ -3,7 +3,7 @@
public final class ProxyConfig {
method public java.util.List<java.lang.String!> getBypassRules();
- method public java.util.List<androidx.core.util.Pair<java.lang.String!,java.lang.String!>!> getProxyRules();
+ method public java.util.List<androidx.webkit.ProxyConfig.ProxyRule!> getProxyRules();
field public static final String MATCH_ALL_SCHEMES = "*";
field public static final String MATCH_HTTP = "http";
field public static final String MATCH_HTTPS = "https";
@@ -22,6 +22,11 @@
method public androidx.webkit.ProxyConfig.Builder removeImplicitRules();
}
+ public static final class ProxyConfig.ProxyRule {
+ method public String getSchemeFilter();
+ method public String getUrl();
+ }
+
public abstract class ProxyController {
method public abstract void clearProxyOverride(java.util.concurrent.Executor, Runnable);
method @RequiresFeature(name=androidx.webkit.WebViewFeature.PROXY_OVERRIDE, enforcement="androidx.webkit.WebViewFeature#isFeatureSupported") public static androidx.webkit.ProxyController getInstance();
diff --git a/webkit/src/main/java/androidx/webkit/ProxyConfig.java b/webkit/src/main/java/androidx/webkit/ProxyConfig.java
index 74adb9c..39c658f 100644
--- a/webkit/src/main/java/androidx/webkit/ProxyConfig.java
+++ b/webkit/src/main/java/androidx/webkit/ProxyConfig.java
@@ -19,11 +19,11 @@
import androidx.annotation.NonNull;
import androidx.annotation.RestrictTo;
import androidx.annotation.StringDef;
-import androidx.core.util.Pair;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
import java.util.concurrent.Executor;
@@ -66,22 +66,22 @@
private static final String BYPASS_RULE_SIMPLE_NAMES = "<local>";
private static final String BYPASS_RULE_REMOVE_IMPLICIT = "<-loopback>";
- private List<Pair<String, String>> mProxyRules;
+ private List<ProxyRule> mProxyRules;
private List<String> mBypassRules;
/**
* @hide Internal use only
*/
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP_PREFIX)
- public ProxyConfig(List<Pair<String, String>> proxyRules, List<String> bypassRules) {
+ public ProxyConfig(List<ProxyRule> proxyRules, List<String> bypassRules) {
mProxyRules = proxyRules;
mBypassRules = bypassRules;
}
/**
- * Returns the current list of proxy rules. Each pair of (String, String) consists of the proxy
- * URL and the URL schemes for which this proxy is used (one of {@code MATCH_HTTP},
- * {@code MATCH_HTTPS}, {@code MATCH_ALL_SCHEMES}).
+ * Returns the current list of proxy rules. Each {@link ProxyRule} object
+ * holds the proxy URL and the URL schemes for which this proxy is used (one of
+ * {@code MATCH_HTTP}, {@code MATCH_HTTPS}, {@code MATCH_ALL_SCHEMES}).
*
* <p>To add new rules use {@link Builder#addProxyRule(String)} or
* {@link Builder#addProxyRule(String, String)}.
@@ -89,8 +89,8 @@
* @return List of proxy rules
*/
@NonNull
- public List<Pair<String, String>> getProxyRules() {
- return mProxyRules;
+ public List<ProxyRule> getProxyRules() {
+ return Collections.unmodifiableList(mProxyRules);
}
/**
@@ -102,7 +102,52 @@
*/
@NonNull
public List<String> getBypassRules() {
- return mBypassRules;
+ return Collections.unmodifiableList(mBypassRules);
+ }
+
+ /**
+ * Class that holds a scheme filter and a proxy URL.
+ */
+ public static final class ProxyRule {
+ private String mSchemeFilter;
+ private String mUrl;
+
+ /**
+ * @hide Internal use only
+ */
+ @RestrictTo(RestrictTo.Scope.LIBRARY)
+ public ProxyRule(@NonNull String schemeFilter, @NonNull String url) {
+ mSchemeFilter = schemeFilter;
+ mUrl = url;
+ }
+
+ /**
+ * @hide Internal use only
+ */
+ @RestrictTo(RestrictTo.Scope.LIBRARY)
+ public ProxyRule(@NonNull String url) {
+ this(ProxyConfig.MATCH_ALL_SCHEMES, url);
+ }
+
+ /**
+ * Returns the {@link String} that represents the scheme filter for this object.
+ *
+ * @return Scheme filter
+ */
+ @NonNull
+ public String getSchemeFilter() {
+ return mSchemeFilter;
+ }
+
+ /**
+ * Returns the {@link String} that represents the proxy URL for this object.
+ *
+ * @return Proxy URL
+ */
+ @NonNull
+ public String getUrl() {
+ return mUrl;
+ }
}
/**
@@ -115,7 +160,7 @@
* connections to be made directly.
*/
public static final class Builder {
- private List<Pair<String, String>> mProxyRules;
+ private List<ProxyRule> mProxyRules;
private List<String> mBypassRules;
/**
@@ -175,7 +220,8 @@
*/
@NonNull
public Builder addProxyRule(@NonNull String proxyUrl) {
- return addProxyRule(proxyUrl, MATCH_ALL_SCHEMES);
+ mProxyRules.add(new ProxyRule(proxyUrl));
+ return this;
}
/**
@@ -191,7 +237,7 @@
@NonNull
public Builder addProxyRule(@NonNull String proxyUrl,
@NonNull @ProxyScheme String schemeFilter) {
- mProxyRules.add(new Pair<>(schemeFilter, proxyUrl));
+ mProxyRules.add(new ProxyRule(schemeFilter, proxyUrl));
return this;
}
@@ -220,7 +266,7 @@
*/
@NonNull
public Builder addDirect(@NonNull @ProxyScheme String schemeFilter) {
- mProxyRules.add(new Pair<>(DIRECT, schemeFilter));
+ mProxyRules.add(new ProxyRule(schemeFilter, DIRECT));
return this;
}
@@ -271,7 +317,7 @@
}
@NonNull
- private List<Pair<String, String>> proxyRules() {
+ private List<ProxyRule> proxyRules() {
return mProxyRules;
}
diff --git a/webkit/src/main/java/androidx/webkit/internal/ProxyControllerImpl.java b/webkit/src/main/java/androidx/webkit/internal/ProxyControllerImpl.java
index c2b4675..fe8dbc8 100644
--- a/webkit/src/main/java/androidx/webkit/internal/ProxyControllerImpl.java
+++ b/webkit/src/main/java/androidx/webkit/internal/ProxyControllerImpl.java
@@ -17,7 +17,6 @@
package androidx.webkit.internal;
import androidx.annotation.NonNull;
-import androidx.core.util.Pair;
import androidx.webkit.ProxyConfig;
import androidx.webkit.ProxyController;
import androidx.webkit.WebViewFeature;
@@ -39,14 +38,15 @@
WebViewFeatureInternal webViewFeature =
WebViewFeatureInternal.getFeature(WebViewFeature.PROXY_OVERRIDE);
if (webViewFeature.isSupportedByWebView()) {
- List<Pair<String, String>> proxyRulesList = proxyConfig.getProxyRules();
+ List<ProxyConfig.ProxyRule> proxyRulesList = proxyConfig.getProxyRules();
// A 2D String array representation is required by reflection
String[][] proxyRulesArray = new String[proxyRulesList.size()][2];
for (int i = 0; i < proxyRulesList.size(); i++) {
- proxyRulesArray[i][0] = proxyRulesList.get(0).first;
- proxyRulesArray[i][1] = proxyRulesList.get(0).second;
+ proxyRulesArray[i][0] = proxyRulesList.get(0).getSchemeFilter();
+ proxyRulesArray[i][1] = proxyRulesList.get(0).getUrl();
}
+
getBoundaryInterface().setProxyOverride(proxyRulesArray,
proxyConfig.getBypassRules().toArray(new String[0]), listener, executor);
} else {