blob: d21a54cf43afba612a45ded6eb3a7c4358956dff [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]03ef4b2a2012-03-06 15:04:2013#include "base/string_number_conversions.h"
14#include "base/utf_string_conversions.h"
[email protected]0b9fdd72012-04-04 10:00:3315#include "base/values.h"
[email protected]b0cb5e82012-07-19 19:22:4716#include "chrome/browser/browsing_data/browsing_data_cookie_helper.h"
17#include "chrome/browser/browsing_data/browsing_data_database_helper.h"
18#include "chrome/browser/browsing_data/browsing_data_file_system_helper.h"
19#include "chrome/browser/browsing_data/browsing_data_indexed_db_helper.h"
20#include "chrome/browser/browsing_data/browsing_data_local_storage_helper.h"
21#include "chrome/browser/browsing_data/browsing_data_server_bound_cert_helper.h"
[email protected]0b9fdd72012-04-04 10:00:3322#include "chrome/browser/content_settings/content_settings_utils.h"
23#include "chrome/browser/content_settings/host_content_settings_map.h"
[email protected]df818272012-04-20 13:10:5024#include "chrome/browser/content_settings/local_shared_objects_container.h"
[email protected]77a91c72012-08-13 16:19:3425#include "chrome/browser/history/history_service_factory.h"
[email protected]66f157312012-08-01 13:50:2626#include "chrome/browser/infobars/infobar_tab_helper.h"
[email protected]03ef4b2a2012-03-06 15:04:2027#include "chrome/browser/profiles/profile.h"
[email protected]03ef4b2a2012-03-06 15:04:2028#include "chrome/browser/ssl/ssl_error_info.h"
[email protected]66f157312012-08-01 13:50:2629#include "chrome/browser/ui/website_settings/website_settings_infobar_delegate.h"
[email protected]4237dd52012-06-05 00:00:3230#include "chrome/browser/ui/website_settings/website_settings_ui.h"
[email protected]0b9fdd72012-04-04 10:00:3331#include "chrome/common/content_settings_pattern.h"
32#include "content/public/browser/browser_thread.h"
[email protected]b59c6cf02012-03-12 20:51:4233#include "content/public/browser/cert_store.h"
[email protected]03ef4b2a2012-03-06 15:04:2034#include "content/public/common/ssl_status.h"
35#include "content/public/common/url_constants.h"
36#include "grit/chromium_strings.h"
37#include "grit/generated_resources.h"
38#include "net/base/cert_status_flags.h"
[email protected]be28b5f42012-07-20 11:31:2539#include "net/base/registry_controlled_domains/registry_controlled_domain.h"
[email protected]03ef4b2a2012-03-06 15:04:2040#include "net/base/ssl_cipher_suite_names.h"
41#include "net/base/ssl_connection_status_flags.h"
42#include "net/base/x509_certificate.h"
43#include "ui/base/l10n/l10n_util.h"
44#include "ui/base/resource/resource_bundle.h"
45
[email protected]0b9fdd72012-04-04 10:00:3346using content::BrowserThread;
47
48namespace {
49
[email protected]b1d113d2012-06-27 21:27:3450// The list of content settings types to display on the Website Settings UI.
[email protected]0b9fdd72012-04-04 10:00:3351ContentSettingsType kPermissionType[] = {
[email protected]b1d113d2012-06-27 21:27:3452 CONTENT_SETTINGS_TYPE_IMAGES,
53 CONTENT_SETTINGS_TYPE_JAVASCRIPT,
[email protected]0b9fdd72012-04-04 10:00:3354 CONTENT_SETTINGS_TYPE_PLUGINS,
[email protected]b1d113d2012-06-27 21:27:3455 CONTENT_SETTINGS_TYPE_POPUPS,
[email protected]0b9fdd72012-04-04 10:00:3356 CONTENT_SETTINGS_TYPE_GEOLOCATION,
[email protected]b1d113d2012-06-27 21:27:3457 CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
58 CONTENT_SETTINGS_TYPE_FULLSCREEN,
59 CONTENT_SETTINGS_TYPE_MOUSELOCK,
60 CONTENT_SETTINGS_TYPE_MEDIASTREAM,
[email protected]0b9fdd72012-04-04 10:00:3361};
62
63} // namespace
64
65WebsiteSettings::WebsiteSettings(
66 WebsiteSettingsUI* ui,
67 Profile* profile,
[email protected]df818272012-04-20 13:10:5068 TabSpecificContentSettings* tab_specific_content_settings,
[email protected]66f157312012-08-01 13:50:2669 InfoBarTabHelper* infobar_tab_helper,
[email protected]0b9fdd72012-04-04 10:00:3370 const GURL& url,
71 const content::SSLStatus& ssl,
72 content::CertStore* cert_store)
[email protected]df818272012-04-20 13:10:5073 : TabSpecificContentSettings::SiteDataObserver(
74 tab_specific_content_settings),
75 ui_(ui),
[email protected]66f157312012-08-01 13:50:2676 infobar_helper_(infobar_tab_helper),
77 show_info_bar_(false),
[email protected]0b9fdd72012-04-04 10:00:3378 site_url_(url),
79 site_identity_status_(SITE_IDENTITY_STATUS_UNKNOWN),
[email protected]f61c1ce2012-05-09 13:55:1180 cert_id_(0),
[email protected]03ef4b2a2012-03-06 15:04:2081 site_connection_status_(SITE_CONNECTION_STATUS_UNKNOWN),
[email protected]0b9fdd72012-04-04 10:00:3382 cert_store_(cert_store),
83 content_settings_(profile->GetHostContentSettingsMap()) {
[email protected]03ef4b2a2012-03-06 15:04:2084 Init(profile, url, ssl);
[email protected]0b9fdd72012-04-04 10:00:3385
[email protected]78a1fd90a2012-07-19 08:11:2586 HistoryService* history_service = HistoryServiceFactory::GetForProfile(
87 profile, Profile::EXPLICIT_ACCESS);
[email protected]15b092542012-05-16 13:08:1488 if (history_service) {
89 history_service->GetVisibleVisitCountToHost(
90 site_url_,
91 &visit_count_request_consumer_,
92 base::Bind(&WebsiteSettings::OnGotVisitCountToHost,
93 base::Unretained(this)));
94 }
95
[email protected]0b9fdd72012-04-04 10:00:3396 PresentSitePermissions();
[email protected]df818272012-04-20 13:10:5097 PresentSiteData();
[email protected]24c8818c2012-04-25 09:57:4198 PresentSiteIdentity();
[email protected]15b092542012-05-16 13:08:1499 PresentHistoryInfo(base::Time());
[email protected]03ef4b2a2012-03-06 15:04:20100}
101
[email protected]0b9fdd72012-04-04 10:00:33102WebsiteSettings::~WebsiteSettings() {
[email protected]03ef4b2a2012-03-06 15:04:20103}
104
[email protected]df818272012-04-20 13:10:50105void WebsiteSettings::OnSitePermissionChanged(ContentSettingsType type,
106 ContentSetting setting) {
107 ContentSettingsPattern primary_pattern;
108 ContentSettingsPattern secondary_pattern;
109 switch (type) {
110 case CONTENT_SETTINGS_TYPE_GEOLOCATION:
111 // TODO(markusheintz): The rule we create here should also change the
112 // location permission for iframed content.
113 primary_pattern = ContentSettingsPattern::FromURLNoWildcard(site_url_);
114 secondary_pattern = ContentSettingsPattern::FromURLNoWildcard(site_url_);
115 break;
116 case CONTENT_SETTINGS_TYPE_NOTIFICATIONS:
117 primary_pattern = ContentSettingsPattern::FromURLNoWildcard(site_url_);
118 secondary_pattern = ContentSettingsPattern::Wildcard();
119 break;
[email protected]b1d113d2012-06-27 21:27:34120 case CONTENT_SETTINGS_TYPE_IMAGES:
121 case CONTENT_SETTINGS_TYPE_JAVASCRIPT:
[email protected]df818272012-04-20 13:10:50122 case CONTENT_SETTINGS_TYPE_PLUGINS:
123 case CONTENT_SETTINGS_TYPE_POPUPS:
[email protected]b1d113d2012-06-27 21:27:34124 case CONTENT_SETTINGS_TYPE_FULLSCREEN:
125 case CONTENT_SETTINGS_TYPE_MOUSELOCK:
126 case CONTENT_SETTINGS_TYPE_MEDIASTREAM:
[email protected]df818272012-04-20 13:10:50127 primary_pattern = ContentSettingsPattern::FromURL(site_url_);
128 secondary_pattern = ContentSettingsPattern::Wildcard();
129 break;
130 default:
131 NOTREACHED() << "ContentSettingsType " << type << "is not supported.";
132 break;
[email protected]0b9fdd72012-04-04 10:00:33133 }
134
[email protected]df818272012-04-20 13:10:50135 // Permission settings are specified via rules. There exists always at least
136 // one rule for the default setting. Get the rule that currently defines
137 // the permission for the given permission |type|. Then test whether the
138 // existing rule is more specific than the rule we are about to create. If
139 // the existing rule is more specific, than change the existing rule instead
140 // of creating a new rule that would be hidden behind the existing rule.
141 content_settings::SettingInfo info;
142 scoped_ptr<Value> v(content_settings_->GetWebsiteSetting(
143 site_url_, site_url_, type, "", &info));
144 DCHECK(info.source == content_settings::SETTING_SOURCE_USER);
145 ContentSettingsPattern::Relation r1 =
146 info.primary_pattern.Compare(primary_pattern);
147 DCHECK(r1 != ContentSettingsPattern::DISJOINT_ORDER_POST &&
148 r1 != ContentSettingsPattern::DISJOINT_ORDER_PRE);
149 if (r1 == ContentSettingsPattern::PREDECESSOR) {
150 primary_pattern = info.primary_pattern;
151 } else if (r1 == ContentSettingsPattern::IDENTITY) {
152 ContentSettingsPattern::Relation r2 =
153 info.secondary_pattern.Compare(secondary_pattern);
154 DCHECK(r2 != ContentSettingsPattern::DISJOINT_ORDER_POST &&
155 r2 != ContentSettingsPattern::DISJOINT_ORDER_PRE);
156 if (r2 == ContentSettingsPattern::PREDECESSOR)
157 secondary_pattern = info.secondary_pattern;
158 }
159
160 Value* value = NULL;
161 if (setting != CONTENT_SETTING_DEFAULT)
162 value = Value::CreateIntegerValue(setting);
163 content_settings_->SetWebsiteSetting(
164 primary_pattern, secondary_pattern, type, "", value);
[email protected]66f157312012-08-01 13:50:26165 show_info_bar_ = true;
[email protected]2f45d542012-08-22 08:47:24166
[email protected]e379ba42012-08-22 22:40:25167// TODO(markusheintz): This is a temporary hack to fix issue: http://crbug.com/144203.
168#if defined(OS_MACOSX)
[email protected]2f45d542012-08-22 08:47:24169 // Refresh the UI to reflect the new setting.
170 PresentSitePermissions();
[email protected]e379ba42012-08-22 22:40:25171#endif
[email protected]df818272012-04-20 13:10:50172}
173
[email protected]15b092542012-05-16 13:08:14174void WebsiteSettings::OnGotVisitCountToHost(HistoryService::Handle handle,
175 bool found_visits,
176 int visit_count,
177 base::Time first_visit) {
178 if (!found_visits) {
179 // This indicates an error, such as the page's URL scheme wasn't
180 // http/https.
181 first_visit = base::Time();
182 } else if (visit_count == 0) {
183 first_visit = base::Time::Now();
184 }
185 PresentHistoryInfo(first_visit);
186}
187
[email protected]df818272012-04-20 13:10:50188void WebsiteSettings::OnSiteDataAccessed() {
189 PresentSiteData();
[email protected]0b9fdd72012-04-04 10:00:33190}
191
[email protected]66f157312012-08-01 13:50:26192void WebsiteSettings::OnUIClosing() {
193 if (show_info_bar_) {
194 infobar_helper_->AddInfoBar(
195 new WebsiteSettingsInfobarDelegate(infobar_helper_));
196 }
197}
198
[email protected]0b9fdd72012-04-04 10:00:33199void WebsiteSettings::Init(Profile* profile,
200 const GURL& url,
201 const content::SSLStatus& ssl) {
[email protected]03ef4b2a2012-03-06 15:04:20202 if (url.SchemeIs(chrome::kChromeUIScheme)) {
203 site_identity_status_ = SITE_IDENTITY_STATUS_INTERNAL_PAGE;
204 site_identity_details_ =
205 l10n_util::GetStringUTF16(IDS_PAGE_INFO_INTERNAL_PAGE);
206 site_connection_status_ = SITE_CONNECTION_STATUS_INTERNAL_PAGE;
207 return;
208 }
209
210 scoped_refptr<net::X509Certificate> cert;
211
212 // Identity section.
213 string16 subject_name(UTF8ToUTF16(url.host()));
[email protected]03ef4b2a2012-03-06 15:04:20214 if (subject_name.empty()) {
215 subject_name.assign(
216 l10n_util::GetStringUTF16(IDS_PAGE_INFO_SECURITY_TAB_UNKNOWN_PARTY));
[email protected]03ef4b2a2012-03-06 15:04:20217 }
218
[email protected]f61c1ce2012-05-09 13:55:11219 cert_id_ = ssl.cert_id;
220
[email protected]03ef4b2a2012-03-06 15:04:20221 if (ssl.cert_id &&
222 cert_store_->RetrieveCert(ssl.cert_id, &cert) &&
223 (!net::IsCertStatusError(ssl.cert_status) ||
224 net::IsCertStatusMinorError(ssl.cert_status))) {
225 // There are no major errors. Check for minor errors.
226 if (net::IsCertStatusMinorError(ssl.cert_status)) {
227 site_identity_status_ = SITE_IDENTITY_STATUS_CERT_REVOCATION_UNKNOWN;
228 string16 issuer_name(UTF8ToUTF16(cert->issuer().GetDisplayName()));
229 if (issuer_name.empty()) {
230 issuer_name.assign(l10n_util::GetStringUTF16(
231 IDS_PAGE_INFO_SECURITY_TAB_UNKNOWN_PARTY));
232 }
233 site_identity_details_.assign(l10n_util::GetStringFUTF16(
234 IDS_PAGE_INFO_SECURITY_TAB_SECURE_IDENTITY, issuer_name));
235
236 site_identity_details_ += ASCIIToUTF16("\n\n");
237 if (ssl.cert_status & net::CERT_STATUS_UNABLE_TO_CHECK_REVOCATION) {
238 site_identity_details_ += l10n_util::GetStringUTF16(
239 IDS_PAGE_INFO_SECURITY_TAB_UNABLE_TO_CHECK_REVOCATION);
240 } else if (ssl.cert_status & net::CERT_STATUS_NO_REVOCATION_MECHANISM) {
241 site_identity_details_ += l10n_util::GetStringUTF16(
242 IDS_PAGE_INFO_SECURITY_TAB_NO_REVOCATION_MECHANISM);
243 } else {
244 NOTREACHED() << "Need to specify string for this warning";
245 }
246 } else if (ssl.cert_status & net::CERT_STATUS_IS_EV) {
247 // EV HTTPS page.
248 site_identity_status_ = SITE_IDENTITY_STATUS_EV_CERT;
249 DCHECK(!cert->subject().organization_names.empty());
250 organization_name_ = UTF8ToUTF16(cert->subject().organization_names[0]);
251 // An EV Cert is required to have a city (localityName) and country but
252 // state is "if any".
253 DCHECK(!cert->subject().locality_name.empty());
254 DCHECK(!cert->subject().country_name.empty());
255 string16 locality;
256 if (!cert->subject().state_or_province_name.empty()) {
257 locality = l10n_util::GetStringFUTF16(
258 IDS_PAGEINFO_ADDRESS,
259 UTF8ToUTF16(cert->subject().locality_name),
260 UTF8ToUTF16(cert->subject().state_or_province_name),
261 UTF8ToUTF16(cert->subject().country_name));
262 } else {
263 locality = l10n_util::GetStringFUTF16(
264 IDS_PAGEINFO_PARTIAL_ADDRESS,
265 UTF8ToUTF16(cert->subject().locality_name),
266 UTF8ToUTF16(cert->subject().country_name));
267 }
268 DCHECK(!cert->subject().organization_names.empty());
269 site_identity_details_.assign(l10n_util::GetStringFUTF16(
270 IDS_PAGE_INFO_SECURITY_TAB_SECURE_IDENTITY_EV,
271 UTF8ToUTF16(cert->subject().organization_names[0]),
272 locality,
273 UTF8ToUTF16(cert->issuer().GetDisplayName())));
274 } else if (ssl.cert_status & net::CERT_STATUS_IS_DNSSEC) {
275 // DNSSEC authenticated page.
276 site_identity_status_ = SITE_IDENTITY_STATUS_DNSSEC_CERT;
277 site_identity_details_.assign(l10n_util::GetStringFUTF16(
278 IDS_PAGE_INFO_SECURITY_TAB_SECURE_IDENTITY, UTF8ToUTF16("DNSSEC")));
279 } else {
280 // Non-EV OK HTTPS page.
281 site_identity_status_ = SITE_IDENTITY_STATUS_CERT;
282 string16 issuer_name(UTF8ToUTF16(cert->issuer().GetDisplayName()));
283 if (issuer_name.empty()) {
284 issuer_name.assign(l10n_util::GetStringUTF16(
285 IDS_PAGE_INFO_SECURITY_TAB_UNKNOWN_PARTY));
286 }
287 site_identity_details_.assign(l10n_util::GetStringFUTF16(
288 IDS_PAGE_INFO_SECURITY_TAB_SECURE_IDENTITY, issuer_name));
289 }
290 } else {
291 // HTTP or HTTPS with errors (not warnings).
292 site_identity_details_.assign(l10n_util::GetStringUTF16(
293 IDS_PAGE_INFO_SECURITY_TAB_INSECURE_IDENTITY));
294 if (ssl.security_style == content::SECURITY_STYLE_UNAUTHENTICATED)
295 site_identity_status_ = SITE_IDENTITY_STATUS_NO_CERT;
296 else
297 site_identity_status_ = SITE_IDENTITY_STATUS_ERROR;
298
299 const string16 bullet = UTF8ToUTF16("\n • ");
300 std::vector<SSLErrorInfo> errors;
301 SSLErrorInfo::GetErrorsForCertStatus(ssl.cert_id, ssl.cert_status,
302 url, &errors);
303 for (size_t i = 0; i < errors.size(); ++i) {
304 site_identity_details_ += bullet;
305 site_identity_details_ += errors[i].short_description();
306 }
307
308 if (ssl.cert_status & net::CERT_STATUS_NON_UNIQUE_NAME) {
309 site_identity_details_ += ASCIIToUTF16("\n\n");
310 site_identity_details_ += l10n_util::GetStringUTF16(
311 IDS_PAGE_INFO_SECURITY_TAB_NON_UNIQUE_NAME);
312 }
313 }
314
315 // Site Connection
316 // We consider anything less than 80 bits encryption to be weak encryption.
317 // TODO(wtc): Bug 1198735: report mixed/unsafe content for unencrypted and
318 // weakly encrypted connections.
319 site_connection_status_ = SITE_CONNECTION_STATUS_UNKNOWN;
320
321 if (!ssl.cert_id) {
322 // Not HTTPS.
323 DCHECK_EQ(ssl.security_style, content::SECURITY_STYLE_UNAUTHENTICATED);
324 if (ssl.security_style == content::SECURITY_STYLE_UNAUTHENTICATED)
325 site_connection_status_ = SITE_CONNECTION_STATUS_UNENCRYPTED;
326 else
327 site_connection_status_ = SITE_CONNECTION_STATUS_ENCRYPTED_ERROR;
328
329 site_connection_details_.assign(l10n_util::GetStringFUTF16(
330 IDS_PAGE_INFO_SECURITY_TAB_NOT_ENCRYPTED_CONNECTION_TEXT,
331 subject_name));
332 } else if (ssl.security_bits < 0) {
333 // Security strength is unknown. Say nothing.
334 site_connection_status_ = SITE_CONNECTION_STATUS_ENCRYPTED_ERROR;
335 } else if (ssl.security_bits == 0) {
336 DCHECK_NE(ssl.security_style, content::SECURITY_STYLE_UNAUTHENTICATED);
337 site_connection_status_ = SITE_CONNECTION_STATUS_ENCRYPTED_ERROR;
338 site_connection_details_.assign(l10n_util::GetStringFUTF16(
339 IDS_PAGE_INFO_SECURITY_TAB_NOT_ENCRYPTED_CONNECTION_TEXT,
340 subject_name));
341 } else if (ssl.security_bits < 80) {
342 site_connection_status_ = SITE_CONNECTION_STATUS_ENCRYPTED_ERROR;
343 site_connection_details_.assign(l10n_util::GetStringFUTF16(
344 IDS_PAGE_INFO_SECURITY_TAB_WEAK_ENCRYPTION_CONNECTION_TEXT,
345 subject_name));
346 } else {
347 site_connection_status_ = SITE_CONNECTION_STATUS_ENCRYPTED;
348 site_connection_details_.assign(l10n_util::GetStringFUTF16(
349 IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTED_CONNECTION_TEXT,
350 subject_name,
351 base::IntToString16(ssl.security_bits)));
352 if (ssl.content_status) {
353 bool ran_insecure_content =
354 !!(ssl.content_status & content::SSLStatus::RAN_INSECURE_CONTENT);
355 site_connection_status_ = ran_insecure_content ?
356 SITE_CONNECTION_STATUS_ENCRYPTED_ERROR
357 : SITE_CONNECTION_STATUS_MIXED_CONTENT;
358 site_connection_details_.assign(l10n_util::GetStringFUTF16(
359 IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTED_SENTENCE_LINK,
360 site_connection_details_,
361 l10n_util::GetStringUTF16(ran_insecure_content ?
362 IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTED_INSECURE_CONTENT_ERROR :
363 IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTED_INSECURE_CONTENT_WARNING)));
364 }
365 }
366
367 uint16 cipher_suite =
368 net::SSLConnectionStatusToCipherSuite(ssl.connection_status);
369 if (ssl.security_bits > 0 && cipher_suite) {
370 int ssl_version =
371 net::SSLConnectionStatusToVersion(ssl.connection_status);
372 const char* ssl_version_str;
373 net::SSLVersionToString(&ssl_version_str, ssl_version);
374 site_connection_details_ += ASCIIToUTF16("\n\n");
375 site_connection_details_ += l10n_util::GetStringFUTF16(
376 IDS_PAGE_INFO_SECURITY_TAB_SSL_VERSION,
377 ASCIIToUTF16(ssl_version_str));
378
379 bool did_fallback = (ssl.connection_status &
[email protected]80c75f682012-05-26 16:22:17380 net::SSL_CONNECTION_VERSION_FALLBACK) != 0;
[email protected]03ef4b2a2012-03-06 15:04:20381 bool no_renegotiation =
382 (ssl.connection_status &
383 net::SSL_CONNECTION_NO_RENEGOTIATION_EXTENSION) != 0;
384 const char *key_exchange, *cipher, *mac;
385 net::SSLCipherSuiteToStrings(&key_exchange, &cipher, &mac, cipher_suite);
386
387 site_connection_details_ += ASCIIToUTF16("\n\n");
388 site_connection_details_ += l10n_util::GetStringFUTF16(
389 IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTION_DETAILS,
390 ASCIIToUTF16(cipher), ASCIIToUTF16(mac), ASCIIToUTF16(key_exchange));
391
392 site_connection_details_ += ASCIIToUTF16("\n\n");
393 uint8 compression_id =
394 net::SSLConnectionStatusToCompression(ssl.connection_status);
395 if (compression_id) {
396 const char* compression;
397 net::SSLCompressionToString(&compression, compression_id);
398 site_connection_details_ += l10n_util::GetStringFUTF16(
399 IDS_PAGE_INFO_SECURITY_TAB_COMPRESSION_DETAILS,
400 ASCIIToUTF16(compression));
401 } else {
402 site_connection_details_ += l10n_util::GetStringUTF16(
403 IDS_PAGE_INFO_SECURITY_TAB_NO_COMPRESSION);
404 }
405
406 if (did_fallback) {
407 // For now, only SSLv3 fallback will trigger a warning icon.
408 if (site_connection_status_ < SITE_CONNECTION_STATUS_MIXED_CONTENT)
409 site_connection_status_ = SITE_CONNECTION_STATUS_MIXED_CONTENT;
410 site_connection_details_ += ASCIIToUTF16("\n\n");
411 site_connection_details_ += l10n_util::GetStringUTF16(
412 IDS_PAGE_INFO_SECURITY_TAB_FALLBACK_MESSAGE);
413 }
414 if (no_renegotiation) {
415 site_connection_details_ += ASCIIToUTF16("\n\n");
416 site_connection_details_ += l10n_util::GetStringUTF16(
417 IDS_PAGE_INFO_SECURITY_TAB_RENEGOTIATION_MESSAGE);
418 }
419 }
420}
[email protected]0b9fdd72012-04-04 10:00:33421
[email protected]df818272012-04-20 13:10:50422void WebsiteSettings::PresentSitePermissions() {
423 PermissionInfoList permission_info_list;
424
425 WebsiteSettingsUI::PermissionInfo permission_info;
426 for (size_t i = 0; i < arraysize(kPermissionType); ++i) {
427 permission_info.type = kPermissionType[i];
428
429 content_settings::SettingInfo info;
430 scoped_ptr<Value> value(content_settings_->GetWebsiteSetting(
431 site_url_, site_url_, permission_info.type, "", &info));
432 DCHECK(value.get());
433 permission_info.setting =
434 content_settings::ValueToContentSetting(value.get());
[email protected]8bdf45c32012-08-04 00:12:55435 permission_info.source = info.source;
[email protected]df818272012-04-20 13:10:50436
[email protected]b1d113d2012-06-27 21:27:34437 if (info.primary_pattern == ContentSettingsPattern::Wildcard() &&
438 info.secondary_pattern == ContentSettingsPattern::Wildcard()) {
439 permission_info.default_setting = permission_info.setting;
440 permission_info.setting = CONTENT_SETTING_DEFAULT;
441 } else {
442 permission_info.default_setting =
443 content_settings_->GetDefaultContentSetting(permission_info.type,
444 NULL);
[email protected]df818272012-04-20 13:10:50445 }
[email protected]b1d113d2012-06-27 21:27:34446 permission_info_list.push_back(permission_info);
[email protected]df818272012-04-20 13:10:50447 }
448
449 ui_->SetPermissionInfo(permission_info_list);
[email protected]0b9fdd72012-04-04 10:00:33450}
451
[email protected]df818272012-04-20 13:10:50452void WebsiteSettings::PresentSiteData() {
453 CookieInfoList cookie_info_list;
[email protected]e0ac35892012-05-15 12:53:34454 const LocalSharedObjectsContainer& allowed_objects =
455 tab_specific_content_settings()->allowed_local_shared_objects();
456 const LocalSharedObjectsContainer& blocked_objects =
457 tab_specific_content_settings()->blocked_local_shared_objects();
458
459 // Add first party cookie and site data counts.
[email protected]df818272012-04-20 13:10:50460 WebsiteSettingsUI::CookieInfo cookie_info;
[email protected]e0ac35892012-05-15 12:53:34461 std::string cookie_source =
462 net::RegistryControlledDomainService::GetDomainAndRegistry(site_url_);
463 if (cookie_source.empty())
464 cookie_source = site_url_.host();
465 cookie_info.cookie_source = cookie_source;
466 cookie_info.allowed = allowed_objects.GetObjectCountForDomain(site_url_);
467 cookie_info.blocked = blocked_objects.GetObjectCountForDomain(site_url_);
468 cookie_info_list.push_back(cookie_info);
469
470 // Add third party cookie counts.
471 cookie_info.cookie_source = l10n_util::GetStringUTF8(
472 IDS_WEBSITE_SETTINGS_THIRD_PARTY_SITE_DATA);
473 cookie_info.allowed = allowed_objects.GetObjectCount() - cookie_info.allowed;
474 cookie_info.blocked = blocked_objects.GetObjectCount() - cookie_info.blocked;
[email protected]df818272012-04-20 13:10:50475 cookie_info_list.push_back(cookie_info);
[email protected]0b9fdd72012-04-04 10:00:33476
[email protected]df818272012-04-20 13:10:50477 ui_->SetCookieInfo(cookie_info_list);
[email protected]0b9fdd72012-04-04 10:00:33478}
[email protected]16de6de2012-04-04 12:24:14479
[email protected]24c8818c2012-04-25 09:57:41480void WebsiteSettings::PresentSiteIdentity() {
481 // After initialization the status about the site's connection
482 // and it's identity must be available.
483 DCHECK_NE(site_identity_status_, SITE_IDENTITY_STATUS_UNKNOWN);
484 DCHECK_NE(site_connection_status_, SITE_CONNECTION_STATUS_UNKNOWN);
485 WebsiteSettingsUI::IdentityInfo info;
486 if (site_identity_status_ == SITE_IDENTITY_STATUS_EV_CERT)
487 info.site_identity = UTF16ToUTF8(organization_name());
488 else
489 info.site_identity = site_url_.host();
490
491 info.connection_status = site_connection_status_;
492 info.connection_status_description =
493 UTF16ToUTF8(site_connection_details_);
494 info.identity_status = site_identity_status_;
495 info.identity_status_description =
496 UTF16ToUTF8(site_identity_details_);
[email protected]f61c1ce2012-05-09 13:55:11497 info.cert_id = cert_id_;
[email protected]24c8818c2012-04-25 09:57:41498 ui_->SetIdentityInfo(info);
499}
500
[email protected]15b092542012-05-16 13:08:14501void WebsiteSettings::PresentHistoryInfo(base::Time first_visit) {
502 if (first_visit == base::Time()) {
503 ui_->SetFirstVisit(string16());
504 return;
505 }
506
507 bool visited_before_today = false;
508 base::Time today = base::Time::Now().LocalMidnight();
509 base::Time first_visit_midnight = first_visit.LocalMidnight();
510 visited_before_today = (first_visit_midnight < today);
511
512 string16 first_visit_text;
513 if (visited_before_today) {
514 first_visit_text = l10n_util::GetStringFUTF16(
515 IDS_PAGE_INFO_SECURITY_TAB_VISITED_BEFORE_TODAY,
516 base::TimeFormatShortDate(first_visit));
517 } else {
518 first_visit_text = l10n_util::GetStringUTF16(
519 IDS_PAGE_INFO_SECURITY_TAB_FIRST_VISITED_TODAY);
520
521 }
522 ui_->SetFirstVisit(first_visit_text);
523}