summaryrefslogtreecommitdiffstats
path: root/chrome/browser/extensions/extension_proxy_api.cc
diff options
context:
space:
mode:
authorbattre@chromium.org <battre@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-12-23 10:18:20 +0000
committerbattre@chromium.org <battre@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-12-23 10:18:20 +0000
commiteccf68e19bd5ddb3a6eac53a5313a49054a418f3 (patch)
tree3e883a8c74dd9e1503da8a05b3f4a555a7e0f1ec /chrome/browser/extensions/extension_proxy_api.cc
parentf61c397ae7c8d07762b02d6578928163e2a8eca0 (diff)
downloadchromium_src-eccf68e19bd5ddb3a6eac53a5313a49054a418f3.zip
chromium_src-eccf68e19bd5ddb3a6eac53a5313a49054a418f3.tar.gz
chromium_src-eccf68e19bd5ddb3a6eac53a5313a49054a418f3.tar.bz2
Introduce a separate preference for 'proxy server mode'
The new preference is kProxyServerMode, which supersedes kProxyAutoDetect and kNoProxyServer. The point of this change is to represent 'use system proxy settings' in a more robust way. The proxy extension API is also adjusted to the preference system. This is a continuation of gfeher's patch from issue 5701003. BUG=65732, 66023 TEST=ProxyPrefsTest.*, and also covered by ExtensionApiTest.Porxy*, PrefProxyConfigServiceTest.* Review URL: http://codereview.chromium.org/6004003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@70042 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions/extension_proxy_api.cc')
-rw-r--r--chrome/browser/extensions/extension_proxy_api.cc41
1 files changed, 26 insertions, 15 deletions
diff --git a/chrome/browser/extensions/extension_proxy_api.cc b/chrome/browser/extensions/extension_proxy_api.cc
index 9bc33cb..d71c055 100644
--- a/chrome/browser/extensions/extension_proxy_api.cc
+++ b/chrome/browser/extensions/extension_proxy_api.cc
@@ -7,6 +7,7 @@
#include "base/string_util.h"
#include "base/stringprintf.h"
#include "base/values.h"
+#include "chrome/browser/prefs/proxy_prefs.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/common/pref_names.h"
@@ -53,8 +54,8 @@ bool UseCustomProxySettingsFunction::RunImpl() {
DictionaryValue* proxy_config;
EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &proxy_config));
- bool auto_detect = false;
- proxy_config->GetBoolean("autoDetect", &auto_detect);
+ std::string proxy_mode;
+ proxy_config->GetString("mode", &proxy_mode);
DictionaryValue* pac_dict = NULL;
proxy_config->GetDictionary("pacScript", &pac_dict);
@@ -62,7 +63,9 @@ bool UseCustomProxySettingsFunction::RunImpl() {
DictionaryValue* proxy_rules = NULL;
proxy_config->GetDictionary("rules", &proxy_rules);
- return ApplyAutoDetect(auto_detect) &&
+ // TODO(battre,gfeher): Make sure all the preferences get always
+ // overwritten.
+ return ApplyMode(proxy_mode) &&
ApplyPacScript(pac_dict) &&
ApplyProxyRules(proxy_rules);
}
@@ -75,13 +78,19 @@ bool UseCustomProxySettingsFunction::GetProxyServer(
return true;
}
-bool UseCustomProxySettingsFunction::ApplyAutoDetect(bool auto_detect) {
- // We take control of the auto-detect preference even if none was specified,
- // so that all proxy preferences are controlled by the same extension (if not
- // by a higher-priority source).
- SendNotification(prefs::kProxyAutoDetect,
- Value::CreateBooleanValue(auto_detect));
- return true;
+bool UseCustomProxySettingsFunction::ApplyMode(const std::string& mode) {
+ // We take control of the mode preference even if none was specified, so that
+ // all proxy preferences are controlled by the same extension (if not by a
+ // higher-priority source).
+ bool result = true;
+ ProxyPrefs::ProxyMode mode_enum;
+ if (!ProxyPrefs::StringToProxyMode(mode, &mode_enum)) {
+ mode_enum = ProxyPrefs::MODE_SYSTEM;
+ LOG(WARNING) << "Invalid mode for proxy settings: " << mode;
+ result = false;
+ }
+ ApplyPreference(prefs::kProxyMode, Value::CreateIntegerValue(mode_enum));
+ return result;
}
bool UseCustomProxySettingsFunction::ApplyPacScript(DictionaryValue* pac_dict) {
@@ -92,14 +101,16 @@ bool UseCustomProxySettingsFunction::ApplyPacScript(DictionaryValue* pac_dict) {
// We take control of the PAC preference even if none was specified, so that
// all proxy preferences are controlled by the same extension (if not by a
// higher-priority source).
- SendNotification(prefs::kProxyPacUrl, Value::CreateStringValue(pac_url));
+ ApplyPreference(prefs::kProxyPacUrl, Value::CreateStringValue(pac_url));
return true;
}
bool UseCustomProxySettingsFunction::ApplyProxyRules(
DictionaryValue* proxy_rules) {
- if (!proxy_rules)
+ if (!proxy_rules) {
+ ApplyPreference(prefs::kProxyServer, Value::CreateStringValue(""));
return true;
+ }
// Local data into which the parameters will be parsed. has_proxy describes
// whether a setting was found for the scheme; proxy_dict holds the
@@ -153,12 +164,12 @@ bool UseCustomProxySettingsFunction::ApplyProxyRules(
}
}
- SendNotification(prefs::kProxyServer, Value::CreateStringValue(proxy_pref));
+ ApplyPreference(prefs::kProxyServer, Value::CreateStringValue(proxy_pref));
return true;
}
-void UseCustomProxySettingsFunction::SendNotification(const char* pref_path,
- Value* pref_value) {
+void UseCustomProxySettingsFunction::ApplyPreference(const char* pref_path,
+ Value* pref_value) {
profile()->GetExtensionService()->extension_prefs()
->SetExtensionControlledPref(extension_id(), pref_path, pref_value);
}