Index: content/browser/renderer_host/pepper/pepper_udp_socket_message_filter.cc |
diff --git a/content/browser/renderer_host/pepper/pepper_udp_socket_message_filter.cc b/content/browser/renderer_host/pepper/pepper_udp_socket_message_filter.cc |
index 50221d9222c4f7dfe3e7f2c87e3218020c864d48..f387b2b5fd1818d4ca195b4757618202eb386cf1 100644 |
--- a/content/browser/renderer_host/pepper/pepper_udp_socket_message_filter.cc |
+++ b/content/browser/renderer_host/pepper/pepper_udp_socket_message_filter.cc |
@@ -29,10 +29,14 @@ |
#include "ppapi/proxy/udp_socket_resource_base.h" |
#include "ppapi/shared_impl/private/net_address_private_impl.h" |
#include "ppapi/shared_impl/socket_option_data.h" |
+#include "ppapi/thunk/enter.h" |
+#include "ppapi/thunk/ppb_net_address_api.h" |
using ppapi::NetAddressPrivateImpl; |
using ppapi::host::NetErrorToPepperError; |
using ppapi::proxy::UDPSocketResourceBase; |
+using ppapi::thunk::EnterResource; |
+using ppapi::thunk::PPB_NetAddress_API; |
namespace { |
@@ -60,6 +64,7 @@ PepperUDPSocketMessageFilter::PepperUDPSocketMessageFilter( |
: socket_options_(0), |
rcvbuf_size_(0), |
sndbuf_size_(0), |
+ multicast_ttl_(0), |
closed_(false), |
remaining_recv_slots_(UDPSocketResourceBase::kPluginReceiveBufferSlots), |
external_plugin_(host->external_plugin()), |
@@ -95,6 +100,8 @@ PepperUDPSocketMessageFilter::OverrideTaskRunnerForMessage( |
return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO); |
case PpapiHostMsg_UDPSocket_Bind::ID: |
case PpapiHostMsg_UDPSocket_SendTo::ID: |
+ case PpapiHostMsg_UDPSocket_JoinGroup::ID: |
+ case PpapiHostMsg_UDPSocket_LeaveGroup::ID: |
return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI); |
} |
return NULL; |
@@ -113,6 +120,10 @@ int32_t PepperUDPSocketMessageFilter::OnResourceMessageReceived( |
OnMsgClose) |
PPAPI_DISPATCH_HOST_RESOURCE_CALL_0( |
PpapiHostMsg_UDPSocket_RecvSlotAvailable, OnMsgRecvSlotAvailable) |
+ PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_UDPSocket_JoinGroup, |
+ OnMsgJoinGroup) |
+ PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_UDPSocket_LeaveGroup, |
+ OnMsgLeaveGroup) |
PPAPI_END_MESSAGE_MAP() |
return PP_ERROR_FAILED; |
} |
@@ -151,7 +162,7 @@ int32_t PepperUDPSocketMessageFilter::OnMsgSetOption( |
if (!value.GetBool(&boolean_value)) |
return PP_ERROR_BADARGUMENT; |
- // If the socket is already connected, proxy the value to TCPSocket. |
+ // If the socket is already connected, proxy the value to UDPSocket. |
if (socket_.get()) |
return NetErrorToPepperError(socket_->SetBroadcast(boolean_value)); |
@@ -201,6 +212,40 @@ int32_t PepperUDPSocketMessageFilter::OnMsgSetOption( |
rcvbuf_size_ = integer_value; |
return PP_OK; |
} |
+ case PP_UDPSOCKET_OPTION_MULTICAST_LOOP: { |
+ bool boolean_value = false; |
+ if (!value.GetBool(&boolean_value)) |
+ return PP_ERROR_BADARGUMENT; |
+ |
+ // If the socket is already connected, proxy the value to UDPSocket. |
+ if (socket_.get()) |
+ return NetErrorToPepperError( |
+ socket_->SetMulticastLoopbackMode(boolean_value)); |
+ |
+ // UDPSocket instance is not yet created, so remember the value here. |
+ if (boolean_value) { |
+ socket_options_ |= SOCKET_OPTION_MULTICAST_LOOP; |
+ } else { |
+ socket_options_ &= ~SOCKET_OPTION_MULTICAST_LOOP; |
+ } |
+ return PP_OK; |
+ } |
+ case PP_UDPSOCKET_OPTION_MULTICAST_TTL: { |
+ int32_t integer_value = 0; |
+ if (!value.GetInt32(&integer_value) || |
+ integer_value < 0 || integer_value > 255) |
+ return PP_ERROR_BADARGUMENT; |
+ |
+ // If the socket is already connected, proxy the value to UDPSocket. |
+ if (socket_.get()) |
+ return NetErrorToPepperError( |
+ socket_->SetMulticastTimeToLive(integer_value)); |
+ |
+ // UDPSocket instance is not yet created, so remember the value here. |
+ socket_options_ |= SOCKET_OPTION_MULTICAST_TTL; |
+ multicast_ttl_ = integer_value; |
+ return PP_OK; |
+ } |
default: { |
NOTREACHED(); |
return PP_ERROR_BADARGUMENT; |
@@ -286,6 +331,42 @@ int32_t PepperUDPSocketMessageFilter::OnMsgRecvSlotAvailable( |
return PP_OK; |
} |
+int32_t PepperUDPSocketMessageFilter::OnMsgJoinGroup( |
+ const ppapi::host::HostMessageContext* context, |
+ const PP_NetAddress_Private& addr) { |
+ DCHECK_CURRENTLY_ON(BrowserThread::UI); |
+ DCHECK(context); |
+ |
+ if (!socket_.get()) |
+ return PP_ERROR_FAILED; |
+ |
+ net::IPAddressNumber group; |
+ uint16 port; |
+ |
+ if (!NetAddressPrivateImpl::NetAddressToIPEndPoint(addr, &group, &port)) |
+ return PP_ERROR_ADDRESS_INVALID; |
+ |
bbudge
2015/02/19 21:27:04
We should add a TODO comment here to check for mul
etrunko
2015/02/23 22:09:10
Done.
|
+ return NetErrorToPepperError(socket_->JoinGroup(group)); |
+} |
+ |
+int32_t PepperUDPSocketMessageFilter::OnMsgLeaveGroup( |
+ const ppapi::host::HostMessageContext* context, |
+ const PP_NetAddress_Private& addr) { |
+ DCHECK_CURRENTLY_ON(BrowserThread::UI); |
+ DCHECK(context); |
+ |
+ if (!socket_.get()) |
+ return PP_ERROR_FAILED; |
+ |
+ net::IPAddressNumber group; |
+ uint16 port; |
+ |
+ if (!NetAddressPrivateImpl::NetAddressToIPEndPoint(addr, &group, &port)) |
+ return PP_ERROR_ADDRESS_INVALID; |
+ |
+ return NetErrorToPepperError(socket_->LeaveGroup(group)); |
+} |
+ |
void PepperUDPSocketMessageFilter::DoBind( |
const ppapi::host::ReplyMessageContext& context, |
const PP_NetAddress_Private& addr) { |
@@ -343,6 +424,20 @@ void PepperUDPSocketMessageFilter::DoBind( |
return; |
} |
} |
+ if (socket_options_ & SOCKET_OPTION_MULTICAST_LOOP) { |
+ int net_result = socket->SetMulticastLoopbackMode(true); |
+ if (net_result != net::OK) { |
+ SendBindError(context, NetErrorToPepperError(net_result)); |
+ return; |
+ } |
+ } |
+ if (socket_options_ & SOCKET_OPTION_MULTICAST_TTL) { |
+ int net_result = socket->SetMulticastInterface(multicast_ttl_); |
+ if (net_result != net::OK) { |
+ SendBindError(context, NetErrorToPepperError(net_result)); |
+ return; |
+ } |
+ } |
{ |
int net_result = socket->Bind(end_point); |