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

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: " 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/profiles/profile.h" 10 #include "chrome/browser/profiles/profile.h"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 COMPILE_ASSERT(SCHEME_MAX == SCHEME_SOCKS, SCHEME_MAX_must_equal_SCHEME_SOCKS); 46 COMPILE_ASSERT(SCHEME_MAX == SCHEME_SOCKS, SCHEME_MAX_must_equal_SCHEME_SOCKS);
47 COMPILE_ASSERT(arraysize(field_name) == SCHEME_MAX + 1, 47 COMPILE_ASSERT(arraysize(field_name) == SCHEME_MAX + 1,
48 field_name_array_is_wrong_size); 48 field_name_array_is_wrong_size);
49 COMPILE_ASSERT(arraysize(scheme_name) == SCHEME_MAX + 1, 49 COMPILE_ASSERT(arraysize(scheme_name) == SCHEME_MAX + 1,
50 scheme_name_array_is_wrong_size); 50 scheme_name_array_is_wrong_size);
51 51
52 bool UseCustomProxySettingsFunction::RunImpl() { 52 bool UseCustomProxySettingsFunction::RunImpl() {
53 DictionaryValue* proxy_config; 53 DictionaryValue* proxy_config;
54 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &proxy_config)); 54 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &proxy_config));
55 55
56 bool auto_detect = false; 56 int proxy_mode = 0;
57 proxy_config->GetBoolean("autoDetect", &auto_detect); 57 proxy_config->GetInteger("mode", &proxy_mode);
battre (please use the other) 2010/12/14 09:45:44 I think we should expose this as string constants
danno 2010/12/14 12:48:17 How about a string value externally to the extensi
gfeher 2010/12/16 10:42:04 Done.
58 58
59 DictionaryValue* pac_dict = NULL; 59 DictionaryValue* pac_dict = NULL;
60 proxy_config->GetDictionary("pacScript", &pac_dict); 60 proxy_config->GetDictionary("pacScript", &pac_dict);
61 61
62 DictionaryValue* proxy_rules = NULL; 62 DictionaryValue* proxy_rules = NULL;
63 proxy_config->GetDictionary("rules", &proxy_rules); 63 proxy_config->GetDictionary("rules", &proxy_rules);
64 64
65 return ApplyAutoDetect(auto_detect) && 65 return ApplyMode(proxy_mode) &&
66 ApplyPacScript(pac_dict) && 66 ApplyPacScript(pac_dict) &&
67 ApplyProxyRules(proxy_rules); 67 ApplyProxyRules(proxy_rules);
68 } 68 }
69 69
70 bool UseCustomProxySettingsFunction::GetProxyServer( 70 bool UseCustomProxySettingsFunction::GetProxyServer(
71 const DictionaryValue* dict, ProxyServer* proxy_server) { 71 const DictionaryValue* dict, ProxyServer* proxy_server) {
72 dict->GetString("scheme", &proxy_server->scheme); 72 dict->GetString("scheme", &proxy_server->scheme);
73 EXTENSION_FUNCTION_VALIDATE(dict->GetString("host", &proxy_server->host)); 73 EXTENSION_FUNCTION_VALIDATE(dict->GetString("host", &proxy_server->host));
74 dict->GetInteger("port", &proxy_server->port); 74 dict->GetInteger("port", &proxy_server->port);
75 return true; 75 return true;
76 } 76 }
77 77
78 bool UseCustomProxySettingsFunction::ApplyAutoDetect(bool auto_detect) { 78 bool UseCustomProxySettingsFunction::ApplyMode(int mode) {
79 // We take control of the auto-detect preference even if none was specified, 79 // 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 80 // so that all proxy preferences are controlled by the same extension (if not
81 // by a higher-priority source). 81 // by a higher-priority source).
82 SendNotification(prefs::kProxyAutoDetect, 82 SendNotification(prefs::kProxyServerMode,
83 Value::CreateBooleanValue(auto_detect)); 83 Value::CreateIntegerValue(mode));
84 return true; 84 return true;
85 } 85 }
86 86
87 bool UseCustomProxySettingsFunction::ApplyPacScript(DictionaryValue* pac_dict) { 87 bool UseCustomProxySettingsFunction::ApplyPacScript(DictionaryValue* pac_dict) {
88 std::string pac_url; 88 std::string pac_url;
89 if (pac_dict) 89 if (pac_dict)
90 pac_dict->GetString("url", &pac_url); 90 pac_dict->GetString("url", &pac_url);
91 91
92 // We take control of the PAC preference even if none was specified, so that 92 // 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 93 // all proxy preferences are controlled by the same extension (if not by a
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 155
156 SendNotification(prefs::kProxyServer, Value::CreateStringValue(proxy_pref)); 156 SendNotification(prefs::kProxyServer, Value::CreateStringValue(proxy_pref));
157 return true; 157 return true;
158 } 158 }
159 159
160 void UseCustomProxySettingsFunction::SendNotification(const char* pref_path, 160 void UseCustomProxySettingsFunction::SendNotification(const char* pref_path,
161 Value* pref_value) { 161 Value* pref_value) {
162 profile()->GetExtensionsService()->extension_prefs() 162 profile()->GetExtensionsService()->extension_prefs()
163 ->SetExtensionControlledPref(extension_id(), pref_path, pref_value); 163 ->SetExtensionControlledPref(extension_id(), pref_path, pref_value);
164 } 164 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698