blob: 11222f19897ee2dbd22f7797ab4e1bb49463c2f0 [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]774cc3c2013-06-07 20:26:4515#include "base/strings/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]d81bb3e2013-05-02 18:17:0327#include "chrome/browser/policy/profile_policy_connector.h"
28#include "chrome/browser/policy/profile_policy_connector_factory.h"
[email protected]03ef4b2a2012-03-06 15:04:2029#include "chrome/browser/profiles/profile.h"
[email protected]03ef4b2a2012-03-06 15:04:2030#include "chrome/browser/ssl/ssl_error_info.h"
[email protected]66f157312012-08-01 13:50:2631#include "chrome/browser/ui/website_settings/website_settings_infobar_delegate.h"
[email protected]4237dd52012-06-05 00:00:3232#include "chrome/browser/ui/website_settings/website_settings_ui.h"
[email protected]0b9fdd72012-04-04 10:00:3333#include "chrome/common/content_settings_pattern.h"
34#include "content/public/browser/browser_thread.h"
[email protected]b59c6cf02012-03-12 20:51:4235#include "content/public/browser/cert_store.h"
[email protected]e22d64f2012-09-10 09:03:2336#include "content/public/browser/user_metrics.h"
[email protected]03ef4b2a2012-03-06 15:04:2037#include "content/public/common/ssl_status.h"
38#include "content/public/common/url_constants.h"
39#include "grit/chromium_strings.h"
40#include "grit/generated_resources.h"
[email protected]be28b5f42012-07-20 11:31:2541#include "net/base/registry_controlled_domains/registry_controlled_domain.h"
[email protected]6e7845ae2013-03-29 21:48:1142#include "net/cert/cert_status_flags.h"
43#include "net/cert/x509_certificate.h"
[email protected]536fd0b2013-03-14 17:41:5744#include "net/ssl/ssl_cipher_suite_names.h"
45#include "net/ssl/ssl_connection_status_flags.h"
[email protected]03ef4b2a2012-03-06 15:04:2046#include "ui/base/l10n/l10n_util.h"
47#include "ui/base/resource/resource_bundle.h"
48
[email protected]0b9fdd72012-04-04 10:00:3349using content::BrowserThread;
50
51namespace {
52
[email protected]b1d113d2012-06-27 21:27:3453// The list of content settings types to display on the Website Settings UI.
[email protected]0b9fdd72012-04-04 10:00:3354ContentSettingsType kPermissionType[] = {
[email protected]b1d113d2012-06-27 21:27:3455 CONTENT_SETTINGS_TYPE_IMAGES,
56 CONTENT_SETTINGS_TYPE_JAVASCRIPT,
[email protected]0b9fdd72012-04-04 10:00:3357 CONTENT_SETTINGS_TYPE_PLUGINS,
[email protected]b1d113d2012-06-27 21:27:3458 CONTENT_SETTINGS_TYPE_POPUPS,
[email protected]0b9fdd72012-04-04 10:00:3359 CONTENT_SETTINGS_TYPE_GEOLOCATION,
[email protected]b1d113d2012-06-27 21:27:3460 CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
61 CONTENT_SETTINGS_TYPE_FULLSCREEN,
62 CONTENT_SETTINGS_TYPE_MOUSELOCK,
63 CONTENT_SETTINGS_TYPE_MEDIASTREAM,
[email protected]62167c12013-07-10 23:02:0864 CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS,
[email protected]0b9fdd72012-04-04 10:00:3365};
66
67} // namespace
68
69WebsiteSettings::WebsiteSettings(
70 WebsiteSettingsUI* ui,
71 Profile* profile,
[email protected]df818272012-04-20 13:10:5072 TabSpecificContentSettings* tab_specific_content_settings,
[email protected]4f822f022012-12-20 19:11:4273 InfoBarService* infobar_service,
[email protected]0b9fdd72012-04-04 10:00:3374 const GURL& url,
75 const content::SSLStatus& ssl,
76 content::CertStore* cert_store)
[email protected]df818272012-04-20 13:10:5077 : TabSpecificContentSettings::SiteDataObserver(
78 tab_specific_content_settings),
79 ui_(ui),
[email protected]4f822f022012-12-20 19:11:4280 infobar_service_(infobar_service),
[email protected]66f157312012-08-01 13:50:2681 show_info_bar_(false),
[email protected]0b9fdd72012-04-04 10:00:3382 site_url_(url),
83 site_identity_status_(SITE_IDENTITY_STATUS_UNKNOWN),
[email protected]f61c1ce2012-05-09 13:55:1184 cert_id_(0),
[email protected]03ef4b2a2012-03-06 15:04:2085 site_connection_status_(SITE_CONNECTION_STATUS_UNKNOWN),
[email protected]0b9fdd72012-04-04 10:00:3386 cert_store_(cert_store),
87 content_settings_(profile->GetHostContentSettingsMap()) {
[email protected]03ef4b2a2012-03-06 15:04:2088 Init(profile, url, ssl);
[email protected]0b9fdd72012-04-04 10:00:3389
[email protected]78a1fd90a2012-07-19 08:11:2590 HistoryService* history_service = HistoryServiceFactory::GetForProfile(
91 profile, Profile::EXPLICIT_ACCESS);
[email protected]15b092542012-05-16 13:08:1492 if (history_service) {
93 history_service->GetVisibleVisitCountToHost(
94 site_url_,
95 &visit_count_request_consumer_,
96 base::Bind(&WebsiteSettings::OnGotVisitCountToHost,
97 base::Unretained(this)));
98 }
99
[email protected]0b9fdd72012-04-04 10:00:33100 PresentSitePermissions();
[email protected]df818272012-04-20 13:10:50101 PresentSiteData();
[email protected]24c8818c2012-04-25 09:57:41102 PresentSiteIdentity();
[email protected]15b092542012-05-16 13:08:14103 PresentHistoryInfo(base::Time());
[email protected]e22d64f2012-09-10 09:03:23104
105 // Every time the Website Settings UI is opened a |WebsiteSettings| object is
106 // created. So this counts how ofter the Website Settings UI is opened.
107 content::RecordAction(content::UserMetricsAction("WebsiteSettings_Opened"));
[email protected]03ef4b2a2012-03-06 15:04:20108}
109
[email protected]0b9fdd72012-04-04 10:00:33110WebsiteSettings::~WebsiteSettings() {
[email protected]03ef4b2a2012-03-06 15:04:20111}
112
[email protected]df818272012-04-20 13:10:50113void WebsiteSettings::OnSitePermissionChanged(ContentSettingsType type,
114 ContentSetting setting) {
[email protected]e22d64f2012-09-10 09:03:23115 // Count how often a permission for a specific content type is changed using
116 // the Website Settings UI.
117 UMA_HISTOGRAM_COUNTS("WebsiteSettings.PermissionChanged", type);
118
[email protected]df818272012-04-20 13:10:50119 ContentSettingsPattern primary_pattern;
120 ContentSettingsPattern secondary_pattern;
121 switch (type) {
122 case CONTENT_SETTINGS_TYPE_GEOLOCATION:
123 // TODO(markusheintz): The rule we create here should also change the
124 // location permission for iframed content.
125 primary_pattern = ContentSettingsPattern::FromURLNoWildcard(site_url_);
126 secondary_pattern = ContentSettingsPattern::FromURLNoWildcard(site_url_);
127 break;
128 case CONTENT_SETTINGS_TYPE_NOTIFICATIONS:
129 primary_pattern = ContentSettingsPattern::FromURLNoWildcard(site_url_);
130 secondary_pattern = ContentSettingsPattern::Wildcard();
131 break;
[email protected]b1d113d2012-06-27 21:27:34132 case CONTENT_SETTINGS_TYPE_IMAGES:
133 case CONTENT_SETTINGS_TYPE_JAVASCRIPT:
[email protected]df818272012-04-20 13:10:50134 case CONTENT_SETTINGS_TYPE_PLUGINS:
135 case CONTENT_SETTINGS_TYPE_POPUPS:
[email protected]b1d113d2012-06-27 21:27:34136 case CONTENT_SETTINGS_TYPE_FULLSCREEN:
137 case CONTENT_SETTINGS_TYPE_MOUSELOCK:
[email protected]df818272012-04-20 13:10:50138 primary_pattern = ContentSettingsPattern::FromURL(site_url_);
139 secondary_pattern = ContentSettingsPattern::Wildcard();
140 break;
[email protected]0bacc1912012-12-11 11:05:34141 case CONTENT_SETTINGS_TYPE_MEDIASTREAM: {
142 // We need to use the same same patterns as other places like infobar code
143 // to override the existing rule instead of creating the new one.
144 primary_pattern = ContentSettingsPattern::FromURLNoWildcard(site_url_);
145 secondary_pattern = ContentSettingsPattern::Wildcard();
146 // Set permission for both microphone and camera.
147 content_settings_->SetContentSetting(
[email protected]007b3f82013-04-09 08:46:45148 primary_pattern,
149 secondary_pattern,
150 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC,
151 std::string(),
152 setting);
[email protected]0bacc1912012-12-11 11:05:34153
154 content_settings_->SetContentSetting(
[email protected]007b3f82013-04-09 08:46:45155 primary_pattern,
156 secondary_pattern,
157 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA,
158 std::string(),
159 setting);
[email protected]0bacc1912012-12-11 11:05:34160 break;
161 }
[email protected]df818272012-04-20 13:10:50162 default:
163 NOTREACHED() << "ContentSettingsType " << type << "is not supported.";
164 break;
[email protected]0b9fdd72012-04-04 10:00:33165 }
166
[email protected]0bacc1912012-12-11 11:05:34167 if (type != CONTENT_SETTINGS_TYPE_MEDIASTREAM) {
168 // Permission settings are specified via rules. There exists always at least
169 // one rule for the default setting. Get the rule that currently defines
170 // the permission for the given permission |type|. Then test whether the
171 // existing rule is more specific than the rule we are about to create. If
172 // the existing rule is more specific, than change the existing rule instead
173 // of creating a new rule that would be hidden behind the existing rule.
174 // This is not a concern for CONTENT_SETTINGS_TYPE_MEDIASTREAM since users
175 // can not create media settings exceptions by hand.
176 content_settings::SettingInfo info;
177 scoped_ptr<Value> v(content_settings_->GetWebsiteSetting(
[email protected]007b3f82013-04-09 08:46:45178 site_url_, site_url_, type, std::string(), &info));
[email protected]0bacc1912012-12-11 11:05:34179 DCHECK(info.source == content_settings::SETTING_SOURCE_USER);
180 ContentSettingsPattern::Relation r1 =
181 info.primary_pattern.Compare(primary_pattern);
182 DCHECK(r1 != ContentSettingsPattern::DISJOINT_ORDER_POST &&
183 r1 != ContentSettingsPattern::DISJOINT_ORDER_PRE);
184 if (r1 == ContentSettingsPattern::PREDECESSOR) {
185 primary_pattern = info.primary_pattern;
186 } else if (r1 == ContentSettingsPattern::IDENTITY) {
187 ContentSettingsPattern::Relation r2 =
188 info.secondary_pattern.Compare(secondary_pattern);
189 DCHECK(r2 != ContentSettingsPattern::DISJOINT_ORDER_POST &&
190 r2 != ContentSettingsPattern::DISJOINT_ORDER_PRE);
191 if (r2 == ContentSettingsPattern::PREDECESSOR)
192 secondary_pattern = info.secondary_pattern;
193 }
194
195 Value* value = NULL;
196 if (setting != CONTENT_SETTING_DEFAULT)
197 value = Value::CreateIntegerValue(setting);
198 content_settings_->SetWebsiteSetting(
[email protected]007b3f82013-04-09 08:46:45199 primary_pattern, secondary_pattern, type, std::string(), value);
[email protected]df818272012-04-20 13:10:50200 }
201
[email protected]66f157312012-08-01 13:50:26202 show_info_bar_ = true;
[email protected]2f45d542012-08-22 08:47:24203
[email protected]76955932012-12-06 11:01:10204// TODO(markusheintz): This is a temporary hack to fix issue:
205// http://crbug.com/144203.
[email protected]e379ba42012-08-22 22:40:25206#if defined(OS_MACOSX)
[email protected]2f45d542012-08-22 08:47:24207 // Refresh the UI to reflect the new setting.
208 PresentSitePermissions();
[email protected]e379ba42012-08-22 22:40:25209#endif
[email protected]df818272012-04-20 13:10:50210}
211
[email protected]15b092542012-05-16 13:08:14212void WebsiteSettings::OnGotVisitCountToHost(HistoryService::Handle handle,
213 bool found_visits,
214 int visit_count,
215 base::Time first_visit) {
216 if (!found_visits) {
217 // This indicates an error, such as the page's URL scheme wasn't
218 // http/https.
219 first_visit = base::Time();
220 } else if (visit_count == 0) {
221 first_visit = base::Time::Now();
222 }
223 PresentHistoryInfo(first_visit);
224}
225
[email protected]df818272012-04-20 13:10:50226void WebsiteSettings::OnSiteDataAccessed() {
227 PresentSiteData();
[email protected]0b9fdd72012-04-04 10:00:33228}
229
[email protected]66f157312012-08-01 13:50:26230void WebsiteSettings::OnUIClosing() {
[email protected]0be09932013-01-08 02:03:50231 if (show_info_bar_)
[email protected]ed9bc652013-07-11 17:17:36232 WebsiteSettingsInfoBarDelegate::Create(infobar_service_);
[email protected]66f157312012-08-01 13:50:26233}
234
[email protected]0b9fdd72012-04-04 10:00:33235void WebsiteSettings::Init(Profile* profile,
236 const GURL& url,
237 const content::SSLStatus& ssl) {
[email protected]03ef4b2a2012-03-06 15:04:20238 if (url.SchemeIs(chrome::kChromeUIScheme)) {
239 site_identity_status_ = SITE_IDENTITY_STATUS_INTERNAL_PAGE;
240 site_identity_details_ =
241 l10n_util::GetStringUTF16(IDS_PAGE_INFO_INTERNAL_PAGE);
242 site_connection_status_ = SITE_CONNECTION_STATUS_INTERNAL_PAGE;
243 return;
244 }
245
246 scoped_refptr<net::X509Certificate> cert;
247
248 // Identity section.
249 string16 subject_name(UTF8ToUTF16(url.host()));
[email protected]03ef4b2a2012-03-06 15:04:20250 if (subject_name.empty()) {
251 subject_name.assign(
252 l10n_util::GetStringUTF16(IDS_PAGE_INFO_SECURITY_TAB_UNKNOWN_PARTY));
[email protected]03ef4b2a2012-03-06 15:04:20253 }
254
[email protected]f61c1ce2012-05-09 13:55:11255 cert_id_ = ssl.cert_id;
256
[email protected]03ef4b2a2012-03-06 15:04:20257 if (ssl.cert_id &&
258 cert_store_->RetrieveCert(ssl.cert_id, &cert) &&
259 (!net::IsCertStatusError(ssl.cert_status) ||
260 net::IsCertStatusMinorError(ssl.cert_status))) {
261 // There are no major errors. Check for minor errors.
[email protected]d81bb3e2013-05-02 18:17:03262 if (policy::ProfilePolicyConnectorFactory::GetForProfile(profile)->
263 UsedPolicyCertificates()) {
[email protected]eaf3f322013-04-25 21:53:59264 site_identity_status_ = SITE_IDENTITY_STATUS_ADMIN_PROVIDED_CERT;
265 site_identity_details_ =
266 l10n_util::GetStringFUTF16(IDS_CERT_POLICY_PROVIDED_CERT_MESSAGE,
267 UTF8ToUTF16(url.host()));
268 } else if (net::IsCertStatusMinorError(ssl.cert_status)) {
[email protected]03ef4b2a2012-03-06 15:04:20269 site_identity_status_ = SITE_IDENTITY_STATUS_CERT_REVOCATION_UNKNOWN;
270 string16 issuer_name(UTF8ToUTF16(cert->issuer().GetDisplayName()));
271 if (issuer_name.empty()) {
272 issuer_name.assign(l10n_util::GetStringUTF16(
273 IDS_PAGE_INFO_SECURITY_TAB_UNKNOWN_PARTY));
274 }
275 site_identity_details_.assign(l10n_util::GetStringFUTF16(
276 IDS_PAGE_INFO_SECURITY_TAB_SECURE_IDENTITY, issuer_name));
277
278 site_identity_details_ += ASCIIToUTF16("\n\n");
279 if (ssl.cert_status & net::CERT_STATUS_UNABLE_TO_CHECK_REVOCATION) {
280 site_identity_details_ += l10n_util::GetStringUTF16(
281 IDS_PAGE_INFO_SECURITY_TAB_UNABLE_TO_CHECK_REVOCATION);
282 } else if (ssl.cert_status & net::CERT_STATUS_NO_REVOCATION_MECHANISM) {
283 site_identity_details_ += l10n_util::GetStringUTF16(
284 IDS_PAGE_INFO_SECURITY_TAB_NO_REVOCATION_MECHANISM);
285 } else {
286 NOTREACHED() << "Need to specify string for this warning";
287 }
288 } else if (ssl.cert_status & net::CERT_STATUS_IS_EV) {
289 // EV HTTPS page.
290 site_identity_status_ = SITE_IDENTITY_STATUS_EV_CERT;
291 DCHECK(!cert->subject().organization_names.empty());
292 organization_name_ = UTF8ToUTF16(cert->subject().organization_names[0]);
293 // An EV Cert is required to have a city (localityName) and country but
294 // state is "if any".
295 DCHECK(!cert->subject().locality_name.empty());
296 DCHECK(!cert->subject().country_name.empty());
297 string16 locality;
298 if (!cert->subject().state_or_province_name.empty()) {
299 locality = l10n_util::GetStringFUTF16(
300 IDS_PAGEINFO_ADDRESS,
301 UTF8ToUTF16(cert->subject().locality_name),
302 UTF8ToUTF16(cert->subject().state_or_province_name),
303 UTF8ToUTF16(cert->subject().country_name));
304 } else {
305 locality = l10n_util::GetStringFUTF16(
306 IDS_PAGEINFO_PARTIAL_ADDRESS,
307 UTF8ToUTF16(cert->subject().locality_name),
308 UTF8ToUTF16(cert->subject().country_name));
309 }
310 DCHECK(!cert->subject().organization_names.empty());
311 site_identity_details_.assign(l10n_util::GetStringFUTF16(
312 IDS_PAGE_INFO_SECURITY_TAB_SECURE_IDENTITY_EV,
313 UTF8ToUTF16(cert->subject().organization_names[0]),
314 locality,
315 UTF8ToUTF16(cert->issuer().GetDisplayName())));
[email protected]03ef4b2a2012-03-06 15:04:20316 } else {
317 // Non-EV OK HTTPS page.
318 site_identity_status_ = SITE_IDENTITY_STATUS_CERT;
319 string16 issuer_name(UTF8ToUTF16(cert->issuer().GetDisplayName()));
320 if (issuer_name.empty()) {
321 issuer_name.assign(l10n_util::GetStringUTF16(
322 IDS_PAGE_INFO_SECURITY_TAB_UNKNOWN_PARTY));
323 }
324 site_identity_details_.assign(l10n_util::GetStringFUTF16(
325 IDS_PAGE_INFO_SECURITY_TAB_SECURE_IDENTITY, issuer_name));
326 }
327 } else {
328 // HTTP or HTTPS with errors (not warnings).
329 site_identity_details_.assign(l10n_util::GetStringUTF16(
330 IDS_PAGE_INFO_SECURITY_TAB_INSECURE_IDENTITY));
331 if (ssl.security_style == content::SECURITY_STYLE_UNAUTHENTICATED)
332 site_identity_status_ = SITE_IDENTITY_STATUS_NO_CERT;
333 else
334 site_identity_status_ = SITE_IDENTITY_STATUS_ERROR;
335
336 const string16 bullet = UTF8ToUTF16("\n • ");
337 std::vector<SSLErrorInfo> errors;
338 SSLErrorInfo::GetErrorsForCertStatus(ssl.cert_id, ssl.cert_status,
339 url, &errors);
340 for (size_t i = 0; i < errors.size(); ++i) {
341 site_identity_details_ += bullet;
342 site_identity_details_ += errors[i].short_description();
343 }
344
345 if (ssl.cert_status & net::CERT_STATUS_NON_UNIQUE_NAME) {
346 site_identity_details_ += ASCIIToUTF16("\n\n");
347 site_identity_details_ += l10n_util::GetStringUTF16(
348 IDS_PAGE_INFO_SECURITY_TAB_NON_UNIQUE_NAME);
349 }
350 }
351
352 // Site Connection
353 // We consider anything less than 80 bits encryption to be weak encryption.
354 // TODO(wtc): Bug 1198735: report mixed/unsafe content for unencrypted and
355 // weakly encrypted connections.
356 site_connection_status_ = SITE_CONNECTION_STATUS_UNKNOWN;
357
358 if (!ssl.cert_id) {
359 // Not HTTPS.
360 DCHECK_EQ(ssl.security_style, content::SECURITY_STYLE_UNAUTHENTICATED);
361 if (ssl.security_style == content::SECURITY_STYLE_UNAUTHENTICATED)
362 site_connection_status_ = SITE_CONNECTION_STATUS_UNENCRYPTED;
363 else
364 site_connection_status_ = SITE_CONNECTION_STATUS_ENCRYPTED_ERROR;
365
366 site_connection_details_.assign(l10n_util::GetStringFUTF16(
367 IDS_PAGE_INFO_SECURITY_TAB_NOT_ENCRYPTED_CONNECTION_TEXT,
368 subject_name));
369 } else if (ssl.security_bits < 0) {
370 // Security strength is unknown. Say nothing.
371 site_connection_status_ = SITE_CONNECTION_STATUS_ENCRYPTED_ERROR;
372 } else if (ssl.security_bits == 0) {
373 DCHECK_NE(ssl.security_style, content::SECURITY_STYLE_UNAUTHENTICATED);
374 site_connection_status_ = SITE_CONNECTION_STATUS_ENCRYPTED_ERROR;
375 site_connection_details_.assign(l10n_util::GetStringFUTF16(
376 IDS_PAGE_INFO_SECURITY_TAB_NOT_ENCRYPTED_CONNECTION_TEXT,
377 subject_name));
378 } else if (ssl.security_bits < 80) {
379 site_connection_status_ = SITE_CONNECTION_STATUS_ENCRYPTED_ERROR;
380 site_connection_details_.assign(l10n_util::GetStringFUTF16(
381 IDS_PAGE_INFO_SECURITY_TAB_WEAK_ENCRYPTION_CONNECTION_TEXT,
382 subject_name));
383 } else {
384 site_connection_status_ = SITE_CONNECTION_STATUS_ENCRYPTED;
385 site_connection_details_.assign(l10n_util::GetStringFUTF16(
386 IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTED_CONNECTION_TEXT,
387 subject_name,
388 base::IntToString16(ssl.security_bits)));
389 if (ssl.content_status) {
390 bool ran_insecure_content =
391 !!(ssl.content_status & content::SSLStatus::RAN_INSECURE_CONTENT);
392 site_connection_status_ = ran_insecure_content ?
393 SITE_CONNECTION_STATUS_ENCRYPTED_ERROR
394 : SITE_CONNECTION_STATUS_MIXED_CONTENT;
395 site_connection_details_.assign(l10n_util::GetStringFUTF16(
396 IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTED_SENTENCE_LINK,
397 site_connection_details_,
398 l10n_util::GetStringUTF16(ran_insecure_content ?
399 IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTED_INSECURE_CONTENT_ERROR :
400 IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTED_INSECURE_CONTENT_WARNING)));
401 }
402 }
403
404 uint16 cipher_suite =
405 net::SSLConnectionStatusToCipherSuite(ssl.connection_status);
406 if (ssl.security_bits > 0 && cipher_suite) {
407 int ssl_version =
408 net::SSLConnectionStatusToVersion(ssl.connection_status);
409 const char* ssl_version_str;
410 net::SSLVersionToString(&ssl_version_str, ssl_version);
411 site_connection_details_ += ASCIIToUTF16("\n\n");
412 site_connection_details_ += l10n_util::GetStringFUTF16(
413 IDS_PAGE_INFO_SECURITY_TAB_SSL_VERSION,
414 ASCIIToUTF16(ssl_version_str));
415
416 bool did_fallback = (ssl.connection_status &
[email protected]80c75f682012-05-26 16:22:17417 net::SSL_CONNECTION_VERSION_FALLBACK) != 0;
[email protected]03ef4b2a2012-03-06 15:04:20418 bool no_renegotiation =
419 (ssl.connection_status &
420 net::SSL_CONNECTION_NO_RENEGOTIATION_EXTENSION) != 0;
421 const char *key_exchange, *cipher, *mac;
[email protected]b6c1d9e82013-06-12 17:26:57422 bool is_aead;
423 net::SSLCipherSuiteToStrings(
424 &key_exchange, &cipher, &mac, &is_aead, cipher_suite);
[email protected]03ef4b2a2012-03-06 15:04:20425
426 site_connection_details_ += ASCIIToUTF16("\n\n");
[email protected]b6c1d9e82013-06-12 17:26:57427 if (is_aead) {
428 site_connection_details_ += l10n_util::GetStringFUTF16(
429 IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTION_DETAILS_AEAD,
430 ASCIIToUTF16(cipher), ASCIIToUTF16(key_exchange));
431 } else {
432 site_connection_details_ += l10n_util::GetStringFUTF16(
433 IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTION_DETAILS,
434 ASCIIToUTF16(cipher), ASCIIToUTF16(mac), ASCIIToUTF16(key_exchange));
435 }
[email protected]03ef4b2a2012-03-06 15:04:20436
[email protected]03ef4b2a2012-03-06 15:04:20437 if (did_fallback) {
438 // For now, only SSLv3 fallback will trigger a warning icon.
439 if (site_connection_status_ < SITE_CONNECTION_STATUS_MIXED_CONTENT)
440 site_connection_status_ = SITE_CONNECTION_STATUS_MIXED_CONTENT;
441 site_connection_details_ += ASCIIToUTF16("\n\n");
442 site_connection_details_ += l10n_util::GetStringUTF16(
443 IDS_PAGE_INFO_SECURITY_TAB_FALLBACK_MESSAGE);
444 }
445 if (no_renegotiation) {
446 site_connection_details_ += ASCIIToUTF16("\n\n");
447 site_connection_details_ += l10n_util::GetStringUTF16(
448 IDS_PAGE_INFO_SECURITY_TAB_RENEGOTIATION_MESSAGE);
449 }
450 }
[email protected]e583f752012-08-30 13:26:21451
452 // By default select the permissions tab that displays all the site
453 // permissions. In case of a connection error or an issue with the
454 // certificate presented by the website, select the connection tab to draw
455 // the user's attention to the issue. If the site does not provide a
456 // certificate because it was loaded over an unencrypted connection, don't
457 // select the connection tab.
458 WebsiteSettingsUI::TabId tab_id = WebsiteSettingsUI::TAB_ID_PERMISSIONS;
459 if (site_connection_status_ == SITE_CONNECTION_STATUS_ENCRYPTED_ERROR ||
460 site_connection_status_ == SITE_CONNECTION_STATUS_MIXED_CONTENT ||
461 site_identity_status_ == SITE_IDENTITY_STATUS_ERROR ||
[email protected]eaf3f322013-04-25 21:53:59462 site_identity_status_ == SITE_IDENTITY_STATUS_CERT_REVOCATION_UNKNOWN ||
463 site_identity_status_ == SITE_IDENTITY_STATUS_ADMIN_PROVIDED_CERT)
[email protected]e583f752012-08-30 13:26:21464 tab_id = WebsiteSettingsUI::TAB_ID_CONNECTION;
465 ui_->SetSelectedTab(tab_id);
[email protected]03ef4b2a2012-03-06 15:04:20466}
[email protected]0b9fdd72012-04-04 10:00:33467
[email protected]df818272012-04-20 13:10:50468void WebsiteSettings::PresentSitePermissions() {
469 PermissionInfoList permission_info_list;
470
471 WebsiteSettingsUI::PermissionInfo permission_info;
472 for (size_t i = 0; i < arraysize(kPermissionType); ++i) {
473 permission_info.type = kPermissionType[i];
474
475 content_settings::SettingInfo info;
[email protected]0bacc1912012-12-11 11:05:34476 if (permission_info.type == CONTENT_SETTINGS_TYPE_MEDIASTREAM) {
477 scoped_ptr<base::Value> mic_value(content_settings_->GetWebsiteSetting(
[email protected]007b3f82013-04-09 08:46:45478 site_url_,
479 site_url_,
480 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC,
481 std::string(),
482 &info));
[email protected]0bacc1912012-12-11 11:05:34483 ContentSetting mic_setting =
484 content_settings::ValueToContentSetting(mic_value.get());
485
486 scoped_ptr<base::Value> camera_value(content_settings_->GetWebsiteSetting(
[email protected]007b3f82013-04-09 08:46:45487 site_url_,
488 site_url_,
489 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA,
490 std::string(),
491 &info));
[email protected]0bacc1912012-12-11 11:05:34492 ContentSetting camera_setting =
493 content_settings::ValueToContentSetting(camera_value.get());
494
495 if (mic_setting != camera_setting || mic_setting == CONTENT_SETTING_ASK)
496 permission_info.setting = CONTENT_SETTING_DEFAULT;
497 else
498 permission_info.setting = mic_setting;
[email protected]fe4686a2012-10-19 15:38:26499 } else {
[email protected]0bacc1912012-12-11 11:05:34500 scoped_ptr<Value> value(content_settings_->GetWebsiteSetting(
[email protected]007b3f82013-04-09 08:46:45501 site_url_, site_url_, permission_info.type, std::string(), &info));
[email protected]0bacc1912012-12-11 11:05:34502 DCHECK(value.get());
503 if (value->GetType() == Value::TYPE_INTEGER) {
504 permission_info.setting =
505 content_settings::ValueToContentSetting(value.get());
506 } else {
507 NOTREACHED();
508 }
[email protected]fe4686a2012-10-19 15:38:26509 }
510
[email protected]8bdf45c32012-08-04 00:12:55511 permission_info.source = info.source;
[email protected]df818272012-04-20 13:10:50512
[email protected]b1d113d2012-06-27 21:27:34513 if (info.primary_pattern == ContentSettingsPattern::Wildcard() &&
[email protected]0bacc1912012-12-11 11:05:34514 info.secondary_pattern == ContentSettingsPattern::Wildcard() &&
515 permission_info.type != CONTENT_SETTINGS_TYPE_MEDIASTREAM) {
[email protected]b1d113d2012-06-27 21:27:34516 permission_info.default_setting = permission_info.setting;
517 permission_info.setting = CONTENT_SETTING_DEFAULT;
518 } else {
519 permission_info.default_setting =
520 content_settings_->GetDefaultContentSetting(permission_info.type,
521 NULL);
[email protected]df818272012-04-20 13:10:50522 }
[email protected]b1d113d2012-06-27 21:27:34523 permission_info_list.push_back(permission_info);
[email protected]df818272012-04-20 13:10:50524 }
525
526 ui_->SetPermissionInfo(permission_info_list);
[email protected]0b9fdd72012-04-04 10:00:33527}
528
[email protected]df818272012-04-20 13:10:50529void WebsiteSettings::PresentSiteData() {
530 CookieInfoList cookie_info_list;
[email protected]e0ac35892012-05-15 12:53:34531 const LocalSharedObjectsContainer& allowed_objects =
532 tab_specific_content_settings()->allowed_local_shared_objects();
533 const LocalSharedObjectsContainer& blocked_objects =
534 tab_specific_content_settings()->blocked_local_shared_objects();
535
536 // Add first party cookie and site data counts.
[email protected]df818272012-04-20 13:10:50537 WebsiteSettingsUI::CookieInfo cookie_info;
[email protected]e0ac35892012-05-15 12:53:34538 std::string cookie_source =
[email protected]ed32c212013-05-14 20:49:29539 net::registry_controlled_domains::GetDomainAndRegistry(
540 site_url_,
541 net::registry_controlled_domains::EXCLUDE_PRIVATE_REGISTRIES);
[email protected]e0ac35892012-05-15 12:53:34542 if (cookie_source.empty())
543 cookie_source = site_url_.host();
544 cookie_info.cookie_source = cookie_source;
545 cookie_info.allowed = allowed_objects.GetObjectCountForDomain(site_url_);
546 cookie_info.blocked = blocked_objects.GetObjectCountForDomain(site_url_);
547 cookie_info_list.push_back(cookie_info);
548
549 // Add third party cookie counts.
550 cookie_info.cookie_source = l10n_util::GetStringUTF8(
551 IDS_WEBSITE_SETTINGS_THIRD_PARTY_SITE_DATA);
552 cookie_info.allowed = allowed_objects.GetObjectCount() - cookie_info.allowed;
553 cookie_info.blocked = blocked_objects.GetObjectCount() - cookie_info.blocked;
[email protected]df818272012-04-20 13:10:50554 cookie_info_list.push_back(cookie_info);
[email protected]0b9fdd72012-04-04 10:00:33555
[email protected]df818272012-04-20 13:10:50556 ui_->SetCookieInfo(cookie_info_list);
[email protected]0b9fdd72012-04-04 10:00:33557}
[email protected]16de6de2012-04-04 12:24:14558
[email protected]24c8818c2012-04-25 09:57:41559void WebsiteSettings::PresentSiteIdentity() {
560 // After initialization the status about the site's connection
561 // and it's identity must be available.
562 DCHECK_NE(site_identity_status_, SITE_IDENTITY_STATUS_UNKNOWN);
563 DCHECK_NE(site_connection_status_, SITE_CONNECTION_STATUS_UNKNOWN);
564 WebsiteSettingsUI::IdentityInfo info;
565 if (site_identity_status_ == SITE_IDENTITY_STATUS_EV_CERT)
566 info.site_identity = UTF16ToUTF8(organization_name());
567 else
568 info.site_identity = site_url_.host();
569
570 info.connection_status = site_connection_status_;
571 info.connection_status_description =
572 UTF16ToUTF8(site_connection_details_);
573 info.identity_status = site_identity_status_;
574 info.identity_status_description =
575 UTF16ToUTF8(site_identity_details_);
[email protected]f61c1ce2012-05-09 13:55:11576 info.cert_id = cert_id_;
[email protected]24c8818c2012-04-25 09:57:41577 ui_->SetIdentityInfo(info);
578}
579
[email protected]15b092542012-05-16 13:08:14580void WebsiteSettings::PresentHistoryInfo(base::Time first_visit) {
581 if (first_visit == base::Time()) {
582 ui_->SetFirstVisit(string16());
583 return;
584 }
585
586 bool visited_before_today = false;
587 base::Time today = base::Time::Now().LocalMidnight();
588 base::Time first_visit_midnight = first_visit.LocalMidnight();
589 visited_before_today = (first_visit_midnight < today);
590
591 string16 first_visit_text;
592 if (visited_before_today) {
593 first_visit_text = l10n_util::GetStringFUTF16(
594 IDS_PAGE_INFO_SECURITY_TAB_VISITED_BEFORE_TODAY,
595 base::TimeFormatShortDate(first_visit));
596 } else {
597 first_visit_text = l10n_util::GetStringUTF16(
598 IDS_PAGE_INFO_SECURITY_TAB_FIRST_VISITED_TODAY);
599
600 }
601 ui_->SetFirstVisit(first_visit_text);
602}