From 41e7e6f9339cd9181df26ca96f0ac133371bc524 Mon Sep 17 00:00:00 2001 From: Kristian Monsen Date: Tue, 21 Dec 2010 12:51:11 +0000 Subject: [PATCH] Retrying sending proxy changes to webkit Now checking if the ProxyProperties object is null, and if the string returned by getHost() is null. Change-Id: I727e26c2a41fe057501c3b610ba6fa221d16da45 --- .../android/webkit/JWebCoreJavaBridge.java | 1 + core/java/android/webkit/WebView.java | 40 +++++++++++++++++++ core/java/android/webkit/WebViewCore.java | 10 +++++ 3 files changed, 51 insertions(+) diff --git a/core/java/android/webkit/JWebCoreJavaBridge.java b/core/java/android/webkit/JWebCoreJavaBridge.java index 908526f7680cb..976e7868c1196 100644 --- a/core/java/android/webkit/JWebCoreJavaBridge.java +++ b/core/java/android/webkit/JWebCoreJavaBridge.java @@ -307,4 +307,5 @@ final class JWebCoreJavaBridge extends Handler { public native void addPackageNames(Set packageNames); public native void addPackageName(String packageName); public native void removePackageName(String packageName); + public native void updateProxy(String newProxy); } diff --git a/core/java/android/webkit/WebView.java b/core/java/android/webkit/WebView.java index 885badab408a8..8e4852acb7c80 100644 --- a/core/java/android/webkit/WebView.java +++ b/core/java/android/webkit/WebView.java @@ -48,6 +48,8 @@ import android.graphics.RectF; import android.graphics.Region; import android.graphics.Shader; import android.graphics.drawable.Drawable; +import android.net.Proxy; +import android.net.ProxyProperties; import android.net.Uri; import android.net.http.SslCertificate; import android.os.AsyncTask; @@ -981,6 +983,7 @@ public class WebView extends AbsoluteLayout */ init(); setupPackageListener(context); + setupProxyListener(context); updateMultiTouchSupport(context); if (privateBrowsing) { @@ -990,6 +993,43 @@ public class WebView extends AbsoluteLayout mAutoFillData = new WebViewCore.AutoFillData(); } + private static class ProxyReceiver extends BroadcastReceiver { + @Override + public void onReceive(Context context, Intent intent) { + if (intent.getAction().equals(Proxy.PROXY_CHANGE_ACTION)) { + handleProxyBroadcast(intent); + } + } + } + + private static void setupProxyListener(Context context) { + IntentFilter filter = new IntentFilter(); + filter.addAction(Proxy.PROXY_CHANGE_ACTION); + Intent currentProxy = context.registerReceiver(new ProxyReceiver(), filter); + if (currentProxy != null) { + handleProxyBroadcast(currentProxy); + } + } + + private static void handleProxyBroadcast(Intent intent) { + ProxyProperties proxyProperties = (ProxyProperties)intent.getExtra(Proxy.EXTRA_PROXY_INFO); + if (proxyProperties == null || proxyProperties.getHost() == null) { + WebViewCore.sendStaticMessage(EventHub.PROXY_CHANGED, ""); + return; + } + + String host = proxyProperties.getHost(); + int port = proxyProperties.getPort(); + if (port != 0) + host += ": " + port; + + // TODO: Handle exclusion list + // The plan is to make an AndroidProxyResolver, and handle the blacklist + // there + String exclusionList = proxyProperties.getExclusionList(); + WebViewCore.sendStaticMessage(EventHub.PROXY_CHANGED, host); + } + /* * A variable to track if there is a receiver added for ACTION_PACKAGE_ADDED * or ACTION_PACKAGE_REMOVED. diff --git a/core/java/android/webkit/WebViewCore.java b/core/java/android/webkit/WebViewCore.java index f45fad92194cf..45927f9737c34 100644 --- a/core/java/android/webkit/WebViewCore.java +++ b/core/java/android/webkit/WebViewCore.java @@ -684,6 +684,14 @@ final class WebViewCore { } BrowserFrame.sJavaBridge.removePackageName((String) msg.obj); break; + + case EventHub.PROXY_CHANGED: + if (BrowserFrame.sJavaBridge == null) { + throw new IllegalStateException( + "No WebView has been created in this process!"); + } + BrowserFrame.sJavaBridge.updateProxy((String) msg.obj); + break; } } }; @@ -983,6 +991,8 @@ final class WebViewCore { static final int AUTOFILL_FORM = 192; + static final int PROXY_CHANGED = 193; + // private message ids private static final int DESTROY = 200;