OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "webkit/plugins/npapi/plugin_lib.h" | 5 #include "webkit/plugins/npapi/plugin_lib.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/metrics/stats_counters.h" | 10 #include "base/metrics/stats_counters.h" |
11 #include "base/string_util.h" | 11 #include "base/string_util.h" |
12 #include "webkit/glue/webkit_glue.h" | 12 #include "webkit/glue/webkit_glue.h" |
13 #include "webkit/plugins/npapi/plugin_instance.h" | 13 #include "webkit/plugins/npapi/plugin_instance.h" |
14 #include "webkit/plugins/npapi/plugin_host.h" | 14 #include "webkit/plugins/npapi/plugin_host.h" |
15 #include "webkit/plugins/npapi/plugin_list.h" | 15 #include "webkit/plugins/npapi/plugin_list.h" |
16 | 16 |
17 namespace webkit { | 17 namespace webkit { |
18 namespace npapi { | 18 namespace npapi { |
19 | 19 |
20 const char kPluginLibrariesLoadedCounter[] = "PluginLibrariesLoaded"; | 20 const char kPluginLibrariesLoadedCounter[] = "PluginLibrariesLoaded"; |
21 const char kPluginInstancesActiveCounter[] = "PluginInstancesActive"; | 21 const char kPluginInstancesActiveCounter[] = "PluginInstancesActive"; |
22 | 22 |
23 // A list of all the instantiated plugins. | 23 // A list of all the instantiated plugins. |
24 static std::vector<scoped_refptr<PluginLib> >* g_loaded_libs; | 24 static std::vector<scoped_refptr<PluginLib> >* g_loaded_libs; |
25 | 25 |
26 PluginLib* PluginLib::CreatePluginLib(const FilePath& filename) { | 26 PluginLib* PluginLib::CreatePluginLib(const base::FilePath& filename) { |
27 // We can only have one PluginLib object per plugin as it controls the per | 27 // We can only have one PluginLib object per plugin as it controls the per |
28 // instance function calls (i.e. NP_Initialize and NP_Shutdown). So we keep | 28 // instance function calls (i.e. NP_Initialize and NP_Shutdown). So we keep |
29 // a map of PluginLib objects. | 29 // a map of PluginLib objects. |
30 if (!g_loaded_libs) | 30 if (!g_loaded_libs) |
31 g_loaded_libs = new std::vector<scoped_refptr<PluginLib> >; | 31 g_loaded_libs = new std::vector<scoped_refptr<PluginLib> >; |
32 | 32 |
33 for (size_t i = 0; i < g_loaded_libs->size(); ++i) { | 33 for (size_t i = 0; i < g_loaded_libs->size(); ++i) { |
34 if ((*g_loaded_libs)[i]->plugin_info().path == filename) | 34 if ((*g_loaded_libs)[i]->plugin_info().path == filename) |
35 return (*g_loaded_libs)[i]; | 35 return (*g_loaded_libs)[i]; |
36 } | 36 } |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 << " failed to load, unloading."; | 264 << " failed to load, unloading."; |
265 base::UnloadNativeLibrary(library); | 265 base::UnloadNativeLibrary(library); |
266 } | 266 } |
267 } | 267 } |
268 | 268 |
269 return rv; | 269 return rv; |
270 } | 270 } |
271 | 271 |
272 // This is a helper to help perform a delayed NP_Shutdown and FreeLibrary on the | 272 // This is a helper to help perform a delayed NP_Shutdown and FreeLibrary on the |
273 // plugin dll. | 273 // plugin dll. |
274 void FreePluginLibraryHelper(const FilePath& path, | 274 void FreePluginLibraryHelper(const base::FilePath& path, |
275 base::NativeLibrary library, | 275 base::NativeLibrary library, |
276 NP_ShutdownFunc shutdown_func) { | 276 NP_ShutdownFunc shutdown_func) { |
277 if (shutdown_func) { | 277 if (shutdown_func) { |
278 // Don't call NP_Shutdown if the library has been reloaded since this task | 278 // Don't call NP_Shutdown if the library has been reloaded since this task |
279 // was posted. | 279 // was posted. |
280 bool reloaded = false; | 280 bool reloaded = false; |
281 if (g_loaded_libs) { | 281 if (g_loaded_libs) { |
282 for (size_t i = 0; i < g_loaded_libs->size(); ++i) { | 282 for (size_t i = 0; i < g_loaded_libs->size(); ++i) { |
283 if ((*g_loaded_libs)[i]->plugin_info().path == path) | 283 if ((*g_loaded_libs)[i]->plugin_info().path == path) |
284 reloaded = true; | 284 reloaded = true; |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
344 | 344 |
345 void PluginLib::Shutdown() { | 345 void PluginLib::Shutdown() { |
346 if (initialized_ && !internal_) { | 346 if (initialized_ && !internal_) { |
347 NP_Shutdown(); | 347 NP_Shutdown(); |
348 initialized_ = false; | 348 initialized_ = false; |
349 } | 349 } |
350 } | 350 } |
351 | 351 |
352 } // namespace npapi | 352 } // namespace npapi |
353 } // namespace webkit | 353 } // namespace webkit |
OLD | NEW |