| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "config.h" | 5 #include "config.h" |
| 6 | 6 |
| 7 #include "webkit/glue/plugins/plugin_lib.h" | 7 #include "webkit/glue/plugins/plugin_lib.h" |
| 8 | 8 |
| 9 #include "base/file_version_info.h" | 9 #include "base/file_version_info.h" |
| 10 #include "base/lazy_instance.h" |
| 10 #include "base/path_service.h" | 11 #include "base/path_service.h" |
| 11 #include "webkit/activex_shim/npp_impl.h" | 12 #include "webkit/activex_shim/npp_impl.h" |
| 12 #include "webkit/default_plugin/plugin_main.h" | 13 #include "webkit/default_plugin/plugin_main.h" |
| 13 #include "webkit/glue/plugins/plugin_constants_win.h" | 14 #include "webkit/glue/plugins/plugin_constants_win.h" |
| 14 #include "webkit/glue/plugins/plugin_list.h" | 15 #include "webkit/glue/plugins/plugin_list.h" |
| 15 | 16 |
| 16 #ifdef GEARS_STATIC_LIB | 17 #ifdef GEARS_STATIC_LIB |
| 17 // defined in gears/base/common/module.cc | 18 // defined in gears/base/common/module.cc |
| 18 NPError API_CALL Gears_NP_GetEntryPoints(NPPluginFuncs* funcs); | 19 NPError API_CALL Gears_NP_GetEntryPoints(NPPluginFuncs* funcs); |
| 19 NPError API_CALL Gears_NP_Initialize(NPNetscapeFuncs* funcs); | 20 NPError API_CALL Gears_NP_Initialize(NPNetscapeFuncs* funcs); |
| 20 NPError API_CALL Gears_NP_Shutdown(void); | 21 NPError API_CALL Gears_NP_Shutdown(void); |
| 21 #endif | 22 #endif |
| 22 | 23 |
| 23 namespace NPAPI | 24 namespace NPAPI |
| 24 { | 25 { |
| 25 | 26 |
| 26 static const PluginVersionInfo g_internal_plugins[] = { | 27 // A list of all dynamically loaded internal plugins. |
| 27 { | 28 base::LazyInstance<std::vector<PluginVersionInfo> > g_dynamic_internal_plugins( |
| 28 kActiveXShimFileName, | 29 base::LINKER_INITIALIZED); |
| 29 L"ActiveX Plug-in", | |
| 30 L"ActiveX Plug-in provides a shim to support ActiveX controls", | |
| 31 L"1, 0, 0, 1", | |
| 32 L"application/x-oleobject|application/oleobject", | |
| 33 L"*|*", | |
| 34 L"", | |
| 35 activex_shim::ActiveX_Shim_NP_GetEntryPoints, | |
| 36 activex_shim::ActiveX_Shim_NP_Initialize, | |
| 37 activex_shim::ActiveX_Shim_NP_Shutdown | |
| 38 }, | |
| 39 { | |
| 40 kActiveXShimFileNameForMediaPlayer, | |
| 41 kActiveXShimFileNameForMediaPlayer, | |
| 42 L"Windows Media Player", | |
| 43 L"1, 0, 0, 1", | |
| 44 L"application/x-ms-wmp|application/asx|video/x-ms-asf-plugin|" | |
| 45 L"application/x-mplayer2|video/x-ms-asf|video/x-ms-wm|audio/x-ms-wma|" | |
| 46 L"audio/x-ms-wax|video/x-ms-wmv|video/x-ms-wvx", | |
| 47 L"*|*|*|*|asf,asx,*|wm,*|wma,*|wax,*|wmv,*|wvx,*", | |
| 48 L"", | |
| 49 activex_shim::ActiveX_Shim_NP_GetEntryPoints, | |
| 50 activex_shim::ActiveX_Shim_NP_Initialize, | |
| 51 activex_shim::ActiveX_Shim_NP_Shutdown | |
| 52 }, | |
| 53 { | |
| 54 kDefaultPluginLibraryName, | |
| 55 L"Default Plug-in", | |
| 56 L"Provides functionality for installing third-party plug-ins", | |
| 57 L"1, 0, 0, 1", | |
| 58 L"*", | |
| 59 L"", | |
| 60 L"", | |
| 61 default_plugin::NP_GetEntryPoints, | |
| 62 default_plugin::NP_Initialize, | |
| 63 default_plugin::NP_Shutdown | |
| 64 }, | |
| 65 #ifdef GEARS_STATIC_LIB | |
| 66 { | |
| 67 kGearsPluginLibraryName, | |
| 68 L"Gears", | |
| 69 L"Statically linked Gears", | |
| 70 L"1, 0, 0, 1", | |
| 71 L"application/x-googlegears", | |
| 72 L"", | |
| 73 L"", | |
| 74 Gears_NP_GetEntryPoints, | |
| 75 Gears_NP_Initialize, | |
| 76 Gears_NP_Shutdown | |
| 77 }, | |
| 78 #endif | |
| 79 }; | |
| 80 | 30 |
| 81 /* static */ | 31 /* static */ |
| 82 PluginLib::NativeLibrary PluginLib::LoadNativeLibrary( | 32 PluginLib::NativeLibrary PluginLib::LoadNativeLibrary( |
| 83 const FilePath& library_path) { | 33 const FilePath& library_path) { |
| 84 // Switch the current directory to the plugin directory as the plugin | 34 // Switch the current directory to the plugin directory as the plugin |
| 85 // may have dependencies on dlls in this directory. | 35 // may have dependencies on dlls in this directory. |
| 86 bool restore_directory = false; | 36 bool restore_directory = false; |
| 87 std::wstring current_directory; | 37 std::wstring current_directory; |
| 88 if (PathService::Get(base::DIR_CURRENT, ¤t_directory)) { | 38 if (PathService::Get(base::DIR_CURRENT, ¤t_directory)) { |
| 89 FilePath plugin_path = library_path.DirName(); | 39 FilePath plugin_path = library_path.DirName(); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 105 FreeLibrary(library); | 55 FreeLibrary(library); |
| 106 } | 56 } |
| 107 | 57 |
| 108 /* static */ | 58 /* static */ |
| 109 void* PluginLib::GetFunctionPointerFromNativeLibrary( | 59 void* PluginLib::GetFunctionPointerFromNativeLibrary( |
| 110 NativeLibrary library, | 60 NativeLibrary library, |
| 111 NativeLibraryFunctionNameType name) { | 61 NativeLibraryFunctionNameType name) { |
| 112 return GetProcAddress(library, name); | 62 return GetProcAddress(library, name); |
| 113 } | 63 } |
| 114 | 64 |
| 65 void PluginLib::RegisterInternalPlugin(const PluginVersionInfo& info) { |
| 66 g_dynamic_internal_plugins.Pointer()->push_back(info); |
| 67 } |
| 68 |
| 115 bool PluginLib::ReadWebPluginInfo(const FilePath &filename, | 69 bool PluginLib::ReadWebPluginInfo(const FilePath &filename, |
| 116 WebPluginInfo* info, | 70 WebPluginInfo* info, |
| 117 NP_GetEntryPointsFunc* np_getentrypoints, | 71 NP_GetEntryPointsFunc* np_getentrypoints, |
| 118 NP_InitializeFunc* np_initialize, | 72 NP_InitializeFunc* np_initialize, |
| 119 NP_ShutdownFunc* np_shutdown) { | 73 NP_ShutdownFunc* np_shutdown) { |
| 120 for (int i = 0; i < arraysize(g_internal_plugins); ++i) { | 74 static bool builtin_plugins_loaded = false; |
| 121 if (filename.value() == g_internal_plugins[i].path) { | 75 if (!builtin_plugins_loaded) { |
| 122 return CreateWebPluginInfo(g_internal_plugins[i], info, np_getentrypoints, | 76 // The builtin plugins only need to be loaded one time |
| 123 np_initialize, np_shutdown); | 77 const PluginVersionInfo builtin_plugins[] = { |
| 78 { |
| 79 kActiveXShimFileName, |
| 80 L"ActiveX Plug-in", |
| 81 L"ActiveX Plug-in provides a shim to support ActiveX controls", |
| 82 L"1, 0, 0, 1", |
| 83 L"application/x-oleobject|application/oleobject", |
| 84 L"*|*", |
| 85 L"", |
| 86 activex_shim::ActiveX_Shim_NP_GetEntryPoints, |
| 87 activex_shim::ActiveX_Shim_NP_Initialize, |
| 88 activex_shim::ActiveX_Shim_NP_Shutdown |
| 89 }, |
| 90 { |
| 91 kActiveXShimFileNameForMediaPlayer, |
| 92 kActiveXShimFileNameForMediaPlayer, |
| 93 L"Windows Media Player", |
| 94 L"1, 0, 0, 1", |
| 95 L"application/x-ms-wmp|application/asx|video/x-ms-asf-plugin|" |
| 96 L"application/x-mplayer2|video/x-ms-asf|video/x-ms-wm|audio/x-ms-wma
|" |
| 97 L"audio/x-ms-wax|video/x-ms-wmv|video/x-ms-wvx", |
| 98 L"*|*|*|*|asf,asx,*|wm,*|wma,*|wax,*|wmv,*|wvx,*", |
| 99 L"", |
| 100 activex_shim::ActiveX_Shim_NP_GetEntryPoints, |
| 101 activex_shim::ActiveX_Shim_NP_Initialize, |
| 102 activex_shim::ActiveX_Shim_NP_Shutdown |
| 103 }, |
| 104 { |
| 105 kDefaultPluginLibraryName, |
| 106 L"Default Plug-in", |
| 107 L"Provides functionality for installing third-party plug-ins", |
| 108 L"1, 0, 0, 1", |
| 109 L"*", |
| 110 L"", |
| 111 L"", |
| 112 default_plugin::NP_GetEntryPoints, |
| 113 default_plugin::NP_Initialize, |
| 114 default_plugin::NP_Shutdown |
| 115 }, |
| 116 #ifdef GEARS_STATIC_LIB |
| 117 { |
| 118 kGearsPluginLibraryName, |
| 119 L"Gears", |
| 120 L"Statically linked Gears", |
| 121 L"1, 0, 0, 1", |
| 122 L"application/x-googlegears", |
| 123 L"", |
| 124 L"", |
| 125 Gears_NP_GetEntryPoints, |
| 126 Gears_NP_Initialize, |
| 127 Gears_NP_Shutdown |
| 128 }, |
| 129 #endif |
| 130 }; |
| 131 |
| 132 for (int i = 0; i < arraysize(builtin_plugins); ++i) { |
| 133 RegisterInternalPlugin(builtin_plugins[i]); |
| 134 } |
| 135 |
| 136 builtin_plugins_loaded = true; |
| 137 } |
| 138 |
| 139 // Check for dynamically loaded internal plugins |
| 140 std::vector<PluginVersionInfo>& internal_plugins = |
| 141 *(g_dynamic_internal_plugins.Pointer()); |
| 142 for (size_t i = 0; i < internal_plugins.size(); ++i) { |
| 143 if (filename.value() == internal_plugins[i].path) { |
| 144 return CreateWebPluginInfo(internal_plugins[i], info, np_getentrypoints, |
| 145 np_initialize, np_shutdown); |
| 124 } | 146 } |
| 125 } | 147 } |
| 126 | 148 |
| 127 // On windows, the way we get the mime types for the library is | 149 // On windows, the way we get the mime types for the library is |
| 128 // to check the version information in the DLL itself. This | 150 // to check the version information in the DLL itself. This |
| 129 // will be a string of the format: <type1>|<type2>|<type3>|... | 151 // will be a string of the format: <type1>|<type2>|<type3>|... |
| 130 // For example: | 152 // For example: |
| 131 // video/quicktime|audio/aiff|image/jpeg | 153 // video/quicktime|audio/aiff|image/jpeg |
| 132 scoped_ptr<FileVersionInfo> version_info( | 154 scoped_ptr<FileVersionInfo> version_info( |
| 133 FileVersionInfo::CreateFileVersionInfo(filename.value())); | 155 FileVersionInfo::CreateFileVersionInfo(filename.value())); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 153 pvi.np_getentrypoints = NULL; | 175 pvi.np_getentrypoints = NULL; |
| 154 pvi.np_initialize = NULL; | 176 pvi.np_initialize = NULL; |
| 155 pvi.np_shutdown = NULL; | 177 pvi.np_shutdown = NULL; |
| 156 | 178 |
| 157 return CreateWebPluginInfo( | 179 return CreateWebPluginInfo( |
| 158 pvi, info, np_getentrypoints, np_initialize, np_shutdown); | 180 pvi, info, np_getentrypoints, np_initialize, np_shutdown); |
| 159 } | 181 } |
| 160 | 182 |
| 161 } // namespace NPAPI | 183 } // namespace NPAPI |
| 162 | 184 |
| OLD | NEW |