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/profiles/profile.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 18 matching lines...) Expand all Loading... |
38 kProxySingle, | 39 kProxySingle, |
39 kProxyFtpUrl, | 40 kProxyFtpUrl, |
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(Profile* profile) |
| 50 : profile_(profile) { |
| 51 } |
49 | 52 |
50 void ProxyCrosSettingsProvider::SetCurrentNetwork(const std::string& network) { | 53 void ProxyCrosSettingsProvider::SetCurrentNetwork(const std::string& network) { |
51 if (!GetConfigService()->UISetCurrentNetwork(network)) | 54 GetConfigService()->UISetCurrentNetwork(network); |
52 return; | |
53 for (size_t i = 0; i < arraysize(kProxySettings); ++i) | 55 for (size_t i = 0; i < arraysize(kProxySettings); ++i) |
54 CrosSettings::Get()->FireObservers(kProxySettings[i]); | 56 CrosSettings::Get()->FireObservers(kProxySettings[i]); |
55 } | 57 } |
56 | 58 |
57 void ProxyCrosSettingsProvider::MakeActiveNetworkCurrent() { | 59 void ProxyCrosSettingsProvider::MakeActiveNetworkCurrent() { |
58 if (!GetConfigService()->UIMakeActiveNetworkCurrent()) | 60 GetConfigService()->UIMakeActiveNetworkCurrent(); |
59 return; | |
60 for (size_t i = 0; i < arraysize(kProxySettings); ++i) | 61 for (size_t i = 0; i < arraysize(kProxySettings); ++i) |
61 CrosSettings::Get()->FireObservers(kProxySettings[i]); | 62 CrosSettings::Get()->FireObservers(kProxySettings[i]); |
62 } | 63 } |
63 | 64 |
64 bool ProxyCrosSettingsProvider::IsUsingSharedProxies() const { | |
65 return GetConfigService()->use_shared_proxies(); | |
66 } | |
67 | |
68 const std::string& ProxyCrosSettingsProvider::GetCurrentNetworkName() const { | |
69 return GetConfigService()->current_network_name(); | |
70 } | |
71 | |
72 void ProxyCrosSettingsProvider::DoSet(const std::string& path, | 65 void ProxyCrosSettingsProvider::DoSet(const std::string& path, |
73 Value* in_value) { | 66 Value* in_value) { |
74 if (!in_value) { | 67 if (!in_value) { |
75 return; | 68 return; |
76 } | 69 } |
77 | 70 |
78 chromeos::ProxyConfigServiceImpl* config_service = GetConfigService(); | 71 chromeos::ProxyConfigServiceImpl* config_service = GetConfigService(); |
79 // Retrieve proxy config. | 72 // Retrieve proxy config. |
80 chromeos::ProxyConfigServiceImpl::ProxyConfig config; | 73 chromeos::ProxyConfigServiceImpl::ProxyConfig config; |
81 config_service->UIGetProxyConfig(&config); | 74 config_service->UIGetProxyConfig(&config); |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 } | 221 } |
229 config_service->UISetProxyConfigBypassRules(bypass_rules); | 222 config_service->UISetProxyConfigBypassRules(bypass_rules); |
230 } | 223 } |
231 } | 224 } |
232 } | 225 } |
233 | 226 |
234 bool ProxyCrosSettingsProvider::Get(const std::string& path, | 227 bool ProxyCrosSettingsProvider::Get(const std::string& path, |
235 Value** out_value) const { | 228 Value** out_value) const { |
236 bool found = false; | 229 bool found = false; |
237 bool managed = false; | 230 bool managed = false; |
| 231 std::string controlled_by; |
238 Value* data = NULL; | 232 Value* data = NULL; |
239 chromeos::ProxyConfigServiceImpl* config_service = GetConfigService(); | 233 chromeos::ProxyConfigServiceImpl* config_service = GetConfigService(); |
240 chromeos::ProxyConfigServiceImpl::ProxyConfig config; | 234 chromeos::ProxyConfigServiceImpl::ProxyConfig config; |
241 config_service->UIGetProxyConfig(&config); | 235 config_service->UIGetProxyConfig(&config); |
242 | 236 |
243 if (path == kProxyPacUrl) { | 237 if (path == kProxyPacUrl) { |
244 // Only show pacurl for pac-script mode. | 238 // Only show pacurl for pac-script mode. |
245 if (config.mode == | 239 if (config.mode == |
246 chromeos::ProxyConfigServiceImpl::ProxyConfig::MODE_PAC_SCRIPT && | 240 chromeos::ProxyConfigServiceImpl::ProxyConfig::MODE_PAC_SCRIPT && |
247 config.automatic_proxy.pac_url.is_valid()) { | 241 config.automatic_proxy.pac_url.is_valid()) { |
(...skipping 19 matching lines...) Expand all Loading... |
267 chromeos::ProxyConfigServiceImpl::ProxyConfig::MODE_PAC_SCRIPT) { | 261 chromeos::ProxyConfigServiceImpl::ProxyConfig::MODE_PAC_SCRIPT) { |
268 data = Value::CreateIntegerValue(3); | 262 data = Value::CreateIntegerValue(3); |
269 } else if (config.mode == | 263 } else if (config.mode == |
270 chromeos::ProxyConfigServiceImpl::ProxyConfig::MODE_SINGLE_PROXY || | 264 chromeos::ProxyConfigServiceImpl::ProxyConfig::MODE_SINGLE_PROXY || |
271 config.mode == | 265 config.mode == |
272 chromeos::ProxyConfigServiceImpl::ProxyConfig::MODE_PROXY_PER_SCHEME) { | 266 chromeos::ProxyConfigServiceImpl::ProxyConfig::MODE_PROXY_PER_SCHEME) { |
273 data = Value::CreateIntegerValue(2); | 267 data = Value::CreateIntegerValue(2); |
274 } else { | 268 } else { |
275 data = Value::CreateIntegerValue(1); | 269 data = Value::CreateIntegerValue(1); |
276 } | 270 } |
| 271 switch (config.state) { |
| 272 case ProxyPrefs::CONFIG_POLICY: |
| 273 controlled_by = "policyManagedPrefsBannerText"; |
| 274 break; |
| 275 case ProxyPrefs::CONFIG_EXTENSION: |
| 276 controlled_by = "extensionManagedPrefsBannerText"; |
| 277 break; |
| 278 case ProxyPrefs::CONFIG_OTHER_PRECEDE: |
| 279 controlled_by = "unmodifiablePrefsBannerText"; |
| 280 break; |
| 281 default: |
| 282 if (!config.user_modifiable) |
| 283 controlled_by = "enableSharedProxiesBannerText"; |
| 284 break; |
| 285 } |
277 found = true; | 286 found = true; |
278 } else if (path == kProxySingle) { | 287 } else if (path == kProxySingle) { |
279 data = Value::CreateBooleanValue(config.mode == | 288 data = Value::CreateBooleanValue(config.mode == |
280 chromeos::ProxyConfigServiceImpl::ProxyConfig::MODE_SINGLE_PROXY); | 289 chromeos::ProxyConfigServiceImpl::ProxyConfig::MODE_SINGLE_PROXY); |
281 found = true; | 290 found = true; |
282 } else if (path == kProxyFtpUrl) { | 291 } else if (path == kProxyFtpUrl) { |
283 data = CreateServerHostValue(config.ftp_proxy); | 292 data = CreateServerHostValue(config.ftp_proxy); |
284 found = true; | 293 found = true; |
285 } else if (path == kProxySocks) { | 294 } else if (path == kProxySocks) { |
286 data = CreateServerHostValue(config.socks_proxy); | 295 data = CreateServerHostValue(config.socks_proxy); |
(...skipping 18 matching lines...) Expand all Loading... |
305 } | 314 } |
306 *out_value = list; | 315 *out_value = list; |
307 return true; | 316 return true; |
308 } | 317 } |
309 if (found) { | 318 if (found) { |
310 DictionaryValue* dict = new DictionaryValue; | 319 DictionaryValue* dict = new DictionaryValue; |
311 if (!data) | 320 if (!data) |
312 data = Value::CreateStringValue(""); | 321 data = Value::CreateStringValue(""); |
313 dict->Set("value", data); | 322 dict->Set("value", data); |
314 dict->SetBoolean("managed", managed); | 323 dict->SetBoolean("managed", managed); |
| 324 if (path == kProxyType) { |
| 325 dict->SetString("controlledBy", controlled_by); |
| 326 dict->SetBoolean("disabled", !config.user_modifiable); |
| 327 } |
315 *out_value = dict; | 328 *out_value = dict; |
316 return true; | 329 return true; |
317 } else { | 330 } else { |
318 *out_value = NULL; | 331 *out_value = NULL; |
319 return false; | 332 return false; |
320 } | 333 } |
321 } | 334 } |
322 | 335 |
323 bool ProxyCrosSettingsProvider::HandlesSetting(const std::string& path) const { | 336 bool ProxyCrosSettingsProvider::HandlesSetting(const std::string& path) const { |
324 return ::StartsWithASCII(path, "cros.session.proxy", true); | 337 return ::StartsWithASCII(path, "cros.session.proxy", true); |
325 } | 338 } |
326 | 339 |
327 //----------------- ProxyCrosSettingsProvider: private methods ----------------- | 340 //----------------- ProxyCrosSettingsProvider: private methods ----------------- |
328 | 341 |
329 chromeos::ProxyConfigServiceImpl* | 342 chromeos::ProxyConfigServiceImpl* |
330 ProxyCrosSettingsProvider::GetConfigService() const { | 343 ProxyCrosSettingsProvider::GetConfigService() const { |
331 return g_browser_process->chromeos_proxy_config_service_impl(); | 344 return profile_->GetProxyConfigTracker(); |
332 } | 345 } |
333 | 346 |
334 net::ProxyServer ProxyCrosSettingsProvider::CreateProxyServerFromHost( | 347 net::ProxyServer ProxyCrosSettingsProvider::CreateProxyServerFromHost( |
335 const std::string& host, | 348 const std::string& host, |
336 const ProxyConfigServiceImpl::ProxyConfig::ManualProxy& proxy, | 349 const ProxyConfigServiceImpl::ProxyConfig::ManualProxy& proxy, |
337 net::ProxyServer::Scheme scheme) const { | 350 net::ProxyServer::Scheme scheme) const { |
338 uint16 port = 0; | 351 uint16 port = 0; |
339 if (proxy.server.is_valid()) | 352 if (proxy.server.is_valid()) |
340 port = proxy.server.host_port_pair().port(); | 353 port = proxy.server.host_port_pair().port(); |
341 if (host.length() == 0 && port == 0) | 354 if (host.length() == 0 && port == 0) |
(...skipping 25 matching lines...) Expand all Loading... |
367 } | 380 } |
368 | 381 |
369 Value* ProxyCrosSettingsProvider::CreateServerPortValue( | 382 Value* ProxyCrosSettingsProvider::CreateServerPortValue( |
370 const ProxyConfigServiceImpl::ProxyConfig::ManualProxy& proxy) const { | 383 const ProxyConfigServiceImpl::ProxyConfig::ManualProxy& proxy) const { |
371 return proxy.server.is_valid() ? | 384 return proxy.server.is_valid() ? |
372 Value::CreateIntegerValue(proxy.server.host_port_pair().port()) : | 385 Value::CreateIntegerValue(proxy.server.host_port_pair().port()) : |
373 NULL; | 386 NULL; |
374 } | 387 } |
375 | 388 |
376 } // namespace chromeos | 389 } // namespace chromeos |
OLD | NEW |