| 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/vpn_provider/vpn_service.h" | 5 #include "extensions/browser/api/vpn_provider/vpn_service.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 | 33 |
| 34 namespace { | 34 namespace { |
| 35 | 35 |
| 36 namespace api_vpn = extensions::core_api::vpn_provider; | 36 namespace api_vpn = extensions::core_api::vpn_provider; |
| 37 | 37 |
| 38 std::string GetKey(const std::string& extension_id, const std::string& name) { | 38 std::string GetKey(const std::string& extension_id, const std::string& name) { |
| 39 const std::string key = crypto::SHA256HashString(extension_id + name); | 39 const std::string key = crypto::SHA256HashString(extension_id + name); |
| 40 return base::HexEncode(key.data(), key.size()); | 40 return base::HexEncode(key.data(), key.size()); |
| 41 } | 41 } |
| 42 | 42 |
| 43 std::string GetCombinedName(const std::string& extension_name, | |
| 44 const std::string& configuration_name) { | |
| 45 // TODO(kaliamoorthi): (crbug.com/434711) Sort out the dependencies and | |
| 46 // replace the string concatenation with internationalized version. | |
| 47 return extension_name + ": " + configuration_name; | |
| 48 } | |
| 49 | |
| 50 void DoNothingFailureCallback(const std::string& error_name, | 43 void DoNothingFailureCallback(const std::string& error_name, |
| 51 const std::string& error_message) { | 44 const std::string& error_message) { |
| 52 LOG(ERROR) << error_name << ": " << error_message; | 45 LOG(ERROR) << error_name << ": " << error_message; |
| 53 } | 46 } |
| 54 | 47 |
| 55 } // namespace | 48 } // namespace |
| 56 | 49 |
| 57 class VpnService::VpnConfiguration : public ShillThirdPartyVpnObserver { | 50 class VpnService::VpnConfiguration : public ShillThirdPartyVpnObserver { |
| 58 public: | 51 public: |
| 59 VpnConfiguration(const std::string& extension_id, | 52 VpnConfiguration(const std::string& extension_id, |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 Source source) { | 203 Source source) { |
| 211 } | 204 } |
| 212 | 205 |
| 213 void VpnService::OnGetPropertiesSuccess( | 206 void VpnService::OnGetPropertiesSuccess( |
| 214 const std::string& service_path, | 207 const std::string& service_path, |
| 215 const base::DictionaryValue& dictionary) { | 208 const base::DictionaryValue& dictionary) { |
| 216 if (service_path_to_configuration_map_.find(service_path) != | 209 if (service_path_to_configuration_map_.find(service_path) != |
| 217 service_path_to_configuration_map_.end()) { | 210 service_path_to_configuration_map_.end()) { |
| 218 return; | 211 return; |
| 219 } | 212 } |
| 220 const base::DictionaryValue* provider = nullptr; | |
| 221 std::string vpn_type; | 213 std::string vpn_type; |
| 222 std::string extension_id; | 214 std::string extension_id; |
| 223 std::string type; | 215 std::string type; |
| 224 std::string name; | |
| 225 std::string configuration_name; | 216 std::string configuration_name; |
| 226 if (!dictionary.GetDictionary(shill::kProviderProperty, &provider) || | 217 if (!dictionary.GetString(shill::kProviderTypeProperty, &vpn_type) || |
| 227 !dictionary.GetString(shill::kProviderTypeProperty, &vpn_type) || | |
| 228 !dictionary.GetString(shill::kProviderHostProperty, &extension_id) || | 218 !dictionary.GetString(shill::kProviderHostProperty, &extension_id) || |
| 229 !dictionary.GetString(shill::kTypeProperty, &type) || | 219 !dictionary.GetString(shill::kTypeProperty, &type) || |
| 230 !dictionary.GetString(shill::kNameProperty, &name) || | 220 !dictionary.GetString(shill::kNameProperty, &configuration_name) || |
| 231 !provider->GetString(shill::kConfigurationNameProperty, | |
| 232 &configuration_name) || | |
| 233 vpn_type != shill::kProviderThirdPartyVpn || type != shill::kTypeVPN) { | 221 vpn_type != shill::kProviderThirdPartyVpn || type != shill::kTypeVPN) { |
| 234 return; | 222 return; |
| 235 } | 223 } |
| 236 | 224 |
| 237 if (!extension_registry_->GetExtensionById( | 225 if (!extension_registry_->GetExtensionById( |
| 238 extension_id, extensions::ExtensionRegistry::ENABLED)) { | 226 extension_id, extensions::ExtensionRegistry::ENABLED)) { |
| 239 // Does not belong to this instance of VpnService. | 227 // Does not belong to this instance of VpnService. |
| 240 return; | 228 return; |
| 241 } | 229 } |
| 242 | 230 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 296 std::string("No user profile for unshared network configuration.")); | 284 std::string("No user profile for unshared network configuration.")); |
| 297 return; | 285 return; |
| 298 } | 286 } |
| 299 | 287 |
| 300 VpnConfiguration* configuration = | 288 VpnConfiguration* configuration = |
| 301 CreateConfigurationInternal(extension_id, configuration_name, key); | 289 CreateConfigurationInternal(extension_id, configuration_name, key); |
| 302 | 290 |
| 303 base::DictionaryValue properties; | 291 base::DictionaryValue properties; |
| 304 properties.SetStringWithoutPathExpansion(shill::kTypeProperty, | 292 properties.SetStringWithoutPathExpansion(shill::kTypeProperty, |
| 305 shill::kTypeVPN); | 293 shill::kTypeVPN); |
| 306 properties.SetStringWithoutPathExpansion( | 294 properties.SetStringWithoutPathExpansion(shill::kNameProperty, |
| 307 shill::kNameProperty, // This value is shown to the user in native UI. | 295 configuration_name); |
| 308 GetCombinedName(extension_name, configuration_name)); | |
| 309 properties.SetStringWithoutPathExpansion(shill::kProviderHostProperty, | 296 properties.SetStringWithoutPathExpansion(shill::kProviderHostProperty, |
| 310 extension_id); | 297 extension_id); |
| 311 properties.SetStringWithoutPathExpansion(shill::kObjectPathSuffixProperty, | 298 properties.SetStringWithoutPathExpansion(shill::kObjectPathSuffixProperty, |
| 312 configuration->key()); | 299 configuration->key()); |
| 313 properties.SetStringWithoutPathExpansion(shill::kProviderTypeProperty, | 300 properties.SetStringWithoutPathExpansion(shill::kProviderTypeProperty, |
| 314 shill::kProviderThirdPartyVpn); | 301 shill::kProviderThirdPartyVpn); |
| 315 properties.SetStringWithoutPathExpansion(shill::kProfileProperty, | 302 properties.SetStringWithoutPathExpansion(shill::kProfileProperty, |
| 316 profile->path); | 303 profile->path); |
| 317 properties.SetStringWithoutPathExpansion(shill::kConfigurationNameProperty, | |
| 318 configuration_name); | |
| 319 | 304 |
| 320 // Note: This will not create an entry in |policy_util|. TODO(pneubeck): | 305 // Note: This will not create an entry in |policy_util|. TODO(pneubeck): |
| 321 // Determine the correct thing to do here, crbug.com/459278. | 306 // Determine the correct thing to do here, crbug.com/459278. |
| 322 std::string guid = base::GenerateGUID(); | 307 std::string guid = base::GenerateGUID(); |
| 323 properties.SetStringWithoutPathExpansion(shill::kGuidProperty, guid); | 308 properties.SetStringWithoutPathExpansion(shill::kGuidProperty, guid); |
| 324 | 309 |
| 325 network_configuration_handler_->CreateShillConfiguration( | 310 network_configuration_handler_->CreateShillConfiguration( |
| 326 properties, NetworkConfigurationObserver::SOURCE_EXTENSION_INSTALL, | 311 properties, NetworkConfigurationObserver::SOURCE_EXTENSION_INSTALL, |
| 327 base::Bind(&VpnService::OnCreateConfigurationSuccess, | 312 base::Bind(&VpnService::OnCreateConfigurationSuccess, |
| 328 weak_factory_.GetWeakPtr(), success, configuration), | 313 weak_factory_.GetWeakPtr(), success, configuration), |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 491 delete configuration; | 476 delete configuration; |
| 492 } | 477 } |
| 493 | 478 |
| 494 bool VpnService::DoesActiveConfigurationExistAndIsAccessAuthorized( | 479 bool VpnService::DoesActiveConfigurationExistAndIsAccessAuthorized( |
| 495 const std::string& extension_id) { | 480 const std::string& extension_id) { |
| 496 return active_configuration_ && | 481 return active_configuration_ && |
| 497 active_configuration_->extension_id() == extension_id; | 482 active_configuration_->extension_id() == extension_id; |
| 498 } | 483 } |
| 499 | 484 |
| 500 } // namespace chromeos | 485 } // namespace chromeos |
| OLD | NEW |