diff options
author | evan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-01-30 01:32:46 +0000 |
---|---|---|
committer | evan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-01-30 01:32:46 +0000 |
commit | 8674cdb422a69d1ab2b61ff88e61479a8430bec1 (patch) | |
tree | d4eba04aea00d9b8d6b24fe4eb086b280823ef3e | |
parent | 0e6860191f3dd4b4bf00ef71336b72c63d319180 (diff) | |
download | chromium_src-8674cdb422a69d1ab2b61ff88e61479a8430bec1.zip chromium_src-8674cdb422a69d1ab2b61ff88e61479a8430bec1.tar.gz chromium_src-8674cdb422a69d1ab2b61ff88e61479a8430bec1.tar.bz2 |
Rearrange plugin entry points code to abstract out Linux.
Review URL: http://codereview.chromium.org/19488
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@8943 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | webkit/glue/plugins/nphostapi.h | 5 | ||||
-rw-r--r-- | webkit/glue/plugins/plugin_lib.cc | 63 | ||||
-rw-r--r-- | webkit/glue/plugins/plugin_lib.h | 14 | ||||
-rw-r--r-- | webkit/glue/plugins/plugin_list.cc | 30 | ||||
-rw-r--r-- | webkit/glue/plugins/plugin_list.h | 23 | ||||
-rw-r--r-- | webkit/glue/plugins/plugin_list_win.cc | 24 |
6 files changed, 87 insertions, 72 deletions
diff --git a/webkit/glue/plugins/nphostapi.h b/webkit/glue/plugins/nphostapi.h index 2fd7a809..b39780b 100644 --- a/webkit/glue/plugins/nphostapi.h +++ b/webkit/glue/plugins/nphostapi.h @@ -266,8 +266,13 @@ typedef struct _NPNetscapeFuncs { // // NPAPI library entry points // +#if defined(OS_LINUX) +typedef NPError (API_CALL * NP_InitializeFunc)(NPNetscapeFuncs* pNFuncs, + NPPluginFuncs* pPFuncs); +#else typedef NPError (API_CALL * NP_InitializeFunc)(NPNetscapeFuncs* pFuncs); typedef NPError (API_CALL * NP_GetEntryPointsFunc)(NPPluginFuncs* pFuncs); +#endif typedef NPError (API_CALL * NP_ShutdownFunc)(void); #ifdef __cplusplus diff --git a/webkit/glue/plugins/plugin_lib.cc b/webkit/glue/plugins/plugin_lib.cc index cae72ce..4298e65 100644 --- a/webkit/glue/plugins/plugin_lib.cc +++ b/webkit/glue/plugins/plugin_lib.cc @@ -37,15 +37,11 @@ PluginLib* PluginLib::CreatePluginLib(const FilePath& filename) { } WebPluginInfo info; - NP_GetEntryPointsFunc np_getentrypoints; - NP_InitializeFunc np_initialize; - NP_ShutdownFunc np_shutdown; - if (!PluginList::ReadPluginInfo(filename, &info, &np_getentrypoints, - &np_initialize, &np_shutdown)) { + const PluginEntryPoints* entry_points = NULL; + if (!PluginList::ReadPluginInfo(filename, &info, &entry_points)) return NULL; - } - return new PluginLib(info, np_getentrypoints, np_initialize, np_shutdown); + return new PluginLib(info, entry_points); } void PluginLib::UnloadAllPlugins() { @@ -66,9 +62,7 @@ void PluginLib::ShutdownAllPlugins() { } PluginLib::PluginLib(const WebPluginInfo& info, - NP_GetEntryPointsFunc np_getentrypoints, - NP_InitializeFunc np_initialize, - NP_ShutdownFunc np_shutdown) + const PluginEntryPoints* entry_points) : web_plugin_info_(info), library_(0), initialized_(false), @@ -78,13 +72,13 @@ PluginLib::PluginLib(const WebPluginInfo& info, memset((void*)&plugin_funcs_, 0, sizeof(plugin_funcs_)); g_loaded_libs->push_back(this); - if (np_getentrypoints && np_initialize && np_shutdown) { + if (entry_points) { internal_ = true; - NP_GetEntryPoints_ = np_getentrypoints; - NP_Initialize_ = np_initialize; - NP_Shutdown_ = np_shutdown; + entry_points_ = *entry_points; } else { internal_ = false; + // We will read the entry points from the plugin directly. + memset(&entry_points_, 0, sizeof(entry_points_)); } } @@ -110,14 +104,19 @@ NPError PluginLib::NP_Initialize() { if (host == 0) return NPERR_GENERIC_ERROR; - NPError rv = NP_Initialize_(host->host_functions()); +#if defined(OS_LINUX) + NPError rv = entry_points_.np_initialize(host->host_functions(), + &plugin_funcs_); +#else + NPError rv = entry_points_.np_initialize(host->host_functions()); +#endif initialized_ = (rv == NPERR_NO_ERROR); return rv; } void PluginLib::NP_Shutdown(void) { DCHECK(initialized_); - NP_Shutdown_(); + entry_points_.np_shutdown(); } PluginInstance* PluginLib::CreateInstance(const std::string& mime_type) { @@ -163,20 +162,24 @@ bool PluginLib::Load() { rv = true; // assume success now - NP_Initialize_ = (NP_InitializeFunc)GetFunctionPointerFromNativeLibrary( - library, FUNCTION_NAME("NP_Initialize")); - if (NP_Initialize_ == 0) + entry_points_.np_initialize = + (NP_InitializeFunc)GetFunctionPointerFromNativeLibrary(library, + FUNCTION_NAME("NP_Initialize")); + if (entry_points_.np_initialize == 0) rv = false; - NP_GetEntryPoints_ = - (NP_GetEntryPointsFunc)GetFunctionPointerFromNativeLibrary( - library, FUNCTION_NAME("NP_GetEntryPoints")); - if (NP_GetEntryPoints_ == 0) +#if !defined(OS_LINUX) + entry_points_.np_getentrypoints = + (NP_GetEntryPointsFunc)GetFunctionPointerFromNativeLibrary(library, + FUNCTION_NAME("NP_GetEntryPoints")); + if (entry_points_.np_getentrypoints == 0) rv = false; +#endif - NP_Shutdown_ = (NP_ShutdownFunc)GetFunctionPointerFromNativeLibrary( - library, FUNCTION_NAME("NP_Shutdown")); - if (NP_Shutdown_ == 0) + entry_points_.np_shutdown = + (NP_ShutdownFunc)GetFunctionPointerFromNativeLibrary(library, + FUNCTION_NAME("NP_Shutdown")); + if (entry_points_.np_shutdown == 0) rv = false; } else { rv = true; @@ -185,8 +188,12 @@ bool PluginLib::Load() { if (rv) { plugin_funcs_.size = sizeof(plugin_funcs_); plugin_funcs_.version = (NP_VERSION_MAJOR << 8) | NP_VERSION_MINOR; - if (NP_GetEntryPoints_(&plugin_funcs_) != NPERR_NO_ERROR) +#if !defined(OS_LINUX) + if (entry_points_.np_getentrypoints(&plugin_funcs_) != NPERR_NO_ERROR) rv = false; +#else + // On Linux, we get the plugin entry points during NP_Initialize. +#endif } if (!internal_) { @@ -242,7 +249,7 @@ void PluginLib::Unload() { if (defer_unload) { FreePluginLibraryTask* free_library_task = - new FreePluginLibraryTask(library_, NP_Shutdown_); + new FreePluginLibraryTask(library_, entry_points_.np_shutdown); MessageLoop::current()->PostTask(FROM_HERE, free_library_task); } else { Shutdown(); diff --git a/webkit/glue/plugins/plugin_lib.h b/webkit/glue/plugins/plugin_lib.h index f8cc74a..7207bc4 100644 --- a/webkit/glue/plugins/plugin_lib.h +++ b/webkit/glue/plugins/plugin_lib.h @@ -14,9 +14,8 @@ #include "base/file_path.h" #include "base/ref_counted.h" #include "base/scoped_ptr.h" -#include "webkit/glue/plugins/nphostapi.h" +#include "webkit/glue/plugins/plugin_list.h" #include "webkit/glue/webplugin.h" -#include "third_party/npapi/bindings/npapi.h" struct WebPluginInfo; @@ -71,10 +70,9 @@ class PluginLib : public base::RefCounted<PluginLib> { private: // Creates a new PluginLib. + // |entry_points| is non-NULL for internal plugins. PluginLib(const WebPluginInfo& info, - NP_GetEntryPointsFunc np_getentrypoints, - NP_InitializeFunc np_initialize, - NP_ShutdownFunc np_shutdown); + const PluginEntryPoints* entry_points); // Attempts to load the plugin from the library. // Returns true if it is a legitimate plugin, false otherwise @@ -122,10 +120,8 @@ class PluginLib : public base::RefCounted<PluginLib> { NPSavedData *saved_data_; // persisted plugin info for NPAPI int instance_count_; // count of plugins in use - // C-style function pointers - NP_InitializeFunc NP_Initialize_; - NP_GetEntryPointsFunc NP_GetEntryPoints_; - NP_ShutdownFunc NP_Shutdown_; + // Function pointers to entry points into the plugin. + PluginEntryPoints entry_points_; DISALLOW_EVIL_CONSTRUCTORS(PluginLib); }; diff --git a/webkit/glue/plugins/plugin_list.cc b/webkit/glue/plugins/plugin_list.cc index 9befa8f..3f308d6 100644 --- a/webkit/glue/plugins/plugin_list.cc +++ b/webkit/glue/plugins/plugin_list.cc @@ -53,26 +53,21 @@ void PluginList::RegisterInternalPlugin(const PluginVersionInfo& info) { bool PluginList::ReadPluginInfo(const FilePath &filename, WebPluginInfo* info, - NP_GetEntryPointsFunc* np_getentrypoints, - NP_InitializeFunc* np_initialize, - NP_ShutdownFunc* np_shutdown) { + const PluginEntryPoints** entry_points) { // We access the singleton directly, and not through Singleton(), since // we might be in a LoadPlugins call and don't want to call it recursively! const std::vector<PluginVersionInfo>& internal_plugins = g_singleton.Pointer()->internal_plugins_; for (size_t i = 0; i < internal_plugins.size(); ++i) { if (filename == internal_plugins[i].path) { - *np_getentrypoints = internal_plugins[i].np_getentrypoints; - *np_initialize = internal_plugins[i].np_initialize; - *np_shutdown = internal_plugins[i].np_shutdown; + *entry_points = &internal_plugins[i].entry_points; return CreateWebPluginInfo(internal_plugins[i], info); } } // Not an internal plugin. - *np_getentrypoints = NULL; - *np_initialize = NULL; - *np_shutdown = NULL; + *entry_points = NULL; + return PluginLib::ReadWebPluginInfo(filename, info); } @@ -133,9 +128,11 @@ PluginList::PluginList() : plugins_loaded_(false) { L"*", L"", L"", - default_plugin::NP_GetEntryPoints, - default_plugin::NP_Initialize, - default_plugin::NP_Shutdown + { + default_plugin::NP_GetEntryPoints, + default_plugin::NP_Initialize, + default_plugin::NP_Shutdown + } }; internal_plugins_.push_back(default_plugin); @@ -173,13 +170,10 @@ void PluginList::LoadPlugins(bool refresh) { void PluginList::LoadPlugin(const FilePath &path) { WebPluginInfo plugin_info; - NP_GetEntryPointsFunc np_getentrypoints; - NP_InitializeFunc np_initialize; - NP_ShutdownFunc np_shutdown; - if (!ReadPluginInfo(path, &plugin_info, &np_getentrypoints, &np_initialize, - &np_shutdown)) { + const PluginEntryPoints* entry_points; + + if (!ReadPluginInfo(path, &plugin_info, &entry_points)) return; - } if (!ShouldLoadPlugin(plugin_info)) return; diff --git a/webkit/glue/plugins/plugin_list.h b/webkit/glue/plugins/plugin_list.h index d71d2ba..d64131e 100644 --- a/webkit/glue/plugins/plugin_list.h +++ b/webkit/glue/plugins/plugin_list.h @@ -32,6 +32,16 @@ namespace NPAPI class PluginInstance; +// This struct holds entry points into a plugin. The entry points are +// slightly different between Linux and other platforms. +struct PluginEntryPoints { +#if !defined(OS_LINUX) + NP_GetEntryPointsFunc np_getentrypoints; +#endif + NP_InitializeFunc np_initialize; + NP_ShutdownFunc np_shutdown; +}; + // This struct fully describes a plugin. For external plugins, it's read in from // the version info of the dll; For internal plugins, it's predefined and // includes addresses of entry functions. (Yes, it's Win32 NPAPI-centric, but @@ -46,10 +56,8 @@ struct PluginVersionInfo { std::wstring mime_types; std::wstring file_extensions; std::wstring type_descriptions; - // Entry points for internal plugins, NULL for external ones. - NP_GetEntryPointsFunc np_getentrypoints; - NP_InitializeFunc np_initialize; - NP_ShutdownFunc np_shutdown; + // Entry points for internal plugins. Pointers are NULL for external plugins. + PluginEntryPoints entry_points; }; // The PluginList is responsible for loading our NPAPI based plugins. It does @@ -79,13 +87,12 @@ class PluginList { // Creates a WebPluginInfo structure given a plugin's path. On success // returns true, with the information being put into "info". If it's an - // internal plugin, the function pointers are returned as well. + // internal plugin, "entry_points" is filled in as well with a + // internally-owned PluginEntryPoints pointer. // Returns false if the library couldn't be found, or if it's not a plugin. static bool ReadPluginInfo(const FilePath& filename, WebPluginInfo* info, - NP_GetEntryPointsFunc* np_getentrypoints, - NP_InitializeFunc* np_initialize, - NP_ShutdownFunc* np_shutdown); + const PluginEntryPoints** entry_points); // Populate a WebPluginInfo from a PluginVersionInfo. static bool CreateWebPluginInfo(const PluginVersionInfo& pvi, diff --git a/webkit/glue/plugins/plugin_list_win.cc b/webkit/glue/plugins/plugin_list_win.cc index 37db580..cfe79a4 100644 --- a/webkit/glue/plugins/plugin_list_win.cc +++ b/webkit/glue/plugins/plugin_list_win.cc @@ -217,9 +217,11 @@ void PluginList::PlatformInit() { L"application/x-oleobject|application/oleobject", L"*|*", L"", - activex_shim::ActiveX_Shim_NP_GetEntryPoints, - activex_shim::ActiveX_Shim_NP_Initialize, - activex_shim::ActiveX_Shim_NP_Shutdown + { + activex_shim::ActiveX_Shim_NP_GetEntryPoints, + activex_shim::ActiveX_Shim_NP_Initialize, + activex_shim::ActiveX_Shim_NP_Shutdown + } }, { FilePath(kActiveXShimFileNameForMediaPlayer), @@ -231,9 +233,11 @@ void PluginList::PlatformInit() { L"audio/x-ms-wax|video/x-ms-wmv|video/x-ms-wvx", L"*|*|*|*|asf,asx,*|wm,*|wma,*|wax,*|wmv,*|wvx,*", L"", - activex_shim::ActiveX_Shim_NP_GetEntryPoints, - activex_shim::ActiveX_Shim_NP_Initialize, - activex_shim::ActiveX_Shim_NP_Shutdown + { + activex_shim::ActiveX_Shim_NP_GetEntryPoints, + activex_shim::ActiveX_Shim_NP_Initialize, + activex_shim::ActiveX_Shim_NP_Shutdown + } }, #ifdef GEARS_STATIC_LIB { @@ -244,9 +248,11 @@ void PluginList::PlatformInit() { L"application/x-googlegears", L"", L"", - Gears_NP_GetEntryPoints, - Gears_NP_Initialize, - Gears_NP_Shutdown + { + Gears_NP_GetEntryPoints, + Gears_NP_Initialize, + Gears_NP_Shutdown + } }, #endif }; |