OLD | NEW |
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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 base::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 base::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."; |
(...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
468 if (!proxy_config.GetPacUrl(&pac_url)) { | 468 if (!proxy_config.GetPacUrl(&pac_url)) { |
469 LOG(ERROR) << "Invalid proxy configuration. Missing PAC URL."; | 469 LOG(ERROR) << "Invalid proxy configuration. Missing PAC URL."; |
470 return NULL; | 470 return NULL; |
471 } | 471 } |
472 bool pac_mandatory = false; | 472 bool pac_mandatory = false; |
473 if (!proxy_config.GetPacMandatory(&pac_mandatory)) { | 473 if (!proxy_config.GetPacMandatory(&pac_mandatory)) { |
474 LOG(ERROR) << "Invalid proxy configuration. Missing PAC mandatory field."; | 474 LOG(ERROR) << "Invalid proxy configuration. Missing PAC mandatory field."; |
475 return NULL; | 475 return NULL; |
476 } | 476 } |
477 | 477 |
478 if (pac_url.find("data") == 0) { | 478 if (base::StartsWith(pac_url, "data", base::CompareCase::SENSITIVE)) { |
479 std::string pac_data; | 479 std::string pac_data; |
480 if (!CreatePACScriptFromDataURL(pac_url, &pac_data)) { | 480 if (!CreatePACScriptFromDataURL(pac_url, &pac_data)) { |
481 LOG(ERROR) << "Cannot decode base64-encoded PAC data URL: " << pac_url; | 481 LOG(ERROR) << "Cannot decode base64-encoded PAC data URL: " << pac_url; |
482 return NULL; | 482 return NULL; |
483 } | 483 } |
484 pac_script_dict->SetString(keys::kProxyConfigPacScriptData, pac_data); | 484 pac_script_dict->SetString(keys::kProxyConfigPacScriptData, pac_data); |
485 } else { | 485 } else { |
486 pac_script_dict->SetString(keys::kProxyConfigPacScriptUrl, pac_url); | 486 pac_script_dict->SetString(keys::kProxyConfigPacScriptUrl, pac_url); |
487 } | 487 } |
488 pac_script_dict->SetBoolean(keys::kProxyConfigPacScriptMandatory, | 488 pac_script_dict->SetBoolean(keys::kProxyConfigPacScriptMandatory, |
489 pac_mandatory); | 489 pac_mandatory); |
490 return pac_script_dict.release(); | 490 return pac_script_dict.release(); |
491 } | 491 } |
492 | 492 |
493 base::ListValue* TokenizeToStringList(const std::string& in, | 493 base::ListValue* TokenizeToStringList(const std::string& in, |
494 const std::string& delims) { | 494 const std::string& delims) { |
495 base::ListValue* out = new base::ListValue; | 495 base::ListValue* out = new base::ListValue; |
496 base::StringTokenizer entries(in, delims); | 496 base::StringTokenizer entries(in, delims); |
497 while (entries.GetNext()) | 497 while (entries.GetNext()) |
498 out->AppendString(entries.token()); | 498 out->AppendString(entries.token()); |
499 return out; | 499 return out; |
500 } | 500 } |
501 | 501 |
502 } // namespace proxy_api_helpers | 502 } // namespace proxy_api_helpers |
503 } // namespace extensions | 503 } // namespace extensions |
OLD | NEW |