Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(111)

Side by Side Diff: chrome/browser/extensions/api/proxy/proxy_api_helpers.cc

Issue 12315019: Change ProxyRules to handle ProxyLists rather than just single ProxyServer instances. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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(keys::field_name[keys::SCHEME_ALL],
382 CreateProxyServerDict(rules.single_proxy)); 382 CreateProxyServerDict(rules.single_proxies));
383 } 383 }
384 break; 384 break;
385 case net::ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME: 385 case net::ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME:
386 if (rules.proxy_for_http.is_valid()) { 386 if (!rules.proxies_for_http.IsEmpty()) {
387 extension_proxy_rules->Set(keys::field_name[keys::SCHEME_HTTP], 387 extension_proxy_rules->Set(
388 CreateProxyServerDict(rules.proxy_for_http)); 388 keys::field_name[keys::SCHEME_HTTP],
389 CreateProxyServerDict(rules.proxies_for_http));
389 } 390 }
390 if (rules.proxy_for_https.is_valid()) { 391 if (!rules.proxies_for_https.IsEmpty()) {
391 extension_proxy_rules->Set( 392 extension_proxy_rules->Set(
392 keys::field_name[keys::SCHEME_HTTPS], 393 keys::field_name[keys::SCHEME_HTTPS],
393 CreateProxyServerDict(rules.proxy_for_https)); 394 CreateProxyServerDict(rules.proxies_for_https));
394 } 395 }
395 if (rules.proxy_for_ftp.is_valid()) { 396 if (!rules.proxies_for_ftp.IsEmpty()) {
396 extension_proxy_rules->Set(keys::field_name[keys::SCHEME_FTP], 397 extension_proxy_rules->Set(
397 CreateProxyServerDict(rules.proxy_for_ftp)); 398 keys::field_name[keys::SCHEME_FTP],
399 CreateProxyServerDict(rules.proxies_for_ftp));
398 } 400 }
399 if (rules.fallback_proxy.is_valid()) { 401 if (!rules.fallback_proxies.IsEmpty()) {
400 extension_proxy_rules->Set(keys::field_name[keys::SCHEME_FALLBACK], 402 extension_proxy_rules->Set(
401 CreateProxyServerDict(rules.fallback_proxy)); 403 keys::field_name[keys::SCHEME_FALLBACK],
404 CreateProxyServerDict(rules.fallback_proxies));
402 } 405 }
403 break; 406 break;
404 } 407 }
405 408
406 // If we add a new scheme some time, we need to also store a new dictionary 409 // If we add a new scheme some time, we need to also store a new dictionary
407 // representing this scheme in the code above. 410 // representing this scheme in the code above.
408 COMPILE_ASSERT(keys::SCHEME_MAX == 4, SCHEME_FORGOTTEN); 411 COMPILE_ASSERT(keys::SCHEME_MAX == 4, SCHEME_FORGOTTEN);
409 412
410 if (proxy_config.HasBypassList()) { 413 if (proxy_config.HasBypassList()) {
411 std::string bypass_list_string; 414 std::string bypass_list_string;
412 if (!proxy_config.GetBypassList(&bypass_list_string)) { 415 if (!proxy_config.GetBypassList(&bypass_list_string)) {
413 LOG(ERROR) << "Invalid bypassList in configuration."; 416 LOG(ERROR) << "Invalid bypassList in configuration.";
414 return NULL; 417 return NULL;
415 } 418 }
416 ListValue* bypass_list = TokenizeToStringList(bypass_list_string, ",;"); 419 ListValue* bypass_list = TokenizeToStringList(bypass_list_string, ",;");
417 extension_proxy_rules->Set(keys::kProxyConfigBypassList, bypass_list); 420 extension_proxy_rules->Set(keys::kProxyConfigBypassList, bypass_list);
418 } 421 }
419 422
420 return extension_proxy_rules.release(); 423 return extension_proxy_rules.release();
421 } 424 }
422 425
423 DictionaryValue* CreateProxyServerDict(const net::ProxyServer& proxy) { 426 DictionaryValue* CreateProxyServerDict(const net::ProxyList& proxies) {
427 CHECK(proxies.size() == 1);
battre 2013/03/07 10:18:54 I think this can cause trouble. See CommandLinePre
marq_use_my_chromium_address 2013/03/07 20:26:15 Yeah, this is bad. Removed.
428 net::ProxyServer proxy = proxies.Get();
424 scoped_ptr<DictionaryValue> out(new DictionaryValue); 429 scoped_ptr<DictionaryValue> out(new DictionaryValue);
425 switch (proxy.scheme()) { 430 switch (proxy.scheme()) {
426 case net::ProxyServer::SCHEME_HTTP: 431 case net::ProxyServer::SCHEME_HTTP:
427 out->SetString(keys::kProxyConfigRuleScheme, "http"); 432 out->SetString(keys::kProxyConfigRuleScheme, "http");
428 break; 433 break;
429 case net::ProxyServer::SCHEME_HTTPS: 434 case net::ProxyServer::SCHEME_HTTPS:
430 out->SetString(keys::kProxyConfigRuleScheme, "https"); 435 out->SetString(keys::kProxyConfigRuleScheme, "https");
431 break; 436 break;
432 case net::ProxyServer::SCHEME_SOCKS4: 437 case net::ProxyServer::SCHEME_SOCKS4:
433 out->SetString(keys::kProxyConfigRuleScheme, "socks4"); 438 out->SetString(keys::kProxyConfigRuleScheme, "socks4");
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
481 const std::string& delims) { 486 const std::string& delims) {
482 ListValue* out = new ListValue; 487 ListValue* out = new ListValue;
483 base::StringTokenizer entries(in, delims); 488 base::StringTokenizer entries(in, delims);
484 while (entries.GetNext()) 489 while (entries.GetNext())
485 out->Append(Value::CreateStringValue(entries.token())); 490 out->Append(Value::CreateStringValue(entries.token()));
486 return out; 491 return out;
487 } 492 }
488 493
489 } // namespace proxy_api_helpers 494 } // namespace proxy_api_helpers
490 } // namespace extensions 495 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/proxy/proxy_api_helpers.h ('k') | chrome/browser/importer/firefox_proxy_settings.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698