| 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 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 return NULL; | 370 return NULL; |
| 371 } | 371 } |
| 372 | 372 |
| 373 net::ProxyConfig::ProxyRules rules; | 373 net::ProxyConfig::ProxyRules rules; |
| 374 rules.ParseFromString(proxy_servers); | 374 rules.ParseFromString(proxy_servers); |
| 375 | 375 |
| 376 switch (rules.type) { | 376 switch (rules.type) { |
| 377 case net::ProxyConfig::ProxyRules::TYPE_NO_RULES: | 377 case net::ProxyConfig::ProxyRules::TYPE_NO_RULES: |
| 378 return NULL; | 378 return NULL; |
| 379 case net::ProxyConfig::ProxyRules::TYPE_SINGLE_PROXY: | 379 case net::ProxyConfig::ProxyRules::TYPE_SINGLE_PROXY: |
| 380 if (rules.single_proxy.is_valid()) { | 380 if (!rules.single_proxies.IsEmpty()) { |
| 381 extension_proxy_rules->Set(keys::field_name[keys::SCHEME_ALL], | 381 extension_proxy_rules->Set( |
| 382 CreateProxyServerDict(rules.single_proxy)); | 382 keys::field_name[keys::SCHEME_ALL], |
| 383 CreateProxyServerDict(rules.single_proxies.Get())); |
| 383 } | 384 } |
| 384 break; | 385 break; |
| 385 case net::ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME: | 386 case net::ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME: |
| 386 if (rules.proxy_for_http.is_valid()) { | 387 if (!rules.proxies_for_http.IsEmpty()) { |
| 387 extension_proxy_rules->Set(keys::field_name[keys::SCHEME_HTTP], | 388 extension_proxy_rules->Set( |
| 388 CreateProxyServerDict(rules.proxy_for_http)); | 389 keys::field_name[keys::SCHEME_HTTP], |
| 390 CreateProxyServerDict(rules.proxies_for_http.Get())); |
| 389 } | 391 } |
| 390 if (rules.proxy_for_https.is_valid()) { | 392 if (!rules.proxies_for_https.IsEmpty()) { |
| 391 extension_proxy_rules->Set( | 393 extension_proxy_rules->Set( |
| 392 keys::field_name[keys::SCHEME_HTTPS], | 394 keys::field_name[keys::SCHEME_HTTPS], |
| 393 CreateProxyServerDict(rules.proxy_for_https)); | 395 CreateProxyServerDict(rules.proxies_for_https.Get())); |
| 394 } | 396 } |
| 395 if (rules.proxy_for_ftp.is_valid()) { | 397 if (!rules.proxies_for_ftp.IsEmpty()) { |
| 396 extension_proxy_rules->Set(keys::field_name[keys::SCHEME_FTP], | 398 extension_proxy_rules->Set( |
| 397 CreateProxyServerDict(rules.proxy_for_ftp)); | 399 keys::field_name[keys::SCHEME_FTP], |
| 400 CreateProxyServerDict(rules.proxies_for_ftp.Get())); |
| 398 } | 401 } |
| 399 if (rules.fallback_proxy.is_valid()) { | 402 if (!rules.fallback_proxies.IsEmpty()) { |
| 400 extension_proxy_rules->Set(keys::field_name[keys::SCHEME_FALLBACK], | 403 extension_proxy_rules->Set( |
| 401 CreateProxyServerDict(rules.fallback_proxy)); | 404 keys::field_name[keys::SCHEME_FALLBACK], |
| 405 CreateProxyServerDict(rules.fallback_proxies.Get())); |
| 402 } | 406 } |
| 403 break; | 407 break; |
| 404 } | 408 } |
| 405 | 409 |
| 406 // If we add a new scheme some time, we need to also store a new dictionary | 410 // If we add a new scheme some time, we need to also store a new dictionary |
| 407 // representing this scheme in the code above. | 411 // representing this scheme in the code above. |
| 408 COMPILE_ASSERT(keys::SCHEME_MAX == 4, SCHEME_FORGOTTEN); | 412 COMPILE_ASSERT(keys::SCHEME_MAX == 4, SCHEME_FORGOTTEN); |
| 409 | 413 |
| 410 if (proxy_config.HasBypassList()) { | 414 if (proxy_config.HasBypassList()) { |
| 411 std::string bypass_list_string; | 415 std::string bypass_list_string; |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 481 const std::string& delims) { | 485 const std::string& delims) { |
| 482 ListValue* out = new ListValue; | 486 ListValue* out = new ListValue; |
| 483 base::StringTokenizer entries(in, delims); | 487 base::StringTokenizer entries(in, delims); |
| 484 while (entries.GetNext()) | 488 while (entries.GetNext()) |
| 485 out->Append(Value::CreateStringValue(entries.token())); | 489 out->Append(Value::CreateStringValue(entries.token())); |
| 486 return out; | 490 return out; |
| 487 } | 491 } |
| 488 | 492 |
| 489 } // namespace proxy_api_helpers | 493 } // namespace proxy_api_helpers |
| 490 } // namespace extensions | 494 } // namespace extensions |
| OLD | NEW |