blob: acb3ad8555a29f70fb5b5f538670d09edc5479f5 [file] [log] [blame]
[email protected]03ef4b2a2012-03-06 15:04:201// Copyright (c) 2012 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]4237dd52012-06-05 00:00:325#include "chrome/browser/ui/website_settings/website_settings.h"
[email protected]03ef4b2a2012-03-06 15:04:206
7#include <string>
8#include <vector>
9
[email protected]15b092542012-05-16 13:08:1410#include "base/bind.h"
11#include "base/bind_helpers.h"
[email protected]e22d64f2012-09-10 09:03:2312#include "base/metrics/histogram.h"
[email protected]15b092542012-05-16 13:08:1413#include "base/i18n/time_formatting.h"
[email protected]03ef4b2a2012-03-06 15:04:2014#include "base/string_number_conversions.h"
15#include "base/utf_string_conversions.h"
[email protected]0b9fdd72012-04-04 10:00:3316#include "base/values.h"
[email protected]b0cb5e82012-07-19 19:22:4717#include "chrome/browser/browsing_data/browsing_data_cookie_helper.h"
18#include "chrome/browser/browsing_data/browsing_data_database_helper.h"
19#include "chrome/browser/browsing_data/browsing_data_file_system_helper.h"
20#include "chrome/browser/browsing_data/browsing_data_indexed_db_helper.h"
21#include "chrome/browser/browsing_data/browsing_data_local_storage_helper.h"
22#include "chrome/browser/browsing_data/browsing_data_server_bound_cert_helper.h"
[email protected]0b9fdd72012-04-04 10:00:3323#include "chrome/browser/content_settings/content_settings_utils.h"
24#include "chrome/browser/content_settings/host_content_settings_map.h"
[email protected]df818272012-04-20 13:10:5025#include "chrome/browser/content_settings/local_shared_objects_container.h"
[email protected]77a91c72012-08-13 16:19:3426#include "chrome/browser/history/history_service_factory.h"
[email protected]66f157312012-08-01 13:50:2627#include "chrome/browser/infobars/infobar_tab_helper.h"
[email protected]03ef4b2a2012-03-06 15:04:2028#include "chrome/browser/profiles/profile.h"
[email protected]03ef4b2a2012-03-06 15:04:2029#include "chrome/browser/ssl/ssl_error_info.h"
[email protected]66f157312012-08-01 13:50:2630#include "chrome/browser/ui/website_settings/website_settings_infobar_delegate.h"
[email protected]4237dd52012-06-05 00:00:3231#include "chrome/browser/ui/website_settings/website_settings_ui.h"
[email protected]0b9fdd72012-04-04 10:00:3332#include "chrome/common/content_settings_pattern.h"
33#include "content/public/browser/browser_thread.h"
[email protected]b59c6cf02012-03-12 20:51:4234#include "content/public/browser/cert_store.h"
[email protected]e22d64f2012-09-10 09:03:2335#include "content/public/browser/user_metrics.h"
[email protected]03ef4b2a2012-03-06 15:04:2036#include "content/public/common/ssl_status.h"
37#include "content/public/common/url_constants.h"
38#include "grit/chromium_strings.h"
39#include "grit/generated_resources.h"
40#include "net/base/cert_status_flags.h"
[email protected]be28b5f42012-07-20 11:31:2541#include "net/base/registry_controlled_domains/registry_controlled_domain.h"
[email protected]03ef4b2a2012-03-06 15:04:2042#include "net/base/ssl_cipher_suite_names.h"
43#include "net/base/ssl_connection_status_flags.h"
44#include "net/base/x509_certificate.h"
45#include "ui/base/l10n/l10n_util.h"
46#include "ui/base/resource/resource_bundle.h"
47
[email protected]0b9fdd72012-04-04 10:00:3348using content::BrowserThread;
49
50namespace {
51
[email protected]b1d113d2012-06-27 21:27:3452// The list of content settings types to display on the Website Settings UI.
[email protected]0b9fdd72012-04-04 10:00:3353ContentSettingsType kPermissionType[] = {
[email protected]b1d113d2012-06-27 21:27:3454 CONTENT_SETTINGS_TYPE_IMAGES,
55 CONTENT_SETTINGS_TYPE_JAVASCRIPT,
[email protected]0b9fdd72012-04-04 10:00:3356 CONTENT_SETTINGS_TYPE_PLUGINS,
[email protected]b1d113d2012-06-27 21:27:3457 CONTENT_SETTINGS_TYPE_POPUPS,
[email protected]0b9fdd72012-04-04 10:00:3358 CONTENT_SETTINGS_TYPE_GEOLOCATION,
[email protected]b1d113d2012-06-27 21:27:3459 CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
60 CONTENT_SETTINGS_TYPE_FULLSCREEN,
61 CONTENT_SETTINGS_TYPE_MOUSELOCK,
62 CONTENT_SETTINGS_TYPE_MEDIASTREAM,
[email protected]0b9fdd72012-04-04 10:00:3363};
64
65} // namespace
66
67WebsiteSettings::WebsiteSettings(
68 WebsiteSettingsUI* ui,
69 Profile* profile,
[email protected]df818272012-04-20 13:10:5070 TabSpecificContentSettings* tab_specific_content_settings,
[email protected]66f157312012-08-01 13:50:2671 InfoBarTabHelper* infobar_tab_helper,
[email protected]0b9fdd72012-04-04 10:00:3372 const GURL& url,
73 const content::SSLStatus& ssl,
74 content::CertStore* cert_store)
[email protected]df818272012-04-20 13:10:5075 : TabSpecificContentSettings::SiteDataObserver(
76 tab_specific_content_settings),
77 ui_(ui),
[email protected]66f157312012-08-01 13:50:2678 infobar_helper_(infobar_tab_helper),
79 show_info_bar_(false),
[email protected]0b9fdd72012-04-04 10:00:3380 site_url_(url),
81 site_identity_status_(SITE_IDENTITY_STATUS_UNKNOWN),
[email protected]f61c1ce2012-05-09 13:55:1182 cert_id_(0),
[email protected]03ef4b2a2012-03-06 15:04:2083 site_connection_status_(SITE_CONNECTION_STATUS_UNKNOWN),
[email protected]0b9fdd72012-04-04 10:00:3384 cert_store_(cert_store),
85 content_settings_(profile->GetHostContentSettingsMap()) {
[email protected]03ef4b2a2012-03-06 15:04:2086 Init(profile, url, ssl);
[email protected]0b9fdd72012-04-04 10:00:3387
[email protected]78a1fd90a2012-07-19 08:11:2588 HistoryService* history_service = HistoryServiceFactory::GetForProfile(
89 profile, Profile::EXPLICIT_ACCESS);
[email protected]15b092542012-05-16 13:08:1490 if (history_service) {
91 history_service->GetVisibleVisitCountToHost(
92 site_url_,
93 &visit_count_request_consumer_,
94 base::Bind(&WebsiteSettings::OnGotVisitCountToHost,
95 base::Unretained(this)));
96 }
97
[email protected]0b9fdd72012-04-04 10:00:3398 PresentSitePermissions();
[email protected]df818272012-04-20 13:10:5099 PresentSiteData();
[email protected]24c8818c2012-04-25 09:57:41100 PresentSiteIdentity();
[email protected]15b092542012-05-16 13:08:14101 PresentHistoryInfo(base::Time());
[email protected]e22d64f2012-09-10 09:03:23102
103 // Every time the Website Settings UI is opened a |WebsiteSettings| object is
104 // created. So this counts how ofter the Website Settings UI is opened.
105 content::RecordAction(content::UserMetricsAction("WebsiteSettings_Opened"));
[email protected]03ef4b2a2012-03-06 15:04:20106}
107
[email protected]0b9fdd72012-04-04 10:00:33108WebsiteSettings::~WebsiteSettings() {
[email protected]03ef4b2a2012-03-06 15:04:20109}
110
[email protected]df818272012-04-20 13:10:50111void WebsiteSettings::OnSitePermissionChanged(ContentSettingsType type,
112 ContentSetting setting) {
[email protected]e22d64f2012-09-10 09:03:23113 // Count how often a permission for a specific content type is changed using
114 // the Website Settings UI.
115 UMA_HISTOGRAM_COUNTS("WebsiteSettings.PermissionChanged", type);
116
[email protected]df818272012-04-20 13:10:50117 ContentSettingsPattern primary_pattern;
118 ContentSettingsPattern secondary_pattern;
119 switch (type) {
120 case CONTENT_SETTINGS_TYPE_GEOLOCATION:
121 // TODO(markusheintz): The rule we create here should also change the
122 // location permission for iframed content.
123 primary_pattern = ContentSettingsPattern::FromURLNoWildcard(site_url_);
124 secondary_pattern = ContentSettingsPattern::FromURLNoWildcard(site_url_);
125 break;
126 case CONTENT_SETTINGS_TYPE_NOTIFICATIONS:
127 primary_pattern = ContentSettingsPattern::FromURLNoWildcard(site_url_);
128 secondary_pattern = ContentSettingsPattern::Wildcard();
129 break;
[email protected]b1d113d2012-06-27 21:27:34130 case CONTENT_SETTINGS_TYPE_IMAGES:
131 case CONTENT_SETTINGS_TYPE_JAVASCRIPT:
[email protected]df818272012-04-20 13:10:50132 case CONTENT_SETTINGS_TYPE_PLUGINS:
133 case CONTENT_SETTINGS_TYPE_POPUPS:
[email protected]b1d113d2012-06-27 21:27:34134 case CONTENT_SETTINGS_TYPE_FULLSCREEN:
135 case CONTENT_SETTINGS_TYPE_MOUSELOCK:
136 case CONTENT_SETTINGS_TYPE_MEDIASTREAM:
[email protected]df818272012-04-20 13:10:50137 primary_pattern = ContentSettingsPattern::FromURL(site_url_);
138 secondary_pattern = ContentSettingsPattern::Wildcard();
139 break;
140 default:
141 NOTREACHED() << "ContentSettingsType " << type << "is not supported.";
142 break;
[email protected]0b9fdd72012-04-04 10:00:33143 }
144
[email protected]df818272012-04-20 13:10:50145 // Permission settings are specified via rules. There exists always at least
146 // one rule for the default setting. Get the rule that currently defines
147 // the permission for the given permission |type|. Then test whether the
148 // existing rule is more specific than the rule we are about to create. If
149 // the existing rule is more specific, than change the existing rule instead
150 // of creating a new rule that would be hidden behind the existing rule.
151 content_settings::SettingInfo info;
152 scoped_ptr<Value> v(content_settings_->GetWebsiteSetting(
153 site_url_, site_url_, type, "", &info));
154 DCHECK(info.source == content_settings::SETTING_SOURCE_USER);
155 ContentSettingsPattern::Relation r1 =
156 info.primary_pattern.Compare(primary_pattern);
157 DCHECK(r1 != ContentSettingsPattern::DISJOINT_ORDER_POST &&
158 r1 != ContentSettingsPattern::DISJOINT_ORDER_PRE);
159 if (r1 == ContentSettingsPattern::PREDECESSOR) {
160 primary_pattern = info.primary_pattern;
161 } else if (r1 == ContentSettingsPattern::IDENTITY) {
162 ContentSettingsPattern::Relation r2 =
163 info.secondary_pattern.Compare(secondary_pattern);
164 DCHECK(r2 != ContentSettingsPattern::DISJOINT_ORDER_POST &&
165 r2 != ContentSettingsPattern::DISJOINT_ORDER_PRE);
166 if (r2 == ContentSettingsPattern::PREDECESSOR)
167 secondary_pattern = info.secondary_pattern;
168 }
169
170 Value* value = NULL;
171 if (setting != CONTENT_SETTING_DEFAULT)
172 value = Value::CreateIntegerValue(setting);
173 content_settings_->SetWebsiteSetting(
174 primary_pattern, secondary_pattern, type, "", value);
[email protected]66f157312012-08-01 13:50:26175 show_info_bar_ = true;
[email protected]2f45d542012-08-22 08:47:24176
[email protected]76955932012-12-06 11:01:10177// TODO(markusheintz): This is a temporary hack to fix issue:
178// http://crbug.com/144203.
[email protected]e379ba42012-08-22 22:40:25179#if defined(OS_MACOSX)
[email protected]2f45d542012-08-22 08:47:24180 // Refresh the UI to reflect the new setting.
181 PresentSitePermissions();
[email protected]e379ba42012-08-22 22:40:25182#endif
[email protected]df818272012-04-20 13:10:50183}
184
[email protected]15b092542012-05-16 13:08:14185void WebsiteSettings::OnGotVisitCountToHost(HistoryService::Handle handle,
186 bool found_visits,
187 int visit_count,
188 base::Time first_visit) {
189 if (!found_visits) {
190 // This indicates an error, such as the page's URL scheme wasn't
191 // http/https.
192 first_visit = base::Time();
193 } else if (visit_count == 0) {
194 first_visit = base::Time::Now();
195 }
196 PresentHistoryInfo(first_visit);
197}
198
[email protected]df818272012-04-20 13:10:50199void WebsiteSettings::OnSiteDataAccessed() {
200 PresentSiteData();
[email protected]0b9fdd72012-04-04 10:00:33201}
202
[email protected]66f157312012-08-01 13:50:26203void WebsiteSettings::OnUIClosing() {
204 if (show_info_bar_) {
205 infobar_helper_->AddInfoBar(
206 new WebsiteSettingsInfobarDelegate(infobar_helper_));
207 }
208}
209
[email protected]0b9fdd72012-04-04 10:00:33210void WebsiteSettings::Init(Profile* profile,
211 const GURL& url,
212 const content::SSLStatus& ssl) {
[email protected]03ef4b2a2012-03-06 15:04:20213 if (url.SchemeIs(chrome::kChromeUIScheme)) {
214 site_identity_status_ = SITE_IDENTITY_STATUS_INTERNAL_PAGE;
215 site_identity_details_ =
216 l10n_util::GetStringUTF16(IDS_PAGE_INFO_INTERNAL_PAGE);
217 site_connection_status_ = SITE_CONNECTION_STATUS_INTERNAL_PAGE;
218 return;
219 }
220
221 scoped_refptr<net::X509Certificate> cert;
222
223 // Identity section.
224 string16 subject_name(UTF8ToUTF16(url.host()));
[email protected]03ef4b2a2012-03-06 15:04:20225 if (subject_name.empty()) {
226 subject_name.assign(
227 l10n_util::GetStringUTF16(IDS_PAGE_INFO_SECURITY_TAB_UNKNOWN_PARTY));
[email protected]03ef4b2a2012-03-06 15:04:20228 }
229
[email protected]f61c1ce2012-05-09 13:55:11230 cert_id_ = ssl.cert_id;
231
[email protected]03ef4b2a2012-03-06 15:04:20232 if (ssl.cert_id &&
233 cert_store_->RetrieveCert(ssl.cert_id, &cert) &&
234 (!net::IsCertStatusError(ssl.cert_status) ||
235 net::IsCertStatusMinorError(ssl.cert_status))) {
236 // There are no major errors. Check for minor errors.
237 if (net::IsCertStatusMinorError(ssl.cert_status)) {
238 site_identity_status_ = SITE_IDENTITY_STATUS_CERT_REVOCATION_UNKNOWN;
239 string16 issuer_name(UTF8ToUTF16(cert->issuer().GetDisplayName()));
240 if (issuer_name.empty()) {
241 issuer_name.assign(l10n_util::GetStringUTF16(
242 IDS_PAGE_INFO_SECURITY_TAB_UNKNOWN_PARTY));
243 }
244 site_identity_details_.assign(l10n_util::GetStringFUTF16(
245 IDS_PAGE_INFO_SECURITY_TAB_SECURE_IDENTITY, issuer_name));
246
247 site_identity_details_ += ASCIIToUTF16("\n\n");
248 if (ssl.cert_status & net::CERT_STATUS_UNABLE_TO_CHECK_REVOCATION) {
249 site_identity_details_ += l10n_util::GetStringUTF16(
250 IDS_PAGE_INFO_SECURITY_TAB_UNABLE_TO_CHECK_REVOCATION);
251 } else if (ssl.cert_status & net::CERT_STATUS_NO_REVOCATION_MECHANISM) {
252 site_identity_details_ += l10n_util::GetStringUTF16(
253 IDS_PAGE_INFO_SECURITY_TAB_NO_REVOCATION_MECHANISM);
254 } else {
255 NOTREACHED() << "Need to specify string for this warning";
256 }
257 } else if (ssl.cert_status & net::CERT_STATUS_IS_EV) {
258 // EV HTTPS page.
259 site_identity_status_ = SITE_IDENTITY_STATUS_EV_CERT;
260 DCHECK(!cert->subject().organization_names.empty());
261 organization_name_ = UTF8ToUTF16(cert->subject().organization_names[0]);
262 // An EV Cert is required to have a city (localityName) and country but
263 // state is "if any".
264 DCHECK(!cert->subject().locality_name.empty());
265 DCHECK(!cert->subject().country_name.empty());
266 string16 locality;
267 if (!cert->subject().state_or_province_name.empty()) {
268 locality = l10n_util::GetStringFUTF16(
269 IDS_PAGEINFO_ADDRESS,
270 UTF8ToUTF16(cert->subject().locality_name),
271 UTF8ToUTF16(cert->subject().state_or_province_name),
272 UTF8ToUTF16(cert->subject().country_name));
273 } else {
274 locality = l10n_util::GetStringFUTF16(
275 IDS_PAGEINFO_PARTIAL_ADDRESS,
276 UTF8ToUTF16(cert->subject().locality_name),
277 UTF8ToUTF16(cert->subject().country_name));
278 }
279 DCHECK(!cert->subject().organization_names.empty());
280 site_identity_details_.assign(l10n_util::GetStringFUTF16(
281 IDS_PAGE_INFO_SECURITY_TAB_SECURE_IDENTITY_EV,
282 UTF8ToUTF16(cert->subject().organization_names[0]),
283 locality,
284 UTF8ToUTF16(cert->issuer().GetDisplayName())));
[email protected]03ef4b2a2012-03-06 15:04:20285 } else {
286 // Non-EV OK HTTPS page.
287 site_identity_status_ = SITE_IDENTITY_STATUS_CERT;
288 string16 issuer_name(UTF8ToUTF16(cert->issuer().GetDisplayName()));
289 if (issuer_name.empty()) {
290 issuer_name.assign(l10n_util::GetStringUTF16(
291 IDS_PAGE_INFO_SECURITY_TAB_UNKNOWN_PARTY));
292 }
293 site_identity_details_.assign(l10n_util::GetStringFUTF16(
294 IDS_PAGE_INFO_SECURITY_TAB_SECURE_IDENTITY, issuer_name));
295 }
296 } else {
297 // HTTP or HTTPS with errors (not warnings).
298 site_identity_details_.assign(l10n_util::GetStringUTF16(
299 IDS_PAGE_INFO_SECURITY_TAB_INSECURE_IDENTITY));
300 if (ssl.security_style == content::SECURITY_STYLE_UNAUTHENTICATED)
301 site_identity_status_ = SITE_IDENTITY_STATUS_NO_CERT;
302 else
303 site_identity_status_ = SITE_IDENTITY_STATUS_ERROR;
304
305 const string16 bullet = UTF8ToUTF16("\n • ");
306 std::vector<SSLErrorInfo> errors;
307 SSLErrorInfo::GetErrorsForCertStatus(ssl.cert_id, ssl.cert_status,
308 url, &errors);
309 for (size_t i = 0; i < errors.size(); ++i) {
310 site_identity_details_ += bullet;
311 site_identity_details_ += errors[i].short_description();
312 }
313
314 if (ssl.cert_status & net::CERT_STATUS_NON_UNIQUE_NAME) {
315 site_identity_details_ += ASCIIToUTF16("\n\n");
316 site_identity_details_ += l10n_util::GetStringUTF16(
317 IDS_PAGE_INFO_SECURITY_TAB_NON_UNIQUE_NAME);
318 }
319 }
320
321 // Site Connection
322 // We consider anything less than 80 bits encryption to be weak encryption.
323 // TODO(wtc): Bug 1198735: report mixed/unsafe content for unencrypted and
324 // weakly encrypted connections.
325 site_connection_status_ = SITE_CONNECTION_STATUS_UNKNOWN;
326
327 if (!ssl.cert_id) {
328 // Not HTTPS.
329 DCHECK_EQ(ssl.security_style, content::SECURITY_STYLE_UNAUTHENTICATED);
330 if (ssl.security_style == content::SECURITY_STYLE_UNAUTHENTICATED)
331 site_connection_status_ = SITE_CONNECTION_STATUS_UNENCRYPTED;
332 else
333 site_connection_status_ = SITE_CONNECTION_STATUS_ENCRYPTED_ERROR;
334
335 site_connection_details_.assign(l10n_util::GetStringFUTF16(
336 IDS_PAGE_INFO_SECURITY_TAB_NOT_ENCRYPTED_CONNECTION_TEXT,
337 subject_name));
338 } else if (ssl.security_bits < 0) {
339 // Security strength is unknown. Say nothing.
340 site_connection_status_ = SITE_CONNECTION_STATUS_ENCRYPTED_ERROR;
341 } else if (ssl.security_bits == 0) {
342 DCHECK_NE(ssl.security_style, content::SECURITY_STYLE_UNAUTHENTICATED);
343 site_connection_status_ = SITE_CONNECTION_STATUS_ENCRYPTED_ERROR;
344 site_connection_details_.assign(l10n_util::GetStringFUTF16(
345 IDS_PAGE_INFO_SECURITY_TAB_NOT_ENCRYPTED_CONNECTION_TEXT,
346 subject_name));
347 } else if (ssl.security_bits < 80) {
348 site_connection_status_ = SITE_CONNECTION_STATUS_ENCRYPTED_ERROR;
349 site_connection_details_.assign(l10n_util::GetStringFUTF16(
350 IDS_PAGE_INFO_SECURITY_TAB_WEAK_ENCRYPTION_CONNECTION_TEXT,
351 subject_name));
352 } else {
353 site_connection_status_ = SITE_CONNECTION_STATUS_ENCRYPTED;
354 site_connection_details_.assign(l10n_util::GetStringFUTF16(
355 IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTED_CONNECTION_TEXT,
356 subject_name,
357 base::IntToString16(ssl.security_bits)));
358 if (ssl.content_status) {
359 bool ran_insecure_content =
360 !!(ssl.content_status & content::SSLStatus::RAN_INSECURE_CONTENT);
361 site_connection_status_ = ran_insecure_content ?
362 SITE_CONNECTION_STATUS_ENCRYPTED_ERROR
363 : SITE_CONNECTION_STATUS_MIXED_CONTENT;
364 site_connection_details_.assign(l10n_util::GetStringFUTF16(
365 IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTED_SENTENCE_LINK,
366 site_connection_details_,
367 l10n_util::GetStringUTF16(ran_insecure_content ?
368 IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTED_INSECURE_CONTENT_ERROR :
369 IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTED_INSECURE_CONTENT_WARNING)));
370 }
371 }
372
373 uint16 cipher_suite =
374 net::SSLConnectionStatusToCipherSuite(ssl.connection_status);
375 if (ssl.security_bits > 0 && cipher_suite) {
376 int ssl_version =
377 net::SSLConnectionStatusToVersion(ssl.connection_status);
378 const char* ssl_version_str;
379 net::SSLVersionToString(&ssl_version_str, ssl_version);
380 site_connection_details_ += ASCIIToUTF16("\n\n");
381 site_connection_details_ += l10n_util::GetStringFUTF16(
382 IDS_PAGE_INFO_SECURITY_TAB_SSL_VERSION,
383 ASCIIToUTF16(ssl_version_str));
384
385 bool did_fallback = (ssl.connection_status &
[email protected]80c75f682012-05-26 16:22:17386 net::SSL_CONNECTION_VERSION_FALLBACK) != 0;
[email protected]03ef4b2a2012-03-06 15:04:20387 bool no_renegotiation =
388 (ssl.connection_status &
389 net::SSL_CONNECTION_NO_RENEGOTIATION_EXTENSION) != 0;
390 const char *key_exchange, *cipher, *mac;
391 net::SSLCipherSuiteToStrings(&key_exchange, &cipher, &mac, cipher_suite);
392
393 site_connection_details_ += ASCIIToUTF16("\n\n");
394 site_connection_details_ += l10n_util::GetStringFUTF16(
395 IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTION_DETAILS,
396 ASCIIToUTF16(cipher), ASCIIToUTF16(mac), ASCIIToUTF16(key_exchange));
397
398 site_connection_details_ += ASCIIToUTF16("\n\n");
399 uint8 compression_id =
400 net::SSLConnectionStatusToCompression(ssl.connection_status);
401 if (compression_id) {
402 const char* compression;
403 net::SSLCompressionToString(&compression, compression_id);
404 site_connection_details_ += l10n_util::GetStringFUTF16(
405 IDS_PAGE_INFO_SECURITY_TAB_COMPRESSION_DETAILS,
406 ASCIIToUTF16(compression));
407 } else {
408 site_connection_details_ += l10n_util::GetStringUTF16(
409 IDS_PAGE_INFO_SECURITY_TAB_NO_COMPRESSION);
410 }
411
412 if (did_fallback) {
413 // For now, only SSLv3 fallback will trigger a warning icon.
414 if (site_connection_status_ < SITE_CONNECTION_STATUS_MIXED_CONTENT)
415 site_connection_status_ = SITE_CONNECTION_STATUS_MIXED_CONTENT;
416 site_connection_details_ += ASCIIToUTF16("\n\n");
417 site_connection_details_ += l10n_util::GetStringUTF16(
418 IDS_PAGE_INFO_SECURITY_TAB_FALLBACK_MESSAGE);
419 }
420 if (no_renegotiation) {
421 site_connection_details_ += ASCIIToUTF16("\n\n");
422 site_connection_details_ += l10n_util::GetStringUTF16(
423 IDS_PAGE_INFO_SECURITY_TAB_RENEGOTIATION_MESSAGE);
424 }
425 }
[email protected]e583f752012-08-30 13:26:21426
427 // By default select the permissions tab that displays all the site
428 // permissions. In case of a connection error or an issue with the
429 // certificate presented by the website, select the connection tab to draw
430 // the user's attention to the issue. If the site does not provide a
431 // certificate because it was loaded over an unencrypted connection, don't
432 // select the connection tab.
433 WebsiteSettingsUI::TabId tab_id = WebsiteSettingsUI::TAB_ID_PERMISSIONS;
434 if (site_connection_status_ == SITE_CONNECTION_STATUS_ENCRYPTED_ERROR ||
435 site_connection_status_ == SITE_CONNECTION_STATUS_MIXED_CONTENT ||
436 site_identity_status_ == SITE_IDENTITY_STATUS_ERROR ||
437 site_identity_status_ == SITE_IDENTITY_STATUS_CERT_REVOCATION_UNKNOWN)
438 tab_id = WebsiteSettingsUI::TAB_ID_CONNECTION;
439 ui_->SetSelectedTab(tab_id);
[email protected]03ef4b2a2012-03-06 15:04:20440}
[email protected]0b9fdd72012-04-04 10:00:33441
[email protected]df818272012-04-20 13:10:50442void WebsiteSettings::PresentSitePermissions() {
443 PermissionInfoList permission_info_list;
444
445 WebsiteSettingsUI::PermissionInfo permission_info;
446 for (size_t i = 0; i < arraysize(kPermissionType); ++i) {
447 permission_info.type = kPermissionType[i];
448
449 content_settings::SettingInfo info;
450 scoped_ptr<Value> value(content_settings_->GetWebsiteSetting(
451 site_url_, site_url_, permission_info.type, "", &info));
452 DCHECK(value.get());
[email protected]fe4686a2012-10-19 15:38:26453 // The values for default settings of the CONTENT_SETTINGS_TYPE_MEDIASTREAM
454 // are of type integer, while the values for exceptions are of type
455 // dictionary. Content settings exceptions of type
456 // CONTENT_SETTINGS_TYPE_MEDIASTREAM can only be set in order to allow the
457 // use of a specific camera and/or microphone for a certain website. This
458 // means if the value is of type dictionary then the url has the permission
459 // to use a specific camera and/or microphone.
460 if (value->GetType() == Value::TYPE_INTEGER) {
461 permission_info.setting =
462 content_settings::ValueToContentSetting(value.get());
463 } else if (value->GetType() == Value::TYPE_DICTIONARY &&
464 permission_info.type == CONTENT_SETTINGS_TYPE_MEDIASTREAM) {
465 permission_info.setting = CONTENT_SETTING_ALLOW;
466 } else {
467 NOTREACHED();
468 }
469
[email protected]8bdf45c32012-08-04 00:12:55470 permission_info.source = info.source;
[email protected]df818272012-04-20 13:10:50471
[email protected]b1d113d2012-06-27 21:27:34472 if (info.primary_pattern == ContentSettingsPattern::Wildcard() &&
473 info.secondary_pattern == ContentSettingsPattern::Wildcard()) {
474 permission_info.default_setting = permission_info.setting;
475 permission_info.setting = CONTENT_SETTING_DEFAULT;
476 } else {
477 permission_info.default_setting =
478 content_settings_->GetDefaultContentSetting(permission_info.type,
479 NULL);
[email protected]df818272012-04-20 13:10:50480 }
[email protected]b1d113d2012-06-27 21:27:34481 permission_info_list.push_back(permission_info);
[email protected]df818272012-04-20 13:10:50482 }
483
484 ui_->SetPermissionInfo(permission_info_list);
[email protected]0b9fdd72012-04-04 10:00:33485}
486
[email protected]df818272012-04-20 13:10:50487void WebsiteSettings::PresentSiteData() {
488 CookieInfoList cookie_info_list;
[email protected]e0ac35892012-05-15 12:53:34489 const LocalSharedObjectsContainer& allowed_objects =
490 tab_specific_content_settings()->allowed_local_shared_objects();
491 const LocalSharedObjectsContainer& blocked_objects =
492 tab_specific_content_settings()->blocked_local_shared_objects();
493
494 // Add first party cookie and site data counts.
[email protected]df818272012-04-20 13:10:50495 WebsiteSettingsUI::CookieInfo cookie_info;
[email protected]e0ac35892012-05-15 12:53:34496 std::string cookie_source =
497 net::RegistryControlledDomainService::GetDomainAndRegistry(site_url_);
498 if (cookie_source.empty())
499 cookie_source = site_url_.host();
500 cookie_info.cookie_source = cookie_source;
501 cookie_info.allowed = allowed_objects.GetObjectCountForDomain(site_url_);
502 cookie_info.blocked = blocked_objects.GetObjectCountForDomain(site_url_);
503 cookie_info_list.push_back(cookie_info);
504
505 // Add third party cookie counts.
506 cookie_info.cookie_source = l10n_util::GetStringUTF8(
507 IDS_WEBSITE_SETTINGS_THIRD_PARTY_SITE_DATA);
508 cookie_info.allowed = allowed_objects.GetObjectCount() - cookie_info.allowed;
509 cookie_info.blocked = blocked_objects.GetObjectCount() - cookie_info.blocked;
[email protected]df818272012-04-20 13:10:50510 cookie_info_list.push_back(cookie_info);
[email protected]0b9fdd72012-04-04 10:00:33511
[email protected]df818272012-04-20 13:10:50512 ui_->SetCookieInfo(cookie_info_list);
[email protected]0b9fdd72012-04-04 10:00:33513}
[email protected]16de6de2012-04-04 12:24:14514
[email protected]24c8818c2012-04-25 09:57:41515void WebsiteSettings::PresentSiteIdentity() {
516 // After initialization the status about the site's connection
517 // and it's identity must be available.
518 DCHECK_NE(site_identity_status_, SITE_IDENTITY_STATUS_UNKNOWN);
519 DCHECK_NE(site_connection_status_, SITE_CONNECTION_STATUS_UNKNOWN);
520 WebsiteSettingsUI::IdentityInfo info;
521 if (site_identity_status_ == SITE_IDENTITY_STATUS_EV_CERT)
522 info.site_identity = UTF16ToUTF8(organization_name());
523 else
524 info.site_identity = site_url_.host();
525
526 info.connection_status = site_connection_status_;
527 info.connection_status_description =
528 UTF16ToUTF8(site_connection_details_);
529 info.identity_status = site_identity_status_;
530 info.identity_status_description =
531 UTF16ToUTF8(site_identity_details_);
[email protected]f61c1ce2012-05-09 13:55:11532 info.cert_id = cert_id_;
[email protected]24c8818c2012-04-25 09:57:41533 ui_->SetIdentityInfo(info);
534}
535
[email protected]15b092542012-05-16 13:08:14536void WebsiteSettings::PresentHistoryInfo(base::Time first_visit) {
537 if (first_visit == base::Time()) {
538 ui_->SetFirstVisit(string16());
539 return;
540 }
541
542 bool visited_before_today = false;
543 base::Time today = base::Time::Now().LocalMidnight();
544 base::Time first_visit_midnight = first_visit.LocalMidnight();
545 visited_before_today = (first_visit_midnight < today);
546
547 string16 first_visit_text;
548 if (visited_before_today) {
549 first_visit_text = l10n_util::GetStringFUTF16(
550 IDS_PAGE_INFO_SECURITY_TAB_VISITED_BEFORE_TODAY,
551 base::TimeFormatShortDate(first_visit));
552 } else {
553 first_visit_text = l10n_util::GetStringUTF16(
554 IDS_PAGE_INFO_SECURITY_TAB_FIRST_VISITED_TODAY);
555
556 }
557 ui_->SetFirstVisit(first_visit_text);
558}