blob: 15a6c07f10408886bcf14e595860affafed0c2b2 [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]d81bb3e2013-05-02 18:17:0328#include "chrome/browser/policy/profile_policy_connector.h"
29#include "chrome/browser/policy/profile_policy_connector_factory.h"
[email protected]03ef4b2a2012-03-06 15:04:2030#include "chrome/browser/profiles/profile.h"
[email protected]03ef4b2a2012-03-06 15:04:2031#include "chrome/browser/ssl/ssl_error_info.h"
[email protected]66f157312012-08-01 13:50:2632#include "chrome/browser/ui/website_settings/website_settings_infobar_delegate.h"
[email protected]4237dd52012-06-05 00:00:3233#include "chrome/browser/ui/website_settings/website_settings_ui.h"
[email protected]0b9fdd72012-04-04 10:00:3334#include "chrome/common/content_settings_pattern.h"
35#include "content/public/browser/browser_thread.h"
[email protected]b59c6cf02012-03-12 20:51:4236#include "content/public/browser/cert_store.h"
[email protected]e22d64f2012-09-10 09:03:2337#include "content/public/browser/user_metrics.h"
[email protected]eb2140c2013-07-29 12:37:3438#include "content/public/common/content_switches.h"
[email protected]03ef4b2a2012-03-06 15:04:2039#include "content/public/common/ssl_status.h"
40#include "content/public/common/url_constants.h"
41#include "grit/chromium_strings.h"
42#include "grit/generated_resources.h"
[email protected]be28b5f42012-07-20 11:31:2543#include "net/base/registry_controlled_domains/registry_controlled_domain.h"
[email protected]6e7845ae2013-03-29 21:48:1144#include "net/cert/cert_status_flags.h"
45#include "net/cert/x509_certificate.h"
[email protected]536fd0b2013-03-14 17:41:5746#include "net/ssl/ssl_cipher_suite_names.h"
47#include "net/ssl/ssl_connection_status_flags.h"
[email protected]03ef4b2a2012-03-06 15:04:2048#include "ui/base/l10n/l10n_util.h"
49#include "ui/base/resource/resource_bundle.h"
50
[email protected]0b9fdd72012-04-04 10:00:3351using content::BrowserThread;
52
53namespace {
54
[email protected]b1d113d2012-06-27 21:27:3455// The list of content settings types to display on the Website Settings UI.
[email protected]0b9fdd72012-04-04 10:00:3356ContentSettingsType kPermissionType[] = {
[email protected]b1d113d2012-06-27 21:27:3457 CONTENT_SETTINGS_TYPE_IMAGES,
58 CONTENT_SETTINGS_TYPE_JAVASCRIPT,
[email protected]0b9fdd72012-04-04 10:00:3359 CONTENT_SETTINGS_TYPE_PLUGINS,
[email protected]b1d113d2012-06-27 21:27:3460 CONTENT_SETTINGS_TYPE_POPUPS,
[email protected]0b9fdd72012-04-04 10:00:3361 CONTENT_SETTINGS_TYPE_GEOLOCATION,
[email protected]b1d113d2012-06-27 21:27:3462 CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
63 CONTENT_SETTINGS_TYPE_FULLSCREEN,
64 CONTENT_SETTINGS_TYPE_MOUSELOCK,
65 CONTENT_SETTINGS_TYPE_MEDIASTREAM,
[email protected]62167c12013-07-10 23:02:0866 CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS,
[email protected]eb2140c2013-07-29 12:37:3467 CONTENT_SETTINGS_TYPE_MIDI_SYSEX,
[email protected]0b9fdd72012-04-04 10:00:3368};
69
70} // namespace
71
72WebsiteSettings::WebsiteSettings(
73 WebsiteSettingsUI* ui,
74 Profile* profile,
[email protected]df818272012-04-20 13:10:5075 TabSpecificContentSettings* tab_specific_content_settings,
[email protected]4f822f022012-12-20 19:11:4276 InfoBarService* infobar_service,
[email protected]0b9fdd72012-04-04 10:00:3377 const GURL& url,
78 const content::SSLStatus& ssl,
79 content::CertStore* cert_store)
[email protected]df818272012-04-20 13:10:5080 : TabSpecificContentSettings::SiteDataObserver(
81 tab_specific_content_settings),
82 ui_(ui),
[email protected]4f822f022012-12-20 19:11:4283 infobar_service_(infobar_service),
[email protected]66f157312012-08-01 13:50:2684 show_info_bar_(false),
[email protected]0b9fdd72012-04-04 10:00:3385 site_url_(url),
86 site_identity_status_(SITE_IDENTITY_STATUS_UNKNOWN),
[email protected]f61c1ce2012-05-09 13:55:1187 cert_id_(0),
[email protected]03ef4b2a2012-03-06 15:04:2088 site_connection_status_(SITE_CONNECTION_STATUS_UNKNOWN),
[email protected]0b9fdd72012-04-04 10:00:3389 cert_store_(cert_store),
90 content_settings_(profile->GetHostContentSettingsMap()) {
[email protected]03ef4b2a2012-03-06 15:04:2091 Init(profile, url, ssl);
[email protected]0b9fdd72012-04-04 10:00:3392
[email protected]78a1fd90a2012-07-19 08:11:2593 HistoryService* history_service = HistoryServiceFactory::GetForProfile(
94 profile, Profile::EXPLICIT_ACCESS);
[email protected]15b092542012-05-16 13:08:1495 if (history_service) {
96 history_service->GetVisibleVisitCountToHost(
97 site_url_,
98 &visit_count_request_consumer_,
99 base::Bind(&WebsiteSettings::OnGotVisitCountToHost,
100 base::Unretained(this)));
101 }
102
[email protected]0b9fdd72012-04-04 10:00:33103 PresentSitePermissions();
[email protected]df818272012-04-20 13:10:50104 PresentSiteData();
[email protected]24c8818c2012-04-25 09:57:41105 PresentSiteIdentity();
[email protected]15b092542012-05-16 13:08:14106 PresentHistoryInfo(base::Time());
[email protected]e22d64f2012-09-10 09:03:23107
108 // Every time the Website Settings UI is opened a |WebsiteSettings| object is
109 // created. So this counts how ofter the Website Settings UI is opened.
110 content::RecordAction(content::UserMetricsAction("WebsiteSettings_Opened"));
[email protected]03ef4b2a2012-03-06 15:04:20111}
112
[email protected]0b9fdd72012-04-04 10:00:33113WebsiteSettings::~WebsiteSettings() {
[email protected]03ef4b2a2012-03-06 15:04:20114}
115
[email protected]df818272012-04-20 13:10:50116void WebsiteSettings::OnSitePermissionChanged(ContentSettingsType type,
117 ContentSetting setting) {
[email protected]e22d64f2012-09-10 09:03:23118 // Count how often a permission for a specific content type is changed using
119 // the Website Settings UI.
120 UMA_HISTOGRAM_COUNTS("WebsiteSettings.PermissionChanged", type);
121
[email protected]df818272012-04-20 13:10:50122 ContentSettingsPattern primary_pattern;
123 ContentSettingsPattern secondary_pattern;
124 switch (type) {
125 case CONTENT_SETTINGS_TYPE_GEOLOCATION:
[email protected]eb2140c2013-07-29 12:37:34126 case CONTENT_SETTINGS_TYPE_MIDI_SYSEX:
[email protected]df818272012-04-20 13:10:50127 // TODO(markusheintz): The rule we create here should also change the
128 // location permission for iframed content.
129 primary_pattern = ContentSettingsPattern::FromURLNoWildcard(site_url_);
130 secondary_pattern = ContentSettingsPattern::FromURLNoWildcard(site_url_);
131 break;
132 case CONTENT_SETTINGS_TYPE_NOTIFICATIONS:
133 primary_pattern = ContentSettingsPattern::FromURLNoWildcard(site_url_);
134 secondary_pattern = ContentSettingsPattern::Wildcard();
135 break;
[email protected]b1d113d2012-06-27 21:27:34136 case CONTENT_SETTINGS_TYPE_IMAGES:
137 case CONTENT_SETTINGS_TYPE_JAVASCRIPT:
[email protected]df818272012-04-20 13:10:50138 case CONTENT_SETTINGS_TYPE_PLUGINS:
139 case CONTENT_SETTINGS_TYPE_POPUPS:
[email protected]b1d113d2012-06-27 21:27:34140 case CONTENT_SETTINGS_TYPE_FULLSCREEN:
141 case CONTENT_SETTINGS_TYPE_MOUSELOCK:
[email protected]ad635b12013-07-22 21:53:27142 case CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS:
[email protected]df818272012-04-20 13:10:50143 primary_pattern = ContentSettingsPattern::FromURL(site_url_);
144 secondary_pattern = ContentSettingsPattern::Wildcard();
145 break;
[email protected]0bacc1912012-12-11 11:05:34146 case CONTENT_SETTINGS_TYPE_MEDIASTREAM: {
147 // We need to use the same same patterns as other places like infobar code
148 // to override the existing rule instead of creating the new one.
149 primary_pattern = ContentSettingsPattern::FromURLNoWildcard(site_url_);
150 secondary_pattern = ContentSettingsPattern::Wildcard();
151 // Set permission for both microphone and camera.
152 content_settings_->SetContentSetting(
[email protected]007b3f82013-04-09 08:46:45153 primary_pattern,
154 secondary_pattern,
155 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC,
156 std::string(),
157 setting);
[email protected]0bacc1912012-12-11 11:05:34158
159 content_settings_->SetContentSetting(
[email protected]007b3f82013-04-09 08:46:45160 primary_pattern,
161 secondary_pattern,
162 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA,
163 std::string(),
164 setting);
[email protected]0bacc1912012-12-11 11:05:34165 break;
166 }
[email protected]df818272012-04-20 13:10:50167 default:
168 NOTREACHED() << "ContentSettingsType " << type << "is not supported.";
169 break;
[email protected]0b9fdd72012-04-04 10:00:33170 }
171
[email protected]0bacc1912012-12-11 11:05:34172 if (type != CONTENT_SETTINGS_TYPE_MEDIASTREAM) {
173 // Permission settings are specified via rules. There exists always at least
174 // one rule for the default setting. Get the rule that currently defines
175 // the permission for the given permission |type|. Then test whether the
176 // existing rule is more specific than the rule we are about to create. If
177 // the existing rule is more specific, than change the existing rule instead
178 // of creating a new rule that would be hidden behind the existing rule.
179 // This is not a concern for CONTENT_SETTINGS_TYPE_MEDIASTREAM since users
180 // can not create media settings exceptions by hand.
181 content_settings::SettingInfo info;
182 scoped_ptr<Value> v(content_settings_->GetWebsiteSetting(
[email protected]007b3f82013-04-09 08:46:45183 site_url_, site_url_, type, std::string(), &info));
[email protected]0bacc1912012-12-11 11:05:34184 DCHECK(info.source == content_settings::SETTING_SOURCE_USER);
185 ContentSettingsPattern::Relation r1 =
186 info.primary_pattern.Compare(primary_pattern);
187 DCHECK(r1 != ContentSettingsPattern::DISJOINT_ORDER_POST &&
188 r1 != ContentSettingsPattern::DISJOINT_ORDER_PRE);
189 if (r1 == ContentSettingsPattern::PREDECESSOR) {
190 primary_pattern = info.primary_pattern;
191 } else if (r1 == ContentSettingsPattern::IDENTITY) {
192 ContentSettingsPattern::Relation r2 =
193 info.secondary_pattern.Compare(secondary_pattern);
194 DCHECK(r2 != ContentSettingsPattern::DISJOINT_ORDER_POST &&
195 r2 != ContentSettingsPattern::DISJOINT_ORDER_PRE);
196 if (r2 == ContentSettingsPattern::PREDECESSOR)
197 secondary_pattern = info.secondary_pattern;
198 }
199
200 Value* value = NULL;
201 if (setting != CONTENT_SETTING_DEFAULT)
202 value = Value::CreateIntegerValue(setting);
203 content_settings_->SetWebsiteSetting(
[email protected]007b3f82013-04-09 08:46:45204 primary_pattern, secondary_pattern, type, std::string(), value);
[email protected]df818272012-04-20 13:10:50205 }
206
[email protected]66f157312012-08-01 13:50:26207 show_info_bar_ = true;
[email protected]2f45d542012-08-22 08:47:24208
[email protected]76955932012-12-06 11:01:10209// TODO(markusheintz): This is a temporary hack to fix issue:
210// http://crbug.com/144203.
[email protected]e379ba42012-08-22 22:40:25211#if defined(OS_MACOSX)
[email protected]2f45d542012-08-22 08:47:24212 // Refresh the UI to reflect the new setting.
213 PresentSitePermissions();
[email protected]e379ba42012-08-22 22:40:25214#endif
[email protected]df818272012-04-20 13:10:50215}
216
[email protected]15b092542012-05-16 13:08:14217void WebsiteSettings::OnGotVisitCountToHost(HistoryService::Handle handle,
218 bool found_visits,
219 int visit_count,
220 base::Time first_visit) {
221 if (!found_visits) {
222 // This indicates an error, such as the page's URL scheme wasn't
223 // http/https.
224 first_visit = base::Time();
225 } else if (visit_count == 0) {
226 first_visit = base::Time::Now();
227 }
228 PresentHistoryInfo(first_visit);
229}
230
[email protected]df818272012-04-20 13:10:50231void WebsiteSettings::OnSiteDataAccessed() {
232 PresentSiteData();
[email protected]0b9fdd72012-04-04 10:00:33233}
234
[email protected]66f157312012-08-01 13:50:26235void WebsiteSettings::OnUIClosing() {
[email protected]0be09932013-01-08 02:03:50236 if (show_info_bar_)
[email protected]ed9bc652013-07-11 17:17:36237 WebsiteSettingsInfoBarDelegate::Create(infobar_service_);
[email protected]66f157312012-08-01 13:50:26238}
239
[email protected]0b9fdd72012-04-04 10:00:33240void WebsiteSettings::Init(Profile* profile,
241 const GURL& url,
242 const content::SSLStatus& ssl) {
[email protected]03ef4b2a2012-03-06 15:04:20243 if (url.SchemeIs(chrome::kChromeUIScheme)) {
244 site_identity_status_ = SITE_IDENTITY_STATUS_INTERNAL_PAGE;
245 site_identity_details_ =
246 l10n_util::GetStringUTF16(IDS_PAGE_INFO_INTERNAL_PAGE);
247 site_connection_status_ = SITE_CONNECTION_STATUS_INTERNAL_PAGE;
248 return;
249 }
250
251 scoped_refptr<net::X509Certificate> cert;
252
253 // Identity section.
254 string16 subject_name(UTF8ToUTF16(url.host()));
[email protected]03ef4b2a2012-03-06 15:04:20255 if (subject_name.empty()) {
256 subject_name.assign(
257 l10n_util::GetStringUTF16(IDS_PAGE_INFO_SECURITY_TAB_UNKNOWN_PARTY));
[email protected]03ef4b2a2012-03-06 15:04:20258 }
259
[email protected]f61c1ce2012-05-09 13:55:11260 cert_id_ = ssl.cert_id;
261
[email protected]03ef4b2a2012-03-06 15:04:20262 if (ssl.cert_id &&
263 cert_store_->RetrieveCert(ssl.cert_id, &cert) &&
264 (!net::IsCertStatusError(ssl.cert_status) ||
265 net::IsCertStatusMinorError(ssl.cert_status))) {
266 // There are no major errors. Check for minor errors.
[email protected]d81bb3e2013-05-02 18:17:03267 if (policy::ProfilePolicyConnectorFactory::GetForProfile(profile)->
268 UsedPolicyCertificates()) {
[email protected]eaf3f322013-04-25 21:53:59269 site_identity_status_ = SITE_IDENTITY_STATUS_ADMIN_PROVIDED_CERT;
270 site_identity_details_ =
271 l10n_util::GetStringFUTF16(IDS_CERT_POLICY_PROVIDED_CERT_MESSAGE,
272 UTF8ToUTF16(url.host()));
273 } else if (net::IsCertStatusMinorError(ssl.cert_status)) {
[email protected]03ef4b2a2012-03-06 15:04:20274 site_identity_status_ = SITE_IDENTITY_STATUS_CERT_REVOCATION_UNKNOWN;
275 string16 issuer_name(UTF8ToUTF16(cert->issuer().GetDisplayName()));
276 if (issuer_name.empty()) {
277 issuer_name.assign(l10n_util::GetStringUTF16(
278 IDS_PAGE_INFO_SECURITY_TAB_UNKNOWN_PARTY));
279 }
280 site_identity_details_.assign(l10n_util::GetStringFUTF16(
281 IDS_PAGE_INFO_SECURITY_TAB_SECURE_IDENTITY, issuer_name));
282
283 site_identity_details_ += ASCIIToUTF16("\n\n");
284 if (ssl.cert_status & net::CERT_STATUS_UNABLE_TO_CHECK_REVOCATION) {
285 site_identity_details_ += l10n_util::GetStringUTF16(
286 IDS_PAGE_INFO_SECURITY_TAB_UNABLE_TO_CHECK_REVOCATION);
287 } else if (ssl.cert_status & net::CERT_STATUS_NO_REVOCATION_MECHANISM) {
288 site_identity_details_ += l10n_util::GetStringUTF16(
289 IDS_PAGE_INFO_SECURITY_TAB_NO_REVOCATION_MECHANISM);
290 } else {
291 NOTREACHED() << "Need to specify string for this warning";
292 }
293 } else if (ssl.cert_status & net::CERT_STATUS_IS_EV) {
294 // EV HTTPS page.
295 site_identity_status_ = SITE_IDENTITY_STATUS_EV_CERT;
296 DCHECK(!cert->subject().organization_names.empty());
297 organization_name_ = UTF8ToUTF16(cert->subject().organization_names[0]);
298 // An EV Cert is required to have a city (localityName) and country but
299 // state is "if any".
300 DCHECK(!cert->subject().locality_name.empty());
301 DCHECK(!cert->subject().country_name.empty());
302 string16 locality;
303 if (!cert->subject().state_or_province_name.empty()) {
304 locality = l10n_util::GetStringFUTF16(
305 IDS_PAGEINFO_ADDRESS,
306 UTF8ToUTF16(cert->subject().locality_name),
307 UTF8ToUTF16(cert->subject().state_or_province_name),
308 UTF8ToUTF16(cert->subject().country_name));
309 } else {
310 locality = l10n_util::GetStringFUTF16(
311 IDS_PAGEINFO_PARTIAL_ADDRESS,
312 UTF8ToUTF16(cert->subject().locality_name),
313 UTF8ToUTF16(cert->subject().country_name));
314 }
315 DCHECK(!cert->subject().organization_names.empty());
316 site_identity_details_.assign(l10n_util::GetStringFUTF16(
317 IDS_PAGE_INFO_SECURITY_TAB_SECURE_IDENTITY_EV,
318 UTF8ToUTF16(cert->subject().organization_names[0]),
319 locality,
320 UTF8ToUTF16(cert->issuer().GetDisplayName())));
[email protected]03ef4b2a2012-03-06 15:04:20321 } else {
322 // Non-EV OK HTTPS page.
323 site_identity_status_ = SITE_IDENTITY_STATUS_CERT;
324 string16 issuer_name(UTF8ToUTF16(cert->issuer().GetDisplayName()));
325 if (issuer_name.empty()) {
326 issuer_name.assign(l10n_util::GetStringUTF16(
327 IDS_PAGE_INFO_SECURITY_TAB_UNKNOWN_PARTY));
328 }
329 site_identity_details_.assign(l10n_util::GetStringFUTF16(
330 IDS_PAGE_INFO_SECURITY_TAB_SECURE_IDENTITY, issuer_name));
331 }
332 } else {
333 // HTTP or HTTPS with errors (not warnings).
334 site_identity_details_.assign(l10n_util::GetStringUTF16(
335 IDS_PAGE_INFO_SECURITY_TAB_INSECURE_IDENTITY));
336 if (ssl.security_style == content::SECURITY_STYLE_UNAUTHENTICATED)
337 site_identity_status_ = SITE_IDENTITY_STATUS_NO_CERT;
338 else
339 site_identity_status_ = SITE_IDENTITY_STATUS_ERROR;
340
341 const string16 bullet = UTF8ToUTF16("\n • ");
342 std::vector<SSLErrorInfo> errors;
343 SSLErrorInfo::GetErrorsForCertStatus(ssl.cert_id, ssl.cert_status,
344 url, &errors);
345 for (size_t i = 0; i < errors.size(); ++i) {
346 site_identity_details_ += bullet;
347 site_identity_details_ += errors[i].short_description();
348 }
349
350 if (ssl.cert_status & net::CERT_STATUS_NON_UNIQUE_NAME) {
351 site_identity_details_ += ASCIIToUTF16("\n\n");
352 site_identity_details_ += l10n_util::GetStringUTF16(
353 IDS_PAGE_INFO_SECURITY_TAB_NON_UNIQUE_NAME);
354 }
355 }
356
357 // Site Connection
358 // We consider anything less than 80 bits encryption to be weak encryption.
359 // TODO(wtc): Bug 1198735: report mixed/unsafe content for unencrypted and
360 // weakly encrypted connections.
361 site_connection_status_ = SITE_CONNECTION_STATUS_UNKNOWN;
362
363 if (!ssl.cert_id) {
364 // Not HTTPS.
365 DCHECK_EQ(ssl.security_style, content::SECURITY_STYLE_UNAUTHENTICATED);
366 if (ssl.security_style == content::SECURITY_STYLE_UNAUTHENTICATED)
367 site_connection_status_ = SITE_CONNECTION_STATUS_UNENCRYPTED;
368 else
369 site_connection_status_ = SITE_CONNECTION_STATUS_ENCRYPTED_ERROR;
370
371 site_connection_details_.assign(l10n_util::GetStringFUTF16(
372 IDS_PAGE_INFO_SECURITY_TAB_NOT_ENCRYPTED_CONNECTION_TEXT,
373 subject_name));
374 } else if (ssl.security_bits < 0) {
375 // Security strength is unknown. Say nothing.
376 site_connection_status_ = SITE_CONNECTION_STATUS_ENCRYPTED_ERROR;
377 } else if (ssl.security_bits == 0) {
378 DCHECK_NE(ssl.security_style, content::SECURITY_STYLE_UNAUTHENTICATED);
379 site_connection_status_ = SITE_CONNECTION_STATUS_ENCRYPTED_ERROR;
380 site_connection_details_.assign(l10n_util::GetStringFUTF16(
381 IDS_PAGE_INFO_SECURITY_TAB_NOT_ENCRYPTED_CONNECTION_TEXT,
382 subject_name));
383 } else if (ssl.security_bits < 80) {
384 site_connection_status_ = SITE_CONNECTION_STATUS_ENCRYPTED_ERROR;
385 site_connection_details_.assign(l10n_util::GetStringFUTF16(
386 IDS_PAGE_INFO_SECURITY_TAB_WEAK_ENCRYPTION_CONNECTION_TEXT,
387 subject_name));
388 } else {
389 site_connection_status_ = SITE_CONNECTION_STATUS_ENCRYPTED;
390 site_connection_details_.assign(l10n_util::GetStringFUTF16(
391 IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTED_CONNECTION_TEXT,
392 subject_name,
393 base::IntToString16(ssl.security_bits)));
394 if (ssl.content_status) {
395 bool ran_insecure_content =
396 !!(ssl.content_status & content::SSLStatus::RAN_INSECURE_CONTENT);
397 site_connection_status_ = ran_insecure_content ?
398 SITE_CONNECTION_STATUS_ENCRYPTED_ERROR
399 : SITE_CONNECTION_STATUS_MIXED_CONTENT;
400 site_connection_details_.assign(l10n_util::GetStringFUTF16(
401 IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTED_SENTENCE_LINK,
402 site_connection_details_,
403 l10n_util::GetStringUTF16(ran_insecure_content ?
404 IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTED_INSECURE_CONTENT_ERROR :
405 IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTED_INSECURE_CONTENT_WARNING)));
406 }
407 }
408
409 uint16 cipher_suite =
410 net::SSLConnectionStatusToCipherSuite(ssl.connection_status);
411 if (ssl.security_bits > 0 && cipher_suite) {
412 int ssl_version =
413 net::SSLConnectionStatusToVersion(ssl.connection_status);
414 const char* ssl_version_str;
415 net::SSLVersionToString(&ssl_version_str, ssl_version);
416 site_connection_details_ += ASCIIToUTF16("\n\n");
417 site_connection_details_ += l10n_util::GetStringFUTF16(
418 IDS_PAGE_INFO_SECURITY_TAB_SSL_VERSION,
419 ASCIIToUTF16(ssl_version_str));
420
421 bool did_fallback = (ssl.connection_status &
[email protected]80c75f682012-05-26 16:22:17422 net::SSL_CONNECTION_VERSION_FALLBACK) != 0;
[email protected]03ef4b2a2012-03-06 15:04:20423 bool no_renegotiation =
424 (ssl.connection_status &
425 net::SSL_CONNECTION_NO_RENEGOTIATION_EXTENSION) != 0;
426 const char *key_exchange, *cipher, *mac;
[email protected]b6c1d9e82013-06-12 17:26:57427 bool is_aead;
428 net::SSLCipherSuiteToStrings(
429 &key_exchange, &cipher, &mac, &is_aead, cipher_suite);
[email protected]03ef4b2a2012-03-06 15:04:20430
431 site_connection_details_ += ASCIIToUTF16("\n\n");
[email protected]b6c1d9e82013-06-12 17:26:57432 if (is_aead) {
433 site_connection_details_ += l10n_util::GetStringFUTF16(
434 IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTION_DETAILS_AEAD,
435 ASCIIToUTF16(cipher), ASCIIToUTF16(key_exchange));
436 } else {
437 site_connection_details_ += l10n_util::GetStringFUTF16(
438 IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTION_DETAILS,
439 ASCIIToUTF16(cipher), ASCIIToUTF16(mac), ASCIIToUTF16(key_exchange));
440 }
[email protected]03ef4b2a2012-03-06 15:04:20441
[email protected]03ef4b2a2012-03-06 15:04:20442 if (did_fallback) {
443 // For now, only SSLv3 fallback will trigger a warning icon.
444 if (site_connection_status_ < SITE_CONNECTION_STATUS_MIXED_CONTENT)
445 site_connection_status_ = SITE_CONNECTION_STATUS_MIXED_CONTENT;
446 site_connection_details_ += ASCIIToUTF16("\n\n");
447 site_connection_details_ += l10n_util::GetStringUTF16(
448 IDS_PAGE_INFO_SECURITY_TAB_FALLBACK_MESSAGE);
449 }
450 if (no_renegotiation) {
451 site_connection_details_ += ASCIIToUTF16("\n\n");
452 site_connection_details_ += l10n_util::GetStringUTF16(
453 IDS_PAGE_INFO_SECURITY_TAB_RENEGOTIATION_MESSAGE);
454 }
455 }
[email protected]e583f752012-08-30 13:26:21456
457 // By default select the permissions tab that displays all the site
458 // permissions. In case of a connection error or an issue with the
459 // certificate presented by the website, select the connection tab to draw
460 // the user's attention to the issue. If the site does not provide a
461 // certificate because it was loaded over an unencrypted connection, don't
462 // select the connection tab.
463 WebsiteSettingsUI::TabId tab_id = WebsiteSettingsUI::TAB_ID_PERMISSIONS;
464 if (site_connection_status_ == SITE_CONNECTION_STATUS_ENCRYPTED_ERROR ||
465 site_connection_status_ == SITE_CONNECTION_STATUS_MIXED_CONTENT ||
466 site_identity_status_ == SITE_IDENTITY_STATUS_ERROR ||
[email protected]eaf3f322013-04-25 21:53:59467 site_identity_status_ == SITE_IDENTITY_STATUS_CERT_REVOCATION_UNKNOWN ||
468 site_identity_status_ == SITE_IDENTITY_STATUS_ADMIN_PROVIDED_CERT)
[email protected]e583f752012-08-30 13:26:21469 tab_id = WebsiteSettingsUI::TAB_ID_CONNECTION;
470 ui_->SetSelectedTab(tab_id);
[email protected]03ef4b2a2012-03-06 15:04:20471}
[email protected]0b9fdd72012-04-04 10:00:33472
[email protected]df818272012-04-20 13:10:50473void WebsiteSettings::PresentSitePermissions() {
474 PermissionInfoList permission_info_list;
475
476 WebsiteSettingsUI::PermissionInfo permission_info;
477 for (size_t i = 0; i < arraysize(kPermissionType); ++i) {
478 permission_info.type = kPermissionType[i];
[email protected]eb2140c2013-07-29 12:37:34479 if (permission_info.type == CONTENT_SETTINGS_TYPE_MIDI_SYSEX) {
480 const CommandLine* command_line = CommandLine::ForCurrentProcess();
481 if (!command_line->HasSwitch(switches::kEnableWebMIDI))
482 continue;
483 }
[email protected]df818272012-04-20 13:10:50484
485 content_settings::SettingInfo info;
[email protected]0bacc1912012-12-11 11:05:34486 if (permission_info.type == CONTENT_SETTINGS_TYPE_MEDIASTREAM) {
487 scoped_ptr<base::Value> mic_value(content_settings_->GetWebsiteSetting(
[email protected]007b3f82013-04-09 08:46:45488 site_url_,
489 site_url_,
490 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC,
491 std::string(),
492 &info));
[email protected]0bacc1912012-12-11 11:05:34493 ContentSetting mic_setting =
494 content_settings::ValueToContentSetting(mic_value.get());
495
496 scoped_ptr<base::Value> camera_value(content_settings_->GetWebsiteSetting(
[email protected]007b3f82013-04-09 08:46:45497 site_url_,
498 site_url_,
499 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA,
500 std::string(),
501 &info));
[email protected]0bacc1912012-12-11 11:05:34502 ContentSetting camera_setting =
503 content_settings::ValueToContentSetting(camera_value.get());
504
505 if (mic_setting != camera_setting || mic_setting == CONTENT_SETTING_ASK)
506 permission_info.setting = CONTENT_SETTING_DEFAULT;
507 else
508 permission_info.setting = mic_setting;
[email protected]fe4686a2012-10-19 15:38:26509 } else {
[email protected]0bacc1912012-12-11 11:05:34510 scoped_ptr<Value> value(content_settings_->GetWebsiteSetting(
[email protected]007b3f82013-04-09 08:46:45511 site_url_, site_url_, permission_info.type, std::string(), &info));
[email protected]0bacc1912012-12-11 11:05:34512 DCHECK(value.get());
513 if (value->GetType() == Value::TYPE_INTEGER) {
514 permission_info.setting =
515 content_settings::ValueToContentSetting(value.get());
516 } else {
517 NOTREACHED();
518 }
[email protected]fe4686a2012-10-19 15:38:26519 }
520
[email protected]8bdf45c32012-08-04 00:12:55521 permission_info.source = info.source;
[email protected]df818272012-04-20 13:10:50522
[email protected]b1d113d2012-06-27 21:27:34523 if (info.primary_pattern == ContentSettingsPattern::Wildcard() &&
[email protected]0bacc1912012-12-11 11:05:34524 info.secondary_pattern == ContentSettingsPattern::Wildcard() &&
525 permission_info.type != CONTENT_SETTINGS_TYPE_MEDIASTREAM) {
[email protected]b1d113d2012-06-27 21:27:34526 permission_info.default_setting = permission_info.setting;
527 permission_info.setting = CONTENT_SETTING_DEFAULT;
528 } else {
529 permission_info.default_setting =
530 content_settings_->GetDefaultContentSetting(permission_info.type,
531 NULL);
[email protected]df818272012-04-20 13:10:50532 }
[email protected]b1d113d2012-06-27 21:27:34533 permission_info_list.push_back(permission_info);
[email protected]df818272012-04-20 13:10:50534 }
535
536 ui_->SetPermissionInfo(permission_info_list);
[email protected]0b9fdd72012-04-04 10:00:33537}
538
[email protected]df818272012-04-20 13:10:50539void WebsiteSettings::PresentSiteData() {
540 CookieInfoList cookie_info_list;
[email protected]e0ac35892012-05-15 12:53:34541 const LocalSharedObjectsContainer& allowed_objects =
542 tab_specific_content_settings()->allowed_local_shared_objects();
543 const LocalSharedObjectsContainer& blocked_objects =
544 tab_specific_content_settings()->blocked_local_shared_objects();
545
546 // Add first party cookie and site data counts.
[email protected]df818272012-04-20 13:10:50547 WebsiteSettingsUI::CookieInfo cookie_info;
[email protected]e0ac35892012-05-15 12:53:34548 std::string cookie_source =
[email protected]ed32c212013-05-14 20:49:29549 net::registry_controlled_domains::GetDomainAndRegistry(
550 site_url_,
551 net::registry_controlled_domains::EXCLUDE_PRIVATE_REGISTRIES);
[email protected]e0ac35892012-05-15 12:53:34552 if (cookie_source.empty())
553 cookie_source = site_url_.host();
554 cookie_info.cookie_source = cookie_source;
555 cookie_info.allowed = allowed_objects.GetObjectCountForDomain(site_url_);
556 cookie_info.blocked = blocked_objects.GetObjectCountForDomain(site_url_);
557 cookie_info_list.push_back(cookie_info);
558
559 // Add third party cookie counts.
560 cookie_info.cookie_source = l10n_util::GetStringUTF8(
561 IDS_WEBSITE_SETTINGS_THIRD_PARTY_SITE_DATA);
562 cookie_info.allowed = allowed_objects.GetObjectCount() - cookie_info.allowed;
563 cookie_info.blocked = blocked_objects.GetObjectCount() - cookie_info.blocked;
[email protected]df818272012-04-20 13:10:50564 cookie_info_list.push_back(cookie_info);
[email protected]0b9fdd72012-04-04 10:00:33565
[email protected]df818272012-04-20 13:10:50566 ui_->SetCookieInfo(cookie_info_list);
[email protected]0b9fdd72012-04-04 10:00:33567}
[email protected]16de6de2012-04-04 12:24:14568
[email protected]24c8818c2012-04-25 09:57:41569void WebsiteSettings::PresentSiteIdentity() {
570 // After initialization the status about the site's connection
571 // and it's identity must be available.
572 DCHECK_NE(site_identity_status_, SITE_IDENTITY_STATUS_UNKNOWN);
573 DCHECK_NE(site_connection_status_, SITE_CONNECTION_STATUS_UNKNOWN);
574 WebsiteSettingsUI::IdentityInfo info;
575 if (site_identity_status_ == SITE_IDENTITY_STATUS_EV_CERT)
576 info.site_identity = UTF16ToUTF8(organization_name());
577 else
578 info.site_identity = site_url_.host();
579
580 info.connection_status = site_connection_status_;
581 info.connection_status_description =
582 UTF16ToUTF8(site_connection_details_);
583 info.identity_status = site_identity_status_;
584 info.identity_status_description =
585 UTF16ToUTF8(site_identity_details_);
[email protected]f61c1ce2012-05-09 13:55:11586 info.cert_id = cert_id_;
[email protected]24c8818c2012-04-25 09:57:41587 ui_->SetIdentityInfo(info);
588}
589
[email protected]15b092542012-05-16 13:08:14590void WebsiteSettings::PresentHistoryInfo(base::Time first_visit) {
591 if (first_visit == base::Time()) {
592 ui_->SetFirstVisit(string16());
593 return;
594 }
595
596 bool visited_before_today = false;
597 base::Time today = base::Time::Now().LocalMidnight();
598 base::Time first_visit_midnight = first_visit.LocalMidnight();
599 visited_before_today = (first_visit_midnight < today);
600
601 string16 first_visit_text;
602 if (visited_before_today) {
603 first_visit_text = l10n_util::GetStringFUTF16(
604 IDS_PAGE_INFO_SECURITY_TAB_VISITED_BEFORE_TODAY,
605 base::TimeFormatShortDate(first_visit));
606 } else {
607 first_visit_text = l10n_util::GetStringUTF16(
608 IDS_PAGE_INFO_SECURITY_TAB_FIRST_VISITED_TODAY);
609
610 }
611 ui_->SetFirstVisit(first_visit_text);
612}