diff --git a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/proxy/ProxyManager.java b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/proxy/ProxyManager.java index 261fdecb..f2b5b07f 100755 --- a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/proxy/ProxyManager.java +++ b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/proxy/ProxyManager.java @@ -84,6 +84,9 @@ public class ProxyManager extends ChannelDelegateImpl { if (settings.removeImplicitRules != null && settings.removeImplicitRules) { proxyConfigBuilder.removeImplicitRules(); } + if (settings.reverseBypassEnabled != null && WebViewFeature.isFeatureSupported(WebViewFeature.PROXY_OVERRIDE_REVERSE_BYPASS)) { + proxyConfigBuilder.setReverseBypassEnabled(settings.reverseBypassEnabled); + } proxyController.setProxyOverride(proxyConfigBuilder.build(), new Executor() { @Override public void execute(Runnable command) { diff --git a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/proxy/ProxySettings.java b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/proxy/ProxySettings.java index bd2ae74b..953834d2 100644 --- a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/proxy/ProxySettings.java +++ b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/proxy/ProxySettings.java @@ -17,6 +17,7 @@ public class ProxySettings implements ISettings { List proxyRules = new ArrayList<>(); Boolean bypassSimpleHostnames = null; Boolean removeImplicitRules = null; + Boolean reverseBypassEnabled = false; @NonNull @Override @@ -51,6 +52,9 @@ public class ProxySettings implements ISettings { case "removeImplicitRules": removeImplicitRules = (Boolean) value; break; + case "reverseBypassEnabled": + reverseBypassEnabled = (Boolean) value; + break; } } @@ -70,6 +74,7 @@ public class ProxySettings implements ISettings { settings.put("proxyRules", proxyRuleMapList); settings.put("bypassSimpleHostnames", bypassSimpleHostnames); settings.put("removeImplicitRules", removeImplicitRules); + settings.put("reverseBypassEnabled", reverseBypassEnabled); return settings; } @@ -87,6 +92,7 @@ public class ProxySettings implements ISettings { } realSettings.put("bypassRules", proxyConfig.getBypassRules()); realSettings.put("proxyRules", proxyRuleMapList); + realSettings.put("reverseBypassEnabled", proxyConfig.isReverseBypassEnabled()); return realSettings; } } diff --git a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/types/ProxyRuleExt.java b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/types/ProxyRuleExt.java index f6b12b8f..25ec9fd9 100644 --- a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/types/ProxyRuleExt.java +++ b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/types/ProxyRuleExt.java @@ -2,17 +2,19 @@ package com.pichillilorenzo.flutter_inappwebview.types; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import androidx.webkit.ProxyConfig; import java.util.HashMap; import java.util.Map; public class ProxyRuleExt { @Nullable + @ProxyConfig.ProxyScheme private String schemeFilter; @NonNull private String url; - public ProxyRuleExt(@Nullable String schemeFilter, @NonNull String url) { + public ProxyRuleExt(@Nullable @ProxyConfig.ProxyScheme String schemeFilter, @NonNull String url) { this.schemeFilter = schemeFilter; this.url = url; } diff --git a/lib/src/android/proxy_controller.dart b/lib/src/android/proxy_controller.dart index fb16ac1a..ce0f438a 100644 --- a/lib/src/android/proxy_controller.dart +++ b/lib/src/android/proxy_controller.dart @@ -115,12 +115,24 @@ class ProxySettings { ///Set this to `true` to override the default behavior and force localhost and link-local URLs to be sent through the proxy. bool? removeImplicitRules; + ///Reverse the bypass list. + /// + ///The default value is `false`, in which case all URLs will use proxy settings except the ones in the bypass list, which will be connected to directly instead. + /// + ///If set to `true`, then only URLs in the bypass list will use these proxy settings, and all other URLs will be connected to directly. + /// + ///Use [bypassRules] to add bypass rules. + /// + ///**NOTE**: available only if [WebViewFeature.PROXY_OVERRIDE_REVERSE_BYPASS] feature is supported. + bool reverseBypassEnabled; + ProxySettings( {this.bypassRules = const [], this.directs = const [], this.proxyRules = const [], this.bypassSimpleHostnames, - this.removeImplicitRules}); + this.removeImplicitRules, + this.reverseBypassEnabled = false}); Map toMap() { return { @@ -128,7 +140,8 @@ class ProxySettings { "directs": directs, "proxyRules": proxyRules.map((e) => e.toMap()).toList(), "bypassSimpleHostnames": bypassSimpleHostnames, - "removeImplicitRules": removeImplicitRules + "removeImplicitRules": removeImplicitRules, + "reverseBypassEnabled": reverseBypassEnabled }; } @@ -141,6 +154,7 @@ class ProxySettings { .map((e) => ProxyRule.fromMap(e)) as List; settings.bypassSimpleHostnames = map["bypassSimpleHostnames"]; settings.removeImplicitRules = map["removeImplicitRules"]; + settings.reverseBypassEnabled = map["reverseBypassEnabled"]; return settings; } diff --git a/lib/src/android/webview_feature.dart b/lib/src/android/webview_feature.dart index 811a38e7..dcd12605 100644 --- a/lib/src/android/webview_feature.dart +++ b/lib/src/android/webview_feature.dart @@ -66,6 +66,10 @@ class WebViewFeature_ { static const PROXY_OVERRIDE = const WebViewFeature_._internal("PROXY_OVERRIDE"); + ///This feature covers [ProxySettings.reverseBypassEnabled]. + static const PROXY_OVERRIDE_REVERSE_BYPASS = + const WebViewFeature_._internal("PROXY_OVERRIDE_REVERSE_BYPASS"); + /// static const RECEIVE_HTTP_ERROR = const WebViewFeature_._internal("RECEIVE_HTTP_ERROR");