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/command_line.h" | 8 #include "base/command_line.h" |
8 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
9 #include "base/file_path.h" | 10 #include "base/file_path.h" |
| 11 #include "base/message_loop.h" |
| 12 #include "base/message_loop_proxy.h" |
10 #include "base/path_service.h" | 13 #include "base/path_service.h" |
11 #include "base/string_util.h" | 14 #include "base/string_util.h" |
12 #include "base/synchronization/waitable_event.h" | 15 #include "base/synchronization/waitable_event.h" |
13 #include "base/threading/thread.h" | 16 #include "base/threading/thread.h" |
14 #include "base/utf_string_conversions.h" | 17 #include "base/utf_string_conversions.h" |
15 #include "base/values.h" | 18 #include "base/values.h" |
16 #include "content/browser/browser_thread.h" | 19 #include "content/browser/browser_thread.h" |
17 #include "content/browser/content_browser_client.h" | 20 #include "content/browser/content_browser_client.h" |
18 #include "content/browser/plugin_service_filter.h" | 21 #include "content/browser/plugin_service_filter.h" |
19 #include "content/browser/ppapi_plugin_process_host.h" | 22 #include "content/browser/ppapi_plugin_process_host.h" |
20 #include "content/browser/renderer_host/render_process_host.h" | 23 #include "content/browser/renderer_host/render_process_host.h" |
21 #include "content/browser/renderer_host/render_view_host.h" | 24 #include "content/browser/renderer_host/render_view_host.h" |
22 #include "content/browser/resource_context.h" | 25 #include "content/browser/resource_context.h" |
23 #include "content/common/content_notification_types.h" | 26 #include "content/common/content_notification_types.h" |
24 #include "content/common/content_switches.h" | 27 #include "content/common/content_switches.h" |
25 #include "content/common/notification_service.h" | 28 #include "content/common/notification_service.h" |
26 #include "content/common/pepper_plugin_registry.h" | 29 #include "content/common/pepper_plugin_registry.h" |
27 #include "content/common/plugin_messages.h" | 30 #include "content/common/plugin_messages.h" |
28 #include "content/common/view_messages.h" | 31 #include "content/common/view_messages.h" |
29 #include "webkit/plugins/npapi/plugin_constants_win.h" | 32 #include "webkit/plugins/npapi/plugin_constants_win.h" |
| 33 #include "webkit/plugins/npapi/plugin_group.h" |
30 #include "webkit/plugins/npapi/plugin_list.h" | 34 #include "webkit/plugins/npapi/plugin_list.h" |
31 #include "webkit/plugins/webplugininfo.h" | 35 #include "webkit/plugins/webplugininfo.h" |
32 | 36 |
33 #if defined(OS_POSIX) && !defined(OS_MACOSX) | 37 #if defined(OS_POSIX) && !defined(OS_MACOSX) |
34 using ::base::files::FilePathWatcher; | 38 using ::base::files::FilePathWatcher; |
35 #endif | 39 #endif |
36 | 40 |
37 using content::PluginServiceFilter; | 41 using content::PluginServiceFilter; |
38 | 42 |
| 43 namespace { |
| 44 |
| 45 // Helper function that merely runs the callback with the result. Called on the |
| 46 // thread on which the original GetPlugins() call was made. |
| 47 static void RunGetPluginsCallback( |
| 48 const PluginService::GetPluginsCallback& callback, |
| 49 const std::vector<webkit::WebPluginInfo>& result) { |
| 50 callback.Run(result); |
| 51 } |
| 52 |
| 53 // A callback for GetPlugins() that then gets the freshly loaded plugin groups |
| 54 // and runs the callback for GetPluginGroups(). |
| 55 static void GetPluginsForGroupsCallback( |
| 56 const PluginService::GetPluginGroupsCallback& callback, |
| 57 const std::vector<webkit::WebPluginInfo>& plugins) { |
| 58 std::vector<webkit::npapi::PluginGroup> groups; |
| 59 webkit::npapi::PluginList::Singleton()->GetPluginGroups(false, &groups); |
| 60 callback.Run(groups); |
| 61 } |
| 62 |
| 63 } // namespace |
| 64 |
39 #if defined(OS_MACOSX) | 65 #if defined(OS_MACOSX) |
40 static void NotifyPluginsOfActivation() { | 66 static void NotifyPluginsOfActivation() { |
41 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 67 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
42 | 68 |
43 for (BrowserChildProcessHost::Iterator iter(ChildProcessInfo::PLUGIN_PROCESS); | 69 for (BrowserChildProcessHost::Iterator iter(ChildProcessInfo::PLUGIN_PROCESS); |
44 !iter.Done(); ++iter) { | 70 !iter.Done(); ++iter) { |
45 PluginProcessHost* plugin = static_cast<PluginProcessHost*>(*iter); | 71 PluginProcessHost* plugin = static_cast<PluginProcessHost*>(*iter); |
46 plugin->OnAppActivation(); | 72 plugin->OnAppActivation(); |
47 } | 73 } |
48 } | 74 } |
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
410 &plugins[i])) { | 436 &plugins[i])) { |
411 *info = plugins[i]; | 437 *info = plugins[i]; |
412 if (actual_mime_type) | 438 if (actual_mime_type) |
413 *actual_mime_type = mime_types[i]; | 439 *actual_mime_type = mime_types[i]; |
414 return true; | 440 return true; |
415 } | 441 } |
416 } | 442 } |
417 return false; | 443 return false; |
418 } | 444 } |
419 | 445 |
420 void PluginService::GetPlugins( | 446 void PluginService::RefreshPluginList() { |
421 const content::ResourceContext& context, | 447 webkit::npapi::PluginList::Singleton()->RefreshPlugins(); |
422 std::vector<webkit::WebPluginInfo>* plugins) { | 448 } |
423 // GetPlugins may need to load the plugins, so we need to be | 449 |
424 // on the FILE thread. | 450 void PluginService::GetPlugins(const GetPluginsCallback& callback) { |
| 451 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
| 452 base::Bind(&PluginService::GetPluginsInternal, base::Unretained(this), |
| 453 MessageLoop::current()->message_loop_proxy(), |
| 454 callback)); |
| 455 } |
| 456 |
| 457 void PluginService::GetPluginGroups(const GetPluginGroupsCallback& callback) { |
| 458 GetPlugins(base::Bind(&GetPluginsForGroupsCallback, callback)); |
| 459 } |
| 460 |
| 461 void PluginService::GetPluginsInternal( |
| 462 base::MessageLoopProxy* target_loop, |
| 463 const PluginService::GetPluginsCallback& callback) { |
425 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 464 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
426 webkit::npapi::PluginList* plugin_list = | |
427 webkit::npapi::PluginList::Singleton(); | |
428 std::vector<webkit::WebPluginInfo> all_plugins; | |
429 plugin_list->GetPlugins(&all_plugins); | |
430 | 465 |
431 int child_process_id = -1; | 466 std::vector<webkit::WebPluginInfo> plugins; |
432 int routing_id = MSG_ROUTING_NONE; | 467 webkit::npapi::PluginList::Singleton()->GetPlugins(&plugins); |
433 for (size_t i = 0; i < all_plugins.size(); ++i) { | 468 |
434 if (!filter_ || filter_->ShouldUsePlugin(child_process_id, | 469 target_loop->PostTask(FROM_HERE, |
435 routing_id, | 470 base::Bind(&RunGetPluginsCallback, callback, plugins)); |
436 &context, | |
437 GURL(), | |
438 GURL(), | |
439 &all_plugins[i])) { | |
440 plugins->push_back(all_plugins[i]); | |
441 } | |
442 } | |
443 } | 471 } |
444 | 472 |
445 void PluginService::OnWaitableEventSignaled( | 473 void PluginService::OnWaitableEventSignaled( |
446 base::WaitableEvent* waitable_event) { | 474 base::WaitableEvent* waitable_event) { |
447 #if defined(OS_WIN) | 475 #if defined(OS_WIN) |
448 if (waitable_event == hkcu_event_.get()) { | 476 if (waitable_event == hkcu_event_.get()) { |
449 hkcu_key_.StartWatching(); | 477 hkcu_key_.StartWatching(); |
450 } else { | 478 } else { |
451 hklm_key_.StartWatching(); | 479 hklm_key_.StartWatching(); |
452 } | 480 } |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
519 #if defined(OS_POSIX) && !defined(OS_MACOSX) | 547 #if defined(OS_POSIX) && !defined(OS_MACOSX) |
520 // static | 548 // static |
521 void PluginService::RegisterFilePathWatcher( | 549 void PluginService::RegisterFilePathWatcher( |
522 FilePathWatcher *watcher, | 550 FilePathWatcher *watcher, |
523 const FilePath& path, | 551 const FilePath& path, |
524 FilePathWatcher::Delegate* delegate) { | 552 FilePathWatcher::Delegate* delegate) { |
525 bool result = watcher->Watch(path, delegate); | 553 bool result = watcher->Watch(path, delegate); |
526 DCHECK(result); | 554 DCHECK(result); |
527 } | 555 } |
528 #endif | 556 #endif |
OLD | NEW |