Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #include "chrome/browser/extensions/extension_proxy_api.h" | 5 #include "chrome/browser/extensions/extension_proxy_api.h" |
| 6 | 6 |
| 7 #include "base/string_util.h" | 7 #include "base/string_util.h" |
| 8 #include "base/stringprintf.h" | 8 #include "base/stringprintf.h" |
| 9 #include "base/values.h" | 9 #include "base/values.h" |
| 10 #include "chrome/browser/prefs/proxy_prefs.h" | |
| 10 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
| 11 #include "chrome/browser/extensions/extension_service.h" | 12 #include "chrome/browser/extensions/extension_service.h" |
| 12 #include "chrome/common/pref_names.h" | 13 #include "chrome/common/pref_names.h" |
| 13 | 14 |
| 14 namespace { | 15 namespace { |
| 15 | 16 |
| 16 // The scheme for which to use a manually specified proxy, not of the proxy URI | 17 // The scheme for which to use a manually specified proxy, not of the proxy URI |
| 17 // itself. | 18 // itself. |
| 18 enum { | 19 enum { |
| 19 SCHEME_ALL = 0, | 20 SCHEME_ALL = 0, |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 46 COMPILE_ASSERT(SCHEME_MAX == SCHEME_SOCKS, SCHEME_MAX_must_equal_SCHEME_SOCKS); | 47 COMPILE_ASSERT(SCHEME_MAX == SCHEME_SOCKS, SCHEME_MAX_must_equal_SCHEME_SOCKS); |
| 47 COMPILE_ASSERT(arraysize(field_name) == SCHEME_MAX + 1, | 48 COMPILE_ASSERT(arraysize(field_name) == SCHEME_MAX + 1, |
| 48 field_name_array_is_wrong_size); | 49 field_name_array_is_wrong_size); |
| 49 COMPILE_ASSERT(arraysize(scheme_name) == SCHEME_MAX + 1, | 50 COMPILE_ASSERT(arraysize(scheme_name) == SCHEME_MAX + 1, |
| 50 scheme_name_array_is_wrong_size); | 51 scheme_name_array_is_wrong_size); |
| 51 | 52 |
| 52 bool UseCustomProxySettingsFunction::RunImpl() { | 53 bool UseCustomProxySettingsFunction::RunImpl() { |
| 53 DictionaryValue* proxy_config; | 54 DictionaryValue* proxy_config; |
| 54 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &proxy_config)); | 55 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &proxy_config)); |
| 55 | 56 |
| 56 bool auto_detect = false; | 57 std::string proxy_mode; |
| 57 proxy_config->GetBoolean("autoDetect", &auto_detect); | 58 proxy_config->GetString("mode", &proxy_mode); |
| 58 | 59 |
| 59 DictionaryValue* pac_dict = NULL; | 60 DictionaryValue* pac_dict = NULL; |
| 60 proxy_config->GetDictionary("pacScript", &pac_dict); | 61 proxy_config->GetDictionary("pacScript", &pac_dict); |
| 61 | 62 |
| 62 DictionaryValue* proxy_rules = NULL; | 63 DictionaryValue* proxy_rules = NULL; |
| 63 proxy_config->GetDictionary("rules", &proxy_rules); | 64 proxy_config->GetDictionary("rules", &proxy_rules); |
| 64 | 65 |
| 65 return ApplyAutoDetect(auto_detect) && | 66 // TODO(battre,gfeher): Make sure all the preferences get always |
| 67 // overwritten. | |
| 68 return ApplyMode(proxy_mode) && | |
| 66 ApplyPacScript(pac_dict) && | 69 ApplyPacScript(pac_dict) && |
| 67 ApplyProxyRules(proxy_rules); | 70 ApplyProxyRules(proxy_rules); |
| 68 } | 71 } |
| 69 | 72 |
| 70 bool UseCustomProxySettingsFunction::GetProxyServer( | 73 bool UseCustomProxySettingsFunction::GetProxyServer( |
| 71 const DictionaryValue* dict, ProxyServer* proxy_server) { | 74 const DictionaryValue* dict, ProxyServer* proxy_server) { |
| 72 dict->GetString("scheme", &proxy_server->scheme); | 75 dict->GetString("scheme", &proxy_server->scheme); |
| 73 EXTENSION_FUNCTION_VALIDATE(dict->GetString("host", &proxy_server->host)); | 76 EXTENSION_FUNCTION_VALIDATE(dict->GetString("host", &proxy_server->host)); |
| 74 dict->GetInteger("port", &proxy_server->port); | 77 dict->GetInteger("port", &proxy_server->port); |
| 75 return true; | 78 return true; |
| 76 } | 79 } |
| 77 | 80 |
| 78 bool UseCustomProxySettingsFunction::ApplyAutoDetect(bool auto_detect) { | 81 bool UseCustomProxySettingsFunction::ApplyMode(const std::string& mode) { |
| 79 // We take control of the auto-detect preference even if none was specified, | 82 // We take control of the mode preference even if none was specified, |
| 80 // so that all proxy preferences are controlled by the same extension (if not | 83 // so that all proxy preferences are controlled by the same extension (if not |
| 81 // by a higher-priority source). | 84 // by a higher-priority source). |
| 82 SendNotification(prefs::kProxyAutoDetect, | 85 bool result = true; |
| 83 Value::CreateBooleanValue(auto_detect)); | 86 ProxyPrefs::ProxyServerMode mode_enum; |
| 84 return true; | 87 if (!ProxyPrefs::StringToProxyMode(mode, &mode_enum)) { |
| 88 mode_enum = ProxyPrefs::SYSTEM; | |
| 89 LOG(WARNING) << "Invalid mode for proxy settings: " << mode << std::endl; | |
|
Pam (message me for reviews)
2010/12/18 08:29:55
Is the endl needed? I don't recall seeing it in ot
battre (please use the other)
2010/12/20 12:57:23
Done.
Mattias Nissler (ping if slow)
2010/12/20 13:34:03
No, it gets appended automatically. Please remove.
battre (please use the other)
2010/12/21 14:18:18
Done.
| |
| 90 result = false; | |
| 91 } | |
| 92 SendNotification(prefs::kProxyServerMode, | |
|
Mattias Nissler (ping if slow)
2010/12/20 13:34:03
I think it's time to rename SendNotification() to
battre (please use the other)
2010/12/21 14:18:18
Done.
| |
| 93 Value::CreateIntegerValue(mode_enum)); | |
| 94 return result; | |
| 85 } | 95 } |
| 86 | 96 |
| 87 bool UseCustomProxySettingsFunction::ApplyPacScript(DictionaryValue* pac_dict) { | 97 bool UseCustomProxySettingsFunction::ApplyPacScript(DictionaryValue* pac_dict) { |
| 88 std::string pac_url; | 98 std::string pac_url; |
| 89 if (pac_dict) | 99 if (pac_dict) |
| 90 pac_dict->GetString("url", &pac_url); | 100 pac_dict->GetString("url", &pac_url); |
| 91 | 101 |
| 92 // We take control of the PAC preference even if none was specified, so that | 102 // We take control of the PAC preference even if none was specified, so that |
| 93 // all proxy preferences are controlled by the same extension (if not by a | 103 // all proxy preferences are controlled by the same extension (if not by a |
| 94 // higher-priority source). | 104 // higher-priority source). |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 155 | 165 |
| 156 SendNotification(prefs::kProxyServer, Value::CreateStringValue(proxy_pref)); | 166 SendNotification(prefs::kProxyServer, Value::CreateStringValue(proxy_pref)); |
| 157 return true; | 167 return true; |
| 158 } | 168 } |
| 159 | 169 |
| 160 void UseCustomProxySettingsFunction::SendNotification(const char* pref_path, | 170 void UseCustomProxySettingsFunction::SendNotification(const char* pref_path, |
| 161 Value* pref_value) { | 171 Value* pref_value) { |
| 162 profile()->GetExtensionService()->extension_prefs() | 172 profile()->GetExtensionService()->extension_prefs() |
| 163 ->SetExtensionControlledPref(extension_id(), pref_path, pref_value); | 173 ->SetExtensionControlledPref(extension_id(), pref_path, pref_value); |
| 164 } | 174 } |
| OLD | NEW |