Chromium Code Reviews| Index: content/browser/renderer_host/pepper_message_filter.cc |
| diff --git a/content/browser/renderer_host/pepper_message_filter.cc b/content/browser/renderer_host/pepper_message_filter.cc |
| index eaac07bdcc487a4adf4ca4b95aba2ae61b492a01..43b0743b753e02d4f47c1e2c937702657c57c027 100644 |
| --- a/content/browser/renderer_host/pepper_message_filter.cc |
| +++ b/content/browser/renderer_host/pepper_message_filter.cc |
| @@ -1,4 +1,4 @@ |
| -// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| @@ -14,6 +14,7 @@ |
| #include "base/values.h" |
| #include "content/browser/font_list_async.h" |
| #include "content/browser/resource_context.h" |
| +#include "content/browser/renderer_host/pepper_tcp_server_socket.h" |
| #include "content/browser/renderer_host/pepper_tcp_socket.h" |
| #include "content/browser/renderer_host/pepper_udp_socket.h" |
| #include "content/browser/renderer_host/render_process_host_impl.h" |
| @@ -95,6 +96,16 @@ bool PepperMessageFilter::OnMessageReceived(const IPC::Message& msg, |
| IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBUDPSocket_SendTo, OnUDPSendTo) |
| IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBUDPSocket_Close, OnUDPClose) |
| + // TCP Server messages. |
| + IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBTCPServerSocket_Initialize, |
| + OnTCPServerInitialize) |
| + IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBTCPServerSocket_Listen, |
| + OnTCPServerListen) |
| + IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBTCPServerSocket_Accept, |
| + OnTCPServerAccept) |
| + IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBTCPServerSocket_StopListening, |
| + OnTCPServerStopListening) |
| + |
| IPC_MESSAGE_UNHANDLED(handled = false) |
| IPC_END_MESSAGE_MAP_EX() |
| return handled; |
| @@ -476,6 +487,83 @@ void PepperMessageFilter::OnUDPClose(uint32 socket_id) { |
| udp_sockets_.erase(iter); |
| } |
| +void PepperMessageFilter::OnTCPServerInitialize(int32 routing_id, |
| + uint32 plugin_dispatcher_id) { |
| + uint32 tcp_server_socket_id = GenerateSocketID(); |
| + if (tcp_server_socket_id != kInvalidSocketID) { |
| + PepperTCPServerSocket* socket = new PepperTCPServerSocket( |
| + this, routing_id, plugin_dispatcher_id, tcp_server_socket_id); |
| + socket->SetAcceptCallback(base::Bind( |
| + &PepperMessageFilter::OnTCPServerSocketAcceptComplete, |
| + base::Unretained(this))); |
| + |
| + tcp_server_sockets_[tcp_server_socket_id] = |
| + linked_ptr<PepperTCPServerSocket>(socket); |
| + } |
| + Send(new PpapiMsg_PPBTCPServerSocket_InitializeACK(routing_id, |
| + plugin_dispatcher_id, |
| + tcp_server_socket_id)); |
| +} |
| + |
| +void PepperMessageFilter::OnTCPServerListen(uint32 socket_id, |
| + const PP_NetAddress_Private& addr, |
| + int32_t backlog) { |
| + TCPServerSocketMap::iterator iter = tcp_server_sockets_.find(socket_id); |
| + if (iter == tcp_server_sockets_.end()) { |
| + NOTREACHED(); |
| + return; |
| + } |
| + iter->second->Listen(addr, backlog); |
| +} |
| + |
| +void PepperMessageFilter::OnTCPServerAccept(uint32 socket_id) { |
| + TCPServerSocketMap::iterator iter = tcp_server_sockets_.find(socket_id); |
| + if (iter == tcp_server_sockets_.end()) { |
| + NOTREACHED(); |
| + return; |
| + } |
| + iter->second->Accept(); |
| +} |
| + |
| +void PepperMessageFilter::OnTCPServerSocketAcceptComplete( |
| + int32 routing_id, |
| + uint32 plugin_dispatcher_id, |
| + uint32 tcp_server_socket_id, |
| + net::StreamSocket* socket, |
| + PP_NetAddress_Private local_addr, |
| + PP_NetAddress_Private remote_addr) { |
| + uint32 tcp_socket_id = GenerateSocketID(); |
| + if (tcp_socket_id == kInvalidSocketID) |
| + return; |
|
yzshen1
2012/02/09 02:31:50
|socket| is leaked here.
ygorshenin1
2012/02/09 15:00:10
Done.
|
| + |
| + tcp_sockets_[tcp_socket_id] = linked_ptr<PepperTCPSocket>( |
| + new PepperTCPSocket(this, |
| + routing_id, |
| + plugin_dispatcher_id, |
| + tcp_socket_id, |
| + socket)); |
| + |
| + Send(new PpapiMsg_PPBTCPServerSocket_AcceptACK(routing_id, |
| + plugin_dispatcher_id, |
| + tcp_server_socket_id, |
| + tcp_socket_id, |
| + local_addr, |
| + remote_addr)); |
| +} |
| + |
| +void PepperMessageFilter::OnTCPServerStopListening(uint32 socket_id) { |
| + TCPServerSocketMap::iterator iter = tcp_server_sockets_.find(socket_id); |
| + if (iter == tcp_server_sockets_.end()) { |
| + NOTREACHED(); |
| + return; |
| + } |
| + |
| + // Destroy the TCPServerSocket instance will cancel any pending |
| + // completion callback. From this point on, there won't be any |
| + // messages associated with this socket sent to the plugin side. |
| + tcp_server_sockets_.erase(iter); |
| +} |
| + |
| void PepperMessageFilter::GetFontFamiliesComplete( |
| IPC::Message* reply_msg, |
| scoped_refptr<content::FontListResult> result) { |
| @@ -514,8 +602,10 @@ uint32 PepperMessageFilter::GenerateSocketID() { |
| // PepperSocketMessageHandler object, because for each plugin or renderer |
| // process, there is at most one PepperMessageFilter (in other words, at most |
| // one PepperSocketMessageHandler) talking to it. |
| - if (tcp_sockets_.size() + udp_sockets_.size() >= kMaxSocketsAllowed) |
| + if (tcp_sockets_.size() + udp_sockets_.size() + tcp_server_sockets_.size() >= |
| + kMaxSocketsAllowed) { |
| return kInvalidSocketID; |
| + } |
| uint32 socket_id = kInvalidSocketID; |
| do { |
| @@ -524,7 +614,8 @@ uint32 PepperMessageFilter::GenerateSocketID() { |
| socket_id = next_socket_id_++; |
| } while (socket_id == kInvalidSocketID || |
| tcp_sockets_.find(socket_id) != tcp_sockets_.end() || |
| - udp_sockets_.find(socket_id) != udp_sockets_.end()); |
| + udp_sockets_.find(socket_id) != udp_sockets_.end() || |
| + tcp_server_sockets_.find(socket_id) != tcp_server_sockets_.end()); |
| return socket_id; |
| } |