Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/browser/renderer_host/pepper/pepper_udp_socket_message_filter. h" | 5 #include "content/browser/renderer_host/pepper/pepper_udp_socket_message_filter. h" |
| 6 | 6 |
| 7 #include <cstring> | 7 #include <cstring> |
| 8 | 8 |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 53 PepperUDPSocketMessageFilter::PendingSend::~PendingSend() { | 53 PepperUDPSocketMessageFilter::PendingSend::~PendingSend() { |
| 54 } | 54 } |
| 55 | 55 |
| 56 PepperUDPSocketMessageFilter::PepperUDPSocketMessageFilter( | 56 PepperUDPSocketMessageFilter::PepperUDPSocketMessageFilter( |
| 57 BrowserPpapiHostImpl* host, | 57 BrowserPpapiHostImpl* host, |
| 58 PP_Instance instance, | 58 PP_Instance instance, |
| 59 bool private_api) | 59 bool private_api) |
| 60 : socket_options_(0), | 60 : socket_options_(0), |
| 61 rcvbuf_size_(0), | 61 rcvbuf_size_(0), |
| 62 sndbuf_size_(0), | 62 sndbuf_size_(0), |
| 63 multicast_ttl_(0), | |
| 63 closed_(false), | 64 closed_(false), |
| 64 remaining_recv_slots_(UDPSocketResourceBase::kPluginReceiveBufferSlots), | 65 remaining_recv_slots_(UDPSocketResourceBase::kPluginReceiveBufferSlots), |
| 65 external_plugin_(host->external_plugin()), | 66 external_plugin_(host->external_plugin()), |
| 66 private_api_(private_api), | 67 private_api_(private_api), |
| 67 render_process_id_(0), | 68 render_process_id_(0), |
| 68 render_frame_id_(0) { | 69 render_frame_id_(0) { |
| 69 ++g_num_instances; | 70 ++g_num_instances; |
| 70 DCHECK(host); | 71 DCHECK(host); |
| 71 | 72 |
| 72 if (!host->GetRenderFrameIDsForInstance( | 73 if (!host->GetRenderFrameIDsForInstance( |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 88 scoped_refptr<base::TaskRunner> | 89 scoped_refptr<base::TaskRunner> |
| 89 PepperUDPSocketMessageFilter::OverrideTaskRunnerForMessage( | 90 PepperUDPSocketMessageFilter::OverrideTaskRunnerForMessage( |
| 90 const IPC::Message& message) { | 91 const IPC::Message& message) { |
| 91 switch (message.type()) { | 92 switch (message.type()) { |
| 92 case PpapiHostMsg_UDPSocket_SetOption::ID: | 93 case PpapiHostMsg_UDPSocket_SetOption::ID: |
| 93 case PpapiHostMsg_UDPSocket_Close::ID: | 94 case PpapiHostMsg_UDPSocket_Close::ID: |
| 94 case PpapiHostMsg_UDPSocket_RecvSlotAvailable::ID: | 95 case PpapiHostMsg_UDPSocket_RecvSlotAvailable::ID: |
| 95 return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO); | 96 return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO); |
| 96 case PpapiHostMsg_UDPSocket_Bind::ID: | 97 case PpapiHostMsg_UDPSocket_Bind::ID: |
| 97 case PpapiHostMsg_UDPSocket_SendTo::ID: | 98 case PpapiHostMsg_UDPSocket_SendTo::ID: |
| 99 case PpapiHostMsg_UDPSocket_JoinGroup::ID: | |
| 100 case PpapiHostMsg_UDPSocket_LeaveGroup::ID: | |
| 98 return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI); | 101 return BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI); |
| 99 } | 102 } |
| 100 return NULL; | 103 return NULL; |
| 101 } | 104 } |
| 102 | 105 |
| 103 int32_t PepperUDPSocketMessageFilter::OnResourceMessageReceived( | 106 int32_t PepperUDPSocketMessageFilter::OnResourceMessageReceived( |
| 104 const IPC::Message& msg, | 107 const IPC::Message& msg, |
| 105 ppapi::host::HostMessageContext* context) { | 108 ppapi::host::HostMessageContext* context) { |
| 106 PPAPI_BEGIN_MESSAGE_MAP(PepperUDPSocketMessageFilter, msg) | 109 PPAPI_BEGIN_MESSAGE_MAP(PepperUDPSocketMessageFilter, msg) |
| 107 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_UDPSocket_SetOption, | 110 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_UDPSocket_SetOption, |
| 108 OnMsgSetOption) | 111 OnMsgSetOption) |
| 109 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_UDPSocket_Bind, OnMsgBind) | 112 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_UDPSocket_Bind, OnMsgBind) |
| 110 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_UDPSocket_SendTo, | 113 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_UDPSocket_SendTo, |
| 111 OnMsgSendTo) | 114 OnMsgSendTo) |
| 112 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(PpapiHostMsg_UDPSocket_Close, | 115 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(PpapiHostMsg_UDPSocket_Close, |
| 113 OnMsgClose) | 116 OnMsgClose) |
| 114 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0( | 117 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0( |
| 115 PpapiHostMsg_UDPSocket_RecvSlotAvailable, OnMsgRecvSlotAvailable) | 118 PpapiHostMsg_UDPSocket_RecvSlotAvailable, OnMsgRecvSlotAvailable) |
| 119 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_UDPSocket_JoinGroup, | |
| 120 OnMsgJoinGroup) | |
| 121 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_UDPSocket_LeaveGroup, | |
| 122 OnMsgLeaveGroup) | |
| 116 PPAPI_END_MESSAGE_MAP() | 123 PPAPI_END_MESSAGE_MAP() |
| 117 return PP_ERROR_FAILED; | 124 return PP_ERROR_FAILED; |
| 118 } | 125 } |
| 119 | 126 |
| 120 int32_t PepperUDPSocketMessageFilter::OnMsgSetOption( | 127 int32_t PepperUDPSocketMessageFilter::OnMsgSetOption( |
| 121 const ppapi::host::HostMessageContext* context, | 128 const ppapi::host::HostMessageContext* context, |
| 122 PP_UDPSocket_Option name, | 129 PP_UDPSocket_Option name, |
| 123 const ppapi::SocketOptionData& value) { | 130 const ppapi::SocketOptionData& value) { |
| 124 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 131 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 125 | 132 |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 144 } else { | 151 } else { |
| 145 socket_options_ &= ~SOCKET_OPTION_ADDRESS_REUSE; | 152 socket_options_ &= ~SOCKET_OPTION_ADDRESS_REUSE; |
| 146 } | 153 } |
| 147 return PP_OK; | 154 return PP_OK; |
| 148 } | 155 } |
| 149 case PP_UDPSOCKET_OPTION_BROADCAST: { | 156 case PP_UDPSOCKET_OPTION_BROADCAST: { |
| 150 bool boolean_value = false; | 157 bool boolean_value = false; |
| 151 if (!value.GetBool(&boolean_value)) | 158 if (!value.GetBool(&boolean_value)) |
| 152 return PP_ERROR_BADARGUMENT; | 159 return PP_ERROR_BADARGUMENT; |
| 153 | 160 |
| 154 // If the socket is already connected, proxy the value to TCPSocket. | 161 // If the socket is already bound, proxy the value to UDPSocket. |
| 155 if (socket_.get()) | 162 if (socket_.get()) |
| 156 return NetErrorToPepperError(socket_->SetBroadcast(boolean_value)); | 163 return NetErrorToPepperError(socket_->SetBroadcast(boolean_value)); |
| 157 | 164 |
| 158 // UDPSocket instance is not yet created, so remember the value here. | 165 // UDPSocket instance is not yet created, so remember the value here. |
| 159 if (boolean_value) { | 166 if (boolean_value) { |
| 160 socket_options_ |= SOCKET_OPTION_BROADCAST; | 167 socket_options_ |= SOCKET_OPTION_BROADCAST; |
| 161 } else { | 168 } else { |
| 162 socket_options_ &= ~SOCKET_OPTION_BROADCAST; | 169 socket_options_ &= ~SOCKET_OPTION_BROADCAST; |
| 163 } | 170 } |
| 164 return PP_OK; | 171 return PP_OK; |
| 165 } | 172 } |
| 166 case PP_UDPSOCKET_OPTION_SEND_BUFFER_SIZE: { | 173 case PP_UDPSOCKET_OPTION_SEND_BUFFER_SIZE: { |
| 167 int32_t integer_value = 0; | 174 int32_t integer_value = 0; |
| 168 if (!value.GetInt32(&integer_value) || | 175 if (!value.GetInt32(&integer_value) || |
| 169 integer_value <= 0 || | 176 integer_value <= 0 || |
| 170 integer_value > | 177 integer_value > |
| 171 ppapi::proxy::UDPSocketResourceBase::kMaxSendBufferSize) | 178 ppapi::proxy::UDPSocketResourceBase::kMaxSendBufferSize) |
| 172 return PP_ERROR_BADARGUMENT; | 179 return PP_ERROR_BADARGUMENT; |
| 173 | 180 |
| 174 // If the socket is already connected, proxy the value to UDPSocket. | 181 // If the socket is already bound, proxy the value to UDPSocket. |
| 175 if (socket_.get()) { | 182 if (socket_.get()) { |
| 176 return NetErrorToPepperError( | 183 return NetErrorToPepperError( |
| 177 socket_->SetSendBufferSize(integer_value)); | 184 socket_->SetSendBufferSize(integer_value)); |
| 178 } | 185 } |
| 179 | 186 |
| 180 // UDPSocket instance is not yet created, so remember the value here. | 187 // UDPSocket instance is not yet created, so remember the value here. |
| 181 socket_options_ |= SOCKET_OPTION_SNDBUF_SIZE; | 188 socket_options_ |= SOCKET_OPTION_SNDBUF_SIZE; |
| 182 sndbuf_size_ = integer_value; | 189 sndbuf_size_ = integer_value; |
| 183 return PP_OK; | 190 return PP_OK; |
| 184 } | 191 } |
| 185 case PP_UDPSOCKET_OPTION_RECV_BUFFER_SIZE: { | 192 case PP_UDPSOCKET_OPTION_RECV_BUFFER_SIZE: { |
| 186 int32_t integer_value = 0; | 193 int32_t integer_value = 0; |
| 187 if (!value.GetInt32(&integer_value) || | 194 if (!value.GetInt32(&integer_value) || |
| 188 integer_value <= 0 || | 195 integer_value <= 0 || |
| 189 integer_value > | 196 integer_value > |
| 190 ppapi::proxy::UDPSocketResourceBase::kMaxReceiveBufferSize) | 197 ppapi::proxy::UDPSocketResourceBase::kMaxReceiveBufferSize) |
| 191 return PP_ERROR_BADARGUMENT; | 198 return PP_ERROR_BADARGUMENT; |
| 192 | 199 |
| 193 // If the socket is already connected, proxy the value to UDPSocket. | 200 // If the socket is already bound, proxy the value to UDPSocket. |
| 194 if (socket_.get()) { | 201 if (socket_.get()) { |
| 195 return NetErrorToPepperError( | 202 return NetErrorToPepperError( |
| 196 socket_->SetReceiveBufferSize(integer_value)); | 203 socket_->SetReceiveBufferSize(integer_value)); |
| 197 } | 204 } |
| 198 | 205 |
| 199 // UDPSocket instance is not yet created, so remember the value here. | 206 // UDPSocket instance is not yet created, so remember the value here. |
| 200 socket_options_ |= SOCKET_OPTION_RCVBUF_SIZE; | 207 socket_options_ |= SOCKET_OPTION_RCVBUF_SIZE; |
| 201 rcvbuf_size_ = integer_value; | 208 rcvbuf_size_ = integer_value; |
| 202 return PP_OK; | 209 return PP_OK; |
| 203 } | 210 } |
| 211 case PP_UDPSOCKET_OPTION_MULTICAST_LOOP: { | |
| 212 bool boolean_value = false; | |
| 213 if (!value.GetBool(&boolean_value)) | |
| 214 return PP_ERROR_BADARGUMENT; | |
| 215 | |
| 216 // If the socket is already bound, proxy the value to UDPSocket. | |
| 217 if (socket_.get()) | |
|
dcheng
2015/03/05 15:34:49
No .get().
etrunko
2015/03/05 17:07:12
Done.
| |
| 218 return NetErrorToPepperError( | |
| 219 socket_->SetMulticastLoopbackMode(boolean_value)); | |
| 220 | |
| 221 // UDPSocket instance is not yet created, so remember the value here. | |
| 222 if (boolean_value) { | |
| 223 socket_options_ |= SOCKET_OPTION_MULTICAST_LOOP; | |
| 224 } else { | |
| 225 socket_options_ &= ~SOCKET_OPTION_MULTICAST_LOOP; | |
| 226 } | |
| 227 return PP_OK; | |
| 228 } | |
| 229 case PP_UDPSOCKET_OPTION_MULTICAST_TTL: { | |
| 230 int32_t integer_value = 0; | |
| 231 if (!value.GetInt32(&integer_value) || | |
| 232 integer_value < 0 || integer_value > 255) | |
| 233 return PP_ERROR_BADARGUMENT; | |
| 234 | |
| 235 // If the socket is already bound, proxy the value to UDPSocket. | |
| 236 if (socket_.get()) | |
|
dcheng
2015/03/05 15:34:49
Ditto.
etrunko
2015/03/05 17:07:12
Done.
| |
| 237 return NetErrorToPepperError( | |
| 238 socket_->SetMulticastTimeToLive(integer_value)); | |
| 239 | |
| 240 // UDPSocket instance is not yet created, so remember the value here. | |
| 241 socket_options_ |= SOCKET_OPTION_MULTICAST_TTL; | |
| 242 multicast_ttl_ = integer_value; | |
| 243 return PP_OK; | |
| 244 } | |
| 204 default: { | 245 default: { |
| 205 NOTREACHED(); | 246 NOTREACHED(); |
| 206 return PP_ERROR_BADARGUMENT; | 247 return PP_ERROR_BADARGUMENT; |
| 207 } | 248 } |
| 208 } | 249 } |
| 209 } | 250 } |
| 210 | 251 |
| 211 int32_t PepperUDPSocketMessageFilter::OnMsgBind( | 252 int32_t PepperUDPSocketMessageFilter::OnMsgBind( |
| 212 const ppapi::host::HostMessageContext* context, | 253 const ppapi::host::HostMessageContext* context, |
| 213 const PP_NetAddress_Private& addr) { | 254 const PP_NetAddress_Private& addr) { |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 279 } | 320 } |
| 280 | 321 |
| 281 if (!recvfrom_buffer_.get() && !closed_ && socket_.get()) { | 322 if (!recvfrom_buffer_.get() && !closed_ && socket_.get()) { |
| 282 DCHECK_EQ(1u, remaining_recv_slots_); | 323 DCHECK_EQ(1u, remaining_recv_slots_); |
| 283 DoRecvFrom(); | 324 DoRecvFrom(); |
| 284 } | 325 } |
| 285 | 326 |
| 286 return PP_OK; | 327 return PP_OK; |
| 287 } | 328 } |
| 288 | 329 |
| 330 int32_t PepperUDPSocketMessageFilter::OnMsgJoinGroup( | |
| 331 const ppapi::host::HostMessageContext* context, | |
| 332 const PP_NetAddress_Private& addr) { | |
| 333 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
| 334 | |
| 335 if (!socket_.get()) | |
|
dcheng
2015/03/05 15:34:49
Same for .get() here and elsewhere.
etrunko
2015/03/05 17:07:12
Is this to be changed all over this file? For exam
dcheng
2015/03/05 17:08:29
No, let's just change the ones that were added. No
| |
| 336 return PP_ERROR_FAILED; | |
| 337 | |
| 338 net::IPAddressNumber group; | |
| 339 uint16 port; | |
| 340 | |
| 341 if (!NetAddressPrivateImpl::NetAddressToIPEndPoint(addr, &group, &port)) | |
| 342 return PP_ERROR_ADDRESS_INVALID; | |
| 343 | |
| 344 // TODO(etrunko) Check that app has multicast permission. | |
|
dcheng
2015/03/05 15:34:49
Nit: TODO(etrunko): (missing a colon)
Also, this
bbudge
2015/03/05 16:42:55
This check must be added before the API can be mad
| |
| 345 return NetErrorToPepperError(socket_->JoinGroup(group)); | |
| 346 } | |
| 347 | |
| 348 int32_t PepperUDPSocketMessageFilter::OnMsgLeaveGroup( | |
| 349 const ppapi::host::HostMessageContext* context, | |
| 350 const PP_NetAddress_Private& addr) { | |
| 351 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
| 352 | |
| 353 if (!socket_.get()) | |
| 354 return PP_ERROR_FAILED; | |
| 355 | |
| 356 net::IPAddressNumber group; | |
| 357 uint16 port; | |
| 358 | |
| 359 if (!NetAddressPrivateImpl::NetAddressToIPEndPoint(addr, &group, &port)) | |
| 360 return PP_ERROR_ADDRESS_INVALID; | |
| 361 | |
| 362 return NetErrorToPepperError(socket_->LeaveGroup(group)); | |
| 363 } | |
| 364 | |
| 289 void PepperUDPSocketMessageFilter::DoBind( | 365 void PepperUDPSocketMessageFilter::DoBind( |
| 290 const ppapi::host::ReplyMessageContext& context, | 366 const ppapi::host::ReplyMessageContext& context, |
| 291 const PP_NetAddress_Private& addr) { | 367 const PP_NetAddress_Private& addr) { |
| 292 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 368 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 293 | 369 |
| 294 if (closed_ || socket_.get()) { | 370 if (closed_ || socket_.get()) { |
| 295 SendBindError(context, PP_ERROR_FAILED); | 371 SendBindError(context, PP_ERROR_FAILED); |
| 296 return; | 372 return; |
| 297 } | 373 } |
| 298 | 374 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 336 return; | 412 return; |
| 337 } | 413 } |
| 338 } | 414 } |
| 339 if (socket_options_ & SOCKET_OPTION_RCVBUF_SIZE) { | 415 if (socket_options_ & SOCKET_OPTION_RCVBUF_SIZE) { |
| 340 int net_result = socket->SetReceiveBufferSize(rcvbuf_size_); | 416 int net_result = socket->SetReceiveBufferSize(rcvbuf_size_); |
| 341 if (net_result != net::OK) { | 417 if (net_result != net::OK) { |
| 342 SendBindError(context, NetErrorToPepperError(net_result)); | 418 SendBindError(context, NetErrorToPepperError(net_result)); |
| 343 return; | 419 return; |
| 344 } | 420 } |
| 345 } | 421 } |
| 422 if (socket_options_ & SOCKET_OPTION_MULTICAST_LOOP) { | |
| 423 int net_result = socket->SetMulticastLoopbackMode(true); | |
| 424 if (net_result != net::OK) { | |
| 425 SendBindError(context, NetErrorToPepperError(net_result)); | |
| 426 return; | |
| 427 } | |
| 428 } | |
| 429 if (socket_options_ & SOCKET_OPTION_MULTICAST_TTL) { | |
| 430 int net_result = socket->SetMulticastInterface(multicast_ttl_); | |
| 431 if (net_result != net::OK) { | |
| 432 SendBindError(context, NetErrorToPepperError(net_result)); | |
| 433 return; | |
| 434 } | |
| 435 } | |
| 346 | 436 |
| 347 { | 437 { |
| 348 int net_result = socket->Bind(end_point); | 438 int net_result = socket->Bind(end_point); |
| 349 if (net_result != net::OK) { | 439 if (net_result != net::OK) { |
| 350 SendBindError(context, NetErrorToPepperError(net_result)); | 440 SendBindError(context, NetErrorToPepperError(net_result)); |
| 351 return; | 441 return; |
| 352 } | 442 } |
| 353 } | 443 } |
| 354 | 444 |
| 355 net::IPEndPoint bound_address; | 445 net::IPEndPoint bound_address; |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 564 NetAddressPrivateImpl::kInvalidNetAddress); | 654 NetAddressPrivateImpl::kInvalidNetAddress); |
| 565 } | 655 } |
| 566 | 656 |
| 567 void PepperUDPSocketMessageFilter::SendSendToError( | 657 void PepperUDPSocketMessageFilter::SendSendToError( |
| 568 const ppapi::host::ReplyMessageContext& context, | 658 const ppapi::host::ReplyMessageContext& context, |
| 569 int32_t result) { | 659 int32_t result) { |
| 570 SendSendToReply(context, result, 0); | 660 SendSendToReply(context, result, 0); |
| 571 } | 661 } |
| 572 | 662 |
| 573 } // namespace content | 663 } // namespace content |
| OLD | NEW |