OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "ppapi/proxy/ppb_flash_tcp_socket_proxy.h" | 5 #include "ppapi/proxy/ppb_flash_tcp_socket_proxy.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <cstring> | 8 #include <cstring> |
9 #include <map> | 9 #include <map> |
10 | 10 |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
13 #include "base/scoped_ptr.h" | 13 #include "base/scoped_ptr.h" |
14 #include "base/task.h" | 14 #include "base/task.h" |
15 #include "ppapi/c/pp_errors.h" | 15 #include "ppapi/c/pp_errors.h" |
16 #include "ppapi/proxy/plugin_dispatcher.h" | 16 #include "ppapi/proxy/plugin_dispatcher.h" |
17 #include "ppapi/proxy/plugin_resource.h" | |
18 #include "ppapi/proxy/plugin_resource_tracker.h" | 17 #include "ppapi/proxy/plugin_resource_tracker.h" |
19 #include "ppapi/proxy/ppapi_messages.h" | 18 #include "ppapi/proxy/ppapi_messages.h" |
| 19 #include "ppapi/shared_impl/resource.h" |
20 #include "ppapi/thunk/ppb_flash_tcp_socket_api.h" | 20 #include "ppapi/thunk/ppb_flash_tcp_socket_api.h" |
21 #include "ppapi/thunk/thunk.h" | 21 #include "ppapi/thunk/thunk.h" |
22 | 22 |
23 using ppapi::HostResource; | 23 using ppapi::HostResource; |
| 24 using ppapi::Resource; |
24 using ppapi::thunk::PPB_Flash_TCPSocket_API; | 25 using ppapi::thunk::PPB_Flash_TCPSocket_API; |
25 | 26 |
26 namespace pp { | 27 namespace pp { |
27 namespace proxy { | 28 namespace proxy { |
28 | 29 |
29 const int32_t kFlashTCPSocketMaxReadSize = 1024 * 1024; | 30 const int32_t kFlashTCPSocketMaxReadSize = 1024 * 1024; |
30 const int32_t kFlashTCPSocketMaxWriteSize = 1024 * 1024; | 31 const int32_t kFlashTCPSocketMaxWriteSize = 1024 * 1024; |
31 | 32 |
32 class FlashTCPSocket; | 33 class FlashTCPSocket; |
33 | 34 |
(...skipping 17 matching lines...) Expand all Loading... |
51 }; | 52 }; |
52 | 53 |
53 InterfaceProxy* CreateFlashTCPSocketProxy(Dispatcher* dispatcher, | 54 InterfaceProxy* CreateFlashTCPSocketProxy(Dispatcher* dispatcher, |
54 const void* target_interface) { | 55 const void* target_interface) { |
55 return new PPB_Flash_TCPSocket_Proxy(dispatcher, target_interface); | 56 return new PPB_Flash_TCPSocket_Proxy(dispatcher, target_interface); |
56 } | 57 } |
57 | 58 |
58 } // namespace | 59 } // namespace |
59 | 60 |
60 class FlashTCPSocket : public PPB_Flash_TCPSocket_API, | 61 class FlashTCPSocket : public PPB_Flash_TCPSocket_API, |
61 public PluginResource { | 62 public Resource { |
62 public: | 63 public: |
63 FlashTCPSocket(const HostResource& resource, uint32 socket_id); | 64 FlashTCPSocket(const HostResource& resource, uint32 socket_id); |
64 virtual ~FlashTCPSocket(); | 65 virtual ~FlashTCPSocket(); |
65 | 66 |
66 // ResourceObjectBase overrides. | 67 // Resource overrides. |
67 virtual PPB_Flash_TCPSocket_API* AsPPB_Flash_TCPSocket_API() OVERRIDE; | 68 virtual PPB_Flash_TCPSocket_API* AsPPB_Flash_TCPSocket_API() OVERRIDE; |
68 | 69 |
69 // PPB_Flash_TCPSocket_API implementation. | 70 // PPB_Flash_TCPSocket_API implementation. |
70 virtual int32_t Connect(const char* host, | 71 virtual int32_t Connect(const char* host, |
71 uint16_t port, | 72 uint16_t port, |
72 PP_CompletionCallback callback) OVERRIDE; | 73 PP_CompletionCallback callback) OVERRIDE; |
73 virtual int32_t ConnectWithNetAddress( | 74 virtual int32_t ConnectWithNetAddress( |
74 const PP_Flash_NetAddress* addr, | 75 const PP_Flash_NetAddress* addr, |
75 PP_CompletionCallback callback) OVERRIDE; | 76 PP_CompletionCallback callback) OVERRIDE; |
76 virtual PP_Bool GetLocalAddress(PP_Flash_NetAddress* local_addr) OVERRIDE; | 77 virtual PP_Bool GetLocalAddress(PP_Flash_NetAddress* local_addr) OVERRIDE; |
(...skipping 26 matching lines...) Expand all Loading... |
103 // initiating SSL is pending). | 104 // initiating SSL is pending). |
104 CONNECTED, | 105 CONNECTED, |
105 // An SSL connection has been successfully established. | 106 // An SSL connection has been successfully established. |
106 SSL_CONNECTED, | 107 SSL_CONNECTED, |
107 // The connection has been ended. | 108 // The connection has been ended. |
108 DISCONNECTED | 109 DISCONNECTED |
109 }; | 110 }; |
110 | 111 |
111 bool IsConnected() const; | 112 bool IsConnected() const; |
112 | 113 |
| 114 PluginDispatcher* GetDispatcher() const { |
| 115 return PluginDispatcher::GetForResource(this); |
| 116 } |
| 117 |
113 // Backend for both Connect() and ConnectWithNetAddress(). To keep things | 118 // Backend for both Connect() and ConnectWithNetAddress(). To keep things |
114 // generic, the message is passed in (on error, it's deleted). | 119 // generic, the message is passed in (on error, it's deleted). |
115 int32_t ConnectWithMessage(IPC::Message* msg, | 120 int32_t ConnectWithMessage(IPC::Message* msg, |
116 PP_CompletionCallback callback); | 121 PP_CompletionCallback callback); |
117 | 122 |
118 void PostAbortAndClearIfNecessary(PP_CompletionCallback* callback); | 123 void PostAbortAndClearIfNecessary(PP_CompletionCallback* callback); |
119 | 124 |
120 uint32 socket_id_; | 125 uint32 socket_id_; |
121 ConnectionState connection_state_; | 126 ConnectionState connection_state_; |
122 | 127 |
123 PP_CompletionCallback connect_callback_; | 128 PP_CompletionCallback connect_callback_; |
124 PP_CompletionCallback ssl_handshake_callback_; | 129 PP_CompletionCallback ssl_handshake_callback_; |
125 PP_CompletionCallback read_callback_; | 130 PP_CompletionCallback read_callback_; |
126 PP_CompletionCallback write_callback_; | 131 PP_CompletionCallback write_callback_; |
127 | 132 |
128 char* read_buffer_; | 133 char* read_buffer_; |
129 int32_t bytes_to_read_; | 134 int32_t bytes_to_read_; |
130 | 135 |
131 PP_Flash_NetAddress local_addr_; | 136 PP_Flash_NetAddress local_addr_; |
132 PP_Flash_NetAddress remote_addr_; | 137 PP_Flash_NetAddress remote_addr_; |
133 | 138 |
134 DISALLOW_COPY_AND_ASSIGN(FlashTCPSocket); | 139 DISALLOW_COPY_AND_ASSIGN(FlashTCPSocket); |
135 }; | 140 }; |
136 | 141 |
137 FlashTCPSocket::FlashTCPSocket(const HostResource& resource, uint32 socket_id) | 142 FlashTCPSocket::FlashTCPSocket(const HostResource& resource, uint32 socket_id) |
138 : PluginResource(resource), | 143 : Resource(resource), |
139 socket_id_(socket_id), | 144 socket_id_(socket_id), |
140 connection_state_(BEFORE_CONNECT), | 145 connection_state_(BEFORE_CONNECT), |
141 connect_callback_(PP_BlockUntilComplete()), | 146 connect_callback_(PP_BlockUntilComplete()), |
142 ssl_handshake_callback_(PP_BlockUntilComplete()), | 147 ssl_handshake_callback_(PP_BlockUntilComplete()), |
143 read_callback_(PP_BlockUntilComplete()), | 148 read_callback_(PP_BlockUntilComplete()), |
144 write_callback_(PP_BlockUntilComplete()), | 149 write_callback_(PP_BlockUntilComplete()), |
145 read_buffer_(NULL), | 150 read_buffer_(NULL), |
146 bytes_to_read_(-1) { | 151 bytes_to_read_(-1) { |
147 DCHECK(socket_id != 0); | 152 DCHECK(socket_id != 0); |
148 | 153 |
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
413 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); | 418 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); |
414 if (!dispatcher) | 419 if (!dispatcher) |
415 return 0; | 420 return 0; |
416 | 421 |
417 uint32 socket_id = 0; | 422 uint32 socket_id = 0; |
418 dispatcher->SendToBrowser(new PpapiHostMsg_PPBFlashTCPSocket_Create( | 423 dispatcher->SendToBrowser(new PpapiHostMsg_PPBFlashTCPSocket_Create( |
419 INTERFACE_ID_PPB_FLASH_TCPSOCKET, dispatcher->plugin_dispatcher_id(), | 424 INTERFACE_ID_PPB_FLASH_TCPSOCKET, dispatcher->plugin_dispatcher_id(), |
420 &socket_id)); | 425 &socket_id)); |
421 if (socket_id == 0) | 426 if (socket_id == 0) |
422 return 0; | 427 return 0; |
423 | 428 return (new FlashTCPSocket(HostResource::MakeInstanceOnly(instance), |
424 return PluginResourceTracker::GetInstance()->AddResource( | 429 socket_id))->GetReference(); |
425 new FlashTCPSocket(HostResource::MakeInstanceOnly(instance), socket_id)); | |
426 } | 430 } |
427 | 431 |
428 bool PPB_Flash_TCPSocket_Proxy::OnMessageReceived(const IPC::Message& msg) { | 432 bool PPB_Flash_TCPSocket_Proxy::OnMessageReceived(const IPC::Message& msg) { |
429 bool handled = true; | 433 bool handled = true; |
430 IPC_BEGIN_MESSAGE_MAP(PPB_Flash_TCPSocket_Proxy, msg) | 434 IPC_BEGIN_MESSAGE_MAP(PPB_Flash_TCPSocket_Proxy, msg) |
431 IPC_MESSAGE_HANDLER(PpapiMsg_PPBFlashTCPSocket_ConnectACK, OnMsgConnectACK) | 435 IPC_MESSAGE_HANDLER(PpapiMsg_PPBFlashTCPSocket_ConnectACK, OnMsgConnectACK) |
432 IPC_MESSAGE_HANDLER(PpapiMsg_PPBFlashTCPSocket_SSLHandshakeACK, | 436 IPC_MESSAGE_HANDLER(PpapiMsg_PPBFlashTCPSocket_SSLHandshakeACK, |
433 OnMsgSSLHandshakeACK) | 437 OnMsgSSLHandshakeACK) |
434 IPC_MESSAGE_HANDLER(PpapiMsg_PPBFlashTCPSocket_ReadACK, OnMsgReadACK) | 438 IPC_MESSAGE_HANDLER(PpapiMsg_PPBFlashTCPSocket_ReadACK, OnMsgReadACK) |
435 IPC_MESSAGE_HANDLER(PpapiMsg_PPBFlashTCPSocket_WriteACK, OnMsgWriteACK) | 439 IPC_MESSAGE_HANDLER(PpapiMsg_PPBFlashTCPSocket_WriteACK, OnMsgWriteACK) |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
491 return; | 495 return; |
492 } | 496 } |
493 IDToSocketMap::iterator iter = g_id_to_socket->find(socket_id); | 497 IDToSocketMap::iterator iter = g_id_to_socket->find(socket_id); |
494 if (iter == g_id_to_socket->end()) | 498 if (iter == g_id_to_socket->end()) |
495 return; | 499 return; |
496 iter->second->OnWriteCompleted(succeeded, bytes_written); | 500 iter->second->OnWriteCompleted(succeeded, bytes_written); |
497 } | 501 } |
498 | 502 |
499 } // namespace proxy | 503 } // namespace proxy |
500 } // namespace pp | 504 } // namespace pp |
OLD | NEW |