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

Side by Side Diff: webkit/glue/plugins/pepper_plugin_module.cc

Issue 3915002: Out of process Pepper (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 1 month 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 | « webkit/glue/plugins/pepper_plugin_module.h ('k') | no next file » | 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/glue/plugins/pepper_plugin_module.h" 5 #include "webkit/glue/plugins/pepper_plugin_module.h"
6 6
7 #include <set> 7 #include <set>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
(...skipping 29 matching lines...) Expand all
40 #include "ppapi/c/pp_module.h" 40 #include "ppapi/c/pp_module.h"
41 #include "ppapi/c/pp_resource.h" 41 #include "ppapi/c/pp_resource.h"
42 #include "ppapi/c/pp_var.h" 42 #include "ppapi/c/pp_var.h"
43 #include "ppapi/c/ppb_core.h" 43 #include "ppapi/c/ppb_core.h"
44 #include "ppapi/c/ppb_graphics_2d.h" 44 #include "ppapi/c/ppb_graphics_2d.h"
45 #include "ppapi/c/ppb_image_data.h" 45 #include "ppapi/c/ppb_image_data.h"
46 #include "ppapi/c/ppb_instance.h" 46 #include "ppapi/c/ppb_instance.h"
47 #include "ppapi/c/ppb_var.h" 47 #include "ppapi/c/ppb_var.h"
48 #include "ppapi/c/ppp.h" 48 #include "ppapi/c/ppp.h"
49 #include "ppapi/c/ppp_instance.h" 49 #include "ppapi/c/ppp_instance.h"
50 #include "ppapi/proxy/host_dispatcher.h"
51 #include "ppapi/proxy/ppapi_messages.h"
50 #include "webkit/glue/plugins/pepper_audio.h" 52 #include "webkit/glue/plugins/pepper_audio.h"
51 #include "webkit/glue/plugins/pepper_buffer.h" 53 #include "webkit/glue/plugins/pepper_buffer.h"
52 #include "webkit/glue/plugins/pepper_char_set.h" 54 #include "webkit/glue/plugins/pepper_char_set.h"
53 #include "webkit/glue/plugins/pepper_cursor_control.h" 55 #include "webkit/glue/plugins/pepper_cursor_control.h"
54 #include "webkit/glue/plugins/pepper_directory_reader.h" 56 #include "webkit/glue/plugins/pepper_directory_reader.h"
55 #include "webkit/glue/plugins/pepper_file_chooser.h" 57 #include "webkit/glue/plugins/pepper_file_chooser.h"
56 #include "webkit/glue/plugins/pepper_file_io.h" 58 #include "webkit/glue/plugins/pepper_file_io.h"
57 #include "webkit/glue/plugins/pepper_file_ref.h" 59 #include "webkit/glue/plugins/pepper_file_ref.h"
58 #include "webkit/glue/plugins/pepper_file_system.h" 60 #include "webkit/glue/plugins/pepper_file_system.h"
59 #include "webkit/glue/plugins/pepper_font.h" 61 #include "webkit/glue/plugins/pepper_font.h"
(...skipping 13 matching lines...) Expand all
73 #include "webkit/glue/plugins/pepper_var.h" 75 #include "webkit/glue/plugins/pepper_var.h"
74 #include "webkit/glue/plugins/pepper_video_decoder.h" 76 #include "webkit/glue/plugins/pepper_video_decoder.h"
75 #include "webkit/glue/plugins/pepper_widget.h" 77 #include "webkit/glue/plugins/pepper_widget.h"
76 #include "webkit/glue/plugins/ppb_private.h" 78 #include "webkit/glue/plugins/ppb_private.h"
77 #include "webkit/glue/plugins/ppb_private2.h" 79 #include "webkit/glue/plugins/ppb_private2.h"
78 80
79 #ifdef ENABLE_GPU 81 #ifdef ENABLE_GPU
80 #include "webkit/glue/plugins/pepper_graphics_3d.h" 82 #include "webkit/glue/plugins/pepper_graphics_3d.h"
81 #endif // ENABLE_GPU 83 #endif // ENABLE_GPU
82 84
85 #if defined(OS_POSIX)
86 #include "ipc/ipc_channel_posix.h"
87 #endif
88
83 namespace pepper { 89 namespace pepper {
84 90
85 namespace { 91 namespace {
86 92
87 // Maintains all currently loaded plugin libs for validating PP_Module 93 // Maintains all currently loaded plugin libs for validating PP_Module
88 // identifiers. 94 // identifiers.
89 typedef std::set<PluginModule*> PluginModuleSet; 95 typedef std::set<PluginModule*> PluginModuleSet;
90 96
91 PluginModuleSet* GetLivePluginSet() { 97 PluginModuleSet* GetLivePluginSet() {
92 static PluginModuleSet live_plugin_libs; 98 static PluginModuleSet live_plugin_libs;
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 const FilePath& path) { 329 const FilePath& path) {
324 // FIXME(brettw) do uniquifying of the plugin here like the NPAPI one. 330 // FIXME(brettw) do uniquifying of the plugin here like the NPAPI one.
325 331
326 scoped_refptr<PluginModule> lib(new PluginModule()); 332 scoped_refptr<PluginModule> lib(new PluginModule());
327 if (!lib->InitFromFile(path)) 333 if (!lib->InitFromFile(path))
328 return NULL; 334 return NULL;
329 335
330 return lib; 336 return lib;
331 } 337 }
332 338
339 // static
333 scoped_refptr<PluginModule> PluginModule::CreateInternalModule( 340 scoped_refptr<PluginModule> PluginModule::CreateInternalModule(
334 EntryPoints entry_points) { 341 EntryPoints entry_points) {
335 scoped_refptr<PluginModule> lib(new PluginModule()); 342 scoped_refptr<PluginModule> lib(new PluginModule());
336 if (!lib->InitFromEntryPoints(entry_points)) 343 if (!lib->InitFromEntryPoints(entry_points))
337 return NULL; 344 return NULL;
338 345
339 return lib; 346 return lib;
340 } 347 }
341 348
342 // static 349 // static
350 scoped_refptr<PluginModule> PluginModule::CreateOutOfProcessModule(
351 MessageLoop* ipc_message_loop,
352 const IPC::ChannelHandle& handle,
353 base::WaitableEvent* shutdown_event) {
354 scoped_refptr<PluginModule> lib(new PluginModule);
355 if (!lib->InitForOutOfProcess(ipc_message_loop, handle, shutdown_event))
356 return NULL;
357 return lib;
358 }
359
360 // static
343 const PPB_Core* PluginModule::GetCore() { 361 const PPB_Core* PluginModule::GetCore() {
344 return &core_interface; 362 return &core_interface;
345 } 363 }
346 364
347 bool PluginModule::InitFromEntryPoints(const EntryPoints& entry_points) { 365 bool PluginModule::InitFromEntryPoints(const EntryPoints& entry_points) {
348 if (initialized_) 366 if (initialized_)
349 return true; 367 return true;
350 368
351 // Attempt to run the initialization funciton. 369 // Attempt to run the initialization funciton.
352 int retval = entry_points.initialize_module(pp_module(), &GetInterface); 370 int retval = entry_points.initialize_module(pp_module(), &GetInterface);
(...skipping 21 matching lines...) Expand all
374 base::UnloadNativeLibrary(library); 392 base::UnloadNativeLibrary(library);
375 return false; 393 return false;
376 } 394 }
377 395
378 // We let InitFromEntryPoints() handle setting the all the internal state 396 // We let InitFromEntryPoints() handle setting the all the internal state
379 // of the object other than the |library_| reference. 397 // of the object other than the |library_| reference.
380 library_ = library; 398 library_ = library;
381 return true; 399 return true;
382 } 400 }
383 401
402 bool PluginModule::InitForOutOfProcess(MessageLoop* ipc_message_loop,
403 const IPC::ChannelHandle& handle,
404 base::WaitableEvent* shutdown_event) {
405 const PPB_Var_Deprecated* var_interface =
406 reinterpret_cast<const PPB_Var_Deprecated*>(
407 GetInterface(PPB_VAR_DEPRECATED_INTERFACE));
408 dispatcher_.reset(new pp::proxy::HostDispatcher(var_interface,
409 pp_module(), &GetInterface));
410
411 #if defined(OS_POSIX)
412 // If we received a ChannelHandle, register it now.
413 if (handle.socket.fd >= 0)
414 IPC::AddChannelSocket(handle.name, handle.socket.fd);
415 #endif
416
417 if (!dispatcher_->InitWithChannel(ipc_message_loop, handle.name, true,
418 shutdown_event)) {
419 dispatcher_.reset();
420 return false;
421 }
422
423 bool init_result = false;
424 dispatcher_->Send(new PpapiMsg_InitializeModule(pp_module(), &init_result));
425
426 if (!init_result) {
427 // TODO(brettw) does the module get unloaded in this case?
428 dispatcher_.reset();
429 return false;
430 }
431 return true;
432 }
433
384 // static 434 // static
385 bool PluginModule::LoadEntryPoints(const base::NativeLibrary& library, 435 bool PluginModule::LoadEntryPoints(const base::NativeLibrary& library,
386 EntryPoints* entry_points) { 436 EntryPoints* entry_points) {
387
388 entry_points->get_interface = 437 entry_points->get_interface =
389 reinterpret_cast<PPP_GetInterfaceFunc>( 438 reinterpret_cast<PPP_GetInterfaceFunc>(
390 base::GetFunctionPointerFromNativeLibrary(library, 439 base::GetFunctionPointerFromNativeLibrary(library,
391 "PPP_GetInterface")); 440 "PPP_GetInterface"));
392 if (!entry_points->get_interface) { 441 if (!entry_points->get_interface) {
393 LOG(WARNING) << "No PPP_GetInterface in plugin library"; 442 LOG(WARNING) << "No PPP_GetInterface in plugin library";
394 return false; 443 return false;
395 } 444 }
396 445
397 entry_points->initialize_module = 446 entry_points->initialize_module =
(...skipping 16 matching lines...) Expand all
414 } 463 }
415 464
416 PluginInstance* PluginModule::CreateInstance(PluginDelegate* delegate) { 465 PluginInstance* PluginModule::CreateInstance(PluginDelegate* delegate) {
417 const PPP_Instance* plugin_instance_interface = 466 const PPP_Instance* plugin_instance_interface =
418 reinterpret_cast<const PPP_Instance*>(GetPluginInterface( 467 reinterpret_cast<const PPP_Instance*>(GetPluginInterface(
419 PPP_INSTANCE_INTERFACE)); 468 PPP_INSTANCE_INTERFACE));
420 if (!plugin_instance_interface) { 469 if (!plugin_instance_interface) {
421 LOG(WARNING) << "Plugin doesn't support instance interface, failing."; 470 LOG(WARNING) << "Plugin doesn't support instance interface, failing.";
422 return NULL; 471 return NULL;
423 } 472 }
424 return new PluginInstance(delegate, this, plugin_instance_interface); 473 PluginInstance* instance = new PluginInstance(delegate, this,
474 plugin_instance_interface);
475 if (dispatcher_.get()) {
476 pp::proxy::HostDispatcher::SetForInstance(instance->pp_instance(),
477 dispatcher_.get());
478 }
479 return instance;
425 } 480 }
426 481
427 PluginInstance* PluginModule::GetSomeInstance() const { 482 PluginInstance* PluginModule::GetSomeInstance() const {
428 // This will generally crash later if there is not actually any instance to 483 // This will generally crash later if there is not actually any instance to
429 // return, so we force a crash now to make bugs easier to track down. 484 // return, so we force a crash now to make bugs easier to track down.
430 CHECK(!instances_.empty()); 485 CHECK(!instances_.empty());
431 return *instances_.begin(); 486 return *instances_.begin();
432 } 487 }
433 488
434 const void* PluginModule::GetPluginInterface(const char* name) const { 489 const void* PluginModule::GetPluginInterface(const char* name) const {
490 if (dispatcher_.get())
491 return dispatcher_->GetProxiedInterface(name);
492
493 // In-process plugins.
435 if (!entry_points_.get_interface) 494 if (!entry_points_.get_interface)
436 return NULL; 495 return NULL;
437 return entry_points_.get_interface(name); 496 return entry_points_.get_interface(name);
438 } 497 }
439 498
440 void PluginModule::InstanceCreated(PluginInstance* instance) { 499 void PluginModule::InstanceCreated(PluginInstance* instance) {
441 instances_.insert(instance); 500 instances_.insert(instance);
442 } 501 }
443 502
444 void PluginModule::InstanceDeleted(PluginInstance* instance) { 503 void PluginModule::InstanceDeleted(PluginInstance* instance) {
504 pp::proxy::HostDispatcher::RemoveForInstance(instance->pp_instance());
445 instances_.erase(instance); 505 instances_.erase(instance);
446 } 506 }
447 507
448 void PluginModule::AddNPObjectVar(ObjectVar* object_var) { 508 void PluginModule::AddNPObjectVar(ObjectVar* object_var) {
449 DCHECK(np_object_to_object_var_.find(object_var->np_object()) == 509 DCHECK(np_object_to_object_var_.find(object_var->np_object()) ==
450 np_object_to_object_var_.end()) << "ObjectVar already in map"; 510 np_object_to_object_var_.end()) << "ObjectVar already in map";
451 np_object_to_object_var_[object_var->np_object()] = object_var; 511 np_object_to_object_var_[object_var->np_object()] = object_var;
452 } 512 }
453 513
454 void PluginModule::RemoveNPObjectVar(ObjectVar* object_var) { 514 void PluginModule::RemoveNPObjectVar(ObjectVar* object_var) {
(...skipping 24 matching lines...) Expand all
479 live_plugin_objects_.insert(plugin_object); 539 live_plugin_objects_.insert(plugin_object);
480 } 540 }
481 541
482 void PluginModule::RemovePluginObject(PluginObject* plugin_object) { 542 void PluginModule::RemovePluginObject(PluginObject* plugin_object) {
483 // Don't actually verify that the object is in the set since during module 543 // Don't actually verify that the object is in the set since during module
484 // deletion we'll be in the process of freeing them. 544 // deletion we'll be in the process of freeing them.
485 live_plugin_objects_.erase(plugin_object); 545 live_plugin_objects_.erase(plugin_object);
486 } 546 }
487 547
488 } // namespace pepper 548 } // namespace pepper
OLDNEW
« no previous file with comments | « webkit/glue/plugins/pepper_plugin_module.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698