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