[email protected] | a08ebea | 2011-02-13 17:50:20 | [diff] [blame] | 1 | // Copyright (c) 2011 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] | a042173 | 2011-02-23 03:55:40 | [diff] [blame] | 5 | #include "content/browser/plugin_service.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 6 | |
[email protected] | d48f1e0c | 2009-02-12 20:57:54 | [diff] [blame] | 7 | #include "base/command_line.h" |
[email protected] | 7b3ee8b | 2011-04-01 18:48:19 | [diff] [blame] | 8 | #include "base/compiler_specific.h" |
[email protected] | dfba876 | 2011-09-02 12:49:54 | [diff] [blame] | 9 | #include "base/file_path.h" |
[email protected] | 9c49ff0 | 2010-01-27 01:20:55 | [diff] [blame] | 10 | #include "base/path_service.h" |
[email protected] | d70539de | 2009-06-24 22:17:06 | [diff] [blame] | 11 | #include "base/string_util.h" |
[email protected] | 7f070d4 | 2011-03-09 20:25:32 | [diff] [blame] | 12 | #include "base/synchronization/waitable_event.h" |
[email protected] | 34b9963 | 2011-01-01 01:01:06 | [diff] [blame] | 13 | #include "base/threading/thread.h" |
[email protected] | be1ce6a7 | 2010-08-03 14:35:22 | [diff] [blame] | 14 | #include "base/utf_string_conversions.h" |
[email protected] | cec1b8d | 2010-03-24 00:21:34 | [diff] [blame] | 15 | #include "base/values.h" |
[email protected] | a042173 | 2011-02-23 03:55:40 | [diff] [blame] | 16 | #include "content/browser/browser_thread.h" |
[email protected] | de23f3f | 2011-05-18 16:20:23 | [diff] [blame] | 17 | #include "content/browser/content_browser_client.h" |
[email protected] | dfba876 | 2011-09-02 12:49:54 | [diff] [blame] | 18 | #include "content/browser/plugin_service_filter.h" |
[email protected] | a01efd2 | 2011-03-01 00:38:32 | [diff] [blame] | 19 | #include "content/browser/ppapi_plugin_process_host.h" |
[email protected] | a042173 | 2011-02-23 03:55:40 | [diff] [blame] | 20 | #include "content/browser/renderer_host/render_process_host.h" |
| 21 | #include "content/browser/renderer_host/render_view_host.h" |
[email protected] | d259a8e | 2011-05-18 22:31:09 | [diff] [blame] | 22 | #include "content/browser/resource_context.h" |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 23 | #include "content/common/content_notification_types.h" |
[email protected] | 4287a3d | 2011-06-13 23:56:51 | [diff] [blame] | 24 | #include "content/common/content_switches.h" |
[email protected] | 7f070d4 | 2011-03-09 20:25:32 | [diff] [blame] | 25 | #include "content/common/notification_service.h" |
[email protected] | cebc3dc | 2011-04-18 17:15:00 | [diff] [blame] | 26 | #include "content/common/pepper_plugin_registry.h" |
[email protected] | 105303e | 2011-03-14 22:16:10 | [diff] [blame] | 27 | #include "content/common/plugin_messages.h" |
[email protected] | 38b59290 | 2011-04-16 02:08:42 | [diff] [blame] | 28 | #include "content/common/view_messages.h" |
[email protected] | 191eb3f7 | 2010-12-21 06:27:50 | [diff] [blame] | 29 | #include "webkit/plugins/npapi/plugin_constants_win.h" |
| 30 | #include "webkit/plugins/npapi/plugin_list.h" |
[email protected] | 91d9f3d | 2011-08-14 05:24:44 | [diff] [blame] | 31 | #include "webkit/plugins/webplugininfo.h" |
[email protected] | 191eb3f7 | 2010-12-21 06:27:50 | [diff] [blame] | 32 | |
[email protected] | e63c4d7 | 2011-05-31 22:38:29 | [diff] [blame] | 33 | #if defined(OS_POSIX) && !defined(OS_MACOSX) |
[email protected] | 493c800 | 2011-04-14 16:56:01 | [diff] [blame] | 34 | using ::base::files::FilePathWatcher; |
| 35 | #endif |
| 36 | |
[email protected] | dfba876 | 2011-09-02 12:49:54 | [diff] [blame] | 37 | using content::PluginServiceFilter; |
| 38 | |
[email protected] | a96ec6a | 2009-11-04 17:27:08 | [diff] [blame] | 39 | #if defined(OS_MACOSX) |
| 40 | static void NotifyPluginsOfActivation() { |
[email protected] | f8b3ef8 | 2010-10-11 02:45:52 | [diff] [blame] | 41 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
[email protected] | a96ec6a | 2009-11-04 17:27:08 | [diff] [blame] | 42 | |
[email protected] | d27893f6 | 2010-07-03 05:47:42 | [diff] [blame] | 43 | for (BrowserChildProcessHost::Iterator iter(ChildProcessInfo::PLUGIN_PROCESS); |
[email protected] | a96ec6a | 2009-11-04 17:27:08 | [diff] [blame] | 44 | !iter.Done(); ++iter) { |
| 45 | PluginProcessHost* plugin = static_cast<PluginProcessHost*>(*iter); |
| 46 | plugin->OnAppActivation(); |
| 47 | } |
| 48 | } |
[email protected] | e63c4d7 | 2011-05-31 22:38:29 | [diff] [blame] | 49 | #elif defined(OS_POSIX) |
[email protected] | 634d23d | 2011-01-19 10:38:19 | [diff] [blame] | 50 | // Delegate class for monitoring directories. |
| 51 | class PluginDirWatcherDelegate : public FilePathWatcher::Delegate { |
[email protected] | 7b3ee8b | 2011-04-01 18:48:19 | [diff] [blame] | 52 | virtual void OnFilePathChanged(const FilePath& path) OVERRIDE { |
[email protected] | 634d23d | 2011-01-19 10:38:19 | [diff] [blame] | 53 | VLOG(1) << "Watched path changed: " << path.value(); |
| 54 | // Make the plugin list update itself |
| 55 | webkit::npapi::PluginList::Singleton()->RefreshPlugins(); |
| 56 | } |
[email protected] | 7b3ee8b | 2011-04-01 18:48:19 | [diff] [blame] | 57 | virtual void OnFilePathError(const FilePath& path) OVERRIDE { |
[email protected] | 634d23d | 2011-01-19 10:38:19 | [diff] [blame] | 58 | // TODO(pastarmovj): Add some sensible error handling. Maybe silently |
| 59 | // stopping the watcher would be enough. Or possibly restart it. |
| 60 | NOTREACHED(); |
| 61 | } |
| 62 | }; |
| 63 | #endif |
| 64 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 65 | // static |
| 66 | PluginService* PluginService::GetInstance() { |
| 67 | return Singleton<PluginService>::get(); |
| 68 | } |
| 69 | |
| 70 | PluginService::PluginService() |
[email protected] | de23f3f | 2011-05-18 16:20:23 | [diff] [blame] | 71 | : ui_locale_( |
[email protected] | dfba876 | 2011-09-02 12:49:54 | [diff] [blame] | 72 | content::GetContentClient()->browser()->GetApplicationLocale()), |
| 73 | filter_(NULL) { |
[email protected] | 4e0616e | 2010-05-28 14:55:53 | [diff] [blame] | 74 | RegisterPepperPlugins(); |
| 75 | |
[email protected] | 9a1c426 | 2010-06-29 21:50:27 | [diff] [blame] | 76 | // Load any specified on the command line as well. |
[email protected] | d48f1e0c | 2009-02-12 20:57:54 | [diff] [blame] | 77 | const CommandLine* command_line = CommandLine::ForCurrentProcess(); |
[email protected] | c4e52f0d | 2009-11-06 19:55:16 | [diff] [blame] | 78 | FilePath path = command_line->GetSwitchValuePath(switches::kLoadPlugin); |
[email protected] | 7bf795d9 | 2010-05-22 00:14:28 | [diff] [blame] | 79 | if (!path.empty()) |
[email protected] | 191eb3f7 | 2010-12-21 06:27:50 | [diff] [blame] | 80 | webkit::npapi::PluginList::Singleton()->AddExtraPluginPath(path); |
[email protected] | 9a1c426 | 2010-06-29 21:50:27 | [diff] [blame] | 81 | path = command_line->GetSwitchValuePath(switches::kExtraPluginDir); |
| 82 | if (!path.empty()) |
[email protected] | 191eb3f7 | 2010-12-21 06:27:50 | [diff] [blame] | 83 | webkit::npapi::PluginList::Singleton()->AddExtraPluginDir(path); |
[email protected] | 7bf795d9 | 2010-05-22 00:14:28 | [diff] [blame] | 84 | |
[email protected] | dfba876 | 2011-09-02 12:49:54 | [diff] [blame] | 85 | #if defined(OS_MACOSX) |
| 86 | // We need to know when the browser comes forward so we can bring modal plugin |
| 87 | // windows forward too. |
| 88 | registrar_.Add(this, content::NOTIFICATION_APP_ACTIVATED, |
| 89 | NotificationService::AllSources()); |
| 90 | #endif |
| 91 | } |
| 92 | |
| 93 | PluginService::~PluginService() { |
| 94 | #if defined(OS_WIN) |
| 95 | // Release the events since they're owned by RegKey, not WaitableEvent. |
| 96 | hkcu_watcher_.StopWatching(); |
| 97 | hklm_watcher_.StopWatching(); |
| 98 | if (hkcu_event_.get()) |
| 99 | hkcu_event_->Release(); |
| 100 | if (hklm_event_.get()) |
| 101 | hklm_event_->Release(); |
| 102 | #endif |
[email protected] | 4befe759 | 2011-09-14 22:49:09 | [diff] [blame] | 103 | // Make sure no plugin channel requests have been leaked. |
| 104 | DCHECK(pending_plugin_clients_.empty()); |
[email protected] | dfba876 | 2011-09-02 12:49:54 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | void PluginService::StartWatchingPlugins() { |
[email protected] | 634d23d | 2011-01-19 10:38:19 | [diff] [blame] | 108 | // Start watching for changes in the plugin list. This means watching |
| 109 | // for changes in the Windows registry keys and on both Windows and POSIX |
| 110 | // watch for changes in the paths that are expected to contain plugins. |
[email protected] | b547fd4 | 2009-04-23 23:16:27 | [diff] [blame] | 111 | #if defined(OS_WIN) |
[email protected] | 86ec4f6e | 2011-04-20 16:21:19 | [diff] [blame] | 112 | if (hkcu_key_.Create(HKEY_CURRENT_USER, |
| 113 | webkit::npapi::kRegistryMozillaPlugins, |
| 114 | KEY_NOTIFY) == ERROR_SUCCESS) { |
| 115 | if (hkcu_key_.StartWatching() == ERROR_SUCCESS) { |
| 116 | hkcu_event_.reset(new base::WaitableEvent(hkcu_key_.watch_event())); |
| 117 | hkcu_watcher_.StartWatching(hkcu_event_.get(), this); |
| 118 | } |
[email protected] | b547fd4 | 2009-04-23 23:16:27 | [diff] [blame] | 119 | } |
[email protected] | 86ec4f6e | 2011-04-20 16:21:19 | [diff] [blame] | 120 | if (hklm_key_.Create(HKEY_LOCAL_MACHINE, |
| 121 | webkit::npapi::kRegistryMozillaPlugins, |
| 122 | KEY_NOTIFY) == ERROR_SUCCESS) { |
| 123 | if (hklm_key_.StartWatching() == ERROR_SUCCESS) { |
| 124 | hklm_event_.reset(new base::WaitableEvent(hklm_key_.watch_event())); |
| 125 | hklm_watcher_.StartWatching(hklm_event_.get(), this); |
| 126 | } |
[email protected] | b547fd4 | 2009-04-23 23:16:27 | [diff] [blame] | 127 | } |
[email protected] | dfba876 | 2011-09-02 12:49:54 | [diff] [blame] | 128 | #elif defined(OS_POSIX) && !defined(OS_MACOSX) |
[email protected] | 634d23d | 2011-01-19 10:38:19 | [diff] [blame] | 129 | // The FilePathWatcher produces too many false positives on MacOS (access time |
| 130 | // updates?) which will lead to enforcing updates of the plugins way too often. |
| 131 | // On ChromeOS the user can't install plugins anyway and on Windows all |
| 132 | // important plugins register themselves in the registry so no need to do that. |
[email protected] | 634d23d | 2011-01-19 10:38:19 | [diff] [blame] | 133 | file_watcher_delegate_ = new PluginDirWatcherDelegate(); |
| 134 | // Get the list of all paths for registering the FilePathWatchers |
| 135 | // that will track and if needed reload the list of plugins on runtime. |
| 136 | std::vector<FilePath> plugin_dirs; |
| 137 | webkit::npapi::PluginList::Singleton()->GetPluginDirectories( |
| 138 | &plugin_dirs); |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 139 | |
[email protected] | 634d23d | 2011-01-19 10:38:19 | [diff] [blame] | 140 | for (size_t i = 0; i < plugin_dirs.size(); ++i) { |
[email protected] | 634d23d | 2011-01-19 10:38:19 | [diff] [blame] | 141 | // FilePathWatcher can not handle non-absolute paths under windows. |
| 142 | // We don't watch for file changes in windows now but if this should ever |
| 143 | // be extended to Windows these lines might save some time of debugging. |
| 144 | #if defined(OS_WIN) |
| 145 | if (!plugin_dirs[i].IsAbsolute()) |
| 146 | continue; |
| 147 | #endif |
[email protected] | 493c800 | 2011-04-14 16:56:01 | [diff] [blame] | 148 | FilePathWatcher* watcher = new FilePathWatcher(); |
[email protected] | 634d23d | 2011-01-19 10:38:19 | [diff] [blame] | 149 | VLOG(1) << "Watching for changes in: " << plugin_dirs[i].value(); |
| 150 | BrowserThread::PostTask( |
| 151 | BrowserThread::FILE, FROM_HERE, |
| 152 | NewRunnableFunction( |
| 153 | &PluginService::RegisterFilePathWatcher, |
| 154 | watcher, plugin_dirs[i], file_watcher_delegate_)); |
| 155 | file_watchers_.push_back(watcher); |
| 156 | } |
| 157 | #endif |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 158 | } |
| 159 | |
[email protected] | f77d8762 | 2010-07-30 17:43:17 | [diff] [blame] | 160 | const std::string& PluginService::GetUILocale() { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 161 | return ui_locale_; |
| 162 | } |
| 163 | |
[email protected] | a08ebea | 2011-02-13 17:50:20 | [diff] [blame] | 164 | PluginProcessHost* PluginService::FindNpapiPluginProcess( |
[email protected] | 28ab7f9 | 2009-01-06 21:39:04 | [diff] [blame] | 165 | const FilePath& plugin_path) { |
[email protected] | f8b3ef8 | 2010-10-11 02:45:52 | [diff] [blame] | 166 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 167 | |
[email protected] | d27893f6 | 2010-07-03 05:47:42 | [diff] [blame] | 168 | for (BrowserChildProcessHost::Iterator iter(ChildProcessInfo::PLUGIN_PROCESS); |
[email protected] | a436d92 | 2009-02-13 23:16:42 | [diff] [blame] | 169 | !iter.Done(); ++iter) { |
| 170 | PluginProcessHost* plugin = static_cast<PluginProcessHost*>(*iter); |
| 171 | if (plugin->info().path == plugin_path) |
| 172 | return plugin; |
| 173 | } |
| 174 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 175 | return NULL; |
| 176 | } |
| 177 | |
[email protected] | a08ebea | 2011-02-13 17:50:20 | [diff] [blame] | 178 | PpapiPluginProcessHost* PluginService::FindPpapiPluginProcess( |
[email protected] | 610c089 | 2009-09-08 19:46:18 | [diff] [blame] | 179 | const FilePath& plugin_path) { |
[email protected] | f8b3ef8 | 2010-10-11 02:45:52 | [diff] [blame] | 180 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 181 | |
[email protected] | a08ebea | 2011-02-13 17:50:20 | [diff] [blame] | 182 | for (BrowserChildProcessHost::Iterator iter( |
| 183 | ChildProcessInfo::PPAPI_PLUGIN_PROCESS); |
| 184 | !iter.Done(); ++iter) { |
| 185 | PpapiPluginProcessHost* plugin = |
| 186 | static_cast<PpapiPluginProcessHost*>(*iter); |
| 187 | if (plugin->plugin_path() == plugin_path) |
| 188 | return plugin; |
| 189 | } |
| 190 | |
| 191 | return NULL; |
| 192 | } |
| 193 | |
[email protected] | eb415bf0e | 2011-04-14 02:45:42 | [diff] [blame] | 194 | PpapiBrokerProcessHost* PluginService::FindPpapiBrokerProcess( |
| 195 | const FilePath& broker_path) { |
| 196 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 197 | |
| 198 | for (BrowserChildProcessHost::Iterator iter( |
| 199 | ChildProcessInfo::PPAPI_BROKER_PROCESS); |
| 200 | !iter.Done(); ++iter) { |
| 201 | PpapiBrokerProcessHost* broker = |
| 202 | static_cast<PpapiBrokerProcessHost*>(*iter); |
| 203 | if (broker->broker_path() == broker_path) |
| 204 | return broker; |
| 205 | } |
| 206 | |
| 207 | return NULL; |
| 208 | } |
| 209 | |
[email protected] | a08ebea | 2011-02-13 17:50:20 | [diff] [blame] | 210 | PluginProcessHost* PluginService::FindOrStartNpapiPluginProcess( |
| 211 | const FilePath& plugin_path) { |
| 212 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 213 | |
| 214 | PluginProcessHost* plugin_host = FindNpapiPluginProcess(plugin_path); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 215 | if (plugin_host) |
| 216 | return plugin_host; |
| 217 | |
[email protected] | 91d9f3d | 2011-08-14 05:24:44 | [diff] [blame] | 218 | webkit::WebPluginInfo info; |
[email protected] | 191eb3f7 | 2010-12-21 06:27:50 | [diff] [blame] | 219 | if (!webkit::npapi::PluginList::Singleton()->GetPluginInfoByPath( |
| 220 | plugin_path, &info)) { |
[email protected] | a27a938 | 2009-02-11 23:55:10 | [diff] [blame] | 221 | return NULL; |
| 222 | } |
| 223 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 224 | // 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] | 225 | scoped_ptr<PluginProcessHost> new_host(new PluginProcessHost()); |
| 226 | if (!new_host->Init(info, ui_locale_)) { |
[email protected] | a08ebea | 2011-02-13 17:50:20 | [diff] [blame] | 227 | NOTREACHED(); // Init is not expected to fail. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 228 | return NULL; |
| 229 | } |
[email protected] | 8b8a554d | 2010-11-18 13:26:40 | [diff] [blame] | 230 | return new_host.release(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 231 | } |
| 232 | |
[email protected] | a08ebea | 2011-02-13 17:50:20 | [diff] [blame] | 233 | PpapiPluginProcessHost* PluginService::FindOrStartPpapiPluginProcess( |
[email protected] | d259a8e | 2011-05-18 22:31:09 | [diff] [blame] | 234 | const FilePath& plugin_path, |
| 235 | PpapiPluginProcessHost::Client* client) { |
[email protected] | a08ebea | 2011-02-13 17:50:20 | [diff] [blame] | 236 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 237 | |
| 238 | PpapiPluginProcessHost* plugin_host = FindPpapiPluginProcess(plugin_path); |
| 239 | if (plugin_host) |
| 240 | return plugin_host; |
| 241 | |
[email protected] | eb415bf0e | 2011-04-14 02:45:42 | [diff] [blame] | 242 | // Validate that the plugin is actually registered. |
| 243 | PepperPluginInfo* info = GetRegisteredPpapiPluginInfo(plugin_path); |
[email protected] | a08ebea | 2011-02-13 17:50:20 | [diff] [blame] | 244 | if (!info) |
| 245 | return NULL; |
| 246 | |
| 247 | // This plugin isn't loaded by any plugin process, so create a new process. |
[email protected] | d259a8e | 2011-05-18 22:31:09 | [diff] [blame] | 248 | scoped_ptr<PpapiPluginProcessHost> new_host(new PpapiPluginProcessHost( |
| 249 | client->GetResourceContext()->host_resolver())); |
[email protected] | 277a111 | 2011-03-19 06:03:56 | [diff] [blame] | 250 | if (!new_host->Init(*info)) { |
[email protected] | a08ebea | 2011-02-13 17:50:20 | [diff] [blame] | 251 | NOTREACHED(); // Init is not expected to fail. |
| 252 | return NULL; |
| 253 | } |
| 254 | return new_host.release(); |
| 255 | } |
| 256 | |
[email protected] | eb415bf0e | 2011-04-14 02:45:42 | [diff] [blame] | 257 | PpapiBrokerProcessHost* PluginService::FindOrStartPpapiBrokerProcess( |
| 258 | const FilePath& plugin_path) { |
| 259 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 260 | |
| 261 | PpapiBrokerProcessHost* plugin_host = FindPpapiBrokerProcess(plugin_path); |
| 262 | if (plugin_host) |
| 263 | return plugin_host; |
| 264 | |
| 265 | // Validate that the plugin is actually registered. |
| 266 | PepperPluginInfo* info = GetRegisteredPpapiPluginInfo(plugin_path); |
| 267 | if (!info) |
| 268 | return NULL; |
| 269 | |
| 270 | // TODO(ddorwin): Uncomment once out of process is supported. |
| 271 | // DCHECK(info->is_out_of_process); |
| 272 | |
| 273 | // This broker isn't loaded by any broker process, so create a new process. |
| 274 | scoped_ptr<PpapiBrokerProcessHost> new_host( |
| 275 | new PpapiBrokerProcessHost); |
| 276 | if (!new_host->Init(*info)) { |
| 277 | NOTREACHED(); // Init is not expected to fail. |
| 278 | return NULL; |
| 279 | } |
| 280 | return new_host.release(); |
| 281 | } |
| 282 | |
[email protected] | a08ebea | 2011-02-13 17:50:20 | [diff] [blame] | 283 | void PluginService::OpenChannelToNpapiPlugin( |
[email protected] | c8f73ab | 2011-01-22 00:05:17 | [diff] [blame] | 284 | int render_process_id, |
| 285 | int render_view_id, |
[email protected] | 610c089 | 2009-09-08 19:46:18 | [diff] [blame] | 286 | const GURL& url, |
[email protected] | dfba876 | 2011-09-02 12:49:54 | [diff] [blame] | 287 | const GURL& page_url, |
[email protected] | 610c089 | 2009-09-08 19:46:18 | [diff] [blame] | 288 | const std::string& mime_type, |
[email protected] | 46b69e4 | 2010-11-02 12:26:39 | [diff] [blame] | 289 | PluginProcessHost::Client* client) { |
[email protected] | 4befe759 | 2011-09-14 22:49:09 | [diff] [blame] | 290 | DCHECK(!ContainsKey(pending_plugin_clients_, client)); |
| 291 | pending_plugin_clients_.insert(client); |
[email protected] | 11e1c18 | 2011-05-17 20:26:27 | [diff] [blame] | 292 | // The PluginList::GetPluginInfo may need to load the plugins. Don't do it on |
| 293 | // the IO thread. |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 294 | BrowserThread::PostTask( |
| 295 | BrowserThread::FILE, FROM_HERE, |
| 296 | NewRunnableMethod( |
| 297 | this, &PluginService::GetAllowedPluginForOpenChannelToPlugin, |
[email protected] | dfba876 | 2011-09-02 12:49:54 | [diff] [blame] | 298 | render_process_id, render_view_id, url, page_url, mime_type, |
[email protected] | 87c4be4 | 2011-09-16 01:10:59 | [diff] [blame^] | 299 | client, &client->GetResourceContext())); |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 300 | } |
| 301 | |
[email protected] | a08ebea | 2011-02-13 17:50:20 | [diff] [blame] | 302 | void PluginService::OpenChannelToPpapiPlugin( |
| 303 | const FilePath& path, |
| 304 | PpapiPluginProcessHost::Client* client) { |
[email protected] | d259a8e | 2011-05-18 22:31:09 | [diff] [blame] | 305 | PpapiPluginProcessHost* plugin_host = FindOrStartPpapiPluginProcess( |
| 306 | path, client); |
[email protected] | a08ebea | 2011-02-13 17:50:20 | [diff] [blame] | 307 | if (plugin_host) |
| 308 | plugin_host->OpenChannelToPlugin(client); |
| 309 | else // Send error. |
| 310 | client->OnChannelOpened(base::kNullProcessHandle, IPC::ChannelHandle()); |
| 311 | } |
| 312 | |
[email protected] | eb415bf0e | 2011-04-14 02:45:42 | [diff] [blame] | 313 | void PluginService::OpenChannelToPpapiBroker( |
| 314 | const FilePath& path, |
| 315 | PpapiBrokerProcessHost::Client* client) { |
| 316 | PpapiBrokerProcessHost* plugin_host = FindOrStartPpapiBrokerProcess(path); |
| 317 | if (plugin_host) |
| 318 | plugin_host->OpenChannelToPpapiBroker(client); |
| 319 | else // Send error. |
| 320 | client->OnChannelOpened(base::kNullProcessHandle, IPC::ChannelHandle()); |
| 321 | } |
| 322 | |
[email protected] | 4befe759 | 2011-09-14 22:49:09 | [diff] [blame] | 323 | void PluginService::CancelOpenChannelToNpapiPlugin( |
| 324 | PluginProcessHost::Client* client) { |
| 325 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 326 | DCHECK(ContainsKey(pending_plugin_clients_, client)); |
| 327 | pending_plugin_clients_.erase(client); |
| 328 | } |
| 329 | |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 330 | void PluginService::GetAllowedPluginForOpenChannelToPlugin( |
[email protected] | c8f73ab | 2011-01-22 00:05:17 | [diff] [blame] | 331 | int render_process_id, |
| 332 | int render_view_id, |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 333 | const GURL& url, |
[email protected] | dfba876 | 2011-09-02 12:49:54 | [diff] [blame] | 334 | const GURL& page_url, |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 335 | const std::string& mime_type, |
[email protected] | 87c4be4 | 2011-09-16 01:10:59 | [diff] [blame^] | 336 | PluginProcessHost::Client* client, |
| 337 | const content::ResourceContext* resource_context) { |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 338 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
[email protected] | 87c4be4 | 2011-09-16 01:10:59 | [diff] [blame^] | 339 | DCHECK(resource_context); |
[email protected] | 91d9f3d | 2011-08-14 05:24:44 | [diff] [blame] | 340 | webkit::WebPluginInfo info; |
[email protected] | dfba876 | 2011-09-02 12:49:54 | [diff] [blame] | 341 | bool allow_wildcard = true; |
[email protected] | 11e1c18 | 2011-05-17 20:26:27 | [diff] [blame] | 342 | bool found = GetPluginInfo( |
[email protected] | 87c4be4 | 2011-09-16 01:10:59 | [diff] [blame^] | 343 | render_process_id, render_view_id, *resource_context, |
[email protected] | dfba876 | 2011-09-02 12:49:54 | [diff] [blame] | 344 | url, page_url, mime_type, allow_wildcard, |
| 345 | NULL, &info, NULL); |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 346 | FilePath plugin_path; |
[email protected] | 6859807 | 2011-07-29 08:21:28 | [diff] [blame] | 347 | if (found) |
[email protected] | dfba876 | 2011-09-02 12:49:54 | [diff] [blame] | 348 | plugin_path = info.path; |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 349 | |
| 350 | // Now we jump back to the IO thread to finish opening the channel. |
| 351 | BrowserThread::PostTask( |
| 352 | BrowserThread::IO, FROM_HERE, |
| 353 | NewRunnableMethod( |
| 354 | this, &PluginService::FinishOpenChannelToPlugin, |
[email protected] | 46b69e4 | 2010-11-02 12:26:39 | [diff] [blame] | 355 | plugin_path, client)); |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 356 | } |
| 357 | |
| 358 | void PluginService::FinishOpenChannelToPlugin( |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 359 | const FilePath& plugin_path, |
[email protected] | 46b69e4 | 2010-11-02 12:26:39 | [diff] [blame] | 360 | PluginProcessHost::Client* client) { |
[email protected] | f8b3ef8 | 2010-10-11 02:45:52 | [diff] [blame] | 361 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
[email protected] | 20a793e | 2010-10-12 06:50:08 | [diff] [blame] | 362 | |
[email protected] | 4befe759 | 2011-09-14 22:49:09 | [diff] [blame] | 363 | // Make sure it hasn't been canceled yet. |
| 364 | if (!ContainsKey(pending_plugin_clients_, client)) |
| 365 | return; |
| 366 | pending_plugin_clients_.erase(client); |
| 367 | |
[email protected] | a08ebea | 2011-02-13 17:50:20 | [diff] [blame] | 368 | PluginProcessHost* plugin_host = FindOrStartNpapiPluginProcess(plugin_path); |
[email protected] | 4befe759 | 2011-09-14 22:49:09 | [diff] [blame] | 369 | if (plugin_host) { |
| 370 | client->OnFoundPluginProcessHost(plugin_host); |
[email protected] | 46b69e4 | 2010-11-02 12:26:39 | [diff] [blame] | 371 | plugin_host->OpenChannelToPlugin(client); |
[email protected] | 4befe759 | 2011-09-14 22:49:09 | [diff] [blame] | 372 | } else { |
[email protected] | 46b69e4 | 2010-11-02 12:26:39 | [diff] [blame] | 373 | client->OnError(); |
[email protected] | 4befe759 | 2011-09-14 22:49:09 | [diff] [blame] | 374 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 375 | } |
| 376 | |
[email protected] | 11e1c18 | 2011-05-17 20:26:27 | [diff] [blame] | 377 | bool PluginService::GetPluginInfo(int render_process_id, |
| 378 | int render_view_id, |
[email protected] | dfba876 | 2011-09-02 12:49:54 | [diff] [blame] | 379 | const content::ResourceContext& context, |
[email protected] | 11e1c18 | 2011-05-17 20:26:27 | [diff] [blame] | 380 | const GURL& url, |
[email protected] | dfba876 | 2011-09-02 12:49:54 | [diff] [blame] | 381 | const GURL& page_url, |
[email protected] | 11e1c18 | 2011-05-17 20:26:27 | [diff] [blame] | 382 | const std::string& mime_type, |
[email protected] | dfba876 | 2011-09-02 12:49:54 | [diff] [blame] | 383 | bool allow_wildcard, |
| 384 | bool* use_stale, |
[email protected] | 91d9f3d | 2011-08-14 05:24:44 | [diff] [blame] | 385 | webkit::WebPluginInfo* info, |
[email protected] | 11e1c18 | 2011-05-17 20:26:27 | [diff] [blame] | 386 | std::string* actual_mime_type) { |
[email protected] | dfba876 | 2011-09-02 12:49:54 | [diff] [blame] | 387 | webkit::npapi::PluginList* plugin_list = |
| 388 | webkit::npapi::PluginList::Singleton(); |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 389 | // GetPluginInfoArray may need to load the plugins, so we need to be |
| 390 | // on the FILE thread. |
[email protected] | dfba876 | 2011-09-02 12:49:54 | [diff] [blame] | 391 | DCHECK(use_stale || BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
[email protected] | 91d9f3d | 2011-08-14 05:24:44 | [diff] [blame] | 392 | std::vector<webkit::WebPluginInfo> plugins; |
[email protected] | 6859807 | 2011-07-29 08:21:28 | [diff] [blame] | 393 | std::vector<std::string> mime_types; |
[email protected] | dfba876 | 2011-09-02 12:49:54 | [diff] [blame] | 394 | plugin_list->GetPluginInfoArray( |
| 395 | url, mime_type, allow_wildcard, use_stale, &plugins, &mime_types); |
| 396 | if (plugins.size() > 1 && |
| 397 | plugins.back().path == |
| 398 | FilePath(webkit::npapi::kDefaultPluginLibraryName)) { |
| 399 | // If there is at least one plug-in handling the required MIME type (apart |
| 400 | // from the default plug-in), we don't need the default plug-in. |
| 401 | plugins.pop_back(); |
| 402 | } |
| 403 | |
[email protected] | 6859807 | 2011-07-29 08:21:28 | [diff] [blame] | 404 | for (size_t i = 0; i < plugins.size(); ++i) { |
[email protected] | dfba876 | 2011-09-02 12:49:54 | [diff] [blame] | 405 | if (!filter_ || filter_->ShouldUsePlugin(render_process_id, |
| 406 | render_view_id, |
| 407 | &context, |
| 408 | url, |
| 409 | page_url, |
| 410 | &plugins[i])) { |
[email protected] | 6859807 | 2011-07-29 08:21:28 | [diff] [blame] | 411 | *info = plugins[i]; |
| 412 | if (actual_mime_type) |
| 413 | *actual_mime_type = mime_types[i]; |
| 414 | return true; |
| 415 | } |
| 416 | } |
| 417 | return false; |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 418 | } |
| 419 | |
[email protected] | dfba876 | 2011-09-02 12:49:54 | [diff] [blame] | 420 | void PluginService::GetPlugins( |
| 421 | const content::ResourceContext& context, |
| 422 | std::vector<webkit::WebPluginInfo>* plugins) { |
| 423 | // GetPlugins may need to load the plugins, so we need to be |
| 424 | // on the FILE thread. |
| 425 | 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 | |
| 431 | int child_process_id = -1; |
| 432 | int routing_id = MSG_ROUTING_NONE; |
| 433 | for (size_t i = 0; i < all_plugins.size(); ++i) { |
| 434 | if (!filter_ || filter_->ShouldUsePlugin(child_process_id, |
| 435 | routing_id, |
| 436 | &context, |
| 437 | GURL(), |
| 438 | GURL(), |
| 439 | &all_plugins[i])) { |
| 440 | plugins->push_back(all_plugins[i]); |
| 441 | } |
| 442 | } |
| 443 | } |
| 444 | |
[email protected] | 58052263 | 2009-08-17 21:55:55 | [diff] [blame] | 445 | void PluginService::OnWaitableEventSignaled( |
| 446 | base::WaitableEvent* waitable_event) { |
[email protected] | b547fd4 | 2009-04-23 23:16:27 | [diff] [blame] | 447 | #if defined(OS_WIN) |
| 448 | if (waitable_event == hkcu_event_.get()) { |
| 449 | hkcu_key_.StartWatching(); |
| 450 | } else { |
| 451 | hklm_key_.StartWatching(); |
| 452 | } |
| 453 | |
[email protected] | 191eb3f7 | 2010-12-21 06:27:50 | [diff] [blame] | 454 | webkit::npapi::PluginList::Singleton()->RefreshPlugins(); |
[email protected] | b78e168b | 2009-09-21 22:05:45 | [diff] [blame] | 455 | PurgePluginListCache(true); |
[email protected] | 634d23d | 2011-01-19 10:38:19 | [diff] [blame] | 456 | #else |
| 457 | // This event should only get signaled on a Windows machine. |
| 458 | NOTREACHED(); |
[email protected] | 9de09f8 | 2009-08-17 20:13:53 | [diff] [blame] | 459 | #endif // defined(OS_WIN) |
[email protected] | b547fd4 | 2009-04-23 23:16:27 | [diff] [blame] | 460 | } |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 461 | |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 462 | void PluginService::Observe(int type, |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 463 | const NotificationSource& source, |
| 464 | const NotificationDetails& details) { |
[email protected] | a96ec6a | 2009-11-04 17:27:08 | [diff] [blame] | 465 | #if defined(OS_MACOSX) |
[email protected] | dfba876 | 2011-09-02 12:49:54 | [diff] [blame] | 466 | if (type == content::NOTIFICATION_APP_ACTIVATED) { |
| 467 | BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
| 468 | NewRunnableFunction(&NotifyPluginsOfActivation)); |
| 469 | return; |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 470 | } |
[email protected] | dfba876 | 2011-09-02 12:49:54 | [diff] [blame] | 471 | #endif |
| 472 | NOTREACHED(); |
[email protected] | c8f73ab | 2011-01-22 00:05:17 | [diff] [blame] | 473 | } |
| 474 | |
[email protected] | 2de30759 | 2011-04-05 21:16:58 | [diff] [blame] | 475 | void PluginService::PurgePluginListCache(bool reload_pages) { |
| 476 | for (RenderProcessHost::iterator it = RenderProcessHost::AllHostsIterator(); |
| 477 | !it.IsAtEnd(); it.Advance()) { |
| 478 | it.GetCurrentValue()->Send(new ViewMsg_PurgePluginListCache(reload_pages)); |
| 479 | } |
| 480 | } |
| 481 | |
[email protected] | 4e0616e | 2010-05-28 14:55:53 | [diff] [blame] | 482 | void PluginService::RegisterPepperPlugins() { |
[email protected] | 84396dbc | 2011-04-14 06:33:42 | [diff] [blame] | 483 | // TODO(abarth): It seems like the PepperPluginRegistry should do this work. |
[email protected] | a08ebea | 2011-02-13 17:50:20 | [diff] [blame] | 484 | PepperPluginRegistry::ComputeList(&ppapi_plugins_); |
| 485 | for (size_t i = 0; i < ppapi_plugins_.size(); ++i) { |
[email protected] | 84396dbc | 2011-04-14 06:33:42 | [diff] [blame] | 486 | webkit::npapi::PluginList::Singleton()->RegisterInternalPlugin( |
| 487 | ppapi_plugins_[i].ToWebPluginInfo()); |
[email protected] | 4e0616e | 2010-05-28 14:55:53 | [diff] [blame] | 488 | } |
| 489 | } |
[email protected] | 634d23d | 2011-01-19 10:38:19 | [diff] [blame] | 490 | |
[email protected] | eb415bf0e | 2011-04-14 02:45:42 | [diff] [blame] | 491 | // There should generally be very few plugins so a brute-force search is fine. |
| 492 | PepperPluginInfo* PluginService::GetRegisteredPpapiPluginInfo( |
| 493 | const FilePath& plugin_path) { |
| 494 | PepperPluginInfo* info = NULL; |
| 495 | for (size_t i = 0; i < ppapi_plugins_.size(); i++) { |
[email protected] | 6b14feb | 2011-08-16 11:22:56 | [diff] [blame] | 496 | if (ppapi_plugins_[i].path == plugin_path) { |
| 497 | info = &ppapi_plugins_[i]; |
| 498 | break; |
| 499 | } |
[email protected] | eb415bf0e | 2011-04-14 02:45:42 | [diff] [blame] | 500 | } |
[email protected] | 07611759 | 2011-08-17 03:16:41 | [diff] [blame] | 501 | if (info) |
| 502 | return info; |
| 503 | // We did not find the plugin in our list. But wait! the plugin can also |
| 504 | // be a latecomer, as it happens with pepper flash. This information |
| 505 | // can be obtained from the PluginList singleton and we can use it to |
| 506 | // construct it and add it to the list. This same deal needs to be done |
| 507 | // in the renderer side in PepperPluginRegistry. |
| 508 | webkit::WebPluginInfo webplugin_info; |
| 509 | if (!webkit::npapi::PluginList::Singleton()->GetPluginInfoByPath( |
| 510 | plugin_path, &webplugin_info)) |
| 511 | return NULL; |
| 512 | PepperPluginInfo new_pepper_info; |
| 513 | if (!MakePepperPluginInfo(webplugin_info, &new_pepper_info)) |
| 514 | return NULL; |
| 515 | ppapi_plugins_.push_back(new_pepper_info); |
| 516 | return &ppapi_plugins_[ppapi_plugins_.size() - 1]; |
[email protected] | eb415bf0e | 2011-04-14 02:45:42 | [diff] [blame] | 517 | } |
| 518 | |
[email protected] | e63c4d7 | 2011-05-31 22:38:29 | [diff] [blame] | 519 | #if defined(OS_POSIX) && !defined(OS_MACOSX) |
[email protected] | 634d23d | 2011-01-19 10:38:19 | [diff] [blame] | 520 | // static |
| 521 | void PluginService::RegisterFilePathWatcher( |
| 522 | FilePathWatcher *watcher, |
| 523 | const FilePath& path, |
| 524 | FilePathWatcher::Delegate* delegate) { |
[email protected] | 7b3ee8b | 2011-04-01 18:48:19 | [diff] [blame] | 525 | bool result = watcher->Watch(path, delegate); |
[email protected] | 634d23d | 2011-01-19 10:38:19 | [diff] [blame] | 526 | DCHECK(result); |
| 527 | } |
| 528 | #endif |