diff options
author | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-01-29 01:53:24 +0000 |
---|---|---|
committer | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-01-29 01:53:24 +0000 |
commit | 8ff260907719175f91a380fba3f6114af23725dd (patch) | |
tree | 71cbfd4960535bcbb71ca06c82e013d19c50e605 | |
parent | a6c712d9b9f2459273ad7616e03ee5f823d539ca (diff) | |
download | chromium_src-8ff260907719175f91a380fba3f6114af23725dd.zip chromium_src-8ff260907719175f91a380fba3f6114af23725dd.tar.gz chromium_src-8ff260907719175f91a380fba3f6114af23725dd.tar.bz2 |
Make adding internal plugins easier (and allow it to be dynamic). This code also cleans up the internal plugin handling some more.
Review URL: http://codereview.chromium.org/19443
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@8855 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/test/plugin/plugin_tests.vcproj | 4 | ||||
-rw-r--r-- | webkit/glue/plugins/plugin_lib.cc | 60 | ||||
-rw-r--r-- | webkit/glue/plugins/plugin_lib.h | 36 | ||||
-rw-r--r-- | webkit/glue/plugins/plugin_lib_linux.cc | 9 | ||||
-rw-r--r-- | webkit/glue/plugins/plugin_lib_mac.mm | 32 | ||||
-rw-r--r-- | webkit/glue/plugins/plugin_lib_win.cc | 106 | ||||
-rw-r--r-- | webkit/glue/plugins/plugin_list.cc | 105 | ||||
-rw-r--r-- | webkit/glue/plugins/plugin_list.h | 50 | ||||
-rw-r--r-- | webkit/glue/plugins/plugin_list_win.cc | 56 |
9 files changed, 221 insertions, 237 deletions
diff --git a/chrome/test/plugin/plugin_tests.vcproj b/chrome/test/plugin/plugin_tests.vcproj index 9c2fa00..0e43ea8 100644 --- a/chrome/test/plugin/plugin_tests.vcproj +++ b/chrome/test/plugin/plugin_tests.vcproj @@ -17,7 +17,7 @@ <Configuration Name="Debug|Win32" ConfigurationType="1" - InheritedPropertySheets="$(SolutionDir)..\build\common.vsprops;$(SolutionDir)..\build\debug.vsprops;..\..\tools\build\win\precompiled_wtl.vsprops;$(SolutionDir)..\third_party\libxml\build\using_libxml.vsprops;$(SolutionDir)..\third_party\libxslt\build\using_libxslt.vsprops;..\..\tools\build\win\unit_test.vsprops;..\..\tools\build\win\ui_test.vsprops;$(SolutionDir)..\skia\using_skia.vsprops;$(SolutionDir)..\testing\using_gtest.vsprops" + InheritedPropertySheets="$(SolutionDir)..\build\common.vsprops;$(SolutionDir)..\build\debug.vsprops;..\..\tools\build\win\precompiled_wtl.vsprops;$(SolutionDir)..\third_party\libxml\build\using_libxml.vsprops;$(SolutionDir)..\third_party\libxslt\build\using_libxslt.vsprops;..\..\tools\build\win\unit_test.vsprops;..\..\tools\build\win\ui_test.vsprops;$(SolutionDir)..\skia\using_skia.vsprops;$(SolutionDir)..\testing\using_gtest.vsprops;$(SolutionDir)..\third_party\npapi\using_npapi.vsprops" > <Tool Name="VCPreBuildEventTool" @@ -78,7 +78,7 @@ <Configuration Name="Release|Win32" ConfigurationType="1" - InheritedPropertySheets="$(SolutionDir)..\build\common.vsprops;$(SolutionDir)..\build\release.vsprops;$(SolutionDir)..\third_party\libxml\build\using_libxml.vsprops;$(SolutionDir)..\third_party\libxslt\build\using_libxslt.vsprops;..\..\tools\build\win\unit_test.vsprops;..\..\tools\build\win\ui_test.vsprops;$(SolutionDir)..\skia\using_skia.vsprops;$(SolutionDir)..\testing\using_gtest.vsprops" + InheritedPropertySheets="$(SolutionDir)..\build\common.vsprops;$(SolutionDir)..\build\release.vsprops;$(SolutionDir)..\third_party\libxml\build\using_libxml.vsprops;$(SolutionDir)..\third_party\libxslt\build\using_libxslt.vsprops;..\..\tools\build\win\unit_test.vsprops;..\..\tools\build\win\ui_test.vsprops;$(SolutionDir)..\skia\using_skia.vsprops;$(SolutionDir)..\testing\using_gtest.vsprops;$(SolutionDir)..\third_party\npapi\using_npapi.vsprops" > <Tool Name="VCPreBuildEventTool" diff --git a/webkit/glue/plugins/plugin_lib.cc b/webkit/glue/plugins/plugin_lib.cc index e5a3352..cae72ce 100644 --- a/webkit/glue/plugins/plugin_lib.cc +++ b/webkit/glue/plugins/plugin_lib.cc @@ -13,6 +13,7 @@ #include "webkit/glue/webkit_glue.h" #include "webkit/glue/plugins/plugin_instance.h" #include "webkit/glue/plugins/plugin_host.h" +#include "webkit/glue/plugins/plugin_list.h" namespace NPAPI { @@ -39,8 +40,8 @@ PluginLib* PluginLib::CreatePluginLib(const FilePath& filename) { NP_GetEntryPointsFunc np_getentrypoints; NP_InitializeFunc np_initialize; NP_ShutdownFunc np_shutdown; - if (!ReadWebPluginInfo(filename, &info, &np_getentrypoints, &np_initialize, - &np_shutdown)) { + if (!PluginList::ReadPluginInfo(filename, &info, &np_getentrypoints, + &np_initialize, &np_shutdown)) { return NULL; } @@ -259,59 +260,4 @@ void PluginLib::Shutdown() { } } -// Creates WebPluginInfo structure based on read in or built in -// PluginVersionInfo. -/* static */ -bool PluginLib::CreateWebPluginInfo(const PluginVersionInfo& pvi, - WebPluginInfo* info, - NP_GetEntryPointsFunc* np_getentrypoints, - NP_InitializeFunc* np_initialize, - NP_ShutdownFunc* np_shutdown) { - std::vector<std::string> mime_types, file_extensions; - std::vector<std::wstring> descriptions; - SplitString(WideToUTF8(pvi.mime_types), '|', &mime_types); - SplitString(WideToUTF8(pvi.file_extensions), '|', &file_extensions); - SplitString(pvi.type_descriptions, '|', &descriptions); - - info->mime_types.clear(); - - if (mime_types.empty()) - return false; - - info->name = pvi.product_name; - info->desc = pvi.file_description; - info->version = pvi.file_version; - info->path = FilePath(pvi.path); - - for (size_t i = 0; i < mime_types.size(); ++i) { - WebPluginMimeType mime_type; - mime_type.mime_type = StringToLowerASCII(mime_types[i]); - if (file_extensions.size() > i) - SplitString(file_extensions[i], ',', &mime_type.file_extensions); - - if (descriptions.size() > i) { - mime_type.description = descriptions[i]; - - // On Windows, the description likely has a list of file extensions - // embedded in it (e.g. "SurfWriter file (*.swr)"). Remove an extension - // list from the description if it is present. - size_t ext = mime_type.description.find(L"(*"); - if (ext != std::wstring::npos) { - if (ext > 1 && mime_type.description[ext -1] == ' ') - ext--; - - mime_type.description.erase(ext); - } - } - - info->mime_types.push_back(mime_type); - } - - *np_getentrypoints = pvi.np_getentrypoints; - *np_initialize = pvi.np_initialize; - *np_shutdown = pvi.np_shutdown; - - return true; -} - } // namespace NPAPI diff --git a/webkit/glue/plugins/plugin_lib.h b/webkit/glue/plugins/plugin_lib.h index 3febcf5..f8cc74a 100644 --- a/webkit/glue/plugins/plugin_lib.h +++ b/webkit/glue/plugins/plugin_lib.h @@ -25,26 +25,6 @@ namespace NPAPI class PluginInstance; -// 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 -// it'll do for holding descriptions of internal plugins cross-platform.) -struct PluginVersionInfo { - const FilePath::CharType* path; - // Info about the plugin itself. - const wchar_t* product_name; - const wchar_t* file_description; - const wchar_t* file_version; - // Info about the data types that the plugin supports. - const wchar_t* mime_types; - const wchar_t* file_extensions; - const wchar_t* type_descriptions; - // Entry points for internal plugins, NULL for external ones. - NP_GetEntryPointsFunc np_getentrypoints; - NP_InitializeFunc np_initialize; - NP_ShutdownFunc np_shutdown; -}; - // A PluginLib is a single NPAPI Plugin Library, and is the lifecycle // manager for new PluginInstances. class PluginLib : public base::RefCounted<PluginLib> { @@ -53,14 +33,9 @@ class PluginLib : public base::RefCounted<PluginLib> { virtual ~PluginLib(); // 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. + // returns true, with the information being put into "info". // Returns false if the library couldn't be found, or if it's not a plugin. - static bool ReadWebPluginInfo(const FilePath& filename, - WebPluginInfo* info, - NP_GetEntryPointsFunc* np_getentrypoints, - NP_InitializeFunc* np_initialize, - NP_ShutdownFunc* np_shutdown); + static bool ReadWebPluginInfo(const FilePath& filename, WebPluginInfo* info); // Unloads all the loaded plugin libraries and cleans up the plugin map. static void UnloadAllPlugins(); @@ -111,13 +86,6 @@ class PluginLib : public base::RefCounted<PluginLib> { // Shutdown the plugin library. void Shutdown(); - // Populate a WebPluginInfo from a PluginVersionInfo. - static bool CreateWebPluginInfo(const PluginVersionInfo& pvi, - WebPluginInfo* info, - NP_GetEntryPointsFunc* np_getentrypoints, - NP_InitializeFunc* np_initialize, - NP_ShutdownFunc* np_shutdown); - public: #if defined(OS_WIN) typedef HMODULE NativeLibrary; diff --git a/webkit/glue/plugins/plugin_lib_linux.cc b/webkit/glue/plugins/plugin_lib_linux.cc index 6217a82..36de951 100644 --- a/webkit/glue/plugins/plugin_lib_linux.cc +++ b/webkit/glue/plugins/plugin_lib_linux.cc @@ -44,17 +44,10 @@ void* PluginLib::GetFunctionPointerFromNativeLibrary( } bool PluginLib::ReadWebPluginInfo(const FilePath& filename, - WebPluginInfo* info, - NP_GetEntryPointsFunc* np_getentrypoints, - NP_InitializeFunc* np_initialize, - NP_ShutdownFunc* np_shutdown) { + WebPluginInfo* info) { // The file to reference is: // http://mxr.mozilla.org/firefox/source/modules/plugin/base/src/nsPluginsDirUnix.cpp - *np_getentrypoints = NULL; - *np_initialize = NULL; - *np_shutdown = NULL; - void* dl = LoadNativeLibrary(filename); if (!dl) return false; diff --git a/webkit/glue/plugins/plugin_lib_mac.mm b/webkit/glue/plugins/plugin_lib_mac.mm index bfd5a13f..7fcb41a3 100644 --- a/webkit/glue/plugins/plugin_lib_mac.mm +++ b/webkit/glue/plugins/plugin_lib_mac.mm @@ -11,7 +11,6 @@ #include "base/scoped_cftyperef.h" #include "base/string_util.h" #include "base/sys_string_conversions.h" -#include "webkit/default_plugin/plugin_main.h" #include "webkit/glue/plugins/plugin_list.h" static const short kSTRTypeDefinitionResourceID = 128; @@ -21,21 +20,6 @@ static const short kSTRPluginDescriptionResourceID = 126; namespace NPAPI { -static const PluginVersionInfo g_internal_plugins[] = { - { - kDefaultPluginLibraryName, - L"Default Plug-in", - L"Provides functionality for installing third-party plug-ins", - L"1.0", - L"*", - L"", - L"", - default_plugin::NP_GetEntryPoints, - default_plugin::NP_Initialize, - default_plugin::NP_Shutdown - }, -}; - /* static */ PluginLib::NativeLibrary PluginLib::LoadNativeLibrary( const FilePath& library_path) { @@ -258,21 +242,7 @@ bool ReadSTRPluginInfo(const FilePath& filename, CFBundleRef bundle, } // anonymous namespace bool PluginLib::ReadWebPluginInfo(const FilePath &filename, - WebPluginInfo* info, - NP_GetEntryPointsFunc* np_getentrypoints, - NP_InitializeFunc* np_initialize, - NP_ShutdownFunc* np_shutdown) { - for (int i = 0; i < arraysize(g_internal_plugins); ++i) { - if (filename.value() == g_internal_plugins[i].path) { - return CreateWebPluginInfo(g_internal_plugins[i], info, np_getentrypoints, - np_initialize, np_shutdown); - } - } - - *np_getentrypoints = NULL; - *np_initialize = NULL; - *np_shutdown = NULL; - + WebPluginInfo* info) { // There are two ways to get information about plugin capabilities. One is an // Info.plist set of keys, documented at // http://developer.apple.com/documentation/InternetWeb/Conceptual/WebKit_PluginProgTopic/Concepts/AboutPlugins.html . diff --git a/webkit/glue/plugins/plugin_lib_win.cc b/webkit/glue/plugins/plugin_lib_win.cc index d34f424..d1a9d09 100644 --- a/webkit/glue/plugins/plugin_lib_win.cc +++ b/webkit/glue/plugins/plugin_lib_win.cc @@ -8,76 +8,12 @@ #include "base/file_version_info.h" #include "base/path_service.h" -#include "webkit/activex_shim/npp_impl.h" -#include "webkit/default_plugin/plugin_main.h" #include "webkit/glue/plugins/plugin_constants_win.h" #include "webkit/glue/plugins/plugin_list.h" -#ifdef GEARS_STATIC_LIB -// defined in gears/base/common/module.cc -NPError API_CALL Gears_NP_GetEntryPoints(NPPluginFuncs* funcs); -NPError API_CALL Gears_NP_Initialize(NPNetscapeFuncs* funcs); -NPError API_CALL Gears_NP_Shutdown(void); -#endif - namespace NPAPI { -static const PluginVersionInfo g_internal_plugins[] = { - { - kActiveXShimFileName, - L"ActiveX Plug-in", - L"ActiveX Plug-in provides a shim to support ActiveX controls", - L"1, 0, 0, 1", - 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 - }, - { - kActiveXShimFileNameForMediaPlayer, - kActiveXShimFileNameForMediaPlayer, - L"Windows Media Player", - L"1, 0, 0, 1", - L"application/x-ms-wmp|application/asx|video/x-ms-asf-plugin|" - L"application/x-mplayer2|video/x-ms-asf|video/x-ms-wm|audio/x-ms-wma|" - 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 - }, - { - kDefaultPluginLibraryName, - L"Default Plug-in", - L"Provides functionality for installing third-party plug-ins", - L"1, 0, 0, 1", - L"*", - L"", - L"", - default_plugin::NP_GetEntryPoints, - default_plugin::NP_Initialize, - default_plugin::NP_Shutdown - }, -#ifdef GEARS_STATIC_LIB - { - kGearsPluginLibraryName, - L"Gears", - L"Statically linked Gears", - L"1, 0, 0, 1", - L"application/x-googlegears", - L"", - L"", - Gears_NP_GetEntryPoints, - Gears_NP_Initialize, - Gears_NP_Shutdown - }, -#endif -}; - /* static */ PluginLib::NativeLibrary PluginLib::LoadNativeLibrary( const FilePath& library_path) { @@ -113,17 +49,7 @@ void* PluginLib::GetFunctionPointerFromNativeLibrary( } bool PluginLib::ReadWebPluginInfo(const FilePath &filename, - WebPluginInfo* info, - NP_GetEntryPointsFunc* np_getentrypoints, - NP_InitializeFunc* np_initialize, - NP_ShutdownFunc* np_shutdown) { - for (int i = 0; i < arraysize(g_internal_plugins); ++i) { - if (filename.value() == g_internal_plugins[i].path) { - return CreateWebPluginInfo(g_internal_plugins[i], info, np_getentrypoints, - np_initialize, np_shutdown); - } - } - + WebPluginInfo* info) { // On windows, the way we get the mime types for the library is // to check the version information in the DLL itself. This // will be a string of the format: <type1>|<type2>|<type3>|... @@ -134,28 +60,16 @@ bool PluginLib::ReadWebPluginInfo(const FilePath &filename, if (!version_info.get()) return false; - std::wstring mime_types = version_info->GetStringValue(L"MIMEType"); - std::wstring file_extents = version_info->GetStringValue(L"FileExtents"); - std::wstring file_open_names = version_info->GetStringValue(L"FileOpenName"); - std::wstring product_name = version_info->product_name(); - std::wstring file_description = version_info->file_description(); - std::wstring file_version = version_info->file_version(); - std::wstring path = filename.value(); - PluginVersionInfo pvi; - pvi.mime_types = mime_types.c_str(); - pvi.file_extensions = file_extents.c_str(); - pvi.type_descriptions = file_open_names.c_str(); - pvi.product_name = product_name.c_str(); - pvi.file_description = file_description.c_str(); - pvi.file_version = file_version.c_str(); - pvi.path = path.c_str(); - pvi.np_getentrypoints = NULL; - pvi.np_initialize = NULL; - pvi.np_shutdown = NULL; - - return CreateWebPluginInfo( - pvi, info, np_getentrypoints, np_initialize, np_shutdown); + pvi.mime_types = version_info->GetStringValue(L"MIMEType"); + pvi.file_extensions = version_info->GetStringValue(L"FileExtents"); + pvi.type_descriptions = version_info->GetStringValue(L"FileOpenName"); + pvi.product_name = version_info->product_name(); + pvi.file_description = version_info->file_description(); + pvi.file_version = version_info->file_version(); + pvi.path = filename; + + return PluginList::CreateWebPluginInfo(pvi, info); } } // namespace NPAPI diff --git a/webkit/glue/plugins/plugin_list.cc b/webkit/glue/plugins/plugin_list.cc index 4484fa3..fb9ae10 100644 --- a/webkit/glue/plugins/plugin_list.cc +++ b/webkit/glue/plugins/plugin_list.cc @@ -11,6 +11,7 @@ #include "base/string_util.h" #include "base/time.h" #include "net/base/mime_util.h" +#include "webkit/default_plugin/plugin_main.h" #include "webkit/glue/plugins/plugin_lib.h" #include "webkit/glue/webkit_glue.h" #include "googleurl/src/gurl.h" @@ -43,14 +44,111 @@ void PluginList::AddExtraPluginPath(const FilePath& plugin_path) { g_singleton.Pointer()->extra_plugin_paths_.push_back(plugin_path); } +void PluginList::RegisterInternalPlugin(const PluginVersionInfo& info) { + // We access the singleton directly, and not through Singleton(), since + // we don't want LoadPlugins() to be called. + DCHECK(!g_singleton.Pointer()->plugins_loaded_); + g_singleton.Pointer()->internal_plugins_.push_back(info); +} + +bool PluginList::ReadPluginInfo(const FilePath &filename, + WebPluginInfo* info, + NP_GetEntryPointsFunc* np_getentrypoints, + NP_InitializeFunc* np_initialize, + NP_ShutdownFunc* np_shutdown) { + // 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; + return CreateWebPluginInfo(internal_plugins[i], info); + } + } + + // Not an internal plugin. + *np_getentrypoints = NULL; + *np_initialize = NULL; + *np_shutdown = NULL; + return PluginLib::ReadWebPluginInfo(filename, info); +} + +bool PluginList::CreateWebPluginInfo(const PluginVersionInfo& pvi, + WebPluginInfo* info) { + std::vector<std::string> mime_types, file_extensions; + std::vector<std::wstring> descriptions; + SplitString(WideToUTF8(pvi.mime_types), '|', &mime_types); + SplitString(WideToUTF8(pvi.file_extensions), '|', &file_extensions); + SplitString(pvi.type_descriptions, '|', &descriptions); + + info->mime_types.clear(); + + if (mime_types.empty()) + return false; + + info->name = pvi.product_name; + info->desc = pvi.file_description; + info->version = pvi.file_version; + info->path = pvi.path; + + for (size_t i = 0; i < mime_types.size(); ++i) { + WebPluginMimeType mime_type; + mime_type.mime_type = StringToLowerASCII(mime_types[i]); + if (file_extensions.size() > i) + SplitString(file_extensions[i], ',', &mime_type.file_extensions); + + if (descriptions.size() > i) { + mime_type.description = descriptions[i]; + + // On Windows, the description likely has a list of file extensions + // embedded in it (e.g. "SurfWriter file (*.swr)"). Remove an extension + // list from the description if it is present. + size_t ext = mime_type.description.find(L"(*"); + if (ext != std::wstring::npos) { + if (ext > 1 && mime_type.description[ext -1] == ' ') + ext--; + + mime_type.description.erase(ext); + } + } + + info->mime_types.push_back(mime_type); + } + + return true; +} + PluginList::PluginList() : plugins_loaded_(false) { - PlatformInit(); } void PluginList::LoadPlugins(bool refresh) { if (plugins_loaded_ && !refresh) return; + if (!plugins_loaded_) { + PlatformInit(); + +#if defined(OS_WIN) + const PluginVersionInfo default_plugin = { + FilePath(kDefaultPluginLibraryName), + L"Default Plug-in", + L"Provides functionality for installing third-party plug-ins", + L"1", + L"*", + L"", + L"", + default_plugin::NP_GetEntryPoints, + default_plugin::NP_Initialize, + default_plugin::NP_Shutdown + }; + + RegisterInternalPlugin(default_plugin); +#endif + } + plugins_.clear(); plugins_loaded_ = true; @@ -67,7 +165,6 @@ void PluginList::LoadPlugins(bool refresh) { for (size_t i = 0; i < extra_plugin_paths_.size(); ++i) LoadPlugin(extra_plugin_paths_[i]); - extra_plugin_paths_.clear(); if (webkit_glue::IsDefaultPluginEnabled()) LoadPlugin(FilePath(kDefaultPluginLibraryName)); @@ -82,8 +179,8 @@ void PluginList::LoadPlugin(const FilePath &path) { NP_GetEntryPointsFunc np_getentrypoints; NP_InitializeFunc np_initialize; NP_ShutdownFunc np_shutdown; - if (!PluginLib::ReadWebPluginInfo(path, &plugin_info, &np_getentrypoints, - &np_initialize, &np_shutdown)) { + if (!ReadPluginInfo(path, &plugin_info, &np_getentrypoints, &np_initialize, + &np_shutdown)) { return; } diff --git a/webkit/glue/plugins/plugin_list.h b/webkit/glue/plugins/plugin_list.h index 9c4efef..d71d2ba 100644 --- a/webkit/glue/plugins/plugin_list.h +++ b/webkit/glue/plugins/plugin_list.h @@ -13,6 +13,7 @@ #include "base/file_path.h" #include "base/ref_counted.h" #include "webkit/glue/webplugin.h" +#include "webkit/glue/plugins/nphostapi.h" class GURL; @@ -31,6 +32,26 @@ namespace NPAPI class PluginInstance; +// 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 +// it'll do for holding descriptions of internal plugins cross-platform.) +struct PluginVersionInfo { + FilePath path; + // Info about the plugin itself. + std::wstring product_name; + std::wstring file_description; + std::wstring file_version; + // Info about the data types that the plugin supports. + 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; +}; + // The PluginList is responsible for loading our NPAPI based plugins. It does // so in whatever manner is appropriate for the platform. On Windows, it loads // plugins from a known directory by looking for DLLs which start with "NP", @@ -51,6 +72,25 @@ class PluginList { // for plugins. Must be called before the plugins have been loaded. static void AddExtraPluginPath(const FilePath& plugin_path); + // Register an internal plugin with the specified plugin information and + // function pointers. An internal plugin must be registered before it can + // be loaded using PluginList::LoadPlugin(). + static void RegisterInternalPlugin(const PluginVersionInfo& info); + + // 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. + // 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); + + // Populate a WebPluginInfo from a PluginVersionInfo. + static bool CreateWebPluginInfo(const PluginVersionInfo& pvi, + WebPluginInfo* info); + // Shutdown all plugins. Should be called at process teardown. void Shutdown(); @@ -73,6 +113,10 @@ class PluginList { // WebPluginInfo has been filled in |info|. bool GetPluginInfoByPath(const FilePath& plugin_path, WebPluginInfo* info); + + // Load a specific plugin with full path. + void LoadPlugin(const FilePath& filename); + private: // Constructors are private for singletons PluginList(); @@ -83,9 +127,6 @@ class PluginList { // Load all plugins from a specific directory void LoadPluginsFromDir(const FilePath& path); - // Load a specific plugin with full path. - void LoadPlugin(const FilePath& filename); - // Returns true if we should load the given plugin, or false otherwise. bool ShouldLoadPlugin(const WebPluginInfo& info); @@ -156,6 +197,9 @@ class PluginList { // Extra plugin paths that we want to search when loading. std::vector<FilePath> extra_plugin_paths_; + // Holds information about internal plugins. + std::vector<PluginVersionInfo> internal_plugins_; + friend struct base::DefaultLazyInstanceTraits<PluginList>; DISALLOW_EVIL_CONSTRUCTORS(PluginList); diff --git a/webkit/glue/plugins/plugin_list_win.cc b/webkit/glue/plugins/plugin_list_win.cc index 2aaf983..55d21dc 100644 --- a/webkit/glue/plugins/plugin_list_win.cc +++ b/webkit/glue/plugins/plugin_list_win.cc @@ -11,6 +11,7 @@ #include "base/path_service.h" #include "base/registry.h" #include "base/string_util.h" +#include "webkit/activex_shim/npp_impl.h" #include "webkit/glue/plugins/plugin_constants_win.h" #include "webkit/glue/plugins/plugin_lib.h" #include "webkit/glue/webkit_glue.h" @@ -38,6 +39,13 @@ const TCHAR kRegistryBrowserJavaVersion[] = _T("BrowserJavaVersion"); const TCHAR kRegistryCurrentJavaVersion[] = _T("CurrentVersion"); const TCHAR kRegistryJavaHome[] = _T("JavaHome"); +#ifdef GEARS_STATIC_LIB +// defined in gears/base/common/module.cc +NPError API_CALL Gears_NP_GetEntryPoints(NPPluginFuncs* funcs); +NPError API_CALL Gears_NP_Initialize(NPNetscapeFuncs* funcs); +NPError API_CALL Gears_NP_Shutdown(void); +#endif + // The application path where we expect to find plugins. void GetAppDirectory(std::set<FilePath>* plugin_dirs) { std::wstring app_path; @@ -199,6 +207,52 @@ void PluginList::PlatformInit() { dont_load_new_wmp_ = command_line.HasSwitch(kUseOldWMPPluginSwitch); use_internal_activex_shim_ = !command_line.HasSwitch(kNoNativeActiveXShimSwitch); + + const PluginVersionInfo builtin_plugins[] = { + { + FilePath(kActiveXShimFileName), + L"ActiveX Plug-in", + L"ActiveX Plug-in provides a shim to support ActiveX controls", + L"1, 0, 0, 1", + 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 + }, + { + FilePath(kActiveXShimFileNameForMediaPlayer), + kActiveXShimFileNameForMediaPlayer, + L"Windows Media Player", + L"1, 0, 0, 1", + L"application/x-ms-wmp|application/asx|video/x-ms-asf-plugin|" + L"application/x-mplayer2|video/x-ms-asf|video/x-ms-wm|audio/x-ms-wma|" + 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 + }, +#ifdef GEARS_STATIC_LIB + { + FilePath(kGearsPluginLibraryName), + L"Gears", + L"Statically linked Gears", + L"1, 0, 0, 1", + L"application/x-googlegears", + L"", + L"", + Gears_NP_GetEntryPoints, + Gears_NP_Initialize, + Gears_NP_Shutdown + }, +#endif + }; + + for (int i = 0; i < arraysize(builtin_plugins); ++i) + RegisterInternalPlugin(builtin_plugins[i]); } void PluginList::GetPluginDirectories(std::vector<FilePath>* plugin_dirs) { @@ -324,8 +378,6 @@ bool PluginList::ShouldLoadPlugin(const WebPluginInfo& info) { } void PluginList::LoadInternalPlugins() { - WebPluginInfo info; - #ifdef GEARS_STATIC_LIB LoadPlugin(FilePath(kGearsPluginLibraryName)); #endif |