blob: 0378ab3c501348fb65a6329e09b7c014c62c5dc6 [file] [log] [blame]
[email protected]3b48dbc2012-01-06 16:34:171// Copyright (c) 2012 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
[email protected]e67385f2011-12-21 06:00:565#include "content/browser/plugin_service_impl.h"
initial.commit09911bf2008-07-26 23:55:296
avib7348942015-12-25 20:57:107#include <stddef.h>
8
fdoray9292e0722017-05-13 03:47:519#include <utility>
10
[email protected]d33e7cc2011-09-23 01:43:5611#include "base/bind.h"
[email protected]d48f1e0c2009-02-12 20:57:5412#include "base/command_line.h"
[email protected]7b3ee8b2011-04-01 18:48:1913#include "base/compiler_specific.h"
[email protected]57999812013-02-24 05:40:5214#include "base/files/file_path.h"
skyostil95082a62015-06-05 19:53:0715#include "base/location.h"
fdoray5e1706c32016-09-08 12:57:0916#include "base/logging.h"
asvitkine30330812016-08-30 04:01:0817#include "base/metrics/histogram_macros.h"
[email protected]348fbaac2013-06-11 06:31:5118#include "base/strings/string_util.h"
[email protected]74ebfb12013-06-07 20:48:0019#include "base/strings/utf_string_conversions.h"
[email protected]7f070d42011-03-09 20:25:3220#include "base/synchronization/waitable_event.h"
fdoray9292e0722017-05-13 03:47:5121#include "base/task_runner_util.h"
fdoraycc22a38d2017-04-27 06:56:3922#include "base/task_scheduler/post_task.h"
[email protected]34b99632011-01-01 01:01:0623#include "base/threading/thread.h"
avib7348942015-12-25 20:57:1024#include "build/build_config.h"
[email protected]a01efd22011-03-01 00:38:3225#include "content/browser/ppapi_plugin_process_host.h"
[email protected]f3b1a082011-11-18 00:34:3026#include "content/browser/renderer_host/render_process_host_impl.h"
[email protected]b3c41c0b2012-03-06 15:48:3227#include "content/browser/renderer_host/render_view_host_impl.h"
wfh1a90e032015-04-14 17:10:1728#include "content/common/content_switches_internal.h"
[email protected]dac6a5a2013-07-25 05:06:4829#include "content/common/pepper_plugin_list.h"
[email protected]29e2fb42013-07-19 01:13:4730#include "content/common/plugin_list.h"
[email protected]38b592902011-04-16 02:08:4231#include "content/common/view_messages.h"
[email protected]c38831a12011-10-28 12:44:4932#include "content/public/browser/browser_thread.h"
[email protected]87f3c082011-10-19 18:07:4433#include "content/public/browser/content_browser_client.h"
[email protected]31f376c2012-03-13 16:43:0934#include "content/public/browser/plugin_service_filter.h"
Raymes Khoury978652c2017-11-27 06:28:3735#include "content/public/browser/render_frame_host.h"
[email protected]ce967862012-02-09 22:47:0536#include "content/public/browser/resource_context.h"
Raymes Khoury978652c2017-11-27 06:28:3737#include "content/public/browser/web_contents.h"
[email protected]73270292013-08-09 03:48:0738#include "content/public/common/content_constants.h"
[email protected]c08950d22011-10-13 22:20:2939#include "content/public/common/content_switches.h"
[email protected]bd5d6cf2011-12-01 00:39:1240#include "content/public/common/process_type.h"
[email protected]d7bd3e52013-07-21 04:29:2041#include "content/public/common/webplugininfo.h"
Raymes Khoury978652c2017-11-27 06:28:3742#include "services/metrics/public/cpp/ukm_builders.h"
[email protected]191eb3f72010-12-21 06:27:5043
[email protected]130757672012-10-24 00:26:1944namespace content {
[email protected]d33e7cc2011-09-23 01:43:5645namespace {
46
[email protected]fd8d8d6c2013-02-28 02:48:3347// This enum is used to collect Flash usage data.
48enum FlashUsage {
[email protected]fd8d8d6c2013-02-28 02:48:3349 // Number of browser processes that have started at least one PPAPI Flash
50 // process during their lifetime.
pimane8c57ea2016-04-06 01:19:3651 START_PPAPI_FLASH_AT_LEAST_ONCE = 1,
[email protected]fd8d8d6c2013-02-28 02:48:3352 // Total number of browser processes.
53 TOTAL_BROWSER_PROCESSES,
54 FLASH_USAGE_ENUM_COUNT
55};
56
[email protected]49125952011-09-27 18:05:1557// Callback set on the PluginList to assert that plugin loading happens on the
58// correct thread.
fdoray5e1706c32016-09-08 12:57:0959void WillLoadPluginsCallback(base::SequenceChecker* sequence_checker) {
60 DCHECK(sequence_checker->CalledOnValidSequence());
[email protected]a79912252012-05-16 11:52:1961}
[email protected]d33e7cc2011-09-23 01:43:5662
Raymes Khoury978652c2017-11-27 06:28:3763void RecordBrokerUsage(int render_process_id, int render_frame_id) {
64 ukm::UkmRecorder* recorder = ukm::UkmRecorder::Get();
65 ukm::SourceId source_id = ukm::UkmRecorder::GetNewSourceID();
66 WebContents* web_contents = WebContents::FromRenderFrameHost(
67 RenderFrameHost::FromID(render_process_id, render_frame_id));
68 if (web_contents) {
69 recorder->UpdateSourceURL(source_id, web_contents->GetLastCommittedURL());
70 ukm::builders::Pepper_Broker(source_id).Record(recorder);
71 }
72}
73
[email protected]07b71c82013-01-08 19:07:3174} // namespace
75
[email protected]3a5180ae2011-12-21 02:39:3876// static
77PluginService* PluginService::GetInstance() {
[email protected]e67385f2011-12-21 06:00:5678 return PluginServiceImpl::GetInstance();
[email protected]3a5180ae2011-12-21 02:39:3879}
80
81void PluginService::PurgePluginListCache(BrowserContext* browser_context,
82 bool reload_pages) {
83 for (RenderProcessHost::iterator it = RenderProcessHost::AllHostsIterator();
84 !it.IsAtEnd(); it.Advance()) {
85 RenderProcessHost* host = it.GetCurrentValue();
86 if (!browser_context || host->GetBrowserContext() == browser_context)
rockota2db0da2016-10-18 17:39:1187 host->GetRendererInterface()->PurgePluginListCache(reload_pages);
[email protected]3a5180ae2011-12-21 02:39:3888 }
89}
90
initial.commit09911bf2008-07-26 23:55:2991// static
[email protected]e67385f2011-12-21 06:00:5692PluginServiceImpl* PluginServiceImpl::GetInstance() {
olli.raula36aa8be2015-09-10 11:14:2293 return base::Singleton<PluginServiceImpl>::get();
initial.commit09911bf2008-07-26 23:55:2994}
95
Ivan Kotenkov2c0d2bb32017-11-01 15:41:2896PluginServiceImpl::PluginServiceImpl() : filter_(nullptr) {
fdoray5e1706c32016-09-08 12:57:0997 plugin_list_sequence_checker_.DetachFromSequence();
98
[email protected]fd8d8d6c2013-02-28 02:48:3399 // Collect the total number of browser processes (which create
100 // PluginServiceImpl objects, to be precise). The number is used to normalize
101 // the number of processes which start at least one NPAPI/PPAPI Flash process.
102 static bool counted = false;
103 if (!counted) {
104 counted = true;
105 UMA_HISTOGRAM_ENUMERATION("Plugin.FlashUsage", TOTAL_BROWSER_PROCESSES,
106 FLASH_USAGE_ENUM_COUNT);
107 }
[email protected]ee066172011-11-10 23:20:05108}
109
[email protected]e67385f2011-12-21 06:00:56110PluginServiceImpl::~PluginServiceImpl() {
[email protected]ee066172011-11-10 23:20:05111}
112
[email protected]e67385f2011-12-21 06:00:56113void PluginServiceImpl::Init() {
fdoraycc22a38d2017-04-27 06:56:39114 plugin_list_task_runner_ = base::CreateSequencedTaskRunnerWithTraits(
fdoray27b0b2a2017-05-04 19:52:08115 {base::MayBlock(), base::TaskPriority::USER_VISIBLE,
116 base::TaskShutdownBehavior::SKIP_ON_SHUTDOWN});
[email protected]29e2fb42013-07-19 01:13:47117 PluginList::Singleton()->set_will_load_plugins_callback(
fdoray5e1706c32016-09-08 12:57:09118 base::Bind(&WillLoadPluginsCallback, &plugin_list_sequence_checker_));
[email protected]49125952011-09-27 18:05:15119
[email protected]4e0616e2010-05-28 14:55:53120 RegisterPepperPlugins();
initial.commit09911bf2008-07-26 23:55:29121}
122
[email protected]e67385f2011-12-21 06:00:56123PpapiPluginProcessHost* PluginServiceImpl::FindPpapiPluginProcess(
[email protected]2dec8ec2013-02-07 19:20:34124 const base::FilePath& plugin_path,
125 const base::FilePath& profile_data_directory) {
[email protected]4967f792012-01-20 22:14:40126 for (PpapiPluginProcessHostIterator iter; !iter.Done(); ++iter) {
[email protected]dd9a0952012-05-31 20:11:31127 if (iter->plugin_path() == plugin_path &&
128 iter->profile_data_directory() == profile_data_directory) {
[email protected]4967f792012-01-20 22:14:40129 return *iter;
[email protected]dd9a0952012-05-31 20:11:31130 }
[email protected]a08ebea2011-02-13 17:50:20131 }
Ivan Kotenkov2c0d2bb32017-11-01 15:41:28132 return nullptr;
[email protected]a08ebea2011-02-13 17:50:20133}
134
[email protected]e67385f2011-12-21 06:00:56135PpapiPluginProcessHost* PluginServiceImpl::FindPpapiBrokerProcess(
[email protected]2dec8ec2013-02-07 19:20:34136 const base::FilePath& broker_path) {
[email protected]4967f792012-01-20 22:14:40137 for (PpapiBrokerProcessHostIterator iter; !iter.Done(); ++iter) {
138 if (iter->plugin_path() == broker_path)
139 return *iter;
[email protected]eb415bf0e2011-04-14 02:45:42140 }
141
Ivan Kotenkov2c0d2bb32017-11-01 15:41:28142 return nullptr;
[email protected]eb415bf0e2011-04-14 02:45:42143}
144
[email protected]e67385f2011-12-21 06:00:56145PpapiPluginProcessHost* PluginServiceImpl::FindOrStartPpapiPluginProcess(
[email protected]6be31d202013-02-01 18:20:54146 int render_process_id,
[email protected]2dec8ec2013-02-07 19:20:34147 const base::FilePath& plugin_path,
[email protected]8522332e2013-08-28 19:42:59148 const base::FilePath& profile_data_directory) {
mostynb4c27d042015-03-18 21:47:47149 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]a08ebea2011-02-13 17:50:20150
[email protected]132bca82013-12-10 09:14:47151 if (filter_ && !filter_->CanLoadPlugin(render_process_id, plugin_path)) {
152 VLOG(1) << "Unable to load ppapi plugin: " << plugin_path.MaybeAsASCII();
Ivan Kotenkov2c0d2bb32017-11-01 15:41:28153 return nullptr;
[email protected]132bca82013-12-10 09:14:47154 }
[email protected]6be31d202013-02-01 18:20:54155
[email protected]dd9a0952012-05-31 20:11:31156 PpapiPluginProcessHost* plugin_host =
157 FindPpapiPluginProcess(plugin_path, profile_data_directory);
[email protected]a08ebea2011-02-13 17:50:20158 if (plugin_host)
159 return plugin_host;
160
[email protected]eb415bf0e2011-04-14 02:45:42161 // Validate that the plugin is actually registered.
[email protected]130757672012-10-24 00:26:19162 PepperPluginInfo* info = GetRegisteredPpapiPluginInfo(plugin_path);
[email protected]132bca82013-12-10 09:14:47163 if (!info) {
164 VLOG(1) << "Unable to find ppapi plugin registration for: "
165 << plugin_path.MaybeAsASCII();
Ivan Kotenkov2c0d2bb32017-11-01 15:41:28166 return nullptr;
[email protected]132bca82013-12-10 09:14:47167 }
[email protected]a08ebea2011-02-13 17:50:20168
[email protected]fd8d8d6c2013-02-28 02:48:33169 // Record when PPAPI Flash process is started for the first time.
170 static bool counted = false;
171 if (!counted && info->name == kFlashPluginName) {
172 counted = true;
173 UMA_HISTOGRAM_ENUMERATION("Plugin.FlashUsage",
174 START_PPAPI_FLASH_AT_LEAST_ONCE,
175 FLASH_USAGE_ENUM_COUNT);
176 }
177
[email protected]a08ebea2011-02-13 17:50:20178 // This plugin isn't loaded by any plugin process, so create a new process.
[email protected]132bca82013-12-10 09:14:47179 plugin_host = PpapiPluginProcessHost::CreatePluginHost(
[email protected]8522332e2013-08-28 19:42:59180 *info, profile_data_directory);
[email protected]132bca82013-12-10 09:14:47181 if (!plugin_host) {
182 VLOG(1) << "Unable to create ppapi plugin process for: "
183 << plugin_path.MaybeAsASCII();
184 }
185
186 return plugin_host;
[email protected]a08ebea2011-02-13 17:50:20187}
188
[email protected]e67385f2011-12-21 06:00:56189PpapiPluginProcessHost* PluginServiceImpl::FindOrStartPpapiBrokerProcess(
[email protected]6be31d202013-02-01 18:20:54190 int render_process_id,
[email protected]2dec8ec2013-02-07 19:20:34191 const base::FilePath& plugin_path) {
mostynb4c27d042015-03-18 21:47:47192 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]eb415bf0e2011-04-14 02:45:42193
[email protected]6be31d202013-02-01 18:20:54194 if (filter_ && !filter_->CanLoadPlugin(render_process_id, plugin_path))
Ivan Kotenkov2c0d2bb32017-11-01 15:41:28195 return nullptr;
[email protected]6be31d202013-02-01 18:20:54196
[email protected]a50432d2011-09-30 16:32:14197 PpapiPluginProcessHost* plugin_host = FindPpapiBrokerProcess(plugin_path);
[email protected]eb415bf0e2011-04-14 02:45:42198 if (plugin_host)
199 return plugin_host;
200
201 // Validate that the plugin is actually registered.
[email protected]130757672012-10-24 00:26:19202 PepperPluginInfo* info = GetRegisteredPpapiPluginInfo(plugin_path);
[email protected]eb415bf0e2011-04-14 02:45:42203 if (!info)
Ivan Kotenkov2c0d2bb32017-11-01 15:41:28204 return nullptr;
[email protected]eb415bf0e2011-04-14 02:45:42205
206 // TODO(ddorwin): Uncomment once out of process is supported.
207 // DCHECK(info->is_out_of_process);
208
209 // This broker isn't loaded by any broker process, so create a new process.
[email protected]a50432d2011-09-30 16:32:14210 return PpapiPluginProcessHost::CreateBrokerHost(*info);
[email protected]eb415bf0e2011-04-14 02:45:42211}
212
[email protected]e67385f2011-12-21 06:00:56213void PluginServiceImpl::OpenChannelToPpapiPlugin(
[email protected]6be31d202013-02-01 18:20:54214 int render_process_id,
[email protected]2dec8ec2013-02-07 19:20:34215 const base::FilePath& plugin_path,
216 const base::FilePath& profile_data_directory,
[email protected]a50432d2011-09-30 16:32:14217 PpapiPluginProcessHost::PluginClient* client) {
[email protected]d259a8e2011-05-18 22:31:09218 PpapiPluginProcessHost* plugin_host = FindOrStartPpapiPluginProcess(
[email protected]8522332e2013-08-28 19:42:59219 render_process_id, plugin_path, profile_data_directory);
[email protected]1bf0fb22012-04-12 21:44:16220 if (plugin_host) {
[email protected]a08ebea2011-02-13 17:50:20221 plugin_host->OpenChannelToPlugin(client);
[email protected]1bf0fb22012-04-12 21:44:16222 } else {
223 // Send error.
[email protected]108fd342013-01-04 20:46:54224 client->OnPpapiChannelOpened(IPC::ChannelHandle(), base::kNullProcessId, 0);
[email protected]1bf0fb22012-04-12 21:44:16225 }
[email protected]a08ebea2011-02-13 17:50:20226}
227
[email protected]e67385f2011-12-21 06:00:56228void PluginServiceImpl::OpenChannelToPpapiBroker(
[email protected]6be31d202013-02-01 18:20:54229 int render_process_id,
Raymes Khoury978652c2017-11-27 06:28:37230 int render_frame_id,
[email protected]2dec8ec2013-02-07 19:20:34231 const base::FilePath& path,
[email protected]a50432d2011-09-30 16:32:14232 PpapiPluginProcessHost::BrokerClient* client) {
Raymes Khoury978652c2017-11-27 06:28:37233 BrowserThread::PostTask(
234 BrowserThread::UI, FROM_HERE,
235 base::Bind(&RecordBrokerUsage, render_process_id, render_frame_id));
236
[email protected]6be31d202013-02-01 18:20:54237 PpapiPluginProcessHost* plugin_host = FindOrStartPpapiBrokerProcess(
238 render_process_id, path);
[email protected]1bf0fb22012-04-12 21:44:16239 if (plugin_host) {
[email protected]a50432d2011-09-30 16:32:14240 plugin_host->OpenChannelToPlugin(client);
[email protected]1bf0fb22012-04-12 21:44:16241 } else {
242 // Send error.
[email protected]108fd342013-01-04 20:46:54243 client->OnPpapiChannelOpened(IPC::ChannelHandle(), base::kNullProcessId, 0);
[email protected]1bf0fb22012-04-12 21:44:16244 }
[email protected]eb415bf0e2011-04-14 02:45:42245}
246
[email protected]e67385f2011-12-21 06:00:56247bool PluginServiceImpl::GetPluginInfoArray(
[email protected]51b63f62011-10-05 18:55:42248 const GURL& url,
249 const std::string& mime_type,
250 bool allow_wildcard,
[email protected]d7bd3e52013-07-21 04:29:20251 std::vector<WebPluginInfo>* plugins,
[email protected]51b63f62011-10-05 18:55:42252 std::vector<std::string>* actual_mime_types) {
253 bool use_stale = false;
[email protected]29e2fb42013-07-19 01:13:47254 PluginList::Singleton()->GetPluginInfoArray(
pimane8c57ea2016-04-06 01:19:36255 url, mime_type, allow_wildcard, &use_stale, plugins, actual_mime_types);
[email protected]51b63f62011-10-05 18:55:42256 return use_stale;
257}
258
[email protected]e67385f2011-12-21 06:00:56259bool PluginServiceImpl::GetPluginInfo(int render_process_id,
[email protected]60eca4eb2013-12-06 00:02:16260 int render_frame_id,
[email protected]130757672012-10-24 00:26:19261 ResourceContext* context,
[email protected]e67385f2011-12-21 06:00:56262 const GURL& url,
tommyclif2a1e9f2016-10-06 18:34:36263 const url::Origin& main_frame_origin,
[email protected]e67385f2011-12-21 06:00:56264 const std::string& mime_type,
265 bool allow_wildcard,
266 bool* is_stale,
[email protected]d7bd3e52013-07-21 04:29:20267 WebPluginInfo* info,
[email protected]e67385f2011-12-21 06:00:56268 std::string* actual_mime_type) {
[email protected]d7bd3e52013-07-21 04:29:20269 std::vector<WebPluginInfo> plugins;
[email protected]68598072011-07-29 08:21:28270 std::vector<std::string> mime_types;
[email protected]88ca4912011-10-12 14:00:43271 bool stale = GetPluginInfoArray(
272 url, mime_type, allow_wildcard, &plugins, &mime_types);
273 if (is_stale)
274 *is_stale = stale;
[email protected]dfba8762011-09-02 12:49:54275
[email protected]68598072011-07-29 08:21:28276 for (size_t i = 0; i < plugins.size(); ++i) {
tommyclif2a1e9f2016-10-06 18:34:36277 if (!filter_ ||
278 filter_->IsPluginAvailable(render_process_id, render_frame_id, context,
279 url, main_frame_origin, &plugins[i])) {
[email protected]68598072011-07-29 08:21:28280 *info = plugins[i];
281 if (actual_mime_type)
282 *actual_mime_type = mime_types[i];
283 return true;
284 }
285 }
286 return false;
[email protected]6fdd4182010-10-14 23:59:26287}
288
[email protected]2dec8ec2013-02-07 19:20:34289bool PluginServiceImpl::GetPluginInfoByPath(const base::FilePath& plugin_path,
[email protected]d7bd3e52013-07-21 04:29:20290 WebPluginInfo* info) {
291 std::vector<WebPluginInfo> plugins;
[email protected]29e2fb42013-07-19 01:13:47292 PluginList::Singleton()->GetPluginsNoRefresh(&plugins);
[email protected]88ca4912011-10-12 14:00:43293
[email protected]d7bd3e52013-07-21 04:29:20294 for (std::vector<WebPluginInfo>::iterator it = plugins.begin();
[email protected]88ca4912011-10-12 14:00:43295 it != plugins.end();
296 ++it) {
297 if (it->path == plugin_path) {
298 *info = *it;
299 return true;
300 }
301 }
302
303 return false;
304}
305
[email protected]fcf75d42013-12-03 20:11:26306base::string16 PluginServiceImpl::GetPluginDisplayNameByPath(
[email protected]2dec8ec2013-02-07 19:20:34307 const base::FilePath& path) {
[email protected]fcf75d42013-12-03 20:11:26308 base::string16 plugin_name = path.LossyDisplayName();
[email protected]d7bd3e52013-07-21 04:29:20309 WebPluginInfo info;
[email protected]8be45842012-04-13 19:49:29310 if (PluginService::GetInstance()->GetPluginInfoByPath(path, &info) &&
311 !info.name.empty()) {
312 plugin_name = info.name;
313#if defined(OS_MACOSX)
314 // Many plugins on the Mac have .plugin in the actual name, which looks
315 // terrible, so look for that and strip it off if present.
316 const std::string kPluginExtension = ".plugin";
brettwa7ff1b292015-07-16 17:49:29317 if (base::EndsWith(plugin_name, base::ASCIIToUTF16(kPluginExtension),
318 base::CompareCase::SENSITIVE))
[email protected]8be45842012-04-13 19:49:29319 plugin_name.erase(plugin_name.length() - kPluginExtension.length());
320#endif // OS_MACOSX
321 }
322 return plugin_name;
323}
324
fdoray9292e0722017-05-13 03:47:51325void PluginServiceImpl::GetPlugins(GetPluginsCallback callback) {
326 base::PostTaskAndReplyWithResult(
327 plugin_list_task_runner_.get(), FROM_HERE, base::BindOnce([]() {
328 std::vector<WebPluginInfo> plugins;
329 PluginList::Singleton()->GetPlugins(&plugins);
330 return plugins;
331 }),
332 std::move(callback));
[email protected]dfba8762011-09-02 12:49:54333}
334
[email protected]e67385f2011-12-21 06:00:56335void PluginServiceImpl::RegisterPepperPlugins() {
[email protected]dac6a5a2013-07-25 05:06:48336 ComputePepperPluginList(&ppapi_plugins_);
[email protected]a08ebea2011-02-13 17:50:20337 for (size_t i = 0; i < ppapi_plugins_.size(); ++i) {
[email protected]c6f3dea2012-01-14 02:23:11338 RegisterInternalPlugin(ppapi_plugins_[i].ToWebPluginInfo(), true);
[email protected]4e0616e2010-05-28 14:55:53339 }
340}
[email protected]634d23d2011-01-19 10:38:19341
[email protected]eb415bf0e2011-04-14 02:45:42342// There should generally be very few plugins so a brute-force search is fine.
[email protected]130757672012-10-24 00:26:19343PepperPluginInfo* PluginServiceImpl::GetRegisteredPpapiPluginInfo(
[email protected]2dec8ec2013-02-07 19:20:34344 const base::FilePath& plugin_path) {
[email protected]3627aa3f2013-09-17 22:32:51345 for (size_t i = 0; i < ppapi_plugins_.size(); ++i) {
thestig76ee1f42016-07-08 18:54:00346 if (ppapi_plugins_[i].path == plugin_path)
347 return &ppapi_plugins_[i];
[email protected]eb415bf0e2011-04-14 02:45:42348 }
[email protected]076117592011-08-17 03:16:41349 // We did not find the plugin in our list. But wait! the plugin can also
350 // be a latecomer, as it happens with pepper flash. This information
351 // can be obtained from the PluginList singleton and we can use it to
352 // construct it and add it to the list. This same deal needs to be done
353 // in the renderer side in PepperPluginRegistry.
[email protected]d7bd3e52013-07-21 04:29:20354 WebPluginInfo webplugin_info;
[email protected]88ca4912011-10-12 14:00:43355 if (!GetPluginInfoByPath(plugin_path, &webplugin_info))
thestig76ee1f42016-07-08 18:54:00356 return nullptr;
[email protected]130757672012-10-24 00:26:19357 PepperPluginInfo new_pepper_info;
[email protected]076117592011-08-17 03:16:41358 if (!MakePepperPluginInfo(webplugin_info, &new_pepper_info))
thestig76ee1f42016-07-08 18:54:00359 return nullptr;
[email protected]076117592011-08-17 03:16:41360 ppapi_plugins_.push_back(new_pepper_info);
thestig76ee1f42016-07-08 18:54:00361 return &ppapi_plugins_.back();
[email protected]eb415bf0e2011-04-14 02:45:42362}
363
[email protected]130757672012-10-24 00:26:19364void PluginServiceImpl::SetFilter(PluginServiceFilter* filter) {
[email protected]3a5180ae2011-12-21 02:39:38365 filter_ = filter;
366}
367
[email protected]130757672012-10-24 00:26:19368PluginServiceFilter* PluginServiceImpl::GetFilter() {
[email protected]3a5180ae2011-12-21 02:39:38369 return filter_;
370}
371
[email protected]47214d882012-02-29 06:28:48372static const unsigned int kMaxCrashesPerInterval = 3;
373static const unsigned int kCrashesInterval = 120;
374
[email protected]2dec8ec2013-02-07 19:20:34375void PluginServiceImpl::RegisterPluginCrash(const base::FilePath& path) {
mostynb4c27d042015-03-18 21:47:47376 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]2dec8ec2013-02-07 19:20:34377 std::map<base::FilePath, std::vector<base::Time> >::iterator i =
[email protected]47214d882012-02-29 06:28:48378 crash_times_.find(path);
379 if (i == crash_times_.end()) {
380 crash_times_[path] = std::vector<base::Time>();
381 i = crash_times_.find(path);
382 }
383 if (i->second.size() == kMaxCrashesPerInterval) {
384 i->second.erase(i->second.begin());
385 }
386 base::Time time = base::Time::Now();
387 i->second.push_back(time);
388}
389
[email protected]2dec8ec2013-02-07 19:20:34390bool PluginServiceImpl::IsPluginUnstable(const base::FilePath& path) {
mostynb4c27d042015-03-18 21:47:47391 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]2dec8ec2013-02-07 19:20:34392 std::map<base::FilePath, std::vector<base::Time> >::const_iterator i =
[email protected]47214d882012-02-29 06:28:48393 crash_times_.find(path);
394 if (i == crash_times_.end()) {
395 return false;
396 }
397 if (i->second.size() != kMaxCrashesPerInterval) {
398 return false;
399 }
400 base::TimeDelta delta = base::Time::Now() - i->second[0];
[email protected]d8c70062013-04-24 00:22:34401 return delta.InSeconds() <= kCrashesInterval;
[email protected]47214d882012-02-29 06:28:48402}
403
[email protected]e67385f2011-12-21 06:00:56404void PluginServiceImpl::RefreshPlugins() {
[email protected]29e2fb42013-07-19 01:13:47405 PluginList::Singleton()->RefreshPlugins();
[email protected]f520b5b2011-11-08 02:42:14406}
407
[email protected]8f3372122013-07-18 04:34:14408void PluginServiceImpl::RegisterInternalPlugin(
[email protected]d7bd3e52013-07-21 04:29:20409 const WebPluginInfo& info,
[email protected]8f3372122013-07-18 04:34:14410 bool add_at_beginning) {
[email protected]29e2fb42013-07-19 01:13:47411 PluginList::Singleton()->RegisterInternalPlugin(info, add_at_beginning);
[email protected]f520b5b2011-11-08 02:42:14412}
413
[email protected]2dec8ec2013-02-07 19:20:34414void PluginServiceImpl::UnregisterInternalPlugin(const base::FilePath& path) {
[email protected]29e2fb42013-07-19 01:13:47415 PluginList::Singleton()->UnregisterInternalPlugin(path);
[email protected]f520b5b2011-11-08 02:42:14416}
417
[email protected]8f3372122013-07-18 04:34:14418void PluginServiceImpl::GetInternalPlugins(
[email protected]d7bd3e52013-07-21 04:29:20419 std::vector<WebPluginInfo>* plugins) {
[email protected]29e2fb42013-07-19 01:13:47420 PluginList::Singleton()->GetInternalPlugins(plugins);
[email protected]8f3372122013-07-18 04:34:14421}
422
[email protected]aec5ed52014-06-20 07:51:42423bool PluginServiceImpl::PpapiDevChannelSupported(
424 BrowserContext* browser_context,
425 const GURL& document_url) {
wfh6be06282015-07-20 18:04:02426 return GetContentClient()->browser()->IsPluginAllowedToUseDevChannelAPIs(
427 browser_context, document_url);
[email protected]8ddc6b7c2013-12-12 20:42:06428}
429
[email protected]130757672012-10-24 00:26:19430} // namespace content