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

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

Issue 5701003: Intorduce a separate preference for 'proxy server mode' (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address Dominic's comments, fix test, add TODO Created 10 years 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) 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
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::StringToMode(mode, &mode_enum)) {
88 mode_enum = ProxyPrefs::SYSTEM;
danno 2010/12/16 16:29:29 Add a log warning.
gfeher 2010/12/16 23:54:29 Done.
89 result = false;
90 }
91 SendNotification(prefs::kProxyServerMode,
92 Value::CreateIntegerValue(mode_enum));
93 return result;
85 } 94 }
86 95
87 bool UseCustomProxySettingsFunction::ApplyPacScript(DictionaryValue* pac_dict) { 96 bool UseCustomProxySettingsFunction::ApplyPacScript(DictionaryValue* pac_dict) {
88 std::string pac_url; 97 std::string pac_url;
89 if (pac_dict) 98 if (pac_dict)
90 pac_dict->GetString("url", &pac_url); 99 pac_dict->GetString("url", &pac_url);
91 100
92 // We take control of the PAC preference even if none was specified, so that 101 // 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 102 // all proxy preferences are controlled by the same extension (if not by a
94 // higher-priority source). 103 // higher-priority source).
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 164
156 SendNotification(prefs::kProxyServer, Value::CreateStringValue(proxy_pref)); 165 SendNotification(prefs::kProxyServer, Value::CreateStringValue(proxy_pref));
157 return true; 166 return true;
158 } 167 }
159 168
160 void UseCustomProxySettingsFunction::SendNotification(const char* pref_path, 169 void UseCustomProxySettingsFunction::SendNotification(const char* pref_path,
161 Value* pref_value) { 170 Value* pref_value) {
162 profile()->GetExtensionService()->extension_prefs() 171 profile()->GetExtensionService()->extension_prefs()
163 ->SetExtensionControlledPref(extension_id(), pref_path, pref_value); 172 ->SetExtensionControlledPref(extension_id(), pref_path, pref_value);
164 } 173 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698