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 "components/proxy_config/proxy_config_dictionary.h" | 5 #include "components/proxy_config/proxy_config_dictionary.h" |
6 | 6 |
7 #include <utility> | |
8 | |
7 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/memory/ptr_util.h" | |
8 #include "base/values.h" | 11 #include "base/values.h" |
9 #include "net/proxy/proxy_config.h" | 12 #include "net/proxy/proxy_config.h" |
10 | 13 |
11 namespace { | 14 namespace { |
12 | 15 |
13 // Integer to specify the type of proxy settings. | 16 // Integer to specify the type of proxy settings. |
14 // See ProxyPrefs for possible values and interactions with the other proxy | 17 // See ProxyPrefs for possible values and interactions with the other proxy |
15 // preferences. | 18 // preferences. |
16 const char kProxyMode[] = "mode"; | 19 const char kProxyMode[] = "mode"; |
17 // String specifying the proxy server. For a specification of the expected | 20 // String specifying the proxy server. For a specification of the expected |
18 // syntax see net::ProxyConfig::ProxyRules::ParseFromString(). | 21 // syntax see net::ProxyConfig::ProxyRules::ParseFromString(). |
19 const char kProxyServer[] = "server"; | 22 const char kProxyServer[] = "server"; |
20 // URL to the proxy .pac file. | 23 // URL to the proxy .pac file. |
21 const char kProxyPacUrl[] = "pac_url"; | 24 const char kProxyPacUrl[] = "pac_url"; |
22 // Optional boolean flag indicating whether a valid PAC script is mandatory. | 25 // 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 | 26 // If true, network traffic does not fall back to direct connections in case the |
24 // PAC script is not available. | 27 // PAC script is not available. |
25 const char kProxyPacMandatory[] = "pac_mandatory"; | 28 const char kProxyPacMandatory[] = "pac_mandatory"; |
26 // String containing proxy bypass rules. For a specification of the | 29 // String containing proxy bypass rules. For a specification of the |
27 // expected syntax see net::ProxyBypassRules::ParseFromString(). | 30 // expected syntax see net::ProxyBypassRules::ParseFromString(). |
28 const char kProxyBypassList[] = "bypass_list"; | 31 const char kProxyBypassList[] = "bypass_list"; |
29 | 32 |
30 } // namespace | 33 } // namespace |
31 | 34 |
35 ProxyConfigDictionary::ProxyConfigDictionary( | |
36 std::unique_ptr<base::DictionaryValue> dict) | |
37 : dict_(std::move(dict)) {} | |
38 | |
32 ProxyConfigDictionary::ProxyConfigDictionary(const base::DictionaryValue* dict) | 39 ProxyConfigDictionary::ProxyConfigDictionary(const base::DictionaryValue* dict) |
33 : dict_(dict->DeepCopy()) { | 40 : dict_(dict->CreateDeepCopy()) {} |
34 } | |
35 | 41 |
36 ProxyConfigDictionary::~ProxyConfigDictionary() {} | 42 ProxyConfigDictionary::~ProxyConfigDictionary() {} |
37 | 43 |
38 bool ProxyConfigDictionary::GetMode(ProxyPrefs::ProxyMode* out) const { | 44 bool ProxyConfigDictionary::GetMode(ProxyPrefs::ProxyMode* out) const { |
39 std::string mode_str; | 45 std::string mode_str; |
40 return dict_->GetString(kProxyMode, &mode_str) | 46 return dict_->GetString(kProxyMode, &mode_str) |
41 && StringToProxyMode(mode_str, out); | 47 && StringToProxyMode(mode_str, out); |
42 } | 48 } |
43 | 49 |
44 bool ProxyConfigDictionary::GetPacUrl(std::string* out) const { | 50 bool ProxyConfigDictionary::GetPacUrl(std::string* out) const { |
(...skipping 18 matching lines...) Expand all Loading... | |
63 | 69 |
64 bool ProxyConfigDictionary::HasBypassList() const { | 70 bool ProxyConfigDictionary::HasBypassList() const { |
65 return dict_->HasKey(kProxyBypassList); | 71 return dict_->HasKey(kProxyBypassList); |
66 } | 72 } |
67 | 73 |
68 const base::DictionaryValue& ProxyConfigDictionary::GetDictionary() const { | 74 const base::DictionaryValue& ProxyConfigDictionary::GetDictionary() const { |
69 return *dict_; | 75 return *dict_; |
70 } | 76 } |
71 | 77 |
72 // static | 78 // static |
73 base::DictionaryValue* ProxyConfigDictionary::CreateDirect() { | 79 std::unique_ptr<base::DictionaryValue> ProxyConfigDictionary::CreateDirect() { |
74 return CreateDictionary(ProxyPrefs::MODE_DIRECT, | 80 return CreateDictionary(ProxyPrefs::MODE_DIRECT, |
75 std::string(), | 81 std::string(), |
76 false, | 82 false, |
77 std::string(), | 83 std::string(), |
78 std::string()); | 84 std::string()); |
79 } | 85 } |
80 | 86 |
81 // static | 87 // static |
82 base::DictionaryValue* ProxyConfigDictionary::CreateAutoDetect() { | 88 std::unique_ptr<base::DictionaryValue> |
89 ProxyConfigDictionary::CreateAutoDetect() { | |
83 return CreateDictionary(ProxyPrefs::MODE_AUTO_DETECT, | 90 return CreateDictionary(ProxyPrefs::MODE_AUTO_DETECT, |
84 std::string(), | 91 std::string(), |
85 false, | 92 false, |
86 std::string(), | 93 std::string(), |
87 std::string()); | 94 std::string()); |
88 } | 95 } |
89 | 96 |
90 // static | 97 // static |
91 base::DictionaryValue* ProxyConfigDictionary::CreatePacScript( | 98 std::unique_ptr<base::DictionaryValue> ProxyConfigDictionary::CreatePacScript( |
92 const std::string& pac_url, | 99 const std::string& pac_url, |
93 bool pac_mandatory) { | 100 bool pac_mandatory) { |
94 return CreateDictionary(ProxyPrefs::MODE_PAC_SCRIPT, | 101 return CreateDictionary(ProxyPrefs::MODE_PAC_SCRIPT, |
95 pac_url, | 102 pac_url, |
96 pac_mandatory, | 103 pac_mandatory, |
97 std::string(), | 104 std::string(), |
98 std::string()); | 105 std::string()); |
99 } | 106 } |
100 | 107 |
101 // static | 108 // static |
102 base::DictionaryValue* ProxyConfigDictionary::CreateFixedServers( | 109 std::unique_ptr<base::DictionaryValue> |
103 const std::string& proxy_server, | 110 ProxyConfigDictionary::CreateFixedServers(const std::string& proxy_server, |
104 const std::string& bypass_list) { | 111 const std::string& bypass_list) { |
105 if (!proxy_server.empty()) { | 112 if (!proxy_server.empty()) { |
106 return CreateDictionary(ProxyPrefs::MODE_FIXED_SERVERS, | 113 return CreateDictionary(ProxyPrefs::MODE_FIXED_SERVERS, |
107 std::string(), | 114 std::string(), |
108 false, | 115 false, |
109 proxy_server, | 116 proxy_server, |
110 bypass_list); | 117 bypass_list); |
111 } else { | 118 } else { |
112 return CreateDirect(); | 119 return CreateDirect(); |
113 } | 120 } |
114 } | 121 } |
115 | 122 |
116 // static | 123 // static |
117 base::DictionaryValue* ProxyConfigDictionary::CreateSystem() { | 124 std::unique_ptr<base::DictionaryValue> ProxyConfigDictionary::CreateSystem() { |
118 return CreateDictionary(ProxyPrefs::MODE_SYSTEM, | 125 return CreateDictionary(ProxyPrefs::MODE_SYSTEM, |
119 std::string(), | 126 std::string(), |
120 false, | 127 false, |
121 std::string(), | 128 std::string(), |
122 std::string()); | 129 std::string()); |
123 } | 130 } |
124 | 131 |
125 // static | 132 // static |
126 base::DictionaryValue* ProxyConfigDictionary::CreateDictionary( | 133 std::unique_ptr<base::DictionaryValue> ProxyConfigDictionary::CreateDictionary( |
127 ProxyPrefs::ProxyMode mode, | 134 ProxyPrefs::ProxyMode mode, |
128 const std::string& pac_url, | 135 const std::string& pac_url, |
129 bool pac_mandatory, | 136 bool pac_mandatory, |
130 const std::string& proxy_server, | 137 const std::string& proxy_server, |
131 const std::string& bypass_list) { | 138 const std::string& bypass_list) { |
132 base::DictionaryValue* dict = new base::DictionaryValue(); | 139 std::unique_ptr<base::DictionaryValue> dict = |
jdoerrie
2017/03/30 11:00:39
nit: auto
vabr (Chromium)
2017/03/30 12:07:41
Done.
| |
140 base::MakeUnique<base::DictionaryValue>(); | |
133 dict->SetString(kProxyMode, ProxyModeToString(mode)); | 141 dict->SetString(kProxyMode, ProxyModeToString(mode)); |
134 if (!pac_url.empty()) { | 142 if (!pac_url.empty()) { |
135 dict->SetString(kProxyPacUrl, pac_url); | 143 dict->SetString(kProxyPacUrl, pac_url); |
136 dict->SetBoolean(kProxyPacMandatory, pac_mandatory); | 144 dict->SetBoolean(kProxyPacMandatory, pac_mandatory); |
137 } | 145 } |
138 if (!proxy_server.empty()) | 146 if (!proxy_server.empty()) |
139 dict->SetString(kProxyServer, proxy_server); | 147 dict->SetString(kProxyServer, proxy_server); |
140 if (!bypass_list.empty()) | 148 if (!bypass_list.empty()) |
141 dict->SetString(kProxyBypassList, bypass_list); | 149 dict->SetString(kProxyBypassList, bypass_list); |
142 return dict; | 150 return dict; |
143 } | 151 } |
144 | 152 |
145 // static | 153 // static |
146 void ProxyConfigDictionary::EncodeAndAppendProxyServer( | 154 void ProxyConfigDictionary::EncodeAndAppendProxyServer( |
147 const std::string& url_scheme, | 155 const std::string& url_scheme, |
148 const net::ProxyServer& server, | 156 const net::ProxyServer& server, |
149 std::string* spec) { | 157 std::string* spec) { |
150 if (!server.is_valid()) | 158 if (!server.is_valid()) |
151 return; | 159 return; |
152 | 160 |
153 if (!spec->empty()) | 161 if (!spec->empty()) |
154 *spec += ';'; | 162 *spec += ';'; |
155 | 163 |
156 if (!url_scheme.empty()) { | 164 if (!url_scheme.empty()) { |
157 *spec += url_scheme; | 165 *spec += url_scheme; |
158 *spec += "="; | 166 *spec += "="; |
159 } | 167 } |
160 *spec += server.ToURI(); | 168 *spec += server.ToURI(); |
161 } | 169 } |
OLD | NEW |