blob: 66854757a3a2bb4159350411b10ce4309f54dee1 [file] [log] [blame]
[email protected]03ef4b2a2012-03-06 15:04:201// Copyright (c) 2012 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
lgarron617a30f32017-03-24 21:42:075#include "chrome/browser/ui/page_info/page_info.h"
[email protected]03ef4b2a2012-03-06 15:04:206
avi655876a2015-12-25 07:18:157#include <stddef.h>
8#include <stdint.h>
9
Eric Lawrence6758d1d2017-11-21 16:06:0510#include <memory>
[email protected]03ef4b2a2012-03-06 15:04:2011#include <string>
Eric Lawrence6758d1d2017-11-21 16:06:0512#include <utility>
[email protected]03ef4b2a2012-03-06 15:04:2013#include <vector>
14
[email protected]eb2140c2013-07-29 12:37:3415#include "base/command_line.h"
[email protected]15b092542012-05-16 13:08:1416#include "base/i18n/time_formatting.h"
avi655876a2015-12-25 07:18:1517#include "base/macros.h"
[email protected]71cd5ef2014-08-13 21:22:0418#include "base/metrics/field_trial.h"
asvitkine75036032016-09-01 20:49:3419#include "base/metrics/histogram_macros.h"
Tommy Steimeldea90f72017-11-07 20:58:0320#include "base/metrics/user_metrics.h"
[email protected]3ea1b182013-02-08 22:38:4121#include "base/strings/string_number_conversions.h"
[email protected]774cc3c2013-06-07 20:26:4522#include "base/strings/utf_string_conversions.h"
[email protected]0b9fdd72012-04-04 10:00:3323#include "base/values.h"
jialiul02aad2d2015-04-01 18:56:0324#include "chrome/browser/browser_process.h"
[email protected]6b8a3c742014-07-25 00:25:3525#include "chrome/browser/browsing_data/browsing_data_channel_id_helper.h"
[email protected]b0cb5e82012-07-19 19:22:4726#include "chrome/browser/browsing_data/browsing_data_cookie_helper.h"
27#include "chrome/browser/browsing_data/browsing_data_database_helper.h"
28#include "chrome/browser/browsing_data/browsing_data_file_system_helper.h"
29#include "chrome/browser/browsing_data/browsing_data_indexed_db_helper.h"
30#include "chrome/browser/browsing_data/browsing_data_local_storage_helper.h"
peconn5100d432015-09-16 12:03:0831#include "chrome/browser/content_settings/host_content_settings_map_factory.h"
vabrbab3ffcb2016-10-04 10:08:1032#include "chrome/browser/content_settings/local_shared_objects_container.h"
[email protected]77a91c72012-08-13 16:19:3433#include "chrome/browser/history/history_service_factory.h"
palmerf2cba0d2015-08-27 23:15:0634#include "chrome/browser/infobars/infobar_service.h"
reillyg85f57db2016-01-12 23:14:3835#include "chrome/browser/permissions/chooser_context_base.h"
patricialor7131c1fe2017-04-07 01:25:5236#include "chrome/browser/permissions/permission_decision_auto_blocker.h"
patricialor2a4f41a2017-03-08 02:52:5637#include "chrome/browser/permissions/permission_manager.h"
38#include "chrome/browser/permissions/permission_result.h"
tsergeantf1e89352016-01-15 20:34:5439#include "chrome/browser/permissions/permission_uma_util.h"
40#include "chrome/browser/permissions/permission_util.h"
[email protected]03ef4b2a2012-03-06 15:04:2041#include "chrome/browser/profiles/profile.h"
Jialiu Lin11e18542017-08-14 18:16:2642#include "chrome/browser/safe_browsing/safe_browsing_service.h"
[email protected]71cd5ef2014-08-13 21:22:0443#include "chrome/browser/ssl/chrome_ssl_host_state_delegate.h"
44#include "chrome/browser/ssl/chrome_ssl_host_state_delegate_factory.h"
lgarron617a30f32017-03-24 21:42:0745#include "chrome/browser/ui/page_info/page_info_ui.h"
reillyg85f57db2016-01-12 23:14:3846#include "chrome/browser/usb/usb_chooser_context.h"
47#include "chrome/browser/usb/usb_chooser_context_factory.h"
Patricia Lora21a04cf2017-06-05 02:53:2948#include "chrome/common/chrome_features.h"
[email protected]71cd5ef2014-08-13 21:22:0449#include "chrome/common/chrome_switches.h"
jsbellddb849e2015-08-27 00:12:5650#include "chrome/common/url_constants.h"
reillyg85f57db2016-01-12 23:14:3851#include "chrome/grit/theme_resources.h"
Patti0601e532017-09-20 08:39:3052#include "components/content_settings/core/browser/content_settings_registry.h"
mukai8eaec822014-10-25 17:53:1653#include "components/content_settings/core/browser/content_settings_utils.h"
54#include "components/content_settings/core/browser/host_content_settings_map.h"
palmer0da10b32015-02-11 00:42:1955#include "components/content_settings/core/common/content_settings.h"
vasiliif62dbf92014-09-05 10:23:1356#include "components/content_settings/core/common/content_settings_pattern.h"
tbansal08a0e3e2017-06-30 21:30:0857#include "components/content_settings/core/common/content_settings_utils.h"
nzolghadrd87a308d2016-12-07 15:45:5658#include "components/rappor/public/rappor_utils.h"
59#include "components/rappor/rappor_service_impl.h"
felt2493b4452015-09-17 20:33:5960#include "components/ssl_errors/error_info.h"
thestig4a2e88e2016-08-27 23:23:5161#include "components/strings/grit/components_chromium_strings.h"
62#include "components/strings/grit/components_strings.h"
melandory7be36d312017-03-29 15:51:1263#include "components/subresource_filter/core/browser/subresource_filter_features.h"
palmer153af982015-09-15 02:04:1964#include "components/url_formatter/elide_url.h"
[email protected]0b9fdd72012-04-04 10:00:3365#include "content/public/browser/browser_thread.h"
[email protected]eb2140c2013-07-29 12:37:3466#include "content/public/common/content_switches.h"
[email protected]03ef4b2a2012-03-06 15:04:2067#include "content/public/common/url_constants.h"
[email protected]6e7845ae2013-03-29 21:48:1168#include "net/cert/cert_status_flags.h"
69#include "net/cert/x509_certificate.h"
[email protected]536fd0b2013-03-14 17:41:5770#include "net/ssl/ssl_cipher_suite_names.h"
71#include "net/ssl/ssl_connection_status_flags.h"
tfarina29a3a1742016-10-28 18:47:3372#include "third_party/boringssl/src/include/openssl/ssl.h"
[email protected]03ef4b2a2012-03-06 15:04:2073#include "ui/base/l10n/l10n_util.h"
Patricia Lora21a04cf2017-06-05 02:53:2974#include "url/origin.h"
[email protected]03ef4b2a2012-03-06 15:04:2075
[email protected]24a9f1c92013-11-13 12:33:3776#if defined(OS_CHROMEOS)
77#include "chrome/browser/chromeos/policy/policy_cert_service.h"
78#include "chrome/browser/chromeos/policy/policy_cert_service_factory.h"
79#endif
80
estade3feb83f2015-09-01 23:00:4981#if !defined(OS_ANDROID)
Christopher Lam0dbac2b2017-11-14 07:12:1082#include "chrome/browser/ui/browser_finder.h"
83#include "chrome/browser/ui/chrome_pages.h"
mgiucaa319f212016-01-14 03:30:1184#include "chrome/browser/ui/exclusive_access/exclusive_access_manager.h"
lgarron617a30f32017-03-24 21:42:0785#include "chrome/browser/ui/page_info/page_info_infobar_delegate.h"
estade3feb83f2015-09-01 23:00:4986#endif
87
Jialiu Lin11e18542017-08-14 18:16:2688#if defined(SAFE_BROWSING_DB_LOCAL)
Jialiu Lin0d8cc722017-09-19 01:01:5189#include "chrome/browser/safe_browsing/chrome_password_protection_service.h"
Jialiu Lin11e18542017-08-14 18:16:2690#endif
91
[email protected]ab6df3b12013-12-24 23:32:2692using base::ASCIIToUTF16;
93using base::UTF8ToUTF16;
[email protected]f729d7a2013-12-26 07:07:5694using base::UTF16ToUTF8;
[email protected]0b9fdd72012-04-04 10:00:3395using content::BrowserThread;
96
97namespace {
98
lgarron617a30f32017-03-24 21:42:0799// The list of content settings types to display on the Page Info UI. THE
csharrisonad1eaa6c2017-05-11 17:14:38100// ORDER OF THESE ITEMS IS IMPORTANT and comes from https://crbug.com/610358. To
101// propose changing it, email [email protected].
[email protected]0b9fdd72012-04-04 10:00:33102ContentSettingsType kPermissionType[] = {
sashab2b2a314f2015-01-17 06:42:21103 CONTENT_SETTINGS_TYPE_GEOLOCATION,
sashab2b2a314f2015-01-17 06:42:21104 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA,
105 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC,
palmer0da10b32015-02-11 00:42:19106 CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
palmer7715e332016-05-27 00:41:19107 CONTENT_SETTINGS_TYPE_JAVASCRIPT,
lshange085f202016-06-14 01:25:08108#if !defined(OS_ANDROID)
palmer7715e332016-05-27 00:41:19109 CONTENT_SETTINGS_TYPE_PLUGINS,
110 CONTENT_SETTINGS_TYPE_IMAGES,
lshange085f202016-06-14 01:25:08111#endif
palmer7715e332016-05-27 00:41:19112 CONTENT_SETTINGS_TYPE_POPUPS,
Charles Harrison239d47982017-06-13 02:42:31113 CONTENT_SETTINGS_TYPE_ADS,
nsatragno670fe922016-04-08 14:10:50114 CONTENT_SETTINGS_TYPE_BACKGROUND_SYNC,
Tommy Steimela8c3757e2017-08-24 00:15:46115 CONTENT_SETTINGS_TYPE_SOUND,
palmer7715e332016-05-27 00:41:19116 CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS,
finnur46cafd42016-09-22 10:27:17117 CONTENT_SETTINGS_TYPE_AUTOPLAY,
palmer7715e332016-05-27 00:41:19118 CONTENT_SETTINGS_TYPE_MIDI_SYSEX,
Gary Kacmarcik10533cf2017-11-22 03:31:28119 CONTENT_SETTINGS_TYPE_CLIPBOARD_READ,
[email protected]0b9fdd72012-04-04 10:00:33120};
121
Patti0601e532017-09-20 08:39:30122// Checks whether this permission is currently the factory default, as set by
123// Chrome. Specifically, that the following three conditions are true:
124// - The current active setting comes from the default or pref provider.
125// - The setting is the factory default setting (as opposed to a global
126// default setting set by the user).
127// - The setting is a wildcard setting applying to all origins (which can only
128// be set from the default provider).
129bool IsPermissionFactoryDefault(HostContentSettingsMap* content_settings,
130 const PageInfoUI::PermissionInfo& info) {
131 const ContentSetting factory_default_setting =
132 content_settings::ContentSettingsRegistry::GetInstance()
133 ->Get(info.type)
134 ->GetInitialDefaultSetting();
135 return (info.source == content_settings::SETTING_SOURCE_USER &&
136 factory_default_setting == info.default_setting &&
137 info.setting == CONTENT_SETTING_DEFAULT);
138}
139
lgarron617a30f32017-03-24 21:42:07140// Determines whether to show permission |type| in the Page Info UI. Only
mgiucaa319f212016-01-14 03:30:11141// applies to permissions listed in |kPermissionType|.
shahriar rostamia9c769d2017-12-06 04:54:08142bool ShouldShowPermission(
143 const PageInfoUI::PermissionInfo& info,
144 const GURL& site_url,
145 HostContentSettingsMap* content_settings,
146 content::WebContents* web_contents,
147 TabSpecificContentSettings* tab_specific_content_settings) {
Patti0601e532017-09-20 08:39:30148 // Note |CONTENT_SETTINGS_TYPE_ADS| will show up regardless of its default
149 // value when it has been activated on the current origin.
150 if (info.type == CONTENT_SETTINGS_TYPE_ADS) {
csharrisonad1eaa6c2017-05-11 17:14:38151 if (!base::FeatureList::IsEnabled(
152 subresource_filter::kSafeBrowsingSubresourceFilterExperimentalUI)) {
153 return false;
154 }
155
156 // The setting for subresource filtering should not show up if the site is
157 // not activated, both on android and desktop platforms.
158 return content_settings->GetWebsiteSetting(
Charles Harrison239d47982017-06-13 02:42:31159 site_url, GURL(), CONTENT_SETTINGS_TYPE_ADS_DATA, std::string(),
160 nullptr) != nullptr;
melandory7be36d312017-03-29 15:51:12161 }
162
Tommy Steimelc9f6c932017-10-13 23:33:04163 if (info.type == CONTENT_SETTINGS_TYPE_SOUND) {
164 if (!base::FeatureList::IsEnabled(features::kSoundContentSetting))
165 return false;
166
Tommy Steimel18360512017-11-01 00:38:19167 // The sound content setting should always show up when the tab has played
168 // audio.
169 if (web_contents && web_contents->WasEverAudible())
Tommy Steimelc9f6c932017-10-13 23:33:04170 return true;
171 }
172
Gary Kacmarcik10533cf2017-11-22 03:31:28173 if (info.type == CONTENT_SETTINGS_TYPE_CLIPBOARD_READ) {
174 if (!base::FeatureList::IsEnabled(features::kClipboardContentSetting))
175 return false;
176 }
177
Patti749d4d12017-10-11 06:20:30178#if defined(OS_ANDROID)
179 // Special geolocation DSE settings apply only on Android, so make sure it
180 // gets checked there regardless of default setting on Desktop.
181 if (info.type == CONTENT_SETTINGS_TYPE_GEOLOCATION)
182 return true;
Pattid7c4d542017-12-07 00:54:14183#else
Patti8c57f37d2018-01-31 04:33:21184 // Flash is shown if the user has ever changed its setting for |site_url|.
185 if (info.type == CONTENT_SETTINGS_TYPE_PLUGINS &&
186 content_settings->GetWebsiteSetting(site_url, site_url,
187 CONTENT_SETTINGS_TYPE_PLUGINS_DATA,
188 std::string(), nullptr) != nullptr) {
Pattid7c4d542017-12-07 00:54:14189 return true;
Patti8c57f37d2018-01-31 04:33:21190 }
Patti749d4d12017-10-11 06:20:30191#endif
192
Patti0601e532017-09-20 08:39:30193#if !defined(OS_ANDROID)
194 // Autoplay is Android-only at the moment.
195 if (info.type == CONTENT_SETTINGS_TYPE_AUTOPLAY)
196 return false;
197#endif
198
shahriar rostamia9c769d2017-12-06 04:54:08199 // Show the content setting if it has been changed by the user since the last
200 // page load.
201 if (tab_specific_content_settings->HasContentSettingChangedViaPageInfo(
202 info.type)) {
203 return true;
204 }
205
206 // Show the content setting when it has a non-default value.
207 if (!IsPermissionFactoryDefault(content_settings, info))
208 return true;
209
210 return false;
mgiucaa319f212016-01-14 03:30:11211}
212
esecklercac56b62016-11-16 13:49:44213void CheckContentStatus(security_state::ContentStatus content_status,
estark00e83f12016-08-19 18:24:04214 bool* displayed,
215 bool* ran) {
216 switch (content_status) {
esecklercac56b62016-11-16 13:49:44217 case security_state::CONTENT_STATUS_DISPLAYED:
estark00e83f12016-08-19 18:24:04218 *displayed = true;
219 break;
esecklercac56b62016-11-16 13:49:44220 case security_state::CONTENT_STATUS_RAN:
estark00e83f12016-08-19 18:24:04221 *ran = true;
222 break;
esecklercac56b62016-11-16 13:49:44223 case security_state::CONTENT_STATUS_DISPLAYED_AND_RAN:
estark00e83f12016-08-19 18:24:04224 *displayed = true;
225 *ran = true;
226 break;
esecklercac56b62016-11-16 13:49:44227 case security_state::CONTENT_STATUS_UNKNOWN:
228 case security_state::CONTENT_STATUS_NONE:
estark00e83f12016-08-19 18:24:04229 break;
230 }
231}
232
elawrenceb2ac2a232017-03-27 21:46:25233// If the |security_info| indicates that mixed content or certificate errors
234// were present, update |connection_status| and |connection_details|.
235void ReportAnyInsecureContent(const security_state::SecurityInfo& security_info,
thestig4427f13b2017-06-20 20:42:47236 PageInfo::SiteConnectionStatus* connection_status,
237 base::string16* connection_details) {
elawrenceb2ac2a232017-03-27 21:46:25238 bool displayed_insecure_content = false;
239 bool ran_insecure_content = false;
240 CheckContentStatus(security_info.mixed_content_status,
241 &displayed_insecure_content, &ran_insecure_content);
242 // Only note subresources with certificate errors if the main resource was
243 // loaded without major certificate errors. If the main resource had a
244 // certificate error, then it would not be that useful (and could
245 // potentially be confusing) to warn about subresources that had certificate
246 // errors too.
247 if (!net::IsCertStatusError(security_info.cert_status) ||
248 net::IsCertStatusMinorError(security_info.cert_status)) {
249 CheckContentStatus(security_info.content_with_cert_errors_status,
250 &displayed_insecure_content, &ran_insecure_content);
251 }
252
253 // Only one insecure content warning is displayed; show the most severe.
254 if (ran_insecure_content) {
thestig4427f13b2017-06-20 20:42:47255 *connection_status =
elawrenceb2ac2a232017-03-27 21:46:25256 PageInfo::SITE_CONNECTION_STATUS_INSECURE_ACTIVE_SUBRESOURCE;
thestig4427f13b2017-06-20 20:42:47257 connection_details->assign(l10n_util::GetStringFUTF16(
258 IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTED_SENTENCE_LINK, *connection_details,
elawrenceb2ac2a232017-03-27 21:46:25259 l10n_util::GetStringUTF16(
260 IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTED_INSECURE_CONTENT_ERROR)));
estark00e83f12016-08-19 18:24:04261 return;
262 }
elawrenceb2ac2a232017-03-27 21:46:25263 if (security_info.contained_mixed_form) {
thestig4427f13b2017-06-20 20:42:47264 *connection_status = PageInfo::SITE_CONNECTION_STATUS_INSECURE_FORM_ACTION;
265 connection_details->assign(l10n_util::GetStringFUTF16(
266 IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTED_SENTENCE_LINK, *connection_details,
elawrenceb2ac2a232017-03-27 21:46:25267 l10n_util::GetStringUTF16(
268 IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTED_INSECURE_FORM_WARNING)));
269 return;
270 }
271 if (displayed_insecure_content) {
thestig4427f13b2017-06-20 20:42:47272 *connection_status =
elawrenceb2ac2a232017-03-27 21:46:25273 PageInfo::SITE_CONNECTION_STATUS_INSECURE_PASSIVE_SUBRESOURCE;
thestig4427f13b2017-06-20 20:42:47274 connection_details->assign(l10n_util::GetStringFUTF16(
275 IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTED_SENTENCE_LINK, *connection_details,
elawrenceb2ac2a232017-03-27 21:46:25276 l10n_util::GetStringUTF16(
277 IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTED_INSECURE_CONTENT_WARNING)));
278 }
estark00e83f12016-08-19 18:24:04279}
280
estarkfcfccdb82016-11-14 02:17:29281void GetSiteIdentityByMaliciousContentStatus(
esecklercac56b62016-11-16 13:49:44282 security_state::MaliciousContentStatus malicious_content_status,
lgarron617a30f32017-03-24 21:42:07283 PageInfo::SiteIdentityStatus* status,
estarkfcfccdb82016-11-14 02:17:29284 base::string16* details) {
285 switch (malicious_content_status) {
esecklercac56b62016-11-16 13:49:44286 case security_state::MALICIOUS_CONTENT_STATUS_NONE:
estarkfcfccdb82016-11-14 02:17:29287 NOTREACHED();
288 break;
esecklercac56b62016-11-16 13:49:44289 case security_state::MALICIOUS_CONTENT_STATUS_MALWARE:
lgarron617a30f32017-03-24 21:42:07290 *status = PageInfo::SITE_IDENTITY_STATUS_MALWARE;
lgarronfc1d5e52017-05-03 23:15:21291 *details = l10n_util::GetStringUTF16(IDS_PAGE_INFO_MALWARE_DETAILS);
estarkfcfccdb82016-11-14 02:17:29292 break;
esecklercac56b62016-11-16 13:49:44293 case security_state::MALICIOUS_CONTENT_STATUS_SOCIAL_ENGINEERING:
lgarron617a30f32017-03-24 21:42:07294 *status = PageInfo::SITE_IDENTITY_STATUS_SOCIAL_ENGINEERING;
lgarron1a6300d2017-03-18 03:33:04295 *details =
lgarronfc1d5e52017-05-03 23:15:21296 l10n_util::GetStringUTF16(IDS_PAGE_INFO_SOCIAL_ENGINEERING_DETAILS);
estarkfcfccdb82016-11-14 02:17:29297 break;
esecklercac56b62016-11-16 13:49:44298 case security_state::MALICIOUS_CONTENT_STATUS_UNWANTED_SOFTWARE:
lgarron617a30f32017-03-24 21:42:07299 *status = PageInfo::SITE_IDENTITY_STATUS_UNWANTED_SOFTWARE;
lgarron1a6300d2017-03-18 03:33:04300 *details =
lgarronfc1d5e52017-05-03 23:15:21301 l10n_util::GetStringUTF16(IDS_PAGE_INFO_UNWANTED_SOFTWARE_DETAILS);
estarkfcfccdb82016-11-14 02:17:29302 break;
Jialiu Lin11e18542017-08-14 18:16:26303 case security_state::MALICIOUS_CONTENT_STATUS_PASSWORD_REUSE:
Jialiu Linfeb6bb32017-08-30 00:21:36304#if defined(SAFE_BROWSING_DB_LOCAL)
Jialiu Lin11e18542017-08-14 18:16:26305 *status = PageInfo::SITE_IDENTITY_STATUS_PASSWORD_REUSE;
306 *details =
307 l10n_util::GetStringUTF16(IDS_PAGE_INFO_CHANGE_PASSWORD_DETAILS);
308#endif
309 break;
estarkfcfccdb82016-11-14 02:17:29310 }
311}
312
jshin1fb76462016-04-05 22:13:03313base::string16 GetSimpleSiteName(const GURL& url) {
benwells2337b8102016-04-20 01:53:53314 return url_formatter::FormatUrlForSecurityDisplay(
315 url, url_formatter::SchemeDisplay::OMIT_HTTP_AND_HTTPS);
palmer153af982015-09-15 02:04:19316}
317
reillyg85f57db2016-01-12 23:14:38318ChooserContextBase* GetUsbChooserContext(Profile* profile) {
319 return UsbChooserContextFactory::GetForProfile(profile);
320}
321
322// The list of chooser types that need to display entries in the Website
323// Settings UI. THE ORDER OF THESE ITEMS IS IMPORTANT. To propose changing it,
324// email [email protected].
Andrew Grieved1978b0e2017-07-28 15:53:41325const PageInfo::ChooserUIInfo kChooserUIInfo[] = {
reillyg58f82ab2016-08-03 01:49:52326 {CONTENT_SETTINGS_TYPE_USB_CHOOSER_DATA, &GetUsbChooserContext,
Patti1d8a4312018-01-19 06:36:11327 IDS_PAGE_INFO_USB_DEVICE_LABEL, IDS_PAGE_INFO_USB_DEVICE_SECONDARY_LABEL,
328 IDS_PAGE_INFO_DELETE_USB_DEVICE, "name"},
reillyg85f57db2016-01-12 23:14:38329};
330
[email protected]0b9fdd72012-04-04 10:00:33331} // namespace
332
lgarron617a30f32017-03-24 21:42:07333PageInfo::PageInfo(PageInfoUI* ui,
334 Profile* profile,
335 TabSpecificContentSettings* tab_specific_content_settings,
336 content::WebContents* web_contents,
337 const GURL& url,
338 const security_state::SecurityInfo& security_info)
[email protected]df818272012-04-20 13:10:50339 : TabSpecificContentSettings::SiteDataObserver(
340 tab_specific_content_settings),
dominicknbdd53b5f2016-09-28 01:08:13341 content::WebContentsObserver(web_contents),
[email protected]df818272012-04-20 13:10:50342 ui_(ui),
[email protected]66f157312012-08-01 13:50:26343 show_info_bar_(false),
[email protected]0b9fdd72012-04-04 10:00:33344 site_url_(url),
345 site_identity_status_(SITE_IDENTITY_STATUS_UNKNOWN),
[email protected]03ef4b2a2012-03-06 15:04:20346 site_connection_status_(SITE_CONNECTION_STATUS_UNKNOWN),
alshabalin5e894c12016-10-25 06:47:46347 show_ssl_decision_revoke_button_(false),
peconn5100d432015-09-16 12:03:08348 content_settings_(HostContentSettingsMapFactory::GetForProfile(profile)),
[email protected]71cd5ef2014-08-13 21:22:04349 chrome_ssl_host_state_delegate_(
jww1ed8ea72014-09-02 20:43:25350 ChromeSSLHostStateDelegateFactory::GetForProfile(profile)),
palmer153af982015-09-15 02:04:19351 did_revoke_user_ssl_decisions_(false),
estark8d67cd7a2016-10-24 05:06:41352 profile_(profile),
Jialiu Lin11e18542017-08-14 18:16:26353 security_level_(security_state::NONE),
Jialiu Linfeb6bb32017-08-30 00:21:36354#if defined(SAFE_BROWSING_DB_LOCAL)
Jialiu Lin0d8cc722017-09-19 01:01:51355 password_protection_service_(
356 safe_browsing::ChromePasswordProtectionService::
357 GetPasswordProtectionService(profile_)),
Jialiu Lin11e18542017-08-14 18:16:26358#endif
359 show_change_password_buttons_(false) {
estarka3121f6b2015-09-18 21:15:59360 Init(url, security_info);
[email protected]0b9fdd72012-04-04 10:00:33361
362 PresentSitePermissions();
[email protected]24c8818c2012-04-25 09:57:41363 PresentSiteIdentity();
Pattie8c616202017-09-29 07:58:03364 PresentSiteData();
[email protected]e22d64f2012-09-10 09:03:23365
lgarron617a30f32017-03-24 21:42:07366 // Every time the Page Info UI is opened a |PageInfo| object is
367 // created. So this counts how ofter the Page Info UI is opened.
368 RecordPageInfoAction(PAGE_INFO_OPENED);
[email protected]03ef4b2a2012-03-06 15:04:20369}
370
Carlos ILe5dfda72017-09-21 02:33:05371PageInfo::~PageInfo() {
372 // Check if Re-enable warnings button was visible, if so, log on UMA whether
373 // it was clicked or not.
374 SSLCertificateDecisionsDidRevoke user_decision =
375 did_revoke_user_ssl_decisions_ ? USER_CERT_DECISIONS_REVOKED
376 : USER_CERT_DECISIONS_NOT_REVOKED;
377 if (show_ssl_decision_revoke_button_) {
378 UMA_HISTOGRAM_ENUMERATION("interstitial.ssl.did_user_revoke_decisions2",
379 user_decision,
380 END_OF_SSL_CERTIFICATE_DECISIONS_DID_REVOKE_ENUM);
381 }
382}
[email protected]03ef4b2a2012-03-06 15:04:20383
lgarron617a30f32017-03-24 21:42:07384void PageInfo::RecordPageInfoAction(PageInfoAction action) {
385 UMA_HISTOGRAM_ENUMERATION("WebsiteSettings.Action", action, PAGE_INFO_COUNT);
lgarron04a93502014-11-04 22:25:04386
estark8d67cd7a2016-10-24 05:06:41387 std::string histogram_name;
estark8d67cd7a2016-10-24 05:06:41388 if (site_url_.SchemeIsCryptographic()) {
Carlos ILcb2321112018-02-01 18:05:23389 if (security_level_ == security_state::SECURE) {
390 UMA_HISTOGRAM_ENUMERATION("Security.PageInfo.Action.HttpsUrl.ValidNonEV",
391 action, PAGE_INFO_COUNT);
392 } else if (security_level_ == security_state::EV_SECURE) {
393 UMA_HISTOGRAM_ENUMERATION("Security.PageInfo.Action.HttpsUrl.ValidEV",
lgarron617a30f32017-03-24 21:42:07394 action, PAGE_INFO_COUNT);
esecklercac56b62016-11-16 13:49:44395 } else if (security_level_ == security_state::NONE) {
estark8d67cd7a2016-10-24 05:06:41396 UMA_HISTOGRAM_ENUMERATION("Security.PageInfo.Action.HttpsUrl.Downgraded",
lgarron617a30f32017-03-24 21:42:07397 action, PAGE_INFO_COUNT);
esecklercac56b62016-11-16 13:49:44398 } else if (security_level_ == security_state::DANGEROUS) {
estark8d67cd7a2016-10-24 05:06:41399 UMA_HISTOGRAM_ENUMERATION("Security.PageInfo.Action.HttpsUrl.Dangerous",
lgarron617a30f32017-03-24 21:42:07400 action, PAGE_INFO_COUNT);
estark8d67cd7a2016-10-24 05:06:41401 }
402 return;
403 }
404
esecklercac56b62016-11-16 13:49:44405 if (security_level_ == security_state::HTTP_SHOW_WARNING) {
estark8d67cd7a2016-10-24 05:06:41406 UMA_HISTOGRAM_ENUMERATION("Security.PageInfo.Action.HttpUrl.Warning",
lgarron617a30f32017-03-24 21:42:07407 action, PAGE_INFO_COUNT);
esecklercac56b62016-11-16 13:49:44408 } else if (security_level_ == security_state::DANGEROUS) {
estark8d67cd7a2016-10-24 05:06:41409 UMA_HISTOGRAM_ENUMERATION("Security.PageInfo.Action.HttpUrl.Dangerous",
lgarron617a30f32017-03-24 21:42:07410 action, PAGE_INFO_COUNT);
estark8d67cd7a2016-10-24 05:06:41411 } else {
412 UMA_HISTOGRAM_ENUMERATION("Security.PageInfo.Action.HttpUrl.Neutral",
lgarron617a30f32017-03-24 21:42:07413 action, PAGE_INFO_COUNT);
lgarron04a93502014-11-04 22:25:04414 }
415}
416
lgarron617a30f32017-03-24 21:42:07417void PageInfo::OnSitePermissionChanged(ContentSettingsType type,
418 ContentSetting setting) {
shahriar rostamia9c769d2017-12-06 04:54:08419 tab_specific_content_settings()->ContentSettingChangedViaPageInfo(type);
420
[email protected]e22d64f2012-09-10 09:03:23421 // Count how often a permission for a specific content type is changed using
lgarron617a30f32017-03-24 21:42:07422 // the Page Info UI.
raymes4a13d432015-09-08 00:44:07423 size_t num_values;
424 int histogram_value = ContentSettingTypeToHistogramValue(type, &num_values);
dchengf6f4e4942017-03-30 23:55:57425 UMA_HISTOGRAM_EXACT_LINEAR("WebsiteSettings.OriginInfo.PermissionChanged",
426 histogram_value, num_values);
sashab9debecd2014-12-18 04:15:56427
428 if (setting == ContentSetting::CONTENT_SETTING_ALLOW) {
dchengf6f4e4942017-03-30 23:55:57429 UMA_HISTOGRAM_EXACT_LINEAR(
sashab9debecd2014-12-18 04:15:56430 "WebsiteSettings.OriginInfo.PermissionChanged.Allowed", histogram_value,
raymes4a13d432015-09-08 00:44:07431 num_values);
tommycli34cf29bf2016-09-08 05:46:25432
433 if (type == CONTENT_SETTINGS_TYPE_PLUGINS) {
434 rappor::SampleDomainAndRegistryFromGURL(
435 g_browser_process->rappor_service(),
436 "ContentSettings.Plugins.AddedAllowException", site_url_);
437 }
sashab9debecd2014-12-18 04:15:56438 } else if (setting == ContentSetting::CONTENT_SETTING_BLOCK) {
dchengf6f4e4942017-03-30 23:55:57439 UMA_HISTOGRAM_EXACT_LINEAR(
sashab9debecd2014-12-18 04:15:56440 "WebsiteSettings.OriginInfo.PermissionChanged.Blocked", histogram_value,
raymes4a13d432015-09-08 00:44:07441 num_values);
sashab9debecd2014-12-18 04:15:56442 }
[email protected]e22d64f2012-09-10 09:03:23443
lgarron04a93502014-11-04 22:25:04444 // This is technically redundant given the histogram above, but putting the
445 // total count of permission changes in another histogram makes it easier to
lgarron026e9c42017-04-07 20:09:31446 // compare it against other kinds of actions in Page Info.
lgarron617a30f32017-03-24 21:42:07447 RecordPageInfoAction(PAGE_INFO_CHANGED_PERMISSION);
Tommy Steimeldea90f72017-11-07 20:58:03448 if (type == CONTENT_SETTINGS_TYPE_SOUND) {
449 ContentSetting default_setting =
450 content_settings_->GetDefaultContentSetting(CONTENT_SETTINGS_TYPE_SOUND,
451 nullptr);
452 bool mute = (setting == CONTENT_SETTING_BLOCK) ||
453 (setting == CONTENT_SETTING_DEFAULT &&
454 default_setting == CONTENT_SETTING_BLOCK);
455 if (mute) {
456 base::RecordAction(
457 base::UserMetricsAction("SoundContentSetting.MuteBy.PageInfo"));
458 } else {
459 base::RecordAction(
460 base::UserMetricsAction("SoundContentSetting.UnmuteBy.PageInfo"));
461 }
462 }
lgarron04a93502014-11-04 22:25:04463
stefanocs8b3490cc2016-07-28 05:32:52464 PermissionUtil::ScopedRevocationReporter scoped_revocation_reporter(
patricialor7131c1fe2017-04-07 01:25:52465 profile_, site_url_, site_url_, type, PermissionSourceUI::OIB);
stefanocs8b3490cc2016-07-28 05:32:52466
patricialor7131c1fe2017-04-07 01:25:52467 // The permission may have been blocked due to being under embargo, so if it
468 // was changed away from BLOCK, clear embargo status if it exists.
469 if (setting != CONTENT_SETTING_BLOCK) {
470 PermissionDecisionAutoBlocker::GetForProfile(profile_)->RemoveEmbargoByUrl(
471 site_url_, type);
472 }
raymesfbaaaaa2015-11-10 02:20:40473 content_settings_->SetNarrowestContentSetting(site_url_, site_url_, type,
474 setting);
[email protected]df818272012-04-20 13:10:50475
Tommy Steimel97ee2f82017-11-01 21:39:52476 // When the sound setting is changed, no reload is necessary.
477 if (type != CONTENT_SETTINGS_TYPE_SOUND)
478 show_info_bar_ = true;
[email protected]2f45d542012-08-22 08:47:24479
480 // Refresh the UI to reflect the new setting.
481 PresentSitePermissions();
[email protected]df818272012-04-20 13:10:50482}
483
lgarron617a30f32017-03-24 21:42:07484void PageInfo::OnSiteChosenObjectDeleted(const ChooserUIInfo& ui_info,
485 const base::DictionaryValue& object) {
reillyg85f57db2016-01-12 23:14:38486 // TODO(reillyg): Create metrics for revocations. crbug.com/556845
487 ChooserContextBase* context = ui_info.get_context(profile_);
reillyg36a7fab32016-01-28 19:15:10488 const GURL origin = site_url_.GetOrigin();
489 context->RevokeObjectPermission(origin, origin, object);
reillyg85f57db2016-01-12 23:14:38490 show_info_bar_ = true;
491
492 // Refresh the UI to reflect the changed settings.
493 PresentSitePermissions();
494}
495
lgarron617a30f32017-03-24 21:42:07496void PageInfo::OnSiteDataAccessed() {
[email protected]df818272012-04-20 13:10:50497 PresentSiteData();
[email protected]0b9fdd72012-04-04 10:00:33498}
499
lgarron617a30f32017-03-24 21:42:07500void PageInfo::OnUIClosing() {
estade3feb83f2015-09-01 23:00:49501#if defined(OS_ANDROID)
502 NOTREACHED();
503#else
dominicknbdd53b5f2016-09-28 01:08:13504 if (show_info_bar_ && web_contents() && !web_contents()->IsBeingDestroyed()) {
palmerf2cba0d2015-08-27 23:15:06505 InfoBarService* infobar_service =
dominicknbdd53b5f2016-09-28 01:08:13506 InfoBarService::FromWebContents(web_contents());
palmerf2cba0d2015-08-27 23:15:06507 if (infobar_service)
lgarron617a30f32017-03-24 21:42:07508 PageInfoInfoBarDelegate::Create(infobar_service);
palmerf2cba0d2015-08-27 23:15:06509 }
estade3feb83f2015-09-01 23:00:49510#endif
jww1ed8ea72014-09-02 20:43:25511}
512
lgarron617a30f32017-03-24 21:42:07513void PageInfo::OnRevokeSSLErrorBypassButtonPressed() {
jww1ed8ea72014-09-02 20:43:25514 DCHECK(chrome_ssl_host_state_delegate_);
jww6a55df72014-09-05 19:59:29515 chrome_ssl_host_state_delegate_->RevokeUserAllowExceptionsHard(
516 site_url().host());
jww1ed8ea72014-09-02 20:43:25517 did_revoke_user_ssl_decisions_ = true;
[email protected]66f157312012-08-01 13:50:26518}
519
Patricia Lora21a04cf2017-06-05 02:53:29520void PageInfo::OpenSiteSettingsView() {
Christopher Lam0dbac2b2017-11-14 07:12:10521#if defined(OS_ANDROID)
522 NOTREACHED();
523#else
524 chrome::ShowSiteSettings(chrome::FindBrowserWithWebContents(web_contents()),
525 site_url());
Patricia Lora21a04cf2017-06-05 02:53:29526 RecordPageInfoAction(PageInfo::PAGE_INFO_SITE_SETTINGS_OPENED);
Christopher Lam0dbac2b2017-11-14 07:12:10527#endif
Patricia Lora21a04cf2017-06-05 02:53:29528}
529
Jialiu Lin11e18542017-08-14 18:16:26530void PageInfo::OnChangePasswordButtonPressed(
531 content::WebContents* web_contents) {
Jialiu Linfeb6bb32017-08-30 00:21:36532#if defined(SAFE_BROWSING_DB_LOCAL)
Jialiu Lin11e18542017-08-14 18:16:26533 DCHECK(password_protection_service_);
Jialiu Lin3fc7f38f2017-09-21 18:38:37534 password_protection_service_->OnUserAction(
Jialiu Lin11e18542017-08-14 18:16:26535 web_contents, safe_browsing::PasswordProtectionService::PAGE_INFO,
536 safe_browsing::PasswordProtectionService::CHANGE_PASSWORD);
537#endif
538}
539
540void PageInfo::OnWhitelistPasswordReuseButtonPressed(
541 content::WebContents* web_contents) {
Jialiu Linfeb6bb32017-08-30 00:21:36542#if defined(SAFE_BROWSING_DB_LOCAL)
Jialiu Lin11e18542017-08-14 18:16:26543 DCHECK(password_protection_service_);
Jialiu Lin3fc7f38f2017-09-21 18:38:37544 password_protection_service_->OnUserAction(
Jialiu Lin11e18542017-08-14 18:16:26545 web_contents, safe_browsing::PasswordProtectionService::PAGE_INFO,
546 safe_browsing::PasswordProtectionService::MARK_AS_LEGITIMATE);
547#endif
548}
549
lgarron617a30f32017-03-24 21:42:07550void PageInfo::Init(const GURL& url,
551 const security_state::SecurityInfo& security_info) {
thestig0c55ee32017-06-20 22:17:51552#if !defined(OS_ANDROID)
meacerde53fcff2016-10-12 19:21:57553 // On desktop, internal URLs aren't handled by this class. Instead, a
lgarron026e9c42017-04-07 20:09:31554 // custom and simpler bubble is shown.
meacerde53fcff2016-10-12 19:21:57555 DCHECK(!url.SchemeIs(content::kChromeUIScheme) &&
556 !url.SchemeIs(content::kChromeDevToolsScheme) &&
557 !url.SchemeIs(content::kViewSourceScheme) &&
558 !url.SchemeIs(content_settings::kExtensionScheme));
559#endif
560
thestig0c55ee32017-06-20 22:17:51561 bool is_chrome_ui_native_scheme = false;
zpengdb4a58e2017-01-10 17:40:32562#if defined(OS_ANDROID)
thestig0c55ee32017-06-20 22:17:51563 is_chrome_ui_native_scheme = url.SchemeIs(chrome::kChromeUINativeScheme);
sashab97894ce2014-10-22 10:08:33564#endif
565
estark8d67cd7a2016-10-24 05:06:41566 security_level_ = security_info.security_level;
567
upendrag.gowda60886a6e2015-10-31 05:51:09568 if (url.SchemeIs(url::kAboutScheme)) {
569 // All about: URLs except about:blank are redirected.
570 DCHECK_EQ(url::kAboutBlankURL, url.spec());
571 site_identity_status_ = SITE_IDENTITY_STATUS_NO_CERT;
572 site_identity_details_ =
573 l10n_util::GetStringUTF16(IDS_PAGE_INFO_SECURITY_TAB_INSECURE_IDENTITY);
574 site_connection_status_ = SITE_CONNECTION_STATUS_UNENCRYPTED;
575 site_connection_details_ = l10n_util::GetStringFUTF16(
576 IDS_PAGE_INFO_SECURITY_TAB_NOT_ENCRYPTED_CONNECTION_TEXT,
577 UTF8ToUTF16(url.spec()));
578 return;
579 }
580
thestig0c55ee32017-06-20 22:17:51581 if (url.SchemeIs(content::kChromeUIScheme) || is_chrome_ui_native_scheme) {
[email protected]03ef4b2a2012-03-06 15:04:20582 site_identity_status_ = SITE_IDENTITY_STATUS_INTERNAL_PAGE;
583 site_identity_details_ =
584 l10n_util::GetStringUTF16(IDS_PAGE_INFO_INTERNAL_PAGE);
585 site_connection_status_ = SITE_CONNECTION_STATUS_INTERNAL_PAGE;
586 return;
587 }
588
[email protected]03ef4b2a2012-03-06 15:04:20589 // Identity section.
jam8ae7cad2016-09-08 23:55:21590 certificate_ = security_info.certificate;
[email protected]f61c1ce2012-05-09 13:55:11591
estarkfcfccdb82016-11-14 02:17:29592 if (security_info.malicious_content_status !=
esecklercac56b62016-11-16 13:49:44593 security_state::MALICIOUS_CONTENT_STATUS_NONE) {
estarkfcfccdb82016-11-14 02:17:29594 // The site has been flagged by Safe Browsing as dangerous.
595 GetSiteIdentityByMaliciousContentStatus(
596 security_info.malicious_content_status, &site_identity_status_,
597 &site_identity_details_);
Jialiu Lin11e18542017-08-14 18:16:26598 show_change_password_buttons_ =
599 security_info.malicious_content_status ==
600 security_state::MALICIOUS_CONTENT_STATUS_PASSWORD_REUSE;
estarkfcfccdb82016-11-14 02:17:29601 } else if (certificate_ &&
602 (!net::IsCertStatusError(security_info.cert_status) ||
603 net::IsCertStatusMinorError(security_info.cert_status))) {
604 // HTTPS with no or minor errors.
estarka3121f6b2015-09-18 21:15:59605 if (security_info.security_level ==
esecklercac56b62016-11-16 13:49:44606 security_state::SECURE_WITH_POLICY_INSTALLED_CERT) {
Eric Lawrence6758d1d2017-11-21 16:06:05607#if defined(OS_CHROMEOS)
[email protected]eaf3f322013-04-25 21:53:59608 site_identity_status_ = SITE_IDENTITY_STATUS_ADMIN_PROVIDED_CERT;
[email protected]24a9f1c92013-11-13 12:33:37609 site_identity_details_ = l10n_util::GetStringFUTF16(
610 IDS_CERT_POLICY_PROVIDED_CERT_MESSAGE, UTF8ToUTF16(url.host()));
Eric Lawrence6758d1d2017-11-21 16:06:05611#else
612 DCHECK(false) << "Policy certificates exist only on ChromeOS";
613#endif
estarka3121f6b2015-09-18 21:15:59614 } else if (net::IsCertStatusMinorError(security_info.cert_status)) {
[email protected]03ef4b2a2012-03-06 15:04:20615 site_identity_status_ = SITE_IDENTITY_STATUS_CERT_REVOCATION_UNKNOWN;
jam8ae7cad2016-09-08 23:55:21616 base::string16 issuer_name(
617 UTF8ToUTF16(certificate_->issuer().GetDisplayName()));
[email protected]03ef4b2a2012-03-06 15:04:20618 if (issuer_name.empty()) {
619 issuer_name.assign(l10n_util::GetStringUTF16(
620 IDS_PAGE_INFO_SECURITY_TAB_UNKNOWN_PARTY));
621 }
[email protected]94c74b42013-12-02 15:19:49622
[email protected]03ef4b2a2012-03-06 15:04:20623 site_identity_details_.assign(l10n_util::GetStringFUTF16(
estarkcf305562016-11-15 03:45:39624 IDS_PAGE_INFO_SECURITY_TAB_SECURE_IDENTITY_VERIFIED, issuer_name));
[email protected]03ef4b2a2012-03-06 15:04:20625
626 site_identity_details_ += ASCIIToUTF16("\n\n");
estarka3121f6b2015-09-18 21:15:59627 if (security_info.cert_status &
628 net::CERT_STATUS_UNABLE_TO_CHECK_REVOCATION) {
[email protected]03ef4b2a2012-03-06 15:04:20629 site_identity_details_ += l10n_util::GetStringUTF16(
630 IDS_PAGE_INFO_SECURITY_TAB_UNABLE_TO_CHECK_REVOCATION);
estarka3121f6b2015-09-18 21:15:59631 } else if (security_info.cert_status &
632 net::CERT_STATUS_NO_REVOCATION_MECHANISM) {
[email protected]03ef4b2a2012-03-06 15:04:20633 site_identity_details_ += l10n_util::GetStringUTF16(
634 IDS_PAGE_INFO_SECURITY_TAB_NO_REVOCATION_MECHANISM);
635 } else {
636 NOTREACHED() << "Need to specify string for this warning";
637 }
[email protected]03ef4b2a2012-03-06 15:04:20638 } else {
estarkcf305562016-11-15 03:45:39639 // No major or minor errors.
estarka3121f6b2015-09-18 21:15:59640 if (security_info.cert_status & net::CERT_STATUS_IS_EV) {
rsleevi4f8012722014-09-30 01:28:01641 // EV HTTPS page.
estarkcf305562016-11-15 03:45:39642 site_identity_status_ = SITE_IDENTITY_STATUS_EV_CERT;
jam8ae7cad2016-09-08 23:55:21643 DCHECK(!certificate_->subject().organization_names.empty());
644 organization_name_ =
645 UTF8ToUTF16(certificate_->subject().organization_names[0]);
rsleevi4f8012722014-09-30 01:28:01646 // An EV Cert is required to have a city (localityName) and country but
647 // state is "if any".
jam8ae7cad2016-09-08 23:55:21648 DCHECK(!certificate_->subject().locality_name.empty());
649 DCHECK(!certificate_->subject().country_name.empty());
rsleevi4f8012722014-09-30 01:28:01650 base::string16 locality;
jam8ae7cad2016-09-08 23:55:21651 if (!certificate_->subject().state_or_province_name.empty()) {
rsleevi4f8012722014-09-30 01:28:01652 locality = l10n_util::GetStringFUTF16(
lgarronfc1d5e52017-05-03 23:15:21653 IDS_PAGE_INFO_ADDRESS,
jam8ae7cad2016-09-08 23:55:21654 UTF8ToUTF16(certificate_->subject().locality_name),
655 UTF8ToUTF16(certificate_->subject().state_or_province_name),
656 UTF8ToUTF16(certificate_->subject().country_name));
rsleevi4f8012722014-09-30 01:28:01657 } else {
658 locality = l10n_util::GetStringFUTF16(
lgarronfc1d5e52017-05-03 23:15:21659 IDS_PAGE_INFO_PARTIAL_ADDRESS,
jam8ae7cad2016-09-08 23:55:21660 UTF8ToUTF16(certificate_->subject().locality_name),
661 UTF8ToUTF16(certificate_->subject().country_name));
rsleevi4f8012722014-09-30 01:28:01662 }
jam8ae7cad2016-09-08 23:55:21663 DCHECK(!certificate_->subject().organization_names.empty());
rsleevi4f8012722014-09-30 01:28:01664 site_identity_details_.assign(l10n_util::GetStringFUTF16(
estarkcf305562016-11-15 03:45:39665 IDS_PAGE_INFO_SECURITY_TAB_SECURE_IDENTITY_EV_VERIFIED,
jam8ae7cad2016-09-08 23:55:21666 UTF8ToUTF16(certificate_->subject().organization_names[0]),
estarkcf305562016-11-15 03:45:39667 locality, UTF8ToUTF16(certificate_->issuer().GetDisplayName())));
rsleevi4f8012722014-09-30 01:28:01668 } else {
669 // Non-EV OK HTTPS page.
estarkcf305562016-11-15 03:45:39670 site_identity_status_ = SITE_IDENTITY_STATUS_CERT;
rsleevi4f8012722014-09-30 01:28:01671 base::string16 issuer_name(
jam8ae7cad2016-09-08 23:55:21672 UTF8ToUTF16(certificate_->issuer().GetDisplayName()));
rsleevi4f8012722014-09-30 01:28:01673 if (issuer_name.empty()) {
674 issuer_name.assign(l10n_util::GetStringUTF16(
675 IDS_PAGE_INFO_SECURITY_TAB_UNKNOWN_PARTY));
676 }
[email protected]94c74b42013-12-02 15:19:49677
rsleevi4f8012722014-09-30 01:28:01678 site_identity_details_.assign(l10n_util::GetStringFUTF16(
estarkcf305562016-11-15 03:45:39679 IDS_PAGE_INFO_SECURITY_TAB_SECURE_IDENTITY_VERIFIED, issuer_name));
rsleevi4f8012722014-09-30 01:28:01680 }
elawrencebe87bd62017-01-10 16:08:59681 if (security_info.sha1_in_chain) {
682 site_identity_status_ =
683 SITE_IDENTITY_STATUS_DEPRECATED_SIGNATURE_ALGORITHM;
684 site_identity_details_ +=
685 UTF8ToUTF16("\n\n") +
686 l10n_util::GetStringUTF16(
687 IDS_PAGE_INFO_SECURITY_TAB_DEPRECATED_SIGNATURE_ALGORITHM);
rsleevi4f8012722014-09-30 01:28:01688 }
[email protected]03ef4b2a2012-03-06 15:04:20689 }
690 } else {
691 // HTTP or HTTPS with errors (not warnings).
692 site_identity_details_.assign(l10n_util::GetStringUTF16(
693 IDS_PAGE_INFO_SECURITY_TAB_INSECURE_IDENTITY));
jam8ae7cad2016-09-08 23:55:21694 if (!security_info.scheme_is_cryptographic || !security_info.certificate)
[email protected]03ef4b2a2012-03-06 15:04:20695 site_identity_status_ = SITE_IDENTITY_STATUS_NO_CERT;
696 else
697 site_identity_status_ = SITE_IDENTITY_STATUS_ERROR;
698
[email protected]a04db822013-12-11 19:14:40699 const base::string16 bullet = UTF8ToUTF16("\n • ");
felt2493b4452015-09-17 20:33:59700 std::vector<ssl_errors::ErrorInfo> errors;
estarka3121f6b2015-09-18 21:15:59701 ssl_errors::ErrorInfo::GetErrorsForCertStatus(
jam8ae7cad2016-09-08 23:55:21702 certificate_, security_info.cert_status, url, &errors);
[email protected]03ef4b2a2012-03-06 15:04:20703 for (size_t i = 0; i < errors.size(); ++i) {
704 site_identity_details_ += bullet;
705 site_identity_details_ += errors[i].short_description();
706 }
707
estarka3121f6b2015-09-18 21:15:59708 if (security_info.cert_status & net::CERT_STATUS_NON_UNIQUE_NAME) {
[email protected]03ef4b2a2012-03-06 15:04:20709 site_identity_details_ += ASCIIToUTF16("\n\n");
lgarron1a6300d2017-03-18 03:33:04710 site_identity_details_ +=
711 l10n_util::GetStringUTF16(IDS_PAGE_INFO_SECURITY_TAB_NON_UNIQUE_NAME);
[email protected]03ef4b2a2012-03-06 15:04:20712 }
713 }
714
715 // Site Connection
716 // We consider anything less than 80 bits encryption to be weak encryption.
717 // TODO(wtc): Bug 1198735: report mixed/unsafe content for unencrypted and
718 // weakly encrypted connections.
719 site_connection_status_ = SITE_CONNECTION_STATUS_UNKNOWN;
720
jshin1fb76462016-04-05 22:13:03721 base::string16 subject_name(GetSimpleSiteName(url));
palmer153af982015-09-15 02:04:19722 if (subject_name.empty()) {
723 subject_name.assign(
724 l10n_util::GetStringUTF16(IDS_PAGE_INFO_SECURITY_TAB_UNKNOWN_PARTY));
725 }
726
jam8ae7cad2016-09-08 23:55:21727 if (!security_info.certificate || !security_info.scheme_is_cryptographic) {
estarka3121f6b2015-09-18 21:15:59728 // Page is still loading (so SSL status is not yet available) or
729 // loaded over HTTP or loaded over HTTPS with no cert.
[email protected]1c1051d2014-05-10 11:39:58730 site_connection_status_ = SITE_CONNECTION_STATUS_UNENCRYPTED;
731
732 site_connection_details_.assign(l10n_util::GetStringFUTF16(
733 IDS_PAGE_INFO_SECURITY_TAB_NOT_ENCRYPTED_CONNECTION_TEXT,
734 subject_name));
estarka3121f6b2015-09-18 21:15:59735 } else if (security_info.security_bits < 0) {
736 // Security strength is unknown. Say nothing.
[email protected]03ef4b2a2012-03-06 15:04:20737 site_connection_status_ = SITE_CONNECTION_STATUS_ENCRYPTED_ERROR;
estarka3121f6b2015-09-18 21:15:59738 } else if (security_info.security_bits == 0) {
esecklercac56b62016-11-16 13:49:44739 DCHECK_NE(security_info.security_level, security_state::NONE);
[email protected]03ef4b2a2012-03-06 15:04:20740 site_connection_status_ = SITE_CONNECTION_STATUS_ENCRYPTED_ERROR;
741 site_connection_details_.assign(l10n_util::GetStringFUTF16(
742 IDS_PAGE_INFO_SECURITY_TAB_NOT_ENCRYPTED_CONNECTION_TEXT,
743 subject_name));
[email protected]03ef4b2a2012-03-06 15:04:20744 } else {
745 site_connection_status_ = SITE_CONNECTION_STATUS_ENCRYPTED;
Adam Langley71c2b59b2014-11-13 00:34:22746
lgarron3e2c33e2016-08-25 06:33:43747 if (security_info.obsolete_ssl_status == net::OBSOLETE_SSL_NONE) {
Adam Langley71c2b59b2014-11-13 00:34:22748 site_connection_details_.assign(l10n_util::GetStringFUTF16(
lgarron1a6300d2017-03-18 03:33:04749 IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTED_CONNECTION_TEXT, subject_name));
Adam Langley71c2b59b2014-11-13 00:34:22750 } else {
751 site_connection_details_.assign(l10n_util::GetStringFUTF16(
752 IDS_PAGE_INFO_SECURITY_TAB_WEAK_ENCRYPTION_CONNECTION_TEXT,
753 subject_name));
754 }
755
thestig4427f13b2017-06-20 20:42:47756 ReportAnyInsecureContent(security_info, &site_connection_status_,
757 &site_connection_details_);
[email protected]03ef4b2a2012-03-06 15:04:20758 }
759
avi655876a2015-12-25 07:18:15760 uint16_t cipher_suite =
estarka3121f6b2015-09-18 21:15:59761 net::SSLConnectionStatusToCipherSuite(security_info.connection_status);
762 if (security_info.security_bits > 0 && cipher_suite) {
[email protected]03ef4b2a2012-03-06 15:04:20763 int ssl_version =
estarka3121f6b2015-09-18 21:15:59764 net::SSLConnectionStatusToVersion(security_info.connection_status);
[email protected]03ef4b2a2012-03-06 15:04:20765 const char* ssl_version_str;
766 net::SSLVersionToString(&ssl_version_str, ssl_version);
767 site_connection_details_ += ASCIIToUTF16("\n\n");
768 site_connection_details_ += l10n_util::GetStringFUTF16(
lgarron1a6300d2017-03-18 03:33:04769 IDS_PAGE_INFO_SECURITY_TAB_SSL_VERSION, ASCIIToUTF16(ssl_version_str));
[email protected]03ef4b2a2012-03-06 15:04:20770
[email protected]03ef4b2a2012-03-06 15:04:20771 const char *key_exchange, *cipher, *mac;
davidben56a8aece2016-10-14 18:20:56772 bool is_aead, is_tls13;
773 net::SSLCipherSuiteToStrings(&key_exchange, &cipher, &mac, &is_aead,
774 &is_tls13, cipher_suite);
[email protected]03ef4b2a2012-03-06 15:04:20775
776 site_connection_details_ += ASCIIToUTF16("\n\n");
[email protected]b6c1d9e82013-06-12 17:26:57777 if (is_aead) {
davidben56a8aece2016-10-14 18:20:56778 if (is_tls13) {
779 // For TLS 1.3 ciphers, report the group (historically, curve) as the
780 // key exchange.
781 key_exchange = SSL_get_curve_name(security_info.key_exchange_group);
782 if (!key_exchange) {
783 NOTREACHED();
784 key_exchange = "";
785 }
786 }
[email protected]b6c1d9e82013-06-12 17:26:57787 site_connection_details_ += l10n_util::GetStringFUTF16(
788 IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTION_DETAILS_AEAD,
789 ASCIIToUTF16(cipher), ASCIIToUTF16(key_exchange));
790 } else {
791 site_connection_details_ += l10n_util::GetStringFUTF16(
lgarron1a6300d2017-03-18 03:33:04792 IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTION_DETAILS, ASCIIToUTF16(cipher),
793 ASCIIToUTF16(mac), ASCIIToUTF16(key_exchange));
[email protected]b6c1d9e82013-06-12 17:26:57794 }
[email protected]03ef4b2a2012-03-06 15:04:20795 }
[email protected]e583f752012-08-30 13:26:21796
[email protected]71cd5ef2014-08-13 21:22:04797 // Check if a user decision has been made to allow or deny certificates with
798 // errors on this site.
799 ChromeSSLHostStateDelegate* delegate =
estark7c6bfbf2015-09-16 22:20:50800 ChromeSSLHostStateDelegateFactory::GetForProfile(profile_);
[email protected]71cd5ef2014-08-13 21:22:04801 DCHECK(delegate);
jwwf806c362015-06-02 02:00:40802 // Only show an SSL decision revoke button if the user has chosen to bypass
803 // SSL host errors for this host in the past.
804 show_ssl_decision_revoke_button_ = delegate->HasAllowException(url.host());
[email protected]03ef4b2a2012-03-06 15:04:20805}
[email protected]0b9fdd72012-04-04 10:00:33806
lgarron617a30f32017-03-24 21:42:07807void PageInfo::PresentSitePermissions() {
[email protected]df818272012-04-20 13:10:50808 PermissionInfoList permission_info_list;
reillyg85f57db2016-01-12 23:14:38809 ChosenObjectInfoList chosen_object_info_list;
[email protected]df818272012-04-20 13:10:50810
lgarron617a30f32017-03-24 21:42:07811 PageInfoUI::PermissionInfo permission_info;
[email protected]df818272012-04-20 13:10:50812 for (size_t i = 0; i < arraysize(kPermissionType); ++i) {
813 permission_info.type = kPermissionType[i];
814
815 content_settings::SettingInfo info;
dcheng9603ab92016-04-08 04:17:32816 std::unique_ptr<base::Value> value = content_settings_->GetWebsiteSetting(
817 site_url_, site_url_, permission_info.type, std::string(), &info);
sashab2b2a314f2015-01-17 06:42:21818 DCHECK(value.get());
jdoerrie76cee9c2017-10-06 22:42:42819 if (value->type() == base::Value::Type::INTEGER) {
sashab2b2a314f2015-01-17 06:42:21820 permission_info.setting =
821 content_settings::ValueToContentSetting(value.get());
[email protected]fe4686a2012-10-19 15:38:26822 } else {
sashab2b2a314f2015-01-17 06:42:21823 NOTREACHED();
[email protected]fe4686a2012-10-19 15:38:26824 }
825
[email protected]8bdf45c32012-08-04 00:12:55826 permission_info.source = info.source;
johnme9ed93882016-01-15 01:13:28827 permission_info.is_incognito = profile_->IsOffTheRecord();
[email protected]df818272012-04-20 13:10:50828
[email protected]b1d113d2012-06-27 21:27:34829 if (info.primary_pattern == ContentSettingsPattern::Wildcard() &&
sashab2b2a314f2015-01-17 06:42:21830 info.secondary_pattern == ContentSettingsPattern::Wildcard()) {
[email protected]b1d113d2012-06-27 21:27:34831 permission_info.default_setting = permission_info.setting;
832 permission_info.setting = CONTENT_SETTING_DEFAULT;
833 } else {
834 permission_info.default_setting =
835 content_settings_->GetDefaultContentSetting(permission_info.type,
836 NULL);
[email protected]df818272012-04-20 13:10:50837 }
palmer0da10b32015-02-11 00:42:19838
patricialor2a4f41a2017-03-08 02:52:56839 // For permissions that are still prompting the user and haven't been
840 // explicitly set by another source, check its embargo status.
841 if (PermissionUtil::IsPermission(permission_info.type) &&
842 permission_info.setting == CONTENT_SETTING_DEFAULT &&
843 permission_info.source ==
844 content_settings::SettingSource::SETTING_SOURCE_USER) {
845 // TODO(raymes): Use GetPermissionStatus() to retrieve information
846 // about *all* permissions once it has default behaviour implemented for
847 // ContentSettingTypes that aren't permissions.
848 PermissionResult permission_result =
849 PermissionManager::Get(profile_)->GetPermissionStatus(
850 permission_info.type, site_url_, site_url_);
851
852 // If under embargo, update |permission_info| to reflect that.
853 if (permission_result.content_setting == CONTENT_SETTING_BLOCK &&
854 (permission_result.source ==
855 PermissionStatusSource::MULTIPLE_DISMISSALS ||
856 permission_result.source ==
857 PermissionStatusSource::SAFE_BROWSING_BLACKLIST))
858 permission_info.setting = permission_result.content_setting;
859 }
860
Tommy Steimelc9f6c932017-10-13 23:33:04861 if (ShouldShowPermission(permission_info, site_url_, content_settings_,
shahriar rostamia9c769d2017-12-06 04:54:08862 web_contents(), tab_specific_content_settings())) {
Patti0601e532017-09-20 08:39:30863 permission_info_list.push_back(permission_info);
Tommy Steimelc9f6c932017-10-13 23:33:04864 }
[email protected]df818272012-04-20 13:10:50865 }
866
reillyg85f57db2016-01-12 23:14:38867 for (const ChooserUIInfo& ui_info : kChooserUIInfo) {
868 ChooserContextBase* context = ui_info.get_context(profile_);
reillyg36a7fab32016-01-28 19:15:10869 const GURL origin = site_url_.GetOrigin();
870 auto chosen_objects = context->GetGrantedObjects(origin, origin);
dcheng9603ab92016-04-08 04:17:32871 for (std::unique_ptr<base::DictionaryValue>& object : chosen_objects) {
reillyg85f57db2016-01-12 23:14:38872 chosen_object_info_list.push_back(
Jinho Bangcc280792018-01-17 23:33:55873 std::make_unique<PageInfoUI::ChosenObjectInfo>(ui_info,
lgarron617a30f32017-03-24 21:42:07874 std::move(object)));
reillyg85f57db2016-01-12 23:14:38875 }
876 }
877
avi09dd4d02016-10-14 20:40:09878 ui_->SetPermissionInfo(permission_info_list,
879 std::move(chosen_object_info_list));
[email protected]0b9fdd72012-04-04 10:00:33880}
881
lgarron617a30f32017-03-24 21:42:07882void PageInfo::PresentSiteData() {
[email protected]df818272012-04-20 13:10:50883 CookieInfoList cookie_info_list;
vabrbab3ffcb2016-10-04 10:08:10884 const LocalSharedObjectsContainer& allowed_objects =
[email protected]e0ac35892012-05-15 12:53:34885 tab_specific_content_settings()->allowed_local_shared_objects();
vabrbab3ffcb2016-10-04 10:08:10886 const LocalSharedObjectsContainer& blocked_objects =
[email protected]e0ac35892012-05-15 12:53:34887 tab_specific_content_settings()->blocked_local_shared_objects();
888
889 // Add first party cookie and site data counts.
lgarron617a30f32017-03-24 21:42:07890 PageInfoUI::CookieInfo cookie_info;
[email protected]e0ac35892012-05-15 12:53:34891 cookie_info.allowed = allowed_objects.GetObjectCountForDomain(site_url_);
892 cookie_info.blocked = blocked_objects.GetObjectCountForDomain(site_url_);
palmerb145264922015-08-28 23:53:15893 cookie_info.is_first_party = true;
[email protected]e0ac35892012-05-15 12:53:34894 cookie_info_list.push_back(cookie_info);
895
896 // Add third party cookie counts.
[email protected]e0ac35892012-05-15 12:53:34897 cookie_info.allowed = allowed_objects.GetObjectCount() - cookie_info.allowed;
898 cookie_info.blocked = blocked_objects.GetObjectCount() - cookie_info.blocked;
palmerb145264922015-08-28 23:53:15899 cookie_info.is_first_party = false;
[email protected]df818272012-04-20 13:10:50900 cookie_info_list.push_back(cookie_info);
[email protected]0b9fdd72012-04-04 10:00:33901
[email protected]df818272012-04-20 13:10:50902 ui_->SetCookieInfo(cookie_info_list);
[email protected]0b9fdd72012-04-04 10:00:33903}
[email protected]16de6de2012-04-04 12:24:14904
lgarron617a30f32017-03-24 21:42:07905void PageInfo::PresentSiteIdentity() {
palmerf9b680a2015-07-09 18:56:04906 // After initialization the status about the site's connection and its
907 // identity must be available.
[email protected]24c8818c2012-04-25 09:57:41908 DCHECK_NE(site_identity_status_, SITE_IDENTITY_STATUS_UNKNOWN);
909 DCHECK_NE(site_connection_status_, SITE_CONNECTION_STATUS_UNKNOWN);
lgarron617a30f32017-03-24 21:42:07910 PageInfoUI::IdentityInfo info;
[email protected]24c8818c2012-04-25 09:57:41911 if (site_identity_status_ == SITE_IDENTITY_STATUS_EV_CERT)
912 info.site_identity = UTF16ToUTF8(organization_name());
913 else
jshin1fb76462016-04-05 22:13:03914 info.site_identity = UTF16ToUTF8(GetSimpleSiteName(site_url_));
[email protected]24c8818c2012-04-25 09:57:41915
916 info.connection_status = site_connection_status_;
lgarron1a6300d2017-03-18 03:33:04917 info.connection_status_description = UTF16ToUTF8(site_connection_details_);
[email protected]24c8818c2012-04-25 09:57:41918 info.identity_status = site_identity_status_;
lgarron1a6300d2017-03-18 03:33:04919 info.identity_status_description = UTF16ToUTF8(site_identity_details_);
jam8ae7cad2016-09-08 23:55:21920 info.certificate = certificate_;
[email protected]71cd5ef2014-08-13 21:22:04921 info.show_ssl_decision_revoke_button = show_ssl_decision_revoke_button_;
Jialiu Lin11e18542017-08-14 18:16:26922 info.show_change_password_buttons = show_change_password_buttons_;
[email protected]24c8818c2012-04-25 09:57:41923 ui_->SetIdentityInfo(info);
Jialiu Linfeb6bb32017-08-30 00:21:36924#if defined(SAFE_BROWSING_DB_LOCAL)
Jialiu Lin11e18542017-08-14 18:16:26925 if (password_protection_service_ && show_change_password_buttons_) {
Jialiu Linfecb75432017-11-07 19:14:59926 password_protection_service_->RecordWarningAction(
927 safe_browsing::PasswordProtectionService::PAGE_INFO,
928 safe_browsing::PasswordProtectionService::SHOWN);
Jialiu Lin11e18542017-08-14 18:16:26929 }
930#endif
[email protected]24c8818c2012-04-25 09:57:41931}
Patti7f21c4b2017-11-28 03:37:17932
933std::vector<ContentSettingsType> PageInfo::GetAllPermissionsForTesting() {
934 std::vector<ContentSettingsType> permission_list;
935 for (size_t i = 0; i < arraysize(kPermissionType); ++i) {
936#if !defined(OS_ANDROID)
937 if (kPermissionType[i] == CONTENT_SETTINGS_TYPE_AUTOPLAY)
938 continue;
939#endif
940 permission_list.push_back(kPermissionType[i]);
941 }
942 return permission_list;
943}