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_tcp_socket_message_filter. h" | 5 #include "content/browser/renderer_host/pepper/pepper_tcp_socket_message_filter. h" |
| 6 | 6 |
| 7 #include <cstring> | 7 #include <cstring> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 56 : version_(version), | 56 : version_(version), |
| 57 external_plugin_(host->external_plugin()), | 57 external_plugin_(host->external_plugin()), |
| 58 render_process_id_(0), | 58 render_process_id_(0), |
| 59 render_frame_id_(0), | 59 render_frame_id_(0), |
| 60 ppapi_host_(host->GetPpapiHost()), | 60 ppapi_host_(host->GetPpapiHost()), |
| 61 factory_(factory), | 61 factory_(factory), |
| 62 instance_(instance), | 62 instance_(instance), |
| 63 state_(TCPSocketState::INITIAL), | 63 state_(TCPSocketState::INITIAL), |
| 64 end_of_file_reached_(false), | 64 end_of_file_reached_(false), |
| 65 bind_input_addr_(NetAddressPrivateImpl::kInvalidNetAddress), | 65 bind_input_addr_(NetAddressPrivateImpl::kInvalidNetAddress), |
| 66 socket_options_(SOCKET_OPTION_NODELAY), | |
| 66 address_index_(0), | 67 address_index_(0), |
| 67 socket_(new net::TCPSocket(NULL, net::NetLog::Source())), | 68 socket_(new net::TCPSocket(NULL, net::NetLog::Source())), |
| 68 ssl_context_helper_(host->ssl_context_helper()), | 69 ssl_context_helper_(host->ssl_context_helper()), |
| 69 pending_accept_(false) { | 70 pending_accept_(false) { |
| 70 DCHECK(host); | 71 DCHECK(host); |
| 71 ++g_num_instances; | 72 ++g_num_instances; |
| 72 if (!host->GetRenderFrameIDsForInstance( | 73 if (!host->GetRenderFrameIDsForInstance( |
| 73 instance, &render_process_id_, &render_frame_id_)) { | 74 instance, &render_process_id_, &render_frame_id_)) { |
| 74 NOTREACHED(); | 75 NOTREACHED(); |
| 75 } | 76 } |
| 76 } | 77 } |
| 77 | 78 |
| 78 PepperTCPSocketMessageFilter::PepperTCPSocketMessageFilter( | 79 PepperTCPSocketMessageFilter::PepperTCPSocketMessageFilter( |
| 79 BrowserPpapiHostImpl* host, | 80 BrowserPpapiHostImpl* host, |
| 80 PP_Instance instance, | 81 PP_Instance instance, |
| 81 TCPSocketVersion version, | 82 TCPSocketVersion version, |
| 82 scoped_ptr<net::TCPSocket> socket) | 83 scoped_ptr<net::TCPSocket> socket) |
| 83 : version_(version), | 84 : version_(version), |
| 84 external_plugin_(host->external_plugin()), | 85 external_plugin_(host->external_plugin()), |
| 85 render_process_id_(0), | 86 render_process_id_(0), |
| 86 render_frame_id_(0), | 87 render_frame_id_(0), |
| 87 ppapi_host_(host->GetPpapiHost()), | 88 ppapi_host_(host->GetPpapiHost()), |
| 88 factory_(NULL), | 89 factory_(NULL), |
| 89 instance_(instance), | 90 instance_(instance), |
| 90 state_(TCPSocketState::CONNECTED), | 91 state_(TCPSocketState::CONNECTED), |
| 91 end_of_file_reached_(false), | 92 end_of_file_reached_(false), |
| 92 bind_input_addr_(NetAddressPrivateImpl::kInvalidNetAddress), | 93 bind_input_addr_(NetAddressPrivateImpl::kInvalidNetAddress), |
| 94 socket_options_(SOCKET_OPTION_NODELAY), | |
| 93 address_index_(0), | 95 address_index_(0), |
| 94 socket_(socket.Pass()), | 96 socket_(socket.Pass()), |
| 95 ssl_context_helper_(host->ssl_context_helper()), | 97 ssl_context_helper_(host->ssl_context_helper()), |
| 96 pending_accept_(false) { | 98 pending_accept_(false) { |
| 97 DCHECK(host); | 99 DCHECK(host); |
| 98 DCHECK_NE(version, ppapi::TCP_SOCKET_VERSION_1_0); | 100 DCHECK_NE(version, ppapi::TCP_SOCKET_VERSION_1_0); |
| 99 | 101 |
| 100 ++g_num_instances; | 102 ++g_num_instances; |
| 101 if (!host->GetRenderFrameIDsForInstance( | 103 if (!host->GetRenderFrameIDsForInstance( |
| 102 instance, &render_process_id_, &render_frame_id_)) { | 104 instance, &render_process_id_, &render_frame_id_)) { |
| (...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 449 } | 451 } |
| 450 | 452 |
| 451 int32_t PepperTCPSocketMessageFilter::OnMsgSetOption( | 453 int32_t PepperTCPSocketMessageFilter::OnMsgSetOption( |
| 452 const ppapi::host::HostMessageContext* context, | 454 const ppapi::host::HostMessageContext* context, |
| 453 PP_TCPSocket_Option name, | 455 PP_TCPSocket_Option name, |
| 454 const ppapi::SocketOptionData& value) { | 456 const ppapi::SocketOptionData& value) { |
| 455 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 457 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 456 | 458 |
| 457 switch (name) { | 459 switch (name) { |
| 458 case PP_TCPSOCKET_OPTION_NO_DELAY: { | 460 case PP_TCPSOCKET_OPTION_NO_DELAY: { |
| 459 if (state_.state() != TCPSocketState::CONNECTED) | |
| 460 return PP_ERROR_FAILED; | |
| 461 | |
| 462 bool boolean_value = false; | 461 bool boolean_value = false; |
| 463 if (!value.GetBool(&boolean_value)) | 462 if (!value.GetBool(&boolean_value)) |
| 464 return PP_ERROR_BADARGUMENT; | 463 return PP_ERROR_BADARGUMENT; |
| 465 return socket_->SetNoDelay(boolean_value) ? PP_OK : PP_ERROR_FAILED; | 464 if (state_.state() == TCPSocketState::CONNECTED) |
| 465 return socket_->SetNoDelay(boolean_value) ? PP_OK : PP_ERROR_FAILED; | |
| 466 | |
| 467 if (boolean_value) { | |
| 468 socket_options_ |= SOCKET_OPTION_NODELAY; | |
| 469 } else { | |
| 470 socket_options_ &= ~SOCKET_OPTION_NODELAY; | |
| 471 } | |
| 472 return PP_OK; | |
| 466 } | 473 } |
| 467 case PP_TCPSOCKET_OPTION_SEND_BUFFER_SIZE: | 474 case PP_TCPSOCKET_OPTION_SEND_BUFFER_SIZE: |
| 468 case PP_TCPSOCKET_OPTION_RECV_BUFFER_SIZE: { | 475 case PP_TCPSOCKET_OPTION_RECV_BUFFER_SIZE: { |
| 469 if (state_.state() != TCPSocketState::CONNECTED) | |
| 470 return PP_ERROR_FAILED; | |
| 471 | |
| 472 int32_t integer_value = 0; | 476 int32_t integer_value = 0; |
| 473 if (!value.GetInt32(&integer_value) || integer_value <= 0) | 477 if (!value.GetInt32(&integer_value) || integer_value <= 0) |
| 474 return PP_ERROR_BADARGUMENT; | 478 return PP_ERROR_BADARGUMENT; |
| 475 | 479 |
| 476 int net_result = net::ERR_UNEXPECTED; | |
| 477 if (name == PP_TCPSOCKET_OPTION_SEND_BUFFER_SIZE) { | 480 if (name == PP_TCPSOCKET_OPTION_SEND_BUFFER_SIZE) { |
| 478 if (integer_value > TCPSocketResourceBase::kMaxSendBufferSize) | 481 if (integer_value > TCPSocketResourceBase::kMaxSendBufferSize) |
| 479 return PP_ERROR_BADARGUMENT; | 482 return PP_ERROR_BADARGUMENT; |
| 480 net_result = socket_->SetSendBufferSize(integer_value); | 483 if (state_.state() == TCPSocketState::CONNECTED) { |
| 484 return NetErrorToPepperError( | |
| 485 socket_->SetSendBufferSize(integer_value)); | |
| 486 } | |
| 487 socket_options_ |= SOCKET_OPTION_SNDBUF_SIZE; | |
| 488 sndbuf_size_ = integer_value; | |
| 489 return PP_OK; | |
| 481 } else { | 490 } else { |
| 482 if (integer_value > TCPSocketResourceBase::kMaxReceiveBufferSize) | 491 if (integer_value > TCPSocketResourceBase::kMaxReceiveBufferSize) |
| 483 return PP_ERROR_BADARGUMENT; | 492 return PP_ERROR_BADARGUMENT; |
| 484 net_result = socket_->SetReceiveBufferSize(integer_value); | 493 if (state_.state() == TCPSocketState::CONNECTED) { |
| 494 return NetErrorToPepperError( | |
| 495 socket_->SetReceiveBufferSize(integer_value)); | |
| 496 } | |
| 497 socket_options_ |= SOCKET_OPTION_RCVBUF_SIZE; | |
| 498 rcvbuf_size_ = integer_value; | |
| 499 return PP_OK; | |
| 485 } | 500 } |
| 486 // TODO(wtc): Add error mapping code. | |
| 487 return (net_result == net::OK) ? PP_OK : PP_ERROR_FAILED; | |
| 488 } | 501 } |
| 489 default: { | 502 default: { |
| 490 NOTREACHED(); | 503 NOTREACHED(); |
| 491 return PP_ERROR_BADARGUMENT; | 504 return PP_ERROR_BADARGUMENT; |
| 492 } | 505 } |
| 493 } | 506 } |
| 494 } | 507 } |
| 495 | 508 |
| 496 void PepperTCPSocketMessageFilter::DoBind( | 509 void PepperTCPSocketMessageFilter::DoBind( |
| 497 const ppapi::host::ReplyMessageContext& context, | 510 const ppapi::host::ReplyMessageContext& context, |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 742 &local_addr) || | 755 &local_addr) || |
| 743 !NetAddressPrivateImpl::IPEndPointToNetAddress( | 756 !NetAddressPrivateImpl::IPEndPointToNetAddress( |
| 744 ip_end_point_remote.address(), | 757 ip_end_point_remote.address(), |
| 745 ip_end_point_remote.port(), | 758 ip_end_point_remote.port(), |
| 746 &remote_addr)) { | 759 &remote_addr)) { |
| 747 pp_result = PP_ERROR_ADDRESS_INVALID; | 760 pp_result = PP_ERROR_ADDRESS_INVALID; |
| 748 break; | 761 break; |
| 749 } | 762 } |
| 750 | 763 |
| 751 socket_->SetDefaultOptionsForClient(); | 764 socket_->SetDefaultOptionsForClient(); |
| 765 // NODELAY is set by SetDefaultOptionsForClient(). | |
| 766 if (!(socket_options_ & SOCKET_OPTION_NODELAY)) { | |
| 767 pp_result = NetErrorToPepperError(socket_->SetNoDelay(false)); | |
| 768 if (pp_result != PP_OK) | |
| 769 break; | |
| 770 } | |
| 771 if (socket_options_ & SOCKET_OPTION_RCVBUF_SIZE) { | |
| 772 pp_result = NetErrorToPepperError( | |
| 773 socket_->SetReceiveBufferSize(rcvbuf_size_)); | |
| 774 if (pp_result != PP_OK) | |
| 775 break; | |
| 776 } | |
| 777 if (socket_options_ & SOCKET_OPTION_SNDBUF_SIZE) { | |
| 778 pp_result = NetErrorToPepperError( | |
| 779 socket_->SetSendBufferSize(sndbuf_size_)); | |
| 780 if (pp_result != PP_OK) | |
| 781 break; | |
| 782 } | |
| 783 socket_options_ = SOCKET_OPTION_NODELAY; | |
| 752 SendConnectReply(context, PP_OK, local_addr, remote_addr); | 784 SendConnectReply(context, PP_OK, local_addr, remote_addr); |
| 753 state_.CompletePendingTransition(true); | 785 state_.CompletePendingTransition(true); |
| 754 return; | 786 return; |
| 755 } while (false); | 787 } while (false); |
| 756 | 788 |
| 757 if (version_ == ppapi::TCP_SOCKET_VERSION_1_1_OR_ABOVE) { | 789 if (version_ == ppapi::TCP_SOCKET_VERSION_1_1_OR_ABOVE) { |
| 758 DCHECK_EQ(1u, address_list_.size()); | 790 DCHECK_EQ(1u, address_list_.size()); |
| 759 | 791 |
| 760 SendConnectError(context, pp_result); | 792 SendConnectError(context, pp_result); |
|
jar (doing other things)
2014/11/04 22:51:08
What are the list of previously expectable error c
hidehiko
2014/11/05 12:48:29
IIUC, it is not managed, at least not-documented.
| |
| 761 state_.CompletePendingTransition(false); | 793 state_.CompletePendingTransition(false); |
| 762 } else { | 794 } else { |
| 763 // We have to recreate |socket_| because it doesn't allow a second connect | 795 // We have to recreate |socket_| because it doesn't allow a second connect |
| 764 // attempt. We won't lose any state such as bound address or set options, | 796 // attempt. We won't lose any state such as bound address or set options, |
| 765 // because in the private or v1.0 API, connect must be the first operation. | 797 // because in the private or v1.0 API, connect must be the first operation. |
|
jar (doing other things)
2014/11/04 22:51:09
This comment appears to be broken by this change.
hidehiko
2014/11/05 12:48:29
I think this is still correct comment? Could you k
| |
| 766 socket_.reset(new net::TCPSocket(NULL, net::NetLog::Source())); | 798 socket_.reset(new net::TCPSocket(NULL, net::NetLog::Source())); |
| 767 | 799 |
| 768 if (address_index_ + 1 < address_list_.size()) { | 800 if (address_index_ + 1 < address_list_.size()) { |
| 769 DCHECK_EQ(version_, ppapi::TCP_SOCKET_VERSION_PRIVATE); | 801 DCHECK_EQ(version_, ppapi::TCP_SOCKET_VERSION_PRIVATE); |
| 770 address_index_++; | 802 address_index_++; |
| 771 StartConnect(context); | 803 StartConnect(context); |
| 772 } else { | 804 } else { |
| 773 SendConnectError(context, pp_result); | 805 SendConnectError(context, pp_result); |
| 774 // In order to maintain backward compatibility, allow further attempts to | 806 // In order to maintain backward compatibility, allow further attempts to |
| 775 // connect the socket. | 807 // connect the socket. |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 993 const ppapi::host::ReplyMessageContext& context, | 1025 const ppapi::host::ReplyMessageContext& context, |
| 994 int32_t pp_error) { | 1026 int32_t pp_error) { |
| 995 SendAcceptReply(context, | 1027 SendAcceptReply(context, |
| 996 pp_error, | 1028 pp_error, |
| 997 0, | 1029 0, |
| 998 NetAddressPrivateImpl::kInvalidNetAddress, | 1030 NetAddressPrivateImpl::kInvalidNetAddress, |
| 999 NetAddressPrivateImpl::kInvalidNetAddress); | 1031 NetAddressPrivateImpl::kInvalidNetAddress); |
| 1000 } | 1032 } |
| 1001 | 1033 |
| 1002 } // namespace content | 1034 } // namespace content |
| OLD | NEW |