[email protected] | dca589ef | 2012-01-09 11:53:32 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 8aa7a41 | 2011-11-07 12:33:42 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Nicholas Verne | d391eae | 2017-11-13 02:41:38 | [diff] [blame] | 5 | #include "chrome/browser/plugins/plugin_info_host_impl.h" |
[email protected] | 8aa7a41 | 2011-11-07 12:33:42 | [diff] [blame] | 6 | |
avi | b896c71 | 2015-12-26 02:10:43 | [diff] [blame] | 7 | #include <stddef.h> |
dcheng | 4af4858 | 2016-04-19 00:29:35 | [diff] [blame] | 8 | |
waffles | cd59e9b | 2016-08-30 04:34:44 | [diff] [blame] | 9 | #include <algorithm> |
dcheng | 4af4858 | 2016-04-19 00:29:35 | [diff] [blame] | 10 | #include <memory> |
dcheng | e73d8520c | 2015-12-27 01:19:09 | [diff] [blame] | 11 | #include <utility> |
avi | b896c71 | 2015-12-26 02:10:43 | [diff] [blame] | 12 | |
[email protected] | 8aa7a41 | 2011-11-07 12:33:42 | [diff] [blame] | 13 | #include "base/bind.h" |
rbpotter | 654f42d | 2016-12-02 22:17:07 | [diff] [blame] | 14 | #include "base/memory/singleton.h" |
Eugene Kim | 0b4b457 | 2018-09-01 02:37:58 | [diff] [blame] | 15 | #include "base/stl_util.h" |
[email protected] | e309f31 | 2013-06-07 21:50:08 | [diff] [blame] | 16 | #include "base/strings/utf_string_conversions.h" |
Eric Seckler | 8652dcd5 | 2018-09-20 10:42:28 | [diff] [blame] | 17 | #include "base/task/post_task.h" |
waffles | 77255cc | 2016-08-02 17:25:12 | [diff] [blame] | 18 | #include "base/task_runner_util.h" |
gab | b15e1907 | 2016-05-11 20:45:41 | [diff] [blame] | 19 | #include "base/threading/thread_task_runner_handle.h" |
avi | b896c71 | 2015-12-26 02:10:43 | [diff] [blame] | 20 | #include "build/build_config.h" |
wfh | dfcab2e4 | 2014-11-07 06:48:32 | [diff] [blame] | 21 | #include "chrome/browser/browser_process.h" |
peconn | 5100d43 | 2015-09-16 12:03:08 | [diff] [blame] | 22 | #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
[email protected] | 6be31d20 | 2013-02-01 18:20:54 | [diff] [blame] | 23 | #include "chrome/browser/plugins/chrome_plugin_service_filter.h" |
[email protected] | cd33d28 | 2012-09-21 12:53:04 | [diff] [blame] | 24 | #include "chrome/browser/plugins/plugin_finder.h" |
[email protected] | de75c70 | 2012-09-25 23:06:02 | [diff] [blame] | 25 | #include "chrome/browser/plugins/plugin_metadata.h" |
[email protected] | 601e3c8 | 2013-10-03 01:31:20 | [diff] [blame] | 26 | #include "chrome/browser/plugins/plugin_prefs.h" |
raymes | 978301a2 | 2016-09-22 00:54:28 | [diff] [blame] | 27 | #include "chrome/browser/plugins/plugin_utils.h" |
[email protected] | 8aa7a41 | 2011-11-07 12:33:42 | [diff] [blame] | 28 | #include "chrome/browser/profiles/profile.h" |
wfh | dfcab2e4 | 2014-11-07 06:48:32 | [diff] [blame] | 29 | #include "chrome/browser/ui/browser_otr_state.h" |
Scott Violet | 6200d33 | 2018-02-23 21:29:23 | [diff] [blame] | 30 | #include "chrome/common/buildflags.h" |
waffles | cd59e9b | 2016-08-30 04:34:44 | [diff] [blame] | 31 | #include "chrome/common/chrome_content_client.h" |
tommycli | c0c4f94 | 2016-09-19 19:35:00 | [diff] [blame] | 32 | #include "chrome/common/chrome_features.h" |
Nicholas Verne | b5df4f7 | 2017-11-08 09:12:07 | [diff] [blame] | 33 | #include "chrome/common/plugin.mojom.h" |
[email protected] | 8aa7a41 | 2011-11-07 12:33:42 | [diff] [blame] | 34 | #include "chrome/common/pref_names.h" |
waffles | 77255cc | 2016-08-02 17:25:12 | [diff] [blame] | 35 | #include "components/component_updater/component_updater_service.h" |
mukai | 8eaec82 | 2014-10-25 17:53:16 | [diff] [blame] | 36 | #include "components/content_settings/core/browser/content_settings_utils.h" |
| 37 | #include "components/content_settings/core/browser/host_content_settings_map.h" |
mukai | 077089f | 2014-09-11 18:41:52 | [diff] [blame] | 38 | #include "components/content_settings/core/common/content_settings.h" |
rbpotter | 654f42d | 2016-12-02 22:17:07 | [diff] [blame] | 39 | #include "components/keyed_service/content/browser_context_keyed_service_shutdown_notifier_factory.h" |
Scott Violet | 9ae8289 | 2018-03-01 18:38:12 | [diff] [blame] | 40 | #include "components/nacl/common/buildflags.h" |
Bernhard Bauer | 1919073 | 2017-09-28 09:03:33 | [diff] [blame] | 41 | #include "components/pref_registry/pref_registry_syncable.h" |
brettw | b1fc1b8 | 2016-02-02 00:19:08 | [diff] [blame] | 42 | #include "components/prefs/pref_service.h" |
nzolghadr | d87a308d | 2016-12-07 15:45:56 | [diff] [blame] | 43 | #include "components/rappor/rappor_service_impl.h" |
Steven Holte | f0f4677 | 2017-12-11 20:54:51 | [diff] [blame] | 44 | #include "components/ukm/content/source_url_recorder.h" |
Eric Seckler | 8652dcd5 | 2018-09-20 10:42:28 | [diff] [blame] | 45 | #include "content/public/browser/browser_task_traits.h" |
[email protected] | 3a5180ae | 2011-12-21 02:39:38 | [diff] [blame] | 46 | #include "content/public/browser/plugin_service.h" |
[email protected] | 31f376c | 2012-03-13 16:43:09 | [diff] [blame] | 47 | #include "content/public/browser/plugin_service_filter.h" |
tommycli | 910b408 | 2017-04-03 17:04:15 | [diff] [blame] | 48 | #include "content/public/browser/render_frame_host.h" |
wfh | dfcab2e4 | 2014-11-07 06:48:32 | [diff] [blame] | 49 | #include "content/public/common/content_constants.h" |
Scott Violet | c8240b0 | 2018-03-08 22:03:59 | [diff] [blame] | 50 | #include "extensions/buildflags/buildflags.h" |
wfh | dfcab2e4 | 2014-11-07 06:48:32 | [diff] [blame] | 51 | #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
Scott Violet | 02e38b9 | 2018-03-27 23:42:14 | [diff] [blame] | 52 | #include "ppapi/buildflags/buildflags.h" |
Steven Holte | f0f4677 | 2017-12-11 20:54:51 | [diff] [blame] | 53 | #include "services/metrics/public/cpp/ukm_builders.h" |
Mounir Lamouri | fd9dcefa | 2017-07-06 10:26:55 | [diff] [blame] | 54 | #include "services/metrics/public/cpp/ukm_recorder.h" |
[email protected] | 761fa470 | 2013-07-02 15:25:15 | [diff] [blame] | 55 | #include "url/gurl.h" |
tommycli | f2a1e9f | 2016-10-06 18:34:36 | [diff] [blame] | 56 | #include "url/origin.h" |
[email protected] | b9b88a08 | 2013-03-21 03:51:02 | [diff] [blame] | 57 | |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 58 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
fsamuel | 8dfa19a | 2015-05-05 01:00:39 | [diff] [blame] | 59 | #include "components/guest_view/browser/guest_view_base.h" |
Sadrul Habib Chowdhury | f43c33c | 2014-12-04 15:53:52 | [diff] [blame] | 60 | #include "extensions/browser/extension_registry.h" |
hanxi | 0d0a1e9 | 2014-08-26 18:39:48 | [diff] [blame] | 61 | #include "extensions/browser/guest_view/web_view/web_view_renderer_state.h" |
lfg | 44c8a68f | 2015-04-16 16:38:15 | [diff] [blame] | 62 | #include "extensions/common/constants.h" |
Sadrul Habib Chowdhury | f43c33c | 2014-12-04 15:53:52 | [diff] [blame] | 63 | #include "extensions/common/extension.h" |
| 64 | #include "extensions/common/manifest_handlers/webview_info.h" |
[email protected] | 21a2013 | 2014-07-16 00:48:59 | [diff] [blame] | 65 | #endif |
| 66 | |
Nico Weber | af3b00b | 2017-09-11 17:58:17 | [diff] [blame] | 67 | #if BUILDFLAG(ENABLE_NACL) |
[email protected] | e0ff1aa | 2014-08-16 01:38:11 | [diff] [blame] | 68 | #include "components/nacl/common/nacl_constants.h" |
| 69 | #endif |
| 70 | |
[email protected] | 3a5180ae | 2011-12-21 02:39:38 | [diff] [blame] | 71 | using content::PluginService; |
[email protected] | d7bd3e5 | 2013-07-21 04:29:20 | [diff] [blame] | 72 | using content::WebPluginInfo; |
[email protected] | 3a5180ae | 2011-12-21 02:39:38 | [diff] [blame] | 73 | |
[email protected] | b9b88a08 | 2013-03-21 03:51:02 | [diff] [blame] | 74 | namespace { |
| 75 | |
Daniel Bratell | 84928c5 | 2018-01-16 21:40:34 | [diff] [blame] | 76 | class PluginInfoHostImplShutdownNotifierFactory |
rbpotter | 654f42d | 2016-12-02 22:17:07 | [diff] [blame] | 77 | : public BrowserContextKeyedServiceShutdownNotifierFactory { |
| 78 | public: |
Daniel Bratell | 84928c5 | 2018-01-16 21:40:34 | [diff] [blame] | 79 | static PluginInfoHostImplShutdownNotifierFactory* GetInstance() { |
| 80 | return base::Singleton<PluginInfoHostImplShutdownNotifierFactory>::get(); |
rbpotter | 654f42d | 2016-12-02 22:17:07 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | private: |
Daniel Bratell | 84928c5 | 2018-01-16 21:40:34 | [diff] [blame] | 84 | friend struct base::DefaultSingletonTraits< |
| 85 | PluginInfoHostImplShutdownNotifierFactory>; |
rbpotter | 654f42d | 2016-12-02 22:17:07 | [diff] [blame] | 86 | |
Daniel Bratell | 84928c5 | 2018-01-16 21:40:34 | [diff] [blame] | 87 | PluginInfoHostImplShutdownNotifierFactory() |
rbpotter | 654f42d | 2016-12-02 22:17:07 | [diff] [blame] | 88 | : BrowserContextKeyedServiceShutdownNotifierFactory( |
Nicholas Verne | d391eae | 2017-11-13 02:41:38 | [diff] [blame] | 89 | "PluginInfoHostImpl") {} |
rbpotter | 654f42d | 2016-12-02 22:17:07 | [diff] [blame] | 90 | |
Daniel Bratell | 84928c5 | 2018-01-16 21:40:34 | [diff] [blame] | 91 | ~PluginInfoHostImplShutdownNotifierFactory() override {} |
rbpotter | 654f42d | 2016-12-02 22:17:07 | [diff] [blame] | 92 | |
Daniel Bratell | 84928c5 | 2018-01-16 21:40:34 | [diff] [blame] | 93 | DISALLOW_COPY_AND_ASSIGN(PluginInfoHostImplShutdownNotifierFactory); |
rbpotter | 654f42d | 2016-12-02 22:17:07 | [diff] [blame] | 94 | }; |
| 95 | |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 96 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
Sadrul Habib Chowdhury | f43c33c | 2014-12-04 15:53:52 | [diff] [blame] | 97 | // Returns whether a request from a plugin to load |resource| from a renderer |
| 98 | // with process id |process_id| is a request for an internal resource by an app |
| 99 | // listed in |accessible_resources| in its manifest. |
| 100 | bool IsPluginLoadingAccessibleResourceInWebView( |
| 101 | extensions::ExtensionRegistry* extension_registry, |
| 102 | int process_id, |
| 103 | const GURL& resource) { |
| 104 | extensions::WebViewRendererState* renderer_state = |
| 105 | extensions::WebViewRendererState::GetInstance(); |
| 106 | std::string partition_id; |
| 107 | if (!renderer_state->IsGuest(process_id) || |
| 108 | !renderer_state->GetPartitionID(process_id, &partition_id)) { |
| 109 | return false; |
| 110 | } |
| 111 | |
| 112 | const std::string extension_id = resource.host(); |
paulmeyer | ad727fc6 | 2015-09-09 15:29:59 | [diff] [blame] | 113 | const extensions::Extension* extension = extension_registry->GetExtensionById( |
| 114 | extension_id, extensions::ExtensionRegistry::ENABLED); |
| 115 | if (!extension || !extensions::WebviewInfo::IsResourceWebviewAccessible( |
Nicholas Verne | d391eae | 2017-11-13 02:41:38 | [diff] [blame] | 116 | extension, partition_id, resource.path())) { |
Sadrul Habib Chowdhury | f43c33c | 2014-12-04 15:53:52 | [diff] [blame] | 117 | return false; |
| 118 | } |
| 119 | |
| 120 | // Make sure the renderer making the request actually belongs to the |
| 121 | // same extension. |
| 122 | std::string owner_extension; |
| 123 | return renderer_state->GetOwnerInfo(process_id, nullptr, &owner_extension) && |
| 124 | owner_extension == extension_id; |
| 125 | } |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 126 | #endif // BUILDFLAG(ENABLE_EXTENSIONS) |
Sadrul Habib Chowdhury | f43c33c | 2014-12-04 15:53:52 | [diff] [blame] | 127 | |
[email protected] | b9b88a08 | 2013-03-21 03:51:02 | [diff] [blame] | 128 | } // namespace |
| 129 | |
Nicholas Verne | d391eae | 2017-11-13 02:41:38 | [diff] [blame] | 130 | PluginInfoHostImpl::Context::Context(int render_process_id, Profile* profile) |
[email protected] | 0a8f3a7f | 2012-01-17 16:17:19 | [diff] [blame] | 131 | : render_process_id_(render_process_id), |
[email protected] | df02aca | 2012-02-09 21:03:20 | [diff] [blame] | 132 | resource_context_(profile->GetResourceContext()), |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 133 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
Sadrul Habib Chowdhury | f43c33c | 2014-12-04 15:53:52 | [diff] [blame] | 134 | extension_registry_(extensions::ExtensionRegistry::Get(profile)), |
| 135 | #endif |
Nicholas Verne | d391eae | 2017-11-13 02:41:38 | [diff] [blame] | 136 | host_content_settings_map_( |
| 137 | HostContentSettingsMapFactory::GetForProfile(profile)), |
[email protected] | 601e3c8 | 2013-10-03 01:31:20 | [diff] [blame] | 138 | plugin_prefs_(PluginPrefs::GetForProfile(profile)) { |
[email protected] | 8aa7a41 | 2011-11-07 12:33:42 | [diff] [blame] | 139 | allow_outdated_plugins_.Init(prefs::kPluginsAllowOutdated, |
[email protected] | 96a5c34 | 2012-12-04 18:14:02 | [diff] [blame] | 140 | profile->GetPrefs()); |
[email protected] | 6a1c98e0 | 2012-10-24 21:49:43 | [diff] [blame] | 141 | allow_outdated_plugins_.MoveToThread( |
Eric Seckler | 8652dcd5 | 2018-09-20 10:42:28 | [diff] [blame] | 142 | base::CreateSingleThreadTaskRunnerWithTraits( |
| 143 | {content::BrowserThread::IO})); |
Bernhard Bauer | 1919073 | 2017-09-28 09:03:33 | [diff] [blame] | 144 | run_all_flash_in_allow_mode_.Init(prefs::kRunAllFlashInAllowMode, |
| 145 | profile->GetPrefs()); |
| 146 | run_all_flash_in_allow_mode_.MoveToThread( |
Eric Seckler | 8652dcd5 | 2018-09-20 10:42:28 | [diff] [blame] | 147 | base::CreateSingleThreadTaskRunnerWithTraits( |
| 148 | {content::BrowserThread::IO})); |
[email protected] | 8aa7a41 | 2011-11-07 12:33:42 | [diff] [blame] | 149 | } |
| 150 | |
Nicholas Verne | d391eae | 2017-11-13 02:41:38 | [diff] [blame] | 151 | PluginInfoHostImpl::Context::~Context() {} |
[email protected] | 0a8f3a7f | 2012-01-17 16:17:19 | [diff] [blame] | 152 | |
Nicholas Verne | d391eae | 2017-11-13 02:41:38 | [diff] [blame] | 153 | void PluginInfoHostImpl::Context::ShutdownOnUIThread() { |
rbpotter | 654f42d | 2016-12-02 22:17:07 | [diff] [blame] | 154 | DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
rbpotter | 654f42d | 2016-12-02 22:17:07 | [diff] [blame] | 155 | allow_outdated_plugins_.Destroy(); |
Bernhard Bauer | 1919073 | 2017-09-28 09:03:33 | [diff] [blame] | 156 | run_all_flash_in_allow_mode_.Destroy(); |
rbpotter | 654f42d | 2016-12-02 22:17:07 | [diff] [blame] | 157 | } |
| 158 | |
Nicholas Verne | d391eae | 2017-11-13 02:41:38 | [diff] [blame] | 159 | PluginInfoHostImpl::PluginInfoHostImpl(int render_process_id, Profile* profile) |
| 160 | : context_(render_process_id, profile), |
tommycli | 910b408 | 2017-04-03 17:04:15 | [diff] [blame] | 161 | main_thread_task_runner_(base::ThreadTaskRunnerHandle::Get()), |
Nicholas Verne | b5df4f7 | 2017-11-08 09:12:07 | [diff] [blame] | 162 | binding_(this) { |
rbpotter | 654f42d | 2016-12-02 22:17:07 | [diff] [blame] | 163 | shutdown_notifier_ = |
Daniel Bratell | 84928c5 | 2018-01-16 21:40:34 | [diff] [blame] | 164 | PluginInfoHostImplShutdownNotifierFactory::GetInstance() |
| 165 | ->Get(profile) |
| 166 | ->Subscribe(base::Bind(&PluginInfoHostImpl::ShutdownOnUIThread, |
| 167 | base::Unretained(this))); |
rbpotter | 654f42d | 2016-12-02 22:17:07 | [diff] [blame] | 168 | } |
| 169 | |
Nicholas Verne | d391eae | 2017-11-13 02:41:38 | [diff] [blame] | 170 | void PluginInfoHostImpl::ShutdownOnUIThread() { |
rbpotter | 654f42d | 2016-12-02 22:17:07 | [diff] [blame] | 171 | DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 172 | context_.ShutdownOnUIThread(); |
| 173 | shutdown_notifier_.reset(); |
[email protected] | 0a8f3a7f | 2012-01-17 16:17:19 | [diff] [blame] | 174 | } |
| 175 | |
Nicholas Verne | d391eae | 2017-11-13 02:41:38 | [diff] [blame] | 176 | void PluginInfoHostImplTraits::Destruct(const PluginInfoHostImpl* impl) { |
Eric Seckler | 8652dcd5 | 2018-09-20 10:42:28 | [diff] [blame] | 177 | base::PostTaskWithTraits( |
| 178 | FROM_HERE, {content::BrowserThread::IO}, |
Nicholas Verne | d391eae | 2017-11-13 02:41:38 | [diff] [blame] | 179 | base::BindOnce(&PluginInfoHostImpl::DestructOnBrowserThread, |
| 180 | base::Unretained(impl))); |
Nicholas Verne | 4ec6cda | 2017-11-11 11:36:25 | [diff] [blame] | 181 | } |
| 182 | |
Nicholas Verne | d391eae | 2017-11-13 02:41:38 | [diff] [blame] | 183 | void PluginInfoHostImpl::DestructOnBrowserThread() const { |
Nicholas Verne | b5df4f7 | 2017-11-08 09:12:07 | [diff] [blame] | 184 | binding_.Close(); |
[email protected] | 8aa7a41 | 2011-11-07 12:33:42 | [diff] [blame] | 185 | // Destroy on the UI thread because we contain a |PrefMember|. |
| 186 | content::BrowserThread::DeleteOnUIThread::Destruct(this); |
| 187 | } |
| 188 | |
Bernhard Bauer | 1919073 | 2017-09-28 09:03:33 | [diff] [blame] | 189 | // static |
Nicholas Verne | d391eae | 2017-11-13 02:41:38 | [diff] [blame] | 190 | void PluginInfoHostImpl::RegisterUserPrefs( |
Bernhard Bauer | 1919073 | 2017-09-28 09:03:33 | [diff] [blame] | 191 | user_prefs::PrefRegistrySyncable* registry) { |
| 192 | registry->RegisterBooleanPref(prefs::kPluginsAllowOutdated, false); |
Bernhard Bauer | 1919073 | 2017-09-28 09:03:33 | [diff] [blame] | 193 | registry->RegisterBooleanPref(prefs::kRunAllFlashInAllowMode, false); |
| 194 | } |
| 195 | |
Nicholas Verne | d391eae | 2017-11-13 02:41:38 | [diff] [blame] | 196 | PluginInfoHostImpl::~PluginInfoHostImpl() {} |
[email protected] | 649d1c0 | 2012-04-27 02:56:21 | [diff] [blame] | 197 | |
Nicholas Verne | d391eae | 2017-11-13 02:41:38 | [diff] [blame] | 198 | struct PluginInfoHostImpl::GetPluginInfo_Params { |
[email protected] | 60eca4eb | 2013-12-06 00:02:16 | [diff] [blame] | 199 | int render_frame_id; |
[email protected] | 8aa7a41 | 2011-11-07 12:33:42 | [diff] [blame] | 200 | GURL url; |
tommycli | f2a1e9f | 2016-10-06 18:34:36 | [diff] [blame] | 201 | url::Origin main_frame_origin; |
[email protected] | 8aa7a41 | 2011-11-07 12:33:42 | [diff] [blame] | 202 | std::string mime_type; |
| 203 | }; |
| 204 | |
Nicholas Verne | d391eae | 2017-11-13 02:41:38 | [diff] [blame] | 205 | void PluginInfoHostImpl::OnPluginInfoHostRequest( |
Nicholas Verne | b5df4f7 | 2017-11-08 09:12:07 | [diff] [blame] | 206 | chrome::mojom::PluginInfoHostAssociatedRequest request) { |
| 207 | binding_.Bind(std::move(request)); |
| 208 | } |
| 209 | |
Nicholas Verne | d391eae | 2017-11-13 02:41:38 | [diff] [blame] | 210 | void PluginInfoHostImpl::GetPluginInfo(int32_t render_frame_id, |
| 211 | const GURL& url, |
| 212 | const url::Origin& origin, |
| 213 | const std::string& mime_type, |
tzik | cd02d3b | 2018-08-09 21:32:47 | [diff] [blame] | 214 | GetPluginInfoCallback callback) { |
Nicholas Verne | b5df4f7 | 2017-11-08 09:12:07 | [diff] [blame] | 215 | GetPluginInfo_Params params = {render_frame_id, url, origin, mime_type}; |
Nicholas Verne | d391eae | 2017-11-13 02:41:38 | [diff] [blame] | 216 | PluginService::GetInstance()->GetPlugins(base::BindOnce( |
| 217 | &PluginInfoHostImpl::PluginsLoaded, this, params, std::move(callback))); |
[email protected] | 8aa7a41 | 2011-11-07 12:33:42 | [diff] [blame] | 218 | } |
| 219 | |
Nicholas Verne | d391eae | 2017-11-13 02:41:38 | [diff] [blame] | 220 | void PluginInfoHostImpl::PluginsLoaded( |
[email protected] | 8aa7a41 | 2011-11-07 12:33:42 | [diff] [blame] | 221 | const GetPluginInfo_Params& params, |
Nicholas Verne | b5df4f7 | 2017-11-08 09:12:07 | [diff] [blame] | 222 | GetPluginInfoCallback callback, |
[email protected] | dfdfeb7 | 2012-06-08 11:29:02 | [diff] [blame] | 223 | const std::vector<WebPluginInfo>& plugins) { |
Nicholas Verne | b5df4f7 | 2017-11-08 09:12:07 | [diff] [blame] | 224 | chrome::mojom::PluginInfoPtr output = chrome::mojom::PluginInfo::New(); |
[email protected] | 79fa336 | 2012-03-28 16:21:11 | [diff] [blame] | 225 | // This also fills in |actual_mime_type|. |
dcheng | 4af4858 | 2016-04-19 00:29:35 | [diff] [blame] | 226 | std::unique_ptr<PluginMetadata> plugin_metadata; |
[email protected] | 60eca4eb | 2013-12-06 00:02:16 | [diff] [blame] | 227 | if (context_.FindEnabledPlugin(params.render_frame_id, params.url, |
tommycli | f2a1e9f | 2016-10-06 18:34:36 | [diff] [blame] | 228 | params.main_frame_origin, params.mime_type, |
waffles | 77255cc | 2016-08-02 17:25:12 | [diff] [blame] | 229 | &output->status, &output->plugin, |
| 230 | &output->actual_mime_type, &plugin_metadata)) { |
tommycli | e97656b8 | 2016-11-30 16:43:00 | [diff] [blame] | 231 | context_.DecidePluginStatus( |
| 232 | params.url, params.main_frame_origin, output->plugin, |
| 233 | plugin_metadata->GetSecurityStatus(output->plugin), |
| 234 | plugin_metadata->identifier(), &output->status); |
[email protected] | 79fa336 | 2012-03-28 16:21:11 | [diff] [blame] | 235 | } |
[email protected] | cd33d28 | 2012-09-21 12:53:04 | [diff] [blame] | 236 | |
Nicholas Verne | b5df4f7 | 2017-11-08 09:12:07 | [diff] [blame] | 237 | if (output->status == chrome::mojom::PluginStatus::kNotFound) { |
waffles | 77255cc | 2016-08-02 17:25:12 | [diff] [blame] | 238 | // Check to see if the component updater can fetch an implementation. |
| 239 | base::PostTaskAndReplyWithResult( |
| 240 | main_thread_task_runner_.get(), FROM_HERE, |
Nicholas Verne | b5df4f7 | 2017-11-08 09:12:07 | [diff] [blame] | 241 | base::BindOnce( |
waffles | 77255cc | 2016-08-02 17:25:12 | [diff] [blame] | 242 | &component_updater::ComponentUpdateService::GetComponentForMimeType, |
| 243 | base::Unretained(g_browser_process->component_updater()), |
| 244 | params.mime_type), |
Nicholas Verne | d391eae | 2017-11-13 02:41:38 | [diff] [blame] | 245 | base::BindOnce(&PluginInfoHostImpl::ComponentPluginLookupDone, this, |
| 246 | params, std::move(output), std::move(callback), |
Nicholas Verne | b5df4f7 | 2017-11-08 09:12:07 | [diff] [blame] | 247 | std::move(plugin_metadata))); |
waffles | 77255cc | 2016-08-02 17:25:12 | [diff] [blame] | 248 | } else { |
Nicholas Verne | b5df4f7 | 2017-11-08 09:12:07 | [diff] [blame] | 249 | GetPluginInfoFinish(params, std::move(output), std::move(callback), |
| 250 | std::move(plugin_metadata)); |
wfh | be79ad5 | 2014-11-07 19:02:07 | [diff] [blame] | 251 | } |
[email protected] | 8aa7a41 | 2011-11-07 12:33:42 | [diff] [blame] | 252 | } |
| 253 | |
Nicholas Verne | d391eae | 2017-11-13 02:41:38 | [diff] [blame] | 254 | void PluginInfoHostImpl::Context::DecidePluginStatus( |
tommycli | e97656b8 | 2016-11-30 16:43:00 | [diff] [blame] | 255 | const GURL& url, |
| 256 | const url::Origin& main_frame_origin, |
[email protected] | 546abf3 | 2012-09-14 16:55:09 | [diff] [blame] | 257 | const WebPluginInfo& plugin, |
tommycli | e97656b8 | 2016-11-30 16:43:00 | [diff] [blame] | 258 | PluginMetadata::SecurityStatus security_status, |
| 259 | const std::string& plugin_identifier, |
Nicholas Verne | b5df4f7 | 2017-11-08 09:12:07 | [diff] [blame] | 260 | chrome::mojom::PluginStatus* status) const { |
tommycli | e97656b8 | 2016-11-30 16:43:00 | [diff] [blame] | 261 | if (security_status == PluginMetadata::SECURITY_STATUS_FULLY_TRUSTED) { |
Nicholas Verne | b5df4f7 | 2017-11-08 09:12:07 | [diff] [blame] | 262 | *status = chrome::mojom::PluginStatus::kAllowed; |
wfh | e53608b | 2016-04-07 02:18:53 | [diff] [blame] | 263 | return; |
| 264 | } |
| 265 | |
[email protected] | 8aa7a41 | 2011-11-07 12:33:42 | [diff] [blame] | 266 | ContentSetting plugin_setting = CONTENT_SETTING_DEFAULT; |
| 267 | bool uses_default_content_setting = true; |
[email protected] | 6a9d1deb | 2014-01-13 19:39:41 | [diff] [blame] | 268 | bool is_managed = false; |
tommycli | e86b298 | 2015-03-16 20:16:45 | [diff] [blame] | 269 | // Check plugin content settings. The primary URL is the top origin URL and |
| 270 | // the secondary URL is the plugin URL. |
raymes | 978301a2 | 2016-09-22 00:54:28 | [diff] [blame] | 271 | PluginUtils::GetPluginContentSetting( |
tommycli | e97656b8 | 2016-11-30 16:43:00 | [diff] [blame] | 272 | host_content_settings_map_, plugin, main_frame_origin, url, |
| 273 | plugin_identifier, &plugin_setting, &uses_default_content_setting, |
| 274 | &is_managed); |
tommycli | e2b1f1b | 2015-03-31 22:54:59 | [diff] [blame] | 275 | |
[email protected] | 8aa7a41 | 2011-11-07 12:33:42 | [diff] [blame] | 276 | DCHECK(plugin_setting != CONTENT_SETTING_DEFAULT); |
tommycli | e2b1f1b | 2015-03-31 22:54:59 | [diff] [blame] | 277 | DCHECK(plugin_setting != CONTENT_SETTING_ASK); |
[email protected] | 8aa7a41 | 2011-11-07 12:33:42 | [diff] [blame] | 278 | |
Nicholas Verne | b5df4f7 | 2017-11-08 09:12:07 | [diff] [blame] | 279 | if (*status == chrome::mojom::PluginStatus::kFlashHiddenPreferHtml) { |
tommycli | e97656b8 | 2016-11-30 16:43:00 | [diff] [blame] | 280 | if (plugin_setting == CONTENT_SETTING_BLOCK) { |
Tommy C. Li | 717a34a | 2019-03-28 16:24:51 | [diff] [blame^] | 281 | *status = is_managed ? chrome::mojom::PluginStatus::kBlockedByPolicy |
| 282 | : chrome::mojom::PluginStatus::kBlockedNoLoading; |
tommycli | e97656b8 | 2016-11-30 16:43:00 | [diff] [blame] | 283 | } |
| 284 | return; |
| 285 | } |
| 286 | |
bauerb | ecab4f5 | 2017-03-13 20:16:41 | [diff] [blame] | 287 | #if BUILDFLAG(ENABLE_PLUGINS) |
tommycli | e86b298 | 2015-03-16 20:16:45 | [diff] [blame] | 288 | // Check if the plugin is outdated. |
tommycli | e97656b8 | 2016-11-30 16:43:00 | [diff] [blame] | 289 | if (security_status == PluginMetadata::SECURITY_STATUS_OUT_OF_DATE && |
[email protected] | 9f230ed | 2012-05-24 11:19:40 | [diff] [blame] | 290 | !allow_outdated_plugins_.GetValue()) { |
[email protected] | 8aa7a41 | 2011-11-07 12:33:42 | [diff] [blame] | 291 | if (allow_outdated_plugins_.IsManaged()) { |
Nicholas Verne | b5df4f7 | 2017-11-08 09:12:07 | [diff] [blame] | 292 | *status = chrome::mojom::PluginStatus::kOutdatedDisallowed; |
[email protected] | 8aa7a41 | 2011-11-07 12:33:42 | [diff] [blame] | 293 | } else { |
Nicholas Verne | b5df4f7 | 2017-11-08 09:12:07 | [diff] [blame] | 294 | *status = chrome::mojom::PluginStatus::kOutdatedBlocked; |
[email protected] | 8aa7a41 | 2011-11-07 12:33:42 | [diff] [blame] | 295 | } |
| 296 | return; |
| 297 | } |
bauerb | ecab4f5 | 2017-03-13 20:16:41 | [diff] [blame] | 298 | #endif // BUILDFLAG(ENABLE_PLUGINS) |
[email protected] | ef97ce34 | 2012-09-24 20:05:02 | [diff] [blame] | 299 | |
tommycli | e86b298 | 2015-03-16 20:16:45 | [diff] [blame] | 300 | // Check if the plugin is crashing too much. |
[email protected] | ef97ce34 | 2012-09-24 20:05:02 | [diff] [blame] | 301 | if (PluginService::GetInstance()->IsPluginUnstable(plugin.path) && |
Nicholas Verne | d391eae | 2017-11-13 02:41:38 | [diff] [blame] | 302 | plugin_setting != CONTENT_SETTING_BLOCK && uses_default_content_setting) { |
Nicholas Verne | b5df4f7 | 2017-11-08 09:12:07 | [diff] [blame] | 303 | *status = chrome::mojom::PluginStatus::kUnauthorized; |
[email protected] | ef97ce34 | 2012-09-24 20:05:02 | [diff] [blame] | 304 | return; |
| 305 | } |
[email protected] | 8aa7a41 | 2011-11-07 12:33:42 | [diff] [blame] | 306 | |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 307 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
Sadrul Habib Chowdhury | f43c33c | 2014-12-04 15:53:52 | [diff] [blame] | 308 | // If an app has explicitly made internal resources available by listing them |
| 309 | // in |accessible_resources| in the manifest, then allow them to be loaded by |
| 310 | // plugins inside a guest-view. |
tommycli | e97656b8 | 2016-11-30 16:43:00 | [diff] [blame] | 311 | if (url.SchemeIs(extensions::kExtensionScheme) && !is_managed && |
lfg | 44c8a68f | 2015-04-16 16:38:15 | [diff] [blame] | 312 | plugin_setting == CONTENT_SETTING_BLOCK && |
tommycli | e97656b8 | 2016-11-30 16:43:00 | [diff] [blame] | 313 | IsPluginLoadingAccessibleResourceInWebView(extension_registry_, |
| 314 | render_process_id_, url)) { |
Sadrul Habib Chowdhury | f43c33c | 2014-12-04 15:53:52 | [diff] [blame] | 315 | plugin_setting = CONTENT_SETTING_ALLOW; |
| 316 | } |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 317 | #endif // BUILDFLAG(ENABLE_EXTENSIONS) |
Sadrul Habib Chowdhury | f43c33c | 2014-12-04 15:53:52 | [diff] [blame] | 318 | |
tommycli | 608ec89b | 2016-09-28 16:39:00 | [diff] [blame] | 319 | if (plugin_setting == CONTENT_SETTING_DETECT_IMPORTANT_CONTENT || |
| 320 | (plugin_setting == CONTENT_SETTING_ALLOW && |
Bernhard Bauer | 1919073 | 2017-09-28 09:03:33 | [diff] [blame] | 321 | !run_all_flash_in_allow_mode_.GetValue())) { |
Nicholas Verne | b5df4f7 | 2017-11-08 09:12:07 | [diff] [blame] | 322 | *status = chrome::mojom::PluginStatus::kPlayImportantContent; |
tommycli | e2b1f1b | 2015-03-31 22:54:59 | [diff] [blame] | 323 | } else if (plugin_setting == CONTENT_SETTING_BLOCK) { |
Tommy C. Li | 717a34a | 2019-03-28 16:24:51 | [diff] [blame^] | 324 | *status = is_managed ? chrome::mojom::PluginStatus::kBlockedByPolicy |
| 325 | : chrome::mojom::PluginStatus::kBlocked; |
[email protected] | 6a9d1deb | 2014-01-13 19:39:41 | [diff] [blame] | 326 | } |
[email protected] | aea757d | 2013-09-27 22:27:38 | [diff] [blame] | 327 | |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 328 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
tommycli | 550b222 | 2015-09-03 21:06:10 | [diff] [blame] | 329 | // Allow an embedder of <webview> to block a plugin from being loaded inside |
| 330 | // the guest. In order to do this, set the status to 'Unauthorized' here, |
| 331 | // and update the status as appropriate depending on the response from the |
| 332 | // embedder. |
Nicholas Verne | b5df4f7 | 2017-11-08 09:12:07 | [diff] [blame] | 333 | if (*status == chrome::mojom::PluginStatus::kAllowed || |
| 334 | *status == chrome::mojom::PluginStatus::kBlocked || |
| 335 | *status == chrome::mojom::PluginStatus::kPlayImportantContent) { |
[email protected] | 140d6cd9 | 2014-08-12 18:26:46 | [diff] [blame] | 336 | if (extensions::WebViewRendererState::GetInstance()->IsGuest( |
tommycli | 550b222 | 2015-09-03 21:06:10 | [diff] [blame] | 337 | render_process_id_)) |
Nicholas Verne | b5df4f7 | 2017-11-08 09:12:07 | [diff] [blame] | 338 | *status = chrome::mojom::PluginStatus::kUnauthorized; |
[email protected] | aea757d | 2013-09-27 22:27:38 | [diff] [blame] | 339 | } |
tommycli | 550b222 | 2015-09-03 21:06:10 | [diff] [blame] | 340 | #endif |
[email protected] | 8aa7a41 | 2011-11-07 12:33:42 | [diff] [blame] | 341 | } |
| 342 | |
Nicholas Verne | d391eae | 2017-11-13 02:41:38 | [diff] [blame] | 343 | bool PluginInfoHostImpl::Context::FindEnabledPlugin( |
[email protected] | 60eca4eb | 2013-12-06 00:02:16 | [diff] [blame] | 344 | int render_frame_id, |
[email protected] | 8aa7a41 | 2011-11-07 12:33:42 | [diff] [blame] | 345 | const GURL& url, |
tommycli | f2a1e9f | 2016-10-06 18:34:36 | [diff] [blame] | 346 | const url::Origin& main_frame_origin, |
[email protected] | 8aa7a41 | 2011-11-07 12:33:42 | [diff] [blame] | 347 | const std::string& mime_type, |
Nicholas Verne | b5df4f7 | 2017-11-08 09:12:07 | [diff] [blame] | 348 | chrome::mojom::PluginStatus* status, |
[email protected] | dfdfeb7 | 2012-06-08 11:29:02 | [diff] [blame] | 349 | WebPluginInfo* plugin, |
[email protected] | 4da40567 | 2012-10-25 10:43:03 | [diff] [blame] | 350 | std::string* actual_mime_type, |
dcheng | 4af4858 | 2016-04-19 00:29:35 | [diff] [blame] | 351 | std::unique_ptr<PluginMetadata>* plugin_metadata) const { |
Nicholas Verne | b5df4f7 | 2017-11-08 09:12:07 | [diff] [blame] | 352 | *status = chrome::mojom::PluginStatus::kAllowed; |
bauerb | 96d29c0 | 2015-04-09 08:40:35 | [diff] [blame] | 353 | |
[email protected] | 8aa7a41 | 2011-11-07 12:33:42 | [diff] [blame] | 354 | bool allow_wildcard = true; |
[email protected] | dfdfeb7 | 2012-06-08 11:29:02 | [diff] [blame] | 355 | std::vector<WebPluginInfo> matching_plugins; |
[email protected] | 8aa7a41 | 2011-11-07 12:33:42 | [diff] [blame] | 356 | std::vector<std::string> mime_types; |
| 357 | PluginService::GetInstance()->GetPluginInfoArray( |
| 358 | url, mime_type, allow_wildcard, &matching_plugins, &mime_types); |
waffles | cd59e9b | 2016-08-30 04:34:44 | [diff] [blame] | 359 | #if defined(GOOGLE_CHROME_BUILD) |
Eugene Kim | 0b4b457 | 2018-09-01 02:37:58 | [diff] [blame] | 360 | base::EraseIf(matching_plugins, [&](const WebPluginInfo& info) { |
| 361 | return info.path.value() == ChromeContentClient::kNotPresent; |
| 362 | }); |
waffles | cd59e9b | 2016-08-30 04:34:44 | [diff] [blame] | 363 | #endif // defined(GOOGLE_CHROME_BUILD) |
[email protected] | 4da40567 | 2012-10-25 10:43:03 | [diff] [blame] | 364 | if (matching_plugins.empty()) { |
Nicholas Verne | b5df4f7 | 2017-11-08 09:12:07 | [diff] [blame] | 365 | *status = chrome::mojom::PluginStatus::kNotFound; |
[email protected] | 4da40567 | 2012-10-25 10:43:03 | [diff] [blame] | 366 | return false; |
| 367 | } |
| 368 | |
[email protected] | 3a5180ae | 2011-12-21 02:39:38 | [diff] [blame] | 369 | content::PluginServiceFilter* filter = |
| 370 | PluginService::GetInstance()->GetFilter(); |
[email protected] | 4da40567 | 2012-10-25 10:43:03 | [diff] [blame] | 371 | size_t i = 0; |
| 372 | for (; i < matching_plugins.size(); ++i) { |
Nicholas Verne | d391eae | 2017-11-13 02:41:38 | [diff] [blame] | 373 | if (!filter || filter->IsPluginAvailable( |
| 374 | render_process_id_, render_frame_id, resource_context_, |
| 375 | url, main_frame_origin, &matching_plugins[i])) { |
[email protected] | 4da40567 | 2012-10-25 10:43:03 | [diff] [blame] | 376 | break; |
[email protected] | 8aa7a41 | 2011-11-07 12:33:42 | [diff] [blame] | 377 | } |
| 378 | } |
| 379 | |
tommycli | e86b298 | 2015-03-16 20:16:45 | [diff] [blame] | 380 | // If we broke out of the loop, we have found an enabled plugin. |
[email protected] | 4da40567 | 2012-10-25 10:43:03 | [diff] [blame] | 381 | bool enabled = i < matching_plugins.size(); |
| 382 | if (!enabled) { |
tommycli | e86b298 | 2015-03-16 20:16:45 | [diff] [blame] | 383 | // Otherwise, we only found disabled plugins, so we take the first one. |
[email protected] | 4da40567 | 2012-10-25 10:43:03 | [diff] [blame] | 384 | i = 0; |
Nicholas Verne | b5df4f7 | 2017-11-08 09:12:07 | [diff] [blame] | 385 | *status = chrome::mojom::PluginStatus::kDisabled; |
tommycli | c0c4f94 | 2016-09-19 19:35:00 | [diff] [blame] | 386 | |
Tommy C. Li | 5834262 | 2019-03-27 23:08:51 | [diff] [blame] | 387 | // Special case for Flash: this is our Prefer HTML over Plugins logic. |
| 388 | if (matching_plugins[0].name == |
| 389 | base::ASCIIToUTF16(content::kFlashPluginName)) { |
Nicholas Verne | b5df4f7 | 2017-11-08 09:12:07 | [diff] [blame] | 390 | *status = chrome::mojom::PluginStatus::kFlashHiddenPreferHtml; |
tommycli | e97656b8 | 2016-11-30 16:43:00 | [diff] [blame] | 391 | |
| 392 | // In the Prefer HTML case, the plugin is actually enabled, but hidden. |
| 393 | // It will still be blocked in the body of DecidePluginStatus. |
| 394 | enabled = true; |
tommycli | c0c4f94 | 2016-09-19 19:35:00 | [diff] [blame] | 395 | } |
[email protected] | 4da40567 | 2012-10-25 10:43:03 | [diff] [blame] | 396 | } |
| 397 | |
| 398 | *plugin = matching_plugins[i]; |
| 399 | *actual_mime_type = mime_types[i]; |
| 400 | if (plugin_metadata) |
| 401 | *plugin_metadata = PluginFinder::GetInstance()->GetPluginMetadata(*plugin); |
| 402 | |
| 403 | return enabled; |
[email protected] | 8aa7a41 | 2011-11-07 12:33:42 | [diff] [blame] | 404 | } |
| 405 | |
Nicholas Verne | d391eae | 2017-11-13 02:41:38 | [diff] [blame] | 406 | void PluginInfoHostImpl::ComponentPluginLookupDone( |
waffles | 77255cc | 2016-08-02 17:25:12 | [diff] [blame] | 407 | const GetPluginInfo_Params& params, |
Nicholas Verne | b5df4f7 | 2017-11-08 09:12:07 | [diff] [blame] | 408 | chrome::mojom::PluginInfoPtr output, |
| 409 | GetPluginInfoCallback callback, |
waffles | 77255cc | 2016-08-02 17:25:12 | [diff] [blame] | 410 | std::unique_ptr<PluginMetadata> plugin_metadata, |
waffles | 77255cc | 2016-08-02 17:25:12 | [diff] [blame] | 411 | std::unique_ptr<component_updater::ComponentInfo> cus_plugin_info) { |
| 412 | if (cus_plugin_info) { |
Nicholas Verne | b5df4f7 | 2017-11-08 09:12:07 | [diff] [blame] | 413 | output->status = chrome::mojom::PluginStatus::kComponentUpdateRequired; |
waffles | e7759f7 | 2016-10-10 23:41:25 | [diff] [blame] | 414 | #if defined(OS_LINUX) |
| 415 | if (cus_plugin_info->version != base::Version("0")) { |
Nicholas Verne | b5df4f7 | 2017-11-08 09:12:07 | [diff] [blame] | 416 | output->status = chrome::mojom::PluginStatus::kRestartRequired; |
waffles | e7759f7 | 2016-10-10 23:41:25 | [diff] [blame] | 417 | } |
thestig | d6e43818 | 2017-06-01 23:16:27 | [diff] [blame] | 418 | #endif |
Jeremy Roman | ec48d7a | 2018-03-01 17:35:09 | [diff] [blame] | 419 | plugin_metadata = std::make_unique<PluginMetadata>( |
waffles | 77255cc | 2016-08-02 17:25:12 | [diff] [blame] | 420 | cus_plugin_info->id, cus_plugin_info->name, false, GURL(), GURL(), |
thestig | d6e43818 | 2017-06-01 23:16:27 | [diff] [blame] | 421 | base::ASCIIToUTF16(cus_plugin_info->id), std::string()); |
waffles | 77255cc | 2016-08-02 17:25:12 | [diff] [blame] | 422 | } |
Nicholas Verne | b5df4f7 | 2017-11-08 09:12:07 | [diff] [blame] | 423 | GetPluginInfoFinish(params, std::move(output), std::move(callback), |
| 424 | std::move(plugin_metadata)); |
waffles | 77255cc | 2016-08-02 17:25:12 | [diff] [blame] | 425 | } |
| 426 | |
Nicholas Verne | d391eae | 2017-11-13 02:41:38 | [diff] [blame] | 427 | void PluginInfoHostImpl::GetPluginInfoFinish( |
waffles | 77255cc | 2016-08-02 17:25:12 | [diff] [blame] | 428 | const GetPluginInfo_Params& params, |
Nicholas Verne | b5df4f7 | 2017-11-08 09:12:07 | [diff] [blame] | 429 | chrome::mojom::PluginInfoPtr output, |
| 430 | GetPluginInfoCallback callback, |
| 431 | std::unique_ptr<PluginMetadata> plugin_metadata) { |
waffles | 77255cc | 2016-08-02 17:25:12 | [diff] [blame] | 432 | if (plugin_metadata) { |
| 433 | output->group_identifier = plugin_metadata->identifier(); |
| 434 | output->group_name = plugin_metadata->name(); |
| 435 | } |
| 436 | |
| 437 | context_.MaybeGrantAccess(output->status, output->plugin.path); |
| 438 | |
Nicholas Verne | b5df4f7 | 2017-11-08 09:12:07 | [diff] [blame] | 439 | if (output->status != chrome::mojom::PluginStatus::kNotFound) { |
waffles | 77255cc | 2016-08-02 17:25:12 | [diff] [blame] | 440 | main_thread_task_runner_->PostTask( |
tommycli | 910b408 | 2017-04-03 17:04:15 | [diff] [blame] | 441 | FROM_HERE, |
Nicholas Verne | d391eae | 2017-11-13 02:41:38 | [diff] [blame] | 442 | base::BindOnce(&PluginInfoHostImpl::ReportMetrics, this, |
tzik | 3f7781d | 2017-04-20 17:09:33 | [diff] [blame] | 443 | params.render_frame_id, output->actual_mime_type, |
Steven Holte | f0f4677 | 2017-12-11 20:54:51 | [diff] [blame] | 444 | params.url, params.main_frame_origin)); |
waffles | 77255cc | 2016-08-02 17:25:12 | [diff] [blame] | 445 | } |
Nicholas Verne | b5df4f7 | 2017-11-08 09:12:07 | [diff] [blame] | 446 | std::move(callback).Run(std::move(output)); |
waffles | 77255cc | 2016-08-02 17:25:12 | [diff] [blame] | 447 | } |
| 448 | |
Nicholas Verne | d391eae | 2017-11-13 02:41:38 | [diff] [blame] | 449 | void PluginInfoHostImpl::ReportMetrics(int render_frame_id, |
| 450 | const base::StringPiece& mime_type, |
| 451 | const GURL& url, |
Steven Holte | f0f4677 | 2017-12-11 20:54:51 | [diff] [blame] | 452 | const url::Origin& main_frame_origin) { |
tommycli | 910b408 | 2017-04-03 17:04:15 | [diff] [blame] | 453 | DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 454 | |
| 455 | content::RenderFrameHost* frame = content::RenderFrameHost::FromID( |
| 456 | context_.render_process_id(), render_frame_id); |
| 457 | content::WebContents* web_contents = |
| 458 | content::WebContents::FromRenderFrameHost(frame); |
| 459 | // This can occur the web contents has already been closed or navigated away. |
| 460 | if (!web_contents) |
| 461 | return; |
| 462 | |
| 463 | if (web_contents->GetBrowserContext()->IsOffTheRecord()) |
| 464 | return; |
| 465 | |
| 466 | rappor::RapporServiceImpl* rappor_service = |
| 467 | g_browser_process->rappor_service(); |
| 468 | if (!rappor_service) |
| 469 | return; |
Chris Palmer | ab5e5b5 | 2018-09-28 19:19:30 | [diff] [blame] | 470 | if (main_frame_origin.opaque()) |
tommycli | 910b408 | 2017-04-03 17:04:15 | [diff] [blame] | 471 | return; |
| 472 | |
| 473 | if (mime_type != content::kFlashPluginSwfMimeType && |
| 474 | mime_type != content::kFlashPluginSplMimeType) { |
| 475 | return; |
| 476 | } |
| 477 | |
| 478 | rappor_service->RecordSampleString( |
| 479 | "Plugins.FlashOriginUrl", rappor::ETLD_PLUS_ONE_RAPPOR_TYPE, |
| 480 | net::registry_controlled_domains::GetDomainAndRegistry( |
| 481 | main_frame_origin.GetURL(), |
| 482 | net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES)); |
| 483 | rappor_service->RecordSampleString( |
| 484 | "Plugins.FlashUrl", rappor::ETLD_PLUS_ONE_RAPPOR_TYPE, |
| 485 | net::registry_controlled_domains::GetDomainAndRegistry( |
| 486 | url, net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES)); |
| 487 | |
Steven Holte | f0f4677 | 2017-12-11 20:54:51 | [diff] [blame] | 488 | ukm::builders::Plugins_FlashInstance( |
| 489 | ukm::GetSourceIdForWebContentsDocument(web_contents)) |
| 490 | .Record(ukm::UkmRecorder::Get()); |
tommycli | 910b408 | 2017-04-03 17:04:15 | [diff] [blame] | 491 | } |
| 492 | |
Nicholas Verne | d391eae | 2017-11-13 02:41:38 | [diff] [blame] | 493 | void PluginInfoHostImpl::Context::MaybeGrantAccess( |
Nicholas Verne | b5df4f7 | 2017-11-08 09:12:07 | [diff] [blame] | 494 | chrome::mojom::PluginStatus status, |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 495 | const base::FilePath& path) const { |
Nicholas Verne | b5df4f7 | 2017-11-08 09:12:07 | [diff] [blame] | 496 | if (status == chrome::mojom::PluginStatus::kAllowed || |
| 497 | status == chrome::mojom::PluginStatus::kPlayImportantContent) { |
[email protected] | 6be31d20 | 2013-02-01 18:20:54 | [diff] [blame] | 498 | ChromePluginServiceFilter::GetInstance()->AuthorizePlugin( |
| 499 | render_process_id_, path); |
| 500 | } |
| 501 | } |
| 502 | |
Nicholas Verne | d391eae | 2017-11-13 02:41:38 | [diff] [blame] | 503 | bool PluginInfoHostImpl::Context::IsPluginEnabled( |
[email protected] | 4cbbeb4 | 2014-07-22 19:29:38 | [diff] [blame] | 504 | const content::WebPluginInfo& plugin) const { |
| 505 | return plugin_prefs_->IsPluginEnabled(plugin); |
| 506 | } |