blob: b6e88ecf9fd8f49d3c1a4b371956998ac9347645 [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
[email protected]4237dd52012-06-05 00:00:325#include "chrome/browser/ui/website_settings/website_settings.h"
[email protected]03ef4b2a2012-03-06 15:04:206
7#include <string>
8#include <vector>
9
[email protected]15b092542012-05-16 13:08:1410#include "base/bind.h"
11#include "base/bind_helpers.h"
[email protected]eb2140c2013-07-29 12:37:3412#include "base/command_line.h"
[email protected]15b092542012-05-16 13:08:1413#include "base/i18n/time_formatting.h"
[email protected]71cd5ef2014-08-13 21:22:0414#include "base/metrics/field_trial.h"
[email protected]3ea1b182013-02-08 22:38:4115#include "base/metrics/histogram.h"
16#include "base/strings/string_number_conversions.h"
[email protected]774cc3c2013-06-07 20:26:4517#include "base/strings/utf_string_conversions.h"
[email protected]0b9fdd72012-04-04 10:00:3318#include "base/values.h"
[email protected]6b8a3c742014-07-25 00:25:3519#include "chrome/browser/browsing_data/browsing_data_channel_id_helper.h"
[email protected]b0cb5e82012-07-19 19:22:4720#include "chrome/browser/browsing_data/browsing_data_cookie_helper.h"
21#include "chrome/browser/browsing_data/browsing_data_database_helper.h"
22#include "chrome/browser/browsing_data/browsing_data_file_system_helper.h"
23#include "chrome/browser/browsing_data/browsing_data_indexed_db_helper.h"
24#include "chrome/browser/browsing_data/browsing_data_local_storage_helper.h"
[email protected]0b9fdd72012-04-04 10:00:3325#include "chrome/browser/content_settings/content_settings_utils.h"
26#include "chrome/browser/content_settings/host_content_settings_map.h"
[email protected]df818272012-04-20 13:10:5027#include "chrome/browser/content_settings/local_shared_objects_container.h"
[email protected]77a91c72012-08-13 16:19:3428#include "chrome/browser/history/history_service_factory.h"
[email protected]03ef4b2a2012-03-06 15:04:2029#include "chrome/browser/profiles/profile.h"
[email protected]71cd5ef2014-08-13 21:22:0430#include "chrome/browser/ssl/chrome_ssl_host_state_delegate.h"
31#include "chrome/browser/ssl/chrome_ssl_host_state_delegate_factory.h"
[email protected]03ef4b2a2012-03-06 15:04:2032#include "chrome/browser/ssl/ssl_error_info.h"
[email protected]66f157312012-08-01 13:50:2633#include "chrome/browser/ui/website_settings/website_settings_infobar_delegate.h"
[email protected]4237dd52012-06-05 00:00:3234#include "chrome/browser/ui/website_settings/website_settings_ui.h"
[email protected]71cd5ef2014-08-13 21:22:0435#include "chrome/common/chrome_switches.h"
thestig884a1602014-08-27 01:29:3936#include "chrome/grit/chromium_strings.h"
37#include "chrome/grit/generated_resources.h"
vasiliif62dbf92014-09-05 10:23:1338#include "components/content_settings/core/common/content_settings_pattern.h"
[email protected]0b9fdd72012-04-04 10:00:3339#include "content/public/browser/browser_thread.h"
[email protected]b59c6cf02012-03-12 20:51:4240#include "content/public/browser/cert_store.h"
[email protected]e22d64f2012-09-10 09:03:2341#include "content/public/browser/user_metrics.h"
[email protected]eb2140c2013-07-29 12:37:3442#include "content/public/common/content_switches.h"
[email protected]03ef4b2a2012-03-06 15:04:2043#include "content/public/common/ssl_status.h"
44#include "content/public/common/url_constants.h"
[email protected]be28b5f42012-07-20 11:31:2545#include "net/base/registry_controlled_domains/registry_controlled_domain.h"
[email protected]6e7845ae2013-03-29 21:48:1146#include "net/cert/cert_status_flags.h"
47#include "net/cert/x509_certificate.h"
[email protected]536fd0b2013-03-14 17:41:5748#include "net/ssl/ssl_cipher_suite_names.h"
49#include "net/ssl/ssl_connection_status_flags.h"
[email protected]03ef4b2a2012-03-06 15:04:2050#include "ui/base/l10n/l10n_util.h"
[email protected]03ef4b2a2012-03-06 15:04:2051
[email protected]24a9f1c92013-11-13 12:33:3752#if defined(OS_CHROMEOS)
53#include "chrome/browser/chromeos/policy/policy_cert_service.h"
54#include "chrome/browser/chromeos/policy/policy_cert_service_factory.h"
55#endif
56
[email protected]ab6df3b12013-12-24 23:32:2657using base::ASCIIToUTF16;
58using base::UTF8ToUTF16;
[email protected]f729d7a2013-12-26 07:07:5659using base::UTF16ToUTF8;
[email protected]0b9fdd72012-04-04 10:00:3360using content::BrowserThread;
61
62namespace {
63
jww1ed8ea72014-09-02 20:43:2564// Events for UMA. Do not reorder or change!
65enum SSLCertificateDecisionsDidRevoke {
66 USER_CERT_DECISIONS_NOT_REVOKED = 0,
67 USER_CERT_DECISIONS_REVOKED,
68 END_OF_SSL_CERTIFICATE_DECISIONS_DID_REVOKE_ENUM
69};
70
[email protected]b1d113d2012-06-27 21:27:3471// The list of content settings types to display on the Website Settings UI.
[email protected]0b9fdd72012-04-04 10:00:3372ContentSettingsType kPermissionType[] = {
[email protected]b1d113d2012-06-27 21:27:3473 CONTENT_SETTINGS_TYPE_IMAGES,
74 CONTENT_SETTINGS_TYPE_JAVASCRIPT,
[email protected]0b9fdd72012-04-04 10:00:3375 CONTENT_SETTINGS_TYPE_PLUGINS,
[email protected]b1d113d2012-06-27 21:27:3476 CONTENT_SETTINGS_TYPE_POPUPS,
[email protected]0b9fdd72012-04-04 10:00:3377 CONTENT_SETTINGS_TYPE_GEOLOCATION,
[email protected]b1d113d2012-06-27 21:27:3478 CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
79 CONTENT_SETTINGS_TYPE_FULLSCREEN,
80 CONTENT_SETTINGS_TYPE_MOUSELOCK,
81 CONTENT_SETTINGS_TYPE_MEDIASTREAM,
[email protected]62167c12013-07-10 23:02:0882 CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS,
[email protected]eb2140c2013-07-29 12:37:3483 CONTENT_SETTINGS_TYPE_MIDI_SYSEX,
[email protected]0b9fdd72012-04-04 10:00:3384};
85
[email protected]94c74b42013-12-02 15:19:4986bool CertificateTransparencyStatusMatch(
87 const content::SignedCertificateTimestampIDStatusList& scts,
88 net::ct::SCTVerifyStatus status) {
89 for (content::SignedCertificateTimestampIDStatusList::const_iterator it =
90 scts.begin();
91 it != scts.end();
92 ++it) {
93 if (it->status == status)
94 return true;
95 }
96
97 return false;
98}
99
100int GetSiteIdentityDetailsMessageByCTInfo(
101 const content::SignedCertificateTimestampIDStatusList& scts,
102 bool is_ev) {
103 // No SCTs - no CT information.
104 if (scts.empty())
105 return (is_ev ? IDS_PAGE_INFO_SECURITY_TAB_SECURE_IDENTITY_EV_NO_CT
106 : IDS_PAGE_INFO_SECURITY_TAB_SECURE_IDENTITY_NO_CT);
107
108 if (CertificateTransparencyStatusMatch(scts, net::ct::SCT_STATUS_OK))
109 return (is_ev ? IDS_PAGE_INFO_SECURITY_TAB_SECURE_IDENTITY_EV_CT_VERIFIED
110 : IDS_PAGE_INFO_SECURITY_TAB_SECURE_IDENTITY_CT_VERIFIED);
111
112 if (CertificateTransparencyStatusMatch(scts, net::ct::SCT_STATUS_INVALID))
113 return (is_ev ? IDS_PAGE_INFO_SECURITY_TAB_SECURE_IDENTITY_EV_CT_INVALID
114 : IDS_PAGE_INFO_SECURITY_TAB_SECURE_IDENTITY_CT_INVALID);
115
116 // status is SCT_STATUS_LOG_UNKNOWN
117 return (is_ev ? IDS_PAGE_INFO_SECURITY_TAB_SECURE_IDENTITY_EV_CT_UNVERIFIED
118 : IDS_PAGE_INFO_SECURITY_TAB_SECURE_IDENTITY_CT_UNVERIFIED);
119}
120
121// This function will return SITE_IDENTITY_STATUS_CERT or
122// SITE_IDENTITY_STATUS_EV_CERT depending on |is_ev| unless there are SCTs
123// which failed verification, in which case it will return
124// SITE_IDENTITY_STATUS_ERROR.
125WebsiteSettings::SiteIdentityStatus GetSiteIdentityStatusByCTInfo(
126 const content::SignedCertificateTimestampIDStatusList& scts,
127 bool is_ev) {
128 if (CertificateTransparencyStatusMatch(scts, net::ct::SCT_STATUS_INVALID))
129 return WebsiteSettings::SITE_IDENTITY_STATUS_ERROR;
130
131 return is_ev ? WebsiteSettings::SITE_IDENTITY_STATUS_EV_CERT
132 : WebsiteSettings::SITE_IDENTITY_STATUS_CERT;
133}
134
[email protected]71cd5ef2014-08-13 21:22:04135const char kRememberCertificateErrorDecisionsFieldTrialName[] =
136 "RememberCertificateErrorDecisions";
137const char kRememberCertificateErrorDecisionsFieldTrialDefaultGroup[] =
138 "Default";
139const char kRememberCertificateErrorDecisionsFieldTrialDisableGroup[] =
140 "Disable";
141// Returns true if the user is in the experimental group or has the flag enabled
142// for remembering SSL error decisions, otherwise false.
143//
144// TODO(jww): The field trial is scheduled to end 2015/02/28. This should be
145// removed at that point unless the field trial or flag continues.
146bool InRememberCertificateErrorDecisionsGroup() {
147 std::string group_name = base::FieldTrialList::FindFullName(
148 kRememberCertificateErrorDecisionsFieldTrialName);
149
150 // The Default and Disable groups are the "old-style" forget-at-session
151 // restart groups, so they do not get the button.
152 bool in_experimental_group = !group_name.empty() &&
153 group_name.compare(
154 kRememberCertificateErrorDecisionsFieldTrialDefaultGroup) != 0 &&
155 group_name.compare(
156 kRememberCertificateErrorDecisionsFieldTrialDisableGroup) != 0;
157 bool has_command_line_switch = CommandLine::ForCurrentProcess()->HasSwitch(
158 switches::kRememberCertErrorDecisions);
159 return in_experimental_group || has_command_line_switch;
160}
161
[email protected]0b9fdd72012-04-04 10:00:33162} // namespace
163
164WebsiteSettings::WebsiteSettings(
165 WebsiteSettingsUI* ui,
166 Profile* profile,
[email protected]df818272012-04-20 13:10:50167 TabSpecificContentSettings* tab_specific_content_settings,
[email protected]4f822f022012-12-20 19:11:42168 InfoBarService* infobar_service,
[email protected]0b9fdd72012-04-04 10:00:33169 const GURL& url,
170 const content::SSLStatus& ssl,
171 content::CertStore* cert_store)
[email protected]df818272012-04-20 13:10:50172 : TabSpecificContentSettings::SiteDataObserver(
173 tab_specific_content_settings),
174 ui_(ui),
[email protected]4f822f022012-12-20 19:11:42175 infobar_service_(infobar_service),
[email protected]66f157312012-08-01 13:50:26176 show_info_bar_(false),
[email protected]0b9fdd72012-04-04 10:00:33177 site_url_(url),
178 site_identity_status_(SITE_IDENTITY_STATUS_UNKNOWN),
[email protected]f61c1ce2012-05-09 13:55:11179 cert_id_(0),
[email protected]03ef4b2a2012-03-06 15:04:20180 site_connection_status_(SITE_CONNECTION_STATUS_UNKNOWN),
[email protected]0b9fdd72012-04-04 10:00:33181 cert_store_(cert_store),
[email protected]71cd5ef2014-08-13 21:22:04182 content_settings_(profile->GetHostContentSettingsMap()),
183 chrome_ssl_host_state_delegate_(
jww1ed8ea72014-09-02 20:43:25184 ChromeSSLHostStateDelegateFactory::GetForProfile(profile)),
185 did_revoke_user_ssl_decisions_(false) {
[email protected]03ef4b2a2012-03-06 15:04:20186 Init(profile, url, ssl);
[email protected]0b9fdd72012-04-04 10:00:33187
[email protected]78a1fd90a2012-07-19 08:11:25188 HistoryService* history_service = HistoryServiceFactory::GetForProfile(
189 profile, Profile::EXPLICIT_ACCESS);
[email protected]15b092542012-05-16 13:08:14190 if (history_service) {
191 history_service->GetVisibleVisitCountToHost(
192 site_url_,
[email protected]15b092542012-05-16 13:08:14193 base::Bind(&WebsiteSettings::OnGotVisitCountToHost,
[email protected]e800fe742014-07-01 10:38:19194 base::Unretained(this)),
195 &visit_count_task_tracker_);
[email protected]15b092542012-05-16 13:08:14196 }
197
[email protected]0b9fdd72012-04-04 10:00:33198 PresentSitePermissions();
[email protected]df818272012-04-20 13:10:50199 PresentSiteData();
[email protected]24c8818c2012-04-25 09:57:41200 PresentSiteIdentity();
[email protected]15b092542012-05-16 13:08:14201 PresentHistoryInfo(base::Time());
[email protected]e22d64f2012-09-10 09:03:23202
203 // Every time the Website Settings UI is opened a |WebsiteSettings| object is
204 // created. So this counts how ofter the Website Settings UI is opened.
[email protected]e6e30ac2014-01-13 21:24:39205 content::RecordAction(base::UserMetricsAction("WebsiteSettings_Opened"));
[email protected]03ef4b2a2012-03-06 15:04:20206}
207
[email protected]0b9fdd72012-04-04 10:00:33208WebsiteSettings::~WebsiteSettings() {
[email protected]03ef4b2a2012-03-06 15:04:20209}
210
[email protected]df818272012-04-20 13:10:50211void WebsiteSettings::OnSitePermissionChanged(ContentSettingsType type,
212 ContentSetting setting) {
[email protected]e22d64f2012-09-10 09:03:23213 // Count how often a permission for a specific content type is changed using
214 // the Website Settings UI.
215 UMA_HISTOGRAM_COUNTS("WebsiteSettings.PermissionChanged", type);
216
[email protected]df818272012-04-20 13:10:50217 ContentSettingsPattern primary_pattern;
218 ContentSettingsPattern secondary_pattern;
219 switch (type) {
220 case CONTENT_SETTINGS_TYPE_GEOLOCATION:
[email protected]eb2140c2013-07-29 12:37:34221 case CONTENT_SETTINGS_TYPE_MIDI_SYSEX:
[email protected]df818272012-04-20 13:10:50222 // TODO(markusheintz): The rule we create here should also change the
223 // location permission for iframed content.
224 primary_pattern = ContentSettingsPattern::FromURLNoWildcard(site_url_);
225 secondary_pattern = ContentSettingsPattern::FromURLNoWildcard(site_url_);
226 break;
227 case CONTENT_SETTINGS_TYPE_NOTIFICATIONS:
228 primary_pattern = ContentSettingsPattern::FromURLNoWildcard(site_url_);
229 secondary_pattern = ContentSettingsPattern::Wildcard();
230 break;
[email protected]b1d113d2012-06-27 21:27:34231 case CONTENT_SETTINGS_TYPE_IMAGES:
232 case CONTENT_SETTINGS_TYPE_JAVASCRIPT:
[email protected]df818272012-04-20 13:10:50233 case CONTENT_SETTINGS_TYPE_PLUGINS:
234 case CONTENT_SETTINGS_TYPE_POPUPS:
[email protected]b1d113d2012-06-27 21:27:34235 case CONTENT_SETTINGS_TYPE_FULLSCREEN:
236 case CONTENT_SETTINGS_TYPE_MOUSELOCK:
[email protected]ad635b12013-07-22 21:53:27237 case CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS:
[email protected]df818272012-04-20 13:10:50238 primary_pattern = ContentSettingsPattern::FromURL(site_url_);
239 secondary_pattern = ContentSettingsPattern::Wildcard();
240 break;
[email protected]0bacc1912012-12-11 11:05:34241 case CONTENT_SETTINGS_TYPE_MEDIASTREAM: {
242 // We need to use the same same patterns as other places like infobar code
243 // to override the existing rule instead of creating the new one.
244 primary_pattern = ContentSettingsPattern::FromURLNoWildcard(site_url_);
245 secondary_pattern = ContentSettingsPattern::Wildcard();
246 // Set permission for both microphone and camera.
247 content_settings_->SetContentSetting(
[email protected]007b3f82013-04-09 08:46:45248 primary_pattern,
249 secondary_pattern,
250 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC,
251 std::string(),
252 setting);
[email protected]0bacc1912012-12-11 11:05:34253
254 content_settings_->SetContentSetting(
[email protected]007b3f82013-04-09 08:46:45255 primary_pattern,
256 secondary_pattern,
257 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA,
258 std::string(),
259 setting);
[email protected]0bacc1912012-12-11 11:05:34260 break;
261 }
[email protected]df818272012-04-20 13:10:50262 default:
263 NOTREACHED() << "ContentSettingsType " << type << "is not supported.";
264 break;
[email protected]0b9fdd72012-04-04 10:00:33265 }
266
[email protected]0bacc1912012-12-11 11:05:34267 if (type != CONTENT_SETTINGS_TYPE_MEDIASTREAM) {
268 // Permission settings are specified via rules. There exists always at least
269 // one rule for the default setting. Get the rule that currently defines
270 // the permission for the given permission |type|. Then test whether the
271 // existing rule is more specific than the rule we are about to create. If
272 // the existing rule is more specific, than change the existing rule instead
273 // of creating a new rule that would be hidden behind the existing rule.
274 // This is not a concern for CONTENT_SETTINGS_TYPE_MEDIASTREAM since users
275 // can not create media settings exceptions by hand.
276 content_settings::SettingInfo info;
[email protected]2c95d102013-12-23 20:42:16277 scoped_ptr<base::Value> v(content_settings_->GetWebsiteSetting(
[email protected]007b3f82013-04-09 08:46:45278 site_url_, site_url_, type, std::string(), &info));
[email protected]6b3552a2014-08-21 21:10:12279 content_settings_->SetNarrowestWebsiteSetting(
280 primary_pattern, secondary_pattern, type, std::string(), setting, info);
281 } else {
[email protected]2c95d102013-12-23 20:42:16282 base::Value* value = NULL;
[email protected]0bacc1912012-12-11 11:05:34283 if (setting != CONTENT_SETTING_DEFAULT)
[email protected]a7965a42014-07-22 02:35:56284 value = new base::FundamentalValue(setting);
[email protected]0bacc1912012-12-11 11:05:34285 content_settings_->SetWebsiteSetting(
[email protected]007b3f82013-04-09 08:46:45286 primary_pattern, secondary_pattern, type, std::string(), value);
[email protected]df818272012-04-20 13:10:50287 }
288
[email protected]66f157312012-08-01 13:50:26289 show_info_bar_ = true;
[email protected]2f45d542012-08-22 08:47:24290
[email protected]76955932012-12-06 11:01:10291// TODO(markusheintz): This is a temporary hack to fix issue:
292// http://crbug.com/144203.
[email protected]e379ba42012-08-22 22:40:25293#if defined(OS_MACOSX)
[email protected]2f45d542012-08-22 08:47:24294 // Refresh the UI to reflect the new setting.
295 PresentSitePermissions();
[email protected]e379ba42012-08-22 22:40:25296#endif
[email protected]df818272012-04-20 13:10:50297}
298
[email protected]e800fe742014-07-01 10:38:19299void WebsiteSettings::OnGotVisitCountToHost(bool found_visits,
[email protected]15b092542012-05-16 13:08:14300 int visit_count,
301 base::Time first_visit) {
302 if (!found_visits) {
303 // This indicates an error, such as the page's URL scheme wasn't
304 // http/https.
305 first_visit = base::Time();
306 } else if (visit_count == 0) {
307 first_visit = base::Time::Now();
308 }
309 PresentHistoryInfo(first_visit);
310}
311
[email protected]df818272012-04-20 13:10:50312void WebsiteSettings::OnSiteDataAccessed() {
313 PresentSiteData();
[email protected]0b9fdd72012-04-04 10:00:33314}
315
[email protected]66f157312012-08-01 13:50:26316void WebsiteSettings::OnUIClosing() {
[email protected]0be09932013-01-08 02:03:50317 if (show_info_bar_)
[email protected]ed9bc652013-07-11 17:17:36318 WebsiteSettingsInfoBarDelegate::Create(infobar_service_);
jww1ed8ea72014-09-02 20:43:25319
320 SSLCertificateDecisionsDidRevoke user_decision =
321 did_revoke_user_ssl_decisions_ ? USER_CERT_DECISIONS_REVOKED
322 : USER_CERT_DECISIONS_NOT_REVOKED;
323
324 UMA_HISTOGRAM_ENUMERATION("interstitial.ssl.did_user_revoke_decisions",
325 user_decision,
326 END_OF_SSL_CERTIFICATE_DECISIONS_DID_REVOKE_ENUM);
327}
328
329void WebsiteSettings::OnRevokeSSLErrorBypassButtonPressed() {
330 DCHECK(chrome_ssl_host_state_delegate_);
331 chrome_ssl_host_state_delegate_->RevokeUserDecisionsHard(site_url().host());
332 did_revoke_user_ssl_decisions_ = true;
[email protected]66f157312012-08-01 13:50:26333}
334
[email protected]0b9fdd72012-04-04 10:00:33335void WebsiteSettings::Init(Profile* profile,
336 const GURL& url,
337 const content::SSLStatus& ssl) {
[email protected]2d9748b22014-02-11 00:17:29338 if (url.SchemeIs(content::kChromeUIScheme)) {
[email protected]03ef4b2a2012-03-06 15:04:20339 site_identity_status_ = SITE_IDENTITY_STATUS_INTERNAL_PAGE;
340 site_identity_details_ =
341 l10n_util::GetStringUTF16(IDS_PAGE_INFO_INTERNAL_PAGE);
342 site_connection_status_ = SITE_CONNECTION_STATUS_INTERNAL_PAGE;
343 return;
344 }
345
346 scoped_refptr<net::X509Certificate> cert;
347
348 // Identity section.
[email protected]a04db822013-12-11 19:14:40349 base::string16 subject_name(UTF8ToUTF16(url.host()));
[email protected]03ef4b2a2012-03-06 15:04:20350 if (subject_name.empty()) {
351 subject_name.assign(
352 l10n_util::GetStringUTF16(IDS_PAGE_INFO_SECURITY_TAB_UNKNOWN_PARTY));
[email protected]03ef4b2a2012-03-06 15:04:20353 }
354
[email protected]f61c1ce2012-05-09 13:55:11355 cert_id_ = ssl.cert_id;
356
[email protected]3d6d34b12013-12-23 00:34:02357 if (ssl.cert_id && !ssl.signed_certificate_timestamp_ids.empty()) {
358 signed_certificate_timestamp_ids_.assign(
359 ssl.signed_certificate_timestamp_ids.begin(),
360 ssl.signed_certificate_timestamp_ids.end());
361 }
362
[email protected]03ef4b2a2012-03-06 15:04:20363 if (ssl.cert_id &&
364 cert_store_->RetrieveCert(ssl.cert_id, &cert) &&
365 (!net::IsCertStatusError(ssl.cert_status) ||
366 net::IsCertStatusMinorError(ssl.cert_status))) {
367 // There are no major errors. Check for minor errors.
[email protected]24a9f1c92013-11-13 12:33:37368#if defined(OS_CHROMEOS)
369 policy::PolicyCertService* service =
370 policy::PolicyCertServiceFactory::GetForProfile(profile);
371 const bool used_policy_certs = service && service->UsedPolicyCertificates();
372#else
373 const bool used_policy_certs = false;
374#endif
375 if (used_policy_certs) {
[email protected]eaf3f322013-04-25 21:53:59376 site_identity_status_ = SITE_IDENTITY_STATUS_ADMIN_PROVIDED_CERT;
[email protected]24a9f1c92013-11-13 12:33:37377 site_identity_details_ = l10n_util::GetStringFUTF16(
378 IDS_CERT_POLICY_PROVIDED_CERT_MESSAGE, UTF8ToUTF16(url.host()));
[email protected]eaf3f322013-04-25 21:53:59379 } else if (net::IsCertStatusMinorError(ssl.cert_status)) {
[email protected]03ef4b2a2012-03-06 15:04:20380 site_identity_status_ = SITE_IDENTITY_STATUS_CERT_REVOCATION_UNKNOWN;
[email protected]a04db822013-12-11 19:14:40381 base::string16 issuer_name(UTF8ToUTF16(cert->issuer().GetDisplayName()));
[email protected]03ef4b2a2012-03-06 15:04:20382 if (issuer_name.empty()) {
383 issuer_name.assign(l10n_util::GetStringUTF16(
384 IDS_PAGE_INFO_SECURITY_TAB_UNKNOWN_PARTY));
385 }
[email protected]94c74b42013-12-02 15:19:49386
[email protected]03ef4b2a2012-03-06 15:04:20387 site_identity_details_.assign(l10n_util::GetStringFUTF16(
[email protected]94c74b42013-12-02 15:19:49388 GetSiteIdentityDetailsMessageByCTInfo(
389 ssl.signed_certificate_timestamp_ids, false /* not EV */),
390 issuer_name));
[email protected]03ef4b2a2012-03-06 15:04:20391
392 site_identity_details_ += ASCIIToUTF16("\n\n");
393 if (ssl.cert_status & net::CERT_STATUS_UNABLE_TO_CHECK_REVOCATION) {
394 site_identity_details_ += l10n_util::GetStringUTF16(
395 IDS_PAGE_INFO_SECURITY_TAB_UNABLE_TO_CHECK_REVOCATION);
396 } else if (ssl.cert_status & net::CERT_STATUS_NO_REVOCATION_MECHANISM) {
397 site_identity_details_ += l10n_util::GetStringUTF16(
398 IDS_PAGE_INFO_SECURITY_TAB_NO_REVOCATION_MECHANISM);
399 } else {
400 NOTREACHED() << "Need to specify string for this warning";
401 }
402 } else if (ssl.cert_status & net::CERT_STATUS_IS_EV) {
403 // EV HTTPS page.
[email protected]94c74b42013-12-02 15:19:49404 site_identity_status_ = GetSiteIdentityStatusByCTInfo(
405 ssl.signed_certificate_timestamp_ids, true);
[email protected]03ef4b2a2012-03-06 15:04:20406 DCHECK(!cert->subject().organization_names.empty());
407 organization_name_ = UTF8ToUTF16(cert->subject().organization_names[0]);
408 // An EV Cert is required to have a city (localityName) and country but
409 // state is "if any".
410 DCHECK(!cert->subject().locality_name.empty());
411 DCHECK(!cert->subject().country_name.empty());
[email protected]a04db822013-12-11 19:14:40412 base::string16 locality;
[email protected]03ef4b2a2012-03-06 15:04:20413 if (!cert->subject().state_or_province_name.empty()) {
414 locality = l10n_util::GetStringFUTF16(
415 IDS_PAGEINFO_ADDRESS,
416 UTF8ToUTF16(cert->subject().locality_name),
417 UTF8ToUTF16(cert->subject().state_or_province_name),
418 UTF8ToUTF16(cert->subject().country_name));
419 } else {
420 locality = l10n_util::GetStringFUTF16(
421 IDS_PAGEINFO_PARTIAL_ADDRESS,
422 UTF8ToUTF16(cert->subject().locality_name),
423 UTF8ToUTF16(cert->subject().country_name));
424 }
425 DCHECK(!cert->subject().organization_names.empty());
426 site_identity_details_.assign(l10n_util::GetStringFUTF16(
[email protected]94c74b42013-12-02 15:19:49427 GetSiteIdentityDetailsMessageByCTInfo(
428 ssl.signed_certificate_timestamp_ids, true /* is EV */),
[email protected]03ef4b2a2012-03-06 15:04:20429 UTF8ToUTF16(cert->subject().organization_names[0]),
430 locality,
431 UTF8ToUTF16(cert->issuer().GetDisplayName())));
[email protected]03ef4b2a2012-03-06 15:04:20432 } else {
433 // Non-EV OK HTTPS page.
[email protected]94c74b42013-12-02 15:19:49434 site_identity_status_ = GetSiteIdentityStatusByCTInfo(
435 ssl.signed_certificate_timestamp_ids, false);
[email protected]a04db822013-12-11 19:14:40436 base::string16 issuer_name(UTF8ToUTF16(cert->issuer().GetDisplayName()));
[email protected]03ef4b2a2012-03-06 15:04:20437 if (issuer_name.empty()) {
438 issuer_name.assign(l10n_util::GetStringUTF16(
439 IDS_PAGE_INFO_SECURITY_TAB_UNKNOWN_PARTY));
440 }
[email protected]94c74b42013-12-02 15:19:49441
[email protected]03ef4b2a2012-03-06 15:04:20442 site_identity_details_.assign(l10n_util::GetStringFUTF16(
[email protected]94c74b42013-12-02 15:19:49443 GetSiteIdentityDetailsMessageByCTInfo(
444 ssl.signed_certificate_timestamp_ids, false /* not EV */),
445 issuer_name));
[email protected]03ef4b2a2012-03-06 15:04:20446 }
447 } else {
448 // HTTP or HTTPS with errors (not warnings).
449 site_identity_details_.assign(l10n_util::GetStringUTF16(
450 IDS_PAGE_INFO_SECURITY_TAB_INSECURE_IDENTITY));
451 if (ssl.security_style == content::SECURITY_STYLE_UNAUTHENTICATED)
452 site_identity_status_ = SITE_IDENTITY_STATUS_NO_CERT;
453 else
454 site_identity_status_ = SITE_IDENTITY_STATUS_ERROR;
455
[email protected]a04db822013-12-11 19:14:40456 const base::string16 bullet = UTF8ToUTF16("\n • ");
[email protected]03ef4b2a2012-03-06 15:04:20457 std::vector<SSLErrorInfo> errors;
458 SSLErrorInfo::GetErrorsForCertStatus(ssl.cert_id, ssl.cert_status,
459 url, &errors);
460 for (size_t i = 0; i < errors.size(); ++i) {
461 site_identity_details_ += bullet;
462 site_identity_details_ += errors[i].short_description();
463 }
464
465 if (ssl.cert_status & net::CERT_STATUS_NON_UNIQUE_NAME) {
466 site_identity_details_ += ASCIIToUTF16("\n\n");
467 site_identity_details_ += l10n_util::GetStringUTF16(
468 IDS_PAGE_INFO_SECURITY_TAB_NON_UNIQUE_NAME);
469 }
470 }
471
472 // Site Connection
473 // We consider anything less than 80 bits encryption to be weak encryption.
474 // TODO(wtc): Bug 1198735: report mixed/unsafe content for unencrypted and
475 // weakly encrypted connections.
476 site_connection_status_ = SITE_CONNECTION_STATUS_UNKNOWN;
477
[email protected]1c1051d2014-05-10 11:39:58478 if (ssl.security_style == content::SECURITY_STYLE_UNKNOWN) {
479 // Page is still loading, so SSL status is not yet available. Say nothing.
480 DCHECK_EQ(ssl.security_bits, -1);
481 site_connection_status_ = SITE_CONNECTION_STATUS_UNENCRYPTED;
482
483 site_connection_details_.assign(l10n_util::GetStringFUTF16(
484 IDS_PAGE_INFO_SECURITY_TAB_NOT_ENCRYPTED_CONNECTION_TEXT,
485 subject_name));
486 } else if (ssl.security_style == content::SECURITY_STYLE_UNAUTHENTICATED) {
487 // HTTPS without a certificate, or not HTTPS.
488 DCHECK(!ssl.cert_id);
489 site_connection_status_ = SITE_CONNECTION_STATUS_UNENCRYPTED;
[email protected]03ef4b2a2012-03-06 15:04:20490
491 site_connection_details_.assign(l10n_util::GetStringFUTF16(
492 IDS_PAGE_INFO_SECURITY_TAB_NOT_ENCRYPTED_CONNECTION_TEXT,
493 subject_name));
494 } else if (ssl.security_bits < 0) {
495 // Security strength is unknown. Say nothing.
496 site_connection_status_ = SITE_CONNECTION_STATUS_ENCRYPTED_ERROR;
497 } else if (ssl.security_bits == 0) {
498 DCHECK_NE(ssl.security_style, content::SECURITY_STYLE_UNAUTHENTICATED);
499 site_connection_status_ = SITE_CONNECTION_STATUS_ENCRYPTED_ERROR;
500 site_connection_details_.assign(l10n_util::GetStringFUTF16(
501 IDS_PAGE_INFO_SECURITY_TAB_NOT_ENCRYPTED_CONNECTION_TEXT,
502 subject_name));
503 } else if (ssl.security_bits < 80) {
504 site_connection_status_ = SITE_CONNECTION_STATUS_ENCRYPTED_ERROR;
505 site_connection_details_.assign(l10n_util::GetStringFUTF16(
506 IDS_PAGE_INFO_SECURITY_TAB_WEAK_ENCRYPTION_CONNECTION_TEXT,
507 subject_name));
508 } else {
509 site_connection_status_ = SITE_CONNECTION_STATUS_ENCRYPTED;
510 site_connection_details_.assign(l10n_util::GetStringFUTF16(
511 IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTED_CONNECTION_TEXT,
512 subject_name,
513 base::IntToString16(ssl.security_bits)));
514 if (ssl.content_status) {
515 bool ran_insecure_content =
516 !!(ssl.content_status & content::SSLStatus::RAN_INSECURE_CONTENT);
517 site_connection_status_ = ran_insecure_content ?
518 SITE_CONNECTION_STATUS_ENCRYPTED_ERROR
519 : SITE_CONNECTION_STATUS_MIXED_CONTENT;
520 site_connection_details_.assign(l10n_util::GetStringFUTF16(
521 IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTED_SENTENCE_LINK,
522 site_connection_details_,
523 l10n_util::GetStringUTF16(ran_insecure_content ?
524 IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTED_INSECURE_CONTENT_ERROR :
525 IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTED_INSECURE_CONTENT_WARNING)));
526 }
527 }
528
529 uint16 cipher_suite =
530 net::SSLConnectionStatusToCipherSuite(ssl.connection_status);
531 if (ssl.security_bits > 0 && cipher_suite) {
532 int ssl_version =
533 net::SSLConnectionStatusToVersion(ssl.connection_status);
534 const char* ssl_version_str;
535 net::SSLVersionToString(&ssl_version_str, ssl_version);
536 site_connection_details_ += ASCIIToUTF16("\n\n");
537 site_connection_details_ += l10n_util::GetStringFUTF16(
538 IDS_PAGE_INFO_SECURITY_TAB_SSL_VERSION,
539 ASCIIToUTF16(ssl_version_str));
540
541 bool did_fallback = (ssl.connection_status &
[email protected]80c75f682012-05-26 16:22:17542 net::SSL_CONNECTION_VERSION_FALLBACK) != 0;
[email protected]03ef4b2a2012-03-06 15:04:20543 bool no_renegotiation =
544 (ssl.connection_status &
545 net::SSL_CONNECTION_NO_RENEGOTIATION_EXTENSION) != 0;
546 const char *key_exchange, *cipher, *mac;
[email protected]b6c1d9e82013-06-12 17:26:57547 bool is_aead;
548 net::SSLCipherSuiteToStrings(
549 &key_exchange, &cipher, &mac, &is_aead, cipher_suite);
[email protected]03ef4b2a2012-03-06 15:04:20550
551 site_connection_details_ += ASCIIToUTF16("\n\n");
[email protected]b6c1d9e82013-06-12 17:26:57552 if (is_aead) {
553 site_connection_details_ += l10n_util::GetStringFUTF16(
554 IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTION_DETAILS_AEAD,
555 ASCIIToUTF16(cipher), ASCIIToUTF16(key_exchange));
556 } else {
557 site_connection_details_ += l10n_util::GetStringFUTF16(
558 IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTION_DETAILS,
559 ASCIIToUTF16(cipher), ASCIIToUTF16(mac), ASCIIToUTF16(key_exchange));
560 }
[email protected]03ef4b2a2012-03-06 15:04:20561
[email protected]03ef4b2a2012-03-06 15:04:20562 if (did_fallback) {
563 // For now, only SSLv3 fallback will trigger a warning icon.
564 if (site_connection_status_ < SITE_CONNECTION_STATUS_MIXED_CONTENT)
565 site_connection_status_ = SITE_CONNECTION_STATUS_MIXED_CONTENT;
566 site_connection_details_ += ASCIIToUTF16("\n\n");
567 site_connection_details_ += l10n_util::GetStringUTF16(
568 IDS_PAGE_INFO_SECURITY_TAB_FALLBACK_MESSAGE);
569 }
570 if (no_renegotiation) {
571 site_connection_details_ += ASCIIToUTF16("\n\n");
572 site_connection_details_ += l10n_util::GetStringUTF16(
573 IDS_PAGE_INFO_SECURITY_TAB_RENEGOTIATION_MESSAGE);
574 }
575 }
[email protected]e583f752012-08-30 13:26:21576
[email protected]71cd5ef2014-08-13 21:22:04577 // Check if a user decision has been made to allow or deny certificates with
578 // errors on this site.
579 ChromeSSLHostStateDelegate* delegate =
580 ChromeSSLHostStateDelegateFactory::GetForProfile(profile);
581 DCHECK(delegate);
582 // Only show an SSL decision revoke button if both the user has chosen to
583 // bypass SSL host errors for this host in the past and the user is not using
584 // the traditional "forget-at-session-restart" error decision memory.
585 show_ssl_decision_revoke_button_ = delegate->HasUserDecision(url.host()) &&
586 InRememberCertificateErrorDecisionsGroup();
587
[email protected]e583f752012-08-30 13:26:21588 // By default select the permissions tab that displays all the site
589 // permissions. In case of a connection error or an issue with the
590 // certificate presented by the website, select the connection tab to draw
591 // the user's attention to the issue. If the site does not provide a
592 // certificate because it was loaded over an unencrypted connection, don't
593 // select the connection tab.
594 WebsiteSettingsUI::TabId tab_id = WebsiteSettingsUI::TAB_ID_PERMISSIONS;
595 if (site_connection_status_ == SITE_CONNECTION_STATUS_ENCRYPTED_ERROR ||
596 site_connection_status_ == SITE_CONNECTION_STATUS_MIXED_CONTENT ||
597 site_identity_status_ == SITE_IDENTITY_STATUS_ERROR ||
[email protected]eaf3f322013-04-25 21:53:59598 site_identity_status_ == SITE_IDENTITY_STATUS_CERT_REVOCATION_UNKNOWN ||
599 site_identity_status_ == SITE_IDENTITY_STATUS_ADMIN_PROVIDED_CERT)
[email protected]e583f752012-08-30 13:26:21600 tab_id = WebsiteSettingsUI::TAB_ID_CONNECTION;
601 ui_->SetSelectedTab(tab_id);
[email protected]03ef4b2a2012-03-06 15:04:20602}
[email protected]0b9fdd72012-04-04 10:00:33603
[email protected]df818272012-04-20 13:10:50604void WebsiteSettings::PresentSitePermissions() {
605 PermissionInfoList permission_info_list;
606
607 WebsiteSettingsUI::PermissionInfo permission_info;
608 for (size_t i = 0; i < arraysize(kPermissionType); ++i) {
609 permission_info.type = kPermissionType[i];
[email protected]eb2140c2013-07-29 12:37:34610 if (permission_info.type == CONTENT_SETTINGS_TYPE_MIDI_SYSEX) {
611 const CommandLine* command_line = CommandLine::ForCurrentProcess();
612 if (!command_line->HasSwitch(switches::kEnableWebMIDI))
613 continue;
614 }
[email protected]df818272012-04-20 13:10:50615
616 content_settings::SettingInfo info;
[email protected]0bacc1912012-12-11 11:05:34617 if (permission_info.type == CONTENT_SETTINGS_TYPE_MEDIASTREAM) {
618 scoped_ptr<base::Value> mic_value(content_settings_->GetWebsiteSetting(
[email protected]007b3f82013-04-09 08:46:45619 site_url_,
620 site_url_,
621 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC,
622 std::string(),
623 &info));
[email protected]0bacc1912012-12-11 11:05:34624 ContentSetting mic_setting =
625 content_settings::ValueToContentSetting(mic_value.get());
626
627 scoped_ptr<base::Value> camera_value(content_settings_->GetWebsiteSetting(
[email protected]007b3f82013-04-09 08:46:45628 site_url_,
629 site_url_,
630 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA,
631 std::string(),
632 &info));
[email protected]0bacc1912012-12-11 11:05:34633 ContentSetting camera_setting =
634 content_settings::ValueToContentSetting(camera_value.get());
635
636 if (mic_setting != camera_setting || mic_setting == CONTENT_SETTING_ASK)
637 permission_info.setting = CONTENT_SETTING_DEFAULT;
638 else
639 permission_info.setting = mic_setting;
[email protected]fe4686a2012-10-19 15:38:26640 } else {
[email protected]2c95d102013-12-23 20:42:16641 scoped_ptr<base::Value> value(content_settings_->GetWebsiteSetting(
[email protected]007b3f82013-04-09 08:46:45642 site_url_, site_url_, permission_info.type, std::string(), &info));
[email protected]0bacc1912012-12-11 11:05:34643 DCHECK(value.get());
[email protected]2c95d102013-12-23 20:42:16644 if (value->GetType() == base::Value::TYPE_INTEGER) {
[email protected]0bacc1912012-12-11 11:05:34645 permission_info.setting =
646 content_settings::ValueToContentSetting(value.get());
647 } else {
648 NOTREACHED();
649 }
[email protected]fe4686a2012-10-19 15:38:26650 }
651
[email protected]8bdf45c32012-08-04 00:12:55652 permission_info.source = info.source;
[email protected]df818272012-04-20 13:10:50653
[email protected]b1d113d2012-06-27 21:27:34654 if (info.primary_pattern == ContentSettingsPattern::Wildcard() &&
[email protected]0bacc1912012-12-11 11:05:34655 info.secondary_pattern == ContentSettingsPattern::Wildcard() &&
656 permission_info.type != CONTENT_SETTINGS_TYPE_MEDIASTREAM) {
[email protected]b1d113d2012-06-27 21:27:34657 permission_info.default_setting = permission_info.setting;
658 permission_info.setting = CONTENT_SETTING_DEFAULT;
659 } else {
660 permission_info.default_setting =
661 content_settings_->GetDefaultContentSetting(permission_info.type,
662 NULL);
[email protected]df818272012-04-20 13:10:50663 }
[email protected]b1d113d2012-06-27 21:27:34664 permission_info_list.push_back(permission_info);
[email protected]df818272012-04-20 13:10:50665 }
666
667 ui_->SetPermissionInfo(permission_info_list);
[email protected]0b9fdd72012-04-04 10:00:33668}
669
[email protected]df818272012-04-20 13:10:50670void WebsiteSettings::PresentSiteData() {
671 CookieInfoList cookie_info_list;
[email protected]e0ac35892012-05-15 12:53:34672 const LocalSharedObjectsContainer& allowed_objects =
673 tab_specific_content_settings()->allowed_local_shared_objects();
674 const LocalSharedObjectsContainer& blocked_objects =
675 tab_specific_content_settings()->blocked_local_shared_objects();
676
677 // Add first party cookie and site data counts.
[email protected]df818272012-04-20 13:10:50678 WebsiteSettingsUI::CookieInfo cookie_info;
[email protected]e0ac35892012-05-15 12:53:34679 std::string cookie_source =
[email protected]ed32c212013-05-14 20:49:29680 net::registry_controlled_domains::GetDomainAndRegistry(
681 site_url_,
[email protected]aabe1792014-01-30 21:37:46682 net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES);
[email protected]e0ac35892012-05-15 12:53:34683 if (cookie_source.empty())
684 cookie_source = site_url_.host();
685 cookie_info.cookie_source = cookie_source;
686 cookie_info.allowed = allowed_objects.GetObjectCountForDomain(site_url_);
687 cookie_info.blocked = blocked_objects.GetObjectCountForDomain(site_url_);
688 cookie_info_list.push_back(cookie_info);
689
690 // Add third party cookie counts.
691 cookie_info.cookie_source = l10n_util::GetStringUTF8(
692 IDS_WEBSITE_SETTINGS_THIRD_PARTY_SITE_DATA);
693 cookie_info.allowed = allowed_objects.GetObjectCount() - cookie_info.allowed;
694 cookie_info.blocked = blocked_objects.GetObjectCount() - cookie_info.blocked;
[email protected]df818272012-04-20 13:10:50695 cookie_info_list.push_back(cookie_info);
[email protected]0b9fdd72012-04-04 10:00:33696
[email protected]df818272012-04-20 13:10:50697 ui_->SetCookieInfo(cookie_info_list);
[email protected]0b9fdd72012-04-04 10:00:33698}
[email protected]16de6de2012-04-04 12:24:14699
[email protected]24c8818c2012-04-25 09:57:41700void WebsiteSettings::PresentSiteIdentity() {
701 // After initialization the status about the site's connection
702 // and it's identity must be available.
703 DCHECK_NE(site_identity_status_, SITE_IDENTITY_STATUS_UNKNOWN);
704 DCHECK_NE(site_connection_status_, SITE_CONNECTION_STATUS_UNKNOWN);
705 WebsiteSettingsUI::IdentityInfo info;
706 if (site_identity_status_ == SITE_IDENTITY_STATUS_EV_CERT)
707 info.site_identity = UTF16ToUTF8(organization_name());
708 else
709 info.site_identity = site_url_.host();
710
711 info.connection_status = site_connection_status_;
712 info.connection_status_description =
713 UTF16ToUTF8(site_connection_details_);
714 info.identity_status = site_identity_status_;
715 info.identity_status_description =
716 UTF16ToUTF8(site_identity_details_);
[email protected]f61c1ce2012-05-09 13:55:11717 info.cert_id = cert_id_;
[email protected]3d6d34b12013-12-23 00:34:02718 info.signed_certificate_timestamp_ids.assign(
719 signed_certificate_timestamp_ids_.begin(),
720 signed_certificate_timestamp_ids_.end());
[email protected]71cd5ef2014-08-13 21:22:04721 info.show_ssl_decision_revoke_button = show_ssl_decision_revoke_button_;
[email protected]24c8818c2012-04-25 09:57:41722 ui_->SetIdentityInfo(info);
723}
724
[email protected]15b092542012-05-16 13:08:14725void WebsiteSettings::PresentHistoryInfo(base::Time first_visit) {
726 if (first_visit == base::Time()) {
[email protected]b959d7d42013-12-13 17:26:37727 ui_->SetFirstVisit(base::string16());
[email protected]15b092542012-05-16 13:08:14728 return;
729 }
730
731 bool visited_before_today = false;
732 base::Time today = base::Time::Now().LocalMidnight();
733 base::Time first_visit_midnight = first_visit.LocalMidnight();
734 visited_before_today = (first_visit_midnight < today);
735
[email protected]a04db822013-12-11 19:14:40736 base::string16 first_visit_text;
[email protected]15b092542012-05-16 13:08:14737 if (visited_before_today) {
738 first_visit_text = l10n_util::GetStringFUTF16(
739 IDS_PAGE_INFO_SECURITY_TAB_VISITED_BEFORE_TODAY,
740 base::TimeFormatShortDate(first_visit));
741 } else {
742 first_visit_text = l10n_util::GetStringUTF16(
743 IDS_PAGE_INFO_SECURITY_TAB_FIRST_VISITED_TODAY);
[email protected]15b092542012-05-16 13:08:14744 }
745 ui_->SetFirstVisit(first_visit_text);
746}