diff options
author | battre@chromium.org <battre@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-03 12:44:19 +0000 |
---|---|---|
committer | battre@chromium.org <battre@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-03 12:44:19 +0000 |
commit | e0470bd2dd6b88f88b1e96cae90872a1b84fe265 (patch) | |
tree | 68fe6de9bc811ad6ce4237c50812ee3028510196 /chrome/browser/prefs | |
parent | 82a3767c45e85b77fb41d4fc92fc49fcb879e75b (diff) | |
download | chromium_src-e0470bd2dd6b88f88b1e96cae90872a1b84fe265.zip chromium_src-e0470bd2dd6b88f88b1e96cae90872a1b84fe265.tar.gz chromium_src-e0470bd2dd6b88f88b1e96cae90872a1b84fe265.tar.bz2 |
Enable (optional) blocking of webrequests in case a PAC script cannot be fetched or is invalid.
The optional blocking is currently only exposed to the Proxy Settings API, not to command-line parameters or policies.
BUG=79344
TEST=Install the sample proxy extension and enter a non-existing url and a URL that does not point to a valid JavaScript file. In either case, the request should fail.
Review URL: http://codereview.chromium.org/6871019
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@83882 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/prefs')
4 files changed, 30 insertions, 10 deletions
diff --git a/chrome/browser/prefs/command_line_pref_store.cc b/chrome/browser/prefs/command_line_pref_store.cc index a992ced..03b6ef6 100644 --- a/chrome/browser/prefs/command_line_pref_store.cc +++ b/chrome/browser/prefs/command_line_pref_store.cc @@ -86,7 +86,7 @@ void CommandLinePrefStore::ApplyProxyMode() { std::string pac_script_url = command_line_->GetSwitchValueASCII(switches::kProxyPacUrl); SetValue(prefs::kProxy, - ProxyConfigDictionary::CreatePacScript(pac_script_url)); + ProxyConfigDictionary::CreatePacScript(pac_script_url, false)); } else if (command_line_->HasSwitch(switches::kProxyAutoDetect)) { SetValue(prefs::kProxy, ProxyConfigDictionary::CreateAutoDetect()); diff --git a/chrome/browser/prefs/proxy_config_dictionary.cc b/chrome/browser/prefs/proxy_config_dictionary.cc index 0c063cd..a99fa7c 100644 --- a/chrome/browser/prefs/proxy_config_dictionary.cc +++ b/chrome/browser/prefs/proxy_config_dictionary.cc @@ -19,6 +19,10 @@ const char kProxyMode[] = "mode"; const char kProxyServer[] = "server"; // URL to the proxy .pac file. const char kProxyPacUrl[] = "pac_url"; +// Optional boolean flag indicating whether a valid PAC script is mandatory. +// If true, network traffic does not fall back to direct connections in case the +// PAC script is not available. +const char kProxyPacMandatory[] = "pac_mandatory"; // String containing proxy bypass rules. For a specification of the // expected syntax see net::ProxyBypassRules::ParseFromString(). const char kProxyBypassList[] = "bypass_list"; @@ -41,6 +45,14 @@ bool ProxyConfigDictionary::GetPacUrl(std::string* out) const { return dict_->GetString(kProxyPacUrl, out); } +bool ProxyConfigDictionary::GetPacMandatory(bool* out) const { + if (!dict_->HasKey(kProxyPacMandatory)) { + *out = false; + return true; + } + return dict_->GetBoolean(kProxyPacMandatory, out); +} + bool ProxyConfigDictionary::GetProxyServer(std::string* out) const { return dict_->GetString(kProxyServer, out); } @@ -55,18 +67,20 @@ bool ProxyConfigDictionary::HasBypassList() const { // static DictionaryValue* ProxyConfigDictionary::CreateDirect() { - return CreateDictionary(ProxyPrefs::MODE_DIRECT, "", "", ""); + return CreateDictionary(ProxyPrefs::MODE_DIRECT, "", false, "", ""); } // static DictionaryValue* ProxyConfigDictionary::CreateAutoDetect() { - return CreateDictionary(ProxyPrefs::MODE_AUTO_DETECT, "", "", ""); + return CreateDictionary(ProxyPrefs::MODE_AUTO_DETECT, "", false, "", ""); } // static DictionaryValue* ProxyConfigDictionary::CreatePacScript( - const std::string& pac_url) { - return CreateDictionary(ProxyPrefs::MODE_PAC_SCRIPT, pac_url, "", ""); + const std::string& pac_url, + bool pac_mandatory) { + return CreateDictionary(ProxyPrefs::MODE_PAC_SCRIPT, + pac_url, pac_mandatory, "", ""); } // static @@ -75,7 +89,7 @@ DictionaryValue* ProxyConfigDictionary::CreateFixedServers( const std::string& bypass_list) { if (!proxy_server.empty()) { return CreateDictionary( - ProxyPrefs::MODE_FIXED_SERVERS, "", proxy_server, bypass_list); + ProxyPrefs::MODE_FIXED_SERVERS, "", false, proxy_server, bypass_list); } else { return CreateDirect(); } @@ -83,19 +97,22 @@ DictionaryValue* ProxyConfigDictionary::CreateFixedServers( // static DictionaryValue* ProxyConfigDictionary::CreateSystem() { - return CreateDictionary(ProxyPrefs::MODE_SYSTEM, "", "", ""); + return CreateDictionary(ProxyPrefs::MODE_SYSTEM, "", false, "", ""); } // static DictionaryValue* ProxyConfigDictionary::CreateDictionary( ProxyPrefs::ProxyMode mode, const std::string& pac_url, + bool pac_mandatory, const std::string& proxy_server, const std::string& bypass_list) { DictionaryValue* dict = new DictionaryValue(); dict->SetString(kProxyMode, ProxyModeToString(mode)); - if (!pac_url.empty()) + if (!pac_url.empty()) { dict->SetString(kProxyPacUrl, pac_url); + dict->SetBoolean(kProxyPacMandatory, pac_mandatory); + } if (!proxy_server.empty()) dict->SetString(kProxyServer, proxy_server); if (!bypass_list.empty()) diff --git a/chrome/browser/prefs/proxy_config_dictionary.h b/chrome/browser/prefs/proxy_config_dictionary.h index c05f182..3eeac12 100644 --- a/chrome/browser/prefs/proxy_config_dictionary.h +++ b/chrome/browser/prefs/proxy_config_dictionary.h @@ -31,13 +31,15 @@ class ProxyConfigDictionary { bool GetMode(ProxyPrefs::ProxyMode* out) const; bool GetPacUrl(std::string* out) const; + bool GetPacMandatory(bool* out) const; bool GetProxyServer(std::string* out) const; bool GetBypassList(std::string* out) const; bool HasBypassList() const; static DictionaryValue* CreateDirect(); static DictionaryValue* CreateAutoDetect(); - static DictionaryValue* CreatePacScript(const std::string& pac_url); + static DictionaryValue* CreatePacScript(const std::string& pac_url, + bool pac_mandatory); static DictionaryValue* CreateFixedServers( const std::string& proxy_server, const std::string& bypass_list); @@ -45,6 +47,7 @@ class ProxyConfigDictionary { private: static DictionaryValue* CreateDictionary(ProxyPrefs::ProxyMode mode, const std::string& pac_url, + bool pac_mandatory, const std::string& proxy_server, const std::string& bypass_list); diff --git a/chrome/browser/prefs/proxy_config_dictionary_unittest.cc b/chrome/browser/prefs/proxy_config_dictionary_unittest.cc index 5575b66..8301266 100644 --- a/chrome/browser/prefs/proxy_config_dictionary_unittest.cc +++ b/chrome/browser/prefs/proxy_config_dictionary_unittest.cc @@ -43,7 +43,7 @@ TEST(ProxyConfigDictionaryTest, CreateAutoDetect) { TEST(ProxyConfigDictionaryTest, CreatePacScript) { scoped_ptr<DictionaryValue> dict_value( - ProxyConfigDictionary::CreatePacScript("pac")); + ProxyConfigDictionary::CreatePacScript("pac", false)); ProxyConfigDictionary dict(dict_value.get()); ProxyConfigHolder h; |