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 "chromeos/dbus/dbus_thread_manager.h" | 10 #include "chromeos/dbus/dbus_thread_manager.h" |
| 11 #include "chromeos/dbus/shill_manager_client.h" | 11 #include "chromeos/dbus/shill_manager_client.h" |
| 12 #include "chromeos/login/login_state.h" | 12 #include "chromeos/login/login_state.h" |
| 13 #include "chromeos/network/device_state.h" | 13 #include "chromeos/network/device_state.h" |
| 14 #include "chromeos/network/managed_network_configuration_handler.h" | 14 #include "chromeos/network/managed_network_configuration_handler.h" |
| 15 #include "chromeos/network/network_activation_handler.h" | 15 #include "chromeos/network/network_activation_handler.h" |
| 16 #include "chromeos/network/network_connection_handler.h" | 16 #include "chromeos/network/network_connection_handler.h" |
| 17 #include "chromeos/network/network_device_handler.h" | 17 #include "chromeos/network/network_device_handler.h" |
| 18 #include "chromeos/network/network_event_log.h" | 18 #include "chromeos/network/network_event_log.h" |
| 19 #include "chromeos/network/network_state.h" | 19 #include "chromeos/network/network_state.h" |
| 20 #include "chromeos/network/network_state_handler.h" | 20 #include "chromeos/network/network_state_handler.h" |
| 21 #include "chromeos/network/network_util.h" | 21 #include "chromeos/network/network_util.h" |
| 22 #include "chromeos/network/onc/onc_signature.h" | 22 #include "chromeos/network/onc/onc_signature.h" |
| 23 #include "chromeos/network/onc/onc_translator.h" | 23 #include "chromeos/network/onc/onc_translator.h" |
| 24 #include "chromeos/network/onc/onc_utils.h" | 24 #include "chromeos/network/onc/onc_utils.h" |
| 25 #include "chromeos/network/portal_detector/network_portal_detector.h" | 25 #include "chromeos/network/portal_detector/network_portal_detector.h" |
| 26 #include "components/onc/onc_constants.h" | 26 #include "components/onc/onc_constants.h" |
| 27 #include "content/public/browser/browser_context.h" | 27 #include "content/public/browser/browser_context.h" |
| 28 #include "extensions/browser/api/networking_private/networking_private_api.h" | 28 #include "extensions/browser/api/networking_private/networking_private_api.h" |
| 29 #include "extensions/browser/extension_registry.h" | |
| 29 #include "extensions/browser/extensions_browser_client.h" | 30 #include "extensions/browser/extensions_browser_client.h" |
| 31 #include "extensions/common/extension.h" | |
| 32 #include "extensions/common/extension_set.h" | |
| 33 #include "extensions/common/permissions/api_permission.h" | |
| 34 #include "extensions/common/permissions/permissions_data.h" | |
| 30 #include "third_party/cros_system_api/dbus/service_constants.h" | 35 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 31 | 36 |
| 32 using chromeos::DeviceState; | 37 using chromeos::DeviceState; |
| 33 using chromeos::NetworkHandler; | 38 using chromeos::NetworkHandler; |
| 34 using chromeos::NetworkStateHandler; | 39 using chromeos::NetworkStateHandler; |
| 35 using chromeos::NetworkTypePattern; | 40 using chromeos::NetworkTypePattern; |
| 36 using chromeos::ShillManagerClient; | 41 using chromeos::ShillManagerClient; |
| 37 using extensions::NetworkingPrivateDelegate; | 42 using extensions::NetworkingPrivateDelegate; |
| 38 | 43 |
| 39 namespace private_api = extensions::api::networking_private; | 44 namespace private_api = extensions::api::networking_private; |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 116 DCHECK_NE(private_api::DEVICE_STATE_TYPE_NONE, state); | 121 DCHECK_NE(private_api::DEVICE_STATE_TYPE_NONE, state); |
| 117 scoped_ptr<private_api::DeviceStateProperties> properties( | 122 scoped_ptr<private_api::DeviceStateProperties> properties( |
| 118 new private_api::DeviceStateProperties); | 123 new private_api::DeviceStateProperties); |
| 119 properties->type = private_api::ParseNetworkType(type); | 124 properties->type = private_api::ParseNetworkType(type); |
| 120 properties->state = state; | 125 properties->state = state; |
| 121 if (device && state == private_api::DEVICE_STATE_TYPE_ENABLED) | 126 if (device && state == private_api::DEVICE_STATE_TYPE_ENABLED) |
| 122 properties->scanning.reset(new bool(device->scanning())); | 127 properties->scanning.reset(new bool(device->scanning())); |
| 123 device_state_list->push_back(properties.Pass()); | 128 device_state_list->push_back(properties.Pass()); |
| 124 } | 129 } |
| 125 | 130 |
| 126 void NetworkHandlerDictionaryCallback( | |
| 127 const NetworkingPrivateDelegate::DictionaryCallback& callback, | |
| 128 const std::string& service_path, | |
| 129 const base::DictionaryValue& dictionary) { | |
| 130 scoped_ptr<base::DictionaryValue> dictionary_copy(dictionary.DeepCopy()); | |
| 131 callback.Run(dictionary_copy.Pass()); | |
| 132 } | |
| 133 | |
| 134 void NetworkHandlerFailureCallback( | 131 void NetworkHandlerFailureCallback( |
| 135 const NetworkingPrivateDelegate::FailureCallback& callback, | 132 const NetworkingPrivateDelegate::FailureCallback& callback, |
| 136 const std::string& error_name, | 133 const std::string& error_name, |
| 137 scoped_ptr<base::DictionaryValue> error_data) { | 134 scoped_ptr<base::DictionaryValue> error_data) { |
| 138 callback.Run(error_name); | 135 callback.Run(error_name); |
| 139 } | 136 } |
| 140 | 137 |
| 141 void RequirePinSuccess( | 138 void RequirePinSuccess( |
| 142 const std::string& device_path, | 139 const std::string& device_path, |
| 143 const std::string& current_pin, | 140 const std::string& current_pin, |
| 144 const std::string& new_pin, | 141 const std::string& new_pin, |
| 145 const extensions::NetworkingPrivateChromeOS::VoidCallback& success_callback, | 142 const extensions::NetworkingPrivateChromeOS::VoidCallback& success_callback, |
| 146 const extensions::NetworkingPrivateChromeOS::FailureCallback& | 143 const extensions::NetworkingPrivateChromeOS::FailureCallback& |
| 147 failure_callback) { | 144 failure_callback) { |
| 148 // After RequirePin succeeds, call ChangePIN iff a different new_pin is | 145 // After RequirePin succeeds, call ChangePIN iff a different new_pin is |
| 149 // provided. | 146 // provided. |
| 150 if (new_pin.empty() || new_pin == current_pin) { | 147 if (new_pin.empty() || new_pin == current_pin) { |
| 151 success_callback.Run(); | 148 success_callback.Run(); |
| 152 return; | 149 return; |
| 153 } | 150 } |
| 154 NetworkHandler::Get()->network_device_handler()->ChangePin( | 151 NetworkHandler::Get()->network_device_handler()->ChangePin( |
| 155 device_path, current_pin, new_pin, success_callback, | 152 device_path, current_pin, new_pin, success_callback, |
| 156 base::Bind(&NetworkHandlerFailureCallback, failure_callback)); | 153 base::Bind(&NetworkHandlerFailureCallback, failure_callback)); |
| 157 } | 154 } |
| 158 | 155 |
| 156 // Returns the string corresponding to |key|. If the property is a managed | |
| 157 // dictionary, returns the active value. If the property does not exist or | |
| 158 // has no active value, returns an empty string. | |
| 159 std::string GetStringFromDictionary(const base::DictionaryValue& dictionary, | |
| 160 const std::string& key) { | |
| 161 std::string result; | |
| 162 if (!dictionary.GetString(key, &result)) { | |
| 163 const base::DictionaryValue* managed = nullptr; | |
| 164 if (dictionary.GetDictionary(key, &managed)) | |
| 165 managed->GetString(::onc::kAugmentationActiveSetting, &result); | |
| 166 } | |
| 167 return result; | |
| 168 } | |
| 169 | |
| 159 } // namespace | 170 } // namespace |
| 160 | 171 |
| 161 //////////////////////////////////////////////////////////////////////////////// | 172 //////////////////////////////////////////////////////////////////////////////// |
| 162 | 173 |
| 163 namespace extensions { | 174 namespace extensions { |
| 164 | 175 |
| 165 NetworkingPrivateChromeOS::NetworkingPrivateChromeOS( | 176 NetworkingPrivateChromeOS::NetworkingPrivateChromeOS( |
| 166 content::BrowserContext* browser_context, | 177 content::BrowserContext* browser_context, |
| 167 scoped_ptr<VerifyDelegate> verify_delegate) | 178 scoped_ptr<VerifyDelegate> verify_delegate) |
| 168 : NetworkingPrivateDelegate(verify_delegate.Pass()), | 179 : NetworkingPrivateDelegate(verify_delegate.Pass()), |
| 169 browser_context_(browser_context), | 180 browser_context_(browser_context), |
| 170 weak_ptr_factory_(this) {} | 181 weak_ptr_factory_(this) {} |
| 171 | 182 |
| 172 NetworkingPrivateChromeOS::~NetworkingPrivateChromeOS() { | 183 NetworkingPrivateChromeOS::~NetworkingPrivateChromeOS() { |
| 173 } | 184 } |
| 174 | 185 |
| 175 void NetworkingPrivateChromeOS::GetProperties( | 186 void NetworkingPrivateChromeOS::GetProperties( |
| 176 const std::string& guid, | 187 const std::string& guid, |
| 177 const DictionaryCallback& success_callback, | 188 const DictionaryCallback& success_callback, |
| 178 const FailureCallback& failure_callback) { | 189 const FailureCallback& failure_callback) { |
| 179 std::string service_path, error; | 190 std::string service_path, error; |
| 180 if (!GetServicePathFromGuid(guid, &service_path, &error)) { | 191 if (!GetServicePathFromGuid(guid, &service_path, &error)) { |
| 181 failure_callback.Run(error); | 192 failure_callback.Run(error); |
| 182 return; | 193 return; |
| 183 } | 194 } |
| 184 | 195 |
| 185 GetManagedConfigurationHandler()->GetProperties( | 196 GetManagedConfigurationHandler()->GetProperties( |
| 186 service_path, | 197 service_path, |
| 187 base::Bind(&NetworkHandlerDictionaryCallback, success_callback), | 198 base::Bind(&NetworkingPrivateChromeOS::GetPropertiesCallback, |
| 199 weak_ptr_factory_.GetWeakPtr(), success_callback), | |
| 188 base::Bind(&NetworkHandlerFailureCallback, failure_callback)); | 200 base::Bind(&NetworkHandlerFailureCallback, failure_callback)); |
| 189 } | 201 } |
| 190 | 202 |
| 191 void NetworkingPrivateChromeOS::GetManagedProperties( | 203 void NetworkingPrivateChromeOS::GetManagedProperties( |
| 192 const std::string& guid, | 204 const std::string& guid, |
| 193 const DictionaryCallback& success_callback, | 205 const DictionaryCallback& success_callback, |
| 194 const FailureCallback& failure_callback) { | 206 const FailureCallback& failure_callback) { |
| 195 std::string service_path, error; | 207 std::string service_path, error; |
| 196 if (!GetServicePathFromGuid(guid, &service_path, &error)) { | 208 if (!GetServicePathFromGuid(guid, &service_path, &error)) { |
| 197 failure_callback.Run(error); | 209 failure_callback.Run(error); |
| 198 return; | 210 return; |
| 199 } | 211 } |
| 200 | 212 |
| 201 std::string user_id_hash; | 213 std::string user_id_hash; |
| 202 if (!GetUserIdHash(browser_context_, &user_id_hash, &error)) { | 214 if (!GetUserIdHash(browser_context_, &user_id_hash, &error)) { |
| 203 failure_callback.Run(error); | 215 failure_callback.Run(error); |
| 204 return; | 216 return; |
| 205 } | 217 } |
| 206 | 218 |
| 207 GetManagedConfigurationHandler()->GetManagedProperties( | 219 GetManagedConfigurationHandler()->GetManagedProperties( |
| 208 user_id_hash, service_path, | 220 user_id_hash, service_path, |
| 209 base::Bind(&NetworkHandlerDictionaryCallback, success_callback), | 221 base::Bind(&NetworkingPrivateChromeOS::GetPropertiesCallback, |
| 222 weak_ptr_factory_.GetWeakPtr(), success_callback), | |
| 210 base::Bind(&NetworkHandlerFailureCallback, failure_callback)); | 223 base::Bind(&NetworkHandlerFailureCallback, failure_callback)); |
| 211 } | 224 } |
| 212 | 225 |
| 226 void NetworkingPrivateChromeOS::GetPropertiesCallback( | |
| 227 const NetworkingPrivateDelegate::DictionaryCallback& callback, | |
| 228 const std::string& service_path, | |
| 229 const base::DictionaryValue& dictionary) { | |
| 230 scoped_ptr<base::DictionaryValue> dictionary_copy(dictionary.DeepCopy()); | |
| 231 | |
| 232 std::string type = | |
| 233 GetStringFromDictionary(dictionary, ::onc::network_config::kType); | |
| 234 | |
| 235 if (type == ::onc::network_config::kVPN) | |
| 236 AppendThirdPartyProviderName(dictionary_copy.get()); | |
| 237 | |
| 238 callback.Run(dictionary_copy.Pass()); | |
| 239 } | |
| 240 | |
| 241 // Populate ThirdPartyVPN.kName with the provider name for third-party VPNs. | |
| 242 void NetworkingPrivateChromeOS::AppendThirdPartyProviderName( | |
| 243 base::DictionaryValue* dictionary) { | |
| 244 base::DictionaryValue* vpn_dict = nullptr; | |
| 245 if (!dictionary->GetDictionary(::onc::network_config::kVPN, &vpn_dict)) | |
| 246 return; | |
| 247 if (GetStringFromDictionary(*vpn_dict, ::onc::vpn::kType) != | |
| 248 ::onc::vpn::kThirdPartyVpn) | |
| 249 return; | |
| 250 base::DictionaryValue* third_party_vpn = nullptr; | |
| 251 if (!vpn_dict->GetDictionary(::onc::vpn::kThirdPartyVpn, &third_party_vpn)) | |
| 252 return; | |
| 253 | |
| 254 std::string extension_id = GetStringFromDictionary( | |
| 255 *third_party_vpn, ::onc::third_party_vpn::kExtensionID); | |
| 256 const ExtensionSet& extensions = | |
| 257 ExtensionRegistry::Get(browser_context_)->enabled_extensions(); | |
| 258 for (const auto& extension : extensions) { | |
| 259 if (extension->permissions_data()->HasAPIPermission( | |
| 260 APIPermission::kVpnProvider) && | |
| 261 extension->id() == extension_id) { | |
| 262 third_party_vpn->SetStringWithoutPathExpansion( | |
| 263 ::onc::third_party_vpn::kName, extension->name()); | |
| 264 break; | |
| 265 } | |
| 266 } | |
| 267 } | |
| 268 | |
| 213 void NetworkingPrivateChromeOS::GetState( | 269 void NetworkingPrivateChromeOS::GetState( |
| 214 const std::string& guid, | 270 const std::string& guid, |
| 215 const DictionaryCallback& success_callback, | 271 const DictionaryCallback& success_callback, |
| 216 const FailureCallback& failure_callback) { | 272 const FailureCallback& failure_callback) { |
| 217 std::string service_path, error; | 273 std::string service_path, error; |
| 218 if (!GetServicePathFromGuid(guid, &service_path, &error)) { | 274 if (!GetServicePathFromGuid(guid, &service_path, &error)) { |
| 219 failure_callback.Run(error); | 275 failure_callback.Run(error); |
| 220 return; | 276 return; |
| 221 } | 277 } |
| 222 | 278 |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 286 const std::string& network_type, | 342 const std::string& network_type, |
| 287 bool configured_only, | 343 bool configured_only, |
| 288 bool visible_only, | 344 bool visible_only, |
| 289 int limit, | 345 int limit, |
| 290 const NetworkListCallback& success_callback, | 346 const NetworkListCallback& success_callback, |
| 291 const FailureCallback& failure_callback) { | 347 const FailureCallback& failure_callback) { |
| 292 NetworkTypePattern pattern = | 348 NetworkTypePattern pattern = |
| 293 chromeos::onc::NetworkTypePatternFromOncType(network_type); | 349 chromeos::onc::NetworkTypePatternFromOncType(network_type); |
| 294 scoped_ptr<base::ListValue> network_properties_list = | 350 scoped_ptr<base::ListValue> network_properties_list = |
| 295 chromeos::network_util::TranslateNetworkListToONC( | 351 chromeos::network_util::TranslateNetworkListToONC( |
| 296 pattern, configured_only, visible_only, limit, false /* debugging */); | 352 pattern, configured_only, visible_only, limit); |
| 297 success_callback.Run(network_properties_list.Pass()); | 353 success_callback.Run(network_properties_list.Pass()); |
| 298 } | 354 } |
| 299 | 355 |
| 300 void NetworkingPrivateChromeOS::StartConnect( | 356 void NetworkingPrivateChromeOS::StartConnect( |
| 301 const std::string& guid, | 357 const std::string& guid, |
| 302 const VoidCallback& success_callback, | 358 const VoidCallback& success_callback, |
| 303 const FailureCallback& failure_callback) { | 359 const FailureCallback& failure_callback) { |
| 304 std::string service_path, error; | 360 std::string service_path, error; |
| 305 if (!GetServicePathFromGuid(guid, &service_path, &error)) { | 361 if (!GetServicePathFromGuid(guid, &service_path, &error)) { |
| 306 failure_callback.Run(error); | 362 failure_callback.Run(error); |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 559 pattern, false, chromeos::network_handler::ErrorCallback()); | 615 pattern, false, chromeos::network_handler::ErrorCallback()); |
| 560 | 616 |
| 561 return true; | 617 return true; |
| 562 } | 618 } |
| 563 | 619 |
| 564 bool NetworkingPrivateChromeOS::RequestScan() { | 620 bool NetworkingPrivateChromeOS::RequestScan() { |
| 565 GetStateHandler()->RequestScan(); | 621 GetStateHandler()->RequestScan(); |
| 566 return true; | 622 return true; |
| 567 } | 623 } |
| 568 | 624 |
| 625 scoped_ptr<base::ListValue> | |
| 626 NetworkingPrivateChromeOS::GetThirdPartyVpnProviderList() { | |
| 627 scoped_ptr<ThirdPartyVPNPropertyList> vpn_provider_list( | |
| 628 new ThirdPartyVPNPropertyList); | |
| 629 const ExtensionSet& extensions = | |
| 630 ExtensionRegistry::Get(browser_context_)->enabled_extensions(); | |
| 631 for (const auto& extension : extensions) { | |
| 632 if (!extension->permissions_data()->HasAPIPermission( | |
| 633 APIPermission::kVpnProvider)) { | |
| 634 continue; | |
| 635 } | |
| 636 linked_ptr<private_api::ThirdPartyVPNProperties> provider( | |
| 637 new private_api::ThirdPartyVPNProperties); | |
| 638 provider->extension_id = extension->id(); | |
| 639 provider->name.reset(new std::string(extension->name())); | |
|
pneubeck (no reviews)
2015/08/13 12:58:37
why not using
https://developer.chrome.com/extens
| |
| 640 vpn_provider_list->push_back(provider); | |
| 641 } | |
| 642 | |
| 643 scoped_ptr<base::ListValue> vpn_provider_list_value(new base::ListValue); | |
| 644 for (const auto& provider : *vpn_provider_list) | |
| 645 vpn_provider_list_value->Append(provider->ToValue().release()); | |
| 646 | |
| 647 return vpn_provider_list_value.Pass(); | |
| 648 } | |
| 649 | |
| 569 } // namespace extensions | 650 } // namespace extensions |
| OLD | NEW |