blob: ab82b18234b9c24adb85eecbda88d356a898fd18 [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]eb2140c2013-07-29 12:37:3412#include "base/command_line.h"
[email protected]15b092542012-05-16 13:08:1413#include "base/i18n/time_formatting.h"
[email protected]3ea1b182013-02-08 22:38:4114#include "base/metrics/histogram.h"
15#include "base/strings/string_number_conversions.h"
[email protected]774cc3c2013-06-07 20:26:4516#include "base/strings/utf_string_conversions.h"
[email protected]0b9fdd72012-04-04 10:00:3317#include "base/values.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]eb2140c2013-07-29 12:37:3436#include "content/public/common/content_switches.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]24a9f1c92013-11-13 12:33:3749#if defined(OS_CHROMEOS)
50#include "chrome/browser/chromeos/policy/policy_cert_service.h"
51#include "chrome/browser/chromeos/policy/policy_cert_service_factory.h"
52#endif
53
[email protected]0b9fdd72012-04-04 10:00:3354using content::BrowserThread;
55
56namespace {
57
[email protected]b1d113d2012-06-27 21:27:3458// The list of content settings types to display on the Website Settings UI.
[email protected]0b9fdd72012-04-04 10:00:3359ContentSettingsType kPermissionType[] = {
[email protected]b1d113d2012-06-27 21:27:3460 CONTENT_SETTINGS_TYPE_IMAGES,
61 CONTENT_SETTINGS_TYPE_JAVASCRIPT,
[email protected]0b9fdd72012-04-04 10:00:3362 CONTENT_SETTINGS_TYPE_PLUGINS,
[email protected]b1d113d2012-06-27 21:27:3463 CONTENT_SETTINGS_TYPE_POPUPS,
[email protected]0b9fdd72012-04-04 10:00:3364 CONTENT_SETTINGS_TYPE_GEOLOCATION,
[email protected]b1d113d2012-06-27 21:27:3465 CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
66 CONTENT_SETTINGS_TYPE_FULLSCREEN,
67 CONTENT_SETTINGS_TYPE_MOUSELOCK,
68 CONTENT_SETTINGS_TYPE_MEDIASTREAM,
[email protected]62167c12013-07-10 23:02:0869 CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS,
[email protected]eb2140c2013-07-29 12:37:3470 CONTENT_SETTINGS_TYPE_MIDI_SYSEX,
[email protected]0b9fdd72012-04-04 10:00:3371};
72
73} // namespace
74
75WebsiteSettings::WebsiteSettings(
76 WebsiteSettingsUI* ui,
77 Profile* profile,
[email protected]df818272012-04-20 13:10:5078 TabSpecificContentSettings* tab_specific_content_settings,
[email protected]4f822f022012-12-20 19:11:4279 InfoBarService* infobar_service,
[email protected]0b9fdd72012-04-04 10:00:3380 const GURL& url,
81 const content::SSLStatus& ssl,
82 content::CertStore* cert_store)
[email protected]df818272012-04-20 13:10:5083 : TabSpecificContentSettings::SiteDataObserver(
84 tab_specific_content_settings),
85 ui_(ui),
[email protected]4f822f022012-12-20 19:11:4286 infobar_service_(infobar_service),
[email protected]66f157312012-08-01 13:50:2687 show_info_bar_(false),
[email protected]0b9fdd72012-04-04 10:00:3388 site_url_(url),
89 site_identity_status_(SITE_IDENTITY_STATUS_UNKNOWN),
[email protected]f61c1ce2012-05-09 13:55:1190 cert_id_(0),
[email protected]03ef4b2a2012-03-06 15:04:2091 site_connection_status_(SITE_CONNECTION_STATUS_UNKNOWN),
[email protected]0b9fdd72012-04-04 10:00:3392 cert_store_(cert_store),
93 content_settings_(profile->GetHostContentSettingsMap()) {
[email protected]03ef4b2a2012-03-06 15:04:2094 Init(profile, url, ssl);
[email protected]0b9fdd72012-04-04 10:00:3395
[email protected]78a1fd90a2012-07-19 08:11:2596 HistoryService* history_service = HistoryServiceFactory::GetForProfile(
97 profile, Profile::EXPLICIT_ACCESS);
[email protected]15b092542012-05-16 13:08:1498 if (history_service) {
99 history_service->GetVisibleVisitCountToHost(
100 site_url_,
101 &visit_count_request_consumer_,
102 base::Bind(&WebsiteSettings::OnGotVisitCountToHost,
103 base::Unretained(this)));
104 }
105
[email protected]0b9fdd72012-04-04 10:00:33106 PresentSitePermissions();
[email protected]df818272012-04-20 13:10:50107 PresentSiteData();
[email protected]24c8818c2012-04-25 09:57:41108 PresentSiteIdentity();
[email protected]15b092542012-05-16 13:08:14109 PresentHistoryInfo(base::Time());
[email protected]e22d64f2012-09-10 09:03:23110
111 // Every time the Website Settings UI is opened a |WebsiteSettings| object is
112 // created. So this counts how ofter the Website Settings UI is opened.
113 content::RecordAction(content::UserMetricsAction("WebsiteSettings_Opened"));
[email protected]03ef4b2a2012-03-06 15:04:20114}
115
[email protected]0b9fdd72012-04-04 10:00:33116WebsiteSettings::~WebsiteSettings() {
[email protected]03ef4b2a2012-03-06 15:04:20117}
118
[email protected]df818272012-04-20 13:10:50119void WebsiteSettings::OnSitePermissionChanged(ContentSettingsType type,
120 ContentSetting setting) {
[email protected]e22d64f2012-09-10 09:03:23121 // Count how often a permission for a specific content type is changed using
122 // the Website Settings UI.
123 UMA_HISTOGRAM_COUNTS("WebsiteSettings.PermissionChanged", type);
124
[email protected]df818272012-04-20 13:10:50125 ContentSettingsPattern primary_pattern;
126 ContentSettingsPattern secondary_pattern;
127 switch (type) {
128 case CONTENT_SETTINGS_TYPE_GEOLOCATION:
[email protected]eb2140c2013-07-29 12:37:34129 case CONTENT_SETTINGS_TYPE_MIDI_SYSEX:
[email protected]df818272012-04-20 13:10:50130 // TODO(markusheintz): The rule we create here should also change the
131 // location permission for iframed content.
132 primary_pattern = ContentSettingsPattern::FromURLNoWildcard(site_url_);
133 secondary_pattern = ContentSettingsPattern::FromURLNoWildcard(site_url_);
134 break;
135 case CONTENT_SETTINGS_TYPE_NOTIFICATIONS:
136 primary_pattern = ContentSettingsPattern::FromURLNoWildcard(site_url_);
137 secondary_pattern = ContentSettingsPattern::Wildcard();
138 break;
[email protected]b1d113d2012-06-27 21:27:34139 case CONTENT_SETTINGS_TYPE_IMAGES:
140 case CONTENT_SETTINGS_TYPE_JAVASCRIPT:
[email protected]df818272012-04-20 13:10:50141 case CONTENT_SETTINGS_TYPE_PLUGINS:
142 case CONTENT_SETTINGS_TYPE_POPUPS:
[email protected]b1d113d2012-06-27 21:27:34143 case CONTENT_SETTINGS_TYPE_FULLSCREEN:
144 case CONTENT_SETTINGS_TYPE_MOUSELOCK:
[email protected]ad635b12013-07-22 21:53:27145 case CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS:
[email protected]df818272012-04-20 13:10:50146 primary_pattern = ContentSettingsPattern::FromURL(site_url_);
147 secondary_pattern = ContentSettingsPattern::Wildcard();
148 break;
[email protected]0bacc1912012-12-11 11:05:34149 case CONTENT_SETTINGS_TYPE_MEDIASTREAM: {
150 // We need to use the same same patterns as other places like infobar code
151 // to override the existing rule instead of creating the new one.
152 primary_pattern = ContentSettingsPattern::FromURLNoWildcard(site_url_);
153 secondary_pattern = ContentSettingsPattern::Wildcard();
154 // Set permission for both microphone and camera.
155 content_settings_->SetContentSetting(
[email protected]007b3f82013-04-09 08:46:45156 primary_pattern,
157 secondary_pattern,
158 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC,
159 std::string(),
160 setting);
[email protected]0bacc1912012-12-11 11:05:34161
162 content_settings_->SetContentSetting(
[email protected]007b3f82013-04-09 08:46:45163 primary_pattern,
164 secondary_pattern,
165 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA,
166 std::string(),
167 setting);
[email protected]0bacc1912012-12-11 11:05:34168 break;
169 }
[email protected]df818272012-04-20 13:10:50170 default:
171 NOTREACHED() << "ContentSettingsType " << type << "is not supported.";
172 break;
[email protected]0b9fdd72012-04-04 10:00:33173 }
174
[email protected]0bacc1912012-12-11 11:05:34175 if (type != CONTENT_SETTINGS_TYPE_MEDIASTREAM) {
176 // Permission settings are specified via rules. There exists always at least
177 // one rule for the default setting. Get the rule that currently defines
178 // the permission for the given permission |type|. Then test whether the
179 // existing rule is more specific than the rule we are about to create. If
180 // the existing rule is more specific, than change the existing rule instead
181 // of creating a new rule that would be hidden behind the existing rule.
182 // This is not a concern for CONTENT_SETTINGS_TYPE_MEDIASTREAM since users
183 // can not create media settings exceptions by hand.
184 content_settings::SettingInfo info;
185 scoped_ptr<Value> v(content_settings_->GetWebsiteSetting(
[email protected]007b3f82013-04-09 08:46:45186 site_url_, site_url_, type, std::string(), &info));
[email protected]0bacc1912012-12-11 11:05:34187 DCHECK(info.source == content_settings::SETTING_SOURCE_USER);
188 ContentSettingsPattern::Relation r1 =
189 info.primary_pattern.Compare(primary_pattern);
190 DCHECK(r1 != ContentSettingsPattern::DISJOINT_ORDER_POST &&
191 r1 != ContentSettingsPattern::DISJOINT_ORDER_PRE);
192 if (r1 == ContentSettingsPattern::PREDECESSOR) {
193 primary_pattern = info.primary_pattern;
194 } else if (r1 == ContentSettingsPattern::IDENTITY) {
195 ContentSettingsPattern::Relation r2 =
196 info.secondary_pattern.Compare(secondary_pattern);
197 DCHECK(r2 != ContentSettingsPattern::DISJOINT_ORDER_POST &&
198 r2 != ContentSettingsPattern::DISJOINT_ORDER_PRE);
199 if (r2 == ContentSettingsPattern::PREDECESSOR)
200 secondary_pattern = info.secondary_pattern;
201 }
202
203 Value* value = NULL;
204 if (setting != CONTENT_SETTING_DEFAULT)
205 value = Value::CreateIntegerValue(setting);
206 content_settings_->SetWebsiteSetting(
[email protected]007b3f82013-04-09 08:46:45207 primary_pattern, secondary_pattern, type, std::string(), value);
[email protected]df818272012-04-20 13:10:50208 }
209
[email protected]66f157312012-08-01 13:50:26210 show_info_bar_ = true;
[email protected]2f45d542012-08-22 08:47:24211
[email protected]76955932012-12-06 11:01:10212// TODO(markusheintz): This is a temporary hack to fix issue:
213// http://crbug.com/144203.
[email protected]e379ba42012-08-22 22:40:25214#if defined(OS_MACOSX)
[email protected]2f45d542012-08-22 08:47:24215 // Refresh the UI to reflect the new setting.
216 PresentSitePermissions();
[email protected]e379ba42012-08-22 22:40:25217#endif
[email protected]df818272012-04-20 13:10:50218}
219
[email protected]15b092542012-05-16 13:08:14220void WebsiteSettings::OnGotVisitCountToHost(HistoryService::Handle handle,
221 bool found_visits,
222 int visit_count,
223 base::Time first_visit) {
224 if (!found_visits) {
225 // This indicates an error, such as the page's URL scheme wasn't
226 // http/https.
227 first_visit = base::Time();
228 } else if (visit_count == 0) {
229 first_visit = base::Time::Now();
230 }
231 PresentHistoryInfo(first_visit);
232}
233
[email protected]df818272012-04-20 13:10:50234void WebsiteSettings::OnSiteDataAccessed() {
235 PresentSiteData();
[email protected]0b9fdd72012-04-04 10:00:33236}
237
[email protected]66f157312012-08-01 13:50:26238void WebsiteSettings::OnUIClosing() {
[email protected]0be09932013-01-08 02:03:50239 if (show_info_bar_)
[email protected]ed9bc652013-07-11 17:17:36240 WebsiteSettingsInfoBarDelegate::Create(infobar_service_);
[email protected]66f157312012-08-01 13:50:26241}
242
[email protected]0b9fdd72012-04-04 10:00:33243void WebsiteSettings::Init(Profile* profile,
244 const GURL& url,
245 const content::SSLStatus& ssl) {
[email protected]03ef4b2a2012-03-06 15:04:20246 if (url.SchemeIs(chrome::kChromeUIScheme)) {
247 site_identity_status_ = SITE_IDENTITY_STATUS_INTERNAL_PAGE;
248 site_identity_details_ =
249 l10n_util::GetStringUTF16(IDS_PAGE_INFO_INTERNAL_PAGE);
250 site_connection_status_ = SITE_CONNECTION_STATUS_INTERNAL_PAGE;
251 return;
252 }
253
254 scoped_refptr<net::X509Certificate> cert;
255
256 // Identity section.
257 string16 subject_name(UTF8ToUTF16(url.host()));
[email protected]03ef4b2a2012-03-06 15:04:20258 if (subject_name.empty()) {
259 subject_name.assign(
260 l10n_util::GetStringUTF16(IDS_PAGE_INFO_SECURITY_TAB_UNKNOWN_PARTY));
[email protected]03ef4b2a2012-03-06 15:04:20261 }
262
[email protected]f61c1ce2012-05-09 13:55:11263 cert_id_ = ssl.cert_id;
264
[email protected]03ef4b2a2012-03-06 15:04:20265 if (ssl.cert_id &&
266 cert_store_->RetrieveCert(ssl.cert_id, &cert) &&
267 (!net::IsCertStatusError(ssl.cert_status) ||
268 net::IsCertStatusMinorError(ssl.cert_status))) {
269 // There are no major errors. Check for minor errors.
[email protected]24a9f1c92013-11-13 12:33:37270#if defined(OS_CHROMEOS)
271 policy::PolicyCertService* service =
272 policy::PolicyCertServiceFactory::GetForProfile(profile);
273 const bool used_policy_certs = service && service->UsedPolicyCertificates();
274#else
275 const bool used_policy_certs = false;
276#endif
277 if (used_policy_certs) {
[email protected]eaf3f322013-04-25 21:53:59278 site_identity_status_ = SITE_IDENTITY_STATUS_ADMIN_PROVIDED_CERT;
[email protected]24a9f1c92013-11-13 12:33:37279 site_identity_details_ = l10n_util::GetStringFUTF16(
280 IDS_CERT_POLICY_PROVIDED_CERT_MESSAGE, UTF8ToUTF16(url.host()));
[email protected]eaf3f322013-04-25 21:53:59281 } else if (net::IsCertStatusMinorError(ssl.cert_status)) {
[email protected]03ef4b2a2012-03-06 15:04:20282 site_identity_status_ = SITE_IDENTITY_STATUS_CERT_REVOCATION_UNKNOWN;
283 string16 issuer_name(UTF8ToUTF16(cert->issuer().GetDisplayName()));
284 if (issuer_name.empty()) {
285 issuer_name.assign(l10n_util::GetStringUTF16(
286 IDS_PAGE_INFO_SECURITY_TAB_UNKNOWN_PARTY));
287 }
288 site_identity_details_.assign(l10n_util::GetStringFUTF16(
289 IDS_PAGE_INFO_SECURITY_TAB_SECURE_IDENTITY, issuer_name));
290
291 site_identity_details_ += ASCIIToUTF16("\n\n");
292 if (ssl.cert_status & net::CERT_STATUS_UNABLE_TO_CHECK_REVOCATION) {
293 site_identity_details_ += l10n_util::GetStringUTF16(
294 IDS_PAGE_INFO_SECURITY_TAB_UNABLE_TO_CHECK_REVOCATION);
295 } else if (ssl.cert_status & net::CERT_STATUS_NO_REVOCATION_MECHANISM) {
296 site_identity_details_ += l10n_util::GetStringUTF16(
297 IDS_PAGE_INFO_SECURITY_TAB_NO_REVOCATION_MECHANISM);
298 } else {
299 NOTREACHED() << "Need to specify string for this warning";
300 }
301 } else if (ssl.cert_status & net::CERT_STATUS_IS_EV) {
302 // EV HTTPS page.
303 site_identity_status_ = SITE_IDENTITY_STATUS_EV_CERT;
304 DCHECK(!cert->subject().organization_names.empty());
305 organization_name_ = UTF8ToUTF16(cert->subject().organization_names[0]);
306 // An EV Cert is required to have a city (localityName) and country but
307 // state is "if any".
308 DCHECK(!cert->subject().locality_name.empty());
309 DCHECK(!cert->subject().country_name.empty());
310 string16 locality;
311 if (!cert->subject().state_or_province_name.empty()) {
312 locality = l10n_util::GetStringFUTF16(
313 IDS_PAGEINFO_ADDRESS,
314 UTF8ToUTF16(cert->subject().locality_name),
315 UTF8ToUTF16(cert->subject().state_or_province_name),
316 UTF8ToUTF16(cert->subject().country_name));
317 } else {
318 locality = l10n_util::GetStringFUTF16(
319 IDS_PAGEINFO_PARTIAL_ADDRESS,
320 UTF8ToUTF16(cert->subject().locality_name),
321 UTF8ToUTF16(cert->subject().country_name));
322 }
323 DCHECK(!cert->subject().organization_names.empty());
324 site_identity_details_.assign(l10n_util::GetStringFUTF16(
325 IDS_PAGE_INFO_SECURITY_TAB_SECURE_IDENTITY_EV,
326 UTF8ToUTF16(cert->subject().organization_names[0]),
327 locality,
328 UTF8ToUTF16(cert->issuer().GetDisplayName())));
[email protected]03ef4b2a2012-03-06 15:04:20329 } else {
330 // Non-EV OK HTTPS page.
331 site_identity_status_ = SITE_IDENTITY_STATUS_CERT;
332 string16 issuer_name(UTF8ToUTF16(cert->issuer().GetDisplayName()));
333 if (issuer_name.empty()) {
334 issuer_name.assign(l10n_util::GetStringUTF16(
335 IDS_PAGE_INFO_SECURITY_TAB_UNKNOWN_PARTY));
336 }
337 site_identity_details_.assign(l10n_util::GetStringFUTF16(
338 IDS_PAGE_INFO_SECURITY_TAB_SECURE_IDENTITY, issuer_name));
339 }
340 } else {
341 // HTTP or HTTPS with errors (not warnings).
342 site_identity_details_.assign(l10n_util::GetStringUTF16(
343 IDS_PAGE_INFO_SECURITY_TAB_INSECURE_IDENTITY));
344 if (ssl.security_style == content::SECURITY_STYLE_UNAUTHENTICATED)
345 site_identity_status_ = SITE_IDENTITY_STATUS_NO_CERT;
346 else
347 site_identity_status_ = SITE_IDENTITY_STATUS_ERROR;
348
349 const string16 bullet = UTF8ToUTF16("\n • ");
350 std::vector<SSLErrorInfo> errors;
351 SSLErrorInfo::GetErrorsForCertStatus(ssl.cert_id, ssl.cert_status,
352 url, &errors);
353 for (size_t i = 0; i < errors.size(); ++i) {
354 site_identity_details_ += bullet;
355 site_identity_details_ += errors[i].short_description();
356 }
357
358 if (ssl.cert_status & net::CERT_STATUS_NON_UNIQUE_NAME) {
359 site_identity_details_ += ASCIIToUTF16("\n\n");
360 site_identity_details_ += l10n_util::GetStringUTF16(
361 IDS_PAGE_INFO_SECURITY_TAB_NON_UNIQUE_NAME);
362 }
363 }
364
365 // Site Connection
366 // We consider anything less than 80 bits encryption to be weak encryption.
367 // TODO(wtc): Bug 1198735: report mixed/unsafe content for unencrypted and
368 // weakly encrypted connections.
369 site_connection_status_ = SITE_CONNECTION_STATUS_UNKNOWN;
370
371 if (!ssl.cert_id) {
372 // Not HTTPS.
373 DCHECK_EQ(ssl.security_style, content::SECURITY_STYLE_UNAUTHENTICATED);
374 if (ssl.security_style == content::SECURITY_STYLE_UNAUTHENTICATED)
375 site_connection_status_ = SITE_CONNECTION_STATUS_UNENCRYPTED;
376 else
377 site_connection_status_ = SITE_CONNECTION_STATUS_ENCRYPTED_ERROR;
378
379 site_connection_details_.assign(l10n_util::GetStringFUTF16(
380 IDS_PAGE_INFO_SECURITY_TAB_NOT_ENCRYPTED_CONNECTION_TEXT,
381 subject_name));
382 } else if (ssl.security_bits < 0) {
383 // Security strength is unknown. Say nothing.
384 site_connection_status_ = SITE_CONNECTION_STATUS_ENCRYPTED_ERROR;
385 } else if (ssl.security_bits == 0) {
386 DCHECK_NE(ssl.security_style, content::SECURITY_STYLE_UNAUTHENTICATED);
387 site_connection_status_ = SITE_CONNECTION_STATUS_ENCRYPTED_ERROR;
388 site_connection_details_.assign(l10n_util::GetStringFUTF16(
389 IDS_PAGE_INFO_SECURITY_TAB_NOT_ENCRYPTED_CONNECTION_TEXT,
390 subject_name));
391 } else if (ssl.security_bits < 80) {
392 site_connection_status_ = SITE_CONNECTION_STATUS_ENCRYPTED_ERROR;
393 site_connection_details_.assign(l10n_util::GetStringFUTF16(
394 IDS_PAGE_INFO_SECURITY_TAB_WEAK_ENCRYPTION_CONNECTION_TEXT,
395 subject_name));
396 } else {
397 site_connection_status_ = SITE_CONNECTION_STATUS_ENCRYPTED;
398 site_connection_details_.assign(l10n_util::GetStringFUTF16(
399 IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTED_CONNECTION_TEXT,
400 subject_name,
401 base::IntToString16(ssl.security_bits)));
402 if (ssl.content_status) {
403 bool ran_insecure_content =
404 !!(ssl.content_status & content::SSLStatus::RAN_INSECURE_CONTENT);
405 site_connection_status_ = ran_insecure_content ?
406 SITE_CONNECTION_STATUS_ENCRYPTED_ERROR
407 : SITE_CONNECTION_STATUS_MIXED_CONTENT;
408 site_connection_details_.assign(l10n_util::GetStringFUTF16(
409 IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTED_SENTENCE_LINK,
410 site_connection_details_,
411 l10n_util::GetStringUTF16(ran_insecure_content ?
412 IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTED_INSECURE_CONTENT_ERROR :
413 IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTED_INSECURE_CONTENT_WARNING)));
414 }
415 }
416
417 uint16 cipher_suite =
418 net::SSLConnectionStatusToCipherSuite(ssl.connection_status);
419 if (ssl.security_bits > 0 && cipher_suite) {
420 int ssl_version =
421 net::SSLConnectionStatusToVersion(ssl.connection_status);
422 const char* ssl_version_str;
423 net::SSLVersionToString(&ssl_version_str, ssl_version);
424 site_connection_details_ += ASCIIToUTF16("\n\n");
425 site_connection_details_ += l10n_util::GetStringFUTF16(
426 IDS_PAGE_INFO_SECURITY_TAB_SSL_VERSION,
427 ASCIIToUTF16(ssl_version_str));
428
429 bool did_fallback = (ssl.connection_status &
[email protected]80c75f682012-05-26 16:22:17430 net::SSL_CONNECTION_VERSION_FALLBACK) != 0;
[email protected]03ef4b2a2012-03-06 15:04:20431 bool no_renegotiation =
432 (ssl.connection_status &
433 net::SSL_CONNECTION_NO_RENEGOTIATION_EXTENSION) != 0;
434 const char *key_exchange, *cipher, *mac;
[email protected]b6c1d9e82013-06-12 17:26:57435 bool is_aead;
436 net::SSLCipherSuiteToStrings(
437 &key_exchange, &cipher, &mac, &is_aead, cipher_suite);
[email protected]03ef4b2a2012-03-06 15:04:20438
439 site_connection_details_ += ASCIIToUTF16("\n\n");
[email protected]b6c1d9e82013-06-12 17:26:57440 if (is_aead) {
441 site_connection_details_ += l10n_util::GetStringFUTF16(
442 IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTION_DETAILS_AEAD,
443 ASCIIToUTF16(cipher), ASCIIToUTF16(key_exchange));
444 } else {
445 site_connection_details_ += l10n_util::GetStringFUTF16(
446 IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTION_DETAILS,
447 ASCIIToUTF16(cipher), ASCIIToUTF16(mac), ASCIIToUTF16(key_exchange));
448 }
[email protected]03ef4b2a2012-03-06 15:04:20449
[email protected]03ef4b2a2012-03-06 15:04:20450 if (did_fallback) {
451 // For now, only SSLv3 fallback will trigger a warning icon.
452 if (site_connection_status_ < SITE_CONNECTION_STATUS_MIXED_CONTENT)
453 site_connection_status_ = SITE_CONNECTION_STATUS_MIXED_CONTENT;
454 site_connection_details_ += ASCIIToUTF16("\n\n");
455 site_connection_details_ += l10n_util::GetStringUTF16(
456 IDS_PAGE_INFO_SECURITY_TAB_FALLBACK_MESSAGE);
457 }
458 if (no_renegotiation) {
459 site_connection_details_ += ASCIIToUTF16("\n\n");
460 site_connection_details_ += l10n_util::GetStringUTF16(
461 IDS_PAGE_INFO_SECURITY_TAB_RENEGOTIATION_MESSAGE);
462 }
463 }
[email protected]e583f752012-08-30 13:26:21464
465 // By default select the permissions tab that displays all the site
466 // permissions. In case of a connection error or an issue with the
467 // certificate presented by the website, select the connection tab to draw
468 // the user's attention to the issue. If the site does not provide a
469 // certificate because it was loaded over an unencrypted connection, don't
470 // select the connection tab.
471 WebsiteSettingsUI::TabId tab_id = WebsiteSettingsUI::TAB_ID_PERMISSIONS;
472 if (site_connection_status_ == SITE_CONNECTION_STATUS_ENCRYPTED_ERROR ||
473 site_connection_status_ == SITE_CONNECTION_STATUS_MIXED_CONTENT ||
474 site_identity_status_ == SITE_IDENTITY_STATUS_ERROR ||
[email protected]eaf3f322013-04-25 21:53:59475 site_identity_status_ == SITE_IDENTITY_STATUS_CERT_REVOCATION_UNKNOWN ||
476 site_identity_status_ == SITE_IDENTITY_STATUS_ADMIN_PROVIDED_CERT)
[email protected]e583f752012-08-30 13:26:21477 tab_id = WebsiteSettingsUI::TAB_ID_CONNECTION;
478 ui_->SetSelectedTab(tab_id);
[email protected]03ef4b2a2012-03-06 15:04:20479}
[email protected]0b9fdd72012-04-04 10:00:33480
[email protected]df818272012-04-20 13:10:50481void WebsiteSettings::PresentSitePermissions() {
482 PermissionInfoList permission_info_list;
483
484 WebsiteSettingsUI::PermissionInfo permission_info;
485 for (size_t i = 0; i < arraysize(kPermissionType); ++i) {
486 permission_info.type = kPermissionType[i];
[email protected]eb2140c2013-07-29 12:37:34487 if (permission_info.type == CONTENT_SETTINGS_TYPE_MIDI_SYSEX) {
488 const CommandLine* command_line = CommandLine::ForCurrentProcess();
489 if (!command_line->HasSwitch(switches::kEnableWebMIDI))
490 continue;
491 }
[email protected]df818272012-04-20 13:10:50492
493 content_settings::SettingInfo info;
[email protected]0bacc1912012-12-11 11:05:34494 if (permission_info.type == CONTENT_SETTINGS_TYPE_MEDIASTREAM) {
495 scoped_ptr<base::Value> mic_value(content_settings_->GetWebsiteSetting(
[email protected]007b3f82013-04-09 08:46:45496 site_url_,
497 site_url_,
498 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC,
499 std::string(),
500 &info));
[email protected]0bacc1912012-12-11 11:05:34501 ContentSetting mic_setting =
502 content_settings::ValueToContentSetting(mic_value.get());
503
504 scoped_ptr<base::Value> camera_value(content_settings_->GetWebsiteSetting(
[email protected]007b3f82013-04-09 08:46:45505 site_url_,
506 site_url_,
507 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA,
508 std::string(),
509 &info));
[email protected]0bacc1912012-12-11 11:05:34510 ContentSetting camera_setting =
511 content_settings::ValueToContentSetting(camera_value.get());
512
513 if (mic_setting != camera_setting || mic_setting == CONTENT_SETTING_ASK)
514 permission_info.setting = CONTENT_SETTING_DEFAULT;
515 else
516 permission_info.setting = mic_setting;
[email protected]fe4686a2012-10-19 15:38:26517 } else {
[email protected]0bacc1912012-12-11 11:05:34518 scoped_ptr<Value> value(content_settings_->GetWebsiteSetting(
[email protected]007b3f82013-04-09 08:46:45519 site_url_, site_url_, permission_info.type, std::string(), &info));
[email protected]0bacc1912012-12-11 11:05:34520 DCHECK(value.get());
521 if (value->GetType() == Value::TYPE_INTEGER) {
522 permission_info.setting =
523 content_settings::ValueToContentSetting(value.get());
524 } else {
525 NOTREACHED();
526 }
[email protected]fe4686a2012-10-19 15:38:26527 }
528
[email protected]8bdf45c32012-08-04 00:12:55529 permission_info.source = info.source;
[email protected]df818272012-04-20 13:10:50530
[email protected]b1d113d2012-06-27 21:27:34531 if (info.primary_pattern == ContentSettingsPattern::Wildcard() &&
[email protected]0bacc1912012-12-11 11:05:34532 info.secondary_pattern == ContentSettingsPattern::Wildcard() &&
533 permission_info.type != CONTENT_SETTINGS_TYPE_MEDIASTREAM) {
[email protected]b1d113d2012-06-27 21:27:34534 permission_info.default_setting = permission_info.setting;
535 permission_info.setting = CONTENT_SETTING_DEFAULT;
536 } else {
537 permission_info.default_setting =
538 content_settings_->GetDefaultContentSetting(permission_info.type,
539 NULL);
[email protected]df818272012-04-20 13:10:50540 }
[email protected]b1d113d2012-06-27 21:27:34541 permission_info_list.push_back(permission_info);
[email protected]df818272012-04-20 13:10:50542 }
543
544 ui_->SetPermissionInfo(permission_info_list);
[email protected]0b9fdd72012-04-04 10:00:33545}
546
[email protected]df818272012-04-20 13:10:50547void WebsiteSettings::PresentSiteData() {
548 CookieInfoList cookie_info_list;
[email protected]e0ac35892012-05-15 12:53:34549 const LocalSharedObjectsContainer& allowed_objects =
550 tab_specific_content_settings()->allowed_local_shared_objects();
551 const LocalSharedObjectsContainer& blocked_objects =
552 tab_specific_content_settings()->blocked_local_shared_objects();
553
554 // Add first party cookie and site data counts.
[email protected]df818272012-04-20 13:10:50555 WebsiteSettingsUI::CookieInfo cookie_info;
[email protected]e0ac35892012-05-15 12:53:34556 std::string cookie_source =
[email protected]ed32c212013-05-14 20:49:29557 net::registry_controlled_domains::GetDomainAndRegistry(
558 site_url_,
559 net::registry_controlled_domains::EXCLUDE_PRIVATE_REGISTRIES);
[email protected]e0ac35892012-05-15 12:53:34560 if (cookie_source.empty())
561 cookie_source = site_url_.host();
562 cookie_info.cookie_source = cookie_source;
563 cookie_info.allowed = allowed_objects.GetObjectCountForDomain(site_url_);
564 cookie_info.blocked = blocked_objects.GetObjectCountForDomain(site_url_);
565 cookie_info_list.push_back(cookie_info);
566
567 // Add third party cookie counts.
568 cookie_info.cookie_source = l10n_util::GetStringUTF8(
569 IDS_WEBSITE_SETTINGS_THIRD_PARTY_SITE_DATA);
570 cookie_info.allowed = allowed_objects.GetObjectCount() - cookie_info.allowed;
571 cookie_info.blocked = blocked_objects.GetObjectCount() - cookie_info.blocked;
[email protected]df818272012-04-20 13:10:50572 cookie_info_list.push_back(cookie_info);
[email protected]0b9fdd72012-04-04 10:00:33573
[email protected]df818272012-04-20 13:10:50574 ui_->SetCookieInfo(cookie_info_list);
[email protected]0b9fdd72012-04-04 10:00:33575}
[email protected]16de6de2012-04-04 12:24:14576
[email protected]24c8818c2012-04-25 09:57:41577void WebsiteSettings::PresentSiteIdentity() {
578 // After initialization the status about the site's connection
579 // and it's identity must be available.
580 DCHECK_NE(site_identity_status_, SITE_IDENTITY_STATUS_UNKNOWN);
581 DCHECK_NE(site_connection_status_, SITE_CONNECTION_STATUS_UNKNOWN);
582 WebsiteSettingsUI::IdentityInfo info;
583 if (site_identity_status_ == SITE_IDENTITY_STATUS_EV_CERT)
584 info.site_identity = UTF16ToUTF8(organization_name());
585 else
586 info.site_identity = site_url_.host();
587
588 info.connection_status = site_connection_status_;
589 info.connection_status_description =
590 UTF16ToUTF8(site_connection_details_);
591 info.identity_status = site_identity_status_;
592 info.identity_status_description =
593 UTF16ToUTF8(site_identity_details_);
[email protected]f61c1ce2012-05-09 13:55:11594 info.cert_id = cert_id_;
[email protected]24c8818c2012-04-25 09:57:41595 ui_->SetIdentityInfo(info);
596}
597
[email protected]15b092542012-05-16 13:08:14598void WebsiteSettings::PresentHistoryInfo(base::Time first_visit) {
599 if (first_visit == base::Time()) {
600 ui_->SetFirstVisit(string16());
601 return;
602 }
603
604 bool visited_before_today = false;
605 base::Time today = base::Time::Now().LocalMidnight();
606 base::Time first_visit_midnight = first_visit.LocalMidnight();
607 visited_before_today = (first_visit_midnight < today);
608
609 string16 first_visit_text;
610 if (visited_before_today) {
611 first_visit_text = l10n_util::GetStringFUTF16(
612 IDS_PAGE_INFO_SECURITY_TAB_VISITED_BEFORE_TODAY,
613 base::TimeFormatShortDate(first_visit));
614 } else {
615 first_visit_text = l10n_util::GetStringUTF16(
616 IDS_PAGE_INFO_SECURITY_TAB_FIRST_VISITED_TODAY);
617
618 }
619 ui_->SetFirstVisit(first_visit_text);
620}