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

Side by Side Diff: webkit/plugins/ppapi/ppb_flash_impl.cc

Issue 6578007: PPB_Flash cleanup part 1: move the net connector stuff to its own files. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/ppapi/proxy
Patch Set: merged ToT Created 9 years, 10 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
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 "webkit/plugins/ppapi/ppb_flash_impl.h" 5 #include "webkit/plugins/ppapi/ppb_flash_impl.h"
6 6
7 #include <string.h> 7 #include <string.h>
8 8
9 #include <string>
10
9 #include "base/file_path.h" 11 #include "base/file_path.h"
10 #include "base/message_loop.h" 12 #include "base/message_loop.h"
11 #include "base/stringprintf.h"
12 #include "base/utf_string_conversions.h" 13 #include "base/utf_string_conversions.h"
13 #include "googleurl/src/gurl.h" 14 #include "googleurl/src/gurl.h"
14 #include "ppapi/c/dev/pp_file_info_dev.h" 15 #include "ppapi/c/dev/pp_file_info_dev.h"
15 #include "ppapi/c/dev/ppb_file_io_dev.h" 16 #include "ppapi/c/dev/ppb_file_io_dev.h"
16 #include "ppapi/c/pp_completion_callback.h" 17 #include "ppapi/c/pp_completion_callback.h"
17 #include "ppapi/c/private/ppb_flash.h" 18 #include "ppapi/c/private/ppb_flash.h"
18 #include "webkit/plugins/ppapi/common.h" 19 #include "webkit/plugins/ppapi/common.h"
19 #include "webkit/plugins/ppapi/error_util.h" 20 #include "webkit/plugins/ppapi/error_util.h"
20 #include "webkit/plugins/ppapi/plugin_delegate.h" 21 #include "webkit/plugins/ppapi/plugin_delegate.h"
21 #include "webkit/plugins/ppapi/plugin_module.h" 22 #include "webkit/plugins/ppapi/plugin_module.h"
22 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" 23 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
24 #include "webkit/plugins/ppapi/resource_tracker.h"
23 #include "webkit/plugins/ppapi/var.h" 25 #include "webkit/plugins/ppapi/var.h"
24 26
25 namespace webkit { 27 namespace webkit {
26 namespace ppapi { 28 namespace ppapi {
27 29
28 // PPB_Flash_Impl --------------------------------------------------------------
29
30 namespace { 30 namespace {
31 31
32 void SetInstanceAlwaysOnTop(PP_Instance pp_instance, PP_Bool on_top) { 32 void SetInstanceAlwaysOnTop(PP_Instance pp_instance, PP_Bool on_top) {
33 PluginInstance* instance = ResourceTracker::Get()->GetInstance(pp_instance); 33 PluginInstance* instance = ResourceTracker::Get()->GetInstance(pp_instance);
34 if (!instance) 34 if (!instance)
35 return; 35 return;
36 instance->set_always_on_top(PPBoolToBool(on_top)); 36 instance->set_always_on_top(PPBoolToBool(on_top));
37 } 37 }
38 38
39 PP_Var GetProxyForURL(PP_Instance pp_instance, const char* url) { 39 PP_Var GetProxyForURL(PP_Instance pp_instance, const char* url) {
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 &QuitMessageLoop, 245 &QuitMessageLoop,
246 }; 246 };
247 247
248 } // namespace 248 } // namespace
249 249
250 // static 250 // static
251 const PPB_Flash* PPB_Flash_Impl::GetInterface() { 251 const PPB_Flash* PPB_Flash_Impl::GetInterface() {
252 return &ppb_flash; 252 return &ppb_flash;
253 } 253 }
254 254
255 // PPB_Flash_NetConnector_Impl -------------------------------------------------
256
257 namespace {
258
259 PP_Resource Create(PP_Instance instance_id) {
260 PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id);
261 if (!instance)
262 return 0;
263
264 scoped_refptr<PPB_Flash_NetConnector_Impl> connector(
265 new PPB_Flash_NetConnector_Impl(instance));
266 return connector->GetReference();
267 }
268
269 PP_Bool IsFlashNetConnector(PP_Resource resource) {
270 return BoolToPPBool(!!Resource::GetAs<PPB_Flash_NetConnector_Impl>(resource));
271 }
272
273 int32_t ConnectTcp(PP_Resource connector_id,
274 const char* host,
275 uint16_t port,
276 PP_FileHandle* socket_out,
277 PP_Flash_NetAddress* local_addr_out,
278 PP_Flash_NetAddress* remote_addr_out,
279 PP_CompletionCallback callback) {
280 scoped_refptr<PPB_Flash_NetConnector_Impl> connector(
281 Resource::GetAs<PPB_Flash_NetConnector_Impl>(connector_id));
282 if (!connector.get())
283 return PP_ERROR_BADRESOURCE;
284
285 return connector->ConnectTcp(
286 host, port, socket_out, local_addr_out, remote_addr_out, callback);
287 }
288
289 int32_t ConnectTcpAddress(PP_Resource connector_id,
290 const PP_Flash_NetAddress* addr,
291 PP_FileHandle* socket_out,
292 PP_Flash_NetAddress* local_addr_out,
293 PP_Flash_NetAddress* remote_addr_out,
294 PP_CompletionCallback callback) {
295 scoped_refptr<PPB_Flash_NetConnector_Impl> connector(
296 Resource::GetAs<PPB_Flash_NetConnector_Impl>(connector_id));
297 if (!connector.get())
298 return PP_ERROR_BADRESOURCE;
299
300 return connector->ConnectTcpAddress(
301 addr, socket_out, local_addr_out, remote_addr_out, callback);
302 }
303
304 const PPB_Flash_NetConnector ppb_flash_netconnector = {
305 &Create,
306 &IsFlashNetConnector,
307 &ConnectTcp,
308 &ConnectTcpAddress,
309 };
310
311 } // namespace
312
313 PPB_Flash_NetConnector_Impl::PPB_Flash_NetConnector_Impl(
314 PluginInstance* instance)
315 : Resource(instance) {
316 }
317
318 PPB_Flash_NetConnector_Impl::~PPB_Flash_NetConnector_Impl() {
319 }
320
321 // static
322 const PPB_Flash_NetConnector* PPB_Flash_NetConnector_Impl::GetInterface() {
323 return &ppb_flash_netconnector;
324 }
325
326 PPB_Flash_NetConnector_Impl*
327 PPB_Flash_NetConnector_Impl::AsPPB_Flash_NetConnector_Impl() {
328 return this;
329 }
330
331 int32_t PPB_Flash_NetConnector_Impl::ConnectTcp(
332 const char* host,
333 uint16_t port,
334 PP_FileHandle* socket_out,
335 PP_Flash_NetAddress* local_addr_out,
336 PP_Flash_NetAddress* remote_addr_out,
337 PP_CompletionCallback callback) {
338 // |socket_out| is not optional.
339 if (!socket_out)
340 return PP_ERROR_BADARGUMENT;
341
342 if (!callback.func) {
343 NOTIMPLEMENTED();
344 return PP_ERROR_BADARGUMENT;
345 }
346
347 if (callback_.get() && !callback_->completed())
348 return PP_ERROR_INPROGRESS;
349
350 PP_Resource resource_id = GetReferenceNoAddRef();
351 if (!resource_id) {
352 NOTREACHED();
353 return PP_ERROR_FAILED;
354 }
355
356 int32_t rv = instance()->delegate()->ConnectTcp(this, host, port);
357 if (rv == PP_ERROR_WOULDBLOCK) {
358 // Record callback and output buffers.
359 callback_ = new TrackedCompletionCallback(
360 instance()->module()->GetCallbackTracker(), resource_id, callback);
361 socket_out_ = socket_out;
362 local_addr_out_ = local_addr_out;
363 remote_addr_out_ = remote_addr_out;
364 } else {
365 // This should never be completed synchronously successfully.
366 DCHECK_NE(rv, PP_OK);
367 }
368 return rv;
369 }
370
371 int32_t PPB_Flash_NetConnector_Impl::ConnectTcpAddress(
372 const PP_Flash_NetAddress* addr,
373 PP_FileHandle* socket_out,
374 PP_Flash_NetAddress* local_addr_out,
375 PP_Flash_NetAddress* remote_addr_out,
376 PP_CompletionCallback callback) {
377 // |socket_out| is not optional.
378 if (!socket_out)
379 return PP_ERROR_BADARGUMENT;
380
381 if (!callback.func) {
382 NOTIMPLEMENTED();
383 return PP_ERROR_BADARGUMENT;
384 }
385
386 if (callback_.get() && !callback_->completed())
387 return PP_ERROR_INPROGRESS;
388
389 PP_Resource resource_id = GetReferenceNoAddRef();
390 if (!resource_id) {
391 NOTREACHED();
392 return PP_ERROR_FAILED;
393 }
394
395 int32_t rv = instance()->delegate()->ConnectTcpAddress(this, addr);
396 if (rv == PP_ERROR_WOULDBLOCK) {
397 // Record callback and output buffers.
398 callback_ = new TrackedCompletionCallback(
399 instance()->module()->GetCallbackTracker(), resource_id, callback);
400 socket_out_ = socket_out;
401 local_addr_out_ = local_addr_out;
402 remote_addr_out_ = remote_addr_out;
403 } else {
404 // This should never be completed synchronously successfully.
405 DCHECK_NE(rv, PP_OK);
406 }
407 return rv;
408 }
409
410 void PPB_Flash_NetConnector_Impl::CompleteConnectTcp(
411 PP_FileHandle socket,
412 const PP_Flash_NetAddress& local_addr,
413 const PP_Flash_NetAddress& remote_addr) {
414 int32_t rv = PP_ERROR_ABORTED;
415 if (!callback_->aborted()) {
416 CHECK(!callback_->completed());
417
418 // Write output data.
419 *socket_out_ = socket;
420 if (socket != PP_kInvalidFileHandle) {
421 if (local_addr_out_)
422 *local_addr_out_ = local_addr;
423 if (remote_addr_out_)
424 *remote_addr_out_ = remote_addr;
425 rv = PP_OK;
426 } else {
427 rv = PP_ERROR_FAILED;
428 }
429 }
430
431 // Theoretically, the plugin should be allowed to try another |ConnectTcp()|
432 // from the callback.
433 scoped_refptr<TrackedCompletionCallback> callback;
434 callback.swap(callback_);
435 // Wipe everything else out for safety.
436 socket_out_ = NULL;
437 local_addr_out_ = NULL;
438 remote_addr_out_ = NULL;
439
440 callback->Run(rv); // Will complete abortively if necessary.
441 }
442
443 } // namespace ppapi 255 } // namespace ppapi
444 } // namespace webkit 256 } // namespace webkit
OLDNEW
« no previous file with comments | « webkit/plugins/ppapi/ppb_flash_impl.h ('k') | webkit/plugins/ppapi/ppb_flash_net_connector_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698