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

Side by Side Diff: chrome/browser/extensions/extension_proxy_api_helpers.cc

Issue 6871019: Enable (optional) blocking of webrequests in case a PAC script cannot be fetched or is invalid. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 8 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) 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 // 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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 // We can safely assume that this is ASCII due to the allowed enumeration 65 // We can safely assume that this is ASCII due to the allowed enumeration
66 // values specified in extension_api.json. 66 // values specified in extension_api.json.
67 proxy_config->GetStringASCII(keys::kProxyConfigMode, &proxy_mode); 67 proxy_config->GetStringASCII(keys::kProxyConfigMode, &proxy_mode);
68 if (!ProxyPrefs::StringToProxyMode(proxy_mode, out)) { 68 if (!ProxyPrefs::StringToProxyMode(proxy_mode, out)) {
69 LOG(ERROR) << "Invalid mode for proxy settings: " << proxy_mode; 69 LOG(ERROR) << "Invalid mode for proxy settings: " << proxy_mode;
70 return false; 70 return false;
71 } 71 }
72 return true; 72 return true;
73 } 73 }
74 74
75 bool GetPacMandatoryFromExtensionPref(const DictionaryValue* proxy_config,
76 bool* out,
77 std::string* error){
78 DictionaryValue* pac_dict = NULL;
79 proxy_config->GetDictionary(keys::kProxyConfigPacScript, &pac_dict);
80 if (!pac_dict)
81 return true;
82
83 bool mandatory_pac = false;
84 if (pac_dict->HasKey(keys::kProxyConfigPacScriptMandatory) &&
85 !pac_dict->GetBoolean(keys::kProxyConfigPacScriptMandatory,
86 &mandatory_pac)) {
87 LOG(ERROR) << "'pacScript.mandatory' could not be parsed.";
Bernhard Bauer 2011/04/15 18:38:47 Hm, this should already be covered by the JSON sch
battre 2011/04/26 15:31:30 I have added a TODO, in order to do this in a sepa
88 return false;
89 }
90 *out = mandatory_pac;
91 return true;
92 }
93
75 bool GetPacUrlFromExtensionPref(const DictionaryValue* proxy_config, 94 bool GetPacUrlFromExtensionPref(const DictionaryValue* proxy_config,
76 std::string* out, 95 std::string* out,
77 std::string* error) { 96 std::string* error) {
78 DictionaryValue* pac_dict = NULL; 97 DictionaryValue* pac_dict = NULL;
79 proxy_config->GetDictionary(keys::kProxyConfigPacScript, &pac_dict); 98 proxy_config->GetDictionary(keys::kProxyConfigPacScript, &pac_dict);
80 if (!pac_dict) 99 if (!pac_dict)
81 return true; 100 return true;
82 101
83 // TODO(battre): Handle UTF-8 URLs (http://crbug.com/72692). 102 // TODO(battre): Handle UTF-8 URLs (http://crbug.com/72692).
84 string16 pac_url16; 103 string16 pac_url16;
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 ListValue* bypass_list = NULL; 283 ListValue* bypass_list = NULL;
265 if (!proxy_rules->GetList(keys::kProxyConfigBypassList, &bypass_list)) { 284 if (!proxy_rules->GetList(keys::kProxyConfigBypassList, &bypass_list)) {
266 LOG(ERROR) << "'rules.bypassList' not be parsed."; 285 LOG(ERROR) << "'rules.bypassList' not be parsed.";
267 return false; 286 return false;
268 } 287 }
269 288
270 return JoinUrlList(bypass_list, ",", out, error); 289 return JoinUrlList(bypass_list, ",", out, error);
271 } 290 }
272 291
273 DictionaryValue* CreateProxyConfigDict(ProxyPrefs::ProxyMode mode_enum, 292 DictionaryValue* CreateProxyConfigDict(ProxyPrefs::ProxyMode mode_enum,
293 bool pac_mandatory,
274 const std::string& pac_url, 294 const std::string& pac_url,
275 const std::string& pac_data, 295 const std::string& pac_data,
276 const std::string& proxy_rules_string, 296 const std::string& proxy_rules_string,
277 const std::string& bypass_list, 297 const std::string& bypass_list,
278 std::string* error) { 298 std::string* error) {
279 DictionaryValue* result_proxy_config = NULL; 299 DictionaryValue* result_proxy_config = NULL;
280 switch (mode_enum) { 300 switch (mode_enum) {
281 case ProxyPrefs::MODE_DIRECT: 301 case ProxyPrefs::MODE_DIRECT:
282 result_proxy_config = ProxyConfigDictionary::CreateDirect(); 302 result_proxy_config = ProxyConfigDictionary::CreateDirect();
283 break; 303 break;
284 case ProxyPrefs::MODE_AUTO_DETECT: 304 case ProxyPrefs::MODE_AUTO_DETECT:
285 result_proxy_config = ProxyConfigDictionary::CreateAutoDetect(); 305 result_proxy_config = ProxyConfigDictionary::CreateAutoDetect();
286 break; 306 break;
287 case ProxyPrefs::MODE_PAC_SCRIPT: { 307 case ProxyPrefs::MODE_PAC_SCRIPT: {
288 std::string url; 308 std::string url;
289 if (!pac_url.empty()) { 309 if (!pac_url.empty()) {
290 url = pac_url; 310 url = pac_url;
291 } else if (!pac_data.empty()) { 311 } else if (!pac_data.empty()) {
292 if (!CreateDataURLFromPACScript(pac_data, &url)) { 312 if (!CreateDataURLFromPACScript(pac_data, &url)) {
293 *error = "Internal error, at base64 encoding of 'pacScript.data'."; 313 *error = "Internal error, at base64 encoding of 'pacScript.data'.";
294 return NULL; 314 return NULL;
295 } 315 }
296 } else { 316 } else {
297 *error = "Proxy mode 'pac_script' requires a 'pacScript' field with " 317 *error = "Proxy mode 'pac_script' requires a 'pacScript' field with "
298 "either a 'url' field or a 'data' field."; 318 "either a 'url' field or a 'data' field.";
299 return NULL; 319 return NULL;
300 } 320 }
301 result_proxy_config = ProxyConfigDictionary::CreatePacScript(url); 321 result_proxy_config =
322 ProxyConfigDictionary::CreatePacScript(url, pac_mandatory);
302 break; 323 break;
303 } 324 }
304 case ProxyPrefs::MODE_FIXED_SERVERS: { 325 case ProxyPrefs::MODE_FIXED_SERVERS: {
305 if (proxy_rules_string.empty()) { 326 if (proxy_rules_string.empty()) {
306 *error = "Proxy mode 'fixed_servers' requires a 'rules' field."; 327 *error = "Proxy mode 'fixed_servers' requires a 'rules' field.";
307 return NULL; 328 return NULL;
308 } 329 }
309 result_proxy_config = ProxyConfigDictionary::CreateFixedServers( 330 result_proxy_config = ProxyConfigDictionary::CreateFixedServers(
310 proxy_rules_string, bypass_list); 331 proxy_rules_string, bypass_list);
311 break; 332 break;
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
408 const ProxyConfigDictionary& proxy_config) { 429 const ProxyConfigDictionary& proxy_config) {
409 ProxyPrefs::ProxyMode mode; 430 ProxyPrefs::ProxyMode mode;
410 CHECK(proxy_config.GetMode(&mode) && mode == ProxyPrefs::MODE_PAC_SCRIPT); 431 CHECK(proxy_config.GetMode(&mode) && mode == ProxyPrefs::MODE_PAC_SCRIPT);
411 432
412 scoped_ptr<DictionaryValue> pac_script_dict(new DictionaryValue); 433 scoped_ptr<DictionaryValue> pac_script_dict(new DictionaryValue);
413 std::string pac_url; 434 std::string pac_url;
414 if (!proxy_config.GetPacUrl(&pac_url)) { 435 if (!proxy_config.GetPacUrl(&pac_url)) {
415 LOG(ERROR) << "Invalid proxy configuration. Missing PAC URL."; 436 LOG(ERROR) << "Invalid proxy configuration. Missing PAC URL.";
416 return NULL; 437 return NULL;
417 } 438 }
439 bool pac_mandatory = false;
440 if (!proxy_config.GetPacMandatory(&pac_mandatory)) {
441 LOG(ERROR) << "Invalid proxy configuration. Missing PAC mandatory field.";
442 return NULL;
443 }
418 444
419 if (pac_url.find("data") == 0) { 445 if (pac_url.find("data") == 0) {
420 std::string pac_data; 446 std::string pac_data;
421 if (!CreatePACScriptFromDataURL(pac_url, &pac_data)) { 447 if (!CreatePACScriptFromDataURL(pac_url, &pac_data)) {
422 LOG(ERROR) << "Cannot decode base64-encoded PAC data URL."; 448 LOG(ERROR) << "Cannot decode base64-encoded PAC data URL.";
423 return NULL; 449 return NULL;
424 } 450 }
425 pac_script_dict->SetString(keys::kProxyConfigPacScriptData, pac_data); 451 pac_script_dict->SetString(keys::kProxyConfigPacScriptData, pac_data);
426 } else { 452 } else {
427 pac_script_dict->SetString(keys::kProxyConfigPacScriptUrl, pac_url); 453 pac_script_dict->SetString(keys::kProxyConfigPacScriptUrl, pac_url);
428 } 454 }
455 pac_script_dict->SetBoolean(keys::kProxyConfigPacScriptMandatory,
456 pac_mandatory);
429 return pac_script_dict.release(); 457 return pac_script_dict.release();
430 } 458 }
431 459
432 ListValue* TokenizeToStringList(const std::string& in, 460 ListValue* TokenizeToStringList(const std::string& in,
433 const std::string& delims) { 461 const std::string& delims) {
434 ListValue* out = new ListValue; 462 ListValue* out = new ListValue;
435 StringTokenizer entries(in, delims); 463 StringTokenizer entries(in, delims);
436 while (entries.GetNext()) 464 while (entries.GetNext())
437 out->Append(Value::CreateStringValue(entries.token())); 465 out->Append(Value::CreateStringValue(entries.token()));
438 return out; 466 return out;
439 } 467 }
440 468
441 } // namespace extension_proxy_api_helpers 469 } // namespace extension_proxy_api_helpers
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698