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