OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // Implementation of helper functions for the Chrome Extensions Proxy Settings | 5 // Implementation of helper functions for the Chrome Extensions Proxy Settings |
6 // API. | 6 // API. |
7 // | 7 // |
8 // Throughout this code, we report errors to the user by setting an |error| | 8 // Throughout this code, we report errors to the user by setting an |error| |
9 // parameter, if and only if these errors can be cause by invalid input | 9 // parameter, if and only if these errors can be cause by invalid input |
10 // from the extension and we cannot expect that the extensions API has | 10 // from the extension and we cannot expect that the extensions API has |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 if (has_proxy[i]) { | 213 if (has_proxy[i]) { |
214 net::ProxyServer::Scheme default_scheme = net::ProxyServer::SCHEME_HTTP; | 214 net::ProxyServer::Scheme default_scheme = net::ProxyServer::SCHEME_HTTP; |
215 if (!GetProxyServer(proxy_dict, default_scheme, | 215 if (!GetProxyServer(proxy_dict, default_scheme, |
216 &proxy_server[i], error, bad_message)) { | 216 &proxy_server[i], error, bad_message)) { |
217 // Don't set |error| here, as GetProxyServer takes care of that. | 217 // Don't set |error| here, as GetProxyServer takes care of that. |
218 return false; | 218 return false; |
219 } | 219 } |
220 } | 220 } |
221 } | 221 } |
222 | 222 |
223 COMPILE_ASSERT(keys::SCHEME_ALL == 0, singleProxy_must_be_first_option); | 223 static_assert(keys::SCHEME_ALL == 0, "SCHEME_ALL must be the first value"); |
224 | 224 |
225 // Handle case that only singleProxy is specified. | 225 // Handle case that only singleProxy is specified. |
226 if (has_proxy[keys::SCHEME_ALL]) { | 226 if (has_proxy[keys::SCHEME_ALL]) { |
227 for (size_t i = 1; i <= keys::SCHEME_MAX; ++i) { | 227 for (size_t i = 1; i <= keys::SCHEME_MAX; ++i) { |
228 if (has_proxy[i]) { | 228 if (has_proxy[i]) { |
229 *error = ErrorUtils::FormatErrorMessage( | 229 *error = ErrorUtils::FormatErrorMessage( |
230 "Proxy rule for * and * cannot be set at the same time.", | 230 "Proxy rule for * and * cannot be set at the same time.", |
231 keys::field_name[keys::SCHEME_ALL], keys::field_name[i]); | 231 keys::field_name[keys::SCHEME_ALL], keys::field_name[i]); |
232 return false; | 232 return false; |
233 } | 233 } |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
402 CreateProxyServerDict(rules.proxies_for_ftp.Get())); | 402 CreateProxyServerDict(rules.proxies_for_ftp.Get())); |
403 } | 403 } |
404 if (!rules.fallback_proxies.IsEmpty()) { | 404 if (!rules.fallback_proxies.IsEmpty()) { |
405 extension_proxy_rules->Set( | 405 extension_proxy_rules->Set( |
406 keys::field_name[keys::SCHEME_FALLBACK], | 406 keys::field_name[keys::SCHEME_FALLBACK], |
407 CreateProxyServerDict(rules.fallback_proxies.Get())); | 407 CreateProxyServerDict(rules.fallback_proxies.Get())); |
408 } | 408 } |
409 break; | 409 break; |
410 } | 410 } |
411 | 411 |
412 // If we add a new scheme some time, we need to also store a new dictionary | 412 // If we add a new scheme sometime, we need to also store a new dictionary |
413 // representing this scheme in the code above. | 413 // representing this scheme in the code above. |
414 COMPILE_ASSERT(keys::SCHEME_MAX == 4, SCHEME_FORGOTTEN); | 414 static_assert(keys::SCHEME_MAX == 4, |
| 415 "rules need to be updated along with schemes"); |
415 | 416 |
416 if (proxy_config.HasBypassList()) { | 417 if (proxy_config.HasBypassList()) { |
417 std::string bypass_list_string; | 418 std::string bypass_list_string; |
418 if (!proxy_config.GetBypassList(&bypass_list_string)) { | 419 if (!proxy_config.GetBypassList(&bypass_list_string)) { |
419 LOG(ERROR) << "Invalid bypassList in configuration."; | 420 LOG(ERROR) << "Invalid bypassList in configuration."; |
420 return NULL; | 421 return NULL; |
421 } | 422 } |
422 base::ListValue* bypass_list = | 423 base::ListValue* bypass_list = |
423 TokenizeToStringList(bypass_list_string, ",;"); | 424 TokenizeToStringList(bypass_list_string, ",;"); |
424 extension_proxy_rules->Set(keys::kProxyConfigBypassList, bypass_list); | 425 extension_proxy_rules->Set(keys::kProxyConfigBypassList, bypass_list); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
491 const std::string& delims) { | 492 const std::string& delims) { |
492 base::ListValue* out = new base::ListValue; | 493 base::ListValue* out = new base::ListValue; |
493 base::StringTokenizer entries(in, delims); | 494 base::StringTokenizer entries(in, delims); |
494 while (entries.GetNext()) | 495 while (entries.GetNext()) |
495 out->Append(new base::StringValue(entries.token())); | 496 out->Append(new base::StringValue(entries.token())); |
496 return out; | 497 return out; |
497 } | 498 } |
498 | 499 |
499 } // namespace proxy_api_helpers | 500 } // namespace proxy_api_helpers |
500 } // namespace extensions | 501 } // namespace extensions |
OLD | NEW |