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