| 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/plugin_dispatcher.h" | 11 #include "ppapi/proxy/plugin_dispatcher.h" |
| 12 #include "ppapi/proxy/plugin_resource.h" | 12 #include "ppapi/proxy/plugin_resource.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/common.h" |
| 15 | 16 |
| 16 namespace pp { | 17 namespace pp { |
| 17 namespace proxy { | 18 namespace proxy { |
| 18 | 19 |
| 19 std::string NetAddressToString(const PP_Flash_NetAddress& addr) { | 20 std::string NetAddressToString(const PP_Flash_NetAddress& addr) { |
| 20 return std::string(addr.data, std::min(static_cast<size_t>(addr.size), | 21 return std::string(addr.data, std::min(static_cast<size_t>(addr.size), |
| 21 sizeof(addr.data))); | 22 sizeof(addr.data))); |
| 22 } | 23 } |
| 23 | 24 |
| 24 void StringToNetAddress(const std::string& str, PP_Flash_NetAddress* addr) { | 25 void StringToNetAddress(const std::string& str, PP_Flash_NetAddress* addr) { |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 int32_t ConnectTcp(PP_Resource connector_id, | 162 int32_t ConnectTcp(PP_Resource connector_id, |
| 162 const char* host, | 163 const char* host, |
| 163 uint16_t port, | 164 uint16_t port, |
| 164 PP_FileHandle* socket_out, | 165 PP_FileHandle* socket_out, |
| 165 struct PP_Flash_NetAddress* local_addr_out, | 166 struct PP_Flash_NetAddress* local_addr_out, |
| 166 struct PP_Flash_NetAddress* remote_addr_out, | 167 struct PP_Flash_NetAddress* remote_addr_out, |
| 167 struct PP_CompletionCallback callback) { | 168 struct PP_CompletionCallback callback) { |
| 168 FlashNetConnector* object = | 169 FlashNetConnector* object = |
| 169 PluginResource::GetAs<FlashNetConnector>(connector_id); | 170 PluginResource::GetAs<FlashNetConnector>(connector_id); |
| 170 if (!object) | 171 if (!object) |
| 171 return PP_ERROR_BADARGUMENT; | 172 return ppapi::thunk::MayForceCallback(callback, PP_ERROR_BADARGUMENT); |
| 172 return ConnectWithMessage( | 173 int32_t result = ConnectWithMessage( |
| 173 object, | 174 object, |
| 174 new PpapiHostMsg_PPBFlashNetConnector_ConnectTcp( | 175 new PpapiHostMsg_PPBFlashNetConnector_ConnectTcp( |
| 175 INTERFACE_ID_PPB_FLASH_NETCONNECTOR, | 176 INTERFACE_ID_PPB_FLASH_NETCONNECTOR, |
| 176 object->host_resource(), host, port), | 177 object->host_resource(), host, port), |
| 177 socket_out, local_addr_out, remote_addr_out, callback); | 178 socket_out, local_addr_out, remote_addr_out, callback); |
| 179 return ppapi::thunk::MayForceCallback(callback, result); |
| 178 } | 180 } |
| 179 | 181 |
| 180 int32_t ConnectTcpAddress(PP_Resource connector_id, | 182 int32_t ConnectTcpAddress(PP_Resource connector_id, |
| 181 const struct PP_Flash_NetAddress* addr, | 183 const struct PP_Flash_NetAddress* addr, |
| 182 PP_FileHandle* socket_out, | 184 PP_FileHandle* socket_out, |
| 183 struct PP_Flash_NetAddress* local_addr_out, | 185 struct PP_Flash_NetAddress* local_addr_out, |
| 184 struct PP_Flash_NetAddress* remote_addr_out, | 186 struct PP_Flash_NetAddress* remote_addr_out, |
| 185 struct PP_CompletionCallback callback) { | 187 struct PP_CompletionCallback callback) { |
| 186 FlashNetConnector* object = | 188 FlashNetConnector* object = |
| 187 PluginResource::GetAs<FlashNetConnector>(connector_id); | 189 PluginResource::GetAs<FlashNetConnector>(connector_id); |
| 188 if (!object) | 190 if (!object) |
| 189 return PP_ERROR_BADARGUMENT; | 191 return ppapi::thunk::MayForceCallback(callback, PP_ERROR_BADARGUMENT); |
| 190 return ConnectWithMessage( | 192 int32_t result = ConnectWithMessage( |
| 191 object, | 193 object, |
| 192 new PpapiHostMsg_PPBFlashNetConnector_ConnectTcpAddress( | 194 new PpapiHostMsg_PPBFlashNetConnector_ConnectTcpAddress( |
| 193 INTERFACE_ID_PPB_FLASH_NETCONNECTOR, | 195 INTERFACE_ID_PPB_FLASH_NETCONNECTOR, |
| 194 object->host_resource(), NetAddressToString(*addr)), | 196 object->host_resource(), NetAddressToString(*addr)), |
| 195 socket_out, local_addr_out, remote_addr_out, callback); | 197 socket_out, local_addr_out, remote_addr_out, callback); |
| 198 return ppapi::thunk::MayForceCallback(callback, result); |
| 196 } | 199 } |
| 197 | 200 |
| 198 const PPB_Flash_NetConnector flash_netconnector_interface = { | 201 const PPB_Flash_NetConnector flash_netconnector_interface = { |
| 199 &Create, | 202 &Create, |
| 200 &IsFlashNetConnector, | 203 &IsFlashNetConnector, |
| 201 &ConnectTcp, | 204 &ConnectTcp, |
| 202 &ConnectTcpAddress | 205 &ConnectTcpAddress |
| 203 }; | 206 }; |
| 204 | 207 |
| 205 InterfaceProxy* CreateFlashNetConnectorProxy(Dispatcher* dispatcher, | 208 InterfaceProxy* CreateFlashNetConnectorProxy(Dispatcher* dispatcher, |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 331 } else { | 334 } else { |
| 332 dispatcher()->Send(new PpapiMsg_PPBFlashNetConnector_ConnectACK( | 335 dispatcher()->Send(new PpapiMsg_PPBFlashNetConnector_ConnectACK( |
| 333 INTERFACE_ID_PPB_FLASH_NETCONNECTOR, | 336 INTERFACE_ID_PPB_FLASH_NETCONNECTOR, |
| 334 info->resource, result, | 337 info->resource, result, |
| 335 IPC::InvalidPlatformFileForTransit(), std::string(), std::string())); | 338 IPC::InvalidPlatformFileForTransit(), std::string(), std::string())); |
| 336 } | 339 } |
| 337 } | 340 } |
| 338 | 341 |
| 339 } // namespace proxy | 342 } // namespace proxy |
| 340 } // namespace pp | 343 } // namespace pp |
| OLD | NEW |