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

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

Issue 16915006: Convert most of extensions and some other random stuff to using the base namespace for Values. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 6 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 | Annotate | Revision Log
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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 if (!url.is_valid()) 51 if (!url.is_valid())
52 return false; 52 return false;
53 53
54 std::string mime_type; 54 std::string mime_type;
55 std::string charset; 55 std::string charset;
56 return net::DataURL::Parse(url, &mime_type, &charset, pac_script); 56 return net::DataURL::Parse(url, &mime_type, &charset, pac_script);
57 } 57 }
58 58
59 // Extension Pref -> Browser Pref conversion. 59 // Extension Pref -> Browser Pref conversion.
60 60
61 bool GetProxyModeFromExtensionPref(const DictionaryValue* proxy_config, 61 bool GetProxyModeFromExtensionPref(const base::DictionaryValue* proxy_config,
62 ProxyPrefs::ProxyMode* out, 62 ProxyPrefs::ProxyMode* out,
63 std::string* error, 63 std::string* error,
64 bool* bad_message) { 64 bool* bad_message) {
65 std::string proxy_mode; 65 std::string proxy_mode;
66 66
67 // We can safely assume that this is ASCII due to the allowed enumeration 67 // We can safely assume that this is ASCII due to the allowed enumeration
68 // values specified in the extension API JSON. 68 // values specified in the extension API JSON.
69 proxy_config->GetStringASCII(keys::kProxyConfigMode, &proxy_mode); 69 proxy_config->GetStringASCII(keys::kProxyConfigMode, &proxy_mode);
70 if (!ProxyPrefs::StringToProxyMode(proxy_mode, out)) { 70 if (!ProxyPrefs::StringToProxyMode(proxy_mode, out)) {
71 LOG(ERROR) << "Invalid mode for proxy settings: " << proxy_mode; 71 LOG(ERROR) << "Invalid mode for proxy settings: " << proxy_mode;
72 *bad_message = true; 72 *bad_message = true;
73 return false; 73 return false;
74 } 74 }
75 return true; 75 return true;
76 } 76 }
77 77
78 bool GetPacMandatoryFromExtensionPref(const DictionaryValue* proxy_config, 78 bool GetPacMandatoryFromExtensionPref(const base::DictionaryValue* proxy_config,
79 bool* out, 79 bool* out,
80 std::string* error, 80 std::string* error,
81 bool* bad_message){ 81 bool* bad_message){
82 const DictionaryValue* pac_dict = NULL; 82 const base::DictionaryValue* pac_dict = NULL;
83 proxy_config->GetDictionary(keys::kProxyConfigPacScript, &pac_dict); 83 proxy_config->GetDictionary(keys::kProxyConfigPacScript, &pac_dict);
84 if (!pac_dict) 84 if (!pac_dict)
85 return true; 85 return true;
86 86
87 bool mandatory_pac = false; 87 bool mandatory_pac = false;
88 if (pac_dict->HasKey(keys::kProxyConfigPacScriptMandatory) && 88 if (pac_dict->HasKey(keys::kProxyConfigPacScriptMandatory) &&
89 !pac_dict->GetBoolean(keys::kProxyConfigPacScriptMandatory, 89 !pac_dict->GetBoolean(keys::kProxyConfigPacScriptMandatory,
90 &mandatory_pac)) { 90 &mandatory_pac)) {
91 LOG(ERROR) << "'pacScript.mandatory' could not be parsed."; 91 LOG(ERROR) << "'pacScript.mandatory' could not be parsed.";
92 *bad_message = true; 92 *bad_message = true;
93 return false; 93 return false;
94 } 94 }
95 *out = mandatory_pac; 95 *out = mandatory_pac;
96 return true; 96 return true;
97 } 97 }
98 98
99 bool GetPacUrlFromExtensionPref(const DictionaryValue* proxy_config, 99 bool GetPacUrlFromExtensionPref(const base::DictionaryValue* proxy_config,
100 std::string* out, 100 std::string* out,
101 std::string* error, 101 std::string* error,
102 bool* bad_message) { 102 bool* bad_message) {
103 const DictionaryValue* pac_dict = NULL; 103 const base::DictionaryValue* pac_dict = NULL;
104 proxy_config->GetDictionary(keys::kProxyConfigPacScript, &pac_dict); 104 proxy_config->GetDictionary(keys::kProxyConfigPacScript, &pac_dict);
105 if (!pac_dict) 105 if (!pac_dict)
106 return true; 106 return true;
107 107
108 // TODO(battre): Handle UTF-8 URLs (http://crbug.com/72692). 108 // TODO(battre): Handle UTF-8 URLs (http://crbug.com/72692).
109 string16 pac_url16; 109 string16 pac_url16;
110 if (pac_dict->HasKey(keys::kProxyConfigPacScriptUrl) && 110 if (pac_dict->HasKey(keys::kProxyConfigPacScriptUrl) &&
111 !pac_dict->GetString(keys::kProxyConfigPacScriptUrl, &pac_url16)) { 111 !pac_dict->GetString(keys::kProxyConfigPacScriptUrl, &pac_url16)) {
112 LOG(ERROR) << "'pacScript.url' could not be parsed."; 112 LOG(ERROR) << "'pacScript.url' could not be parsed.";
113 *bad_message = true; 113 *bad_message = true;
114 return false; 114 return false;
115 } 115 }
116 if (!IsStringASCII(pac_url16)) { 116 if (!IsStringASCII(pac_url16)) {
117 *error = "'pacScript.url' supports only ASCII URLs " 117 *error = "'pacScript.url' supports only ASCII URLs "
118 "(encode URLs in Punycode format)."; 118 "(encode URLs in Punycode format).";
119 return false; 119 return false;
120 } 120 }
121 *out = UTF16ToASCII(pac_url16); 121 *out = UTF16ToASCII(pac_url16);
122 return true; 122 return true;
123 } 123 }
124 124
125 bool GetPacDataFromExtensionPref(const DictionaryValue* proxy_config, 125 bool GetPacDataFromExtensionPref(const base::DictionaryValue* proxy_config,
126 std::string* out, 126 std::string* out,
127 std::string* error, 127 std::string* error,
128 bool* bad_message) { 128 bool* bad_message) {
129 const DictionaryValue* pac_dict = NULL; 129 const base::DictionaryValue* pac_dict = NULL;
130 proxy_config->GetDictionary(keys::kProxyConfigPacScript, &pac_dict); 130 proxy_config->GetDictionary(keys::kProxyConfigPacScript, &pac_dict);
131 if (!pac_dict) 131 if (!pac_dict)
132 return true; 132 return true;
133 133
134 string16 pac_data16; 134 string16 pac_data16;
135 if (pac_dict->HasKey(keys::kProxyConfigPacScriptData) && 135 if (pac_dict->HasKey(keys::kProxyConfigPacScriptData) &&
136 !pac_dict->GetString(keys::kProxyConfigPacScriptData, &pac_data16)) { 136 !pac_dict->GetString(keys::kProxyConfigPacScriptData, &pac_data16)) {
137 LOG(ERROR) << "'pacScript.data' could not be parsed."; 137 LOG(ERROR) << "'pacScript.data' could not be parsed.";
138 *bad_message = true; 138 *bad_message = true;
139 return false; 139 return false;
140 } 140 }
141 if (!IsStringASCII(pac_data16)) { 141 if (!IsStringASCII(pac_data16)) {
142 *error = "'pacScript.data' supports only ASCII code" 142 *error = "'pacScript.data' supports only ASCII code"
143 "(encode URLs in Punycode format)."; 143 "(encode URLs in Punycode format).";
144 return false; 144 return false;
145 } 145 }
146 *out = UTF16ToASCII(pac_data16); 146 *out = UTF16ToASCII(pac_data16);
147 return true; 147 return true;
148 } 148 }
149 149
150 bool GetProxyServer(const DictionaryValue* proxy_server, 150 bool GetProxyServer(const base::DictionaryValue* proxy_server,
151 net::ProxyServer::Scheme default_scheme, 151 net::ProxyServer::Scheme default_scheme,
152 net::ProxyServer* out, 152 net::ProxyServer* out,
153 std::string* error, 153 std::string* error,
154 bool* bad_message) { 154 bool* bad_message) {
155 std::string scheme_string; // optional. 155 std::string scheme_string; // optional.
156 156
157 // We can safely assume that this is ASCII due to the allowed enumeration 157 // We can safely assume that this is ASCII due to the allowed enumeration
158 // values specified in the extension API JSON. 158 // values specified in the extension API JSON.
159 proxy_server->GetStringASCII(keys::kProxyConfigRuleScheme, &scheme_string); 159 proxy_server->GetStringASCII(keys::kProxyConfigRuleScheme, &scheme_string);
160 160
(...skipping 20 matching lines...) Expand all
181 181
182 int port; // optional. 182 int port; // optional.
183 if (!proxy_server->GetInteger(keys::kProxyConfigRulePort, &port)) 183 if (!proxy_server->GetInteger(keys::kProxyConfigRulePort, &port))
184 port = net::ProxyServer::GetDefaultPortForScheme(scheme); 184 port = net::ProxyServer::GetDefaultPortForScheme(scheme);
185 185
186 *out = net::ProxyServer(scheme, net::HostPortPair(host, port)); 186 *out = net::ProxyServer(scheme, net::HostPortPair(host, port));
187 187
188 return true; 188 return true;
189 } 189 }
190 190
191 bool GetProxyRulesStringFromExtensionPref(const DictionaryValue* proxy_config, 191 bool GetProxyRulesStringFromExtensionPref(
192 std::string* out, 192 const base::DictionaryValue* proxy_config,
193 std::string* error, 193 std::string* out,
194 bool* bad_message) { 194 std::string* error,
195 const DictionaryValue* proxy_rules = NULL; 195 bool* bad_message) {
196 const base::DictionaryValue* proxy_rules = NULL;
196 proxy_config->GetDictionary(keys::kProxyConfigRules, &proxy_rules); 197 proxy_config->GetDictionary(keys::kProxyConfigRules, &proxy_rules);
197 if (!proxy_rules) 198 if (!proxy_rules)
198 return true; 199 return true;
199 200
200 // Local data into which the parameters will be parsed. has_proxy describes 201 // Local data into which the parameters will be parsed. has_proxy describes
201 // whether a setting was found for the scheme; proxy_server holds the 202 // whether a setting was found for the scheme; proxy_server holds the
202 // respective ProxyServer objects containing those descriptions. 203 // respective ProxyServer objects containing those descriptions.
203 bool has_proxy[keys::SCHEME_MAX + 1]; 204 bool has_proxy[keys::SCHEME_MAX + 1];
204 net::ProxyServer proxy_server[keys::SCHEME_MAX + 1]; 205 net::ProxyServer proxy_server[keys::SCHEME_MAX + 1];
205 206
206 // Looking for all possible proxy types is inefficient if we have a 207 // Looking for all possible proxy types is inefficient if we have a
207 // singleProxy that will supersede per-URL proxies, but it's worth it to keep 208 // singleProxy that will supersede per-URL proxies, but it's worth it to keep
208 // the code simple and extensible. 209 // the code simple and extensible.
209 for (size_t i = 0; i <= keys::SCHEME_MAX; ++i) { 210 for (size_t i = 0; i <= keys::SCHEME_MAX; ++i) {
210 const DictionaryValue* proxy_dict = NULL; 211 const base::DictionaryValue* proxy_dict = NULL;
211 has_proxy[i] = proxy_rules->GetDictionary(keys::field_name[i], 212 has_proxy[i] = proxy_rules->GetDictionary(keys::field_name[i],
212 &proxy_dict); 213 &proxy_dict);
213 if (has_proxy[i]) { 214 if (has_proxy[i]) {
214 net::ProxyServer::Scheme default_scheme = net::ProxyServer::SCHEME_HTTP; 215 net::ProxyServer::Scheme default_scheme = net::ProxyServer::SCHEME_HTTP;
215 if (!GetProxyServer(proxy_dict, default_scheme, 216 if (!GetProxyServer(proxy_dict, default_scheme,
216 &proxy_server[i], error, bad_message)) { 217 &proxy_server[i], error, bad_message)) {
217 // Don't set |error| here, as GetProxyServer takes care of that. 218 // Don't set |error| here, as GetProxyServer takes care of that.
218 return false; 219 return false;
219 } 220 }
220 } 221 }
(...skipping 27 matching lines...) Expand all
248 proxy_pref.append(keys::scheme_name[i]); 249 proxy_pref.append(keys::scheme_name[i]);
249 proxy_pref.append("="); 250 proxy_pref.append("=");
250 proxy_pref.append(proxy_server[i].ToURI()); 251 proxy_pref.append(proxy_server[i].ToURI());
251 } 252 }
252 } 253 }
253 254
254 *out = proxy_pref; 255 *out = proxy_pref;
255 return true; 256 return true;
256 } 257 }
257 258
258 bool JoinUrlList(const ListValue* list, 259 bool JoinUrlList(const base::ListValue* list,
259 const std::string& joiner, 260 const std::string& joiner,
260 std::string* out, 261 std::string* out,
261 std::string* error, 262 std::string* error,
262 bool* bad_message) { 263 bool* bad_message) {
263 std::string result; 264 std::string result;
264 for (size_t i = 0; i < list->GetSize(); ++i) { 265 for (size_t i = 0; i < list->GetSize(); ++i) {
265 if (!result.empty()) 266 if (!result.empty())
266 result.append(joiner); 267 result.append(joiner);
267 268
268 // TODO(battre): handle UTF-8 (http://crbug.com/72692). 269 // TODO(battre): handle UTF-8 (http://crbug.com/72692).
269 string16 entry; 270 string16 entry;
270 if (!list->GetString(i, &entry)) { 271 if (!list->GetString(i, &entry)) {
271 LOG(ERROR) << "'rules.bypassList' could not be parsed."; 272 LOG(ERROR) << "'rules.bypassList' could not be parsed.";
272 *bad_message = true; 273 *bad_message = true;
273 return false; 274 return false;
274 } 275 }
275 if (!IsStringASCII(entry)) { 276 if (!IsStringASCII(entry)) {
276 *error = "'rules.bypassList' supports only ASCII URLs " 277 *error = "'rules.bypassList' supports only ASCII URLs "
277 "(encode URLs in Punycode format)."; 278 "(encode URLs in Punycode format).";
278 return false; 279 return false;
279 } 280 }
280 result.append(UTF16ToASCII(entry)); 281 result.append(UTF16ToASCII(entry));
281 } 282 }
282 *out = result; 283 *out = result;
283 return true; 284 return true;
284 } 285 }
285 286
286 bool GetBypassListFromExtensionPref(const DictionaryValue* proxy_config, 287 bool GetBypassListFromExtensionPref(const base::DictionaryValue* proxy_config,
287 std::string* out, 288 std::string* out,
288 std::string* error, 289 std::string* error,
289 bool* bad_message) { 290 bool* bad_message) {
290 const DictionaryValue* proxy_rules = NULL; 291 const base::DictionaryValue* proxy_rules = NULL;
291 proxy_config->GetDictionary(keys::kProxyConfigRules, &proxy_rules); 292 proxy_config->GetDictionary(keys::kProxyConfigRules, &proxy_rules);
292 if (!proxy_rules) 293 if (!proxy_rules)
293 return true; 294 return true;
294 295
295 if (!proxy_rules->HasKey(keys::kProxyConfigBypassList)) { 296 if (!proxy_rules->HasKey(keys::kProxyConfigBypassList)) {
296 *out = ""; 297 *out = "";
297 return true; 298 return true;
298 } 299 }
299 const ListValue* bypass_list = NULL; 300 const base::ListValue* bypass_list = NULL;
300 if (!proxy_rules->GetList(keys::kProxyConfigBypassList, &bypass_list)) { 301 if (!proxy_rules->GetList(keys::kProxyConfigBypassList, &bypass_list)) {
301 LOG(ERROR) << "'rules.bypassList' could not be parsed."; 302 LOG(ERROR) << "'rules.bypassList' could not be parsed.";
302 *bad_message = true; 303 *bad_message = true;
303 return false; 304 return false;
304 } 305 }
305 306
306 return JoinUrlList(bypass_list, ",", out, error, bad_message); 307 return JoinUrlList(bypass_list, ",", out, error, bad_message);
307 } 308 }
308 309
309 DictionaryValue* CreateProxyConfigDict(ProxyPrefs::ProxyMode mode_enum, 310 base::DictionaryValue* CreateProxyConfigDict(
310 bool pac_mandatory, 311 ProxyPrefs::ProxyMode mode_enum,
311 const std::string& pac_url, 312 bool pac_mandatory,
312 const std::string& pac_data, 313 const std::string& pac_url,
313 const std::string& proxy_rules_string, 314 const std::string& pac_data,
314 const std::string& bypass_list, 315 const std::string& proxy_rules_string,
315 std::string* error) { 316 const std::string& bypass_list,
316 DictionaryValue* result_proxy_config = NULL; 317 std::string* error) {
318 base::DictionaryValue* result_proxy_config = NULL;
317 switch (mode_enum) { 319 switch (mode_enum) {
318 case ProxyPrefs::MODE_DIRECT: 320 case ProxyPrefs::MODE_DIRECT:
319 result_proxy_config = ProxyConfigDictionary::CreateDirect(); 321 result_proxy_config = ProxyConfigDictionary::CreateDirect();
320 break; 322 break;
321 case ProxyPrefs::MODE_AUTO_DETECT: 323 case ProxyPrefs::MODE_AUTO_DETECT:
322 result_proxy_config = ProxyConfigDictionary::CreateAutoDetect(); 324 result_proxy_config = ProxyConfigDictionary::CreateAutoDetect();
323 break; 325 break;
324 case ProxyPrefs::MODE_PAC_SCRIPT: { 326 case ProxyPrefs::MODE_PAC_SCRIPT: {
325 std::string url; 327 std::string url;
326 if (!pac_url.empty()) { 328 if (!pac_url.empty()) {
(...skipping 23 matching lines...) Expand all
350 } 352 }
351 case ProxyPrefs::MODE_SYSTEM: 353 case ProxyPrefs::MODE_SYSTEM:
352 result_proxy_config = ProxyConfigDictionary::CreateSystem(); 354 result_proxy_config = ProxyConfigDictionary::CreateSystem();
353 break; 355 break;
354 case ProxyPrefs::kModeCount: 356 case ProxyPrefs::kModeCount:
355 NOTREACHED(); 357 NOTREACHED();
356 } 358 }
357 return result_proxy_config; 359 return result_proxy_config;
358 } 360 }
359 361
360 DictionaryValue* CreateProxyRulesDict( 362 base::DictionaryValue* CreateProxyRulesDict(
361 const ProxyConfigDictionary& proxy_config) { 363 const ProxyConfigDictionary& proxy_config) {
362 ProxyPrefs::ProxyMode mode; 364 ProxyPrefs::ProxyMode mode;
363 CHECK(proxy_config.GetMode(&mode) && mode == ProxyPrefs::MODE_FIXED_SERVERS); 365 CHECK(proxy_config.GetMode(&mode) && mode == ProxyPrefs::MODE_FIXED_SERVERS);
364 366
365 scoped_ptr<DictionaryValue> extension_proxy_rules(new DictionaryValue); 367 scoped_ptr<base::DictionaryValue> extension_proxy_rules(
368 new base::DictionaryValue);
366 369
367 std::string proxy_servers; 370 std::string proxy_servers;
368 if (!proxy_config.GetProxyServer(&proxy_servers)) { 371 if (!proxy_config.GetProxyServer(&proxy_servers)) {
369 LOG(ERROR) << "Missing proxy servers in configuration."; 372 LOG(ERROR) << "Missing proxy servers in configuration.";
370 return NULL; 373 return NULL;
371 } 374 }
372 375
373 net::ProxyConfig::ProxyRules rules; 376 net::ProxyConfig::ProxyRules rules;
374 rules.ParseFromString(proxy_servers); 377 rules.ParseFromString(proxy_servers);
375 378
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 // If we add a new scheme some time, we need to also store a new dictionary 413 // If we add a new scheme some time, we need to also store a new dictionary
411 // representing this scheme in the code above. 414 // representing this scheme in the code above.
412 COMPILE_ASSERT(keys::SCHEME_MAX == 4, SCHEME_FORGOTTEN); 415 COMPILE_ASSERT(keys::SCHEME_MAX == 4, SCHEME_FORGOTTEN);
413 416
414 if (proxy_config.HasBypassList()) { 417 if (proxy_config.HasBypassList()) {
415 std::string bypass_list_string; 418 std::string bypass_list_string;
416 if (!proxy_config.GetBypassList(&bypass_list_string)) { 419 if (!proxy_config.GetBypassList(&bypass_list_string)) {
417 LOG(ERROR) << "Invalid bypassList in configuration."; 420 LOG(ERROR) << "Invalid bypassList in configuration.";
418 return NULL; 421 return NULL;
419 } 422 }
420 ListValue* bypass_list = TokenizeToStringList(bypass_list_string, ",;"); 423 base::ListValue* bypass_list =
424 TokenizeToStringList(bypass_list_string, ",;");
421 extension_proxy_rules->Set(keys::kProxyConfigBypassList, bypass_list); 425 extension_proxy_rules->Set(keys::kProxyConfigBypassList, bypass_list);
422 } 426 }
423 427
424 return extension_proxy_rules.release(); 428 return extension_proxy_rules.release();
425 } 429 }
426 430
427 DictionaryValue* CreateProxyServerDict(const net::ProxyServer& proxy) { 431 base::DictionaryValue* CreateProxyServerDict(const net::ProxyServer& proxy) {
428 scoped_ptr<DictionaryValue> out(new DictionaryValue); 432 scoped_ptr<base::DictionaryValue> out(new base::DictionaryValue);
429 switch (proxy.scheme()) { 433 switch (proxy.scheme()) {
430 case net::ProxyServer::SCHEME_HTTP: 434 case net::ProxyServer::SCHEME_HTTP:
431 out->SetString(keys::kProxyConfigRuleScheme, "http"); 435 out->SetString(keys::kProxyConfigRuleScheme, "http");
432 break; 436 break;
433 case net::ProxyServer::SCHEME_HTTPS: 437 case net::ProxyServer::SCHEME_HTTPS:
434 out->SetString(keys::kProxyConfigRuleScheme, "https"); 438 out->SetString(keys::kProxyConfigRuleScheme, "https");
435 break; 439 break;
436 case net::ProxyServer::SCHEME_SOCKS4: 440 case net::ProxyServer::SCHEME_SOCKS4:
437 out->SetString(keys::kProxyConfigRuleScheme, "socks4"); 441 out->SetString(keys::kProxyConfigRuleScheme, "socks4");
438 break; 442 break;
439 case net::ProxyServer::SCHEME_SOCKS5: 443 case net::ProxyServer::SCHEME_SOCKS5:
440 out->SetString(keys::kProxyConfigRuleScheme, "socks5"); 444 out->SetString(keys::kProxyConfigRuleScheme, "socks5");
441 break; 445 break;
442 case net::ProxyServer::SCHEME_DIRECT: 446 case net::ProxyServer::SCHEME_DIRECT:
443 case net::ProxyServer::SCHEME_INVALID: 447 case net::ProxyServer::SCHEME_INVALID:
444 NOTREACHED(); 448 NOTREACHED();
445 return NULL; 449 return NULL;
446 } 450 }
447 out->SetString(keys::kProxyConfigRuleHost, proxy.host_port_pair().host()); 451 out->SetString(keys::kProxyConfigRuleHost, proxy.host_port_pair().host());
448 out->SetInteger(keys::kProxyConfigRulePort, proxy.host_port_pair().port()); 452 out->SetInteger(keys::kProxyConfigRulePort, proxy.host_port_pair().port());
449 return out.release(); 453 return out.release();
450 } 454 }
451 455
452 DictionaryValue* CreatePacScriptDict( 456 base::DictionaryValue* CreatePacScriptDict(
453 const ProxyConfigDictionary& proxy_config) { 457 const ProxyConfigDictionary& proxy_config) {
454 ProxyPrefs::ProxyMode mode; 458 ProxyPrefs::ProxyMode mode;
455 CHECK(proxy_config.GetMode(&mode) && mode == ProxyPrefs::MODE_PAC_SCRIPT); 459 CHECK(proxy_config.GetMode(&mode) && mode == ProxyPrefs::MODE_PAC_SCRIPT);
456 460
457 scoped_ptr<DictionaryValue> pac_script_dict(new DictionaryValue); 461 scoped_ptr<base::DictionaryValue> pac_script_dict(new base::DictionaryValue);
458 std::string pac_url; 462 std::string pac_url;
459 if (!proxy_config.GetPacUrl(&pac_url)) { 463 if (!proxy_config.GetPacUrl(&pac_url)) {
460 LOG(ERROR) << "Invalid proxy configuration. Missing PAC URL."; 464 LOG(ERROR) << "Invalid proxy configuration. Missing PAC URL.";
461 return NULL; 465 return NULL;
462 } 466 }
463 bool pac_mandatory = false; 467 bool pac_mandatory = false;
464 if (!proxy_config.GetPacMandatory(&pac_mandatory)) { 468 if (!proxy_config.GetPacMandatory(&pac_mandatory)) {
465 LOG(ERROR) << "Invalid proxy configuration. Missing PAC mandatory field."; 469 LOG(ERROR) << "Invalid proxy configuration. Missing PAC mandatory field.";
466 return NULL; 470 return NULL;
467 } 471 }
468 472
469 if (pac_url.find("data") == 0) { 473 if (pac_url.find("data") == 0) {
470 std::string pac_data; 474 std::string pac_data;
471 if (!CreatePACScriptFromDataURL(pac_url, &pac_data)) { 475 if (!CreatePACScriptFromDataURL(pac_url, &pac_data)) {
472 LOG(ERROR) << "Cannot decode base64-encoded PAC data URL: " << pac_url; 476 LOG(ERROR) << "Cannot decode base64-encoded PAC data URL: " << pac_url;
473 return NULL; 477 return NULL;
474 } 478 }
475 pac_script_dict->SetString(keys::kProxyConfigPacScriptData, pac_data); 479 pac_script_dict->SetString(keys::kProxyConfigPacScriptData, pac_data);
476 } else { 480 } else {
477 pac_script_dict->SetString(keys::kProxyConfigPacScriptUrl, pac_url); 481 pac_script_dict->SetString(keys::kProxyConfigPacScriptUrl, pac_url);
478 } 482 }
479 pac_script_dict->SetBoolean(keys::kProxyConfigPacScriptMandatory, 483 pac_script_dict->SetBoolean(keys::kProxyConfigPacScriptMandatory,
480 pac_mandatory); 484 pac_mandatory);
481 return pac_script_dict.release(); 485 return pac_script_dict.release();
482 } 486 }
483 487
484 ListValue* TokenizeToStringList(const std::string& in, 488 base::ListValue* TokenizeToStringList(const std::string& in,
485 const std::string& delims) { 489 const std::string& delims) {
486 ListValue* out = new ListValue; 490 base::ListValue* out = new base::ListValue;
487 base::StringTokenizer entries(in, delims); 491 base::StringTokenizer entries(in, delims);
488 while (entries.GetNext()) 492 while (entries.GetNext())
489 out->Append(Value::CreateStringValue(entries.token())); 493 out->Append(Value::CreateStringValue(entries.token()));
490 return out; 494 return out;
491 } 495 }
492 496
493 } // namespace proxy_api_helpers 497 } // namespace proxy_api_helpers
494 } // namespace extensions 498 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698