blob: 8d672c2e4c9e96cea1db452ae79c250731224e19 [file] [log] [blame]
[email protected]03ef4b2a2012-03-06 15:04:201// Copyright (c) 2012 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]4237dd52012-06-05 00:00:325#include "chrome/browser/ui/website_settings/website_settings.h"
[email protected]03ef4b2a2012-03-06 15:04:206
7#include <string>
8#include <vector>
9
[email protected]15b092542012-05-16 13:08:1410#include "base/bind.h"
11#include "base/bind_helpers.h"
12#include "base/i18n/time_formatting.h"
[email protected]3ea1b182013-02-08 22:38:4113#include "base/metrics/histogram.h"
14#include "base/strings/string_number_conversions.h"
[email protected]03ef4b2a2012-03-06 15:04:2015#include "base/utf_string_conversions.h"
[email protected]0b9fdd72012-04-04 10:00:3316#include "base/values.h"
[email protected]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() {
[email protected]0be09932013-01-08 02:03:50223 if (show_info_bar_)
224 WebsiteSettingsInfobarDelegate::Create(infobar_service_);
[email protected]66f157312012-08-01 13:50:26225}
226
[email protected]0b9fdd72012-04-04 10:00:33227void WebsiteSettings::Init(Profile* profile,
228 const GURL& url,
229 const content::SSLStatus& ssl) {
[email protected]03ef4b2a2012-03-06 15:04:20230 if (url.SchemeIs(chrome::kChromeUIScheme)) {
231 site_identity_status_ = SITE_IDENTITY_STATUS_INTERNAL_PAGE;
232 site_identity_details_ =
233 l10n_util::GetStringUTF16(IDS_PAGE_INFO_INTERNAL_PAGE);
234 site_connection_status_ = SITE_CONNECTION_STATUS_INTERNAL_PAGE;
235 return;
236 }
237
238 scoped_refptr<net::X509Certificate> cert;
239
240 // Identity section.
241 string16 subject_name(UTF8ToUTF16(url.host()));
[email protected]03ef4b2a2012-03-06 15:04:20242 if (subject_name.empty()) {
243 subject_name.assign(
244 l10n_util::GetStringUTF16(IDS_PAGE_INFO_SECURITY_TAB_UNKNOWN_PARTY));
[email protected]03ef4b2a2012-03-06 15:04:20245 }
246
[email protected]f61c1ce2012-05-09 13:55:11247 cert_id_ = ssl.cert_id;
248
[email protected]03ef4b2a2012-03-06 15:04:20249 if (ssl.cert_id &&
250 cert_store_->RetrieveCert(ssl.cert_id, &cert) &&
251 (!net::IsCertStatusError(ssl.cert_status) ||
252 net::IsCertStatusMinorError(ssl.cert_status))) {
253 // There are no major errors. Check for minor errors.
254 if (net::IsCertStatusMinorError(ssl.cert_status)) {
255 site_identity_status_ = SITE_IDENTITY_STATUS_CERT_REVOCATION_UNKNOWN;
256 string16 issuer_name(UTF8ToUTF16(cert->issuer().GetDisplayName()));
257 if (issuer_name.empty()) {
258 issuer_name.assign(l10n_util::GetStringUTF16(
259 IDS_PAGE_INFO_SECURITY_TAB_UNKNOWN_PARTY));
260 }
261 site_identity_details_.assign(l10n_util::GetStringFUTF16(
262 IDS_PAGE_INFO_SECURITY_TAB_SECURE_IDENTITY, issuer_name));
263
264 site_identity_details_ += ASCIIToUTF16("\n\n");
265 if (ssl.cert_status & net::CERT_STATUS_UNABLE_TO_CHECK_REVOCATION) {
266 site_identity_details_ += l10n_util::GetStringUTF16(
267 IDS_PAGE_INFO_SECURITY_TAB_UNABLE_TO_CHECK_REVOCATION);
268 } else if (ssl.cert_status & net::CERT_STATUS_NO_REVOCATION_MECHANISM) {
269 site_identity_details_ += l10n_util::GetStringUTF16(
270 IDS_PAGE_INFO_SECURITY_TAB_NO_REVOCATION_MECHANISM);
271 } else {
272 NOTREACHED() << "Need to specify string for this warning";
273 }
274 } else if (ssl.cert_status & net::CERT_STATUS_IS_EV) {
275 // EV HTTPS page.
276 site_identity_status_ = SITE_IDENTITY_STATUS_EV_CERT;
277 DCHECK(!cert->subject().organization_names.empty());
278 organization_name_ = UTF8ToUTF16(cert->subject().organization_names[0]);
279 // An EV Cert is required to have a city (localityName) and country but
280 // state is "if any".
281 DCHECK(!cert->subject().locality_name.empty());
282 DCHECK(!cert->subject().country_name.empty());
283 string16 locality;
284 if (!cert->subject().state_or_province_name.empty()) {
285 locality = l10n_util::GetStringFUTF16(
286 IDS_PAGEINFO_ADDRESS,
287 UTF8ToUTF16(cert->subject().locality_name),
288 UTF8ToUTF16(cert->subject().state_or_province_name),
289 UTF8ToUTF16(cert->subject().country_name));
290 } else {
291 locality = l10n_util::GetStringFUTF16(
292 IDS_PAGEINFO_PARTIAL_ADDRESS,
293 UTF8ToUTF16(cert->subject().locality_name),
294 UTF8ToUTF16(cert->subject().country_name));
295 }
296 DCHECK(!cert->subject().organization_names.empty());
297 site_identity_details_.assign(l10n_util::GetStringFUTF16(
298 IDS_PAGE_INFO_SECURITY_TAB_SECURE_IDENTITY_EV,
299 UTF8ToUTF16(cert->subject().organization_names[0]),
300 locality,
301 UTF8ToUTF16(cert->issuer().GetDisplayName())));
[email protected]03ef4b2a2012-03-06 15:04:20302 } else {
303 // Non-EV OK HTTPS page.
304 site_identity_status_ = SITE_IDENTITY_STATUS_CERT;
305 string16 issuer_name(UTF8ToUTF16(cert->issuer().GetDisplayName()));
306 if (issuer_name.empty()) {
307 issuer_name.assign(l10n_util::GetStringUTF16(
308 IDS_PAGE_INFO_SECURITY_TAB_UNKNOWN_PARTY));
309 }
310 site_identity_details_.assign(l10n_util::GetStringFUTF16(
311 IDS_PAGE_INFO_SECURITY_TAB_SECURE_IDENTITY, issuer_name));
312 }
313 } else {
314 // HTTP or HTTPS with errors (not warnings).
315 site_identity_details_.assign(l10n_util::GetStringUTF16(
316 IDS_PAGE_INFO_SECURITY_TAB_INSECURE_IDENTITY));
317 if (ssl.security_style == content::SECURITY_STYLE_UNAUTHENTICATED)
318 site_identity_status_ = SITE_IDENTITY_STATUS_NO_CERT;
319 else
320 site_identity_status_ = SITE_IDENTITY_STATUS_ERROR;
321
322 const string16 bullet = UTF8ToUTF16("\n • ");
323 std::vector<SSLErrorInfo> errors;
324 SSLErrorInfo::GetErrorsForCertStatus(ssl.cert_id, ssl.cert_status,
325 url, &errors);
326 for (size_t i = 0; i < errors.size(); ++i) {
327 site_identity_details_ += bullet;
328 site_identity_details_ += errors[i].short_description();
329 }
330
331 if (ssl.cert_status & net::CERT_STATUS_NON_UNIQUE_NAME) {
332 site_identity_details_ += ASCIIToUTF16("\n\n");
333 site_identity_details_ += l10n_util::GetStringUTF16(
334 IDS_PAGE_INFO_SECURITY_TAB_NON_UNIQUE_NAME);
335 }
336 }
337
338 // Site Connection
339 // We consider anything less than 80 bits encryption to be weak encryption.
340 // TODO(wtc): Bug 1198735: report mixed/unsafe content for unencrypted and
341 // weakly encrypted connections.
342 site_connection_status_ = SITE_CONNECTION_STATUS_UNKNOWN;
343
344 if (!ssl.cert_id) {
345 // Not HTTPS.
346 DCHECK_EQ(ssl.security_style, content::SECURITY_STYLE_UNAUTHENTICATED);
347 if (ssl.security_style == content::SECURITY_STYLE_UNAUTHENTICATED)
348 site_connection_status_ = SITE_CONNECTION_STATUS_UNENCRYPTED;
349 else
350 site_connection_status_ = SITE_CONNECTION_STATUS_ENCRYPTED_ERROR;
351
352 site_connection_details_.assign(l10n_util::GetStringFUTF16(
353 IDS_PAGE_INFO_SECURITY_TAB_NOT_ENCRYPTED_CONNECTION_TEXT,
354 subject_name));
355 } else if (ssl.security_bits < 0) {
356 // Security strength is unknown. Say nothing.
357 site_connection_status_ = SITE_CONNECTION_STATUS_ENCRYPTED_ERROR;
358 } else if (ssl.security_bits == 0) {
359 DCHECK_NE(ssl.security_style, content::SECURITY_STYLE_UNAUTHENTICATED);
360 site_connection_status_ = SITE_CONNECTION_STATUS_ENCRYPTED_ERROR;
361 site_connection_details_.assign(l10n_util::GetStringFUTF16(
362 IDS_PAGE_INFO_SECURITY_TAB_NOT_ENCRYPTED_CONNECTION_TEXT,
363 subject_name));
364 } else if (ssl.security_bits < 80) {
365 site_connection_status_ = SITE_CONNECTION_STATUS_ENCRYPTED_ERROR;
366 site_connection_details_.assign(l10n_util::GetStringFUTF16(
367 IDS_PAGE_INFO_SECURITY_TAB_WEAK_ENCRYPTION_CONNECTION_TEXT,
368 subject_name));
369 } else {
370 site_connection_status_ = SITE_CONNECTION_STATUS_ENCRYPTED;
371 site_connection_details_.assign(l10n_util::GetStringFUTF16(
372 IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTED_CONNECTION_TEXT,
373 subject_name,
374 base::IntToString16(ssl.security_bits)));
375 if (ssl.content_status) {
376 bool ran_insecure_content =
377 !!(ssl.content_status & content::SSLStatus::RAN_INSECURE_CONTENT);
378 site_connection_status_ = ran_insecure_content ?
379 SITE_CONNECTION_STATUS_ENCRYPTED_ERROR
380 : SITE_CONNECTION_STATUS_MIXED_CONTENT;
381 site_connection_details_.assign(l10n_util::GetStringFUTF16(
382 IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTED_SENTENCE_LINK,
383 site_connection_details_,
384 l10n_util::GetStringUTF16(ran_insecure_content ?
385 IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTED_INSECURE_CONTENT_ERROR :
386 IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTED_INSECURE_CONTENT_WARNING)));
387 }
388 }
389
390 uint16 cipher_suite =
391 net::SSLConnectionStatusToCipherSuite(ssl.connection_status);
392 if (ssl.security_bits > 0 && cipher_suite) {
393 int ssl_version =
394 net::SSLConnectionStatusToVersion(ssl.connection_status);
395 const char* ssl_version_str;
396 net::SSLVersionToString(&ssl_version_str, ssl_version);
397 site_connection_details_ += ASCIIToUTF16("\n\n");
398 site_connection_details_ += l10n_util::GetStringFUTF16(
399 IDS_PAGE_INFO_SECURITY_TAB_SSL_VERSION,
400 ASCIIToUTF16(ssl_version_str));
401
402 bool did_fallback = (ssl.connection_status &
[email protected]80c75f682012-05-26 16:22:17403 net::SSL_CONNECTION_VERSION_FALLBACK) != 0;
[email protected]03ef4b2a2012-03-06 15:04:20404 bool no_renegotiation =
405 (ssl.connection_status &
406 net::SSL_CONNECTION_NO_RENEGOTIATION_EXTENSION) != 0;
407 const char *key_exchange, *cipher, *mac;
408 net::SSLCipherSuiteToStrings(&key_exchange, &cipher, &mac, cipher_suite);
409
410 site_connection_details_ += ASCIIToUTF16("\n\n");
411 site_connection_details_ += l10n_util::GetStringFUTF16(
412 IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTION_DETAILS,
413 ASCIIToUTF16(cipher), ASCIIToUTF16(mac), ASCIIToUTF16(key_exchange));
414
415 site_connection_details_ += ASCIIToUTF16("\n\n");
416 uint8 compression_id =
417 net::SSLConnectionStatusToCompression(ssl.connection_status);
418 if (compression_id) {
419 const char* compression;
420 net::SSLCompressionToString(&compression, compression_id);
421 site_connection_details_ += l10n_util::GetStringFUTF16(
422 IDS_PAGE_INFO_SECURITY_TAB_COMPRESSION_DETAILS,
423 ASCIIToUTF16(compression));
424 } else {
425 site_connection_details_ += l10n_util::GetStringUTF16(
426 IDS_PAGE_INFO_SECURITY_TAB_NO_COMPRESSION);
427 }
428
429 if (did_fallback) {
430 // For now, only SSLv3 fallback will trigger a warning icon.
431 if (site_connection_status_ < SITE_CONNECTION_STATUS_MIXED_CONTENT)
432 site_connection_status_ = SITE_CONNECTION_STATUS_MIXED_CONTENT;
433 site_connection_details_ += ASCIIToUTF16("\n\n");
434 site_connection_details_ += l10n_util::GetStringUTF16(
435 IDS_PAGE_INFO_SECURITY_TAB_FALLBACK_MESSAGE);
436 }
437 if (no_renegotiation) {
438 site_connection_details_ += ASCIIToUTF16("\n\n");
439 site_connection_details_ += l10n_util::GetStringUTF16(
440 IDS_PAGE_INFO_SECURITY_TAB_RENEGOTIATION_MESSAGE);
441 }
442 }
[email protected]e583f752012-08-30 13:26:21443
444 // By default select the permissions tab that displays all the site
445 // permissions. In case of a connection error or an issue with the
446 // certificate presented by the website, select the connection tab to draw
447 // the user's attention to the issue. If the site does not provide a
448 // certificate because it was loaded over an unencrypted connection, don't
449 // select the connection tab.
450 WebsiteSettingsUI::TabId tab_id = WebsiteSettingsUI::TAB_ID_PERMISSIONS;
451 if (site_connection_status_ == SITE_CONNECTION_STATUS_ENCRYPTED_ERROR ||
452 site_connection_status_ == SITE_CONNECTION_STATUS_MIXED_CONTENT ||
453 site_identity_status_ == SITE_IDENTITY_STATUS_ERROR ||
454 site_identity_status_ == SITE_IDENTITY_STATUS_CERT_REVOCATION_UNKNOWN)
455 tab_id = WebsiteSettingsUI::TAB_ID_CONNECTION;
456 ui_->SetSelectedTab(tab_id);
[email protected]03ef4b2a2012-03-06 15:04:20457}
[email protected]0b9fdd72012-04-04 10:00:33458
[email protected]df818272012-04-20 13:10:50459void WebsiteSettings::PresentSitePermissions() {
460 PermissionInfoList permission_info_list;
461
462 WebsiteSettingsUI::PermissionInfo permission_info;
463 for (size_t i = 0; i < arraysize(kPermissionType); ++i) {
464 permission_info.type = kPermissionType[i];
465
466 content_settings::SettingInfo info;
[email protected]0bacc1912012-12-11 11:05:34467 if (permission_info.type == CONTENT_SETTINGS_TYPE_MEDIASTREAM) {
468 scoped_ptr<base::Value> mic_value(content_settings_->GetWebsiteSetting(
469 site_url_, site_url_, CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC,
470 "", &info));
471 ContentSetting mic_setting =
472 content_settings::ValueToContentSetting(mic_value.get());
473
474 scoped_ptr<base::Value> camera_value(content_settings_->GetWebsiteSetting(
475 site_url_, site_url_, CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA,
476 "", &info));
477 ContentSetting camera_setting =
478 content_settings::ValueToContentSetting(camera_value.get());
479
480 if (mic_setting != camera_setting || mic_setting == CONTENT_SETTING_ASK)
481 permission_info.setting = CONTENT_SETTING_DEFAULT;
482 else
483 permission_info.setting = mic_setting;
[email protected]fe4686a2012-10-19 15:38:26484 } else {
[email protected]0bacc1912012-12-11 11:05:34485 scoped_ptr<Value> value(content_settings_->GetWebsiteSetting(
486 site_url_, site_url_, permission_info.type, "", &info));
487 DCHECK(value.get());
488 if (value->GetType() == Value::TYPE_INTEGER) {
489 permission_info.setting =
490 content_settings::ValueToContentSetting(value.get());
491 } else {
492 NOTREACHED();
493 }
[email protected]fe4686a2012-10-19 15:38:26494 }
495
[email protected]8bdf45c32012-08-04 00:12:55496 permission_info.source = info.source;
[email protected]df818272012-04-20 13:10:50497
[email protected]b1d113d2012-06-27 21:27:34498 if (info.primary_pattern == ContentSettingsPattern::Wildcard() &&
[email protected]0bacc1912012-12-11 11:05:34499 info.secondary_pattern == ContentSettingsPattern::Wildcard() &&
500 permission_info.type != CONTENT_SETTINGS_TYPE_MEDIASTREAM) {
[email protected]b1d113d2012-06-27 21:27:34501 permission_info.default_setting = permission_info.setting;
502 permission_info.setting = CONTENT_SETTING_DEFAULT;
503 } else {
504 permission_info.default_setting =
505 content_settings_->GetDefaultContentSetting(permission_info.type,
506 NULL);
[email protected]df818272012-04-20 13:10:50507 }
[email protected]b1d113d2012-06-27 21:27:34508 permission_info_list.push_back(permission_info);
[email protected]df818272012-04-20 13:10:50509 }
510
511 ui_->SetPermissionInfo(permission_info_list);
[email protected]0b9fdd72012-04-04 10:00:33512}
513
[email protected]df818272012-04-20 13:10:50514void WebsiteSettings::PresentSiteData() {
515 CookieInfoList cookie_info_list;
[email protected]e0ac35892012-05-15 12:53:34516 const LocalSharedObjectsContainer& allowed_objects =
517 tab_specific_content_settings()->allowed_local_shared_objects();
518 const LocalSharedObjectsContainer& blocked_objects =
519 tab_specific_content_settings()->blocked_local_shared_objects();
520
521 // Add first party cookie and site data counts.
[email protected]df818272012-04-20 13:10:50522 WebsiteSettingsUI::CookieInfo cookie_info;
[email protected]e0ac35892012-05-15 12:53:34523 std::string cookie_source =
524 net::RegistryControlledDomainService::GetDomainAndRegistry(site_url_);
525 if (cookie_source.empty())
526 cookie_source = site_url_.host();
527 cookie_info.cookie_source = cookie_source;
528 cookie_info.allowed = allowed_objects.GetObjectCountForDomain(site_url_);
529 cookie_info.blocked = blocked_objects.GetObjectCountForDomain(site_url_);
530 cookie_info_list.push_back(cookie_info);
531
532 // Add third party cookie counts.
533 cookie_info.cookie_source = l10n_util::GetStringUTF8(
534 IDS_WEBSITE_SETTINGS_THIRD_PARTY_SITE_DATA);
535 cookie_info.allowed = allowed_objects.GetObjectCount() - cookie_info.allowed;
536 cookie_info.blocked = blocked_objects.GetObjectCount() - cookie_info.blocked;
[email protected]df818272012-04-20 13:10:50537 cookie_info_list.push_back(cookie_info);
[email protected]0b9fdd72012-04-04 10:00:33538
[email protected]df818272012-04-20 13:10:50539 ui_->SetCookieInfo(cookie_info_list);
[email protected]0b9fdd72012-04-04 10:00:33540}
[email protected]16de6de2012-04-04 12:24:14541
[email protected]24c8818c2012-04-25 09:57:41542void WebsiteSettings::PresentSiteIdentity() {
543 // After initialization the status about the site's connection
544 // and it's identity must be available.
545 DCHECK_NE(site_identity_status_, SITE_IDENTITY_STATUS_UNKNOWN);
546 DCHECK_NE(site_connection_status_, SITE_CONNECTION_STATUS_UNKNOWN);
547 WebsiteSettingsUI::IdentityInfo info;
548 if (site_identity_status_ == SITE_IDENTITY_STATUS_EV_CERT)
549 info.site_identity = UTF16ToUTF8(organization_name());
550 else
551 info.site_identity = site_url_.host();
552
553 info.connection_status = site_connection_status_;
554 info.connection_status_description =
555 UTF16ToUTF8(site_connection_details_);
556 info.identity_status = site_identity_status_;
557 info.identity_status_description =
558 UTF16ToUTF8(site_identity_details_);
[email protected]f61c1ce2012-05-09 13:55:11559 info.cert_id = cert_id_;
[email protected]24c8818c2012-04-25 09:57:41560 ui_->SetIdentityInfo(info);
561}
562
[email protected]15b092542012-05-16 13:08:14563void WebsiteSettings::PresentHistoryInfo(base::Time first_visit) {
564 if (first_visit == base::Time()) {
565 ui_->SetFirstVisit(string16());
566 return;
567 }
568
569 bool visited_before_today = false;
570 base::Time today = base::Time::Now().LocalMidnight();
571 base::Time first_visit_midnight = first_visit.LocalMidnight();
572 visited_before_today = (first_visit_midnight < today);
573
574 string16 first_visit_text;
575 if (visited_before_today) {
576 first_visit_text = l10n_util::GetStringFUTF16(
577 IDS_PAGE_INFO_SECURITY_TAB_VISITED_BEFORE_TODAY,
578 base::TimeFormatShortDate(first_visit));
579 } else {
580 first_visit_text = l10n_util::GetStringUTF16(
581 IDS_PAGE_INFO_SECURITY_TAB_FIRST_VISITED_TODAY);
582
583 }
584 ui_->SetFirstVisit(first_visit_text);
585}