blob: 3b2821e6c7cc402634463e407050f9b78a27e8b8 [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,
Alexander Shalamovce5aab52018-02-07 11:45:15106 CONTENT_SETTINGS_TYPE_SENSORS,
palmer0da10b32015-02-11 00:42:19107 CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
palmer7715e332016-05-27 00:41:19108 CONTENT_SETTINGS_TYPE_JAVASCRIPT,
lshange085f202016-06-14 01:25:08109#if !defined(OS_ANDROID)
palmer7715e332016-05-27 00:41:19110 CONTENT_SETTINGS_TYPE_PLUGINS,
111 CONTENT_SETTINGS_TYPE_IMAGES,
lshange085f202016-06-14 01:25:08112#endif
palmer7715e332016-05-27 00:41:19113 CONTENT_SETTINGS_TYPE_POPUPS,
Charles Harrison239d47982017-06-13 02:42:31114 CONTENT_SETTINGS_TYPE_ADS,
nsatragno670fe922016-04-08 14:10:50115 CONTENT_SETTINGS_TYPE_BACKGROUND_SYNC,
Tommy Steimela8c3757e2017-08-24 00:15:46116 CONTENT_SETTINGS_TYPE_SOUND,
palmer7715e332016-05-27 00:41:19117 CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS,
finnur46cafd42016-09-22 10:27:17118 CONTENT_SETTINGS_TYPE_AUTOPLAY,
palmer7715e332016-05-27 00:41:19119 CONTENT_SETTINGS_TYPE_MIDI_SYSEX,
Gary Kacmarcik10533cf2017-11-22 03:31:28120 CONTENT_SETTINGS_TYPE_CLIPBOARD_READ,
[email protected]0b9fdd72012-04-04 10:00:33121};
122
Patti0601e532017-09-20 08:39:30123// Checks whether this permission is currently the factory default, as set by
124// Chrome. Specifically, that the following three conditions are true:
125// - The current active setting comes from the default or pref provider.
126// - The setting is the factory default setting (as opposed to a global
127// default setting set by the user).
128// - The setting is a wildcard setting applying to all origins (which can only
129// be set from the default provider).
130bool IsPermissionFactoryDefault(HostContentSettingsMap* content_settings,
131 const PageInfoUI::PermissionInfo& info) {
132 const ContentSetting factory_default_setting =
133 content_settings::ContentSettingsRegistry::GetInstance()
134 ->Get(info.type)
135 ->GetInitialDefaultSetting();
136 return (info.source == content_settings::SETTING_SOURCE_USER &&
137 factory_default_setting == info.default_setting &&
138 info.setting == CONTENT_SETTING_DEFAULT);
139}
140
lgarron617a30f32017-03-24 21:42:07141// Determines whether to show permission |type| in the Page Info UI. Only
mgiucaa319f212016-01-14 03:30:11142// applies to permissions listed in |kPermissionType|.
shahriar rostamia9c769d2017-12-06 04:54:08143bool ShouldShowPermission(
144 const PageInfoUI::PermissionInfo& info,
145 const GURL& site_url,
146 HostContentSettingsMap* content_settings,
147 content::WebContents* web_contents,
148 TabSpecificContentSettings* tab_specific_content_settings) {
Patti0601e532017-09-20 08:39:30149 // Note |CONTENT_SETTINGS_TYPE_ADS| will show up regardless of its default
150 // value when it has been activated on the current origin.
151 if (info.type == CONTENT_SETTINGS_TYPE_ADS) {
csharrisonad1eaa6c2017-05-11 17:14:38152 if (!base::FeatureList::IsEnabled(
153 subresource_filter::kSafeBrowsingSubresourceFilterExperimentalUI)) {
154 return false;
155 }
156
157 // The setting for subresource filtering should not show up if the site is
158 // not activated, both on android and desktop platforms.
159 return content_settings->GetWebsiteSetting(
Charles Harrison239d47982017-06-13 02:42:31160 site_url, GURL(), CONTENT_SETTINGS_TYPE_ADS_DATA, std::string(),
161 nullptr) != nullptr;
melandory7be36d312017-03-29 15:51:12162 }
163
Tommy Steimelc9f6c932017-10-13 23:33:04164 if (info.type == CONTENT_SETTINGS_TYPE_SOUND) {
165 if (!base::FeatureList::IsEnabled(features::kSoundContentSetting))
166 return false;
167
Tommy Steimel18360512017-11-01 00:38:19168 // The sound content setting should always show up when the tab has played
169 // audio.
170 if (web_contents && web_contents->WasEverAudible())
Tommy Steimelc9f6c932017-10-13 23:33:04171 return true;
172 }
173
Gary Kacmarcik10533cf2017-11-22 03:31:28174 if (info.type == CONTENT_SETTINGS_TYPE_CLIPBOARD_READ) {
175 if (!base::FeatureList::IsEnabled(features::kClipboardContentSetting))
176 return false;
177 }
178
Patti749d4d12017-10-11 06:20:30179#if defined(OS_ANDROID)
180 // Special geolocation DSE settings apply only on Android, so make sure it
181 // gets checked there regardless of default setting on Desktop.
182 if (info.type == CONTENT_SETTINGS_TYPE_GEOLOCATION)
183 return true;
Pattid7c4d542017-12-07 00:54:14184#else
Patti8c57f37d2018-01-31 04:33:21185 // Flash is shown if the user has ever changed its setting for |site_url|.
186 if (info.type == CONTENT_SETTINGS_TYPE_PLUGINS &&
187 content_settings->GetWebsiteSetting(site_url, site_url,
188 CONTENT_SETTINGS_TYPE_PLUGINS_DATA,
189 std::string(), nullptr) != nullptr) {
Pattid7c4d542017-12-07 00:54:14190 return true;
Patti8c57f37d2018-01-31 04:33:21191 }
Patti749d4d12017-10-11 06:20:30192#endif
193
Patti0601e532017-09-20 08:39:30194#if !defined(OS_ANDROID)
195 // Autoplay is Android-only at the moment.
196 if (info.type == CONTENT_SETTINGS_TYPE_AUTOPLAY)
197 return false;
198#endif
199
shahriar rostamia9c769d2017-12-06 04:54:08200 // Show the content setting if it has been changed by the user since the last
201 // page load.
202 if (tab_specific_content_settings->HasContentSettingChangedViaPageInfo(
203 info.type)) {
204 return true;
205 }
206
207 // Show the content setting when it has a non-default value.
208 if (!IsPermissionFactoryDefault(content_settings, info))
209 return true;
210
211 return false;
mgiucaa319f212016-01-14 03:30:11212}
213
esecklercac56b62016-11-16 13:49:44214void CheckContentStatus(security_state::ContentStatus content_status,
estark00e83f12016-08-19 18:24:04215 bool* displayed,
216 bool* ran) {
217 switch (content_status) {
esecklercac56b62016-11-16 13:49:44218 case security_state::CONTENT_STATUS_DISPLAYED:
estark00e83f12016-08-19 18:24:04219 *displayed = true;
220 break;
esecklercac56b62016-11-16 13:49:44221 case security_state::CONTENT_STATUS_RAN:
estark00e83f12016-08-19 18:24:04222 *ran = true;
223 break;
esecklercac56b62016-11-16 13:49:44224 case security_state::CONTENT_STATUS_DISPLAYED_AND_RAN:
estark00e83f12016-08-19 18:24:04225 *displayed = true;
226 *ran = true;
227 break;
esecklercac56b62016-11-16 13:49:44228 case security_state::CONTENT_STATUS_UNKNOWN:
229 case security_state::CONTENT_STATUS_NONE:
estark00e83f12016-08-19 18:24:04230 break;
231 }
232}
233
elawrenceb2ac2a232017-03-27 21:46:25234// If the |security_info| indicates that mixed content or certificate errors
235// were present, update |connection_status| and |connection_details|.
236void ReportAnyInsecureContent(const security_state::SecurityInfo& security_info,
thestig4427f13b2017-06-20 20:42:47237 PageInfo::SiteConnectionStatus* connection_status,
238 base::string16* connection_details) {
elawrenceb2ac2a232017-03-27 21:46:25239 bool displayed_insecure_content = false;
240 bool ran_insecure_content = false;
241 CheckContentStatus(security_info.mixed_content_status,
242 &displayed_insecure_content, &ran_insecure_content);
243 // Only note subresources with certificate errors if the main resource was
244 // loaded without major certificate errors. If the main resource had a
245 // certificate error, then it would not be that useful (and could
246 // potentially be confusing) to warn about subresources that had certificate
247 // errors too.
248 if (!net::IsCertStatusError(security_info.cert_status) ||
249 net::IsCertStatusMinorError(security_info.cert_status)) {
250 CheckContentStatus(security_info.content_with_cert_errors_status,
251 &displayed_insecure_content, &ran_insecure_content);
252 }
253
254 // Only one insecure content warning is displayed; show the most severe.
255 if (ran_insecure_content) {
thestig4427f13b2017-06-20 20:42:47256 *connection_status =
elawrenceb2ac2a232017-03-27 21:46:25257 PageInfo::SITE_CONNECTION_STATUS_INSECURE_ACTIVE_SUBRESOURCE;
thestig4427f13b2017-06-20 20:42:47258 connection_details->assign(l10n_util::GetStringFUTF16(
259 IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTED_SENTENCE_LINK, *connection_details,
elawrenceb2ac2a232017-03-27 21:46:25260 l10n_util::GetStringUTF16(
261 IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTED_INSECURE_CONTENT_ERROR)));
estark00e83f12016-08-19 18:24:04262 return;
263 }
elawrenceb2ac2a232017-03-27 21:46:25264 if (security_info.contained_mixed_form) {
thestig4427f13b2017-06-20 20:42:47265 *connection_status = PageInfo::SITE_CONNECTION_STATUS_INSECURE_FORM_ACTION;
266 connection_details->assign(l10n_util::GetStringFUTF16(
267 IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTED_SENTENCE_LINK, *connection_details,
elawrenceb2ac2a232017-03-27 21:46:25268 l10n_util::GetStringUTF16(
269 IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTED_INSECURE_FORM_WARNING)));
270 return;
271 }
272 if (displayed_insecure_content) {
thestig4427f13b2017-06-20 20:42:47273 *connection_status =
elawrenceb2ac2a232017-03-27 21:46:25274 PageInfo::SITE_CONNECTION_STATUS_INSECURE_PASSIVE_SUBRESOURCE;
thestig4427f13b2017-06-20 20:42:47275 connection_details->assign(l10n_util::GetStringFUTF16(
276 IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTED_SENTENCE_LINK, *connection_details,
elawrenceb2ac2a232017-03-27 21:46:25277 l10n_util::GetStringUTF16(
278 IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTED_INSECURE_CONTENT_WARNING)));
279 }
estark00e83f12016-08-19 18:24:04280}
281
estarkfcfccdb82016-11-14 02:17:29282void GetSiteIdentityByMaliciousContentStatus(
esecklercac56b62016-11-16 13:49:44283 security_state::MaliciousContentStatus malicious_content_status,
lgarron617a30f32017-03-24 21:42:07284 PageInfo::SiteIdentityStatus* status,
estarkfcfccdb82016-11-14 02:17:29285 base::string16* details) {
286 switch (malicious_content_status) {
esecklercac56b62016-11-16 13:49:44287 case security_state::MALICIOUS_CONTENT_STATUS_NONE:
estarkfcfccdb82016-11-14 02:17:29288 NOTREACHED();
289 break;
esecklercac56b62016-11-16 13:49:44290 case security_state::MALICIOUS_CONTENT_STATUS_MALWARE:
lgarron617a30f32017-03-24 21:42:07291 *status = PageInfo::SITE_IDENTITY_STATUS_MALWARE;
lgarronfc1d5e52017-05-03 23:15:21292 *details = l10n_util::GetStringUTF16(IDS_PAGE_INFO_MALWARE_DETAILS);
estarkfcfccdb82016-11-14 02:17:29293 break;
esecklercac56b62016-11-16 13:49:44294 case security_state::MALICIOUS_CONTENT_STATUS_SOCIAL_ENGINEERING:
lgarron617a30f32017-03-24 21:42:07295 *status = PageInfo::SITE_IDENTITY_STATUS_SOCIAL_ENGINEERING;
lgarron1a6300d2017-03-18 03:33:04296 *details =
lgarronfc1d5e52017-05-03 23:15:21297 l10n_util::GetStringUTF16(IDS_PAGE_INFO_SOCIAL_ENGINEERING_DETAILS);
estarkfcfccdb82016-11-14 02:17:29298 break;
esecklercac56b62016-11-16 13:49:44299 case security_state::MALICIOUS_CONTENT_STATUS_UNWANTED_SOFTWARE:
lgarron617a30f32017-03-24 21:42:07300 *status = PageInfo::SITE_IDENTITY_STATUS_UNWANTED_SOFTWARE;
lgarron1a6300d2017-03-18 03:33:04301 *details =
lgarronfc1d5e52017-05-03 23:15:21302 l10n_util::GetStringUTF16(IDS_PAGE_INFO_UNWANTED_SOFTWARE_DETAILS);
estarkfcfccdb82016-11-14 02:17:29303 break;
Jialiu Lin11e18542017-08-14 18:16:26304 case security_state::MALICIOUS_CONTENT_STATUS_PASSWORD_REUSE:
Jialiu Linfeb6bb32017-08-30 00:21:36305#if defined(SAFE_BROWSING_DB_LOCAL)
Jialiu Lin11e18542017-08-14 18:16:26306 *status = PageInfo::SITE_IDENTITY_STATUS_PASSWORD_REUSE;
307 *details =
308 l10n_util::GetStringUTF16(IDS_PAGE_INFO_CHANGE_PASSWORD_DETAILS);
309#endif
310 break;
estarkfcfccdb82016-11-14 02:17:29311 }
312}
313
jshin1fb76462016-04-05 22:13:03314base::string16 GetSimpleSiteName(const GURL& url) {
benwells2337b8102016-04-20 01:53:53315 return url_formatter::FormatUrlForSecurityDisplay(
316 url, url_formatter::SchemeDisplay::OMIT_HTTP_AND_HTTPS);
palmer153af982015-09-15 02:04:19317}
318
reillyg85f57db2016-01-12 23:14:38319ChooserContextBase* GetUsbChooserContext(Profile* profile) {
320 return UsbChooserContextFactory::GetForProfile(profile);
321}
322
323// The list of chooser types that need to display entries in the Website
324// Settings UI. THE ORDER OF THESE ITEMS IS IMPORTANT. To propose changing it,
325// email [email protected].
Andrew Grieved1978b0e2017-07-28 15:53:41326const PageInfo::ChooserUIInfo kChooserUIInfo[] = {
reillyg58f82ab2016-08-03 01:49:52327 {CONTENT_SETTINGS_TYPE_USB_CHOOSER_DATA, &GetUsbChooserContext,
Patti1d8a4312018-01-19 06:36:11328 IDS_PAGE_INFO_USB_DEVICE_LABEL, IDS_PAGE_INFO_USB_DEVICE_SECONDARY_LABEL,
329 IDS_PAGE_INFO_DELETE_USB_DEVICE, "name"},
reillyg85f57db2016-01-12 23:14:38330};
331
[email protected]0b9fdd72012-04-04 10:00:33332} // namespace
333
lgarron617a30f32017-03-24 21:42:07334PageInfo::PageInfo(PageInfoUI* ui,
335 Profile* profile,
336 TabSpecificContentSettings* tab_specific_content_settings,
337 content::WebContents* web_contents,
338 const GURL& url,
339 const security_state::SecurityInfo& security_info)
[email protected]df818272012-04-20 13:10:50340 : TabSpecificContentSettings::SiteDataObserver(
341 tab_specific_content_settings),
dominicknbdd53b5f2016-09-28 01:08:13342 content::WebContentsObserver(web_contents),
[email protected]df818272012-04-20 13:10:50343 ui_(ui),
[email protected]66f157312012-08-01 13:50:26344 show_info_bar_(false),
[email protected]0b9fdd72012-04-04 10:00:33345 site_url_(url),
346 site_identity_status_(SITE_IDENTITY_STATUS_UNKNOWN),
[email protected]03ef4b2a2012-03-06 15:04:20347 site_connection_status_(SITE_CONNECTION_STATUS_UNKNOWN),
alshabalin5e894c12016-10-25 06:47:46348 show_ssl_decision_revoke_button_(false),
peconn5100d432015-09-16 12:03:08349 content_settings_(HostContentSettingsMapFactory::GetForProfile(profile)),
[email protected]71cd5ef2014-08-13 21:22:04350 chrome_ssl_host_state_delegate_(
jww1ed8ea72014-09-02 20:43:25351 ChromeSSLHostStateDelegateFactory::GetForProfile(profile)),
palmer153af982015-09-15 02:04:19352 did_revoke_user_ssl_decisions_(false),
estark8d67cd7a2016-10-24 05:06:41353 profile_(profile),
Jialiu Lin11e18542017-08-14 18:16:26354 security_level_(security_state::NONE),
Jialiu Linfeb6bb32017-08-30 00:21:36355#if defined(SAFE_BROWSING_DB_LOCAL)
Jialiu Lin0d8cc722017-09-19 01:01:51356 password_protection_service_(
357 safe_browsing::ChromePasswordProtectionService::
358 GetPasswordProtectionService(profile_)),
Jialiu Lin11e18542017-08-14 18:16:26359#endif
360 show_change_password_buttons_(false) {
estarka3121f6b2015-09-18 21:15:59361 Init(url, security_info);
[email protected]0b9fdd72012-04-04 10:00:33362
363 PresentSitePermissions();
[email protected]24c8818c2012-04-25 09:57:41364 PresentSiteIdentity();
Pattie8c616202017-09-29 07:58:03365 PresentSiteData();
[email protected]e22d64f2012-09-10 09:03:23366
lgarron617a30f32017-03-24 21:42:07367 // Every time the Page Info UI is opened a |PageInfo| object is
368 // created. So this counts how ofter the Page Info UI is opened.
369 RecordPageInfoAction(PAGE_INFO_OPENED);
[email protected]03ef4b2a2012-03-06 15:04:20370}
371
Carlos ILe5dfda72017-09-21 02:33:05372PageInfo::~PageInfo() {
373 // Check if Re-enable warnings button was visible, if so, log on UMA whether
374 // it was clicked or not.
375 SSLCertificateDecisionsDidRevoke user_decision =
376 did_revoke_user_ssl_decisions_ ? USER_CERT_DECISIONS_REVOKED
377 : USER_CERT_DECISIONS_NOT_REVOKED;
378 if (show_ssl_decision_revoke_button_) {
379 UMA_HISTOGRAM_ENUMERATION("interstitial.ssl.did_user_revoke_decisions2",
380 user_decision,
381 END_OF_SSL_CERTIFICATE_DECISIONS_DID_REVOKE_ENUM);
382 }
383}
[email protected]03ef4b2a2012-03-06 15:04:20384
lgarron617a30f32017-03-24 21:42:07385void PageInfo::RecordPageInfoAction(PageInfoAction action) {
386 UMA_HISTOGRAM_ENUMERATION("WebsiteSettings.Action", action, PAGE_INFO_COUNT);
lgarron04a93502014-11-04 22:25:04387
estark8d67cd7a2016-10-24 05:06:41388 std::string histogram_name;
estark8d67cd7a2016-10-24 05:06:41389 if (site_url_.SchemeIsCryptographic()) {
Carlos ILcb2321112018-02-01 18:05:23390 if (security_level_ == security_state::SECURE) {
391 UMA_HISTOGRAM_ENUMERATION("Security.PageInfo.Action.HttpsUrl.ValidNonEV",
392 action, PAGE_INFO_COUNT);
393 } else if (security_level_ == security_state::EV_SECURE) {
394 UMA_HISTOGRAM_ENUMERATION("Security.PageInfo.Action.HttpsUrl.ValidEV",
lgarron617a30f32017-03-24 21:42:07395 action, PAGE_INFO_COUNT);
esecklercac56b62016-11-16 13:49:44396 } else if (security_level_ == security_state::NONE) {
estark8d67cd7a2016-10-24 05:06:41397 UMA_HISTOGRAM_ENUMERATION("Security.PageInfo.Action.HttpsUrl.Downgraded",
lgarron617a30f32017-03-24 21:42:07398 action, PAGE_INFO_COUNT);
esecklercac56b62016-11-16 13:49:44399 } else if (security_level_ == security_state::DANGEROUS) {
estark8d67cd7a2016-10-24 05:06:41400 UMA_HISTOGRAM_ENUMERATION("Security.PageInfo.Action.HttpsUrl.Dangerous",
lgarron617a30f32017-03-24 21:42:07401 action, PAGE_INFO_COUNT);
estark8d67cd7a2016-10-24 05:06:41402 }
403 return;
404 }
405
esecklercac56b62016-11-16 13:49:44406 if (security_level_ == security_state::HTTP_SHOW_WARNING) {
estark8d67cd7a2016-10-24 05:06:41407 UMA_HISTOGRAM_ENUMERATION("Security.PageInfo.Action.HttpUrl.Warning",
lgarron617a30f32017-03-24 21:42:07408 action, PAGE_INFO_COUNT);
esecklercac56b62016-11-16 13:49:44409 } else if (security_level_ == security_state::DANGEROUS) {
estark8d67cd7a2016-10-24 05:06:41410 UMA_HISTOGRAM_ENUMERATION("Security.PageInfo.Action.HttpUrl.Dangerous",
lgarron617a30f32017-03-24 21:42:07411 action, PAGE_INFO_COUNT);
estark8d67cd7a2016-10-24 05:06:41412 } else {
413 UMA_HISTOGRAM_ENUMERATION("Security.PageInfo.Action.HttpUrl.Neutral",
lgarron617a30f32017-03-24 21:42:07414 action, PAGE_INFO_COUNT);
lgarron04a93502014-11-04 22:25:04415 }
416}
417
lgarron617a30f32017-03-24 21:42:07418void PageInfo::OnSitePermissionChanged(ContentSettingsType type,
419 ContentSetting setting) {
shahriar rostamia9c769d2017-12-06 04:54:08420 tab_specific_content_settings()->ContentSettingChangedViaPageInfo(type);
421
[email protected]e22d64f2012-09-10 09:03:23422 // Count how often a permission for a specific content type is changed using
lgarron617a30f32017-03-24 21:42:07423 // the Page Info UI.
raymes4a13d432015-09-08 00:44:07424 size_t num_values;
425 int histogram_value = ContentSettingTypeToHistogramValue(type, &num_values);
dchengf6f4e4942017-03-30 23:55:57426 UMA_HISTOGRAM_EXACT_LINEAR("WebsiteSettings.OriginInfo.PermissionChanged",
427 histogram_value, num_values);
sashab9debecd2014-12-18 04:15:56428
429 if (setting == ContentSetting::CONTENT_SETTING_ALLOW) {
dchengf6f4e4942017-03-30 23:55:57430 UMA_HISTOGRAM_EXACT_LINEAR(
sashab9debecd2014-12-18 04:15:56431 "WebsiteSettings.OriginInfo.PermissionChanged.Allowed", histogram_value,
raymes4a13d432015-09-08 00:44:07432 num_values);
tommycli34cf29bf2016-09-08 05:46:25433
434 if (type == CONTENT_SETTINGS_TYPE_PLUGINS) {
435 rappor::SampleDomainAndRegistryFromGURL(
436 g_browser_process->rappor_service(),
437 "ContentSettings.Plugins.AddedAllowException", site_url_);
438 }
sashab9debecd2014-12-18 04:15:56439 } else if (setting == ContentSetting::CONTENT_SETTING_BLOCK) {
dchengf6f4e4942017-03-30 23:55:57440 UMA_HISTOGRAM_EXACT_LINEAR(
sashab9debecd2014-12-18 04:15:56441 "WebsiteSettings.OriginInfo.PermissionChanged.Blocked", histogram_value,
raymes4a13d432015-09-08 00:44:07442 num_values);
sashab9debecd2014-12-18 04:15:56443 }
[email protected]e22d64f2012-09-10 09:03:23444
lgarron04a93502014-11-04 22:25:04445 // This is technically redundant given the histogram above, but putting the
446 // total count of permission changes in another histogram makes it easier to
lgarron026e9c42017-04-07 20:09:31447 // compare it against other kinds of actions in Page Info.
lgarron617a30f32017-03-24 21:42:07448 RecordPageInfoAction(PAGE_INFO_CHANGED_PERMISSION);
Tommy Steimeldea90f72017-11-07 20:58:03449 if (type == CONTENT_SETTINGS_TYPE_SOUND) {
450 ContentSetting default_setting =
451 content_settings_->GetDefaultContentSetting(CONTENT_SETTINGS_TYPE_SOUND,
452 nullptr);
453 bool mute = (setting == CONTENT_SETTING_BLOCK) ||
454 (setting == CONTENT_SETTING_DEFAULT &&
455 default_setting == CONTENT_SETTING_BLOCK);
456 if (mute) {
457 base::RecordAction(
458 base::UserMetricsAction("SoundContentSetting.MuteBy.PageInfo"));
459 } else {
460 base::RecordAction(
461 base::UserMetricsAction("SoundContentSetting.UnmuteBy.PageInfo"));
462 }
463 }
lgarron04a93502014-11-04 22:25:04464
stefanocs8b3490cc2016-07-28 05:32:52465 PermissionUtil::ScopedRevocationReporter scoped_revocation_reporter(
patricialor7131c1fe2017-04-07 01:25:52466 profile_, site_url_, site_url_, type, PermissionSourceUI::OIB);
stefanocs8b3490cc2016-07-28 05:32:52467
patricialor7131c1fe2017-04-07 01:25:52468 // The permission may have been blocked due to being under embargo, so if it
469 // was changed away from BLOCK, clear embargo status if it exists.
470 if (setting != CONTENT_SETTING_BLOCK) {
471 PermissionDecisionAutoBlocker::GetForProfile(profile_)->RemoveEmbargoByUrl(
472 site_url_, type);
473 }
raymesfbaaaaa2015-11-10 02:20:40474 content_settings_->SetNarrowestContentSetting(site_url_, site_url_, type,
475 setting);
[email protected]df818272012-04-20 13:10:50476
Tommy Steimel97ee2f82017-11-01 21:39:52477 // When the sound setting is changed, no reload is necessary.
478 if (type != CONTENT_SETTINGS_TYPE_SOUND)
479 show_info_bar_ = true;
[email protected]2f45d542012-08-22 08:47:24480
481 // Refresh the UI to reflect the new setting.
482 PresentSitePermissions();
[email protected]df818272012-04-20 13:10:50483}
484
lgarron617a30f32017-03-24 21:42:07485void PageInfo::OnSiteChosenObjectDeleted(const ChooserUIInfo& ui_info,
486 const base::DictionaryValue& object) {
reillyg85f57db2016-01-12 23:14:38487 // TODO(reillyg): Create metrics for revocations. crbug.com/556845
488 ChooserContextBase* context = ui_info.get_context(profile_);
reillyg36a7fab32016-01-28 19:15:10489 const GURL origin = site_url_.GetOrigin();
490 context->RevokeObjectPermission(origin, origin, object);
reillyg85f57db2016-01-12 23:14:38491 show_info_bar_ = true;
492
493 // Refresh the UI to reflect the changed settings.
494 PresentSitePermissions();
495}
496
lgarron617a30f32017-03-24 21:42:07497void PageInfo::OnSiteDataAccessed() {
[email protected]df818272012-04-20 13:10:50498 PresentSiteData();
[email protected]0b9fdd72012-04-04 10:00:33499}
500
lgarron617a30f32017-03-24 21:42:07501void PageInfo::OnUIClosing() {
estade3feb83f2015-09-01 23:00:49502#if defined(OS_ANDROID)
503 NOTREACHED();
504#else
dominicknbdd53b5f2016-09-28 01:08:13505 if (show_info_bar_ && web_contents() && !web_contents()->IsBeingDestroyed()) {
palmerf2cba0d2015-08-27 23:15:06506 InfoBarService* infobar_service =
dominicknbdd53b5f2016-09-28 01:08:13507 InfoBarService::FromWebContents(web_contents());
palmerf2cba0d2015-08-27 23:15:06508 if (infobar_service)
lgarron617a30f32017-03-24 21:42:07509 PageInfoInfoBarDelegate::Create(infobar_service);
palmerf2cba0d2015-08-27 23:15:06510 }
estade3feb83f2015-09-01 23:00:49511#endif
jww1ed8ea72014-09-02 20:43:25512}
513
lgarron617a30f32017-03-24 21:42:07514void PageInfo::OnRevokeSSLErrorBypassButtonPressed() {
jww1ed8ea72014-09-02 20:43:25515 DCHECK(chrome_ssl_host_state_delegate_);
jww6a55df72014-09-05 19:59:29516 chrome_ssl_host_state_delegate_->RevokeUserAllowExceptionsHard(
517 site_url().host());
jww1ed8ea72014-09-02 20:43:25518 did_revoke_user_ssl_decisions_ = true;
[email protected]66f157312012-08-01 13:50:26519}
520
Patricia Lora21a04cf2017-06-05 02:53:29521void PageInfo::OpenSiteSettingsView() {
Christopher Lam0dbac2b2017-11-14 07:12:10522#if defined(OS_ANDROID)
523 NOTREACHED();
524#else
525 chrome::ShowSiteSettings(chrome::FindBrowserWithWebContents(web_contents()),
526 site_url());
Patricia Lora21a04cf2017-06-05 02:53:29527 RecordPageInfoAction(PageInfo::PAGE_INFO_SITE_SETTINGS_OPENED);
Christopher Lam0dbac2b2017-11-14 07:12:10528#endif
Patricia Lora21a04cf2017-06-05 02:53:29529}
530
Jialiu Lin11e18542017-08-14 18:16:26531void PageInfo::OnChangePasswordButtonPressed(
532 content::WebContents* web_contents) {
Jialiu Linfeb6bb32017-08-30 00:21:36533#if defined(SAFE_BROWSING_DB_LOCAL)
Jialiu Lin11e18542017-08-14 18:16:26534 DCHECK(password_protection_service_);
Jialiu Lin3fc7f38f2017-09-21 18:38:37535 password_protection_service_->OnUserAction(
Jialiu Lin11e18542017-08-14 18:16:26536 web_contents, safe_browsing::PasswordProtectionService::PAGE_INFO,
537 safe_browsing::PasswordProtectionService::CHANGE_PASSWORD);
538#endif
539}
540
541void PageInfo::OnWhitelistPasswordReuseButtonPressed(
542 content::WebContents* web_contents) {
Jialiu Linfeb6bb32017-08-30 00:21:36543#if defined(SAFE_BROWSING_DB_LOCAL)
Jialiu Lin11e18542017-08-14 18:16:26544 DCHECK(password_protection_service_);
Jialiu Lin3fc7f38f2017-09-21 18:38:37545 password_protection_service_->OnUserAction(
Jialiu Lin11e18542017-08-14 18:16:26546 web_contents, safe_browsing::PasswordProtectionService::PAGE_INFO,
547 safe_browsing::PasswordProtectionService::MARK_AS_LEGITIMATE);
548#endif
549}
550
lgarron617a30f32017-03-24 21:42:07551void PageInfo::Init(const GURL& url,
552 const security_state::SecurityInfo& security_info) {
thestig0c55ee32017-06-20 22:17:51553#if !defined(OS_ANDROID)
meacerde53fcff2016-10-12 19:21:57554 // On desktop, internal URLs aren't handled by this class. Instead, a
lgarron026e9c42017-04-07 20:09:31555 // custom and simpler bubble is shown.
meacerde53fcff2016-10-12 19:21:57556 DCHECK(!url.SchemeIs(content::kChromeUIScheme) &&
557 !url.SchemeIs(content::kChromeDevToolsScheme) &&
558 !url.SchemeIs(content::kViewSourceScheme) &&
559 !url.SchemeIs(content_settings::kExtensionScheme));
560#endif
561
thestig0c55ee32017-06-20 22:17:51562 bool is_chrome_ui_native_scheme = false;
zpengdb4a58e2017-01-10 17:40:32563#if defined(OS_ANDROID)
thestig0c55ee32017-06-20 22:17:51564 is_chrome_ui_native_scheme = url.SchemeIs(chrome::kChromeUINativeScheme);
sashab97894ce2014-10-22 10:08:33565#endif
566
estark8d67cd7a2016-10-24 05:06:41567 security_level_ = security_info.security_level;
568
upendrag.gowda60886a6e2015-10-31 05:51:09569 if (url.SchemeIs(url::kAboutScheme)) {
570 // All about: URLs except about:blank are redirected.
571 DCHECK_EQ(url::kAboutBlankURL, url.spec());
572 site_identity_status_ = SITE_IDENTITY_STATUS_NO_CERT;
573 site_identity_details_ =
574 l10n_util::GetStringUTF16(IDS_PAGE_INFO_SECURITY_TAB_INSECURE_IDENTITY);
575 site_connection_status_ = SITE_CONNECTION_STATUS_UNENCRYPTED;
576 site_connection_details_ = l10n_util::GetStringFUTF16(
577 IDS_PAGE_INFO_SECURITY_TAB_NOT_ENCRYPTED_CONNECTION_TEXT,
578 UTF8ToUTF16(url.spec()));
579 return;
580 }
581
thestig0c55ee32017-06-20 22:17:51582 if (url.SchemeIs(content::kChromeUIScheme) || is_chrome_ui_native_scheme) {
[email protected]03ef4b2a2012-03-06 15:04:20583 site_identity_status_ = SITE_IDENTITY_STATUS_INTERNAL_PAGE;
584 site_identity_details_ =
585 l10n_util::GetStringUTF16(IDS_PAGE_INFO_INTERNAL_PAGE);
586 site_connection_status_ = SITE_CONNECTION_STATUS_INTERNAL_PAGE;
587 return;
588 }
589
[email protected]03ef4b2a2012-03-06 15:04:20590 // Identity section.
jam8ae7cad2016-09-08 23:55:21591 certificate_ = security_info.certificate;
[email protected]f61c1ce2012-05-09 13:55:11592
estarkfcfccdb82016-11-14 02:17:29593 if (security_info.malicious_content_status !=
esecklercac56b62016-11-16 13:49:44594 security_state::MALICIOUS_CONTENT_STATUS_NONE) {
estarkfcfccdb82016-11-14 02:17:29595 // The site has been flagged by Safe Browsing as dangerous.
596 GetSiteIdentityByMaliciousContentStatus(
597 security_info.malicious_content_status, &site_identity_status_,
598 &site_identity_details_);
Jialiu Lin11e18542017-08-14 18:16:26599 show_change_password_buttons_ =
600 security_info.malicious_content_status ==
601 security_state::MALICIOUS_CONTENT_STATUS_PASSWORD_REUSE;
estarkfcfccdb82016-11-14 02:17:29602 } else if (certificate_ &&
603 (!net::IsCertStatusError(security_info.cert_status) ||
604 net::IsCertStatusMinorError(security_info.cert_status))) {
605 // HTTPS with no or minor errors.
estarka3121f6b2015-09-18 21:15:59606 if (security_info.security_level ==
esecklercac56b62016-11-16 13:49:44607 security_state::SECURE_WITH_POLICY_INSTALLED_CERT) {
Eric Lawrence6758d1d2017-11-21 16:06:05608#if defined(OS_CHROMEOS)
[email protected]eaf3f322013-04-25 21:53:59609 site_identity_status_ = SITE_IDENTITY_STATUS_ADMIN_PROVIDED_CERT;
[email protected]24a9f1c92013-11-13 12:33:37610 site_identity_details_ = l10n_util::GetStringFUTF16(
611 IDS_CERT_POLICY_PROVIDED_CERT_MESSAGE, UTF8ToUTF16(url.host()));
Eric Lawrence6758d1d2017-11-21 16:06:05612#else
613 DCHECK(false) << "Policy certificates exist only on ChromeOS";
614#endif
estarka3121f6b2015-09-18 21:15:59615 } else if (net::IsCertStatusMinorError(security_info.cert_status)) {
[email protected]03ef4b2a2012-03-06 15:04:20616 site_identity_status_ = SITE_IDENTITY_STATUS_CERT_REVOCATION_UNKNOWN;
jam8ae7cad2016-09-08 23:55:21617 base::string16 issuer_name(
618 UTF8ToUTF16(certificate_->issuer().GetDisplayName()));
[email protected]03ef4b2a2012-03-06 15:04:20619 if (issuer_name.empty()) {
620 issuer_name.assign(l10n_util::GetStringUTF16(
621 IDS_PAGE_INFO_SECURITY_TAB_UNKNOWN_PARTY));
622 }
[email protected]94c74b42013-12-02 15:19:49623
[email protected]03ef4b2a2012-03-06 15:04:20624 site_identity_details_.assign(l10n_util::GetStringFUTF16(
estarkcf305562016-11-15 03:45:39625 IDS_PAGE_INFO_SECURITY_TAB_SECURE_IDENTITY_VERIFIED, issuer_name));
[email protected]03ef4b2a2012-03-06 15:04:20626
627 site_identity_details_ += ASCIIToUTF16("\n\n");
estarka3121f6b2015-09-18 21:15:59628 if (security_info.cert_status &
629 net::CERT_STATUS_UNABLE_TO_CHECK_REVOCATION) {
[email protected]03ef4b2a2012-03-06 15:04:20630 site_identity_details_ += l10n_util::GetStringUTF16(
631 IDS_PAGE_INFO_SECURITY_TAB_UNABLE_TO_CHECK_REVOCATION);
estarka3121f6b2015-09-18 21:15:59632 } else if (security_info.cert_status &
633 net::CERT_STATUS_NO_REVOCATION_MECHANISM) {
[email protected]03ef4b2a2012-03-06 15:04:20634 site_identity_details_ += l10n_util::GetStringUTF16(
635 IDS_PAGE_INFO_SECURITY_TAB_NO_REVOCATION_MECHANISM);
636 } else {
637 NOTREACHED() << "Need to specify string for this warning";
638 }
[email protected]03ef4b2a2012-03-06 15:04:20639 } else {
estarkcf305562016-11-15 03:45:39640 // No major or minor errors.
estarka3121f6b2015-09-18 21:15:59641 if (security_info.cert_status & net::CERT_STATUS_IS_EV) {
rsleevi4f8012722014-09-30 01:28:01642 // EV HTTPS page.
estarkcf305562016-11-15 03:45:39643 site_identity_status_ = SITE_IDENTITY_STATUS_EV_CERT;
jam8ae7cad2016-09-08 23:55:21644 DCHECK(!certificate_->subject().organization_names.empty());
645 organization_name_ =
646 UTF8ToUTF16(certificate_->subject().organization_names[0]);
rsleevi4f8012722014-09-30 01:28:01647 // An EV Cert is required to have a city (localityName) and country but
648 // state is "if any".
jam8ae7cad2016-09-08 23:55:21649 DCHECK(!certificate_->subject().locality_name.empty());
650 DCHECK(!certificate_->subject().country_name.empty());
rsleevi4f8012722014-09-30 01:28:01651 base::string16 locality;
jam8ae7cad2016-09-08 23:55:21652 if (!certificate_->subject().state_or_province_name.empty()) {
rsleevi4f8012722014-09-30 01:28:01653 locality = l10n_util::GetStringFUTF16(
lgarronfc1d5e52017-05-03 23:15:21654 IDS_PAGE_INFO_ADDRESS,
jam8ae7cad2016-09-08 23:55:21655 UTF8ToUTF16(certificate_->subject().locality_name),
656 UTF8ToUTF16(certificate_->subject().state_or_province_name),
657 UTF8ToUTF16(certificate_->subject().country_name));
rsleevi4f8012722014-09-30 01:28:01658 } else {
659 locality = l10n_util::GetStringFUTF16(
lgarronfc1d5e52017-05-03 23:15:21660 IDS_PAGE_INFO_PARTIAL_ADDRESS,
jam8ae7cad2016-09-08 23:55:21661 UTF8ToUTF16(certificate_->subject().locality_name),
662 UTF8ToUTF16(certificate_->subject().country_name));
rsleevi4f8012722014-09-30 01:28:01663 }
jam8ae7cad2016-09-08 23:55:21664 DCHECK(!certificate_->subject().organization_names.empty());
rsleevi4f8012722014-09-30 01:28:01665 site_identity_details_.assign(l10n_util::GetStringFUTF16(
estarkcf305562016-11-15 03:45:39666 IDS_PAGE_INFO_SECURITY_TAB_SECURE_IDENTITY_EV_VERIFIED,
jam8ae7cad2016-09-08 23:55:21667 UTF8ToUTF16(certificate_->subject().organization_names[0]),
estarkcf305562016-11-15 03:45:39668 locality, UTF8ToUTF16(certificate_->issuer().GetDisplayName())));
rsleevi4f8012722014-09-30 01:28:01669 } else {
670 // Non-EV OK HTTPS page.
estarkcf305562016-11-15 03:45:39671 site_identity_status_ = SITE_IDENTITY_STATUS_CERT;
rsleevi4f8012722014-09-30 01:28:01672 base::string16 issuer_name(
jam8ae7cad2016-09-08 23:55:21673 UTF8ToUTF16(certificate_->issuer().GetDisplayName()));
rsleevi4f8012722014-09-30 01:28:01674 if (issuer_name.empty()) {
675 issuer_name.assign(l10n_util::GetStringUTF16(
676 IDS_PAGE_INFO_SECURITY_TAB_UNKNOWN_PARTY));
677 }
[email protected]94c74b42013-12-02 15:19:49678
rsleevi4f8012722014-09-30 01:28:01679 site_identity_details_.assign(l10n_util::GetStringFUTF16(
estarkcf305562016-11-15 03:45:39680 IDS_PAGE_INFO_SECURITY_TAB_SECURE_IDENTITY_VERIFIED, issuer_name));
rsleevi4f8012722014-09-30 01:28:01681 }
elawrencebe87bd62017-01-10 16:08:59682 if (security_info.sha1_in_chain) {
683 site_identity_status_ =
684 SITE_IDENTITY_STATUS_DEPRECATED_SIGNATURE_ALGORITHM;
685 site_identity_details_ +=
686 UTF8ToUTF16("\n\n") +
687 l10n_util::GetStringUTF16(
688 IDS_PAGE_INFO_SECURITY_TAB_DEPRECATED_SIGNATURE_ALGORITHM);
rsleevi4f8012722014-09-30 01:28:01689 }
[email protected]03ef4b2a2012-03-06 15:04:20690 }
691 } else {
692 // HTTP or HTTPS with errors (not warnings).
693 site_identity_details_.assign(l10n_util::GetStringUTF16(
694 IDS_PAGE_INFO_SECURITY_TAB_INSECURE_IDENTITY));
jam8ae7cad2016-09-08 23:55:21695 if (!security_info.scheme_is_cryptographic || !security_info.certificate)
[email protected]03ef4b2a2012-03-06 15:04:20696 site_identity_status_ = SITE_IDENTITY_STATUS_NO_CERT;
697 else
698 site_identity_status_ = SITE_IDENTITY_STATUS_ERROR;
699
[email protected]a04db822013-12-11 19:14:40700 const base::string16 bullet = UTF8ToUTF16("\n • ");
felt2493b4452015-09-17 20:33:59701 std::vector<ssl_errors::ErrorInfo> errors;
estarka3121f6b2015-09-18 21:15:59702 ssl_errors::ErrorInfo::GetErrorsForCertStatus(
jam8ae7cad2016-09-08 23:55:21703 certificate_, security_info.cert_status, url, &errors);
[email protected]03ef4b2a2012-03-06 15:04:20704 for (size_t i = 0; i < errors.size(); ++i) {
705 site_identity_details_ += bullet;
706 site_identity_details_ += errors[i].short_description();
707 }
708
estarka3121f6b2015-09-18 21:15:59709 if (security_info.cert_status & net::CERT_STATUS_NON_UNIQUE_NAME) {
[email protected]03ef4b2a2012-03-06 15:04:20710 site_identity_details_ += ASCIIToUTF16("\n\n");
lgarron1a6300d2017-03-18 03:33:04711 site_identity_details_ +=
712 l10n_util::GetStringUTF16(IDS_PAGE_INFO_SECURITY_TAB_NON_UNIQUE_NAME);
[email protected]03ef4b2a2012-03-06 15:04:20713 }
714 }
715
716 // Site Connection
717 // We consider anything less than 80 bits encryption to be weak encryption.
718 // TODO(wtc): Bug 1198735: report mixed/unsafe content for unencrypted and
719 // weakly encrypted connections.
720 site_connection_status_ = SITE_CONNECTION_STATUS_UNKNOWN;
721
jshin1fb76462016-04-05 22:13:03722 base::string16 subject_name(GetSimpleSiteName(url));
palmer153af982015-09-15 02:04:19723 if (subject_name.empty()) {
724 subject_name.assign(
725 l10n_util::GetStringUTF16(IDS_PAGE_INFO_SECURITY_TAB_UNKNOWN_PARTY));
726 }
727
jam8ae7cad2016-09-08 23:55:21728 if (!security_info.certificate || !security_info.scheme_is_cryptographic) {
estarka3121f6b2015-09-18 21:15:59729 // Page is still loading (so SSL status is not yet available) or
730 // loaded over HTTP or loaded over HTTPS with no cert.
[email protected]1c1051d2014-05-10 11:39:58731 site_connection_status_ = SITE_CONNECTION_STATUS_UNENCRYPTED;
732
733 site_connection_details_.assign(l10n_util::GetStringFUTF16(
734 IDS_PAGE_INFO_SECURITY_TAB_NOT_ENCRYPTED_CONNECTION_TEXT,
735 subject_name));
estarka3121f6b2015-09-18 21:15:59736 } else if (security_info.security_bits < 0) {
737 // Security strength is unknown. Say nothing.
[email protected]03ef4b2a2012-03-06 15:04:20738 site_connection_status_ = SITE_CONNECTION_STATUS_ENCRYPTED_ERROR;
estarka3121f6b2015-09-18 21:15:59739 } else if (security_info.security_bits == 0) {
esecklercac56b62016-11-16 13:49:44740 DCHECK_NE(security_info.security_level, security_state::NONE);
[email protected]03ef4b2a2012-03-06 15:04:20741 site_connection_status_ = SITE_CONNECTION_STATUS_ENCRYPTED_ERROR;
742 site_connection_details_.assign(l10n_util::GetStringFUTF16(
743 IDS_PAGE_INFO_SECURITY_TAB_NOT_ENCRYPTED_CONNECTION_TEXT,
744 subject_name));
[email protected]03ef4b2a2012-03-06 15:04:20745 } else {
746 site_connection_status_ = SITE_CONNECTION_STATUS_ENCRYPTED;
Adam Langley71c2b59b2014-11-13 00:34:22747
lgarron3e2c33e2016-08-25 06:33:43748 if (security_info.obsolete_ssl_status == net::OBSOLETE_SSL_NONE) {
Adam Langley71c2b59b2014-11-13 00:34:22749 site_connection_details_.assign(l10n_util::GetStringFUTF16(
lgarron1a6300d2017-03-18 03:33:04750 IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTED_CONNECTION_TEXT, subject_name));
Adam Langley71c2b59b2014-11-13 00:34:22751 } else {
752 site_connection_details_.assign(l10n_util::GetStringFUTF16(
753 IDS_PAGE_INFO_SECURITY_TAB_WEAK_ENCRYPTION_CONNECTION_TEXT,
754 subject_name));
755 }
756
thestig4427f13b2017-06-20 20:42:47757 ReportAnyInsecureContent(security_info, &site_connection_status_,
758 &site_connection_details_);
[email protected]03ef4b2a2012-03-06 15:04:20759 }
760
avi655876a2015-12-25 07:18:15761 uint16_t cipher_suite =
estarka3121f6b2015-09-18 21:15:59762 net::SSLConnectionStatusToCipherSuite(security_info.connection_status);
763 if (security_info.security_bits > 0 && cipher_suite) {
[email protected]03ef4b2a2012-03-06 15:04:20764 int ssl_version =
estarka3121f6b2015-09-18 21:15:59765 net::SSLConnectionStatusToVersion(security_info.connection_status);
[email protected]03ef4b2a2012-03-06 15:04:20766 const char* ssl_version_str;
767 net::SSLVersionToString(&ssl_version_str, ssl_version);
768 site_connection_details_ += ASCIIToUTF16("\n\n");
769 site_connection_details_ += l10n_util::GetStringFUTF16(
lgarron1a6300d2017-03-18 03:33:04770 IDS_PAGE_INFO_SECURITY_TAB_SSL_VERSION, ASCIIToUTF16(ssl_version_str));
[email protected]03ef4b2a2012-03-06 15:04:20771
[email protected]03ef4b2a2012-03-06 15:04:20772 const char *key_exchange, *cipher, *mac;
davidben56a8aece2016-10-14 18:20:56773 bool is_aead, is_tls13;
774 net::SSLCipherSuiteToStrings(&key_exchange, &cipher, &mac, &is_aead,
775 &is_tls13, cipher_suite);
[email protected]03ef4b2a2012-03-06 15:04:20776
777 site_connection_details_ += ASCIIToUTF16("\n\n");
[email protected]b6c1d9e82013-06-12 17:26:57778 if (is_aead) {
davidben56a8aece2016-10-14 18:20:56779 if (is_tls13) {
780 // For TLS 1.3 ciphers, report the group (historically, curve) as the
781 // key exchange.
782 key_exchange = SSL_get_curve_name(security_info.key_exchange_group);
783 if (!key_exchange) {
784 NOTREACHED();
785 key_exchange = "";
786 }
787 }
[email protected]b6c1d9e82013-06-12 17:26:57788 site_connection_details_ += l10n_util::GetStringFUTF16(
789 IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTION_DETAILS_AEAD,
790 ASCIIToUTF16(cipher), ASCIIToUTF16(key_exchange));
791 } else {
792 site_connection_details_ += l10n_util::GetStringFUTF16(
lgarron1a6300d2017-03-18 03:33:04793 IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTION_DETAILS, ASCIIToUTF16(cipher),
794 ASCIIToUTF16(mac), ASCIIToUTF16(key_exchange));
[email protected]b6c1d9e82013-06-12 17:26:57795 }
[email protected]03ef4b2a2012-03-06 15:04:20796 }
[email protected]e583f752012-08-30 13:26:21797
[email protected]71cd5ef2014-08-13 21:22:04798 // Check if a user decision has been made to allow or deny certificates with
799 // errors on this site.
800 ChromeSSLHostStateDelegate* delegate =
estark7c6bfbf2015-09-16 22:20:50801 ChromeSSLHostStateDelegateFactory::GetForProfile(profile_);
[email protected]71cd5ef2014-08-13 21:22:04802 DCHECK(delegate);
jwwf806c362015-06-02 02:00:40803 // Only show an SSL decision revoke button if the user has chosen to bypass
804 // SSL host errors for this host in the past.
805 show_ssl_decision_revoke_button_ = delegate->HasAllowException(url.host());
[email protected]03ef4b2a2012-03-06 15:04:20806}
[email protected]0b9fdd72012-04-04 10:00:33807
lgarron617a30f32017-03-24 21:42:07808void PageInfo::PresentSitePermissions() {
[email protected]df818272012-04-20 13:10:50809 PermissionInfoList permission_info_list;
reillyg85f57db2016-01-12 23:14:38810 ChosenObjectInfoList chosen_object_info_list;
[email protected]df818272012-04-20 13:10:50811
lgarron617a30f32017-03-24 21:42:07812 PageInfoUI::PermissionInfo permission_info;
[email protected]df818272012-04-20 13:10:50813 for (size_t i = 0; i < arraysize(kPermissionType); ++i) {
814 permission_info.type = kPermissionType[i];
815
816 content_settings::SettingInfo info;
dcheng9603ab92016-04-08 04:17:32817 std::unique_ptr<base::Value> value = content_settings_->GetWebsiteSetting(
818 site_url_, site_url_, permission_info.type, std::string(), &info);
sashab2b2a314f2015-01-17 06:42:21819 DCHECK(value.get());
jdoerrie76cee9c2017-10-06 22:42:42820 if (value->type() == base::Value::Type::INTEGER) {
sashab2b2a314f2015-01-17 06:42:21821 permission_info.setting =
822 content_settings::ValueToContentSetting(value.get());
[email protected]fe4686a2012-10-19 15:38:26823 } else {
sashab2b2a314f2015-01-17 06:42:21824 NOTREACHED();
[email protected]fe4686a2012-10-19 15:38:26825 }
826
[email protected]8bdf45c32012-08-04 00:12:55827 permission_info.source = info.source;
johnme9ed93882016-01-15 01:13:28828 permission_info.is_incognito = profile_->IsOffTheRecord();
[email protected]df818272012-04-20 13:10:50829
[email protected]b1d113d2012-06-27 21:27:34830 if (info.primary_pattern == ContentSettingsPattern::Wildcard() &&
sashab2b2a314f2015-01-17 06:42:21831 info.secondary_pattern == ContentSettingsPattern::Wildcard()) {
[email protected]b1d113d2012-06-27 21:27:34832 permission_info.default_setting = permission_info.setting;
833 permission_info.setting = CONTENT_SETTING_DEFAULT;
834 } else {
835 permission_info.default_setting =
836 content_settings_->GetDefaultContentSetting(permission_info.type,
837 NULL);
[email protected]df818272012-04-20 13:10:50838 }
palmer0da10b32015-02-11 00:42:19839
patricialor2a4f41a2017-03-08 02:52:56840 // For permissions that are still prompting the user and haven't been
841 // explicitly set by another source, check its embargo status.
842 if (PermissionUtil::IsPermission(permission_info.type) &&
843 permission_info.setting == CONTENT_SETTING_DEFAULT &&
844 permission_info.source ==
845 content_settings::SettingSource::SETTING_SOURCE_USER) {
846 // TODO(raymes): Use GetPermissionStatus() to retrieve information
847 // about *all* permissions once it has default behaviour implemented for
848 // ContentSettingTypes that aren't permissions.
849 PermissionResult permission_result =
850 PermissionManager::Get(profile_)->GetPermissionStatus(
851 permission_info.type, site_url_, site_url_);
852
853 // If under embargo, update |permission_info| to reflect that.
854 if (permission_result.content_setting == CONTENT_SETTING_BLOCK &&
Timothy Loh8fbdac52018-03-15 03:34:30855 permission_result.source ==
856 PermissionStatusSource::MULTIPLE_DISMISSALS) {
patricialor2a4f41a2017-03-08 02:52:56857 permission_info.setting = permission_result.content_setting;
Timothy Loh8fbdac52018-03-15 03:34:30858 }
patricialor2a4f41a2017-03-08 02:52:56859 }
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}