Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(118)

Side by Side Diff: ppapi/proxy/ppb_flash_net_connector_proxy.cc

Issue 7149026: Implement flash menu and net connector resources using the API/thunk model. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ppapi/proxy/ppb_flash_net_connector_proxy.h ('k') | ppapi/proxy/ppb_image_data_proxy.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/plugin_dispatcher.h" 12 #include "ppapi/proxy/plugin_dispatcher.h"
12 #include "ppapi/proxy/plugin_resource.h" 13 #include "ppapi/proxy/plugin_resource.h"
13 #include "ppapi/proxy/ppapi_messages.h" 14 #include "ppapi/proxy/ppapi_messages.h"
14 #include "ppapi/proxy/serialized_var.h" 15 #include "ppapi/proxy/serialized_var.h"
16 #include "ppapi/thunk/enter.h"
17 #include "ppapi/thunk/ppb_flash_net_connector_api.h"
18 #include "ppapi/thunk/resource_creation_api.h"
19 #include "ppapi/thunk/thunk.h"
20
21 using ppapi::thunk::EnterFunctionNoLock;
22 using ppapi::thunk::PPB_Flash_NetConnector_API;
23 using ppapi::thunk::ResourceCreationAPI;
15 24
16 namespace pp { 25 namespace pp {
17 namespace proxy { 26 namespace proxy {
18 27
19 std::string NetAddressToString(const PP_Flash_NetAddress& addr) { 28 std::string NetAddressToString(const PP_Flash_NetAddress& addr) {
20 return std::string(addr.data, std::min(static_cast<size_t>(addr.size), 29 return std::string(addr.data, std::min(static_cast<size_t>(addr.size),
21 sizeof(addr.data))); 30 sizeof(addr.data)));
22 } 31 }
23 32
24 void StringToNetAddress(const std::string& str, PP_Flash_NetAddress* addr) { 33 void StringToNetAddress(const std::string& str, PP_Flash_NetAddress* addr) {
25 addr->size = std::min(str.size(), sizeof(addr->data)); 34 addr->size = std::min(str.size(), sizeof(addr->data));
26 memcpy(addr->data, str.data(), addr->size); 35 memcpy(addr->data, str.data(), addr->size);
27 } 36 }
28 37
29 class AbortCallbackTask : public Task { 38 class AbortCallbackTask : public Task {
30 public: 39 public:
31 AbortCallbackTask(PP_CompletionCallback callback) 40 AbortCallbackTask(PP_CompletionCallback callback)
32 : callback_(callback) {} 41 : callback_(callback) {}
33 42
34 virtual void Run() { 43 virtual void Run() {
35 PP_RunCompletionCallback(&callback_, PP_ERROR_ABORTED); 44 PP_RunCompletionCallback(&callback_, PP_ERROR_ABORTED);
36 } 45 }
37 46
38 private: 47 private:
39 PP_CompletionCallback callback_; 48 PP_CompletionCallback callback_;
40 }; 49 };
41 50
42 class FlashNetConnector : public PluginResource { 51 class FlashNetConnector : public PPB_Flash_NetConnector_API,
52 public PluginResource {
43 public: 53 public:
44 FlashNetConnector(const HostResource& resource) 54 explicit FlashNetConnector(const HostResource& resource);
45 : PluginResource(resource), 55 virtual ~FlashNetConnector();
46 callback_(PP_BlockUntilComplete()),
47 local_addr_out_(NULL),
48 remote_addr_out_(NULL) {
49 }
50 ~FlashNetConnector() {
51 if (callback_.func) {
52 MessageLoop::current()->PostTask(FROM_HERE,
53 new AbortCallbackTask(callback_));
54 }
55 }
56 56
57 // Resource overrides. 57 // ResourceObjectBase overrides.
58 virtual FlashNetConnector* AsFlashNetConnector() { 58 virtual PPB_Flash_NetConnector_API* AsPPB_Flash_NetConnector_API() OVERRIDE;
59 return this;
60 }
61 59
62 bool HasCallback() const { 60 // PPB_Flash_NetConnector_API implementation.
63 return callback_.func != NULL; 61 virtual int32_t ConnectTcp(const char* host,
64 } 62 uint16_t port,
65 63 PP_FileHandle* socket_out,
66 void SetCallback(const PP_CompletionCallback& callback, 64 PP_Flash_NetAddress* local_addr_out,
67 PP_FileHandle* socket_out, 65 PP_Flash_NetAddress* remote_addr_out,
68 PP_Flash_NetAddress* local_addr_out, 66 PP_CompletionCallback callback) OVERRIDE;
69 PP_Flash_NetAddress* remote_addr_out) { 67 virtual int32_t ConnectTcpAddress(const PP_Flash_NetAddress* addr,
70 callback_ = callback; 68 PP_FileHandle* socket_out,
71 socket_out_ = socket_out; 69 PP_Flash_NetAddress* local_addr_out,
72 local_addr_out_ = local_addr_out; 70 PP_Flash_NetAddress* remote_addr_out,
73 remote_addr_out_ = remote_addr_out; 71 PP_CompletionCallback callback) OVERRIDE;
74 }
75 72
76 void ConnectComplete(int32_t result, 73 void ConnectComplete(int32_t result,
77 base::PlatformFile file, 74 base::PlatformFile file,
78 const std::string& local_addr_as_string, 75 const std::string& local_addr_as_string,
79 const std::string& remote_addr_as_string) { 76 const std::string& remote_addr_as_string);
80 if (!callback_.func) {
81 base::ClosePlatformFile(file);
82 return;
83 }
84
85 *socket_out_ = static_cast<PP_FileHandle>(file);
86 StringToNetAddress(local_addr_as_string, local_addr_out_);
87 StringToNetAddress(remote_addr_as_string, remote_addr_out_);
88
89 PP_RunAndClearCompletionCallback(&callback_, result);
90 }
91 77
92 private: 78 private:
79 // Backend for both ConnectTcp and ConnectTcpAddress. To keep things generic,
80 // the message is passed in (on error, it's deleted).
81 int32_t ConnectWithMessage(IPC::Message* msg,
82 PP_FileHandle* socket_out,
83 PP_Flash_NetAddress* local_addr_out,
84 PP_Flash_NetAddress* remote_addr_out,
85 PP_CompletionCallback callback);
86
93 PP_CompletionCallback callback_; 87 PP_CompletionCallback callback_;
94 PP_FileHandle* socket_out_; 88 PP_FileHandle* socket_out_;
95 PP_Flash_NetAddress* local_addr_out_; 89 PP_Flash_NetAddress* local_addr_out_;
96 PP_Flash_NetAddress* remote_addr_out_; 90 PP_Flash_NetAddress* remote_addr_out_;
97 }; 91 };
98 92
93 FlashNetConnector::FlashNetConnector(const HostResource& resource)
94 : PluginResource(resource),
95 callback_(PP_BlockUntilComplete()),
96 local_addr_out_(NULL),
97 remote_addr_out_(NULL) {
98 }
99
100 FlashNetConnector::~FlashNetConnector() {
101 if (callback_.func) {
102 MessageLoop::current()->PostTask(FROM_HERE,
103 new AbortCallbackTask(callback_));
104 }
105 }
106
107 PPB_Flash_NetConnector_API* FlashNetConnector::AsPPB_Flash_NetConnector_API() {
108 return this;
109 }
110
111 int32_t FlashNetConnector::ConnectTcp(
112 const char* host,
113 uint16_t port,
114 PP_FileHandle* socket_out,
115 PP_Flash_NetAddress* local_addr_out,
116 PP_Flash_NetAddress* remote_addr_out,
117 PP_CompletionCallback callback) {
118 return ConnectWithMessage(
119 new PpapiHostMsg_PPBFlashNetConnector_ConnectTcp(
120 INTERFACE_ID_PPB_FLASH_NETCONNECTOR, host_resource(), host, port),
121 socket_out, local_addr_out, remote_addr_out, callback);
122 }
123
124 int32_t FlashNetConnector::ConnectTcpAddress(
125 const PP_Flash_NetAddress* addr,
126 PP_FileHandle* socket_out,
127 PP_Flash_NetAddress* local_addr_out,
128 PP_Flash_NetAddress* remote_addr_out,
129 PP_CompletionCallback callback) {
130 return ConnectWithMessage(
131 new PpapiHostMsg_PPBFlashNetConnector_ConnectTcpAddress(
132 INTERFACE_ID_PPB_FLASH_NETCONNECTOR,
133 host_resource(), NetAddressToString(*addr)),
134 socket_out, local_addr_out, remote_addr_out, callback);
135 }
136
137 void FlashNetConnector::ConnectComplete(
138 int32_t result,
139 base::PlatformFile file,
140 const std::string& local_addr_as_string,
141 const std::string& remote_addr_as_string) {
142 if (!callback_.func) {
143 base::ClosePlatformFile(file);
144 return;
145 }
146
147 *socket_out_ = static_cast<PP_FileHandle>(file);
148 StringToNetAddress(local_addr_as_string, local_addr_out_);
149 StringToNetAddress(remote_addr_as_string, remote_addr_out_);
150
151 PP_RunAndClearCompletionCallback(&callback_, result);
152 }
153
154 int32_t FlashNetConnector::ConnectWithMessage(
155 IPC::Message* msg,
156 PP_FileHandle* socket_out,
157 PP_Flash_NetAddress* local_addr_out,
158 PP_Flash_NetAddress* remote_addr_out,
159 PP_CompletionCallback callback) {
160 scoped_ptr<IPC::Message> msg_deletor(msg);
161 if (callback_.func != NULL)
162 return PP_ERROR_INPROGRESS; // Can only have one pending request.
163
164 // Send the request, it will call us back via ConnectACK.
165 GetDispatcher()->Send(msg_deletor.release());
166
167 callback_ = callback;
168 socket_out_ = socket_out;
169 local_addr_out_ = local_addr_out;
170 remote_addr_out_ = remote_addr_out;
171 return PP_OK_COMPLETIONPENDING;
172 }
173
99 // Contains the data that the host interface will write to so we can send it 174 // Contains the data that the host interface will write to so we can send it
100 // to the plugin. This is created when a request is initiated, and deleted in 175 // to the plugin. This is created when a request is initiated, and deleted in
101 // the callback handler. 176 // the callback handler.
102 struct PPB_Flash_NetConnector_Proxy::ConnectCallbackInfo { 177 struct PPB_Flash_NetConnector_Proxy::ConnectCallbackInfo {
103 ConnectCallbackInfo(const HostResource& r) : resource(r), handle(0) { 178 ConnectCallbackInfo(const HostResource& r) : resource(r), handle(0) {
104 local_addr.size = 0; 179 local_addr.size = 0;
105 remote_addr.size = 0; 180 remote_addr.size = 0;
106 } 181 }
107 182
108 HostResource resource; 183 HostResource resource;
109 184
110 PP_FileHandle handle; 185 PP_FileHandle handle;
111 PP_Flash_NetAddress local_addr; 186 PP_Flash_NetAddress local_addr;
112 PP_Flash_NetAddress remote_addr; 187 PP_Flash_NetAddress remote_addr;
113 }; 188 };
114 189
115 namespace { 190 namespace {
116 191
117 PP_Resource Create(PP_Instance instance_id) {
118 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance_id);
119 if (!dispatcher)
120 return 0;
121
122 HostResource result;
123 dispatcher->Send(new PpapiHostMsg_PPBFlashNetConnector_Create(
124 INTERFACE_ID_PPB_FLASH_NETCONNECTOR, instance_id, &result));
125 if (result.is_null())
126 return 0;
127
128 linked_ptr<FlashNetConnector> object(new FlashNetConnector(result));
129 return PluginResourceTracker::GetInstance()->AddResource(object);
130 }
131
132 PP_Bool IsFlashNetConnector(PP_Resource resource_id) {
133 FlashNetConnector* object =
134 PluginResource::GetAs<FlashNetConnector>(resource_id);
135 return BoolToPPBool(!!object);
136 }
137
138 // Backend for both ConnectTcp and ConnectTcpAddress. To keep things generic,
139 // the message is passed in (on error, it's deleted).
140 int32_t ConnectWithMessage(FlashNetConnector* object,
141 IPC::Message* msg,
142 PP_FileHandle* socket_out,
143 struct PP_Flash_NetAddress* local_addr_out,
144 struct PP_Flash_NetAddress* remote_addr_out,
145 struct PP_CompletionCallback callback) {
146 scoped_ptr<IPC::Message> msg_deletor(msg);
147 if (object->HasCallback())
148 return PP_ERROR_INPROGRESS; // Can only have one pending request.
149
150 // Send the request, it will call us back via ConnectACK.
151 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(
152 object->instance());
153 if (!dispatcher)
154 return PP_ERROR_BADARGUMENT;
155 dispatcher->Send(msg_deletor.release());
156
157 object->SetCallback(callback, socket_out, local_addr_out, remote_addr_out);
158 return PP_OK_COMPLETIONPENDING;
159 }
160
161 int32_t ConnectTcp(PP_Resource connector_id,
162 const char* host,
163 uint16_t port,
164 PP_FileHandle* socket_out,
165 struct PP_Flash_NetAddress* local_addr_out,
166 struct PP_Flash_NetAddress* remote_addr_out,
167 struct PP_CompletionCallback callback) {
168 FlashNetConnector* object =
169 PluginResource::GetAs<FlashNetConnector>(connector_id);
170 if (!object)
171 return PP_ERROR_BADARGUMENT;
172 return ConnectWithMessage(
173 object,
174 new PpapiHostMsg_PPBFlashNetConnector_ConnectTcp(
175 INTERFACE_ID_PPB_FLASH_NETCONNECTOR,
176 object->host_resource(), host, port),
177 socket_out, local_addr_out, remote_addr_out, callback);
178 }
179
180 int32_t ConnectTcpAddress(PP_Resource connector_id,
181 const struct PP_Flash_NetAddress* addr,
182 PP_FileHandle* socket_out,
183 struct PP_Flash_NetAddress* local_addr_out,
184 struct PP_Flash_NetAddress* remote_addr_out,
185 struct PP_CompletionCallback callback) {
186 FlashNetConnector* object =
187 PluginResource::GetAs<FlashNetConnector>(connector_id);
188 if (!object)
189 return PP_ERROR_BADARGUMENT;
190 return ConnectWithMessage(
191 object,
192 new PpapiHostMsg_PPBFlashNetConnector_ConnectTcpAddress(
193 INTERFACE_ID_PPB_FLASH_NETCONNECTOR,
194 object->host_resource(), NetAddressToString(*addr)),
195 socket_out, local_addr_out, remote_addr_out, callback);
196 }
197
198 const PPB_Flash_NetConnector flash_netconnector_interface = {
199 &Create,
200 &IsFlashNetConnector,
201 &ConnectTcp,
202 &ConnectTcpAddress
203 };
204
205 InterfaceProxy* CreateFlashNetConnectorProxy(Dispatcher* dispatcher, 192 InterfaceProxy* CreateFlashNetConnectorProxy(Dispatcher* dispatcher,
206 const void* target_interface) { 193 const void* target_interface) {
207 return new PPB_Flash_NetConnector_Proxy(dispatcher, target_interface); 194 return new PPB_Flash_NetConnector_Proxy(dispatcher, target_interface);
208 } 195 }
209 196
210 } // namespace 197 } // namespace
211 198
212 PPB_Flash_NetConnector_Proxy::PPB_Flash_NetConnector_Proxy( 199 PPB_Flash_NetConnector_Proxy::PPB_Flash_NetConnector_Proxy(
213 Dispatcher* dispatcher, const void* target_interface) 200 Dispatcher* dispatcher, const void* target_interface)
214 : InterfaceProxy(dispatcher, target_interface), 201 : InterfaceProxy(dispatcher, target_interface),
215 callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { 202 callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
216 } 203 }
217 204
218 PPB_Flash_NetConnector_Proxy::~PPB_Flash_NetConnector_Proxy() { 205 PPB_Flash_NetConnector_Proxy::~PPB_Flash_NetConnector_Proxy() {
219 } 206 }
220 207
221 // static 208 // static
222 const InterfaceProxy::Info* PPB_Flash_NetConnector_Proxy::GetInfo() { 209 const InterfaceProxy::Info* PPB_Flash_NetConnector_Proxy::GetInfo() {
223 static const Info info = { 210 static const Info info = {
224 &flash_netconnector_interface, 211 ppapi::thunk::GetPPB_Flash_NetConnector_Thunk(),
225 PPB_FLASH_NETCONNECTOR_INTERFACE, 212 PPB_FLASH_NETCONNECTOR_INTERFACE,
226 INTERFACE_ID_PPB_FLASH_NETCONNECTOR, 213 INTERFACE_ID_PPB_FLASH_NETCONNECTOR,
227 false, 214 false,
228 &CreateFlashNetConnectorProxy 215 &CreateFlashNetConnectorProxy
229 }; 216 };
230 return &info; 217 return &info;
231 } 218 }
232 219
220 // static
221 PP_Resource PPB_Flash_NetConnector_Proxy::CreateProxyResource(
222 PP_Instance instance) {
223 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance);
224 if (!dispatcher)
225 return 0;
226
227 HostResource result;
228 dispatcher->Send(new PpapiHostMsg_PPBFlashNetConnector_Create(
229 INTERFACE_ID_PPB_FLASH_NETCONNECTOR, instance, &result));
230 if (result.is_null())
231 return 0;
232
233 linked_ptr<FlashNetConnector> object(new FlashNetConnector(result));
234 return PluginResourceTracker::GetInstance()->AddResource(object);
235 }
236
233 bool PPB_Flash_NetConnector_Proxy::OnMessageReceived(const IPC::Message& msg) { 237 bool PPB_Flash_NetConnector_Proxy::OnMessageReceived(const IPC::Message& msg) {
234 bool handled = true; 238 bool handled = true;
235 IPC_BEGIN_MESSAGE_MAP(PPB_Flash_NetConnector_Proxy, msg) 239 IPC_BEGIN_MESSAGE_MAP(PPB_Flash_NetConnector_Proxy, msg)
236 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlashNetConnector_Create, 240 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlashNetConnector_Create,
237 OnMsgCreate) 241 OnMsgCreate)
238 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlashNetConnector_ConnectTcp, 242 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlashNetConnector_ConnectTcp,
239 OnMsgConnectTcp) 243 OnMsgConnectTcp)
240 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlashNetConnector_ConnectTcpAddress, 244 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlashNetConnector_ConnectTcpAddress,
241 OnMsgConnectTcpAddress) 245 OnMsgConnectTcpAddress)
242 IPC_MESSAGE_HANDLER(PpapiMsg_PPBFlashNetConnector_ConnectACK, 246 IPC_MESSAGE_HANDLER(PpapiMsg_PPBFlashNetConnector_ConnectACK,
243 OnMsgConnectACK) 247 OnMsgConnectACK)
244 IPC_MESSAGE_UNHANDLED(handled = false) 248 IPC_MESSAGE_UNHANDLED(handled = false)
245 IPC_END_MESSAGE_MAP() 249 IPC_END_MESSAGE_MAP()
246 return handled; 250 return handled;
247 } 251 }
248 252
249 void PPB_Flash_NetConnector_Proxy::OnMsgCreate(PP_Instance instance_id, 253 void PPB_Flash_NetConnector_Proxy::OnMsgCreate(PP_Instance instance,
250 HostResource* result) { 254 HostResource* result) {
251 result->SetHostResource( 255 EnterFunctionNoLock<ResourceCreationAPI> enter(instance, true);
252 instance_id, 256 if (enter.succeeded()) {
253 ppb_flash_net_connector_target()->Create(instance_id)); 257 result->SetHostResource(
258 instance,
259 enter.functions()->CreateFlashNetConnector(instance));
260 }
254 } 261 }
255 262
256 void PPB_Flash_NetConnector_Proxy::OnMsgConnectTcp( 263 void PPB_Flash_NetConnector_Proxy::OnMsgConnectTcp(
257 const HostResource& resource, 264 const HostResource& resource,
258 const std::string& host, 265 const std::string& host,
259 uint16_t port) { 266 uint16_t port) {
260 ConnectCallbackInfo* info = new ConnectCallbackInfo(resource); 267 ConnectCallbackInfo* info = new ConnectCallbackInfo(resource);
261 CompletionCallback callback = callback_factory_.NewCallback( 268 CompletionCallback callback = callback_factory_.NewCallback(
262 &PPB_Flash_NetConnector_Proxy::OnCompleteCallbackInHost, info); 269 &PPB_Flash_NetConnector_Proxy::OnCompleteCallbackInHost, info);
263 270
264 int32_t result = ppb_flash_net_connector_target()->ConnectTcp( 271 EnterHostFromHostResource<PPB_Flash_NetConnector_API> enter(resource);
265 resource.host_resource(), host.c_str(), port, 272 int32_t result = PP_ERROR_BADRESOURCE;
266 &info->handle, &info->local_addr, &info->remote_addr, 273 if (enter.succeeded()) {
267 callback.pp_completion_callback()); 274 result = enter.object()->ConnectTcp(
275 host.c_str(), port, &info->handle, &info->local_addr,
276 &info->remote_addr, callback.pp_completion_callback());
277 }
268 if (result != PP_OK_COMPLETIONPENDING) 278 if (result != PP_OK_COMPLETIONPENDING)
269 OnCompleteCallbackInHost(result, info); 279 OnCompleteCallbackInHost(result, info);
270 } 280 }
271 281
272 void PPB_Flash_NetConnector_Proxy::OnMsgConnectTcpAddress( 282 void PPB_Flash_NetConnector_Proxy::OnMsgConnectTcpAddress(
273 const HostResource& resource, 283 const HostResource& resource,
274 const std::string& net_address_as_string) { 284 const std::string& net_address_as_string) {
275 ConnectCallbackInfo* info = new ConnectCallbackInfo(resource); 285 ConnectCallbackInfo* info = new ConnectCallbackInfo(resource);
276 CompletionCallback callback = callback_factory_.NewCallback( 286 CompletionCallback callback = callback_factory_.NewCallback(
277 &PPB_Flash_NetConnector_Proxy::OnCompleteCallbackInHost, info); 287 &PPB_Flash_NetConnector_Proxy::OnCompleteCallbackInHost, info);
278 288
279 PP_Flash_NetAddress net_address; 289 PP_Flash_NetAddress net_address;
280 StringToNetAddress(net_address_as_string, &net_address); 290 StringToNetAddress(net_address_as_string, &net_address);
281 291
282 int32_t result = ppb_flash_net_connector_target()->ConnectTcpAddress( 292 EnterHostFromHostResource<PPB_Flash_NetConnector_API> enter(resource);
283 resource.host_resource(), &net_address, 293 int32_t result = PP_ERROR_BADRESOURCE;
284 &info->handle, &info->local_addr, &info->remote_addr, 294 if (enter.succeeded()) {
285 callback.pp_completion_callback()); 295 result = enter.object()->ConnectTcpAddress(
296 &net_address, &info->handle, &info->local_addr, &info->remote_addr,
297 callback.pp_completion_callback());
298 }
286 if (result != PP_OK_COMPLETIONPENDING) 299 if (result != PP_OK_COMPLETIONPENDING)
287 OnCompleteCallbackInHost(result, info); 300 OnCompleteCallbackInHost(result, info);
288 } 301 }
289 302
290 void PPB_Flash_NetConnector_Proxy::OnMsgConnectACK( 303 void PPB_Flash_NetConnector_Proxy::OnMsgConnectACK(
291 const HostResource& host_resource, 304 const HostResource& host_resource,
292 int32_t result, 305 int32_t result,
293 IPC::PlatformFileForTransit handle, 306 IPC::PlatformFileForTransit handle,
294 const std::string& load_addr_as_string, 307 const std::string& load_addr_as_string,
295 const std::string& remote_addr_as_string) { 308 const std::string& remote_addr_as_string) {
296 base::PlatformFile platform_file = 309 base::PlatformFile platform_file =
297 IPC::PlatformFileForTransitToPlatformFile(handle); 310 IPC::PlatformFileForTransitToPlatformFile(handle);
298 311
299 PP_Resource plugin_resource = 312 EnterPluginFromHostResource<PPB_Flash_NetConnector_API> enter(host_resource);
300 PluginResourceTracker::GetInstance()->PluginResourceForHostResource( 313 if (enter.failed()) {
301 host_resource);
302 if (!plugin_resource) {
303 base::ClosePlatformFile(platform_file); 314 base::ClosePlatformFile(platform_file);
304 return; 315 return;
305 } 316 }
306 FlashNetConnector* object = 317 FlashNetConnector* object = static_cast<FlashNetConnector*>(enter.object());
307 PluginResource::GetAs<FlashNetConnector>(plugin_resource);
308 if (!object) {
309 base::ClosePlatformFile(platform_file);
310 return;
311 }
312
313 object->ConnectComplete(result, platform_file, 318 object->ConnectComplete(result, platform_file,
314 load_addr_as_string, remote_addr_as_string); 319 load_addr_as_string, remote_addr_as_string);
315 } 320 }
316 321
317 void PPB_Flash_NetConnector_Proxy::OnCompleteCallbackInHost( 322 void PPB_Flash_NetConnector_Proxy::OnCompleteCallbackInHost(
318 int32_t result, 323 int32_t result,
319 ConnectCallbackInfo* info) { 324 ConnectCallbackInfo* info) {
320 // Callback must always delete the info. 325 // Callback must always delete the info.
321 scoped_ptr<ConnectCallbackInfo> info_deletor(info); 326 scoped_ptr<ConnectCallbackInfo> info_deletor(info);
322 327
323 if (result == PP_OK) { 328 if (result == PP_OK) {
324 dispatcher()->Send(new PpapiMsg_PPBFlashNetConnector_ConnectACK( 329 dispatcher()->Send(new PpapiMsg_PPBFlashNetConnector_ConnectACK(
325 INTERFACE_ID_PPB_FLASH_NETCONNECTOR, 330 INTERFACE_ID_PPB_FLASH_NETCONNECTOR,
326 info->resource, result, 331 info->resource, result,
327 dispatcher()->ShareHandleWithRemote( 332 dispatcher()->ShareHandleWithRemote(
328 static_cast<base::PlatformFile>(info->handle), true), 333 static_cast<base::PlatformFile>(info->handle), true),
329 NetAddressToString(info->local_addr), 334 NetAddressToString(info->local_addr),
330 NetAddressToString(info->remote_addr))); 335 NetAddressToString(info->remote_addr)));
331 } else { 336 } else {
332 dispatcher()->Send(new PpapiMsg_PPBFlashNetConnector_ConnectACK( 337 dispatcher()->Send(new PpapiMsg_PPBFlashNetConnector_ConnectACK(
333 INTERFACE_ID_PPB_FLASH_NETCONNECTOR, 338 INTERFACE_ID_PPB_FLASH_NETCONNECTOR,
334 info->resource, result, 339 info->resource, result,
335 IPC::InvalidPlatformFileForTransit(), std::string(), std::string())); 340 IPC::InvalidPlatformFileForTransit(), std::string(), std::string()));
336 } 341 }
337 } 342 }
338 343
339 } // namespace proxy 344 } // namespace proxy
340 } // namespace pp 345 } // namespace pp
OLDNEW
« no previous file with comments | « ppapi/proxy/ppb_flash_net_connector_proxy.h ('k') | ppapi/proxy/ppb_image_data_proxy.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698