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/extensions/extension_pref_store.h" | 10 #include "chrome/browser/extensions/extension_pref_store.h" |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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::ApplyAutoDetect(bool auto_detect) { |
79 // We take control of the auto-detect preference even if none was specified, | 79 // We take control of the auto-detect 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 scoped_ptr<Value> value(Value::CreateBooleanValue(auto_detect)); |
83 Value::CreateBooleanValue(auto_detect)); | 83 SendNotification(prefs::kProxyAutoDetect, value.get()); |
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 |
94 // higher-priority source). | 94 // higher-priority source). |
95 SendNotification(prefs::kProxyPacUrl, Value::CreateStringValue(pac_url)); | 95 scoped_ptr<Value> value(Value::CreateStringValue(pac_url)); |
| 96 SendNotification(prefs::kProxyPacUrl, value.get()); |
96 return true; | 97 return true; |
97 } | 98 } |
98 | 99 |
99 bool UseCustomProxySettingsFunction::ApplyProxyRules( | 100 bool UseCustomProxySettingsFunction::ApplyProxyRules( |
100 DictionaryValue* proxy_rules) { | 101 DictionaryValue* proxy_rules) { |
101 if (!proxy_rules) | 102 if (!proxy_rules) |
102 return true; | 103 return true; |
103 | 104 |
104 // Local data into which the parameters will be parsed. has_proxy describes | 105 // Local data into which the parameters will be parsed. has_proxy describes |
105 // whether a setting was found for the scheme; proxy_dict holds the | 106 // whether a setting was found for the scheme; proxy_dict holds the |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 proxy_pref.append(proxy_server[i].scheme); | 147 proxy_pref.append(proxy_server[i].scheme); |
147 proxy_pref.append("://"); | 148 proxy_pref.append("://"); |
148 proxy_pref.append(proxy_server[i].host); | 149 proxy_pref.append(proxy_server[i].host); |
149 if (proxy_server[i].port != ProxyServer::INVALID_PORT) { | 150 if (proxy_server[i].port != ProxyServer::INVALID_PORT) { |
150 proxy_pref.append(":"); | 151 proxy_pref.append(":"); |
151 proxy_pref.append(base::StringPrintf("%d", proxy_server[i].port)); | 152 proxy_pref.append(base::StringPrintf("%d", proxy_server[i].port)); |
152 } | 153 } |
153 } | 154 } |
154 } | 155 } |
155 | 156 |
156 SendNotification(prefs::kProxyServer, Value::CreateStringValue(proxy_pref)); | 157 scoped_ptr<Value> value(Value::CreateStringValue(proxy_pref)); |
| 158 SendNotification(prefs::kProxyServer, value.get()); |
157 return true; | 159 return true; |
158 } | 160 } |
159 | 161 |
160 void UseCustomProxySettingsFunction::SendNotification(const char* pref_path, | 162 void UseCustomProxySettingsFunction::SendNotification(const char* pref_path, |
161 Value* pref_value) { | 163 Value* pref_value) { |
162 ExtensionPrefStore::ExtensionPrefDetails details = | 164 ExtensionPrefStore::ExtensionPrefDetails details = |
163 std::make_pair(GetExtension(), std::make_pair(pref_path, pref_value)); | 165 std::make_pair(GetExtension(), std::make_pair(pref_path, pref_value)); |
164 | 166 |
165 NotificationService::current()->Notify( | 167 NotificationService::current()->Notify( |
166 NotificationType::EXTENSION_PREF_CHANGED, | 168 NotificationType::EXTENSION_PREF_CHANGED, |
167 Source<Profile>(profile_), | 169 Source<Profile>(profile_), |
168 Details<ExtensionPrefStore::ExtensionPrefDetails>(&details)); | 170 Details<ExtensionPrefStore::ExtensionPrefDetails>(&details)); |
169 } | 171 } |
OLD | NEW |