| 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/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| 11 #include "base/stats_counters.h" | 11 #include "base/stats_counters.h" |
| 12 #include "base/string_util.h" | 12 #include "base/string_util.h" |
| 13 #include "webkit/glue/webkit_glue.h" | 13 #include "webkit/glue/webkit_glue.h" |
| 14 #include "webkit/glue/plugins/plugin_instance.h" | 14 #include "webkit/glue/plugins/plugin_instance.h" |
| 15 #include "webkit/glue/plugins/plugin_host.h" | 15 #include "webkit/glue/plugins/plugin_host.h" |
| 16 #include "webkit/glue/plugins/plugin_list.h" | 16 #include "webkit/glue/plugins/plugin_list.h" |
| 17 | 17 |
| 18 // A macro for converting string constants into appropriate |
| 19 // NativeLibraryFunctionNameTypes. |
| 20 #if defined(OS_MACOSX) |
| 21 #define NATIVE_LIBRARY_FUNCTION_NAME(x) CFSTR(x) |
| 22 #else |
| 23 #define NATIVE_LIBRARY_FUNCTION_NAME(x) x |
| 24 #endif // OS_* |
| 25 |
| 18 namespace NPAPI | 26 namespace NPAPI |
| 19 { | 27 { |
| 20 | 28 |
| 21 const char kPluginLibrariesLoadedCounter[] = "PluginLibrariesLoaded"; | 29 const char kPluginLibrariesLoadedCounter[] = "PluginLibrariesLoaded"; |
| 22 const char kPluginInstancesActiveCounter[] = "PluginInstancesActive"; | 30 const char kPluginInstancesActiveCounter[] = "PluginInstancesActive"; |
| 23 | 31 |
| 24 // A list of all the instantiated plugins. | 32 // A list of all the instantiated plugins. |
| 25 static std::vector<scoped_refptr<PluginLib> >* g_loaded_libs; | 33 static std::vector<scoped_refptr<PluginLib> >* g_loaded_libs; |
| 26 | 34 |
| 27 PluginLib* PluginLib::CreatePluginLib(const FilePath& filename) { | 35 PluginLib* PluginLib::CreatePluginLib(const FilePath& filename) { |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 } | 155 } |
| 148 if (g_loaded_libs->empty()) { | 156 if (g_loaded_libs->empty()) { |
| 149 delete g_loaded_libs; | 157 delete g_loaded_libs; |
| 150 g_loaded_libs = NULL; | 158 g_loaded_libs = NULL; |
| 151 } | 159 } |
| 152 } | 160 } |
| 153 } | 161 } |
| 154 | 162 |
| 155 bool PluginLib::Load() { | 163 bool PluginLib::Load() { |
| 156 bool rv = false; | 164 bool rv = false; |
| 157 NativeLibrary library = 0; | 165 base::NativeLibrary library = 0; |
| 158 | 166 |
| 159 if (!internal_) { | 167 if (!internal_) { |
| 160 if (library_ != 0) | 168 if (library_ != 0) |
| 161 return rv; | 169 return rv; |
| 162 | 170 |
| 163 library = LoadNativeLibrary(web_plugin_info_.path); | 171 library = base::LoadNativeLibrary(web_plugin_info_.path); |
| 164 if (library == 0) | 172 if (library == 0) |
| 165 return rv; | 173 return rv; |
| 166 | 174 |
| 167 rv = true; // assume success now | 175 rv = true; // assume success now |
| 168 | 176 |
| 169 entry_points_.np_initialize = | 177 entry_points_.np_initialize = |
| 170 (NP_InitializeFunc)GetFunctionPointerFromNativeLibrary(library, | 178 (NP_InitializeFunc)base::GetFunctionPointerFromNativeLibrary(library, |
| 171 FUNCTION_NAME("NP_Initialize")); | 179 NATIVE_LIBRARY_FUNCTION_NAME("NP_Initialize")); |
| 172 if (entry_points_.np_initialize == 0) | 180 if (entry_points_.np_initialize == 0) |
| 173 rv = false; | 181 rv = false; |
| 174 | 182 |
| 175 #if !defined(OS_LINUX) | 183 #if !defined(OS_LINUX) |
| 176 entry_points_.np_getentrypoints = | 184 entry_points_.np_getentrypoints = |
| 177 (NP_GetEntryPointsFunc)GetFunctionPointerFromNativeLibrary(library, | 185 (NP_GetEntryPointsFunc)base::GetFunctionPointerFromNativeLibrary( |
| 178 FUNCTION_NAME("NP_GetEntryPoints")); | 186 library, |
| 187 NATIVE_LIBRARY_FUNCTION_NAME("NP_GetEntryPoints")); |
| 179 if (entry_points_.np_getentrypoints == 0) | 188 if (entry_points_.np_getentrypoints == 0) |
| 180 rv = false; | 189 rv = false; |
| 181 #endif | 190 #endif |
| 182 | 191 |
| 183 entry_points_.np_shutdown = | 192 entry_points_.np_shutdown = |
| 184 (NP_ShutdownFunc)GetFunctionPointerFromNativeLibrary(library, | 193 (NP_ShutdownFunc)base::GetFunctionPointerFromNativeLibrary(library, |
| 185 FUNCTION_NAME("NP_Shutdown")); | 194 NATIVE_LIBRARY_FUNCTION_NAME("NP_Shutdown")); |
| 186 if (entry_points_.np_shutdown == 0) | 195 if (entry_points_.np_shutdown == 0) |
| 187 rv = false; | 196 rv = false; |
| 188 } else { | 197 } else { |
| 189 rv = true; | 198 rv = true; |
| 190 } | 199 } |
| 191 | 200 |
| 192 if (rv) { | 201 if (rv) { |
| 193 plugin_funcs_.size = sizeof(plugin_funcs_); | 202 plugin_funcs_.size = sizeof(plugin_funcs_); |
| 194 plugin_funcs_.version = (NP_VERSION_MAJOR << 8) | NP_VERSION_MINOR; | 203 plugin_funcs_.version = (NP_VERSION_MAJOR << 8) | NP_VERSION_MINOR; |
| 195 #if !defined(OS_LINUX) | 204 #if !defined(OS_LINUX) |
| 196 if (entry_points_.np_getentrypoints(&plugin_funcs_) != NPERR_NO_ERROR) | 205 if (entry_points_.np_getentrypoints(&plugin_funcs_) != NPERR_NO_ERROR) |
| 197 rv = false; | 206 rv = false; |
| 198 #else | 207 #else |
| 199 // On Linux, we get the plugin entry points during NP_Initialize. | 208 // On Linux, we get the plugin entry points during NP_Initialize. |
| 200 #endif | 209 #endif |
| 201 } | 210 } |
| 202 | 211 |
| 203 if (!internal_) { | 212 if (!internal_) { |
| 204 if (rv) | 213 if (rv) |
| 205 library_ = library; | 214 library_ = library; |
| 206 else | 215 else |
| 207 UnloadNativeLibrary(library); | 216 base::UnloadNativeLibrary(library); |
| 208 } | 217 } |
| 209 | 218 |
| 210 return rv; | 219 return rv; |
| 211 } | 220 } |
| 212 | 221 |
| 213 // This class implements delayed NP_Shutdown and FreeLibrary on the plugin dll. | 222 // This class implements delayed NP_Shutdown and FreeLibrary on the plugin dll. |
| 214 class FreePluginLibraryTask : public Task { | 223 class FreePluginLibraryTask : public Task { |
| 215 public: | 224 public: |
| 216 FreePluginLibraryTask(PluginLib::NativeLibrary library, | 225 FreePluginLibraryTask(base::NativeLibrary library, |
| 217 NP_ShutdownFunc shutdown_func) | 226 NP_ShutdownFunc shutdown_func) |
| 218 : library_(library), | 227 : library_(library), |
| 219 NP_Shutdown_(shutdown_func) { | 228 NP_Shutdown_(shutdown_func) { |
| 220 } | 229 } |
| 221 | 230 |
| 222 ~FreePluginLibraryTask() {} | 231 ~FreePluginLibraryTask() {} |
| 223 | 232 |
| 224 void Run() { | 233 void Run() { |
| 225 if (NP_Shutdown_) | 234 if (NP_Shutdown_) |
| 226 NP_Shutdown_(); | 235 NP_Shutdown_(); |
| 227 | 236 |
| 228 if (library_) { | 237 if (library_) { |
| 229 PluginLib::UnloadNativeLibrary(library_); | 238 base::UnloadNativeLibrary(library_); |
| 230 library_ = NULL; | 239 library_ = NULL; |
| 231 } | 240 } |
| 232 } | 241 } |
| 233 | 242 |
| 234 private: | 243 private: |
| 235 PluginLib::NativeLibrary library_; | 244 base::NativeLibrary library_; |
| 236 NP_ShutdownFunc NP_Shutdown_; | 245 NP_ShutdownFunc NP_Shutdown_; |
| 237 DISALLOW_EVIL_CONSTRUCTORS(FreePluginLibraryTask); | 246 DISALLOW_EVIL_CONSTRUCTORS(FreePluginLibraryTask); |
| 238 }; | 247 }; |
| 239 | 248 |
| 240 void PluginLib::Unload() { | 249 void PluginLib::Unload() { |
| 241 if (!internal_ && library_) { | 250 if (!internal_ && library_) { |
| 242 // In case of single process mode, a plugin can delete itself | 251 // In case of single process mode, a plugin can delete itself |
| 243 // by executing a script. So delay the unloading of the library | 252 // by executing a script. So delay the unloading of the library |
| 244 // so that the plugin will have a chance to unwind. | 253 // so that the plugin will have a chance to unwind. |
| 245 bool defer_unload = webkit_glue::IsPluginRunningInRendererProcess(); | 254 bool defer_unload = webkit_glue::IsPluginRunningInRendererProcess(); |
| 246 | 255 |
| 247 #if USE(JSC) | 256 #if USE(JSC) |
| 248 // The plugin NPAPI instances may still be around. Delay the | 257 // The plugin NPAPI instances may still be around. Delay the |
| 249 // NP_Shutdown and FreeLibrary calls at least till the next | 258 // NP_Shutdown and FreeLibrary calls at least till the next |
| 250 // peek message. | 259 // peek message. |
| 251 defer_unload = true; | 260 defer_unload = true; |
| 252 #endif | 261 #endif |
| 253 | 262 |
| 254 if (defer_unload) { | 263 if (defer_unload) { |
| 255 FreePluginLibraryTask* free_library_task = | 264 FreePluginLibraryTask* free_library_task = |
| 256 new FreePluginLibraryTask(library_, entry_points_.np_shutdown); | 265 new FreePluginLibraryTask(library_, entry_points_.np_shutdown); |
| 257 MessageLoop::current()->PostTask(FROM_HERE, free_library_task); | 266 MessageLoop::current()->PostTask(FROM_HERE, free_library_task); |
| 258 } else { | 267 } else { |
| 259 Shutdown(); | 268 Shutdown(); |
| 260 UnloadNativeLibrary(library_); | 269 base::UnloadNativeLibrary(library_); |
| 261 } | 270 } |
| 262 | 271 |
| 263 library_ = 0; | 272 library_ = 0; |
| 264 } | 273 } |
| 265 } | 274 } |
| 266 | 275 |
| 267 void PluginLib::Shutdown() { | 276 void PluginLib::Shutdown() { |
| 268 if (initialized_ && !internal_) { | 277 if (initialized_ && !internal_) { |
| 269 NP_Shutdown(); | 278 NP_Shutdown(); |
| 270 initialized_ = false; | 279 initialized_ = false; |
| 271 } | 280 } |
| 272 } | 281 } |
| 273 | 282 |
| 274 } // namespace NPAPI | 283 } // namespace NPAPI |
| OLD | NEW |