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_net_connector_proxy.h" | 5 #include "ppapi/proxy/ppb_flash_net_connector_proxy.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "ppapi/c/pp_errors.h" | 9 #include "ppapi/c/pp_errors.h" |
10 #include "ppapi/c/private/ppb_flash_net_connector.h" | 10 #include "ppapi/c/private/ppb_flash_net_connector.h" |
11 #include "ppapi/proxy/enter_proxy.h" | 11 #include "ppapi/proxy/enter_proxy.h" |
12 #include "ppapi/proxy/plugin_dispatcher.h" | 12 #include "ppapi/proxy/plugin_dispatcher.h" |
13 #include "ppapi/proxy/plugin_resource.h" | |
14 #include "ppapi/proxy/ppapi_messages.h" | 13 #include "ppapi/proxy/ppapi_messages.h" |
15 #include "ppapi/proxy/serialized_var.h" | 14 #include "ppapi/proxy/serialized_var.h" |
16 #include "ppapi/thunk/enter.h" | 15 #include "ppapi/thunk/enter.h" |
17 #include "ppapi/thunk/ppb_flash_net_connector_api.h" | 16 #include "ppapi/thunk/ppb_flash_net_connector_api.h" |
18 #include "ppapi/thunk/resource_creation_api.h" | 17 #include "ppapi/thunk/resource_creation_api.h" |
19 #include "ppapi/thunk/thunk.h" | 18 #include "ppapi/thunk/thunk.h" |
20 | 19 |
21 using ppapi::HostResource; | 20 using ppapi::HostResource; |
| 21 using ppapi::Resource; |
22 using ppapi::thunk::EnterFunctionNoLock; | 22 using ppapi::thunk::EnterFunctionNoLock; |
23 using ppapi::thunk::PPB_Flash_NetConnector_API; | 23 using ppapi::thunk::PPB_Flash_NetConnector_API; |
24 using ppapi::thunk::ResourceCreationAPI; | 24 using ppapi::thunk::ResourceCreationAPI; |
25 | 25 |
26 namespace pp { | 26 namespace pp { |
27 namespace proxy { | 27 namespace proxy { |
28 | 28 |
29 std::string NetAddressToString(const PP_Flash_NetAddress& addr) { | 29 std::string NetAddressToString(const PP_Flash_NetAddress& addr) { |
30 return std::string(addr.data, std::min(static_cast<size_t>(addr.size), | 30 return std::string(addr.data, std::min(static_cast<size_t>(addr.size), |
31 sizeof(addr.data))); | 31 sizeof(addr.data))); |
(...skipping 11 matching lines...) Expand all Loading... |
43 | 43 |
44 virtual void Run() { | 44 virtual void Run() { |
45 PP_RunCompletionCallback(&callback_, PP_ERROR_ABORTED); | 45 PP_RunCompletionCallback(&callback_, PP_ERROR_ABORTED); |
46 } | 46 } |
47 | 47 |
48 private: | 48 private: |
49 PP_CompletionCallback callback_; | 49 PP_CompletionCallback callback_; |
50 }; | 50 }; |
51 | 51 |
52 class FlashNetConnector : public PPB_Flash_NetConnector_API, | 52 class FlashNetConnector : public PPB_Flash_NetConnector_API, |
53 public PluginResource { | 53 public Resource { |
54 public: | 54 public: |
55 explicit FlashNetConnector(const HostResource& resource); | 55 explicit FlashNetConnector(const HostResource& resource); |
56 virtual ~FlashNetConnector(); | 56 virtual ~FlashNetConnector(); |
57 | 57 |
58 // ResourceObjectBase overrides. | 58 // Resource overrides. |
59 virtual PPB_Flash_NetConnector_API* AsPPB_Flash_NetConnector_API() OVERRIDE; | 59 virtual PPB_Flash_NetConnector_API* AsPPB_Flash_NetConnector_API() OVERRIDE; |
60 | 60 |
61 // PPB_Flash_NetConnector_API implementation. | 61 // PPB_Flash_NetConnector_API implementation. |
62 virtual int32_t ConnectTcp(const char* host, | 62 virtual int32_t ConnectTcp(const char* host, |
63 uint16_t port, | 63 uint16_t port, |
64 PP_FileHandle* socket_out, | 64 PP_FileHandle* socket_out, |
65 PP_Flash_NetAddress* local_addr_out, | 65 PP_Flash_NetAddress* local_addr_out, |
66 PP_Flash_NetAddress* remote_addr_out, | 66 PP_Flash_NetAddress* remote_addr_out, |
67 PP_CompletionCallback callback) OVERRIDE; | 67 PP_CompletionCallback callback) OVERRIDE; |
68 virtual int32_t ConnectTcpAddress(const PP_Flash_NetAddress* addr, | 68 virtual int32_t ConnectTcpAddress(const PP_Flash_NetAddress* addr, |
(...skipping 16 matching lines...) Expand all Loading... |
85 PP_Flash_NetAddress* remote_addr_out, | 85 PP_Flash_NetAddress* remote_addr_out, |
86 PP_CompletionCallback callback); | 86 PP_CompletionCallback callback); |
87 | 87 |
88 PP_CompletionCallback callback_; | 88 PP_CompletionCallback callback_; |
89 PP_FileHandle* socket_out_; | 89 PP_FileHandle* socket_out_; |
90 PP_Flash_NetAddress* local_addr_out_; | 90 PP_Flash_NetAddress* local_addr_out_; |
91 PP_Flash_NetAddress* remote_addr_out_; | 91 PP_Flash_NetAddress* remote_addr_out_; |
92 }; | 92 }; |
93 | 93 |
94 FlashNetConnector::FlashNetConnector(const HostResource& resource) | 94 FlashNetConnector::FlashNetConnector(const HostResource& resource) |
95 : PluginResource(resource), | 95 : Resource(resource), |
96 callback_(PP_BlockUntilComplete()), | 96 callback_(PP_BlockUntilComplete()), |
97 local_addr_out_(NULL), | 97 local_addr_out_(NULL), |
98 remote_addr_out_(NULL) { | 98 remote_addr_out_(NULL) { |
99 } | 99 } |
100 | 100 |
101 FlashNetConnector::~FlashNetConnector() { | 101 FlashNetConnector::~FlashNetConnector() { |
102 if (callback_.func) { | 102 if (callback_.func) { |
103 MessageLoop::current()->PostTask(FROM_HERE, | 103 MessageLoop::current()->PostTask(FROM_HERE, |
104 new AbortCallbackTask(callback_)); | 104 new AbortCallbackTask(callback_)); |
105 } | 105 } |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 IPC::Message* msg, | 156 IPC::Message* msg, |
157 PP_FileHandle* socket_out, | 157 PP_FileHandle* socket_out, |
158 PP_Flash_NetAddress* local_addr_out, | 158 PP_Flash_NetAddress* local_addr_out, |
159 PP_Flash_NetAddress* remote_addr_out, | 159 PP_Flash_NetAddress* remote_addr_out, |
160 PP_CompletionCallback callback) { | 160 PP_CompletionCallback callback) { |
161 scoped_ptr<IPC::Message> msg_deletor(msg); | 161 scoped_ptr<IPC::Message> msg_deletor(msg); |
162 if (callback_.func != NULL) | 162 if (callback_.func != NULL) |
163 return PP_ERROR_INPROGRESS; // Can only have one pending request. | 163 return PP_ERROR_INPROGRESS; // Can only have one pending request. |
164 | 164 |
165 // Send the request, it will call us back via ConnectACK. | 165 // Send the request, it will call us back via ConnectACK. |
166 GetDispatcher()->Send(msg_deletor.release()); | 166 PluginDispatcher::GetForResource(this)->Send(msg_deletor.release()); |
167 | 167 |
168 callback_ = callback; | 168 callback_ = callback; |
169 socket_out_ = socket_out; | 169 socket_out_ = socket_out; |
170 local_addr_out_ = local_addr_out; | 170 local_addr_out_ = local_addr_out; |
171 remote_addr_out_ = remote_addr_out; | 171 remote_addr_out_ = remote_addr_out; |
172 return PP_OK_COMPLETIONPENDING; | 172 return PP_OK_COMPLETIONPENDING; |
173 } | 173 } |
174 | 174 |
175 // Contains the data that the host interface will write to so we can send it | 175 // Contains the data that the host interface will write to so we can send it |
176 // to the plugin. This is created when a request is initiated, and deleted in | 176 // to the plugin. This is created when a request is initiated, and deleted in |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 PP_Instance instance) { | 223 PP_Instance instance) { |
224 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); | 224 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); |
225 if (!dispatcher) | 225 if (!dispatcher) |
226 return 0; | 226 return 0; |
227 | 227 |
228 HostResource result; | 228 HostResource result; |
229 dispatcher->Send(new PpapiHostMsg_PPBFlashNetConnector_Create( | 229 dispatcher->Send(new PpapiHostMsg_PPBFlashNetConnector_Create( |
230 INTERFACE_ID_PPB_FLASH_NETCONNECTOR, instance, &result)); | 230 INTERFACE_ID_PPB_FLASH_NETCONNECTOR, instance, &result)); |
231 if (result.is_null()) | 231 if (result.is_null()) |
232 return 0; | 232 return 0; |
233 | 233 return (new FlashNetConnector(result))->GetReference(); |
234 return PluginResourceTracker::GetInstance()->AddResource( | |
235 new FlashNetConnector(result)); | |
236 } | 234 } |
237 | 235 |
238 bool PPB_Flash_NetConnector_Proxy::OnMessageReceived(const IPC::Message& msg) { | 236 bool PPB_Flash_NetConnector_Proxy::OnMessageReceived(const IPC::Message& msg) { |
239 bool handled = true; | 237 bool handled = true; |
240 IPC_BEGIN_MESSAGE_MAP(PPB_Flash_NetConnector_Proxy, msg) | 238 IPC_BEGIN_MESSAGE_MAP(PPB_Flash_NetConnector_Proxy, msg) |
241 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlashNetConnector_Create, | 239 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlashNetConnector_Create, |
242 OnMsgCreate) | 240 OnMsgCreate) |
243 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlashNetConnector_ConnectTcp, | 241 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlashNetConnector_ConnectTcp, |
244 OnMsgConnectTcp) | 242 OnMsgConnectTcp) |
245 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlashNetConnector_ConnectTcpAddress, | 243 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlashNetConnector_ConnectTcpAddress, |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
337 } else { | 335 } else { |
338 dispatcher()->Send(new PpapiMsg_PPBFlashNetConnector_ConnectACK( | 336 dispatcher()->Send(new PpapiMsg_PPBFlashNetConnector_ConnectACK( |
339 INTERFACE_ID_PPB_FLASH_NETCONNECTOR, | 337 INTERFACE_ID_PPB_FLASH_NETCONNECTOR, |
340 info->resource, result, | 338 info->resource, result, |
341 IPC::InvalidPlatformFileForTransit(), std::string(), std::string())); | 339 IPC::InvalidPlatformFileForTransit(), std::string(), std::string())); |
342 } | 340 } |
343 } | 341 } |
344 | 342 |
345 } // namespace proxy | 343 } // namespace proxy |
346 } // namespace pp | 344 } // namespace pp |
OLD | NEW |