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" |
11 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
12 #include "base/message_loop_proxy.h" | 12 #include "base/message_loop_proxy.h" |
13 #include "base/path_service.h" | 13 #include "base/path_service.h" |
14 #include "base/string_util.h" | 14 #include "base/string_util.h" |
15 #include "base/synchronization/waitable_event.h" | 15 #include "base/synchronization/waitable_event.h" |
16 #include "base/threading/thread.h" | 16 #include "base/threading/thread.h" |
17 #include "base/utf_string_conversions.h" | 17 #include "base/utf_string_conversions.h" |
18 #include "base/values.h" | 18 #include "base/values.h" |
19 #include "content/browser/browser_thread.h" | 19 #include "content/browser/browser_thread.h" |
20 #include "content/browser/content_browser_client.h" | 20 #include "content/browser/content_browser_client.h" |
21 #include "content/browser/plugin_service_filter.h" | 21 #include "content/browser/plugin_service_filter.h" |
22 #include "content/browser/ppapi_plugin_process_host.h" | 22 #include "content/browser/ppapi_plugin_process_host.h" |
23 #include "content/browser/renderer_host/render_process_host.h" | 23 #include "content/browser/renderer_host/render_process_host.h" |
24 #include "content/browser/renderer_host/render_view_host.h" | 24 #include "content/browser/renderer_host/render_view_host.h" |
25 #include "content/browser/resource_context.h" | 25 #include "content/browser/resource_context.h" |
26 #include "content/browser/utility_process_host.h" | |
27 #include "content/common/content_notification_types.h" | 26 #include "content/common/content_notification_types.h" |
28 #include "content/common/content_switches.h" | 27 #include "content/common/content_switches.h" |
29 #include "content/common/notification_service.h" | 28 #include "content/common/notification_service.h" |
30 #include "content/common/pepper_plugin_registry.h" | 29 #include "content/common/pepper_plugin_registry.h" |
31 #include "content/common/plugin_messages.h" | 30 #include "content/common/plugin_messages.h" |
32 #include "content/common/utility_messages.h" | |
33 #include "content/common/view_messages.h" | 31 #include "content/common/view_messages.h" |
34 #include "webkit/plugins/npapi/plugin_constants_win.h" | 32 #include "webkit/plugins/npapi/plugin_constants_win.h" |
35 #include "webkit/plugins/npapi/plugin_group.h" | 33 #include "webkit/plugins/npapi/plugin_group.h" |
36 #include "webkit/plugins/npapi/plugin_list.h" | 34 #include "webkit/plugins/npapi/plugin_list.h" |
37 #include "webkit/plugins/webplugininfo.h" | 35 #include "webkit/plugins/webplugininfo.h" |
38 | 36 |
| 37 #if defined(OS_POSIX) |
| 38 #include "content/browser/plugin_loader.h" |
| 39 #endif |
| 40 |
39 #if defined(OS_POSIX) && !defined(OS_MACOSX) | 41 #if defined(OS_POSIX) && !defined(OS_MACOSX) |
40 using ::base::files::FilePathWatcher; | 42 using ::base::files::FilePathWatcher; |
41 #endif | 43 #endif |
42 | 44 |
43 using content::PluginServiceFilter; | 45 using content::PluginServiceFilter; |
44 | 46 |
45 namespace { | 47 namespace { |
46 | 48 |
47 // Helper function that merely runs the callback with the result. Called on the | 49 // Helper function that merely runs the callback with the result. Called on the |
48 // thread on which the original GetPlugins() call was made. | 50 // thread on which the original GetPlugins() call was made. |
(...skipping 17 matching lines...) Expand all Loading... |
66 // correct thread. | 68 // correct thread. |
67 void WillLoadPluginsCallback() { | 69 void WillLoadPluginsCallback() { |
68 // TODO(rsesek): Change these to CHECKs. | 70 // TODO(rsesek): Change these to CHECKs. |
69 #if defined(OS_WIN) || (defined(OS_POSIX) && !defined(OS_MACOSX)) | 71 #if defined(OS_WIN) || (defined(OS_POSIX) && !defined(OS_MACOSX)) |
70 CHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 72 CHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
71 #else | 73 #else |
72 CHECK(false) << "Plugin loading should happen out-of-process."; | 74 CHECK(false) << "Plugin loading should happen out-of-process."; |
73 #endif | 75 #endif |
74 } | 76 } |
75 | 77 |
76 #if defined(OS_POSIX) | |
77 // Utility child process client that manages the IPC for loading plugins out of | |
78 // process. | |
79 class PluginLoaderClient : public UtilityProcessHost::Client { | |
80 public: | |
81 // Meant to be called on the IO thread. Will invoke the callback on the target | |
82 // loop when the plugins have been loaded. | |
83 static void LoadPluginsOutOfProcess( | |
84 base::MessageLoopProxy* target_loop, | |
85 const PluginService::GetPluginsCallback& callback) { | |
86 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
87 | |
88 PluginLoaderClient* client = new PluginLoaderClient(target_loop, callback); | |
89 UtilityProcessHost* process_host = | |
90 new UtilityProcessHost(client, BrowserThread::IO); | |
91 process_host->set_no_sandbox(true); | |
92 #if defined(OS_MACOSX) | |
93 process_host->set_child_flags(ChildProcessHost::CHILD_ALLOW_HEAP_EXECUTION); | |
94 #endif | |
95 | |
96 std::vector<FilePath> extra_plugin_paths; | |
97 std::vector<FilePath> extra_plugin_dirs; | |
98 std::vector<webkit::WebPluginInfo> internal_plugins; | |
99 webkit::npapi::PluginList::Singleton()->GetPluginPathListsToLoad( | |
100 &extra_plugin_paths, &extra_plugin_dirs, &internal_plugins); | |
101 | |
102 process_host->Send(new UtilityMsg_LoadPlugins( | |
103 extra_plugin_paths, extra_plugin_dirs, internal_plugins)); | |
104 } | |
105 | |
106 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE { | |
107 bool handled = true; | |
108 IPC_BEGIN_MESSAGE_MAP(PluginLoaderClient, message) | |
109 IPC_MESSAGE_HANDLER(UtilityHostMsg_LoadedPlugins, OnGotPlugins) | |
110 IPC_MESSAGE_UNHANDLED(handled = false) | |
111 IPC_END_MESSAGE_MAP() | |
112 return handled; | |
113 } | |
114 | |
115 virtual void OnProcessCrashed(int exit_code) OVERRIDE { | |
116 LOG(ERROR) << "Out-of-process plugin loader crashed with code " << exit_code | |
117 << ". You will have no plugins!"; | |
118 // Don't leave callers hanging. | |
119 OnGotPlugins(std::vector<webkit::WebPluginInfo>()); | |
120 } | |
121 | |
122 virtual void OnGotPlugins(const std::vector<webkit::WebPluginInfo>& plugins) { | |
123 webkit::npapi::PluginList::Singleton()->SetPlugins(plugins); | |
124 target_loop_->PostTask(FROM_HERE, | |
125 base::Bind(&RunGetPluginsCallback, callback_, plugins)); | |
126 } | |
127 | |
128 private: | |
129 PluginLoaderClient(base::MessageLoopProxy* target_loop, | |
130 const PluginService::GetPluginsCallback& callback) | |
131 : target_loop_(target_loop), | |
132 callback_(callback) { | |
133 } | |
134 | |
135 scoped_refptr<base::MessageLoopProxy> target_loop_; | |
136 PluginService::GetPluginsCallback callback_; | |
137 | |
138 DISALLOW_COPY_AND_ASSIGN(PluginLoaderClient); | |
139 }; | |
140 #endif // OS_POSIX | |
141 | |
142 } // namespace | 78 } // namespace |
143 | 79 |
144 #if defined(OS_MACOSX) | 80 #if defined(OS_MACOSX) |
145 static void NotifyPluginsOfActivation() { | 81 static void NotifyPluginsOfActivation() { |
146 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 82 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
147 | 83 |
148 for (BrowserChildProcessHost::Iterator iter(ChildProcessInfo::PLUGIN_PROCESS); | 84 for (BrowserChildProcessHost::Iterator iter(ChildProcessInfo::PLUGIN_PROCESS); |
149 !iter.Done(); ++iter) { | 85 !iter.Done(); ++iter) { |
150 PluginProcessHost* plugin = static_cast<PluginProcessHost*>(*iter); | 86 PluginProcessHost* plugin = static_cast<PluginProcessHost*>(*iter); |
151 plugin->OnAppActivation(); | 87 plugin->OnAppActivation(); |
(...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
567 target_loop, callback)); | 503 target_loop, callback)); |
568 #else | 504 #else |
569 std::vector<webkit::WebPluginInfo> cached_plugins; | 505 std::vector<webkit::WebPluginInfo> cached_plugins; |
570 if (webkit::npapi::PluginList::Singleton()->GetPluginsIfNoRefreshNeeded( | 506 if (webkit::npapi::PluginList::Singleton()->GetPluginsIfNoRefreshNeeded( |
571 &cached_plugins)) { | 507 &cached_plugins)) { |
572 // Can't assume the caller is reentrant. | 508 // Can't assume the caller is reentrant. |
573 target_loop->PostTask(FROM_HERE, | 509 target_loop->PostTask(FROM_HERE, |
574 base::Bind(&RunGetPluginsCallback, callback, cached_plugins)); | 510 base::Bind(&RunGetPluginsCallback, callback, cached_plugins)); |
575 } else { | 511 } else { |
576 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | 512 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
577 base::Bind(&PluginLoaderClient::LoadPluginsOutOfProcess, | 513 base::Bind(&PluginService::LoadPluginsOutOfProcess, |
578 target_loop, callback)); | 514 base::Unretained(this), target_loop, callback)); |
579 } | 515 } |
580 #endif | 516 #endif |
581 } | 517 } |
582 | 518 |
583 void PluginService::GetPluginGroups(const GetPluginGroupsCallback& callback) { | 519 void PluginService::GetPluginGroups(const GetPluginGroupsCallback& callback) { |
584 GetPlugins(base::Bind(&GetPluginsForGroupsCallback, callback)); | 520 GetPlugins(base::Bind(&GetPluginsForGroupsCallback, callback)); |
585 } | 521 } |
586 | 522 |
587 void PluginService::GetPluginsInternal( | 523 void PluginService::GetPluginsInternal( |
588 base::MessageLoopProxy* target_loop, | 524 base::MessageLoopProxy* target_loop, |
589 const PluginService::GetPluginsCallback& callback) { | 525 const PluginService::GetPluginsCallback& callback) { |
590 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 526 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
591 | 527 |
592 std::vector<webkit::WebPluginInfo> plugins; | 528 std::vector<webkit::WebPluginInfo> plugins; |
593 webkit::npapi::PluginList::Singleton()->GetPlugins(&plugins); | 529 webkit::npapi::PluginList::Singleton()->GetPlugins(&plugins); |
594 | 530 |
595 target_loop->PostTask(FROM_HERE, | 531 target_loop->PostTask(FROM_HERE, |
596 base::Bind(&RunGetPluginsCallback, callback, plugins)); | 532 base::Bind(&RunGetPluginsCallback, callback, plugins)); |
597 } | 533 } |
598 | 534 |
| 535 #if defined(OS_POSIX) |
| 536 void PluginService::LoadPluginsOutOfProcess( |
| 537 base::MessageLoopProxy* target_loop, |
| 538 const PluginService::GetPluginsCallback& callback) { |
| 539 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 540 if (!plugin_loader_) |
| 541 plugin_loader_ = new PluginLoader(); |
| 542 plugin_loader_->LoadPlugins(target_loop, callback); |
| 543 } |
| 544 #endif |
| 545 |
599 void PluginService::OnWaitableEventSignaled( | 546 void PluginService::OnWaitableEventSignaled( |
600 base::WaitableEvent* waitable_event) { | 547 base::WaitableEvent* waitable_event) { |
601 #if defined(OS_WIN) | 548 #if defined(OS_WIN) |
602 if (waitable_event == hkcu_event_.get()) { | 549 if (waitable_event == hkcu_event_.get()) { |
603 hkcu_key_.StartWatching(); | 550 hkcu_key_.StartWatching(); |
604 } else { | 551 } else { |
605 hklm_key_.StartWatching(); | 552 hklm_key_.StartWatching(); |
606 } | 553 } |
607 | 554 |
608 webkit::npapi::PluginList::Singleton()->RefreshPlugins(); | 555 webkit::npapi::PluginList::Singleton()->RefreshPlugins(); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
676 #if defined(OS_POSIX) && !defined(OS_MACOSX) | 623 #if defined(OS_POSIX) && !defined(OS_MACOSX) |
677 // static | 624 // static |
678 void PluginService::RegisterFilePathWatcher( | 625 void PluginService::RegisterFilePathWatcher( |
679 FilePathWatcher *watcher, | 626 FilePathWatcher *watcher, |
680 const FilePath& path, | 627 const FilePath& path, |
681 FilePathWatcher::Delegate* delegate) { | 628 FilePathWatcher::Delegate* delegate) { |
682 bool result = watcher->Watch(path, delegate); | 629 bool result = watcher->Watch(path, delegate); |
683 DCHECK(result); | 630 DCHECK(result); |
684 } | 631 } |
685 #endif | 632 #endif |
OLD | NEW |