[email protected] | cec1b8d | 2010-03-24 00:21:34 | [diff] [blame] | 1 | // Copyright (c) 2010 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 | |
| 5 | #include "chrome/browser/plugin_service.h" |
| 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] | 9c49ff0 | 2010-01-27 01:20:55 | [diff] [blame] | 10 | #include "base/path_service.h" |
[email protected] | d70539de | 2009-06-24 22:17:06 | [diff] [blame] | 11 | #include "base/string_util.h" |
[email protected] | 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] | 44f9c95 | 2011-01-02 06:05:39 | [diff] [blame] | 15 | #include "base/synchronization/waitable_event.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 16 | #include "chrome/browser/browser_process.h" |
[email protected] | 017a7a11 | 2010-10-12 16:38:27 | [diff] [blame] | 17 | #include "chrome/browser/browser_thread.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 18 | #include "chrome/browser/chrome_plugin_host.h" |
[email protected] | eaa7dd18 | 2010-12-14 11:09:00 | [diff] [blame] | 19 | #include "chrome/browser/extensions/extension_service.h" |
[email protected] | 0a8b1e2 | 2010-07-02 09:31:11 | [diff] [blame] | 20 | #include "chrome/browser/plugin_updater.h" |
[email protected] | 8ecad5e | 2010-12-02 21:18:33 | [diff] [blame] | 21 | #include "chrome/browser/profiles/profile.h" |
[email protected] | 8c8657d6 | 2009-01-16 18:31:26 | [diff] [blame] | 22 | #include "chrome/browser/renderer_host/render_process_host.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 23 | #include "chrome/common/chrome_plugin_lib.h" |
[email protected] | 9c49ff0 | 2010-01-27 01:20:55 | [diff] [blame] | 24 | #include "chrome/common/chrome_paths.h" |
[email protected] | d48f1e0c | 2009-02-12 20:57:54 | [diff] [blame] | 25 | #include "chrome/common/chrome_switches.h" |
[email protected] | 2290cb86 | 2010-06-02 16:50:58 | [diff] [blame] | 26 | #include "chrome/common/default_plugin.h" |
[email protected] | 5b1a0e2 | 2009-05-26 19:00:58 | [diff] [blame] | 27 | #include "chrome/common/extensions/extension.h" |
[email protected] | 7477ea6f | 2009-12-22 23:28:15 | [diff] [blame] | 28 | #include "chrome/common/gpu_plugin.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 29 | #include "chrome/common/logging_chrome.h" |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 30 | #include "chrome/common/notification_type.h" |
| 31 | #include "chrome/common/notification_service.h" |
[email protected] | 4e0616e | 2010-05-28 14:55:53 | [diff] [blame] | 32 | #include "chrome/common/pepper_plugin_registry.h" |
[email protected] | 4e59e81 | 2010-04-06 20:51:16 | [diff] [blame] | 33 | #include "chrome/common/plugin_messages.h" |
[email protected] | b547fd4 | 2009-04-23 23:16:27 | [diff] [blame] | 34 | #include "chrome/common/render_messages.h" |
[email protected] | 191eb3f7 | 2010-12-21 06:27:50 | [diff] [blame] | 35 | #include "webkit/plugins/npapi/plugin_constants_win.h" |
| 36 | #include "webkit/plugins/npapi/plugin_list.h" |
| 37 | #include "webkit/plugins/npapi/webplugininfo.h" |
| 38 | |
[email protected] | d8c7cbcc | 2009-10-02 19:00:31 | [diff] [blame] | 39 | #ifndef DISABLE_NACL |
[email protected] | d032f49 | 2009-09-29 00:33:46 | [diff] [blame] | 40 | #include "native_client/src/trusted/plugin/nacl_entry_points.h" |
[email protected] | d8c7cbcc | 2009-10-02 19:00:31 | [diff] [blame] | 41 | #endif |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 42 | |
| 43 | #if defined(OS_CHROMEOS) |
| 44 | #include "chrome/browser/chromeos/plugin_selection_policy.h" |
| 45 | #endif |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 46 | |
[email protected] | a96ec6a | 2009-11-04 17:27:08 | [diff] [blame] | 47 | #if defined(OS_MACOSX) |
| 48 | static void NotifyPluginsOfActivation() { |
[email protected] | f8b3ef8 | 2010-10-11 02:45:52 | [diff] [blame] | 49 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
[email protected] | a96ec6a | 2009-11-04 17:27:08 | [diff] [blame] | 50 | |
[email protected] | d27893f6 | 2010-07-03 05:47:42 | [diff] [blame] | 51 | for (BrowserChildProcessHost::Iterator iter(ChildProcessInfo::PLUGIN_PROCESS); |
[email protected] | a96ec6a | 2009-11-04 17:27:08 | [diff] [blame] | 52 | !iter.Done(); ++iter) { |
| 53 | PluginProcessHost* plugin = static_cast<PluginProcessHost*>(*iter); |
| 54 | plugin->OnAppActivation(); |
| 55 | } |
| 56 | } |
| 57 | #endif |
| 58 | |
[email protected] | 634d23d | 2011-01-19 10:38:19 | [diff] [blame^] | 59 | static void PurgePluginListCache(bool reload_pages) { |
| 60 | for (RenderProcessHost::iterator it = RenderProcessHost::AllHostsIterator(); |
| 61 | !it.IsAtEnd(); it.Advance()) { |
| 62 | it.GetCurrentValue()->Send(new ViewMsg_PurgePluginListCache(reload_pages)); |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | #if defined(OS_LINUX) |
| 67 | // Delegate class for monitoring directories. |
| 68 | class PluginDirWatcherDelegate : public FilePathWatcher::Delegate { |
| 69 | virtual void OnFilePathChanged(const FilePath& path) { |
| 70 | VLOG(1) << "Watched path changed: " << path.value(); |
| 71 | // Make the plugin list update itself |
| 72 | webkit::npapi::PluginList::Singleton()->RefreshPlugins(); |
| 73 | } |
| 74 | virtual void OnError() { |
| 75 | // TODO(pastarmovj): Add some sensible error handling. Maybe silently |
| 76 | // stopping the watcher would be enough. Or possibly restart it. |
| 77 | NOTREACHED(); |
| 78 | } |
| 79 | }; |
| 80 | #endif |
| 81 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 82 | // static |
[email protected] | 51549da | 2009-11-21 08:43:39 | [diff] [blame] | 83 | bool PluginService::enable_chrome_plugins_ = true; |
| 84 | |
| 85 | // static |
[email protected] | cec1b8d | 2010-03-24 00:21:34 | [diff] [blame] | 86 | void PluginService::InitGlobalInstance(Profile* profile) { |
[email protected] | f8b3ef8 | 2010-10-11 02:45:52 | [diff] [blame] | 87 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
[email protected] | cec1b8d | 2010-03-24 00:21:34 | [diff] [blame] | 88 | |
[email protected] | 0a8b1e2 | 2010-07-02 09:31:11 | [diff] [blame] | 89 | // We first group the plugins and then figure out which groups to disable. |
[email protected] | 8e8bb6d | 2010-12-13 08:18:55 | [diff] [blame] | 90 | PluginUpdater::GetInstance()->DisablePluginGroupsFromPrefs(profile); |
[email protected] | 7bf795d9 | 2010-05-22 00:14:28 | [diff] [blame] | 91 | |
[email protected] | cec1b8d | 2010-03-24 00:21:34 | [diff] [blame] | 92 | // Have Chrome plugins write their data to the profile directory. |
| 93 | GetInstance()->SetChromePluginDataDir(profile->GetPath()); |
| 94 | } |
| 95 | |
| 96 | // static |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 97 | PluginService* PluginService::GetInstance() { |
| 98 | return Singleton<PluginService>::get(); |
| 99 | } |
| 100 | |
[email protected] | 51549da | 2009-11-21 08:43:39 | [diff] [blame] | 101 | // static |
| 102 | void PluginService::EnableChromePlugins(bool enable) { |
| 103 | enable_chrome_plugins_ = enable; |
| 104 | } |
| 105 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 106 | PluginService::PluginService() |
| 107 | : main_message_loop_(MessageLoop::current()), |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 108 | resource_dispatcher_host_(NULL), |
[email protected] | f77d8762 | 2010-07-30 17:43:17 | [diff] [blame] | 109 | ui_locale_(g_browser_process->GetApplicationLocale()) { |
[email protected] | 4e0616e | 2010-05-28 14:55:53 | [diff] [blame] | 110 | RegisterPepperPlugins(); |
| 111 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 112 | // Have the NPAPI plugin list search for Chrome plugins as well. |
| 113 | ChromePluginLib::RegisterPluginsWithNPAPI(); |
[email protected] | 9a1c426 | 2010-06-29 21:50:27 | [diff] [blame] | 114 | |
| 115 | // Load any specified on the command line as well. |
[email protected] | d48f1e0c | 2009-02-12 20:57:54 | [diff] [blame] | 116 | const CommandLine* command_line = CommandLine::ForCurrentProcess(); |
[email protected] | c4e52f0d | 2009-11-06 19:55:16 | [diff] [blame] | 117 | FilePath path = command_line->GetSwitchValuePath(switches::kLoadPlugin); |
[email protected] | 7bf795d9 | 2010-05-22 00:14:28 | [diff] [blame] | 118 | if (!path.empty()) |
[email protected] | 191eb3f7 | 2010-12-21 06:27:50 | [diff] [blame] | 119 | webkit::npapi::PluginList::Singleton()->AddExtraPluginPath(path); |
[email protected] | 9a1c426 | 2010-06-29 21:50:27 | [diff] [blame] | 120 | path = command_line->GetSwitchValuePath(switches::kExtraPluginDir); |
| 121 | if (!path.empty()) |
[email protected] | 191eb3f7 | 2010-12-21 06:27:50 | [diff] [blame] | 122 | webkit::npapi::PluginList::Singleton()->AddExtraPluginDir(path); |
[email protected] | 7bf795d9 | 2010-05-22 00:14:28 | [diff] [blame] | 123 | |
[email protected] | 2290cb86 | 2010-06-02 16:50:58 | [diff] [blame] | 124 | chrome::RegisterInternalDefaultPlugin(); |
| 125 | |
[email protected] | 7bf795d9 | 2010-05-22 00:14:28 | [diff] [blame] | 126 | // Register the internal Flash and PDF, if available. |
| 127 | if (!CommandLine::ForCurrentProcess()->HasSwitch( |
| 128 | switches::kDisableInternalFlash) && |
| 129 | PathService::Get(chrome::FILE_FLASH_PLUGIN, &path)) { |
[email protected] | 191eb3f7 | 2010-12-21 06:27:50 | [diff] [blame] | 130 | webkit::npapi::PluginList::Singleton()->AddExtraPluginPath(path); |
[email protected] | 35fa6a2 | 2009-08-15 00:04:01 | [diff] [blame] | 131 | } |
[email protected] | d7ce427 | 2010-03-27 01:06:01 | [diff] [blame] | 132 | |
[email protected] | d8c7cbcc | 2009-10-02 19:00:31 | [diff] [blame] | 133 | #ifndef DISABLE_NACL |
[email protected] | 5cad70a8 | 2010-09-03 22:14:11 | [diff] [blame] | 134 | if (command_line->HasSwitch(switches::kInternalNaCl)) { |
| 135 | RegisterInternalNaClPlugin(); |
| 136 | } |
[email protected] | d8c7cbcc | 2009-10-02 19:00:31 | [diff] [blame] | 137 | #endif |
[email protected] | b547fd4 | 2009-04-23 23:16:27 | [diff] [blame] | 138 | |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 139 | #if defined(OS_CHROMEOS) |
| 140 | plugin_selection_policy_ = new chromeos::PluginSelectionPolicy; |
| 141 | plugin_selection_policy_->StartInit(); |
| 142 | #endif |
| 143 | |
[email protected] | 7477ea6f | 2009-12-22 23:28:15 | [diff] [blame] | 144 | chrome::RegisterInternalGPUPlugin(); |
| 145 | |
[email protected] | 634d23d | 2011-01-19 10:38:19 | [diff] [blame^] | 146 | // Start watching for changes in the plugin list. This means watching |
| 147 | // for changes in the Windows registry keys and on both Windows and POSIX |
| 148 | // watch for changes in the paths that are expected to contain plugins. |
[email protected] | b547fd4 | 2009-04-23 23:16:27 | [diff] [blame] | 149 | #if defined(OS_WIN) |
| 150 | hkcu_key_.Create( |
[email protected] | 191eb3f7 | 2010-12-21 06:27:50 | [diff] [blame] | 151 | HKEY_CURRENT_USER, webkit::npapi::kRegistryMozillaPlugins, KEY_NOTIFY); |
[email protected] | b547fd4 | 2009-04-23 23:16:27 | [diff] [blame] | 152 | hklm_key_.Create( |
[email protected] | 191eb3f7 | 2010-12-21 06:27:50 | [diff] [blame] | 153 | HKEY_LOCAL_MACHINE, webkit::npapi::kRegistryMozillaPlugins, KEY_NOTIFY); |
[email protected] | e06f4d5 | 2011-01-19 07:28:46 | [diff] [blame] | 154 | if (hkcu_key_.StartWatching() == ERROR_SUCCESS) { |
[email protected] | b547fd4 | 2009-04-23 23:16:27 | [diff] [blame] | 155 | hkcu_event_.reset(new base::WaitableEvent(hkcu_key_.watch_event())); |
| 156 | hkcu_watcher_.StartWatching(hkcu_event_.get(), this); |
| 157 | } |
| 158 | |
[email protected] | e06f4d5 | 2011-01-19 07:28:46 | [diff] [blame] | 159 | if (hklm_key_.StartWatching() == ERROR_SUCCESS) { |
[email protected] | b547fd4 | 2009-04-23 23:16:27 | [diff] [blame] | 160 | hklm_event_.reset(new base::WaitableEvent(hklm_key_.watch_event())); |
| 161 | hklm_watcher_.StartWatching(hklm_event_.get(), this); |
| 162 | } |
[email protected] | 9c49ff0 | 2010-01-27 01:20:55 | [diff] [blame] | 163 | #elif defined(OS_POSIX) && !defined(OS_MACOSX) |
| 164 | // Also find plugins in a user-specific plugins dir, |
| 165 | // e.g. ~/.config/chromium/Plugins. |
| 166 | FilePath user_data_dir; |
| 167 | if (PathService::Get(chrome::DIR_USER_DATA, &user_data_dir)) { |
[email protected] | 191eb3f7 | 2010-12-21 06:27:50 | [diff] [blame] | 168 | webkit::npapi::PluginList::Singleton()->AddExtraPluginDir( |
[email protected] | 9c49ff0 | 2010-01-27 01:20:55 | [diff] [blame] | 169 | user_data_dir.Append("Plugins")); |
| 170 | } |
[email protected] | b547fd4 | 2009-04-23 23:16:27 | [diff] [blame] | 171 | #endif |
[email protected] | 634d23d | 2011-01-19 10:38:19 | [diff] [blame^] | 172 | // The FilePathWatcher produces too many false positives on MacOS (access time |
| 173 | // updates?) which will lead to enforcing updates of the plugins way too often. |
| 174 | // On ChromeOS the user can't install plugins anyway and on Windows all |
| 175 | // important plugins register themselves in the registry so no need to do that. |
| 176 | #if defined(OS_LINUX) |
| 177 | file_watcher_delegate_ = new PluginDirWatcherDelegate(); |
| 178 | // Get the list of all paths for registering the FilePathWatchers |
| 179 | // that will track and if needed reload the list of plugins on runtime. |
| 180 | std::vector<FilePath> plugin_dirs; |
| 181 | webkit::npapi::PluginList::Singleton()->GetPluginDirectories( |
| 182 | &plugin_dirs); |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 183 | |
[email protected] | 634d23d | 2011-01-19 10:38:19 | [diff] [blame^] | 184 | for (size_t i = 0; i < plugin_dirs.size(); ++i) { |
| 185 | FilePathWatcher* watcher = new FilePathWatcher(); |
| 186 | // FilePathWatcher can not handle non-absolute paths under windows. |
| 187 | // We don't watch for file changes in windows now but if this should ever |
| 188 | // be extended to Windows these lines might save some time of debugging. |
| 189 | #if defined(OS_WIN) |
| 190 | if (!plugin_dirs[i].IsAbsolute()) |
| 191 | continue; |
| 192 | #endif |
| 193 | VLOG(1) << "Watching for changes in: " << plugin_dirs[i].value(); |
| 194 | BrowserThread::PostTask( |
| 195 | BrowserThread::FILE, FROM_HERE, |
| 196 | NewRunnableFunction( |
| 197 | &PluginService::RegisterFilePathWatcher, |
| 198 | watcher, plugin_dirs[i], file_watcher_delegate_)); |
| 199 | file_watchers_.push_back(watcher); |
| 200 | } |
| 201 | #endif |
[email protected] | ae09ca6 | 2009-08-21 19:46:46 | [diff] [blame] | 202 | registrar_.Add(this, NotificationType::EXTENSION_LOADED, |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 203 | NotificationService::AllSources()); |
| 204 | registrar_.Add(this, NotificationType::EXTENSION_UNLOADED, |
| 205 | NotificationService::AllSources()); |
[email protected] | a96ec6a | 2009-11-04 17:27:08 | [diff] [blame] | 206 | #if defined(OS_MACOSX) |
| 207 | // We need to know when the browser comes forward so we can bring modal plugin |
| 208 | // windows forward too. |
| 209 | registrar_.Add(this, NotificationType::APP_ACTIVATED, |
| 210 | NotificationService::AllSources()); |
| 211 | #endif |
[email protected] | 5f101bbe | 2010-10-08 08:01:16 | [diff] [blame] | 212 | registrar_.Add(this, NotificationType::PLUGIN_ENABLE_STATUS_CHANGED, |
| 213 | NotificationService::AllSources()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 214 | } |
| 215 | |
| 216 | PluginService::~PluginService() { |
[email protected] | b547fd4 | 2009-04-23 23:16:27 | [diff] [blame] | 217 | #if defined(OS_WIN) |
| 218 | // Release the events since they're owned by RegKey, not WaitableEvent. |
| 219 | hkcu_watcher_.StopWatching(); |
| 220 | hklm_watcher_.StopWatching(); |
| 221 | hkcu_event_->Release(); |
| 222 | hklm_event_->Release(); |
| 223 | #endif |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 224 | } |
| 225 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 226 | void PluginService::LoadChromePlugins( |
| 227 | ResourceDispatcherHost* resource_dispatcher_host) { |
[email protected] | 51549da | 2009-11-21 08:43:39 | [diff] [blame] | 228 | if (!enable_chrome_plugins_) |
| 229 | return; |
| 230 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 231 | resource_dispatcher_host_ = resource_dispatcher_host; |
| 232 | ChromePluginLib::LoadChromePlugins(GetCPBrowserFuncsForBrowser()); |
| 233 | } |
| 234 | |
[email protected] | f7011fcb | 2009-01-28 21:54:32 | [diff] [blame] | 235 | void PluginService::SetChromePluginDataDir(const FilePath& data_dir) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 236 | chrome_plugin_data_dir_ = data_dir; |
| 237 | } |
| 238 | |
[email protected] | f7011fcb | 2009-01-28 21:54:32 | [diff] [blame] | 239 | const FilePath& PluginService::GetChromePluginDataDir() { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 240 | return chrome_plugin_data_dir_; |
| 241 | } |
| 242 | |
[email protected] | f77d8762 | 2010-07-30 17:43:17 | [diff] [blame] | 243 | const std::string& PluginService::GetUILocale() { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 244 | return ui_locale_; |
| 245 | } |
| 246 | |
[email protected] | 28ab7f9 | 2009-01-06 21:39:04 | [diff] [blame] | 247 | PluginProcessHost* PluginService::FindPluginProcess( |
| 248 | const FilePath& plugin_path) { |
[email protected] | f8b3ef8 | 2010-10-11 02:45:52 | [diff] [blame] | 249 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 250 | |
[email protected] | d27893f6 | 2010-07-03 05:47:42 | [diff] [blame] | 251 | for (BrowserChildProcessHost::Iterator iter(ChildProcessInfo::PLUGIN_PROCESS); |
[email protected] | a436d92 | 2009-02-13 23:16:42 | [diff] [blame] | 252 | !iter.Done(); ++iter) { |
| 253 | PluginProcessHost* plugin = static_cast<PluginProcessHost*>(*iter); |
| 254 | if (plugin->info().path == plugin_path) |
| 255 | return plugin; |
| 256 | } |
| 257 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 258 | return NULL; |
| 259 | } |
| 260 | |
| 261 | PluginProcessHost* PluginService::FindOrStartPluginProcess( |
[email protected] | 610c089 | 2009-09-08 19:46:18 | [diff] [blame] | 262 | const FilePath& plugin_path) { |
[email protected] | f8b3ef8 | 2010-10-11 02:45:52 | [diff] [blame] | 263 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 264 | |
[email protected] | 8b8a554d | 2010-11-18 13:26:40 | [diff] [blame] | 265 | PluginProcessHost* plugin_host = FindPluginProcess(plugin_path); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 266 | if (plugin_host) |
| 267 | return plugin_host; |
| 268 | |
[email protected] | 191eb3f7 | 2010-12-21 06:27:50 | [diff] [blame] | 269 | webkit::npapi::WebPluginInfo info; |
| 270 | if (!webkit::npapi::PluginList::Singleton()->GetPluginInfoByPath( |
| 271 | plugin_path, &info)) { |
[email protected] | a27a938 | 2009-02-11 23:55:10 | [diff] [blame] | 272 | return NULL; |
| 273 | } |
| 274 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 275 | // 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] | 276 | scoped_ptr<PluginProcessHost> new_host(new PluginProcessHost()); |
| 277 | if (!new_host->Init(info, ui_locale_)) { |
| 278 | NOTREACHED(); // Init is not expected to fail |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 279 | return NULL; |
| 280 | } |
[email protected] | a436d92 | 2009-02-13 23:16:42 | [diff] [blame] | 281 | |
[email protected] | 8b8a554d | 2010-11-18 13:26:40 | [diff] [blame] | 282 | return new_host.release(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 283 | } |
| 284 | |
| 285 | void PluginService::OpenChannelToPlugin( |
[email protected] | 610c089 | 2009-09-08 19:46:18 | [diff] [blame] | 286 | const GURL& url, |
| 287 | const std::string& mime_type, |
[email protected] | 46b69e4 | 2010-11-02 12:26:39 | [diff] [blame] | 288 | PluginProcessHost::Client* client) { |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 289 | // The PluginList::GetFirstAllowedPluginInfo may need to load the |
| 290 | // plugins. Don't do it on the IO thread. |
| 291 | BrowserThread::PostTask( |
| 292 | BrowserThread::FILE, FROM_HERE, |
| 293 | NewRunnableMethod( |
| 294 | this, &PluginService::GetAllowedPluginForOpenChannelToPlugin, |
[email protected] | 46b69e4 | 2010-11-02 12:26:39 | [diff] [blame] | 295 | url, mime_type, client)); |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 296 | } |
| 297 | |
| 298 | void PluginService::GetAllowedPluginForOpenChannelToPlugin( |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 299 | const GURL& url, |
| 300 | const std::string& mime_type, |
[email protected] | 46b69e4 | 2010-11-02 12:26:39 | [diff] [blame] | 301 | PluginProcessHost::Client* client) { |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 302 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
[email protected] | 191eb3f7 | 2010-12-21 06:27:50 | [diff] [blame] | 303 | webkit::npapi::WebPluginInfo info; |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 304 | bool found = GetFirstAllowedPluginInfo(url, mime_type, &info, NULL); |
| 305 | FilePath plugin_path; |
| 306 | if (found && info.enabled) |
| 307 | plugin_path = FilePath(info.path); |
| 308 | |
| 309 | // Now we jump back to the IO thread to finish opening the channel. |
| 310 | BrowserThread::PostTask( |
| 311 | BrowserThread::IO, FROM_HERE, |
| 312 | NewRunnableMethod( |
| 313 | this, &PluginService::FinishOpenChannelToPlugin, |
[email protected] | 46b69e4 | 2010-11-02 12:26:39 | [diff] [blame] | 314 | plugin_path, client)); |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 315 | } |
| 316 | |
| 317 | void PluginService::FinishOpenChannelToPlugin( |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 318 | const FilePath& plugin_path, |
[email protected] | 46b69e4 | 2010-11-02 12:26:39 | [diff] [blame] | 319 | PluginProcessHost::Client* client) { |
[email protected] | f8b3ef8 | 2010-10-11 02:45:52 | [diff] [blame] | 320 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
[email protected] | 20a793e | 2010-10-12 06:50:08 | [diff] [blame] | 321 | |
[email protected] | 610c089 | 2009-09-08 19:46:18 | [diff] [blame] | 322 | PluginProcessHost* plugin_host = FindOrStartPluginProcess(plugin_path); |
[email protected] | 46b69e4 | 2010-11-02 12:26:39 | [diff] [blame] | 323 | if (plugin_host) |
| 324 | plugin_host->OpenChannelToPlugin(client); |
| 325 | else |
| 326 | client->OnError(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 327 | } |
| 328 | |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 329 | bool PluginService::GetFirstAllowedPluginInfo( |
| 330 | const GURL& url, |
| 331 | const std::string& mime_type, |
[email protected] | 191eb3f7 | 2010-12-21 06:27:50 | [diff] [blame] | 332 | webkit::npapi::WebPluginInfo* info, |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 333 | std::string* actual_mime_type) { |
| 334 | // GetPluginInfoArray may need to load the plugins, so we need to be |
| 335 | // on the FILE thread. |
| 336 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 337 | bool allow_wildcard = true; |
| 338 | #if defined(OS_CHROMEOS) |
[email protected] | 191eb3f7 | 2010-12-21 06:27:50 | [diff] [blame] | 339 | std::vector<webkit::npapi::WebPluginInfo> info_array; |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 340 | std::vector<std::string> actual_mime_types; |
[email protected] | 191eb3f7 | 2010-12-21 06:27:50 | [diff] [blame] | 341 | webkit::npapi::PluginList::Singleton()->GetPluginInfoArray( |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 342 | url, mime_type, allow_wildcard, &info_array, &actual_mime_types); |
| 343 | |
| 344 | // Now we filter by the plugin selection policy. |
| 345 | int allowed_index = plugin_selection_policy_->FindFirstAllowed(url, |
| 346 | info_array); |
| 347 | if (!info_array.empty() && allowed_index >= 0) { |
| 348 | *info = info_array[allowed_index]; |
| 349 | if (actual_mime_type) |
| 350 | *actual_mime_type = actual_mime_types[allowed_index]; |
| 351 | return true; |
| 352 | } |
| 353 | return false; |
| 354 | #else |
[email protected] | 191eb3f7 | 2010-12-21 06:27:50 | [diff] [blame] | 355 | return webkit::npapi::PluginList::Singleton()->GetPluginInfo( |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 356 | url, mime_type, allow_wildcard, info, actual_mime_type); |
| 357 | #endif |
| 358 | } |
| 359 | |
[email protected] | 58052263 | 2009-08-17 21:55:55 | [diff] [blame] | 360 | void PluginService::OnWaitableEventSignaled( |
| 361 | base::WaitableEvent* waitable_event) { |
[email protected] | b547fd4 | 2009-04-23 23:16:27 | [diff] [blame] | 362 | #if defined(OS_WIN) |
| 363 | if (waitable_event == hkcu_event_.get()) { |
| 364 | hkcu_key_.StartWatching(); |
| 365 | } else { |
| 366 | hklm_key_.StartWatching(); |
| 367 | } |
| 368 | |
[email protected] | 191eb3f7 | 2010-12-21 06:27:50 | [diff] [blame] | 369 | webkit::npapi::PluginList::Singleton()->RefreshPlugins(); |
[email protected] | b78e168b | 2009-09-21 22:05:45 | [diff] [blame] | 370 | PurgePluginListCache(true); |
[email protected] | 634d23d | 2011-01-19 10:38:19 | [diff] [blame^] | 371 | #else |
| 372 | // This event should only get signaled on a Windows machine. |
| 373 | NOTREACHED(); |
[email protected] | 9de09f8 | 2009-08-17 20:13:53 | [diff] [blame] | 374 | #endif // defined(OS_WIN) |
[email protected] | b547fd4 | 2009-04-23 23:16:27 | [diff] [blame] | 375 | } |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 376 | |
[email protected] | 4e59e81 | 2010-04-06 20:51:16 | [diff] [blame] | 377 | static void ForceShutdownPlugin(const FilePath& plugin_path) { |
| 378 | PluginProcessHost* plugin = |
| 379 | PluginService::GetInstance()->FindPluginProcess(plugin_path); |
| 380 | if (plugin) |
| 381 | plugin->ForceShutdown(); |
| 382 | } |
| 383 | |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 384 | void PluginService::Observe(NotificationType type, |
| 385 | const NotificationSource& source, |
| 386 | const NotificationDetails& details) { |
| 387 | switch (type.value) { |
[email protected] | ae09ca6 | 2009-08-21 19:46:46 | [diff] [blame] | 388 | case NotificationType::EXTENSION_LOADED: { |
[email protected] | 9adb969 | 2010-10-29 23:14:02 | [diff] [blame] | 389 | const Extension* extension = Details<const Extension>(details).ptr(); |
[email protected] | b78e168b | 2009-09-21 22:05:45 | [diff] [blame] | 390 | bool plugins_changed = false; |
[email protected] | ee5e379 | 2009-10-13 23:23:47 | [diff] [blame] | 391 | for (size_t i = 0; i < extension->plugins().size(); ++i) { |
[email protected] | ae09ca6 | 2009-08-21 19:46:46 | [diff] [blame] | 392 | const Extension::PluginInfo& plugin = extension->plugins()[i]; |
[email protected] | 191eb3f7 | 2010-12-21 06:27:50 | [diff] [blame] | 393 | webkit::npapi::PluginList::Singleton()->RefreshPlugins(); |
| 394 | webkit::npapi::PluginList::Singleton()->AddExtraPluginPath(plugin.path); |
[email protected] | b78e168b | 2009-09-21 22:05:45 | [diff] [blame] | 395 | plugins_changed = true; |
[email protected] | ae09ca6 | 2009-08-21 19:46:46 | [diff] [blame] | 396 | if (!plugin.is_public) |
| 397 | private_plugins_[plugin.path] = extension->url(); |
[email protected] | c533bb2 | 2009-06-03 19:06:11 | [diff] [blame] | 398 | } |
[email protected] | b78e168b | 2009-09-21 22:05:45 | [diff] [blame] | 399 | if (plugins_changed) |
| 400 | PurgePluginListCache(false); |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 401 | break; |
| 402 | } |
| 403 | |
| 404 | case NotificationType::EXTENSION_UNLOADED: { |
[email protected] | a9f39a31 | 2010-12-23 22:14:27 | [diff] [blame] | 405 | const Extension* extension = |
| 406 | Details<UnloadedExtensionInfo>(details)->extension; |
[email protected] | b78e168b | 2009-09-21 22:05:45 | [diff] [blame] | 407 | bool plugins_changed = false; |
[email protected] | ee5e379 | 2009-10-13 23:23:47 | [diff] [blame] | 408 | for (size_t i = 0; i < extension->plugins().size(); ++i) { |
[email protected] | b78e168b | 2009-09-21 22:05:45 | [diff] [blame] | 409 | const Extension::PluginInfo& plugin = extension->plugins()[i]; |
[email protected] | f8b3ef8 | 2010-10-11 02:45:52 | [diff] [blame] | 410 | BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
| 411 | NewRunnableFunction(&ForceShutdownPlugin, |
| 412 | plugin.path)); |
[email protected] | 191eb3f7 | 2010-12-21 06:27:50 | [diff] [blame] | 413 | webkit::npapi::PluginList::Singleton()->RefreshPlugins(); |
| 414 | webkit::npapi::PluginList::Singleton()->RemoveExtraPluginPath( |
| 415 | plugin.path); |
[email protected] | b78e168b | 2009-09-21 22:05:45 | [diff] [blame] | 416 | plugins_changed = true; |
| 417 | if (!plugin.is_public) |
| 418 | private_plugins_.erase(plugin.path); |
| 419 | } |
| 420 | if (plugins_changed) |
| 421 | PurgePluginListCache(false); |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 422 | break; |
| 423 | } |
| 424 | |
[email protected] | a96ec6a | 2009-11-04 17:27:08 | [diff] [blame] | 425 | #if defined(OS_MACOSX) |
| 426 | case NotificationType::APP_ACTIVATED: { |
[email protected] | f8b3ef8 | 2010-10-11 02:45:52 | [diff] [blame] | 427 | BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
| 428 | NewRunnableFunction(&NotifyPluginsOfActivation)); |
[email protected] | a96ec6a | 2009-11-04 17:27:08 | [diff] [blame] | 429 | break; |
| 430 | } |
| 431 | #endif |
| 432 | |
[email protected] | 5f101bbe | 2010-10-08 08:01:16 | [diff] [blame] | 433 | case NotificationType::PLUGIN_ENABLE_STATUS_CHANGED: { |
| 434 | PurgePluginListCache(false); |
| 435 | break; |
| 436 | } |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 437 | default: |
[email protected] | 634d23d | 2011-01-19 10:38:19 | [diff] [blame^] | 438 | NOTREACHED(); |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 439 | } |
| 440 | } |
[email protected] | 9dd9e838 | 2009-06-05 18:23:21 | [diff] [blame] | 441 | |
[email protected] | 7a13e79 | 2010-08-03 08:18:24 | [diff] [blame] | 442 | bool PluginService::PrivatePluginAllowedForURL(const FilePath& plugin_path, |
| 443 | const GURL& url) { |
[email protected] | 9dd9e838 | 2009-06-05 18:23:21 | [diff] [blame] | 444 | if (url.is_empty()) |
| 445 | return true; // Caller wants all plugins. |
| 446 | |
| 447 | PrivatePluginMap::iterator it = private_plugins_.find(plugin_path); |
| 448 | if (it == private_plugins_.end()) |
| 449 | return true; // This plugin is not private, so it's allowed everywhere. |
| 450 | |
| 451 | // We do a dumb compare of scheme and host, rather than using the domain |
| 452 | // service, since we only care about this for extensions. |
| 453 | const GURL& required_url = it->second; |
| 454 | return (url.scheme() == required_url.scheme() && |
| 455 | url.host() == required_url.host()); |
| 456 | } |
[email protected] | 4e0616e | 2010-05-28 14:55:53 | [diff] [blame] | 457 | |
| 458 | void PluginService::RegisterPepperPlugins() { |
| 459 | std::vector<PepperPluginInfo> plugins; |
| 460 | PepperPluginRegistry::GetList(&plugins); |
| 461 | for (size_t i = 0; i < plugins.size(); ++i) { |
[email protected] | 191eb3f7 | 2010-12-21 06:27:50 | [diff] [blame] | 462 | webkit::npapi::PluginVersionInfo info; |
[email protected] | 4e0616e | 2010-05-28 14:55:53 | [diff] [blame] | 463 | info.path = plugins[i].path; |
[email protected] | 2fb3e36 | 2010-07-02 18:05:44 | [diff] [blame] | 464 | info.product_name = plugins[i].name.empty() ? |
| 465 | plugins[i].path.BaseName().ToWStringHack() : |
| 466 | ASCIIToWide(plugins[i].name); |
| 467 | info.file_description = ASCIIToWide(plugins[i].description); |
| 468 | info.file_extensions = ASCIIToWide(plugins[i].file_extensions); |
| 469 | info.file_description = ASCIIToWide(plugins[i].type_descriptions); |
[email protected] | 4e0616e | 2010-05-28 14:55:53 | [diff] [blame] | 470 | info.mime_types = ASCIIToWide(JoinString(plugins[i].mime_types, '|')); |
| 471 | |
| 472 | // These NPAPI entry points will never be called. TODO(darin): Come up |
| 473 | // with a cleaner way to register pepper plugins with the NPAPI PluginList, |
| 474 | // or perhaps refactor the PluginList to be less specific to NPAPI. |
| 475 | memset(&info.entry_points, 0, sizeof(info.entry_points)); |
| 476 | |
[email protected] | 191eb3f7 | 2010-12-21 06:27:50 | [diff] [blame] | 477 | webkit::npapi::PluginList::Singleton()->RegisterInternalPlugin(info); |
[email protected] | 4e0616e | 2010-05-28 14:55:53 | [diff] [blame] | 478 | } |
| 479 | } |
[email protected] | 634d23d | 2011-01-19 10:38:19 | [diff] [blame^] | 480 | |
| 481 | #if defined(OS_LINUX) |
| 482 | // static |
| 483 | void PluginService::RegisterFilePathWatcher( |
| 484 | FilePathWatcher *watcher, |
| 485 | const FilePath& path, |
| 486 | FilePathWatcher::Delegate* delegate) { |
| 487 | bool result = watcher->Watch(path, delegate); |
| 488 | DCHECK(result); |
| 489 | } |
| 490 | #endif |