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 "webkit/plugins/ppapi/ppb_flash_net_connector_impl.h" | 5 #include "webkit/plugins/ppapi/ppb_flash_net_connector_impl.h" |
6 | 6 |
7 #include "ppapi/c/pp_completion_callback.h" | 7 #include "ppapi/c/pp_completion_callback.h" |
8 #include "ppapi/c/private/ppb_flash_net_connector.h" | 8 #include "ppapi/c/private/ppb_flash_net_connector.h" |
9 #include "webkit/plugins/ppapi/common.h" | 9 #include "webkit/plugins/ppapi/common.h" |
10 #include "webkit/plugins/ppapi/plugin_delegate.h" | 10 #include "webkit/plugins/ppapi/plugin_delegate.h" |
11 #include "webkit/plugins/ppapi/plugin_module.h" | 11 #include "webkit/plugins/ppapi/plugin_module.h" |
12 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" | 12 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" |
13 | 13 |
| 14 using ::ppapi::thunk::PPB_Flash_NetConnector_API; |
| 15 |
14 namespace webkit { | 16 namespace webkit { |
15 namespace ppapi { | 17 namespace ppapi { |
16 | 18 |
17 namespace { | |
18 | |
19 PP_Resource Create(PP_Instance instance_id) { | |
20 PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id); | |
21 if (!instance) | |
22 return 0; | |
23 | |
24 scoped_refptr<PPB_Flash_NetConnector_Impl> connector( | |
25 new PPB_Flash_NetConnector_Impl(instance)); | |
26 return connector->GetReference(); | |
27 } | |
28 | |
29 PP_Bool IsFlashNetConnector(PP_Resource resource) { | |
30 return BoolToPPBool(!!Resource::GetAs<PPB_Flash_NetConnector_Impl>(resource)); | |
31 } | |
32 | |
33 int32_t ConnectTcp(PP_Resource connector_id, | |
34 const char* host, | |
35 uint16_t port, | |
36 PP_FileHandle* socket_out, | |
37 PP_Flash_NetAddress* local_addr_out, | |
38 PP_Flash_NetAddress* remote_addr_out, | |
39 PP_CompletionCallback callback) { | |
40 scoped_refptr<PPB_Flash_NetConnector_Impl> connector( | |
41 Resource::GetAs<PPB_Flash_NetConnector_Impl>(connector_id)); | |
42 if (!connector.get()) | |
43 return PP_ERROR_BADRESOURCE; | |
44 | |
45 return connector->ConnectTcp( | |
46 host, port, socket_out, local_addr_out, remote_addr_out, callback); | |
47 } | |
48 | |
49 int32_t ConnectTcpAddress(PP_Resource connector_id, | |
50 const PP_Flash_NetAddress* addr, | |
51 PP_FileHandle* socket_out, | |
52 PP_Flash_NetAddress* local_addr_out, | |
53 PP_Flash_NetAddress* remote_addr_out, | |
54 PP_CompletionCallback callback) { | |
55 scoped_refptr<PPB_Flash_NetConnector_Impl> connector( | |
56 Resource::GetAs<PPB_Flash_NetConnector_Impl>(connector_id)); | |
57 if (!connector.get()) | |
58 return PP_ERROR_BADRESOURCE; | |
59 | |
60 return connector->ConnectTcpAddress( | |
61 addr, socket_out, local_addr_out, remote_addr_out, callback); | |
62 } | |
63 | |
64 const PPB_Flash_NetConnector ppb_flash_netconnector = { | |
65 &Create, | |
66 &IsFlashNetConnector, | |
67 &ConnectTcp, | |
68 &ConnectTcpAddress, | |
69 }; | |
70 | |
71 } // namespace | |
72 | |
73 PPB_Flash_NetConnector_Impl::PPB_Flash_NetConnector_Impl( | 19 PPB_Flash_NetConnector_Impl::PPB_Flash_NetConnector_Impl( |
74 PluginInstance* instance) | 20 PluginInstance* instance) |
75 : Resource(instance) { | 21 : Resource(instance) { |
76 } | 22 } |
77 | 23 |
78 PPB_Flash_NetConnector_Impl::~PPB_Flash_NetConnector_Impl() { | 24 PPB_Flash_NetConnector_Impl::~PPB_Flash_NetConnector_Impl() { |
79 } | 25 } |
80 | 26 |
81 // static | 27 // static |
82 const PPB_Flash_NetConnector* PPB_Flash_NetConnector_Impl::GetInterface() { | 28 PP_Resource PPB_Flash_NetConnector_Impl::Create(PP_Instance pp_instance) { |
83 return &ppb_flash_netconnector; | 29 PluginInstance* instance = ResourceTracker::Get()->GetInstance(pp_instance); |
| 30 if (!instance) |
| 31 return 0; |
| 32 |
| 33 scoped_refptr<PPB_Flash_NetConnector_Impl> connector( |
| 34 new PPB_Flash_NetConnector_Impl(instance)); |
| 35 return connector->GetReference(); |
84 } | 36 } |
85 | 37 |
86 PPB_Flash_NetConnector_Impl* | 38 PPB_Flash_NetConnector_API* |
87 PPB_Flash_NetConnector_Impl::AsPPB_Flash_NetConnector_Impl() { | 39 PPB_Flash_NetConnector_Impl::AsPPB_Flash_NetConnector_API() { |
88 return this; | 40 return this; |
89 } | 41 } |
90 | 42 |
91 int32_t PPB_Flash_NetConnector_Impl::ConnectTcp( | 43 int32_t PPB_Flash_NetConnector_Impl::ConnectTcp( |
92 const char* host, | 44 const char* host, |
93 uint16_t port, | 45 uint16_t port, |
94 PP_FileHandle* socket_out, | 46 PP_FileHandle* socket_out, |
95 PP_Flash_NetAddress* local_addr_out, | 47 PP_Flash_NetAddress* local_addr_out, |
96 PP_Flash_NetAddress* remote_addr_out, | 48 PP_Flash_NetAddress* remote_addr_out, |
97 PP_CompletionCallback callback) { | 49 PP_CompletionCallback callback) { |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 socket_out_ = NULL; | 148 socket_out_ = NULL; |
197 local_addr_out_ = NULL; | 149 local_addr_out_ = NULL; |
198 remote_addr_out_ = NULL; | 150 remote_addr_out_ = NULL; |
199 | 151 |
200 callback->Run(rv); // Will complete abortively if necessary. | 152 callback->Run(rv); // Will complete abortively if necessary. |
201 } | 153 } |
202 | 154 |
203 } // namespace ppapi | 155 } // namespace ppapi |
204 } // namespace webkit | 156 } // namespace webkit |
205 | 157 |
OLD | NEW |