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