blob: 9da367b1a09e3ff2a71197dae08bc4d670056686 [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]4f822f022012-12-20 19:11:4217#include "chrome/browser/api/infobars/infobar_service.h"
[email protected]b0cb5e82012-07-19 19:22:4718#include "chrome/browser/browsing_data/browsing_data_cookie_helper.h"
19#include "chrome/browser/browsing_data/browsing_data_database_helper.h"
20#include "chrome/browser/browsing_data/browsing_data_file_system_helper.h"
21#include "chrome/browser/browsing_data/browsing_data_indexed_db_helper.h"
22#include "chrome/browser/browsing_data/browsing_data_local_storage_helper.h"
23#include "chrome/browser/browsing_data/browsing_data_server_bound_cert_helper.h"
[email protected]0b9fdd72012-04-04 10:00:3324#include "chrome/browser/content_settings/content_settings_utils.h"
25#include "chrome/browser/content_settings/host_content_settings_map.h"
[email protected]df818272012-04-20 13:10:5026#include "chrome/browser/content_settings/local_shared_objects_container.h"
[email protected]77a91c72012-08-13 16:19:3427#include "chrome/browser/history/history_service_factory.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]4f822f022012-12-20 19:11:4271 InfoBarService* infobar_service,
[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]4f822f022012-12-20 19:11:4278 infobar_service_(infobar_service),
[email protected]66f157312012-08-01 13:50:2679 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:
[email protected]df818272012-04-20 13:10:50136 primary_pattern = ContentSettingsPattern::FromURL(site_url_);
137 secondary_pattern = ContentSettingsPattern::Wildcard();
138 break;
[email protected]0bacc1912012-12-11 11:05:34139 case CONTENT_SETTINGS_TYPE_MEDIASTREAM: {
140 // We need to use the same same patterns as other places like infobar code
141 // to override the existing rule instead of creating the new one.
142 primary_pattern = ContentSettingsPattern::FromURLNoWildcard(site_url_);
143 secondary_pattern = ContentSettingsPattern::Wildcard();
144 // Set permission for both microphone and camera.
145 content_settings_->SetContentSetting(
146 primary_pattern, secondary_pattern,
147 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, "", setting);
148
149 content_settings_->SetContentSetting(
150 primary_pattern, secondary_pattern,
151 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, "", setting);
152 break;
153 }
[email protected]df818272012-04-20 13:10:50154 default:
155 NOTREACHED() << "ContentSettingsType " << type << "is not supported.";
156 break;
[email protected]0b9fdd72012-04-04 10:00:33157 }
158
[email protected]0bacc1912012-12-11 11:05:34159 if (type != CONTENT_SETTINGS_TYPE_MEDIASTREAM) {
160 // Permission settings are specified via rules. There exists always at least
161 // one rule for the default setting. Get the rule that currently defines
162 // the permission for the given permission |type|. Then test whether the
163 // existing rule is more specific than the rule we are about to create. If
164 // the existing rule is more specific, than change the existing rule instead
165 // of creating a new rule that would be hidden behind the existing rule.
166 // This is not a concern for CONTENT_SETTINGS_TYPE_MEDIASTREAM since users
167 // can not create media settings exceptions by hand.
168 content_settings::SettingInfo info;
169 scoped_ptr<Value> v(content_settings_->GetWebsiteSetting(
170 site_url_, site_url_, type, "", &info));
171 DCHECK(info.source == content_settings::SETTING_SOURCE_USER);
172 ContentSettingsPattern::Relation r1 =
173 info.primary_pattern.Compare(primary_pattern);
174 DCHECK(r1 != ContentSettingsPattern::DISJOINT_ORDER_POST &&
175 r1 != ContentSettingsPattern::DISJOINT_ORDER_PRE);
176 if (r1 == ContentSettingsPattern::PREDECESSOR) {
177 primary_pattern = info.primary_pattern;
178 } else if (r1 == ContentSettingsPattern::IDENTITY) {
179 ContentSettingsPattern::Relation r2 =
180 info.secondary_pattern.Compare(secondary_pattern);
181 DCHECK(r2 != ContentSettingsPattern::DISJOINT_ORDER_POST &&
182 r2 != ContentSettingsPattern::DISJOINT_ORDER_PRE);
183 if (r2 == ContentSettingsPattern::PREDECESSOR)
184 secondary_pattern = info.secondary_pattern;
185 }
186
187 Value* value = NULL;
188 if (setting != CONTENT_SETTING_DEFAULT)
189 value = Value::CreateIntegerValue(setting);
190 content_settings_->SetWebsiteSetting(
191 primary_pattern, secondary_pattern, type, "", value);
[email protected]df818272012-04-20 13:10:50192 }
193
[email protected]66f157312012-08-01 13:50:26194 show_info_bar_ = true;
[email protected]2f45d542012-08-22 08:47:24195
[email protected]76955932012-12-06 11:01:10196// TODO(markusheintz): This is a temporary hack to fix issue:
197// http://crbug.com/144203.
[email protected]e379ba42012-08-22 22:40:25198#if defined(OS_MACOSX)
[email protected]2f45d542012-08-22 08:47:24199 // Refresh the UI to reflect the new setting.
200 PresentSitePermissions();
[email protected]e379ba42012-08-22 22:40:25201#endif
[email protected]df818272012-04-20 13:10:50202}
203
[email protected]15b092542012-05-16 13:08:14204void WebsiteSettings::OnGotVisitCountToHost(HistoryService::Handle handle,
205 bool found_visits,
206 int visit_count,
207 base::Time first_visit) {
208 if (!found_visits) {
209 // This indicates an error, such as the page's URL scheme wasn't
210 // http/https.
211 first_visit = base::Time();
212 } else if (visit_count == 0) {
213 first_visit = base::Time::Now();
214 }
215 PresentHistoryInfo(first_visit);
216}
217
[email protected]df818272012-04-20 13:10:50218void WebsiteSettings::OnSiteDataAccessed() {
219 PresentSiteData();
[email protected]0b9fdd72012-04-04 10:00:33220}
221
[email protected]66f157312012-08-01 13:50:26222void WebsiteSettings::OnUIClosing() {
223 if (show_info_bar_) {
[email protected]4f822f022012-12-20 19:11:42224 infobar_service_->AddInfoBar(
225 new WebsiteSettingsInfobarDelegate(infobar_service_));
[email protected]66f157312012-08-01 13:50:26226 }
227}
228
[email protected]0b9fdd72012-04-04 10:00:33229void WebsiteSettings::Init(Profile* profile,
230 const GURL& url,
231 const content::SSLStatus& ssl) {
[email protected]03ef4b2a2012-03-06 15:04:20232 if (url.SchemeIs(chrome::kChromeUIScheme)) {
233 site_identity_status_ = SITE_IDENTITY_STATUS_INTERNAL_PAGE;
234 site_identity_details_ =
235 l10n_util::GetStringUTF16(IDS_PAGE_INFO_INTERNAL_PAGE);
236 site_connection_status_ = SITE_CONNECTION_STATUS_INTERNAL_PAGE;
237 return;
238 }
239
240 scoped_refptr<net::X509Certificate> cert;
241
242 // Identity section.
243 string16 subject_name(UTF8ToUTF16(url.host()));
[email protected]03ef4b2a2012-03-06 15:04:20244 if (subject_name.empty()) {
245 subject_name.assign(
246 l10n_util::GetStringUTF16(IDS_PAGE_INFO_SECURITY_TAB_UNKNOWN_PARTY));
[email protected]03ef4b2a2012-03-06 15:04:20247 }
248
[email protected]f61c1ce2012-05-09 13:55:11249 cert_id_ = ssl.cert_id;
250
[email protected]03ef4b2a2012-03-06 15:04:20251 if (ssl.cert_id &&
252 cert_store_->RetrieveCert(ssl.cert_id, &cert) &&
253 (!net::IsCertStatusError(ssl.cert_status) ||
254 net::IsCertStatusMinorError(ssl.cert_status))) {
255 // There are no major errors. Check for minor errors.
256 if (net::IsCertStatusMinorError(ssl.cert_status)) {
257 site_identity_status_ = SITE_IDENTITY_STATUS_CERT_REVOCATION_UNKNOWN;
258 string16 issuer_name(UTF8ToUTF16(cert->issuer().GetDisplayName()));
259 if (issuer_name.empty()) {
260 issuer_name.assign(l10n_util::GetStringUTF16(
261 IDS_PAGE_INFO_SECURITY_TAB_UNKNOWN_PARTY));
262 }
263 site_identity_details_.assign(l10n_util::GetStringFUTF16(
264 IDS_PAGE_INFO_SECURITY_TAB_SECURE_IDENTITY, issuer_name));
265
266 site_identity_details_ += ASCIIToUTF16("\n\n");
267 if (ssl.cert_status & net::CERT_STATUS_UNABLE_TO_CHECK_REVOCATION) {
268 site_identity_details_ += l10n_util::GetStringUTF16(
269 IDS_PAGE_INFO_SECURITY_TAB_UNABLE_TO_CHECK_REVOCATION);
270 } else if (ssl.cert_status & net::CERT_STATUS_NO_REVOCATION_MECHANISM) {
271 site_identity_details_ += l10n_util::GetStringUTF16(
272 IDS_PAGE_INFO_SECURITY_TAB_NO_REVOCATION_MECHANISM);
273 } else {
274 NOTREACHED() << "Need to specify string for this warning";
275 }
276 } else if (ssl.cert_status & net::CERT_STATUS_IS_EV) {
277 // EV HTTPS page.
278 site_identity_status_ = SITE_IDENTITY_STATUS_EV_CERT;
279 DCHECK(!cert->subject().organization_names.empty());
280 organization_name_ = UTF8ToUTF16(cert->subject().organization_names[0]);
281 // An EV Cert is required to have a city (localityName) and country but
282 // state is "if any".
283 DCHECK(!cert->subject().locality_name.empty());
284 DCHECK(!cert->subject().country_name.empty());
285 string16 locality;
286 if (!cert->subject().state_or_province_name.empty()) {
287 locality = l10n_util::GetStringFUTF16(
288 IDS_PAGEINFO_ADDRESS,
289 UTF8ToUTF16(cert->subject().locality_name),
290 UTF8ToUTF16(cert->subject().state_or_province_name),
291 UTF8ToUTF16(cert->subject().country_name));
292 } else {
293 locality = l10n_util::GetStringFUTF16(
294 IDS_PAGEINFO_PARTIAL_ADDRESS,
295 UTF8ToUTF16(cert->subject().locality_name),
296 UTF8ToUTF16(cert->subject().country_name));
297 }
298 DCHECK(!cert->subject().organization_names.empty());
299 site_identity_details_.assign(l10n_util::GetStringFUTF16(
300 IDS_PAGE_INFO_SECURITY_TAB_SECURE_IDENTITY_EV,
301 UTF8ToUTF16(cert->subject().organization_names[0]),
302 locality,
303 UTF8ToUTF16(cert->issuer().GetDisplayName())));
[email protected]03ef4b2a2012-03-06 15:04:20304 } else {
305 // Non-EV OK HTTPS page.
306 site_identity_status_ = SITE_IDENTITY_STATUS_CERT;
307 string16 issuer_name(UTF8ToUTF16(cert->issuer().GetDisplayName()));
308 if (issuer_name.empty()) {
309 issuer_name.assign(l10n_util::GetStringUTF16(
310 IDS_PAGE_INFO_SECURITY_TAB_UNKNOWN_PARTY));
311 }
312 site_identity_details_.assign(l10n_util::GetStringFUTF16(
313 IDS_PAGE_INFO_SECURITY_TAB_SECURE_IDENTITY, issuer_name));
314 }
315 } else {
316 // HTTP or HTTPS with errors (not warnings).
317 site_identity_details_.assign(l10n_util::GetStringUTF16(
318 IDS_PAGE_INFO_SECURITY_TAB_INSECURE_IDENTITY));
319 if (ssl.security_style == content::SECURITY_STYLE_UNAUTHENTICATED)
320 site_identity_status_ = SITE_IDENTITY_STATUS_NO_CERT;
321 else
322 site_identity_status_ = SITE_IDENTITY_STATUS_ERROR;
323
324 const string16 bullet = UTF8ToUTF16("\n • ");
325 std::vector<SSLErrorInfo> errors;
326 SSLErrorInfo::GetErrorsForCertStatus(ssl.cert_id, ssl.cert_status,
327 url, &errors);
328 for (size_t i = 0; i < errors.size(); ++i) {
329 site_identity_details_ += bullet;
330 site_identity_details_ += errors[i].short_description();
331 }
332
333 if (ssl.cert_status & net::CERT_STATUS_NON_UNIQUE_NAME) {
334 site_identity_details_ += ASCIIToUTF16("\n\n");
335 site_identity_details_ += l10n_util::GetStringUTF16(
336 IDS_PAGE_INFO_SECURITY_TAB_NON_UNIQUE_NAME);
337 }
338 }
339
340 // Site Connection
341 // We consider anything less than 80 bits encryption to be weak encryption.
342 // TODO(wtc): Bug 1198735: report mixed/unsafe content for unencrypted and
343 // weakly encrypted connections.
344 site_connection_status_ = SITE_CONNECTION_STATUS_UNKNOWN;
345
346 if (!ssl.cert_id) {
347 // Not HTTPS.
348 DCHECK_EQ(ssl.security_style, content::SECURITY_STYLE_UNAUTHENTICATED);
349 if (ssl.security_style == content::SECURITY_STYLE_UNAUTHENTICATED)
350 site_connection_status_ = SITE_CONNECTION_STATUS_UNENCRYPTED;
351 else
352 site_connection_status_ = SITE_CONNECTION_STATUS_ENCRYPTED_ERROR;
353
354 site_connection_details_.assign(l10n_util::GetStringFUTF16(
355 IDS_PAGE_INFO_SECURITY_TAB_NOT_ENCRYPTED_CONNECTION_TEXT,
356 subject_name));
357 } else if (ssl.security_bits < 0) {
358 // Security strength is unknown. Say nothing.
359 site_connection_status_ = SITE_CONNECTION_STATUS_ENCRYPTED_ERROR;
360 } else if (ssl.security_bits == 0) {
361 DCHECK_NE(ssl.security_style, content::SECURITY_STYLE_UNAUTHENTICATED);
362 site_connection_status_ = SITE_CONNECTION_STATUS_ENCRYPTED_ERROR;
363 site_connection_details_.assign(l10n_util::GetStringFUTF16(
364 IDS_PAGE_INFO_SECURITY_TAB_NOT_ENCRYPTED_CONNECTION_TEXT,
365 subject_name));
366 } else if (ssl.security_bits < 80) {
367 site_connection_status_ = SITE_CONNECTION_STATUS_ENCRYPTED_ERROR;
368 site_connection_details_.assign(l10n_util::GetStringFUTF16(
369 IDS_PAGE_INFO_SECURITY_TAB_WEAK_ENCRYPTION_CONNECTION_TEXT,
370 subject_name));
371 } else {
372 site_connection_status_ = SITE_CONNECTION_STATUS_ENCRYPTED;
373 site_connection_details_.assign(l10n_util::GetStringFUTF16(
374 IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTED_CONNECTION_TEXT,
375 subject_name,
376 base::IntToString16(ssl.security_bits)));
377 if (ssl.content_status) {
378 bool ran_insecure_content =
379 !!(ssl.content_status & content::SSLStatus::RAN_INSECURE_CONTENT);
380 site_connection_status_ = ran_insecure_content ?
381 SITE_CONNECTION_STATUS_ENCRYPTED_ERROR
382 : SITE_CONNECTION_STATUS_MIXED_CONTENT;
383 site_connection_details_.assign(l10n_util::GetStringFUTF16(
384 IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTED_SENTENCE_LINK,
385 site_connection_details_,
386 l10n_util::GetStringUTF16(ran_insecure_content ?
387 IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTED_INSECURE_CONTENT_ERROR :
388 IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTED_INSECURE_CONTENT_WARNING)));
389 }
390 }
391
392 uint16 cipher_suite =
393 net::SSLConnectionStatusToCipherSuite(ssl.connection_status);
394 if (ssl.security_bits > 0 && cipher_suite) {
395 int ssl_version =
396 net::SSLConnectionStatusToVersion(ssl.connection_status);
397 const char* ssl_version_str;
398 net::SSLVersionToString(&ssl_version_str, ssl_version);
399 site_connection_details_ += ASCIIToUTF16("\n\n");
400 site_connection_details_ += l10n_util::GetStringFUTF16(
401 IDS_PAGE_INFO_SECURITY_TAB_SSL_VERSION,
402 ASCIIToUTF16(ssl_version_str));
403
404 bool did_fallback = (ssl.connection_status &
[email protected]80c75f682012-05-26 16:22:17405 net::SSL_CONNECTION_VERSION_FALLBACK) != 0;
[email protected]03ef4b2a2012-03-06 15:04:20406 bool no_renegotiation =
407 (ssl.connection_status &
408 net::SSL_CONNECTION_NO_RENEGOTIATION_EXTENSION) != 0;
409 const char *key_exchange, *cipher, *mac;
410 net::SSLCipherSuiteToStrings(&key_exchange, &cipher, &mac, cipher_suite);
411
412 site_connection_details_ += ASCIIToUTF16("\n\n");
413 site_connection_details_ += l10n_util::GetStringFUTF16(
414 IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTION_DETAILS,
415 ASCIIToUTF16(cipher), ASCIIToUTF16(mac), ASCIIToUTF16(key_exchange));
416
417 site_connection_details_ += ASCIIToUTF16("\n\n");
418 uint8 compression_id =
419 net::SSLConnectionStatusToCompression(ssl.connection_status);
420 if (compression_id) {
421 const char* compression;
422 net::SSLCompressionToString(&compression, compression_id);
423 site_connection_details_ += l10n_util::GetStringFUTF16(
424 IDS_PAGE_INFO_SECURITY_TAB_COMPRESSION_DETAILS,
425 ASCIIToUTF16(compression));
426 } else {
427 site_connection_details_ += l10n_util::GetStringUTF16(
428 IDS_PAGE_INFO_SECURITY_TAB_NO_COMPRESSION);
429 }
430
431 if (did_fallback) {
432 // For now, only SSLv3 fallback will trigger a warning icon.
433 if (site_connection_status_ < SITE_CONNECTION_STATUS_MIXED_CONTENT)
434 site_connection_status_ = SITE_CONNECTION_STATUS_MIXED_CONTENT;
435 site_connection_details_ += ASCIIToUTF16("\n\n");
436 site_connection_details_ += l10n_util::GetStringUTF16(
437 IDS_PAGE_INFO_SECURITY_TAB_FALLBACK_MESSAGE);
438 }
439 if (no_renegotiation) {
440 site_connection_details_ += ASCIIToUTF16("\n\n");
441 site_connection_details_ += l10n_util::GetStringUTF16(
442 IDS_PAGE_INFO_SECURITY_TAB_RENEGOTIATION_MESSAGE);
443 }
444 }
[email protected]e583f752012-08-30 13:26:21445
446 // By default select the permissions tab that displays all the site
447 // permissions. In case of a connection error or an issue with the
448 // certificate presented by the website, select the connection tab to draw
449 // the user's attention to the issue. If the site does not provide a
450 // certificate because it was loaded over an unencrypted connection, don't
451 // select the connection tab.
452 WebsiteSettingsUI::TabId tab_id = WebsiteSettingsUI::TAB_ID_PERMISSIONS;
453 if (site_connection_status_ == SITE_CONNECTION_STATUS_ENCRYPTED_ERROR ||
454 site_connection_status_ == SITE_CONNECTION_STATUS_MIXED_CONTENT ||
455 site_identity_status_ == SITE_IDENTITY_STATUS_ERROR ||
456 site_identity_status_ == SITE_IDENTITY_STATUS_CERT_REVOCATION_UNKNOWN)
457 tab_id = WebsiteSettingsUI::TAB_ID_CONNECTION;
458 ui_->SetSelectedTab(tab_id);
[email protected]03ef4b2a2012-03-06 15:04:20459}
[email protected]0b9fdd72012-04-04 10:00:33460
[email protected]df818272012-04-20 13:10:50461void WebsiteSettings::PresentSitePermissions() {
462 PermissionInfoList permission_info_list;
463
464 WebsiteSettingsUI::PermissionInfo permission_info;
465 for (size_t i = 0; i < arraysize(kPermissionType); ++i) {
466 permission_info.type = kPermissionType[i];
467
468 content_settings::SettingInfo info;
[email protected]0bacc1912012-12-11 11:05:34469 if (permission_info.type == CONTENT_SETTINGS_TYPE_MEDIASTREAM) {
470 scoped_ptr<base::Value> mic_value(content_settings_->GetWebsiteSetting(
471 site_url_, site_url_, CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC,
472 "", &info));
473 ContentSetting mic_setting =
474 content_settings::ValueToContentSetting(mic_value.get());
475
476 scoped_ptr<base::Value> camera_value(content_settings_->GetWebsiteSetting(
477 site_url_, site_url_, CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA,
478 "", &info));
479 ContentSetting camera_setting =
480 content_settings::ValueToContentSetting(camera_value.get());
481
482 if (mic_setting != camera_setting || mic_setting == CONTENT_SETTING_ASK)
483 permission_info.setting = CONTENT_SETTING_DEFAULT;
484 else
485 permission_info.setting = mic_setting;
[email protected]fe4686a2012-10-19 15:38:26486 } else {
[email protected]0bacc1912012-12-11 11:05:34487 scoped_ptr<Value> value(content_settings_->GetWebsiteSetting(
488 site_url_, site_url_, permission_info.type, "", &info));
489 DCHECK(value.get());
490 if (value->GetType() == Value::TYPE_INTEGER) {
491 permission_info.setting =
492 content_settings::ValueToContentSetting(value.get());
493 } else {
494 NOTREACHED();
495 }
[email protected]fe4686a2012-10-19 15:38:26496 }
497
[email protected]8bdf45c32012-08-04 00:12:55498 permission_info.source = info.source;
[email protected]df818272012-04-20 13:10:50499
[email protected]b1d113d2012-06-27 21:27:34500 if (info.primary_pattern == ContentSettingsPattern::Wildcard() &&
[email protected]0bacc1912012-12-11 11:05:34501 info.secondary_pattern == ContentSettingsPattern::Wildcard() &&
502 permission_info.type != CONTENT_SETTINGS_TYPE_MEDIASTREAM) {
[email protected]b1d113d2012-06-27 21:27:34503 permission_info.default_setting = permission_info.setting;
504 permission_info.setting = CONTENT_SETTING_DEFAULT;
505 } else {
506 permission_info.default_setting =
507 content_settings_->GetDefaultContentSetting(permission_info.type,
508 NULL);
[email protected]df818272012-04-20 13:10:50509 }
[email protected]b1d113d2012-06-27 21:27:34510 permission_info_list.push_back(permission_info);
[email protected]df818272012-04-20 13:10:50511 }
512
513 ui_->SetPermissionInfo(permission_info_list);
[email protected]0b9fdd72012-04-04 10:00:33514}
515
[email protected]df818272012-04-20 13:10:50516void WebsiteSettings::PresentSiteData() {
517 CookieInfoList cookie_info_list;
[email protected]e0ac35892012-05-15 12:53:34518 const LocalSharedObjectsContainer& allowed_objects =
519 tab_specific_content_settings()->allowed_local_shared_objects();
520 const LocalSharedObjectsContainer& blocked_objects =
521 tab_specific_content_settings()->blocked_local_shared_objects();
522
523 // Add first party cookie and site data counts.
[email protected]df818272012-04-20 13:10:50524 WebsiteSettingsUI::CookieInfo cookie_info;
[email protected]e0ac35892012-05-15 12:53:34525 std::string cookie_source =
526 net::RegistryControlledDomainService::GetDomainAndRegistry(site_url_);
527 if (cookie_source.empty())
528 cookie_source = site_url_.host();
529 cookie_info.cookie_source = cookie_source;
530 cookie_info.allowed = allowed_objects.GetObjectCountForDomain(site_url_);
531 cookie_info.blocked = blocked_objects.GetObjectCountForDomain(site_url_);
532 cookie_info_list.push_back(cookie_info);
533
534 // Add third party cookie counts.
535 cookie_info.cookie_source = l10n_util::GetStringUTF8(
536 IDS_WEBSITE_SETTINGS_THIRD_PARTY_SITE_DATA);
537 cookie_info.allowed = allowed_objects.GetObjectCount() - cookie_info.allowed;
538 cookie_info.blocked = blocked_objects.GetObjectCount() - cookie_info.blocked;
[email protected]df818272012-04-20 13:10:50539 cookie_info_list.push_back(cookie_info);
[email protected]0b9fdd72012-04-04 10:00:33540
[email protected]df818272012-04-20 13:10:50541 ui_->SetCookieInfo(cookie_info_list);
[email protected]0b9fdd72012-04-04 10:00:33542}
[email protected]16de6de2012-04-04 12:24:14543
[email protected]24c8818c2012-04-25 09:57:41544void WebsiteSettings::PresentSiteIdentity() {
545 // After initialization the status about the site's connection
546 // and it's identity must be available.
547 DCHECK_NE(site_identity_status_, SITE_IDENTITY_STATUS_UNKNOWN);
548 DCHECK_NE(site_connection_status_, SITE_CONNECTION_STATUS_UNKNOWN);
549 WebsiteSettingsUI::IdentityInfo info;
550 if (site_identity_status_ == SITE_IDENTITY_STATUS_EV_CERT)
551 info.site_identity = UTF16ToUTF8(organization_name());
552 else
553 info.site_identity = site_url_.host();
554
555 info.connection_status = site_connection_status_;
556 info.connection_status_description =
557 UTF16ToUTF8(site_connection_details_);
558 info.identity_status = site_identity_status_;
559 info.identity_status_description =
560 UTF16ToUTF8(site_identity_details_);
[email protected]f61c1ce2012-05-09 13:55:11561 info.cert_id = cert_id_;
[email protected]24c8818c2012-04-25 09:57:41562 ui_->SetIdentityInfo(info);
563}
564
[email protected]15b092542012-05-16 13:08:14565void WebsiteSettings::PresentHistoryInfo(base::Time first_visit) {
566 if (first_visit == base::Time()) {
567 ui_->SetFirstVisit(string16());
568 return;
569 }
570
571 bool visited_before_today = false;
572 base::Time today = base::Time::Now().LocalMidnight();
573 base::Time first_visit_midnight = first_visit.LocalMidnight();
574 visited_before_today = (first_visit_midnight < today);
575
576 string16 first_visit_text;
577 if (visited_before_today) {
578 first_visit_text = l10n_util::GetStringFUTF16(
579 IDS_PAGE_INFO_SECURITY_TAB_VISITED_BEFORE_TODAY,
580 base::TimeFormatShortDate(first_visit));
581 } else {
582 first_visit_text = l10n_util::GetStringUTF16(
583 IDS_PAGE_INFO_SECURITY_TAB_FIRST_VISITED_TODAY);
584
585 }
586 ui_->SetFirstVisit(first_visit_text);
587}