[email protected] | 3b48dbc | 2012-01-06 16:34:17 | [diff] [blame] | 1 | // Copyright (c) 2012 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] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 5 | #include "content/browser/plugin_service_impl.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 6 | |
[email protected] | d33e7cc | 2011-09-23 01:43:56 | [diff] [blame] | 7 | #include "base/bind.h" |
[email protected] | d48f1e0c | 2009-02-12 20:57:54 | [diff] [blame] | 8 | #include "base/command_line.h" |
[email protected] | 7b3ee8b | 2011-04-01 18:48:19 | [diff] [blame] | 9 | #include "base/compiler_specific.h" |
[email protected] | dfba876 | 2011-09-02 12:49:54 | [diff] [blame] | 10 | #include "base/file_path.h" |
[email protected] | d33e7cc | 2011-09-23 01:43:56 | [diff] [blame] | 11 | #include "base/message_loop.h" |
| 12 | #include "base/message_loop_proxy.h" |
[email protected] | 9c49ff0 | 2010-01-27 01:20:55 | [diff] [blame] | 13 | #include "base/path_service.h" |
[email protected] | d70539de | 2009-06-24 22:17:06 | [diff] [blame] | 14 | #include "base/string_util.h" |
[email protected] | 7f070d4 | 2011-03-09 20:25:32 | [diff] [blame] | 15 | #include "base/synchronization/waitable_event.h" |
[email protected] | 34b9963 | 2011-01-01 01:01:06 | [diff] [blame] | 16 | #include "base/threading/thread.h" |
[email protected] | be1ce6a7 | 2010-08-03 14:35:22 | [diff] [blame] | 17 | #include "base/utf_string_conversions.h" |
[email protected] | cec1b8d | 2010-03-24 00:21:34 | [diff] [blame] | 18 | #include "base/values.h" |
[email protected] | a01efd2 | 2011-03-01 00:38:32 | [diff] [blame] | 19 | #include "content/browser/ppapi_plugin_process_host.h" |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 20 | #include "content/browser/renderer_host/render_process_host_impl.h" |
[email protected] | b3c41c0b | 2012-03-06 15:48:32 | [diff] [blame] | 21 | #include "content/browser/renderer_host/render_view_host_impl.h" |
[email protected] | cebc3dc | 2011-04-18 17:15:00 | [diff] [blame] | 22 | #include "content/common/pepper_plugin_registry.h" |
[email protected] | 105303e | 2011-03-14 22:16:10 | [diff] [blame] | 23 | #include "content/common/plugin_messages.h" |
[email protected] | 4912595 | 2011-09-27 18:05:15 | [diff] [blame] | 24 | #include "content/common/utility_messages.h" |
[email protected] | 38b59290 | 2011-04-16 02:08:42 | [diff] [blame] | 25 | #include "content/common/view_messages.h" |
[email protected] | c38831a1 | 2011-10-28 12:44:49 | [diff] [blame] | 26 | #include "content/public/browser/browser_thread.h" |
[email protected] | 87f3c08 | 2011-10-19 18:07:44 | [diff] [blame] | 27 | #include "content/public/browser/content_browser_client.h" |
[email protected] | 31f376c | 2012-03-13 16:43:09 | [diff] [blame] | 28 | #include "content/public/browser/plugin_service_filter.h" |
[email protected] | ce96786 | 2012-02-09 22:47:05 | [diff] [blame] | 29 | #include "content/public/browser/resource_context.h" |
[email protected] | c08950d2 | 2011-10-13 22:20:29 | [diff] [blame] | 30 | #include "content/public/common/content_switches.h" |
[email protected] | bd5d6cf | 2011-12-01 00:39:12 | [diff] [blame] | 31 | #include "content/public/common/process_type.h" |
[email protected] | 191eb3f7 | 2010-12-21 06:27:50 | [diff] [blame] | 32 | #include "webkit/plugins/npapi/plugin_list.h" |
[email protected] | 1b51720 | 2012-12-19 17:16:10 | [diff] [blame] | 33 | #include "webkit/plugins/npapi/plugin_utils.h" |
[email protected] | 91d9f3d | 2011-08-14 05:24:44 | [diff] [blame] | 34 | #include "webkit/plugins/webplugininfo.h" |
[email protected] | 191eb3f7 | 2010-12-21 06:27:50 | [diff] [blame] | 35 | |
[email protected] | 3b91edbe | 2012-09-27 22:49:23 | [diff] [blame] | 36 | #if defined(OS_WIN) |
| 37 | #include "webkit/plugins/npapi/plugin_constants_win.h" |
| 38 | #endif |
| 39 | |
| 40 | #if defined(OS_POSIX) |
| 41 | #include "content/browser/plugin_loader_posix.h" |
| 42 | #endif |
| 43 | |
[email protected] | 52348b2 | 2012-11-07 10:19:34 | [diff] [blame] | 44 | #if defined(OS_POSIX) && !defined(OS_OPENBSD) && !defined(OS_ANDROID) |
[email protected] | 6665571f | 2013-01-15 07:59:52 | [diff] [blame] | 45 | using ::base::FilePathWatcher; |
[email protected] | 493c800 | 2011-04-14 16:56:01 | [diff] [blame] | 46 | #endif |
| 47 | |
[email protected] | 13075767 | 2012-10-24 00:26:19 | [diff] [blame] | 48 | namespace content { |
[email protected] | d33e7cc | 2011-09-23 01:43:56 | [diff] [blame] | 49 | namespace { |
| 50 | |
[email protected] | 1b51720 | 2012-12-19 17:16:10 | [diff] [blame] | 51 | bool LoadPluginListInProcess() { |
| 52 | #if defined(OS_WIN) |
| 53 | return true; |
| 54 | #else |
| 55 | // If on POSIX, we don't want to load the list of NPAPI plugins in-process as |
| 56 | // that causes instability. |
| 57 | return !webkit::npapi::NPAPIPluginsSupported(); |
| 58 | #endif |
| 59 | } |
| 60 | |
[email protected] | 4912595 | 2011-09-27 18:05:15 | [diff] [blame] | 61 | // Callback set on the PluginList to assert that plugin loading happens on the |
| 62 | // correct thread. |
[email protected] | 1b51720 | 2012-12-19 17:16:10 | [diff] [blame] | 63 | void WillLoadPluginsCallback( |
[email protected] | a33fa9d | 2012-05-16 14:47:49 | [diff] [blame] | 64 | base::SequencedWorkerPool::SequenceToken token) { |
[email protected] | 1b51720 | 2012-12-19 17:16:10 | [diff] [blame] | 65 | if (LoadPluginListInProcess()) { |
| 66 | CHECK(BrowserThread::GetBlockingPool()->IsRunningSequenceOnCurrentThread( |
| 67 | token)); |
| 68 | } else { |
| 69 | CHECK(false) << "Plugin loading should happen out-of-process."; |
| 70 | } |
[email protected] | a7991225 | 2012-05-16 11:52:19 | [diff] [blame] | 71 | } |
[email protected] | d33e7cc | 2011-09-23 01:43:56 | [diff] [blame] | 72 | |
[email protected] | a96ec6a | 2009-11-04 17:27:08 | [diff] [blame] | 73 | #if defined(OS_MACOSX) |
[email protected] | 07b71c8 | 2013-01-08 19:07:31 | [diff] [blame] | 74 | void NotifyPluginsOfActivation() { |
[email protected] | f8b3ef8 | 2010-10-11 02:45:52 | [diff] [blame] | 75 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
[email protected] | a96ec6a | 2009-11-04 17:27:08 | [diff] [blame] | 76 | |
[email protected] | 4967f79 | 2012-01-20 22:14:40 | [diff] [blame] | 77 | for (PluginProcessHostIterator iter; !iter.Done(); ++iter) |
| 78 | iter->OnAppActivation(); |
[email protected] | a96ec6a | 2009-11-04 17:27:08 | [diff] [blame] | 79 | } |
[email protected] | 3b48dbc | 2012-01-06 16:34:17 | [diff] [blame] | 80 | #endif |
[email protected] | 45a22e6 | 2011-10-12 09:48:02 | [diff] [blame] | 81 | |
[email protected] | 07b71c8 | 2013-01-08 19:07:31 | [diff] [blame] | 82 | #if defined(OS_POSIX) && !defined(OS_OPENBSD) && !defined(OS_ANDROID) |
| 83 | void NotifyPluginDirChanged(const FilePath& path, bool error) { |
| 84 | if (error) { |
[email protected] | 634d23d | 2011-01-19 10:38:19 | [diff] [blame] | 85 | // TODO(pastarmovj): Add some sensible error handling. Maybe silently |
| 86 | // stopping the watcher would be enough. Or possibly restart it. |
| 87 | NOTREACHED(); |
[email protected] | 07b71c8 | 2013-01-08 19:07:31 | [diff] [blame] | 88 | return; |
[email protected] | 634d23d | 2011-01-19 10:38:19 | [diff] [blame] | 89 | } |
[email protected] | 07b71c8 | 2013-01-08 19:07:31 | [diff] [blame] | 90 | VLOG(1) << "Watched path changed: " << path.value(); |
| 91 | // Make the plugin list update itself |
| 92 | webkit::npapi::PluginList::Singleton()->RefreshPlugins(); |
| 93 | BrowserThread::PostTask( |
| 94 | BrowserThread::UI, FROM_HERE, |
| 95 | base::Bind(&PluginService::PurgePluginListCache, |
| 96 | static_cast<BrowserContext*>(NULL), false)); |
| 97 | } |
[email protected] | 634d23d | 2011-01-19 10:38:19 | [diff] [blame] | 98 | #endif |
| 99 | |
[email protected] | 07b71c8 | 2013-01-08 19:07:31 | [diff] [blame] | 100 | } // namespace |
| 101 | |
[email protected] | 3a5180ae | 2011-12-21 02:39:38 | [diff] [blame] | 102 | // static |
| 103 | PluginService* PluginService::GetInstance() { |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 104 | return PluginServiceImpl::GetInstance(); |
[email protected] | 3a5180ae | 2011-12-21 02:39:38 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | void PluginService::PurgePluginListCache(BrowserContext* browser_context, |
| 108 | bool reload_pages) { |
| 109 | for (RenderProcessHost::iterator it = RenderProcessHost::AllHostsIterator(); |
| 110 | !it.IsAtEnd(); it.Advance()) { |
| 111 | RenderProcessHost* host = it.GetCurrentValue(); |
| 112 | if (!browser_context || host->GetBrowserContext() == browser_context) |
| 113 | host->Send(new ViewMsg_PurgePluginListCache(reload_pages)); |
| 114 | } |
| 115 | } |
| 116 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 117 | // static |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 118 | PluginServiceImpl* PluginServiceImpl::GetInstance() { |
| 119 | return Singleton<PluginServiceImpl>::get(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 120 | } |
| 121 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 122 | PluginServiceImpl::PluginServiceImpl() |
[email protected] | 9990736 | 2012-01-11 05:41:40 | [diff] [blame] | 123 | : plugin_list_(NULL), filter_(NULL) { |
[email protected] | ee06617 | 2011-11-10 23:20:05 | [diff] [blame] | 124 | } |
| 125 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 126 | PluginServiceImpl::~PluginServiceImpl() { |
[email protected] | ee06617 | 2011-11-10 23:20:05 | [diff] [blame] | 127 | #if defined(OS_WIN) |
| 128 | // Release the events since they're owned by RegKey, not WaitableEvent. |
| 129 | hkcu_watcher_.StopWatching(); |
| 130 | hklm_watcher_.StopWatching(); |
| 131 | if (hkcu_event_.get()) |
| 132 | hkcu_event_->Release(); |
| 133 | if (hklm_event_.get()) |
| 134 | hklm_event_->Release(); |
| 135 | #endif |
| 136 | // Make sure no plugin channel requests have been leaked. |
| 137 | DCHECK(pending_plugin_clients_.empty()); |
| 138 | } |
| 139 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 140 | void PluginServiceImpl::Init() { |
[email protected] | ee06617 | 2011-11-10 23:20:05 | [diff] [blame] | 141 | if (!plugin_list_) |
| 142 | plugin_list_ = webkit::npapi::PluginList::Singleton(); |
| 143 | |
[email protected] | a33fa9d | 2012-05-16 14:47:49 | [diff] [blame] | 144 | plugin_list_token_ = BrowserThread::GetBlockingPool()->GetSequenceToken(); |
[email protected] | 3a5180ae | 2011-12-21 02:39:38 | [diff] [blame] | 145 | plugin_list_->set_will_load_plugins_callback( |
[email protected] | 1b51720 | 2012-12-19 17:16:10 | [diff] [blame] | 146 | base::Bind(&WillLoadPluginsCallback, plugin_list_token_)); |
[email protected] | 4912595 | 2011-09-27 18:05:15 | [diff] [blame] | 147 | |
[email protected] | 4e0616e | 2010-05-28 14:55:53 | [diff] [blame] | 148 | RegisterPepperPlugins(); |
| 149 | |
[email protected] | 0f7d449e | 2013-01-23 15:12:35 | [diff] [blame^] | 150 | // The --site-per-process flag enables an out-of-process iframes |
| 151 | // prototype, which uses WebView for rendering. We need to register the MIME |
| 152 | // type we use with the plugin, so the renderer can instantiate it. |
| 153 | const CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 154 | if (command_line->HasSwitch(switches::kSitePerProcess)) { |
| 155 | webkit::WebPluginInfo webview_plugin( |
| 156 | ASCIIToUTF16("WebView Tag"), |
| 157 | FilePath(FILE_PATH_LITERAL("")), |
| 158 | ASCIIToUTF16("1.2.3.4"), |
| 159 | ASCIIToUTF16("Browser Plugin.")); |
| 160 | webview_plugin.type = webkit::WebPluginInfo::PLUGIN_TYPE_NPAPI; |
| 161 | webkit::WebPluginMimeType webview_plugin_mime_type; |
| 162 | webview_plugin_mime_type.mime_type = "application/browser-plugin"; |
| 163 | webview_plugin_mime_type.file_extensions.push_back("*"); |
| 164 | webview_plugin.mime_types.push_back(webview_plugin_mime_type); |
| 165 | RegisterInternalPlugin(webview_plugin, true); |
| 166 | } |
| 167 | |
[email protected] | 13075767 | 2012-10-24 00:26:19 | [diff] [blame] | 168 | GetContentClient()->AddNPAPIPlugins(plugin_list_); |
[email protected] | f520b5b | 2011-11-08 02:42:14 | [diff] [blame] | 169 | |
[email protected] | 9a1c426 | 2010-06-29 21:50:27 | [diff] [blame] | 170 | // Load any specified on the command line as well. |
[email protected] | c4e52f0d | 2009-11-06 19:55:16 | [diff] [blame] | 171 | FilePath path = command_line->GetSwitchValuePath(switches::kLoadPlugin); |
[email protected] | 7bf795d9 | 2010-05-22 00:14:28 | [diff] [blame] | 172 | if (!path.empty()) |
[email protected] | f520b5b | 2011-11-08 02:42:14 | [diff] [blame] | 173 | AddExtraPluginPath(path); |
[email protected] | 9a1c426 | 2010-06-29 21:50:27 | [diff] [blame] | 174 | path = command_line->GetSwitchValuePath(switches::kExtraPluginDir); |
| 175 | if (!path.empty()) |
[email protected] | 3a5180ae | 2011-12-21 02:39:38 | [diff] [blame] | 176 | plugin_list_->AddExtraPluginDir(path); |
[email protected] | dfba876 | 2011-09-02 12:49:54 | [diff] [blame] | 177 | } |
| 178 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 179 | void PluginServiceImpl::StartWatchingPlugins() { |
[email protected] | 634d23d | 2011-01-19 10:38:19 | [diff] [blame] | 180 | // Start watching for changes in the plugin list. This means watching |
| 181 | // for changes in the Windows registry keys and on both Windows and POSIX |
| 182 | // watch for changes in the paths that are expected to contain plugins. |
[email protected] | b547fd4 | 2009-04-23 23:16:27 | [diff] [blame] | 183 | #if defined(OS_WIN) |
[email protected] | 86ec4f6e | 2011-04-20 16:21:19 | [diff] [blame] | 184 | if (hkcu_key_.Create(HKEY_CURRENT_USER, |
| 185 | webkit::npapi::kRegistryMozillaPlugins, |
| 186 | KEY_NOTIFY) == ERROR_SUCCESS) { |
| 187 | if (hkcu_key_.StartWatching() == ERROR_SUCCESS) { |
| 188 | hkcu_event_.reset(new base::WaitableEvent(hkcu_key_.watch_event())); |
| 189 | hkcu_watcher_.StartWatching(hkcu_event_.get(), this); |
| 190 | } |
[email protected] | b547fd4 | 2009-04-23 23:16:27 | [diff] [blame] | 191 | } |
[email protected] | 86ec4f6e | 2011-04-20 16:21:19 | [diff] [blame] | 192 | if (hklm_key_.Create(HKEY_LOCAL_MACHINE, |
| 193 | webkit::npapi::kRegistryMozillaPlugins, |
| 194 | KEY_NOTIFY) == ERROR_SUCCESS) { |
| 195 | if (hklm_key_.StartWatching() == ERROR_SUCCESS) { |
| 196 | hklm_event_.reset(new base::WaitableEvent(hklm_key_.watch_event())); |
| 197 | hklm_watcher_.StartWatching(hklm_event_.get(), this); |
| 198 | } |
[email protected] | b547fd4 | 2009-04-23 23:16:27 | [diff] [blame] | 199 | } |
[email protected] | a33fa9d | 2012-05-16 14:47:49 | [diff] [blame] | 200 | #endif |
[email protected] | 52348b2 | 2012-11-07 10:19:34 | [diff] [blame] | 201 | #if defined(OS_POSIX) && !defined(OS_OPENBSD) && !defined(OS_ANDROID) |
[email protected] | 634d23d | 2011-01-19 10:38:19 | [diff] [blame] | 202 | // On ChromeOS the user can't install plugins anyway and on Windows all |
| 203 | // important plugins register themselves in the registry so no need to do that. |
[email protected] | 07b71c8 | 2013-01-08 19:07:31 | [diff] [blame] | 204 | |
[email protected] | 634d23d | 2011-01-19 10:38:19 | [diff] [blame] | 205 | // Get the list of all paths for registering the FilePathWatchers |
| 206 | // that will track and if needed reload the list of plugins on runtime. |
| 207 | std::vector<FilePath> plugin_dirs; |
[email protected] | 3a5180ae | 2011-12-21 02:39:38 | [diff] [blame] | 208 | plugin_list_->GetPluginDirectories(&plugin_dirs); |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 209 | |
[email protected] | 634d23d | 2011-01-19 10:38:19 | [diff] [blame] | 210 | for (size_t i = 0; i < plugin_dirs.size(); ++i) { |
[email protected] | 634d23d | 2011-01-19 10:38:19 | [diff] [blame] | 211 | // FilePathWatcher can not handle non-absolute paths under windows. |
| 212 | // We don't watch for file changes in windows now but if this should ever |
| 213 | // be extended to Windows these lines might save some time of debugging. |
| 214 | #if defined(OS_WIN) |
| 215 | if (!plugin_dirs[i].IsAbsolute()) |
| 216 | continue; |
| 217 | #endif |
[email protected] | 493c800 | 2011-04-14 16:56:01 | [diff] [blame] | 218 | FilePathWatcher* watcher = new FilePathWatcher(); |
[email protected] | 634d23d | 2011-01-19 10:38:19 | [diff] [blame] | 219 | VLOG(1) << "Watching for changes in: " << plugin_dirs[i].value(); |
| 220 | BrowserThread::PostTask( |
| 221 | BrowserThread::FILE, FROM_HERE, |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 222 | base::Bind(&PluginServiceImpl::RegisterFilePathWatcher, watcher, |
[email protected] | 07b71c8 | 2013-01-08 19:07:31 | [diff] [blame] | 223 | plugin_dirs[i])); |
[email protected] | 634d23d | 2011-01-19 10:38:19 | [diff] [blame] | 224 | file_watchers_.push_back(watcher); |
| 225 | } |
| 226 | #endif |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 227 | } |
| 228 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 229 | PluginProcessHost* PluginServiceImpl::FindNpapiPluginProcess( |
[email protected] | 28ab7f9 | 2009-01-06 21:39:04 | [diff] [blame] | 230 | const FilePath& plugin_path) { |
[email protected] | 4967f79 | 2012-01-20 22:14:40 | [diff] [blame] | 231 | for (PluginProcessHostIterator iter; !iter.Done(); ++iter) { |
| 232 | if (iter->info().path == plugin_path) |
| 233 | return *iter; |
[email protected] | a436d92 | 2009-02-13 23:16:42 | [diff] [blame] | 234 | } |
| 235 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 236 | return NULL; |
| 237 | } |
| 238 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 239 | PpapiPluginProcessHost* PluginServiceImpl::FindPpapiPluginProcess( |
[email protected] | dd9a095 | 2012-05-31 20:11:31 | [diff] [blame] | 240 | const FilePath& plugin_path, |
| 241 | const FilePath& profile_data_directory) { |
[email protected] | 4967f79 | 2012-01-20 22:14:40 | [diff] [blame] | 242 | for (PpapiPluginProcessHostIterator iter; !iter.Done(); ++iter) { |
[email protected] | dd9a095 | 2012-05-31 20:11:31 | [diff] [blame] | 243 | if (iter->plugin_path() == plugin_path && |
| 244 | iter->profile_data_directory() == profile_data_directory) { |
[email protected] | 4967f79 | 2012-01-20 22:14:40 | [diff] [blame] | 245 | return *iter; |
[email protected] | dd9a095 | 2012-05-31 20:11:31 | [diff] [blame] | 246 | } |
[email protected] | a08ebea | 2011-02-13 17:50:20 | [diff] [blame] | 247 | } |
[email protected] | a08ebea | 2011-02-13 17:50:20 | [diff] [blame] | 248 | return NULL; |
| 249 | } |
| 250 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 251 | PpapiPluginProcessHost* PluginServiceImpl::FindPpapiBrokerProcess( |
[email protected] | eb415bf0e | 2011-04-14 02:45:42 | [diff] [blame] | 252 | const FilePath& broker_path) { |
[email protected] | 4967f79 | 2012-01-20 22:14:40 | [diff] [blame] | 253 | for (PpapiBrokerProcessHostIterator iter; !iter.Done(); ++iter) { |
| 254 | if (iter->plugin_path() == broker_path) |
| 255 | return *iter; |
[email protected] | eb415bf0e | 2011-04-14 02:45:42 | [diff] [blame] | 256 | } |
| 257 | |
| 258 | return NULL; |
| 259 | } |
| 260 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 261 | PluginProcessHost* PluginServiceImpl::FindOrStartNpapiPluginProcess( |
[email protected] | a08ebea | 2011-02-13 17:50:20 | [diff] [blame] | 262 | const FilePath& plugin_path) { |
| 263 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 264 | |
| 265 | PluginProcessHost* plugin_host = FindNpapiPluginProcess(plugin_path); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 266 | if (plugin_host) |
| 267 | return plugin_host; |
| 268 | |
[email protected] | 91d9f3d | 2011-08-14 05:24:44 | [diff] [blame] | 269 | webkit::WebPluginInfo info; |
[email protected] | 88ca491 | 2011-10-12 14:00:43 | [diff] [blame] | 270 | if (!GetPluginInfoByPath(plugin_path, &info)) { |
[email protected] | a27a938 | 2009-02-11 23:55:10 | [diff] [blame] | 271 | return NULL; |
| 272 | } |
| 273 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 274 | // 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] | 275 | scoped_ptr<PluginProcessHost> new_host(new PluginProcessHost()); |
[email protected] | 9990736 | 2012-01-11 05:41:40 | [diff] [blame] | 276 | if (!new_host->Init(info)) { |
[email protected] | a08ebea | 2011-02-13 17:50:20 | [diff] [blame] | 277 | NOTREACHED(); // Init is not expected to fail. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 278 | return NULL; |
| 279 | } |
[email protected] | 8b8a554d | 2010-11-18 13:26:40 | [diff] [blame] | 280 | return new_host.release(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 281 | } |
| 282 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 283 | PpapiPluginProcessHost* PluginServiceImpl::FindOrStartPpapiPluginProcess( |
[email protected] | d259a8e | 2011-05-18 22:31:09 | [diff] [blame] | 284 | const FilePath& plugin_path, |
[email protected] | dd9a095 | 2012-05-31 20:11:31 | [diff] [blame] | 285 | const FilePath& profile_data_directory, |
[email protected] | a50432d | 2011-09-30 16:32:14 | [diff] [blame] | 286 | PpapiPluginProcessHost::PluginClient* client) { |
[email protected] | a08ebea | 2011-02-13 17:50:20 | [diff] [blame] | 287 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 288 | |
[email protected] | dd9a095 | 2012-05-31 20:11:31 | [diff] [blame] | 289 | PpapiPluginProcessHost* plugin_host = |
| 290 | FindPpapiPluginProcess(plugin_path, profile_data_directory); |
[email protected] | a08ebea | 2011-02-13 17:50:20 | [diff] [blame] | 291 | if (plugin_host) |
| 292 | return plugin_host; |
| 293 | |
[email protected] | eb415bf0e | 2011-04-14 02:45:42 | [diff] [blame] | 294 | // Validate that the plugin is actually registered. |
[email protected] | 13075767 | 2012-10-24 00:26:19 | [diff] [blame] | 295 | PepperPluginInfo* info = GetRegisteredPpapiPluginInfo(plugin_path); |
[email protected] | a08ebea | 2011-02-13 17:50:20 | [diff] [blame] | 296 | if (!info) |
| 297 | return NULL; |
| 298 | |
| 299 | // This plugin isn't loaded by any plugin process, so create a new process. |
[email protected] | a50432d | 2011-09-30 16:32:14 | [diff] [blame] | 300 | return PpapiPluginProcessHost::CreatePluginHost( |
[email protected] | dd9a095 | 2012-05-31 20:11:31 | [diff] [blame] | 301 | *info, profile_data_directory, |
[email protected] | df02aca | 2012-02-09 21:03:20 | [diff] [blame] | 302 | client->GetResourceContext()->GetHostResolver()); |
[email protected] | a08ebea | 2011-02-13 17:50:20 | [diff] [blame] | 303 | } |
| 304 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 305 | PpapiPluginProcessHost* PluginServiceImpl::FindOrStartPpapiBrokerProcess( |
[email protected] | eb415bf0e | 2011-04-14 02:45:42 | [diff] [blame] | 306 | const FilePath& plugin_path) { |
| 307 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 308 | |
[email protected] | a50432d | 2011-09-30 16:32:14 | [diff] [blame] | 309 | PpapiPluginProcessHost* plugin_host = FindPpapiBrokerProcess(plugin_path); |
[email protected] | eb415bf0e | 2011-04-14 02:45:42 | [diff] [blame] | 310 | if (plugin_host) |
| 311 | return plugin_host; |
| 312 | |
| 313 | // Validate that the plugin is actually registered. |
[email protected] | 13075767 | 2012-10-24 00:26:19 | [diff] [blame] | 314 | PepperPluginInfo* info = GetRegisteredPpapiPluginInfo(plugin_path); |
[email protected] | eb415bf0e | 2011-04-14 02:45:42 | [diff] [blame] | 315 | if (!info) |
| 316 | return NULL; |
| 317 | |
| 318 | // TODO(ddorwin): Uncomment once out of process is supported. |
| 319 | // DCHECK(info->is_out_of_process); |
| 320 | |
| 321 | // This broker isn't loaded by any broker process, so create a new process. |
[email protected] | a50432d | 2011-09-30 16:32:14 | [diff] [blame] | 322 | return PpapiPluginProcessHost::CreateBrokerHost(*info); |
[email protected] | eb415bf0e | 2011-04-14 02:45:42 | [diff] [blame] | 323 | } |
| 324 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 325 | void PluginServiceImpl::OpenChannelToNpapiPlugin( |
[email protected] | c8f73ab | 2011-01-22 00:05:17 | [diff] [blame] | 326 | int render_process_id, |
| 327 | int render_view_id, |
[email protected] | 610c089 | 2009-09-08 19:46:18 | [diff] [blame] | 328 | const GURL& url, |
[email protected] | dfba876 | 2011-09-02 12:49:54 | [diff] [blame] | 329 | const GURL& page_url, |
[email protected] | 610c089 | 2009-09-08 19:46:18 | [diff] [blame] | 330 | const std::string& mime_type, |
[email protected] | 46b69e4 | 2010-11-02 12:26:39 | [diff] [blame] | 331 | PluginProcessHost::Client* client) { |
[email protected] | 76b70f9 | 2011-11-21 19:31:14 | [diff] [blame] | 332 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
[email protected] | 4befe759 | 2011-09-14 22:49:09 | [diff] [blame] | 333 | DCHECK(!ContainsKey(pending_plugin_clients_, client)); |
| 334 | pending_plugin_clients_.insert(client); |
[email protected] | 88ca491 | 2011-10-12 14:00:43 | [diff] [blame] | 335 | |
| 336 | // Make sure plugins are loaded if necessary. |
[email protected] | 209f2ae | 2012-03-13 01:28:08 | [diff] [blame] | 337 | PluginServiceFilterParams params = { |
[email protected] | 88ca491 | 2011-10-12 14:00:43 | [diff] [blame] | 338 | render_process_id, |
| 339 | render_view_id, |
| 340 | page_url, |
[email protected] | df02aca | 2012-02-09 21:03:20 | [diff] [blame] | 341 | client->GetResourceContext() |
[email protected] | 88ca491 | 2011-10-12 14:00:43 | [diff] [blame] | 342 | }; |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 343 | GetPlugins(base::Bind( |
| 344 | &PluginServiceImpl::ForwardGetAllowedPluginForOpenChannelToPlugin, |
| 345 | base::Unretained(this), params, url, mime_type, client)); |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 346 | } |
| 347 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 348 | void PluginServiceImpl::OpenChannelToPpapiPlugin( |
[email protected] | dd9a095 | 2012-05-31 20:11:31 | [diff] [blame] | 349 | const FilePath& plugin_path, |
| 350 | const FilePath& profile_data_directory, |
[email protected] | a50432d | 2011-09-30 16:32:14 | [diff] [blame] | 351 | PpapiPluginProcessHost::PluginClient* client) { |
[email protected] | d259a8e | 2011-05-18 22:31:09 | [diff] [blame] | 352 | PpapiPluginProcessHost* plugin_host = FindOrStartPpapiPluginProcess( |
[email protected] | dd9a095 | 2012-05-31 20:11:31 | [diff] [blame] | 353 | plugin_path, profile_data_directory, client); |
[email protected] | 1bf0fb2 | 2012-04-12 21:44:16 | [diff] [blame] | 354 | if (plugin_host) { |
[email protected] | a08ebea | 2011-02-13 17:50:20 | [diff] [blame] | 355 | plugin_host->OpenChannelToPlugin(client); |
[email protected] | 1bf0fb2 | 2012-04-12 21:44:16 | [diff] [blame] | 356 | } else { |
| 357 | // Send error. |
[email protected] | 108fd34 | 2013-01-04 20:46:54 | [diff] [blame] | 358 | client->OnPpapiChannelOpened(IPC::ChannelHandle(), base::kNullProcessId, 0); |
[email protected] | 1bf0fb2 | 2012-04-12 21:44:16 | [diff] [blame] | 359 | } |
[email protected] | a08ebea | 2011-02-13 17:50:20 | [diff] [blame] | 360 | } |
| 361 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 362 | void PluginServiceImpl::OpenChannelToPpapiBroker( |
[email protected] | eb415bf0e | 2011-04-14 02:45:42 | [diff] [blame] | 363 | const FilePath& path, |
[email protected] | a50432d | 2011-09-30 16:32:14 | [diff] [blame] | 364 | PpapiPluginProcessHost::BrokerClient* client) { |
| 365 | PpapiPluginProcessHost* plugin_host = FindOrStartPpapiBrokerProcess(path); |
[email protected] | 1bf0fb2 | 2012-04-12 21:44:16 | [diff] [blame] | 366 | if (plugin_host) { |
[email protected] | a50432d | 2011-09-30 16:32:14 | [diff] [blame] | 367 | plugin_host->OpenChannelToPlugin(client); |
[email protected] | 1bf0fb2 | 2012-04-12 21:44:16 | [diff] [blame] | 368 | } else { |
| 369 | // Send error. |
[email protected] | 108fd34 | 2013-01-04 20:46:54 | [diff] [blame] | 370 | client->OnPpapiChannelOpened(IPC::ChannelHandle(), base::kNullProcessId, 0); |
[email protected] | 1bf0fb2 | 2012-04-12 21:44:16 | [diff] [blame] | 371 | } |
[email protected] | eb415bf0e | 2011-04-14 02:45:42 | [diff] [blame] | 372 | } |
| 373 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 374 | void PluginServiceImpl::CancelOpenChannelToNpapiPlugin( |
[email protected] | 4befe759 | 2011-09-14 22:49:09 | [diff] [blame] | 375 | PluginProcessHost::Client* client) { |
| 376 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 377 | DCHECK(ContainsKey(pending_plugin_clients_, client)); |
| 378 | pending_plugin_clients_.erase(client); |
| 379 | } |
| 380 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 381 | void PluginServiceImpl::ForwardGetAllowedPluginForOpenChannelToPlugin( |
[email protected] | 209f2ae | 2012-03-13 01:28:08 | [diff] [blame] | 382 | const PluginServiceFilterParams& params, |
[email protected] | 88ca491 | 2011-10-12 14:00:43 | [diff] [blame] | 383 | const GURL& url, |
| 384 | const std::string& mime_type, |
| 385 | PluginProcessHost::Client* client, |
| 386 | const std::vector<webkit::WebPluginInfo>&) { |
| 387 | GetAllowedPluginForOpenChannelToPlugin(params.render_process_id, |
| 388 | params.render_view_id, url, params.page_url, mime_type, client, |
| 389 | params.resource_context); |
| 390 | } |
| 391 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 392 | void PluginServiceImpl::GetAllowedPluginForOpenChannelToPlugin( |
[email protected] | c8f73ab | 2011-01-22 00:05:17 | [diff] [blame] | 393 | int render_process_id, |
| 394 | int render_view_id, |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 395 | const GURL& url, |
[email protected] | dfba876 | 2011-09-02 12:49:54 | [diff] [blame] | 396 | const GURL& page_url, |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 397 | const std::string& mime_type, |
[email protected] | 87c4be4 | 2011-09-16 01:10:59 | [diff] [blame] | 398 | PluginProcessHost::Client* client, |
[email protected] | 13075767 | 2012-10-24 00:26:19 | [diff] [blame] | 399 | ResourceContext* resource_context) { |
[email protected] | 91d9f3d | 2011-08-14 05:24:44 | [diff] [blame] | 400 | webkit::WebPluginInfo info; |
[email protected] | dfba876 | 2011-09-02 12:49:54 | [diff] [blame] | 401 | bool allow_wildcard = true; |
[email protected] | 11e1c18 | 2011-05-17 20:26:27 | [diff] [blame] | 402 | bool found = GetPluginInfo( |
[email protected] | df02aca | 2012-02-09 21:03:20 | [diff] [blame] | 403 | render_process_id, render_view_id, resource_context, |
[email protected] | dfba876 | 2011-09-02 12:49:54 | [diff] [blame] | 404 | url, page_url, mime_type, allow_wildcard, |
| 405 | NULL, &info, NULL); |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 406 | FilePath plugin_path; |
[email protected] | 6859807 | 2011-07-29 08:21:28 | [diff] [blame] | 407 | if (found) |
[email protected] | dfba876 | 2011-09-02 12:49:54 | [diff] [blame] | 408 | plugin_path = info.path; |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 409 | |
| 410 | // Now we jump back to the IO thread to finish opening the channel. |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 411 | BrowserThread::PostTask( |
| 412 | BrowserThread::IO, FROM_HERE, |
| 413 | base::Bind(&PluginServiceImpl::FinishOpenChannelToPlugin, |
[email protected] | 88ca491 | 2011-10-12 14:00:43 | [diff] [blame] | 414 | base::Unretained(this), plugin_path, client)); |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 415 | } |
| 416 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 417 | void PluginServiceImpl::FinishOpenChannelToPlugin( |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 418 | const FilePath& plugin_path, |
[email protected] | 46b69e4 | 2010-11-02 12:26:39 | [diff] [blame] | 419 | PluginProcessHost::Client* client) { |
[email protected] | f8b3ef8 | 2010-10-11 02:45:52 | [diff] [blame] | 420 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
[email protected] | 20a793e | 2010-10-12 06:50:08 | [diff] [blame] | 421 | |
[email protected] | 4befe759 | 2011-09-14 22:49:09 | [diff] [blame] | 422 | // Make sure it hasn't been canceled yet. |
| 423 | if (!ContainsKey(pending_plugin_clients_, client)) |
| 424 | return; |
| 425 | pending_plugin_clients_.erase(client); |
| 426 | |
[email protected] | a08ebea | 2011-02-13 17:50:20 | [diff] [blame] | 427 | PluginProcessHost* plugin_host = FindOrStartNpapiPluginProcess(plugin_path); |
[email protected] | 4befe759 | 2011-09-14 22:49:09 | [diff] [blame] | 428 | if (plugin_host) { |
| 429 | client->OnFoundPluginProcessHost(plugin_host); |
[email protected] | 46b69e4 | 2010-11-02 12:26:39 | [diff] [blame] | 430 | plugin_host->OpenChannelToPlugin(client); |
[email protected] | 4befe759 | 2011-09-14 22:49:09 | [diff] [blame] | 431 | } else { |
[email protected] | 46b69e4 | 2010-11-02 12:26:39 | [diff] [blame] | 432 | client->OnError(); |
[email protected] | 4befe759 | 2011-09-14 22:49:09 | [diff] [blame] | 433 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 434 | } |
| 435 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 436 | bool PluginServiceImpl::GetPluginInfoArray( |
[email protected] | 51b63f6 | 2011-10-05 18:55:42 | [diff] [blame] | 437 | const GURL& url, |
| 438 | const std::string& mime_type, |
| 439 | bool allow_wildcard, |
| 440 | std::vector<webkit::WebPluginInfo>* plugins, |
| 441 | std::vector<std::string>* actual_mime_types) { |
| 442 | bool use_stale = false; |
[email protected] | 3a5180ae | 2011-12-21 02:39:38 | [diff] [blame] | 443 | plugin_list_->GetPluginInfoArray(url, mime_type, allow_wildcard, |
| 444 | &use_stale, plugins, actual_mime_types); |
[email protected] | 51b63f6 | 2011-10-05 18:55:42 | [diff] [blame] | 445 | return use_stale; |
| 446 | } |
| 447 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 448 | bool PluginServiceImpl::GetPluginInfo(int render_process_id, |
| 449 | int render_view_id, |
[email protected] | 13075767 | 2012-10-24 00:26:19 | [diff] [blame] | 450 | ResourceContext* context, |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 451 | const GURL& url, |
| 452 | const GURL& page_url, |
| 453 | const std::string& mime_type, |
| 454 | bool allow_wildcard, |
| 455 | bool* is_stale, |
| 456 | webkit::WebPluginInfo* info, |
| 457 | std::string* actual_mime_type) { |
[email protected] | 91d9f3d | 2011-08-14 05:24:44 | [diff] [blame] | 458 | std::vector<webkit::WebPluginInfo> plugins; |
[email protected] | 6859807 | 2011-07-29 08:21:28 | [diff] [blame] | 459 | std::vector<std::string> mime_types; |
[email protected] | 88ca491 | 2011-10-12 14:00:43 | [diff] [blame] | 460 | bool stale = GetPluginInfoArray( |
| 461 | url, mime_type, allow_wildcard, &plugins, &mime_types); |
| 462 | if (is_stale) |
| 463 | *is_stale = stale; |
[email protected] | dfba876 | 2011-09-02 12:49:54 | [diff] [blame] | 464 | |
[email protected] | 6859807 | 2011-07-29 08:21:28 | [diff] [blame] | 465 | for (size_t i = 0; i < plugins.size(); ++i) { |
[email protected] | dfba876 | 2011-09-02 12:49:54 | [diff] [blame] | 466 | if (!filter_ || filter_->ShouldUsePlugin(render_process_id, |
| 467 | render_view_id, |
[email protected] | df02aca | 2012-02-09 21:03:20 | [diff] [blame] | 468 | context, |
[email protected] | dfba876 | 2011-09-02 12:49:54 | [diff] [blame] | 469 | url, |
| 470 | page_url, |
| 471 | &plugins[i])) { |
[email protected] | 6859807 | 2011-07-29 08:21:28 | [diff] [blame] | 472 | *info = plugins[i]; |
| 473 | if (actual_mime_type) |
| 474 | *actual_mime_type = mime_types[i]; |
| 475 | return true; |
| 476 | } |
| 477 | } |
| 478 | return false; |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 479 | } |
| 480 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 481 | bool PluginServiceImpl::GetPluginInfoByPath(const FilePath& plugin_path, |
| 482 | webkit::WebPluginInfo* info) { |
[email protected] | 88ca491 | 2011-10-12 14:00:43 | [diff] [blame] | 483 | std::vector<webkit::WebPluginInfo> plugins; |
[email protected] | 480c7cc | 2012-06-29 17:38:44 | [diff] [blame] | 484 | plugin_list_->GetPluginsNoRefresh(&plugins); |
[email protected] | 88ca491 | 2011-10-12 14:00:43 | [diff] [blame] | 485 | |
| 486 | for (std::vector<webkit::WebPluginInfo>::iterator it = plugins.begin(); |
| 487 | it != plugins.end(); |
| 488 | ++it) { |
| 489 | if (it->path == plugin_path) { |
| 490 | *info = *it; |
| 491 | return true; |
| 492 | } |
| 493 | } |
| 494 | |
| 495 | return false; |
| 496 | } |
| 497 | |
[email protected] | 8be4584 | 2012-04-13 19:49:29 | [diff] [blame] | 498 | string16 PluginServiceImpl::GetPluginDisplayNameByPath(const FilePath& path) { |
| 499 | string16 plugin_name = path.LossyDisplayName(); |
| 500 | webkit::WebPluginInfo info; |
| 501 | if (PluginService::GetInstance()->GetPluginInfoByPath(path, &info) && |
| 502 | !info.name.empty()) { |
| 503 | plugin_name = info.name; |
| 504 | #if defined(OS_MACOSX) |
| 505 | // Many plugins on the Mac have .plugin in the actual name, which looks |
| 506 | // terrible, so look for that and strip it off if present. |
| 507 | const std::string kPluginExtension = ".plugin"; |
| 508 | if (EndsWith(plugin_name, ASCIIToUTF16(kPluginExtension), true)) |
| 509 | plugin_name.erase(plugin_name.length() - kPluginExtension.length()); |
| 510 | #endif // OS_MACOSX |
| 511 | } |
| 512 | return plugin_name; |
| 513 | } |
| 514 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 515 | void PluginServiceImpl::GetPlugins(const GetPluginsCallback& callback) { |
[email protected] | 4912595 | 2011-09-27 18:05:15 | [diff] [blame] | 516 | scoped_refptr<base::MessageLoopProxy> target_loop( |
| 517 | MessageLoop::current()->message_loop_proxy()); |
| 518 | |
[email protected] | 1b51720 | 2012-12-19 17:16:10 | [diff] [blame] | 519 | if (LoadPluginListInProcess()) { |
| 520 | BrowserThread::GetBlockingPool()-> |
| 521 | PostSequencedWorkerTaskWithShutdownBehavior( |
| 522 | plugin_list_token_, |
| 523 | FROM_HERE, |
| 524 | base::Bind(&PluginServiceImpl::GetPluginsInternal, |
| 525 | base::Unretained(this), |
| 526 | target_loop, callback), |
| 527 | base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); |
| 528 | return; |
| 529 | } |
| 530 | #if defined(OS_POSIX) |
[email protected] | 4912595 | 2011-09-27 18:05:15 | [diff] [blame] | 531 | std::vector<webkit::WebPluginInfo> cached_plugins; |
[email protected] | 480c7cc | 2012-06-29 17:38:44 | [diff] [blame] | 532 | if (plugin_list_->GetPluginsNoRefresh(&cached_plugins)) { |
[email protected] | 4912595 | 2011-09-27 18:05:15 | [diff] [blame] | 533 | // Can't assume the caller is reentrant. |
| 534 | target_loop->PostTask(FROM_HERE, |
[email protected] | 00b2543 | 2012-04-07 04:21:37 | [diff] [blame] | 535 | base::Bind(callback, cached_plugins)); |
[email protected] | 4912595 | 2011-09-27 18:05:15 | [diff] [blame] | 536 | } else { |
[email protected] | 4bb85b9 | 2011-11-05 02:53:29 | [diff] [blame] | 537 | // If we switch back to loading plugins in process, then we need to make |
| 538 | // sure g_thread_init() gets called since plugins may call glib at load. |
[email protected] | d4af1e7 | 2011-10-21 17:45:43 | [diff] [blame] | 539 | if (!plugin_loader_.get()) |
| 540 | plugin_loader_ = new PluginLoaderPosix; |
[email protected] | 4912595 | 2011-09-27 18:05:15 | [diff] [blame] | 541 | BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
[email protected] | d4af1e7 | 2011-10-21 17:45:43 | [diff] [blame] | 542 | base::Bind(&PluginLoaderPosix::LoadPlugins, plugin_loader_, |
| 543 | target_loop, callback)); |
[email protected] | 4912595 | 2011-09-27 18:05:15 | [diff] [blame] | 544 | } |
[email protected] | a33fa9d | 2012-05-16 14:47:49 | [diff] [blame] | 545 | #else |
[email protected] | 1b51720 | 2012-12-19 17:16:10 | [diff] [blame] | 546 | NOTREACHED(); |
[email protected] | 4912595 | 2011-09-27 18:05:15 | [diff] [blame] | 547 | #endif |
[email protected] | d33e7cc | 2011-09-23 01:43:56 | [diff] [blame] | 548 | } |
| 549 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 550 | void PluginServiceImpl::GetPluginsInternal( |
[email protected] | d33e7cc | 2011-09-23 01:43:56 | [diff] [blame] | 551 | base::MessageLoopProxy* target_loop, |
| 552 | const PluginService::GetPluginsCallback& callback) { |
[email protected] | a33fa9d | 2012-05-16 14:47:49 | [diff] [blame] | 553 | DCHECK(BrowserThread::GetBlockingPool()->IsRunningSequenceOnCurrentThread( |
| 554 | plugin_list_token_)); |
[email protected] | d33e7cc | 2011-09-23 01:43:56 | [diff] [blame] | 555 | |
| 556 | std::vector<webkit::WebPluginInfo> plugins; |
[email protected] | 3a5180ae | 2011-12-21 02:39:38 | [diff] [blame] | 557 | plugin_list_->GetPlugins(&plugins); |
[email protected] | d33e7cc | 2011-09-23 01:43:56 | [diff] [blame] | 558 | |
| 559 | target_loop->PostTask(FROM_HERE, |
[email protected] | 00b2543 | 2012-04-07 04:21:37 | [diff] [blame] | 560 | base::Bind(callback, plugins)); |
[email protected] | dfba876 | 2011-09-02 12:49:54 | [diff] [blame] | 561 | } |
| 562 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 563 | void PluginServiceImpl::OnWaitableEventSignaled( |
[email protected] | 58052263 | 2009-08-17 21:55:55 | [diff] [blame] | 564 | base::WaitableEvent* waitable_event) { |
[email protected] | b547fd4 | 2009-04-23 23:16:27 | [diff] [blame] | 565 | #if defined(OS_WIN) |
| 566 | if (waitable_event == hkcu_event_.get()) { |
| 567 | hkcu_key_.StartWatching(); |
| 568 | } else { |
| 569 | hklm_key_.StartWatching(); |
| 570 | } |
| 571 | |
[email protected] | 3a5180ae | 2011-12-21 02:39:38 | [diff] [blame] | 572 | plugin_list_->RefreshPlugins(); |
[email protected] | 45a22e6 | 2011-10-12 09:48:02 | [diff] [blame] | 573 | PurgePluginListCache(NULL, false); |
[email protected] | 634d23d | 2011-01-19 10:38:19 | [diff] [blame] | 574 | #else |
| 575 | // This event should only get signaled on a Windows machine. |
| 576 | NOTREACHED(); |
[email protected] | 9de09f8 | 2009-08-17 20:13:53 | [diff] [blame] | 577 | #endif // defined(OS_WIN) |
[email protected] | b547fd4 | 2009-04-23 23:16:27 | [diff] [blame] | 578 | } |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 579 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 580 | void PluginServiceImpl::RegisterPepperPlugins() { |
[email protected] | 84396dbc | 2011-04-14 06:33:42 | [diff] [blame] | 581 | // TODO(abarth): It seems like the PepperPluginRegistry should do this work. |
[email protected] | a08ebea | 2011-02-13 17:50:20 | [diff] [blame] | 582 | PepperPluginRegistry::ComputeList(&ppapi_plugins_); |
| 583 | for (size_t i = 0; i < ppapi_plugins_.size(); ++i) { |
[email protected] | c6f3dea | 2012-01-14 02:23:11 | [diff] [blame] | 584 | RegisterInternalPlugin(ppapi_plugins_[i].ToWebPluginInfo(), true); |
[email protected] | 4e0616e | 2010-05-28 14:55:53 | [diff] [blame] | 585 | } |
| 586 | } |
[email protected] | 634d23d | 2011-01-19 10:38:19 | [diff] [blame] | 587 | |
[email protected] | eb415bf0e | 2011-04-14 02:45:42 | [diff] [blame] | 588 | // There should generally be very few plugins so a brute-force search is fine. |
[email protected] | 13075767 | 2012-10-24 00:26:19 | [diff] [blame] | 589 | PepperPluginInfo* PluginServiceImpl::GetRegisteredPpapiPluginInfo( |
[email protected] | eb415bf0e | 2011-04-14 02:45:42 | [diff] [blame] | 590 | const FilePath& plugin_path) { |
[email protected] | 13075767 | 2012-10-24 00:26:19 | [diff] [blame] | 591 | PepperPluginInfo* info = NULL; |
[email protected] | eb415bf0e | 2011-04-14 02:45:42 | [diff] [blame] | 592 | for (size_t i = 0; i < ppapi_plugins_.size(); i++) { |
[email protected] | 6b14feb | 2011-08-16 11:22:56 | [diff] [blame] | 593 | if (ppapi_plugins_[i].path == plugin_path) { |
| 594 | info = &ppapi_plugins_[i]; |
| 595 | break; |
| 596 | } |
[email protected] | eb415bf0e | 2011-04-14 02:45:42 | [diff] [blame] | 597 | } |
[email protected] | 07611759 | 2011-08-17 03:16:41 | [diff] [blame] | 598 | if (info) |
| 599 | return info; |
| 600 | // We did not find the plugin in our list. But wait! the plugin can also |
| 601 | // be a latecomer, as it happens with pepper flash. This information |
| 602 | // can be obtained from the PluginList singleton and we can use it to |
| 603 | // construct it and add it to the list. This same deal needs to be done |
| 604 | // in the renderer side in PepperPluginRegistry. |
| 605 | webkit::WebPluginInfo webplugin_info; |
[email protected] | 88ca491 | 2011-10-12 14:00:43 | [diff] [blame] | 606 | if (!GetPluginInfoByPath(plugin_path, &webplugin_info)) |
[email protected] | 07611759 | 2011-08-17 03:16:41 | [diff] [blame] | 607 | return NULL; |
[email protected] | 13075767 | 2012-10-24 00:26:19 | [diff] [blame] | 608 | PepperPluginInfo new_pepper_info; |
[email protected] | 07611759 | 2011-08-17 03:16:41 | [diff] [blame] | 609 | if (!MakePepperPluginInfo(webplugin_info, &new_pepper_info)) |
| 610 | return NULL; |
| 611 | ppapi_plugins_.push_back(new_pepper_info); |
| 612 | return &ppapi_plugins_[ppapi_plugins_.size() - 1]; |
[email protected] | eb415bf0e | 2011-04-14 02:45:42 | [diff] [blame] | 613 | } |
| 614 | |
[email protected] | 52348b2 | 2012-11-07 10:19:34 | [diff] [blame] | 615 | #if defined(OS_POSIX) && !defined(OS_OPENBSD) && !defined(OS_ANDROID) |
[email protected] | 634d23d | 2011-01-19 10:38:19 | [diff] [blame] | 616 | // static |
[email protected] | 07b71c8 | 2013-01-08 19:07:31 | [diff] [blame] | 617 | void PluginServiceImpl::RegisterFilePathWatcher(FilePathWatcher* watcher, |
| 618 | const FilePath& path) { |
| 619 | bool result = watcher->Watch(path, false, |
| 620 | base::Bind(&NotifyPluginDirChanged)); |
[email protected] | 634d23d | 2011-01-19 10:38:19 | [diff] [blame] | 621 | DCHECK(result); |
| 622 | } |
| 623 | #endif |
[email protected] | f520b5b | 2011-11-08 02:42:14 | [diff] [blame] | 624 | |
[email protected] | 13075767 | 2012-10-24 00:26:19 | [diff] [blame] | 625 | void PluginServiceImpl::SetFilter(PluginServiceFilter* filter) { |
[email protected] | 3a5180ae | 2011-12-21 02:39:38 | [diff] [blame] | 626 | filter_ = filter; |
| 627 | } |
| 628 | |
[email protected] | 13075767 | 2012-10-24 00:26:19 | [diff] [blame] | 629 | PluginServiceFilter* PluginServiceImpl::GetFilter() { |
[email protected] | 3a5180ae | 2011-12-21 02:39:38 | [diff] [blame] | 630 | return filter_; |
| 631 | } |
| 632 | |
[email protected] | b6a2f8de | 2012-01-31 17:28:49 | [diff] [blame] | 633 | void PluginServiceImpl::ForcePluginShutdown(const FilePath& plugin_path) { |
| 634 | if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { |
| 635 | BrowserThread::PostTask( |
| 636 | BrowserThread::IO, FROM_HERE, |
| 637 | base::Bind(&PluginServiceImpl::ForcePluginShutdown, |
| 638 | base::Unretained(this), plugin_path)); |
| 639 | return; |
| 640 | } |
| 641 | |
| 642 | PluginProcessHost* plugin = FindNpapiPluginProcess(plugin_path); |
| 643 | if (plugin) |
| 644 | plugin->ForceShutdown(); |
| 645 | } |
| 646 | |
[email protected] | 47214d88 | 2012-02-29 06:28:48 | [diff] [blame] | 647 | static const unsigned int kMaxCrashesPerInterval = 3; |
| 648 | static const unsigned int kCrashesInterval = 120; |
| 649 | |
| 650 | void PluginServiceImpl::RegisterPluginCrash(const FilePath& path) { |
| 651 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 652 | std::map<FilePath, std::vector<base::Time> >::iterator i = |
| 653 | crash_times_.find(path); |
| 654 | if (i == crash_times_.end()) { |
| 655 | crash_times_[path] = std::vector<base::Time>(); |
| 656 | i = crash_times_.find(path); |
| 657 | } |
| 658 | if (i->second.size() == kMaxCrashesPerInterval) { |
| 659 | i->second.erase(i->second.begin()); |
| 660 | } |
| 661 | base::Time time = base::Time::Now(); |
| 662 | i->second.push_back(time); |
| 663 | } |
| 664 | |
| 665 | bool PluginServiceImpl::IsPluginUnstable(const FilePath& path) { |
| 666 | DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 667 | std::map<FilePath, std::vector<base::Time> >::const_iterator i = |
| 668 | crash_times_.find(path); |
| 669 | if (i == crash_times_.end()) { |
| 670 | return false; |
| 671 | } |
| 672 | if (i->second.size() != kMaxCrashesPerInterval) { |
| 673 | return false; |
| 674 | } |
| 675 | base::TimeDelta delta = base::Time::Now() - i->second[0]; |
| 676 | if (delta.InSeconds() <= kCrashesInterval) { |
| 677 | return true; |
| 678 | } |
| 679 | return false; |
| 680 | } |
| 681 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 682 | void PluginServiceImpl::RefreshPlugins() { |
[email protected] | 3a5180ae | 2011-12-21 02:39:38 | [diff] [blame] | 683 | plugin_list_->RefreshPlugins(); |
[email protected] | f520b5b | 2011-11-08 02:42:14 | [diff] [blame] | 684 | } |
| 685 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 686 | void PluginServiceImpl::AddExtraPluginPath(const FilePath& path) { |
[email protected] | 3a5180ae | 2011-12-21 02:39:38 | [diff] [blame] | 687 | plugin_list_->AddExtraPluginPath(path); |
[email protected] | f520b5b | 2011-11-08 02:42:14 | [diff] [blame] | 688 | } |
| 689 | |
[email protected] | c6f3dea | 2012-01-14 02:23:11 | [diff] [blame] | 690 | void PluginServiceImpl::AddExtraPluginDir(const FilePath& path) { |
| 691 | plugin_list_->AddExtraPluginDir(path); |
| 692 | } |
| 693 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 694 | void PluginServiceImpl::RemoveExtraPluginPath(const FilePath& path) { |
[email protected] | 3a5180ae | 2011-12-21 02:39:38 | [diff] [blame] | 695 | plugin_list_->RemoveExtraPluginPath(path); |
[email protected] | f520b5b | 2011-11-08 02:42:14 | [diff] [blame] | 696 | } |
| 697 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 698 | void PluginServiceImpl::UnregisterInternalPlugin(const FilePath& path) { |
[email protected] | 3a5180ae | 2011-12-21 02:39:38 | [diff] [blame] | 699 | plugin_list_->UnregisterInternalPlugin(path); |
[email protected] | f520b5b | 2011-11-08 02:42:14 | [diff] [blame] | 700 | } |
| 701 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 702 | void PluginServiceImpl::SetPluginListForTesting( |
[email protected] | ee06617 | 2011-11-10 23:20:05 | [diff] [blame] | 703 | webkit::npapi::PluginList* plugin_list) { |
| 704 | plugin_list_ = plugin_list; |
| 705 | } |
| 706 | |
[email protected] | 5904cb4 | 2012-09-24 15:05:20 | [diff] [blame] | 707 | #if defined(OS_MACOSX) |
| 708 | void PluginServiceImpl::AppActivated() { |
| 709 | BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
[email protected] | 07b71c8 | 2013-01-08 19:07:31 | [diff] [blame] | 710 | base::Bind(&NotifyPluginsOfActivation)); |
[email protected] | 5904cb4 | 2012-09-24 15:05:20 | [diff] [blame] | 711 | } |
| 712 | #endif |
| 713 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 714 | void PluginServiceImpl::RegisterInternalPlugin( |
[email protected] | c6f3dea | 2012-01-14 02:23:11 | [diff] [blame] | 715 | const webkit::WebPluginInfo& info, |
| 716 | bool add_at_beginning) { |
| 717 | plugin_list_->RegisterInternalPlugin(info, add_at_beginning); |
[email protected] | f520b5b | 2011-11-08 02:42:14 | [diff] [blame] | 718 | } |
| 719 | |
[email protected] | 57aece2 | 2012-10-10 22:10:27 | [diff] [blame] | 720 | void PluginServiceImpl::GetInternalPlugins( |
| 721 | std::vector<webkit::WebPluginInfo>* plugins) { |
| 722 | plugin_list_->GetInternalPlugins(plugins); |
| 723 | } |
| 724 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 725 | webkit::npapi::PluginList* PluginServiceImpl::GetPluginList() { |
[email protected] | 3a5180ae | 2011-12-21 02:39:38 | [diff] [blame] | 726 | return plugin_list_; |
[email protected] | f520b5b | 2011-11-08 02:42:14 | [diff] [blame] | 727 | } |
[email protected] | 13075767 | 2012-10-24 00:26:19 | [diff] [blame] | 728 | |
| 729 | } // namespace content |