| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "chrome/common/chrome_plugin_lib.h" | 5 #include "chrome/common/chrome_plugin_lib.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/hash_tables.h" | 8 #include "base/hash_tables.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| 11 #include "base/path_service.h" | 11 #include "base/path_service.h" |
| 12 #include "base/perftimer.h" | 12 #include "base/perftimer.h" |
| 13 #include "base/string_util.h" |
| 13 #include "base/thread.h" | 14 #include "base/thread.h" |
| 14 #if defined(OS_WIN) | 15 #include "base/threading/platform_thread.h" |
| 15 #include "base/win/registry.h" | |
| 16 #endif | |
| 17 #include "base/string_util.h" | |
| 18 #include "chrome/common/chrome_counters.h" | 16 #include "chrome/common/chrome_counters.h" |
| 19 #include "chrome/common/chrome_switches.h" | 17 #include "chrome/common/chrome_switches.h" |
| 20 #include "chrome/common/notification_service.h" | 18 #include "chrome/common/notification_service.h" |
| 21 #include "chrome/common/chrome_paths.h" | 19 #include "chrome/common/chrome_paths.h" |
| 22 #include "webkit/plugins/npapi/plugin_list.h" | 20 #include "webkit/plugins/npapi/plugin_list.h" |
| 23 | 21 |
| 22 #if defined(OS_WIN) |
| 23 #include "base/win/registry.h" |
| 24 #endif |
| 25 |
| 24 using base::TimeDelta; | 26 using base::TimeDelta; |
| 25 | 27 |
| 26 // TODO(port): revisit when plugins happier | 28 // TODO(port): revisit when plugins happier |
| 27 #if defined(OS_WIN) | 29 #if defined(OS_WIN) |
| 28 const wchar_t ChromePluginLib::kRegistryChromePlugins[] = | 30 const wchar_t ChromePluginLib::kRegistryChromePlugins[] = |
| 29 L"Software\\Google\\Chrome\\Plugins"; | 31 L"Software\\Google\\Chrome\\Plugins"; |
| 30 static const wchar_t kRegistryLoadOnStartup[] = L"LoadOnStartup"; | 32 static const wchar_t kRegistryLoadOnStartup[] = L"LoadOnStartup"; |
| 31 static const wchar_t kRegistryPath[] = L"Path"; | 33 static const wchar_t kRegistryPath[] = L"Path"; |
| 32 #endif | 34 #endif |
| 33 | 35 |
| 34 typedef base::hash_map<FilePath, scoped_refptr<ChromePluginLib> > | 36 typedef base::hash_map<FilePath, scoped_refptr<ChromePluginLib> > |
| 35 PluginMap; | 37 PluginMap; |
| 36 | 38 |
| 37 // A map of all the instantiated plugins. | 39 // A map of all the instantiated plugins. |
| 38 static PluginMap* g_loaded_libs; | 40 static PluginMap* g_loaded_libs; |
| 39 | 41 |
| 40 // The thread plugins are loaded and used in, lazily initialized upon | 42 // The thread plugins are loaded and used in, lazily initialized upon |
| 41 // the first creation call. | 43 // the first creation call. |
| 42 static PlatformThreadId g_plugin_thread_id = 0; | 44 static base::PlatformThreadId g_plugin_thread_id = 0; |
| 43 static MessageLoop* g_plugin_thread_loop = NULL; | 45 static MessageLoop* g_plugin_thread_loop = NULL; |
| 44 | 46 |
| 45 static bool IsSingleProcessMode() { | 47 static bool IsSingleProcessMode() { |
| 46 // We don't support ChromePlugins in single-process mode. | 48 // We don't support ChromePlugins in single-process mode. |
| 47 return CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess); | 49 return CommandLine::ForCurrentProcess()->HasSwitch(switches::kSingleProcess); |
| 48 } | 50 } |
| 49 | 51 |
| 50 // static | 52 // static |
| 51 bool ChromePluginLib::IsInitialized() { | 53 bool ChromePluginLib::IsInitialized() { |
| 52 return (g_loaded_libs != NULL); | 54 return (g_loaded_libs != NULL); |
| 53 } | 55 } |
| 54 | 56 |
| 55 // static | 57 // static |
| 56 ChromePluginLib* ChromePluginLib::Create(const FilePath& filename, | 58 ChromePluginLib* ChromePluginLib::Create(const FilePath& filename, |
| 57 const CPBrowserFuncs* bfuncs) { | 59 const CPBrowserFuncs* bfuncs) { |
| 58 // Keep a map of loaded plugins to ensure we only load each library once. | 60 // Keep a map of loaded plugins to ensure we only load each library once. |
| 59 if (!g_loaded_libs) { | 61 if (!g_loaded_libs) { |
| 60 g_loaded_libs = new PluginMap(); | 62 g_loaded_libs = new PluginMap(); |
| 61 g_plugin_thread_id = PlatformThread::CurrentId(); | 63 g_plugin_thread_id = base::PlatformThread::CurrentId(); |
| 62 g_plugin_thread_loop = MessageLoop::current(); | 64 g_plugin_thread_loop = MessageLoop::current(); |
| 63 } | 65 } |
| 64 DCHECK(IsPluginThread()); | 66 DCHECK(IsPluginThread()); |
| 65 | 67 |
| 66 PluginMap::const_iterator iter = g_loaded_libs->find(filename); | 68 PluginMap::const_iterator iter = g_loaded_libs->find(filename); |
| 67 if (iter != g_loaded_libs->end()) | 69 if (iter != g_loaded_libs->end()) |
| 68 return iter->second; | 70 return iter->second; |
| 69 | 71 |
| 70 scoped_refptr<ChromePluginLib> plugin(new ChromePluginLib(filename)); | 72 scoped_refptr<ChromePluginLib> plugin(new ChromePluginLib(filename)); |
| 71 if (!plugin->CP_Initialize(bfuncs)) | 73 if (!plugin->CP_Initialize(bfuncs)) |
| (...skipping 18 matching lines...) Expand all Loading... |
| 90 DCHECK(g_loaded_libs); | 92 DCHECK(g_loaded_libs); |
| 91 PluginMap::iterator iter = g_loaded_libs->find(filename); | 93 PluginMap::iterator iter = g_loaded_libs->find(filename); |
| 92 if (iter != g_loaded_libs->end()) { | 94 if (iter != g_loaded_libs->end()) { |
| 93 iter->second->Unload(); | 95 iter->second->Unload(); |
| 94 g_loaded_libs->erase(iter); | 96 g_loaded_libs->erase(iter); |
| 95 } | 97 } |
| 96 } | 98 } |
| 97 | 99 |
| 98 // static | 100 // static |
| 99 bool ChromePluginLib::IsPluginThread() { | 101 bool ChromePluginLib::IsPluginThread() { |
| 100 return PlatformThread::CurrentId() == g_plugin_thread_id; | 102 return base::PlatformThread::CurrentId() == g_plugin_thread_id; |
| 101 } | 103 } |
| 102 | 104 |
| 103 // static | 105 // static |
| 104 MessageLoop* ChromePluginLib::GetPluginThreadLoop() { | 106 MessageLoop* ChromePluginLib::GetPluginThreadLoop() { |
| 105 return g_plugin_thread_loop; | 107 return g_plugin_thread_loop; |
| 106 } | 108 } |
| 107 | 109 |
| 108 // static | 110 // static |
| 109 void ChromePluginLib::RegisterPluginsWithNPAPI() { | 111 void ChromePluginLib::RegisterPluginsWithNPAPI() { |
| 110 // We don't support ChromePlugins in single-process mode. | 112 // We don't support ChromePlugins in single-process mode. |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 281 if (initialized_) | 283 if (initialized_) |
| 282 CP_Shutdown(); | 284 CP_Shutdown(); |
| 283 | 285 |
| 284 #if defined(OS_WIN) | 286 #if defined(OS_WIN) |
| 285 if (module_) { | 287 if (module_) { |
| 286 FreeLibrary(module_); | 288 FreeLibrary(module_); |
| 287 module_ = 0; | 289 module_ = 0; |
| 288 } | 290 } |
| 289 #endif | 291 #endif |
| 290 } | 292 } |
| OLD | NEW |