blob: 1d19e684d0c26c35ff56e3dc21771974856d780c [file] [log] [blame]
[email protected]dca589ef2012-01-09 11:53:321// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]8aa7a412011-11-07 12:33:422// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Nicholas Verned391eae2017-11-13 02:41:385#include "chrome/browser/plugins/plugin_info_host_impl.h"
[email protected]8aa7a412011-11-07 12:33:426
avib896c712015-12-26 02:10:437#include <stddef.h>
dcheng4af48582016-04-19 00:29:358
wafflescd59e9b2016-08-30 04:34:449#include <algorithm>
dcheng4af48582016-04-19 00:29:3510#include <memory>
dchenge73d8520c2015-12-27 01:19:0911#include <utility>
avib896c712015-12-26 02:10:4312
[email protected]8aa7a412011-11-07 12:33:4213#include "base/bind.h"
rbpotter654f42d2016-12-02 22:17:0714#include "base/memory/singleton.h"
Eugene Kim0b4b4572018-09-01 02:37:5815#include "base/stl_util.h"
[email protected]e309f312013-06-07 21:50:0816#include "base/strings/utf_string_conversions.h"
Eric Seckler8652dcd52018-09-20 10:42:2817#include "base/task/post_task.h"
waffles77255cc2016-08-02 17:25:1218#include "base/task_runner_util.h"
Nico Webereaa08412019-08-14 01:24:3719#include "build/branding_buildflags.h"
avib896c712015-12-26 02:10:4320#include "build/build_config.h"
wfhdfcab2e42014-11-07 06:48:3221#include "chrome/browser/browser_process.h"
peconn5100d432015-09-16 12:03:0822#include "chrome/browser/content_settings/host_content_settings_map_factory.h"
[email protected]6be31d202013-02-01 18:20:5423#include "chrome/browser/plugins/chrome_plugin_service_filter.h"
[email protected]cd33d282012-09-21 12:53:0424#include "chrome/browser/plugins/plugin_finder.h"
[email protected]de75c702012-09-25 23:06:0225#include "chrome/browser/plugins/plugin_metadata.h"
[email protected]601e3c82013-10-03 01:31:2026#include "chrome/browser/plugins/plugin_prefs.h"
raymes978301a22016-09-22 00:54:2827#include "chrome/browser/plugins/plugin_utils.h"
[email protected]8aa7a412011-11-07 12:33:4228#include "chrome/browser/profiles/profile.h"
wfhdfcab2e42014-11-07 06:48:3229#include "chrome/browser/ui/browser_otr_state.h"
Scott Violet6200d332018-02-23 21:29:2330#include "chrome/common/buildflags.h"
wafflescd59e9b2016-08-30 04:34:4431#include "chrome/common/chrome_content_client.h"
Nicholas Verneb5df4f72017-11-08 09:12:0732#include "chrome/common/plugin.mojom.h"
[email protected]8aa7a412011-11-07 12:33:4233#include "chrome/common/pref_names.h"
waffles77255cc2016-08-02 17:25:1234#include "components/component_updater/component_updater_service.h"
mukai8eaec822014-10-25 17:53:1635#include "components/content_settings/core/browser/content_settings_utils.h"
36#include "components/content_settings/core/browser/host_content_settings_map.h"
mukai077089f2014-09-11 18:41:5237#include "components/content_settings/core/common/content_settings.h"
rbpotter654f42d2016-12-02 22:17:0738#include "components/keyed_service/content/browser_context_keyed_service_shutdown_notifier_factory.h"
Scott Violet9ae82892018-03-01 18:38:1239#include "components/nacl/common/buildflags.h"
Bernhard Bauer19190732017-09-28 09:03:3340#include "components/pref_registry/pref_registry_syncable.h"
brettwb1fc1b82016-02-02 00:19:0841#include "components/prefs/pref_service.h"
Steven Holtef0f46772017-12-11 20:54:5142#include "components/ukm/content/source_url_recorder.h"
Eric Seckler8652dcd52018-09-20 10:42:2843#include "content/public/browser/browser_task_traits.h"
[email protected]3a5180ae2011-12-21 02:39:3844#include "content/public/browser/plugin_service.h"
[email protected]31f376c2012-03-13 16:43:0945#include "content/public/browser/plugin_service_filter.h"
tommycli910b4082017-04-03 17:04:1546#include "content/public/browser/render_frame_host.h"
wfhdfcab2e42014-11-07 06:48:3247#include "content/public/common/content_constants.h"
Scott Violetc8240b02018-03-08 22:03:5948#include "extensions/buildflags/buildflags.h"
wfhdfcab2e42014-11-07 06:48:3249#include "net/base/registry_controlled_domains/registry_controlled_domain.h"
Scott Violet02e38b92018-03-27 23:42:1450#include "ppapi/buildflags/buildflags.h"
Steven Holtef0f46772017-12-11 20:54:5151#include "services/metrics/public/cpp/ukm_builders.h"
Mounir Lamourifd9dcefa2017-07-06 10:26:5552#include "services/metrics/public/cpp/ukm_recorder.h"
[email protected]761fa4702013-07-02 15:25:1553#include "url/gurl.h"
tommyclif2a1e9f2016-10-06 18:34:3654#include "url/origin.h"
[email protected]b9b88a082013-03-21 03:51:0255
brettw00899e62016-11-12 02:10:1756#if BUILDFLAG(ENABLE_EXTENSIONS)
fsamuel8dfa19a2015-05-05 01:00:3957#include "components/guest_view/browser/guest_view_base.h"
Sadrul Habib Chowdhuryf43c33c2014-12-04 15:53:5258#include "extensions/browser/extension_registry.h"
hanxi0d0a1e92014-08-26 18:39:4859#include "extensions/browser/guest_view/web_view/web_view_renderer_state.h"
lfg44c8a68f2015-04-16 16:38:1560#include "extensions/common/constants.h"
Sadrul Habib Chowdhuryf43c33c2014-12-04 15:53:5261#include "extensions/common/extension.h"
62#include "extensions/common/manifest_handlers/webview_info.h"
[email protected]21a20132014-07-16 00:48:5963#endif
64
Nico Weberaf3b00b2017-09-11 17:58:1765#if BUILDFLAG(ENABLE_NACL)
[email protected]e0ff1aa2014-08-16 01:38:1166#include "components/nacl/common/nacl_constants.h"
67#endif
68
[email protected]3a5180ae2011-12-21 02:39:3869using content::PluginService;
[email protected]d7bd3e52013-07-21 04:29:2070using content::WebPluginInfo;
[email protected]3a5180ae2011-12-21 02:39:3871
[email protected]b9b88a082013-03-21 03:51:0272namespace {
73
Daniel Bratell84928c52018-01-16 21:40:3474class PluginInfoHostImplShutdownNotifierFactory
rbpotter654f42d2016-12-02 22:17:0775 : public BrowserContextKeyedServiceShutdownNotifierFactory {
76 public:
Daniel Bratell84928c52018-01-16 21:40:3477 static PluginInfoHostImplShutdownNotifierFactory* GetInstance() {
78 return base::Singleton<PluginInfoHostImplShutdownNotifierFactory>::get();
rbpotter654f42d2016-12-02 22:17:0779 }
80
81 private:
Daniel Bratell84928c52018-01-16 21:40:3482 friend struct base::DefaultSingletonTraits<
83 PluginInfoHostImplShutdownNotifierFactory>;
rbpotter654f42d2016-12-02 22:17:0784
Daniel Bratell84928c52018-01-16 21:40:3485 PluginInfoHostImplShutdownNotifierFactory()
rbpotter654f42d2016-12-02 22:17:0786 : BrowserContextKeyedServiceShutdownNotifierFactory(
Nicholas Verned391eae2017-11-13 02:41:3887 "PluginInfoHostImpl") {}
rbpotter654f42d2016-12-02 22:17:0788
Daniel Bratell84928c52018-01-16 21:40:3489 ~PluginInfoHostImplShutdownNotifierFactory() override {}
rbpotter654f42d2016-12-02 22:17:0790
Daniel Bratell84928c52018-01-16 21:40:3491 DISALLOW_COPY_AND_ASSIGN(PluginInfoHostImplShutdownNotifierFactory);
rbpotter654f42d2016-12-02 22:17:0792};
93
brettw00899e62016-11-12 02:10:1794#if BUILDFLAG(ENABLE_EXTENSIONS)
Sadrul Habib Chowdhuryf43c33c2014-12-04 15:53:5295// Returns whether a request from a plugin to load |resource| from a renderer
96// with process id |process_id| is a request for an internal resource by an app
97// listed in |accessible_resources| in its manifest.
98bool IsPluginLoadingAccessibleResourceInWebView(
99 extensions::ExtensionRegistry* extension_registry,
100 int process_id,
101 const GURL& resource) {
102 extensions::WebViewRendererState* renderer_state =
103 extensions::WebViewRendererState::GetInstance();
104 std::string partition_id;
105 if (!renderer_state->IsGuest(process_id) ||
106 !renderer_state->GetPartitionID(process_id, &partition_id)) {
107 return false;
108 }
109
110 const std::string extension_id = resource.host();
paulmeyerad727fc62015-09-09 15:29:59111 const extensions::Extension* extension = extension_registry->GetExtensionById(
112 extension_id, extensions::ExtensionRegistry::ENABLED);
113 if (!extension || !extensions::WebviewInfo::IsResourceWebviewAccessible(
Nicholas Verned391eae2017-11-13 02:41:38114 extension, partition_id, resource.path())) {
Sadrul Habib Chowdhuryf43c33c2014-12-04 15:53:52115 return false;
116 }
117
118 // Make sure the renderer making the request actually belongs to the
119 // same extension.
120 std::string owner_extension;
121 return renderer_state->GetOwnerInfo(process_id, nullptr, &owner_extension) &&
122 owner_extension == extension_id;
123}
brettw00899e62016-11-12 02:10:17124#endif // BUILDFLAG(ENABLE_EXTENSIONS)
Sadrul Habib Chowdhuryf43c33c2014-12-04 15:53:52125
[email protected]b9b88a082013-03-21 03:51:02126} // namespace
127
Nicholas Verned391eae2017-11-13 02:41:38128PluginInfoHostImpl::Context::Context(int render_process_id, Profile* profile)
[email protected]0a8f3a7f2012-01-17 16:17:19129 : render_process_id_(render_process_id),
brettw00899e62016-11-12 02:10:17130#if BUILDFLAG(ENABLE_EXTENSIONS)
Sadrul Habib Chowdhuryf43c33c2014-12-04 15:53:52131 extension_registry_(extensions::ExtensionRegistry::Get(profile)),
132#endif
Nicholas Verned391eae2017-11-13 02:41:38133 host_content_settings_map_(
134 HostContentSettingsMapFactory::GetForProfile(profile)),
[email protected]601e3c82013-10-03 01:31:20135 plugin_prefs_(PluginPrefs::GetForProfile(profile)) {
[email protected]8aa7a412011-11-07 12:33:42136 allow_outdated_plugins_.Init(prefs::kPluginsAllowOutdated,
[email protected]96a5c342012-12-04 18:14:02137 profile->GetPrefs());
Bernhard Bauer19190732017-09-28 09:03:33138 run_all_flash_in_allow_mode_.Init(prefs::kRunAllFlashInAllowMode,
139 profile->GetPrefs());
[email protected]8aa7a412011-11-07 12:33:42140}
141
Nicholas Verned391eae2017-11-13 02:41:38142PluginInfoHostImpl::Context::~Context() {}
[email protected]0a8f3a7f2012-01-17 16:17:19143
Nicholas Verned391eae2017-11-13 02:41:38144void PluginInfoHostImpl::Context::ShutdownOnUIThread() {
rbpotter654f42d2016-12-02 22:17:07145 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
rbpotter654f42d2016-12-02 22:17:07146 allow_outdated_plugins_.Destroy();
Bernhard Bauer19190732017-09-28 09:03:33147 run_all_flash_in_allow_mode_.Destroy();
rbpotter654f42d2016-12-02 22:17:07148}
149
Nicholas Verned391eae2017-11-13 02:41:38150PluginInfoHostImpl::PluginInfoHostImpl(int render_process_id, Profile* profile)
Clark DuVall1df2052b2019-08-05 19:58:46151 : context_(render_process_id, profile) {
rbpotter654f42d2016-12-02 22:17:07152 shutdown_notifier_ =
Daniel Bratell84928c52018-01-16 21:40:34153 PluginInfoHostImplShutdownNotifierFactory::GetInstance()
154 ->Get(profile)
155 ->Subscribe(base::Bind(&PluginInfoHostImpl::ShutdownOnUIThread,
156 base::Unretained(this)));
rbpotter654f42d2016-12-02 22:17:07157}
158
Nicholas Verned391eae2017-11-13 02:41:38159void PluginInfoHostImpl::ShutdownOnUIThread() {
rbpotter654f42d2016-12-02 22:17:07160 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
161 context_.ShutdownOnUIThread();
162 shutdown_notifier_.reset();
[email protected]0a8f3a7f2012-01-17 16:17:19163}
164
Bernhard Bauer19190732017-09-28 09:03:33165// static
Nicholas Verned391eae2017-11-13 02:41:38166void PluginInfoHostImpl::RegisterUserPrefs(
Bernhard Bauer19190732017-09-28 09:03:33167 user_prefs::PrefRegistrySyncable* registry) {
168 registry->RegisterBooleanPref(prefs::kPluginsAllowOutdated, false);
Bernhard Bauer19190732017-09-28 09:03:33169 registry->RegisterBooleanPref(prefs::kRunAllFlashInAllowMode, false);
170}
171
Nicholas Verned391eae2017-11-13 02:41:38172PluginInfoHostImpl::~PluginInfoHostImpl() {}
[email protected]649d1c02012-04-27 02:56:21173
Nicholas Verned391eae2017-11-13 02:41:38174struct PluginInfoHostImpl::GetPluginInfo_Params {
[email protected]60eca4eb2013-12-06 00:02:16175 int render_frame_id;
[email protected]8aa7a412011-11-07 12:33:42176 GURL url;
tommyclif2a1e9f2016-10-06 18:34:36177 url::Origin main_frame_origin;
[email protected]8aa7a412011-11-07 12:33:42178 std::string mime_type;
179};
180
Nicholas Verned391eae2017-11-13 02:41:38181void PluginInfoHostImpl::GetPluginInfo(int32_t render_frame_id,
182 const GURL& url,
183 const url::Origin& origin,
184 const std::string& mime_type,
tzikcd02d3b2018-08-09 21:32:47185 GetPluginInfoCallback callback) {
Clark DuVall1df2052b2019-08-05 19:58:46186 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
Nicholas Verneb5df4f72017-11-08 09:12:07187 GetPluginInfo_Params params = {render_frame_id, url, origin, mime_type};
Clark DuVall1df2052b2019-08-05 19:58:46188 PluginService::GetInstance()->GetPlugins(
189 base::BindOnce(&PluginInfoHostImpl::PluginsLoaded,
190 weak_factory_.GetWeakPtr(), params, std::move(callback)));
[email protected]8aa7a412011-11-07 12:33:42191}
192
Nicholas Verned391eae2017-11-13 02:41:38193void PluginInfoHostImpl::PluginsLoaded(
[email protected]8aa7a412011-11-07 12:33:42194 const GetPluginInfo_Params& params,
Nicholas Verneb5df4f72017-11-08 09:12:07195 GetPluginInfoCallback callback,
[email protected]dfdfeb72012-06-08 11:29:02196 const std::vector<WebPluginInfo>& plugins) {
Nicholas Verneb5df4f72017-11-08 09:12:07197 chrome::mojom::PluginInfoPtr output = chrome::mojom::PluginInfo::New();
[email protected]79fa3362012-03-28 16:21:11198 // This also fills in |actual_mime_type|.
dcheng4af48582016-04-19 00:29:35199 std::unique_ptr<PluginMetadata> plugin_metadata;
[email protected]60eca4eb2013-12-06 00:02:16200 if (context_.FindEnabledPlugin(params.render_frame_id, params.url,
tommyclif2a1e9f2016-10-06 18:34:36201 params.main_frame_origin, params.mime_type,
waffles77255cc2016-08-02 17:25:12202 &output->status, &output->plugin,
203 &output->actual_mime_type, &plugin_metadata)) {
tommyclie97656b82016-11-30 16:43:00204 context_.DecidePluginStatus(
205 params.url, params.main_frame_origin, output->plugin,
206 plugin_metadata->GetSecurityStatus(output->plugin),
207 plugin_metadata->identifier(), &output->status);
[email protected]79fa3362012-03-28 16:21:11208 }
[email protected]cd33d282012-09-21 12:53:04209
Nicholas Verneb5df4f72017-11-08 09:12:07210 if (output->status == chrome::mojom::PluginStatus::kNotFound) {
waffles77255cc2016-08-02 17:25:12211 // Check to see if the component updater can fetch an implementation.
Clark DuVall1df2052b2019-08-05 19:58:46212 std::unique_ptr<component_updater::ComponentInfo> cus_plugin_info =
213 g_browser_process->component_updater()->GetComponentForMimeType(
214 params.mime_type);
215 ComponentPluginLookupDone(params, std::move(output), std::move(callback),
216 std::move(plugin_metadata),
217 std::move(cus_plugin_info));
waffles77255cc2016-08-02 17:25:12218 } else {
Nicholas Verneb5df4f72017-11-08 09:12:07219 GetPluginInfoFinish(params, std::move(output), std::move(callback),
220 std::move(plugin_metadata));
wfhbe79ad52014-11-07 19:02:07221 }
[email protected]8aa7a412011-11-07 12:33:42222}
223
Nicholas Verned391eae2017-11-13 02:41:38224void PluginInfoHostImpl::Context::DecidePluginStatus(
tommyclie97656b82016-11-30 16:43:00225 const GURL& url,
226 const url::Origin& main_frame_origin,
[email protected]546abf32012-09-14 16:55:09227 const WebPluginInfo& plugin,
tommyclie97656b82016-11-30 16:43:00228 PluginMetadata::SecurityStatus security_status,
229 const std::string& plugin_identifier,
Nicholas Verneb5df4f72017-11-08 09:12:07230 chrome::mojom::PluginStatus* status) const {
tommyclie97656b82016-11-30 16:43:00231 if (security_status == PluginMetadata::SECURITY_STATUS_FULLY_TRUSTED) {
Nicholas Verneb5df4f72017-11-08 09:12:07232 *status = chrome::mojom::PluginStatus::kAllowed;
wfhe53608b2016-04-07 02:18:53233 return;
234 }
235
Tommy Li5c97af5d2020-10-13 23:21:05236// This block is separate from the outdated check, because the deprecated UI
237// must take precedence over any content setting or HTML5 by Default.
238#if BUILDFLAG(ENABLE_PLUGINS)
239 if (security_status == PluginMetadata::SECURITY_STATUS_DEPRECATED) {
240 *status = chrome::mojom::PluginStatus::kDeprecated;
241 return;
242 }
243#endif
244
[email protected]8aa7a412011-11-07 12:33:42245 ContentSetting plugin_setting = CONTENT_SETTING_DEFAULT;
246 bool uses_default_content_setting = true;
[email protected]6a9d1deb2014-01-13 19:39:41247 bool is_managed = false;
tommyclie86b2982015-03-16 20:16:45248 // Check plugin content settings. The primary URL is the top origin URL and
249 // the secondary URL is the plugin URL.
raymes978301a22016-09-22 00:54:28250 PluginUtils::GetPluginContentSetting(
tommyclie97656b82016-11-30 16:43:00251 host_content_settings_map_, plugin, main_frame_origin, url,
252 plugin_identifier, &plugin_setting, &uses_default_content_setting,
253 &is_managed);
tommyclie2b1f1b2015-03-31 22:54:59254
[email protected]8aa7a412011-11-07 12:33:42255 DCHECK(plugin_setting != CONTENT_SETTING_DEFAULT);
tommyclie2b1f1b2015-03-31 22:54:59256 DCHECK(plugin_setting != CONTENT_SETTING_ASK);
[email protected]8aa7a412011-11-07 12:33:42257
Nicholas Verneb5df4f72017-11-08 09:12:07258 if (*status == chrome::mojom::PluginStatus::kFlashHiddenPreferHtml) {
tommyclie97656b82016-11-30 16:43:00259 if (plugin_setting == CONTENT_SETTING_BLOCK) {
Tommy C. Li717a34a2019-03-28 16:24:51260 *status = is_managed ? chrome::mojom::PluginStatus::kBlockedByPolicy
261 : chrome::mojom::PluginStatus::kBlockedNoLoading;
tommyclie97656b82016-11-30 16:43:00262 }
263 return;
264 }
265
bauerbecab4f52017-03-13 20:16:41266#if BUILDFLAG(ENABLE_PLUGINS)
tommyclie86b2982015-03-16 20:16:45267 // Check if the plugin is outdated.
tommyclie97656b82016-11-30 16:43:00268 if (security_status == PluginMetadata::SECURITY_STATUS_OUT_OF_DATE &&
[email protected]9f230ed2012-05-24 11:19:40269 !allow_outdated_plugins_.GetValue()) {
[email protected]8aa7a412011-11-07 12:33:42270 if (allow_outdated_plugins_.IsManaged()) {
Nicholas Verneb5df4f72017-11-08 09:12:07271 *status = chrome::mojom::PluginStatus::kOutdatedDisallowed;
[email protected]8aa7a412011-11-07 12:33:42272 } else {
Nicholas Verneb5df4f72017-11-08 09:12:07273 *status = chrome::mojom::PluginStatus::kOutdatedBlocked;
[email protected]8aa7a412011-11-07 12:33:42274 }
275 return;
276 }
bauerbecab4f52017-03-13 20:16:41277#endif // BUILDFLAG(ENABLE_PLUGINS)
[email protected]ef97ce342012-09-24 20:05:02278
tommyclie86b2982015-03-16 20:16:45279 // Check if the plugin is crashing too much.
[email protected]ef97ce342012-09-24 20:05:02280 if (PluginService::GetInstance()->IsPluginUnstable(plugin.path) &&
Nicholas Verned391eae2017-11-13 02:41:38281 plugin_setting != CONTENT_SETTING_BLOCK && uses_default_content_setting) {
Nicholas Verneb5df4f72017-11-08 09:12:07282 *status = chrome::mojom::PluginStatus::kUnauthorized;
[email protected]ef97ce342012-09-24 20:05:02283 return;
284 }
[email protected]8aa7a412011-11-07 12:33:42285
brettw00899e62016-11-12 02:10:17286#if BUILDFLAG(ENABLE_EXTENSIONS)
Sadrul Habib Chowdhuryf43c33c2014-12-04 15:53:52287 // If an app has explicitly made internal resources available by listing them
288 // in |accessible_resources| in the manifest, then allow them to be loaded by
289 // plugins inside a guest-view.
tommyclie97656b82016-11-30 16:43:00290 if (url.SchemeIs(extensions::kExtensionScheme) && !is_managed &&
lfg44c8a68f2015-04-16 16:38:15291 plugin_setting == CONTENT_SETTING_BLOCK &&
tommyclie97656b82016-11-30 16:43:00292 IsPluginLoadingAccessibleResourceInWebView(extension_registry_,
293 render_process_id_, url)) {
Sadrul Habib Chowdhuryf43c33c2014-12-04 15:53:52294 plugin_setting = CONTENT_SETTING_ALLOW;
295 }
brettw00899e62016-11-12 02:10:17296#endif // BUILDFLAG(ENABLE_EXTENSIONS)
Sadrul Habib Chowdhuryf43c33c2014-12-04 15:53:52297
tommycli608ec89b2016-09-28 16:39:00298 if (plugin_setting == CONTENT_SETTING_DETECT_IMPORTANT_CONTENT ||
299 (plugin_setting == CONTENT_SETTING_ALLOW &&
Bernhard Bauer19190732017-09-28 09:03:33300 !run_all_flash_in_allow_mode_.GetValue())) {
Nicholas Verneb5df4f72017-11-08 09:12:07301 *status = chrome::mojom::PluginStatus::kPlayImportantContent;
tommyclie2b1f1b2015-03-31 22:54:59302 } else if (plugin_setting == CONTENT_SETTING_BLOCK) {
Tommy C. Li717a34a2019-03-28 16:24:51303 *status = is_managed ? chrome::mojom::PluginStatus::kBlockedByPolicy
304 : chrome::mojom::PluginStatus::kBlocked;
[email protected]6a9d1deb2014-01-13 19:39:41305 }
[email protected]aea757d2013-09-27 22:27:38306
brettw00899e62016-11-12 02:10:17307#if BUILDFLAG(ENABLE_EXTENSIONS)
tommycli550b2222015-09-03 21:06:10308 // Allow an embedder of <webview> to block a plugin from being loaded inside
309 // the guest. In order to do this, set the status to 'Unauthorized' here,
310 // and update the status as appropriate depending on the response from the
311 // embedder.
Nicholas Verneb5df4f72017-11-08 09:12:07312 if (*status == chrome::mojom::PluginStatus::kAllowed ||
313 *status == chrome::mojom::PluginStatus::kBlocked ||
314 *status == chrome::mojom::PluginStatus::kPlayImportantContent) {
[email protected]140d6cd92014-08-12 18:26:46315 if (extensions::WebViewRendererState::GetInstance()->IsGuest(
tommycli550b2222015-09-03 21:06:10316 render_process_id_))
Nicholas Verneb5df4f72017-11-08 09:12:07317 *status = chrome::mojom::PluginStatus::kUnauthorized;
[email protected]aea757d2013-09-27 22:27:38318 }
tommycli550b2222015-09-03 21:06:10319#endif
[email protected]8aa7a412011-11-07 12:33:42320}
321
Nicholas Verned391eae2017-11-13 02:41:38322bool PluginInfoHostImpl::Context::FindEnabledPlugin(
[email protected]60eca4eb2013-12-06 00:02:16323 int render_frame_id,
[email protected]8aa7a412011-11-07 12:33:42324 const GURL& url,
tommyclif2a1e9f2016-10-06 18:34:36325 const url::Origin& main_frame_origin,
[email protected]8aa7a412011-11-07 12:33:42326 const std::string& mime_type,
Nicholas Verneb5df4f72017-11-08 09:12:07327 chrome::mojom::PluginStatus* status,
[email protected]dfdfeb72012-06-08 11:29:02328 WebPluginInfo* plugin,
[email protected]4da405672012-10-25 10:43:03329 std::string* actual_mime_type,
dcheng4af48582016-04-19 00:29:35330 std::unique_ptr<PluginMetadata>* plugin_metadata) const {
Nicholas Verneb5df4f72017-11-08 09:12:07331 *status = chrome::mojom::PluginStatus::kAllowed;
bauerb96d29c02015-04-09 08:40:35332
[email protected]8aa7a412011-11-07 12:33:42333 bool allow_wildcard = true;
[email protected]dfdfeb72012-06-08 11:29:02334 std::vector<WebPluginInfo> matching_plugins;
[email protected]8aa7a412011-11-07 12:33:42335 std::vector<std::string> mime_types;
336 PluginService::GetInstance()->GetPluginInfoArray(
337 url, mime_type, allow_wildcard, &matching_plugins, &mime_types);
Nico Webereaa08412019-08-14 01:24:37338#if BUILDFLAG(GOOGLE_CHROME_BRANDING)
Eugene Kim0b4b4572018-09-01 02:37:58339 base::EraseIf(matching_plugins, [&](const WebPluginInfo& info) {
340 return info.path.value() == ChromeContentClient::kNotPresent;
341 });
Nico Webereaa08412019-08-14 01:24:37342#endif // BUILDFLAG(GOOGLE_CHROME_BRANDING)
[email protected]4da405672012-10-25 10:43:03343 if (matching_plugins.empty()) {
Nicholas Verneb5df4f72017-11-08 09:12:07344 *status = chrome::mojom::PluginStatus::kNotFound;
[email protected]4da405672012-10-25 10:43:03345 return false;
346 }
347
[email protected]3a5180ae2011-12-21 02:39:38348 content::PluginServiceFilter* filter =
349 PluginService::GetInstance()->GetFilter();
[email protected]4da405672012-10-25 10:43:03350 size_t i = 0;
351 for (; i < matching_plugins.size(); ++i) {
Clark DuVall1df2052b2019-08-05 19:58:46352 if (!filter ||
353 filter->IsPluginAvailable(render_process_id_, render_frame_id, url,
354 main_frame_origin, &matching_plugins[i])) {
[email protected]4da405672012-10-25 10:43:03355 break;
[email protected]8aa7a412011-11-07 12:33:42356 }
357 }
358
tommyclie86b2982015-03-16 20:16:45359 // If we broke out of the loop, we have found an enabled plugin.
[email protected]4da405672012-10-25 10:43:03360 bool enabled = i < matching_plugins.size();
361 if (!enabled) {
tommyclie86b2982015-03-16 20:16:45362 // Otherwise, we only found disabled plugins, so we take the first one.
[email protected]4da405672012-10-25 10:43:03363 i = 0;
Nicholas Verneb5df4f72017-11-08 09:12:07364 *status = chrome::mojom::PluginStatus::kDisabled;
[email protected]4da405672012-10-25 10:43:03365 }
366
367 *plugin = matching_plugins[i];
368 *actual_mime_type = mime_types[i];
369 if (plugin_metadata)
370 *plugin_metadata = PluginFinder::GetInstance()->GetPluginMetadata(*plugin);
371
372 return enabled;
[email protected]8aa7a412011-11-07 12:33:42373}
374
Nicholas Verned391eae2017-11-13 02:41:38375void PluginInfoHostImpl::ComponentPluginLookupDone(
waffles77255cc2016-08-02 17:25:12376 const GetPluginInfo_Params& params,
Nicholas Verneb5df4f72017-11-08 09:12:07377 chrome::mojom::PluginInfoPtr output,
378 GetPluginInfoCallback callback,
waffles77255cc2016-08-02 17:25:12379 std::unique_ptr<PluginMetadata> plugin_metadata,
waffles77255cc2016-08-02 17:25:12380 std::unique_ptr<component_updater::ComponentInfo> cus_plugin_info) {
381 if (cus_plugin_info) {
Nicholas Verneb5df4f72017-11-08 09:12:07382 output->status = chrome::mojom::PluginStatus::kComponentUpdateRequired;
Sean McAllisterdf807712020-08-13 23:19:09383#if defined(OS_LINUX) || defined(OS_CHROMEOS)
wafflese7759f72016-10-10 23:41:25384 if (cus_plugin_info->version != base::Version("0")) {
Nicholas Verneb5df4f72017-11-08 09:12:07385 output->status = chrome::mojom::PluginStatus::kRestartRequired;
wafflese7759f72016-10-10 23:41:25386 }
thestigd6e438182017-06-01 23:16:27387#endif
Tommy C. Li7c493d192019-03-28 21:50:26388 // Component Updater wouldn't provide a deprecated plugin.
389 bool plugin_is_deprecated = false;
Jeremy Romanec48d7a2018-03-01 17:35:09390 plugin_metadata = std::make_unique<PluginMetadata>(
waffles77255cc2016-08-02 17:25:12391 cus_plugin_info->id, cus_plugin_info->name, false, GURL(), GURL(),
Tommy C. Li7c493d192019-03-28 21:50:26392 base::ASCIIToUTF16(cus_plugin_info->id), std::string(),
393 plugin_is_deprecated);
waffles77255cc2016-08-02 17:25:12394 }
Nicholas Verneb5df4f72017-11-08 09:12:07395 GetPluginInfoFinish(params, std::move(output), std::move(callback),
396 std::move(plugin_metadata));
waffles77255cc2016-08-02 17:25:12397}
398
Nicholas Verned391eae2017-11-13 02:41:38399void PluginInfoHostImpl::GetPluginInfoFinish(
waffles77255cc2016-08-02 17:25:12400 const GetPluginInfo_Params& params,
Nicholas Verneb5df4f72017-11-08 09:12:07401 chrome::mojom::PluginInfoPtr output,
402 GetPluginInfoCallback callback,
403 std::unique_ptr<PluginMetadata> plugin_metadata) {
waffles77255cc2016-08-02 17:25:12404 if (plugin_metadata) {
405 output->group_identifier = plugin_metadata->identifier();
406 output->group_name = plugin_metadata->name();
407 }
408
409 context_.MaybeGrantAccess(output->status, output->plugin.path);
410
Nicholas Verneb5df4f72017-11-08 09:12:07411 std::move(callback).Run(std::move(output));
waffles77255cc2016-08-02 17:25:12412}
413
Nicholas Verned391eae2017-11-13 02:41:38414void PluginInfoHostImpl::Context::MaybeGrantAccess(
Nicholas Verneb5df4f72017-11-08 09:12:07415 chrome::mojom::PluginStatus status,
[email protected]650b2d52013-02-10 03:41:45416 const base::FilePath& path) const {
Nicholas Verneb5df4f72017-11-08 09:12:07417 if (status == chrome::mojom::PluginStatus::kAllowed ||
418 status == chrome::mojom::PluginStatus::kPlayImportantContent) {
[email protected]6be31d202013-02-01 18:20:54419 ChromePluginServiceFilter::GetInstance()->AuthorizePlugin(
420 render_process_id_, path);
421 }
422}
423
Nicholas Verned391eae2017-11-13 02:41:38424bool PluginInfoHostImpl::Context::IsPluginEnabled(
[email protected]4cbbeb42014-07-22 19:29:38425 const content::WebPluginInfo& plugin) const {
426 return plugin_prefs_->IsPluginEnabled(plugin);
427}