[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" |
asvitkine | 3033081 | 2016-08-30 04:01:08 | [diff] [blame^] | 14 | #include "base/metrics/histogram_macros.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] | 13075767 | 2012-10-24 00:26:19 | [diff] [blame] | 37 | namespace content { |
[email protected] | d33e7cc | 2011-09-23 01:43:56 | [diff] [blame] | 38 | namespace { |
| 39 | |
[email protected] | fd8d8d6c | 2013-02-28 02:48:33 | [diff] [blame] | 40 | // This enum is used to collect Flash usage data. |
| 41 | enum FlashUsage { |
[email protected] | fd8d8d6c | 2013-02-28 02:48:33 | [diff] [blame] | 42 | // Number of browser processes that have started at least one PPAPI Flash |
| 43 | // process during their lifetime. |
piman | e8c57ea | 2016-04-06 01:19:36 | [diff] [blame] | 44 | START_PPAPI_FLASH_AT_LEAST_ONCE = 1, |
[email protected] | fd8d8d6c | 2013-02-28 02:48:33 | [diff] [blame] | 45 | // Total number of browser processes. |
| 46 | TOTAL_BROWSER_PROCESSES, |
| 47 | FLASH_USAGE_ENUM_COUNT |
| 48 | }; |
| 49 | |
[email protected] | 4912595 | 2011-09-27 18:05:15 | [diff] [blame] | 50 | // Callback set on the PluginList to assert that plugin loading happens on the |
| 51 | // correct thread. |
[email protected] | 1b51720 | 2012-12-19 17:16:10 | [diff] [blame] | 52 | void WillLoadPluginsCallback( |
[email protected] | a33fa9d | 2012-05-16 14:47:49 | [diff] [blame] | 53 | base::SequencedWorkerPool::SequenceToken token) { |
piman | e8c57ea | 2016-04-06 01:19:36 | [diff] [blame] | 54 | CHECK(BrowserThread::GetBlockingPool()->IsRunningSequenceOnCurrentThread( |
| 55 | token)); |
[email protected] | a7991225 | 2012-05-16 11:52:19 | [diff] [blame] | 56 | } |
[email protected] | d33e7cc | 2011-09-23 01:43:56 | [diff] [blame] | 57 | |
[email protected] | 07b71c8 | 2013-01-08 19:07:31 | [diff] [blame] | 58 | } // namespace |
| 59 | |
[email protected] | 3a5180ae | 2011-12-21 02:39:38 | [diff] [blame] | 60 | // static |
| 61 | PluginService* PluginService::GetInstance() { |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 62 | return PluginServiceImpl::GetInstance(); |
[email protected] | 3a5180ae | 2011-12-21 02:39:38 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | void PluginService::PurgePluginListCache(BrowserContext* browser_context, |
| 66 | bool reload_pages) { |
| 67 | for (RenderProcessHost::iterator it = RenderProcessHost::AllHostsIterator(); |
| 68 | !it.IsAtEnd(); it.Advance()) { |
| 69 | RenderProcessHost* host = it.GetCurrentValue(); |
| 70 | if (!browser_context || host->GetBrowserContext() == browser_context) |
| 71 | host->Send(new ViewMsg_PurgePluginListCache(reload_pages)); |
| 72 | } |
| 73 | } |
| 74 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 75 | // static |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 76 | PluginServiceImpl* PluginServiceImpl::GetInstance() { |
olli.raula | 36aa8be | 2015-09-10 11:14:22 | [diff] [blame] | 77 | return base::Singleton<PluginServiceImpl>::get(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 78 | } |
| 79 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 80 | PluginServiceImpl::PluginServiceImpl() |
piman | e8c57ea | 2016-04-06 01:19:36 | [diff] [blame] | 81 | : filter_(NULL) { |
[email protected] | fd8d8d6c | 2013-02-28 02:48:33 | [diff] [blame] | 82 | // Collect the total number of browser processes (which create |
| 83 | // PluginServiceImpl objects, to be precise). The number is used to normalize |
| 84 | // the number of processes which start at least one NPAPI/PPAPI Flash process. |
| 85 | static bool counted = false; |
| 86 | if (!counted) { |
| 87 | counted = true; |
| 88 | UMA_HISTOGRAM_ENUMERATION("Plugin.FlashUsage", TOTAL_BROWSER_PROCESSES, |
| 89 | FLASH_USAGE_ENUM_COUNT); |
| 90 | } |
[email protected] | ee06617 | 2011-11-10 23:20:05 | [diff] [blame] | 91 | } |
| 92 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 93 | PluginServiceImpl::~PluginServiceImpl() { |
[email protected] | ee06617 | 2011-11-10 23:20:05 | [diff] [blame] | 94 | } |
| 95 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 96 | void PluginServiceImpl::Init() { |
mostynb | c965fd6c | 2016-01-08 14:22:07 | [diff] [blame] | 97 | plugin_list_token_ = base::SequencedWorkerPool::GetSequenceToken(); |
[email protected] | 29e2fb4 | 2013-07-19 01:13:47 | [diff] [blame] | 98 | PluginList::Singleton()->set_will_load_plugins_callback( |
[email protected] | 1b51720 | 2012-12-19 17:16:10 | [diff] [blame] | 99 | base::Bind(&WillLoadPluginsCallback, plugin_list_token_)); |
[email protected] | 4912595 | 2011-09-27 18:05:15 | [diff] [blame] | 100 | |
[email protected] | 4e0616e | 2010-05-28 14:55:53 | [diff] [blame] | 101 | RegisterPepperPlugins(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 102 | } |
| 103 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 104 | PpapiPluginProcessHost* PluginServiceImpl::FindPpapiPluginProcess( |
[email protected] | 2dec8ec | 2013-02-07 19:20:34 | [diff] [blame] | 105 | const base::FilePath& plugin_path, |
| 106 | const base::FilePath& profile_data_directory) { |
[email protected] | 4967f79 | 2012-01-20 22:14:40 | [diff] [blame] | 107 | for (PpapiPluginProcessHostIterator iter; !iter.Done(); ++iter) { |
[email protected] | dd9a095 | 2012-05-31 20:11:31 | [diff] [blame] | 108 | if (iter->plugin_path() == plugin_path && |
| 109 | iter->profile_data_directory() == profile_data_directory) { |
[email protected] | 4967f79 | 2012-01-20 22:14:40 | [diff] [blame] | 110 | return *iter; |
[email protected] | dd9a095 | 2012-05-31 20:11:31 | [diff] [blame] | 111 | } |
[email protected] | a08ebea | 2011-02-13 17:50:20 | [diff] [blame] | 112 | } |
[email protected] | a08ebea | 2011-02-13 17:50:20 | [diff] [blame] | 113 | return NULL; |
| 114 | } |
| 115 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 116 | PpapiPluginProcessHost* PluginServiceImpl::FindPpapiBrokerProcess( |
[email protected] | 2dec8ec | 2013-02-07 19:20:34 | [diff] [blame] | 117 | const base::FilePath& broker_path) { |
[email protected] | 4967f79 | 2012-01-20 22:14:40 | [diff] [blame] | 118 | for (PpapiBrokerProcessHostIterator iter; !iter.Done(); ++iter) { |
| 119 | if (iter->plugin_path() == broker_path) |
| 120 | return *iter; |
[email protected] | eb415bf0e | 2011-04-14 02:45:42 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | return NULL; |
| 124 | } |
| 125 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 126 | PpapiPluginProcessHost* PluginServiceImpl::FindOrStartPpapiPluginProcess( |
[email protected] | 6be31d20 | 2013-02-01 18:20:54 | [diff] [blame] | 127 | int render_process_id, |
[email protected] | 2dec8ec | 2013-02-07 19:20:34 | [diff] [blame] | 128 | const base::FilePath& plugin_path, |
[email protected] | 8522332e | 2013-08-28 19:42:59 | [diff] [blame] | 129 | const base::FilePath& profile_data_directory) { |
mostynb | 4c27d04 | 2015-03-18 21:47:47 | [diff] [blame] | 130 | DCHECK_CURRENTLY_ON(BrowserThread::IO); |
[email protected] | a08ebea | 2011-02-13 17:50:20 | [diff] [blame] | 131 | |
[email protected] | 132bca8 | 2013-12-10 09:14:47 | [diff] [blame] | 132 | if (filter_ && !filter_->CanLoadPlugin(render_process_id, plugin_path)) { |
| 133 | VLOG(1) << "Unable to load ppapi plugin: " << plugin_path.MaybeAsASCII(); |
[email protected] | 6be31d20 | 2013-02-01 18:20:54 | [diff] [blame] | 134 | return NULL; |
[email protected] | 132bca8 | 2013-12-10 09:14:47 | [diff] [blame] | 135 | } |
[email protected] | 6be31d20 | 2013-02-01 18:20:54 | [diff] [blame] | 136 | |
[email protected] | dd9a095 | 2012-05-31 20:11:31 | [diff] [blame] | 137 | PpapiPluginProcessHost* plugin_host = |
| 138 | FindPpapiPluginProcess(plugin_path, profile_data_directory); |
[email protected] | a08ebea | 2011-02-13 17:50:20 | [diff] [blame] | 139 | if (plugin_host) |
| 140 | return plugin_host; |
| 141 | |
[email protected] | eb415bf0e | 2011-04-14 02:45:42 | [diff] [blame] | 142 | // Validate that the plugin is actually registered. |
[email protected] | 13075767 | 2012-10-24 00:26:19 | [diff] [blame] | 143 | PepperPluginInfo* info = GetRegisteredPpapiPluginInfo(plugin_path); |
[email protected] | 132bca8 | 2013-12-10 09:14:47 | [diff] [blame] | 144 | if (!info) { |
| 145 | VLOG(1) << "Unable to find ppapi plugin registration for: " |
| 146 | << plugin_path.MaybeAsASCII(); |
[email protected] | a08ebea | 2011-02-13 17:50:20 | [diff] [blame] | 147 | return NULL; |
[email protected] | 132bca8 | 2013-12-10 09:14:47 | [diff] [blame] | 148 | } |
[email protected] | a08ebea | 2011-02-13 17:50:20 | [diff] [blame] | 149 | |
[email protected] | fd8d8d6c | 2013-02-28 02:48:33 | [diff] [blame] | 150 | // Record when PPAPI Flash process is started for the first time. |
| 151 | static bool counted = false; |
| 152 | if (!counted && info->name == kFlashPluginName) { |
| 153 | counted = true; |
| 154 | UMA_HISTOGRAM_ENUMERATION("Plugin.FlashUsage", |
| 155 | START_PPAPI_FLASH_AT_LEAST_ONCE, |
| 156 | FLASH_USAGE_ENUM_COUNT); |
| 157 | } |
| 158 | |
[email protected] | a08ebea | 2011-02-13 17:50:20 | [diff] [blame] | 159 | // 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] | 160 | plugin_host = PpapiPluginProcessHost::CreatePluginHost( |
[email protected] | 8522332e | 2013-08-28 19:42:59 | [diff] [blame] | 161 | *info, profile_data_directory); |
[email protected] | 132bca8 | 2013-12-10 09:14:47 | [diff] [blame] | 162 | if (!plugin_host) { |
| 163 | VLOG(1) << "Unable to create ppapi plugin process for: " |
| 164 | << plugin_path.MaybeAsASCII(); |
| 165 | } |
| 166 | |
| 167 | return plugin_host; |
[email protected] | a08ebea | 2011-02-13 17:50:20 | [diff] [blame] | 168 | } |
| 169 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 170 | PpapiPluginProcessHost* PluginServiceImpl::FindOrStartPpapiBrokerProcess( |
[email protected] | 6be31d20 | 2013-02-01 18:20:54 | [diff] [blame] | 171 | int render_process_id, |
[email protected] | 2dec8ec | 2013-02-07 19:20:34 | [diff] [blame] | 172 | const base::FilePath& plugin_path) { |
mostynb | 4c27d04 | 2015-03-18 21:47:47 | [diff] [blame] | 173 | DCHECK_CURRENTLY_ON(BrowserThread::IO); |
[email protected] | eb415bf0e | 2011-04-14 02:45:42 | [diff] [blame] | 174 | |
[email protected] | 6be31d20 | 2013-02-01 18:20:54 | [diff] [blame] | 175 | if (filter_ && !filter_->CanLoadPlugin(render_process_id, plugin_path)) |
| 176 | return NULL; |
| 177 | |
[email protected] | a50432d | 2011-09-30 16:32:14 | [diff] [blame] | 178 | PpapiPluginProcessHost* plugin_host = FindPpapiBrokerProcess(plugin_path); |
[email protected] | eb415bf0e | 2011-04-14 02:45:42 | [diff] [blame] | 179 | if (plugin_host) |
| 180 | return plugin_host; |
| 181 | |
| 182 | // Validate that the plugin is actually registered. |
[email protected] | 13075767 | 2012-10-24 00:26:19 | [diff] [blame] | 183 | PepperPluginInfo* info = GetRegisteredPpapiPluginInfo(plugin_path); |
[email protected] | eb415bf0e | 2011-04-14 02:45:42 | [diff] [blame] | 184 | if (!info) |
| 185 | return NULL; |
| 186 | |
| 187 | // TODO(ddorwin): Uncomment once out of process is supported. |
| 188 | // DCHECK(info->is_out_of_process); |
| 189 | |
| 190 | // 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] | 191 | return PpapiPluginProcessHost::CreateBrokerHost(*info); |
[email protected] | eb415bf0e | 2011-04-14 02:45:42 | [diff] [blame] | 192 | } |
| 193 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 194 | void PluginServiceImpl::OpenChannelToPpapiPlugin( |
[email protected] | 6be31d20 | 2013-02-01 18:20:54 | [diff] [blame] | 195 | int render_process_id, |
[email protected] | 2dec8ec | 2013-02-07 19:20:34 | [diff] [blame] | 196 | const base::FilePath& plugin_path, |
| 197 | const base::FilePath& profile_data_directory, |
[email protected] | a50432d | 2011-09-30 16:32:14 | [diff] [blame] | 198 | PpapiPluginProcessHost::PluginClient* client) { |
[email protected] | d259a8e | 2011-05-18 22:31:09 | [diff] [blame] | 199 | PpapiPluginProcessHost* plugin_host = FindOrStartPpapiPluginProcess( |
[email protected] | 8522332e | 2013-08-28 19:42:59 | [diff] [blame] | 200 | render_process_id, plugin_path, profile_data_directory); |
[email protected] | 1bf0fb2 | 2012-04-12 21:44:16 | [diff] [blame] | 201 | if (plugin_host) { |
[email protected] | a08ebea | 2011-02-13 17:50:20 | [diff] [blame] | 202 | plugin_host->OpenChannelToPlugin(client); |
[email protected] | 1bf0fb2 | 2012-04-12 21:44:16 | [diff] [blame] | 203 | } else { |
| 204 | // Send error. |
[email protected] | 108fd34 | 2013-01-04 20:46:54 | [diff] [blame] | 205 | client->OnPpapiChannelOpened(IPC::ChannelHandle(), base::kNullProcessId, 0); |
[email protected] | 1bf0fb2 | 2012-04-12 21:44:16 | [diff] [blame] | 206 | } |
[email protected] | a08ebea | 2011-02-13 17:50:20 | [diff] [blame] | 207 | } |
| 208 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 209 | void PluginServiceImpl::OpenChannelToPpapiBroker( |
[email protected] | 6be31d20 | 2013-02-01 18:20:54 | [diff] [blame] | 210 | int render_process_id, |
[email protected] | 2dec8ec | 2013-02-07 19:20:34 | [diff] [blame] | 211 | const base::FilePath& path, |
[email protected] | a50432d | 2011-09-30 16:32:14 | [diff] [blame] | 212 | PpapiPluginProcessHost::BrokerClient* client) { |
[email protected] | 6be31d20 | 2013-02-01 18:20:54 | [diff] [blame] | 213 | PpapiPluginProcessHost* plugin_host = FindOrStartPpapiBrokerProcess( |
| 214 | render_process_id, path); |
[email protected] | 1bf0fb2 | 2012-04-12 21:44:16 | [diff] [blame] | 215 | if (plugin_host) { |
[email protected] | a50432d | 2011-09-30 16:32:14 | [diff] [blame] | 216 | plugin_host->OpenChannelToPlugin(client); |
[email protected] | 1bf0fb2 | 2012-04-12 21:44:16 | [diff] [blame] | 217 | } else { |
| 218 | // Send error. |
[email protected] | 108fd34 | 2013-01-04 20:46:54 | [diff] [blame] | 219 | client->OnPpapiChannelOpened(IPC::ChannelHandle(), base::kNullProcessId, 0); |
[email protected] | 1bf0fb2 | 2012-04-12 21:44:16 | [diff] [blame] | 220 | } |
[email protected] | eb415bf0e | 2011-04-14 02:45:42 | [diff] [blame] | 221 | } |
| 222 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 223 | bool PluginServiceImpl::GetPluginInfoArray( |
[email protected] | 51b63f6 | 2011-10-05 18:55:42 | [diff] [blame] | 224 | const GURL& url, |
| 225 | const std::string& mime_type, |
| 226 | bool allow_wildcard, |
[email protected] | d7bd3e5 | 2013-07-21 04:29:20 | [diff] [blame] | 227 | std::vector<WebPluginInfo>* plugins, |
[email protected] | 51b63f6 | 2011-10-05 18:55:42 | [diff] [blame] | 228 | std::vector<std::string>* actual_mime_types) { |
| 229 | bool use_stale = false; |
[email protected] | 29e2fb4 | 2013-07-19 01:13:47 | [diff] [blame] | 230 | PluginList::Singleton()->GetPluginInfoArray( |
piman | e8c57ea | 2016-04-06 01:19:36 | [diff] [blame] | 231 | url, mime_type, allow_wildcard, &use_stale, plugins, actual_mime_types); |
[email protected] | 51b63f6 | 2011-10-05 18:55:42 | [diff] [blame] | 232 | return use_stale; |
| 233 | } |
| 234 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 235 | bool PluginServiceImpl::GetPluginInfo(int render_process_id, |
[email protected] | 60eca4eb | 2013-12-06 00:02:16 | [diff] [blame] | 236 | int render_frame_id, |
[email protected] | 13075767 | 2012-10-24 00:26:19 | [diff] [blame] | 237 | ResourceContext* context, |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 238 | const GURL& url, |
| 239 | const GURL& page_url, |
| 240 | const std::string& mime_type, |
| 241 | bool allow_wildcard, |
| 242 | bool* is_stale, |
[email protected] | d7bd3e5 | 2013-07-21 04:29:20 | [diff] [blame] | 243 | WebPluginInfo* info, |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 244 | std::string* actual_mime_type) { |
[email protected] | d7bd3e5 | 2013-07-21 04:29:20 | [diff] [blame] | 245 | std::vector<WebPluginInfo> plugins; |
[email protected] | 6859807 | 2011-07-29 08:21:28 | [diff] [blame] | 246 | std::vector<std::string> mime_types; |
[email protected] | 88ca491 | 2011-10-12 14:00:43 | [diff] [blame] | 247 | bool stale = GetPluginInfoArray( |
| 248 | url, mime_type, allow_wildcard, &plugins, &mime_types); |
| 249 | if (is_stale) |
| 250 | *is_stale = stale; |
[email protected] | dfba876 | 2011-09-02 12:49:54 | [diff] [blame] | 251 | |
[email protected] | 6859807 | 2011-07-29 08:21:28 | [diff] [blame] | 252 | for (size_t i = 0; i < plugins.size(); ++i) { |
[email protected] | 05f51128 | 2013-02-05 15:02:50 | [diff] [blame] | 253 | if (!filter_ || filter_->IsPluginAvailable(render_process_id, |
[email protected] | 60eca4eb | 2013-12-06 00:02:16 | [diff] [blame] | 254 | render_frame_id, |
[email protected] | 05f51128 | 2013-02-05 15:02:50 | [diff] [blame] | 255 | context, |
| 256 | url, |
| 257 | page_url, |
| 258 | &plugins[i])) { |
[email protected] | 6859807 | 2011-07-29 08:21:28 | [diff] [blame] | 259 | *info = plugins[i]; |
| 260 | if (actual_mime_type) |
| 261 | *actual_mime_type = mime_types[i]; |
| 262 | return true; |
| 263 | } |
| 264 | } |
| 265 | return false; |
[email protected] | 6fdd418 | 2010-10-14 23:59:26 | [diff] [blame] | 266 | } |
| 267 | |
[email protected] | 2dec8ec | 2013-02-07 19:20:34 | [diff] [blame] | 268 | bool PluginServiceImpl::GetPluginInfoByPath(const base::FilePath& plugin_path, |
[email protected] | d7bd3e5 | 2013-07-21 04:29:20 | [diff] [blame] | 269 | WebPluginInfo* info) { |
| 270 | std::vector<WebPluginInfo> plugins; |
[email protected] | 29e2fb4 | 2013-07-19 01:13:47 | [diff] [blame] | 271 | PluginList::Singleton()->GetPluginsNoRefresh(&plugins); |
[email protected] | 88ca491 | 2011-10-12 14:00:43 | [diff] [blame] | 272 | |
[email protected] | d7bd3e5 | 2013-07-21 04:29:20 | [diff] [blame] | 273 | for (std::vector<WebPluginInfo>::iterator it = plugins.begin(); |
[email protected] | 88ca491 | 2011-10-12 14:00:43 | [diff] [blame] | 274 | it != plugins.end(); |
| 275 | ++it) { |
| 276 | if (it->path == plugin_path) { |
| 277 | *info = *it; |
| 278 | return true; |
| 279 | } |
| 280 | } |
| 281 | |
| 282 | return false; |
| 283 | } |
| 284 | |
[email protected] | fcf75d4 | 2013-12-03 20:11:26 | [diff] [blame] | 285 | base::string16 PluginServiceImpl::GetPluginDisplayNameByPath( |
[email protected] | 2dec8ec | 2013-02-07 19:20:34 | [diff] [blame] | 286 | const base::FilePath& path) { |
[email protected] | fcf75d4 | 2013-12-03 20:11:26 | [diff] [blame] | 287 | base::string16 plugin_name = path.LossyDisplayName(); |
[email protected] | d7bd3e5 | 2013-07-21 04:29:20 | [diff] [blame] | 288 | WebPluginInfo info; |
[email protected] | 8be4584 | 2012-04-13 19:49:29 | [diff] [blame] | 289 | if (PluginService::GetInstance()->GetPluginInfoByPath(path, &info) && |
| 290 | !info.name.empty()) { |
| 291 | plugin_name = info.name; |
| 292 | #if defined(OS_MACOSX) |
| 293 | // Many plugins on the Mac have .plugin in the actual name, which looks |
| 294 | // terrible, so look for that and strip it off if present. |
| 295 | const std::string kPluginExtension = ".plugin"; |
brettw | a7ff1b29 | 2015-07-16 17:49:29 | [diff] [blame] | 296 | if (base::EndsWith(plugin_name, base::ASCIIToUTF16(kPluginExtension), |
| 297 | base::CompareCase::SENSITIVE)) |
[email protected] | 8be4584 | 2012-04-13 19:49:29 | [diff] [blame] | 298 | plugin_name.erase(plugin_name.length() - kPluginExtension.length()); |
| 299 | #endif // OS_MACOSX |
| 300 | } |
| 301 | return plugin_name; |
| 302 | } |
| 303 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 304 | void PluginServiceImpl::GetPlugins(const GetPluginsCallback& callback) { |
skyostil | 95082a6 | 2015-06-05 19:53:07 | [diff] [blame] | 305 | scoped_refptr<base::SingleThreadTaskRunner> target_task_runner( |
| 306 | base::ThreadTaskRunnerHandle::Get()); |
[email protected] | 4912595 | 2011-09-27 18:05:15 | [diff] [blame] | 307 | |
piman | e8c57ea | 2016-04-06 01:19:36 | [diff] [blame] | 308 | BrowserThread::GetBlockingPool()->PostSequencedWorkerTaskWithShutdownBehavior( |
| 309 | plugin_list_token_, FROM_HERE, |
| 310 | base::Bind(&PluginServiceImpl::GetPluginsInternal, base::Unretained(this), |
| 311 | base::RetainedRef(target_task_runner), callback), |
| 312 | base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); |
[email protected] | d33e7cc | 2011-09-23 01:43:56 | [diff] [blame] | 313 | } |
| 314 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 315 | void PluginServiceImpl::GetPluginsInternal( |
skyostil | 95082a6 | 2015-06-05 19:53:07 | [diff] [blame] | 316 | base::SingleThreadTaskRunner* target_task_runner, |
| 317 | const PluginService::GetPluginsCallback& callback) { |
[email protected] | a33fa9d | 2012-05-16 14:47:49 | [diff] [blame] | 318 | DCHECK(BrowserThread::GetBlockingPool()->IsRunningSequenceOnCurrentThread( |
| 319 | plugin_list_token_)); |
[email protected] | d33e7cc | 2011-09-23 01:43:56 | [diff] [blame] | 320 | |
[email protected] | d7bd3e5 | 2013-07-21 04:29:20 | [diff] [blame] | 321 | std::vector<WebPluginInfo> plugins; |
piman | e8c57ea | 2016-04-06 01:19:36 | [diff] [blame] | 322 | PluginList::Singleton()->GetPlugins(&plugins); |
[email protected] | d33e7cc | 2011-09-23 01:43:56 | [diff] [blame] | 323 | |
skyostil | 95082a6 | 2015-06-05 19:53:07 | [diff] [blame] | 324 | target_task_runner->PostTask(FROM_HERE, base::Bind(callback, plugins)); |
[email protected] | dfba876 | 2011-09-02 12:49:54 | [diff] [blame] | 325 | } |
| 326 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 327 | void PluginServiceImpl::RegisterPepperPlugins() { |
[email protected] | dac6a5a | 2013-07-25 05:06:48 | [diff] [blame] | 328 | ComputePepperPluginList(&ppapi_plugins_); |
[email protected] | a08ebea | 2011-02-13 17:50:20 | [diff] [blame] | 329 | for (size_t i = 0; i < ppapi_plugins_.size(); ++i) { |
[email protected] | c6f3dea | 2012-01-14 02:23:11 | [diff] [blame] | 330 | RegisterInternalPlugin(ppapi_plugins_[i].ToWebPluginInfo(), true); |
[email protected] | 4e0616e | 2010-05-28 14:55:53 | [diff] [blame] | 331 | } |
| 332 | } |
[email protected] | 634d23d | 2011-01-19 10:38:19 | [diff] [blame] | 333 | |
[email protected] | eb415bf0e | 2011-04-14 02:45:42 | [diff] [blame] | 334 | // 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] | 335 | PepperPluginInfo* PluginServiceImpl::GetRegisteredPpapiPluginInfo( |
[email protected] | 2dec8ec | 2013-02-07 19:20:34 | [diff] [blame] | 336 | const base::FilePath& plugin_path) { |
[email protected] | 3627aa3f | 2013-09-17 22:32:51 | [diff] [blame] | 337 | for (size_t i = 0; i < ppapi_plugins_.size(); ++i) { |
thestig | 76ee1f4 | 2016-07-08 18:54:00 | [diff] [blame] | 338 | if (ppapi_plugins_[i].path == plugin_path) |
| 339 | return &ppapi_plugins_[i]; |
[email protected] | eb415bf0e | 2011-04-14 02:45:42 | [diff] [blame] | 340 | } |
[email protected] | 07611759 | 2011-08-17 03:16:41 | [diff] [blame] | 341 | // We did not find the plugin in our list. But wait! the plugin can also |
| 342 | // be a latecomer, as it happens with pepper flash. This information |
| 343 | // can be obtained from the PluginList singleton and we can use it to |
| 344 | // construct it and add it to the list. This same deal needs to be done |
| 345 | // in the renderer side in PepperPluginRegistry. |
[email protected] | d7bd3e5 | 2013-07-21 04:29:20 | [diff] [blame] | 346 | WebPluginInfo webplugin_info; |
[email protected] | 88ca491 | 2011-10-12 14:00:43 | [diff] [blame] | 347 | if (!GetPluginInfoByPath(plugin_path, &webplugin_info)) |
thestig | 76ee1f4 | 2016-07-08 18:54:00 | [diff] [blame] | 348 | return nullptr; |
[email protected] | 13075767 | 2012-10-24 00:26:19 | [diff] [blame] | 349 | PepperPluginInfo new_pepper_info; |
[email protected] | 07611759 | 2011-08-17 03:16:41 | [diff] [blame] | 350 | if (!MakePepperPluginInfo(webplugin_info, &new_pepper_info)) |
thestig | 76ee1f4 | 2016-07-08 18:54:00 | [diff] [blame] | 351 | return nullptr; |
[email protected] | 07611759 | 2011-08-17 03:16:41 | [diff] [blame] | 352 | ppapi_plugins_.push_back(new_pepper_info); |
thestig | 76ee1f4 | 2016-07-08 18:54:00 | [diff] [blame] | 353 | return &ppapi_plugins_.back(); |
[email protected] | eb415bf0e | 2011-04-14 02:45:42 | [diff] [blame] | 354 | } |
| 355 | |
[email protected] | 13075767 | 2012-10-24 00:26:19 | [diff] [blame] | 356 | void PluginServiceImpl::SetFilter(PluginServiceFilter* filter) { |
[email protected] | 3a5180ae | 2011-12-21 02:39:38 | [diff] [blame] | 357 | filter_ = filter; |
| 358 | } |
| 359 | |
[email protected] | 13075767 | 2012-10-24 00:26:19 | [diff] [blame] | 360 | PluginServiceFilter* PluginServiceImpl::GetFilter() { |
[email protected] | 3a5180ae | 2011-12-21 02:39:38 | [diff] [blame] | 361 | return filter_; |
| 362 | } |
| 363 | |
[email protected] | 47214d88 | 2012-02-29 06:28:48 | [diff] [blame] | 364 | static const unsigned int kMaxCrashesPerInterval = 3; |
| 365 | static const unsigned int kCrashesInterval = 120; |
| 366 | |
[email protected] | 2dec8ec | 2013-02-07 19:20:34 | [diff] [blame] | 367 | void PluginServiceImpl::RegisterPluginCrash(const base::FilePath& path) { |
mostynb | 4c27d04 | 2015-03-18 21:47:47 | [diff] [blame] | 368 | DCHECK_CURRENTLY_ON(BrowserThread::IO); |
[email protected] | 2dec8ec | 2013-02-07 19:20:34 | [diff] [blame] | 369 | std::map<base::FilePath, std::vector<base::Time> >::iterator i = |
[email protected] | 47214d88 | 2012-02-29 06:28:48 | [diff] [blame] | 370 | crash_times_.find(path); |
| 371 | if (i == crash_times_.end()) { |
| 372 | crash_times_[path] = std::vector<base::Time>(); |
| 373 | i = crash_times_.find(path); |
| 374 | } |
| 375 | if (i->second.size() == kMaxCrashesPerInterval) { |
| 376 | i->second.erase(i->second.begin()); |
| 377 | } |
| 378 | base::Time time = base::Time::Now(); |
| 379 | i->second.push_back(time); |
| 380 | } |
| 381 | |
[email protected] | 2dec8ec | 2013-02-07 19:20:34 | [diff] [blame] | 382 | bool PluginServiceImpl::IsPluginUnstable(const base::FilePath& path) { |
mostynb | 4c27d04 | 2015-03-18 21:47:47 | [diff] [blame] | 383 | DCHECK_CURRENTLY_ON(BrowserThread::IO); |
[email protected] | 2dec8ec | 2013-02-07 19:20:34 | [diff] [blame] | 384 | std::map<base::FilePath, std::vector<base::Time> >::const_iterator i = |
[email protected] | 47214d88 | 2012-02-29 06:28:48 | [diff] [blame] | 385 | crash_times_.find(path); |
| 386 | if (i == crash_times_.end()) { |
| 387 | return false; |
| 388 | } |
| 389 | if (i->second.size() != kMaxCrashesPerInterval) { |
| 390 | return false; |
| 391 | } |
| 392 | base::TimeDelta delta = base::Time::Now() - i->second[0]; |
[email protected] | d8c7006 | 2013-04-24 00:22:34 | [diff] [blame] | 393 | return delta.InSeconds() <= kCrashesInterval; |
[email protected] | 47214d88 | 2012-02-29 06:28:48 | [diff] [blame] | 394 | } |
| 395 | |
[email protected] | e67385f | 2011-12-21 06:00:56 | [diff] [blame] | 396 | void PluginServiceImpl::RefreshPlugins() { |
[email protected] | 29e2fb4 | 2013-07-19 01:13:47 | [diff] [blame] | 397 | PluginList::Singleton()->RefreshPlugins(); |
[email protected] | f520b5b | 2011-11-08 02:42:14 | [diff] [blame] | 398 | } |
| 399 | |
[email protected] | 8f337212 | 2013-07-18 04:34:14 | [diff] [blame] | 400 | void PluginServiceImpl::RegisterInternalPlugin( |
[email protected] | d7bd3e5 | 2013-07-21 04:29:20 | [diff] [blame] | 401 | const WebPluginInfo& info, |
[email protected] | 8f337212 | 2013-07-18 04:34:14 | [diff] [blame] | 402 | bool add_at_beginning) { |
[email protected] | 29e2fb4 | 2013-07-19 01:13:47 | [diff] [blame] | 403 | PluginList::Singleton()->RegisterInternalPlugin(info, add_at_beginning); |
[email protected] | f520b5b | 2011-11-08 02:42:14 | [diff] [blame] | 404 | } |
| 405 | |
[email protected] | 2dec8ec | 2013-02-07 19:20:34 | [diff] [blame] | 406 | void PluginServiceImpl::UnregisterInternalPlugin(const base::FilePath& path) { |
[email protected] | 29e2fb4 | 2013-07-19 01:13:47 | [diff] [blame] | 407 | PluginList::Singleton()->UnregisterInternalPlugin(path); |
[email protected] | f520b5b | 2011-11-08 02:42:14 | [diff] [blame] | 408 | } |
| 409 | |
[email protected] | 8f337212 | 2013-07-18 04:34:14 | [diff] [blame] | 410 | void PluginServiceImpl::GetInternalPlugins( |
[email protected] | d7bd3e5 | 2013-07-21 04:29:20 | [diff] [blame] | 411 | std::vector<WebPluginInfo>* plugins) { |
[email protected] | 29e2fb4 | 2013-07-19 01:13:47 | [diff] [blame] | 412 | PluginList::Singleton()->GetInternalPlugins(plugins); |
[email protected] | 8f337212 | 2013-07-18 04:34:14 | [diff] [blame] | 413 | } |
| 414 | |
[email protected] | aec5ed5 | 2014-06-20 07:51:42 | [diff] [blame] | 415 | bool PluginServiceImpl::PpapiDevChannelSupported( |
| 416 | BrowserContext* browser_context, |
| 417 | const GURL& document_url) { |
wfh | 6be0628 | 2015-07-20 18:04:02 | [diff] [blame] | 418 | return GetContentClient()->browser()->IsPluginAllowedToUseDevChannelAPIs( |
| 419 | browser_context, document_url); |
[email protected] | 8ddc6b7c | 2013-12-12 20:42:06 | [diff] [blame] | 420 | } |
| 421 | |
[email protected] | 13075767 | 2012-10-24 00:26:19 | [diff] [blame] | 422 | } // namespace content |