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 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 virtual ~FlashTCPSocket(); | 58 virtual ~FlashTCPSocket(); |
59 | 59 |
60 // Resource overrides. | 60 // Resource overrides. |
61 virtual PPB_Flash_TCPSocket_API* AsPPB_Flash_TCPSocket_API() OVERRIDE; | 61 virtual PPB_Flash_TCPSocket_API* AsPPB_Flash_TCPSocket_API() OVERRIDE; |
62 | 62 |
63 // PPB_Flash_TCPSocket_API implementation. | 63 // PPB_Flash_TCPSocket_API implementation. |
64 virtual int32_t Connect(const char* host, | 64 virtual int32_t Connect(const char* host, |
65 uint16_t port, | 65 uint16_t port, |
66 PP_CompletionCallback callback) OVERRIDE; | 66 PP_CompletionCallback callback) OVERRIDE; |
67 virtual int32_t ConnectWithNetAddress( | 67 virtual int32_t ConnectWithNetAddress( |
68 const PP_Flash_NetAddress* addr, | 68 const PP_NetAddress_Private* addr, |
69 PP_CompletionCallback callback) OVERRIDE; | 69 PP_CompletionCallback callback) OVERRIDE; |
70 virtual PP_Bool GetLocalAddress(PP_Flash_NetAddress* local_addr) OVERRIDE; | 70 virtual PP_Bool GetLocalAddress(PP_NetAddress_Private* local_addr) OVERRIDE; |
71 virtual PP_Bool GetRemoteAddress(PP_Flash_NetAddress* remote_addr) OVERRIDE; | 71 virtual PP_Bool GetRemoteAddress(PP_NetAddress_Private* remote_addr) OVERRIDE; |
72 virtual int32_t SSLHandshake(const char* server_name, | 72 virtual int32_t SSLHandshake(const char* server_name, |
73 uint16_t server_port, | 73 uint16_t server_port, |
74 PP_CompletionCallback callback) OVERRIDE; | 74 PP_CompletionCallback callback) OVERRIDE; |
75 virtual int32_t Read(char* buffer, | 75 virtual int32_t Read(char* buffer, |
76 int32_t bytes_to_read, | 76 int32_t bytes_to_read, |
77 PP_CompletionCallback callback) OVERRIDE; | 77 PP_CompletionCallback callback) OVERRIDE; |
78 virtual int32_t Write(const char* buffer, | 78 virtual int32_t Write(const char* buffer, |
79 int32_t bytes_to_write, | 79 int32_t bytes_to_write, |
80 PP_CompletionCallback callback) OVERRIDE; | 80 PP_CompletionCallback callback) OVERRIDE; |
81 virtual void Disconnect() OVERRIDE; | 81 virtual void Disconnect() OVERRIDE; |
82 | 82 |
83 // Notifications from the proxy. | 83 // Notifications from the proxy. |
84 void OnConnectCompleted(bool succeeded, | 84 void OnConnectCompleted(bool succeeded, |
85 const PP_Flash_NetAddress& local_addr, | 85 const PP_NetAddress_Private& local_addr, |
86 const PP_Flash_NetAddress& remote_addr); | 86 const PP_NetAddress_Private& remote_addr); |
87 void OnSSLHandshakeCompleted(bool succeeded); | 87 void OnSSLHandshakeCompleted(bool succeeded); |
88 void OnReadCompleted(bool succeeded, const std::string& data); | 88 void OnReadCompleted(bool succeeded, const std::string& data); |
89 void OnWriteCompleted(bool succeeded, int32_t bytes_written); | 89 void OnWriteCompleted(bool succeeded, int32_t bytes_written); |
90 | 90 |
91 private: | 91 private: |
92 enum ConnectionState { | 92 enum ConnectionState { |
93 // Before a connection is successfully established (including a connect | 93 // Before a connection is successfully established (including a connect |
94 // request is pending or a previous connect request failed). | 94 // request is pending or a previous connect request failed). |
95 BEFORE_CONNECT, | 95 BEFORE_CONNECT, |
96 // A connection has been successfully established (including a request of | 96 // A connection has been successfully established (including a request of |
(...skipping 22 matching lines...) Expand all Loading... |
119 ConnectionState connection_state_; | 119 ConnectionState connection_state_; |
120 | 120 |
121 PP_CompletionCallback connect_callback_; | 121 PP_CompletionCallback connect_callback_; |
122 PP_CompletionCallback ssl_handshake_callback_; | 122 PP_CompletionCallback ssl_handshake_callback_; |
123 PP_CompletionCallback read_callback_; | 123 PP_CompletionCallback read_callback_; |
124 PP_CompletionCallback write_callback_; | 124 PP_CompletionCallback write_callback_; |
125 | 125 |
126 char* read_buffer_; | 126 char* read_buffer_; |
127 int32_t bytes_to_read_; | 127 int32_t bytes_to_read_; |
128 | 128 |
129 PP_Flash_NetAddress local_addr_; | 129 PP_NetAddress_Private local_addr_; |
130 PP_Flash_NetAddress remote_addr_; | 130 PP_NetAddress_Private remote_addr_; |
131 | 131 |
132 DISALLOW_COPY_AND_ASSIGN(FlashTCPSocket); | 132 DISALLOW_COPY_AND_ASSIGN(FlashTCPSocket); |
133 }; | 133 }; |
134 | 134 |
135 FlashTCPSocket::FlashTCPSocket(const HostResource& resource, uint32 socket_id) | 135 FlashTCPSocket::FlashTCPSocket(const HostResource& resource, uint32 socket_id) |
136 : Resource(resource), | 136 : Resource(resource), |
137 socket_id_(socket_id), | 137 socket_id_(socket_id), |
138 connection_state_(BEFORE_CONNECT), | 138 connection_state_(BEFORE_CONNECT), |
139 connect_callback_(PP_BlockUntilComplete()), | 139 connect_callback_(PP_BlockUntilComplete()), |
140 ssl_handshake_callback_(PP_BlockUntilComplete()), | 140 ssl_handshake_callback_(PP_BlockUntilComplete()), |
(...skipping 27 matching lines...) Expand all Loading... |
168 PP_CompletionCallback callback) { | 168 PP_CompletionCallback callback) { |
169 if (!host) | 169 if (!host) |
170 return PP_ERROR_BADARGUMENT; | 170 return PP_ERROR_BADARGUMENT; |
171 | 171 |
172 return ConnectWithMessage( | 172 return ConnectWithMessage( |
173 new PpapiHostMsg_PPBFlashTCPSocket_Connect(socket_id_, host, port), | 173 new PpapiHostMsg_PPBFlashTCPSocket_Connect(socket_id_, host, port), |
174 callback); | 174 callback); |
175 } | 175 } |
176 | 176 |
177 int32_t FlashTCPSocket::ConnectWithNetAddress( | 177 int32_t FlashTCPSocket::ConnectWithNetAddress( |
178 const PP_Flash_NetAddress* addr, | 178 const PP_NetAddress_Private* addr, |
179 PP_CompletionCallback callback) { | 179 PP_CompletionCallback callback) { |
180 if (!addr) | 180 if (!addr) |
181 return PP_ERROR_BADARGUMENT; | 181 return PP_ERROR_BADARGUMENT; |
182 | 182 |
183 return ConnectWithMessage( | 183 return ConnectWithMessage( |
184 new PpapiHostMsg_PPBFlashTCPSocket_ConnectWithNetAddress( | 184 new PpapiHostMsg_PPBFlashTCPSocket_ConnectWithNetAddress( |
185 socket_id_, *addr), | 185 socket_id_, *addr), |
186 callback); | 186 callback); |
187 } | 187 } |
188 | 188 |
189 PP_Bool FlashTCPSocket::GetLocalAddress(PP_Flash_NetAddress* local_addr) { | 189 PP_Bool FlashTCPSocket::GetLocalAddress(PP_NetAddress_Private* local_addr) { |
190 if (!IsConnected() || !local_addr) | 190 if (!IsConnected() || !local_addr) |
191 return PP_FALSE; | 191 return PP_FALSE; |
192 | 192 |
193 *local_addr = local_addr_; | 193 *local_addr = local_addr_; |
194 return PP_TRUE; | 194 return PP_TRUE; |
195 } | 195 } |
196 | 196 |
197 PP_Bool FlashTCPSocket::GetRemoteAddress(PP_Flash_NetAddress* remote_addr) { | 197 PP_Bool FlashTCPSocket::GetRemoteAddress(PP_NetAddress_Private* remote_addr) { |
198 if (!IsConnected() || !remote_addr) | 198 if (!IsConnected() || !remote_addr) |
199 return PP_FALSE; | 199 return PP_FALSE; |
200 | 200 |
201 *remote_addr = remote_addr_; | 201 *remote_addr = remote_addr_; |
202 return PP_TRUE; | 202 return PP_TRUE; |
203 } | 203 } |
204 | 204 |
205 int32_t FlashTCPSocket::SSLHandshake(const char* server_name, | 205 int32_t FlashTCPSocket::SSLHandshake(const char* server_name, |
206 uint16_t server_port, | 206 uint16_t server_port, |
207 PP_CompletionCallback callback) { | 207 PP_CompletionCallback callback) { |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
290 PostAbortAndClearIfNecessary(&connect_callback_); | 290 PostAbortAndClearIfNecessary(&connect_callback_); |
291 PostAbortAndClearIfNecessary(&ssl_handshake_callback_); | 291 PostAbortAndClearIfNecessary(&ssl_handshake_callback_); |
292 PostAbortAndClearIfNecessary(&read_callback_); | 292 PostAbortAndClearIfNecessary(&read_callback_); |
293 PostAbortAndClearIfNecessary(&write_callback_); | 293 PostAbortAndClearIfNecessary(&write_callback_); |
294 read_buffer_ = NULL; | 294 read_buffer_ = NULL; |
295 bytes_to_read_ = -1; | 295 bytes_to_read_ = -1; |
296 } | 296 } |
297 | 297 |
298 void FlashTCPSocket::OnConnectCompleted( | 298 void FlashTCPSocket::OnConnectCompleted( |
299 bool succeeded, | 299 bool succeeded, |
300 const PP_Flash_NetAddress& local_addr, | 300 const PP_NetAddress_Private& local_addr, |
301 const PP_Flash_NetAddress& remote_addr) { | 301 const PP_NetAddress_Private& remote_addr) { |
302 if (connection_state_ != BEFORE_CONNECT || !connect_callback_.func) { | 302 if (connection_state_ != BEFORE_CONNECT || !connect_callback_.func) { |
303 NOTREACHED(); | 303 NOTREACHED(); |
304 return; | 304 return; |
305 } | 305 } |
306 | 306 |
307 if (succeeded) { | 307 if (succeeded) { |
308 local_addr_ = local_addr; | 308 local_addr_ = local_addr; |
309 remote_addr_ = remote_addr; | 309 remote_addr_ = remote_addr; |
310 connection_state_ = CONNECTED; | 310 connection_state_ = CONNECTED; |
311 } | 311 } |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
424 IPC_MESSAGE_HANDLER(PpapiMsg_PPBFlashTCPSocket_WriteACK, OnMsgWriteACK) | 424 IPC_MESSAGE_HANDLER(PpapiMsg_PPBFlashTCPSocket_WriteACK, OnMsgWriteACK) |
425 IPC_MESSAGE_UNHANDLED(handled = false) | 425 IPC_MESSAGE_UNHANDLED(handled = false) |
426 IPC_END_MESSAGE_MAP() | 426 IPC_END_MESSAGE_MAP() |
427 return handled; | 427 return handled; |
428 } | 428 } |
429 | 429 |
430 void PPB_Flash_TCPSocket_Proxy::OnMsgConnectACK( | 430 void PPB_Flash_TCPSocket_Proxy::OnMsgConnectACK( |
431 uint32 /* plugin_dispatcher_id */, | 431 uint32 /* plugin_dispatcher_id */, |
432 uint32 socket_id, | 432 uint32 socket_id, |
433 bool succeeded, | 433 bool succeeded, |
434 const PP_Flash_NetAddress& local_addr, | 434 const PP_NetAddress_Private& local_addr, |
435 const PP_Flash_NetAddress& remote_addr) { | 435 const PP_NetAddress_Private& remote_addr) { |
436 if (!g_id_to_socket) { | 436 if (!g_id_to_socket) { |
437 NOTREACHED(); | 437 NOTREACHED(); |
438 return; | 438 return; |
439 } | 439 } |
440 IDToSocketMap::iterator iter = g_id_to_socket->find(socket_id); | 440 IDToSocketMap::iterator iter = g_id_to_socket->find(socket_id); |
441 if (iter == g_id_to_socket->end()) | 441 if (iter == g_id_to_socket->end()) |
442 return; | 442 return; |
443 iter->second->OnConnectCompleted(succeeded, local_addr, remote_addr); | 443 iter->second->OnConnectCompleted(succeeded, local_addr, remote_addr); |
444 } | 444 } |
445 | 445 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
480 return; | 480 return; |
481 } | 481 } |
482 IDToSocketMap::iterator iter = g_id_to_socket->find(socket_id); | 482 IDToSocketMap::iterator iter = g_id_to_socket->find(socket_id); |
483 if (iter == g_id_to_socket->end()) | 483 if (iter == g_id_to_socket->end()) |
484 return; | 484 return; |
485 iter->second->OnWriteCompleted(succeeded, bytes_written); | 485 iter->second->OnWriteCompleted(succeeded, bytes_written); |
486 } | 486 } |
487 | 487 |
488 } // namespace proxy | 488 } // namespace proxy |
489 } // namespace ppapi | 489 } // namespace ppapi |
OLD | NEW |