diff options
author | ajwong@chromium.org <ajwong@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-28 15:13:10 +0000 |
---|---|---|
committer | ajwong@chromium.org <ajwong@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-28 15:13:10 +0000 |
commit | 8cc9dd62ea7a7d60ce5486fbd62baf9266fa0f15 (patch) | |
tree | 2c8b16963720b487ff79da260c4789891df4bd99 /webkit | |
parent | 241a4f1e1c2164ae31b37cec47ffde2e0c71aed8 (diff) | |
download | chromium_src-8cc9dd62ea7a7d60ce5486fbd62baf9266fa0f15.zip chromium_src-8cc9dd62ea7a7d60ce5486fbd62baf9266fa0f15.tar.gz chromium_src-8cc9dd62ea7a7d60ce5486fbd62baf9266fa0f15.tar.bz2 |
Add in support for internal pepper plugins into the PepperPluginRegistry and pepper::PluginModule.
Used Chromoting's plugin as the first attempt at using this interface.
BUG=none
TEST=compiles
Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=50667
Review URL: http://codereview.chromium.org/2843018
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@50976 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r-- | webkit/glue/plugins/pepper_plugin_module.cc | 109 | ||||
-rw-r--r-- | webkit/glue/plugins/pepper_plugin_module.h | 41 |
2 files changed, 104 insertions, 46 deletions
diff --git a/webkit/glue/plugins/pepper_plugin_module.cc b/webkit/glue/plugins/pepper_plugin_module.cc index 3f5d767..4bb5ea11 100644 --- a/webkit/glue/plugins/pepper_plugin_module.cc +++ b/webkit/glue/plugins/pepper_plugin_module.cc @@ -44,9 +44,6 @@ #include "webkit/glue/plugins/pepper_url_response_info.h" #include "webkit/glue/plugins/pepper_var.h" -typedef bool (*PPP_InitializeModuleFunc)(PP_Module, PPB_GetInterface); -typedef void (*PPP_ShutdownModuleFunc)(); - namespace pepper { namespace { @@ -187,11 +184,9 @@ const void* GetInterface(const char* name) { } // namespace -PluginModule::PluginModule(const FilePath& filename) - : filename_(filename), - initialized_(false), - library_(0), - ppp_get_interface_(NULL) { +PluginModule::PluginModule() + : initialized_(false), + library_(NULL) { GetMainThreadMessageLoop(); // Initialize the main thread message loop. GetLivePluginSet()->insert(this); } @@ -203,25 +198,31 @@ PluginModule::~PluginModule() { GetLivePluginSet()->erase(this); - if (library_) { - PPP_ShutdownModuleFunc shutdown_module = - reinterpret_cast<PPP_ShutdownModuleFunc>( - base::GetFunctionPointerFromNativeLibrary(library_, - "PPP_ShutdownModule")); - if (shutdown_module) - shutdown_module(); + if (entry_points_.shutdown_module) + entry_points_.shutdown_module(); + + if (library_) base::UnloadNativeLibrary(library_); - } } // static scoped_refptr<PluginModule> PluginModule::CreateModule( - const FilePath& filename) { + const FilePath& path) { // FIXME(brettw) do uniquifying of the plugin here like the NPAPI one. - scoped_refptr<PluginModule> lib(new PluginModule(filename)); - if (!lib->Load()) - lib = NULL; + scoped_refptr<PluginModule> lib(new PluginModule()); + if (!lib->InitFromFile(path)) + return NULL; + + return lib; +} + +scoped_refptr<PluginModule> PluginModule::CreateInternalModule( + EntryPoints entry_points) { + scoped_refptr<PluginModule> lib(new PluginModule()); + if (!lib->InitFromEntryPoints(entry_points)) + return NULL; + return lib; } @@ -233,39 +234,71 @@ PluginModule* PluginModule::FromPPModule(PP_Module module) { return lib; } -bool PluginModule::Load() { +bool PluginModule::InitFromEntryPoints(const EntryPoints& entry_points) { if (initialized_) return true; + + // Attempt to run the initialization funciton. + int retval = entry_points.initialize_module(GetPPModule(), &GetInterface); + if (retval != 0) { + LOG(WARNING) << "PPP_InitializeModule returned failure " << retval; + return false; + } + + entry_points_ = entry_points; initialized_ = true; + return true; +} - library_ = base::LoadNativeLibrary(filename_); - if (!library_) +bool PluginModule::InitFromFile(const FilePath& path) { + if (initialized_) + return true; + + base::NativeLibrary library = base::LoadNativeLibrary(path); + if (!library) return false; - // Save the GetInterface function pointer for later. - ppp_get_interface_ = + EntryPoints entry_points; + if (!LoadEntryPoints(library, &entry_points) || + !InitFromEntryPoints(entry_points)) { + base::UnloadNativeLibrary(library); + return false; + } + + // We let InitFromEntryPoints() handle setting the all the internal state + // of the object other than the |library_| reference. + library_ = library; + return true; +} + +// static +bool PluginModule::LoadEntryPoints(const base::NativeLibrary& library, + EntryPoints* entry_points) { + + entry_points->get_interface = reinterpret_cast<PPP_GetInterfaceFunc>( - base::GetFunctionPointerFromNativeLibrary(library_, + base::GetFunctionPointerFromNativeLibrary(library, "PPP_GetInterface")); - if (!ppp_get_interface_) { + if (!entry_points->get_interface) { LOG(WARNING) << "No PPP_GetInterface in plugin library"; return false; } - // Call the plugin initialize function. - PPP_InitializeModuleFunc initialize_module = + entry_points->initialize_module = reinterpret_cast<PPP_InitializeModuleFunc>( - base::GetFunctionPointerFromNativeLibrary(library_, + base::GetFunctionPointerFromNativeLibrary(library, "PPP_InitializeModule")); - if (!initialize_module) { + if (!entry_points->initialize_module) { LOG(WARNING) << "No PPP_InitializeModule in plugin library"; return false; } - int retval = initialize_module(GetPPModule(), &GetInterface); - if (retval != 0) { - LOG(WARNING) << "PPP_InitializeModule returned failure " << retval; - return false; - } + + // It's okay for PPP_ShutdownModule to not be defined and shutdown_module to + // be NULL. + entry_points->shutdown_module = + reinterpret_cast<PPP_ShutdownModuleFunc>( + base::GetFunctionPointerFromNativeLibrary(library, + "PPP_ShutdownModule")); return true; } @@ -293,9 +326,9 @@ PluginInstance* PluginModule::GetSomeInstance() const { } const void* PluginModule::GetPluginInterface(const char* name) const { - if (!ppp_get_interface_) + if (!entry_points_.get_interface) return NULL; - return ppp_get_interface_(name); + return entry_points_.get_interface(name); } void PluginModule::InstanceCreated(PluginInstance* instance) { diff --git a/webkit/glue/plugins/pepper_plugin_module.h b/webkit/glue/plugins/pepper_plugin_module.h index 0498c45..1b2d9fb 100644 --- a/webkit/glue/plugins/pepper_plugin_module.h +++ b/webkit/glue/plugins/pepper_plugin_module.h @@ -12,6 +12,7 @@ #include "base/native_library.h" #include "base/ref_counted.h" #include "third_party/ppapi/c/pp_module.h" +#include "third_party/ppapi/c/ppb.h" namespace pepper { @@ -20,9 +21,27 @@ class PluginInstance; class PluginModule : public base::RefCounted<PluginModule> { public: + typedef const void* (*PPP_GetInterfaceFunc)(const char*); + typedef int (*PPP_InitializeModuleFunc)(PP_Module, PPB_GetInterface); + typedef void (*PPP_ShutdownModuleFunc)(); + + struct EntryPoints { + EntryPoints() + : get_interface(NULL), + initialize_module(NULL), + shutdown_module(NULL) { + } + + PPP_GetInterfaceFunc get_interface; + PPP_InitializeModuleFunc initialize_module; + PPP_ShutdownModuleFunc shutdown_module; + }; + ~PluginModule(); - static scoped_refptr<PluginModule> CreateModule(const FilePath& filename); + static scoped_refptr<PluginModule> CreateModule(const FilePath& path); + static scoped_refptr<PluginModule> CreateInternalModule( + EntryPoints entry_points); // Converts the given module ID to an actual module object. Will return NULL // if the module is invalid. @@ -47,18 +66,24 @@ class PluginModule : public base::RefCounted<PluginModule> { void InstanceDeleted(PluginInstance* instance); private: - typedef const void* (*PPP_GetInterfaceFunc)(const char*); - - explicit PluginModule(const FilePath& filename); + PluginModule(); - bool Load(); - - FilePath filename_; + bool InitFromEntryPoints(const EntryPoints& entry_points); + bool InitFromFile(const FilePath& path); + static bool LoadEntryPoints(const base::NativeLibrary& library, + EntryPoints* entry_points); bool initialized_; + + // Holds a reference to the base::NativeLibrary handle if this PluginModule + // instance wraps functions loaded from a library. Can be NULL. If + // |library_| is non-NULL, PluginModule will attempt to unload the library + // during destruction. base::NativeLibrary library_; - PPP_GetInterfaceFunc ppp_get_interface_; + // Contains pointers to the entry points of the actual plugin + // implementation. + EntryPoints entry_points_; // Non-owning pointers to all instances associated with this module. When // there are no more instances, this object should be deleted. |