Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(140)

Side by Side Diff: chrome/browser/plugin_service.cc

Issue 164305: Ensure we don't load plugins on the IO thread (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "build/build_config.h" 5 #include "build/build_config.h"
6 6
7 #include "chrome/browser/plugin_service.h" 7 #include "chrome/browser/plugin_service.h"
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
(...skipping 22 matching lines...) Expand all
33 33
34 PluginService::PluginService() 34 PluginService::PluginService()
35 : main_message_loop_(MessageLoop::current()), 35 : main_message_loop_(MessageLoop::current()),
36 resource_dispatcher_host_(NULL), 36 resource_dispatcher_host_(NULL),
37 ui_locale_(ASCIIToWide(g_browser_process->GetApplicationLocale())) { 37 ui_locale_(ASCIIToWide(g_browser_process->GetApplicationLocale())) {
38 // Have the NPAPI plugin list search for Chrome plugins as well. 38 // Have the NPAPI plugin list search for Chrome plugins as well.
39 ChromePluginLib::RegisterPluginsWithNPAPI(); 39 ChromePluginLib::RegisterPluginsWithNPAPI();
40 // Load the one specified on the command line as well. 40 // Load the one specified on the command line as well.
41 const CommandLine* command_line = CommandLine::ForCurrentProcess(); 41 const CommandLine* command_line = CommandLine::ForCurrentProcess();
42 std::wstring path = command_line->GetSwitchValue(switches::kLoadPlugin); 42 std::wstring path = command_line->GetSwitchValue(switches::kLoadPlugin);
43 if (!path.empty()) 43 if (!path.empty()) {
44 NPAPI::PluginList::AddExtraPluginPath(FilePath::FromWStringHack(path)); 44 NPAPI::PluginList::Singleton()->AddExtraPluginPath(
45 FilePath::FromWStringHack(path));
46 }
45 47
46 #if defined(OS_WIN) 48 #if defined(OS_WIN)
47 hkcu_key_.Create( 49 hkcu_key_.Create(
48 HKEY_CURRENT_USER, kRegistryMozillaPlugins, KEY_NOTIFY); 50 HKEY_CURRENT_USER, kRegistryMozillaPlugins, KEY_NOTIFY);
49 hklm_key_.Create( 51 hklm_key_.Create(
50 HKEY_LOCAL_MACHINE, kRegistryMozillaPlugins, KEY_NOTIFY); 52 HKEY_LOCAL_MACHINE, kRegistryMozillaPlugins, KEY_NOTIFY);
51 if (hkcu_key_.StartWatching()) { 53 if (hkcu_key_.StartWatching()) {
52 hkcu_event_.reset(new base::WaitableEvent(hkcu_key_.watch_event())); 54 hkcu_event_.reset(new base::WaitableEvent(hkcu_key_.watch_event()));
53 hkcu_watcher_.StartWatching(hkcu_event_.get(), this); 55 hkcu_watcher_.StartWatching(hkcu_event_.get(), this);
54 } 56 }
(...skipping 13 matching lines...) Expand all
68 PluginService::~PluginService() { 70 PluginService::~PluginService() {
69 #if defined(OS_WIN) 71 #if defined(OS_WIN)
70 // Release the events since they're owned by RegKey, not WaitableEvent. 72 // Release the events since they're owned by RegKey, not WaitableEvent.
71 hkcu_watcher_.StopWatching(); 73 hkcu_watcher_.StopWatching();
72 hklm_watcher_.StopWatching(); 74 hklm_watcher_.StopWatching();
73 hkcu_event_->Release(); 75 hkcu_event_->Release();
74 hklm_event_->Release(); 76 hklm_event_->Release();
75 #endif 77 #endif
76 } 78 }
77 79
78 void PluginService::GetPlugins(bool refresh,
79 std::vector<WebPluginInfo>* plugins) {
80 AutoLock lock(lock_);
81 NPAPI::PluginList::Singleton()->GetPlugins(refresh, plugins);
82 }
83
84 void PluginService::LoadChromePlugins( 80 void PluginService::LoadChromePlugins(
85 ResourceDispatcherHost* resource_dispatcher_host) { 81 ResourceDispatcherHost* resource_dispatcher_host) {
86 resource_dispatcher_host_ = resource_dispatcher_host; 82 resource_dispatcher_host_ = resource_dispatcher_host;
87 ChromePluginLib::LoadChromePlugins(GetCPBrowserFuncsForBrowser()); 83 ChromePluginLib::LoadChromePlugins(GetCPBrowserFuncsForBrowser());
88 } 84 }
89 85
90 void PluginService::SetChromePluginDataDir(const FilePath& data_dir) { 86 void PluginService::SetChromePluginDataDir(const FilePath& data_dir) {
91 AutoLock lock(lock_);
92 chrome_plugin_data_dir_ = data_dir; 87 chrome_plugin_data_dir_ = data_dir;
93 } 88 }
94 89
95 const FilePath& PluginService::GetChromePluginDataDir() { 90 const FilePath& PluginService::GetChromePluginDataDir() {
96 AutoLock lock(lock_);
97 return chrome_plugin_data_dir_; 91 return chrome_plugin_data_dir_;
98 } 92 }
99 93
100 const std::wstring& PluginService::GetUILocale() { 94 const std::wstring& PluginService::GetUILocale() {
101 return ui_locale_; 95 return ui_locale_;
102 } 96 }
103 97
104 PluginProcessHost* PluginService::FindPluginProcess( 98 PluginProcessHost* PluginService::FindPluginProcess(
105 const FilePath& plugin_path) { 99 const FilePath& plugin_path) {
106 DCHECK(MessageLoop::current() == 100 DCHECK(MessageLoop::current() ==
(...skipping 18 matching lines...) Expand all
125 const FilePath& plugin_path, 119 const FilePath& plugin_path,
126 const std::string& clsid) { 120 const std::string& clsid) {
127 DCHECK(MessageLoop::current() == 121 DCHECK(MessageLoop::current() ==
128 ChromeThread::GetMessageLoop(ChromeThread::IO)); 122 ChromeThread::GetMessageLoop(ChromeThread::IO));
129 123
130 PluginProcessHost *plugin_host = FindPluginProcess(plugin_path); 124 PluginProcessHost *plugin_host = FindPluginProcess(plugin_path);
131 if (plugin_host) 125 if (plugin_host)
132 return plugin_host; 126 return plugin_host;
133 127
134 WebPluginInfo info; 128 WebPluginInfo info;
135 if (!GetPluginInfoByPath(plugin_path, &info)) { 129 if (!NPAPI::PluginList::Singleton()->GetPluginInfoByPath(
130 plugin_path, &info)) {
136 DCHECK(false); 131 DCHECK(false);
137 return NULL; 132 return NULL;
138 } 133 }
139 134
140 // This plugin isn't loaded by any plugin process, so create a new process. 135 // This plugin isn't loaded by any plugin process, so create a new process.
141 plugin_host = new PluginProcessHost(); 136 plugin_host = new PluginProcessHost();
142 if (!plugin_host->Init(info, clsid, ui_locale_)) { 137 if (!plugin_host->Init(info, clsid, ui_locale_)) {
143 DCHECK(false); // Init is not expected to fail 138 DCHECK(false); // Init is not expected to fail
144 delete plugin_host; 139 delete plugin_host;
145 return NULL; 140 return NULL;
(...skipping 26 matching lines...) Expand all
172 FilePath(), 167 FilePath(),
173 reply_msg); 168 reply_msg);
174 } 169 }
175 } 170 }
176 171
177 FilePath PluginService::GetPluginPath(const GURL& url, 172 FilePath PluginService::GetPluginPath(const GURL& url,
178 const GURL& policy_url, 173 const GURL& policy_url,
179 const std::string& mime_type, 174 const std::string& mime_type,
180 const std::string& clsid, 175 const std::string& clsid,
181 std::string* actual_mime_type) { 176 std::string* actual_mime_type) {
182 AutoLock lock(lock_);
183 bool allow_wildcard = true; 177 bool allow_wildcard = true;
184 WebPluginInfo info; 178 WebPluginInfo info;
185 if (NPAPI::PluginList::Singleton()->GetPluginInfo(url, mime_type, clsid, 179 if (NPAPI::PluginList::Singleton()->GetPluginInfo(url, mime_type, clsid,
186 allow_wildcard, &info, 180 allow_wildcard, &info,
187 actual_mime_type) && 181 actual_mime_type) &&
188 PluginAllowedForURL(info.path, policy_url)) { 182 PluginAllowedForURL(info.path, policy_url)) {
189 return info.path; 183 return info.path;
190 } 184 }
191 185
192 return FilePath(); 186 return FilePath();
193 } 187 }
194 188
195 bool PluginService::GetPluginInfoByPath(const FilePath& plugin_path,
196 WebPluginInfo* info) {
197 AutoLock lock(lock_);
198 return NPAPI::PluginList::Singleton()->GetPluginInfoByPath(plugin_path, info);
199 }
200
201 bool PluginService::HavePluginFor(const std::string& mime_type,
202 bool allow_wildcard) {
203 AutoLock lock(lock_);
204
205 GURL url;
206 WebPluginInfo info;
207 return NPAPI::PluginList::Singleton()->GetPluginInfo(url, mime_type, "",
208 allow_wildcard, &info,
209 NULL);
210 }
211
212 void PluginService::OnWaitableEventSignaled(base::WaitableEvent* waitable_event) { 189 void PluginService::OnWaitableEventSignaled(base::WaitableEvent* waitable_event) {
213 #if defined(OS_WIN) 190 #if defined(OS_WIN)
214 if (waitable_event == hkcu_event_.get()) { 191 if (waitable_event == hkcu_event_.get()) {
215 hkcu_key_.StartWatching(); 192 hkcu_key_.StartWatching();
216 } else { 193 } else {
217 hklm_key_.StartWatching(); 194 hklm_key_.StartWatching();
218 } 195 }
219 196
220 AutoLock lock(lock_); 197 NPAPI::PluginList::Singleton()->ResetPluginsLoaded();
221 NPAPI::PluginList::ResetPluginsLoaded();
222 198
223 for (RenderProcessHost::iterator it = RenderProcessHost::begin(); 199 for (RenderProcessHost::iterator it = RenderProcessHost::begin();
224 it != RenderProcessHost::end(); ++it) { 200 it != RenderProcessHost::end(); ++it) {
225 it->second->Send(new ViewMsg_PurgePluginListCache()); 201 it->second->Send(new ViewMsg_PurgePluginListCache());
226 } 202 }
227 #endif 203 #endif
228 } 204 }
229 205
230 void PluginService::Observe(NotificationType type, 206 void PluginService::Observe(NotificationType type,
231 const NotificationSource& source, 207 const NotificationSource& source,
232 const NotificationDetails& details) { 208 const NotificationDetails& details) {
233 switch (type.value) { 209 switch (type.value) {
234 case NotificationType::EXTENSIONS_LOADED: { 210 case NotificationType::EXTENSIONS_LOADED: {
235 // TODO(mpcomplete): We also need to force a renderer to refresh its 211 // TODO(mpcomplete): We also need to force a renderer to refresh its
236 // cache of the plugin list when we inject user scripts, since it could 212 // cache of the plugin list when we inject user scripts, since it could
237 // have a stale version by the time extensions are loaded. 213 // have a stale version by the time extensions are loaded.
238 // See: http://code.google.com/p/chromium/issues/detail?id=12306 214 // See: http://code.google.com/p/chromium/issues/detail?id=12306
239 215
240 ExtensionList* extensions = Details<ExtensionList>(details).ptr(); 216 ExtensionList* extensions = Details<ExtensionList>(details).ptr();
241 for (ExtensionList::iterator extension = extensions->begin(); 217 for (ExtensionList::iterator extension = extensions->begin();
242 extension != extensions->end(); ++extension) { 218 extension != extensions->end(); ++extension) {
243 for (size_t i = 0; i < (*extension)->plugins().size(); ++i ) { 219 for (size_t i = 0; i < (*extension)->plugins().size(); ++i ) {
244 const Extension::PluginInfo& plugin = (*extension)->plugins()[i]; 220 const Extension::PluginInfo& plugin = (*extension)->plugins()[i];
245 AutoLock lock(lock_); 221 NPAPI::PluginList::Singleton()->ResetPluginsLoaded();
246 NPAPI::PluginList::ResetPluginsLoaded(); 222 NPAPI::PluginList::Singleton()->AddExtraPluginPath(plugin.path);
247 NPAPI::PluginList::AddExtraPluginPath(plugin.path);
248 if (!plugin.is_public) 223 if (!plugin.is_public)
249 private_plugins_[plugin.path] = (*extension)->url(); 224 private_plugins_[plugin.path] = (*extension)->url();
250 } 225 }
251 } 226 }
252 break; 227 break;
253 } 228 }
254 229
255 case NotificationType::EXTENSION_UNLOADED: { 230 case NotificationType::EXTENSION_UNLOADED: {
256 // TODO(aa): Implement this. Also, will it be possible to delete the 231 // TODO(aa): Implement this. Also, will it be possible to delete the
257 // extension folder if this isn't unloaded? 232 // extension folder if this isn't unloaded?
(...skipping 14 matching lines...) Expand all
272 PrivatePluginMap::iterator it = private_plugins_.find(plugin_path); 247 PrivatePluginMap::iterator it = private_plugins_.find(plugin_path);
273 if (it == private_plugins_.end()) 248 if (it == private_plugins_.end())
274 return true; // This plugin is not private, so it's allowed everywhere. 249 return true; // This plugin is not private, so it's allowed everywhere.
275 250
276 // We do a dumb compare of scheme and host, rather than using the domain 251 // We do a dumb compare of scheme and host, rather than using the domain
277 // service, since we only care about this for extensions. 252 // service, since we only care about this for extensions.
278 const GURL& required_url = it->second; 253 const GURL& required_url = it->second;
279 return (url.scheme() == required_url.scheme() && 254 return (url.scheme() == required_url.scheme() &&
280 url.host() == required_url.host()); 255 url.host() == required_url.host());
281 } 256 }
OLDNEW
« no previous file with comments | « chrome/browser/plugin_service.h ('k') | chrome/browser/renderer_host/buffered_resource_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698