| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/extensions/extension_proxy_api.h" | 5 #include "chrome/browser/extensions/extension_proxy_api.h" |
| 6 | 6 |
| 7 #include "base/string_util.h" | 7 #include "base/string_util.h" |
| 8 #include "base/stringprintf.h" | 8 #include "base/stringprintf.h" |
| 9 #include "base/values.h" | 9 #include "base/values.h" |
| 10 #include "chrome/browser/prefs/proxy_prefs.h" | 10 #include "chrome/browser/prefs/proxy_prefs.h" |
| 11 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
| 12 #include "chrome/browser/extensions/extension_service.h" | 12 #include "chrome/browser/extensions/extension_service.h" |
| 13 #include "chrome/common/pref_names.h" | 13 #include "chrome/common/pref_names.h" |
| 14 | 14 |
| 15 namespace { | 15 namespace { |
| 16 | 16 |
| 17 // The scheme for which to use a manually specified proxy, not of the proxy URI | 17 // The scheme for which to use a manually specified proxy, not of the proxy URI |
| 18 // itself. | 18 // itself. |
| 19 enum { | 19 enum { |
| 20 SCHEME_ALL = 0, | 20 SCHEME_ALL = 0, |
| 21 SCHEME_HTTP, | 21 SCHEME_HTTP, |
| 22 SCHEME_HTTPS, | 22 SCHEME_HTTPS, |
| 23 SCHEME_HTTPSV, |
| 23 SCHEME_FTP, | 24 SCHEME_FTP, |
| 24 SCHEME_SOCKS, | 25 SCHEME_SOCKS, |
| 25 SCHEME_MAX = SCHEME_SOCKS // Keep this value up to date. | 26 SCHEME_MAX = SCHEME_SOCKS // Keep this value up to date. |
| 26 }; | 27 }; |
| 27 | 28 |
| 28 // The names of the JavaScript properties to extract from the proxy_rules. | 29 // The names of the JavaScript properties to extract from the proxy_rules. |
| 29 // These must be kept in sync with the SCHEME_* constants. | 30 // These must be kept in sync with the SCHEME_* constants. |
| 30 const char* field_name[] = { "singleProxy", | 31 const char* field_name[] = { "singleProxy", |
| 31 "proxyForHttp", | 32 "proxyForHttp", |
| 32 "proxyForHttps", | 33 "proxyForHttps", |
| 34 "proxyForHttpsv", |
| 33 "proxyForFtp", | 35 "proxyForFtp", |
| 34 "socksProxy" }; | 36 "socksProxy" }; |
| 35 | 37 |
| 36 // The names of the schemes to be used to build the preference value string | 38 // The names of the schemes to be used to build the preference value string |
| 37 // for manual proxy settings. These must be kept in sync with the SCHEME_* | 39 // for manual proxy settings. These must be kept in sync with the SCHEME_* |
| 38 // constants. | 40 // constants. |
| 39 const char* scheme_name[] = { "*error*", | 41 const char* scheme_name[] = { "*error*", |
| 40 "http", | 42 "http", |
| 41 "https", | 43 "https", |
| 44 "httpsv", |
| 42 "ftp", | 45 "ftp", |
| 43 "socks" }; | 46 "socks" }; |
| 44 | 47 |
| 45 } // namespace | 48 } // namespace |
| 46 | 49 |
| 47 COMPILE_ASSERT(SCHEME_MAX == SCHEME_SOCKS, SCHEME_MAX_must_equal_SCHEME_SOCKS); | 50 COMPILE_ASSERT(SCHEME_MAX == SCHEME_SOCKS, SCHEME_MAX_must_equal_SCHEME_SOCKS); |
| 48 COMPILE_ASSERT(arraysize(field_name) == SCHEME_MAX + 1, | 51 COMPILE_ASSERT(arraysize(field_name) == SCHEME_MAX + 1, |
| 49 field_name_array_is_wrong_size); | 52 field_name_array_is_wrong_size); |
| 50 COMPILE_ASSERT(arraysize(scheme_name) == SCHEME_MAX + 1, | 53 COMPILE_ASSERT(arraysize(scheme_name) == SCHEME_MAX + 1, |
| 51 scheme_name_array_is_wrong_size); | 54 scheme_name_array_is_wrong_size); |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 if (has_proxy[i]) { | 156 if (has_proxy[i]) { |
| 154 if (!GetProxyServer(proxy_dict[i], &proxy_server[i])) | 157 if (!GetProxyServer(proxy_dict[i], &proxy_server[i])) |
| 155 return false; | 158 return false; |
| 156 } | 159 } |
| 157 } | 160 } |
| 158 | 161 |
| 159 // A single proxy supersedes individual HTTP, HTTPS, and FTP proxies. | 162 // A single proxy supersedes individual HTTP, HTTPS, and FTP proxies. |
| 160 if (has_proxy[SCHEME_ALL]) { | 163 if (has_proxy[SCHEME_ALL]) { |
| 161 proxy_server[SCHEME_HTTP] = proxy_server[SCHEME_ALL]; | 164 proxy_server[SCHEME_HTTP] = proxy_server[SCHEME_ALL]; |
| 162 proxy_server[SCHEME_HTTPS] = proxy_server[SCHEME_ALL]; | 165 proxy_server[SCHEME_HTTPS] = proxy_server[SCHEME_ALL]; |
| 166 proxy_server[SCHEME_HTTPSV] = proxy_server[SCHEME_ALL]; |
| 163 proxy_server[SCHEME_FTP] = proxy_server[SCHEME_ALL]; | 167 proxy_server[SCHEME_FTP] = proxy_server[SCHEME_ALL]; |
| 164 has_proxy[SCHEME_HTTP] = true; | 168 has_proxy[SCHEME_HTTP] = true; |
| 165 has_proxy[SCHEME_HTTPS] = true; | 169 has_proxy[SCHEME_HTTPS] = true; |
| 170 has_proxy[SCHEME_HTTPSV] = true; |
| 166 has_proxy[SCHEME_FTP] = true; | 171 has_proxy[SCHEME_FTP] = true; |
| 167 has_proxy[SCHEME_ALL] = false; | 172 has_proxy[SCHEME_ALL] = false; |
| 168 } | 173 } |
| 169 | 174 |
| 170 // TODO(pamg): Ensure that if a value is empty, that means "don't use a proxy | 175 // TODO(pamg): Ensure that if a value is empty, that means "don't use a proxy |
| 171 // for this scheme". | 176 // for this scheme". |
| 172 | 177 |
| 173 // Build the proxy preference string. | 178 // Build the proxy preference string. |
| 174 std::string proxy_pref; | 179 std::string proxy_pref; |
| 175 for (size_t i = 0; i <= SCHEME_MAX; ++i) { | 180 for (size_t i = 0; i <= SCHEME_MAX; ++i) { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 196 | 201 |
| 197 bool RemoveCustomProxySettingsFunction::RunImpl() { | 202 bool RemoveCustomProxySettingsFunction::RunImpl() { |
| 198 bool incognito = false; | 203 bool incognito = false; |
| 199 args_->GetBoolean(0, &incognito); | 204 args_->GetBoolean(0, &incognito); |
| 200 | 205 |
| 201 RemovePreference(prefs::kProxyMode, incognito); | 206 RemovePreference(prefs::kProxyMode, incognito); |
| 202 RemovePreference(prefs::kProxyPacUrl, incognito); | 207 RemovePreference(prefs::kProxyPacUrl, incognito); |
| 203 RemovePreference(prefs::kProxyServer, incognito); | 208 RemovePreference(prefs::kProxyServer, incognito); |
| 204 return true; | 209 return true; |
| 205 } | 210 } |
| OLD | NEW |