diff options
author | avi@chromium.org <avi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-01-22 22:47:34 +0000 |
---|---|---|
committer | avi@chromium.org <avi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-01-22 22:47:34 +0000 |
commit | 51048c068d9c273b9976c057832025347f5de4e9 (patch) | |
tree | 147d37c49af4ea3124113f4712221ed5dd8dabf6 /webkit | |
parent | d16d8e951b82049c22d8604851c91a59194545f8 (diff) | |
download | chromium_src-51048c068d9c273b9976c057832025347f5de4e9.zip chromium_src-51048c068d9c273b9976c057832025347f5de4e9.tar.gz chromium_src-51048c068d9c273b9976c057832025347f5de4e9.tar.bz2 |
Mac default plugin.
Review URL: http://codereview.chromium.org/18394
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@8512 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r-- | webkit/glue/plugins/plugin_lib.cc | 57 | ||||
-rw-r--r-- | webkit/glue/plugins/plugin_lib.h | 27 | ||||
-rw-r--r-- | webkit/glue/plugins/plugin_lib_mac.mm | 28 | ||||
-rw-r--r-- | webkit/glue/plugins/plugin_lib_win.cc | 78 |
4 files changed, 108 insertions, 82 deletions
diff --git a/webkit/glue/plugins/plugin_lib.cc b/webkit/glue/plugins/plugin_lib.cc index dace059..e5a3352 100644 --- a/webkit/glue/plugins/plugin_lib.cc +++ b/webkit/glue/plugins/plugin_lib.cc @@ -9,6 +9,7 @@ #include "base/logging.h" #include "base/message_loop.h" #include "base/stats_counters.h" +#include "base/string_util.h" #include "webkit/glue/webkit_glue.h" #include "webkit/glue/plugins/plugin_instance.h" #include "webkit/glue/plugins/plugin_host.h" @@ -258,5 +259,59 @@ void PluginLib::Shutdown() { } } -} // namespace NPAPI +// 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 c7817cc..3febcf5 100644 --- a/webkit/glue/plugins/plugin_lib.h +++ b/webkit/glue/plugins/plugin_lib.h @@ -25,6 +25,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 { + 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> { @@ -91,6 +111,13 @@ 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_mac.mm b/webkit/glue/plugins/plugin_lib_mac.mm index 355adc9..bfd5a13f 100644 --- a/webkit/glue/plugins/plugin_lib_mac.mm +++ b/webkit/glue/plugins/plugin_lib_mac.mm @@ -11,6 +11,7 @@ #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; @@ -20,6 +21,21 @@ 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) { @@ -246,15 +262,17 @@ bool PluginLib::ReadWebPluginInfo(const FilePath &filename, 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; - // TODO(avi): If an internal plugin is requested, immediately return with its - // info. - if (filename.value() == kDefaultPluginLibraryName) - return false; // TODO(avi): default plugin - // 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 a2ef7ef..d34f424 100644 --- a/webkit/glue/plugins/plugin_lib_win.cc +++ b/webkit/glue/plugins/plugin_lib_win.cc @@ -8,8 +8,6 @@ #include "base/file_version_info.h" #include "base/path_service.h" -#include "base/string_util.h" -#include "base/sys_string_conversions.h" #include "webkit/activex_shim/npp_impl.h" #include "webkit/default_plugin/plugin_main.h" #include "webkit/glue/plugins/plugin_constants_win.h" @@ -25,22 +23,6 @@ NPError API_CALL Gears_NP_Shutdown(void); namespace NPAPI { -// 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. -struct PluginVersionInfo { - const wchar_t* path; - const wchar_t* product_name; - const wchar_t* file_description; - const wchar_t* file_version; - const wchar_t* mime_types; - const wchar_t* file_extents; - const wchar_t* file_open_names; - NP_GetEntryPointsFunc np_getentrypoints; - NP_InitializeFunc np_initialize; - NP_ShutdownFunc np_shutdown; -}; - static const PluginVersionInfo g_internal_plugins[] = { { kActiveXShimFileName, @@ -130,62 +112,6 @@ void* PluginLib::GetFunctionPointerFromNativeLibrary( return GetProcAddress(library, name); } -namespace { - -// Creates WebPluginInfo structure based on read in or built in -// PluginVersionInfo. -bool 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(base::SysWideToNativeMB(pvi.mime_types), '|', &mime_types); - SplitString(base::SysWideToNativeMB(pvi.file_extents), '|', &file_extensions); - SplitString(pvi.file_open_names, '|', &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]; - - // Remove the extension list from the description. - 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; -} - -} - bool PluginLib::ReadWebPluginInfo(const FilePath &filename, WebPluginInfo* info, NP_GetEntryPointsFunc* np_getentrypoints, @@ -218,8 +144,8 @@ bool PluginLib::ReadWebPluginInfo(const FilePath &filename, PluginVersionInfo pvi; pvi.mime_types = mime_types.c_str(); - pvi.file_extents = file_extents.c_str(); - pvi.file_open_names = file_open_names.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(); |