Chromium Code Reviews| 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 26c0e44ee34f6277a36309c6dd4b5c2c73a0e4c1..92f75fdac531445121eaaefbb86837d8d2d45938 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 |
| @@ -28,9 +28,13 @@ |
| #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::thunk::EnterResource; |
| +using ppapi::thunk::PPB_NetAddress_API; |
| namespace { |
| @@ -46,6 +50,9 @@ PepperUDPSocketMessageFilter::PepperUDPSocketMessageFilter( |
| bool private_api) |
| : allow_address_reuse_(false), |
| allow_broadcast_(false), |
| + multicast_loop_(false), |
| + multicast_interface_(0), |
| + multicast_time_to_live_(0), |
| closed_(false), |
| remaining_recv_slots_( |
| ppapi::proxy::UDPSocketResourceBase::kPluginReceiveBufferSlots), |
| @@ -113,34 +120,59 @@ int32_t PepperUDPSocketMessageFilter::OnMsgSetOption( |
| if (closed_) |
| return PP_ERROR_FAILED; |
| + // Check if socket is expected to be bound or not according to the option |
| switch (name) { |
| case PP_UDPSOCKET_OPTION_ADDRESS_REUSE: |
| - case PP_UDPSOCKET_OPTION_BROADCAST: { |
| + case PP_UDPSOCKET_OPTION_BROADCAST: |
| + case PP_UDPSOCKET_OPTION_MULTICAST_LOOP: |
| + case PP_UDPSOCKET_OPTION_MULTICAST_TTL: |
| + case PP_UDPSOCKET_OPTION_MULTICAST_IF: { |
| if (socket_.get()) { |
| // They only take effect before the socket is bound. |
| return PP_ERROR_FAILED; |
| } |
| + break; |
| + } |
| + case PP_UDPSOCKET_OPTION_SEND_BUFFER_SIZE: |
| + case PP_UDPSOCKET_OPTION_RECV_BUFFER_SIZE: |
| + case PP_UDPSOCKET_OPTION_MULTICAST_JOIN: |
| + case PP_UDPSOCKET_OPTION_MULTICAST_LEAVE: { |
| + if (!socket_.get()) { |
| + // They only take effect after the socket is bound. |
| + return PP_ERROR_FAILED; |
| + } |
| + break; |
| + } |
| + } |
| + switch (name) { |
| + case PP_UDPSOCKET_OPTION_ADDRESS_REUSE: |
| + case PP_UDPSOCKET_OPTION_BROADCAST: |
| + case PP_UDPSOCKET_OPTION_MULTICAST_LOOP: { |
| bool boolean_value = false; |
| if (!value.GetBool(&boolean_value)) |
| return PP_ERROR_BADARGUMENT; |
| if (name == PP_UDPSOCKET_OPTION_ADDRESS_REUSE) |
| allow_address_reuse_ = boolean_value; |
| - else |
| + else if (name == PP_UDPSOCKET_OPTION_BROADCAST) |
| allow_broadcast_ = boolean_value; |
| + else if (name == PP_UDPSOCKET_OPTION_MULTICAST_LOOP) |
| + multicast_loop_ = boolean_value; |
| return PP_OK; |
| } |
| case PP_UDPSOCKET_OPTION_SEND_BUFFER_SIZE: |
| - case PP_UDPSOCKET_OPTION_RECV_BUFFER_SIZE: { |
| - if (!socket_.get()) { |
| - // They only take effect after the socket is bound. |
| - return PP_ERROR_FAILED; |
| - } |
| + case PP_UDPSOCKET_OPTION_RECV_BUFFER_SIZE: |
| + case PP_UDPSOCKET_OPTION_MULTICAST_IF: { |
| int32_t integer_value = 0; |
| if (!value.GetInt32(&integer_value) || integer_value <= 0) |
| return PP_ERROR_BADARGUMENT; |
| + if (name == PP_UDPSOCKET_OPTION_MULTICAST_IF) { |
| + multicast_interface_ = integer_value; |
| + return PP_OK; |
| + } |
| + |
| int net_result = net::ERR_UNEXPECTED; |
| if (name == PP_UDPSOCKET_OPTION_SEND_BUFFER_SIZE) { |
| if (integer_value > |
| @@ -158,6 +190,56 @@ int32_t PepperUDPSocketMessageFilter::OnMsgSetOption( |
| // TODO(wtc): Add error mapping code. |
| return (net_result == net::OK) ? PP_OK : PP_ERROR_FAILED; |
| } |
| + 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; |
| + |
| + multicast_time_to_live_ = integer_value; |
| + return PP_OK; |
| + } |
| + case PP_UDPSOCKET_OPTION_MULTICAST_JOIN: |
| + case PP_UDPSOCKET_OPTION_MULTICAST_LEAVE: { |
| + PP_Resource resource = 0; |
| + if (!value.GetInt32(&resource)) |
| + return PP_ERROR_BADARGUMENT; |
| + |
| + EnterResource<PPB_NetAddress_API> net_address_api(resource, true); |
| + if (net_address_api.failed()) |
| + return PP_ERROR_BADRESOURCE; |
| + |
| + PP_NetAddress_Private addr; |
| + PP_NetAddress_Family family = net_address_api.object()->GetFamily(); |
| + if (family == PP_NETADDRESS_FAMILY_IPV6) { |
| + PP_NetAddress_IPv4 v4; |
| + if (!net_address_api.object()->DescribeAsIPv4Address(&v4)) |
| + return PP_ERROR_ADDRESS_INVALID; |
| + NetAddressPrivateImpl::CreateNetAddressPrivateFromIPv4Address( |
| + v4, &addr); |
| + } |
| + else if (family == PP_NETADDRESS_FAMILY_IPV6) { |
|
ygorshenin1
2014/11/14 08:03:43
nit: joint lines #220 and #221.
etrunko
2014/11/17 17:45:10
Done.
|
| + PP_NetAddress_IPv6 v6; |
| + if (!net_address_api.object()->DescribeAsIPv6Address(&v6)) |
| + return PP_ERROR_ADDRESS_INVALID; |
| + NetAddressPrivateImpl::CreateNetAddressPrivateFromIPv6Address( |
| + v6, &addr); |
| + } |
| + else |
|
ygorshenin1
2014/11/14 08:03:43
nit: join lines #228 and #227 and wrap return stat
etrunko
2014/11/17 17:45:09
Done.
|
| + return PP_ERROR_BADARGUMENT; |
| + |
| + net::IPAddressNumber group; |
| + int port; |
| + if (!NetAddressPrivateImpl::NetAddressToIPEndPoint(addr, &group, &port)) |
| + return PP_ERROR_ADDRESS_INVALID; |
| + |
| + int net_result = net::ERR_UNEXPECTED; |
| + if (name == PP_UDPSOCKET_OPTION_MULTICAST_JOIN) |
| + net_result = socket_->JoinGroup(group); |
| + else if (name == PP_UDPSOCKET_OPTION_MULTICAST_LEAVE) |
| + net_result = socket_->LeaveGroup(group); |
| + return (net_result == net::OK) ? PP_OK : PP_ERROR_FAILED; |
| + } |
| default: { |
| NOTREACHED(); |
| return PP_ERROR_BADARGUMENT; |
| @@ -267,6 +349,12 @@ void PepperUDPSocketMessageFilter::DoBind( |
| socket->AllowAddressReuse(); |
| if (allow_broadcast_) |
| socket->AllowBroadcast(); |
| + if (multicast_loop_) |
| + socket->SetMulticastLoopbackMode(multicast_loop_); |
| + if (multicast_interface_) |
| + socket->SetMulticastInterface(multicast_interface_); |
| + if (multicast_time_to_live_) |
| + socket->SetMulticastTimeToLive(multicast_time_to_live_); |
| int32_t pp_result = |
| NetErrorToPepperError(socket->Listen(net::IPEndPoint(address, port))); |
| @@ -291,6 +379,9 @@ void PepperUDPSocketMessageFilter::DoBind( |
| allow_address_reuse_ = false; |
| allow_broadcast_ = false; |
| + multicast_loop_ = false; |
| + multicast_interface_ = 0; |
| + multicast_time_to_live_ = 0; |
| socket_.swap(socket); |
| SendBindReply(context, PP_OK, net_address); |