| 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/prefs/proxy_config_dictionary.h" | 5 #include "chrome/browser/prefs/proxy_config_dictionary.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/values.h" | 9 #include "base/values.h" |
| 10 | 10 |
| 11 namespace { | 11 namespace { |
| 12 | 12 |
| 13 // Integer to specify the type of proxy settings. | 13 // Integer to specify the type of proxy settings. |
| 14 // See ProxyPrefs for possible values and interactions with the other proxy | 14 // See ProxyPrefs for possible values and interactions with the other proxy |
| 15 // preferences. | 15 // preferences. |
| 16 const char kProxyMode[] = "mode"; | 16 const char kProxyMode[] = "mode"; |
| 17 // String specifying the proxy server. For a specification of the expected | 17 // String specifying the proxy server. For a specification of the expected |
| 18 // syntax see net::ProxyConfig::ProxyRules::ParseFromString(). | 18 // syntax see net::ProxyConfig::ProxyRules::ParseFromString(). |
| 19 const char kProxyServer[] = "server"; | 19 const char kProxyServer[] = "server"; |
| 20 // URL to the proxy .pac file. | 20 // URL to the proxy .pac file. |
| 21 const char kProxyPacUrl[] = "pac_url"; | 21 const char kProxyPacUrl[] = "pac_url"; |
| 22 // Optional boolean flag indicating whether a valid PAC script is mandatory. |
| 23 // If true, network traffic does not fall back to direct connections in case the |
| 24 // PAC script is not available. |
| 25 const char kProxyPacMandatory[] = "pac_mandatory"; |
| 22 // String containing proxy bypass rules. For a specification of the | 26 // String containing proxy bypass rules. For a specification of the |
| 23 // expected syntax see net::ProxyBypassRules::ParseFromString(). | 27 // expected syntax see net::ProxyBypassRules::ParseFromString(). |
| 24 const char kProxyBypassList[] = "bypass_list"; | 28 const char kProxyBypassList[] = "bypass_list"; |
| 25 | 29 |
| 26 } // namespace | 30 } // namespace |
| 27 | 31 |
| 28 ProxyConfigDictionary::ProxyConfigDictionary(const DictionaryValue* dict) | 32 ProxyConfigDictionary::ProxyConfigDictionary(const DictionaryValue* dict) |
| 29 : dict_(dict->DeepCopy()) { | 33 : dict_(dict->DeepCopy()) { |
| 30 } | 34 } |
| 31 | 35 |
| 32 ProxyConfigDictionary::~ProxyConfigDictionary() {} | 36 ProxyConfigDictionary::~ProxyConfigDictionary() {} |
| 33 | 37 |
| 34 bool ProxyConfigDictionary::GetMode(ProxyPrefs::ProxyMode* out) const { | 38 bool ProxyConfigDictionary::GetMode(ProxyPrefs::ProxyMode* out) const { |
| 35 std::string mode_str; | 39 std::string mode_str; |
| 36 return dict_->GetString(kProxyMode, &mode_str) | 40 return dict_->GetString(kProxyMode, &mode_str) |
| 37 && StringToProxyMode(mode_str, out); | 41 && StringToProxyMode(mode_str, out); |
| 38 } | 42 } |
| 39 | 43 |
| 40 bool ProxyConfigDictionary::GetPacUrl(std::string* out) const { | 44 bool ProxyConfigDictionary::GetPacUrl(std::string* out) const { |
| 41 return dict_->GetString(kProxyPacUrl, out); | 45 return dict_->GetString(kProxyPacUrl, out); |
| 42 } | 46 } |
| 43 | 47 |
| 48 bool ProxyConfigDictionary::GetPacMandatory(bool* out) const { |
| 49 if (!dict_->HasKey(kProxyPacMandatory)) { |
| 50 *out = false; |
| 51 return true; |
| 52 } |
| 53 return dict_->GetBoolean(kProxyPacMandatory, out); |
| 54 } |
| 55 |
| 44 bool ProxyConfigDictionary::GetProxyServer(std::string* out) const { | 56 bool ProxyConfigDictionary::GetProxyServer(std::string* out) const { |
| 45 return dict_->GetString(kProxyServer, out); | 57 return dict_->GetString(kProxyServer, out); |
| 46 } | 58 } |
| 47 | 59 |
| 48 bool ProxyConfigDictionary::GetBypassList(std::string* out) const { | 60 bool ProxyConfigDictionary::GetBypassList(std::string* out) const { |
| 49 return dict_->GetString(kProxyBypassList, out); | 61 return dict_->GetString(kProxyBypassList, out); |
| 50 } | 62 } |
| 51 | 63 |
| 52 bool ProxyConfigDictionary::HasBypassList() const { | 64 bool ProxyConfigDictionary::HasBypassList() const { |
| 53 return dict_->HasKey(kProxyBypassList); | 65 return dict_->HasKey(kProxyBypassList); |
| 54 } | 66 } |
| 55 | 67 |
| 56 // static | 68 // static |
| 57 DictionaryValue* ProxyConfigDictionary::CreateDirect() { | 69 DictionaryValue* ProxyConfigDictionary::CreateDirect() { |
| 58 return CreateDictionary(ProxyPrefs::MODE_DIRECT, "", "", ""); | 70 return CreateDictionary(ProxyPrefs::MODE_DIRECT, "", false, "", ""); |
| 59 } | 71 } |
| 60 | 72 |
| 61 // static | 73 // static |
| 62 DictionaryValue* ProxyConfigDictionary::CreateAutoDetect() { | 74 DictionaryValue* ProxyConfigDictionary::CreateAutoDetect() { |
| 63 return CreateDictionary(ProxyPrefs::MODE_AUTO_DETECT, "", "", ""); | 75 return CreateDictionary(ProxyPrefs::MODE_AUTO_DETECT, "", false, "", ""); |
| 64 } | 76 } |
| 65 | 77 |
| 66 // static | 78 // static |
| 67 DictionaryValue* ProxyConfigDictionary::CreatePacScript( | 79 DictionaryValue* ProxyConfigDictionary::CreatePacScript( |
| 68 const std::string& pac_url) { | 80 const std::string& pac_url, |
| 69 return CreateDictionary(ProxyPrefs::MODE_PAC_SCRIPT, pac_url, "", ""); | 81 bool pac_mandatory) { |
| 82 return CreateDictionary(ProxyPrefs::MODE_PAC_SCRIPT, |
| 83 pac_url, pac_mandatory, "", ""); |
| 70 } | 84 } |
| 71 | 85 |
| 72 // static | 86 // static |
| 73 DictionaryValue* ProxyConfigDictionary::CreateFixedServers( | 87 DictionaryValue* ProxyConfigDictionary::CreateFixedServers( |
| 74 const std::string& proxy_server, | 88 const std::string& proxy_server, |
| 75 const std::string& bypass_list) { | 89 const std::string& bypass_list) { |
| 76 if (!proxy_server.empty()) { | 90 if (!proxy_server.empty()) { |
| 77 return CreateDictionary( | 91 return CreateDictionary( |
| 78 ProxyPrefs::MODE_FIXED_SERVERS, "", proxy_server, bypass_list); | 92 ProxyPrefs::MODE_FIXED_SERVERS, "", false, proxy_server, bypass_list); |
| 79 } else { | 93 } else { |
| 80 return CreateDirect(); | 94 return CreateDirect(); |
| 81 } | 95 } |
| 82 } | 96 } |
| 83 | 97 |
| 84 // static | 98 // static |
| 85 DictionaryValue* ProxyConfigDictionary::CreateSystem() { | 99 DictionaryValue* ProxyConfigDictionary::CreateSystem() { |
| 86 return CreateDictionary(ProxyPrefs::MODE_SYSTEM, "", "", ""); | 100 return CreateDictionary(ProxyPrefs::MODE_SYSTEM, "", false, "", ""); |
| 87 } | 101 } |
| 88 | 102 |
| 89 // static | 103 // static |
| 90 DictionaryValue* ProxyConfigDictionary::CreateDictionary( | 104 DictionaryValue* ProxyConfigDictionary::CreateDictionary( |
| 91 ProxyPrefs::ProxyMode mode, | 105 ProxyPrefs::ProxyMode mode, |
| 92 const std::string& pac_url, | 106 const std::string& pac_url, |
| 107 bool pac_mandatory, |
| 93 const std::string& proxy_server, | 108 const std::string& proxy_server, |
| 94 const std::string& bypass_list) { | 109 const std::string& bypass_list) { |
| 95 DictionaryValue* dict = new DictionaryValue(); | 110 DictionaryValue* dict = new DictionaryValue(); |
| 96 dict->SetString(kProxyMode, ProxyModeToString(mode)); | 111 dict->SetString(kProxyMode, ProxyModeToString(mode)); |
| 97 if (!pac_url.empty()) | 112 if (!pac_url.empty()) { |
| 98 dict->SetString(kProxyPacUrl, pac_url); | 113 dict->SetString(kProxyPacUrl, pac_url); |
| 114 dict->SetBoolean(kProxyPacMandatory, pac_mandatory); |
| 115 } |
| 99 if (!proxy_server.empty()) | 116 if (!proxy_server.empty()) |
| 100 dict->SetString(kProxyServer, proxy_server); | 117 dict->SetString(kProxyServer, proxy_server); |
| 101 if (!bypass_list.empty()) | 118 if (!bypass_list.empty()) |
| 102 dict->SetString(kProxyBypassList, bypass_list); | 119 dict->SetString(kProxyBypassList, bypass_list); |
| 103 return dict; | 120 return dict; |
| 104 } | 121 } |
| OLD | NEW |