OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "content/browser/plugin_service.h" | |
6 | |
7 #include "base/bind.h" | |
8 #include "base/command_line.h" | |
9 #include "base/compiler_specific.h" | |
10 #include "base/file_path.h" | |
11 #include "base/message_loop.h" | |
12 #include "base/message_loop_proxy.h" | |
13 #include "base/path_service.h" | |
14 #include "base/string_util.h" | |
15 #include "base/synchronization/waitable_event.h" | |
16 #include "base/threading/thread.h" | |
17 #include "base/utf_string_conversions.h" | |
18 #include "base/values.h" | |
19 #include "content/browser/plugin_loader_posix.h" | |
20 #include "content/browser/plugin_service_filter.h" | |
21 #include "content/browser/ppapi_plugin_process_host.h" | |
22 #include "content/browser/renderer_host/render_process_host_impl.h" | |
23 #include "content/browser/renderer_host/render_view_host.h" | |
24 #include "content/browser/resource_context.h" | |
25 #include "content/browser/utility_process_host.h" | |
26 #include "content/common/pepper_plugin_registry.h" | |
27 #include "content/common/plugin_messages.h" | |
28 #include "content/common/utility_messages.h" | |
29 #include "content/common/view_messages.h" | |
30 #include "content/public/browser/browser_thread.h" | |
31 #include "content/public/browser/content_browser_client.h" | |
32 #include "content/public/browser/notification_service.h" | |
33 #include "content/public/browser/notification_types.h" | |
34 #include "content/public/common/content_switches.h" | |
35 #include "content/public/common/process_type.h" | |
36 #include "webkit/plugins/npapi/plugin_constants_win.h" | |
37 #include "webkit/plugins/npapi/plugin_group.h" | |
38 #include "webkit/plugins/npapi/plugin_list.h" | |
39 #include "webkit/plugins/webplugininfo.h" | |
40 | |
41 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_OPENBSD) | |
42 using ::base::files::FilePathWatcher; | |
43 #endif | |
44 | |
45 using content::BrowserThread; | |
46 using content::PluginServiceFilter; | |
47 | |
48 namespace { | |
49 | |
50 // Helper function that merely runs the callback with the result. Called on the | |
51 // thread on which the original GetPlugins() call was made. | |
52 static void RunGetPluginsCallback( | |
53 const PluginService::GetPluginsCallback& callback, | |
54 const std::vector<webkit::WebPluginInfo>& result) { | |
55 callback.Run(result); | |
56 } | |
57 | |
58 // A callback for GetPlugins() that then gets the freshly loaded plugin groups | |
59 // and runs the callback for GetPluginGroups(). | |
60 static void GetPluginsForGroupsCallback( | |
61 const PluginService::GetPluginGroupsCallback& callback, | |
62 const std::vector<webkit::WebPluginInfo>& plugins) { | |
63 std::vector<webkit::npapi::PluginGroup> groups; | |
64 webkit::npapi::PluginList::Singleton()->GetPluginGroups(false, &groups); | |
65 callback.Run(groups); | |
66 } | |
67 | |
68 // Callback set on the PluginList to assert that plugin loading happens on the | |
69 // correct thread. | |
70 void WillLoadPluginsCallback() { | |
71 #if defined(OS_WIN) | |
72 CHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | |
73 #else | |
74 CHECK(false) << "Plugin loading should happen out-of-process."; | |
75 #endif | |
76 } | |
77 | |
78 } // namespace | |
79 | |
80 #if defined(OS_MACOSX) | |
81 static void NotifyPluginsOfActivation() { | |
82 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
83 | |
84 for (BrowserChildProcessHost::Iterator iter( | |
85 content::PROCESS_TYPE_PLUGIN); | |
86 !iter.Done(); ++iter) { | |
87 PluginProcessHost* plugin = static_cast<PluginProcessHost*>(*iter); | |
88 plugin->OnAppActivation(); | |
89 } | |
90 } | |
91 #elif defined(OS_POSIX) && !defined(OS_OPENBSD) | |
92 // Delegate class for monitoring directories. | |
93 class PluginDirWatcherDelegate : public FilePathWatcher::Delegate { | |
94 virtual void OnFilePathChanged(const FilePath& path) OVERRIDE { | |
95 VLOG(1) << "Watched path changed: " << path.value(); | |
96 // Make the plugin list update itself | |
97 webkit::npapi::PluginList::Singleton()->RefreshPlugins(); | |
98 BrowserThread::PostTask( | |
99 BrowserThread::UI, FROM_HERE, | |
100 base::Bind(&content::PluginService::PurgePluginListCache, | |
101 static_cast<content::BrowserContext*>(NULL), false)); | |
102 } | |
103 | |
104 virtual void OnFilePathError(const FilePath& path) OVERRIDE { | |
105 // TODO(pastarmovj): Add some sensible error handling. Maybe silently | |
106 // stopping the watcher would be enough. Or possibly restart it. | |
107 NOTREACHED(); | |
108 } | |
109 }; | |
110 #endif | |
111 | |
112 namespace content { | |
113 // static | |
114 PluginService* PluginService::GetInstance() { | |
115 return ::PluginService::GetInstance(); | |
116 } | |
117 | |
118 void PluginService::PurgePluginListCache(BrowserContext* browser_context, | |
119 bool reload_pages) { | |
120 for (RenderProcessHost::iterator it = RenderProcessHost::AllHostsIterator(); | |
121 !it.IsAtEnd(); it.Advance()) { | |
122 RenderProcessHost* host = it.GetCurrentValue(); | |
123 if (!browser_context || host->GetBrowserContext() == browser_context) | |
124 host->Send(new ViewMsg_PurgePluginListCache(reload_pages)); | |
125 } | |
126 } | |
127 | |
128 } // namespace content | |
129 | |
130 // static | |
131 PluginService* PluginService::GetInstance() { | |
132 return Singleton<PluginService>::get(); | |
133 } | |
134 | |
135 PluginService::PluginService() | |
136 : plugin_list_(NULL), | |
137 ui_locale_( | |
138 content::GetContentClient()->browser()->GetApplicationLocale()), | |
139 filter_(NULL) { | |
140 } | |
141 | |
142 PluginService::~PluginService() { | |
143 #if defined(OS_WIN) | |
144 // Release the events since they're owned by RegKey, not WaitableEvent. | |
145 hkcu_watcher_.StopWatching(); | |
146 hklm_watcher_.StopWatching(); | |
147 if (hkcu_event_.get()) | |
148 hkcu_event_->Release(); | |
149 if (hklm_event_.get()) | |
150 hklm_event_->Release(); | |
151 #endif | |
152 // Make sure no plugin channel requests have been leaked. | |
153 DCHECK(pending_plugin_clients_.empty()); | |
154 } | |
155 | |
156 void PluginService::Init() { | |
157 if (!plugin_list_) | |
158 plugin_list_ = webkit::npapi::PluginList::Singleton(); | |
159 | |
160 plugin_list_->set_will_load_plugins_callback( | |
161 base::Bind(&WillLoadPluginsCallback)); | |
162 | |
163 RegisterPepperPlugins(); | |
164 | |
165 content::GetContentClient()->AddNPAPIPlugins(plugin_list_); | |
166 | |
167 // Load any specified on the command line as well. | |
168 const CommandLine* command_line = CommandLine::ForCurrentProcess(); | |
169 FilePath path = command_line->GetSwitchValuePath(switches::kLoadPlugin); | |
170 if (!path.empty()) | |
171 AddExtraPluginPath(path); | |
172 path = command_line->GetSwitchValuePath(switches::kExtraPluginDir); | |
173 if (!path.empty()) | |
174 plugin_list_->AddExtraPluginDir(path); | |
175 | |
176 #if defined(OS_MACOSX) | |
177 // We need to know when the browser comes forward so we can bring modal plugin | |
178 // windows forward too. | |
179 registrar_.Add(this, content::NOTIFICATION_APP_ACTIVATED, | |
180 content::NotificationService::AllSources()); | |
181 #endif | |
182 } | |
183 | |
184 void PluginService::StartWatchingPlugins() { | |
185 // Start watching for changes in the plugin list. This means watching | |
186 // for changes in the Windows registry keys and on both Windows and POSIX | |
187 // watch for changes in the paths that are expected to contain plugins. | |
188 #if defined(OS_WIN) | |
189 if (hkcu_key_.Create(HKEY_CURRENT_USER, | |
190 webkit::npapi::kRegistryMozillaPlugins, | |
191 KEY_NOTIFY) == ERROR_SUCCESS) { | |
192 if (hkcu_key_.StartWatching() == ERROR_SUCCESS) { | |
193 hkcu_event_.reset(new base::WaitableEvent(hkcu_key_.watch_event())); | |
194 hkcu_watcher_.StartWatching(hkcu_event_.get(), this); | |
195 } | |
196 } | |
197 if (hklm_key_.Create(HKEY_LOCAL_MACHINE, | |
198 webkit::npapi::kRegistryMozillaPlugins, | |
199 KEY_NOTIFY) == ERROR_SUCCESS) { | |
200 if (hklm_key_.StartWatching() == ERROR_SUCCESS) { | |
201 hklm_event_.reset(new base::WaitableEvent(hklm_key_.watch_event())); | |
202 hklm_watcher_.StartWatching(hklm_event_.get(), this); | |
203 } | |
204 } | |
205 #elif defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_OPENBSD) | |
206 // The FilePathWatcher produces too many false positives on MacOS (access time | |
207 // updates?) which will lead to enforcing updates of the plugins way too often. | |
208 // On ChromeOS the user can't install plugins anyway and on Windows all | |
209 // important plugins register themselves in the registry so no need to do that. | |
210 file_watcher_delegate_ = new PluginDirWatcherDelegate(); | |
211 // Get the list of all paths for registering the FilePathWatchers | |
212 // that will track and if needed reload the list of plugins on runtime. | |
213 std::vector<FilePath> plugin_dirs; | |
214 plugin_list_->GetPluginDirectories(&plugin_dirs); | |
215 | |
216 for (size_t i = 0; i < plugin_dirs.size(); ++i) { | |
217 // FilePathWatcher can not handle non-absolute paths under windows. | |
218 // We don't watch for file changes in windows now but if this should ever | |
219 // be extended to Windows these lines might save some time of debugging. | |
220 #if defined(OS_WIN) | |
221 if (!plugin_dirs[i].IsAbsolute()) | |
222 continue; | |
223 #endif | |
224 FilePathWatcher* watcher = new FilePathWatcher(); | |
225 VLOG(1) << "Watching for changes in: " << plugin_dirs[i].value(); | |
226 BrowserThread::PostTask( | |
227 BrowserThread::FILE, FROM_HERE, | |
228 base::Bind(&PluginService::RegisterFilePathWatcher, watcher, | |
229 plugin_dirs[i], file_watcher_delegate_)); | |
230 file_watchers_.push_back(watcher); | |
231 } | |
232 #endif | |
233 } | |
234 | |
235 const std::string& PluginService::GetUILocale() { | |
236 return ui_locale_; | |
237 } | |
238 | |
239 PluginProcessHost* PluginService::FindNpapiPluginProcess( | |
240 const FilePath& plugin_path) { | |
241 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
242 | |
243 for (BrowserChildProcessHost::Iterator iter(content::PROCESS_TYPE_PLUGIN); | |
244 !iter.Done(); ++iter) { | |
245 PluginProcessHost* plugin = static_cast<PluginProcessHost*>(*iter); | |
246 if (plugin->info().path == plugin_path) | |
247 return plugin; | |
248 } | |
249 | |
250 return NULL; | |
251 } | |
252 | |
253 PpapiPluginProcessHost* PluginService::FindPpapiPluginProcess( | |
254 const FilePath& plugin_path) { | |
255 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
256 | |
257 for (BrowserChildProcessHost::Iterator iter( | |
258 content::PROCESS_TYPE_PPAPI_PLUGIN); | |
259 !iter.Done(); ++iter) { | |
260 PpapiPluginProcessHost* plugin = | |
261 static_cast<PpapiPluginProcessHost*>(*iter); | |
262 if (plugin->plugin_path() == plugin_path) | |
263 return plugin; | |
264 } | |
265 | |
266 return NULL; | |
267 } | |
268 | |
269 PpapiPluginProcessHost* PluginService::FindPpapiBrokerProcess( | |
270 const FilePath& broker_path) { | |
271 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
272 | |
273 for (BrowserChildProcessHost::Iterator iter( | |
274 content::PROCESS_TYPE_PPAPI_BROKER); | |
275 !iter.Done(); ++iter) { | |
276 PpapiPluginProcessHost* broker = | |
277 static_cast<PpapiPluginProcessHost*>(*iter); | |
278 if (broker->plugin_path() == broker_path) | |
279 return broker; | |
280 } | |
281 | |
282 return NULL; | |
283 } | |
284 | |
285 PluginProcessHost* PluginService::FindOrStartNpapiPluginProcess( | |
286 const FilePath& plugin_path) { | |
287 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
288 | |
289 PluginProcessHost* plugin_host = FindNpapiPluginProcess(plugin_path); | |
290 if (plugin_host) | |
291 return plugin_host; | |
292 | |
293 webkit::WebPluginInfo info; | |
294 if (!GetPluginInfoByPath(plugin_path, &info)) { | |
295 return NULL; | |
296 } | |
297 | |
298 // This plugin isn't loaded by any plugin process, so create a new process. | |
299 scoped_ptr<PluginProcessHost> new_host(new PluginProcessHost()); | |
300 if (!new_host->Init(info, ui_locale_)) { | |
301 NOTREACHED(); // Init is not expected to fail. | |
302 return NULL; | |
303 } | |
304 return new_host.release(); | |
305 } | |
306 | |
307 PpapiPluginProcessHost* PluginService::FindOrStartPpapiPluginProcess( | |
308 const FilePath& plugin_path, | |
309 PpapiPluginProcessHost::PluginClient* client) { | |
310 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
311 | |
312 PpapiPluginProcessHost* plugin_host = FindPpapiPluginProcess(plugin_path); | |
313 if (plugin_host) | |
314 return plugin_host; | |
315 | |
316 // Validate that the plugin is actually registered. | |
317 content::PepperPluginInfo* info = GetRegisteredPpapiPluginInfo(plugin_path); | |
318 if (!info) | |
319 return NULL; | |
320 | |
321 // This plugin isn't loaded by any plugin process, so create a new process. | |
322 return PpapiPluginProcessHost::CreatePluginHost( | |
323 *info, | |
324 client->GetResourceContext()->host_resolver()); | |
325 } | |
326 | |
327 PpapiPluginProcessHost* PluginService::FindOrStartPpapiBrokerProcess( | |
328 const FilePath& plugin_path) { | |
329 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
330 | |
331 PpapiPluginProcessHost* plugin_host = FindPpapiBrokerProcess(plugin_path); | |
332 if (plugin_host) | |
333 return plugin_host; | |
334 | |
335 // Validate that the plugin is actually registered. | |
336 content::PepperPluginInfo* info = GetRegisteredPpapiPluginInfo(plugin_path); | |
337 if (!info) | |
338 return NULL; | |
339 | |
340 // TODO(ddorwin): Uncomment once out of process is supported. | |
341 // DCHECK(info->is_out_of_process); | |
342 | |
343 // This broker isn't loaded by any broker process, so create a new process. | |
344 return PpapiPluginProcessHost::CreateBrokerHost(*info); | |
345 } | |
346 | |
347 void PluginService::OpenChannelToNpapiPlugin( | |
348 int render_process_id, | |
349 int render_view_id, | |
350 const GURL& url, | |
351 const GURL& page_url, | |
352 const std::string& mime_type, | |
353 PluginProcessHost::Client* client) { | |
354 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
355 DCHECK(!ContainsKey(pending_plugin_clients_, client)); | |
356 pending_plugin_clients_.insert(client); | |
357 | |
358 // Make sure plugins are loaded if necessary. | |
359 content::PluginServiceFilterParams params = { | |
360 render_process_id, | |
361 render_view_id, | |
362 page_url, | |
363 &client->GetResourceContext() | |
364 }; | |
365 GetPlugins( | |
366 base::Bind(&PluginService::ForwardGetAllowedPluginForOpenChannelToPlugin, | |
367 base::Unretained(this), params, url, mime_type, client)); | |
368 } | |
369 | |
370 void PluginService::OpenChannelToPpapiPlugin( | |
371 const FilePath& path, | |
372 PpapiPluginProcessHost::PluginClient* client) { | |
373 PpapiPluginProcessHost* plugin_host = FindOrStartPpapiPluginProcess( | |
374 path, client); | |
375 if (plugin_host) | |
376 plugin_host->OpenChannelToPlugin(client); | |
377 else // Send error. | |
378 client->OnChannelOpened(base::kNullProcessHandle, IPC::ChannelHandle()); | |
379 } | |
380 | |
381 void PluginService::OpenChannelToPpapiBroker( | |
382 const FilePath& path, | |
383 PpapiPluginProcessHost::BrokerClient* client) { | |
384 PpapiPluginProcessHost* plugin_host = FindOrStartPpapiBrokerProcess(path); | |
385 if (plugin_host) | |
386 plugin_host->OpenChannelToPlugin(client); | |
387 else // Send error. | |
388 client->OnChannelOpened(base::kNullProcessHandle, IPC::ChannelHandle()); | |
389 } | |
390 | |
391 void PluginService::CancelOpenChannelToNpapiPlugin( | |
392 PluginProcessHost::Client* client) { | |
393 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
394 DCHECK(ContainsKey(pending_plugin_clients_, client)); | |
395 pending_plugin_clients_.erase(client); | |
396 } | |
397 | |
398 void PluginService::ForwardGetAllowedPluginForOpenChannelToPlugin( | |
399 const content::PluginServiceFilterParams& params, | |
400 const GURL& url, | |
401 const std::string& mime_type, | |
402 PluginProcessHost::Client* client, | |
403 const std::vector<webkit::WebPluginInfo>&) { | |
404 GetAllowedPluginForOpenChannelToPlugin(params.render_process_id, | |
405 params.render_view_id, url, params.page_url, mime_type, client, | |
406 params.resource_context); | |
407 } | |
408 | |
409 void PluginService::GetAllowedPluginForOpenChannelToPlugin( | |
410 int render_process_id, | |
411 int render_view_id, | |
412 const GURL& url, | |
413 const GURL& page_url, | |
414 const std::string& mime_type, | |
415 PluginProcessHost::Client* client, | |
416 const content::ResourceContext* resource_context) { | |
417 webkit::WebPluginInfo info; | |
418 bool allow_wildcard = true; | |
419 bool found = GetPluginInfo( | |
420 render_process_id, render_view_id, *resource_context, | |
421 url, page_url, mime_type, allow_wildcard, | |
422 NULL, &info, NULL); | |
423 FilePath plugin_path; | |
424 if (found) | |
425 plugin_path = info.path; | |
426 | |
427 // Now we jump back to the IO thread to finish opening the channel. | |
428 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | |
429 base::Bind(&PluginService::FinishOpenChannelToPlugin, | |
430 base::Unretained(this), plugin_path, client)); | |
431 } | |
432 | |
433 void PluginService::FinishOpenChannelToPlugin( | |
434 const FilePath& plugin_path, | |
435 PluginProcessHost::Client* client) { | |
436 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
437 | |
438 // Make sure it hasn't been canceled yet. | |
439 if (!ContainsKey(pending_plugin_clients_, client)) | |
440 return; | |
441 pending_plugin_clients_.erase(client); | |
442 | |
443 PluginProcessHost* plugin_host = FindOrStartNpapiPluginProcess(plugin_path); | |
444 if (plugin_host) { | |
445 client->OnFoundPluginProcessHost(plugin_host); | |
446 plugin_host->OpenChannelToPlugin(client); | |
447 } else { | |
448 client->OnError(); | |
449 } | |
450 } | |
451 | |
452 bool PluginService::GetPluginInfoArray( | |
453 const GURL& url, | |
454 const std::string& mime_type, | |
455 bool allow_wildcard, | |
456 std::vector<webkit::WebPluginInfo>* plugins, | |
457 std::vector<std::string>* actual_mime_types) { | |
458 bool use_stale = false; | |
459 plugin_list_->GetPluginInfoArray(url, mime_type, allow_wildcard, | |
460 &use_stale, plugins, actual_mime_types); | |
461 return use_stale; | |
462 } | |
463 | |
464 bool PluginService::GetPluginInfo(int render_process_id, | |
465 int render_view_id, | |
466 const content::ResourceContext& context, | |
467 const GURL& url, | |
468 const GURL& page_url, | |
469 const std::string& mime_type, | |
470 bool allow_wildcard, | |
471 bool* is_stale, | |
472 webkit::WebPluginInfo* info, | |
473 std::string* actual_mime_type) { | |
474 std::vector<webkit::WebPluginInfo> plugins; | |
475 std::vector<std::string> mime_types; | |
476 bool stale = GetPluginInfoArray( | |
477 url, mime_type, allow_wildcard, &plugins, &mime_types); | |
478 if (is_stale) | |
479 *is_stale = stale; | |
480 if (plugins.size() > 1 && | |
481 plugins.back().path == | |
482 FilePath(webkit::npapi::kDefaultPluginLibraryName)) { | |
483 // If there is at least one plug-in handling the required MIME type (apart | |
484 // from the default plug-in), we don't need the default plug-in. | |
485 plugins.pop_back(); | |
486 } | |
487 | |
488 for (size_t i = 0; i < plugins.size(); ++i) { | |
489 if (!filter_ || filter_->ShouldUsePlugin(render_process_id, | |
490 render_view_id, | |
491 &context, | |
492 url, | |
493 page_url, | |
494 &plugins[i])) { | |
495 *info = plugins[i]; | |
496 if (actual_mime_type) | |
497 *actual_mime_type = mime_types[i]; | |
498 return true; | |
499 } | |
500 } | |
501 return false; | |
502 } | |
503 | |
504 bool PluginService::GetPluginInfoByPath(const FilePath& plugin_path, | |
505 webkit::WebPluginInfo* info) { | |
506 std::vector<webkit::WebPluginInfo> plugins; | |
507 plugin_list_->GetPluginsIfNoRefreshNeeded(&plugins); | |
508 | |
509 for (std::vector<webkit::WebPluginInfo>::iterator it = plugins.begin(); | |
510 it != plugins.end(); | |
511 ++it) { | |
512 if (it->path == plugin_path) { | |
513 *info = *it; | |
514 return true; | |
515 } | |
516 } | |
517 | |
518 return false; | |
519 } | |
520 | |
521 void PluginService::GetPlugins(const GetPluginsCallback& callback) { | |
522 scoped_refptr<base::MessageLoopProxy> target_loop( | |
523 MessageLoop::current()->message_loop_proxy()); | |
524 | |
525 #if defined(OS_WIN) | |
526 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | |
527 base::Bind(&PluginService::GetPluginsInternal, base::Unretained(this), | |
528 target_loop, callback)); | |
529 #else | |
530 std::vector<webkit::WebPluginInfo> cached_plugins; | |
531 if (plugin_list_->GetPluginsIfNoRefreshNeeded(&cached_plugins)) { | |
532 // Can't assume the caller is reentrant. | |
533 target_loop->PostTask(FROM_HERE, | |
534 base::Bind(&RunGetPluginsCallback, callback, cached_plugins)); | |
535 } else { | |
536 // If we switch back to loading plugins in process, then we need to make | |
537 // sure g_thread_init() gets called since plugins may call glib at load. | |
538 if (!plugin_loader_.get()) | |
539 plugin_loader_ = new PluginLoaderPosix; | |
540 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | |
541 base::Bind(&PluginLoaderPosix::LoadPlugins, plugin_loader_, | |
542 target_loop, callback)); | |
543 } | |
544 #endif | |
545 } | |
546 | |
547 void PluginService::GetPluginGroups(const GetPluginGroupsCallback& callback) { | |
548 GetPlugins(base::Bind(&GetPluginsForGroupsCallback, callback)); | |
549 } | |
550 | |
551 void PluginService::GetPluginsInternal( | |
552 base::MessageLoopProxy* target_loop, | |
553 const PluginService::GetPluginsCallback& callback) { | |
554 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | |
555 | |
556 std::vector<webkit::WebPluginInfo> plugins; | |
557 plugin_list_->GetPlugins(&plugins); | |
558 | |
559 target_loop->PostTask(FROM_HERE, | |
560 base::Bind(&RunGetPluginsCallback, callback, plugins)); | |
561 } | |
562 | |
563 void PluginService::OnWaitableEventSignaled( | |
564 base::WaitableEvent* waitable_event) { | |
565 #if defined(OS_WIN) | |
566 if (waitable_event == hkcu_event_.get()) { | |
567 hkcu_key_.StartWatching(); | |
568 } else { | |
569 hklm_key_.StartWatching(); | |
570 } | |
571 | |
572 plugin_list_->RefreshPlugins(); | |
573 PurgePluginListCache(NULL, false); | |
574 #else | |
575 // This event should only get signaled on a Windows machine. | |
576 NOTREACHED(); | |
577 #endif // defined(OS_WIN) | |
578 } | |
579 | |
580 void PluginService::Observe(int type, | |
581 const content::NotificationSource& source, | |
582 const content::NotificationDetails& details) { | |
583 #if defined(OS_MACOSX) | |
584 if (type == content::NOTIFICATION_APP_ACTIVATED) { | |
585 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | |
586 base::Bind(&NotifyPluginsOfActivation)); | |
587 return; | |
588 } | |
589 #endif | |
590 NOTREACHED(); | |
591 } | |
592 | |
593 void PluginService::RegisterPepperPlugins() { | |
594 // TODO(abarth): It seems like the PepperPluginRegistry should do this work. | |
595 PepperPluginRegistry::ComputeList(&ppapi_plugins_); | |
596 for (size_t i = 0; i < ppapi_plugins_.size(); ++i) { | |
597 RegisterInternalPlugin(ppapi_plugins_[i].ToWebPluginInfo()); | |
598 } | |
599 } | |
600 | |
601 // There should generally be very few plugins so a brute-force search is fine. | |
602 content::PepperPluginInfo* PluginService::GetRegisteredPpapiPluginInfo( | |
603 const FilePath& plugin_path) { | |
604 content::PepperPluginInfo* info = NULL; | |
605 for (size_t i = 0; i < ppapi_plugins_.size(); i++) { | |
606 if (ppapi_plugins_[i].path == plugin_path) { | |
607 info = &ppapi_plugins_[i]; | |
608 break; | |
609 } | |
610 } | |
611 if (info) | |
612 return info; | |
613 // We did not find the plugin in our list. But wait! the plugin can also | |
614 // be a latecomer, as it happens with pepper flash. This information | |
615 // can be obtained from the PluginList singleton and we can use it to | |
616 // construct it and add it to the list. This same deal needs to be done | |
617 // in the renderer side in PepperPluginRegistry. | |
618 webkit::WebPluginInfo webplugin_info; | |
619 if (!GetPluginInfoByPath(plugin_path, &webplugin_info)) | |
620 return NULL; | |
621 content::PepperPluginInfo new_pepper_info; | |
622 if (!MakePepperPluginInfo(webplugin_info, &new_pepper_info)) | |
623 return NULL; | |
624 ppapi_plugins_.push_back(new_pepper_info); | |
625 return &ppapi_plugins_[ppapi_plugins_.size() - 1]; | |
626 } | |
627 | |
628 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_OPENBSD) | |
629 // static | |
630 void PluginService::RegisterFilePathWatcher( | |
631 FilePathWatcher *watcher, | |
632 const FilePath& path, | |
633 FilePathWatcher::Delegate* delegate) { | |
634 bool result = watcher->Watch(path, delegate); | |
635 DCHECK(result); | |
636 } | |
637 #endif | |
638 | |
639 void PluginService::SetFilter(content::PluginServiceFilter* filter) { | |
640 filter_ = filter; | |
641 } | |
642 | |
643 content::PluginServiceFilter* PluginService::GetFilter() { | |
644 return filter_; | |
645 } | |
646 | |
647 void PluginService::RefreshPlugins() { | |
648 plugin_list_->RefreshPlugins(); | |
649 } | |
650 | |
651 void PluginService::AddExtraPluginPath(const FilePath& path) { | |
652 plugin_list_->AddExtraPluginPath(path); | |
653 } | |
654 | |
655 void PluginService::RemoveExtraPluginPath(const FilePath& path) { | |
656 plugin_list_->RemoveExtraPluginPath(path); | |
657 } | |
658 | |
659 void PluginService::UnregisterInternalPlugin(const FilePath& path) { | |
660 plugin_list_->UnregisterInternalPlugin(path); | |
661 } | |
662 | |
663 void PluginService::SetPluginListForTesting( | |
664 webkit::npapi::PluginList* plugin_list) { | |
665 plugin_list_ = plugin_list; | |
666 } | |
667 | |
668 void PluginService::RegisterInternalPlugin(const webkit::WebPluginInfo& info) { | |
669 plugin_list_->RegisterInternalPlugin(info); | |
670 } | |
671 | |
672 string16 PluginService::GetPluginGroupName(const std::string& plugin_name) { | |
673 return plugin_list_->GetPluginGroupName(plugin_name); | |
674 } | |
675 | |
676 webkit::npapi::PluginList* PluginService::GetPluginList() { | |
677 return plugin_list_; | |
678 } | |
OLD | NEW |