blob: 86859ca85b67499051504ce257cf0d0b88274787 [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
[email protected]d33e7cc2011-09-23 01:43:569#include "base/bind.h"
[email protected]d48f1e0c2009-02-12 20:57:5410#include "base/command_line.h"
[email protected]7b3ee8b2011-04-01 18:48:1911#include "base/compiler_specific.h"
[email protected]57999812013-02-24 05:40:5212#include "base/files/file_path.h"
skyostil95082a62015-06-05 19:53:0713#include "base/location.h"
fdoray5e1706c32016-09-08 12:57:0914#include "base/logging.h"
asvitkine30330812016-08-30 04:01:0815#include "base/metrics/histogram_macros.h"
skyostil95082a62015-06-05 19:53:0716#include "base/single_thread_task_runner.h"
[email protected]348fbaac2013-06-11 06:31:5117#include "base/strings/string_util.h"
[email protected]74ebfb12013-06-07 20:48:0018#include "base/strings/utf_string_conversions.h"
[email protected]7f070d42011-03-09 20:25:3219#include "base/synchronization/waitable_event.h"
fdoray5e1706c32016-09-08 12:57:0920#include "base/threading/sequenced_worker_pool.h"
[email protected]34b99632011-01-01 01:01:0621#include "base/threading/thread.h"
avib7348942015-12-25 20:57:1022#include "build/build_config.h"
[email protected]a01efd22011-03-01 00:38:3223#include "content/browser/ppapi_plugin_process_host.h"
[email protected]f3b1a082011-11-18 00:34:3024#include "content/browser/renderer_host/render_process_host_impl.h"
[email protected]b3c41c0b2012-03-06 15:48:3225#include "content/browser/renderer_host/render_view_host_impl.h"
wfh1a90e032015-04-14 17:10:1726#include "content/common/content_switches_internal.h"
[email protected]dac6a5a2013-07-25 05:06:4827#include "content/common/pepper_plugin_list.h"
[email protected]29e2fb42013-07-19 01:13:4728#include "content/common/plugin_list.h"
[email protected]38b592902011-04-16 02:08:4229#include "content/common/view_messages.h"
[email protected]c38831a12011-10-28 12:44:4930#include "content/public/browser/browser_thread.h"
[email protected]87f3c082011-10-19 18:07:4431#include "content/public/browser/content_browser_client.h"
[email protected]31f376c2012-03-13 16:43:0932#include "content/public/browser/plugin_service_filter.h"
[email protected]ce967862012-02-09 22:47:0533#include "content/public/browser/resource_context.h"
[email protected]73270292013-08-09 03:48:0734#include "content/public/common/content_constants.h"
[email protected]c08950d22011-10-13 22:20:2935#include "content/public/common/content_switches.h"
[email protected]bd5d6cf2011-12-01 00:39:1236#include "content/public/common/process_type.h"
[email protected]d7bd3e52013-07-21 04:29:2037#include "content/public/common/webplugininfo.h"
[email protected]191eb3f72010-12-21 06:27:5038
[email protected]130757672012-10-24 00:26:1939namespace content {
[email protected]d33e7cc2011-09-23 01:43:5640namespace {
41
[email protected]fd8d8d6c2013-02-28 02:48:3342// This enum is used to collect Flash usage data.
43enum FlashUsage {
[email protected]fd8d8d6c2013-02-28 02:48:3344 // Number of browser processes that have started at least one PPAPI Flash
45 // process during their lifetime.
pimane8c57ea2016-04-06 01:19:3646 START_PPAPI_FLASH_AT_LEAST_ONCE = 1,
[email protected]fd8d8d6c2013-02-28 02:48:3347 // Total number of browser processes.
48 TOTAL_BROWSER_PROCESSES,
49 FLASH_USAGE_ENUM_COUNT
50};
51
[email protected]49125952011-09-27 18:05:1552// Callback set on the PluginList to assert that plugin loading happens on the
53// correct thread.
fdoray5e1706c32016-09-08 12:57:0954void WillLoadPluginsCallback(base::SequenceChecker* sequence_checker) {
55 DCHECK(sequence_checker->CalledOnValidSequence());
[email protected]a79912252012-05-16 11:52:1956}
[email protected]d33e7cc2011-09-23 01:43:5657
[email protected]07b71c82013-01-08 19:07:3158} // namespace
59
[email protected]3a5180ae2011-12-21 02:39:3860// static
61PluginService* PluginService::GetInstance() {
[email protected]e67385f2011-12-21 06:00:5662 return PluginServiceImpl::GetInstance();
[email protected]3a5180ae2011-12-21 02:39:3863}
64
65void 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.commit09911bf2008-07-26 23:55:2975// static
[email protected]e67385f2011-12-21 06:00:5676PluginServiceImpl* PluginServiceImpl::GetInstance() {
olli.raula36aa8be2015-09-10 11:14:2277 return base::Singleton<PluginServiceImpl>::get();
initial.commit09911bf2008-07-26 23:55:2978}
79
[email protected]e67385f2011-12-21 06:00:5680PluginServiceImpl::PluginServiceImpl()
pimane8c57ea2016-04-06 01:19:3681 : filter_(NULL) {
fdoray5e1706c32016-09-08 12:57:0982 plugin_list_sequence_checker_.DetachFromSequence();
83
[email protected]fd8d8d6c2013-02-28 02:48:3384 // Collect the total number of browser processes (which create
85 // PluginServiceImpl objects, to be precise). The number is used to normalize
86 // the number of processes which start at least one NPAPI/PPAPI Flash process.
87 static bool counted = false;
88 if (!counted) {
89 counted = true;
90 UMA_HISTOGRAM_ENUMERATION("Plugin.FlashUsage", TOTAL_BROWSER_PROCESSES,
91 FLASH_USAGE_ENUM_COUNT);
92 }
[email protected]ee066172011-11-10 23:20:0593}
94
[email protected]e67385f2011-12-21 06:00:5695PluginServiceImpl::~PluginServiceImpl() {
[email protected]ee066172011-11-10 23:20:0596}
97
[email protected]e67385f2011-12-21 06:00:5698void PluginServiceImpl::Init() {
fdoray5e1706c32016-09-08 12:57:0999 plugin_list_task_runner_ =
100 BrowserThread::GetBlockingPool()
101 ->GetSequencedTaskRunnerWithShutdownBehavior(
102 base::SequencedWorkerPool::GetSequenceToken(),
103 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN);
[email protected]29e2fb42013-07-19 01:13:47104 PluginList::Singleton()->set_will_load_plugins_callback(
fdoray5e1706c32016-09-08 12:57:09105 base::Bind(&WillLoadPluginsCallback, &plugin_list_sequence_checker_));
[email protected]49125952011-09-27 18:05:15106
[email protected]4e0616e2010-05-28 14:55:53107 RegisterPepperPlugins();
initial.commit09911bf2008-07-26 23:55:29108}
109
[email protected]e67385f2011-12-21 06:00:56110PpapiPluginProcessHost* PluginServiceImpl::FindPpapiPluginProcess(
[email protected]2dec8ec2013-02-07 19:20:34111 const base::FilePath& plugin_path,
112 const base::FilePath& profile_data_directory) {
[email protected]4967f792012-01-20 22:14:40113 for (PpapiPluginProcessHostIterator iter; !iter.Done(); ++iter) {
[email protected]dd9a0952012-05-31 20:11:31114 if (iter->plugin_path() == plugin_path &&
115 iter->profile_data_directory() == profile_data_directory) {
[email protected]4967f792012-01-20 22:14:40116 return *iter;
[email protected]dd9a0952012-05-31 20:11:31117 }
[email protected]a08ebea2011-02-13 17:50:20118 }
[email protected]a08ebea2011-02-13 17:50:20119 return NULL;
120}
121
[email protected]e67385f2011-12-21 06:00:56122PpapiPluginProcessHost* PluginServiceImpl::FindPpapiBrokerProcess(
[email protected]2dec8ec2013-02-07 19:20:34123 const base::FilePath& broker_path) {
[email protected]4967f792012-01-20 22:14:40124 for (PpapiBrokerProcessHostIterator iter; !iter.Done(); ++iter) {
125 if (iter->plugin_path() == broker_path)
126 return *iter;
[email protected]eb415bf0e2011-04-14 02:45:42127 }
128
129 return NULL;
130}
131
[email protected]e67385f2011-12-21 06:00:56132PpapiPluginProcessHost* PluginServiceImpl::FindOrStartPpapiPluginProcess(
[email protected]6be31d202013-02-01 18:20:54133 int render_process_id,
[email protected]2dec8ec2013-02-07 19:20:34134 const base::FilePath& plugin_path,
[email protected]8522332e2013-08-28 19:42:59135 const base::FilePath& profile_data_directory) {
mostynb4c27d042015-03-18 21:47:47136 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]a08ebea2011-02-13 17:50:20137
[email protected]132bca82013-12-10 09:14:47138 if (filter_ && !filter_->CanLoadPlugin(render_process_id, plugin_path)) {
139 VLOG(1) << "Unable to load ppapi plugin: " << plugin_path.MaybeAsASCII();
[email protected]6be31d202013-02-01 18:20:54140 return NULL;
[email protected]132bca82013-12-10 09:14:47141 }
[email protected]6be31d202013-02-01 18:20:54142
[email protected]dd9a0952012-05-31 20:11:31143 PpapiPluginProcessHost* plugin_host =
144 FindPpapiPluginProcess(plugin_path, profile_data_directory);
[email protected]a08ebea2011-02-13 17:50:20145 if (plugin_host)
146 return plugin_host;
147
[email protected]eb415bf0e2011-04-14 02:45:42148 // Validate that the plugin is actually registered.
[email protected]130757672012-10-24 00:26:19149 PepperPluginInfo* info = GetRegisteredPpapiPluginInfo(plugin_path);
[email protected]132bca82013-12-10 09:14:47150 if (!info) {
151 VLOG(1) << "Unable to find ppapi plugin registration for: "
152 << plugin_path.MaybeAsASCII();
[email protected]a08ebea2011-02-13 17:50:20153 return NULL;
[email protected]132bca82013-12-10 09:14:47154 }
[email protected]a08ebea2011-02-13 17:50:20155
[email protected]fd8d8d6c2013-02-28 02:48:33156 // Record when PPAPI Flash process is started for the first time.
157 static bool counted = false;
158 if (!counted && info->name == kFlashPluginName) {
159 counted = true;
160 UMA_HISTOGRAM_ENUMERATION("Plugin.FlashUsage",
161 START_PPAPI_FLASH_AT_LEAST_ONCE,
162 FLASH_USAGE_ENUM_COUNT);
163 }
164
[email protected]a08ebea2011-02-13 17:50:20165 // This plugin isn't loaded by any plugin process, so create a new process.
[email protected]132bca82013-12-10 09:14:47166 plugin_host = PpapiPluginProcessHost::CreatePluginHost(
[email protected]8522332e2013-08-28 19:42:59167 *info, profile_data_directory);
[email protected]132bca82013-12-10 09:14:47168 if (!plugin_host) {
169 VLOG(1) << "Unable to create ppapi plugin process for: "
170 << plugin_path.MaybeAsASCII();
171 }
172
173 return plugin_host;
[email protected]a08ebea2011-02-13 17:50:20174}
175
[email protected]e67385f2011-12-21 06:00:56176PpapiPluginProcessHost* PluginServiceImpl::FindOrStartPpapiBrokerProcess(
[email protected]6be31d202013-02-01 18:20:54177 int render_process_id,
[email protected]2dec8ec2013-02-07 19:20:34178 const base::FilePath& plugin_path) {
mostynb4c27d042015-03-18 21:47:47179 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]eb415bf0e2011-04-14 02:45:42180
[email protected]6be31d202013-02-01 18:20:54181 if (filter_ && !filter_->CanLoadPlugin(render_process_id, plugin_path))
182 return NULL;
183
[email protected]a50432d2011-09-30 16:32:14184 PpapiPluginProcessHost* plugin_host = FindPpapiBrokerProcess(plugin_path);
[email protected]eb415bf0e2011-04-14 02:45:42185 if (plugin_host)
186 return plugin_host;
187
188 // Validate that the plugin is actually registered.
[email protected]130757672012-10-24 00:26:19189 PepperPluginInfo* info = GetRegisteredPpapiPluginInfo(plugin_path);
[email protected]eb415bf0e2011-04-14 02:45:42190 if (!info)
191 return NULL;
192
193 // TODO(ddorwin): Uncomment once out of process is supported.
194 // DCHECK(info->is_out_of_process);
195
196 // This broker isn't loaded by any broker process, so create a new process.
[email protected]a50432d2011-09-30 16:32:14197 return PpapiPluginProcessHost::CreateBrokerHost(*info);
[email protected]eb415bf0e2011-04-14 02:45:42198}
199
[email protected]e67385f2011-12-21 06:00:56200void PluginServiceImpl::OpenChannelToPpapiPlugin(
[email protected]6be31d202013-02-01 18:20:54201 int render_process_id,
[email protected]2dec8ec2013-02-07 19:20:34202 const base::FilePath& plugin_path,
203 const base::FilePath& profile_data_directory,
[email protected]a50432d2011-09-30 16:32:14204 PpapiPluginProcessHost::PluginClient* client) {
[email protected]d259a8e2011-05-18 22:31:09205 PpapiPluginProcessHost* plugin_host = FindOrStartPpapiPluginProcess(
[email protected]8522332e2013-08-28 19:42:59206 render_process_id, plugin_path, profile_data_directory);
[email protected]1bf0fb22012-04-12 21:44:16207 if (plugin_host) {
[email protected]a08ebea2011-02-13 17:50:20208 plugin_host->OpenChannelToPlugin(client);
[email protected]1bf0fb22012-04-12 21:44:16209 } else {
210 // Send error.
[email protected]108fd342013-01-04 20:46:54211 client->OnPpapiChannelOpened(IPC::ChannelHandle(), base::kNullProcessId, 0);
[email protected]1bf0fb22012-04-12 21:44:16212 }
[email protected]a08ebea2011-02-13 17:50:20213}
214
[email protected]e67385f2011-12-21 06:00:56215void PluginServiceImpl::OpenChannelToPpapiBroker(
[email protected]6be31d202013-02-01 18:20:54216 int render_process_id,
[email protected]2dec8ec2013-02-07 19:20:34217 const base::FilePath& path,
[email protected]a50432d2011-09-30 16:32:14218 PpapiPluginProcessHost::BrokerClient* client) {
[email protected]6be31d202013-02-01 18:20:54219 PpapiPluginProcessHost* plugin_host = FindOrStartPpapiBrokerProcess(
220 render_process_id, path);
[email protected]1bf0fb22012-04-12 21:44:16221 if (plugin_host) {
[email protected]a50432d2011-09-30 16:32:14222 plugin_host->OpenChannelToPlugin(client);
[email protected]1bf0fb22012-04-12 21:44:16223 } else {
224 // Send error.
[email protected]108fd342013-01-04 20:46:54225 client->OnPpapiChannelOpened(IPC::ChannelHandle(), base::kNullProcessId, 0);
[email protected]1bf0fb22012-04-12 21:44:16226 }
[email protected]eb415bf0e2011-04-14 02:45:42227}
228
[email protected]e67385f2011-12-21 06:00:56229bool PluginServiceImpl::GetPluginInfoArray(
[email protected]51b63f62011-10-05 18:55:42230 const GURL& url,
231 const std::string& mime_type,
232 bool allow_wildcard,
[email protected]d7bd3e52013-07-21 04:29:20233 std::vector<WebPluginInfo>* plugins,
[email protected]51b63f62011-10-05 18:55:42234 std::vector<std::string>* actual_mime_types) {
235 bool use_stale = false;
[email protected]29e2fb42013-07-19 01:13:47236 PluginList::Singleton()->GetPluginInfoArray(
pimane8c57ea2016-04-06 01:19:36237 url, mime_type, allow_wildcard, &use_stale, plugins, actual_mime_types);
[email protected]51b63f62011-10-05 18:55:42238 return use_stale;
239}
240
[email protected]e67385f2011-12-21 06:00:56241bool PluginServiceImpl::GetPluginInfo(int render_process_id,
[email protected]60eca4eb2013-12-06 00:02:16242 int render_frame_id,
[email protected]130757672012-10-24 00:26:19243 ResourceContext* context,
[email protected]e67385f2011-12-21 06:00:56244 const GURL& url,
245 const GURL& page_url,
246 const std::string& mime_type,
247 bool allow_wildcard,
248 bool* is_stale,
[email protected]d7bd3e52013-07-21 04:29:20249 WebPluginInfo* info,
[email protected]e67385f2011-12-21 06:00:56250 std::string* actual_mime_type) {
[email protected]d7bd3e52013-07-21 04:29:20251 std::vector<WebPluginInfo> plugins;
[email protected]68598072011-07-29 08:21:28252 std::vector<std::string> mime_types;
[email protected]88ca4912011-10-12 14:00:43253 bool stale = GetPluginInfoArray(
254 url, mime_type, allow_wildcard, &plugins, &mime_types);
255 if (is_stale)
256 *is_stale = stale;
[email protected]dfba8762011-09-02 12:49:54257
[email protected]68598072011-07-29 08:21:28258 for (size_t i = 0; i < plugins.size(); ++i) {
[email protected]05f511282013-02-05 15:02:50259 if (!filter_ || filter_->IsPluginAvailable(render_process_id,
[email protected]60eca4eb2013-12-06 00:02:16260 render_frame_id,
[email protected]05f511282013-02-05 15:02:50261 context,
262 url,
263 page_url,
264 &plugins[i])) {
[email protected]68598072011-07-29 08:21:28265 *info = plugins[i];
266 if (actual_mime_type)
267 *actual_mime_type = mime_types[i];
268 return true;
269 }
270 }
271 return false;
[email protected]6fdd4182010-10-14 23:59:26272}
273
[email protected]2dec8ec2013-02-07 19:20:34274bool PluginServiceImpl::GetPluginInfoByPath(const base::FilePath& plugin_path,
[email protected]d7bd3e52013-07-21 04:29:20275 WebPluginInfo* info) {
276 std::vector<WebPluginInfo> plugins;
[email protected]29e2fb42013-07-19 01:13:47277 PluginList::Singleton()->GetPluginsNoRefresh(&plugins);
[email protected]88ca4912011-10-12 14:00:43278
[email protected]d7bd3e52013-07-21 04:29:20279 for (std::vector<WebPluginInfo>::iterator it = plugins.begin();
[email protected]88ca4912011-10-12 14:00:43280 it != plugins.end();
281 ++it) {
282 if (it->path == plugin_path) {
283 *info = *it;
284 return true;
285 }
286 }
287
288 return false;
289}
290
[email protected]fcf75d42013-12-03 20:11:26291base::string16 PluginServiceImpl::GetPluginDisplayNameByPath(
[email protected]2dec8ec2013-02-07 19:20:34292 const base::FilePath& path) {
[email protected]fcf75d42013-12-03 20:11:26293 base::string16 plugin_name = path.LossyDisplayName();
[email protected]d7bd3e52013-07-21 04:29:20294 WebPluginInfo info;
[email protected]8be45842012-04-13 19:49:29295 if (PluginService::GetInstance()->GetPluginInfoByPath(path, &info) &&
296 !info.name.empty()) {
297 plugin_name = info.name;
298#if defined(OS_MACOSX)
299 // Many plugins on the Mac have .plugin in the actual name, which looks
300 // terrible, so look for that and strip it off if present.
301 const std::string kPluginExtension = ".plugin";
brettwa7ff1b292015-07-16 17:49:29302 if (base::EndsWith(plugin_name, base::ASCIIToUTF16(kPluginExtension),
303 base::CompareCase::SENSITIVE))
[email protected]8be45842012-04-13 19:49:29304 plugin_name.erase(plugin_name.length() - kPluginExtension.length());
305#endif // OS_MACOSX
306 }
307 return plugin_name;
308}
309
[email protected]e67385f2011-12-21 06:00:56310void PluginServiceImpl::GetPlugins(const GetPluginsCallback& callback) {
skyostil95082a62015-06-05 19:53:07311 scoped_refptr<base::SingleThreadTaskRunner> target_task_runner(
312 base::ThreadTaskRunnerHandle::Get());
[email protected]49125952011-09-27 18:05:15313
fdoray5e1706c32016-09-08 12:57:09314 plugin_list_task_runner_->PostTask(
315 FROM_HERE,
pimane8c57ea2016-04-06 01:19:36316 base::Bind(&PluginServiceImpl::GetPluginsInternal, base::Unretained(this),
fdoray5e1706c32016-09-08 12:57:09317 base::RetainedRef(target_task_runner), callback));
[email protected]d33e7cc2011-09-23 01:43:56318}
319
[email protected]e67385f2011-12-21 06:00:56320void PluginServiceImpl::GetPluginsInternal(
skyostil95082a62015-06-05 19:53:07321 base::SingleThreadTaskRunner* target_task_runner,
322 const PluginService::GetPluginsCallback& callback) {
fdoray5e1706c32016-09-08 12:57:09323 DCHECK(plugin_list_sequence_checker_.CalledOnValidSequence());
[email protected]d33e7cc2011-09-23 01:43:56324
[email protected]d7bd3e52013-07-21 04:29:20325 std::vector<WebPluginInfo> plugins;
pimane8c57ea2016-04-06 01:19:36326 PluginList::Singleton()->GetPlugins(&plugins);
[email protected]d33e7cc2011-09-23 01:43:56327
skyostil95082a62015-06-05 19:53:07328 target_task_runner->PostTask(FROM_HERE, base::Bind(callback, plugins));
[email protected]dfba8762011-09-02 12:49:54329}
330
[email protected]e67385f2011-12-21 06:00:56331void PluginServiceImpl::RegisterPepperPlugins() {
[email protected]dac6a5a2013-07-25 05:06:48332 ComputePepperPluginList(&ppapi_plugins_);
[email protected]a08ebea2011-02-13 17:50:20333 for (size_t i = 0; i < ppapi_plugins_.size(); ++i) {
[email protected]c6f3dea2012-01-14 02:23:11334 RegisterInternalPlugin(ppapi_plugins_[i].ToWebPluginInfo(), true);
[email protected]4e0616e2010-05-28 14:55:53335 }
336}
[email protected]634d23d2011-01-19 10:38:19337
[email protected]eb415bf0e2011-04-14 02:45:42338// There should generally be very few plugins so a brute-force search is fine.
[email protected]130757672012-10-24 00:26:19339PepperPluginInfo* PluginServiceImpl::GetRegisteredPpapiPluginInfo(
[email protected]2dec8ec2013-02-07 19:20:34340 const base::FilePath& plugin_path) {
[email protected]3627aa3f2013-09-17 22:32:51341 for (size_t i = 0; i < ppapi_plugins_.size(); ++i) {
thestig76ee1f42016-07-08 18:54:00342 if (ppapi_plugins_[i].path == plugin_path)
343 return &ppapi_plugins_[i];
[email protected]eb415bf0e2011-04-14 02:45:42344 }
[email protected]076117592011-08-17 03:16:41345 // We did not find the plugin in our list. But wait! the plugin can also
346 // be a latecomer, as it happens with pepper flash. This information
347 // can be obtained from the PluginList singleton and we can use it to
348 // construct it and add it to the list. This same deal needs to be done
349 // in the renderer side in PepperPluginRegistry.
[email protected]d7bd3e52013-07-21 04:29:20350 WebPluginInfo webplugin_info;
[email protected]88ca4912011-10-12 14:00:43351 if (!GetPluginInfoByPath(plugin_path, &webplugin_info))
thestig76ee1f42016-07-08 18:54:00352 return nullptr;
[email protected]130757672012-10-24 00:26:19353 PepperPluginInfo new_pepper_info;
[email protected]076117592011-08-17 03:16:41354 if (!MakePepperPluginInfo(webplugin_info, &new_pepper_info))
thestig76ee1f42016-07-08 18:54:00355 return nullptr;
[email protected]076117592011-08-17 03:16:41356 ppapi_plugins_.push_back(new_pepper_info);
thestig76ee1f42016-07-08 18:54:00357 return &ppapi_plugins_.back();
[email protected]eb415bf0e2011-04-14 02:45:42358}
359
[email protected]130757672012-10-24 00:26:19360void PluginServiceImpl::SetFilter(PluginServiceFilter* filter) {
[email protected]3a5180ae2011-12-21 02:39:38361 filter_ = filter;
362}
363
[email protected]130757672012-10-24 00:26:19364PluginServiceFilter* PluginServiceImpl::GetFilter() {
[email protected]3a5180ae2011-12-21 02:39:38365 return filter_;
366}
367
[email protected]47214d882012-02-29 06:28:48368static const unsigned int kMaxCrashesPerInterval = 3;
369static const unsigned int kCrashesInterval = 120;
370
[email protected]2dec8ec2013-02-07 19:20:34371void PluginServiceImpl::RegisterPluginCrash(const base::FilePath& path) {
mostynb4c27d042015-03-18 21:47:47372 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]2dec8ec2013-02-07 19:20:34373 std::map<base::FilePath, std::vector<base::Time> >::iterator i =
[email protected]47214d882012-02-29 06:28:48374 crash_times_.find(path);
375 if (i == crash_times_.end()) {
376 crash_times_[path] = std::vector<base::Time>();
377 i = crash_times_.find(path);
378 }
379 if (i->second.size() == kMaxCrashesPerInterval) {
380 i->second.erase(i->second.begin());
381 }
382 base::Time time = base::Time::Now();
383 i->second.push_back(time);
384}
385
[email protected]2dec8ec2013-02-07 19:20:34386bool PluginServiceImpl::IsPluginUnstable(const base::FilePath& path) {
mostynb4c27d042015-03-18 21:47:47387 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]2dec8ec2013-02-07 19:20:34388 std::map<base::FilePath, std::vector<base::Time> >::const_iterator i =
[email protected]47214d882012-02-29 06:28:48389 crash_times_.find(path);
390 if (i == crash_times_.end()) {
391 return false;
392 }
393 if (i->second.size() != kMaxCrashesPerInterval) {
394 return false;
395 }
396 base::TimeDelta delta = base::Time::Now() - i->second[0];
[email protected]d8c70062013-04-24 00:22:34397 return delta.InSeconds() <= kCrashesInterval;
[email protected]47214d882012-02-29 06:28:48398}
399
[email protected]e67385f2011-12-21 06:00:56400void PluginServiceImpl::RefreshPlugins() {
[email protected]29e2fb42013-07-19 01:13:47401 PluginList::Singleton()->RefreshPlugins();
[email protected]f520b5b2011-11-08 02:42:14402}
403
[email protected]8f3372122013-07-18 04:34:14404void PluginServiceImpl::RegisterInternalPlugin(
[email protected]d7bd3e52013-07-21 04:29:20405 const WebPluginInfo& info,
[email protected]8f3372122013-07-18 04:34:14406 bool add_at_beginning) {
[email protected]29e2fb42013-07-19 01:13:47407 PluginList::Singleton()->RegisterInternalPlugin(info, add_at_beginning);
[email protected]f520b5b2011-11-08 02:42:14408}
409
[email protected]2dec8ec2013-02-07 19:20:34410void PluginServiceImpl::UnregisterInternalPlugin(const base::FilePath& path) {
[email protected]29e2fb42013-07-19 01:13:47411 PluginList::Singleton()->UnregisterInternalPlugin(path);
[email protected]f520b5b2011-11-08 02:42:14412}
413
[email protected]8f3372122013-07-18 04:34:14414void PluginServiceImpl::GetInternalPlugins(
[email protected]d7bd3e52013-07-21 04:29:20415 std::vector<WebPluginInfo>* plugins) {
[email protected]29e2fb42013-07-19 01:13:47416 PluginList::Singleton()->GetInternalPlugins(plugins);
[email protected]8f3372122013-07-18 04:34:14417}
418
[email protected]aec5ed52014-06-20 07:51:42419bool PluginServiceImpl::PpapiDevChannelSupported(
420 BrowserContext* browser_context,
421 const GURL& document_url) {
wfh6be06282015-07-20 18:04:02422 return GetContentClient()->browser()->IsPluginAllowedToUseDevChannelAPIs(
423 browser_context, document_url);
[email protected]8ddc6b7c2013-12-12 20:42:06424}
425
[email protected]130757672012-10-24 00:26:19426} // namespace content