blob: 4d26eeaf643e36e0660ba45bafc03f54c5431c45 [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]e22d64f2012-09-10 09:03:2312#include "base/metrics/histogram.h"
[email protected]15b092542012-05-16 13:08:1413#include "base/i18n/time_formatting.h"
[email protected]03ef4b2a2012-03-06 15:04:2014#include "base/string_number_conversions.h"
15#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]66f157312012-08-01 13:50:2627#include "chrome/browser/infobars/infobar_tab_helper.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"
40#include "net/base/cert_status_flags.h"
[email protected]be28b5f42012-07-20 11:31:2541#include "net/base/registry_controlled_domains/registry_controlled_domain.h"
[email protected]03ef4b2a2012-03-06 15:04:2042#include "net/base/ssl_cipher_suite_names.h"
43#include "net/base/ssl_connection_status_flags.h"
44#include "net/base/x509_certificate.h"
45#include "ui/base/l10n/l10n_util.h"
46#include "ui/base/resource/resource_bundle.h"
47
[email protected]0b9fdd72012-04-04 10:00:3348using content::BrowserThread;
49
50namespace {
51
[email protected]b1d113d2012-06-27 21:27:3452// The list of content settings types to display on the Website Settings UI.
[email protected]0b9fdd72012-04-04 10:00:3353ContentSettingsType kPermissionType[] = {
[email protected]b1d113d2012-06-27 21:27:3454 CONTENT_SETTINGS_TYPE_IMAGES,
55 CONTENT_SETTINGS_TYPE_JAVASCRIPT,
[email protected]0b9fdd72012-04-04 10:00:3356 CONTENT_SETTINGS_TYPE_PLUGINS,
[email protected]b1d113d2012-06-27 21:27:3457 CONTENT_SETTINGS_TYPE_POPUPS,
[email protected]0b9fdd72012-04-04 10:00:3358 CONTENT_SETTINGS_TYPE_GEOLOCATION,
[email protected]b1d113d2012-06-27 21:27:3459 CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
60 CONTENT_SETTINGS_TYPE_FULLSCREEN,
61 CONTENT_SETTINGS_TYPE_MOUSELOCK,
62 CONTENT_SETTINGS_TYPE_MEDIASTREAM,
[email protected]0b9fdd72012-04-04 10:00:3363};
64
65} // namespace
66
67WebsiteSettings::WebsiteSettings(
68 WebsiteSettingsUI* ui,
69 Profile* profile,
[email protected]df818272012-04-20 13:10:5070 TabSpecificContentSettings* tab_specific_content_settings,
[email protected]66f157312012-08-01 13:50:2671 InfoBarTabHelper* infobar_tab_helper,
[email protected]0b9fdd72012-04-04 10:00:3372 const GURL& url,
73 const content::SSLStatus& ssl,
74 content::CertStore* cert_store)
[email protected]df818272012-04-20 13:10:5075 : TabSpecificContentSettings::SiteDataObserver(
76 tab_specific_content_settings),
77 ui_(ui),
[email protected]66f157312012-08-01 13:50:2678 infobar_helper_(infobar_tab_helper),
79 show_info_bar_(false),
[email protected]0b9fdd72012-04-04 10:00:3380 site_url_(url),
81 site_identity_status_(SITE_IDENTITY_STATUS_UNKNOWN),
[email protected]f61c1ce2012-05-09 13:55:1182 cert_id_(0),
[email protected]03ef4b2a2012-03-06 15:04:2083 site_connection_status_(SITE_CONNECTION_STATUS_UNKNOWN),
[email protected]0b9fdd72012-04-04 10:00:3384 cert_store_(cert_store),
85 content_settings_(profile->GetHostContentSettingsMap()) {
[email protected]03ef4b2a2012-03-06 15:04:2086 Init(profile, url, ssl);
[email protected]0b9fdd72012-04-04 10:00:3387
[email protected]78a1fd90a2012-07-19 08:11:2588 HistoryService* history_service = HistoryServiceFactory::GetForProfile(
89 profile, Profile::EXPLICIT_ACCESS);
[email protected]15b092542012-05-16 13:08:1490 if (history_service) {
91 history_service->GetVisibleVisitCountToHost(
92 site_url_,
93 &visit_count_request_consumer_,
94 base::Bind(&WebsiteSettings::OnGotVisitCountToHost,
95 base::Unretained(this)));
96 }
97
[email protected]0b9fdd72012-04-04 10:00:3398 PresentSitePermissions();
[email protected]df818272012-04-20 13:10:5099 PresentSiteData();
[email protected]24c8818c2012-04-25 09:57:41100 PresentSiteIdentity();
[email protected]15b092542012-05-16 13:08:14101 PresentHistoryInfo(base::Time());
[email protected]e22d64f2012-09-10 09:03:23102
103 // Every time the Website Settings UI is opened a |WebsiteSettings| object is
104 // created. So this counts how ofter the Website Settings UI is opened.
105 content::RecordAction(content::UserMetricsAction("WebsiteSettings_Opened"));
[email protected]03ef4b2a2012-03-06 15:04:20106}
107
[email protected]0b9fdd72012-04-04 10:00:33108WebsiteSettings::~WebsiteSettings() {
[email protected]03ef4b2a2012-03-06 15:04:20109}
110
[email protected]df818272012-04-20 13:10:50111void WebsiteSettings::OnSitePermissionChanged(ContentSettingsType type,
112 ContentSetting setting) {
[email protected]e22d64f2012-09-10 09:03:23113 // Count how often a permission for a specific content type is changed using
114 // the Website Settings UI.
115 UMA_HISTOGRAM_COUNTS("WebsiteSettings.PermissionChanged", type);
116
[email protected]df818272012-04-20 13:10:50117 ContentSettingsPattern primary_pattern;
118 ContentSettingsPattern secondary_pattern;
119 switch (type) {
120 case CONTENT_SETTINGS_TYPE_GEOLOCATION:
121 // TODO(markusheintz): The rule we create here should also change the
122 // location permission for iframed content.
123 primary_pattern = ContentSettingsPattern::FromURLNoWildcard(site_url_);
124 secondary_pattern = ContentSettingsPattern::FromURLNoWildcard(site_url_);
125 break;
126 case CONTENT_SETTINGS_TYPE_NOTIFICATIONS:
127 primary_pattern = ContentSettingsPattern::FromURLNoWildcard(site_url_);
128 secondary_pattern = ContentSettingsPattern::Wildcard();
129 break;
[email protected]b1d113d2012-06-27 21:27:34130 case CONTENT_SETTINGS_TYPE_IMAGES:
131 case CONTENT_SETTINGS_TYPE_JAVASCRIPT:
[email protected]df818272012-04-20 13:10:50132 case CONTENT_SETTINGS_TYPE_PLUGINS:
133 case CONTENT_SETTINGS_TYPE_POPUPS:
[email protected]b1d113d2012-06-27 21:27:34134 case CONTENT_SETTINGS_TYPE_FULLSCREEN:
135 case CONTENT_SETTINGS_TYPE_MOUSELOCK:
136 case CONTENT_SETTINGS_TYPE_MEDIASTREAM:
[email protected]df818272012-04-20 13:10:50137 primary_pattern = ContentSettingsPattern::FromURL(site_url_);
138 secondary_pattern = ContentSettingsPattern::Wildcard();
139 break;
140 default:
141 NOTREACHED() << "ContentSettingsType " << type << "is not supported.";
142 break;
[email protected]0b9fdd72012-04-04 10:00:33143 }
144
[email protected]df818272012-04-20 13:10:50145 // Permission settings are specified via rules. There exists always at least
146 // one rule for the default setting. Get the rule that currently defines
147 // the permission for the given permission |type|. Then test whether the
148 // existing rule is more specific than the rule we are about to create. If
149 // the existing rule is more specific, than change the existing rule instead
150 // of creating a new rule that would be hidden behind the existing rule.
151 content_settings::SettingInfo info;
152 scoped_ptr<Value> v(content_settings_->GetWebsiteSetting(
153 site_url_, site_url_, type, "", &info));
154 DCHECK(info.source == content_settings::SETTING_SOURCE_USER);
155 ContentSettingsPattern::Relation r1 =
156 info.primary_pattern.Compare(primary_pattern);
157 DCHECK(r1 != ContentSettingsPattern::DISJOINT_ORDER_POST &&
158 r1 != ContentSettingsPattern::DISJOINT_ORDER_PRE);
159 if (r1 == ContentSettingsPattern::PREDECESSOR) {
160 primary_pattern = info.primary_pattern;
161 } else if (r1 == ContentSettingsPattern::IDENTITY) {
162 ContentSettingsPattern::Relation r2 =
163 info.secondary_pattern.Compare(secondary_pattern);
164 DCHECK(r2 != ContentSettingsPattern::DISJOINT_ORDER_POST &&
165 r2 != ContentSettingsPattern::DISJOINT_ORDER_PRE);
166 if (r2 == ContentSettingsPattern::PREDECESSOR)
167 secondary_pattern = info.secondary_pattern;
168 }
169
170 Value* value = NULL;
171 if (setting != CONTENT_SETTING_DEFAULT)
172 value = Value::CreateIntegerValue(setting);
173 content_settings_->SetWebsiteSetting(
174 primary_pattern, secondary_pattern, type, "", value);
[email protected]66f157312012-08-01 13:50:26175 show_info_bar_ = true;
[email protected]2f45d542012-08-22 08:47:24176
[email protected]e379ba42012-08-22 22:40:25177// TODO(markusheintz): This is a temporary hack to fix issue: http://crbug.com/144203.
178#if defined(OS_MACOSX)
[email protected]2f45d542012-08-22 08:47:24179 // Refresh the UI to reflect the new setting.
180 PresentSitePermissions();
[email protected]e379ba42012-08-22 22:40:25181#endif
[email protected]df818272012-04-20 13:10:50182}
183
[email protected]15b092542012-05-16 13:08:14184void WebsiteSettings::OnGotVisitCountToHost(HistoryService::Handle handle,
185 bool found_visits,
186 int visit_count,
187 base::Time first_visit) {
188 if (!found_visits) {
189 // This indicates an error, such as the page's URL scheme wasn't
190 // http/https.
191 first_visit = base::Time();
192 } else if (visit_count == 0) {
193 first_visit = base::Time::Now();
194 }
195 PresentHistoryInfo(first_visit);
196}
197
[email protected]df818272012-04-20 13:10:50198void WebsiteSettings::OnSiteDataAccessed() {
199 PresentSiteData();
[email protected]0b9fdd72012-04-04 10:00:33200}
201
[email protected]66f157312012-08-01 13:50:26202void WebsiteSettings::OnUIClosing() {
203 if (show_info_bar_) {
204 infobar_helper_->AddInfoBar(
205 new WebsiteSettingsInfobarDelegate(infobar_helper_));
206 }
207}
208
[email protected]0b9fdd72012-04-04 10:00:33209void WebsiteSettings::Init(Profile* profile,
210 const GURL& url,
211 const content::SSLStatus& ssl) {
[email protected]03ef4b2a2012-03-06 15:04:20212 if (url.SchemeIs(chrome::kChromeUIScheme)) {
213 site_identity_status_ = SITE_IDENTITY_STATUS_INTERNAL_PAGE;
214 site_identity_details_ =
215 l10n_util::GetStringUTF16(IDS_PAGE_INFO_INTERNAL_PAGE);
216 site_connection_status_ = SITE_CONNECTION_STATUS_INTERNAL_PAGE;
217 return;
218 }
219
220 scoped_refptr<net::X509Certificate> cert;
221
222 // Identity section.
223 string16 subject_name(UTF8ToUTF16(url.host()));
[email protected]03ef4b2a2012-03-06 15:04:20224 if (subject_name.empty()) {
225 subject_name.assign(
226 l10n_util::GetStringUTF16(IDS_PAGE_INFO_SECURITY_TAB_UNKNOWN_PARTY));
[email protected]03ef4b2a2012-03-06 15:04:20227 }
228
[email protected]f61c1ce2012-05-09 13:55:11229 cert_id_ = ssl.cert_id;
230
[email protected]03ef4b2a2012-03-06 15:04:20231 if (ssl.cert_id &&
232 cert_store_->RetrieveCert(ssl.cert_id, &cert) &&
233 (!net::IsCertStatusError(ssl.cert_status) ||
234 net::IsCertStatusMinorError(ssl.cert_status))) {
235 // There are no major errors. Check for minor errors.
236 if (net::IsCertStatusMinorError(ssl.cert_status)) {
237 site_identity_status_ = SITE_IDENTITY_STATUS_CERT_REVOCATION_UNKNOWN;
238 string16 issuer_name(UTF8ToUTF16(cert->issuer().GetDisplayName()));
239 if (issuer_name.empty()) {
240 issuer_name.assign(l10n_util::GetStringUTF16(
241 IDS_PAGE_INFO_SECURITY_TAB_UNKNOWN_PARTY));
242 }
243 site_identity_details_.assign(l10n_util::GetStringFUTF16(
244 IDS_PAGE_INFO_SECURITY_TAB_SECURE_IDENTITY, issuer_name));
245
246 site_identity_details_ += ASCIIToUTF16("\n\n");
247 if (ssl.cert_status & net::CERT_STATUS_UNABLE_TO_CHECK_REVOCATION) {
248 site_identity_details_ += l10n_util::GetStringUTF16(
249 IDS_PAGE_INFO_SECURITY_TAB_UNABLE_TO_CHECK_REVOCATION);
250 } else if (ssl.cert_status & net::CERT_STATUS_NO_REVOCATION_MECHANISM) {
251 site_identity_details_ += l10n_util::GetStringUTF16(
252 IDS_PAGE_INFO_SECURITY_TAB_NO_REVOCATION_MECHANISM);
253 } else {
254 NOTREACHED() << "Need to specify string for this warning";
255 }
256 } else if (ssl.cert_status & net::CERT_STATUS_IS_EV) {
257 // EV HTTPS page.
258 site_identity_status_ = SITE_IDENTITY_STATUS_EV_CERT;
259 DCHECK(!cert->subject().organization_names.empty());
260 organization_name_ = UTF8ToUTF16(cert->subject().organization_names[0]);
261 // An EV Cert is required to have a city (localityName) and country but
262 // state is "if any".
263 DCHECK(!cert->subject().locality_name.empty());
264 DCHECK(!cert->subject().country_name.empty());
265 string16 locality;
266 if (!cert->subject().state_or_province_name.empty()) {
267 locality = l10n_util::GetStringFUTF16(
268 IDS_PAGEINFO_ADDRESS,
269 UTF8ToUTF16(cert->subject().locality_name),
270 UTF8ToUTF16(cert->subject().state_or_province_name),
271 UTF8ToUTF16(cert->subject().country_name));
272 } else {
273 locality = l10n_util::GetStringFUTF16(
274 IDS_PAGEINFO_PARTIAL_ADDRESS,
275 UTF8ToUTF16(cert->subject().locality_name),
276 UTF8ToUTF16(cert->subject().country_name));
277 }
278 DCHECK(!cert->subject().organization_names.empty());
279 site_identity_details_.assign(l10n_util::GetStringFUTF16(
280 IDS_PAGE_INFO_SECURITY_TAB_SECURE_IDENTITY_EV,
281 UTF8ToUTF16(cert->subject().organization_names[0]),
282 locality,
283 UTF8ToUTF16(cert->issuer().GetDisplayName())));
284 } else if (ssl.cert_status & net::CERT_STATUS_IS_DNSSEC) {
285 // DNSSEC authenticated page.
286 site_identity_status_ = SITE_IDENTITY_STATUS_DNSSEC_CERT;
287 site_identity_details_.assign(l10n_util::GetStringFUTF16(
288 IDS_PAGE_INFO_SECURITY_TAB_SECURE_IDENTITY, UTF8ToUTF16("DNSSEC")));
289 } else {
290 // Non-EV OK HTTPS page.
291 site_identity_status_ = SITE_IDENTITY_STATUS_CERT;
292 string16 issuer_name(UTF8ToUTF16(cert->issuer().GetDisplayName()));
293 if (issuer_name.empty()) {
294 issuer_name.assign(l10n_util::GetStringUTF16(
295 IDS_PAGE_INFO_SECURITY_TAB_UNKNOWN_PARTY));
296 }
297 site_identity_details_.assign(l10n_util::GetStringFUTF16(
298 IDS_PAGE_INFO_SECURITY_TAB_SECURE_IDENTITY, issuer_name));
299 }
300 } else {
301 // HTTP or HTTPS with errors (not warnings).
302 site_identity_details_.assign(l10n_util::GetStringUTF16(
303 IDS_PAGE_INFO_SECURITY_TAB_INSECURE_IDENTITY));
304 if (ssl.security_style == content::SECURITY_STYLE_UNAUTHENTICATED)
305 site_identity_status_ = SITE_IDENTITY_STATUS_NO_CERT;
306 else
307 site_identity_status_ = SITE_IDENTITY_STATUS_ERROR;
308
309 const string16 bullet = UTF8ToUTF16("\n • ");
310 std::vector<SSLErrorInfo> errors;
311 SSLErrorInfo::GetErrorsForCertStatus(ssl.cert_id, ssl.cert_status,
312 url, &errors);
313 for (size_t i = 0; i < errors.size(); ++i) {
314 site_identity_details_ += bullet;
315 site_identity_details_ += errors[i].short_description();
316 }
317
318 if (ssl.cert_status & net::CERT_STATUS_NON_UNIQUE_NAME) {
319 site_identity_details_ += ASCIIToUTF16("\n\n");
320 site_identity_details_ += l10n_util::GetStringUTF16(
321 IDS_PAGE_INFO_SECURITY_TAB_NON_UNIQUE_NAME);
322 }
323 }
324
325 // Site Connection
326 // We consider anything less than 80 bits encryption to be weak encryption.
327 // TODO(wtc): Bug 1198735: report mixed/unsafe content for unencrypted and
328 // weakly encrypted connections.
329 site_connection_status_ = SITE_CONNECTION_STATUS_UNKNOWN;
330
331 if (!ssl.cert_id) {
332 // Not HTTPS.
333 DCHECK_EQ(ssl.security_style, content::SECURITY_STYLE_UNAUTHENTICATED);
334 if (ssl.security_style == content::SECURITY_STYLE_UNAUTHENTICATED)
335 site_connection_status_ = SITE_CONNECTION_STATUS_UNENCRYPTED;
336 else
337 site_connection_status_ = SITE_CONNECTION_STATUS_ENCRYPTED_ERROR;
338
339 site_connection_details_.assign(l10n_util::GetStringFUTF16(
340 IDS_PAGE_INFO_SECURITY_TAB_NOT_ENCRYPTED_CONNECTION_TEXT,
341 subject_name));
342 } else if (ssl.security_bits < 0) {
343 // Security strength is unknown. Say nothing.
344 site_connection_status_ = SITE_CONNECTION_STATUS_ENCRYPTED_ERROR;
345 } else if (ssl.security_bits == 0) {
346 DCHECK_NE(ssl.security_style, content::SECURITY_STYLE_UNAUTHENTICATED);
347 site_connection_status_ = SITE_CONNECTION_STATUS_ENCRYPTED_ERROR;
348 site_connection_details_.assign(l10n_util::GetStringFUTF16(
349 IDS_PAGE_INFO_SECURITY_TAB_NOT_ENCRYPTED_CONNECTION_TEXT,
350 subject_name));
351 } else if (ssl.security_bits < 80) {
352 site_connection_status_ = SITE_CONNECTION_STATUS_ENCRYPTED_ERROR;
353 site_connection_details_.assign(l10n_util::GetStringFUTF16(
354 IDS_PAGE_INFO_SECURITY_TAB_WEAK_ENCRYPTION_CONNECTION_TEXT,
355 subject_name));
356 } else {
357 site_connection_status_ = SITE_CONNECTION_STATUS_ENCRYPTED;
358 site_connection_details_.assign(l10n_util::GetStringFUTF16(
359 IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTED_CONNECTION_TEXT,
360 subject_name,
361 base::IntToString16(ssl.security_bits)));
362 if (ssl.content_status) {
363 bool ran_insecure_content =
364 !!(ssl.content_status & content::SSLStatus::RAN_INSECURE_CONTENT);
365 site_connection_status_ = ran_insecure_content ?
366 SITE_CONNECTION_STATUS_ENCRYPTED_ERROR
367 : SITE_CONNECTION_STATUS_MIXED_CONTENT;
368 site_connection_details_.assign(l10n_util::GetStringFUTF16(
369 IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTED_SENTENCE_LINK,
370 site_connection_details_,
371 l10n_util::GetStringUTF16(ran_insecure_content ?
372 IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTED_INSECURE_CONTENT_ERROR :
373 IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTED_INSECURE_CONTENT_WARNING)));
374 }
375 }
376
377 uint16 cipher_suite =
378 net::SSLConnectionStatusToCipherSuite(ssl.connection_status);
379 if (ssl.security_bits > 0 && cipher_suite) {
380 int ssl_version =
381 net::SSLConnectionStatusToVersion(ssl.connection_status);
382 const char* ssl_version_str;
383 net::SSLVersionToString(&ssl_version_str, ssl_version);
384 site_connection_details_ += ASCIIToUTF16("\n\n");
385 site_connection_details_ += l10n_util::GetStringFUTF16(
386 IDS_PAGE_INFO_SECURITY_TAB_SSL_VERSION,
387 ASCIIToUTF16(ssl_version_str));
388
389 bool did_fallback = (ssl.connection_status &
[email protected]80c75f682012-05-26 16:22:17390 net::SSL_CONNECTION_VERSION_FALLBACK) != 0;
[email protected]03ef4b2a2012-03-06 15:04:20391 bool no_renegotiation =
392 (ssl.connection_status &
393 net::SSL_CONNECTION_NO_RENEGOTIATION_EXTENSION) != 0;
394 const char *key_exchange, *cipher, *mac;
395 net::SSLCipherSuiteToStrings(&key_exchange, &cipher, &mac, cipher_suite);
396
397 site_connection_details_ += ASCIIToUTF16("\n\n");
398 site_connection_details_ += l10n_util::GetStringFUTF16(
399 IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTION_DETAILS,
400 ASCIIToUTF16(cipher), ASCIIToUTF16(mac), ASCIIToUTF16(key_exchange));
401
402 site_connection_details_ += ASCIIToUTF16("\n\n");
403 uint8 compression_id =
404 net::SSLConnectionStatusToCompression(ssl.connection_status);
405 if (compression_id) {
406 const char* compression;
407 net::SSLCompressionToString(&compression, compression_id);
408 site_connection_details_ += l10n_util::GetStringFUTF16(
409 IDS_PAGE_INFO_SECURITY_TAB_COMPRESSION_DETAILS,
410 ASCIIToUTF16(compression));
411 } else {
412 site_connection_details_ += l10n_util::GetStringUTF16(
413 IDS_PAGE_INFO_SECURITY_TAB_NO_COMPRESSION);
414 }
415
416 if (did_fallback) {
417 // For now, only SSLv3 fallback will trigger a warning icon.
418 if (site_connection_status_ < SITE_CONNECTION_STATUS_MIXED_CONTENT)
419 site_connection_status_ = SITE_CONNECTION_STATUS_MIXED_CONTENT;
420 site_connection_details_ += ASCIIToUTF16("\n\n");
421 site_connection_details_ += l10n_util::GetStringUTF16(
422 IDS_PAGE_INFO_SECURITY_TAB_FALLBACK_MESSAGE);
423 }
424 if (no_renegotiation) {
425 site_connection_details_ += ASCIIToUTF16("\n\n");
426 site_connection_details_ += l10n_util::GetStringUTF16(
427 IDS_PAGE_INFO_SECURITY_TAB_RENEGOTIATION_MESSAGE);
428 }
429 }
[email protected]e583f752012-08-30 13:26:21430
431 // By default select the permissions tab that displays all the site
432 // permissions. In case of a connection error or an issue with the
433 // certificate presented by the website, select the connection tab to draw
434 // the user's attention to the issue. If the site does not provide a
435 // certificate because it was loaded over an unencrypted connection, don't
436 // select the connection tab.
437 WebsiteSettingsUI::TabId tab_id = WebsiteSettingsUI::TAB_ID_PERMISSIONS;
438 if (site_connection_status_ == SITE_CONNECTION_STATUS_ENCRYPTED_ERROR ||
439 site_connection_status_ == SITE_CONNECTION_STATUS_MIXED_CONTENT ||
440 site_identity_status_ == SITE_IDENTITY_STATUS_ERROR ||
441 site_identity_status_ == SITE_IDENTITY_STATUS_CERT_REVOCATION_UNKNOWN)
442 tab_id = WebsiteSettingsUI::TAB_ID_CONNECTION;
443 ui_->SetSelectedTab(tab_id);
[email protected]03ef4b2a2012-03-06 15:04:20444}
[email protected]0b9fdd72012-04-04 10:00:33445
[email protected]df818272012-04-20 13:10:50446void WebsiteSettings::PresentSitePermissions() {
447 PermissionInfoList permission_info_list;
448
449 WebsiteSettingsUI::PermissionInfo permission_info;
450 for (size_t i = 0; i < arraysize(kPermissionType); ++i) {
451 permission_info.type = kPermissionType[i];
452
453 content_settings::SettingInfo info;
454 scoped_ptr<Value> value(content_settings_->GetWebsiteSetting(
455 site_url_, site_url_, permission_info.type, "", &info));
456 DCHECK(value.get());
457 permission_info.setting =
458 content_settings::ValueToContentSetting(value.get());
[email protected]8bdf45c32012-08-04 00:12:55459 permission_info.source = info.source;
[email protected]df818272012-04-20 13:10:50460
[email protected]b1d113d2012-06-27 21:27:34461 if (info.primary_pattern == ContentSettingsPattern::Wildcard() &&
462 info.secondary_pattern == ContentSettingsPattern::Wildcard()) {
463 permission_info.default_setting = permission_info.setting;
464 permission_info.setting = CONTENT_SETTING_DEFAULT;
465 } else {
466 permission_info.default_setting =
467 content_settings_->GetDefaultContentSetting(permission_info.type,
468 NULL);
[email protected]df818272012-04-20 13:10:50469 }
[email protected]b1d113d2012-06-27 21:27:34470 permission_info_list.push_back(permission_info);
[email protected]df818272012-04-20 13:10:50471 }
472
473 ui_->SetPermissionInfo(permission_info_list);
[email protected]0b9fdd72012-04-04 10:00:33474}
475
[email protected]df818272012-04-20 13:10:50476void WebsiteSettings::PresentSiteData() {
477 CookieInfoList cookie_info_list;
[email protected]e0ac35892012-05-15 12:53:34478 const LocalSharedObjectsContainer& allowed_objects =
479 tab_specific_content_settings()->allowed_local_shared_objects();
480 const LocalSharedObjectsContainer& blocked_objects =
481 tab_specific_content_settings()->blocked_local_shared_objects();
482
483 // Add first party cookie and site data counts.
[email protected]df818272012-04-20 13:10:50484 WebsiteSettingsUI::CookieInfo cookie_info;
[email protected]e0ac35892012-05-15 12:53:34485 std::string cookie_source =
486 net::RegistryControlledDomainService::GetDomainAndRegistry(site_url_);
487 if (cookie_source.empty())
488 cookie_source = site_url_.host();
489 cookie_info.cookie_source = cookie_source;
490 cookie_info.allowed = allowed_objects.GetObjectCountForDomain(site_url_);
491 cookie_info.blocked = blocked_objects.GetObjectCountForDomain(site_url_);
492 cookie_info_list.push_back(cookie_info);
493
494 // Add third party cookie counts.
495 cookie_info.cookie_source = l10n_util::GetStringUTF8(
496 IDS_WEBSITE_SETTINGS_THIRD_PARTY_SITE_DATA);
497 cookie_info.allowed = allowed_objects.GetObjectCount() - cookie_info.allowed;
498 cookie_info.blocked = blocked_objects.GetObjectCount() - cookie_info.blocked;
[email protected]df818272012-04-20 13:10:50499 cookie_info_list.push_back(cookie_info);
[email protected]0b9fdd72012-04-04 10:00:33500
[email protected]df818272012-04-20 13:10:50501 ui_->SetCookieInfo(cookie_info_list);
[email protected]0b9fdd72012-04-04 10:00:33502}
[email protected]16de6de2012-04-04 12:24:14503
[email protected]24c8818c2012-04-25 09:57:41504void WebsiteSettings::PresentSiteIdentity() {
505 // After initialization the status about the site's connection
506 // and it's identity must be available.
507 DCHECK_NE(site_identity_status_, SITE_IDENTITY_STATUS_UNKNOWN);
508 DCHECK_NE(site_connection_status_, SITE_CONNECTION_STATUS_UNKNOWN);
509 WebsiteSettingsUI::IdentityInfo info;
510 if (site_identity_status_ == SITE_IDENTITY_STATUS_EV_CERT)
511 info.site_identity = UTF16ToUTF8(organization_name());
512 else
513 info.site_identity = site_url_.host();
514
515 info.connection_status = site_connection_status_;
516 info.connection_status_description =
517 UTF16ToUTF8(site_connection_details_);
518 info.identity_status = site_identity_status_;
519 info.identity_status_description =
520 UTF16ToUTF8(site_identity_details_);
[email protected]f61c1ce2012-05-09 13:55:11521 info.cert_id = cert_id_;
[email protected]24c8818c2012-04-25 09:57:41522 ui_->SetIdentityInfo(info);
523}
524
[email protected]15b092542012-05-16 13:08:14525void WebsiteSettings::PresentHistoryInfo(base::Time first_visit) {
526 if (first_visit == base::Time()) {
527 ui_->SetFirstVisit(string16());
528 return;
529 }
530
531 bool visited_before_today = false;
532 base::Time today = base::Time::Now().LocalMidnight();
533 base::Time first_visit_midnight = first_visit.LocalMidnight();
534 visited_before_today = (first_visit_midnight < today);
535
536 string16 first_visit_text;
537 if (visited_before_today) {
538 first_visit_text = l10n_util::GetStringFUTF16(
539 IDS_PAGE_INFO_SECURITY_TAB_VISITED_BEFORE_TODAY,
540 base::TimeFormatShortDate(first_visit));
541 } else {
542 first_visit_text = l10n_util::GetStringUTF16(
543 IDS_PAGE_INFO_SECURITY_TAB_FIRST_VISITED_TODAY);
544
545 }
546 ui_->SetFirstVisit(first_visit_text);
547}