| 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 case ProxyPrefs::CONFIG_FALLBACK: |
| 282 controlled_by = config.user_modifiable ? |
| 283 "policyManagedPrefsBannerText" : "enableSharedProxiesBannerText"; |
| 284 break; |
| 285 default: |
| 286 if (!config.user_modifiable) |
| 287 controlled_by = "enableSharedProxiesBannerText"; |
| 288 break; |
| 289 } |
| 277 found = true; | 290 found = true; |
| 278 } else if (path == kProxySingle) { | 291 } else if (path == kProxySingle) { |
| 279 data = Value::CreateBooleanValue(config.mode == | 292 data = Value::CreateBooleanValue(config.mode == |
| 280 chromeos::ProxyConfigServiceImpl::ProxyConfig::MODE_SINGLE_PROXY); | 293 chromeos::ProxyConfigServiceImpl::ProxyConfig::MODE_SINGLE_PROXY); |
| 281 found = true; | 294 found = true; |
| 282 } else if (path == kProxyFtpUrl) { | 295 } else if (path == kProxyFtpUrl) { |
| 283 data = CreateServerHostValue(config.ftp_proxy); | 296 data = CreateServerHostValue(config.ftp_proxy); |
| 284 found = true; | 297 found = true; |
| 285 } else if (path == kProxySocks) { | 298 } else if (path == kProxySocks) { |
| 286 data = CreateServerHostValue(config.socks_proxy); | 299 data = CreateServerHostValue(config.socks_proxy); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 305 } | 318 } |
| 306 *out_value = list; | 319 *out_value = list; |
| 307 return true; | 320 return true; |
| 308 } | 321 } |
| 309 if (found) { | 322 if (found) { |
| 310 DictionaryValue* dict = new DictionaryValue; | 323 DictionaryValue* dict = new DictionaryValue; |
| 311 if (!data) | 324 if (!data) |
| 312 data = Value::CreateStringValue(""); | 325 data = Value::CreateStringValue(""); |
| 313 dict->Set("value", data); | 326 dict->Set("value", data); |
| 314 dict->SetBoolean("managed", managed); | 327 dict->SetBoolean("managed", managed); |
| 328 if (path == kProxyType) { |
| 329 dict->SetString("controlledBy", controlled_by); |
| 330 dict->SetBoolean("disabled", !config.user_modifiable); |
| 331 } |
| 315 *out_value = dict; | 332 *out_value = dict; |
| 316 return true; | 333 return true; |
| 317 } else { | 334 } else { |
| 318 *out_value = NULL; | 335 *out_value = NULL; |
| 319 return false; | 336 return false; |
| 320 } | 337 } |
| 321 } | 338 } |
| 322 | 339 |
| 323 bool ProxyCrosSettingsProvider::HandlesSetting(const std::string& path) const { | 340 bool ProxyCrosSettingsProvider::HandlesSetting(const std::string& path) const { |
| 324 return ::StartsWithASCII(path, "cros.session.proxy", true); | 341 return ::StartsWithASCII(path, "cros.session.proxy", true); |
| 325 } | 342 } |
| 326 | 343 |
| 327 //----------------- ProxyCrosSettingsProvider: private methods ----------------- | 344 //----------------- ProxyCrosSettingsProvider: private methods ----------------- |
| 328 | 345 |
| 329 chromeos::ProxyConfigServiceImpl* | 346 chromeos::ProxyConfigServiceImpl* |
| 330 ProxyCrosSettingsProvider::GetConfigService() const { | 347 ProxyCrosSettingsProvider::GetConfigService() const { |
| 331 return g_browser_process->chromeos_proxy_config_service_impl(); | 348 return profile_->GetProxyConfigTracker(); |
| 332 } | 349 } |
| 333 | 350 |
| 334 net::ProxyServer ProxyCrosSettingsProvider::CreateProxyServerFromHost( | 351 net::ProxyServer ProxyCrosSettingsProvider::CreateProxyServerFromHost( |
| 335 const std::string& host, | 352 const std::string& host, |
| 336 const ProxyConfigServiceImpl::ProxyConfig::ManualProxy& proxy, | 353 const ProxyConfigServiceImpl::ProxyConfig::ManualProxy& proxy, |
| 337 net::ProxyServer::Scheme scheme) const { | 354 net::ProxyServer::Scheme scheme) const { |
| 338 uint16 port = 0; | 355 uint16 port = 0; |
| 339 if (proxy.server.is_valid()) | 356 if (proxy.server.is_valid()) |
| 340 port = proxy.server.host_port_pair().port(); | 357 port = proxy.server.host_port_pair().port(); |
| 341 if (host.length() == 0 && port == 0) | 358 if (host.length() == 0 && port == 0) |
| (...skipping 25 matching lines...) Expand all Loading... |
| 367 } | 384 } |
| 368 | 385 |
| 369 Value* ProxyCrosSettingsProvider::CreateServerPortValue( | 386 Value* ProxyCrosSettingsProvider::CreateServerPortValue( |
| 370 const ProxyConfigServiceImpl::ProxyConfig::ManualProxy& proxy) const { | 387 const ProxyConfigServiceImpl::ProxyConfig::ManualProxy& proxy) const { |
| 371 return proxy.server.is_valid() ? | 388 return proxy.server.is_valid() ? |
| 372 Value::CreateIntegerValue(proxy.server.host_port_pair().port()) : | 389 Value::CreateIntegerValue(proxy.server.host_port_pair().port()) : |
| 373 NULL; | 390 NULL; |
| 374 } | 391 } |
| 375 | 392 |
| 376 } // namespace chromeos | 393 } // namespace chromeos |
| OLD | NEW |