OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/chromeos/proxy_cros_settings_provider.h" | 5 #include "chrome/browser/chromeos/proxy_cros_settings_provider.h" |
6 | 6 |
7 #include "base/string_util.h" | 7 #include "base/string_util.h" |
8 #include "chrome/browser/browser_process.h" | 8 #include "chrome/browser/browser_process.h" |
9 #include "chrome/browser/chromeos/cros_settings.h" | 9 #include "chrome/browser/chromeos/cros_settings.h" |
10 #include "chrome/browser/net/pref_proxy_config_service.h" | |
10 #include "chrome/browser/ui/browser_list.h" | 11 #include "chrome/browser/ui/browser_list.h" |
11 | 12 |
12 namespace chromeos { | 13 namespace chromeos { |
13 | 14 |
14 static const char kProxyPacUrl[] = "cros.session.proxy.pacurl"; | 15 static const char kProxyPacUrl[] = "cros.session.proxy.pacurl"; |
15 static const char kProxySingleHttp[] = "cros.session.proxy.singlehttp"; | 16 static const char kProxySingleHttp[] = "cros.session.proxy.singlehttp"; |
16 static const char kProxySingleHttpPort[] = "cros.session.proxy.singlehttpport"; | 17 static const char kProxySingleHttpPort[] = "cros.session.proxy.singlehttpport"; |
17 static const char kProxyHttpUrl[] = "cros.session.proxy.httpurl"; | 18 static const char kProxyHttpUrl[] = "cros.session.proxy.httpurl"; |
18 static const char kProxyHttpPort[] = "cros.session.proxy.httpport"; | 19 static const char kProxyHttpPort[] = "cros.session.proxy.httpport"; |
19 static const char kProxyHttpsUrl[] = "cros.session.proxy.httpsurl"; | 20 static const char kProxyHttpsUrl[] = "cros.session.proxy.httpsurl"; |
(...skipping 20 matching lines...) Expand all Loading... | |
40 kProxyFtpPort, | 41 kProxyFtpPort, |
41 kProxySocks, | 42 kProxySocks, |
42 kProxySocksPort, | 43 kProxySocksPort, |
43 kProxyIgnoreList, | 44 kProxyIgnoreList, |
44 }; | 45 }; |
45 | 46 |
46 //------------------ ProxyCrosSettingsProvider: public methods ----------------- | 47 //------------------ ProxyCrosSettingsProvider: public methods ----------------- |
47 | 48 |
48 ProxyCrosSettingsProvider::ProxyCrosSettingsProvider() { } | 49 ProxyCrosSettingsProvider::ProxyCrosSettingsProvider() { } |
49 | 50 |
51 void ProxyCrosSettingsProvider::SetCurrentUserProfile(Profile* profile) { | |
52 GetConfigService()->UISetCurrentUserProfile(profile); | |
53 } | |
54 | |
50 void ProxyCrosSettingsProvider::SetCurrentNetwork(const std::string& network) { | 55 void ProxyCrosSettingsProvider::SetCurrentNetwork(const std::string& network) { |
51 if (!GetConfigService()->UISetCurrentNetwork(network)) | 56 GetConfigService()->UISetCurrentNetwork(network); |
52 return; | |
53 for (size_t i = 0; i < arraysize(kProxySettings); ++i) | 57 for (size_t i = 0; i < arraysize(kProxySettings); ++i) |
54 CrosSettings::Get()->FireObservers(kProxySettings[i]); | 58 CrosSettings::Get()->FireObservers(kProxySettings[i]); |
55 } | 59 } |
56 | 60 |
57 void ProxyCrosSettingsProvider::MakeActiveNetworkCurrent() { | 61 void ProxyCrosSettingsProvider::MakeActiveNetworkCurrent() { |
58 if (!GetConfigService()->UIMakeActiveNetworkCurrent()) | 62 GetConfigService()->UIMakeActiveNetworkCurrent(); |
59 return; | |
60 for (size_t i = 0; i < arraysize(kProxySettings); ++i) | 63 for (size_t i = 0; i < arraysize(kProxySettings); ++i) |
61 CrosSettings::Get()->FireObservers(kProxySettings[i]); | 64 CrosSettings::Get()->FireObservers(kProxySettings[i]); |
62 } | 65 } |
63 | 66 |
64 bool ProxyCrosSettingsProvider::IsUsingSharedProxies() const { | |
65 return GetConfigService()->use_shared_proxies(); | |
66 } | |
67 | |
68 const std::string& ProxyCrosSettingsProvider::GetCurrentNetworkName() const { | 67 const std::string& ProxyCrosSettingsProvider::GetCurrentNetworkName() const { |
69 return GetConfigService()->current_network_name(); | 68 return GetConfigService()->current_network_name(); |
70 } | 69 } |
71 | 70 |
72 void ProxyCrosSettingsProvider::DoSet(const std::string& path, | 71 void ProxyCrosSettingsProvider::DoSet(const std::string& path, |
73 Value* in_value) { | 72 Value* in_value) { |
74 if (!in_value) { | 73 if (!in_value) { |
75 return; | 74 return; |
76 } | 75 } |
77 | 76 |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
228 } | 227 } |
229 config_service->UISetProxyConfigBypassRules(bypass_rules); | 228 config_service->UISetProxyConfigBypassRules(bypass_rules); |
230 } | 229 } |
231 } | 230 } |
232 } | 231 } |
233 | 232 |
234 bool ProxyCrosSettingsProvider::Get(const std::string& path, | 233 bool ProxyCrosSettingsProvider::Get(const std::string& path, |
235 Value** out_value) const { | 234 Value** out_value) const { |
236 bool found = false; | 235 bool found = false; |
237 bool managed = false; | 236 bool managed = false; |
237 std::string controlled_by; | |
238 Value* data = NULL; | 238 Value* data = NULL; |
239 chromeos::ProxyConfigServiceImpl* config_service = GetConfigService(); | 239 chromeos::ProxyConfigServiceImpl* config_service = GetConfigService(); |
240 chromeos::ProxyConfigServiceImpl::ProxyConfig config; | 240 chromeos::ProxyConfigServiceImpl::ProxyConfig config; |
241 config_service->UIGetProxyConfig(&config); | 241 config_service->UIGetProxyConfig(&config); |
242 | 242 |
243 if (path == kProxyPacUrl) { | 243 if (path == kProxyPacUrl) { |
244 // Only show pacurl for pac-script mode. | 244 // Only show pacurl for pac-script mode. |
245 if (config.mode == | 245 if (config.mode == |
246 chromeos::ProxyConfigServiceImpl::ProxyConfig::MODE_PAC_SCRIPT && | 246 chromeos::ProxyConfigServiceImpl::ProxyConfig::MODE_PAC_SCRIPT && |
247 config.automatic_proxy.pac_url.is_valid()) { | 247 config.automatic_proxy.pac_url.is_valid()) { |
(...skipping 19 matching lines...) Expand all Loading... | |
267 chromeos::ProxyConfigServiceImpl::ProxyConfig::MODE_PAC_SCRIPT) { | 267 chromeos::ProxyConfigServiceImpl::ProxyConfig::MODE_PAC_SCRIPT) { |
268 data = Value::CreateIntegerValue(3); | 268 data = Value::CreateIntegerValue(3); |
269 } else if (config.mode == | 269 } else if (config.mode == |
270 chromeos::ProxyConfigServiceImpl::ProxyConfig::MODE_SINGLE_PROXY || | 270 chromeos::ProxyConfigServiceImpl::ProxyConfig::MODE_SINGLE_PROXY || |
271 config.mode == | 271 config.mode == |
272 chromeos::ProxyConfigServiceImpl::ProxyConfig::MODE_PROXY_PER_SCHEME) { | 272 chromeos::ProxyConfigServiceImpl::ProxyConfig::MODE_PROXY_PER_SCHEME) { |
273 data = Value::CreateIntegerValue(2); | 273 data = Value::CreateIntegerValue(2); |
274 } else { | 274 } else { |
275 data = Value::CreateIntegerValue(1); | 275 data = Value::CreateIntegerValue(1); |
276 } | 276 } |
277 switch (config.source) { | |
278 case PrefProxyConfigTracker::CONFIG_SOURCE_POLICY: | |
279 controlled_by = "policyManagedPrefsBannerText"; | |
280 break; | |
281 case PrefProxyConfigTracker::CONFIG_SOURCE_EXTENSION: | |
282 controlled_by = "extensionManagedPrefsBannerText"; | |
283 break; | |
284 case PrefProxyConfigTracker::CONFIG_SOURCE_FALLBACK: | |
285 controlled_by = config.user_modifiable ? | |
286 "policyManagedPrefsBannerText" : "enableSharedProxiesBannerText"; | |
287 break; | |
288 default: | |
289 if (!config.user_modifiable) | |
290 controlled_by = "enableSharedProxiesBannerText"; | |
291 break; | |
292 } | |
277 found = true; | 293 found = true; |
278 } else if (path == kProxySingle) { | 294 } else if (path == kProxySingle) { |
279 data = Value::CreateBooleanValue(config.mode == | 295 data = Value::CreateBooleanValue(config.mode == |
280 chromeos::ProxyConfigServiceImpl::ProxyConfig::MODE_SINGLE_PROXY); | 296 chromeos::ProxyConfigServiceImpl::ProxyConfig::MODE_SINGLE_PROXY); |
281 found = true; | 297 found = true; |
282 } else if (path == kProxyFtpUrl) { | 298 } else if (path == kProxyFtpUrl) { |
283 data = CreateServerHostValue(config.ftp_proxy); | 299 data = CreateServerHostValue(config.ftp_proxy); |
284 found = true; | 300 found = true; |
285 } else if (path == kProxySocks) { | 301 } else if (path == kProxySocks) { |
286 data = CreateServerHostValue(config.socks_proxy); | 302 data = CreateServerHostValue(config.socks_proxy); |
(...skipping 18 matching lines...) Expand all Loading... | |
305 } | 321 } |
306 *out_value = list; | 322 *out_value = list; |
307 return true; | 323 return true; |
308 } | 324 } |
309 if (found) { | 325 if (found) { |
310 DictionaryValue* dict = new DictionaryValue; | 326 DictionaryValue* dict = new DictionaryValue; |
311 if (!data) | 327 if (!data) |
312 data = Value::CreateStringValue(""); | 328 data = Value::CreateStringValue(""); |
313 dict->Set("value", data); | 329 dict->Set("value", data); |
314 dict->SetBoolean("managed", managed); | 330 dict->SetBoolean("managed", managed); |
331 if (path == kProxyType) { | |
Mattias Nissler (ping if slow)
2011/10/07 13:32:10
why only kProxyType?
kuan
2011/10/18 16:25:35
this is because all the other input fields are ena
| |
332 dict->SetString("controlledBy", controlled_by); | |
333 dict->SetBoolean("disabled", !config.user_modifiable); | |
334 } | |
315 *out_value = dict; | 335 *out_value = dict; |
316 return true; | 336 return true; |
317 } else { | 337 } else { |
318 *out_value = NULL; | 338 *out_value = NULL; |
319 return false; | 339 return false; |
320 } | 340 } |
321 } | 341 } |
322 | 342 |
323 bool ProxyCrosSettingsProvider::HandlesSetting(const std::string& path) const { | 343 bool ProxyCrosSettingsProvider::HandlesSetting(const std::string& path) const { |
324 return ::StartsWithASCII(path, "cros.session.proxy", true); | 344 return ::StartsWithASCII(path, "cros.session.proxy", true); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
367 } | 387 } |
368 | 388 |
369 Value* ProxyCrosSettingsProvider::CreateServerPortValue( | 389 Value* ProxyCrosSettingsProvider::CreateServerPortValue( |
370 const ProxyConfigServiceImpl::ProxyConfig::ManualProxy& proxy) const { | 390 const ProxyConfigServiceImpl::ProxyConfig::ManualProxy& proxy) const { |
371 return proxy.server.is_valid() ? | 391 return proxy.server.is_valid() ? |
372 Value::CreateIntegerValue(proxy.server.host_port_pair().port()) : | 392 Value::CreateIntegerValue(proxy.server.host_port_pair().port()) : |
373 NULL; | 393 NULL; |
374 } | 394 } |
375 | 395 |
376 } // namespace chromeos | 396 } // namespace chromeos |
OLD | NEW |