summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsgurun <sgurun@chromium.org>2014-10-10 19:18:57 -0700
committerCommit bot <commit-bot@chromium.org>2014-10-11 02:19:19 +0000
commit9ac8056f252382a8fdffa89a8db3df9675d0bfd8 (patch)
treeae1a6e79264c7a374172ff9e34080409532870a7
parent7faaa25711b1ded3674bda660b84fb47f22632e8 (diff)
downloadchromium_src-9ac8056f252382a8fdffa89a8db3df9675d0bfd8.zip
chromium_src-9ac8056f252382a8fdffa89a8db3df9675d0bfd8.tar.gz
chromium_src-9ac8056f252382a8fdffa89a8db3df9675d0bfd8.tar.bz2
Use Android proxy's exclusion list to enable proxy bypass
Based on Android AOSP submission https://android-review.googlesource.com/#/c/102054/ Author: Jianzheng Zhou jianzheng.zhou@freescale.com BUG= Review URL: https://codereview.chromium.org/421493002 Cr-Commit-Position: refs/heads/master@{#299231}
-rw-r--r--net/android/java/src/org/chromium/net/ProxyChangeListener.java29
-rw-r--r--net/proxy/proxy_config_service_android.cc25
-rw-r--r--net/proxy/proxy_config_service_android.h4
3 files changed, 46 insertions, 12 deletions
diff --git a/net/android/java/src/org/chromium/net/ProxyChangeListener.java b/net/android/java/src/org/chromium/net/ProxyChangeListener.java
index 51b6714..be09be4 100644
--- a/net/android/java/src/org/chromium/net/ProxyChangeListener.java
+++ b/net/android/java/src/org/chromium/net/ProxyChangeListener.java
@@ -36,16 +36,21 @@ public class ProxyChangeListener {
private Delegate mDelegate;
private static class ProxyConfig {
- public ProxyConfig(String host, int port, String pacUrl) {
+ public ProxyConfig(String host, int port, String pacUrl, String[] exclusionList) {
mHost = host;
mPort = port;
mPacUrl = pacUrl;
+ mExclusionList = exclusionList;
}
public final String mHost;
public final int mPort;
public final String mPacUrl;
+ public final String[] mExclusionList;
}
+ /**
+ * The delegate for ProxyChangeListener. Use for testing.
+ */
public interface Delegate {
public void proxySettingsChanged();
}
@@ -104,6 +109,7 @@ public class ProxyChangeListener {
final String getHostName = "getHost";
final String getPortName = "getPort";
final String getPacFileUrl = "getPacFileUrl";
+ final String getExclusionList = "getExclusionList";
String className;
String proxyInfo;
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT) {
@@ -122,27 +128,35 @@ public class ProxyChangeListener {
Class<?> cls = Class.forName(className);
Method getHostMethod = cls.getDeclaredMethod(getHostName);
Method getPortMethod = cls.getDeclaredMethod(getPortName);
+ Method getExclusionListMethod = cls.getDeclaredMethod(getExclusionList);
String host = (String) getHostMethod.invoke(props);
int port = (Integer) getPortMethod.invoke(props);
+ String[] exclusionList;
+ if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT) {
+ String s = (String) getExclusionListMethod.invoke(props);
+ exclusionList = s.split(",");
+ } else {
+ exclusionList = (String[]) getExclusionListMethod.invoke(props);
+ }
// TODO(xunjieli): rewrite this once the API is public.
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.KITKAT) {
Method getPacFileUrlMethod =
cls.getDeclaredMethod(getPacFileUrl);
String pacFileUrl = (String) getPacFileUrlMethod.invoke(props);
if (!TextUtils.isEmpty(pacFileUrl)) {
- return new ProxyConfig(host, port, pacFileUrl);
+ return new ProxyConfig(host, port, pacFileUrl, exclusionList);
}
} else if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT) {
Method getPacFileUrlMethod =
cls.getDeclaredMethod(getPacFileUrl);
Uri pacFileUrl = (Uri) getPacFileUrlMethod.invoke(props);
if (!Uri.EMPTY.equals(pacFileUrl)) {
- return new ProxyConfig(host, port, pacFileUrl.toString());
+ return new ProxyConfig(host, port, pacFileUrl.toString(), exclusionList);
}
}
- return new ProxyConfig(host, port, null);
+ return new ProxyConfig(host, port, null, exclusionList);
} catch (ClassNotFoundException ex) {
Log.e(TAG, "Using no proxy configuration due to exception:" + ex);
return null;
@@ -175,7 +189,8 @@ 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, cfg.mPacUrl);
+ nativeProxySettingsChangedTo(mNativePtr, cfg.mHost, cfg.mPort, cfg.mPacUrl,
+ cfg.mExclusionList);
} else {
nativeProxySettingsChanged(mNativePtr);
}
@@ -206,8 +221,8 @@ public class ProxyChangeListener {
private native void nativeProxySettingsChangedTo(long nativePtr,
String host,
int port,
- String pacUrl);
-
+ String pacUrl,
+ String[] exclusionList);
@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 b294689..f1a0b6c 100644
--- a/net/proxy/proxy_config_service_android.cc
+++ b/net/proxy/proxy_config_service_android.cc
@@ -6,6 +6,7 @@
#include <sys/system_properties.h>
+#include "base/android/jni_array.h"
#include "base/android/jni_string.h"
#include "base/basictypes.h"
#include "base/bind.h"
@@ -162,6 +163,7 @@ std::string GetJavaProperty(const std::string& property) {
void CreateStaticProxyConfig(const std::string& host,
int port,
const std::string& pac_url,
+ const std::vector<std::string>& exclusion_list,
ProxyConfig* config) {
if (!pac_url.empty()) {
config->set_pac_url(GURL(pac_url));
@@ -169,6 +171,16 @@ void CreateStaticProxyConfig(const std::string& host,
} else if (port != 0) {
std::string rules = base::StringPrintf("%s:%d", host.c_str(), port);
config->proxy_rules().ParseFromString(rules);
+ config->proxy_rules().bypass_rules.Clear();
+
+ std::vector<std::string>::const_iterator it;
+ for (it = exclusion_list.begin(); it != exclusion_list.end(); ++it) {
+ std::string pattern;
+ base::TrimWhitespaceASCII(*it, base::TRIM_ALL, &pattern);
+ if (pattern.empty())
+ continue;
+ config->proxy_rules().bypass_rules.AddRuleForHostname("", pattern, -1);
+ }
} else {
*config = ProxyConfig::CreateDirect();
}
@@ -255,10 +267,11 @@ class ProxyConfigServiceAndroid::Delegate
// Called on the JNI thread.
void ProxySettingsChangedTo(const std::string& host,
int port,
- const std::string& pac_url) {
+ const std::string& pac_url,
+ const std::vector<std::string>& exclusion_list) {
DCHECK(OnJNIThread());
ProxyConfig proxy_config;
- CreateStaticProxyConfig(host, port, pac_url, &proxy_config);
+ CreateStaticProxyConfig(host, port, pac_url, exclusion_list, &proxy_config);
network_task_runner_->PostTask(
FROM_HERE,
base::Bind(
@@ -277,12 +290,16 @@ class ProxyConfigServiceAndroid::Delegate
jobject jself,
jstring jhost,
jint jport,
- jstring jpac_url) override {
+ jstring jpac_url,
+ jobjectArray jexclusion_list) override {
std::string host = ConvertJavaStringToUTF8(env, jhost);
std::string pac_url;
if (jpac_url)
ConvertJavaStringToUTF8(env, jpac_url, &pac_url);
- delegate_->ProxySettingsChangedTo(host, jport, pac_url);
+ std::vector<std::string> exclusion_list;
+ base::android::AppendJavaStringArrayToStringVector(
+ env, jexclusion_list, &exclusion_list);
+ delegate_->ProxySettingsChangedTo(host, jport, pac_url, exclusion_list);
}
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 82c27f7..d642d37 100644
--- a/net/proxy/proxy_config_service_android.h
+++ b/net/proxy/proxy_config_service_android.h
@@ -42,11 +42,13 @@ class NET_EXPORT ProxyConfigServiceAndroid : public ProxyConfigService {
// 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".
// The third argument indicates the PAC url.
+ // The fourth argument is the proxy exclusion list.
virtual void ProxySettingsChangedTo(JNIEnv*,
jobject,
jstring,
jint,
- jstring) = 0;
+ jstring,
+ jobjectArray) = 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.