blob: 28362e7507c5493143fb182dad266a09643e03a2 [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"
12#include "base/i18n/time_formatting.h"
[email protected]3ea1b182013-02-08 22:38:4113#include "base/metrics/histogram.h"
14#include "base/strings/string_number_conversions.h"
[email protected]03ef4b2a2012-03-06 15:04:2015#include "base/utf_string_conversions.h"
[email protected]0b9fdd72012-04-04 10:00:3316#include "base/values.h"
[email protected]b0cb5e82012-07-19 19:22:4717#include "chrome/browser/browsing_data/browsing_data_cookie_helper.h"
18#include "chrome/browser/browsing_data/browsing_data_database_helper.h"
19#include "chrome/browser/browsing_data/browsing_data_file_system_helper.h"
20#include "chrome/browser/browsing_data/browsing_data_indexed_db_helper.h"
21#include "chrome/browser/browsing_data/browsing_data_local_storage_helper.h"
22#include "chrome/browser/browsing_data/browsing_data_server_bound_cert_helper.h"
[email protected]0b9fdd72012-04-04 10:00:3323#include "chrome/browser/content_settings/content_settings_utils.h"
24#include "chrome/browser/content_settings/host_content_settings_map.h"
[email protected]df818272012-04-20 13:10:5025#include "chrome/browser/content_settings/local_shared_objects_container.h"
[email protected]77a91c72012-08-13 16:19:3426#include "chrome/browser/history/history_service_factory.h"
[email protected]4a8adfa02013-03-19 22:37:4627#include "chrome/browser/infobars/infobar_service.h"
[email protected]03ef4b2a2012-03-06 15:04:2028#include "chrome/browser/profiles/profile.h"
[email protected]03ef4b2a2012-03-06 15:04:2029#include "chrome/browser/ssl/ssl_error_info.h"
[email protected]66f157312012-08-01 13:50:2630#include "chrome/browser/ui/website_settings/website_settings_infobar_delegate.h"
[email protected]4237dd52012-06-05 00:00:3231#include "chrome/browser/ui/website_settings/website_settings_ui.h"
[email protected]0b9fdd72012-04-04 10:00:3332#include "chrome/common/content_settings_pattern.h"
33#include "content/public/browser/browser_thread.h"
[email protected]b59c6cf02012-03-12 20:51:4234#include "content/public/browser/cert_store.h"
[email protected]e22d64f2012-09-10 09:03:2335#include "content/public/browser/user_metrics.h"
[email protected]03ef4b2a2012-03-06 15:04:2036#include "content/public/common/ssl_status.h"
37#include "content/public/common/url_constants.h"
38#include "grit/chromium_strings.h"
39#include "grit/generated_resources.h"
[email protected]be28b5f42012-07-20 11:31:2540#include "net/base/registry_controlled_domains/registry_controlled_domain.h"
[email protected]6e7845ae2013-03-29 21:48:1141#include "net/cert/cert_status_flags.h"
42#include "net/cert/x509_certificate.h"
[email protected]536fd0b2013-03-14 17:41:5743#include "net/ssl/ssl_cipher_suite_names.h"
44#include "net/ssl/ssl_connection_status_flags.h"
[email protected]03ef4b2a2012-03-06 15:04:2045#include "ui/base/l10n/l10n_util.h"
46#include "ui/base/resource/resource_bundle.h"
47
[email protected]eaf3f322013-04-25 21:53:5948#if defined(ENABLE_CONFIGURATION_POLICY)
49#include "chrome/browser/policy/browser_policy_connector.h"
50#endif
51
[email protected]0b9fdd72012-04-04 10:00:3352using content::BrowserThread;
53
54namespace {
55
[email protected]b1d113d2012-06-27 21:27:3456// The list of content settings types to display on the Website Settings UI.
[email protected]0b9fdd72012-04-04 10:00:3357ContentSettingsType kPermissionType[] = {
[email protected]b1d113d2012-06-27 21:27:3458 CONTENT_SETTINGS_TYPE_IMAGES,
59 CONTENT_SETTINGS_TYPE_JAVASCRIPT,
[email protected]0b9fdd72012-04-04 10:00:3360 CONTENT_SETTINGS_TYPE_PLUGINS,
[email protected]b1d113d2012-06-27 21:27:3461 CONTENT_SETTINGS_TYPE_POPUPS,
[email protected]0b9fdd72012-04-04 10:00:3362 CONTENT_SETTINGS_TYPE_GEOLOCATION,
[email protected]b1d113d2012-06-27 21:27:3463 CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
64 CONTENT_SETTINGS_TYPE_FULLSCREEN,
65 CONTENT_SETTINGS_TYPE_MOUSELOCK,
66 CONTENT_SETTINGS_TYPE_MEDIASTREAM,
[email protected]0b9fdd72012-04-04 10:00:3367};
68
69} // namespace
70
71WebsiteSettings::WebsiteSettings(
72 WebsiteSettingsUI* ui,
73 Profile* profile,
[email protected]df818272012-04-20 13:10:5074 TabSpecificContentSettings* tab_specific_content_settings,
[email protected]4f822f022012-12-20 19:11:4275 InfoBarService* infobar_service,
[email protected]0b9fdd72012-04-04 10:00:3376 const GURL& url,
77 const content::SSLStatus& ssl,
78 content::CertStore* cert_store)
[email protected]df818272012-04-20 13:10:5079 : TabSpecificContentSettings::SiteDataObserver(
80 tab_specific_content_settings),
81 ui_(ui),
[email protected]4f822f022012-12-20 19:11:4282 infobar_service_(infobar_service),
[email protected]66f157312012-08-01 13:50:2683 show_info_bar_(false),
[email protected]0b9fdd72012-04-04 10:00:3384 site_url_(url),
85 site_identity_status_(SITE_IDENTITY_STATUS_UNKNOWN),
[email protected]f61c1ce2012-05-09 13:55:1186 cert_id_(0),
[email protected]03ef4b2a2012-03-06 15:04:2087 site_connection_status_(SITE_CONNECTION_STATUS_UNKNOWN),
[email protected]0b9fdd72012-04-04 10:00:3388 cert_store_(cert_store),
89 content_settings_(profile->GetHostContentSettingsMap()) {
[email protected]03ef4b2a2012-03-06 15:04:2090 Init(profile, url, ssl);
[email protected]0b9fdd72012-04-04 10:00:3391
[email protected]78a1fd90a2012-07-19 08:11:2592 HistoryService* history_service = HistoryServiceFactory::GetForProfile(
93 profile, Profile::EXPLICIT_ACCESS);
[email protected]15b092542012-05-16 13:08:1494 if (history_service) {
95 history_service->GetVisibleVisitCountToHost(
96 site_url_,
97 &visit_count_request_consumer_,
98 base::Bind(&WebsiteSettings::OnGotVisitCountToHost,
99 base::Unretained(this)));
100 }
101
[email protected]0b9fdd72012-04-04 10:00:33102 PresentSitePermissions();
[email protected]df818272012-04-20 13:10:50103 PresentSiteData();
[email protected]24c8818c2012-04-25 09:57:41104 PresentSiteIdentity();
[email protected]15b092542012-05-16 13:08:14105 PresentHistoryInfo(base::Time());
[email protected]e22d64f2012-09-10 09:03:23106
107 // Every time the Website Settings UI is opened a |WebsiteSettings| object is
108 // created. So this counts how ofter the Website Settings UI is opened.
109 content::RecordAction(content::UserMetricsAction("WebsiteSettings_Opened"));
[email protected]03ef4b2a2012-03-06 15:04:20110}
111
[email protected]0b9fdd72012-04-04 10:00:33112WebsiteSettings::~WebsiteSettings() {
[email protected]03ef4b2a2012-03-06 15:04:20113}
114
[email protected]df818272012-04-20 13:10:50115void WebsiteSettings::OnSitePermissionChanged(ContentSettingsType type,
116 ContentSetting setting) {
[email protected]e22d64f2012-09-10 09:03:23117 // Count how often a permission for a specific content type is changed using
118 // the Website Settings UI.
119 UMA_HISTOGRAM_COUNTS("WebsiteSettings.PermissionChanged", type);
120
[email protected]df818272012-04-20 13:10:50121 ContentSettingsPattern primary_pattern;
122 ContentSettingsPattern secondary_pattern;
123 switch (type) {
124 case CONTENT_SETTINGS_TYPE_GEOLOCATION:
125 // TODO(markusheintz): The rule we create here should also change the
126 // location permission for iframed content.
127 primary_pattern = ContentSettingsPattern::FromURLNoWildcard(site_url_);
128 secondary_pattern = ContentSettingsPattern::FromURLNoWildcard(site_url_);
129 break;
130 case CONTENT_SETTINGS_TYPE_NOTIFICATIONS:
131 primary_pattern = ContentSettingsPattern::FromURLNoWildcard(site_url_);
132 secondary_pattern = ContentSettingsPattern::Wildcard();
133 break;
[email protected]b1d113d2012-06-27 21:27:34134 case CONTENT_SETTINGS_TYPE_IMAGES:
135 case CONTENT_SETTINGS_TYPE_JAVASCRIPT:
[email protected]df818272012-04-20 13:10:50136 case CONTENT_SETTINGS_TYPE_PLUGINS:
137 case CONTENT_SETTINGS_TYPE_POPUPS:
[email protected]b1d113d2012-06-27 21:27:34138 case CONTENT_SETTINGS_TYPE_FULLSCREEN:
139 case CONTENT_SETTINGS_TYPE_MOUSELOCK:
[email protected]df818272012-04-20 13:10:50140 primary_pattern = ContentSettingsPattern::FromURL(site_url_);
141 secondary_pattern = ContentSettingsPattern::Wildcard();
142 break;
[email protected]0bacc1912012-12-11 11:05:34143 case CONTENT_SETTINGS_TYPE_MEDIASTREAM: {
144 // We need to use the same same patterns as other places like infobar code
145 // to override the existing rule instead of creating the new one.
146 primary_pattern = ContentSettingsPattern::FromURLNoWildcard(site_url_);
147 secondary_pattern = ContentSettingsPattern::Wildcard();
148 // Set permission for both microphone and camera.
149 content_settings_->SetContentSetting(
[email protected]007b3f82013-04-09 08:46:45150 primary_pattern,
151 secondary_pattern,
152 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC,
153 std::string(),
154 setting);
[email protected]0bacc1912012-12-11 11:05:34155
156 content_settings_->SetContentSetting(
[email protected]007b3f82013-04-09 08:46:45157 primary_pattern,
158 secondary_pattern,
159 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA,
160 std::string(),
161 setting);
[email protected]0bacc1912012-12-11 11:05:34162 break;
163 }
[email protected]df818272012-04-20 13:10:50164 default:
165 NOTREACHED() << "ContentSettingsType " << type << "is not supported.";
166 break;
[email protected]0b9fdd72012-04-04 10:00:33167 }
168
[email protected]0bacc1912012-12-11 11:05:34169 if (type != CONTENT_SETTINGS_TYPE_MEDIASTREAM) {
170 // Permission settings are specified via rules. There exists always at least
171 // one rule for the default setting. Get the rule that currently defines
172 // the permission for the given permission |type|. Then test whether the
173 // existing rule is more specific than the rule we are about to create. If
174 // the existing rule is more specific, than change the existing rule instead
175 // of creating a new rule that would be hidden behind the existing rule.
176 // This is not a concern for CONTENT_SETTINGS_TYPE_MEDIASTREAM since users
177 // can not create media settings exceptions by hand.
178 content_settings::SettingInfo info;
179 scoped_ptr<Value> v(content_settings_->GetWebsiteSetting(
[email protected]007b3f82013-04-09 08:46:45180 site_url_, site_url_, type, std::string(), &info));
[email protected]0bacc1912012-12-11 11:05:34181 DCHECK(info.source == content_settings::SETTING_SOURCE_USER);
182 ContentSettingsPattern::Relation r1 =
183 info.primary_pattern.Compare(primary_pattern);
184 DCHECK(r1 != ContentSettingsPattern::DISJOINT_ORDER_POST &&
185 r1 != ContentSettingsPattern::DISJOINT_ORDER_PRE);
186 if (r1 == ContentSettingsPattern::PREDECESSOR) {
187 primary_pattern = info.primary_pattern;
188 } else if (r1 == ContentSettingsPattern::IDENTITY) {
189 ContentSettingsPattern::Relation r2 =
190 info.secondary_pattern.Compare(secondary_pattern);
191 DCHECK(r2 != ContentSettingsPattern::DISJOINT_ORDER_POST &&
192 r2 != ContentSettingsPattern::DISJOINT_ORDER_PRE);
193 if (r2 == ContentSettingsPattern::PREDECESSOR)
194 secondary_pattern = info.secondary_pattern;
195 }
196
197 Value* value = NULL;
198 if (setting != CONTENT_SETTING_DEFAULT)
199 value = Value::CreateIntegerValue(setting);
200 content_settings_->SetWebsiteSetting(
[email protected]007b3f82013-04-09 08:46:45201 primary_pattern, secondary_pattern, type, std::string(), value);
[email protected]df818272012-04-20 13:10:50202 }
203
[email protected]66f157312012-08-01 13:50:26204 show_info_bar_ = true;
[email protected]2f45d542012-08-22 08:47:24205
[email protected]76955932012-12-06 11:01:10206// TODO(markusheintz): This is a temporary hack to fix issue:
207// http://crbug.com/144203.
[email protected]e379ba42012-08-22 22:40:25208#if defined(OS_MACOSX)
[email protected]2f45d542012-08-22 08:47:24209 // Refresh the UI to reflect the new setting.
210 PresentSitePermissions();
[email protected]e379ba42012-08-22 22:40:25211#endif
[email protected]df818272012-04-20 13:10:50212}
213
[email protected]15b092542012-05-16 13:08:14214void WebsiteSettings::OnGotVisitCountToHost(HistoryService::Handle handle,
215 bool found_visits,
216 int visit_count,
217 base::Time first_visit) {
218 if (!found_visits) {
219 // This indicates an error, such as the page's URL scheme wasn't
220 // http/https.
221 first_visit = base::Time();
222 } else if (visit_count == 0) {
223 first_visit = base::Time::Now();
224 }
225 PresentHistoryInfo(first_visit);
226}
227
[email protected]df818272012-04-20 13:10:50228void WebsiteSettings::OnSiteDataAccessed() {
229 PresentSiteData();
[email protected]0b9fdd72012-04-04 10:00:33230}
231
[email protected]66f157312012-08-01 13:50:26232void WebsiteSettings::OnUIClosing() {
[email protected]0be09932013-01-08 02:03:50233 if (show_info_bar_)
234 WebsiteSettingsInfobarDelegate::Create(infobar_service_);
[email protected]66f157312012-08-01 13:50:26235}
236
[email protected]0b9fdd72012-04-04 10:00:33237void WebsiteSettings::Init(Profile* profile,
238 const GURL& url,
239 const content::SSLStatus& ssl) {
[email protected]03ef4b2a2012-03-06 15:04:20240 if (url.SchemeIs(chrome::kChromeUIScheme)) {
241 site_identity_status_ = SITE_IDENTITY_STATUS_INTERNAL_PAGE;
242 site_identity_details_ =
243 l10n_util::GetStringUTF16(IDS_PAGE_INFO_INTERNAL_PAGE);
244 site_connection_status_ = SITE_CONNECTION_STATUS_INTERNAL_PAGE;
245 return;
246 }
247
248 scoped_refptr<net::X509Certificate> cert;
249
250 // Identity section.
251 string16 subject_name(UTF8ToUTF16(url.host()));
[email protected]03ef4b2a2012-03-06 15:04:20252 if (subject_name.empty()) {
253 subject_name.assign(
254 l10n_util::GetStringUTF16(IDS_PAGE_INFO_SECURITY_TAB_UNKNOWN_PARTY));
[email protected]03ef4b2a2012-03-06 15:04:20255 }
256
[email protected]f61c1ce2012-05-09 13:55:11257 cert_id_ = ssl.cert_id;
258
[email protected]03ef4b2a2012-03-06 15:04:20259 if (ssl.cert_id &&
260 cert_store_->RetrieveCert(ssl.cert_id, &cert) &&
261 (!net::IsCertStatusError(ssl.cert_status) ||
262 net::IsCertStatusMinorError(ssl.cert_status))) {
263 // There are no major errors. Check for minor errors.
[email protected]eaf3f322013-04-25 21:53:59264 bool used_policy_certificates = false;
265#if defined(ENABLE_CONFIGURATION_POLICY)
266 used_policy_certificates =
267 policy::BrowserPolicyConnector::UsedPolicyCertificates(profile);
268#endif
269 if (used_policy_certificates) {
270 site_identity_status_ = SITE_IDENTITY_STATUS_ADMIN_PROVIDED_CERT;
271 site_identity_details_ =
272 l10n_util::GetStringFUTF16(IDS_CERT_POLICY_PROVIDED_CERT_MESSAGE,
273 UTF8ToUTF16(url.host()));
274 } else if (net::IsCertStatusMinorError(ssl.cert_status)) {
[email protected]03ef4b2a2012-03-06 15:04:20275 site_identity_status_ = SITE_IDENTITY_STATUS_CERT_REVOCATION_UNKNOWN;
276 string16 issuer_name(UTF8ToUTF16(cert->issuer().GetDisplayName()));
277 if (issuer_name.empty()) {
278 issuer_name.assign(l10n_util::GetStringUTF16(
279 IDS_PAGE_INFO_SECURITY_TAB_UNKNOWN_PARTY));
280 }
281 site_identity_details_.assign(l10n_util::GetStringFUTF16(
282 IDS_PAGE_INFO_SECURITY_TAB_SECURE_IDENTITY, issuer_name));
283
284 site_identity_details_ += ASCIIToUTF16("\n\n");
285 if (ssl.cert_status & net::CERT_STATUS_UNABLE_TO_CHECK_REVOCATION) {
286 site_identity_details_ += l10n_util::GetStringUTF16(
287 IDS_PAGE_INFO_SECURITY_TAB_UNABLE_TO_CHECK_REVOCATION);
288 } else if (ssl.cert_status & net::CERT_STATUS_NO_REVOCATION_MECHANISM) {
289 site_identity_details_ += l10n_util::GetStringUTF16(
290 IDS_PAGE_INFO_SECURITY_TAB_NO_REVOCATION_MECHANISM);
291 } else {
292 NOTREACHED() << "Need to specify string for this warning";
293 }
294 } else if (ssl.cert_status & net::CERT_STATUS_IS_EV) {
295 // EV HTTPS page.
296 site_identity_status_ = SITE_IDENTITY_STATUS_EV_CERT;
297 DCHECK(!cert->subject().organization_names.empty());
298 organization_name_ = UTF8ToUTF16(cert->subject().organization_names[0]);
299 // An EV Cert is required to have a city (localityName) and country but
300 // state is "if any".
301 DCHECK(!cert->subject().locality_name.empty());
302 DCHECK(!cert->subject().country_name.empty());
303 string16 locality;
304 if (!cert->subject().state_or_province_name.empty()) {
305 locality = l10n_util::GetStringFUTF16(
306 IDS_PAGEINFO_ADDRESS,
307 UTF8ToUTF16(cert->subject().locality_name),
308 UTF8ToUTF16(cert->subject().state_or_province_name),
309 UTF8ToUTF16(cert->subject().country_name));
310 } else {
311 locality = l10n_util::GetStringFUTF16(
312 IDS_PAGEINFO_PARTIAL_ADDRESS,
313 UTF8ToUTF16(cert->subject().locality_name),
314 UTF8ToUTF16(cert->subject().country_name));
315 }
316 DCHECK(!cert->subject().organization_names.empty());
317 site_identity_details_.assign(l10n_util::GetStringFUTF16(
318 IDS_PAGE_INFO_SECURITY_TAB_SECURE_IDENTITY_EV,
319 UTF8ToUTF16(cert->subject().organization_names[0]),
320 locality,
321 UTF8ToUTF16(cert->issuer().GetDisplayName())));
[email protected]03ef4b2a2012-03-06 15:04:20322 } else {
323 // Non-EV OK HTTPS page.
324 site_identity_status_ = SITE_IDENTITY_STATUS_CERT;
325 string16 issuer_name(UTF8ToUTF16(cert->issuer().GetDisplayName()));
326 if (issuer_name.empty()) {
327 issuer_name.assign(l10n_util::GetStringUTF16(
328 IDS_PAGE_INFO_SECURITY_TAB_UNKNOWN_PARTY));
329 }
330 site_identity_details_.assign(l10n_util::GetStringFUTF16(
331 IDS_PAGE_INFO_SECURITY_TAB_SECURE_IDENTITY, issuer_name));
332 }
333 } else {
334 // HTTP or HTTPS with errors (not warnings).
335 site_identity_details_.assign(l10n_util::GetStringUTF16(
336 IDS_PAGE_INFO_SECURITY_TAB_INSECURE_IDENTITY));
337 if (ssl.security_style == content::SECURITY_STYLE_UNAUTHENTICATED)
338 site_identity_status_ = SITE_IDENTITY_STATUS_NO_CERT;
339 else
340 site_identity_status_ = SITE_IDENTITY_STATUS_ERROR;
341
342 const string16 bullet = UTF8ToUTF16("\n • ");
343 std::vector<SSLErrorInfo> errors;
344 SSLErrorInfo::GetErrorsForCertStatus(ssl.cert_id, ssl.cert_status,
345 url, &errors);
346 for (size_t i = 0; i < errors.size(); ++i) {
347 site_identity_details_ += bullet;
348 site_identity_details_ += errors[i].short_description();
349 }
350
351 if (ssl.cert_status & net::CERT_STATUS_NON_UNIQUE_NAME) {
352 site_identity_details_ += ASCIIToUTF16("\n\n");
353 site_identity_details_ += l10n_util::GetStringUTF16(
354 IDS_PAGE_INFO_SECURITY_TAB_NON_UNIQUE_NAME);
355 }
356 }
357
358 // Site Connection
359 // We consider anything less than 80 bits encryption to be weak encryption.
360 // TODO(wtc): Bug 1198735: report mixed/unsafe content for unencrypted and
361 // weakly encrypted connections.
362 site_connection_status_ = SITE_CONNECTION_STATUS_UNKNOWN;
363
364 if (!ssl.cert_id) {
365 // Not HTTPS.
366 DCHECK_EQ(ssl.security_style, content::SECURITY_STYLE_UNAUTHENTICATED);
367 if (ssl.security_style == content::SECURITY_STYLE_UNAUTHENTICATED)
368 site_connection_status_ = SITE_CONNECTION_STATUS_UNENCRYPTED;
369 else
370 site_connection_status_ = SITE_CONNECTION_STATUS_ENCRYPTED_ERROR;
371
372 site_connection_details_.assign(l10n_util::GetStringFUTF16(
373 IDS_PAGE_INFO_SECURITY_TAB_NOT_ENCRYPTED_CONNECTION_TEXT,
374 subject_name));
375 } else if (ssl.security_bits < 0) {
376 // Security strength is unknown. Say nothing.
377 site_connection_status_ = SITE_CONNECTION_STATUS_ENCRYPTED_ERROR;
378 } else if (ssl.security_bits == 0) {
379 DCHECK_NE(ssl.security_style, content::SECURITY_STYLE_UNAUTHENTICATED);
380 site_connection_status_ = SITE_CONNECTION_STATUS_ENCRYPTED_ERROR;
381 site_connection_details_.assign(l10n_util::GetStringFUTF16(
382 IDS_PAGE_INFO_SECURITY_TAB_NOT_ENCRYPTED_CONNECTION_TEXT,
383 subject_name));
384 } else if (ssl.security_bits < 80) {
385 site_connection_status_ = SITE_CONNECTION_STATUS_ENCRYPTED_ERROR;
386 site_connection_details_.assign(l10n_util::GetStringFUTF16(
387 IDS_PAGE_INFO_SECURITY_TAB_WEAK_ENCRYPTION_CONNECTION_TEXT,
388 subject_name));
389 } else {
390 site_connection_status_ = SITE_CONNECTION_STATUS_ENCRYPTED;
391 site_connection_details_.assign(l10n_util::GetStringFUTF16(
392 IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTED_CONNECTION_TEXT,
393 subject_name,
394 base::IntToString16(ssl.security_bits)));
395 if (ssl.content_status) {
396 bool ran_insecure_content =
397 !!(ssl.content_status & content::SSLStatus::RAN_INSECURE_CONTENT);
398 site_connection_status_ = ran_insecure_content ?
399 SITE_CONNECTION_STATUS_ENCRYPTED_ERROR
400 : SITE_CONNECTION_STATUS_MIXED_CONTENT;
401 site_connection_details_.assign(l10n_util::GetStringFUTF16(
402 IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTED_SENTENCE_LINK,
403 site_connection_details_,
404 l10n_util::GetStringUTF16(ran_insecure_content ?
405 IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTED_INSECURE_CONTENT_ERROR :
406 IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTED_INSECURE_CONTENT_WARNING)));
407 }
408 }
409
410 uint16 cipher_suite =
411 net::SSLConnectionStatusToCipherSuite(ssl.connection_status);
412 if (ssl.security_bits > 0 && cipher_suite) {
413 int ssl_version =
414 net::SSLConnectionStatusToVersion(ssl.connection_status);
415 const char* ssl_version_str;
416 net::SSLVersionToString(&ssl_version_str, ssl_version);
417 site_connection_details_ += ASCIIToUTF16("\n\n");
418 site_connection_details_ += l10n_util::GetStringFUTF16(
419 IDS_PAGE_INFO_SECURITY_TAB_SSL_VERSION,
420 ASCIIToUTF16(ssl_version_str));
421
422 bool did_fallback = (ssl.connection_status &
[email protected]80c75f682012-05-26 16:22:17423 net::SSL_CONNECTION_VERSION_FALLBACK) != 0;
[email protected]03ef4b2a2012-03-06 15:04:20424 bool no_renegotiation =
425 (ssl.connection_status &
426 net::SSL_CONNECTION_NO_RENEGOTIATION_EXTENSION) != 0;
427 const char *key_exchange, *cipher, *mac;
428 net::SSLCipherSuiteToStrings(&key_exchange, &cipher, &mac, cipher_suite);
429
430 site_connection_details_ += ASCIIToUTF16("\n\n");
431 site_connection_details_ += l10n_util::GetStringFUTF16(
432 IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTION_DETAILS,
433 ASCIIToUTF16(cipher), ASCIIToUTF16(mac), ASCIIToUTF16(key_exchange));
434
[email protected]03ef4b2a2012-03-06 15:04:20435 if (did_fallback) {
436 // For now, only SSLv3 fallback will trigger a warning icon.
437 if (site_connection_status_ < SITE_CONNECTION_STATUS_MIXED_CONTENT)
438 site_connection_status_ = SITE_CONNECTION_STATUS_MIXED_CONTENT;
439 site_connection_details_ += ASCIIToUTF16("\n\n");
440 site_connection_details_ += l10n_util::GetStringUTF16(
441 IDS_PAGE_INFO_SECURITY_TAB_FALLBACK_MESSAGE);
442 }
443 if (no_renegotiation) {
444 site_connection_details_ += ASCIIToUTF16("\n\n");
445 site_connection_details_ += l10n_util::GetStringUTF16(
446 IDS_PAGE_INFO_SECURITY_TAB_RENEGOTIATION_MESSAGE);
447 }
448 }
[email protected]e583f752012-08-30 13:26:21449
450 // By default select the permissions tab that displays all the site
451 // permissions. In case of a connection error or an issue with the
452 // certificate presented by the website, select the connection tab to draw
453 // the user's attention to the issue. If the site does not provide a
454 // certificate because it was loaded over an unencrypted connection, don't
455 // select the connection tab.
456 WebsiteSettingsUI::TabId tab_id = WebsiteSettingsUI::TAB_ID_PERMISSIONS;
457 if (site_connection_status_ == SITE_CONNECTION_STATUS_ENCRYPTED_ERROR ||
458 site_connection_status_ == SITE_CONNECTION_STATUS_MIXED_CONTENT ||
459 site_identity_status_ == SITE_IDENTITY_STATUS_ERROR ||
[email protected]eaf3f322013-04-25 21:53:59460 site_identity_status_ == SITE_IDENTITY_STATUS_CERT_REVOCATION_UNKNOWN ||
461 site_identity_status_ == SITE_IDENTITY_STATUS_ADMIN_PROVIDED_CERT)
[email protected]e583f752012-08-30 13:26:21462 tab_id = WebsiteSettingsUI::TAB_ID_CONNECTION;
463 ui_->SetSelectedTab(tab_id);
[email protected]03ef4b2a2012-03-06 15:04:20464}
[email protected]0b9fdd72012-04-04 10:00:33465
[email protected]df818272012-04-20 13:10:50466void WebsiteSettings::PresentSitePermissions() {
467 PermissionInfoList permission_info_list;
468
469 WebsiteSettingsUI::PermissionInfo permission_info;
470 for (size_t i = 0; i < arraysize(kPermissionType); ++i) {
471 permission_info.type = kPermissionType[i];
472
473 content_settings::SettingInfo info;
[email protected]0bacc1912012-12-11 11:05:34474 if (permission_info.type == CONTENT_SETTINGS_TYPE_MEDIASTREAM) {
475 scoped_ptr<base::Value> mic_value(content_settings_->GetWebsiteSetting(
[email protected]007b3f82013-04-09 08:46:45476 site_url_,
477 site_url_,
478 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC,
479 std::string(),
480 &info));
[email protected]0bacc1912012-12-11 11:05:34481 ContentSetting mic_setting =
482 content_settings::ValueToContentSetting(mic_value.get());
483
484 scoped_ptr<base::Value> camera_value(content_settings_->GetWebsiteSetting(
[email protected]007b3f82013-04-09 08:46:45485 site_url_,
486 site_url_,
487 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA,
488 std::string(),
489 &info));
[email protected]0bacc1912012-12-11 11:05:34490 ContentSetting camera_setting =
491 content_settings::ValueToContentSetting(camera_value.get());
492
493 if (mic_setting != camera_setting || mic_setting == CONTENT_SETTING_ASK)
494 permission_info.setting = CONTENT_SETTING_DEFAULT;
495 else
496 permission_info.setting = mic_setting;
[email protected]fe4686a2012-10-19 15:38:26497 } else {
[email protected]0bacc1912012-12-11 11:05:34498 scoped_ptr<Value> value(content_settings_->GetWebsiteSetting(
[email protected]007b3f82013-04-09 08:46:45499 site_url_, site_url_, permission_info.type, std::string(), &info));
[email protected]0bacc1912012-12-11 11:05:34500 DCHECK(value.get());
501 if (value->GetType() == Value::TYPE_INTEGER) {
502 permission_info.setting =
503 content_settings::ValueToContentSetting(value.get());
504 } else {
505 NOTREACHED();
506 }
[email protected]fe4686a2012-10-19 15:38:26507 }
508
[email protected]8bdf45c32012-08-04 00:12:55509 permission_info.source = info.source;
[email protected]df818272012-04-20 13:10:50510
[email protected]b1d113d2012-06-27 21:27:34511 if (info.primary_pattern == ContentSettingsPattern::Wildcard() &&
[email protected]0bacc1912012-12-11 11:05:34512 info.secondary_pattern == ContentSettingsPattern::Wildcard() &&
513 permission_info.type != CONTENT_SETTINGS_TYPE_MEDIASTREAM) {
[email protected]b1d113d2012-06-27 21:27:34514 permission_info.default_setting = permission_info.setting;
515 permission_info.setting = CONTENT_SETTING_DEFAULT;
516 } else {
517 permission_info.default_setting =
518 content_settings_->GetDefaultContentSetting(permission_info.type,
519 NULL);
[email protected]df818272012-04-20 13:10:50520 }
[email protected]b1d113d2012-06-27 21:27:34521 permission_info_list.push_back(permission_info);
[email protected]df818272012-04-20 13:10:50522 }
523
524 ui_->SetPermissionInfo(permission_info_list);
[email protected]0b9fdd72012-04-04 10:00:33525}
526
[email protected]df818272012-04-20 13:10:50527void WebsiteSettings::PresentSiteData() {
528 CookieInfoList cookie_info_list;
[email protected]e0ac35892012-05-15 12:53:34529 const LocalSharedObjectsContainer& allowed_objects =
530 tab_specific_content_settings()->allowed_local_shared_objects();
531 const LocalSharedObjectsContainer& blocked_objects =
532 tab_specific_content_settings()->blocked_local_shared_objects();
533
534 // Add first party cookie and site data counts.
[email protected]df818272012-04-20 13:10:50535 WebsiteSettingsUI::CookieInfo cookie_info;
[email protected]e0ac35892012-05-15 12:53:34536 std::string cookie_source =
537 net::RegistryControlledDomainService::GetDomainAndRegistry(site_url_);
538 if (cookie_source.empty())
539 cookie_source = site_url_.host();
540 cookie_info.cookie_source = cookie_source;
541 cookie_info.allowed = allowed_objects.GetObjectCountForDomain(site_url_);
542 cookie_info.blocked = blocked_objects.GetObjectCountForDomain(site_url_);
543 cookie_info_list.push_back(cookie_info);
544
545 // Add third party cookie counts.
546 cookie_info.cookie_source = l10n_util::GetStringUTF8(
547 IDS_WEBSITE_SETTINGS_THIRD_PARTY_SITE_DATA);
548 cookie_info.allowed = allowed_objects.GetObjectCount() - cookie_info.allowed;
549 cookie_info.blocked = blocked_objects.GetObjectCount() - cookie_info.blocked;
[email protected]df818272012-04-20 13:10:50550 cookie_info_list.push_back(cookie_info);
[email protected]0b9fdd72012-04-04 10:00:33551
[email protected]df818272012-04-20 13:10:50552 ui_->SetCookieInfo(cookie_info_list);
[email protected]0b9fdd72012-04-04 10:00:33553}
[email protected]16de6de2012-04-04 12:24:14554
[email protected]24c8818c2012-04-25 09:57:41555void WebsiteSettings::PresentSiteIdentity() {
556 // After initialization the status about the site's connection
557 // and it's identity must be available.
558 DCHECK_NE(site_identity_status_, SITE_IDENTITY_STATUS_UNKNOWN);
559 DCHECK_NE(site_connection_status_, SITE_CONNECTION_STATUS_UNKNOWN);
560 WebsiteSettingsUI::IdentityInfo info;
561 if (site_identity_status_ == SITE_IDENTITY_STATUS_EV_CERT)
562 info.site_identity = UTF16ToUTF8(organization_name());
563 else
564 info.site_identity = site_url_.host();
565
566 info.connection_status = site_connection_status_;
567 info.connection_status_description =
568 UTF16ToUTF8(site_connection_details_);
569 info.identity_status = site_identity_status_;
570 info.identity_status_description =
571 UTF16ToUTF8(site_identity_details_);
[email protected]f61c1ce2012-05-09 13:55:11572 info.cert_id = cert_id_;
[email protected]24c8818c2012-04-25 09:57:41573 ui_->SetIdentityInfo(info);
574}
575
[email protected]15b092542012-05-16 13:08:14576void WebsiteSettings::PresentHistoryInfo(base::Time first_visit) {
577 if (first_visit == base::Time()) {
578 ui_->SetFirstVisit(string16());
579 return;
580 }
581
582 bool visited_before_today = false;
583 base::Time today = base::Time::Now().LocalMidnight();
584 base::Time first_visit_midnight = first_visit.LocalMidnight();
585 visited_before_today = (first_visit_midnight < today);
586
587 string16 first_visit_text;
588 if (visited_before_today) {
589 first_visit_text = l10n_util::GetStringFUTF16(
590 IDS_PAGE_INFO_SECURITY_TAB_VISITED_BEFORE_TODAY,
591 base::TimeFormatShortDate(first_visit));
592 } else {
593 first_visit_text = l10n_util::GetStringUTF16(
594 IDS_PAGE_INFO_SECURITY_TAB_FIRST_VISITED_TODAY);
595
596 }
597 ui_->SetFirstVisit(first_visit_text);
598}