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