| Index: content/browser/renderer_host/pepper/pepper_vpn_provider_message_filter_chromeos.cc
|
| diff --git a/content/browser/renderer_host/pepper/pepper_vpn_provider_message_filter_chromeos.cc b/content/browser/renderer_host/pepper/pepper_vpn_provider_message_filter_chromeos.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..c80c0e9f4e04d96a3bf407c55810977b6b9040fc
|
| --- /dev/null
|
| +++ b/content/browser/renderer_host/pepper/pepper_vpn_provider_message_filter_chromeos.cc
|
| @@ -0,0 +1,383 @@
|
| +// Copyright 2015 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "content/browser/renderer_host/pepper/pepper_vpn_provider_message_filter_chromeos.h"
|
| +
|
| +#include <ctime>
|
| +
|
| +#include "chrome/browser/chromeos/vpn_provider/pepper_vpn_provider_service_helper.h"
|
| +#include "content/public/browser/browser_ppapi_host.h"
|
| +#include "content/public/browser/browser_thread.h"
|
| +#include "ppapi/host/dispatch_host_message.h"
|
| +#include "ppapi/host/host_message_context.h"
|
| +#include "ppapi/proxy/ppapi_messages.h"
|
| +
|
| +namespace {
|
| +
|
| +// TODO(adrian.belgun): Figure out how to generate unique IDs
|
| +void AppendServiceIDTimeStamp(std::string* service_id) {
|
| + char time_string[] = "xYYYYMMDDhhmmss";
|
| + std::time_t t = std::time(NULL);
|
| + if (strftime(time_string, arraysize(time_string), "%Y%m%d%H%M%S",
|
| + std::localtime(&t)) > 0) {
|
| + service_id->append(time_string);
|
| + }
|
| +}
|
| +
|
| +void DoNothingErrorCallback(const std::string& error_name,
|
| + const std::string& error_message) {
|
| +}
|
| +
|
| +} // namespace
|
| +
|
| +namespace content {
|
| +
|
| +/* Workflow:
|
| + * In Constructor:
|
| + - Generate a service ID associated with this instance. Currenly this
|
| + should be "PepperVpnProviderMessageFilterChromeOSyymmddHHMMSS.
|
| + - Register this with the VpnService Handle.
|
| + * In Destructor:
|
| + - Remove from the service lingering configurations
|
| + - Remove from the VpnService the entry from the map and
|
| + from the underlying service.
|
| + * On Create Config:
|
| + - Add the config name to the current configs set.
|
| + * On Destroy Config:
|
| + - Remove the config name to the current configs set.
|
| + */
|
| +PepperVpnProviderMessageFilterChromeOS::PepperVpnProviderMessageFilterChromeOS(
|
| + BrowserPpapiHostImpl* host,
|
| + PP_Instance instance)
|
| + : render_process_id_(0), render_frame_id_(0), weak_factory_(this) {
|
| + DCHECK(host);
|
| +
|
| + if (!host->GetRenderFrameIDsForInstance(instance, &render_process_id_,
|
| + &render_frame_id_)) {
|
| + NOTREACHED();
|
| + }
|
| +
|
| + service_id_ = "PepperVpnProviderMessageFilterChromeOS";
|
| + AppendServiceIDTimeStamp(&service_id_);
|
| +
|
| + chromeos::vpn_provider::VpnProviderServiceHelper::GetInstance()
|
| + ->AddServiceID_IO(service_id_, weak_factory_.GetWeakPtr(),
|
| + render_process_id_);
|
| +}
|
| +
|
| +PepperVpnProviderMessageFilterChromeOS::
|
| + ~PepperVpnProviderMessageFilterChromeOS() {
|
| + // We need a copy. Will iterate and delete from the original.
|
| + std::set<std::string> configs(created_configs_);
|
| + for (const auto& id : configs) {
|
| + DoDestroyConfig(id, base::Bind(&base::DoNothing),
|
| + base::Bind(&DoNothingErrorCallback));
|
| + }
|
| + chromeos::vpn_provider::VpnProviderServiceHelper::GetInstance()
|
| + ->RemoveServiceID_IO(service_id_, render_process_id_);
|
| +}
|
| +
|
| +scoped_refptr<base::TaskRunner>
|
| +PepperVpnProviderMessageFilterChromeOS::OverrideTaskRunnerForMessage(
|
| + const IPC::Message& message) {
|
| + switch (message.type()) {
|
| + case PpapiHostMsg_VpnProvider_CreateConfig::ID:
|
| + case PpapiHostMsg_VpnProvider_DestroyConfig::ID:
|
| + case PpapiHostMsg_VpnProvider_SetParameters::ID:
|
| + case PpapiHostMsg_VpnProvider_SendPacket::ID:
|
| + case PpapiHostMsg_VpnProvider_NotifyConnectionStateChanged::ID:
|
| + return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI);
|
| + }
|
| + return NULL;
|
| +}
|
| +
|
| +int32_t PepperVpnProviderMessageFilterChromeOS::OnResourceMessageReceived(
|
| + const IPC::Message& msg,
|
| + ppapi::host::HostMessageContext* context) {
|
| + PPAPI_BEGIN_MESSAGE_MAP(PepperVpnProviderMessageFilterChromeOS, msg)
|
| + PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_VpnProvider_CreateConfig,
|
| + OnCreateConfig)
|
| + PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_VpnProvider_DestroyConfig,
|
| + OnDestroyConfig)
|
| + PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_VpnProvider_SetParameters,
|
| + OnSetParameters)
|
| + PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_VpnProvider_SendPacket,
|
| + OnSendPacket)
|
| + PPAPI_DISPATCH_HOST_RESOURCE_CALL(
|
| + PpapiHostMsg_VpnProvider_NotifyConnectionStateChanged,
|
| + OnNotifyConnectionStateChanged)
|
| + PPAPI_END_MESSAGE_MAP()
|
| + return PP_ERROR_FAILED;
|
| +}
|
| +
|
| +// Responds to PpapiHostMsg_VpnProvider_CreateConfig,
|
| +// Forwards to VpnService::CreateConfiguration
|
| +// Sends back PpapiPluginMsg_VpnProvider_CreateConfigReply
|
| +int32_t PepperVpnProviderMessageFilterChromeOS::OnCreateConfig(
|
| + ppapi::host::HostMessageContext* context,
|
| + const std::string& name) {
|
| + return DoCreateConfig(
|
| + name,
|
| + base::Bind(&PepperVpnProviderMessageFilterChromeOS::OnCreateConfigSuccess,
|
| + weak_factory_.GetWeakPtr(), context->MakeReplyMessageContext(),
|
| + name), // Use name as id
|
| + base::Bind(&PepperVpnProviderMessageFilterChromeOS::OnCreateConfigFailure,
|
| + weak_factory_.GetWeakPtr(),
|
| + context->MakeReplyMessageContext()));
|
| +}
|
| +
|
| +// Responds to PpapiHostMsg_VpnProvider_DestroyConfig
|
| +// Forwards to VpnService::DestroyConfiguration
|
| +// Sends back PpapiPluginMsg_VpnProvider_DestroyConfigReply
|
| +int32_t PepperVpnProviderMessageFilterChromeOS::OnDestroyConfig(
|
| + ppapi::host::HostMessageContext* context,
|
| + const std::string& id) {
|
| + return DoDestroyConfig(
|
| + id, base::Bind(
|
| + &PepperVpnProviderMessageFilterChromeOS::OnDestroyConfigSuccess,
|
| + weak_factory_.GetWeakPtr(), context->MakeReplyMessageContext()),
|
| + base::Bind(
|
| + &PepperVpnProviderMessageFilterChromeOS::OnDestroyConfigFailure,
|
| + weak_factory_.GetWeakPtr(), context->MakeReplyMessageContext()));
|
| +}
|
| +
|
| +// Responds to PpapiHostMsg_VpnProvider_SetParameters
|
| +// Forwards to VpnService::SetParameters
|
| +// Sends back PpapiHostMsg_VpnProvider_SetParametersReply
|
| +int32_t PepperVpnProviderMessageFilterChromeOS::OnSetParameters(
|
| + ppapi::host::HostMessageContext* context,
|
| + const ppapi::proxy::SerializedVpnProviderParameters& params) {
|
| + return DoSetParameters(
|
| + params,
|
| + base::Bind(
|
| + &PepperVpnProviderMessageFilterChromeOS::OnSetParametersSuccess,
|
| + weak_factory_.GetWeakPtr(), context->MakeReplyMessageContext()),
|
| + base::Bind(
|
| + &PepperVpnProviderMessageFilterChromeOS::OnSetParametersFailure,
|
| + weak_factory_.GetWeakPtr(), context->MakeReplyMessageContext()));
|
| +}
|
| +
|
| +// Responds to PpapiHostMsg_VpnProvider_SendPacket
|
| +// Forwards to VpnService::SendPacket
|
| +// Sends back PpapiHostMsg_VpnProvider_SendPacketReply
|
| +int32_t PepperVpnProviderMessageFilterChromeOS::OnSendPacket(
|
| + ppapi::host::HostMessageContext* context,
|
| + const std::vector<char>& data) {
|
| + return DoSendPacket(data, base::Bind(&base::DoNothing),
|
| + base::Bind(&DoNothingErrorCallback));
|
| +}
|
| +
|
| +// Responds to PpapiHostMsg_VpnProvider_NotifyConnectionStateChanged
|
| +// Forwards to VpnService::NotifyConnectionStateChanged
|
| +// Sends back PpapiPluginMsg_VpnProvider_NotifyConnectionStateChangedReply
|
| +int32_t PepperVpnProviderMessageFilterChromeOS::OnNotifyConnectionStateChanged(
|
| + ppapi::host::HostMessageContext* context,
|
| + PP_VpnProvider_VpnConnectionState status) {
|
| + return DoNotifyConnectionStateChanged(
|
| + status, base::Bind(&PepperVpnProviderMessageFilterChromeOS::
|
| + OnNotifyConnectionStateChangedSuccess,
|
| + weak_factory_.GetWeakPtr(),
|
| + context->MakeReplyMessageContext()),
|
| + base::Bind(&PepperVpnProviderMessageFilterChromeOS::
|
| + OnNotifyConnectionStateChangedFailure,
|
| + weak_factory_.GetWeakPtr(),
|
| + context->MakeReplyMessageContext()));
|
| +}
|
| +
|
| +int32_t PepperVpnProviderMessageFilterChromeOS::DoCreateConfig(
|
| + const std::string& name,
|
| + SuccessCallback success,
|
| + FailureCallback failure) {
|
| + if (created_configs_.find(name) != created_configs_.end()) {
|
| + // Already created
|
| + NOTREACHED();
|
| + return PP_ERROR_BADARGUMENT;
|
| + }
|
| + created_configs_.insert(name);
|
| +
|
| + chromeos::vpn_provider::VpnProviderServiceHelper::GetInstance()
|
| + ->CreateConfig_UI(service_id_, name, render_process_id_, success,
|
| + failure);
|
| + return PP_OK_COMPLETIONPENDING;
|
| +}
|
| +
|
| +void PepperVpnProviderMessageFilterChromeOS::OnCreateConfigSuccess(
|
| + const ppapi::host::ReplyMessageContext& context,
|
| + const std::string& id) {
|
| + OnCreateConfigReply(context, PP_OK, id);
|
| +}
|
| +
|
| +void PepperVpnProviderMessageFilterChromeOS::OnCreateConfigFailure(
|
| + const ppapi::host::ReplyMessageContext& context,
|
| + const std::string& error_name,
|
| + const std::string& error_message) {
|
| + OnCreateConfigReply(context, PP_ERROR_FAILED, std::string(""));
|
| +}
|
| +
|
| +void PepperVpnProviderMessageFilterChromeOS::OnCreateConfigReply(
|
| + const ppapi::host::ReplyMessageContext& context,
|
| + int32_t reply,
|
| + const std::string& id) {
|
| + SendReply(context, PpapiPluginMsg_VpnProvider_CreateConfigReply(reply, id));
|
| +}
|
| +
|
| +int32_t PepperVpnProviderMessageFilterChromeOS::DoDestroyConfig(
|
| + const std::string& id,
|
| + SuccessCallback success,
|
| + FailureCallback failure) {
|
| + if (created_configs_.find(id) == created_configs_.end()) {
|
| + // Attempted to delete exiting configuration
|
| + NOTREACHED();
|
| + return PP_ERROR_BADARGUMENT;
|
| + }
|
| + created_configs_.erase(id);
|
| +
|
| + chromeos::vpn_provider::VpnProviderServiceHelper::GetInstance()
|
| + ->DestroyConfig_UI(service_id_, id, render_process_id_, success, failure);
|
| + return PP_OK_COMPLETIONPENDING;
|
| +}
|
| +
|
| +void PepperVpnProviderMessageFilterChromeOS::OnDestroyConfigSuccess(
|
| + const ppapi::host::ReplyMessageContext& context) {
|
| + OnDestroyConfigReply(context, PP_OK);
|
| +}
|
| +
|
| +void PepperVpnProviderMessageFilterChromeOS::OnDestroyConfigFailure(
|
| + const ppapi::host::ReplyMessageContext& context,
|
| + const std::string& error_name,
|
| + const std::string& error_message) {
|
| + OnDestroyConfigReply(context, PP_ERROR_FAILED);
|
| +}
|
| +
|
| +void PepperVpnProviderMessageFilterChromeOS::OnDestroyConfigReply(
|
| + const ppapi::host::ReplyMessageContext& context,
|
| + int32_t reply) {
|
| + SendReply(context, PpapiPluginMsg_VpnProvider_DestroyConfigReply(reply));
|
| +}
|
| +
|
| +int32_t PepperVpnProviderMessageFilterChromeOS::DoSendPacket(
|
| + const std::vector<char>& data,
|
| + SuccessCallback success,
|
| + FailureCallback failure) {
|
| + chromeos::vpn_provider::VpnProviderServiceHelper::GetInstance()
|
| + ->SendPacket_UI(service_id_, data, render_process_id_, success, failure);
|
| + return PP_OK_COMPLETIONPENDING;
|
| +}
|
| +
|
| +int32_t PepperVpnProviderMessageFilterChromeOS::DoSetParameters(
|
| + const ppapi::proxy::SerializedVpnProviderParameters& params,
|
| + StringCallback success,
|
| + FailureCallback failure) {
|
| + chromeos::vpn_provider::VpnProviderServiceHelper::GetInstance()
|
| + ->SetParameters_UI(service_id_, params, render_process_id_, success,
|
| + failure);
|
| + return PP_OK_COMPLETIONPENDING;
|
| +}
|
| +
|
| +void PepperVpnProviderMessageFilterChromeOS::OnSetParametersSuccess(
|
| + const ppapi::host::ReplyMessageContext& context,
|
| + const std::string& result) {
|
| + OnSetParametersReply(context, PP_OK);
|
| +}
|
| +
|
| +void PepperVpnProviderMessageFilterChromeOS::OnSetParametersFailure(
|
| + const ppapi::host::ReplyMessageContext& context,
|
| + const std::string& error_name,
|
| + const std::string& error_message) {
|
| + OnSetParametersReply(context, PP_ERROR_FAILED);
|
| +}
|
| +
|
| +void PepperVpnProviderMessageFilterChromeOS::OnSetParametersReply(
|
| + const ppapi::host::ReplyMessageContext& context,
|
| + int32_t reply) {
|
| + SendReply(context, PpapiPluginMsg_VpnProvider_SetParametersReply(reply));
|
| +}
|
| +
|
| +int32_t PepperVpnProviderMessageFilterChromeOS::DoNotifyConnectionStateChanged(
|
| + PP_VpnProvider_VpnConnectionState status,
|
| + SuccessCallback success,
|
| + FailureCallback failure) {
|
| + chromeos::vpn_provider::VpnProviderServiceHelper::GetInstance()
|
| + ->NotifyConnectionStateChanged_UI(service_id_, status, render_process_id_,
|
| + success, failure);
|
| + return PP_OK_COMPLETIONPENDING;
|
| +}
|
| +
|
| +void PepperVpnProviderMessageFilterChromeOS::
|
| + OnNotifyConnectionStateChangedSuccess(
|
| + const ppapi::host::ReplyMessageContext& context) {
|
| + OnNotifyConnectionStateChangedReply(context, PP_OK);
|
| +}
|
| +
|
| +void PepperVpnProviderMessageFilterChromeOS::
|
| + OnNotifyConnectionStateChangedFailure(
|
| + const ppapi::host::ReplyMessageContext& context,
|
| + const std::string& error_name,
|
| + const std::string& error_message) {
|
| + OnNotifyConnectionStateChangedReply(context, PP_ERROR_FAILED);
|
| +}
|
| +
|
| +void PepperVpnProviderMessageFilterChromeOS::
|
| + OnNotifyConnectionStateChangedReply(
|
| + const ppapi::host::ReplyMessageContext& context,
|
| + int32_t reply) {
|
| + SendReply(
|
| + context,
|
| + PpapiPluginMsg_VpnProvider_NotifyConnectionStateChangedReply(reply));
|
| +}
|
| +
|
| +void PepperVpnProviderMessageFilterChromeOS::Send_OnPlatformMessage(
|
| + std::string id,
|
| + PP_VpnProvider_PlatformMessage status,
|
| + std::string message) {
|
| + if (resource_host()) {
|
| + resource_host()->host()->SendUnsolicitedReply(
|
| + resource_host()->pp_resource(),
|
| + PpapiPluginMsg_VpnProvider_OnPlatformMessage(id, status, message));
|
| + }
|
| +}
|
| +
|
| +void PepperVpnProviderMessageFilterChromeOS::Send_OnPacketReceived(
|
| + const std::vector<char>& data) {
|
| + if (resource_host()) {
|
| + resource_host()->host()->SendUnsolicitedReply(
|
| + resource_host()->pp_resource(),
|
| + PpapiPluginMsg_VpnProvider_OnPacketReceived(data));
|
| + }
|
| +}
|
| +
|
| +void PepperVpnProviderMessageFilterChromeOS::Send_OnConfigurationEvent(
|
| + const std::string& id,
|
| + PP_VpnProvider_ConfigMessage message,
|
| + const std::string& name,
|
| + const std::string& data) {
|
| + if (message == PP_VPN_PROVIDER_CONFIG_REMOVED) {
|
| + if (created_configs_.find(id) == created_configs_.end()) {
|
| + // Attempted to delete exiting configuration
|
| + NOTREACHED();
|
| + return;
|
| + }
|
| + created_configs_.erase(id);
|
| + } else if (message == PP_VPN_PROVIDER_CONFIG_CREATED) {
|
| + // TODO(adrian.belgun): Figure out if to update created_configs_
|
| + }
|
| +
|
| + if (resource_host()) {
|
| + resource_host()->host()->SendUnsolicitedReply(
|
| + resource_host()->pp_resource(),
|
| + PpapiPluginMsg_VpnProvider_OnConfigEvent(id, message, name, data));
|
| + }
|
| +}
|
| +
|
| +void PepperVpnProviderMessageFilterChromeOS::Send_OnUIEvent(
|
| + PP_VpnProvider_UIEvent event,
|
| + const std::string& id) {
|
| + if (resource_host()) {
|
| + resource_host()->host()->SendUnsolicitedReply(
|
| + resource_host()->pp_resource(),
|
| + PpapiPluginMsg_VpnProvider_OnUIEvent(event, id));
|
| + }
|
| +}
|
| +
|
| +} // namespace content
|
|
|