[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" |
Nico Weber | eaa0841 | 2019-08-14 01:24:37 | [diff] [blame] | 19 | #include "build/branding_buildflags.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" |
Nicholas Verne | b5df4f7 | 2017-11-08 09:12:07 | [diff] [blame] | 32 | #include "chrome/common/plugin.mojom.h" |
[email protected] | 8aa7a41 | 2011-11-07 12:33:42 | [diff] [blame] | 33 | #include "chrome/common/pref_names.h" |
waffles | 77255cc | 2016-08-02 17:25:12 | [diff] [blame] | 34 | #include "components/component_updater/component_updater_service.h" |
mukai | 8eaec82 | 2014-10-25 17:53:16 | [diff] [blame] | 35 | #include "components/content_settings/core/browser/content_settings_utils.h" |
| 36 | #include "components/content_settings/core/browser/host_content_settings_map.h" |
mukai | 077089f | 2014-09-11 18:41:52 | [diff] [blame] | 37 | #include "components/content_settings/core/common/content_settings.h" |
rbpotter | 654f42d | 2016-12-02 22:17:07 | [diff] [blame] | 38 | #include "components/keyed_service/content/browser_context_keyed_service_shutdown_notifier_factory.h" |
Scott Violet | 9ae8289 | 2018-03-01 18:38:12 | [diff] [blame] | 39 | #include "components/nacl/common/buildflags.h" |
Bernhard Bauer | 1919073 | 2017-09-28 09:03:33 | [diff] [blame] | 40 | #include "components/pref_registry/pref_registry_syncable.h" |
brettw | b1fc1b8 | 2016-02-02 00:19:08 | [diff] [blame] | 41 | #include "components/prefs/pref_service.h" |
Steven Holte | f0f4677 | 2017-12-11 20:54:51 | [diff] [blame] | 42 | #include "components/ukm/content/source_url_recorder.h" |
Eric Seckler | 8652dcd5 | 2018-09-20 10:42:28 | [diff] [blame] | 43 | #include "content/public/browser/browser_task_traits.h" |
[email protected] | 3a5180ae | 2011-12-21 02:39:38 | [diff] [blame] | 44 | #include "content/public/browser/plugin_service.h" |
[email protected] | 31f376c | 2012-03-13 16:43:09 | [diff] [blame] | 45 | #include "content/public/browser/plugin_service_filter.h" |
tommycli | 910b408 | 2017-04-03 17:04:15 | [diff] [blame] | 46 | #include "content/public/browser/render_frame_host.h" |
wfh | dfcab2e4 | 2014-11-07 06:48:32 | [diff] [blame] | 47 | #include "content/public/common/content_constants.h" |
Scott Violet | c8240b0 | 2018-03-08 22:03:59 | [diff] [blame] | 48 | #include "extensions/buildflags/buildflags.h" |
wfh | dfcab2e4 | 2014-11-07 06:48:32 | [diff] [blame] | 49 | #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
Scott Violet | 02e38b9 | 2018-03-27 23:42:14 | [diff] [blame] | 50 | #include "ppapi/buildflags/buildflags.h" |
Steven Holte | f0f4677 | 2017-12-11 20:54:51 | [diff] [blame] | 51 | #include "services/metrics/public/cpp/ukm_builders.h" |
Mounir Lamouri | fd9dcefa | 2017-07-06 10:26:55 | [diff] [blame] | 52 | #include "services/metrics/public/cpp/ukm_recorder.h" |
[email protected] | 761fa470 | 2013-07-02 15:25:15 | [diff] [blame] | 53 | #include "url/gurl.h" |
tommycli | f2a1e9f | 2016-10-06 18:34:36 | [diff] [blame] | 54 | #include "url/origin.h" |
[email protected] | b9b88a08 | 2013-03-21 03:51:02 | [diff] [blame] | 55 | |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 56 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
fsamuel | 8dfa19a | 2015-05-05 01:00:39 | [diff] [blame] | 57 | #include "components/guest_view/browser/guest_view_base.h" |
Sadrul Habib Chowdhury | f43c33c | 2014-12-04 15:53:52 | [diff] [blame] | 58 | #include "extensions/browser/extension_registry.h" |
hanxi | 0d0a1e9 | 2014-08-26 18:39:48 | [diff] [blame] | 59 | #include "extensions/browser/guest_view/web_view/web_view_renderer_state.h" |
lfg | 44c8a68f | 2015-04-16 16:38:15 | [diff] [blame] | 60 | #include "extensions/common/constants.h" |
Sadrul Habib Chowdhury | f43c33c | 2014-12-04 15:53:52 | [diff] [blame] | 61 | #include "extensions/common/extension.h" |
| 62 | #include "extensions/common/manifest_handlers/webview_info.h" |
[email protected] | 21a2013 | 2014-07-16 00:48:59 | [diff] [blame] | 63 | #endif |
| 64 | |
Nico Weber | af3b00b | 2017-09-11 17:58:17 | [diff] [blame] | 65 | #if BUILDFLAG(ENABLE_NACL) |
[email protected] | e0ff1aa | 2014-08-16 01:38:11 | [diff] [blame] | 66 | #include "components/nacl/common/nacl_constants.h" |
| 67 | #endif |
| 68 | |
[email protected] | 3a5180ae | 2011-12-21 02:39:38 | [diff] [blame] | 69 | using content::PluginService; |
[email protected] | d7bd3e5 | 2013-07-21 04:29:20 | [diff] [blame] | 70 | using content::WebPluginInfo; |
[email protected] | 3a5180ae | 2011-12-21 02:39:38 | [diff] [blame] | 71 | |
[email protected] | b9b88a08 | 2013-03-21 03:51:02 | [diff] [blame] | 72 | namespace { |
| 73 | |
Daniel Bratell | 84928c5 | 2018-01-16 21:40:34 | [diff] [blame] | 74 | class PluginInfoHostImplShutdownNotifierFactory |
rbpotter | 654f42d | 2016-12-02 22:17:07 | [diff] [blame] | 75 | : public BrowserContextKeyedServiceShutdownNotifierFactory { |
| 76 | public: |
Daniel Bratell | 84928c5 | 2018-01-16 21:40:34 | [diff] [blame] | 77 | static PluginInfoHostImplShutdownNotifierFactory* GetInstance() { |
| 78 | return base::Singleton<PluginInfoHostImplShutdownNotifierFactory>::get(); |
rbpotter | 654f42d | 2016-12-02 22:17:07 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | private: |
Daniel Bratell | 84928c5 | 2018-01-16 21:40:34 | [diff] [blame] | 82 | friend struct base::DefaultSingletonTraits< |
| 83 | PluginInfoHostImplShutdownNotifierFactory>; |
rbpotter | 654f42d | 2016-12-02 22:17:07 | [diff] [blame] | 84 | |
Daniel Bratell | 84928c5 | 2018-01-16 21:40:34 | [diff] [blame] | 85 | PluginInfoHostImplShutdownNotifierFactory() |
rbpotter | 654f42d | 2016-12-02 22:17:07 | [diff] [blame] | 86 | : BrowserContextKeyedServiceShutdownNotifierFactory( |
Nicholas Verne | d391eae | 2017-11-13 02:41:38 | [diff] [blame] | 87 | "PluginInfoHostImpl") {} |
rbpotter | 654f42d | 2016-12-02 22:17:07 | [diff] [blame] | 88 | |
Daniel Bratell | 84928c5 | 2018-01-16 21:40:34 | [diff] [blame] | 89 | ~PluginInfoHostImplShutdownNotifierFactory() override {} |
rbpotter | 654f42d | 2016-12-02 22:17:07 | [diff] [blame] | 90 | |
Daniel Bratell | 84928c5 | 2018-01-16 21:40:34 | [diff] [blame] | 91 | DISALLOW_COPY_AND_ASSIGN(PluginInfoHostImplShutdownNotifierFactory); |
rbpotter | 654f42d | 2016-12-02 22:17:07 | [diff] [blame] | 92 | }; |
| 93 | |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 94 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
Sadrul Habib Chowdhury | f43c33c | 2014-12-04 15:53:52 | [diff] [blame] | 95 | // 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. |
| 98 | bool 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(); |
paulmeyer | ad727fc6 | 2015-09-09 15:29:59 | [diff] [blame] | 111 | const extensions::Extension* extension = extension_registry->GetExtensionById( |
| 112 | extension_id, extensions::ExtensionRegistry::ENABLED); |
| 113 | if (!extension || !extensions::WebviewInfo::IsResourceWebviewAccessible( |
Nicholas Verne | d391eae | 2017-11-13 02:41:38 | [diff] [blame] | 114 | extension, partition_id, resource.path())) { |
Sadrul Habib Chowdhury | f43c33c | 2014-12-04 15:53:52 | [diff] [blame] | 115 | 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 | } |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 124 | #endif // BUILDFLAG(ENABLE_EXTENSIONS) |
Sadrul Habib Chowdhury | f43c33c | 2014-12-04 15:53:52 | [diff] [blame] | 125 | |
[email protected] | b9b88a08 | 2013-03-21 03:51:02 | [diff] [blame] | 126 | } // namespace |
| 127 | |
Nicholas Verne | d391eae | 2017-11-13 02:41:38 | [diff] [blame] | 128 | PluginInfoHostImpl::Context::Context(int render_process_id, Profile* profile) |
[email protected] | 0a8f3a7f | 2012-01-17 16:17:19 | [diff] [blame] | 129 | : render_process_id_(render_process_id), |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 130 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
Sadrul Habib Chowdhury | f43c33c | 2014-12-04 15:53:52 | [diff] [blame] | 131 | extension_registry_(extensions::ExtensionRegistry::Get(profile)), |
| 132 | #endif |
Nicholas Verne | d391eae | 2017-11-13 02:41:38 | [diff] [blame] | 133 | host_content_settings_map_( |
| 134 | HostContentSettingsMapFactory::GetForProfile(profile)), |
[email protected] | 601e3c8 | 2013-10-03 01:31:20 | [diff] [blame] | 135 | plugin_prefs_(PluginPrefs::GetForProfile(profile)) { |
[email protected] | 8aa7a41 | 2011-11-07 12:33:42 | [diff] [blame] | 136 | allow_outdated_plugins_.Init(prefs::kPluginsAllowOutdated, |
[email protected] | 96a5c34 | 2012-12-04 18:14:02 | [diff] [blame] | 137 | profile->GetPrefs()); |
Bernhard Bauer | 1919073 | 2017-09-28 09:03:33 | [diff] [blame] | 138 | run_all_flash_in_allow_mode_.Init(prefs::kRunAllFlashInAllowMode, |
| 139 | profile->GetPrefs()); |
[email protected] | 8aa7a41 | 2011-11-07 12:33:42 | [diff] [blame] | 140 | } |
| 141 | |
Nicholas Verne | d391eae | 2017-11-13 02:41:38 | [diff] [blame] | 142 | PluginInfoHostImpl::Context::~Context() {} |
[email protected] | 0a8f3a7f | 2012-01-17 16:17:19 | [diff] [blame] | 143 | |
Nicholas Verne | d391eae | 2017-11-13 02:41:38 | [diff] [blame] | 144 | void PluginInfoHostImpl::Context::ShutdownOnUIThread() { |
rbpotter | 654f42d | 2016-12-02 22:17:07 | [diff] [blame] | 145 | DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
rbpotter | 654f42d | 2016-12-02 22:17:07 | [diff] [blame] | 146 | allow_outdated_plugins_.Destroy(); |
Bernhard Bauer | 1919073 | 2017-09-28 09:03:33 | [diff] [blame] | 147 | run_all_flash_in_allow_mode_.Destroy(); |
rbpotter | 654f42d | 2016-12-02 22:17:07 | [diff] [blame] | 148 | } |
| 149 | |
Nicholas Verne | d391eae | 2017-11-13 02:41:38 | [diff] [blame] | 150 | PluginInfoHostImpl::PluginInfoHostImpl(int render_process_id, Profile* profile) |
Clark DuVall | 1df2052b | 2019-08-05 19:58:46 | [diff] [blame] | 151 | : context_(render_process_id, profile) { |
rbpotter | 654f42d | 2016-12-02 22:17:07 | [diff] [blame] | 152 | shutdown_notifier_ = |
Daniel Bratell | 84928c5 | 2018-01-16 21:40:34 | [diff] [blame] | 153 | PluginInfoHostImplShutdownNotifierFactory::GetInstance() |
| 154 | ->Get(profile) |
| 155 | ->Subscribe(base::Bind(&PluginInfoHostImpl::ShutdownOnUIThread, |
| 156 | base::Unretained(this))); |
rbpotter | 654f42d | 2016-12-02 22:17:07 | [diff] [blame] | 157 | } |
| 158 | |
Nicholas Verne | d391eae | 2017-11-13 02:41:38 | [diff] [blame] | 159 | void PluginInfoHostImpl::ShutdownOnUIThread() { |
rbpotter | 654f42d | 2016-12-02 22:17:07 | [diff] [blame] | 160 | DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 161 | context_.ShutdownOnUIThread(); |
| 162 | shutdown_notifier_.reset(); |
[email protected] | 0a8f3a7f | 2012-01-17 16:17:19 | [diff] [blame] | 163 | } |
| 164 | |
Bernhard Bauer | 1919073 | 2017-09-28 09:03:33 | [diff] [blame] | 165 | // static |
Nicholas Verne | d391eae | 2017-11-13 02:41:38 | [diff] [blame] | 166 | void PluginInfoHostImpl::RegisterUserPrefs( |
Bernhard Bauer | 1919073 | 2017-09-28 09:03:33 | [diff] [blame] | 167 | user_prefs::PrefRegistrySyncable* registry) { |
| 168 | registry->RegisterBooleanPref(prefs::kPluginsAllowOutdated, false); |
Bernhard Bauer | 1919073 | 2017-09-28 09:03:33 | [diff] [blame] | 169 | registry->RegisterBooleanPref(prefs::kRunAllFlashInAllowMode, false); |
| 170 | } |
| 171 | |
Nicholas Verne | d391eae | 2017-11-13 02:41:38 | [diff] [blame] | 172 | PluginInfoHostImpl::~PluginInfoHostImpl() {} |
[email protected] | 649d1c0 | 2012-04-27 02:56:21 | [diff] [blame] | 173 | |
Nicholas Verne | d391eae | 2017-11-13 02:41:38 | [diff] [blame] | 174 | struct PluginInfoHostImpl::GetPluginInfo_Params { |
[email protected] | 60eca4eb | 2013-12-06 00:02:16 | [diff] [blame] | 175 | int render_frame_id; |
[email protected] | 8aa7a41 | 2011-11-07 12:33:42 | [diff] [blame] | 176 | GURL url; |
tommycli | f2a1e9f | 2016-10-06 18:34:36 | [diff] [blame] | 177 | url::Origin main_frame_origin; |
[email protected] | 8aa7a41 | 2011-11-07 12:33:42 | [diff] [blame] | 178 | std::string mime_type; |
| 179 | }; |
| 180 | |
Nicholas Verne | d391eae | 2017-11-13 02:41:38 | [diff] [blame] | 181 | void PluginInfoHostImpl::GetPluginInfo(int32_t render_frame_id, |
| 182 | const GURL& url, |
| 183 | const url::Origin& origin, |
| 184 | const std::string& mime_type, |
tzik | cd02d3b | 2018-08-09 21:32:47 | [diff] [blame] | 185 | GetPluginInfoCallback callback) { |
Clark DuVall | 1df2052b | 2019-08-05 19:58:46 | [diff] [blame] | 186 | DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
Nicholas Verne | b5df4f7 | 2017-11-08 09:12:07 | [diff] [blame] | 187 | GetPluginInfo_Params params = {render_frame_id, url, origin, mime_type}; |
Clark DuVall | 1df2052b | 2019-08-05 19:58:46 | [diff] [blame] | 188 | PluginService::GetInstance()->GetPlugins( |
| 189 | base::BindOnce(&PluginInfoHostImpl::PluginsLoaded, |
| 190 | weak_factory_.GetWeakPtr(), params, std::move(callback))); |
[email protected] | 8aa7a41 | 2011-11-07 12:33:42 | [diff] [blame] | 191 | } |
| 192 | |
Nicholas Verne | d391eae | 2017-11-13 02:41:38 | [diff] [blame] | 193 | void PluginInfoHostImpl::PluginsLoaded( |
[email protected] | 8aa7a41 | 2011-11-07 12:33:42 | [diff] [blame] | 194 | const GetPluginInfo_Params& params, |
Nicholas Verne | b5df4f7 | 2017-11-08 09:12:07 | [diff] [blame] | 195 | GetPluginInfoCallback callback, |
[email protected] | dfdfeb7 | 2012-06-08 11:29:02 | [diff] [blame] | 196 | const std::vector<WebPluginInfo>& plugins) { |
Nicholas Verne | b5df4f7 | 2017-11-08 09:12:07 | [diff] [blame] | 197 | chrome::mojom::PluginInfoPtr output = chrome::mojom::PluginInfo::New(); |
[email protected] | 79fa336 | 2012-03-28 16:21:11 | [diff] [blame] | 198 | // This also fills in |actual_mime_type|. |
dcheng | 4af4858 | 2016-04-19 00:29:35 | [diff] [blame] | 199 | std::unique_ptr<PluginMetadata> plugin_metadata; |
[email protected] | 60eca4eb | 2013-12-06 00:02:16 | [diff] [blame] | 200 | if (context_.FindEnabledPlugin(params.render_frame_id, params.url, |
tommycli | f2a1e9f | 2016-10-06 18:34:36 | [diff] [blame] | 201 | params.main_frame_origin, params.mime_type, |
waffles | 77255cc | 2016-08-02 17:25:12 | [diff] [blame] | 202 | &output->status, &output->plugin, |
| 203 | &output->actual_mime_type, &plugin_metadata)) { |
tommycli | e97656b8 | 2016-11-30 16:43:00 | [diff] [blame] | 204 | 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] | 79fa336 | 2012-03-28 16:21:11 | [diff] [blame] | 208 | } |
[email protected] | cd33d28 | 2012-09-21 12:53:04 | [diff] [blame] | 209 | |
Nicholas Verne | b5df4f7 | 2017-11-08 09:12:07 | [diff] [blame] | 210 | if (output->status == chrome::mojom::PluginStatus::kNotFound) { |
waffles | 77255cc | 2016-08-02 17:25:12 | [diff] [blame] | 211 | // Check to see if the component updater can fetch an implementation. |
Clark DuVall | 1df2052b | 2019-08-05 19:58:46 | [diff] [blame] | 212 | 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)); |
waffles | 77255cc | 2016-08-02 17:25:12 | [diff] [blame] | 218 | } else { |
Nicholas Verne | b5df4f7 | 2017-11-08 09:12:07 | [diff] [blame] | 219 | GetPluginInfoFinish(params, std::move(output), std::move(callback), |
| 220 | std::move(plugin_metadata)); |
wfh | be79ad5 | 2014-11-07 19:02:07 | [diff] [blame] | 221 | } |
[email protected] | 8aa7a41 | 2011-11-07 12:33:42 | [diff] [blame] | 222 | } |
| 223 | |
Nicholas Verne | d391eae | 2017-11-13 02:41:38 | [diff] [blame] | 224 | void PluginInfoHostImpl::Context::DecidePluginStatus( |
tommycli | e97656b8 | 2016-11-30 16:43:00 | [diff] [blame] | 225 | const GURL& url, |
| 226 | const url::Origin& main_frame_origin, |
[email protected] | 546abf3 | 2012-09-14 16:55:09 | [diff] [blame] | 227 | const WebPluginInfo& plugin, |
tommycli | e97656b8 | 2016-11-30 16:43:00 | [diff] [blame] | 228 | PluginMetadata::SecurityStatus security_status, |
| 229 | const std::string& plugin_identifier, |
Nicholas Verne | b5df4f7 | 2017-11-08 09:12:07 | [diff] [blame] | 230 | chrome::mojom::PluginStatus* status) const { |
tommycli | e97656b8 | 2016-11-30 16:43:00 | [diff] [blame] | 231 | if (security_status == PluginMetadata::SECURITY_STATUS_FULLY_TRUSTED) { |
Nicholas Verne | b5df4f7 | 2017-11-08 09:12:07 | [diff] [blame] | 232 | *status = chrome::mojom::PluginStatus::kAllowed; |
wfh | e53608b | 2016-04-07 02:18:53 | [diff] [blame] | 233 | return; |
| 234 | } |
| 235 | |
Tommy Li | 5c97af5d | 2020-10-13 23:21:05 | [diff] [blame] | 236 | // 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] | 8aa7a41 | 2011-11-07 12:33:42 | [diff] [blame] | 245 | ContentSetting plugin_setting = CONTENT_SETTING_DEFAULT; |
| 246 | bool uses_default_content_setting = true; |
[email protected] | 6a9d1deb | 2014-01-13 19:39:41 | [diff] [blame] | 247 | bool is_managed = false; |
tommycli | e86b298 | 2015-03-16 20:16:45 | [diff] [blame] | 248 | // Check plugin content settings. The primary URL is the top origin URL and |
| 249 | // the secondary URL is the plugin URL. |
raymes | 978301a2 | 2016-09-22 00:54:28 | [diff] [blame] | 250 | PluginUtils::GetPluginContentSetting( |
tommycli | e97656b8 | 2016-11-30 16:43:00 | [diff] [blame] | 251 | host_content_settings_map_, plugin, main_frame_origin, url, |
| 252 | plugin_identifier, &plugin_setting, &uses_default_content_setting, |
| 253 | &is_managed); |
tommycli | e2b1f1b | 2015-03-31 22:54:59 | [diff] [blame] | 254 | |
[email protected] | 8aa7a41 | 2011-11-07 12:33:42 | [diff] [blame] | 255 | DCHECK(plugin_setting != CONTENT_SETTING_DEFAULT); |
tommycli | e2b1f1b | 2015-03-31 22:54:59 | [diff] [blame] | 256 | DCHECK(plugin_setting != CONTENT_SETTING_ASK); |
[email protected] | 8aa7a41 | 2011-11-07 12:33:42 | [diff] [blame] | 257 | |
Nicholas Verne | b5df4f7 | 2017-11-08 09:12:07 | [diff] [blame] | 258 | if (*status == chrome::mojom::PluginStatus::kFlashHiddenPreferHtml) { |
tommycli | e97656b8 | 2016-11-30 16:43:00 | [diff] [blame] | 259 | if (plugin_setting == CONTENT_SETTING_BLOCK) { |
Tommy C. Li | 717a34a | 2019-03-28 16:24:51 | [diff] [blame] | 260 | *status = is_managed ? chrome::mojom::PluginStatus::kBlockedByPolicy |
| 261 | : chrome::mojom::PluginStatus::kBlockedNoLoading; |
tommycli | e97656b8 | 2016-11-30 16:43:00 | [diff] [blame] | 262 | } |
| 263 | return; |
| 264 | } |
| 265 | |
bauerb | ecab4f5 | 2017-03-13 20:16:41 | [diff] [blame] | 266 | #if BUILDFLAG(ENABLE_PLUGINS) |
tommycli | e86b298 | 2015-03-16 20:16:45 | [diff] [blame] | 267 | // Check if the plugin is outdated. |
tommycli | e97656b8 | 2016-11-30 16:43:00 | [diff] [blame] | 268 | if (security_status == PluginMetadata::SECURITY_STATUS_OUT_OF_DATE && |
[email protected] | 9f230ed | 2012-05-24 11:19:40 | [diff] [blame] | 269 | !allow_outdated_plugins_.GetValue()) { |
[email protected] | 8aa7a41 | 2011-11-07 12:33:42 | [diff] [blame] | 270 | if (allow_outdated_plugins_.IsManaged()) { |
Nicholas Verne | b5df4f7 | 2017-11-08 09:12:07 | [diff] [blame] | 271 | *status = chrome::mojom::PluginStatus::kOutdatedDisallowed; |
[email protected] | 8aa7a41 | 2011-11-07 12:33:42 | [diff] [blame] | 272 | } else { |
Nicholas Verne | b5df4f7 | 2017-11-08 09:12:07 | [diff] [blame] | 273 | *status = chrome::mojom::PluginStatus::kOutdatedBlocked; |
[email protected] | 8aa7a41 | 2011-11-07 12:33:42 | [diff] [blame] | 274 | } |
| 275 | return; |
| 276 | } |
bauerb | ecab4f5 | 2017-03-13 20:16:41 | [diff] [blame] | 277 | #endif // BUILDFLAG(ENABLE_PLUGINS) |
[email protected] | ef97ce34 | 2012-09-24 20:05:02 | [diff] [blame] | 278 | |
tommycli | e86b298 | 2015-03-16 20:16:45 | [diff] [blame] | 279 | // Check if the plugin is crashing too much. |
[email protected] | ef97ce34 | 2012-09-24 20:05:02 | [diff] [blame] | 280 | if (PluginService::GetInstance()->IsPluginUnstable(plugin.path) && |
Nicholas Verne | d391eae | 2017-11-13 02:41:38 | [diff] [blame] | 281 | plugin_setting != CONTENT_SETTING_BLOCK && uses_default_content_setting) { |
Nicholas Verne | b5df4f7 | 2017-11-08 09:12:07 | [diff] [blame] | 282 | *status = chrome::mojom::PluginStatus::kUnauthorized; |
[email protected] | ef97ce34 | 2012-09-24 20:05:02 | [diff] [blame] | 283 | return; |
| 284 | } |
[email protected] | 8aa7a41 | 2011-11-07 12:33:42 | [diff] [blame] | 285 | |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 286 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
Sadrul Habib Chowdhury | f43c33c | 2014-12-04 15:53:52 | [diff] [blame] | 287 | // 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. |
tommycli | e97656b8 | 2016-11-30 16:43:00 | [diff] [blame] | 290 | if (url.SchemeIs(extensions::kExtensionScheme) && !is_managed && |
lfg | 44c8a68f | 2015-04-16 16:38:15 | [diff] [blame] | 291 | plugin_setting == CONTENT_SETTING_BLOCK && |
tommycli | e97656b8 | 2016-11-30 16:43:00 | [diff] [blame] | 292 | IsPluginLoadingAccessibleResourceInWebView(extension_registry_, |
| 293 | render_process_id_, url)) { |
Sadrul Habib Chowdhury | f43c33c | 2014-12-04 15:53:52 | [diff] [blame] | 294 | plugin_setting = CONTENT_SETTING_ALLOW; |
| 295 | } |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 296 | #endif // BUILDFLAG(ENABLE_EXTENSIONS) |
Sadrul Habib Chowdhury | f43c33c | 2014-12-04 15:53:52 | [diff] [blame] | 297 | |
tommycli | 608ec89b | 2016-09-28 16:39:00 | [diff] [blame] | 298 | if (plugin_setting == CONTENT_SETTING_DETECT_IMPORTANT_CONTENT || |
| 299 | (plugin_setting == CONTENT_SETTING_ALLOW && |
Bernhard Bauer | 1919073 | 2017-09-28 09:03:33 | [diff] [blame] | 300 | !run_all_flash_in_allow_mode_.GetValue())) { |
Nicholas Verne | b5df4f7 | 2017-11-08 09:12:07 | [diff] [blame] | 301 | *status = chrome::mojom::PluginStatus::kPlayImportantContent; |
tommycli | e2b1f1b | 2015-03-31 22:54:59 | [diff] [blame] | 302 | } else if (plugin_setting == CONTENT_SETTING_BLOCK) { |
Tommy C. Li | 717a34a | 2019-03-28 16:24:51 | [diff] [blame] | 303 | *status = is_managed ? chrome::mojom::PluginStatus::kBlockedByPolicy |
| 304 | : chrome::mojom::PluginStatus::kBlocked; |
[email protected] | 6a9d1deb | 2014-01-13 19:39:41 | [diff] [blame] | 305 | } |
[email protected] | aea757d | 2013-09-27 22:27:38 | [diff] [blame] | 306 | |
brettw | 00899e6 | 2016-11-12 02:10:17 | [diff] [blame] | 307 | #if BUILDFLAG(ENABLE_EXTENSIONS) |
tommycli | 550b222 | 2015-09-03 21:06:10 | [diff] [blame] | 308 | // 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 Verne | b5df4f7 | 2017-11-08 09:12:07 | [diff] [blame] | 312 | if (*status == chrome::mojom::PluginStatus::kAllowed || |
| 313 | *status == chrome::mojom::PluginStatus::kBlocked || |
| 314 | *status == chrome::mojom::PluginStatus::kPlayImportantContent) { |
[email protected] | 140d6cd9 | 2014-08-12 18:26:46 | [diff] [blame] | 315 | if (extensions::WebViewRendererState::GetInstance()->IsGuest( |
tommycli | 550b222 | 2015-09-03 21:06:10 | [diff] [blame] | 316 | render_process_id_)) |
Nicholas Verne | b5df4f7 | 2017-11-08 09:12:07 | [diff] [blame] | 317 | *status = chrome::mojom::PluginStatus::kUnauthorized; |
[email protected] | aea757d | 2013-09-27 22:27:38 | [diff] [blame] | 318 | } |
tommycli | 550b222 | 2015-09-03 21:06:10 | [diff] [blame] | 319 | #endif |
[email protected] | 8aa7a41 | 2011-11-07 12:33:42 | [diff] [blame] | 320 | } |
| 321 | |
Nicholas Verne | d391eae | 2017-11-13 02:41:38 | [diff] [blame] | 322 | bool PluginInfoHostImpl::Context::FindEnabledPlugin( |
[email protected] | 60eca4eb | 2013-12-06 00:02:16 | [diff] [blame] | 323 | int render_frame_id, |
[email protected] | 8aa7a41 | 2011-11-07 12:33:42 | [diff] [blame] | 324 | const GURL& url, |
tommycli | f2a1e9f | 2016-10-06 18:34:36 | [diff] [blame] | 325 | const url::Origin& main_frame_origin, |
[email protected] | 8aa7a41 | 2011-11-07 12:33:42 | [diff] [blame] | 326 | const std::string& mime_type, |
Nicholas Verne | b5df4f7 | 2017-11-08 09:12:07 | [diff] [blame] | 327 | chrome::mojom::PluginStatus* status, |
[email protected] | dfdfeb7 | 2012-06-08 11:29:02 | [diff] [blame] | 328 | WebPluginInfo* plugin, |
[email protected] | 4da40567 | 2012-10-25 10:43:03 | [diff] [blame] | 329 | std::string* actual_mime_type, |
dcheng | 4af4858 | 2016-04-19 00:29:35 | [diff] [blame] | 330 | std::unique_ptr<PluginMetadata>* plugin_metadata) const { |
Nicholas Verne | b5df4f7 | 2017-11-08 09:12:07 | [diff] [blame] | 331 | *status = chrome::mojom::PluginStatus::kAllowed; |
bauerb | 96d29c0 | 2015-04-09 08:40:35 | [diff] [blame] | 332 | |
[email protected] | 8aa7a41 | 2011-11-07 12:33:42 | [diff] [blame] | 333 | bool allow_wildcard = true; |
[email protected] | dfdfeb7 | 2012-06-08 11:29:02 | [diff] [blame] | 334 | std::vector<WebPluginInfo> matching_plugins; |
[email protected] | 8aa7a41 | 2011-11-07 12:33:42 | [diff] [blame] | 335 | std::vector<std::string> mime_types; |
| 336 | PluginService::GetInstance()->GetPluginInfoArray( |
| 337 | url, mime_type, allow_wildcard, &matching_plugins, &mime_types); |
Nico Weber | eaa0841 | 2019-08-14 01:24:37 | [diff] [blame] | 338 | #if BUILDFLAG(GOOGLE_CHROME_BRANDING) |
Eugene Kim | 0b4b457 | 2018-09-01 02:37:58 | [diff] [blame] | 339 | base::EraseIf(matching_plugins, [&](const WebPluginInfo& info) { |
| 340 | return info.path.value() == ChromeContentClient::kNotPresent; |
| 341 | }); |
Nico Weber | eaa0841 | 2019-08-14 01:24:37 | [diff] [blame] | 342 | #endif // BUILDFLAG(GOOGLE_CHROME_BRANDING) |
[email protected] | 4da40567 | 2012-10-25 10:43:03 | [diff] [blame] | 343 | if (matching_plugins.empty()) { |
Nicholas Verne | b5df4f7 | 2017-11-08 09:12:07 | [diff] [blame] | 344 | *status = chrome::mojom::PluginStatus::kNotFound; |
[email protected] | 4da40567 | 2012-10-25 10:43:03 | [diff] [blame] | 345 | return false; |
| 346 | } |
| 347 | |
[email protected] | 3a5180ae | 2011-12-21 02:39:38 | [diff] [blame] | 348 | content::PluginServiceFilter* filter = |
| 349 | PluginService::GetInstance()->GetFilter(); |
[email protected] | 4da40567 | 2012-10-25 10:43:03 | [diff] [blame] | 350 | size_t i = 0; |
| 351 | for (; i < matching_plugins.size(); ++i) { |
Clark DuVall | 1df2052b | 2019-08-05 19:58:46 | [diff] [blame] | 352 | if (!filter || |
| 353 | filter->IsPluginAvailable(render_process_id_, render_frame_id, url, |
| 354 | main_frame_origin, &matching_plugins[i])) { |
[email protected] | 4da40567 | 2012-10-25 10:43:03 | [diff] [blame] | 355 | break; |
[email protected] | 8aa7a41 | 2011-11-07 12:33:42 | [diff] [blame] | 356 | } |
| 357 | } |
| 358 | |
tommycli | e86b298 | 2015-03-16 20:16:45 | [diff] [blame] | 359 | // If we broke out of the loop, we have found an enabled plugin. |
[email protected] | 4da40567 | 2012-10-25 10:43:03 | [diff] [blame] | 360 | bool enabled = i < matching_plugins.size(); |
| 361 | if (!enabled) { |
tommycli | e86b298 | 2015-03-16 20:16:45 | [diff] [blame] | 362 | // Otherwise, we only found disabled plugins, so we take the first one. |
[email protected] | 4da40567 | 2012-10-25 10:43:03 | [diff] [blame] | 363 | i = 0; |
Nicholas Verne | b5df4f7 | 2017-11-08 09:12:07 | [diff] [blame] | 364 | *status = chrome::mojom::PluginStatus::kDisabled; |
[email protected] | 4da40567 | 2012-10-25 10:43:03 | [diff] [blame] | 365 | } |
| 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] | 8aa7a41 | 2011-11-07 12:33:42 | [diff] [blame] | 373 | } |
| 374 | |
Nicholas Verne | d391eae | 2017-11-13 02:41:38 | [diff] [blame] | 375 | void PluginInfoHostImpl::ComponentPluginLookupDone( |
waffles | 77255cc | 2016-08-02 17:25:12 | [diff] [blame] | 376 | const GetPluginInfo_Params& params, |
Nicholas Verne | b5df4f7 | 2017-11-08 09:12:07 | [diff] [blame] | 377 | chrome::mojom::PluginInfoPtr output, |
| 378 | GetPluginInfoCallback callback, |
waffles | 77255cc | 2016-08-02 17:25:12 | [diff] [blame] | 379 | std::unique_ptr<PluginMetadata> plugin_metadata, |
waffles | 77255cc | 2016-08-02 17:25:12 | [diff] [blame] | 380 | std::unique_ptr<component_updater::ComponentInfo> cus_plugin_info) { |
| 381 | if (cus_plugin_info) { |
Nicholas Verne | b5df4f7 | 2017-11-08 09:12:07 | [diff] [blame] | 382 | output->status = chrome::mojom::PluginStatus::kComponentUpdateRequired; |
Sean McAllister | df80771 | 2020-08-13 23:19:09 | [diff] [blame] | 383 | #if defined(OS_LINUX) || defined(OS_CHROMEOS) |
waffles | e7759f7 | 2016-10-10 23:41:25 | [diff] [blame] | 384 | if (cus_plugin_info->version != base::Version("0")) { |
Nicholas Verne | b5df4f7 | 2017-11-08 09:12:07 | [diff] [blame] | 385 | output->status = chrome::mojom::PluginStatus::kRestartRequired; |
waffles | e7759f7 | 2016-10-10 23:41:25 | [diff] [blame] | 386 | } |
thestig | d6e43818 | 2017-06-01 23:16:27 | [diff] [blame] | 387 | #endif |
Tommy C. Li | 7c493d19 | 2019-03-28 21:50:26 | [diff] [blame] | 388 | // Component Updater wouldn't provide a deprecated plugin. |
| 389 | bool plugin_is_deprecated = false; |
Jeremy Roman | ec48d7a | 2018-03-01 17:35:09 | [diff] [blame] | 390 | plugin_metadata = std::make_unique<PluginMetadata>( |
waffles | 77255cc | 2016-08-02 17:25:12 | [diff] [blame] | 391 | cus_plugin_info->id, cus_plugin_info->name, false, GURL(), GURL(), |
Tommy C. Li | 7c493d19 | 2019-03-28 21:50:26 | [diff] [blame] | 392 | base::ASCIIToUTF16(cus_plugin_info->id), std::string(), |
| 393 | plugin_is_deprecated); |
waffles | 77255cc | 2016-08-02 17:25:12 | [diff] [blame] | 394 | } |
Nicholas Verne | b5df4f7 | 2017-11-08 09:12:07 | [diff] [blame] | 395 | GetPluginInfoFinish(params, std::move(output), std::move(callback), |
| 396 | std::move(plugin_metadata)); |
waffles | 77255cc | 2016-08-02 17:25:12 | [diff] [blame] | 397 | } |
| 398 | |
Nicholas Verne | d391eae | 2017-11-13 02:41:38 | [diff] [blame] | 399 | void PluginInfoHostImpl::GetPluginInfoFinish( |
waffles | 77255cc | 2016-08-02 17:25:12 | [diff] [blame] | 400 | const GetPluginInfo_Params& params, |
Nicholas Verne | b5df4f7 | 2017-11-08 09:12:07 | [diff] [blame] | 401 | chrome::mojom::PluginInfoPtr output, |
| 402 | GetPluginInfoCallback callback, |
| 403 | std::unique_ptr<PluginMetadata> plugin_metadata) { |
waffles | 77255cc | 2016-08-02 17:25:12 | [diff] [blame] | 404 | 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 Verne | b5df4f7 | 2017-11-08 09:12:07 | [diff] [blame] | 411 | std::move(callback).Run(std::move(output)); |
waffles | 77255cc | 2016-08-02 17:25:12 | [diff] [blame] | 412 | } |
| 413 | |
Nicholas Verne | d391eae | 2017-11-13 02:41:38 | [diff] [blame] | 414 | void PluginInfoHostImpl::Context::MaybeGrantAccess( |
Nicholas Verne | b5df4f7 | 2017-11-08 09:12:07 | [diff] [blame] | 415 | chrome::mojom::PluginStatus status, |
[email protected] | 650b2d5 | 2013-02-10 03:41:45 | [diff] [blame] | 416 | const base::FilePath& path) const { |
Nicholas Verne | b5df4f7 | 2017-11-08 09:12:07 | [diff] [blame] | 417 | if (status == chrome::mojom::PluginStatus::kAllowed || |
| 418 | status == chrome::mojom::PluginStatus::kPlayImportantContent) { |
[email protected] | 6be31d20 | 2013-02-01 18:20:54 | [diff] [blame] | 419 | ChromePluginServiceFilter::GetInstance()->AuthorizePlugin( |
| 420 | render_process_id_, path); |
| 421 | } |
| 422 | } |
| 423 | |
Nicholas Verne | d391eae | 2017-11-13 02:41:38 | [diff] [blame] | 424 | bool PluginInfoHostImpl::Context::IsPluginEnabled( |
[email protected] | 4cbbeb4 | 2014-07-22 19:29:38 | [diff] [blame] | 425 | const content::WebPluginInfo& plugin) const { |
| 426 | return plugin_prefs_->IsPluginEnabled(plugin); |
| 427 | } |