Index: ppapi/proxy/vpn_provider_resource.cc |
diff --git a/ppapi/proxy/vpn_provider_resource.cc b/ppapi/proxy/vpn_provider_resource.cc |
index bf960bdf8075f8a56d1f9e866e6b1498df4afdfb..2d2f94de6fc8d0492cd67726273f09a89faddca4 100644 |
--- a/ppapi/proxy/vpn_provider_resource.cc |
+++ b/ppapi/proxy/vpn_provider_resource.cc |
@@ -23,7 +23,9 @@ VpnProviderResource::VpnProviderResource(Connection connection, |
send_packet_callback_(nullptr), |
receive_packet_callback_(nullptr), |
receive_packet_callback_var_(nullptr), |
- bound_(false) {} |
+ bound_(false) { |
+ SendCreate(BROWSER, PpapiHostMsg_VpnProvider_Create()); |
+} |
VpnProviderResource::~VpnProviderResource() {} |
@@ -34,7 +36,15 @@ thunk::PPB_VpnProvider_API* VpnProviderResource::AsPPB_VpnProvider_API() { |
void VpnProviderResource::OnReplyReceived( |
const ResourceMessageReplyParams& params, |
const IPC::Message& msg) { |
- PluginResource::OnReplyReceived(params, msg); |
+ PPAPI_BEGIN_MESSAGE_MAP(VpnProviderResource, msg) |
+ PPAPI_DISPATCH_PLUGIN_RESOURCE_CALL(PpapiPluginMsg_VpnProvider_OnUnbind, |
+ OnPluginMsgOnUnbindReceived) |
+ PPAPI_DISPATCH_PLUGIN_RESOURCE_CALL( |
+ PpapiPluginMsg_VpnProvider_OnPacketReceived, |
+ OnPluginMsgOnPacketReceived) |
+ PPAPI_DISPATCH_PLUGIN_RESOURCE_CALL_UNHANDLED( |
+ PluginResource::OnReplyReceived(params, msg)) |
+ PPAPI_END_MESSAGE_MAP() |
} |
int32_t VpnProviderResource::Bind( |
@@ -51,7 +61,14 @@ int32_t VpnProviderResource::Bind( |
if (!configuration_name_var) |
return PP_ERROR_BADARGUMENT; |
- return PP_ERROR_NOTSUPPORTED; |
+ bind_callback_ = callback; |
+ |
+ Call<PpapiPluginMsg_VpnProvider_BindReply>( |
+ BROWSER, PpapiHostMsg_VpnProvider_Bind(configuration_id_var->value(), |
+ configuration_name_var->value()), |
+ base::Bind(&VpnProviderResource::OnPluginMsgBindReply, this)); |
+ |
+ return PP_OK_COMPLETIONPENDING; |
} |
int32_t VpnProviderResource::SendPacket( |
@@ -86,11 +103,18 @@ int32_t VpnProviderResource::DoSendPacket(const PP_Var& packet, uint32_t id) { |
if (!packet_arraybuffer.get()) |
return PP_ERROR_BADARGUMENT; |
- char* packet_pointer = static_cast<char*>(packet_arraybuffer->Map()); |
uint32_t packet_size = packet_arraybuffer->ByteLength(); |
+ if (packet_size > send_packet_buffer_->GetMaxPacketSize()) |
+ return PP_ERROR_MESSAGE_TOO_BIG; |
bbudge
2016/06/23 18:10:23
It's fine to check this to help plugin writers, bu
adrian.belgun
2016/06/24 13:19:37
How can it be bypassed? When the plugin will call
|
+ |
+ char* packet_pointer = static_cast<char*>(packet_arraybuffer->Map()); |
memcpy(send_packet_buffer_->GetBuffer(id), packet_pointer, packet_size); |
packet_arraybuffer->Unmap(); |
+ Call<PpapiPluginMsg_VpnProvider_SendPacketReply>( |
+ BROWSER, PpapiHostMsg_VpnProvider_SendPacket(packet_size, id), |
+ base::Bind(&VpnProviderResource::OnPluginMsgSendPacketReply, this)); |
+ |
return PP_OK; |
} |
@@ -132,7 +156,9 @@ void VpnProviderResource::OnPluginMsgOnPacketReceived( |
const ResourceMessageReplyParams& params, |
uint32_t packet_size, |
uint32_t id) { |
- if (!bound_) { |
+ if (!bound_ || (packet_size > receive_packet_buffer_->GetMaxPacketSize())) { |
bbudge
2016/06/23 18:10:23
packet_size is coming from the browser so this sho
adrian.belgun
2016/06/24 13:19:37
Done.
|
+ // Ignore packet and mark shared memory as available |
+ Post(BROWSER, PpapiHostMsg_VpnProvider_OnPacketReceivedReply(id)); |
return; |
} |
@@ -143,6 +169,9 @@ void VpnProviderResource::OnPluginMsgOnPacketReceived( |
packet_pointer)); |
received_packets_.push(packet_var); |
+ // Mark shared memory as available for next packet |
+ Post(BROWSER, PpapiHostMsg_VpnProvider_OnPacketReceivedReply(id)); |
+ |
if (!TrackedCallback::IsPending(receive_packet_callback_) || |
TrackedCallback::IsScheduledToRun(receive_packet_callback_)) { |
return; |