blob: b822ba75eef6844eec32f966f7373ab540618e1c [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"
Gabriel Charette44db1422018-08-06 11:19:3321#include "base/task/post_task.h"
fdoray9292e0722017-05-13 03:47:5122#include "base/task_runner_util.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"
Steven Holte38041342018-06-22 22:00:5728#include "content/browser/web_contents/web_contents_impl.h"
wfh1a90e032015-04-14 17:10:1729#include "content/common/content_switches_internal.h"
[email protected]dac6a5a2013-07-25 05:06:4830#include "content/common/pepper_plugin_list.h"
[email protected]29e2fb42013-07-19 01:13:4731#include "content/common/plugin_list.h"
[email protected]38b592902011-04-16 02:08:4232#include "content/common/view_messages.h"
[email protected]c38831a12011-10-28 12:44:4933#include "content/public/browser/browser_thread.h"
[email protected]87f3c082011-10-19 18:07:4434#include "content/public/browser/content_browser_client.h"
[email protected]31f376c2012-03-13 16:43:0935#include "content/public/browser/plugin_service_filter.h"
Raymes Khoury978652c2017-11-27 06:28:3736#include "content/public/browser/render_frame_host.h"
[email protected]ce967862012-02-09 22:47:0537#include "content/public/browser/resource_context.h"
Raymes Khoury978652c2017-11-27 06:28:3738#include "content/public/browser/web_contents.h"
[email protected]73270292013-08-09 03:48:0739#include "content/public/common/content_constants.h"
[email protected]c08950d22011-10-13 22:20:2940#include "content/public/common/content_switches.h"
[email protected]bd5d6cf2011-12-01 00:39:1241#include "content/public/common/process_type.h"
[email protected]d7bd3e52013-07-21 04:29:2042#include "content/public/common/webplugininfo.h"
Raymes Khoury978652c2017-11-27 06:28:3743#include "services/metrics/public/cpp/ukm_builders.h"
[email protected]191eb3f72010-12-21 06:27:5044
[email protected]130757672012-10-24 00:26:1945namespace content {
[email protected]d33e7cc2011-09-23 01:43:5646namespace {
47
[email protected]fd8d8d6c2013-02-28 02:48:3348// This enum is used to collect Flash usage data.
49enum FlashUsage {
[email protected]fd8d8d6c2013-02-28 02:48:3350 // Number of browser processes that have started at least one PPAPI Flash
51 // process during their lifetime.
pimane8c57ea2016-04-06 01:19:3652 START_PPAPI_FLASH_AT_LEAST_ONCE = 1,
[email protected]fd8d8d6c2013-02-28 02:48:3353 // Total number of browser processes.
54 TOTAL_BROWSER_PROCESSES,
55 FLASH_USAGE_ENUM_COUNT
56};
57
[email protected]49125952011-09-27 18:05:1558// Callback set on the PluginList to assert that plugin loading happens on the
59// correct thread.
fdoray5e1706c32016-09-08 12:57:0960void WillLoadPluginsCallback(base::SequenceChecker* sequence_checker) {
61 DCHECK(sequence_checker->CalledOnValidSequence());
[email protected]a79912252012-05-16 11:52:1962}
[email protected]d33e7cc2011-09-23 01:43:5663
Steven Holteba045f12017-12-14 21:30:1964} // namespace
65
66// static
67void PluginServiceImpl::RecordBrokerUsage(int render_process_id,
68 int render_frame_id) {
Raymes Khoury978652c2017-11-27 06:28:3769 WebContents* web_contents = WebContents::FromRenderFrameHost(
70 RenderFrameHost::FromID(render_process_id, render_frame_id));
71 if (web_contents) {
Steven Holte38041342018-06-22 22:00:5772 ukm::SourceId source_id = static_cast<WebContentsImpl*>(web_contents)
73 ->GetUkmSourceIdForLastCommittedSource();
74 ukm::builders::Pepper_Broker(source_id).Record(ukm::UkmRecorder::Get());
Raymes Khoury978652c2017-11-27 06:28:3775 }
76}
77
[email protected]3a5180ae2011-12-21 02:39:3878// static
79PluginService* PluginService::GetInstance() {
[email protected]e67385f2011-12-21 06:00:5680 return PluginServiceImpl::GetInstance();
[email protected]3a5180ae2011-12-21 02:39:3881}
82
83void PluginService::PurgePluginListCache(BrowserContext* browser_context,
84 bool reload_pages) {
85 for (RenderProcessHost::iterator it = RenderProcessHost::AllHostsIterator();
86 !it.IsAtEnd(); it.Advance()) {
87 RenderProcessHost* host = it.GetCurrentValue();
88 if (!browser_context || host->GetBrowserContext() == browser_context)
rockota2db0da2016-10-18 17:39:1189 host->GetRendererInterface()->PurgePluginListCache(reload_pages);
[email protected]3a5180ae2011-12-21 02:39:3890 }
91}
92
initial.commit09911bf2008-07-26 23:55:2993// static
[email protected]e67385f2011-12-21 06:00:5694PluginServiceImpl* PluginServiceImpl::GetInstance() {
olli.raula36aa8be2015-09-10 11:14:2295 return base::Singleton<PluginServiceImpl>::get();
initial.commit09911bf2008-07-26 23:55:2996}
97
Ivan Kotenkov2c0d2bb32017-11-01 15:41:2898PluginServiceImpl::PluginServiceImpl() : filter_(nullptr) {
fdoray5e1706c32016-09-08 12:57:0999 plugin_list_sequence_checker_.DetachFromSequence();
100
[email protected]fd8d8d6c2013-02-28 02:48:33101 // Collect the total number of browser processes (which create
102 // PluginServiceImpl objects, to be precise). The number is used to normalize
103 // the number of processes which start at least one NPAPI/PPAPI Flash process.
104 static bool counted = false;
105 if (!counted) {
106 counted = true;
107 UMA_HISTOGRAM_ENUMERATION("Plugin.FlashUsage", TOTAL_BROWSER_PROCESSES,
108 FLASH_USAGE_ENUM_COUNT);
109 }
[email protected]ee066172011-11-10 23:20:05110}
111
[email protected]e67385f2011-12-21 06:00:56112PluginServiceImpl::~PluginServiceImpl() {
[email protected]ee066172011-11-10 23:20:05113}
114
[email protected]e67385f2011-12-21 06:00:56115void PluginServiceImpl::Init() {
fdoraycc22a38d2017-04-27 06:56:39116 plugin_list_task_runner_ = base::CreateSequencedTaskRunnerWithTraits(
fdoray27b0b2a2017-05-04 19:52:08117 {base::MayBlock(), base::TaskPriority::USER_VISIBLE,
118 base::TaskShutdownBehavior::SKIP_ON_SHUTDOWN});
[email protected]29e2fb42013-07-19 01:13:47119 PluginList::Singleton()->set_will_load_plugins_callback(
fdoray5e1706c32016-09-08 12:57:09120 base::Bind(&WillLoadPluginsCallback, &plugin_list_sequence_checker_));
[email protected]49125952011-09-27 18:05:15121
[email protected]4e0616e2010-05-28 14:55:53122 RegisterPepperPlugins();
initial.commit09911bf2008-07-26 23:55:29123}
124
[email protected]e67385f2011-12-21 06:00:56125PpapiPluginProcessHost* PluginServiceImpl::FindPpapiPluginProcess(
[email protected]2dec8ec2013-02-07 19:20:34126 const base::FilePath& plugin_path,
Tom Sepez8db30ad2018-03-01 21:38:54127 const base::FilePath& profile_data_directory,
128 const base::Optional<url::Origin>& origin_lock) {
[email protected]4967f792012-01-20 22:14:40129 for (PpapiPluginProcessHostIterator iter; !iter.Done(); ++iter) {
[email protected]dd9a0952012-05-31 20:11:31130 if (iter->plugin_path() == plugin_path &&
Tom Sepez8db30ad2018-03-01 21:38:54131 iter->profile_data_directory() == profile_data_directory &&
132 (!iter->origin_lock() || iter->origin_lock() == origin_lock)) {
[email protected]4967f792012-01-20 22:14:40133 return *iter;
[email protected]dd9a0952012-05-31 20:11:31134 }
[email protected]a08ebea2011-02-13 17:50:20135 }
Ivan Kotenkov2c0d2bb32017-11-01 15:41:28136 return nullptr;
[email protected]a08ebea2011-02-13 17:50:20137}
138
Tom Sepez19fecb3d2018-03-02 18:40:21139int PluginServiceImpl::CountPpapiPluginProcessesForProfile(
140 const base::FilePath& plugin_path,
141 const base::FilePath& profile_data_directory) {
142 int count = 0;
143 for (PpapiPluginProcessHostIterator iter; !iter.Done(); ++iter) {
144 if (iter->plugin_path() == plugin_path &&
145 iter->profile_data_directory() == profile_data_directory) {
146 ++count;
147 }
148 }
149 return count;
150}
151
[email protected]e67385f2011-12-21 06:00:56152PpapiPluginProcessHost* PluginServiceImpl::FindPpapiBrokerProcess(
[email protected]2dec8ec2013-02-07 19:20:34153 const base::FilePath& broker_path) {
[email protected]4967f792012-01-20 22:14:40154 for (PpapiBrokerProcessHostIterator iter; !iter.Done(); ++iter) {
155 if (iter->plugin_path() == broker_path)
156 return *iter;
[email protected]eb415bf0e2011-04-14 02:45:42157 }
158
Ivan Kotenkov2c0d2bb32017-11-01 15:41:28159 return nullptr;
[email protected]eb415bf0e2011-04-14 02:45:42160}
161
[email protected]e67385f2011-12-21 06:00:56162PpapiPluginProcessHost* PluginServiceImpl::FindOrStartPpapiPluginProcess(
[email protected]6be31d202013-02-01 18:20:54163 int render_process_id,
[email protected]2dec8ec2013-02-07 19:20:34164 const base::FilePath& plugin_path,
Tom Sepez8db30ad2018-03-01 21:38:54165 const base::FilePath& profile_data_directory,
166 const base::Optional<url::Origin>& origin_lock) {
mostynb4c27d042015-03-18 21:47:47167 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]a08ebea2011-02-13 17:50:20168
[email protected]132bca82013-12-10 09:14:47169 if (filter_ && !filter_->CanLoadPlugin(render_process_id, plugin_path)) {
170 VLOG(1) << "Unable to load ppapi plugin: " << plugin_path.MaybeAsASCII();
Ivan Kotenkov2c0d2bb32017-11-01 15:41:28171 return nullptr;
[email protected]132bca82013-12-10 09:14:47172 }
[email protected]6be31d202013-02-01 18:20:54173
[email protected]eb415bf0e2011-04-14 02:45:42174 // Validate that the plugin is actually registered.
[email protected]130757672012-10-24 00:26:19175 PepperPluginInfo* info = GetRegisteredPpapiPluginInfo(plugin_path);
[email protected]132bca82013-12-10 09:14:47176 if (!info) {
177 VLOG(1) << "Unable to find ppapi plugin registration for: "
178 << plugin_path.MaybeAsASCII();
Ivan Kotenkov2c0d2bb32017-11-01 15:41:28179 return nullptr;
[email protected]132bca82013-12-10 09:14:47180 }
[email protected]a08ebea2011-02-13 17:50:20181
Tom Sepez8db30ad2018-03-01 21:38:54182 PpapiPluginProcessHost* plugin_host =
183 FindPpapiPluginProcess(plugin_path, profile_data_directory, origin_lock);
184 if (plugin_host)
185 return plugin_host;
186
[email protected]fd8d8d6c2013-02-28 02:48:33187 // Record when PPAPI Flash process is started for the first time.
188 static bool counted = false;
189 if (!counted && info->name == kFlashPluginName) {
190 counted = true;
191 UMA_HISTOGRAM_ENUMERATION("Plugin.FlashUsage",
192 START_PPAPI_FLASH_AT_LEAST_ONCE,
193 FLASH_USAGE_ENUM_COUNT);
194 }
195
Tom Sepez19fecb3d2018-03-02 18:40:21196 // Avoid fork bomb.
197 if (origin_lock.has_value() && CountPpapiPluginProcessesForProfile(
198 plugin_path, profile_data_directory) >=
199 max_ppapi_processes_per_profile_) {
200 return nullptr;
201 }
202
[email protected]a08ebea2011-02-13 17:50:20203 // This plugin isn't loaded by any plugin process, so create a new process.
[email protected]132bca82013-12-10 09:14:47204 plugin_host = PpapiPluginProcessHost::CreatePluginHost(
Tom Sepez8db30ad2018-03-01 21:38:54205 *info, profile_data_directory, origin_lock);
[email protected]132bca82013-12-10 09:14:47206 if (!plugin_host) {
207 VLOG(1) << "Unable to create ppapi plugin process for: "
208 << plugin_path.MaybeAsASCII();
209 }
210
211 return plugin_host;
[email protected]a08ebea2011-02-13 17:50:20212}
213
[email protected]e67385f2011-12-21 06:00:56214PpapiPluginProcessHost* PluginServiceImpl::FindOrStartPpapiBrokerProcess(
[email protected]6be31d202013-02-01 18:20:54215 int render_process_id,
[email protected]2dec8ec2013-02-07 19:20:34216 const base::FilePath& plugin_path) {
mostynb4c27d042015-03-18 21:47:47217 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]eb415bf0e2011-04-14 02:45:42218
[email protected]6be31d202013-02-01 18:20:54219 if (filter_ && !filter_->CanLoadPlugin(render_process_id, plugin_path))
Ivan Kotenkov2c0d2bb32017-11-01 15:41:28220 return nullptr;
[email protected]6be31d202013-02-01 18:20:54221
[email protected]a50432d2011-09-30 16:32:14222 PpapiPluginProcessHost* plugin_host = FindPpapiBrokerProcess(plugin_path);
[email protected]eb415bf0e2011-04-14 02:45:42223 if (plugin_host)
224 return plugin_host;
225
226 // Validate that the plugin is actually registered.
[email protected]130757672012-10-24 00:26:19227 PepperPluginInfo* info = GetRegisteredPpapiPluginInfo(plugin_path);
[email protected]eb415bf0e2011-04-14 02:45:42228 if (!info)
Ivan Kotenkov2c0d2bb32017-11-01 15:41:28229 return nullptr;
[email protected]eb415bf0e2011-04-14 02:45:42230
231 // TODO(ddorwin): Uncomment once out of process is supported.
232 // DCHECK(info->is_out_of_process);
233
234 // This broker isn't loaded by any broker process, so create a new process.
[email protected]a50432d2011-09-30 16:32:14235 return PpapiPluginProcessHost::CreateBrokerHost(*info);
[email protected]eb415bf0e2011-04-14 02:45:42236}
237
[email protected]e67385f2011-12-21 06:00:56238void PluginServiceImpl::OpenChannelToPpapiPlugin(
[email protected]6be31d202013-02-01 18:20:54239 int render_process_id,
[email protected]2dec8ec2013-02-07 19:20:34240 const base::FilePath& plugin_path,
241 const base::FilePath& profile_data_directory,
Tom Sepez8db30ad2018-03-01 21:38:54242 const base::Optional<url::Origin>& origin_lock,
[email protected]a50432d2011-09-30 16:32:14243 PpapiPluginProcessHost::PluginClient* client) {
[email protected]d259a8e2011-05-18 22:31:09244 PpapiPluginProcessHost* plugin_host = FindOrStartPpapiPluginProcess(
Tom Sepez8db30ad2018-03-01 21:38:54245 render_process_id, plugin_path, profile_data_directory, origin_lock);
[email protected]1bf0fb22012-04-12 21:44:16246 if (plugin_host) {
[email protected]a08ebea2011-02-13 17:50:20247 plugin_host->OpenChannelToPlugin(client);
[email protected]1bf0fb22012-04-12 21:44:16248 } else {
249 // Send error.
[email protected]108fd342013-01-04 20:46:54250 client->OnPpapiChannelOpened(IPC::ChannelHandle(), base::kNullProcessId, 0);
[email protected]1bf0fb22012-04-12 21:44:16251 }
[email protected]a08ebea2011-02-13 17:50:20252}
253
[email protected]e67385f2011-12-21 06:00:56254void PluginServiceImpl::OpenChannelToPpapiBroker(
[email protected]6be31d202013-02-01 18:20:54255 int render_process_id,
Raymes Khoury978652c2017-11-27 06:28:37256 int render_frame_id,
[email protected]2dec8ec2013-02-07 19:20:34257 const base::FilePath& path,
[email protected]a50432d2011-09-30 16:32:14258 PpapiPluginProcessHost::BrokerClient* client) {
Steven Holteba045f12017-12-14 21:30:19259 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
260 base::BindOnce(&PluginServiceImpl::RecordBrokerUsage,
261 render_process_id, render_frame_id));
Raymes Khoury978652c2017-11-27 06:28:37262
[email protected]6be31d202013-02-01 18:20:54263 PpapiPluginProcessHost* plugin_host = FindOrStartPpapiBrokerProcess(
264 render_process_id, path);
[email protected]1bf0fb22012-04-12 21:44:16265 if (plugin_host) {
[email protected]a50432d2011-09-30 16:32:14266 plugin_host->OpenChannelToPlugin(client);
[email protected]1bf0fb22012-04-12 21:44:16267 } else {
268 // Send error.
[email protected]108fd342013-01-04 20:46:54269 client->OnPpapiChannelOpened(IPC::ChannelHandle(), base::kNullProcessId, 0);
[email protected]1bf0fb22012-04-12 21:44:16270 }
[email protected]eb415bf0e2011-04-14 02:45:42271}
272
[email protected]e67385f2011-12-21 06:00:56273bool PluginServiceImpl::GetPluginInfoArray(
[email protected]51b63f62011-10-05 18:55:42274 const GURL& url,
275 const std::string& mime_type,
276 bool allow_wildcard,
[email protected]d7bd3e52013-07-21 04:29:20277 std::vector<WebPluginInfo>* plugins,
[email protected]51b63f62011-10-05 18:55:42278 std::vector<std::string>* actual_mime_types) {
279 bool use_stale = false;
[email protected]29e2fb42013-07-19 01:13:47280 PluginList::Singleton()->GetPluginInfoArray(
pimane8c57ea2016-04-06 01:19:36281 url, mime_type, allow_wildcard, &use_stale, plugins, actual_mime_types);
[email protected]51b63f62011-10-05 18:55:42282 return use_stale;
283}
284
[email protected]e67385f2011-12-21 06:00:56285bool PluginServiceImpl::GetPluginInfo(int render_process_id,
[email protected]60eca4eb2013-12-06 00:02:16286 int render_frame_id,
[email protected]130757672012-10-24 00:26:19287 ResourceContext* context,
[email protected]e67385f2011-12-21 06:00:56288 const GURL& url,
tommyclif2a1e9f2016-10-06 18:34:36289 const url::Origin& main_frame_origin,
[email protected]e67385f2011-12-21 06:00:56290 const std::string& mime_type,
291 bool allow_wildcard,
292 bool* is_stale,
[email protected]d7bd3e52013-07-21 04:29:20293 WebPluginInfo* info,
[email protected]e67385f2011-12-21 06:00:56294 std::string* actual_mime_type) {
[email protected]d7bd3e52013-07-21 04:29:20295 std::vector<WebPluginInfo> plugins;
[email protected]68598072011-07-29 08:21:28296 std::vector<std::string> mime_types;
[email protected]88ca4912011-10-12 14:00:43297 bool stale = GetPluginInfoArray(
298 url, mime_type, allow_wildcard, &plugins, &mime_types);
299 if (is_stale)
300 *is_stale = stale;
[email protected]dfba8762011-09-02 12:49:54301
[email protected]68598072011-07-29 08:21:28302 for (size_t i = 0; i < plugins.size(); ++i) {
tommyclif2a1e9f2016-10-06 18:34:36303 if (!filter_ ||
304 filter_->IsPluginAvailable(render_process_id, render_frame_id, context,
305 url, main_frame_origin, &plugins[i])) {
[email protected]68598072011-07-29 08:21:28306 *info = plugins[i];
307 if (actual_mime_type)
308 *actual_mime_type = mime_types[i];
309 return true;
310 }
311 }
312 return false;
[email protected]6fdd4182010-10-14 23:59:26313}
314
[email protected]2dec8ec2013-02-07 19:20:34315bool PluginServiceImpl::GetPluginInfoByPath(const base::FilePath& plugin_path,
[email protected]d7bd3e52013-07-21 04:29:20316 WebPluginInfo* info) {
317 std::vector<WebPluginInfo> plugins;
[email protected]29e2fb42013-07-19 01:13:47318 PluginList::Singleton()->GetPluginsNoRefresh(&plugins);
[email protected]88ca4912011-10-12 14:00:43319
[email protected]d7bd3e52013-07-21 04:29:20320 for (std::vector<WebPluginInfo>::iterator it = plugins.begin();
[email protected]88ca4912011-10-12 14:00:43321 it != plugins.end();
322 ++it) {
323 if (it->path == plugin_path) {
324 *info = *it;
325 return true;
326 }
327 }
328
329 return false;
330}
331
[email protected]fcf75d42013-12-03 20:11:26332base::string16 PluginServiceImpl::GetPluginDisplayNameByPath(
[email protected]2dec8ec2013-02-07 19:20:34333 const base::FilePath& path) {
[email protected]fcf75d42013-12-03 20:11:26334 base::string16 plugin_name = path.LossyDisplayName();
[email protected]d7bd3e52013-07-21 04:29:20335 WebPluginInfo info;
[email protected]8be45842012-04-13 19:49:29336 if (PluginService::GetInstance()->GetPluginInfoByPath(path, &info) &&
337 !info.name.empty()) {
338 plugin_name = info.name;
339#if defined(OS_MACOSX)
340 // Many plugins on the Mac have .plugin in the actual name, which looks
341 // terrible, so look for that and strip it off if present.
342 const std::string kPluginExtension = ".plugin";
brettwa7ff1b292015-07-16 17:49:29343 if (base::EndsWith(plugin_name, base::ASCIIToUTF16(kPluginExtension),
344 base::CompareCase::SENSITIVE))
[email protected]8be45842012-04-13 19:49:29345 plugin_name.erase(plugin_name.length() - kPluginExtension.length());
346#endif // OS_MACOSX
347 }
348 return plugin_name;
349}
350
fdoray9292e0722017-05-13 03:47:51351void PluginServiceImpl::GetPlugins(GetPluginsCallback callback) {
352 base::PostTaskAndReplyWithResult(
353 plugin_list_task_runner_.get(), FROM_HERE, base::BindOnce([]() {
354 std::vector<WebPluginInfo> plugins;
355 PluginList::Singleton()->GetPlugins(&plugins);
356 return plugins;
357 }),
358 std::move(callback));
[email protected]dfba8762011-09-02 12:49:54359}
360
[email protected]e67385f2011-12-21 06:00:56361void PluginServiceImpl::RegisterPepperPlugins() {
[email protected]dac6a5a2013-07-25 05:06:48362 ComputePepperPluginList(&ppapi_plugins_);
[email protected]a08ebea2011-02-13 17:50:20363 for (size_t i = 0; i < ppapi_plugins_.size(); ++i) {
[email protected]c6f3dea2012-01-14 02:23:11364 RegisterInternalPlugin(ppapi_plugins_[i].ToWebPluginInfo(), true);
[email protected]4e0616e2010-05-28 14:55:53365 }
366}
[email protected]634d23d2011-01-19 10:38:19367
[email protected]eb415bf0e2011-04-14 02:45:42368// There should generally be very few plugins so a brute-force search is fine.
[email protected]130757672012-10-24 00:26:19369PepperPluginInfo* PluginServiceImpl::GetRegisteredPpapiPluginInfo(
[email protected]2dec8ec2013-02-07 19:20:34370 const base::FilePath& plugin_path) {
[email protected]3627aa3f2013-09-17 22:32:51371 for (size_t i = 0; i < ppapi_plugins_.size(); ++i) {
thestig76ee1f42016-07-08 18:54:00372 if (ppapi_plugins_[i].path == plugin_path)
373 return &ppapi_plugins_[i];
[email protected]eb415bf0e2011-04-14 02:45:42374 }
[email protected]076117592011-08-17 03:16:41375 // We did not find the plugin in our list. But wait! the plugin can also
376 // be a latecomer, as it happens with pepper flash. This information
377 // can be obtained from the PluginList singleton and we can use it to
378 // construct it and add it to the list. This same deal needs to be done
379 // in the renderer side in PepperPluginRegistry.
[email protected]d7bd3e52013-07-21 04:29:20380 WebPluginInfo webplugin_info;
[email protected]88ca4912011-10-12 14:00:43381 if (!GetPluginInfoByPath(plugin_path, &webplugin_info))
thestig76ee1f42016-07-08 18:54:00382 return nullptr;
[email protected]130757672012-10-24 00:26:19383 PepperPluginInfo new_pepper_info;
[email protected]076117592011-08-17 03:16:41384 if (!MakePepperPluginInfo(webplugin_info, &new_pepper_info))
thestig76ee1f42016-07-08 18:54:00385 return nullptr;
[email protected]076117592011-08-17 03:16:41386 ppapi_plugins_.push_back(new_pepper_info);
thestig76ee1f42016-07-08 18:54:00387 return &ppapi_plugins_.back();
[email protected]eb415bf0e2011-04-14 02:45:42388}
389
[email protected]130757672012-10-24 00:26:19390void PluginServiceImpl::SetFilter(PluginServiceFilter* filter) {
[email protected]3a5180ae2011-12-21 02:39:38391 filter_ = filter;
392}
393
[email protected]130757672012-10-24 00:26:19394PluginServiceFilter* PluginServiceImpl::GetFilter() {
[email protected]3a5180ae2011-12-21 02:39:38395 return filter_;
396}
397
[email protected]47214d882012-02-29 06:28:48398static const unsigned int kMaxCrashesPerInterval = 3;
399static const unsigned int kCrashesInterval = 120;
400
[email protected]2dec8ec2013-02-07 19:20:34401void PluginServiceImpl::RegisterPluginCrash(const base::FilePath& path) {
mostynb4c27d042015-03-18 21:47:47402 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]2dec8ec2013-02-07 19:20:34403 std::map<base::FilePath, std::vector<base::Time> >::iterator i =
[email protected]47214d882012-02-29 06:28:48404 crash_times_.find(path);
405 if (i == crash_times_.end()) {
406 crash_times_[path] = std::vector<base::Time>();
407 i = crash_times_.find(path);
408 }
409 if (i->second.size() == kMaxCrashesPerInterval) {
410 i->second.erase(i->second.begin());
411 }
412 base::Time time = base::Time::Now();
413 i->second.push_back(time);
414}
415
[email protected]2dec8ec2013-02-07 19:20:34416bool PluginServiceImpl::IsPluginUnstable(const base::FilePath& path) {
mostynb4c27d042015-03-18 21:47:47417 DCHECK_CURRENTLY_ON(BrowserThread::IO);
[email protected]2dec8ec2013-02-07 19:20:34418 std::map<base::FilePath, std::vector<base::Time> >::const_iterator i =
[email protected]47214d882012-02-29 06:28:48419 crash_times_.find(path);
420 if (i == crash_times_.end()) {
421 return false;
422 }
423 if (i->second.size() != kMaxCrashesPerInterval) {
424 return false;
425 }
426 base::TimeDelta delta = base::Time::Now() - i->second[0];
[email protected]d8c70062013-04-24 00:22:34427 return delta.InSeconds() <= kCrashesInterval;
[email protected]47214d882012-02-29 06:28:48428}
429
[email protected]e67385f2011-12-21 06:00:56430void PluginServiceImpl::RefreshPlugins() {
[email protected]29e2fb42013-07-19 01:13:47431 PluginList::Singleton()->RefreshPlugins();
[email protected]f520b5b2011-11-08 02:42:14432}
433
[email protected]8f3372122013-07-18 04:34:14434void PluginServiceImpl::RegisterInternalPlugin(
[email protected]d7bd3e52013-07-21 04:29:20435 const WebPluginInfo& info,
[email protected]8f3372122013-07-18 04:34:14436 bool add_at_beginning) {
[email protected]29e2fb42013-07-19 01:13:47437 PluginList::Singleton()->RegisterInternalPlugin(info, add_at_beginning);
[email protected]f520b5b2011-11-08 02:42:14438}
439
[email protected]2dec8ec2013-02-07 19:20:34440void PluginServiceImpl::UnregisterInternalPlugin(const base::FilePath& path) {
[email protected]29e2fb42013-07-19 01:13:47441 PluginList::Singleton()->UnregisterInternalPlugin(path);
[email protected]f520b5b2011-11-08 02:42:14442}
443
[email protected]8f3372122013-07-18 04:34:14444void PluginServiceImpl::GetInternalPlugins(
[email protected]d7bd3e52013-07-21 04:29:20445 std::vector<WebPluginInfo>* plugins) {
[email protected]29e2fb42013-07-19 01:13:47446 PluginList::Singleton()->GetInternalPlugins(plugins);
[email protected]8f3372122013-07-18 04:34:14447}
448
[email protected]aec5ed52014-06-20 07:51:42449bool PluginServiceImpl::PpapiDevChannelSupported(
450 BrowserContext* browser_context,
451 const GURL& document_url) {
wfh6be06282015-07-20 18:04:02452 return GetContentClient()->browser()->IsPluginAllowedToUseDevChannelAPIs(
453 browser_context, document_url);
[email protected]8ddc6b7c2013-12-12 20:42:06454}
455
[email protected]130757672012-10-24 00:26:19456} // namespace content