diff options
author | xunjieli <xunjieli@chromium.org> | 2014-09-18 10:33:56 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-09-18 17:34:06 +0000 |
commit | b50a78b4dabfffa36b1d847167458d4a961c29ca (patch) | |
tree | 9ac38cb3567ca9ca9c703654a28afd10e038dc2b /net | |
parent | 6d3ff1db3ac108434add039a91813fda93f7a027 (diff) | |
download | chromium_src-b50a78b4dabfffa36b1d847167458d4a961c29ca.zip chromium_src-b50a78b4dabfffa36b1d847167458d4a961c29ca.tar.gz chromium_src-b50a78b4dabfffa36b1d847167458d4a961c29ca.tar.bz2 |
Detect whether a PAC url is present on Android
This CL detects whether a PAC url is set in Android's system settings.
If there is a PAC url, use that PAC url to construct a ProxyConfig.
BUG=372475
Review URL: https://codereview.chromium.org/573013002
Cr-Commit-Position: refs/heads/master@{#295489}
Diffstat (limited to 'net')
-rw-r--r-- | net/android/java/src/org/chromium/net/ProxyChangeListener.java | 33 | ||||
-rw-r--r-- | net/proxy/proxy_config_service_android.cc | 27 | ||||
-rw-r--r-- | net/proxy/proxy_config_service_android.h | 7 |
3 files changed, 54 insertions, 13 deletions
diff --git a/net/android/java/src/org/chromium/net/ProxyChangeListener.java b/net/android/java/src/org/chromium/net/ProxyChangeListener.java index 63bfb30..b130da0 100644 --- a/net/android/java/src/org/chromium/net/ProxyChangeListener.java +++ b/net/android/java/src/org/chromium/net/ProxyChangeListener.java @@ -9,7 +9,9 @@ import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.net.Proxy; +import android.net.Uri; import android.os.Build; +import android.text.TextUtils; import android.util.Log; import org.chromium.base.CalledByNative; @@ -34,12 +36,14 @@ public class ProxyChangeListener { private Delegate mDelegate; private static class ProxyConfig { - public ProxyConfig(String host, int port) { + public ProxyConfig(String host, int port, String pacUrl) { mHost = host; mPort = port; + mPacUrl = pacUrl; } public final String mHost; public final int mPort; + public final String mPacUrl; } public interface Delegate { @@ -91,7 +95,7 @@ public class ProxyChangeListener { // Extract a ProxyConfig object from the supplied Intent's extra data // bundle. The android.net.ProxyProperties class is not exported from - // tne Android SDK, so we have to use reflection to get at it and invoke + // the Android SDK, so we have to use reflection to get at it and invoke // methods on it. If we fail, return an empty proxy config (meaning // 'direct'). // TODO(sgurun): once android.net.ProxyInfo is public, rewrite this. @@ -99,6 +103,7 @@ public class ProxyChangeListener { try { final String GET_HOST_NAME = "getHost"; final String GET_PORT_NAME = "getPort"; + final String GET_PAC_FILE_URL = "getPacFileUrl"; String className; String proxyInfo; if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT) { @@ -121,7 +126,23 @@ public class ProxyChangeListener { String host = (String) getHostMethod.invoke(props); int port = (Integer) getPortMethod.invoke(props); - return new ProxyConfig(host, port); + // TODO(xunjieli): rewrite this once the API is public. + if (Build.VERSION.SDK_INT == Build.VERSION_CODES.KITKAT) { + Method getPacFileUrlMethod = + cls.getDeclaredMethod(GET_PAC_FILE_URL); + String pacFileUrl = (String) getPacFileUrlMethod.invoke(props); + if (!TextUtils.isEmpty(pacFileUrl)) { + return new ProxyConfig(host, port, pacFileUrl); + } + } else if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT) { + Method getPacFileUrlMethod = + cls.getDeclaredMethod(GET_PAC_FILE_URL); + Uri pacFileUrl = (Uri) getPacFileUrlMethod.invoke(props); + if (!Uri.EMPTY.equals(pacFileUrl)) { + return new ProxyConfig(host, port, pacFileUrl.toString()); + } + } + return new ProxyConfig(host, port, null); } catch (ClassNotFoundException ex) { Log.e(TAG, "Using no proxy configuration due to exception:" + ex); return null; @@ -154,7 +175,7 @@ public class ProxyChangeListener { // Note that this code currently runs on a MESSAGE_LOOP_UI thread, but // the C++ code must run the callbacks on the network thread. if (cfg != null) { - nativeProxySettingsChangedTo(mNativePtr, cfg.mHost, cfg.mPort); + nativeProxySettingsChangedTo(mNativePtr, cfg.mHost, cfg.mPort, cfg.mPacUrl); } else { nativeProxySettingsChanged(mNativePtr); } @@ -184,7 +205,9 @@ public class ProxyChangeListener { @NativeClassQualifiedName("ProxyConfigServiceAndroid::JNIDelegate") private native void nativeProxySettingsChangedTo(long nativePtr, String host, - int port); + int port, + String pacUrl); + @NativeClassQualifiedName("ProxyConfigServiceAndroid::JNIDelegate") private native void nativeProxySettingsChanged(long nativePtr); } diff --git a/net/proxy/proxy_config_service_android.cc b/net/proxy/proxy_config_service_android.cc index 4f52aed..d27bc5a 100644 --- a/net/proxy/proxy_config_service_android.cc +++ b/net/proxy/proxy_config_service_android.cc @@ -159,9 +159,14 @@ std::string GetJavaProperty(const std::string& property) { std::string() : ConvertJavaStringToUTF8(env, result.obj()); } -void CreateStaticProxyConfig(const std::string& host, int port, +void CreateStaticProxyConfig(const std::string& host, + int port, + const std::string& pac_url, ProxyConfig* config) { - if (port != 0) { + if (!pac_url.empty()) { + config->set_pac_url(GURL(pac_url)); + config->set_pac_mandatory(false); + } else if (port != 0) { std::string rules = base::StringPrintf("%s:%d", host.c_str(), port); config->proxy_rules().ParseFromString(rules); } else { @@ -248,10 +253,12 @@ class ProxyConfigServiceAndroid::Delegate } // Called on the JNI thread. - void ProxySettingsChangedTo(const std::string& host, int port) { + void ProxySettingsChangedTo(const std::string& host, + int port, + const std::string& pac_url) { DCHECK(OnJNIThread()); ProxyConfig proxy_config; - CreateStaticProxyConfig(host, port, &proxy_config); + CreateStaticProxyConfig(host, port, pac_url, &proxy_config); network_task_runner_->PostTask( FROM_HERE, base::Bind( @@ -266,10 +273,16 @@ class ProxyConfigServiceAndroid::Delegate explicit JNIDelegateImpl(Delegate* delegate) : delegate_(delegate) {} // ProxyConfigServiceAndroid::JNIDelegate overrides. - virtual void ProxySettingsChangedTo(JNIEnv* env, jobject jself, - jstring jhost, jint jport) OVERRIDE { + virtual void ProxySettingsChangedTo(JNIEnv* env, + jobject jself, + jstring jhost, + jint jport, + jstring jpac_url) OVERRIDE { std::string host = ConvertJavaStringToUTF8(env, jhost); - delegate_->ProxySettingsChangedTo(host, jport); + std::string pac_url; + if (jpac_url) + ConvertJavaStringToUTF8(env, jpac_url, &pac_url); + delegate_->ProxySettingsChangedTo(host, jport, pac_url); } virtual void ProxySettingsChanged(JNIEnv* env, jobject self) OVERRIDE { diff --git a/net/proxy/proxy_config_service_android.h b/net/proxy/proxy_config_service_android.h index 7033e9d..ee54b94 100644 --- a/net/proxy/proxy_config_service_android.h +++ b/net/proxy/proxy_config_service_android.h @@ -41,7 +41,12 @@ class NET_EXPORT ProxyConfigServiceAndroid : public ProxyConfigService { // Called from Java (on JNI thread) to signal that the proxy settings have // changed. The string and int arguments (the host/port pair for the proxy) // are either a host/port pair or ("", 0) to indicate "no proxy". - virtual void ProxySettingsChangedTo(JNIEnv*, jobject, jstring, jint) = 0; + // The third argument indicates the PAC url. + virtual void ProxySettingsChangedTo(JNIEnv*, + jobject, + jstring, + jint, + jstring) = 0; // Called from Java (on JNI thread) to signal that the proxy settings have // changed. New proxy settings are fetched from the system property store. |