[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 | |
avi | b734894 | 2015-12-25 20:57:10 | [diff] [blame^] | 7 | #include <stddef.h> |
| 8 | |
[email protected] | d33e7cc | 2011-09-23 01:43:56 | [diff] [blame] | 9 | #include "base/bind.h" |
[email protected] | d48f1e0c | 2009-02-12 20:57:54 | [diff] [blame] | 10 | #include "base/command_line.h" |
[email protected] | 7b3ee8b | 2011-04-01 18:48:19 | [diff] [blame] | 11 | #include "base/compiler_specific.h" |
[email protected] | 5799981 | 2013-02-24 05:40:52 | [diff] [blame] | 12 | #include "base/files/file_path.h" |
skyostil | 95082a6 | 2015-06-05 19:53:07 | [diff] [blame] | 13 | #include "base/location.h" |
[email protected] | fd8d8d6c | 2013-02-28 02:48:33 | [diff] [blame] | 14 | #include "base/metrics/histogram.h" |
skyostil | 95082a6 | 2015-06-05 19:53:07 | [diff] [blame] | 15 | #include "base/single_thread_task_runner.h" |
[email protected] | 348fbaac | 2013-06-11 06:31:51 | [diff] [blame] | 16 | #include "base/strings/string_util.h" |
[email protected] | 74ebfb1 | 2013-06-07 20:48:00 | [diff] [blame] | 17 | #include "base/strings/utf_string_conversions.h" |
[email protected] | 7f070d4 | 2011-03-09 20:25:32 | [diff] [blame] | 18 | #include "base/synchronization/waitable_event.h" |
[email protected] | 34b9963 | 2011-01-01 01:01:06 | [diff] [blame] | 19 | #include "base/threading/thread.h" |
avi | b734894 | 2015-12-25 20:57:10 | [diff] [blame^] | 20 | #include "build/build_config.h" |
[email protected] | a01efd2 | 2011-03-01 00:38:32 | [diff] [blame] | 21 | #include "content/browser/ppapi_plugin_process_host.h" |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 22 | #include "content/browser/renderer_host/render_process_host_impl.h" |
[email protected] | b3c41c0b | 2012-03-06 15:48:32 | [diff] [blame] | 23 | #include "content/browser/renderer_host/render_view_host_impl.h" |
wfh | 1a90e03 | 2015-04-14 17:10:17 | [diff] [blame] | 24 | #include "content/common/content_switches_internal.h" |
[email protected] | dac6a5a | 2013-07-25 05:06:48 | [diff] [blame] | 25 | #include "content/common/pepper_plugin_list.h" |
[email protected] | 29e2fb4 | 2013-07-19 01:13:47 | [diff] [blame] | 26 | #include "content/common/plugin_list.h" |
[email protected] | 38b59290 | 2011-04-16 02:08:42 | [diff] [blame] | 27 | #include "content/common/view_messages.h" |
[email protected] | c38831a1 | 2011-10-28 12:44:49 | [diff] [blame] | 28 | #include "content/public/browser/browser_thread.h" |
[email protected] | 87f3c08 | 2011-10-19 18:07:44 | [diff] [blame] | 29 | #include "content/public/browser/content_browser_client.h" |
[email protected] | 31f376c | 2012-03-13 16:43:09 | [diff] [blame] | 30 | #include "content/public/browser/plugin_service_filter.h" |
[email protected] | ce96786 | 2012-02-09 22:47:05 | [diff] [blame] | 31 | #include "content/public/browser/resource_context.h" |
[email protected] | 7327029 | 2013-08-09 03:48:07 | [diff] [blame] | 32 | #include "content/public/common/content_constants.h" |
[email protected] | c08950d2 | 2011-10-13 22:20:29 | [diff] [blame] | 33 | #include "content/public/common/content_switches.h" |
[email protected] | bd5d6cf | 2011-12-01 00:39:12 | [diff] [blame] | 34 | #include "content/public/common/process_type.h" |
[email protected] | d7bd3e5 | 2013-07-21 04:29:20 | [diff] [blame] | 35 | #include "content/public/common/webplugininfo.h" |
[email protected] | 191eb3f7 | 2010-12-21 06:27:50 | [diff] [blame] | 36 | |
[email protected] | 3b91edbe | 2012-09-27 22:49:23 | [diff] [blame] | 37 | #if defined(OS_WIN) |
[email protected] | 29e2fb4 | 2013-07-19 01:13:47 | [diff] [blame] | 38 | #include "content/common/plugin_constants_win.h" |
[email protected] | bde885b | 2013-09-12 20:55:53 | [diff] [blame] | 39 | #include "ui/gfx/win/hwnd_util.h" |
[email protected] | 3b91edbe | 2012-09-27 22:49:23 | [diff] [blame] | 40 | #endif |
| 41 | |
| 42 | #if defined(OS_POSIX) |
| 43 | #include "content/browser/plugin_loader_posix.h" |
| 44 | #endif |
| 45 | |
[email protected] | 52348b2 | 2012-11-07 10:19:34 | [diff] [blame] | 46 | #if defined(OS_POSIX) && !defined(OS_OPENBSD) && !defined(OS_ANDROID) |
[email protected] | 6665571f | 2013-01-15 07:59:52 | [diff] [blame] | 47 | using ::base::FilePathWatcher; |
[email protected] | 493c800 | 2011-04-14 16:56:01 | [diff] [blame] | 48 | #endif |
| 49 | |
[email protected] | 13075767 | 2012-10-24 00:26:19 | [diff] [blame] | 50 | namespace content { |
[email protected] | d33e7cc | 2011-09-23 01:43:56 | [diff] [blame] | 51 | namespace { |
| 52 | |
[email protected] | fd8d8d6c | 2013-02-28 02:48:33 | [diff] [blame] | 53 | // This enum is used to collect Flash usage data. |
| 54 | enum FlashUsage { |
| 55 | // Number of browser processes that have started at least one NPAPI Flash |
| 56 | // process during their lifetime. |
| 57 | START_NPAPI_FLASH_AT_LEAST_ONCE, |
| 58 | // Number of browser processes that have started at least one PPAPI Flash |
| 59 | // process during their lifetime. |
| 60 | START_PPAPI_FLASH_AT_LEAST_ONCE, |
| 61 | // Total number of browser processes. |
| 62 | TOTAL_BROWSER_PROCESSES, |
| 63 | FLASH_USAGE_ENUM_COUNT |
| 64 | }; |
| 65 | |
wfh | 0539f2f5 | 2015-01-21 14:36:46 | [diff] [blame] | 66 | enum NPAPIPluginStatus { |
| 67 | // Platform does not support NPAPI. |
| 68 | NPAPI_STATUS_UNSUPPORTED, |
| 69 | // Platform supports NPAPI and NPAPI is disabled. |
| 70 | NPAPI_STATUS_DISABLED, |
| 71 | // Platform supports NPAPI and NPAPI is enabled. |
| 72 | NPAPI_STATUS_ENABLED, |
| 73 | NPAPI_STATUS_ENUM_COUNT |
| 74 | }; |
| 75 | |
[email protected] | 1b51720 | 2012-12-19 17:16:10 | [diff] [blame] | 76 | bool LoadPluginListInProcess() { |
| 77 | #if defined(OS_WIN) |
| 78 | return true; |
| 79 | #else |
| 80 | // If on POSIX, we don't want to load the list of NPAPI plugins in-process as |
| 81 | // that causes instability. |
[email protected] | 6d057a0c | 2013-07-09 21:12:07 | [diff] [blame] | 82 | |
| 83 | // Can't load the plugins on the utility thread when in single process mode |
[email protected] | 1021245 | 2013-07-16 20:10:55 | [diff] [blame] | 84 | // since that requires GTK which can only be used on the main thread. |
[email protected] | 6d057a0c | 2013-07-09 21:12:07 | [diff] [blame] | 85 | if (RenderProcessHost::run_renderer_in_process()) |
| 86 | return true; |
| 87 | |
[email protected] | 9a60ccb | 2013-07-19 22:23:36 | [diff] [blame] | 88 | return !PluginService::GetInstance()->NPAPIPluginsSupported(); |
[email protected] | 1b51720 | 2012-12-19 17:16:10 | [diff] [blame] | 89 | #endif |
| 90 | } |
| 91 | |
[email protected] | 4912595 | 2011-09-27 18:05:15 | [diff] [blame] | 92 | // Callback set on the PluginList to assert that plugin loading happens on the |
| 93 | // correct thread. |
[email protected] | 1b51720 | 2012-12-19 17:16:10 | [diff] [blame] | 94 | void WillLoadPluginsCallback( |
[email protected] | a33fa9d | 2012-05-16 14:47:49 | [diff] [blame] | 95 | base::SequencedWorkerPool::SequenceToken token) { |
[email protected] | 1b51720 | 2012-12-19 17:16:10 | [diff] [blame] | 96 | if (LoadPluginListInProcess()) { |
| 97 | CHECK(BrowserThread::GetBlockingPool()->IsRunningSequenceOnCurrentThread( |
| 98 | token)); |
| 99 | } else { |
| 100 | CHECK(false) << "Plugin loading should happen out-of-process."; |
| 101 | } |
[email protected] | a7991225 | 2012-05-16 11:52:19 | [diff] [blame] | 102 | } |
[email protected] | d33e7cc | 2011-09-23 01:43:56 | [diff] [blame] | 103 | |
[email protected] | a96ec6a | 2009-11-04 17:27:08 | [diff] [blame] | 104 | #if defined(OS_MACOSX) |
[email protected] | 07b71c8 | 2013-01-08 19:07:31 | [diff] [blame] | 105 | void NotifyPluginsOfActivation() { |
mostynb | 4c27d04 | 2015-03-18 21:47:47 | [diff] [blame] | 106 | DCHECK_CURRENTLY_ON(BrowserThread::IO); |
[email protected] | a96ec6a | 2009-11-04 17:27:08 | [diff] [blame] | 107 | |
[email protected] | 4967f79 | 2012-01-20 22:14:40 | [diff] [blame] | 108 | for (PluginProcessHostIterator iter; !iter.Done(); ++iter) |
| 109 | iter->OnAppActivation(); |
[email protected] | a96ec6a | 2009-11-04 17:27:08 | [diff] [blame] | 110 | } |
[email protected] | 3b48dbc | 2012-01-06 16:34:17 | [diff] [blame] | 111 | #endif |
[email protected] | 45a22e6 | 2011-10-12 09:48:02 | [diff] [blame] | 112 | |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 113 | #if defined(OS_POSIX) |
| 114 | #if !defined(OS_OPENBSD) && !defined(OS_ANDROID) |
[email protected] | 2dec8ec | 2013-02-07 19:20:34 | [diff] [blame] | 115 | void NotifyPluginDirChanged(const base::FilePath& path, bool error) { |
[email protected] | 07b71c8 | 2013-01-08 19:07:31 | [diff] [blame] | 116 | if (error) { |
[email protected] | 634d23d | 2011-01-19 10:38:19 | [diff] [blame] | 117 | // TODO(pastarmovj): Add some sensible error handling. Maybe silently |
| 118 | // stopping the watcher would be enough. Or possibly restart it. |
| 119 | NOTREACHED(); |
[email protected] | 07b71c8 | 2013-01-08 19:07:31 | [diff] [blame] | 120 | return; |
[email protected] | 634d23d | 2011-01-19 10:38:19 | [diff] [blame] | 121 | } |
[email protected] | 07b71c8 | 2013-01-08 19:07:31 | [diff] [blame] | 122 | VLOG(1) << "Watched path changed: " << path.value(); |
| 123 | // Make the plugin list update itself |
[email protected] | 29e2fb4 | 2013-07-19 01:13:47 | [diff] [blame] | 124 | PluginList::Singleton()->RefreshPlugins(); |
[email protected] | 07b71c8 | 2013-01-08 19:07:31 | [diff] [blame] | 125 | BrowserThread::PostTask( |
| 126 | BrowserThread::UI, FROM_HERE, |
| 127 | base::Bind(&PluginService::PurgePluginListCache, |
| 128 | static_cast<BrowserContext*>(NULL), false)); |
| 129 | } |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 130 | #endif // !defined(OS_OPENBSD) && !defined(OS_ANDROID) |
[email protected] | 634d23d | 2011-01-19 10:38:19 | [diff] [blame] | 131 | |
skyostil | 95082a6 | 2015-06-05 19:53:07 | [diff] [blame] | 132 | void ForwardCallback(base::SingleThreadTaskRunner* target_task_runner, |
[email protected] | aa7f880 | 2014-01-27 16:56:32 | [diff] [blame] | 133 | const PluginService::GetPluginsCallback& callback, |
| 134 | const std::vector<WebPluginInfo>& plugins) { |
skyostil | 95082a6 | 2015-06-05 19:53:07 | [diff] [blame] | 135 | target_task_runner->PostTask(FROM_HERE, base::Bind(callback, plugins)); |
[email protected] | aa7f880 | 2014-01-27 16:56:32 | [diff] [blame] | 136 | } |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 137 | #endif // defined(OS_POSIX) |
[email protected] | aa7f880 | 2014-01-27 16:56:32 | [diff] [blame] | 138 | |
[email protected] | 07b71c8 | 2013-01-08 19:07:31 | [diff] [blame] | 139 | } // namespace |
| 140 | |
[email protected] | 3a5180ae | 2011-12-21 02:39:38 | [diff] [blame] | 141 | // static |
| 142 | PluginService* PluginService::GetInstance() { |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 143 | return PluginServiceImpl::GetInstance(); |
[email protected] | 3a5180ae | 2011-12-21 02:39:38 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | void PluginService::PurgePluginListCache(BrowserContext* browser_context, |
| 147 | bool reload_pages) { |
| 148 | for (RenderProcessHost::iterator it = RenderProcessHost::AllHostsIterator(); |
| 149 | !it.IsAtEnd(); it.Advance()) { |
| 150 | RenderProcessHost* host = it.GetCurrentValue(); |
| 151 | if (!browser_context || host->GetBrowserContext() == browser_context) |
| 152 | host->Send(new ViewMsg_PurgePluginListCache(reload_pages)); |
| 153 | } |
| 154 | } |
| 155 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 156 | // static |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 157 | PluginServiceImpl* PluginServiceImpl::GetInstance() { |
olli.raula | 36aa8be | 2015-09-10 11:14:22 | [diff] [blame] | 158 | return base::Singleton<PluginServiceImpl>::get(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 159 | } |
| 160 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 161 | PluginServiceImpl::PluginServiceImpl() |
wfh | 0539f2f5 | 2015-01-21 14:36:46 | [diff] [blame] | 162 | : npapi_plugins_enabled_(false), filter_(NULL) { |
[email protected] | fd8d8d6c | 2013-02-28 02:48:33 | [diff] [blame] | 163 | // Collect the total number of browser processes (which create |
| 164 | // PluginServiceImpl objects, to be precise). The number is used to normalize |
| 165 | // the number of processes which start at least one NPAPI/PPAPI Flash process. |
| 166 | static bool counted = false; |
| 167 | if (!counted) { |
| 168 | counted = true; |
| 169 | UMA_HISTOGRAM_ENUMERATION("Plugin.FlashUsage", TOTAL_BROWSER_PROCESSES, |
| 170 | FLASH_USAGE_ENUM_COUNT); |
| 171 | } |
[email protected] | ee06617 | 2011-11-10 23:20:05 | [diff] [blame] | 172 | } |
| 173 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 174 | PluginServiceImpl::~PluginServiceImpl() { |
[email protected] | ee06617 | 2011-11-10 23:20:05 | [diff] [blame] | 175 | // Make sure no plugin channel requests have been leaked. |
| 176 | DCHECK(pending_plugin_clients_.empty()); |
| 177 | } |
| 178 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 179 | void PluginServiceImpl::Init() { |
[email protected] | a33fa9d | 2012-05-16 14:47:49 | [diff] [blame] | 180 | plugin_list_token_ = BrowserThread::GetBlockingPool()->GetSequenceToken(); |
[email protected] | 29e2fb4 | 2013-07-19 01:13:47 | [diff] [blame] | 181 | PluginList::Singleton()->set_will_load_plugins_callback( |
[email protected] | 1b51720 | 2012-12-19 17:16:10 | [diff] [blame] | 182 | base::Bind(&WillLoadPluginsCallback, plugin_list_token_)); |
[email protected] | 4912595 | 2011-09-27 18:05:15 | [diff] [blame] | 183 | |
[email protected] | 4e0616e | 2010-05-28 14:55:53 | [diff] [blame] | 184 | RegisterPepperPlugins(); |
| 185 | |
[email protected] | 9a1c426 | 2010-06-29 21:50:27 | [diff] [blame] | 186 | // Load any specified on the command line as well. |
[email protected] | 47927870 | 2014-08-11 20:32:09 | [diff] [blame] | 187 | const base::CommandLine* command_line = |
| 188 | base::CommandLine::ForCurrentProcess(); |
[email protected] | 2dec8ec | 2013-02-07 19:20:34 | [diff] [blame] | 189 | base::FilePath path = |
| 190 | command_line->GetSwitchValuePath(switches::kLoadPlugin); |
[email protected] | 7bf795d9 | 2010-05-22 00:14:28 | [diff] [blame] | 191 | if (!path.empty()) |
[email protected] | f520b5b | 2011-11-08 02:42:14 | [diff] [blame] | 192 | AddExtraPluginPath(path); |
[email protected] | 9a1c426 | 2010-06-29 21:50:27 | [diff] [blame] | 193 | path = command_line->GetSwitchValuePath(switches::kExtraPluginDir); |
| 194 | if (!path.empty()) |
[email protected] | 29e2fb4 | 2013-07-19 01:13:47 | [diff] [blame] | 195 | PluginList::Singleton()->AddExtraPluginDir(path); |
[email protected] | e87ce86 | 2013-06-12 17:30:48 | [diff] [blame] | 196 | |
| 197 | if (command_line->HasSwitch(switches::kDisablePluginsDiscovery)) |
[email protected] | 29e2fb4 | 2013-07-19 01:13:47 | [diff] [blame] | 198 | PluginList::Singleton()->DisablePluginsDiscovery(); |
[email protected] | dfba876 | 2011-09-02 12:49:54 | [diff] [blame] | 199 | } |
| 200 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 201 | void PluginServiceImpl::StartWatchingPlugins() { |
[email protected] | 634d23d | 2011-01-19 10:38:19 | [diff] [blame] | 202 | // Start watching for changes in the plugin list. This means watching |
| 203 | // for changes in the Windows registry keys and on both Windows and POSIX |
| 204 | // watch for changes in the paths that are expected to contain plugins. |
[email protected] | b547fd4 | 2009-04-23 23:16:27 | [diff] [blame] | 205 | #if defined(OS_WIN) |
[email protected] | 86ec4f6e | 2011-04-20 16:21:19 | [diff] [blame] | 206 | if (hkcu_key_.Create(HKEY_CURRENT_USER, |
[email protected] | 29e2fb4 | 2013-07-19 01:13:47 | [diff] [blame] | 207 | kRegistryMozillaPlugins, |
[email protected] | 86ec4f6e | 2011-04-20 16:21:19 | [diff] [blame] | 208 | KEY_NOTIFY) == ERROR_SUCCESS) { |
rvargas | 6f315b8 | 2014-10-17 01:28:58 | [diff] [blame] | 209 | base::win::RegKey::ChangeCallback callback = |
| 210 | base::Bind(&PluginServiceImpl::OnKeyChanged, base::Unretained(this), |
| 211 | base::Unretained(&hkcu_key_)); |
| 212 | hkcu_key_.StartWatching(callback); |
[email protected] | b547fd4 | 2009-04-23 23:16:27 | [diff] [blame] | 213 | } |
[email protected] | 86ec4f6e | 2011-04-20 16:21:19 | [diff] [blame] | 214 | if (hklm_key_.Create(HKEY_LOCAL_MACHINE, |
[email protected] | 29e2fb4 | 2013-07-19 01:13:47 | [diff] [blame] | 215 | kRegistryMozillaPlugins, |
[email protected] | 86ec4f6e | 2011-04-20 16:21:19 | [diff] [blame] | 216 | KEY_NOTIFY) == ERROR_SUCCESS) { |
rvargas | 6f315b8 | 2014-10-17 01:28:58 | [diff] [blame] | 217 | base::win::RegKey::ChangeCallback callback = |
| 218 | base::Bind(&PluginServiceImpl::OnKeyChanged, base::Unretained(this), |
rvargas | b805615 | 2014-11-08 01:44:28 | [diff] [blame] | 219 | base::Unretained(&hklm_key_)); |
rvargas | 6f315b8 | 2014-10-17 01:28:58 | [diff] [blame] | 220 | hklm_key_.StartWatching(callback); |
[email protected] | b547fd4 | 2009-04-23 23:16:27 | [diff] [blame] | 221 | } |
[email protected] | a33fa9d | 2012-05-16 14:47:49 | [diff] [blame] | 222 | #endif |
[email protected] | 52348b2 | 2012-11-07 10:19:34 | [diff] [blame] | 223 | #if defined(OS_POSIX) && !defined(OS_OPENBSD) && !defined(OS_ANDROID) |
[email protected] | 634d23d | 2011-01-19 10:38:19 | [diff] [blame] | 224 | // On ChromeOS the user can't install plugins anyway and on Windows all |
| 225 | // important plugins register themselves in the registry so no need to do that. |
[email protected] | 07b71c8 | 2013-01-08 19:07:31 | [diff] [blame] | 226 | |
[email protected] | 634d23d | 2011-01-19 10:38:19 | [diff] [blame] | 227 | // Get the list of all paths for registering the FilePathWatchers |
| 228 | // that will track and if needed reload the list of plugins on runtime. |
[email protected] | 2dec8ec | 2013-02-07 19:20:34 | [diff] [blame] | 229 | std::vector<base::FilePath> plugin_dirs; |
[email protected] | 29e2fb4 | 2013-07-19 01:13:47 | [diff] [blame] | 230 | PluginList::Singleton()->GetPluginDirectories(&plugin_dirs); |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 231 | |
[email protected] | 634d23d | 2011-01-19 10:38:19 | [diff] [blame] | 232 | for (size_t i = 0; i < plugin_dirs.size(); ++i) { |
[email protected] | 634d23d | 2011-01-19 10:38:19 | [diff] [blame] | 233 | // FilePathWatcher can not handle non-absolute paths under windows. |
| 234 | // We don't watch for file changes in windows now but if this should ever |
| 235 | // be extended to Windows these lines might save some time of debugging. |
| 236 | #if defined(OS_WIN) |
| 237 | if (!plugin_dirs[i].IsAbsolute()) |
| 238 | continue; |
| 239 | #endif |
[email protected] | 493c800 | 2011-04-14 16:56:01 | [diff] [blame] | 240 | FilePathWatcher* watcher = new FilePathWatcher(); |
[email protected] | 634d23d | 2011-01-19 10:38:19 | [diff] [blame] | 241 | VLOG(1) << "Watching for changes in: " << plugin_dirs[i].value(); |
| 242 | BrowserThread::PostTask( |
| 243 | BrowserThread::FILE, FROM_HERE, |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 244 | base::Bind(&PluginServiceImpl::RegisterFilePathWatcher, watcher, |
[email protected] | 07b71c8 | 2013-01-08 19:07:31 | [diff] [blame] | 245 | plugin_dirs[i])); |
[email protected] | 634d23d | 2011-01-19 10:38:19 | [diff] [blame] | 246 | file_watchers_.push_back(watcher); |
| 247 | } |
| 248 | #endif |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 249 | } |
| 250 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 251 | PluginProcessHost* PluginServiceImpl::FindNpapiPluginProcess( |
[email protected] | 2dec8ec | 2013-02-07 19:20:34 | [diff] [blame] | 252 | const base::FilePath& plugin_path) { |
[email protected] | 4967f79 | 2012-01-20 22:14:40 | [diff] [blame] | 253 | for (PluginProcessHostIterator iter; !iter.Done(); ++iter) { |
| 254 | if (iter->info().path == plugin_path) |
| 255 | return *iter; |
[email protected] | a436d92 | 2009-02-13 23:16:42 | [diff] [blame] | 256 | } |
| 257 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 258 | return NULL; |
| 259 | } |
| 260 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 261 | PpapiPluginProcessHost* PluginServiceImpl::FindPpapiPluginProcess( |
[email protected] | 2dec8ec | 2013-02-07 19:20:34 | [diff] [blame] | 262 | const base::FilePath& plugin_path, |
| 263 | const base::FilePath& profile_data_directory) { |
[email protected] | 4967f79 | 2012-01-20 22:14:40 | [diff] [blame] | 264 | for (PpapiPluginProcessHostIterator iter; !iter.Done(); ++iter) { |
[email protected] | dd9a095 | 2012-05-31 20:11:31 | [diff] [blame] | 265 | if (iter->plugin_path() == plugin_path && |
| 266 | iter->profile_data_directory() == profile_data_directory) { |
[email protected] | 4967f79 | 2012-01-20 22:14:40 | [diff] [blame] | 267 | return *iter; |
[email protected] | dd9a095 | 2012-05-31 20:11:31 | [diff] [blame] | 268 | } |
[email protected] | a08ebea | 2011-02-13 17:50:20 | [diff] [blame] | 269 | } |
[email protected] | a08ebea | 2011-02-13 17:50:20 | [diff] [blame] | 270 | return NULL; |
| 271 | } |
| 272 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 273 | PpapiPluginProcessHost* PluginServiceImpl::FindPpapiBrokerProcess( |
[email protected] | 2dec8ec | 2013-02-07 19:20:34 | [diff] [blame] | 274 | const base::FilePath& broker_path) { |
[email protected] | 4967f79 | 2012-01-20 22:14:40 | [diff] [blame] | 275 | for (PpapiBrokerProcessHostIterator iter; !iter.Done(); ++iter) { |
| 276 | if (iter->plugin_path() == broker_path) |
| 277 | return *iter; |
[email protected] | eb415bf0e | 2011-04-14 02:45:42 | [diff] [blame] | 278 | } |
| 279 | |
| 280 | return NULL; |
| 281 | } |
| 282 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 283 | PluginProcessHost* PluginServiceImpl::FindOrStartNpapiPluginProcess( |
[email protected] | 6be31d20 | 2013-02-01 18:20:54 | [diff] [blame] | 284 | int render_process_id, |
[email protected] | 2dec8ec | 2013-02-07 19:20:34 | [diff] [blame] | 285 | const base::FilePath& plugin_path) { |
mostynb | 4c27d04 | 2015-03-18 21:47:47 | [diff] [blame] | 286 | DCHECK_CURRENTLY_ON(BrowserThread::IO); |
[email protected] | a08ebea | 2011-02-13 17:50:20 | [diff] [blame] | 287 | |
[email protected] | 6be31d20 | 2013-02-01 18:20:54 | [diff] [blame] | 288 | if (filter_ && !filter_->CanLoadPlugin(render_process_id, plugin_path)) |
| 289 | return NULL; |
| 290 | |
[email protected] | a08ebea | 2011-02-13 17:50:20 | [diff] [blame] | 291 | PluginProcessHost* plugin_host = FindNpapiPluginProcess(plugin_path); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 292 | if (plugin_host) |
| 293 | return plugin_host; |
| 294 | |
[email protected] | d7bd3e5 | 2013-07-21 04:29:20 | [diff] [blame] | 295 | WebPluginInfo info; |
[email protected] | 88ca491 | 2011-10-12 14:00:43 | [diff] [blame] | 296 | if (!GetPluginInfoByPath(plugin_path, &info)) { |
[email protected] | a27a938 | 2009-02-11 23:55:10 | [diff] [blame] | 297 | return NULL; |
| 298 | } |
| 299 | |
[email protected] | fd8d8d6c | 2013-02-28 02:48:33 | [diff] [blame] | 300 | // Record when NPAPI Flash process is started for the first time. |
| 301 | static bool counted = false; |
[email protected] | 3295612 | 2013-12-25 07:29:24 | [diff] [blame] | 302 | if (!counted && base::UTF16ToUTF8(info.name) == kFlashPluginName) { |
[email protected] | fd8d8d6c | 2013-02-28 02:48:33 | [diff] [blame] | 303 | counted = true; |
| 304 | UMA_HISTOGRAM_ENUMERATION("Plugin.FlashUsage", |
| 305 | START_NPAPI_FLASH_AT_LEAST_ONCE, |
| 306 | FLASH_USAGE_ENUM_COUNT); |
| 307 | } |
[email protected] | 132bca8 | 2013-12-10 09:14:47 | [diff] [blame] | 308 | #if defined(OS_CHROMEOS) |
| 309 | // TODO(ihf): Move to an earlier place once crbug.com/314301 is fixed. For now |
| 310 | // we still want Plugin.FlashUsage recorded if we end up here. |
| 311 | LOG(WARNING) << "Refusing to start npapi plugin on ChromeOS."; |
| 312 | return NULL; |
| 313 | #endif |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 314 | // 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] | 315 | scoped_ptr<PluginProcessHost> new_host(new PluginProcessHost()); |
[email protected] | 9990736 | 2012-01-11 05:41:40 | [diff] [blame] | 316 | if (!new_host->Init(info)) { |
[email protected] | a08ebea | 2011-02-13 17:50:20 | [diff] [blame] | 317 | NOTREACHED(); // Init is not expected to fail. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 318 | return NULL; |
| 319 | } |
[email protected] | 8b8a554d | 2010-11-18 13:26:40 | [diff] [blame] | 320 | return new_host.release(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 321 | } |
| 322 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 323 | PpapiPluginProcessHost* PluginServiceImpl::FindOrStartPpapiPluginProcess( |
[email protected] | 6be31d20 | 2013-02-01 18:20:54 | [diff] [blame] | 324 | int render_process_id, |
[email protected] | 2dec8ec | 2013-02-07 19:20:34 | [diff] [blame] | 325 | const base::FilePath& plugin_path, |
[email protected] | 8522332e | 2013-08-28 19:42:59 | [diff] [blame] | 326 | const base::FilePath& profile_data_directory) { |
mostynb | 4c27d04 | 2015-03-18 21:47:47 | [diff] [blame] | 327 | DCHECK_CURRENTLY_ON(BrowserThread::IO); |
[email protected] | a08ebea | 2011-02-13 17:50:20 | [diff] [blame] | 328 | |
[email protected] | 132bca8 | 2013-12-10 09:14:47 | [diff] [blame] | 329 | if (filter_ && !filter_->CanLoadPlugin(render_process_id, plugin_path)) { |
| 330 | VLOG(1) << "Unable to load ppapi plugin: " << plugin_path.MaybeAsASCII(); |
[email protected] | 6be31d20 | 2013-02-01 18:20:54 | [diff] [blame] | 331 | return NULL; |
[email protected] | 132bca8 | 2013-12-10 09:14:47 | [diff] [blame] | 332 | } |
[email protected] | 6be31d20 | 2013-02-01 18:20:54 | [diff] [blame] | 333 | |
[email protected] | dd9a095 | 2012-05-31 20:11:31 | [diff] [blame] | 334 | PpapiPluginProcessHost* plugin_host = |
| 335 | FindPpapiPluginProcess(plugin_path, profile_data_directory); |
[email protected] | a08ebea | 2011-02-13 17:50:20 | [diff] [blame] | 336 | if (plugin_host) |
| 337 | return plugin_host; |
| 338 | |
[email protected] | eb415bf0e | 2011-04-14 02:45:42 | [diff] [blame] | 339 | // Validate that the plugin is actually registered. |
[email protected] | 13075767 | 2012-10-24 00:26:19 | [diff] [blame] | 340 | PepperPluginInfo* info = GetRegisteredPpapiPluginInfo(plugin_path); |
[email protected] | 132bca8 | 2013-12-10 09:14:47 | [diff] [blame] | 341 | if (!info) { |
| 342 | VLOG(1) << "Unable to find ppapi plugin registration for: " |
| 343 | << plugin_path.MaybeAsASCII(); |
[email protected] | a08ebea | 2011-02-13 17:50:20 | [diff] [blame] | 344 | return NULL; |
[email protected] | 132bca8 | 2013-12-10 09:14:47 | [diff] [blame] | 345 | } |
[email protected] | a08ebea | 2011-02-13 17:50:20 | [diff] [blame] | 346 | |
[email protected] | fd8d8d6c | 2013-02-28 02:48:33 | [diff] [blame] | 347 | // Record when PPAPI Flash process is started for the first time. |
| 348 | static bool counted = false; |
| 349 | if (!counted && info->name == kFlashPluginName) { |
| 350 | counted = true; |
| 351 | UMA_HISTOGRAM_ENUMERATION("Plugin.FlashUsage", |
| 352 | START_PPAPI_FLASH_AT_LEAST_ONCE, |
| 353 | FLASH_USAGE_ENUM_COUNT); |
| 354 | } |
| 355 | |
[email protected] | a08ebea | 2011-02-13 17:50:20 | [diff] [blame] | 356 | // This plugin isn't loaded by any plugin process, so create a new process. |
[email protected] | 132bca8 | 2013-12-10 09:14:47 | [diff] [blame] | 357 | plugin_host = PpapiPluginProcessHost::CreatePluginHost( |
[email protected] | 8522332e | 2013-08-28 19:42:59 | [diff] [blame] | 358 | *info, profile_data_directory); |
[email protected] | 132bca8 | 2013-12-10 09:14:47 | [diff] [blame] | 359 | if (!plugin_host) { |
| 360 | VLOG(1) << "Unable to create ppapi plugin process for: " |
| 361 | << plugin_path.MaybeAsASCII(); |
| 362 | } |
| 363 | |
| 364 | return plugin_host; |
[email protected] | a08ebea | 2011-02-13 17:50:20 | [diff] [blame] | 365 | } |
| 366 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 367 | PpapiPluginProcessHost* PluginServiceImpl::FindOrStartPpapiBrokerProcess( |
[email protected] | 6be31d20 | 2013-02-01 18:20:54 | [diff] [blame] | 368 | int render_process_id, |
[email protected] | 2dec8ec | 2013-02-07 19:20:34 | [diff] [blame] | 369 | const base::FilePath& plugin_path) { |
mostynb | 4c27d04 | 2015-03-18 21:47:47 | [diff] [blame] | 370 | DCHECK_CURRENTLY_ON(BrowserThread::IO); |
[email protected] | eb415bf0e | 2011-04-14 02:45:42 | [diff] [blame] | 371 | |
[email protected] | 6be31d20 | 2013-02-01 18:20:54 | [diff] [blame] | 372 | if (filter_ && !filter_->CanLoadPlugin(render_process_id, plugin_path)) |
| 373 | return NULL; |
| 374 | |
[email protected] | a50432d | 2011-09-30 16:32:14 | [diff] [blame] | 375 | PpapiPluginProcessHost* plugin_host = FindPpapiBrokerProcess(plugin_path); |
[email protected] | eb415bf0e | 2011-04-14 02:45:42 | [diff] [blame] | 376 | if (plugin_host) |
| 377 | return plugin_host; |
| 378 | |
| 379 | // Validate that the plugin is actually registered. |
[email protected] | 13075767 | 2012-10-24 00:26:19 | [diff] [blame] | 380 | PepperPluginInfo* info = GetRegisteredPpapiPluginInfo(plugin_path); |
[email protected] | eb415bf0e | 2011-04-14 02:45:42 | [diff] [blame] | 381 | if (!info) |
| 382 | return NULL; |
| 383 | |
| 384 | // TODO(ddorwin): Uncomment once out of process is supported. |
| 385 | // DCHECK(info->is_out_of_process); |
| 386 | |
| 387 | // 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] | 388 | return PpapiPluginProcessHost::CreateBrokerHost(*info); |
[email protected] | eb415bf0e | 2011-04-14 02:45:42 | [diff] [blame] | 389 | } |
| 390 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 391 | void PluginServiceImpl::OpenChannelToNpapiPlugin( |
[email protected] | c8f73ab | 2011-01-22 00:05:17 | [diff] [blame] | 392 | int render_process_id, |
[email protected] | 60eca4eb | 2013-12-06 00:02:16 | [diff] [blame] | 393 | int render_frame_id, |
[email protected] | 610c089 | 2009-09-08 19:46:18 | [diff] [blame] | 394 | const GURL& url, |
[email protected] | dfba876 | 2011-09-02 12:49:54 | [diff] [blame] | 395 | const GURL& page_url, |
[email protected] | 610c089 | 2009-09-08 19:46:18 | [diff] [blame] | 396 | const std::string& mime_type, |
[email protected] | 46b69e4 | 2010-11-02 12:26:39 | [diff] [blame] | 397 | PluginProcessHost::Client* client) { |
mostynb | 4c27d04 | 2015-03-18 21:47:47 | [diff] [blame] | 398 | DCHECK_CURRENTLY_ON(BrowserThread::IO); |
[email protected] | 4befe759 | 2011-09-14 22:49:09 | [diff] [blame] | 399 | DCHECK(!ContainsKey(pending_plugin_clients_, client)); |
| 400 | pending_plugin_clients_.insert(client); |
[email protected] | 88ca491 | 2011-10-12 14:00:43 | [diff] [blame] | 401 | |
| 402 | // Make sure plugins are loaded if necessary. |
[email protected] | 209f2ae | 2012-03-13 01:28:08 | [diff] [blame] | 403 | PluginServiceFilterParams params = { |
[email protected] | 88ca491 | 2011-10-12 14:00:43 | [diff] [blame] | 404 | render_process_id, |
[email protected] | 60eca4eb | 2013-12-06 00:02:16 | [diff] [blame] | 405 | render_frame_id, |
[email protected] | 88ca491 | 2011-10-12 14:00:43 | [diff] [blame] | 406 | page_url, |
[email protected] | df02aca | 2012-02-09 21:03:20 | [diff] [blame] | 407 | client->GetResourceContext() |
[email protected] | 88ca491 | 2011-10-12 14:00:43 | [diff] [blame] | 408 | }; |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 409 | GetPlugins(base::Bind( |
| 410 | &PluginServiceImpl::ForwardGetAllowedPluginForOpenChannelToPlugin, |
| 411 | base::Unretained(this), params, url, mime_type, client)); |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 412 | } |
| 413 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 414 | void PluginServiceImpl::OpenChannelToPpapiPlugin( |
[email protected] | 6be31d20 | 2013-02-01 18:20:54 | [diff] [blame] | 415 | int render_process_id, |
[email protected] | 2dec8ec | 2013-02-07 19:20:34 | [diff] [blame] | 416 | const base::FilePath& plugin_path, |
| 417 | const base::FilePath& profile_data_directory, |
[email protected] | a50432d | 2011-09-30 16:32:14 | [diff] [blame] | 418 | PpapiPluginProcessHost::PluginClient* client) { |
[email protected] | d259a8e | 2011-05-18 22:31:09 | [diff] [blame] | 419 | PpapiPluginProcessHost* plugin_host = FindOrStartPpapiPluginProcess( |
[email protected] | 8522332e | 2013-08-28 19:42:59 | [diff] [blame] | 420 | render_process_id, plugin_path, profile_data_directory); |
[email protected] | 1bf0fb2 | 2012-04-12 21:44:16 | [diff] [blame] | 421 | if (plugin_host) { |
[email protected] | a08ebea | 2011-02-13 17:50:20 | [diff] [blame] | 422 | plugin_host->OpenChannelToPlugin(client); |
[email protected] | 1bf0fb2 | 2012-04-12 21:44:16 | [diff] [blame] | 423 | } else { |
| 424 | // Send error. |
[email protected] | 108fd34 | 2013-01-04 20:46:54 | [diff] [blame] | 425 | client->OnPpapiChannelOpened(IPC::ChannelHandle(), base::kNullProcessId, 0); |
[email protected] | 1bf0fb2 | 2012-04-12 21:44:16 | [diff] [blame] | 426 | } |
[email protected] | a08ebea | 2011-02-13 17:50:20 | [diff] [blame] | 427 | } |
| 428 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 429 | void PluginServiceImpl::OpenChannelToPpapiBroker( |
[email protected] | 6be31d20 | 2013-02-01 18:20:54 | [diff] [blame] | 430 | int render_process_id, |
[email protected] | 2dec8ec | 2013-02-07 19:20:34 | [diff] [blame] | 431 | const base::FilePath& path, |
[email protected] | a50432d | 2011-09-30 16:32:14 | [diff] [blame] | 432 | PpapiPluginProcessHost::BrokerClient* client) { |
[email protected] | 6be31d20 | 2013-02-01 18:20:54 | [diff] [blame] | 433 | PpapiPluginProcessHost* plugin_host = FindOrStartPpapiBrokerProcess( |
| 434 | render_process_id, path); |
[email protected] | 1bf0fb2 | 2012-04-12 21:44:16 | [diff] [blame] | 435 | if (plugin_host) { |
[email protected] | a50432d | 2011-09-30 16:32:14 | [diff] [blame] | 436 | plugin_host->OpenChannelToPlugin(client); |
[email protected] | 1bf0fb2 | 2012-04-12 21:44:16 | [diff] [blame] | 437 | } else { |
| 438 | // Send error. |
[email protected] | 108fd34 | 2013-01-04 20:46:54 | [diff] [blame] | 439 | client->OnPpapiChannelOpened(IPC::ChannelHandle(), base::kNullProcessId, 0); |
[email protected] | 1bf0fb2 | 2012-04-12 21:44:16 | [diff] [blame] | 440 | } |
[email protected] | eb415bf0e | 2011-04-14 02:45:42 | [diff] [blame] | 441 | } |
| 442 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 443 | void PluginServiceImpl::CancelOpenChannelToNpapiPlugin( |
[email protected] | 4befe759 | 2011-09-14 22:49:09 | [diff] [blame] | 444 | PluginProcessHost::Client* client) { |
mostynb | 4c27d04 | 2015-03-18 21:47:47 | [diff] [blame] | 445 | DCHECK_CURRENTLY_ON(BrowserThread::IO); |
[email protected] | 4befe759 | 2011-09-14 22:49:09 | [diff] [blame] | 446 | DCHECK(ContainsKey(pending_plugin_clients_, client)); |
| 447 | pending_plugin_clients_.erase(client); |
| 448 | } |
| 449 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 450 | void PluginServiceImpl::ForwardGetAllowedPluginForOpenChannelToPlugin( |
[email protected] | 209f2ae | 2012-03-13 01:28:08 | [diff] [blame] | 451 | const PluginServiceFilterParams& params, |
[email protected] | 88ca491 | 2011-10-12 14:00:43 | [diff] [blame] | 452 | const GURL& url, |
| 453 | const std::string& mime_type, |
| 454 | PluginProcessHost::Client* client, |
[email protected] | d7bd3e5 | 2013-07-21 04:29:20 | [diff] [blame] | 455 | const std::vector<WebPluginInfo>&) { |
[email protected] | 60eca4eb | 2013-12-06 00:02:16 | [diff] [blame] | 456 | GetAllowedPluginForOpenChannelToPlugin( |
| 457 | params.render_process_id, params.render_frame_id, url, params.page_url, |
| 458 | mime_type, client, params.resource_context); |
[email protected] | 88ca491 | 2011-10-12 14:00:43 | [diff] [blame] | 459 | } |
| 460 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 461 | void PluginServiceImpl::GetAllowedPluginForOpenChannelToPlugin( |
[email protected] | c8f73ab | 2011-01-22 00:05:17 | [diff] [blame] | 462 | int render_process_id, |
[email protected] | 60eca4eb | 2013-12-06 00:02:16 | [diff] [blame] | 463 | int render_frame_id, |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 464 | const GURL& url, |
[email protected] | dfba876 | 2011-09-02 12:49:54 | [diff] [blame] | 465 | const GURL& page_url, |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 466 | const std::string& mime_type, |
[email protected] | 87c4be4 | 2011-09-16 01:10:59 | [diff] [blame] | 467 | PluginProcessHost::Client* client, |
[email protected] | 13075767 | 2012-10-24 00:26:19 | [diff] [blame] | 468 | ResourceContext* resource_context) { |
[email protected] | d7bd3e5 | 2013-07-21 04:29:20 | [diff] [blame] | 469 | WebPluginInfo info; |
[email protected] | dfba876 | 2011-09-02 12:49:54 | [diff] [blame] | 470 | bool allow_wildcard = true; |
[email protected] | 11e1c18 | 2011-05-17 20:26:27 | [diff] [blame] | 471 | bool found = GetPluginInfo( |
[email protected] | 60eca4eb | 2013-12-06 00:02:16 | [diff] [blame] | 472 | render_process_id, render_frame_id, resource_context, |
[email protected] | dfba876 | 2011-09-02 12:49:54 | [diff] [blame] | 473 | url, page_url, mime_type, allow_wildcard, |
| 474 | NULL, &info, NULL); |
[email protected] | 2dec8ec | 2013-02-07 19:20:34 | [diff] [blame] | 475 | base::FilePath plugin_path; |
[email protected] | 6859807 | 2011-07-29 08:21:28 | [diff] [blame] | 476 | if (found) |
[email protected] | dfba876 | 2011-09-02 12:49:54 | [diff] [blame] | 477 | plugin_path = info.path; |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 478 | |
| 479 | // Now we jump back to the IO thread to finish opening the channel. |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 480 | BrowserThread::PostTask( |
| 481 | BrowserThread::IO, FROM_HERE, |
| 482 | base::Bind(&PluginServiceImpl::FinishOpenChannelToPlugin, |
[email protected] | 6be31d20 | 2013-02-01 18:20:54 | [diff] [blame] | 483 | base::Unretained(this), |
| 484 | render_process_id, |
| 485 | plugin_path, |
| 486 | client)); |
wfh | 3044350 | 2015-05-01 21:58:30 | [diff] [blame] | 487 | if (filter_) { |
| 488 | DCHECK_EQ(WebPluginInfo::PLUGIN_TYPE_NPAPI, info.type); |
wfh | ec1f735 | 2015-05-07 23:44:54 | [diff] [blame] | 489 | filter_->NPAPIPluginLoaded(render_process_id, render_frame_id, mime_type, |
| 490 | info); |
wfh | 3044350 | 2015-05-01 21:58:30 | [diff] [blame] | 491 | } |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 492 | } |
| 493 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 494 | void PluginServiceImpl::FinishOpenChannelToPlugin( |
[email protected] | 6be31d20 | 2013-02-01 18:20:54 | [diff] [blame] | 495 | int render_process_id, |
[email protected] | 2dec8ec | 2013-02-07 19:20:34 | [diff] [blame] | 496 | const base::FilePath& plugin_path, |
[email protected] | 46b69e4 | 2010-11-02 12:26:39 | [diff] [blame] | 497 | PluginProcessHost::Client* client) { |
mostynb | 4c27d04 | 2015-03-18 21:47:47 | [diff] [blame] | 498 | DCHECK_CURRENTLY_ON(BrowserThread::IO); |
[email protected] | 20a793e | 2010-10-12 06:50:08 | [diff] [blame] | 499 | |
[email protected] | 4befe759 | 2011-09-14 22:49:09 | [diff] [blame] | 500 | // Make sure it hasn't been canceled yet. |
| 501 | if (!ContainsKey(pending_plugin_clients_, client)) |
| 502 | return; |
| 503 | pending_plugin_clients_.erase(client); |
| 504 | |
[email protected] | 6be31d20 | 2013-02-01 18:20:54 | [diff] [blame] | 505 | PluginProcessHost* plugin_host = FindOrStartNpapiPluginProcess( |
| 506 | render_process_id, plugin_path); |
[email protected] | 4befe759 | 2011-09-14 22:49:09 | [diff] [blame] | 507 | if (plugin_host) { |
| 508 | client->OnFoundPluginProcessHost(plugin_host); |
[email protected] | 46b69e4 | 2010-11-02 12:26:39 | [diff] [blame] | 509 | plugin_host->OpenChannelToPlugin(client); |
[email protected] | 4befe759 | 2011-09-14 22:49:09 | [diff] [blame] | 510 | } else { |
[email protected] | 46b69e4 | 2010-11-02 12:26:39 | [diff] [blame] | 511 | client->OnError(); |
[email protected] | 4befe759 | 2011-09-14 22:49:09 | [diff] [blame] | 512 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 513 | } |
| 514 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 515 | bool PluginServiceImpl::GetPluginInfoArray( |
[email protected] | 51b63f6 | 2011-10-05 18:55:42 | [diff] [blame] | 516 | const GURL& url, |
| 517 | const std::string& mime_type, |
| 518 | bool allow_wildcard, |
[email protected] | d7bd3e5 | 2013-07-21 04:29:20 | [diff] [blame] | 519 | std::vector<WebPluginInfo>* plugins, |
[email protected] | 51b63f6 | 2011-10-05 18:55:42 | [diff] [blame] | 520 | std::vector<std::string>* actual_mime_types) { |
| 521 | bool use_stale = false; |
[email protected] | 29e2fb4 | 2013-07-19 01:13:47 | [diff] [blame] | 522 | PluginList::Singleton()->GetPluginInfoArray( |
[email protected] | 9a60ccb | 2013-07-19 22:23:36 | [diff] [blame] | 523 | url, mime_type, allow_wildcard, &use_stale, NPAPIPluginsSupported(), |
| 524 | plugins, actual_mime_types); |
[email protected] | 51b63f6 | 2011-10-05 18:55:42 | [diff] [blame] | 525 | return use_stale; |
| 526 | } |
| 527 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 528 | bool PluginServiceImpl::GetPluginInfo(int render_process_id, |
[email protected] | 60eca4eb | 2013-12-06 00:02:16 | [diff] [blame] | 529 | int render_frame_id, |
[email protected] | 13075767 | 2012-10-24 00:26:19 | [diff] [blame] | 530 | ResourceContext* context, |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 531 | const GURL& url, |
| 532 | const GURL& page_url, |
| 533 | const std::string& mime_type, |
| 534 | bool allow_wildcard, |
| 535 | bool* is_stale, |
[email protected] | d7bd3e5 | 2013-07-21 04:29:20 | [diff] [blame] | 536 | WebPluginInfo* info, |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 537 | std::string* actual_mime_type) { |
[email protected] | d7bd3e5 | 2013-07-21 04:29:20 | [diff] [blame] | 538 | std::vector<WebPluginInfo> plugins; |
[email protected] | 6859807 | 2011-07-29 08:21:28 | [diff] [blame] | 539 | std::vector<std::string> mime_types; |
[email protected] | 88ca491 | 2011-10-12 14:00:43 | [diff] [blame] | 540 | bool stale = GetPluginInfoArray( |
| 541 | url, mime_type, allow_wildcard, &plugins, &mime_types); |
| 542 | if (is_stale) |
| 543 | *is_stale = stale; |
[email protected] | dfba876 | 2011-09-02 12:49:54 | [diff] [blame] | 544 | |
[email protected] | 6859807 | 2011-07-29 08:21:28 | [diff] [blame] | 545 | for (size_t i = 0; i < plugins.size(); ++i) { |
[email protected] | 05f51128 | 2013-02-05 15:02:50 | [diff] [blame] | 546 | if (!filter_ || filter_->IsPluginAvailable(render_process_id, |
[email protected] | 60eca4eb | 2013-12-06 00:02:16 | [diff] [blame] | 547 | render_frame_id, |
[email protected] | 05f51128 | 2013-02-05 15:02:50 | [diff] [blame] | 548 | context, |
| 549 | url, |
| 550 | page_url, |
| 551 | &plugins[i])) { |
[email protected] | 6859807 | 2011-07-29 08:21:28 | [diff] [blame] | 552 | *info = plugins[i]; |
| 553 | if (actual_mime_type) |
| 554 | *actual_mime_type = mime_types[i]; |
| 555 | return true; |
| 556 | } |
| 557 | } |
| 558 | return false; |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 559 | } |
| 560 | |
[email protected] | 2dec8ec | 2013-02-07 19:20:34 | [diff] [blame] | 561 | bool PluginServiceImpl::GetPluginInfoByPath(const base::FilePath& plugin_path, |
[email protected] | d7bd3e5 | 2013-07-21 04:29:20 | [diff] [blame] | 562 | WebPluginInfo* info) { |
| 563 | std::vector<WebPluginInfo> plugins; |
[email protected] | 29e2fb4 | 2013-07-19 01:13:47 | [diff] [blame] | 564 | PluginList::Singleton()->GetPluginsNoRefresh(&plugins); |
[email protected] | 88ca491 | 2011-10-12 14:00:43 | [diff] [blame] | 565 | |
[email protected] | d7bd3e5 | 2013-07-21 04:29:20 | [diff] [blame] | 566 | for (std::vector<WebPluginInfo>::iterator it = plugins.begin(); |
[email protected] | 88ca491 | 2011-10-12 14:00:43 | [diff] [blame] | 567 | it != plugins.end(); |
| 568 | ++it) { |
| 569 | if (it->path == plugin_path) { |
| 570 | *info = *it; |
| 571 | return true; |
| 572 | } |
| 573 | } |
| 574 | |
| 575 | return false; |
| 576 | } |
| 577 | |
[email protected] | fcf75d4 | 2013-12-03 20:11:26 | [diff] [blame] | 578 | base::string16 PluginServiceImpl::GetPluginDisplayNameByPath( |
[email protected] | 2dec8ec | 2013-02-07 19:20:34 | [diff] [blame] | 579 | const base::FilePath& path) { |
[email protected] | fcf75d4 | 2013-12-03 20:11:26 | [diff] [blame] | 580 | base::string16 plugin_name = path.LossyDisplayName(); |
[email protected] | d7bd3e5 | 2013-07-21 04:29:20 | [diff] [blame] | 581 | WebPluginInfo info; |
[email protected] | 8be4584 | 2012-04-13 19:49:29 | [diff] [blame] | 582 | if (PluginService::GetInstance()->GetPluginInfoByPath(path, &info) && |
| 583 | !info.name.empty()) { |
| 584 | plugin_name = info.name; |
| 585 | #if defined(OS_MACOSX) |
| 586 | // Many plugins on the Mac have .plugin in the actual name, which looks |
| 587 | // terrible, so look for that and strip it off if present. |
| 588 | const std::string kPluginExtension = ".plugin"; |
brettw | a7ff1b29 | 2015-07-16 17:49:29 | [diff] [blame] | 589 | if (base::EndsWith(plugin_name, base::ASCIIToUTF16(kPluginExtension), |
| 590 | base::CompareCase::SENSITIVE)) |
[email protected] | 8be4584 | 2012-04-13 19:49:29 | [diff] [blame] | 591 | plugin_name.erase(plugin_name.length() - kPluginExtension.length()); |
| 592 | #endif // OS_MACOSX |
| 593 | } |
| 594 | return plugin_name; |
| 595 | } |
| 596 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 597 | void PluginServiceImpl::GetPlugins(const GetPluginsCallback& callback) { |
skyostil | 95082a6 | 2015-06-05 19:53:07 | [diff] [blame] | 598 | scoped_refptr<base::SingleThreadTaskRunner> target_task_runner( |
| 599 | base::ThreadTaskRunnerHandle::Get()); |
[email protected] | 4912595 | 2011-09-27 18:05:15 | [diff] [blame] | 600 | |
[email protected] | 1b51720 | 2012-12-19 17:16:10 | [diff] [blame] | 601 | if (LoadPluginListInProcess()) { |
skyostil | 95082a6 | 2015-06-05 19:53:07 | [diff] [blame] | 602 | BrowserThread::GetBlockingPool() |
| 603 | ->PostSequencedWorkerTaskWithShutdownBehavior( |
| 604 | plugin_list_token_, FROM_HERE, |
[email protected] | 1b51720 | 2012-12-19 17:16:10 | [diff] [blame] | 605 | base::Bind(&PluginServiceImpl::GetPluginsInternal, |
skyostil | 95082a6 | 2015-06-05 19:53:07 | [diff] [blame] | 606 | base::Unretained(this), target_task_runner, callback), |
| 607 | base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); |
[email protected] | 1b51720 | 2012-12-19 17:16:10 | [diff] [blame] | 608 | return; |
| 609 | } |
| 610 | #if defined(OS_POSIX) |
skyostil | 95082a6 | 2015-06-05 19:53:07 | [diff] [blame] | 611 | BrowserThread::PostTask( |
| 612 | BrowserThread::IO, FROM_HERE, |
[email protected] | aa7f880 | 2014-01-27 16:56:32 | [diff] [blame] | 613 | base::Bind(&PluginServiceImpl::GetPluginsOnIOThread, |
skyostil | 95082a6 | 2015-06-05 19:53:07 | [diff] [blame] | 614 | base::Unretained(this), target_task_runner, callback)); |
[email protected] | a33fa9d | 2012-05-16 14:47:49 | [diff] [blame] | 615 | #else |
[email protected] | 1b51720 | 2012-12-19 17:16:10 | [diff] [blame] | 616 | NOTREACHED(); |
[email protected] | 4912595 | 2011-09-27 18:05:15 | [diff] [blame] | 617 | #endif |
[email protected] | d33e7cc | 2011-09-23 01:43:56 | [diff] [blame] | 618 | } |
| 619 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 620 | void PluginServiceImpl::GetPluginsInternal( |
skyostil | 95082a6 | 2015-06-05 19:53:07 | [diff] [blame] | 621 | base::SingleThreadTaskRunner* target_task_runner, |
| 622 | const PluginService::GetPluginsCallback& callback) { |
[email protected] | a33fa9d | 2012-05-16 14:47:49 | [diff] [blame] | 623 | DCHECK(BrowserThread::GetBlockingPool()->IsRunningSequenceOnCurrentThread( |
| 624 | plugin_list_token_)); |
[email protected] | d33e7cc | 2011-09-23 01:43:56 | [diff] [blame] | 625 | |
[email protected] | d7bd3e5 | 2013-07-21 04:29:20 | [diff] [blame] | 626 | std::vector<WebPluginInfo> plugins; |
[email protected] | 9a60ccb | 2013-07-19 22:23:36 | [diff] [blame] | 627 | PluginList::Singleton()->GetPlugins(&plugins, NPAPIPluginsSupported()); |
[email protected] | d33e7cc | 2011-09-23 01:43:56 | [diff] [blame] | 628 | |
skyostil | 95082a6 | 2015-06-05 19:53:07 | [diff] [blame] | 629 | target_task_runner->PostTask(FROM_HERE, base::Bind(callback, plugins)); |
[email protected] | dfba876 | 2011-09-02 12:49:54 | [diff] [blame] | 630 | } |
| 631 | |
[email protected] | aa7f880 | 2014-01-27 16:56:32 | [diff] [blame] | 632 | #if defined(OS_POSIX) |
| 633 | void PluginServiceImpl::GetPluginsOnIOThread( |
skyostil | 95082a6 | 2015-06-05 19:53:07 | [diff] [blame] | 634 | base::SingleThreadTaskRunner* target_task_runner, |
[email protected] | aa7f880 | 2014-01-27 16:56:32 | [diff] [blame] | 635 | const GetPluginsCallback& callback) { |
mostynb | 4c27d04 | 2015-03-18 21:47:47 | [diff] [blame] | 636 | DCHECK_CURRENTLY_ON(BrowserThread::IO); |
[email protected] | aa7f880 | 2014-01-27 16:56:32 | [diff] [blame] | 637 | |
| 638 | // If we switch back to loading plugins in process, then we need to make |
| 639 | // sure g_thread_init() gets called since plugins may call glib at load. |
| 640 | |
dcheng | 54c3719d | 2014-08-26 21:52:56 | [diff] [blame] | 641 | if (!plugin_loader_.get()) |
[email protected] | aa7f880 | 2014-01-27 16:56:32 | [diff] [blame] | 642 | plugin_loader_ = new PluginLoaderPosix; |
| 643 | |
skyostil | 95082a6 | 2015-06-05 19:53:07 | [diff] [blame] | 644 | plugin_loader_->GetPlugins(base::Bind( |
| 645 | &ForwardCallback, make_scoped_refptr(target_task_runner), callback)); |
[email protected] | aa7f880 | 2014-01-27 16:56:32 | [diff] [blame] | 646 | } |
| 647 | #endif |
| 648 | |
[email protected] | b547fd4 | 2009-04-23 23:16:27 | [diff] [blame] | 649 | #if defined(OS_WIN) |
rvargas | 6f315b8 | 2014-10-17 01:28:58 | [diff] [blame] | 650 | void PluginServiceImpl::OnKeyChanged(base::win::RegKey* key) { |
| 651 | key->StartWatching(base::Bind(&PluginServiceImpl::OnKeyChanged, |
| 652 | base::Unretained(this), |
rvargas | b805615 | 2014-11-08 01:44:28 | [diff] [blame] | 653 | base::Unretained(key))); |
[email protected] | b547fd4 | 2009-04-23 23:16:27 | [diff] [blame] | 654 | |
[email protected] | 29e2fb4 | 2013-07-19 01:13:47 | [diff] [blame] | 655 | PluginList::Singleton()->RefreshPlugins(); |
[email protected] | 45a22e6 | 2011-10-12 09:48:02 | [diff] [blame] | 656 | PurgePluginListCache(NULL, false); |
dcheng | 4fe6ccad | 2014-10-16 03:09:26 | [diff] [blame] | 657 | } |
rvargas | 6f315b8 | 2014-10-17 01:28:58 | [diff] [blame] | 658 | #endif // defined(OS_WIN) |
[email protected] | 894bb50 | 2009-05-21 22:39:57 | [diff] [blame] | 659 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 660 | void PluginServiceImpl::RegisterPepperPlugins() { |
[email protected] | dac6a5a | 2013-07-25 05:06:48 | [diff] [blame] | 661 | ComputePepperPluginList(&ppapi_plugins_); |
[email protected] | a08ebea | 2011-02-13 17:50:20 | [diff] [blame] | 662 | for (size_t i = 0; i < ppapi_plugins_.size(); ++i) { |
[email protected] | c6f3dea | 2012-01-14 02:23:11 | [diff] [blame] | 663 | RegisterInternalPlugin(ppapi_plugins_[i].ToWebPluginInfo(), true); |
[email protected] | 4e0616e | 2010-05-28 14:55:53 | [diff] [blame] | 664 | } |
| 665 | } |
[email protected] | 634d23d | 2011-01-19 10:38:19 | [diff] [blame] | 666 | |
[email protected] | eb415bf0e | 2011-04-14 02:45:42 | [diff] [blame] | 667 | // 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] | 668 | PepperPluginInfo* PluginServiceImpl::GetRegisteredPpapiPluginInfo( |
[email protected] | 2dec8ec | 2013-02-07 19:20:34 | [diff] [blame] | 669 | const base::FilePath& plugin_path) { |
[email protected] | 13075767 | 2012-10-24 00:26:19 | [diff] [blame] | 670 | PepperPluginInfo* info = NULL; |
[email protected] | 3627aa3f | 2013-09-17 22:32:51 | [diff] [blame] | 671 | for (size_t i = 0; i < ppapi_plugins_.size(); ++i) { |
[email protected] | 6b14feb | 2011-08-16 11:22:56 | [diff] [blame] | 672 | if (ppapi_plugins_[i].path == plugin_path) { |
| 673 | info = &ppapi_plugins_[i]; |
| 674 | break; |
| 675 | } |
[email protected] | eb415bf0e | 2011-04-14 02:45:42 | [diff] [blame] | 676 | } |
[email protected] | 07611759 | 2011-08-17 03:16:41 | [diff] [blame] | 677 | if (info) |
| 678 | return info; |
| 679 | // We did not find the plugin in our list. But wait! the plugin can also |
| 680 | // be a latecomer, as it happens with pepper flash. This information |
| 681 | // can be obtained from the PluginList singleton and we can use it to |
| 682 | // construct it and add it to the list. This same deal needs to be done |
| 683 | // in the renderer side in PepperPluginRegistry. |
[email protected] | d7bd3e5 | 2013-07-21 04:29:20 | [diff] [blame] | 684 | WebPluginInfo webplugin_info; |
[email protected] | 88ca491 | 2011-10-12 14:00:43 | [diff] [blame] | 685 | if (!GetPluginInfoByPath(plugin_path, &webplugin_info)) |
[email protected] | 07611759 | 2011-08-17 03:16:41 | [diff] [blame] | 686 | return NULL; |
[email protected] | 13075767 | 2012-10-24 00:26:19 | [diff] [blame] | 687 | PepperPluginInfo new_pepper_info; |
[email protected] | 07611759 | 2011-08-17 03:16:41 | [diff] [blame] | 688 | if (!MakePepperPluginInfo(webplugin_info, &new_pepper_info)) |
| 689 | return NULL; |
| 690 | ppapi_plugins_.push_back(new_pepper_info); |
| 691 | return &ppapi_plugins_[ppapi_plugins_.size() - 1]; |
[email protected] | eb415bf0e | 2011-04-14 02:45:42 | [diff] [blame] | 692 | } |
| 693 | |
[email protected] | 52348b2 | 2012-11-07 10:19:34 | [diff] [blame] | 694 | #if defined(OS_POSIX) && !defined(OS_OPENBSD) && !defined(OS_ANDROID) |
[email protected] | 634d23d | 2011-01-19 10:38:19 | [diff] [blame] | 695 | // static |
[email protected] | 07b71c8 | 2013-01-08 19:07:31 | [diff] [blame] | 696 | void PluginServiceImpl::RegisterFilePathWatcher(FilePathWatcher* watcher, |
[email protected] | 2dec8ec | 2013-02-07 19:20:34 | [diff] [blame] | 697 | const base::FilePath& path) { |
[email protected] | 07b71c8 | 2013-01-08 19:07:31 | [diff] [blame] | 698 | bool result = watcher->Watch(path, false, |
| 699 | base::Bind(&NotifyPluginDirChanged)); |
[email protected] | 634d23d | 2011-01-19 10:38:19 | [diff] [blame] | 700 | DCHECK(result); |
| 701 | } |
| 702 | #endif |
[email protected] | f520b5b | 2011-11-08 02:42:14 | [diff] [blame] | 703 | |
[email protected] | 13075767 | 2012-10-24 00:26:19 | [diff] [blame] | 704 | void PluginServiceImpl::SetFilter(PluginServiceFilter* filter) { |
[email protected] | 3a5180ae | 2011-12-21 02:39:38 | [diff] [blame] | 705 | filter_ = filter; |
| 706 | } |
| 707 | |
[email protected] | 13075767 | 2012-10-24 00:26:19 | [diff] [blame] | 708 | PluginServiceFilter* PluginServiceImpl::GetFilter() { |
[email protected] | 3a5180ae | 2011-12-21 02:39:38 | [diff] [blame] | 709 | return filter_; |
| 710 | } |
| 711 | |
[email protected] | 2dec8ec | 2013-02-07 19:20:34 | [diff] [blame] | 712 | void PluginServiceImpl::ForcePluginShutdown(const base::FilePath& plugin_path) { |
[email protected] | b6a2f8de | 2012-01-31 17:28:49 | [diff] [blame] | 713 | if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { |
| 714 | BrowserThread::PostTask( |
| 715 | BrowserThread::IO, FROM_HERE, |
| 716 | base::Bind(&PluginServiceImpl::ForcePluginShutdown, |
| 717 | base::Unretained(this), plugin_path)); |
| 718 | return; |
| 719 | } |
| 720 | |
| 721 | PluginProcessHost* plugin = FindNpapiPluginProcess(plugin_path); |
| 722 | if (plugin) |
| 723 | plugin->ForceShutdown(); |
| 724 | } |
| 725 | |
[email protected] | 47214d88 | 2012-02-29 06:28:48 | [diff] [blame] | 726 | static const unsigned int kMaxCrashesPerInterval = 3; |
| 727 | static const unsigned int kCrashesInterval = 120; |
| 728 | |
[email protected] | 2dec8ec | 2013-02-07 19:20:34 | [diff] [blame] | 729 | void PluginServiceImpl::RegisterPluginCrash(const base::FilePath& path) { |
mostynb | 4c27d04 | 2015-03-18 21:47:47 | [diff] [blame] | 730 | DCHECK_CURRENTLY_ON(BrowserThread::IO); |
[email protected] | 2dec8ec | 2013-02-07 19:20:34 | [diff] [blame] | 731 | std::map<base::FilePath, std::vector<base::Time> >::iterator i = |
[email protected] | 47214d88 | 2012-02-29 06:28:48 | [diff] [blame] | 732 | crash_times_.find(path); |
| 733 | if (i == crash_times_.end()) { |
| 734 | crash_times_[path] = std::vector<base::Time>(); |
| 735 | i = crash_times_.find(path); |
| 736 | } |
| 737 | if (i->second.size() == kMaxCrashesPerInterval) { |
| 738 | i->second.erase(i->second.begin()); |
| 739 | } |
| 740 | base::Time time = base::Time::Now(); |
| 741 | i->second.push_back(time); |
| 742 | } |
| 743 | |
[email protected] | 2dec8ec | 2013-02-07 19:20:34 | [diff] [blame] | 744 | bool PluginServiceImpl::IsPluginUnstable(const base::FilePath& path) { |
mostynb | 4c27d04 | 2015-03-18 21:47:47 | [diff] [blame] | 745 | DCHECK_CURRENTLY_ON(BrowserThread::IO); |
[email protected] | 2dec8ec | 2013-02-07 19:20:34 | [diff] [blame] | 746 | std::map<base::FilePath, std::vector<base::Time> >::const_iterator i = |
[email protected] | 47214d88 | 2012-02-29 06:28:48 | [diff] [blame] | 747 | crash_times_.find(path); |
| 748 | if (i == crash_times_.end()) { |
| 749 | return false; |
| 750 | } |
| 751 | if (i->second.size() != kMaxCrashesPerInterval) { |
| 752 | return false; |
| 753 | } |
| 754 | base::TimeDelta delta = base::Time::Now() - i->second[0]; |
[email protected] | d8c7006 | 2013-04-24 00:22:34 | [diff] [blame] | 755 | return delta.InSeconds() <= kCrashesInterval; |
[email protected] | 47214d88 | 2012-02-29 06:28:48 | [diff] [blame] | 756 | } |
| 757 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 758 | void PluginServiceImpl::RefreshPlugins() { |
[email protected] | 29e2fb4 | 2013-07-19 01:13:47 | [diff] [blame] | 759 | PluginList::Singleton()->RefreshPlugins(); |
[email protected] | f520b5b | 2011-11-08 02:42:14 | [diff] [blame] | 760 | } |
| 761 | |
[email protected] | 2dec8ec | 2013-02-07 19:20:34 | [diff] [blame] | 762 | void PluginServiceImpl::AddExtraPluginPath(const base::FilePath& path) { |
[email protected] | a01c8c8f | 2014-05-09 17:24:53 | [diff] [blame] | 763 | if (!NPAPIPluginsSupported()) { |
[email protected] | 9a60ccb | 2013-07-19 22:23:36 | [diff] [blame] | 764 | // TODO(jam): remove and just have CHECK once we're sure this doesn't get |
| 765 | // triggered. |
[email protected] | efde84b0 | 2013-11-23 04:18:20 | [diff] [blame] | 766 | DVLOG(0) << "NPAPI plugins not supported"; |
[email protected] | 9a60ccb | 2013-07-19 22:23:36 | [diff] [blame] | 767 | return; |
| 768 | } |
[email protected] | 29e2fb4 | 2013-07-19 01:13:47 | [diff] [blame] | 769 | PluginList::Singleton()->AddExtraPluginPath(path); |
[email protected] | c6f3dea | 2012-01-14 02:23:11 | [diff] [blame] | 770 | } |
| 771 | |
[email protected] | 2dec8ec | 2013-02-07 19:20:34 | [diff] [blame] | 772 | void PluginServiceImpl::RemoveExtraPluginPath(const base::FilePath& path) { |
[email protected] | 29e2fb4 | 2013-07-19 01:13:47 | [diff] [blame] | 773 | PluginList::Singleton()->RemoveExtraPluginPath(path); |
[email protected] | 8f337212 | 2013-07-18 04:34:14 | [diff] [blame] | 774 | } |
| 775 | |
| 776 | void PluginServiceImpl::AddExtraPluginDir(const base::FilePath& path) { |
[email protected] | 29e2fb4 | 2013-07-19 01:13:47 | [diff] [blame] | 777 | PluginList::Singleton()->AddExtraPluginDir(path); |
[email protected] | 8f337212 | 2013-07-18 04:34:14 | [diff] [blame] | 778 | } |
| 779 | |
| 780 | void PluginServiceImpl::RegisterInternalPlugin( |
[email protected] | d7bd3e5 | 2013-07-21 04:29:20 | [diff] [blame] | 781 | const WebPluginInfo& info, |
[email protected] | 8f337212 | 2013-07-18 04:34:14 | [diff] [blame] | 782 | bool add_at_beginning) { |
wfh | a79d102 | 2015-02-20 16:13:13 | [diff] [blame] | 783 | // Internal plugins should never be NPAPI. |
| 784 | CHECK_NE(info.type, WebPluginInfo::PLUGIN_TYPE_NPAPI); |
| 785 | if (info.type == WebPluginInfo::PLUGIN_TYPE_NPAPI) { |
[email protected] | efde84b0 | 2013-11-23 04:18:20 | [diff] [blame] | 786 | DVLOG(0) << "Don't register NPAPI plugins when they're not supported"; |
[email protected] | 9a60ccb | 2013-07-19 22:23:36 | [diff] [blame] | 787 | return; |
| 788 | } |
[email protected] | 29e2fb4 | 2013-07-19 01:13:47 | [diff] [blame] | 789 | PluginList::Singleton()->RegisterInternalPlugin(info, add_at_beginning); |
[email protected] | f520b5b | 2011-11-08 02:42:14 | [diff] [blame] | 790 | } |
| 791 | |
[email protected] | 2dec8ec | 2013-02-07 19:20:34 | [diff] [blame] | 792 | void PluginServiceImpl::UnregisterInternalPlugin(const base::FilePath& path) { |
[email protected] | 29e2fb4 | 2013-07-19 01:13:47 | [diff] [blame] | 793 | PluginList::Singleton()->UnregisterInternalPlugin(path); |
[email protected] | f520b5b | 2011-11-08 02:42:14 | [diff] [blame] | 794 | } |
| 795 | |
[email protected] | 8f337212 | 2013-07-18 04:34:14 | [diff] [blame] | 796 | void PluginServiceImpl::GetInternalPlugins( |
[email protected] | d7bd3e5 | 2013-07-21 04:29:20 | [diff] [blame] | 797 | std::vector<WebPluginInfo>* plugins) { |
[email protected] | 29e2fb4 | 2013-07-19 01:13:47 | [diff] [blame] | 798 | PluginList::Singleton()->GetInternalPlugins(plugins); |
[email protected] | 8f337212 | 2013-07-18 04:34:14 | [diff] [blame] | 799 | } |
| 800 | |
[email protected] | 9a60ccb | 2013-07-19 22:23:36 | [diff] [blame] | 801 | bool PluginServiceImpl::NPAPIPluginsSupported() { |
wfh | a79d102 | 2015-02-20 16:13:13 | [diff] [blame] | 802 | #if defined(OS_WIN) || defined(OS_MACOSX) |
wfh | 6be0628 | 2015-07-20 18:04:02 | [diff] [blame] | 803 | npapi_plugins_enabled_ = GetContentClient()->browser()->IsNPAPIEnabled(); |
wfh | ad38f5a3 | 2015-06-03 17:11:07 | [diff] [blame] | 804 | #if defined(OS_WIN) |
wfh | 6be0628 | 2015-07-20 18:04:02 | [diff] [blame] | 805 | // NPAPI plugins don't play well with Win32k renderer lockdown. |
| 806 | if (npapi_plugins_enabled_) |
| 807 | DisableWin32kRendererLockdown(); |
wfh | ad38f5a3 | 2015-06-03 17:11:07 | [diff] [blame] | 808 | #endif |
wfh | 6be0628 | 2015-07-20 18:04:02 | [diff] [blame] | 809 | NPAPIPluginStatus status = |
| 810 | npapi_plugins_enabled_ ? NPAPI_STATUS_ENABLED : NPAPI_STATUS_DISABLED; |
wfh | a79d102 | 2015-02-20 16:13:13 | [diff] [blame] | 811 | #else |
wfh | 6be0628 | 2015-07-20 18:04:02 | [diff] [blame] | 812 | NPAPIPluginStatus status = NPAPI_STATUS_UNSUPPORTED; |
wfh | a79d102 | 2015-02-20 16:13:13 | [diff] [blame] | 813 | #endif |
wfh | 6be0628 | 2015-07-20 18:04:02 | [diff] [blame] | 814 | UMA_HISTOGRAM_ENUMERATION("Plugin.NPAPIStatus", status, |
| 815 | NPAPI_STATUS_ENUM_COUNT); |
wfh | a79d102 | 2015-02-20 16:13:13 | [diff] [blame] | 816 | |
wfh | 0539f2f5 | 2015-01-21 14:36:46 | [diff] [blame] | 817 | return npapi_plugins_enabled_; |
[email protected] | 9a60ccb | 2013-07-19 22:23:36 | [diff] [blame] | 818 | } |
| 819 | |
[email protected] | 8f337212 | 2013-07-18 04:34:14 | [diff] [blame] | 820 | void PluginServiceImpl::DisablePluginsDiscoveryForTesting() { |
[email protected] | 29e2fb4 | 2013-07-19 01:13:47 | [diff] [blame] | 821 | PluginList::Singleton()->DisablePluginsDiscovery(); |
[email protected] | ee06617 | 2011-11-10 23:20:05 | [diff] [blame] | 822 | } |
| 823 | |
[email protected] | 5904cb4 | 2012-09-24 15:05:20 | [diff] [blame] | 824 | #if defined(OS_MACOSX) |
| 825 | void PluginServiceImpl::AppActivated() { |
| 826 | BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
[email protected] | 07b71c8 | 2013-01-08 19:07:31 | [diff] [blame] | 827 | base::Bind(&NotifyPluginsOfActivation)); |
[email protected] | 5904cb4 | 2012-09-24 15:05:20 | [diff] [blame] | 828 | } |
[email protected] | 9a60ccb | 2013-07-19 22:23:36 | [diff] [blame] | 829 | #elif defined(OS_WIN) |
| 830 | |
| 831 | bool GetPluginPropertyFromWindow( |
| 832 | HWND window, const wchar_t* plugin_atom_property, |
| 833 | base::string16* plugin_property) { |
scottmg | 4800fc2 | 2015-04-29 00:31:20 | [diff] [blame] | 834 | ATOM plugin_atom = static_cast<ATOM>( |
| 835 | reinterpret_cast<uintptr_t>(GetPropW(window, plugin_atom_property))); |
[email protected] | 9a60ccb | 2013-07-19 22:23:36 | [diff] [blame] | 836 | if (plugin_atom != 0) { |
| 837 | WCHAR plugin_property_local[MAX_PATH] = {0}; |
| 838 | GlobalGetAtomNameW(plugin_atom, |
| 839 | plugin_property_local, |
| 840 | ARRAYSIZE(plugin_property_local)); |
| 841 | *plugin_property = plugin_property_local; |
| 842 | return true; |
| 843 | } |
| 844 | return false; |
| 845 | } |
| 846 | |
| 847 | bool PluginServiceImpl::GetPluginInfoFromWindow( |
| 848 | HWND window, |
| 849 | base::string16* plugin_name, |
| 850 | base::string16* plugin_version) { |
| 851 | if (!IsPluginWindow(window)) |
| 852 | return false; |
| 853 | |
jam | 3458fc00 | 2014-09-10 03:21:41 | [diff] [blame] | 854 | |
| 855 | DWORD process_id = 0; |
| 856 | GetWindowThreadProcessId(window, &process_id); |
| 857 | WebPluginInfo info; |
| 858 | if (!PluginProcessHost::GetWebPluginInfoFromPluginPid(process_id, &info)) |
| 859 | return false; |
| 860 | |
| 861 | *plugin_name = info.name; |
| 862 | *plugin_version = info.version; |
[email protected] | 9a60ccb | 2013-07-19 22:23:36 | [diff] [blame] | 863 | return true; |
| 864 | } |
| 865 | |
| 866 | bool PluginServiceImpl::IsPluginWindow(HWND window) { |
[email protected] | bde885b | 2013-09-12 20:55:53 | [diff] [blame] | 867 | return gfx::GetClassName(window) == base::string16(kNativeWindowClassName); |
[email protected] | 9a60ccb | 2013-07-19 22:23:36 | [diff] [blame] | 868 | } |
[email protected] | 5904cb4 | 2012-09-24 15:05:20 | [diff] [blame] | 869 | #endif |
| 870 | |
[email protected] | aec5ed5 | 2014-06-20 07:51:42 | [diff] [blame] | 871 | bool PluginServiceImpl::PpapiDevChannelSupported( |
| 872 | BrowserContext* browser_context, |
| 873 | const GURL& document_url) { |
wfh | 6be0628 | 2015-07-20 18:04:02 | [diff] [blame] | 874 | return GetContentClient()->browser()->IsPluginAllowedToUseDevChannelAPIs( |
| 875 | browser_context, document_url); |
[email protected] | 8ddc6b7c | 2013-12-12 20:42:06 | [diff] [blame] | 876 | } |
| 877 | |
[email protected] | 13075767 | 2012-10-24 00:26:19 | [diff] [blame] | 878 | } // namespace content |