blob: 91bfc11db62ef381a284fbd142fb608da211c041 [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]03ef4b2a2012-03-06 15:04:2025#include "chrome/browser/profiles/profile.h"
[email protected]78a1fd90a2012-07-19 08:11:2526#include "chrome/browser/history/history_service_factory.h"
[email protected]03ef4b2a2012-03-06 15:04:2027#include "chrome/browser/ssl/ssl_error_info.h"
[email protected]4237dd52012-06-05 00:00:3228#include "chrome/browser/ui/website_settings/website_settings_ui.h"
[email protected]0b9fdd72012-04-04 10:00:3329#include "chrome/common/content_settings_pattern.h"
30#include "content/public/browser/browser_thread.h"
[email protected]b59c6cf02012-03-12 20:51:4231#include "content/public/browser/cert_store.h"
[email protected]03ef4b2a2012-03-06 15:04:2032#include "content/public/common/ssl_status.h"
33#include "content/public/common/url_constants.h"
34#include "grit/chromium_strings.h"
35#include "grit/generated_resources.h"
36#include "net/base/cert_status_flags.h"
[email protected]e0ac35892012-05-15 12:53:3437#include "net/base/registry_controlled_domain.h"
[email protected]03ef4b2a2012-03-06 15:04:2038#include "net/base/ssl_cipher_suite_names.h"
39#include "net/base/ssl_connection_status_flags.h"
40#include "net/base/x509_certificate.h"
41#include "ui/base/l10n/l10n_util.h"
42#include "ui/base/resource/resource_bundle.h"
43
[email protected]0b9fdd72012-04-04 10:00:3344using content::BrowserThread;
45
46namespace {
47
[email protected]b1d113d2012-06-27 21:27:3448// The list of content settings types to display on the Website Settings UI.
[email protected]0b9fdd72012-04-04 10:00:3349ContentSettingsType kPermissionType[] = {
[email protected]b1d113d2012-06-27 21:27:3450 CONTENT_SETTINGS_TYPE_IMAGES,
51 CONTENT_SETTINGS_TYPE_JAVASCRIPT,
[email protected]0b9fdd72012-04-04 10:00:3352 CONTENT_SETTINGS_TYPE_PLUGINS,
[email protected]b1d113d2012-06-27 21:27:3453 CONTENT_SETTINGS_TYPE_POPUPS,
[email protected]0b9fdd72012-04-04 10:00:3354 CONTENT_SETTINGS_TYPE_GEOLOCATION,
[email protected]b1d113d2012-06-27 21:27:3455 CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
56 CONTENT_SETTINGS_TYPE_FULLSCREEN,
57 CONTENT_SETTINGS_TYPE_MOUSELOCK,
58 CONTENT_SETTINGS_TYPE_MEDIASTREAM,
[email protected]0b9fdd72012-04-04 10:00:3359};
60
61} // namespace
62
63WebsiteSettings::WebsiteSettings(
64 WebsiteSettingsUI* ui,
65 Profile* profile,
[email protected]df818272012-04-20 13:10:5066 TabSpecificContentSettings* tab_specific_content_settings,
[email protected]0b9fdd72012-04-04 10:00:3367 const GURL& url,
68 const content::SSLStatus& ssl,
69 content::CertStore* cert_store)
[email protected]df818272012-04-20 13:10:5070 : TabSpecificContentSettings::SiteDataObserver(
71 tab_specific_content_settings),
72 ui_(ui),
[email protected]0b9fdd72012-04-04 10:00:3373 site_url_(url),
74 site_identity_status_(SITE_IDENTITY_STATUS_UNKNOWN),
[email protected]f61c1ce2012-05-09 13:55:1175 cert_id_(0),
[email protected]03ef4b2a2012-03-06 15:04:2076 site_connection_status_(SITE_CONNECTION_STATUS_UNKNOWN),
[email protected]0b9fdd72012-04-04 10:00:3377 cert_store_(cert_store),
78 content_settings_(profile->GetHostContentSettingsMap()) {
[email protected]03ef4b2a2012-03-06 15:04:2079 Init(profile, url, ssl);
[email protected]0b9fdd72012-04-04 10:00:3380
[email protected]78a1fd90a2012-07-19 08:11:2581 HistoryService* history_service = HistoryServiceFactory::GetForProfile(
82 profile, Profile::EXPLICIT_ACCESS);
[email protected]15b092542012-05-16 13:08:1483 if (history_service) {
84 history_service->GetVisibleVisitCountToHost(
85 site_url_,
86 &visit_count_request_consumer_,
87 base::Bind(&WebsiteSettings::OnGotVisitCountToHost,
88 base::Unretained(this)));
89 }
90
[email protected]0b9fdd72012-04-04 10:00:3391 PresentSitePermissions();
[email protected]df818272012-04-20 13:10:5092 PresentSiteData();
[email protected]24c8818c2012-04-25 09:57:4193 PresentSiteIdentity();
[email protected]15b092542012-05-16 13:08:1494 PresentHistoryInfo(base::Time());
[email protected]03ef4b2a2012-03-06 15:04:2095}
96
[email protected]0b9fdd72012-04-04 10:00:3397WebsiteSettings::~WebsiteSettings() {
[email protected]03ef4b2a2012-03-06 15:04:2098}
99
[email protected]df818272012-04-20 13:10:50100void WebsiteSettings::OnSitePermissionChanged(ContentSettingsType type,
101 ContentSetting setting) {
102 ContentSettingsPattern primary_pattern;
103 ContentSettingsPattern secondary_pattern;
104 switch (type) {
105 case CONTENT_SETTINGS_TYPE_GEOLOCATION:
106 // TODO(markusheintz): The rule we create here should also change the
107 // location permission for iframed content.
108 primary_pattern = ContentSettingsPattern::FromURLNoWildcard(site_url_);
109 secondary_pattern = ContentSettingsPattern::FromURLNoWildcard(site_url_);
110 break;
111 case CONTENT_SETTINGS_TYPE_NOTIFICATIONS:
112 primary_pattern = ContentSettingsPattern::FromURLNoWildcard(site_url_);
113 secondary_pattern = ContentSettingsPattern::Wildcard();
114 break;
[email protected]b1d113d2012-06-27 21:27:34115 case CONTENT_SETTINGS_TYPE_IMAGES:
116 case CONTENT_SETTINGS_TYPE_JAVASCRIPT:
[email protected]df818272012-04-20 13:10:50117 case CONTENT_SETTINGS_TYPE_PLUGINS:
118 case CONTENT_SETTINGS_TYPE_POPUPS:
[email protected]b1d113d2012-06-27 21:27:34119 case CONTENT_SETTINGS_TYPE_FULLSCREEN:
120 case CONTENT_SETTINGS_TYPE_MOUSELOCK:
121 case CONTENT_SETTINGS_TYPE_MEDIASTREAM:
[email protected]df818272012-04-20 13:10:50122 primary_pattern = ContentSettingsPattern::FromURL(site_url_);
123 secondary_pattern = ContentSettingsPattern::Wildcard();
124 break;
125 default:
126 NOTREACHED() << "ContentSettingsType " << type << "is not supported.";
127 break;
[email protected]0b9fdd72012-04-04 10:00:33128 }
129
[email protected]df818272012-04-20 13:10:50130 // Permission settings are specified via rules. There exists always at least
131 // one rule for the default setting. Get the rule that currently defines
132 // the permission for the given permission |type|. Then test whether the
133 // existing rule is more specific than the rule we are about to create. If
134 // the existing rule is more specific, than change the existing rule instead
135 // of creating a new rule that would be hidden behind the existing rule.
136 content_settings::SettingInfo info;
137 scoped_ptr<Value> v(content_settings_->GetWebsiteSetting(
138 site_url_, site_url_, type, "", &info));
139 DCHECK(info.source == content_settings::SETTING_SOURCE_USER);
140 ContentSettingsPattern::Relation r1 =
141 info.primary_pattern.Compare(primary_pattern);
142 DCHECK(r1 != ContentSettingsPattern::DISJOINT_ORDER_POST &&
143 r1 != ContentSettingsPattern::DISJOINT_ORDER_PRE);
144 if (r1 == ContentSettingsPattern::PREDECESSOR) {
145 primary_pattern = info.primary_pattern;
146 } else if (r1 == ContentSettingsPattern::IDENTITY) {
147 ContentSettingsPattern::Relation r2 =
148 info.secondary_pattern.Compare(secondary_pattern);
149 DCHECK(r2 != ContentSettingsPattern::DISJOINT_ORDER_POST &&
150 r2 != ContentSettingsPattern::DISJOINT_ORDER_PRE);
151 if (r2 == ContentSettingsPattern::PREDECESSOR)
152 secondary_pattern = info.secondary_pattern;
153 }
154
155 Value* value = NULL;
156 if (setting != CONTENT_SETTING_DEFAULT)
157 value = Value::CreateIntegerValue(setting);
158 content_settings_->SetWebsiteSetting(
159 primary_pattern, secondary_pattern, type, "", value);
160}
161
[email protected]15b092542012-05-16 13:08:14162void WebsiteSettings::OnGotVisitCountToHost(HistoryService::Handle handle,
163 bool found_visits,
164 int visit_count,
165 base::Time first_visit) {
166 if (!found_visits) {
167 // This indicates an error, such as the page's URL scheme wasn't
168 // http/https.
169 first_visit = base::Time();
170 } else if (visit_count == 0) {
171 first_visit = base::Time::Now();
172 }
173 PresentHistoryInfo(first_visit);
174}
175
[email protected]df818272012-04-20 13:10:50176void WebsiteSettings::OnSiteDataAccessed() {
177 PresentSiteData();
[email protected]0b9fdd72012-04-04 10:00:33178}
179
180void WebsiteSettings::Init(Profile* profile,
181 const GURL& url,
182 const content::SSLStatus& ssl) {
[email protected]03ef4b2a2012-03-06 15:04:20183 if (url.SchemeIs(chrome::kChromeUIScheme)) {
184 site_identity_status_ = SITE_IDENTITY_STATUS_INTERNAL_PAGE;
185 site_identity_details_ =
186 l10n_util::GetStringUTF16(IDS_PAGE_INFO_INTERNAL_PAGE);
187 site_connection_status_ = SITE_CONNECTION_STATUS_INTERNAL_PAGE;
188 return;
189 }
190
191 scoped_refptr<net::X509Certificate> cert;
192
193 // Identity section.
194 string16 subject_name(UTF8ToUTF16(url.host()));
[email protected]03ef4b2a2012-03-06 15:04:20195 if (subject_name.empty()) {
196 subject_name.assign(
197 l10n_util::GetStringUTF16(IDS_PAGE_INFO_SECURITY_TAB_UNKNOWN_PARTY));
[email protected]03ef4b2a2012-03-06 15:04:20198 }
199
[email protected]f61c1ce2012-05-09 13:55:11200 cert_id_ = ssl.cert_id;
201
[email protected]03ef4b2a2012-03-06 15:04:20202 if (ssl.cert_id &&
203 cert_store_->RetrieveCert(ssl.cert_id, &cert) &&
204 (!net::IsCertStatusError(ssl.cert_status) ||
205 net::IsCertStatusMinorError(ssl.cert_status))) {
206 // There are no major errors. Check for minor errors.
207 if (net::IsCertStatusMinorError(ssl.cert_status)) {
208 site_identity_status_ = SITE_IDENTITY_STATUS_CERT_REVOCATION_UNKNOWN;
209 string16 issuer_name(UTF8ToUTF16(cert->issuer().GetDisplayName()));
210 if (issuer_name.empty()) {
211 issuer_name.assign(l10n_util::GetStringUTF16(
212 IDS_PAGE_INFO_SECURITY_TAB_UNKNOWN_PARTY));
213 }
214 site_identity_details_.assign(l10n_util::GetStringFUTF16(
215 IDS_PAGE_INFO_SECURITY_TAB_SECURE_IDENTITY, issuer_name));
216
217 site_identity_details_ += ASCIIToUTF16("\n\n");
218 if (ssl.cert_status & net::CERT_STATUS_UNABLE_TO_CHECK_REVOCATION) {
219 site_identity_details_ += l10n_util::GetStringUTF16(
220 IDS_PAGE_INFO_SECURITY_TAB_UNABLE_TO_CHECK_REVOCATION);
221 } else if (ssl.cert_status & net::CERT_STATUS_NO_REVOCATION_MECHANISM) {
222 site_identity_details_ += l10n_util::GetStringUTF16(
223 IDS_PAGE_INFO_SECURITY_TAB_NO_REVOCATION_MECHANISM);
224 } else {
225 NOTREACHED() << "Need to specify string for this warning";
226 }
227 } else if (ssl.cert_status & net::CERT_STATUS_IS_EV) {
228 // EV HTTPS page.
229 site_identity_status_ = SITE_IDENTITY_STATUS_EV_CERT;
230 DCHECK(!cert->subject().organization_names.empty());
231 organization_name_ = UTF8ToUTF16(cert->subject().organization_names[0]);
232 // An EV Cert is required to have a city (localityName) and country but
233 // state is "if any".
234 DCHECK(!cert->subject().locality_name.empty());
235 DCHECK(!cert->subject().country_name.empty());
236 string16 locality;
237 if (!cert->subject().state_or_province_name.empty()) {
238 locality = l10n_util::GetStringFUTF16(
239 IDS_PAGEINFO_ADDRESS,
240 UTF8ToUTF16(cert->subject().locality_name),
241 UTF8ToUTF16(cert->subject().state_or_province_name),
242 UTF8ToUTF16(cert->subject().country_name));
243 } else {
244 locality = l10n_util::GetStringFUTF16(
245 IDS_PAGEINFO_PARTIAL_ADDRESS,
246 UTF8ToUTF16(cert->subject().locality_name),
247 UTF8ToUTF16(cert->subject().country_name));
248 }
249 DCHECK(!cert->subject().organization_names.empty());
250 site_identity_details_.assign(l10n_util::GetStringFUTF16(
251 IDS_PAGE_INFO_SECURITY_TAB_SECURE_IDENTITY_EV,
252 UTF8ToUTF16(cert->subject().organization_names[0]),
253 locality,
254 UTF8ToUTF16(cert->issuer().GetDisplayName())));
255 } else if (ssl.cert_status & net::CERT_STATUS_IS_DNSSEC) {
256 // DNSSEC authenticated page.
257 site_identity_status_ = SITE_IDENTITY_STATUS_DNSSEC_CERT;
258 site_identity_details_.assign(l10n_util::GetStringFUTF16(
259 IDS_PAGE_INFO_SECURITY_TAB_SECURE_IDENTITY, UTF8ToUTF16("DNSSEC")));
260 } else {
261 // Non-EV OK HTTPS page.
262 site_identity_status_ = SITE_IDENTITY_STATUS_CERT;
263 string16 issuer_name(UTF8ToUTF16(cert->issuer().GetDisplayName()));
264 if (issuer_name.empty()) {
265 issuer_name.assign(l10n_util::GetStringUTF16(
266 IDS_PAGE_INFO_SECURITY_TAB_UNKNOWN_PARTY));
267 }
268 site_identity_details_.assign(l10n_util::GetStringFUTF16(
269 IDS_PAGE_INFO_SECURITY_TAB_SECURE_IDENTITY, issuer_name));
270 }
271 } else {
272 // HTTP or HTTPS with errors (not warnings).
273 site_identity_details_.assign(l10n_util::GetStringUTF16(
274 IDS_PAGE_INFO_SECURITY_TAB_INSECURE_IDENTITY));
275 if (ssl.security_style == content::SECURITY_STYLE_UNAUTHENTICATED)
276 site_identity_status_ = SITE_IDENTITY_STATUS_NO_CERT;
277 else
278 site_identity_status_ = SITE_IDENTITY_STATUS_ERROR;
279
280 const string16 bullet = UTF8ToUTF16("\n • ");
281 std::vector<SSLErrorInfo> errors;
282 SSLErrorInfo::GetErrorsForCertStatus(ssl.cert_id, ssl.cert_status,
283 url, &errors);
284 for (size_t i = 0; i < errors.size(); ++i) {
285 site_identity_details_ += bullet;
286 site_identity_details_ += errors[i].short_description();
287 }
288
289 if (ssl.cert_status & net::CERT_STATUS_NON_UNIQUE_NAME) {
290 site_identity_details_ += ASCIIToUTF16("\n\n");
291 site_identity_details_ += l10n_util::GetStringUTF16(
292 IDS_PAGE_INFO_SECURITY_TAB_NON_UNIQUE_NAME);
293 }
294 }
295
296 // Site Connection
297 // We consider anything less than 80 bits encryption to be weak encryption.
298 // TODO(wtc): Bug 1198735: report mixed/unsafe content for unencrypted and
299 // weakly encrypted connections.
300 site_connection_status_ = SITE_CONNECTION_STATUS_UNKNOWN;
301
302 if (!ssl.cert_id) {
303 // Not HTTPS.
304 DCHECK_EQ(ssl.security_style, content::SECURITY_STYLE_UNAUTHENTICATED);
305 if (ssl.security_style == content::SECURITY_STYLE_UNAUTHENTICATED)
306 site_connection_status_ = SITE_CONNECTION_STATUS_UNENCRYPTED;
307 else
308 site_connection_status_ = SITE_CONNECTION_STATUS_ENCRYPTED_ERROR;
309
310 site_connection_details_.assign(l10n_util::GetStringFUTF16(
311 IDS_PAGE_INFO_SECURITY_TAB_NOT_ENCRYPTED_CONNECTION_TEXT,
312 subject_name));
313 } else if (ssl.security_bits < 0) {
314 // Security strength is unknown. Say nothing.
315 site_connection_status_ = SITE_CONNECTION_STATUS_ENCRYPTED_ERROR;
316 } else if (ssl.security_bits == 0) {
317 DCHECK_NE(ssl.security_style, content::SECURITY_STYLE_UNAUTHENTICATED);
318 site_connection_status_ = SITE_CONNECTION_STATUS_ENCRYPTED_ERROR;
319 site_connection_details_.assign(l10n_util::GetStringFUTF16(
320 IDS_PAGE_INFO_SECURITY_TAB_NOT_ENCRYPTED_CONNECTION_TEXT,
321 subject_name));
322 } else if (ssl.security_bits < 80) {
323 site_connection_status_ = SITE_CONNECTION_STATUS_ENCRYPTED_ERROR;
324 site_connection_details_.assign(l10n_util::GetStringFUTF16(
325 IDS_PAGE_INFO_SECURITY_TAB_WEAK_ENCRYPTION_CONNECTION_TEXT,
326 subject_name));
327 } else {
328 site_connection_status_ = SITE_CONNECTION_STATUS_ENCRYPTED;
329 site_connection_details_.assign(l10n_util::GetStringFUTF16(
330 IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTED_CONNECTION_TEXT,
331 subject_name,
332 base::IntToString16(ssl.security_bits)));
333 if (ssl.content_status) {
334 bool ran_insecure_content =
335 !!(ssl.content_status & content::SSLStatus::RAN_INSECURE_CONTENT);
336 site_connection_status_ = ran_insecure_content ?
337 SITE_CONNECTION_STATUS_ENCRYPTED_ERROR
338 : SITE_CONNECTION_STATUS_MIXED_CONTENT;
339 site_connection_details_.assign(l10n_util::GetStringFUTF16(
340 IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTED_SENTENCE_LINK,
341 site_connection_details_,
342 l10n_util::GetStringUTF16(ran_insecure_content ?
343 IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTED_INSECURE_CONTENT_ERROR :
344 IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTED_INSECURE_CONTENT_WARNING)));
345 }
346 }
347
348 uint16 cipher_suite =
349 net::SSLConnectionStatusToCipherSuite(ssl.connection_status);
350 if (ssl.security_bits > 0 && cipher_suite) {
351 int ssl_version =
352 net::SSLConnectionStatusToVersion(ssl.connection_status);
353 const char* ssl_version_str;
354 net::SSLVersionToString(&ssl_version_str, ssl_version);
355 site_connection_details_ += ASCIIToUTF16("\n\n");
356 site_connection_details_ += l10n_util::GetStringFUTF16(
357 IDS_PAGE_INFO_SECURITY_TAB_SSL_VERSION,
358 ASCIIToUTF16(ssl_version_str));
359
360 bool did_fallback = (ssl.connection_status &
[email protected]80c75f682012-05-26 16:22:17361 net::SSL_CONNECTION_VERSION_FALLBACK) != 0;
[email protected]03ef4b2a2012-03-06 15:04:20362 bool no_renegotiation =
363 (ssl.connection_status &
364 net::SSL_CONNECTION_NO_RENEGOTIATION_EXTENSION) != 0;
365 const char *key_exchange, *cipher, *mac;
366 net::SSLCipherSuiteToStrings(&key_exchange, &cipher, &mac, cipher_suite);
367
368 site_connection_details_ += ASCIIToUTF16("\n\n");
369 site_connection_details_ += l10n_util::GetStringFUTF16(
370 IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTION_DETAILS,
371 ASCIIToUTF16(cipher), ASCIIToUTF16(mac), ASCIIToUTF16(key_exchange));
372
373 site_connection_details_ += ASCIIToUTF16("\n\n");
374 uint8 compression_id =
375 net::SSLConnectionStatusToCompression(ssl.connection_status);
376 if (compression_id) {
377 const char* compression;
378 net::SSLCompressionToString(&compression, compression_id);
379 site_connection_details_ += l10n_util::GetStringFUTF16(
380 IDS_PAGE_INFO_SECURITY_TAB_COMPRESSION_DETAILS,
381 ASCIIToUTF16(compression));
382 } else {
383 site_connection_details_ += l10n_util::GetStringUTF16(
384 IDS_PAGE_INFO_SECURITY_TAB_NO_COMPRESSION);
385 }
386
387 if (did_fallback) {
388 // For now, only SSLv3 fallback will trigger a warning icon.
389 if (site_connection_status_ < SITE_CONNECTION_STATUS_MIXED_CONTENT)
390 site_connection_status_ = SITE_CONNECTION_STATUS_MIXED_CONTENT;
391 site_connection_details_ += ASCIIToUTF16("\n\n");
392 site_connection_details_ += l10n_util::GetStringUTF16(
393 IDS_PAGE_INFO_SECURITY_TAB_FALLBACK_MESSAGE);
394 }
395 if (no_renegotiation) {
396 site_connection_details_ += ASCIIToUTF16("\n\n");
397 site_connection_details_ += l10n_util::GetStringUTF16(
398 IDS_PAGE_INFO_SECURITY_TAB_RENEGOTIATION_MESSAGE);
399 }
400 }
401}
[email protected]0b9fdd72012-04-04 10:00:33402
[email protected]df818272012-04-20 13:10:50403void WebsiteSettings::PresentSitePermissions() {
404 PermissionInfoList permission_info_list;
405
406 WebsiteSettingsUI::PermissionInfo permission_info;
407 for (size_t i = 0; i < arraysize(kPermissionType); ++i) {
408 permission_info.type = kPermissionType[i];
409
410 content_settings::SettingInfo info;
411 scoped_ptr<Value> value(content_settings_->GetWebsiteSetting(
412 site_url_, site_url_, permission_info.type, "", &info));
413 DCHECK(value.get());
414 permission_info.setting =
415 content_settings::ValueToContentSetting(value.get());
416
[email protected]b1d113d2012-06-27 21:27:34417 if (info.primary_pattern == ContentSettingsPattern::Wildcard() &&
418 info.secondary_pattern == ContentSettingsPattern::Wildcard()) {
419 permission_info.default_setting = permission_info.setting;
420 permission_info.setting = CONTENT_SETTING_DEFAULT;
421 } else {
422 permission_info.default_setting =
423 content_settings_->GetDefaultContentSetting(permission_info.type,
424 NULL);
[email protected]df818272012-04-20 13:10:50425 }
[email protected]b1d113d2012-06-27 21:27:34426 permission_info_list.push_back(permission_info);
[email protected]df818272012-04-20 13:10:50427 }
428
429 ui_->SetPermissionInfo(permission_info_list);
[email protected]0b9fdd72012-04-04 10:00:33430}
431
[email protected]df818272012-04-20 13:10:50432void WebsiteSettings::PresentSiteData() {
433 CookieInfoList cookie_info_list;
[email protected]e0ac35892012-05-15 12:53:34434 const LocalSharedObjectsContainer& allowed_objects =
435 tab_specific_content_settings()->allowed_local_shared_objects();
436 const LocalSharedObjectsContainer& blocked_objects =
437 tab_specific_content_settings()->blocked_local_shared_objects();
438
439 // Add first party cookie and site data counts.
[email protected]df818272012-04-20 13:10:50440 WebsiteSettingsUI::CookieInfo cookie_info;
[email protected]e0ac35892012-05-15 12:53:34441 std::string cookie_source =
442 net::RegistryControlledDomainService::GetDomainAndRegistry(site_url_);
443 if (cookie_source.empty())
444 cookie_source = site_url_.host();
445 cookie_info.cookie_source = cookie_source;
446 cookie_info.allowed = allowed_objects.GetObjectCountForDomain(site_url_);
447 cookie_info.blocked = blocked_objects.GetObjectCountForDomain(site_url_);
448 cookie_info_list.push_back(cookie_info);
449
450 // Add third party cookie counts.
451 cookie_info.cookie_source = l10n_util::GetStringUTF8(
452 IDS_WEBSITE_SETTINGS_THIRD_PARTY_SITE_DATA);
453 cookie_info.allowed = allowed_objects.GetObjectCount() - cookie_info.allowed;
454 cookie_info.blocked = blocked_objects.GetObjectCount() - cookie_info.blocked;
[email protected]df818272012-04-20 13:10:50455 cookie_info_list.push_back(cookie_info);
[email protected]0b9fdd72012-04-04 10:00:33456
[email protected]df818272012-04-20 13:10:50457 ui_->SetCookieInfo(cookie_info_list);
[email protected]0b9fdd72012-04-04 10:00:33458}
[email protected]16de6de2012-04-04 12:24:14459
[email protected]24c8818c2012-04-25 09:57:41460void WebsiteSettings::PresentSiteIdentity() {
461 // After initialization the status about the site's connection
462 // and it's identity must be available.
463 DCHECK_NE(site_identity_status_, SITE_IDENTITY_STATUS_UNKNOWN);
464 DCHECK_NE(site_connection_status_, SITE_CONNECTION_STATUS_UNKNOWN);
465 WebsiteSettingsUI::IdentityInfo info;
466 if (site_identity_status_ == SITE_IDENTITY_STATUS_EV_CERT)
467 info.site_identity = UTF16ToUTF8(organization_name());
468 else
469 info.site_identity = site_url_.host();
470
471 info.connection_status = site_connection_status_;
472 info.connection_status_description =
473 UTF16ToUTF8(site_connection_details_);
474 info.identity_status = site_identity_status_;
475 info.identity_status_description =
476 UTF16ToUTF8(site_identity_details_);
[email protected]f61c1ce2012-05-09 13:55:11477 info.cert_id = cert_id_;
[email protected]24c8818c2012-04-25 09:57:41478 ui_->SetIdentityInfo(info);
479}
480
[email protected]15b092542012-05-16 13:08:14481void WebsiteSettings::PresentHistoryInfo(base::Time first_visit) {
482 if (first_visit == base::Time()) {
483 ui_->SetFirstVisit(string16());
484 return;
485 }
486
487 bool visited_before_today = false;
488 base::Time today = base::Time::Now().LocalMidnight();
489 base::Time first_visit_midnight = first_visit.LocalMidnight();
490 visited_before_today = (first_visit_midnight < today);
491
492 string16 first_visit_text;
493 if (visited_before_today) {
494 first_visit_text = l10n_util::GetStringFUTF16(
495 IDS_PAGE_INFO_SECURITY_TAB_VISITED_BEFORE_TODAY,
496 base::TimeFormatShortDate(first_visit));
497 } else {
498 first_visit_text = l10n_util::GetStringUTF16(
499 IDS_PAGE_INFO_SECURITY_TAB_FIRST_VISITED_TODAY);
500
501 }
502 ui_->SetFirstVisit(first_visit_text);
503}