Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "extensions/browser/api/networking_private/networking_private_chromeos. h" | 5 #include "extensions/browser/api/networking_private/networking_private_chromeos. h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/memory/ptr_util.h" | |
| 11 #include "base/values.h" | 12 #include "base/values.h" |
| 12 #include "chromeos/dbus/dbus_thread_manager.h" | 13 #include "chromeos/dbus/dbus_thread_manager.h" |
| 13 #include "chromeos/dbus/shill_manager_client.h" | 14 #include "chromeos/dbus/shill_manager_client.h" |
| 14 #include "chromeos/login/login_state.h" | 15 #include "chromeos/login/login_state.h" |
| 15 #include "chromeos/network/device_state.h" | 16 #include "chromeos/network/device_state.h" |
| 16 #include "chromeos/network/managed_network_configuration_handler.h" | 17 #include "chromeos/network/managed_network_configuration_handler.h" |
| 17 #include "chromeos/network/network_activation_handler.h" | 18 #include "chromeos/network/network_activation_handler.h" |
| 18 #include "chromeos/network/network_connection_handler.h" | 19 #include "chromeos/network/network_connection_handler.h" |
| 19 #include "chromeos/network/network_device_handler.h" | 20 #include "chromeos/network/network_device_handler.h" |
| 20 #include "chromeos/network/network_event_log.h" | 21 #include "chromeos/network/network_event_log.h" |
| 21 #include "chromeos/network/network_state.h" | 22 #include "chromeos/network/network_state.h" |
| 22 #include "chromeos/network/network_state_handler.h" | 23 #include "chromeos/network/network_state_handler.h" |
| 23 #include "chromeos/network/network_util.h" | 24 #include "chromeos/network/network_util.h" |
| 24 #include "chromeos/network/onc/onc_signature.h" | 25 #include "chromeos/network/onc/onc_signature.h" |
| 25 #include "chromeos/network/onc/onc_translator.h" | 26 #include "chromeos/network/onc/onc_translator.h" |
| 26 #include "chromeos/network/onc/onc_utils.h" | 27 #include "chromeos/network/onc/onc_utils.h" |
| 27 #include "chromeos/network/portal_detector/network_portal_detector.h" | 28 #include "chromeos/network/portal_detector/network_portal_detector.h" |
| 29 #include "chromeos/network/proxy/ui_proxy_config.h" | |
| 30 #include "chromeos/network/proxy/ui_proxy_config_service.h" | |
| 28 #include "components/onc/onc_constants.h" | 31 #include "components/onc/onc_constants.h" |
| 32 #include "components/proxy_config/proxy_prefs.h" | |
| 29 #include "content/public/browser/browser_context.h" | 33 #include "content/public/browser/browser_context.h" |
| 30 #include "extensions/browser/api/networking_private/networking_private_api.h" | 34 #include "extensions/browser/api/networking_private/networking_private_api.h" |
| 31 #include "extensions/browser/extension_registry.h" | 35 #include "extensions/browser/extension_registry.h" |
| 32 #include "extensions/browser/extensions_browser_client.h" | 36 #include "extensions/browser/extensions_browser_client.h" |
| 33 #include "extensions/common/extension.h" | 37 #include "extensions/common/extension.h" |
| 34 #include "extensions/common/extension_set.h" | 38 #include "extensions/common/extension_set.h" |
| 35 #include "extensions/common/permissions/api_permission.h" | 39 #include "extensions/common/permissions/api_permission.h" |
| 36 #include "extensions/common/permissions/permissions_data.h" | 40 #include "extensions/common/permissions/permissions_data.h" |
| 37 #include "third_party/cros_system_api/dbus/service_constants.h" | 41 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 38 | 42 |
| 39 using chromeos::NetworkHandler; | 43 using chromeos::NetworkHandler; |
| 40 using chromeos::NetworkStateHandler; | 44 using chromeos::NetworkStateHandler; |
| 41 using chromeos::NetworkTypePattern; | 45 using chromeos::NetworkTypePattern; |
| 42 using chromeos::ShillManagerClient; | 46 using chromeos::ShillManagerClient; |
| 47 using chromeos::UIProxyConfig; | |
| 43 using extensions::NetworkingPrivateDelegate; | 48 using extensions::NetworkingPrivateDelegate; |
| 44 | 49 |
| 45 namespace private_api = extensions::api::networking_private; | 50 namespace private_api = extensions::api::networking_private; |
| 46 | 51 |
| 47 namespace { | 52 namespace { |
| 48 | 53 |
| 49 chromeos::NetworkStateHandler* GetStateHandler() { | 54 chromeos::NetworkStateHandler* GetStateHandler() { |
| 50 return NetworkHandler::Get()->network_state_handler(); | 55 return NetworkHandler::Get()->network_state_handler(); |
| 51 } | 56 } |
| 52 | 57 |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 207 device_state = | 212 device_state = |
| 208 GetStateHandler()->GetDeviceState(network_state->device_path()); | 213 GetStateHandler()->GetDeviceState(network_state->device_path()); |
| 209 } | 214 } |
| 210 if (!device_state) { | 215 if (!device_state) { |
| 211 device_state = | 216 device_state = |
| 212 GetStateHandler()->GetDeviceStateByType(NetworkTypePattern::Cellular()); | 217 GetStateHandler()->GetDeviceStateByType(NetworkTypePattern::Cellular()); |
| 213 } | 218 } |
| 214 return device_state; | 219 return device_state; |
| 215 } | 220 } |
| 216 | 221 |
| 222 // Ensures that |container| contains a DictionaryValue for |key| and | |
| 223 // returns the dictionary. | |
| 224 base::DictionaryValue* EnsureDictionaryValue(const std::string& key, | |
| 225 base::DictionaryValue* container) { | |
| 226 base::DictionaryValue* dict; | |
| 227 if (!container->GetDictionary(key, &dict)) { | |
| 228 container->SetWithoutPathExpansion( | |
| 229 key, base::MakeUnique<base::DictionaryValue>()); | |
| 230 container->GetDictionary(key, &dict); | |
| 231 } | |
| 232 return dict; | |
| 233 } | |
| 234 | |
| 235 // Sets the effective ONC dictionary value of |dict| to 'ActiveExtension' and | |
| 236 // sets the UserEditable property to false. | |
| 237 void SetEffectiveToActiveExtension(base::DictionaryValue* dict) { | |
| 238 dict->SetStringWithoutPathExpansion(::onc::kAugmentationEffectiveSetting, | |
| 239 ::onc::kAugmentationActiveExtension); | |
| 240 dict->SetBooleanWithoutPathExpansion(::onc::kAugmentationUserEditable, false); | |
| 241 } | |
| 242 | |
| 243 std::string GetProxySettingsType(const UIProxyConfig::Mode& mode) { | |
| 244 switch (mode) { | |
| 245 case UIProxyConfig::MODE_DIRECT: | |
| 246 return ::onc::proxy::kDirect; | |
| 247 case UIProxyConfig::MODE_AUTO_DETECT: | |
| 248 return ::onc::proxy::kWPAD; | |
| 249 case UIProxyConfig::MODE_PAC_SCRIPT: | |
| 250 return ::onc::proxy::kPAC; | |
| 251 case UIProxyConfig::MODE_SINGLE_PROXY: | |
| 252 case UIProxyConfig::MODE_PROXY_PER_SCHEME: | |
| 253 return ::onc::proxy::kManual; | |
| 254 } | |
| 255 NOTREACHED(); | |
| 256 return ::onc::proxy::kDirect; | |
| 257 } | |
| 258 | |
| 259 void SetManualProxy(base::DictionaryValue* manual, | |
| 260 const std::string& key, | |
|
michaelpg
2016/11/04 00:58:28
unused?
stevenjb
2016/11/09 22:20:18
Done.
| |
| 261 const UIProxyConfig::ManualProxy& proxy) { | |
| 262 manual->SetStringWithoutPathExpansion(::onc::proxy::kHost, | |
| 263 proxy.server.host_port_pair().host()); | |
| 264 uint16_t port = proxy.server.host_port_pair().port(); | |
| 265 manual->SetIntegerWithoutPathExpansion(::onc::proxy::kHost, | |
|
michaelpg
2016/11/04 00:58:28
kHost is being set twice...
stevenjb
2016/11/09 22:20:18
Done.
| |
| 266 static_cast<int>(port)); | |
| 267 } | |
| 268 | |
| 217 } // namespace | 269 } // namespace |
| 218 | 270 |
| 219 //////////////////////////////////////////////////////////////////////////////// | 271 //////////////////////////////////////////////////////////////////////////////// |
| 220 | 272 |
| 221 namespace extensions { | 273 namespace extensions { |
| 222 | 274 |
| 223 NetworkingPrivateChromeOS::NetworkingPrivateChromeOS( | 275 NetworkingPrivateChromeOS::NetworkingPrivateChromeOS( |
| 224 content::BrowserContext* browser_context, | 276 content::BrowserContext* browser_context, |
| 225 std::unique_ptr<VerifyDelegate> verify_delegate) | 277 std::unique_ptr<VerifyDelegate> verify_delegate) |
| 226 : NetworkingPrivateDelegate(std::move(verify_delegate)), | 278 : NetworkingPrivateDelegate(std::move(verify_delegate)), |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 242 | 294 |
| 243 std::string user_id_hash; | 295 std::string user_id_hash; |
| 244 if (!GetPrimaryUserIdHash(browser_context_, &user_id_hash, &error)) { | 296 if (!GetPrimaryUserIdHash(browser_context_, &user_id_hash, &error)) { |
| 245 failure_callback.Run(error); | 297 failure_callback.Run(error); |
| 246 return; | 298 return; |
| 247 } | 299 } |
| 248 | 300 |
| 249 GetManagedConfigurationHandler()->GetProperties( | 301 GetManagedConfigurationHandler()->GetProperties( |
| 250 user_id_hash, service_path, | 302 user_id_hash, service_path, |
| 251 base::Bind(&NetworkingPrivateChromeOS::GetPropertiesCallback, | 303 base::Bind(&NetworkingPrivateChromeOS::GetPropertiesCallback, |
| 252 weak_ptr_factory_.GetWeakPtr(), success_callback), | 304 weak_ptr_factory_.GetWeakPtr(), guid, false /* managed */, |
| 305 success_callback), | |
| 253 base::Bind(&NetworkHandlerFailureCallback, failure_callback)); | 306 base::Bind(&NetworkHandlerFailureCallback, failure_callback)); |
| 254 } | 307 } |
| 255 | 308 |
| 256 void NetworkingPrivateChromeOS::GetManagedProperties( | 309 void NetworkingPrivateChromeOS::GetManagedProperties( |
| 257 const std::string& guid, | 310 const std::string& guid, |
| 258 const DictionaryCallback& success_callback, | 311 const DictionaryCallback& success_callback, |
| 259 const FailureCallback& failure_callback) { | 312 const FailureCallback& failure_callback) { |
| 260 std::string service_path, error; | 313 std::string service_path, error; |
| 261 if (!GetServicePathFromGuid(guid, &service_path, &error)) { | 314 if (!GetServicePathFromGuid(guid, &service_path, &error)) { |
| 262 failure_callback.Run(error); | 315 failure_callback.Run(error); |
| 263 return; | 316 return; |
| 264 } | 317 } |
| 265 | 318 |
| 266 std::string user_id_hash; | 319 std::string user_id_hash; |
| 267 if (!GetPrimaryUserIdHash(browser_context_, &user_id_hash, &error)) { | 320 if (!GetPrimaryUserIdHash(browser_context_, &user_id_hash, &error)) { |
| 268 failure_callback.Run(error); | 321 failure_callback.Run(error); |
| 269 return; | 322 return; |
| 270 } | 323 } |
| 271 | 324 |
| 272 GetManagedConfigurationHandler()->GetManagedProperties( | 325 GetManagedConfigurationHandler()->GetManagedProperties( |
| 273 user_id_hash, service_path, | 326 user_id_hash, service_path, |
| 274 base::Bind(&NetworkingPrivateChromeOS::GetPropertiesCallback, | 327 base::Bind(&NetworkingPrivateChromeOS::GetPropertiesCallback, |
| 275 weak_ptr_factory_.GetWeakPtr(), success_callback), | 328 weak_ptr_factory_.GetWeakPtr(), guid, true /* managed */, |
| 329 success_callback), | |
| 276 base::Bind(&NetworkHandlerFailureCallback, failure_callback)); | 330 base::Bind(&NetworkHandlerFailureCallback, failure_callback)); |
| 277 } | 331 } |
| 278 | 332 |
| 279 void NetworkingPrivateChromeOS::GetState( | 333 void NetworkingPrivateChromeOS::GetState( |
| 280 const std::string& guid, | 334 const std::string& guid, |
| 281 const DictionaryCallback& success_callback, | 335 const DictionaryCallback& success_callback, |
| 282 const FailureCallback& failure_callback) { | 336 const FailureCallback& failure_callback) { |
| 283 std::string service_path, error; | 337 std::string service_path, error; |
| 284 if (!GetServicePathFromGuid(guid, &service_path, &error)) { | 338 if (!GetServicePathFromGuid(guid, &service_path, &error)) { |
| 285 failure_callback.Run(error); | 339 failure_callback.Run(error); |
| (...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 618 } | 672 } |
| 619 | 673 |
| 620 bool NetworkingPrivateChromeOS::RequestScan() { | 674 bool NetworkingPrivateChromeOS::RequestScan() { |
| 621 GetStateHandler()->RequestScan(); | 675 GetStateHandler()->RequestScan(); |
| 622 return true; | 676 return true; |
| 623 } | 677 } |
| 624 | 678 |
| 625 // Private methods | 679 // Private methods |
| 626 | 680 |
| 627 void NetworkingPrivateChromeOS::GetPropertiesCallback( | 681 void NetworkingPrivateChromeOS::GetPropertiesCallback( |
| 682 const std::string& guid, | |
| 683 bool managed, | |
| 628 const DictionaryCallback& callback, | 684 const DictionaryCallback& callback, |
| 629 const std::string& service_path, | 685 const std::string& service_path, |
| 630 const base::DictionaryValue& dictionary) { | 686 const base::DictionaryValue& dictionary) { |
| 631 std::unique_ptr<base::DictionaryValue> dictionary_copy(dictionary.DeepCopy()); | 687 std::unique_ptr<base::DictionaryValue> dictionary_copy(dictionary.DeepCopy()); |
| 632 AppendThirdPartyProviderName(dictionary_copy.get()); | 688 AppendThirdPartyProviderName(dictionary_copy.get()); |
| 689 if (managed) | |
| 690 SetActiveProxyValues(guid, dictionary_copy.get()); | |
| 633 callback.Run(std::move(dictionary_copy)); | 691 callback.Run(std::move(dictionary_copy)); |
| 634 } | 692 } |
| 635 | 693 |
| 636 // Populate ThirdPartyVPN.kProviderName for third-party VPNs. | |
| 637 void NetworkingPrivateChromeOS::AppendThirdPartyProviderName( | 694 void NetworkingPrivateChromeOS::AppendThirdPartyProviderName( |
| 638 base::DictionaryValue* dictionary) { | 695 base::DictionaryValue* dictionary) { |
| 639 base::DictionaryValue* third_party_vpn = | 696 base::DictionaryValue* third_party_vpn = |
| 640 GetThirdPartyVPNDictionary(dictionary); | 697 GetThirdPartyVPNDictionary(dictionary); |
| 641 if (!third_party_vpn) | 698 if (!third_party_vpn) |
| 642 return; | 699 return; |
| 643 | 700 |
| 644 const std::string extension_id = GetStringFromDictionary( | 701 const std::string extension_id = GetStringFromDictionary( |
| 645 *third_party_vpn, ::onc::third_party_vpn::kExtensionID); | 702 *third_party_vpn, ::onc::third_party_vpn::kExtensionID); |
| 646 const ExtensionSet& extensions = | 703 const ExtensionSet& extensions = |
| 647 ExtensionRegistry::Get(browser_context_)->enabled_extensions(); | 704 ExtensionRegistry::Get(browser_context_)->enabled_extensions(); |
| 648 for (const auto& extension : extensions) { | 705 for (const auto& extension : extensions) { |
| 649 if (extension->permissions_data()->HasAPIPermission( | 706 if (extension->permissions_data()->HasAPIPermission( |
| 650 APIPermission::kVpnProvider) && | 707 APIPermission::kVpnProvider) && |
| 651 extension->id() == extension_id) { | 708 extension->id() == extension_id) { |
| 652 third_party_vpn->SetStringWithoutPathExpansion( | 709 third_party_vpn->SetStringWithoutPathExpansion( |
| 653 ::onc::third_party_vpn::kProviderName, extension->name()); | 710 ::onc::third_party_vpn::kProviderName, extension->name()); |
| 654 break; | 711 break; |
| 655 } | 712 } |
| 656 } | 713 } |
| 657 } | 714 } |
| 658 | 715 |
| 716 void NetworkingPrivateChromeOS::SetActiveProxyValues( | |
| 717 const std::string& guid, | |
| 718 base::DictionaryValue* dictionary) { | |
| 719 chromeos::UIProxyConfigService* ui_proxy_config_service = | |
| 720 NetworkHandler::Get()->ui_proxy_config_service(); | |
| 721 ui_proxy_config_service->UpdateFromPrefs(guid); | |
| 722 UIProxyConfig config; | |
| 723 ui_proxy_config_service->GetProxyConfig(guid, &config); | |
| 724 | |
| 725 // We only override the active values if the proxy is set by an extension. | |
| 726 if (config.state != ProxyPrefs::CONFIG_EXTENSION) | |
| 727 return; | |
| 728 | |
| 729 // Ensure that the ProxySettings dictionary exists. | |
|
michaelpg
2016/11/04 00:58:28
The rest of the function assumes kProxySettings is
stevenjb
2016/11/09 22:20:18
This is only called for managed dictionaries (mana
| |
| 730 base::DictionaryValue* proxy_settings = | |
| 731 EnsureDictionaryValue(::onc::network_config::kProxySettings, dictionary); | |
| 732 | |
| 733 // Ensure that the ProxySettings.Type dictionary exists and set the active | |
| 734 // type value to the value from |ui_proxy_config_service|. | |
| 735 base::DictionaryValue* proxy_type_dict = | |
| 736 EnsureDictionaryValue(::onc::network_config::kType, proxy_settings); | |
| 737 SetEffectiveToActiveExtension(proxy_type_dict); | |
| 738 proxy_type_dict->SetStringWithoutPathExpansion( | |
| 739 ::onc::kAugmentationActiveSetting, GetProxySettingsType(config.mode)); | |
| 740 | |
| 741 // Update any appropriate sub dictionary based on the new type. | |
| 742 if (config.mode == UIProxyConfig::MODE_SINGLE_PROXY) { | |
| 743 base::DictionaryValue* manual = | |
| 744 EnsureDictionaryValue(::onc::proxy::kManual, proxy_settings); | |
| 745 SetManualProxy(manual, ::onc::proxy::kHttp, config.single_proxy); | |
| 746 manual->RemoveWithoutPathExpansion(::onc::proxy::kHttps, nullptr); | |
|
emaxx
2016/11/03 21:15:44
I'm lacking the context here, but maybe some expla
michaelpg
2016/11/04 00:58:28
+1; SetManualProxy doesn't seem like it's doing wh
stevenjb
2016/11/09 22:20:18
Short version: We only care about kHttp when we in
| |
| 747 manual->RemoveWithoutPathExpansion(::onc::proxy::kFtp, nullptr); | |
| 748 manual->RemoveWithoutPathExpansion(::onc::proxy::kSocks, nullptr); | |
| 749 } else if (config.mode == UIProxyConfig::MODE_PROXY_PER_SCHEME) { | |
| 750 base::DictionaryValue* manual = | |
| 751 EnsureDictionaryValue(::onc::proxy::kManual, proxy_settings); | |
| 752 SetManualProxy(manual, ::onc::proxy::kHttp, config.http_proxy); | |
| 753 SetManualProxy(manual, ::onc::proxy::kHttps, config.https_proxy); | |
| 754 SetManualProxy(manual, ::onc::proxy::kFtp, config.ftp_proxy); | |
| 755 SetManualProxy(manual, ::onc::proxy::kSocks, config.socks_proxy); | |
| 756 } else if (config.mode == UIProxyConfig::MODE_PAC_SCRIPT) { | |
| 757 base::DictionaryValue* pac = | |
| 758 EnsureDictionaryValue(::onc::proxy::kPAC, proxy_settings); | |
| 759 SetEffectiveToActiveExtension(pac); | |
| 760 pac->SetStringWithoutPathExpansion(::onc::kAugmentationActiveSetting, | |
| 761 config.automatic_proxy.pac_url.spec()); | |
| 762 } | |
| 763 } | |
| 764 | |
| 659 void NetworkingPrivateChromeOS::ConnectFailureCallback( | 765 void NetworkingPrivateChromeOS::ConnectFailureCallback( |
| 660 const std::string& guid, | 766 const std::string& guid, |
| 661 const VoidCallback& success_callback, | 767 const VoidCallback& success_callback, |
| 662 const FailureCallback& failure_callback, | 768 const FailureCallback& failure_callback, |
| 663 const std::string& error_name, | 769 const std::string& error_name, |
| 664 std::unique_ptr<base::DictionaryValue> error_data) { | 770 std::unique_ptr<base::DictionaryValue> error_data) { |
| 665 // TODO(stevenjb): Temporary workaround to show the configuration UI. | 771 // TODO(stevenjb): Temporary workaround to show the configuration UI. |
| 666 // Eventually the caller (e.g. Settings) should handle any failures and | 772 // Eventually the caller (e.g. Settings) should handle any failures and |
| 667 // show its own configuration UI. crbug.com/380937. | 773 // show its own configuration UI. crbug.com/380937. |
| 668 if (ui_delegate()->HandleConnectFailed(guid, error_name)) { | 774 if (ui_delegate()->HandleConnectFailed(guid, error_name)) { |
| 669 success_callback.Run(); | 775 success_callback.Run(); |
| 670 return; | 776 return; |
| 671 } | 777 } |
| 672 failure_callback.Run(error_name); | 778 failure_callback.Run(error_name); |
| 673 } | 779 } |
| 674 | 780 |
| 675 } // namespace extensions | 781 } // namespace extensions |
| OLD | NEW |