OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_settings_android.h" | 5 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_settings_android.h" |
6 | 6 |
7 #include "base/android/build_info.h" | 7 #include "base/android/build_info.h" |
8 #include "base/android/jni_android.h" | 8 #include "base/android/jni_android.h" |
9 #include "base/android/jni_string.h" | 9 #include "base/android/jni_string.h" |
10 #include "base/base64.h" | 10 #include "base/base64.h" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
48 // New values should be added at the end before |NUM_SPDY_PROXY_AUTH_STATE|. | 48 // New values should be added at the end before |NUM_SPDY_PROXY_AUTH_STATE|. |
49 enum { | 49 enum { |
50 CHROME_STARTUP, | 50 CHROME_STARTUP, |
51 SPDY_PROXY_AUTH_ON_AT_STARTUP, | 51 SPDY_PROXY_AUTH_ON_AT_STARTUP, |
52 SPDY_PROXY_AUTH_ON_BY_USER, | 52 SPDY_PROXY_AUTH_ON_BY_USER, |
53 SPDY_PROXY_AUTH_OFF_BY_USER, | 53 SPDY_PROXY_AUTH_OFF_BY_USER, |
54 // Used by UMA histograms and should always be the last value. | 54 // Used by UMA histograms and should always be the last value. |
55 NUM_SPDY_PROXY_AUTH_STATE | 55 NUM_SPDY_PROXY_AUTH_STATE |
56 }; | 56 }; |
57 | 57 |
58 std::string ProtocolAndHost(std::string origin) { | |
bengr
2013/10/20 18:19:31
Please add a comment that describes the format of
| |
59 if (origin.empty()) { | |
60 return origin; | |
61 } | |
62 GURL url = GURL(origin); | |
63 std::string protocol = url.SchemeIsSecure() ? "HTTPS " : "HTTP "; | |
64 return protocol + net::HostPortPair::FromURL(url).ToString() + "; "; | |
65 } | |
66 | |
58 } // namespace | 67 } // namespace |
59 | 68 |
60 DataReductionProxySettingsAndroid::DataReductionProxySettingsAndroid( | 69 DataReductionProxySettingsAndroid::DataReductionProxySettingsAndroid( |
61 JNIEnv* env, jobject obj): DataReductionProxySettings() { | 70 JNIEnv* env, jobject obj): DataReductionProxySettings() { |
62 } | 71 } |
63 | 72 |
64 DataReductionProxySettingsAndroid::~DataReductionProxySettingsAndroid() {} | 73 DataReductionProxySettingsAndroid::~DataReductionProxySettingsAndroid() {} |
65 | 74 |
66 void DataReductionProxySettingsAndroid::InitDataReductionProxySettings( | 75 void DataReductionProxySettingsAndroid::InitDataReductionProxySettings( |
67 JNIEnv* env, | 76 JNIEnv* env, |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
253 | 262 |
254 // TODO(bengr): Replace with our own ProxyResolver. | 263 // TODO(bengr): Replace with our own ProxyResolver. |
255 std::string DataReductionProxySettingsAndroid::GetProxyPacScript() { | 264 std::string DataReductionProxySettingsAndroid::GetProxyPacScript() { |
256 // Compose the PAC-only bypass code; these will be URL patterns that | 265 // Compose the PAC-only bypass code; these will be URL patterns that |
257 // are matched by regular expression. Host bypasses are handled outside | 266 // are matched by regular expression. Host bypasses are handled outside |
258 // of the PAC file using the regular proxy bypass list configs. | 267 // of the PAC file using the regular proxy bypass list configs. |
259 std::string bypass_clause = | 268 std::string bypass_clause = |
260 "(" + JoinString(pac_bypass_rules_, ") || (") + ")"; | 269 "(" + JoinString(pac_bypass_rules_, ") || (") + ")"; |
261 | 270 |
262 // Generate a proxy PAC that falls back to direct loading when the proxy is | 271 // Generate a proxy PAC that falls back to direct loading when the proxy is |
263 // unavailable and only process HTTP traffic. (With a statically configured | 272 // unavailable and only process HTTP traffic. |
264 // proxy, proxy failures will simply result in a connection error presented to | |
265 // users.) | |
266 | 273 |
267 std::string proxy_host = | 274 std::string proxy_host = ProtocolAndHost( |
268 DataReductionProxySettings::GetDataReductionProxyOriginHostPort(); | 275 DataReductionProxySettings::GetDataReductionProxyOrigin()); |
276 std::string fallback_host = ProtocolAndHost( | |
277 DataReductionProxySettings::GetDataReductionProxyFallback()); | |
269 std::string pac = "function FindProxyForURL(url, host) {" | 278 std::string pac = "function FindProxyForURL(url, host) {" |
270 " if (" + bypass_clause + ") {" | 279 " if (" + bypass_clause + ") {" |
271 " return 'DIRECT';" | 280 " return 'DIRECT';" |
272 " } " | 281 " } " |
273 " if (url.substring(0, 5) == 'http:') {" | 282 " if (url.substring(0, 5) == 'http:') {" |
274 " return 'HTTPS " + proxy_host + | 283 " return '" + proxy_host + fallback_host + "DIRECT';" |
275 "; DIRECT';" | |
276 " }" | 284 " }" |
277 " return 'DIRECT';" | 285 " return 'DIRECT';" |
278 "}"; | 286 "}"; |
279 return pac; | 287 return pac; |
280 } | 288 } |
281 | 289 |
282 // Used by generated jni code. | 290 // Used by generated jni code. |
283 static jint Init(JNIEnv* env, jobject obj) { | 291 static jint Init(JNIEnv* env, jobject obj) { |
284 DataReductionProxySettingsAndroid* settings = | 292 DataReductionProxySettingsAndroid* settings = |
285 new DataReductionProxySettingsAndroid(env, obj); | 293 new DataReductionProxySettingsAndroid(env, obj); |
286 return reinterpret_cast<jint>(settings); | 294 return reinterpret_cast<jint>(settings); |
287 } | 295 } |
OLD | NEW |