blob: 989d5d02cedba57efd233f4e15c5475a46eab711 [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"
gabb15e19072016-05-11 20:45:4119#include "base/threading/thread_task_runner_handle.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"
trizzofoa1b970452016-08-26 02:33:2528#include "chrome/browser/plugins/plugins_field_trial.h"
[email protected]8aa7a412011-11-07 12:33:4229#include "chrome/browser/profiles/profile.h"
wfhdfcab2e42014-11-07 06:48:3230#include "chrome/browser/ui/browser_otr_state.h"
Scott Violet6200d332018-02-23 21:29:2331#include "chrome/common/buildflags.h"
wafflescd59e9b2016-08-30 04:34:4432#include "chrome/common/chrome_content_client.h"
tommyclic0c4f942016-09-19 19:35:0033#include "chrome/common/chrome_features.h"
Nicholas Verneb5df4f72017-11-08 09:12:0734#include "chrome/common/plugin.mojom.h"
[email protected]8aa7a412011-11-07 12:33:4235#include "chrome/common/pref_names.h"
waffles77255cc2016-08-02 17:25:1236#include "components/component_updater/component_updater_service.h"
mukai8eaec822014-10-25 17:53:1637#include "components/content_settings/core/browser/content_settings_utils.h"
38#include "components/content_settings/core/browser/host_content_settings_map.h"
mukai077089f2014-09-11 18:41:5239#include "components/content_settings/core/common/content_settings.h"
rbpotter654f42d2016-12-02 22:17:0740#include "components/keyed_service/content/browser_context_keyed_service_shutdown_notifier_factory.h"
Scott Violet9ae82892018-03-01 18:38:1241#include "components/nacl/common/buildflags.h"
Bernhard Bauer19190732017-09-28 09:03:3342#include "components/pref_registry/pref_registry_syncable.h"
brettwb1fc1b82016-02-02 00:19:0843#include "components/prefs/pref_service.h"
nzolghadrd87a308d2016-12-07 15:45:5644#include "components/rappor/rappor_service_impl.h"
Steven Holtef0f46772017-12-11 20:54:5145#include "components/ukm/content/source_url_recorder.h"
Eric Seckler8652dcd52018-09-20 10:42:2846#include "content/public/browser/browser_task_traits.h"
[email protected]3a5180ae2011-12-21 02:39:3847#include "content/public/browser/plugin_service.h"
[email protected]31f376c2012-03-13 16:43:0948#include "content/public/browser/plugin_service_filter.h"
tommycli910b4082017-04-03 17:04:1549#include "content/public/browser/render_frame_host.h"
wfhdfcab2e42014-11-07 06:48:3250#include "content/public/common/content_constants.h"
Scott Violetc8240b02018-03-08 22:03:5951#include "extensions/buildflags/buildflags.h"
wfhdfcab2e42014-11-07 06:48:3252#include "net/base/registry_controlled_domains/registry_controlled_domain.h"
Scott Violet02e38b92018-03-27 23:42:1453#include "ppapi/buildflags/buildflags.h"
Steven Holtef0f46772017-12-11 20:54:5154#include "services/metrics/public/cpp/ukm_builders.h"
Mounir Lamourifd9dcefa2017-07-06 10:26:5555#include "services/metrics/public/cpp/ukm_recorder.h"
[email protected]761fa4702013-07-02 15:25:1556#include "url/gurl.h"
tommyclif2a1e9f2016-10-06 18:34:3657#include "url/origin.h"
[email protected]b9b88a082013-03-21 03:51:0258
brettw00899e62016-11-12 02:10:1759#if BUILDFLAG(ENABLE_EXTENSIONS)
fsamuel8dfa19a2015-05-05 01:00:3960#include "components/guest_view/browser/guest_view_base.h"
Sadrul Habib Chowdhuryf43c33c2014-12-04 15:53:5261#include "extensions/browser/extension_registry.h"
hanxi0d0a1e92014-08-26 18:39:4862#include "extensions/browser/guest_view/web_view/web_view_renderer_state.h"
lfg44c8a68f2015-04-16 16:38:1563#include "extensions/common/constants.h"
Sadrul Habib Chowdhuryf43c33c2014-12-04 15:53:5264#include "extensions/common/extension.h"
65#include "extensions/common/manifest_handlers/webview_info.h"
[email protected]21a20132014-07-16 00:48:5966#endif
67
Nico Weberaf3b00b2017-09-11 17:58:1768#if BUILDFLAG(ENABLE_NACL)
[email protected]e0ff1aa2014-08-16 01:38:1169#include "components/nacl/common/nacl_constants.h"
70#endif
71
[email protected]3a5180ae2011-12-21 02:39:3872using content::PluginService;
[email protected]d7bd3e52013-07-21 04:29:2073using content::WebPluginInfo;
[email protected]3a5180ae2011-12-21 02:39:3874
[email protected]b9b88a082013-03-21 03:51:0275namespace {
76
Daniel Bratell84928c52018-01-16 21:40:3477class PluginInfoHostImplShutdownNotifierFactory
rbpotter654f42d2016-12-02 22:17:0778 : public BrowserContextKeyedServiceShutdownNotifierFactory {
79 public:
Daniel Bratell84928c52018-01-16 21:40:3480 static PluginInfoHostImplShutdownNotifierFactory* GetInstance() {
81 return base::Singleton<PluginInfoHostImplShutdownNotifierFactory>::get();
rbpotter654f42d2016-12-02 22:17:0782 }
83
84 private:
Daniel Bratell84928c52018-01-16 21:40:3485 friend struct base::DefaultSingletonTraits<
86 PluginInfoHostImplShutdownNotifierFactory>;
rbpotter654f42d2016-12-02 22:17:0787
Daniel Bratell84928c52018-01-16 21:40:3488 PluginInfoHostImplShutdownNotifierFactory()
rbpotter654f42d2016-12-02 22:17:0789 : BrowserContextKeyedServiceShutdownNotifierFactory(
Nicholas Verned391eae2017-11-13 02:41:3890 "PluginInfoHostImpl") {}
rbpotter654f42d2016-12-02 22:17:0791
Daniel Bratell84928c52018-01-16 21:40:3492 ~PluginInfoHostImplShutdownNotifierFactory() override {}
rbpotter654f42d2016-12-02 22:17:0793
Daniel Bratell84928c52018-01-16 21:40:3494 DISALLOW_COPY_AND_ASSIGN(PluginInfoHostImplShutdownNotifierFactory);
rbpotter654f42d2016-12-02 22:17:0795};
96
brettw00899e62016-11-12 02:10:1797#if BUILDFLAG(ENABLE_EXTENSIONS)
Sadrul Habib Chowdhuryf43c33c2014-12-04 15:53:5298// Returns whether a request from a plugin to load |resource| from a renderer
99// with process id |process_id| is a request for an internal resource by an app
100// listed in |accessible_resources| in its manifest.
101bool IsPluginLoadingAccessibleResourceInWebView(
102 extensions::ExtensionRegistry* extension_registry,
103 int process_id,
104 const GURL& resource) {
105 extensions::WebViewRendererState* renderer_state =
106 extensions::WebViewRendererState::GetInstance();
107 std::string partition_id;
108 if (!renderer_state->IsGuest(process_id) ||
109 !renderer_state->GetPartitionID(process_id, &partition_id)) {
110 return false;
111 }
112
113 const std::string extension_id = resource.host();
paulmeyerad727fc62015-09-09 15:29:59114 const extensions::Extension* extension = extension_registry->GetExtensionById(
115 extension_id, extensions::ExtensionRegistry::ENABLED);
116 if (!extension || !extensions::WebviewInfo::IsResourceWebviewAccessible(
Nicholas Verned391eae2017-11-13 02:41:38117 extension, partition_id, resource.path())) {
Sadrul Habib Chowdhuryf43c33c2014-12-04 15:53:52118 return false;
119 }
120
121 // Make sure the renderer making the request actually belongs to the
122 // same extension.
123 std::string owner_extension;
124 return renderer_state->GetOwnerInfo(process_id, nullptr, &owner_extension) &&
125 owner_extension == extension_id;
126}
brettw00899e62016-11-12 02:10:17127#endif // BUILDFLAG(ENABLE_EXTENSIONS)
Sadrul Habib Chowdhuryf43c33c2014-12-04 15:53:52128
[email protected]b9b88a082013-03-21 03:51:02129} // namespace
130
Nicholas Verned391eae2017-11-13 02:41:38131PluginInfoHostImpl::Context::Context(int render_process_id, Profile* profile)
[email protected]0a8f3a7f2012-01-17 16:17:19132 : render_process_id_(render_process_id),
[email protected]df02aca2012-02-09 21:03:20133 resource_context_(profile->GetResourceContext()),
brettw00899e62016-11-12 02:10:17134#if BUILDFLAG(ENABLE_EXTENSIONS)
Sadrul Habib Chowdhuryf43c33c2014-12-04 15:53:52135 extension_registry_(extensions::ExtensionRegistry::Get(profile)),
136#endif
Nicholas Verned391eae2017-11-13 02:41:38137 host_content_settings_map_(
138 HostContentSettingsMapFactory::GetForProfile(profile)),
[email protected]601e3c82013-10-03 01:31:20139 plugin_prefs_(PluginPrefs::GetForProfile(profile)) {
[email protected]8aa7a412011-11-07 12:33:42140 allow_outdated_plugins_.Init(prefs::kPluginsAllowOutdated,
[email protected]96a5c342012-12-04 18:14:02141 profile->GetPrefs());
[email protected]6a1c98e02012-10-24 21:49:43142 allow_outdated_plugins_.MoveToThread(
Eric Seckler8652dcd52018-09-20 10:42:28143 base::CreateSingleThreadTaskRunnerWithTraits(
144 {content::BrowserThread::IO}));
Bernhard Bauer19190732017-09-28 09:03:33145 run_all_flash_in_allow_mode_.Init(prefs::kRunAllFlashInAllowMode,
146 profile->GetPrefs());
147 run_all_flash_in_allow_mode_.MoveToThread(
Eric Seckler8652dcd52018-09-20 10:42:28148 base::CreateSingleThreadTaskRunnerWithTraits(
149 {content::BrowserThread::IO}));
[email protected]8aa7a412011-11-07 12:33:42150}
151
Nicholas Verned391eae2017-11-13 02:41:38152PluginInfoHostImpl::Context::~Context() {}
[email protected]0a8f3a7f2012-01-17 16:17:19153
Nicholas Verned391eae2017-11-13 02:41:38154void PluginInfoHostImpl::Context::ShutdownOnUIThread() {
rbpotter654f42d2016-12-02 22:17:07155 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
rbpotter654f42d2016-12-02 22:17:07156 allow_outdated_plugins_.Destroy();
Bernhard Bauer19190732017-09-28 09:03:33157 run_all_flash_in_allow_mode_.Destroy();
rbpotter654f42d2016-12-02 22:17:07158}
159
Nicholas Verned391eae2017-11-13 02:41:38160PluginInfoHostImpl::PluginInfoHostImpl(int render_process_id, Profile* profile)
161 : context_(render_process_id, profile),
tommycli910b4082017-04-03 17:04:15162 main_thread_task_runner_(base::ThreadTaskRunnerHandle::Get()),
Nicholas Verneb5df4f72017-11-08 09:12:07163 binding_(this) {
rbpotter654f42d2016-12-02 22:17:07164 shutdown_notifier_ =
Daniel Bratell84928c52018-01-16 21:40:34165 PluginInfoHostImplShutdownNotifierFactory::GetInstance()
166 ->Get(profile)
167 ->Subscribe(base::Bind(&PluginInfoHostImpl::ShutdownOnUIThread,
168 base::Unretained(this)));
rbpotter654f42d2016-12-02 22:17:07169}
170
Nicholas Verned391eae2017-11-13 02:41:38171void PluginInfoHostImpl::ShutdownOnUIThread() {
rbpotter654f42d2016-12-02 22:17:07172 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
173 context_.ShutdownOnUIThread();
174 shutdown_notifier_.reset();
[email protected]0a8f3a7f2012-01-17 16:17:19175}
176
Nicholas Verned391eae2017-11-13 02:41:38177void PluginInfoHostImplTraits::Destruct(const PluginInfoHostImpl* impl) {
Eric Seckler8652dcd52018-09-20 10:42:28178 base::PostTaskWithTraits(
179 FROM_HERE, {content::BrowserThread::IO},
Nicholas Verned391eae2017-11-13 02:41:38180 base::BindOnce(&PluginInfoHostImpl::DestructOnBrowserThread,
181 base::Unretained(impl)));
Nicholas Verne4ec6cda2017-11-11 11:36:25182}
183
Nicholas Verned391eae2017-11-13 02:41:38184void PluginInfoHostImpl::DestructOnBrowserThread() const {
Nicholas Verneb5df4f72017-11-08 09:12:07185 binding_.Close();
[email protected]8aa7a412011-11-07 12:33:42186 // Destroy on the UI thread because we contain a |PrefMember|.
187 content::BrowserThread::DeleteOnUIThread::Destruct(this);
188}
189
Bernhard Bauer19190732017-09-28 09:03:33190// static
Nicholas Verned391eae2017-11-13 02:41:38191void PluginInfoHostImpl::RegisterUserPrefs(
Bernhard Bauer19190732017-09-28 09:03:33192 user_prefs::PrefRegistrySyncable* registry) {
193 registry->RegisterBooleanPref(prefs::kPluginsAllowOutdated, false);
Bernhard Bauer19190732017-09-28 09:03:33194 registry->RegisterBooleanPref(prefs::kRunAllFlashInAllowMode, false);
195}
196
Nicholas Verned391eae2017-11-13 02:41:38197PluginInfoHostImpl::~PluginInfoHostImpl() {}
[email protected]649d1c02012-04-27 02:56:21198
Nicholas Verned391eae2017-11-13 02:41:38199struct PluginInfoHostImpl::GetPluginInfo_Params {
[email protected]60eca4eb2013-12-06 00:02:16200 int render_frame_id;
[email protected]8aa7a412011-11-07 12:33:42201 GURL url;
tommyclif2a1e9f2016-10-06 18:34:36202 url::Origin main_frame_origin;
[email protected]8aa7a412011-11-07 12:33:42203 std::string mime_type;
204};
205
Nicholas Verned391eae2017-11-13 02:41:38206void PluginInfoHostImpl::OnPluginInfoHostRequest(
Nicholas Verneb5df4f72017-11-08 09:12:07207 chrome::mojom::PluginInfoHostAssociatedRequest request) {
208 binding_.Bind(std::move(request));
209}
210
Nicholas Verned391eae2017-11-13 02:41:38211void PluginInfoHostImpl::GetPluginInfo(int32_t render_frame_id,
212 const GURL& url,
213 const url::Origin& origin,
214 const std::string& mime_type,
tzikcd02d3b2018-08-09 21:32:47215 GetPluginInfoCallback callback) {
Nicholas Verneb5df4f72017-11-08 09:12:07216 GetPluginInfo_Params params = {render_frame_id, url, origin, mime_type};
Nicholas Verned391eae2017-11-13 02:41:38217 PluginService::GetInstance()->GetPlugins(base::BindOnce(
218 &PluginInfoHostImpl::PluginsLoaded, this, params, std::move(callback)));
[email protected]8aa7a412011-11-07 12:33:42219}
220
Nicholas Verned391eae2017-11-13 02:41:38221void PluginInfoHostImpl::PluginsLoaded(
[email protected]8aa7a412011-11-07 12:33:42222 const GetPluginInfo_Params& params,
Nicholas Verneb5df4f72017-11-08 09:12:07223 GetPluginInfoCallback callback,
[email protected]dfdfeb72012-06-08 11:29:02224 const std::vector<WebPluginInfo>& plugins) {
Nicholas Verneb5df4f72017-11-08 09:12:07225 chrome::mojom::PluginInfoPtr output = chrome::mojom::PluginInfo::New();
[email protected]79fa3362012-03-28 16:21:11226 // This also fills in |actual_mime_type|.
dcheng4af48582016-04-19 00:29:35227 std::unique_ptr<PluginMetadata> plugin_metadata;
[email protected]60eca4eb2013-12-06 00:02:16228 if (context_.FindEnabledPlugin(params.render_frame_id, params.url,
tommyclif2a1e9f2016-10-06 18:34:36229 params.main_frame_origin, params.mime_type,
waffles77255cc2016-08-02 17:25:12230 &output->status, &output->plugin,
231 &output->actual_mime_type, &plugin_metadata)) {
tommyclie97656b82016-11-30 16:43:00232 context_.DecidePluginStatus(
233 params.url, params.main_frame_origin, output->plugin,
234 plugin_metadata->GetSecurityStatus(output->plugin),
235 plugin_metadata->identifier(), &output->status);
[email protected]79fa3362012-03-28 16:21:11236 }
[email protected]cd33d282012-09-21 12:53:04237
Nicholas Verneb5df4f72017-11-08 09:12:07238 if (output->status == chrome::mojom::PluginStatus::kNotFound) {
waffles77255cc2016-08-02 17:25:12239 // Check to see if the component updater can fetch an implementation.
240 base::PostTaskAndReplyWithResult(
241 main_thread_task_runner_.get(), FROM_HERE,
Nicholas Verneb5df4f72017-11-08 09:12:07242 base::BindOnce(
waffles77255cc2016-08-02 17:25:12243 &component_updater::ComponentUpdateService::GetComponentForMimeType,
244 base::Unretained(g_browser_process->component_updater()),
245 params.mime_type),
Nicholas Verned391eae2017-11-13 02:41:38246 base::BindOnce(&PluginInfoHostImpl::ComponentPluginLookupDone, this,
247 params, std::move(output), std::move(callback),
Nicholas Verneb5df4f72017-11-08 09:12:07248 std::move(plugin_metadata)));
waffles77255cc2016-08-02 17:25:12249 } else {
Nicholas Verneb5df4f72017-11-08 09:12:07250 GetPluginInfoFinish(params, std::move(output), std::move(callback),
251 std::move(plugin_metadata));
wfhbe79ad52014-11-07 19:02:07252 }
[email protected]8aa7a412011-11-07 12:33:42253}
254
Nicholas Verned391eae2017-11-13 02:41:38255void PluginInfoHostImpl::Context::DecidePluginStatus(
tommyclie97656b82016-11-30 16:43:00256 const GURL& url,
257 const url::Origin& main_frame_origin,
[email protected]546abf32012-09-14 16:55:09258 const WebPluginInfo& plugin,
tommyclie97656b82016-11-30 16:43:00259 PluginMetadata::SecurityStatus security_status,
260 const std::string& plugin_identifier,
Nicholas Verneb5df4f72017-11-08 09:12:07261 chrome::mojom::PluginStatus* status) const {
tommyclie97656b82016-11-30 16:43:00262 if (security_status == PluginMetadata::SECURITY_STATUS_FULLY_TRUSTED) {
Nicholas Verneb5df4f72017-11-08 09:12:07263 *status = chrome::mojom::PluginStatus::kAllowed;
wfhe53608b2016-04-07 02:18:53264 return;
265 }
266
[email protected]8aa7a412011-11-07 12:33:42267 ContentSetting plugin_setting = CONTENT_SETTING_DEFAULT;
268 bool uses_default_content_setting = true;
[email protected]6a9d1deb2014-01-13 19:39:41269 bool is_managed = false;
tommyclie86b2982015-03-16 20:16:45270 // Check plugin content settings. The primary URL is the top origin URL and
271 // the secondary URL is the plugin URL.
raymes978301a22016-09-22 00:54:28272 PluginUtils::GetPluginContentSetting(
tommyclie97656b82016-11-30 16:43:00273 host_content_settings_map_, plugin, main_frame_origin, url,
274 plugin_identifier, &plugin_setting, &uses_default_content_setting,
275 &is_managed);
tommyclie2b1f1b2015-03-31 22:54:59276
tommyclif0555a52015-05-13 15:43:42277 // TODO(tommycli): Remove once we deprecate the plugin ASK policy.
tommyclid727a4c2015-04-21 16:35:05278 bool legacy_ask_user = plugin_setting == CONTENT_SETTING_ASK;
trizzofoa1b970452016-08-26 02:33:25279 plugin_setting = PluginsFieldTrial::EffectiveContentSetting(
raymesb512db82016-10-11 23:07:27280 host_content_settings_map_, CONTENT_SETTINGS_TYPE_PLUGINS,
281 plugin_setting);
tommyclie2b1f1b2015-03-31 22:54:59282
[email protected]8aa7a412011-11-07 12:33:42283 DCHECK(plugin_setting != CONTENT_SETTING_DEFAULT);
tommyclie2b1f1b2015-03-31 22:54:59284 DCHECK(plugin_setting != CONTENT_SETTING_ASK);
[email protected]8aa7a412011-11-07 12:33:42285
Nicholas Verneb5df4f72017-11-08 09:12:07286 if (*status == chrome::mojom::PluginStatus::kFlashHiddenPreferHtml) {
tommyclie97656b82016-11-30 16:43:00287 if (plugin_setting == CONTENT_SETTING_BLOCK) {
288 *status = is_managed && !legacy_ask_user
Nicholas Verneb5df4f72017-11-08 09:12:07289 ? chrome::mojom::PluginStatus::kBlockedByPolicy
290 : chrome::mojom::PluginStatus::kBlockedNoLoading;
tommyclie97656b82016-11-30 16:43:00291 }
292 return;
293 }
294
bauerbecab4f52017-03-13 20:16:41295#if BUILDFLAG(ENABLE_PLUGINS)
tommyclie86b2982015-03-16 20:16:45296 // Check if the plugin is outdated.
tommyclie97656b82016-11-30 16:43:00297 if (security_status == PluginMetadata::SECURITY_STATUS_OUT_OF_DATE &&
[email protected]9f230ed2012-05-24 11:19:40298 !allow_outdated_plugins_.GetValue()) {
[email protected]8aa7a412011-11-07 12:33:42299 if (allow_outdated_plugins_.IsManaged()) {
Nicholas Verneb5df4f72017-11-08 09:12:07300 *status = chrome::mojom::PluginStatus::kOutdatedDisallowed;
[email protected]8aa7a412011-11-07 12:33:42301 } else {
Nicholas Verneb5df4f72017-11-08 09:12:07302 *status = chrome::mojom::PluginStatus::kOutdatedBlocked;
[email protected]8aa7a412011-11-07 12:33:42303 }
304 return;
305 }
bauerbecab4f52017-03-13 20:16:41306#endif // BUILDFLAG(ENABLE_PLUGINS)
[email protected]ef97ce342012-09-24 20:05:02307
tommyclie86b2982015-03-16 20:16:45308 // Check if the plugin is crashing too much.
[email protected]ef97ce342012-09-24 20:05:02309 if (PluginService::GetInstance()->IsPluginUnstable(plugin.path) &&
Nicholas Verned391eae2017-11-13 02:41:38310 plugin_setting != CONTENT_SETTING_BLOCK && uses_default_content_setting) {
Nicholas Verneb5df4f72017-11-08 09:12:07311 *status = chrome::mojom::PluginStatus::kUnauthorized;
[email protected]ef97ce342012-09-24 20:05:02312 return;
313 }
[email protected]8aa7a412011-11-07 12:33:42314
brettw00899e62016-11-12 02:10:17315#if BUILDFLAG(ENABLE_EXTENSIONS)
Sadrul Habib Chowdhuryf43c33c2014-12-04 15:53:52316 // If an app has explicitly made internal resources available by listing them
317 // in |accessible_resources| in the manifest, then allow them to be loaded by
318 // plugins inside a guest-view.
tommyclie97656b82016-11-30 16:43:00319 if (url.SchemeIs(extensions::kExtensionScheme) && !is_managed &&
lfg44c8a68f2015-04-16 16:38:15320 plugin_setting == CONTENT_SETTING_BLOCK &&
tommyclie97656b82016-11-30 16:43:00321 IsPluginLoadingAccessibleResourceInWebView(extension_registry_,
322 render_process_id_, url)) {
Sadrul Habib Chowdhuryf43c33c2014-12-04 15:53:52323 plugin_setting = CONTENT_SETTING_ALLOW;
324 }
brettw00899e62016-11-12 02:10:17325#endif // BUILDFLAG(ENABLE_EXTENSIONS)
Sadrul Habib Chowdhuryf43c33c2014-12-04 15:53:52326
tommycli608ec89b2016-09-28 16:39:00327 if (plugin_setting == CONTENT_SETTING_DETECT_IMPORTANT_CONTENT ||
328 (plugin_setting == CONTENT_SETTING_ALLOW &&
Bernhard Bauer19190732017-09-28 09:03:33329 PluginUtils::ShouldPreferHtmlOverPlugins(host_content_settings_map_) &&
330 !run_all_flash_in_allow_mode_.GetValue())) {
Nicholas Verneb5df4f72017-11-08 09:12:07331 *status = chrome::mojom::PluginStatus::kPlayImportantContent;
tommyclie2b1f1b2015-03-31 22:54:59332 } else if (plugin_setting == CONTENT_SETTING_BLOCK) {
tommyclid727a4c2015-04-21 16:35:05333 // For managed users with the ASK policy, we allow manually running plugins
334 // via context menu. This is the closest to admin intent.
335 *status = is_managed && !legacy_ask_user
Nicholas Verneb5df4f72017-11-08 09:12:07336 ? chrome::mojom::PluginStatus::kBlockedByPolicy
337 : chrome::mojom::PluginStatus::kBlocked;
[email protected]6a9d1deb2014-01-13 19:39:41338 }
[email protected]aea757d2013-09-27 22:27:38339
brettw00899e62016-11-12 02:10:17340#if BUILDFLAG(ENABLE_EXTENSIONS)
tommycli550b2222015-09-03 21:06:10341 // Allow an embedder of <webview> to block a plugin from being loaded inside
342 // the guest. In order to do this, set the status to 'Unauthorized' here,
343 // and update the status as appropriate depending on the response from the
344 // embedder.
Nicholas Verneb5df4f72017-11-08 09:12:07345 if (*status == chrome::mojom::PluginStatus::kAllowed ||
346 *status == chrome::mojom::PluginStatus::kBlocked ||
347 *status == chrome::mojom::PluginStatus::kPlayImportantContent) {
[email protected]140d6cd92014-08-12 18:26:46348 if (extensions::WebViewRendererState::GetInstance()->IsGuest(
tommycli550b2222015-09-03 21:06:10349 render_process_id_))
Nicholas Verneb5df4f72017-11-08 09:12:07350 *status = chrome::mojom::PluginStatus::kUnauthorized;
[email protected]aea757d2013-09-27 22:27:38351 }
tommycli550b2222015-09-03 21:06:10352#endif
[email protected]8aa7a412011-11-07 12:33:42353}
354
Nicholas Verned391eae2017-11-13 02:41:38355bool PluginInfoHostImpl::Context::FindEnabledPlugin(
[email protected]60eca4eb2013-12-06 00:02:16356 int render_frame_id,
[email protected]8aa7a412011-11-07 12:33:42357 const GURL& url,
tommyclif2a1e9f2016-10-06 18:34:36358 const url::Origin& main_frame_origin,
[email protected]8aa7a412011-11-07 12:33:42359 const std::string& mime_type,
Nicholas Verneb5df4f72017-11-08 09:12:07360 chrome::mojom::PluginStatus* status,
[email protected]dfdfeb72012-06-08 11:29:02361 WebPluginInfo* plugin,
[email protected]4da405672012-10-25 10:43:03362 std::string* actual_mime_type,
dcheng4af48582016-04-19 00:29:35363 std::unique_ptr<PluginMetadata>* plugin_metadata) const {
Nicholas Verneb5df4f72017-11-08 09:12:07364 *status = chrome::mojom::PluginStatus::kAllowed;
bauerb96d29c02015-04-09 08:40:35365
[email protected]8aa7a412011-11-07 12:33:42366 bool allow_wildcard = true;
[email protected]dfdfeb72012-06-08 11:29:02367 std::vector<WebPluginInfo> matching_plugins;
[email protected]8aa7a412011-11-07 12:33:42368 std::vector<std::string> mime_types;
369 PluginService::GetInstance()->GetPluginInfoArray(
370 url, mime_type, allow_wildcard, &matching_plugins, &mime_types);
wafflescd59e9b2016-08-30 04:34:44371#if defined(GOOGLE_CHROME_BUILD)
Eugene Kim0b4b4572018-09-01 02:37:58372 base::EraseIf(matching_plugins, [&](const WebPluginInfo& info) {
373 return info.path.value() == ChromeContentClient::kNotPresent;
374 });
wafflescd59e9b2016-08-30 04:34:44375#endif // defined(GOOGLE_CHROME_BUILD)
[email protected]4da405672012-10-25 10:43:03376 if (matching_plugins.empty()) {
Nicholas Verneb5df4f72017-11-08 09:12:07377 *status = chrome::mojom::PluginStatus::kNotFound;
[email protected]4da405672012-10-25 10:43:03378 return false;
379 }
380
[email protected]3a5180ae2011-12-21 02:39:38381 content::PluginServiceFilter* filter =
382 PluginService::GetInstance()->GetFilter();
[email protected]4da405672012-10-25 10:43:03383 size_t i = 0;
384 for (; i < matching_plugins.size(); ++i) {
Nicholas Verned391eae2017-11-13 02:41:38385 if (!filter || filter->IsPluginAvailable(
386 render_process_id_, render_frame_id, resource_context_,
387 url, main_frame_origin, &matching_plugins[i])) {
[email protected]4da405672012-10-25 10:43:03388 break;
[email protected]8aa7a412011-11-07 12:33:42389 }
390 }
391
tommyclie86b2982015-03-16 20:16:45392 // If we broke out of the loop, we have found an enabled plugin.
[email protected]4da405672012-10-25 10:43:03393 bool enabled = i < matching_plugins.size();
394 if (!enabled) {
tommyclie86b2982015-03-16 20:16:45395 // Otherwise, we only found disabled plugins, so we take the first one.
[email protected]4da405672012-10-25 10:43:03396 i = 0;
Nicholas Verneb5df4f72017-11-08 09:12:07397 *status = chrome::mojom::PluginStatus::kDisabled;
tommyclic0c4f942016-09-19 19:35:00398
raymesb512db82016-10-11 23:07:27399 if (PluginUtils::ShouldPreferHtmlOverPlugins(host_content_settings_map_) &&
tommyclic0c4f942016-09-19 19:35:00400 matching_plugins[0].name ==
401 base::ASCIIToUTF16(content::kFlashPluginName)) {
Nicholas Verneb5df4f72017-11-08 09:12:07402 *status = chrome::mojom::PluginStatus::kFlashHiddenPreferHtml;
tommyclie97656b82016-11-30 16:43:00403
404 // In the Prefer HTML case, the plugin is actually enabled, but hidden.
405 // It will still be blocked in the body of DecidePluginStatus.
406 enabled = true;
tommyclic0c4f942016-09-19 19:35:00407 }
[email protected]4da405672012-10-25 10:43:03408 }
409
410 *plugin = matching_plugins[i];
411 *actual_mime_type = mime_types[i];
412 if (plugin_metadata)
413 *plugin_metadata = PluginFinder::GetInstance()->GetPluginMetadata(*plugin);
414
415 return enabled;
[email protected]8aa7a412011-11-07 12:33:42416}
417
Nicholas Verned391eae2017-11-13 02:41:38418void PluginInfoHostImpl::ComponentPluginLookupDone(
waffles77255cc2016-08-02 17:25:12419 const GetPluginInfo_Params& params,
Nicholas Verneb5df4f72017-11-08 09:12:07420 chrome::mojom::PluginInfoPtr output,
421 GetPluginInfoCallback callback,
waffles77255cc2016-08-02 17:25:12422 std::unique_ptr<PluginMetadata> plugin_metadata,
waffles77255cc2016-08-02 17:25:12423 std::unique_ptr<component_updater::ComponentInfo> cus_plugin_info) {
424 if (cus_plugin_info) {
Nicholas Verneb5df4f72017-11-08 09:12:07425 output->status = chrome::mojom::PluginStatus::kComponentUpdateRequired;
wafflese7759f72016-10-10 23:41:25426#if defined(OS_LINUX)
427 if (cus_plugin_info->version != base::Version("0")) {
Nicholas Verneb5df4f72017-11-08 09:12:07428 output->status = chrome::mojom::PluginStatus::kRestartRequired;
wafflese7759f72016-10-10 23:41:25429 }
thestigd6e438182017-06-01 23:16:27430#endif
Jeremy Romanec48d7a2018-03-01 17:35:09431 plugin_metadata = std::make_unique<PluginMetadata>(
waffles77255cc2016-08-02 17:25:12432 cus_plugin_info->id, cus_plugin_info->name, false, GURL(), GURL(),
thestigd6e438182017-06-01 23:16:27433 base::ASCIIToUTF16(cus_plugin_info->id), std::string());
waffles77255cc2016-08-02 17:25:12434 }
Nicholas Verneb5df4f72017-11-08 09:12:07435 GetPluginInfoFinish(params, std::move(output), std::move(callback),
436 std::move(plugin_metadata));
waffles77255cc2016-08-02 17:25:12437}
438
Nicholas Verned391eae2017-11-13 02:41:38439void PluginInfoHostImpl::GetPluginInfoFinish(
waffles77255cc2016-08-02 17:25:12440 const GetPluginInfo_Params& params,
Nicholas Verneb5df4f72017-11-08 09:12:07441 chrome::mojom::PluginInfoPtr output,
442 GetPluginInfoCallback callback,
443 std::unique_ptr<PluginMetadata> plugin_metadata) {
waffles77255cc2016-08-02 17:25:12444 if (plugin_metadata) {
445 output->group_identifier = plugin_metadata->identifier();
446 output->group_name = plugin_metadata->name();
447 }
448
449 context_.MaybeGrantAccess(output->status, output->plugin.path);
450
Nicholas Verneb5df4f72017-11-08 09:12:07451 if (output->status != chrome::mojom::PluginStatus::kNotFound) {
waffles77255cc2016-08-02 17:25:12452 main_thread_task_runner_->PostTask(
tommycli910b4082017-04-03 17:04:15453 FROM_HERE,
Nicholas Verned391eae2017-11-13 02:41:38454 base::BindOnce(&PluginInfoHostImpl::ReportMetrics, this,
tzik3f7781d2017-04-20 17:09:33455 params.render_frame_id, output->actual_mime_type,
Steven Holtef0f46772017-12-11 20:54:51456 params.url, params.main_frame_origin));
waffles77255cc2016-08-02 17:25:12457 }
Nicholas Verneb5df4f72017-11-08 09:12:07458 std::move(callback).Run(std::move(output));
waffles77255cc2016-08-02 17:25:12459}
460
Nicholas Verned391eae2017-11-13 02:41:38461void PluginInfoHostImpl::ReportMetrics(int render_frame_id,
462 const base::StringPiece& mime_type,
463 const GURL& url,
Steven Holtef0f46772017-12-11 20:54:51464 const url::Origin& main_frame_origin) {
tommycli910b4082017-04-03 17:04:15465 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
466
467 content::RenderFrameHost* frame = content::RenderFrameHost::FromID(
468 context_.render_process_id(), render_frame_id);
469 content::WebContents* web_contents =
470 content::WebContents::FromRenderFrameHost(frame);
471 // This can occur the web contents has already been closed or navigated away.
472 if (!web_contents)
473 return;
474
475 if (web_contents->GetBrowserContext()->IsOffTheRecord())
476 return;
477
478 rappor::RapporServiceImpl* rappor_service =
479 g_browser_process->rappor_service();
480 if (!rappor_service)
481 return;
Chris Palmerab5e5b52018-09-28 19:19:30482 if (main_frame_origin.opaque())
tommycli910b4082017-04-03 17:04:15483 return;
484
485 if (mime_type != content::kFlashPluginSwfMimeType &&
486 mime_type != content::kFlashPluginSplMimeType) {
487 return;
488 }
489
490 rappor_service->RecordSampleString(
491 "Plugins.FlashOriginUrl", rappor::ETLD_PLUS_ONE_RAPPOR_TYPE,
492 net::registry_controlled_domains::GetDomainAndRegistry(
493 main_frame_origin.GetURL(),
494 net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES));
495 rappor_service->RecordSampleString(
496 "Plugins.FlashUrl", rappor::ETLD_PLUS_ONE_RAPPOR_TYPE,
497 net::registry_controlled_domains::GetDomainAndRegistry(
498 url, net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES));
499
Steven Holtef0f46772017-12-11 20:54:51500 ukm::builders::Plugins_FlashInstance(
501 ukm::GetSourceIdForWebContentsDocument(web_contents))
502 .Record(ukm::UkmRecorder::Get());
tommycli910b4082017-04-03 17:04:15503}
504
Nicholas Verned391eae2017-11-13 02:41:38505void PluginInfoHostImpl::Context::MaybeGrantAccess(
Nicholas Verneb5df4f72017-11-08 09:12:07506 chrome::mojom::PluginStatus status,
[email protected]650b2d52013-02-10 03:41:45507 const base::FilePath& path) const {
Nicholas Verneb5df4f72017-11-08 09:12:07508 if (status == chrome::mojom::PluginStatus::kAllowed ||
509 status == chrome::mojom::PluginStatus::kPlayImportantContent) {
[email protected]6be31d202013-02-01 18:20:54510 ChromePluginServiceFilter::GetInstance()->AuthorizePlugin(
511 render_process_id_, path);
512 }
513}
514
Nicholas Verned391eae2017-11-13 02:41:38515bool PluginInfoHostImpl::Context::IsPluginEnabled(
[email protected]4cbbeb42014-07-22 19:29:38516 const content::WebPluginInfo& plugin) const {
517 return plugin_prefs_->IsPluginEnabled(plugin);
518}