[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] | cec1b8d | 2010-03-24 00:21:34 | [diff] [blame] | 13 | #include "base/values.h" |
[email protected] | b547fd4 | 2009-04-23 23:16:27 | [diff] [blame] | 14 | #include "base/waitable_event.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 15 | #include "chrome/browser/browser_process.h" |
| 16 | #include "chrome/browser/chrome_plugin_host.h" |
| 17 | #include "chrome/browser/chrome_thread.h" |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 18 | #include "chrome/browser/extensions/extensions_service.h" |
[email protected] | 6eaddcc | 2009-02-23 21:03:04 | [diff] [blame] | 19 | #include "chrome/browser/plugin_process_host.h" |
[email protected] | cec1b8d | 2010-03-24 00:21:34 | [diff] [blame] | 20 | #include "chrome/browser/pref_service.h" |
| 21 | #include "chrome/browser/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] | cec1b8d | 2010-03-24 00:21:34 | [diff] [blame] | 34 | #include "chrome/common/pref_names.h" |
[email protected] | b547fd4 | 2009-04-23 23:16:27 | [diff] [blame] | 35 | #include "chrome/common/render_messages.h" |
[email protected] | d8c7cbcc | 2009-10-02 19:00:31 | [diff] [blame] | 36 | #ifndef DISABLE_NACL |
[email protected] | d032f49 | 2009-09-29 00:33:46 | [diff] [blame] | 37 | #include "native_client/src/trusted/plugin/nacl_entry_points.h" |
[email protected] | d8c7cbcc | 2009-10-02 19:00:31 | [diff] [blame] | 38 | #endif |
[email protected] | b547fd4 | 2009-04-23 23:16:27 | [diff] [blame] | 39 | #include "webkit/glue/plugins/plugin_constants_win.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 40 | #include "webkit/glue/plugins/plugin_list.h" |
| 41 | |
[email protected] | a96ec6a | 2009-11-04 17:27:08 | [diff] [blame] | 42 | #if defined(OS_MACOSX) |
| 43 | static void NotifyPluginsOfActivation() { |
| 44 | DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); |
| 45 | |
| 46 | for (ChildProcessHost::Iterator iter(ChildProcessInfo::PLUGIN_PROCESS); |
| 47 | !iter.Done(); ++iter) { |
| 48 | PluginProcessHost* plugin = static_cast<PluginProcessHost*>(*iter); |
| 49 | plugin->OnAppActivation(); |
| 50 | } |
| 51 | } |
| 52 | #endif |
| 53 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 54 | // static |
[email protected] | 51549da | 2009-11-21 08:43:39 | [diff] [blame] | 55 | bool PluginService::enable_chrome_plugins_ = true; |
[email protected] | 7bf795d9 | 2010-05-22 00:14:28 | [diff] [blame] | 56 | bool PluginService::enable_internal_pdf_ = false; |
[email protected] | 51549da | 2009-11-21 08:43:39 | [diff] [blame] | 57 | |
| 58 | // static |
[email protected] | cec1b8d | 2010-03-24 00:21:34 | [diff] [blame] | 59 | void PluginService::InitGlobalInstance(Profile* profile) { |
| 60 | DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); |
| 61 | |
[email protected] | 388dd3a | 2010-05-05 22:47:27 | [diff] [blame] | 62 | bool update_internal_dir = false; |
| 63 | FilePath last_internal_dir = |
| 64 | profile->GetPrefs()->GetFilePath(prefs::kPluginsLastInternalDirectory); |
| 65 | FilePath cur_internal_dir; |
[email protected] | 7bf795d9 | 2010-05-22 00:14:28 | [diff] [blame] | 66 | if (PathService::Get(chrome::DIR_INTERNAL_PLUGINS, &cur_internal_dir) && |
| 67 | cur_internal_dir != last_internal_dir) { |
| 68 | update_internal_dir = true; |
| 69 | profile->GetPrefs()->SetFilePath( |
| 70 | prefs::kPluginsLastInternalDirectory, cur_internal_dir); |
| 71 | } |
| 72 | |
| 73 | bool found_internal_pdf = false; |
| 74 | bool force_enable_internal_pdf = false; |
| 75 | FilePath pdf_path; |
| 76 | PathService::Get(chrome::FILE_PDF_PLUGIN, &pdf_path); |
| 77 | FilePath::StringType pdf_path_str = pdf_path.value(); |
| 78 | if (enable_internal_pdf_ && |
| 79 | !profile->GetPrefs()->GetBoolean(prefs::kPluginsEnabledInternalPDF)) { |
| 80 | // We switched to the internal pdf plugin being on by default, and so we |
| 81 | // need to force it to be enabled. We only want to do it this once though, |
| 82 | // i.e. we don't want to enable it again if the user disables it afterwards. |
| 83 | profile->GetPrefs()->SetBoolean(prefs::kPluginsEnabledInternalPDF, true); |
| 84 | force_enable_internal_pdf = true; |
| 85 | } |
[email protected] | 388dd3a | 2010-05-05 22:47:27 | [diff] [blame] | 86 | |
[email protected] | cec1b8d | 2010-03-24 00:21:34 | [diff] [blame] | 87 | // Disable plugins listed as disabled in prefs. |
[email protected] | 7bf795d9 | 2010-05-22 00:14:28 | [diff] [blame] | 88 | if (ListValue* saved_plugins_list = |
| 89 | profile->GetPrefs()->GetMutableList(prefs::kPluginsPluginsList)) { |
[email protected] | cec1b8d | 2010-03-24 00:21:34 | [diff] [blame] | 90 | for (ListValue::const_iterator it = saved_plugins_list->begin(); |
| 91 | it != saved_plugins_list->end(); |
| 92 | ++it) { |
| 93 | if (!(*it)->IsType(Value::TYPE_DICTIONARY)) { |
| 94 | LOG(WARNING) << "Invalid entry in " << prefs::kPluginsPluginsList; |
| 95 | continue; // Oops, don't know what to do with this item. |
| 96 | } |
| 97 | |
| 98 | DictionaryValue* plugin = static_cast<DictionaryValue*>(*it); |
| 99 | FilePath::StringType path; |
[email protected] | 7bf795d9 | 2010-05-22 00:14:28 | [diff] [blame] | 100 | if (!plugin->GetString(L"path", &path)) |
| 101 | continue; |
| 102 | |
[email protected] | cec1b8d | 2010-03-24 00:21:34 | [diff] [blame] | 103 | bool enabled = true; |
| 104 | plugin->GetBoolean(L"enabled", &enabled); |
[email protected] | 388dd3a | 2010-05-05 22:47:27 | [diff] [blame] | 105 | |
[email protected] | 3193859 | 2010-05-24 22:51:02 | [diff] [blame] | 106 | if (FilePath::CompareIgnoreCase(path, pdf_path_str) == 0) { |
[email protected] | 7bf795d9 | 2010-05-22 00:14:28 | [diff] [blame] | 107 | found_internal_pdf = true; |
| 108 | if (!enabled && force_enable_internal_pdf) { |
| 109 | enabled = true; |
| 110 | plugin->SetBoolean(L"enabled", true); |
[email protected] | 388dd3a | 2010-05-05 22:47:27 | [diff] [blame] | 111 | } |
| 112 | } |
[email protected] | 7bf795d9 | 2010-05-22 00:14:28 | [diff] [blame] | 113 | |
| 114 | FilePath plugin_path(path); |
[email protected] | 3193859 | 2010-05-24 22:51:02 | [diff] [blame] | 115 | if (update_internal_dir && |
| 116 | FilePath::CompareIgnoreCase(plugin_path.DirName().value(), |
| 117 | last_internal_dir.value()) == 0) { |
[email protected] | 7bf795d9 | 2010-05-22 00:14:28 | [diff] [blame] | 118 | // If the internal plugin directory has changed and if the plugin looks |
| 119 | // internal, update its path in the prefs. |
| 120 | plugin_path = cur_internal_dir.Append(plugin_path.BaseName()); |
| 121 | plugin->SetString(L"path", plugin_path.value()); |
| 122 | } |
| 123 | |
| 124 | if (!enabled) |
| 125 | NPAPI::PluginList::Singleton()->DisablePlugin(plugin_path); |
[email protected] | cec1b8d | 2010-03-24 00:21:34 | [diff] [blame] | 126 | } |
| 127 | } |
| 128 | |
[email protected] | 7bf795d9 | 2010-05-22 00:14:28 | [diff] [blame] | 129 | if (!enable_internal_pdf_ && !found_internal_pdf) { |
| 130 | // The internal PDF plugin is disabled by default, and the user hasn't |
| 131 | // overridden the default. |
| 132 | NPAPI::PluginList::Singleton()->DisablePlugin(pdf_path); |
| 133 | } |
| 134 | |
[email protected] | cec1b8d | 2010-03-24 00:21:34 | [diff] [blame] | 135 | // Have Chrome plugins write their data to the profile directory. |
| 136 | GetInstance()->SetChromePluginDataDir(profile->GetPath()); |
| 137 | } |
| 138 | |
| 139 | // static |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 140 | PluginService* PluginService::GetInstance() { |
| 141 | return Singleton<PluginService>::get(); |
| 142 | } |
| 143 | |
[email protected] | 51549da | 2009-11-21 08:43:39 | [diff] [blame] | 144 | // static |
| 145 | void PluginService::EnableChromePlugins(bool enable) { |
| 146 | enable_chrome_plugins_ = enable; |
| 147 | } |
| 148 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 149 | PluginService::PluginService() |
| 150 | : main_message_loop_(MessageLoop::current()), |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 151 | resource_dispatcher_host_(NULL), |
[email protected] | d70539de | 2009-06-24 22:17:06 | [diff] [blame] | 152 | ui_locale_(ASCIIToWide(g_browser_process->GetApplicationLocale())) { |
[email protected] | 4e0616e | 2010-05-28 14:55:53 | [diff] [blame] | 153 | RegisterPepperPlugins(); |
| 154 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 155 | // Have the NPAPI plugin list search for Chrome plugins as well. |
| 156 | ChromePluginLib::RegisterPluginsWithNPAPI(); |
[email protected] | d48f1e0c | 2009-02-12 20:57:54 | [diff] [blame] | 157 | // Load the one specified on the command line as well. |
| 158 | const CommandLine* command_line = CommandLine::ForCurrentProcess(); |
[email protected] | c4e52f0d | 2009-11-06 19:55:16 | [diff] [blame] | 159 | FilePath path = command_line->GetSwitchValuePath(switches::kLoadPlugin); |
[email protected] | 7bf795d9 | 2010-05-22 00:14:28 | [diff] [blame] | 160 | if (!path.empty()) |
| 161 | NPAPI::PluginList::Singleton()->AddExtraPluginPath(path); |
| 162 | |
[email protected] | 2290cb86 | 2010-06-02 16:50:58 | [diff] [blame^] | 163 | chrome::RegisterInternalDefaultPlugin(); |
| 164 | |
[email protected] | 7bf795d9 | 2010-05-22 00:14:28 | [diff] [blame] | 165 | // Register the internal Flash and PDF, if available. |
| 166 | if (!CommandLine::ForCurrentProcess()->HasSwitch( |
| 167 | switches::kDisableInternalFlash) && |
| 168 | PathService::Get(chrome::FILE_FLASH_PLUGIN, &path)) { |
[email protected] | c4e52f0d | 2009-11-06 19:55:16 | [diff] [blame] | 169 | NPAPI::PluginList::Singleton()->AddExtraPluginPath(path); |
[email protected] | 35fa6a2 | 2009-08-15 00:04:01 | [diff] [blame] | 170 | } |
[email protected] | d7ce427 | 2010-03-27 01:06:01 | [diff] [blame] | 171 | |
[email protected] | 7bf795d9 | 2010-05-22 00:14:28 | [diff] [blame] | 172 | if (PathService::Get(chrome::FILE_PDF_PLUGIN, &path)) |
| 173 | NPAPI::PluginList::Singleton()->AddExtraPluginPath(path); |
[email protected] | d7ce427 | 2010-03-27 01:06:01 | [diff] [blame] | 174 | |
[email protected] | d8c7cbcc | 2009-10-02 19:00:31 | [diff] [blame] | 175 | #ifndef DISABLE_NACL |
[email protected] | d032f49 | 2009-09-29 00:33:46 | [diff] [blame] | 176 | if (command_line->HasSwitch(switches::kInternalNaCl)) |
| 177 | RegisterInternalNaClPlugin(); |
[email protected] | d8c7cbcc | 2009-10-02 19:00:31 | [diff] [blame] | 178 | #endif |
[email protected] | b547fd4 | 2009-04-23 23:16:27 | [diff] [blame] | 179 | |
[email protected] | 7477ea6f | 2009-12-22 23:28:15 | [diff] [blame] | 180 | chrome::RegisterInternalGPUPlugin(); |
| 181 | |
[email protected] | b547fd4 | 2009-04-23 23:16:27 | [diff] [blame] | 182 | #if defined(OS_WIN) |
| 183 | hkcu_key_.Create( |
| 184 | HKEY_CURRENT_USER, kRegistryMozillaPlugins, KEY_NOTIFY); |
| 185 | hklm_key_.Create( |
| 186 | HKEY_LOCAL_MACHINE, kRegistryMozillaPlugins, KEY_NOTIFY); |
| 187 | if (hkcu_key_.StartWatching()) { |
| 188 | hkcu_event_.reset(new base::WaitableEvent(hkcu_key_.watch_event())); |
| 189 | hkcu_watcher_.StartWatching(hkcu_event_.get(), this); |
| 190 | } |
| 191 | |
| 192 | if (hklm_key_.StartWatching()) { |
| 193 | hklm_event_.reset(new base::WaitableEvent(hklm_key_.watch_event())); |
| 194 | hklm_watcher_.StartWatching(hklm_event_.get(), this); |
| 195 | } |
[email protected] | 9c49ff0 | 2010-01-27 01:20:55 | [diff] [blame] | 196 | #elif defined(OS_POSIX) && !defined(OS_MACOSX) |
| 197 | // Also find plugins in a user-specific plugins dir, |
| 198 | // e.g. ~/.config/chromium/Plugins. |
| 199 | FilePath user_data_dir; |
| 200 | if (PathService::Get(chrome::DIR_USER_DATA, &user_data_dir)) { |
| 201 | NPAPI::PluginList::Singleton()->AddExtraPluginDir( |
| 202 | user_data_dir.Append("Plugins")); |
| 203 | } |
[email protected] | b547fd4 | 2009-04-23 23:16:27 | [diff] [blame] | 204 | #endif |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 205 | |
[email protected] | ae09ca6 | 2009-08-21 19:46:46 | [diff] [blame] | 206 | registrar_.Add(this, NotificationType::EXTENSION_LOADED, |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 207 | NotificationService::AllSources()); |
| 208 | registrar_.Add(this, NotificationType::EXTENSION_UNLOADED, |
| 209 | NotificationService::AllSources()); |
[email protected] | a96ec6a | 2009-11-04 17:27:08 | [diff] [blame] | 210 | #if defined(OS_MACOSX) |
| 211 | // We need to know when the browser comes forward so we can bring modal plugin |
| 212 | // windows forward too. |
| 213 | registrar_.Add(this, NotificationType::APP_ACTIVATED, |
| 214 | NotificationService::AllSources()); |
| 215 | #endif |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 216 | } |
| 217 | |
| 218 | PluginService::~PluginService() { |
[email protected] | b547fd4 | 2009-04-23 23:16:27 | [diff] [blame] | 219 | #if defined(OS_WIN) |
| 220 | // Release the events since they're owned by RegKey, not WaitableEvent. |
| 221 | hkcu_watcher_.StopWatching(); |
| 222 | hklm_watcher_.StopWatching(); |
| 223 | hkcu_event_->Release(); |
| 224 | hklm_event_->Release(); |
| 225 | #endif |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 226 | } |
| 227 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 228 | void PluginService::LoadChromePlugins( |
| 229 | ResourceDispatcherHost* resource_dispatcher_host) { |
[email protected] | 51549da | 2009-11-21 08:43:39 | [diff] [blame] | 230 | if (!enable_chrome_plugins_) |
| 231 | return; |
| 232 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 233 | resource_dispatcher_host_ = resource_dispatcher_host; |
| 234 | ChromePluginLib::LoadChromePlugins(GetCPBrowserFuncsForBrowser()); |
| 235 | } |
| 236 | |
[email protected] | f7011fcb | 2009-01-28 21:54:32 | [diff] [blame] | 237 | void PluginService::SetChromePluginDataDir(const FilePath& data_dir) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 238 | chrome_plugin_data_dir_ = data_dir; |
| 239 | } |
| 240 | |
[email protected] | f7011fcb | 2009-01-28 21:54:32 | [diff] [blame] | 241 | const FilePath& PluginService::GetChromePluginDataDir() { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 242 | return chrome_plugin_data_dir_; |
| 243 | } |
| 244 | |
| 245 | const std::wstring& PluginService::GetUILocale() { |
| 246 | return ui_locale_; |
| 247 | } |
| 248 | |
[email protected] | 28ab7f9 | 2009-01-06 21:39:04 | [diff] [blame] | 249 | PluginProcessHost* PluginService::FindPluginProcess( |
| 250 | const FilePath& plugin_path) { |
[email protected] | d85cf07 | 2009-10-27 03:59:31 | [diff] [blame] | 251 | DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 252 | |
[email protected] | 28ab7f9 | 2009-01-06 21:39:04 | [diff] [blame] | 253 | if (plugin_path.value().empty()) { |
| 254 | NOTREACHED() << "should only be called if we have a plugin to load"; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 255 | return NULL; |
| 256 | } |
| 257 | |
[email protected] | 6dffde32 | 2009-02-18 03:47:48 | [diff] [blame] | 258 | for (ChildProcessHost::Iterator iter(ChildProcessInfo::PLUGIN_PROCESS); |
[email protected] | a436d92 | 2009-02-13 23:16:42 | [diff] [blame] | 259 | !iter.Done(); ++iter) { |
| 260 | PluginProcessHost* plugin = static_cast<PluginProcessHost*>(*iter); |
| 261 | if (plugin->info().path == plugin_path) |
| 262 | return plugin; |
| 263 | } |
| 264 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 265 | return NULL; |
| 266 | } |
| 267 | |
| 268 | PluginProcessHost* PluginService::FindOrStartPluginProcess( |
[email protected] | 610c089 | 2009-09-08 19:46:18 | [diff] [blame] | 269 | const FilePath& plugin_path) { |
[email protected] | d85cf07 | 2009-10-27 03:59:31 | [diff] [blame] | 270 | DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 271 | |
[email protected] | 28ab7f9 | 2009-01-06 21:39:04 | [diff] [blame] | 272 | PluginProcessHost *plugin_host = FindPluginProcess(plugin_path); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 273 | if (plugin_host) |
| 274 | return plugin_host; |
| 275 | |
[email protected] | a27a938 | 2009-02-11 23:55:10 | [diff] [blame] | 276 | WebPluginInfo info; |
[email protected] | 35fa6a2 | 2009-08-15 00:04:01 | [diff] [blame] | 277 | if (!NPAPI::PluginList::Singleton()->GetPluginInfoByPath( |
| 278 | plugin_path, &info)) { |
[email protected] | a27a938 | 2009-02-11 23:55:10 | [diff] [blame] | 279 | DCHECK(false); |
| 280 | return NULL; |
| 281 | } |
| 282 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 283 | // This plugin isn't loaded by any plugin process, so create a new process. |
[email protected] | dabe607 | 2009-03-17 00:52:35 | [diff] [blame] | 284 | plugin_host = new PluginProcessHost(); |
[email protected] | 610c089 | 2009-09-08 19:46:18 | [diff] [blame] | 285 | if (!plugin_host->Init(info, ui_locale_)) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 286 | DCHECK(false); // Init is not expected to fail |
| 287 | delete plugin_host; |
| 288 | return NULL; |
| 289 | } |
[email protected] | a436d92 | 2009-02-13 23:16:42 | [diff] [blame] | 290 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 291 | return plugin_host; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 292 | } |
| 293 | |
| 294 | void PluginService::OpenChannelToPlugin( |
[email protected] | 610c089 | 2009-09-08 19:46:18 | [diff] [blame] | 295 | ResourceMessageFilter* renderer_msg_filter, |
| 296 | const GURL& url, |
| 297 | const std::string& mime_type, |
| 298 | const std::wstring& locale, |
| 299 | IPC::Message* reply_msg) { |
[email protected] | d85cf07 | 2009-10-27 03:59:31 | [diff] [blame] | 300 | DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); |
[email protected] | 9dd9e838 | 2009-06-05 18:23:21 | [diff] [blame] | 301 | // We don't need a policy URL here because that was already checked by a |
| 302 | // previous call to GetPluginPath. |
| 303 | GURL policy_url; |
[email protected] | 610c089 | 2009-09-08 19:46:18 | [diff] [blame] | 304 | FilePath plugin_path = GetPluginPath(url, policy_url, mime_type, NULL); |
| 305 | PluginProcessHost* plugin_host = FindOrStartPluginProcess(plugin_path); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 306 | if (plugin_host) { |
| 307 | plugin_host->OpenChannelToPlugin(renderer_msg_filter, mime_type, reply_msg); |
| 308 | } else { |
[email protected] | 610c089 | 2009-09-08 19:46:18 | [diff] [blame] | 309 | PluginProcessHost::ReplyToRenderer( |
| 310 | renderer_msg_filter, IPC::ChannelHandle(), WebPluginInfo(), reply_msg); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 311 | } |
| 312 | } |
| 313 | |
[email protected] | 690a99c | 2009-01-06 16:48:45 | [diff] [blame] | 314 | FilePath PluginService::GetPluginPath(const GURL& url, |
[email protected] | 9dd9e838 | 2009-06-05 18:23:21 | [diff] [blame] | 315 | const GURL& policy_url, |
[email protected] | 690a99c | 2009-01-06 16:48:45 | [diff] [blame] | 316 | const std::string& mime_type, |
[email protected] | 690a99c | 2009-01-06 16:48:45 | [diff] [blame] | 317 | std::string* actual_mime_type) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 318 | bool allow_wildcard = true; |
| 319 | WebPluginInfo info; |
[email protected] | 610c089 | 2009-09-08 19:46:18 | [diff] [blame] | 320 | if (NPAPI::PluginList::Singleton()->GetPluginInfo( |
| 321 | url, mime_type, allow_wildcard, &info, actual_mime_type) && |
[email protected] | 9dd9e838 | 2009-06-05 18:23:21 | [diff] [blame] | 322 | PluginAllowedForURL(info.path, policy_url)) { |
| 323 | return info.path; |
| 324 | } |
| 325 | |
| 326 | return FilePath(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 327 | } |
| 328 | |
[email protected] | b78e168b | 2009-09-21 22:05:45 | [diff] [blame] | 329 | static void PurgePluginListCache(bool reload_pages) { |
| 330 | for (RenderProcessHost::iterator it = RenderProcessHost::AllHostsIterator(); |
| 331 | !it.IsAtEnd(); it.Advance()) { |
| 332 | it.GetCurrentValue()->Send(new ViewMsg_PurgePluginListCache(reload_pages)); |
| 333 | } |
| 334 | } |
| 335 | |
[email protected] | 58052263 | 2009-08-17 21:55:55 | [diff] [blame] | 336 | void PluginService::OnWaitableEventSignaled( |
| 337 | base::WaitableEvent* waitable_event) { |
[email protected] | b547fd4 | 2009-04-23 23:16:27 | [diff] [blame] | 338 | #if defined(OS_WIN) |
| 339 | if (waitable_event == hkcu_event_.get()) { |
| 340 | hkcu_key_.StartWatching(); |
| 341 | } else { |
| 342 | hklm_key_.StartWatching(); |
| 343 | } |
| 344 | |
[email protected] | 4e59e81 | 2010-04-06 20:51:16 | [diff] [blame] | 345 | NPAPI::PluginList::Singleton()->RefreshPlugins(); |
[email protected] | b78e168b | 2009-09-21 22:05:45 | [diff] [blame] | 346 | PurgePluginListCache(true); |
[email protected] | 9de09f8 | 2009-08-17 20:13:53 | [diff] [blame] | 347 | #endif // defined(OS_WIN) |
[email protected] | b547fd4 | 2009-04-23 23:16:27 | [diff] [blame] | 348 | } |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 349 | |
[email protected] | 4e59e81 | 2010-04-06 20:51:16 | [diff] [blame] | 350 | static void ForceShutdownPlugin(const FilePath& plugin_path) { |
| 351 | PluginProcessHost* plugin = |
| 352 | PluginService::GetInstance()->FindPluginProcess(plugin_path); |
| 353 | if (plugin) |
| 354 | plugin->ForceShutdown(); |
| 355 | } |
| 356 | |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 357 | void PluginService::Observe(NotificationType type, |
| 358 | const NotificationSource& source, |
| 359 | const NotificationDetails& details) { |
| 360 | switch (type.value) { |
[email protected] | ae09ca6 | 2009-08-21 19:46:46 | [diff] [blame] | 361 | case NotificationType::EXTENSION_LOADED: { |
[email protected] | ae09ca6 | 2009-08-21 19:46:46 | [diff] [blame] | 362 | Extension* extension = Details<Extension>(details).ptr(); |
[email protected] | b78e168b | 2009-09-21 22:05:45 | [diff] [blame] | 363 | bool plugins_changed = false; |
[email protected] | ee5e379 | 2009-10-13 23:23:47 | [diff] [blame] | 364 | for (size_t i = 0; i < extension->plugins().size(); ++i) { |
[email protected] | ae09ca6 | 2009-08-21 19:46:46 | [diff] [blame] | 365 | const Extension::PluginInfo& plugin = extension->plugins()[i]; |
[email protected] | 4e59e81 | 2010-04-06 20:51:16 | [diff] [blame] | 366 | NPAPI::PluginList::Singleton()->RefreshPlugins(); |
[email protected] | ae09ca6 | 2009-08-21 19:46:46 | [diff] [blame] | 367 | NPAPI::PluginList::Singleton()->AddExtraPluginPath(plugin.path); |
[email protected] | b78e168b | 2009-09-21 22:05:45 | [diff] [blame] | 368 | plugins_changed = true; |
[email protected] | ae09ca6 | 2009-08-21 19:46:46 | [diff] [blame] | 369 | if (!plugin.is_public) |
| 370 | private_plugins_[plugin.path] = extension->url(); |
[email protected] | c533bb2 | 2009-06-03 19:06:11 | [diff] [blame] | 371 | } |
[email protected] | b78e168b | 2009-09-21 22:05:45 | [diff] [blame] | 372 | if (plugins_changed) |
| 373 | PurgePluginListCache(false); |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 374 | break; |
| 375 | } |
| 376 | |
| 377 | case NotificationType::EXTENSION_UNLOADED: { |
[email protected] | b78e168b | 2009-09-21 22:05:45 | [diff] [blame] | 378 | Extension* extension = Details<Extension>(details).ptr(); |
| 379 | bool plugins_changed = false; |
[email protected] | ee5e379 | 2009-10-13 23:23:47 | [diff] [blame] | 380 | for (size_t i = 0; i < extension->plugins().size(); ++i) { |
[email protected] | b78e168b | 2009-09-21 22:05:45 | [diff] [blame] | 381 | const Extension::PluginInfo& plugin = extension->plugins()[i]; |
[email protected] | 4e59e81 | 2010-04-06 20:51:16 | [diff] [blame] | 382 | ChromeThread::PostTask(ChromeThread::IO, FROM_HERE, |
| 383 | NewRunnableFunction(&ForceShutdownPlugin, |
| 384 | plugin.path)); |
| 385 | NPAPI::PluginList::Singleton()->RefreshPlugins(); |
[email protected] | b78e168b | 2009-09-21 22:05:45 | [diff] [blame] | 386 | NPAPI::PluginList::Singleton()->RemoveExtraPluginPath(plugin.path); |
| 387 | plugins_changed = true; |
| 388 | if (!plugin.is_public) |
| 389 | private_plugins_.erase(plugin.path); |
| 390 | } |
| 391 | if (plugins_changed) |
| 392 | PurgePluginListCache(false); |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 393 | break; |
| 394 | } |
| 395 | |
[email protected] | a96ec6a | 2009-11-04 17:27:08 | [diff] [blame] | 396 | #if defined(OS_MACOSX) |
| 397 | case NotificationType::APP_ACTIVATED: { |
| 398 | ChromeThread::PostTask(ChromeThread::IO, FROM_HERE, |
| 399 | NewRunnableFunction(&NotifyPluginsOfActivation)); |
| 400 | break; |
| 401 | } |
| 402 | #endif |
| 403 | |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 404 | default: |
| 405 | DCHECK(false); |
| 406 | } |
| 407 | } |
[email protected] | 9dd9e838 | 2009-06-05 18:23:21 | [diff] [blame] | 408 | |
| 409 | bool PluginService::PluginAllowedForURL(const FilePath& plugin_path, |
| 410 | const GURL& url) { |
| 411 | if (url.is_empty()) |
| 412 | return true; // Caller wants all plugins. |
| 413 | |
| 414 | PrivatePluginMap::iterator it = private_plugins_.find(plugin_path); |
| 415 | if (it == private_plugins_.end()) |
| 416 | return true; // This plugin is not private, so it's allowed everywhere. |
| 417 | |
| 418 | // We do a dumb compare of scheme and host, rather than using the domain |
| 419 | // service, since we only care about this for extensions. |
| 420 | const GURL& required_url = it->second; |
| 421 | return (url.scheme() == required_url.scheme() && |
| 422 | url.host() == required_url.host()); |
| 423 | } |
[email protected] | 4e0616e | 2010-05-28 14:55:53 | [diff] [blame] | 424 | |
| 425 | void PluginService::RegisterPepperPlugins() { |
| 426 | std::vector<PepperPluginInfo> plugins; |
| 427 | PepperPluginRegistry::GetList(&plugins); |
| 428 | for (size_t i = 0; i < plugins.size(); ++i) { |
| 429 | NPAPI::PluginVersionInfo info; |
| 430 | info.path = plugins[i].path; |
| 431 | info.product_name = plugins[i].path.BaseName().ToWStringHack(); |
| 432 | info.mime_types = ASCIIToWide(JoinString(plugins[i].mime_types, '|')); |
| 433 | |
| 434 | // These NPAPI entry points will never be called. TODO(darin): Come up |
| 435 | // with a cleaner way to register pepper plugins with the NPAPI PluginList, |
| 436 | // or perhaps refactor the PluginList to be less specific to NPAPI. |
| 437 | memset(&info.entry_points, 0, sizeof(info.entry_points)); |
| 438 | |
| 439 | NPAPI::PluginList::Singleton()->RegisterInternalPlugin(info); |
| 440 | } |
| 441 | } |