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/ppapi_messages.h" | 13 #include "ppapi/proxy/ppapi_messages.h" |
14 #include "ppapi/proxy/serialized_var.h" | 14 #include "ppapi/proxy/serialized_var.h" |
15 #include "ppapi/thunk/enter.h" | 15 #include "ppapi/thunk/enter.h" |
16 #include "ppapi/thunk/ppb_flash_net_connector_api.h" | 16 #include "ppapi/thunk/ppb_flash_net_connector_api.h" |
17 #include "ppapi/thunk/resource_creation_api.h" | 17 #include "ppapi/thunk/resource_creation_api.h" |
18 #include "ppapi/thunk/thunk.h" | 18 #include "ppapi/thunk/thunk.h" |
19 | 19 |
20 using ppapi::HostResource; | |
21 using ppapi::Resource; | |
22 using ppapi::thunk::EnterFunctionNoLock; | 20 using ppapi::thunk::EnterFunctionNoLock; |
23 using ppapi::thunk::PPB_Flash_NetConnector_API; | 21 using ppapi::thunk::PPB_Flash_NetConnector_API; |
24 using ppapi::thunk::ResourceCreationAPI; | 22 using ppapi::thunk::ResourceCreationAPI; |
25 | 23 |
26 namespace pp { | 24 namespace ppapi { |
27 namespace proxy { | 25 namespace proxy { |
28 | 26 |
29 std::string NetAddressToString(const PP_Flash_NetAddress& addr) { | 27 std::string NetAddressToString(const PP_Flash_NetAddress& addr) { |
30 return std::string(addr.data, std::min(static_cast<size_t>(addr.size), | 28 return std::string(addr.data, std::min(static_cast<size_t>(addr.size), |
31 sizeof(addr.data))); | 29 sizeof(addr.data))); |
32 } | 30 } |
33 | 31 |
34 void StringToNetAddress(const std::string& str, PP_Flash_NetAddress* addr) { | 32 void StringToNetAddress(const std::string& str, PP_Flash_NetAddress* addr) { |
35 addr->size = std::min(str.size(), sizeof(addr->data)); | 33 addr->size = std::min(str.size(), sizeof(addr->data)); |
36 memcpy(addr->data, str.data(), addr->size); | 34 memcpy(addr->data, str.data(), addr->size); |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
257 instance, | 255 instance, |
258 enter.functions()->CreateFlashNetConnector(instance)); | 256 enter.functions()->CreateFlashNetConnector(instance)); |
259 } | 257 } |
260 } | 258 } |
261 | 259 |
262 void PPB_Flash_NetConnector_Proxy::OnMsgConnectTcp( | 260 void PPB_Flash_NetConnector_Proxy::OnMsgConnectTcp( |
263 const HostResource& resource, | 261 const HostResource& resource, |
264 const std::string& host, | 262 const std::string& host, |
265 uint16_t port) { | 263 uint16_t port) { |
266 ConnectCallbackInfo* info = new ConnectCallbackInfo(resource); | 264 ConnectCallbackInfo* info = new ConnectCallbackInfo(resource); |
267 CompletionCallback callback = callback_factory_.NewOptionalCallback( | 265 pp::CompletionCallback callback = callback_factory_.NewOptionalCallback( |
268 &PPB_Flash_NetConnector_Proxy::OnCompleteCallbackInHost, info); | 266 &PPB_Flash_NetConnector_Proxy::OnCompleteCallbackInHost, info); |
269 | 267 |
270 EnterHostFromHostResource<PPB_Flash_NetConnector_API> enter(resource); | 268 EnterHostFromHostResource<PPB_Flash_NetConnector_API> enter(resource); |
271 int32_t result = PP_ERROR_BADRESOURCE; | 269 int32_t result = PP_ERROR_BADRESOURCE; |
272 if (enter.succeeded()) { | 270 if (enter.succeeded()) { |
273 result = enter.object()->ConnectTcp( | 271 result = enter.object()->ConnectTcp( |
274 host.c_str(), port, &info->handle, &info->local_addr, | 272 host.c_str(), port, &info->handle, &info->local_addr, |
275 &info->remote_addr, callback.pp_completion_callback()); | 273 &info->remote_addr, callback.pp_completion_callback()); |
276 } | 274 } |
277 if (result != PP_OK_COMPLETIONPENDING) | 275 if (result != PP_OK_COMPLETIONPENDING) |
278 OnCompleteCallbackInHost(result, info); | 276 OnCompleteCallbackInHost(result, info); |
279 } | 277 } |
280 | 278 |
281 void PPB_Flash_NetConnector_Proxy::OnMsgConnectTcpAddress( | 279 void PPB_Flash_NetConnector_Proxy::OnMsgConnectTcpAddress( |
282 const HostResource& resource, | 280 const HostResource& resource, |
283 const std::string& net_address_as_string) { | 281 const std::string& net_address_as_string) { |
284 ConnectCallbackInfo* info = new ConnectCallbackInfo(resource); | 282 ConnectCallbackInfo* info = new ConnectCallbackInfo(resource); |
285 CompletionCallback callback = callback_factory_.NewOptionalCallback( | 283 pp::CompletionCallback callback = callback_factory_.NewOptionalCallback( |
286 &PPB_Flash_NetConnector_Proxy::OnCompleteCallbackInHost, info); | 284 &PPB_Flash_NetConnector_Proxy::OnCompleteCallbackInHost, info); |
287 | 285 |
288 PP_Flash_NetAddress net_address; | 286 PP_Flash_NetAddress net_address; |
289 StringToNetAddress(net_address_as_string, &net_address); | 287 StringToNetAddress(net_address_as_string, &net_address); |
290 | 288 |
291 EnterHostFromHostResource<PPB_Flash_NetConnector_API> enter(resource); | 289 EnterHostFromHostResource<PPB_Flash_NetConnector_API> enter(resource); |
292 int32_t result = PP_ERROR_BADRESOURCE; | 290 int32_t result = PP_ERROR_BADRESOURCE; |
293 if (enter.succeeded()) { | 291 if (enter.succeeded()) { |
294 result = enter.object()->ConnectTcpAddress( | 292 result = enter.object()->ConnectTcpAddress( |
295 &net_address, &info->handle, &info->local_addr, &info->remote_addr, | 293 &net_address, &info->handle, &info->local_addr, &info->remote_addr, |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
334 NetAddressToString(info->remote_addr))); | 332 NetAddressToString(info->remote_addr))); |
335 } else { | 333 } else { |
336 dispatcher()->Send(new PpapiMsg_PPBFlashNetConnector_ConnectACK( | 334 dispatcher()->Send(new PpapiMsg_PPBFlashNetConnector_ConnectACK( |
337 INTERFACE_ID_PPB_FLASH_NETCONNECTOR, | 335 INTERFACE_ID_PPB_FLASH_NETCONNECTOR, |
338 info->resource, result, | 336 info->resource, result, |
339 IPC::InvalidPlatformFileForTransit(), std::string(), std::string())); | 337 IPC::InvalidPlatformFileForTransit(), std::string(), std::string())); |
340 } | 338 } |
341 } | 339 } |
342 | 340 |
343 } // namespace proxy | 341 } // namespace proxy |
344 } // namespace pp | 342 } // namespace ppapi |
OLD | NEW |