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" |
11 #include "base/bind_helpers.h" | 11 #include "base/bind_helpers.h" |
12 #include "base/guid.h" | 12 #include "base/guid.h" |
13 #include "base/location.h" | 13 #include "base/location.h" |
14 #include "base/logging.h" | 14 #include "base/logging.h" |
15 #include "base/message_loop/message_loop.h" | 15 #include "base/message_loop/message_loop.h" |
16 #include "base/stl_util.h" | 16 #include "base/stl_util.h" |
17 #include "base/strings/string_number_conversions.h" | 17 #include "base/strings/string_number_conversions.h" |
18 #include "base/strings/string_util.h" | 18 #include "base/strings/string_util.h" |
19 #include "base/values.h" | 19 #include "base/values.h" |
| 20 #include "chrome/browser/chromeos/vpn_provider/pepper_vpn_provider_service_helpe
r.h" |
20 #include "chromeos/dbus/shill_third_party_vpn_driver_client.h" | 21 #include "chromeos/dbus/shill_third_party_vpn_driver_client.h" |
21 #include "chromeos/dbus/shill_third_party_vpn_observer.h" | 22 #include "chromeos/dbus/shill_third_party_vpn_observer.h" |
22 #include "chromeos/network/network_configuration_handler.h" | 23 #include "chromeos/network/network_configuration_handler.h" |
23 #include "chromeos/network/network_profile.h" | 24 #include "chromeos/network/network_profile.h" |
24 #include "chromeos/network/network_profile_handler.h" | 25 #include "chromeos/network/network_profile_handler.h" |
25 #include "chromeos/network/network_state.h" | 26 #include "chromeos/network/network_state.h" |
26 #include "chromeos/network/network_state_handler.h" | 27 #include "chromeos/network/network_state_handler.h" |
27 #include "chromeos/network/network_type_pattern.h" | 28 #include "chromeos/network/network_type_pattern.h" |
28 #include "crypto/sha2.h" | 29 #include "crypto/sha2.h" |
29 #include "extensions/browser/event_router.h" | 30 #include "extensions/browser/event_router.h" |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 } | 91 } |
91 | 92 |
92 VpnService::VpnConfiguration::~VpnConfiguration() { | 93 VpnService::VpnConfiguration::~VpnConfiguration() { |
93 } | 94 } |
94 | 95 |
95 void VpnService::VpnConfiguration::OnPacketReceived( | 96 void VpnService::VpnConfiguration::OnPacketReceived( |
96 const std::vector<char>& data) { | 97 const std::vector<char>& data) { |
97 if (!vpn_service_) { | 98 if (!vpn_service_) { |
98 return; | 99 return; |
99 } | 100 } |
100 scoped_ptr<base::ListValue> event_args = | 101 // If the configrataion was added via de PPAPI plugin |
101 api_vpn::OnPacketReceived::Create(data); | 102 if (vpn_service_->RegisteredViaPlugin(extension_id_)) { |
102 vpn_service_->SendSignalToExtension( | 103 vpn_provider::VpnProviderServiceHelper::GetInstance()->OnPacketReceived_UI( |
103 extension_id_, extensions::events::VPN_PROVIDER_ON_PACKET_RECEIVED, | 104 extension_id_, data); |
104 api_vpn::OnPacketReceived::kEventName, event_args.Pass()); | 105 } else { |
| 106 scoped_ptr<base::ListValue> event_args = |
| 107 api_vpn::OnPacketReceived::Create(data); |
| 108 vpn_service_->SendSignalToExtension( |
| 109 extension_id_, extensions::events::VPN_PROVIDER_ON_PACKET_RECEIVED, |
| 110 api_vpn::OnPacketReceived::kEventName, event_args.Pass()); |
| 111 } |
105 } | 112 } |
106 | 113 |
107 void VpnService::VpnConfiguration::OnPlatformMessage(uint32_t message) { | 114 void VpnService::VpnConfiguration::OnPlatformMessage(uint32_t message) { |
108 if (!vpn_service_) { | 115 if (!vpn_service_) { |
109 return; | 116 return; |
110 } | 117 } |
111 DCHECK_GE(api_vpn::PLATFORM_MESSAGE_LAST, message); | 118 DCHECK_GE(api_vpn::PLATFORM_MESSAGE_LAST, message); |
112 | 119 |
113 api_vpn::PlatformMessage platform_message = | 120 api_vpn::PlatformMessage platform_message = |
114 static_cast<api_vpn::PlatformMessage>(message); | 121 static_cast<api_vpn::PlatformMessage>(message); |
115 vpn_service_->SetActiveConfiguration( | 122 vpn_service_->SetActiveConfiguration( |
116 platform_message == api_vpn::PLATFORM_MESSAGE_CONNECTED ? this : nullptr); | 123 platform_message == api_vpn::PLATFORM_MESSAGE_CONNECTED ? this : nullptr); |
117 | 124 |
118 // TODO(kaliamoorthi): Update the lower layers to get the error message and | 125 // If the configrataion was added via de PPAPI plugin |
119 // pass in the error instead of std::string(). | 126 if (vpn_service_->RegisteredViaPlugin(extension_id_)) { |
120 scoped_ptr<base::ListValue> event_args = api_vpn::OnPlatformMessage::Create( | 127 vpn_provider::VpnProviderServiceHelper::GetInstance()->OnPlatformMessage_UI( |
121 configuration_name_, platform_message, std::string()); | 128 extension_id_, configuration_name_, |
| 129 (PP_VpnProvider_PlatformMessage)message, // TODO: Fix mappings |
| 130 std::string()); |
| 131 } else { |
| 132 // TODO(kaliamoorthi): Update the lower layers to get the error message and |
| 133 // pass in the error instead of std::string(). |
| 134 scoped_ptr<base::ListValue> event_args = api_vpn::OnPlatformMessage::Create( |
| 135 configuration_name_, platform_message, std::string()); |
122 | 136 |
123 vpn_service_->SendSignalToExtension( | 137 vpn_service_->SendSignalToExtension( |
124 extension_id_, extensions::events::VPN_PROVIDER_ON_PLATFORM_MESSAGE, | 138 extension_id_, extensions::events::VPN_PROVIDER_ON_PLATFORM_MESSAGE, |
125 api_vpn::OnPlatformMessage::kEventName, event_args.Pass()); | 139 api_vpn::OnPlatformMessage::kEventName, event_args.Pass()); |
| 140 } |
126 } | 141 } |
127 | 142 |
128 VpnService::VpnService( | 143 VpnService::VpnService( |
129 content::BrowserContext* browser_context, | 144 content::BrowserContext* browser_context, |
130 const std::string& userid_hash, | 145 const std::string& userid_hash, |
131 extensions::ExtensionRegistry* extension_registry, | 146 extensions::ExtensionRegistry* extension_registry, |
132 extensions::EventRouter* event_router, | 147 extensions::EventRouter* event_router, |
133 ShillThirdPartyVpnDriverClient* shill_client, | 148 ShillThirdPartyVpnDriverClient* shill_client, |
134 NetworkConfigurationHandler* network_configuration_handler, | 149 NetworkConfigurationHandler* network_configuration_handler, |
135 NetworkProfileHandler* network_profile_handler, | 150 NetworkProfileHandler* network_profile_handler, |
(...skipping 18 matching lines...) Expand all Loading... |
154 | 169 |
155 VpnService::~VpnService() { | 170 VpnService::~VpnService() { |
156 network_configuration_handler_->RemoveObserver(this); | 171 network_configuration_handler_->RemoveObserver(this); |
157 network_state_handler_->RemoveObserver(this, FROM_HERE); | 172 network_state_handler_->RemoveObserver(this, FROM_HERE); |
158 extension_registry_->RemoveObserver(this); | 173 extension_registry_->RemoveObserver(this); |
159 STLDeleteContainerPairSecondPointers(key_to_configuration_map_.begin(), | 174 STLDeleteContainerPairSecondPointers(key_to_configuration_map_.begin(), |
160 key_to_configuration_map_.end()); | 175 key_to_configuration_map_.end()); |
161 } | 176 } |
162 | 177 |
163 void VpnService::SendShowAddDialogToExtension(const std::string& extension_id) { | 178 void VpnService::SendShowAddDialogToExtension(const std::string& extension_id) { |
164 SendSignalToExtension(extension_id, | 179 // If the configrataion was added via de PPAPI plugin |
165 extensions::events::VPN_PROVIDER_ON_UI_EVENT, | 180 if (RegisteredViaPlugin(extension_id)) { |
166 api_vpn::OnUIEvent::kEventName, | 181 vpn_provider::VpnProviderServiceHelper::GetInstance()->OnUIEvent_UI( |
167 api_vpn::OnUIEvent::Create( | 182 extension_id, PP_VPN_PROVIDER_UI_EVENT_SHOWADDDIALOG, std::string()); |
168 api_vpn::UI_EVENT_SHOWADDDIALOG, std::string())); | 183 } else { // via extension |
| 184 SendSignalToExtension(extension_id, |
| 185 extensions::events::VPN_PROVIDER_ON_UI_EVENT, |
| 186 api_vpn::OnUIEvent::kEventName, |
| 187 api_vpn::OnUIEvent::Create( |
| 188 api_vpn::UI_EVENT_SHOWADDDIALOG, std::string())); |
| 189 } |
169 } | 190 } |
170 | 191 |
171 void VpnService::SendShowConfigureDialogToExtension( | 192 void VpnService::SendShowConfigureDialogToExtension( |
172 const std::string& extension_id, | 193 const std::string& extension_id, |
173 const std::string& configuration_id) { | 194 const std::string& configuration_id) { |
174 SendSignalToExtension( | 195 // If the configrataion was added via de PPAPI plugin |
175 extension_id, extensions::events::VPN_PROVIDER_ON_UI_EVENT, | 196 if (RegisteredViaPlugin(extension_id)) { |
176 api_vpn::OnUIEvent::kEventName, | 197 vpn_provider::VpnProviderServiceHelper::GetInstance()->OnUIEvent_UI( |
177 api_vpn::OnUIEvent::Create(api_vpn::UI_EVENT_SHOWCONFIGUREDIALOG, | 198 extension_id, PP_VPN_PROVIDER_UI_EVENT_SHOWCONFIGUREDIALOG, |
178 configuration_id)); | 199 configuration_id); |
| 200 } else { |
| 201 SendSignalToExtension( |
| 202 extension_id, extensions::events::VPN_PROVIDER_ON_UI_EVENT, |
| 203 api_vpn::OnUIEvent::kEventName, |
| 204 api_vpn::OnUIEvent::Create(api_vpn::UI_EVENT_SHOWCONFIGUREDIALOG, |
| 205 configuration_id)); |
| 206 } |
179 } | 207 } |
180 | 208 |
181 void VpnService::SendPlatformError(const std::string& extension_id, | 209 void VpnService::SendPlatformError(const std::string& extension_id, |
182 const std::string& configuration_id, | 210 const std::string& configuration_id, |
183 const std::string& error_message) { | 211 const std::string& error_message) { |
184 SendSignalToExtension( | 212 // If the configrataion was added via de PPAPI plugin |
185 extension_id, extensions::events::VPN_PROVIDER_ON_PLATFORM_MESSAGE, | 213 if (RegisteredViaPlugin(extension_id)) { |
186 api_vpn::OnPlatformMessage::kEventName, | 214 vpn_provider::VpnProviderServiceHelper::GetInstance()->OnPlatformMessage_UI( |
187 api_vpn::OnPlatformMessage::Create( | 215 extension_id, configuration_id, PP_VPN_PROVIDER_PLATFORM_MESSAGE_ERROR, |
188 configuration_id, api_vpn::PLATFORM_MESSAGE_ERROR, error_message)); | 216 error_message); |
| 217 } else { |
| 218 SendSignalToExtension( |
| 219 extension_id, extensions::events::VPN_PROVIDER_ON_PLATFORM_MESSAGE, |
| 220 api_vpn::OnPlatformMessage::kEventName, |
| 221 api_vpn::OnPlatformMessage::Create( |
| 222 configuration_id, api_vpn::PLATFORM_MESSAGE_ERROR, error_message)); |
| 223 } |
189 } | 224 } |
190 | 225 |
191 std::string VpnService::GetKey(const std::string& extension_id, | 226 std::string VpnService::GetKey(const std::string& extension_id, |
192 const std::string& name) { | 227 const std::string& name) { |
193 const std::string key = crypto::SHA256HashString(extension_id + name); | 228 const std::string key = crypto::SHA256HashString(extension_id + name); |
194 return base::HexEncode(key.data(), key.size()); | 229 return base::HexEncode(key.data(), key.size()); |
195 } | 230 } |
196 | 231 |
197 void VpnService::OnConfigurationCreated(const std::string& service_path, | 232 void VpnService::OnConfigurationCreated(const std::string& service_path, |
198 const std::string& profile_path, | 233 const std::string& profile_path, |
(...skipping 12 matching lines...) Expand all Loading... |
211 | 246 |
212 if (service_path_to_configuration_map_.find(service_path) == | 247 if (service_path_to_configuration_map_.find(service_path) == |
213 service_path_to_configuration_map_.end()) { | 248 service_path_to_configuration_map_.end()) { |
214 // Ignore removal of a configuration unknown to VPN service, which means the | 249 // Ignore removal of a configuration unknown to VPN service, which means the |
215 // configuration was created internally by the platform. | 250 // configuration was created internally by the platform. |
216 return; | 251 return; |
217 } | 252 } |
218 | 253 |
219 VpnConfiguration* configuration = | 254 VpnConfiguration* configuration = |
220 service_path_to_configuration_map_[service_path]; | 255 service_path_to_configuration_map_[service_path]; |
221 scoped_ptr<base::ListValue> event_args = | 256 // If the configrataion was added via de PPAPI plugin |
222 api_vpn::OnConfigRemoved::Create(configuration->configuration_name()); | 257 if (RegisteredViaPlugin(configuration->extension_id())) { |
223 SendSignalToExtension(configuration->extension_id(), | 258 vpn_provider::VpnProviderServiceHelper::GetInstance() |
224 extensions::events::VPN_PROVIDER_ON_CONFIG_REMOVED, | 259 ->OnConfigurationRemoved_UI(configuration->extension_id(), |
225 api_vpn::OnConfigRemoved::kEventName, | 260 configuration->configuration_name()); |
226 event_args.Pass()); | 261 } else { // via extension |
| 262 scoped_ptr<base::ListValue> event_args = |
| 263 api_vpn::OnConfigRemoved::Create(configuration->configuration_name()); |
| 264 SendSignalToExtension(configuration->extension_id(), |
| 265 extensions::events::VPN_PROVIDER_ON_CONFIG_REMOVED, |
| 266 api_vpn::OnConfigRemoved::kEventName, |
| 267 event_args.Pass()); |
| 268 } |
227 | 269 |
228 DestroyConfigurationInternal(configuration); | 270 DestroyConfigurationInternal(configuration); |
229 } | 271 } |
230 | 272 |
231 void VpnService::OnPropertiesSet(const std::string& service_path, | 273 void VpnService::OnPropertiesSet(const std::string& service_path, |
232 const std::string& guid, | 274 const std::string& guid, |
233 const base::DictionaryValue& set_properties, | 275 const base::DictionaryValue& set_properties, |
234 Source source) { | 276 Source source) { |
235 } | 277 } |
236 | 278 |
(...skipping 15 matching lines...) Expand all Loading... |
252 std::string configuration_name; | 294 std::string configuration_name; |
253 if (!dictionary.GetString(shill::kProviderTypeProperty, &vpn_type) || | 295 if (!dictionary.GetString(shill::kProviderTypeProperty, &vpn_type) || |
254 !dictionary.GetString(shill::kProviderHostProperty, &extension_id) || | 296 !dictionary.GetString(shill::kProviderHostProperty, &extension_id) || |
255 !dictionary.GetString(shill::kTypeProperty, &type) || | 297 !dictionary.GetString(shill::kTypeProperty, &type) || |
256 !dictionary.GetString(shill::kNameProperty, &configuration_name) || | 298 !dictionary.GetString(shill::kNameProperty, &configuration_name) || |
257 vpn_type != shill::kProviderThirdPartyVpn || type != shill::kTypeVPN) { | 299 vpn_type != shill::kProviderThirdPartyVpn || type != shill::kTypeVPN) { |
258 return; | 300 return; |
259 } | 301 } |
260 | 302 |
261 if (!extension_registry_->GetExtensionById( | 303 if (!extension_registry_->GetExtensionById( |
262 extension_id, extensions::ExtensionRegistry::ENABLED)) { | 304 extension_id, extensions::ExtensionRegistry::ENABLED) && |
| 305 !RegisteredViaPlugin(extension_id)) { |
263 // Does not belong to this instance of VpnService. | 306 // Does not belong to this instance of VpnService. |
| 307 // OR to our plugin map. |
264 return; | 308 return; |
265 } | 309 } |
266 | 310 |
267 const std::string key = GetKey(extension_id, configuration_name); | 311 const std::string key = GetKey(extension_id, configuration_name); |
268 VpnConfiguration* configuration = | 312 VpnConfiguration* configuration = |
269 CreateConfigurationInternal(extension_id, configuration_name, key); | 313 CreateConfigurationInternal(extension_id, configuration_name, key); |
270 configuration->set_service_path(service_path); | 314 configuration->set_service_path(service_path); |
271 service_path_to_configuration_map_[service_path] = configuration; | 315 service_path_to_configuration_map_[service_path] = configuration; |
272 shill_client_->AddShillThirdPartyVpnObserver(configuration->object_path(), | 316 shill_client_->AddShillThirdPartyVpnObserver(configuration->object_path(), |
273 configuration); | 317 configuration); |
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
560 } | 604 } |
561 delete configuration; | 605 delete configuration; |
562 } | 606 } |
563 | 607 |
564 bool VpnService::DoesActiveConfigurationExistAndIsAccessAuthorized( | 608 bool VpnService::DoesActiveConfigurationExistAndIsAccessAuthorized( |
565 const std::string& extension_id) { | 609 const std::string& extension_id) { |
566 return active_configuration_ && | 610 return active_configuration_ && |
567 active_configuration_->extension_id() == extension_id; | 611 active_configuration_->extension_id() == extension_id; |
568 } | 612 } |
569 | 613 |
| 614 void VpnService::AddPlugin(const std::string& service_id) { |
| 615 pepper_plugin_set_.insert(service_id); |
| 616 } |
| 617 |
| 618 void VpnService::RemovePlugin(const std::string& service_id) { |
| 619 pepper_plugin_set_.erase(service_id); |
| 620 } |
| 621 |
| 622 bool VpnService::RegisteredViaPlugin(const std::string& service_id) { |
| 623 return (pepper_plugin_set_.find(service_id) != pepper_plugin_set_.end()); |
| 624 } |
| 625 |
570 } // namespace chromeos | 626 } // namespace chromeos |
OLD | NEW |