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 : did_init_(false), |
117 plugin_list_(NULL), | |
118 ui_locale_( | |
117 content::GetContentClient()->browser()->GetApplicationLocale()), | 119 content::GetContentClient()->browser()->GetApplicationLocale()), |
118 filter_(NULL) { | 120 filter_(NULL) { |
121 } | |
122 | |
123 PluginService::~PluginService() { | |
124 #if defined(OS_WIN) | |
125 // Release the events since they're owned by RegKey, not WaitableEvent. | |
126 hkcu_watcher_.StopWatching(); | |
127 hklm_watcher_.StopWatching(); | |
128 if (hkcu_event_.get()) | |
129 hkcu_event_->Release(); | |
130 if (hklm_event_.get()) | |
131 hklm_event_->Release(); | |
132 #endif | |
133 // Make sure no plugin channel requests have been leaked. | |
134 DCHECK(pending_plugin_clients_.empty()); | |
135 } | |
136 | |
137 void PluginService::Init() { | |
138 DCHECK(!did_init_); | |
jam
2011/11/10 21:53:54
nit: is this member variable really needed now?
Robert Sesek
2011/11/10 22:04:32
Doesn't have to be. Removed.
| |
139 | |
140 if (!plugin_list_) | |
141 plugin_list_ = webkit::npapi::PluginList::Singleton(); | |
142 | |
119 plugin_list()->set_will_load_plugins_callback( | 143 plugin_list()->set_will_load_plugins_callback( |
120 base::Bind(&WillLoadPluginsCallback)); | 144 base::Bind(&WillLoadPluginsCallback)); |
121 | 145 |
122 RegisterPepperPlugins(); | 146 RegisterPepperPlugins(); |
123 | 147 |
124 content::GetContentClient()->AddNPAPIPlugins(plugin_list()); | 148 content::GetContentClient()->AddNPAPIPlugins(plugin_list()); |
125 | 149 |
126 // Load any specified on the command line as well. | 150 // Load any specified on the command line as well. |
127 const CommandLine* command_line = CommandLine::ForCurrentProcess(); | 151 const CommandLine* command_line = CommandLine::ForCurrentProcess(); |
128 FilePath path = command_line->GetSwitchValuePath(switches::kLoadPlugin); | 152 FilePath path = command_line->GetSwitchValuePath(switches::kLoadPlugin); |
129 if (!path.empty()) | 153 if (!path.empty()) |
130 AddExtraPluginPath(path); | 154 AddExtraPluginPath(path); |
131 path = command_line->GetSwitchValuePath(switches::kExtraPluginDir); | 155 path = command_line->GetSwitchValuePath(switches::kExtraPluginDir); |
132 if (!path.empty()) | 156 if (!path.empty()) |
133 plugin_list()->AddExtraPluginDir(path); | 157 plugin_list()->AddExtraPluginDir(path); |
134 | 158 |
135 #if defined(OS_MACOSX) | 159 #if defined(OS_MACOSX) |
136 // We need to know when the browser comes forward so we can bring modal plugin | 160 // We need to know when the browser comes forward so we can bring modal plugin |
137 // windows forward too. | 161 // windows forward too. |
138 registrar_.Add(this, content::NOTIFICATION_APP_ACTIVATED, | 162 registrar_.Add(this, content::NOTIFICATION_APP_ACTIVATED, |
139 content::NotificationService::AllSources()); | 163 content::NotificationService::AllSources()); |
140 #endif | 164 #endif |
141 } | |
142 | 165 |
143 PluginService::~PluginService() { | 166 did_init_ = true; |
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 } | 167 } |
156 | 168 |
157 void PluginService::StartWatchingPlugins() { | 169 void PluginService::StartWatchingPlugins() { |
158 // Start watching for changes in the plugin list. This means watching | 170 // 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 | 171 // 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. | 172 // watch for changes in the paths that are expected to contain plugins. |
161 #if defined(OS_WIN) | 173 #if defined(OS_WIN) |
162 if (hkcu_key_.Create(HKEY_CURRENT_USER, | 174 if (hkcu_key_.Create(HKEY_CURRENT_USER, |
163 webkit::npapi::kRegistryMozillaPlugins, | 175 webkit::npapi::kRegistryMozillaPlugins, |
164 KEY_NOTIFY) == ERROR_SUCCESS) { | 176 KEY_NOTIFY) == ERROR_SUCCESS) { |
(...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
633 } | 645 } |
634 | 646 |
635 void PluginService::UnregisterInternalPlugin(const FilePath& path) { | 647 void PluginService::UnregisterInternalPlugin(const FilePath& path) { |
636 plugin_list()->UnregisterInternalPlugin(path); | 648 plugin_list()->UnregisterInternalPlugin(path); |
637 } | 649 } |
638 | 650 |
639 webkit::npapi::PluginList* PluginService::plugin_list() { | 651 webkit::npapi::PluginList* PluginService::plugin_list() { |
640 return webkit::npapi::PluginList::Singleton(); | 652 return webkit::npapi::PluginList::Singleton(); |
641 } | 653 } |
642 | 654 |
655 void PluginService::SetPluginListForTesting( | |
656 webkit::npapi::PluginList* plugin_list) { | |
657 plugin_list_ = plugin_list; | |
658 } | |
659 | |
643 void PluginService::RegisterInternalPlugin(const webkit::WebPluginInfo& info) { | 660 void PluginService::RegisterInternalPlugin(const webkit::WebPluginInfo& info) { |
644 plugin_list()->RegisterInternalPlugin(info); | 661 plugin_list()->RegisterInternalPlugin(info); |
645 } | 662 } |
646 | 663 |
647 string16 PluginService::GetPluginGroupName(const std::string& plugin_name) { | 664 string16 PluginService::GetPluginGroupName(const std::string& plugin_name) { |
648 return plugin_list()->GetPluginGroupName(plugin_name); | 665 return plugin_list()->GetPluginGroupName(plugin_name); |
649 } | 666 } |
OLD | NEW |