blob: 216301a9119cedcb302d1b237f8fb92501603ced [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"
avi09dd4d02016-10-14 20:40:0918#include "base/memory/ptr_util.h"
[email protected]71cd5ef2014-08-13 21:22:0419#include "base/metrics/field_trial.h"
asvitkine75036032016-09-01 20:49:3420#include "base/metrics/histogram_macros.h"
Tommy Steimeldea90f72017-11-07 20:58:0321#include "base/metrics/user_metrics.h"
[email protected]3ea1b182013-02-08 22:38:4122#include "base/strings/string_number_conversions.h"
[email protected]774cc3c2013-06-07 20:26:4523#include "base/strings/utf_string_conversions.h"
[email protected]0b9fdd72012-04-04 10:00:3324#include "base/values.h"
jialiul02aad2d2015-04-01 18:56:0325#include "chrome/browser/browser_process.h"
[email protected]6b8a3c742014-07-25 00:25:3526#include "chrome/browser/browsing_data/browsing_data_channel_id_helper.h"
[email protected]b0cb5e82012-07-19 19:22:4727#include "chrome/browser/browsing_data/browsing_data_cookie_helper.h"
28#include "chrome/browser/browsing_data/browsing_data_database_helper.h"
29#include "chrome/browser/browsing_data/browsing_data_file_system_helper.h"
30#include "chrome/browser/browsing_data/browsing_data_indexed_db_helper.h"
31#include "chrome/browser/browsing_data/browsing_data_local_storage_helper.h"
peconn5100d432015-09-16 12:03:0832#include "chrome/browser/content_settings/host_content_settings_map_factory.h"
vabrbab3ffcb2016-10-04 10:08:1033#include "chrome/browser/content_settings/local_shared_objects_container.h"
[email protected]77a91c72012-08-13 16:19:3434#include "chrome/browser/history/history_service_factory.h"
palmerf2cba0d2015-08-27 23:15:0635#include "chrome/browser/infobars/infobar_service.h"
reillyg85f57db2016-01-12 23:14:3836#include "chrome/browser/permissions/chooser_context_base.h"
patricialor7131c1fe2017-04-07 01:25:5237#include "chrome/browser/permissions/permission_decision_auto_blocker.h"
patricialor2a4f41a2017-03-08 02:52:5638#include "chrome/browser/permissions/permission_manager.h"
39#include "chrome/browser/permissions/permission_result.h"
tsergeantf1e89352016-01-15 20:34:5440#include "chrome/browser/permissions/permission_uma_util.h"
41#include "chrome/browser/permissions/permission_util.h"
[email protected]03ef4b2a2012-03-06 15:04:2042#include "chrome/browser/profiles/profile.h"
Jialiu Lin11e18542017-08-14 18:16:2643#include "chrome/browser/safe_browsing/safe_browsing_service.h"
[email protected]71cd5ef2014-08-13 21:22:0444#include "chrome/browser/ssl/chrome_ssl_host_state_delegate.h"
45#include "chrome/browser/ssl/chrome_ssl_host_state_delegate_factory.h"
lgarron617a30f32017-03-24 21:42:0746#include "chrome/browser/ui/page_info/page_info_ui.h"
reillyg85f57db2016-01-12 23:14:3847#include "chrome/browser/usb/usb_chooser_context.h"
48#include "chrome/browser/usb/usb_chooser_context_factory.h"
Patricia Lora21a04cf2017-06-05 02:53:2949#include "chrome/common/chrome_features.h"
[email protected]71cd5ef2014-08-13 21:22:0450#include "chrome/common/chrome_switches.h"
jsbellddb849e2015-08-27 00:12:5651#include "chrome/common/url_constants.h"
reillyg85f57db2016-01-12 23:14:3852#include "chrome/grit/theme_resources.h"
Patti0601e532017-09-20 08:39:3053#include "components/content_settings/core/browser/content_settings_registry.h"
mukai8eaec822014-10-25 17:53:1654#include "components/content_settings/core/browser/content_settings_utils.h"
55#include "components/content_settings/core/browser/host_content_settings_map.h"
palmer0da10b32015-02-11 00:42:1956#include "components/content_settings/core/common/content_settings.h"
vasiliif62dbf92014-09-05 10:23:1357#include "components/content_settings/core/common/content_settings_pattern.h"
tbansal08a0e3e2017-06-30 21:30:0858#include "components/content_settings/core/common/content_settings_utils.h"
nzolghadrd87a308d2016-12-07 15:45:5659#include "components/rappor/public/rappor_utils.h"
60#include "components/rappor/rappor_service_impl.h"
felt2493b4452015-09-17 20:33:5961#include "components/ssl_errors/error_info.h"
thestig4a2e88e2016-08-27 23:23:5162#include "components/strings/grit/components_chromium_strings.h"
63#include "components/strings/grit/components_strings.h"
melandory7be36d312017-03-29 15:51:1264#include "components/subresource_filter/core/browser/subresource_filter_features.h"
palmer153af982015-09-15 02:04:1965#include "components/url_formatter/elide_url.h"
[email protected]0b9fdd72012-04-04 10:00:3366#include "content/public/browser/browser_thread.h"
[email protected]eb2140c2013-07-29 12:37:3467#include "content/public/common/content_switches.h"
[email protected]03ef4b2a2012-03-06 15:04:2068#include "content/public/common/url_constants.h"
[email protected]6e7845ae2013-03-29 21:48:1169#include "net/cert/cert_status_flags.h"
70#include "net/cert/x509_certificate.h"
[email protected]536fd0b2013-03-14 17:41:5771#include "net/ssl/ssl_cipher_suite_names.h"
72#include "net/ssl/ssl_connection_status_flags.h"
tfarina29a3a1742016-10-28 18:47:3373#include "third_party/boringssl/src/include/openssl/ssl.h"
[email protected]03ef4b2a2012-03-06 15:04:2074#include "ui/base/l10n/l10n_util.h"
Patricia Lora21a04cf2017-06-05 02:53:2975#include "url/origin.h"
[email protected]03ef4b2a2012-03-06 15:04:2076
[email protected]24a9f1c92013-11-13 12:33:3777#if defined(OS_CHROMEOS)
78#include "chrome/browser/chromeos/policy/policy_cert_service.h"
79#include "chrome/browser/chromeos/policy/policy_cert_service_factory.h"
80#endif
81
estade3feb83f2015-09-01 23:00:4982#if !defined(OS_ANDROID)
Christopher Lam0dbac2b2017-11-14 07:12:1083#include "chrome/browser/ui/browser_finder.h"
84#include "chrome/browser/ui/chrome_pages.h"
mgiucaa319f212016-01-14 03:30:1185#include "chrome/browser/ui/exclusive_access/exclusive_access_manager.h"
lgarron617a30f32017-03-24 21:42:0786#include "chrome/browser/ui/page_info/page_info_infobar_delegate.h"
estade3feb83f2015-09-01 23:00:4987#endif
88
Jialiu Lin11e18542017-08-14 18:16:2689#if defined(SAFE_BROWSING_DB_LOCAL)
Jialiu Lin0d8cc722017-09-19 01:01:5190#include "chrome/browser/safe_browsing/chrome_password_protection_service.h"
Jialiu Lin11e18542017-08-14 18:16:2691#endif
92
[email protected]ab6df3b12013-12-24 23:32:2693using base::ASCIIToUTF16;
94using base::UTF8ToUTF16;
[email protected]f729d7a2013-12-26 07:07:5695using base::UTF16ToUTF8;
[email protected]0b9fdd72012-04-04 10:00:3396using content::BrowserThread;
97
98namespace {
99
lgarron617a30f32017-03-24 21:42:07100// The list of content settings types to display on the Page Info UI. THE
csharrisonad1eaa6c2017-05-11 17:14:38101// ORDER OF THESE ITEMS IS IMPORTANT and comes from https://crbug.com/610358. To
102// propose changing it, email [email protected].
[email protected]0b9fdd72012-04-04 10:00:33103ContentSettingsType kPermissionType[] = {
sashab2b2a314f2015-01-17 06:42:21104 CONTENT_SETTINGS_TYPE_GEOLOCATION,
sashab2b2a314f2015-01-17 06:42:21105 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA,
106 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC,
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;
184#endif
185
Patti0601e532017-09-20 08:39:30186#if !defined(OS_ANDROID)
187 // Autoplay is Android-only at the moment.
188 if (info.type == CONTENT_SETTINGS_TYPE_AUTOPLAY)
189 return false;
190#endif
191
shahriar rostamia9c769d2017-12-06 04:54:08192 // Show the content setting if it has been changed by the user since the last
193 // page load.
194 if (tab_specific_content_settings->HasContentSettingChangedViaPageInfo(
195 info.type)) {
196 return true;
197 }
198
199 // Show the content setting when it has a non-default value.
200 if (!IsPermissionFactoryDefault(content_settings, info))
201 return true;
202
203 return false;
mgiucaa319f212016-01-14 03:30:11204}
205
esecklercac56b62016-11-16 13:49:44206void CheckContentStatus(security_state::ContentStatus content_status,
estark00e83f12016-08-19 18:24:04207 bool* displayed,
208 bool* ran) {
209 switch (content_status) {
esecklercac56b62016-11-16 13:49:44210 case security_state::CONTENT_STATUS_DISPLAYED:
estark00e83f12016-08-19 18:24:04211 *displayed = true;
212 break;
esecklercac56b62016-11-16 13:49:44213 case security_state::CONTENT_STATUS_RAN:
estark00e83f12016-08-19 18:24:04214 *ran = true;
215 break;
esecklercac56b62016-11-16 13:49:44216 case security_state::CONTENT_STATUS_DISPLAYED_AND_RAN:
estark00e83f12016-08-19 18:24:04217 *displayed = true;
218 *ran = true;
219 break;
esecklercac56b62016-11-16 13:49:44220 case security_state::CONTENT_STATUS_UNKNOWN:
221 case security_state::CONTENT_STATUS_NONE:
estark00e83f12016-08-19 18:24:04222 break;
223 }
224}
225
elawrenceb2ac2a232017-03-27 21:46:25226// If the |security_info| indicates that mixed content or certificate errors
227// were present, update |connection_status| and |connection_details|.
228void ReportAnyInsecureContent(const security_state::SecurityInfo& security_info,
thestig4427f13b2017-06-20 20:42:47229 PageInfo::SiteConnectionStatus* connection_status,
230 base::string16* connection_details) {
elawrenceb2ac2a232017-03-27 21:46:25231 bool displayed_insecure_content = false;
232 bool ran_insecure_content = false;
233 CheckContentStatus(security_info.mixed_content_status,
234 &displayed_insecure_content, &ran_insecure_content);
235 // Only note subresources with certificate errors if the main resource was
236 // loaded without major certificate errors. If the main resource had a
237 // certificate error, then it would not be that useful (and could
238 // potentially be confusing) to warn about subresources that had certificate
239 // errors too.
240 if (!net::IsCertStatusError(security_info.cert_status) ||
241 net::IsCertStatusMinorError(security_info.cert_status)) {
242 CheckContentStatus(security_info.content_with_cert_errors_status,
243 &displayed_insecure_content, &ran_insecure_content);
244 }
245
246 // Only one insecure content warning is displayed; show the most severe.
247 if (ran_insecure_content) {
thestig4427f13b2017-06-20 20:42:47248 *connection_status =
elawrenceb2ac2a232017-03-27 21:46:25249 PageInfo::SITE_CONNECTION_STATUS_INSECURE_ACTIVE_SUBRESOURCE;
thestig4427f13b2017-06-20 20:42:47250 connection_details->assign(l10n_util::GetStringFUTF16(
251 IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTED_SENTENCE_LINK, *connection_details,
elawrenceb2ac2a232017-03-27 21:46:25252 l10n_util::GetStringUTF16(
253 IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTED_INSECURE_CONTENT_ERROR)));
estark00e83f12016-08-19 18:24:04254 return;
255 }
elawrenceb2ac2a232017-03-27 21:46:25256 if (security_info.contained_mixed_form) {
thestig4427f13b2017-06-20 20:42:47257 *connection_status = PageInfo::SITE_CONNECTION_STATUS_INSECURE_FORM_ACTION;
258 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_FORM_WARNING)));
262 return;
263 }
264 if (displayed_insecure_content) {
thestig4427f13b2017-06-20 20:42:47265 *connection_status =
elawrenceb2ac2a232017-03-27 21:46:25266 PageInfo::SITE_CONNECTION_STATUS_INSECURE_PASSIVE_SUBRESOURCE;
thestig4427f13b2017-06-20 20:42:47267 connection_details->assign(l10n_util::GetStringFUTF16(
268 IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTED_SENTENCE_LINK, *connection_details,
elawrenceb2ac2a232017-03-27 21:46:25269 l10n_util::GetStringUTF16(
270 IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTED_INSECURE_CONTENT_WARNING)));
271 }
estark00e83f12016-08-19 18:24:04272}
273
estarkfcfccdb82016-11-14 02:17:29274void GetSiteIdentityByMaliciousContentStatus(
esecklercac56b62016-11-16 13:49:44275 security_state::MaliciousContentStatus malicious_content_status,
lgarron617a30f32017-03-24 21:42:07276 PageInfo::SiteIdentityStatus* status,
estarkfcfccdb82016-11-14 02:17:29277 base::string16* details) {
278 switch (malicious_content_status) {
esecklercac56b62016-11-16 13:49:44279 case security_state::MALICIOUS_CONTENT_STATUS_NONE:
estarkfcfccdb82016-11-14 02:17:29280 NOTREACHED();
281 break;
esecklercac56b62016-11-16 13:49:44282 case security_state::MALICIOUS_CONTENT_STATUS_MALWARE:
lgarron617a30f32017-03-24 21:42:07283 *status = PageInfo::SITE_IDENTITY_STATUS_MALWARE;
lgarronfc1d5e52017-05-03 23:15:21284 *details = l10n_util::GetStringUTF16(IDS_PAGE_INFO_MALWARE_DETAILS);
estarkfcfccdb82016-11-14 02:17:29285 break;
esecklercac56b62016-11-16 13:49:44286 case security_state::MALICIOUS_CONTENT_STATUS_SOCIAL_ENGINEERING:
lgarron617a30f32017-03-24 21:42:07287 *status = PageInfo::SITE_IDENTITY_STATUS_SOCIAL_ENGINEERING;
lgarron1a6300d2017-03-18 03:33:04288 *details =
lgarronfc1d5e52017-05-03 23:15:21289 l10n_util::GetStringUTF16(IDS_PAGE_INFO_SOCIAL_ENGINEERING_DETAILS);
estarkfcfccdb82016-11-14 02:17:29290 break;
esecklercac56b62016-11-16 13:49:44291 case security_state::MALICIOUS_CONTENT_STATUS_UNWANTED_SOFTWARE:
lgarron617a30f32017-03-24 21:42:07292 *status = PageInfo::SITE_IDENTITY_STATUS_UNWANTED_SOFTWARE;
lgarron1a6300d2017-03-18 03:33:04293 *details =
lgarronfc1d5e52017-05-03 23:15:21294 l10n_util::GetStringUTF16(IDS_PAGE_INFO_UNWANTED_SOFTWARE_DETAILS);
estarkfcfccdb82016-11-14 02:17:29295 break;
Jialiu Lin11e18542017-08-14 18:16:26296 case security_state::MALICIOUS_CONTENT_STATUS_PASSWORD_REUSE:
Jialiu Linfeb6bb32017-08-30 00:21:36297#if defined(SAFE_BROWSING_DB_LOCAL)
Jialiu Lin11e18542017-08-14 18:16:26298 *status = PageInfo::SITE_IDENTITY_STATUS_PASSWORD_REUSE;
299 *details =
300 l10n_util::GetStringUTF16(IDS_PAGE_INFO_CHANGE_PASSWORD_DETAILS);
301#endif
302 break;
estarkfcfccdb82016-11-14 02:17:29303 }
304}
305
jshin1fb76462016-04-05 22:13:03306base::string16 GetSimpleSiteName(const GURL& url) {
benwells2337b8102016-04-20 01:53:53307 return url_formatter::FormatUrlForSecurityDisplay(
308 url, url_formatter::SchemeDisplay::OMIT_HTTP_AND_HTTPS);
palmer153af982015-09-15 02:04:19309}
310
reillyg85f57db2016-01-12 23:14:38311ChooserContextBase* GetUsbChooserContext(Profile* profile) {
312 return UsbChooserContextFactory::GetForProfile(profile);
313}
314
315// The list of chooser types that need to display entries in the Website
316// Settings UI. THE ORDER OF THESE ITEMS IS IMPORTANT. To propose changing it,
317// email [email protected].
Andrew Grieved1978b0e2017-07-28 15:53:41318const PageInfo::ChooserUIInfo kChooserUIInfo[] = {
reillyg58f82ab2016-08-03 01:49:52319 {CONTENT_SETTINGS_TYPE_USB_CHOOSER_DATA, &GetUsbChooserContext,
lgarron617a30f32017-03-24 21:42:07320 IDR_BLOCKED_USB, IDR_ALLOWED_USB, IDS_PAGE_INFO_USB_DEVICE_LABEL,
321 IDS_PAGE_INFO_DELETE_USB_DEVICE, "name"},
reillyg85f57db2016-01-12 23:14:38322};
323
[email protected]0b9fdd72012-04-04 10:00:33324} // namespace
325
lgarron617a30f32017-03-24 21:42:07326PageInfo::PageInfo(PageInfoUI* ui,
327 Profile* profile,
328 TabSpecificContentSettings* tab_specific_content_settings,
329 content::WebContents* web_contents,
330 const GURL& url,
331 const security_state::SecurityInfo& security_info)
[email protected]df818272012-04-20 13:10:50332 : TabSpecificContentSettings::SiteDataObserver(
333 tab_specific_content_settings),
dominicknbdd53b5f2016-09-28 01:08:13334 content::WebContentsObserver(web_contents),
[email protected]df818272012-04-20 13:10:50335 ui_(ui),
[email protected]66f157312012-08-01 13:50:26336 show_info_bar_(false),
[email protected]0b9fdd72012-04-04 10:00:33337 site_url_(url),
338 site_identity_status_(SITE_IDENTITY_STATUS_UNKNOWN),
[email protected]03ef4b2a2012-03-06 15:04:20339 site_connection_status_(SITE_CONNECTION_STATUS_UNKNOWN),
alshabalin5e894c12016-10-25 06:47:46340 show_ssl_decision_revoke_button_(false),
peconn5100d432015-09-16 12:03:08341 content_settings_(HostContentSettingsMapFactory::GetForProfile(profile)),
[email protected]71cd5ef2014-08-13 21:22:04342 chrome_ssl_host_state_delegate_(
jww1ed8ea72014-09-02 20:43:25343 ChromeSSLHostStateDelegateFactory::GetForProfile(profile)),
palmer153af982015-09-15 02:04:19344 did_revoke_user_ssl_decisions_(false),
estark8d67cd7a2016-10-24 05:06:41345 profile_(profile),
Jialiu Lin11e18542017-08-14 18:16:26346 security_level_(security_state::NONE),
Jialiu Linfeb6bb32017-08-30 00:21:36347#if defined(SAFE_BROWSING_DB_LOCAL)
Jialiu Lin0d8cc722017-09-19 01:01:51348 password_protection_service_(
349 safe_browsing::ChromePasswordProtectionService::
350 GetPasswordProtectionService(profile_)),
Jialiu Lin11e18542017-08-14 18:16:26351#endif
352 show_change_password_buttons_(false) {
estarka3121f6b2015-09-18 21:15:59353 Init(url, security_info);
[email protected]0b9fdd72012-04-04 10:00:33354
355 PresentSitePermissions();
[email protected]24c8818c2012-04-25 09:57:41356 PresentSiteIdentity();
Pattie8c616202017-09-29 07:58:03357 PresentSiteData();
[email protected]e22d64f2012-09-10 09:03:23358
lgarron617a30f32017-03-24 21:42:07359 // Every time the Page Info UI is opened a |PageInfo| object is
360 // created. So this counts how ofter the Page Info UI is opened.
361 RecordPageInfoAction(PAGE_INFO_OPENED);
[email protected]03ef4b2a2012-03-06 15:04:20362}
363
Carlos ILe5dfda72017-09-21 02:33:05364PageInfo::~PageInfo() {
365 // Check if Re-enable warnings button was visible, if so, log on UMA whether
366 // it was clicked or not.
367 SSLCertificateDecisionsDidRevoke user_decision =
368 did_revoke_user_ssl_decisions_ ? USER_CERT_DECISIONS_REVOKED
369 : USER_CERT_DECISIONS_NOT_REVOKED;
370 if (show_ssl_decision_revoke_button_) {
371 UMA_HISTOGRAM_ENUMERATION("interstitial.ssl.did_user_revoke_decisions2",
372 user_decision,
373 END_OF_SSL_CERTIFICATE_DECISIONS_DID_REVOKE_ENUM);
374 }
375}
[email protected]03ef4b2a2012-03-06 15:04:20376
lgarron617a30f32017-03-24 21:42:07377void PageInfo::RecordPageInfoAction(PageInfoAction action) {
378 UMA_HISTOGRAM_ENUMERATION("WebsiteSettings.Action", action, PAGE_INFO_COUNT);
lgarron04a93502014-11-04 22:25:04379
estark8d67cd7a2016-10-24 05:06:41380 std::string histogram_name;
estark8d67cd7a2016-10-24 05:06:41381 if (site_url_.SchemeIsCryptographic()) {
esecklercac56b62016-11-16 13:49:44382 if (security_level_ == security_state::SECURE ||
383 security_level_ == security_state::EV_SECURE) {
estark8d67cd7a2016-10-24 05:06:41384 UMA_HISTOGRAM_ENUMERATION("Security.PageInfo.Action.HttpsUrl.Valid",
lgarron617a30f32017-03-24 21:42:07385 action, PAGE_INFO_COUNT);
esecklercac56b62016-11-16 13:49:44386 } else if (security_level_ == security_state::NONE) {
estark8d67cd7a2016-10-24 05:06:41387 UMA_HISTOGRAM_ENUMERATION("Security.PageInfo.Action.HttpsUrl.Downgraded",
lgarron617a30f32017-03-24 21:42:07388 action, PAGE_INFO_COUNT);
esecklercac56b62016-11-16 13:49:44389 } else if (security_level_ == security_state::DANGEROUS) {
estark8d67cd7a2016-10-24 05:06:41390 UMA_HISTOGRAM_ENUMERATION("Security.PageInfo.Action.HttpsUrl.Dangerous",
lgarron617a30f32017-03-24 21:42:07391 action, PAGE_INFO_COUNT);
estark8d67cd7a2016-10-24 05:06:41392 }
393 return;
394 }
395
esecklercac56b62016-11-16 13:49:44396 if (security_level_ == security_state::HTTP_SHOW_WARNING) {
estark8d67cd7a2016-10-24 05:06:41397 UMA_HISTOGRAM_ENUMERATION("Security.PageInfo.Action.HttpUrl.Warning",
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.HttpUrl.Dangerous",
lgarron617a30f32017-03-24 21:42:07401 action, PAGE_INFO_COUNT);
estark8d67cd7a2016-10-24 05:06:41402 } else {
403 UMA_HISTOGRAM_ENUMERATION("Security.PageInfo.Action.HttpUrl.Neutral",
lgarron617a30f32017-03-24 21:42:07404 action, PAGE_INFO_COUNT);
lgarron04a93502014-11-04 22:25:04405 }
406}
407
lgarron617a30f32017-03-24 21:42:07408void PageInfo::OnSitePermissionChanged(ContentSettingsType type,
409 ContentSetting setting) {
shahriar rostamia9c769d2017-12-06 04:54:08410 tab_specific_content_settings()->ContentSettingChangedViaPageInfo(type);
411
[email protected]e22d64f2012-09-10 09:03:23412 // Count how often a permission for a specific content type is changed using
lgarron617a30f32017-03-24 21:42:07413 // the Page Info UI.
raymes4a13d432015-09-08 00:44:07414 size_t num_values;
415 int histogram_value = ContentSettingTypeToHistogramValue(type, &num_values);
dchengf6f4e4942017-03-30 23:55:57416 UMA_HISTOGRAM_EXACT_LINEAR("WebsiteSettings.OriginInfo.PermissionChanged",
417 histogram_value, num_values);
sashab9debecd2014-12-18 04:15:56418
419 if (setting == ContentSetting::CONTENT_SETTING_ALLOW) {
dchengf6f4e4942017-03-30 23:55:57420 UMA_HISTOGRAM_EXACT_LINEAR(
sashab9debecd2014-12-18 04:15:56421 "WebsiteSettings.OriginInfo.PermissionChanged.Allowed", histogram_value,
raymes4a13d432015-09-08 00:44:07422 num_values);
tommycli34cf29bf2016-09-08 05:46:25423
424 if (type == CONTENT_SETTINGS_TYPE_PLUGINS) {
425 rappor::SampleDomainAndRegistryFromGURL(
426 g_browser_process->rappor_service(),
427 "ContentSettings.Plugins.AddedAllowException", site_url_);
428 }
sashab9debecd2014-12-18 04:15:56429 } else if (setting == ContentSetting::CONTENT_SETTING_BLOCK) {
dchengf6f4e4942017-03-30 23:55:57430 UMA_HISTOGRAM_EXACT_LINEAR(
sashab9debecd2014-12-18 04:15:56431 "WebsiteSettings.OriginInfo.PermissionChanged.Blocked", histogram_value,
raymes4a13d432015-09-08 00:44:07432 num_values);
sashab9debecd2014-12-18 04:15:56433 }
[email protected]e22d64f2012-09-10 09:03:23434
lgarron04a93502014-11-04 22:25:04435 // This is technically redundant given the histogram above, but putting the
436 // total count of permission changes in another histogram makes it easier to
lgarron026e9c42017-04-07 20:09:31437 // compare it against other kinds of actions in Page Info.
lgarron617a30f32017-03-24 21:42:07438 RecordPageInfoAction(PAGE_INFO_CHANGED_PERMISSION);
Tommy Steimeldea90f72017-11-07 20:58:03439 if (type == CONTENT_SETTINGS_TYPE_SOUND) {
440 ContentSetting default_setting =
441 content_settings_->GetDefaultContentSetting(CONTENT_SETTINGS_TYPE_SOUND,
442 nullptr);
443 bool mute = (setting == CONTENT_SETTING_BLOCK) ||
444 (setting == CONTENT_SETTING_DEFAULT &&
445 default_setting == CONTENT_SETTING_BLOCK);
446 if (mute) {
447 base::RecordAction(
448 base::UserMetricsAction("SoundContentSetting.MuteBy.PageInfo"));
449 } else {
450 base::RecordAction(
451 base::UserMetricsAction("SoundContentSetting.UnmuteBy.PageInfo"));
452 }
453 }
lgarron04a93502014-11-04 22:25:04454
stefanocs8b3490cc2016-07-28 05:32:52455 PermissionUtil::ScopedRevocationReporter scoped_revocation_reporter(
patricialor7131c1fe2017-04-07 01:25:52456 profile_, site_url_, site_url_, type, PermissionSourceUI::OIB);
stefanocs8b3490cc2016-07-28 05:32:52457
patricialor7131c1fe2017-04-07 01:25:52458 // The permission may have been blocked due to being under embargo, so if it
459 // was changed away from BLOCK, clear embargo status if it exists.
460 if (setting != CONTENT_SETTING_BLOCK) {
461 PermissionDecisionAutoBlocker::GetForProfile(profile_)->RemoveEmbargoByUrl(
462 site_url_, type);
463 }
raymesfbaaaaa2015-11-10 02:20:40464 content_settings_->SetNarrowestContentSetting(site_url_, site_url_, type,
465 setting);
[email protected]df818272012-04-20 13:10:50466
Tommy Steimel97ee2f82017-11-01 21:39:52467 // When the sound setting is changed, no reload is necessary.
468 if (type != CONTENT_SETTINGS_TYPE_SOUND)
469 show_info_bar_ = true;
[email protected]2f45d542012-08-22 08:47:24470
471 // Refresh the UI to reflect the new setting.
472 PresentSitePermissions();
[email protected]df818272012-04-20 13:10:50473}
474
lgarron617a30f32017-03-24 21:42:07475void PageInfo::OnSiteChosenObjectDeleted(const ChooserUIInfo& ui_info,
476 const base::DictionaryValue& object) {
reillyg85f57db2016-01-12 23:14:38477 // TODO(reillyg): Create metrics for revocations. crbug.com/556845
478 ChooserContextBase* context = ui_info.get_context(profile_);
reillyg36a7fab32016-01-28 19:15:10479 const GURL origin = site_url_.GetOrigin();
480 context->RevokeObjectPermission(origin, origin, object);
reillyg85f57db2016-01-12 23:14:38481 show_info_bar_ = true;
482
483 // Refresh the UI to reflect the changed settings.
484 PresentSitePermissions();
485}
486
lgarron617a30f32017-03-24 21:42:07487void PageInfo::OnSiteDataAccessed() {
[email protected]df818272012-04-20 13:10:50488 PresentSiteData();
[email protected]0b9fdd72012-04-04 10:00:33489}
490
lgarron617a30f32017-03-24 21:42:07491void PageInfo::OnUIClosing() {
estade3feb83f2015-09-01 23:00:49492#if defined(OS_ANDROID)
493 NOTREACHED();
494#else
dominicknbdd53b5f2016-09-28 01:08:13495 if (show_info_bar_ && web_contents() && !web_contents()->IsBeingDestroyed()) {
palmerf2cba0d2015-08-27 23:15:06496 InfoBarService* infobar_service =
dominicknbdd53b5f2016-09-28 01:08:13497 InfoBarService::FromWebContents(web_contents());
palmerf2cba0d2015-08-27 23:15:06498 if (infobar_service)
lgarron617a30f32017-03-24 21:42:07499 PageInfoInfoBarDelegate::Create(infobar_service);
palmerf2cba0d2015-08-27 23:15:06500 }
estade3feb83f2015-09-01 23:00:49501#endif
jww1ed8ea72014-09-02 20:43:25502}
503
lgarron617a30f32017-03-24 21:42:07504void PageInfo::OnRevokeSSLErrorBypassButtonPressed() {
jww1ed8ea72014-09-02 20:43:25505 DCHECK(chrome_ssl_host_state_delegate_);
jww6a55df72014-09-05 19:59:29506 chrome_ssl_host_state_delegate_->RevokeUserAllowExceptionsHard(
507 site_url().host());
jww1ed8ea72014-09-02 20:43:25508 did_revoke_user_ssl_decisions_ = true;
[email protected]66f157312012-08-01 13:50:26509}
510
Patricia Lora21a04cf2017-06-05 02:53:29511void PageInfo::OpenSiteSettingsView() {
Christopher Lam0dbac2b2017-11-14 07:12:10512#if defined(OS_ANDROID)
513 NOTREACHED();
514#else
515 chrome::ShowSiteSettings(chrome::FindBrowserWithWebContents(web_contents()),
516 site_url());
Patricia Lora21a04cf2017-06-05 02:53:29517 RecordPageInfoAction(PageInfo::PAGE_INFO_SITE_SETTINGS_OPENED);
Christopher Lam0dbac2b2017-11-14 07:12:10518#endif
Patricia Lora21a04cf2017-06-05 02:53:29519}
520
Jialiu Lin11e18542017-08-14 18:16:26521void PageInfo::OnChangePasswordButtonPressed(
522 content::WebContents* web_contents) {
Jialiu Linfeb6bb32017-08-30 00:21:36523#if defined(SAFE_BROWSING_DB_LOCAL)
Jialiu Lin11e18542017-08-14 18:16:26524 DCHECK(password_protection_service_);
Jialiu Lin3fc7f38f2017-09-21 18:38:37525 password_protection_service_->OnUserAction(
Jialiu Lin11e18542017-08-14 18:16:26526 web_contents, safe_browsing::PasswordProtectionService::PAGE_INFO,
527 safe_browsing::PasswordProtectionService::CHANGE_PASSWORD);
528#endif
529}
530
531void PageInfo::OnWhitelistPasswordReuseButtonPressed(
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::MARK_AS_LEGITIMATE);
538#endif
539}
540
lgarron617a30f32017-03-24 21:42:07541void PageInfo::Init(const GURL& url,
542 const security_state::SecurityInfo& security_info) {
thestig0c55ee32017-06-20 22:17:51543#if !defined(OS_ANDROID)
meacerde53fcff2016-10-12 19:21:57544 // On desktop, internal URLs aren't handled by this class. Instead, a
lgarron026e9c42017-04-07 20:09:31545 // custom and simpler bubble is shown.
meacerde53fcff2016-10-12 19:21:57546 DCHECK(!url.SchemeIs(content::kChromeUIScheme) &&
547 !url.SchemeIs(content::kChromeDevToolsScheme) &&
548 !url.SchemeIs(content::kViewSourceScheme) &&
549 !url.SchemeIs(content_settings::kExtensionScheme));
550#endif
551
thestig0c55ee32017-06-20 22:17:51552 bool is_chrome_ui_native_scheme = false;
zpengdb4a58e2017-01-10 17:40:32553#if defined(OS_ANDROID)
thestig0c55ee32017-06-20 22:17:51554 is_chrome_ui_native_scheme = url.SchemeIs(chrome::kChromeUINativeScheme);
sashab97894ce2014-10-22 10:08:33555#endif
556
estark8d67cd7a2016-10-24 05:06:41557 security_level_ = security_info.security_level;
558
upendrag.gowda60886a6e2015-10-31 05:51:09559 if (url.SchemeIs(url::kAboutScheme)) {
560 // All about: URLs except about:blank are redirected.
561 DCHECK_EQ(url::kAboutBlankURL, url.spec());
562 site_identity_status_ = SITE_IDENTITY_STATUS_NO_CERT;
563 site_identity_details_ =
564 l10n_util::GetStringUTF16(IDS_PAGE_INFO_SECURITY_TAB_INSECURE_IDENTITY);
565 site_connection_status_ = SITE_CONNECTION_STATUS_UNENCRYPTED;
566 site_connection_details_ = l10n_util::GetStringFUTF16(
567 IDS_PAGE_INFO_SECURITY_TAB_NOT_ENCRYPTED_CONNECTION_TEXT,
568 UTF8ToUTF16(url.spec()));
569 return;
570 }
571
thestig0c55ee32017-06-20 22:17:51572 if (url.SchemeIs(content::kChromeUIScheme) || is_chrome_ui_native_scheme) {
[email protected]03ef4b2a2012-03-06 15:04:20573 site_identity_status_ = SITE_IDENTITY_STATUS_INTERNAL_PAGE;
574 site_identity_details_ =
575 l10n_util::GetStringUTF16(IDS_PAGE_INFO_INTERNAL_PAGE);
576 site_connection_status_ = SITE_CONNECTION_STATUS_INTERNAL_PAGE;
577 return;
578 }
579
[email protected]03ef4b2a2012-03-06 15:04:20580 // Identity section.
jam8ae7cad2016-09-08 23:55:21581 certificate_ = security_info.certificate;
[email protected]f61c1ce2012-05-09 13:55:11582
estarkfcfccdb82016-11-14 02:17:29583 if (security_info.malicious_content_status !=
esecklercac56b62016-11-16 13:49:44584 security_state::MALICIOUS_CONTENT_STATUS_NONE) {
estarkfcfccdb82016-11-14 02:17:29585 // The site has been flagged by Safe Browsing as dangerous.
586 GetSiteIdentityByMaliciousContentStatus(
587 security_info.malicious_content_status, &site_identity_status_,
588 &site_identity_details_);
Jialiu Lin11e18542017-08-14 18:16:26589 show_change_password_buttons_ =
590 security_info.malicious_content_status ==
591 security_state::MALICIOUS_CONTENT_STATUS_PASSWORD_REUSE;
estarkfcfccdb82016-11-14 02:17:29592 } else if (certificate_ &&
593 (!net::IsCertStatusError(security_info.cert_status) ||
594 net::IsCertStatusMinorError(security_info.cert_status))) {
595 // HTTPS with no or minor errors.
estarka3121f6b2015-09-18 21:15:59596 if (security_info.security_level ==
esecklercac56b62016-11-16 13:49:44597 security_state::SECURE_WITH_POLICY_INSTALLED_CERT) {
Eric Lawrence6758d1d2017-11-21 16:06:05598#if defined(OS_CHROMEOS)
[email protected]eaf3f322013-04-25 21:53:59599 site_identity_status_ = SITE_IDENTITY_STATUS_ADMIN_PROVIDED_CERT;
[email protected]24a9f1c92013-11-13 12:33:37600 site_identity_details_ = l10n_util::GetStringFUTF16(
601 IDS_CERT_POLICY_PROVIDED_CERT_MESSAGE, UTF8ToUTF16(url.host()));
Eric Lawrence6758d1d2017-11-21 16:06:05602#else
603 DCHECK(false) << "Policy certificates exist only on ChromeOS";
604#endif
estarka3121f6b2015-09-18 21:15:59605 } else if (net::IsCertStatusMinorError(security_info.cert_status)) {
[email protected]03ef4b2a2012-03-06 15:04:20606 site_identity_status_ = SITE_IDENTITY_STATUS_CERT_REVOCATION_UNKNOWN;
jam8ae7cad2016-09-08 23:55:21607 base::string16 issuer_name(
608 UTF8ToUTF16(certificate_->issuer().GetDisplayName()));
[email protected]03ef4b2a2012-03-06 15:04:20609 if (issuer_name.empty()) {
610 issuer_name.assign(l10n_util::GetStringUTF16(
611 IDS_PAGE_INFO_SECURITY_TAB_UNKNOWN_PARTY));
612 }
[email protected]94c74b42013-12-02 15:19:49613
[email protected]03ef4b2a2012-03-06 15:04:20614 site_identity_details_.assign(l10n_util::GetStringFUTF16(
estarkcf305562016-11-15 03:45:39615 IDS_PAGE_INFO_SECURITY_TAB_SECURE_IDENTITY_VERIFIED, issuer_name));
[email protected]03ef4b2a2012-03-06 15:04:20616
617 site_identity_details_ += ASCIIToUTF16("\n\n");
estarka3121f6b2015-09-18 21:15:59618 if (security_info.cert_status &
619 net::CERT_STATUS_UNABLE_TO_CHECK_REVOCATION) {
[email protected]03ef4b2a2012-03-06 15:04:20620 site_identity_details_ += l10n_util::GetStringUTF16(
621 IDS_PAGE_INFO_SECURITY_TAB_UNABLE_TO_CHECK_REVOCATION);
estarka3121f6b2015-09-18 21:15:59622 } else if (security_info.cert_status &
623 net::CERT_STATUS_NO_REVOCATION_MECHANISM) {
[email protected]03ef4b2a2012-03-06 15:04:20624 site_identity_details_ += l10n_util::GetStringUTF16(
625 IDS_PAGE_INFO_SECURITY_TAB_NO_REVOCATION_MECHANISM);
626 } else {
627 NOTREACHED() << "Need to specify string for this warning";
628 }
[email protected]03ef4b2a2012-03-06 15:04:20629 } else {
estarkcf305562016-11-15 03:45:39630 // No major or minor errors.
estarka3121f6b2015-09-18 21:15:59631 if (security_info.cert_status & net::CERT_STATUS_IS_EV) {
rsleevi4f8012722014-09-30 01:28:01632 // EV HTTPS page.
estarkcf305562016-11-15 03:45:39633 site_identity_status_ = SITE_IDENTITY_STATUS_EV_CERT;
jam8ae7cad2016-09-08 23:55:21634 DCHECK(!certificate_->subject().organization_names.empty());
635 organization_name_ =
636 UTF8ToUTF16(certificate_->subject().organization_names[0]);
rsleevi4f8012722014-09-30 01:28:01637 // An EV Cert is required to have a city (localityName) and country but
638 // state is "if any".
jam8ae7cad2016-09-08 23:55:21639 DCHECK(!certificate_->subject().locality_name.empty());
640 DCHECK(!certificate_->subject().country_name.empty());
rsleevi4f8012722014-09-30 01:28:01641 base::string16 locality;
jam8ae7cad2016-09-08 23:55:21642 if (!certificate_->subject().state_or_province_name.empty()) {
rsleevi4f8012722014-09-30 01:28:01643 locality = l10n_util::GetStringFUTF16(
lgarronfc1d5e52017-05-03 23:15:21644 IDS_PAGE_INFO_ADDRESS,
jam8ae7cad2016-09-08 23:55:21645 UTF8ToUTF16(certificate_->subject().locality_name),
646 UTF8ToUTF16(certificate_->subject().state_or_province_name),
647 UTF8ToUTF16(certificate_->subject().country_name));
rsleevi4f8012722014-09-30 01:28:01648 } else {
649 locality = l10n_util::GetStringFUTF16(
lgarronfc1d5e52017-05-03 23:15:21650 IDS_PAGE_INFO_PARTIAL_ADDRESS,
jam8ae7cad2016-09-08 23:55:21651 UTF8ToUTF16(certificate_->subject().locality_name),
652 UTF8ToUTF16(certificate_->subject().country_name));
rsleevi4f8012722014-09-30 01:28:01653 }
jam8ae7cad2016-09-08 23:55:21654 DCHECK(!certificate_->subject().organization_names.empty());
rsleevi4f8012722014-09-30 01:28:01655 site_identity_details_.assign(l10n_util::GetStringFUTF16(
estarkcf305562016-11-15 03:45:39656 IDS_PAGE_INFO_SECURITY_TAB_SECURE_IDENTITY_EV_VERIFIED,
jam8ae7cad2016-09-08 23:55:21657 UTF8ToUTF16(certificate_->subject().organization_names[0]),
estarkcf305562016-11-15 03:45:39658 locality, UTF8ToUTF16(certificate_->issuer().GetDisplayName())));
rsleevi4f8012722014-09-30 01:28:01659 } else {
660 // Non-EV OK HTTPS page.
estarkcf305562016-11-15 03:45:39661 site_identity_status_ = SITE_IDENTITY_STATUS_CERT;
rsleevi4f8012722014-09-30 01:28:01662 base::string16 issuer_name(
jam8ae7cad2016-09-08 23:55:21663 UTF8ToUTF16(certificate_->issuer().GetDisplayName()));
rsleevi4f8012722014-09-30 01:28:01664 if (issuer_name.empty()) {
665 issuer_name.assign(l10n_util::GetStringUTF16(
666 IDS_PAGE_INFO_SECURITY_TAB_UNKNOWN_PARTY));
667 }
[email protected]94c74b42013-12-02 15:19:49668
rsleevi4f8012722014-09-30 01:28:01669 site_identity_details_.assign(l10n_util::GetStringFUTF16(
estarkcf305562016-11-15 03:45:39670 IDS_PAGE_INFO_SECURITY_TAB_SECURE_IDENTITY_VERIFIED, issuer_name));
rsleevi4f8012722014-09-30 01:28:01671 }
elawrencebe87bd62017-01-10 16:08:59672 if (security_info.sha1_in_chain) {
673 site_identity_status_ =
674 SITE_IDENTITY_STATUS_DEPRECATED_SIGNATURE_ALGORITHM;
675 site_identity_details_ +=
676 UTF8ToUTF16("\n\n") +
677 l10n_util::GetStringUTF16(
678 IDS_PAGE_INFO_SECURITY_TAB_DEPRECATED_SIGNATURE_ALGORITHM);
rsleevi4f8012722014-09-30 01:28:01679 }
[email protected]03ef4b2a2012-03-06 15:04:20680 }
681 } else {
682 // HTTP or HTTPS with errors (not warnings).
683 site_identity_details_.assign(l10n_util::GetStringUTF16(
684 IDS_PAGE_INFO_SECURITY_TAB_INSECURE_IDENTITY));
jam8ae7cad2016-09-08 23:55:21685 if (!security_info.scheme_is_cryptographic || !security_info.certificate)
[email protected]03ef4b2a2012-03-06 15:04:20686 site_identity_status_ = SITE_IDENTITY_STATUS_NO_CERT;
687 else
688 site_identity_status_ = SITE_IDENTITY_STATUS_ERROR;
689
[email protected]a04db822013-12-11 19:14:40690 const base::string16 bullet = UTF8ToUTF16("\n • ");
felt2493b4452015-09-17 20:33:59691 std::vector<ssl_errors::ErrorInfo> errors;
estarka3121f6b2015-09-18 21:15:59692 ssl_errors::ErrorInfo::GetErrorsForCertStatus(
jam8ae7cad2016-09-08 23:55:21693 certificate_, security_info.cert_status, url, &errors);
[email protected]03ef4b2a2012-03-06 15:04:20694 for (size_t i = 0; i < errors.size(); ++i) {
695 site_identity_details_ += bullet;
696 site_identity_details_ += errors[i].short_description();
697 }
698
estarka3121f6b2015-09-18 21:15:59699 if (security_info.cert_status & net::CERT_STATUS_NON_UNIQUE_NAME) {
[email protected]03ef4b2a2012-03-06 15:04:20700 site_identity_details_ += ASCIIToUTF16("\n\n");
lgarron1a6300d2017-03-18 03:33:04701 site_identity_details_ +=
702 l10n_util::GetStringUTF16(IDS_PAGE_INFO_SECURITY_TAB_NON_UNIQUE_NAME);
[email protected]03ef4b2a2012-03-06 15:04:20703 }
704 }
705
706 // Site Connection
707 // We consider anything less than 80 bits encryption to be weak encryption.
708 // TODO(wtc): Bug 1198735: report mixed/unsafe content for unencrypted and
709 // weakly encrypted connections.
710 site_connection_status_ = SITE_CONNECTION_STATUS_UNKNOWN;
711
jshin1fb76462016-04-05 22:13:03712 base::string16 subject_name(GetSimpleSiteName(url));
palmer153af982015-09-15 02:04:19713 if (subject_name.empty()) {
714 subject_name.assign(
715 l10n_util::GetStringUTF16(IDS_PAGE_INFO_SECURITY_TAB_UNKNOWN_PARTY));
716 }
717
jam8ae7cad2016-09-08 23:55:21718 if (!security_info.certificate || !security_info.scheme_is_cryptographic) {
estarka3121f6b2015-09-18 21:15:59719 // Page is still loading (so SSL status is not yet available) or
720 // loaded over HTTP or loaded over HTTPS with no cert.
[email protected]1c1051d2014-05-10 11:39:58721 site_connection_status_ = SITE_CONNECTION_STATUS_UNENCRYPTED;
722
723 site_connection_details_.assign(l10n_util::GetStringFUTF16(
724 IDS_PAGE_INFO_SECURITY_TAB_NOT_ENCRYPTED_CONNECTION_TEXT,
725 subject_name));
estarka3121f6b2015-09-18 21:15:59726 } else if (security_info.security_bits < 0) {
727 // Security strength is unknown. Say nothing.
[email protected]03ef4b2a2012-03-06 15:04:20728 site_connection_status_ = SITE_CONNECTION_STATUS_ENCRYPTED_ERROR;
estarka3121f6b2015-09-18 21:15:59729 } else if (security_info.security_bits == 0) {
esecklercac56b62016-11-16 13:49:44730 DCHECK_NE(security_info.security_level, security_state::NONE);
[email protected]03ef4b2a2012-03-06 15:04:20731 site_connection_status_ = SITE_CONNECTION_STATUS_ENCRYPTED_ERROR;
732 site_connection_details_.assign(l10n_util::GetStringFUTF16(
733 IDS_PAGE_INFO_SECURITY_TAB_NOT_ENCRYPTED_CONNECTION_TEXT,
734 subject_name));
[email protected]03ef4b2a2012-03-06 15:04:20735 } else {
736 site_connection_status_ = SITE_CONNECTION_STATUS_ENCRYPTED;
Adam Langley71c2b59b2014-11-13 00:34:22737
lgarron3e2c33e2016-08-25 06:33:43738 if (security_info.obsolete_ssl_status == net::OBSOLETE_SSL_NONE) {
Adam Langley71c2b59b2014-11-13 00:34:22739 site_connection_details_.assign(l10n_util::GetStringFUTF16(
lgarron1a6300d2017-03-18 03:33:04740 IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTED_CONNECTION_TEXT, subject_name));
Adam Langley71c2b59b2014-11-13 00:34:22741 } else {
742 site_connection_details_.assign(l10n_util::GetStringFUTF16(
743 IDS_PAGE_INFO_SECURITY_TAB_WEAK_ENCRYPTION_CONNECTION_TEXT,
744 subject_name));
745 }
746
thestig4427f13b2017-06-20 20:42:47747 ReportAnyInsecureContent(security_info, &site_connection_status_,
748 &site_connection_details_);
[email protected]03ef4b2a2012-03-06 15:04:20749 }
750
avi655876a2015-12-25 07:18:15751 uint16_t cipher_suite =
estarka3121f6b2015-09-18 21:15:59752 net::SSLConnectionStatusToCipherSuite(security_info.connection_status);
753 if (security_info.security_bits > 0 && cipher_suite) {
[email protected]03ef4b2a2012-03-06 15:04:20754 int ssl_version =
estarka3121f6b2015-09-18 21:15:59755 net::SSLConnectionStatusToVersion(security_info.connection_status);
[email protected]03ef4b2a2012-03-06 15:04:20756 const char* ssl_version_str;
757 net::SSLVersionToString(&ssl_version_str, ssl_version);
758 site_connection_details_ += ASCIIToUTF16("\n\n");
759 site_connection_details_ += l10n_util::GetStringFUTF16(
lgarron1a6300d2017-03-18 03:33:04760 IDS_PAGE_INFO_SECURITY_TAB_SSL_VERSION, ASCIIToUTF16(ssl_version_str));
[email protected]03ef4b2a2012-03-06 15:04:20761
[email protected]03ef4b2a2012-03-06 15:04:20762 const char *key_exchange, *cipher, *mac;
davidben56a8aece2016-10-14 18:20:56763 bool is_aead, is_tls13;
764 net::SSLCipherSuiteToStrings(&key_exchange, &cipher, &mac, &is_aead,
765 &is_tls13, cipher_suite);
[email protected]03ef4b2a2012-03-06 15:04:20766
767 site_connection_details_ += ASCIIToUTF16("\n\n");
[email protected]b6c1d9e82013-06-12 17:26:57768 if (is_aead) {
davidben56a8aece2016-10-14 18:20:56769 if (is_tls13) {
770 // For TLS 1.3 ciphers, report the group (historically, curve) as the
771 // key exchange.
772 key_exchange = SSL_get_curve_name(security_info.key_exchange_group);
773 if (!key_exchange) {
774 NOTREACHED();
775 key_exchange = "";
776 }
777 }
[email protected]b6c1d9e82013-06-12 17:26:57778 site_connection_details_ += l10n_util::GetStringFUTF16(
779 IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTION_DETAILS_AEAD,
780 ASCIIToUTF16(cipher), ASCIIToUTF16(key_exchange));
781 } else {
782 site_connection_details_ += l10n_util::GetStringFUTF16(
lgarron1a6300d2017-03-18 03:33:04783 IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTION_DETAILS, ASCIIToUTF16(cipher),
784 ASCIIToUTF16(mac), ASCIIToUTF16(key_exchange));
[email protected]b6c1d9e82013-06-12 17:26:57785 }
[email protected]03ef4b2a2012-03-06 15:04:20786 }
[email protected]e583f752012-08-30 13:26:21787
[email protected]71cd5ef2014-08-13 21:22:04788 // Check if a user decision has been made to allow or deny certificates with
789 // errors on this site.
790 ChromeSSLHostStateDelegate* delegate =
estark7c6bfbf2015-09-16 22:20:50791 ChromeSSLHostStateDelegateFactory::GetForProfile(profile_);
[email protected]71cd5ef2014-08-13 21:22:04792 DCHECK(delegate);
jwwf806c362015-06-02 02:00:40793 // Only show an SSL decision revoke button if the user has chosen to bypass
794 // SSL host errors for this host in the past.
795 show_ssl_decision_revoke_button_ = delegate->HasAllowException(url.host());
[email protected]03ef4b2a2012-03-06 15:04:20796}
[email protected]0b9fdd72012-04-04 10:00:33797
lgarron617a30f32017-03-24 21:42:07798void PageInfo::PresentSitePermissions() {
[email protected]df818272012-04-20 13:10:50799 PermissionInfoList permission_info_list;
reillyg85f57db2016-01-12 23:14:38800 ChosenObjectInfoList chosen_object_info_list;
[email protected]df818272012-04-20 13:10:50801
lgarron617a30f32017-03-24 21:42:07802 PageInfoUI::PermissionInfo permission_info;
[email protected]df818272012-04-20 13:10:50803 for (size_t i = 0; i < arraysize(kPermissionType); ++i) {
804 permission_info.type = kPermissionType[i];
805
806 content_settings::SettingInfo info;
dcheng9603ab92016-04-08 04:17:32807 std::unique_ptr<base::Value> value = content_settings_->GetWebsiteSetting(
808 site_url_, site_url_, permission_info.type, std::string(), &info);
sashab2b2a314f2015-01-17 06:42:21809 DCHECK(value.get());
jdoerrie76cee9c2017-10-06 22:42:42810 if (value->type() == base::Value::Type::INTEGER) {
sashab2b2a314f2015-01-17 06:42:21811 permission_info.setting =
812 content_settings::ValueToContentSetting(value.get());
[email protected]fe4686a2012-10-19 15:38:26813 } else {
sashab2b2a314f2015-01-17 06:42:21814 NOTREACHED();
[email protected]fe4686a2012-10-19 15:38:26815 }
816
[email protected]8bdf45c32012-08-04 00:12:55817 permission_info.source = info.source;
johnme9ed93882016-01-15 01:13:28818 permission_info.is_incognito = profile_->IsOffTheRecord();
[email protected]df818272012-04-20 13:10:50819
[email protected]b1d113d2012-06-27 21:27:34820 if (info.primary_pattern == ContentSettingsPattern::Wildcard() &&
sashab2b2a314f2015-01-17 06:42:21821 info.secondary_pattern == ContentSettingsPattern::Wildcard()) {
[email protected]b1d113d2012-06-27 21:27:34822 permission_info.default_setting = permission_info.setting;
823 permission_info.setting = CONTENT_SETTING_DEFAULT;
824 } else {
825 permission_info.default_setting =
826 content_settings_->GetDefaultContentSetting(permission_info.type,
827 NULL);
[email protected]df818272012-04-20 13:10:50828 }
palmer0da10b32015-02-11 00:42:19829
patricialor2a4f41a2017-03-08 02:52:56830 // For permissions that are still prompting the user and haven't been
831 // explicitly set by another source, check its embargo status.
832 if (PermissionUtil::IsPermission(permission_info.type) &&
833 permission_info.setting == CONTENT_SETTING_DEFAULT &&
834 permission_info.source ==
835 content_settings::SettingSource::SETTING_SOURCE_USER) {
836 // TODO(raymes): Use GetPermissionStatus() to retrieve information
837 // about *all* permissions once it has default behaviour implemented for
838 // ContentSettingTypes that aren't permissions.
839 PermissionResult permission_result =
840 PermissionManager::Get(profile_)->GetPermissionStatus(
841 permission_info.type, site_url_, site_url_);
842
843 // If under embargo, update |permission_info| to reflect that.
844 if (permission_result.content_setting == CONTENT_SETTING_BLOCK &&
845 (permission_result.source ==
846 PermissionStatusSource::MULTIPLE_DISMISSALS ||
847 permission_result.source ==
848 PermissionStatusSource::SAFE_BROWSING_BLACKLIST))
849 permission_info.setting = permission_result.content_setting;
850 }
851
Tommy Steimelc9f6c932017-10-13 23:33:04852 if (ShouldShowPermission(permission_info, site_url_, content_settings_,
shahriar rostamia9c769d2017-12-06 04:54:08853 web_contents(), tab_specific_content_settings())) {
Patti0601e532017-09-20 08:39:30854 permission_info_list.push_back(permission_info);
Tommy Steimelc9f6c932017-10-13 23:33:04855 }
[email protected]df818272012-04-20 13:10:50856 }
857
reillyg85f57db2016-01-12 23:14:38858 for (const ChooserUIInfo& ui_info : kChooserUIInfo) {
859 ChooserContextBase* context = ui_info.get_context(profile_);
reillyg36a7fab32016-01-28 19:15:10860 const GURL origin = site_url_.GetOrigin();
861 auto chosen_objects = context->GetGrantedObjects(origin, origin);
dcheng9603ab92016-04-08 04:17:32862 for (std::unique_ptr<base::DictionaryValue>& object : chosen_objects) {
reillyg85f57db2016-01-12 23:14:38863 chosen_object_info_list.push_back(
lgarron617a30f32017-03-24 21:42:07864 base::MakeUnique<PageInfoUI::ChosenObjectInfo>(ui_info,
865 std::move(object)));
reillyg85f57db2016-01-12 23:14:38866 }
867 }
868
avi09dd4d02016-10-14 20:40:09869 ui_->SetPermissionInfo(permission_info_list,
870 std::move(chosen_object_info_list));
[email protected]0b9fdd72012-04-04 10:00:33871}
872
lgarron617a30f32017-03-24 21:42:07873void PageInfo::PresentSiteData() {
[email protected]df818272012-04-20 13:10:50874 CookieInfoList cookie_info_list;
vabrbab3ffcb2016-10-04 10:08:10875 const LocalSharedObjectsContainer& allowed_objects =
[email protected]e0ac35892012-05-15 12:53:34876 tab_specific_content_settings()->allowed_local_shared_objects();
vabrbab3ffcb2016-10-04 10:08:10877 const LocalSharedObjectsContainer& blocked_objects =
[email protected]e0ac35892012-05-15 12:53:34878 tab_specific_content_settings()->blocked_local_shared_objects();
879
880 // Add first party cookie and site data counts.
lgarron617a30f32017-03-24 21:42:07881 PageInfoUI::CookieInfo cookie_info;
[email protected]e0ac35892012-05-15 12:53:34882 cookie_info.allowed = allowed_objects.GetObjectCountForDomain(site_url_);
883 cookie_info.blocked = blocked_objects.GetObjectCountForDomain(site_url_);
palmerb145264922015-08-28 23:53:15884 cookie_info.is_first_party = true;
[email protected]e0ac35892012-05-15 12:53:34885 cookie_info_list.push_back(cookie_info);
886
887 // Add third party cookie counts.
[email protected]e0ac35892012-05-15 12:53:34888 cookie_info.allowed = allowed_objects.GetObjectCount() - cookie_info.allowed;
889 cookie_info.blocked = blocked_objects.GetObjectCount() - cookie_info.blocked;
palmerb145264922015-08-28 23:53:15890 cookie_info.is_first_party = false;
[email protected]df818272012-04-20 13:10:50891 cookie_info_list.push_back(cookie_info);
[email protected]0b9fdd72012-04-04 10:00:33892
[email protected]df818272012-04-20 13:10:50893 ui_->SetCookieInfo(cookie_info_list);
[email protected]0b9fdd72012-04-04 10:00:33894}
[email protected]16de6de2012-04-04 12:24:14895
lgarron617a30f32017-03-24 21:42:07896void PageInfo::PresentSiteIdentity() {
palmerf9b680a2015-07-09 18:56:04897 // After initialization the status about the site's connection and its
898 // identity must be available.
[email protected]24c8818c2012-04-25 09:57:41899 DCHECK_NE(site_identity_status_, SITE_IDENTITY_STATUS_UNKNOWN);
900 DCHECK_NE(site_connection_status_, SITE_CONNECTION_STATUS_UNKNOWN);
lgarron617a30f32017-03-24 21:42:07901 PageInfoUI::IdentityInfo info;
[email protected]24c8818c2012-04-25 09:57:41902 if (site_identity_status_ == SITE_IDENTITY_STATUS_EV_CERT)
903 info.site_identity = UTF16ToUTF8(organization_name());
904 else
jshin1fb76462016-04-05 22:13:03905 info.site_identity = UTF16ToUTF8(GetSimpleSiteName(site_url_));
[email protected]24c8818c2012-04-25 09:57:41906
907 info.connection_status = site_connection_status_;
lgarron1a6300d2017-03-18 03:33:04908 info.connection_status_description = UTF16ToUTF8(site_connection_details_);
[email protected]24c8818c2012-04-25 09:57:41909 info.identity_status = site_identity_status_;
lgarron1a6300d2017-03-18 03:33:04910 info.identity_status_description = UTF16ToUTF8(site_identity_details_);
jam8ae7cad2016-09-08 23:55:21911 info.certificate = certificate_;
[email protected]71cd5ef2014-08-13 21:22:04912 info.show_ssl_decision_revoke_button = show_ssl_decision_revoke_button_;
Jialiu Lin11e18542017-08-14 18:16:26913 info.show_change_password_buttons = show_change_password_buttons_;
[email protected]24c8818c2012-04-25 09:57:41914 ui_->SetIdentityInfo(info);
Jialiu Linfeb6bb32017-08-30 00:21:36915#if defined(SAFE_BROWSING_DB_LOCAL)
Jialiu Lin11e18542017-08-14 18:16:26916 if (password_protection_service_ && show_change_password_buttons_) {
Jialiu Linfecb75432017-11-07 19:14:59917 password_protection_service_->RecordWarningAction(
918 safe_browsing::PasswordProtectionService::PAGE_INFO,
919 safe_browsing::PasswordProtectionService::SHOWN);
Jialiu Lin11e18542017-08-14 18:16:26920 }
921#endif
[email protected]24c8818c2012-04-25 09:57:41922}
Patti7f21c4b2017-11-28 03:37:17923
924std::vector<ContentSettingsType> PageInfo::GetAllPermissionsForTesting() {
925 std::vector<ContentSettingsType> permission_list;
926 for (size_t i = 0; i < arraysize(kPermissionType); ++i) {
927#if !defined(OS_ANDROID)
928 if (kPermissionType[i] == CONTENT_SETTINGS_TYPE_AUTOPLAY)
929 continue;
930#endif
931 permission_list.push_back(kPermissionType[i]);
932 }
933 return permission_list;
934}