| 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 "content/browser/plugin_service.h" | 5 #include "content/browser/plugin_service.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 } | 106 } |
| 107 }; | 107 }; |
| 108 #endif | 108 #endif |
| 109 | 109 |
| 110 // static | 110 // static |
| 111 PluginService* PluginService::GetInstance() { | 111 PluginService* PluginService::GetInstance() { |
| 112 return Singleton<PluginService>::get(); | 112 return Singleton<PluginService>::get(); |
| 113 } | 113 } |
| 114 | 114 |
| 115 PluginService::PluginService() | 115 PluginService::PluginService() |
| 116 : ui_locale_( | 116 : plugin_list_(NULL), |
| 117 ui_locale_( |
| 117 content::GetContentClient()->browser()->GetApplicationLocale()), | 118 content::GetContentClient()->browser()->GetApplicationLocale()), |
| 118 filter_(NULL) { | 119 filter_(NULL) { |
| 120 } |
| 121 |
| 122 PluginService::~PluginService() { |
| 123 #if defined(OS_WIN) |
| 124 // Release the events since they're owned by RegKey, not WaitableEvent. |
| 125 hkcu_watcher_.StopWatching(); |
| 126 hklm_watcher_.StopWatching(); |
| 127 if (hkcu_event_.get()) |
| 128 hkcu_event_->Release(); |
| 129 if (hklm_event_.get()) |
| 130 hklm_event_->Release(); |
| 131 #endif |
| 132 // Make sure no plugin channel requests have been leaked. |
| 133 DCHECK(pending_plugin_clients_.empty()); |
| 134 } |
| 135 |
| 136 void PluginService::Init(webkit::npapi::PluginList* a_plugin_list) { |
| 137 DCHECK(!plugin_list_) << "PluginService already initialized"; |
| 138 DCHECK(a_plugin_list); |
| 139 plugin_list_ = a_plugin_list; |
| 140 |
| 119 plugin_list()->set_will_load_plugins_callback( | 141 plugin_list()->set_will_load_plugins_callback( |
| 120 base::Bind(&WillLoadPluginsCallback)); | 142 base::Bind(&WillLoadPluginsCallback)); |
| 121 | 143 |
| 122 RegisterPepperPlugins(); | 144 RegisterPepperPlugins(); |
| 123 | 145 |
| 124 content::GetContentClient()->AddNPAPIPlugins(plugin_list()); | 146 content::GetContentClient()->AddNPAPIPlugins(plugin_list()); |
| 125 | 147 |
| 126 // Load any specified on the command line as well. | 148 // Load any specified on the command line as well. |
| 127 const CommandLine* command_line = CommandLine::ForCurrentProcess(); | 149 const CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 128 FilePath path = command_line->GetSwitchValuePath(switches::kLoadPlugin); | 150 FilePath path = command_line->GetSwitchValuePath(switches::kLoadPlugin); |
| 129 if (!path.empty()) | 151 if (!path.empty()) |
| 130 AddExtraPluginPath(path); | 152 AddExtraPluginPath(path); |
| 131 path = command_line->GetSwitchValuePath(switches::kExtraPluginDir); | 153 path = command_line->GetSwitchValuePath(switches::kExtraPluginDir); |
| 132 if (!path.empty()) | 154 if (!path.empty()) |
| 133 plugin_list()->AddExtraPluginDir(path); | 155 plugin_list()->AddExtraPluginDir(path); |
| 134 | 156 |
| 135 #if defined(OS_MACOSX) | 157 #if defined(OS_MACOSX) |
| 136 // We need to know when the browser comes forward so we can bring modal plugin | 158 // We need to know when the browser comes forward so we can bring modal plugin |
| 137 // windows forward too. | 159 // windows forward too. |
| 138 registrar_.Add(this, content::NOTIFICATION_APP_ACTIVATED, | 160 registrar_.Add(this, content::NOTIFICATION_APP_ACTIVATED, |
| 139 content::NotificationService::AllSources()); | 161 content::NotificationService::AllSources()); |
| 140 #endif | 162 #endif |
| 141 } | 163 } |
| 142 | 164 |
| 143 PluginService::~PluginService() { | |
| 144 #if defined(OS_WIN) | |
| 145 // Release the events since they're owned by RegKey, not WaitableEvent. | |
| 146 hkcu_watcher_.StopWatching(); | |
| 147 hklm_watcher_.StopWatching(); | |
| 148 if (hkcu_event_.get()) | |
| 149 hkcu_event_->Release(); | |
| 150 if (hklm_event_.get()) | |
| 151 hklm_event_->Release(); | |
| 152 #endif | |
| 153 // Make sure no plugin channel requests have been leaked. | |
| 154 DCHECK(pending_plugin_clients_.empty()); | |
| 155 } | |
| 156 | |
| 157 void PluginService::StartWatchingPlugins() { | 165 void PluginService::StartWatchingPlugins() { |
| 158 // Start watching for changes in the plugin list. This means watching | 166 // Start watching for changes in the plugin list. This means watching |
| 159 // for changes in the Windows registry keys and on both Windows and POSIX | 167 // for changes in the Windows registry keys and on both Windows and POSIX |
| 160 // watch for changes in the paths that are expected to contain plugins. | 168 // watch for changes in the paths that are expected to contain plugins. |
| 161 #if defined(OS_WIN) | 169 #if defined(OS_WIN) |
| 162 if (hkcu_key_.Create(HKEY_CURRENT_USER, | 170 if (hkcu_key_.Create(HKEY_CURRENT_USER, |
| 163 webkit::npapi::kRegistryMozillaPlugins, | 171 webkit::npapi::kRegistryMozillaPlugins, |
| 164 KEY_NOTIFY) == ERROR_SUCCESS) { | 172 KEY_NOTIFY) == ERROR_SUCCESS) { |
| 165 if (hkcu_key_.StartWatching() == ERROR_SUCCESS) { | 173 if (hkcu_key_.StartWatching() == ERROR_SUCCESS) { |
| 166 hkcu_event_.reset(new base::WaitableEvent(hkcu_key_.watch_event())); | 174 hkcu_event_.reset(new base::WaitableEvent(hkcu_key_.watch_event())); |
| (...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 640 return webkit::npapi::PluginList::Singleton(); | 648 return webkit::npapi::PluginList::Singleton(); |
| 641 } | 649 } |
| 642 | 650 |
| 643 void PluginService::RegisterInternalPlugin(const webkit::WebPluginInfo& info) { | 651 void PluginService::RegisterInternalPlugin(const webkit::WebPluginInfo& info) { |
| 644 plugin_list()->RegisterInternalPlugin(info); | 652 plugin_list()->RegisterInternalPlugin(info); |
| 645 } | 653 } |
| 646 | 654 |
| 647 string16 PluginService::GetPluginGroupName(const std::string& plugin_name) { | 655 string16 PluginService::GetPluginGroupName(const std::string& plugin_name) { |
| 648 return plugin_list()->GetPluginGroupName(plugin_name); | 656 return plugin_list()->GetPluginGroupName(plugin_name); |
| 649 } | 657 } |
| OLD | NEW |