| Index: extensions/browser/api/vpn_provider/vpn_service.cc
|
| diff --git a/extensions/browser/api/vpn_provider/vpn_service.cc b/extensions/browser/api/vpn_provider/vpn_service.cc
|
| index 3afe0b7a6a0a9471105fbb5282db41e3ef37ed19..f184bd93284bef75ee8631bb6260394c6736127c 100644
|
| --- a/extensions/browser/api/vpn_provider/vpn_service.cc
|
| +++ b/extensions/browser/api/vpn_provider/vpn_service.cc
|
| @@ -17,6 +17,7 @@
|
| #include "base/strings/string_number_conversions.h"
|
| #include "base/strings/string_util.h"
|
| #include "base/values.h"
|
| +#include "chrome/browser/chromeos/vpn_provider/pepper_vpn_provider_service_helper.h"
|
| #include "chromeos/dbus/shill_third_party_vpn_driver_client.h"
|
| #include "chromeos/dbus/shill_third_party_vpn_observer.h"
|
| #include "chromeos/network/network_configuration_handler.h"
|
| @@ -97,11 +98,17 @@ void VpnService::VpnConfiguration::OnPacketReceived(
|
| if (!vpn_service_) {
|
| return;
|
| }
|
| - scoped_ptr<base::ListValue> event_args =
|
| - api_vpn::OnPacketReceived::Create(data);
|
| - vpn_service_->SendSignalToExtension(
|
| - extension_id_, extensions::events::VPN_PROVIDER_ON_PACKET_RECEIVED,
|
| - api_vpn::OnPacketReceived::kEventName, event_args.Pass());
|
| + // If the configrataion was added via de PPAPI plugin
|
| + if (vpn_service_->RegisteredViaPlugin(extension_id_)) {
|
| + vpn_provider::VpnProviderServiceHelper::GetInstance()->OnPacketReceived_UI(
|
| + extension_id_, data);
|
| + } else {
|
| + scoped_ptr<base::ListValue> event_args =
|
| + api_vpn::OnPacketReceived::Create(data);
|
| + vpn_service_->SendSignalToExtension(
|
| + extension_id_, extensions::events::VPN_PROVIDER_ON_PACKET_RECEIVED,
|
| + api_vpn::OnPacketReceived::kEventName, event_args.Pass());
|
| + }
|
| }
|
|
|
| void VpnService::VpnConfiguration::OnPlatformMessage(uint32_t message) {
|
| @@ -115,14 +122,22 @@ void VpnService::VpnConfiguration::OnPlatformMessage(uint32_t message) {
|
| vpn_service_->SetActiveConfiguration(
|
| platform_message == api_vpn::PLATFORM_MESSAGE_CONNECTED ? this : nullptr);
|
|
|
| - // TODO(kaliamoorthi): Update the lower layers to get the error message and
|
| - // pass in the error instead of std::string().
|
| - scoped_ptr<base::ListValue> event_args = api_vpn::OnPlatformMessage::Create(
|
| - configuration_name_, platform_message, std::string());
|
| -
|
| - vpn_service_->SendSignalToExtension(
|
| - extension_id_, extensions::events::VPN_PROVIDER_ON_PLATFORM_MESSAGE,
|
| - api_vpn::OnPlatformMessage::kEventName, event_args.Pass());
|
| + // If the configrataion was added via de PPAPI plugin
|
| + if (vpn_service_->RegisteredViaPlugin(extension_id_)) {
|
| + vpn_provider::VpnProviderServiceHelper::GetInstance()->OnPlatformMessage_UI(
|
| + extension_id_, configuration_name_,
|
| + (PP_VpnProvider_PlatformMessage)message, // TODO: Fix mappings
|
| + std::string());
|
| + } else {
|
| + // TODO(kaliamoorthi): Update the lower layers to get the error message and
|
| + // pass in the error instead of std::string().
|
| + scoped_ptr<base::ListValue> event_args = api_vpn::OnPlatformMessage::Create(
|
| + configuration_name_, platform_message, std::string());
|
| +
|
| + vpn_service_->SendSignalToExtension(
|
| + extension_id_, extensions::events::VPN_PROVIDER_ON_PLATFORM_MESSAGE,
|
| + api_vpn::OnPlatformMessage::kEventName, event_args.Pass());
|
| + }
|
| }
|
|
|
| VpnService::VpnService(
|
| @@ -161,31 +176,51 @@ VpnService::~VpnService() {
|
| }
|
|
|
| void VpnService::SendShowAddDialogToExtension(const std::string& extension_id) {
|
| - SendSignalToExtension(extension_id,
|
| - extensions::events::VPN_PROVIDER_ON_UI_EVENT,
|
| - api_vpn::OnUIEvent::kEventName,
|
| - api_vpn::OnUIEvent::Create(
|
| - api_vpn::UI_EVENT_SHOWADDDIALOG, std::string()));
|
| + // If the configrataion was added via de PPAPI plugin
|
| + if (RegisteredViaPlugin(extension_id)) {
|
| + vpn_provider::VpnProviderServiceHelper::GetInstance()->OnUIEvent_UI(
|
| + extension_id, PP_VPN_PROVIDER_UI_EVENT_SHOWADDDIALOG, std::string());
|
| + } else { // via extension
|
| + SendSignalToExtension(extension_id,
|
| + extensions::events::VPN_PROVIDER_ON_UI_EVENT,
|
| + api_vpn::OnUIEvent::kEventName,
|
| + api_vpn::OnUIEvent::Create(
|
| + api_vpn::UI_EVENT_SHOWADDDIALOG, std::string()));
|
| + }
|
| }
|
|
|
| void VpnService::SendShowConfigureDialogToExtension(
|
| const std::string& extension_id,
|
| const std::string& configuration_id) {
|
| - SendSignalToExtension(
|
| - extension_id, extensions::events::VPN_PROVIDER_ON_UI_EVENT,
|
| - api_vpn::OnUIEvent::kEventName,
|
| - api_vpn::OnUIEvent::Create(api_vpn::UI_EVENT_SHOWCONFIGUREDIALOG,
|
| - configuration_id));
|
| + // If the configrataion was added via de PPAPI plugin
|
| + if (RegisteredViaPlugin(extension_id)) {
|
| + vpn_provider::VpnProviderServiceHelper::GetInstance()->OnUIEvent_UI(
|
| + extension_id, PP_VPN_PROVIDER_UI_EVENT_SHOWCONFIGUREDIALOG,
|
| + configuration_id);
|
| + } else {
|
| + SendSignalToExtension(
|
| + extension_id, extensions::events::VPN_PROVIDER_ON_UI_EVENT,
|
| + api_vpn::OnUIEvent::kEventName,
|
| + api_vpn::OnUIEvent::Create(api_vpn::UI_EVENT_SHOWCONFIGUREDIALOG,
|
| + configuration_id));
|
| + }
|
| }
|
|
|
| void VpnService::SendPlatformError(const std::string& extension_id,
|
| const std::string& configuration_id,
|
| const std::string& error_message) {
|
| - SendSignalToExtension(
|
| - extension_id, extensions::events::VPN_PROVIDER_ON_PLATFORM_MESSAGE,
|
| - api_vpn::OnPlatformMessage::kEventName,
|
| - api_vpn::OnPlatformMessage::Create(
|
| - configuration_id, api_vpn::PLATFORM_MESSAGE_ERROR, error_message));
|
| + // If the configrataion was added via de PPAPI plugin
|
| + if (RegisteredViaPlugin(extension_id)) {
|
| + vpn_provider::VpnProviderServiceHelper::GetInstance()->OnPlatformMessage_UI(
|
| + extension_id, configuration_id, PP_VPN_PROVIDER_PLATFORM_MESSAGE_ERROR,
|
| + error_message);
|
| + } else {
|
| + SendSignalToExtension(
|
| + extension_id, extensions::events::VPN_PROVIDER_ON_PLATFORM_MESSAGE,
|
| + api_vpn::OnPlatformMessage::kEventName,
|
| + api_vpn::OnPlatformMessage::Create(
|
| + configuration_id, api_vpn::PLATFORM_MESSAGE_ERROR, error_message));
|
| + }
|
| }
|
|
|
| std::string VpnService::GetKey(const std::string& extension_id,
|
| @@ -218,12 +253,19 @@ void VpnService::OnConfigurationRemoved(const std::string& service_path,
|
|
|
| VpnConfiguration* configuration =
|
| service_path_to_configuration_map_[service_path];
|
| - scoped_ptr<base::ListValue> event_args =
|
| - api_vpn::OnConfigRemoved::Create(configuration->configuration_name());
|
| - SendSignalToExtension(configuration->extension_id(),
|
| - extensions::events::VPN_PROVIDER_ON_CONFIG_REMOVED,
|
| - api_vpn::OnConfigRemoved::kEventName,
|
| - event_args.Pass());
|
| + // If the configrataion was added via de PPAPI plugin
|
| + if (RegisteredViaPlugin(configuration->extension_id())) {
|
| + vpn_provider::VpnProviderServiceHelper::GetInstance()
|
| + ->OnConfigurationRemoved_UI(configuration->extension_id(),
|
| + configuration->configuration_name());
|
| + } else { // via extension
|
| + scoped_ptr<base::ListValue> event_args =
|
| + api_vpn::OnConfigRemoved::Create(configuration->configuration_name());
|
| + SendSignalToExtension(configuration->extension_id(),
|
| + extensions::events::VPN_PROVIDER_ON_CONFIG_REMOVED,
|
| + api_vpn::OnConfigRemoved::kEventName,
|
| + event_args.Pass());
|
| + }
|
|
|
| DestroyConfigurationInternal(configuration);
|
| }
|
| @@ -259,8 +301,10 @@ void VpnService::OnGetPropertiesSuccess(
|
| }
|
|
|
| if (!extension_registry_->GetExtensionById(
|
| - extension_id, extensions::ExtensionRegistry::ENABLED)) {
|
| + extension_id, extensions::ExtensionRegistry::ENABLED) &&
|
| + !RegisteredViaPlugin(extension_id)) {
|
| // Does not belong to this instance of VpnService.
|
| + // OR to our plugin map.
|
| return;
|
| }
|
|
|
| @@ -567,4 +611,16 @@ bool VpnService::DoesActiveConfigurationExistAndIsAccessAuthorized(
|
| active_configuration_->extension_id() == extension_id;
|
| }
|
|
|
| +void VpnService::AddPlugin(const std::string& service_id) {
|
| + pepper_plugin_set_.insert(service_id);
|
| +}
|
| +
|
| +void VpnService::RemovePlugin(const std::string& service_id) {
|
| + pepper_plugin_set_.erase(service_id);
|
| +}
|
| +
|
| +bool VpnService::RegisteredViaPlugin(const std::string& service_id) {
|
| + return (pepper_plugin_set_.find(service_id) != pepper_plugin_set_.end());
|
| +}
|
| +
|
| } // namespace chromeos
|
|
|