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