| 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 // Generates a PAC proxy string component, including trailing semicolon and |
| 59 // space, for |origin|. Eg: |
| 60 // "http://foo.com/" -> "HTTP foo.com:80; " |
| 61 // "https://bar.com:10443" -> "HTTPS bar.coom:10443; " |
| 62 // The returned strings are suitable for concatenating into a PAC string. |
| 63 // If |origin| is empty, returns an empty string. |
| 64 std::string ProtocolAndHostForPACString(const std::string& origin) { |
| 65 if (origin.empty()) { |
| 66 return std::string(); |
| 67 } |
| 68 GURL url = GURL(origin); |
| 69 std::string protocol = url.SchemeIsSecure() ? "HTTPS " : "HTTP "; |
| 70 return protocol + net::HostPortPair::FromURL(url).ToString() + "; "; |
| 71 } |
| 72 |
| 58 } // namespace | 73 } // namespace |
| 59 | 74 |
| 60 DataReductionProxySettingsAndroid::DataReductionProxySettingsAndroid( | 75 DataReductionProxySettingsAndroid::DataReductionProxySettingsAndroid( |
| 61 JNIEnv* env, jobject obj): DataReductionProxySettings() { | 76 JNIEnv* env, jobject obj): DataReductionProxySettings() { |
| 62 } | 77 } |
| 63 | 78 |
| 64 DataReductionProxySettingsAndroid::~DataReductionProxySettingsAndroid() {} | 79 DataReductionProxySettingsAndroid::~DataReductionProxySettingsAndroid() {} |
| 65 | 80 |
| 66 void DataReductionProxySettingsAndroid::InitDataReductionProxySettings( | 81 void DataReductionProxySettingsAndroid::InitDataReductionProxySettings( |
| 67 JNIEnv* env, | 82 JNIEnv* env, |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 | 268 |
| 254 // TODO(bengr): Replace with our own ProxyResolver. | 269 // TODO(bengr): Replace with our own ProxyResolver. |
| 255 std::string DataReductionProxySettingsAndroid::GetProxyPacScript() { | 270 std::string DataReductionProxySettingsAndroid::GetProxyPacScript() { |
| 256 // Compose the PAC-only bypass code; these will be URL patterns that | 271 // Compose the PAC-only bypass code; these will be URL patterns that |
| 257 // are matched by regular expression. Host bypasses are handled outside | 272 // are matched by regular expression. Host bypasses are handled outside |
| 258 // of the PAC file using the regular proxy bypass list configs. | 273 // of the PAC file using the regular proxy bypass list configs. |
| 259 std::string bypass_clause = | 274 std::string bypass_clause = |
| 260 "(" + JoinString(pac_bypass_rules_, ") || (") + ")"; | 275 "(" + JoinString(pac_bypass_rules_, ") || (") + ")"; |
| 261 | 276 |
| 262 // Generate a proxy PAC that falls back to direct loading when the proxy is | 277 // 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 | 278 // unavailable and only process HTTP traffic. |
| 264 // proxy, proxy failures will simply result in a connection error presented to | |
| 265 // users.) | |
| 266 | 279 |
| 267 std::string proxy_host = | 280 std::string proxy_host = ProtocolAndHostForPACString( |
| 268 DataReductionProxySettings::GetDataReductionProxyOriginHostPort(); | 281 DataReductionProxySettings::GetDataReductionProxyOrigin()); |
| 282 std::string fallback_host = ProtocolAndHostForPACString( |
| 283 DataReductionProxySettings::GetDataReductionProxyFallback()); |
| 269 std::string pac = "function FindProxyForURL(url, host) {" | 284 std::string pac = "function FindProxyForURL(url, host) {" |
| 270 " if (" + bypass_clause + ") {" | 285 " if (" + bypass_clause + ") {" |
| 271 " return 'DIRECT';" | 286 " return 'DIRECT';" |
| 272 " } " | 287 " } " |
| 273 " if (url.substring(0, 5) == 'http:') {" | 288 " if (url.substring(0, 5) == 'http:') {" |
| 274 " return 'HTTPS " + proxy_host + | 289 " return '" + proxy_host + fallback_host + "DIRECT';" |
| 275 "; DIRECT';" | |
| 276 " }" | 290 " }" |
| 277 " return 'DIRECT';" | 291 " return 'DIRECT';" |
| 278 "}"; | 292 "}"; |
| 279 return pac; | 293 return pac; |
| 280 } | 294 } |
| 281 | 295 |
| 282 // Used by generated jni code. | 296 // Used by generated jni code. |
| 283 static jint Init(JNIEnv* env, jobject obj) { | 297 static jint Init(JNIEnv* env, jobject obj) { |
| 284 DataReductionProxySettingsAndroid* settings = | 298 DataReductionProxySettingsAndroid* settings = |
| 285 new DataReductionProxySettingsAndroid(env, obj); | 299 new DataReductionProxySettingsAndroid(env, obj); |
| 286 return reinterpret_cast<jint>(settings); | 300 return reinterpret_cast<jint>(settings); |
| 287 } | 301 } |
| OLD | NEW |