[email protected] | 03ef4b2a | 2012-03-06 15:04:20 | [diff] [blame] | 1 | // 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] | 4237dd5 | 2012-06-05 00:00:32 | [diff] [blame] | 5 | #include "chrome/browser/ui/website_settings/website_settings.h" |
[email protected] | 03ef4b2a | 2012-03-06 15:04:20 | [diff] [blame] | 6 | |
| 7 | #include <string> |
| 8 | #include <vector> |
| 9 | |
[email protected] | 15b09254 | 2012-05-16 13:08:14 | [diff] [blame] | 10 | #include "base/bind.h" |
| 11 | #include "base/bind_helpers.h" |
| 12 | #include "base/i18n/time_formatting.h" |
[email protected] | 03ef4b2a | 2012-03-06 15:04:20 | [diff] [blame] | 13 | #include "base/string_number_conversions.h" |
| 14 | #include "base/utf_string_conversions.h" |
[email protected] | 0b9fdd7 | 2012-04-04 10:00:33 | [diff] [blame] | 15 | #include "base/values.h" |
[email protected] | b0cb5e8 | 2012-07-19 19:22:47 | [diff] [blame] | 16 | #include "chrome/browser/browsing_data/browsing_data_cookie_helper.h" |
| 17 | #include "chrome/browser/browsing_data/browsing_data_database_helper.h" |
| 18 | #include "chrome/browser/browsing_data/browsing_data_file_system_helper.h" |
| 19 | #include "chrome/browser/browsing_data/browsing_data_indexed_db_helper.h" |
| 20 | #include "chrome/browser/browsing_data/browsing_data_local_storage_helper.h" |
| 21 | #include "chrome/browser/browsing_data/browsing_data_server_bound_cert_helper.h" |
[email protected] | 0b9fdd7 | 2012-04-04 10:00:33 | [diff] [blame] | 22 | #include "chrome/browser/content_settings/content_settings_utils.h" |
| 23 | #include "chrome/browser/content_settings/host_content_settings_map.h" |
[email protected] | df81827 | 2012-04-20 13:10:50 | [diff] [blame] | 24 | #include "chrome/browser/content_settings/local_shared_objects_container.h" |
[email protected] | 66f15731 | 2012-08-01 13:50:26 | [diff] [blame^] | 25 | #include "chrome/browser/infobars/infobar_tab_helper.h" |
[email protected] | 03ef4b2a | 2012-03-06 15:04:20 | [diff] [blame] | 26 | #include "chrome/browser/profiles/profile.h" |
[email protected] | 78a1fd90a | 2012-07-19 08:11:25 | [diff] [blame] | 27 | #include "chrome/browser/history/history_service_factory.h" |
[email protected] | 03ef4b2a | 2012-03-06 15:04:20 | [diff] [blame] | 28 | #include "chrome/browser/ssl/ssl_error_info.h" |
[email protected] | 66f15731 | 2012-08-01 13:50:26 | [diff] [blame^] | 29 | #include "chrome/browser/ui/website_settings/website_settings_infobar_delegate.h" |
[email protected] | 4237dd5 | 2012-06-05 00:00:32 | [diff] [blame] | 30 | #include "chrome/browser/ui/website_settings/website_settings_ui.h" |
[email protected] | 0b9fdd7 | 2012-04-04 10:00:33 | [diff] [blame] | 31 | #include "chrome/common/content_settings_pattern.h" |
| 32 | #include "content/public/browser/browser_thread.h" |
[email protected] | b59c6cf0 | 2012-03-12 20:51:42 | [diff] [blame] | 33 | #include "content/public/browser/cert_store.h" |
[email protected] | 03ef4b2a | 2012-03-06 15:04:20 | [diff] [blame] | 34 | #include "content/public/common/ssl_status.h" |
| 35 | #include "content/public/common/url_constants.h" |
| 36 | #include "grit/chromium_strings.h" |
| 37 | #include "grit/generated_resources.h" |
| 38 | #include "net/base/cert_status_flags.h" |
[email protected] | be28b5f4 | 2012-07-20 11:31:25 | [diff] [blame] | 39 | #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
[email protected] | 03ef4b2a | 2012-03-06 15:04:20 | [diff] [blame] | 40 | #include "net/base/ssl_cipher_suite_names.h" |
| 41 | #include "net/base/ssl_connection_status_flags.h" |
| 42 | #include "net/base/x509_certificate.h" |
| 43 | #include "ui/base/l10n/l10n_util.h" |
| 44 | #include "ui/base/resource/resource_bundle.h" |
| 45 | |
[email protected] | 0b9fdd7 | 2012-04-04 10:00:33 | [diff] [blame] | 46 | using content::BrowserThread; |
| 47 | |
| 48 | namespace { |
| 49 | |
[email protected] | b1d113d | 2012-06-27 21:27:34 | [diff] [blame] | 50 | // The list of content settings types to display on the Website Settings UI. |
[email protected] | 0b9fdd7 | 2012-04-04 10:00:33 | [diff] [blame] | 51 | ContentSettingsType kPermissionType[] = { |
[email protected] | b1d113d | 2012-06-27 21:27:34 | [diff] [blame] | 52 | CONTENT_SETTINGS_TYPE_IMAGES, |
| 53 | CONTENT_SETTINGS_TYPE_JAVASCRIPT, |
[email protected] | 0b9fdd7 | 2012-04-04 10:00:33 | [diff] [blame] | 54 | CONTENT_SETTINGS_TYPE_PLUGINS, |
[email protected] | b1d113d | 2012-06-27 21:27:34 | [diff] [blame] | 55 | CONTENT_SETTINGS_TYPE_POPUPS, |
[email protected] | 0b9fdd7 | 2012-04-04 10:00:33 | [diff] [blame] | 56 | CONTENT_SETTINGS_TYPE_GEOLOCATION, |
[email protected] | b1d113d | 2012-06-27 21:27:34 | [diff] [blame] | 57 | CONTENT_SETTINGS_TYPE_NOTIFICATIONS, |
| 58 | CONTENT_SETTINGS_TYPE_FULLSCREEN, |
| 59 | CONTENT_SETTINGS_TYPE_MOUSELOCK, |
| 60 | CONTENT_SETTINGS_TYPE_MEDIASTREAM, |
[email protected] | 0b9fdd7 | 2012-04-04 10:00:33 | [diff] [blame] | 61 | }; |
| 62 | |
| 63 | } // namespace |
| 64 | |
| 65 | WebsiteSettings::WebsiteSettings( |
| 66 | WebsiteSettingsUI* ui, |
| 67 | Profile* profile, |
[email protected] | df81827 | 2012-04-20 13:10:50 | [diff] [blame] | 68 | TabSpecificContentSettings* tab_specific_content_settings, |
[email protected] | 66f15731 | 2012-08-01 13:50:26 | [diff] [blame^] | 69 | InfoBarTabHelper* infobar_tab_helper, |
[email protected] | 0b9fdd7 | 2012-04-04 10:00:33 | [diff] [blame] | 70 | const GURL& url, |
| 71 | const content::SSLStatus& ssl, |
| 72 | content::CertStore* cert_store) |
[email protected] | df81827 | 2012-04-20 13:10:50 | [diff] [blame] | 73 | : TabSpecificContentSettings::SiteDataObserver( |
| 74 | tab_specific_content_settings), |
| 75 | ui_(ui), |
[email protected] | 66f15731 | 2012-08-01 13:50:26 | [diff] [blame^] | 76 | infobar_helper_(infobar_tab_helper), |
| 77 | show_info_bar_(false), |
[email protected] | 0b9fdd7 | 2012-04-04 10:00:33 | [diff] [blame] | 78 | site_url_(url), |
| 79 | site_identity_status_(SITE_IDENTITY_STATUS_UNKNOWN), |
[email protected] | f61c1ce | 2012-05-09 13:55:11 | [diff] [blame] | 80 | cert_id_(0), |
[email protected] | 03ef4b2a | 2012-03-06 15:04:20 | [diff] [blame] | 81 | site_connection_status_(SITE_CONNECTION_STATUS_UNKNOWN), |
[email protected] | 0b9fdd7 | 2012-04-04 10:00:33 | [diff] [blame] | 82 | cert_store_(cert_store), |
| 83 | content_settings_(profile->GetHostContentSettingsMap()) { |
[email protected] | 03ef4b2a | 2012-03-06 15:04:20 | [diff] [blame] | 84 | Init(profile, url, ssl); |
[email protected] | 0b9fdd7 | 2012-04-04 10:00:33 | [diff] [blame] | 85 | |
[email protected] | 78a1fd90a | 2012-07-19 08:11:25 | [diff] [blame] | 86 | HistoryService* history_service = HistoryServiceFactory::GetForProfile( |
| 87 | profile, Profile::EXPLICIT_ACCESS); |
[email protected] | 15b09254 | 2012-05-16 13:08:14 | [diff] [blame] | 88 | if (history_service) { |
| 89 | history_service->GetVisibleVisitCountToHost( |
| 90 | site_url_, |
| 91 | &visit_count_request_consumer_, |
| 92 | base::Bind(&WebsiteSettings::OnGotVisitCountToHost, |
| 93 | base::Unretained(this))); |
| 94 | } |
| 95 | |
[email protected] | 0b9fdd7 | 2012-04-04 10:00:33 | [diff] [blame] | 96 | PresentSitePermissions(); |
[email protected] | df81827 | 2012-04-20 13:10:50 | [diff] [blame] | 97 | PresentSiteData(); |
[email protected] | 24c8818c | 2012-04-25 09:57:41 | [diff] [blame] | 98 | PresentSiteIdentity(); |
[email protected] | 15b09254 | 2012-05-16 13:08:14 | [diff] [blame] | 99 | PresentHistoryInfo(base::Time()); |
[email protected] | 03ef4b2a | 2012-03-06 15:04:20 | [diff] [blame] | 100 | } |
| 101 | |
[email protected] | 0b9fdd7 | 2012-04-04 10:00:33 | [diff] [blame] | 102 | WebsiteSettings::~WebsiteSettings() { |
[email protected] | 03ef4b2a | 2012-03-06 15:04:20 | [diff] [blame] | 103 | } |
| 104 | |
[email protected] | df81827 | 2012-04-20 13:10:50 | [diff] [blame] | 105 | void WebsiteSettings::OnSitePermissionChanged(ContentSettingsType type, |
| 106 | ContentSetting setting) { |
| 107 | ContentSettingsPattern primary_pattern; |
| 108 | ContentSettingsPattern secondary_pattern; |
| 109 | switch (type) { |
| 110 | case CONTENT_SETTINGS_TYPE_GEOLOCATION: |
| 111 | // TODO(markusheintz): The rule we create here should also change the |
| 112 | // location permission for iframed content. |
| 113 | primary_pattern = ContentSettingsPattern::FromURLNoWildcard(site_url_); |
| 114 | secondary_pattern = ContentSettingsPattern::FromURLNoWildcard(site_url_); |
| 115 | break; |
| 116 | case CONTENT_SETTINGS_TYPE_NOTIFICATIONS: |
| 117 | primary_pattern = ContentSettingsPattern::FromURLNoWildcard(site_url_); |
| 118 | secondary_pattern = ContentSettingsPattern::Wildcard(); |
| 119 | break; |
[email protected] | b1d113d | 2012-06-27 21:27:34 | [diff] [blame] | 120 | case CONTENT_SETTINGS_TYPE_IMAGES: |
| 121 | case CONTENT_SETTINGS_TYPE_JAVASCRIPT: |
[email protected] | df81827 | 2012-04-20 13:10:50 | [diff] [blame] | 122 | case CONTENT_SETTINGS_TYPE_PLUGINS: |
| 123 | case CONTENT_SETTINGS_TYPE_POPUPS: |
[email protected] | b1d113d | 2012-06-27 21:27:34 | [diff] [blame] | 124 | case CONTENT_SETTINGS_TYPE_FULLSCREEN: |
| 125 | case CONTENT_SETTINGS_TYPE_MOUSELOCK: |
| 126 | case CONTENT_SETTINGS_TYPE_MEDIASTREAM: |
[email protected] | df81827 | 2012-04-20 13:10:50 | [diff] [blame] | 127 | primary_pattern = ContentSettingsPattern::FromURL(site_url_); |
| 128 | secondary_pattern = ContentSettingsPattern::Wildcard(); |
| 129 | break; |
| 130 | default: |
| 131 | NOTREACHED() << "ContentSettingsType " << type << "is not supported."; |
| 132 | break; |
[email protected] | 0b9fdd7 | 2012-04-04 10:00:33 | [diff] [blame] | 133 | } |
| 134 | |
[email protected] | df81827 | 2012-04-20 13:10:50 | [diff] [blame] | 135 | // Permission settings are specified via rules. There exists always at least |
| 136 | // one rule for the default setting. Get the rule that currently defines |
| 137 | // the permission for the given permission |type|. Then test whether the |
| 138 | // existing rule is more specific than the rule we are about to create. If |
| 139 | // the existing rule is more specific, than change the existing rule instead |
| 140 | // of creating a new rule that would be hidden behind the existing rule. |
| 141 | content_settings::SettingInfo info; |
| 142 | scoped_ptr<Value> v(content_settings_->GetWebsiteSetting( |
| 143 | site_url_, site_url_, type, "", &info)); |
| 144 | DCHECK(info.source == content_settings::SETTING_SOURCE_USER); |
| 145 | ContentSettingsPattern::Relation r1 = |
| 146 | info.primary_pattern.Compare(primary_pattern); |
| 147 | DCHECK(r1 != ContentSettingsPattern::DISJOINT_ORDER_POST && |
| 148 | r1 != ContentSettingsPattern::DISJOINT_ORDER_PRE); |
| 149 | if (r1 == ContentSettingsPattern::PREDECESSOR) { |
| 150 | primary_pattern = info.primary_pattern; |
| 151 | } else if (r1 == ContentSettingsPattern::IDENTITY) { |
| 152 | ContentSettingsPattern::Relation r2 = |
| 153 | info.secondary_pattern.Compare(secondary_pattern); |
| 154 | DCHECK(r2 != ContentSettingsPattern::DISJOINT_ORDER_POST && |
| 155 | r2 != ContentSettingsPattern::DISJOINT_ORDER_PRE); |
| 156 | if (r2 == ContentSettingsPattern::PREDECESSOR) |
| 157 | secondary_pattern = info.secondary_pattern; |
| 158 | } |
| 159 | |
| 160 | Value* value = NULL; |
| 161 | if (setting != CONTENT_SETTING_DEFAULT) |
| 162 | value = Value::CreateIntegerValue(setting); |
| 163 | content_settings_->SetWebsiteSetting( |
| 164 | primary_pattern, secondary_pattern, type, "", value); |
[email protected] | 66f15731 | 2012-08-01 13:50:26 | [diff] [blame^] | 165 | show_info_bar_ = true; |
[email protected] | df81827 | 2012-04-20 13:10:50 | [diff] [blame] | 166 | } |
| 167 | |
[email protected] | 15b09254 | 2012-05-16 13:08:14 | [diff] [blame] | 168 | void WebsiteSettings::OnGotVisitCountToHost(HistoryService::Handle handle, |
| 169 | bool found_visits, |
| 170 | int visit_count, |
| 171 | base::Time first_visit) { |
| 172 | if (!found_visits) { |
| 173 | // This indicates an error, such as the page's URL scheme wasn't |
| 174 | // http/https. |
| 175 | first_visit = base::Time(); |
| 176 | } else if (visit_count == 0) { |
| 177 | first_visit = base::Time::Now(); |
| 178 | } |
| 179 | PresentHistoryInfo(first_visit); |
| 180 | } |
| 181 | |
[email protected] | df81827 | 2012-04-20 13:10:50 | [diff] [blame] | 182 | void WebsiteSettings::OnSiteDataAccessed() { |
| 183 | PresentSiteData(); |
[email protected] | 0b9fdd7 | 2012-04-04 10:00:33 | [diff] [blame] | 184 | } |
| 185 | |
[email protected] | 66f15731 | 2012-08-01 13:50:26 | [diff] [blame^] | 186 | void WebsiteSettings::OnUIClosing() { |
| 187 | if (show_info_bar_) { |
| 188 | infobar_helper_->AddInfoBar( |
| 189 | new WebsiteSettingsInfobarDelegate(infobar_helper_)); |
| 190 | } |
| 191 | } |
| 192 | |
[email protected] | 0b9fdd7 | 2012-04-04 10:00:33 | [diff] [blame] | 193 | void WebsiteSettings::Init(Profile* profile, |
| 194 | const GURL& url, |
| 195 | const content::SSLStatus& ssl) { |
[email protected] | 03ef4b2a | 2012-03-06 15:04:20 | [diff] [blame] | 196 | if (url.SchemeIs(chrome::kChromeUIScheme)) { |
| 197 | site_identity_status_ = SITE_IDENTITY_STATUS_INTERNAL_PAGE; |
| 198 | site_identity_details_ = |
| 199 | l10n_util::GetStringUTF16(IDS_PAGE_INFO_INTERNAL_PAGE); |
| 200 | site_connection_status_ = SITE_CONNECTION_STATUS_INTERNAL_PAGE; |
| 201 | return; |
| 202 | } |
| 203 | |
| 204 | scoped_refptr<net::X509Certificate> cert; |
| 205 | |
| 206 | // Identity section. |
| 207 | string16 subject_name(UTF8ToUTF16(url.host())); |
[email protected] | 03ef4b2a | 2012-03-06 15:04:20 | [diff] [blame] | 208 | if (subject_name.empty()) { |
| 209 | subject_name.assign( |
| 210 | l10n_util::GetStringUTF16(IDS_PAGE_INFO_SECURITY_TAB_UNKNOWN_PARTY)); |
[email protected] | 03ef4b2a | 2012-03-06 15:04:20 | [diff] [blame] | 211 | } |
| 212 | |
[email protected] | f61c1ce | 2012-05-09 13:55:11 | [diff] [blame] | 213 | cert_id_ = ssl.cert_id; |
| 214 | |
[email protected] | 03ef4b2a | 2012-03-06 15:04:20 | [diff] [blame] | 215 | if (ssl.cert_id && |
| 216 | cert_store_->RetrieveCert(ssl.cert_id, &cert) && |
| 217 | (!net::IsCertStatusError(ssl.cert_status) || |
| 218 | net::IsCertStatusMinorError(ssl.cert_status))) { |
| 219 | // There are no major errors. Check for minor errors. |
| 220 | if (net::IsCertStatusMinorError(ssl.cert_status)) { |
| 221 | site_identity_status_ = SITE_IDENTITY_STATUS_CERT_REVOCATION_UNKNOWN; |
| 222 | string16 issuer_name(UTF8ToUTF16(cert->issuer().GetDisplayName())); |
| 223 | if (issuer_name.empty()) { |
| 224 | issuer_name.assign(l10n_util::GetStringUTF16( |
| 225 | IDS_PAGE_INFO_SECURITY_TAB_UNKNOWN_PARTY)); |
| 226 | } |
| 227 | site_identity_details_.assign(l10n_util::GetStringFUTF16( |
| 228 | IDS_PAGE_INFO_SECURITY_TAB_SECURE_IDENTITY, issuer_name)); |
| 229 | |
| 230 | site_identity_details_ += ASCIIToUTF16("\n\n"); |
| 231 | if (ssl.cert_status & net::CERT_STATUS_UNABLE_TO_CHECK_REVOCATION) { |
| 232 | site_identity_details_ += l10n_util::GetStringUTF16( |
| 233 | IDS_PAGE_INFO_SECURITY_TAB_UNABLE_TO_CHECK_REVOCATION); |
| 234 | } else if (ssl.cert_status & net::CERT_STATUS_NO_REVOCATION_MECHANISM) { |
| 235 | site_identity_details_ += l10n_util::GetStringUTF16( |
| 236 | IDS_PAGE_INFO_SECURITY_TAB_NO_REVOCATION_MECHANISM); |
| 237 | } else { |
| 238 | NOTREACHED() << "Need to specify string for this warning"; |
| 239 | } |
| 240 | } else if (ssl.cert_status & net::CERT_STATUS_IS_EV) { |
| 241 | // EV HTTPS page. |
| 242 | site_identity_status_ = SITE_IDENTITY_STATUS_EV_CERT; |
| 243 | DCHECK(!cert->subject().organization_names.empty()); |
| 244 | organization_name_ = UTF8ToUTF16(cert->subject().organization_names[0]); |
| 245 | // An EV Cert is required to have a city (localityName) and country but |
| 246 | // state is "if any". |
| 247 | DCHECK(!cert->subject().locality_name.empty()); |
| 248 | DCHECK(!cert->subject().country_name.empty()); |
| 249 | string16 locality; |
| 250 | if (!cert->subject().state_or_province_name.empty()) { |
| 251 | locality = l10n_util::GetStringFUTF16( |
| 252 | IDS_PAGEINFO_ADDRESS, |
| 253 | UTF8ToUTF16(cert->subject().locality_name), |
| 254 | UTF8ToUTF16(cert->subject().state_or_province_name), |
| 255 | UTF8ToUTF16(cert->subject().country_name)); |
| 256 | } else { |
| 257 | locality = l10n_util::GetStringFUTF16( |
| 258 | IDS_PAGEINFO_PARTIAL_ADDRESS, |
| 259 | UTF8ToUTF16(cert->subject().locality_name), |
| 260 | UTF8ToUTF16(cert->subject().country_name)); |
| 261 | } |
| 262 | DCHECK(!cert->subject().organization_names.empty()); |
| 263 | site_identity_details_.assign(l10n_util::GetStringFUTF16( |
| 264 | IDS_PAGE_INFO_SECURITY_TAB_SECURE_IDENTITY_EV, |
| 265 | UTF8ToUTF16(cert->subject().organization_names[0]), |
| 266 | locality, |
| 267 | UTF8ToUTF16(cert->issuer().GetDisplayName()))); |
| 268 | } else if (ssl.cert_status & net::CERT_STATUS_IS_DNSSEC) { |
| 269 | // DNSSEC authenticated page. |
| 270 | site_identity_status_ = SITE_IDENTITY_STATUS_DNSSEC_CERT; |
| 271 | site_identity_details_.assign(l10n_util::GetStringFUTF16( |
| 272 | IDS_PAGE_INFO_SECURITY_TAB_SECURE_IDENTITY, UTF8ToUTF16("DNSSEC"))); |
| 273 | } else { |
| 274 | // Non-EV OK HTTPS page. |
| 275 | site_identity_status_ = SITE_IDENTITY_STATUS_CERT; |
| 276 | string16 issuer_name(UTF8ToUTF16(cert->issuer().GetDisplayName())); |
| 277 | if (issuer_name.empty()) { |
| 278 | issuer_name.assign(l10n_util::GetStringUTF16( |
| 279 | IDS_PAGE_INFO_SECURITY_TAB_UNKNOWN_PARTY)); |
| 280 | } |
| 281 | site_identity_details_.assign(l10n_util::GetStringFUTF16( |
| 282 | IDS_PAGE_INFO_SECURITY_TAB_SECURE_IDENTITY, issuer_name)); |
| 283 | } |
| 284 | } else { |
| 285 | // HTTP or HTTPS with errors (not warnings). |
| 286 | site_identity_details_.assign(l10n_util::GetStringUTF16( |
| 287 | IDS_PAGE_INFO_SECURITY_TAB_INSECURE_IDENTITY)); |
| 288 | if (ssl.security_style == content::SECURITY_STYLE_UNAUTHENTICATED) |
| 289 | site_identity_status_ = SITE_IDENTITY_STATUS_NO_CERT; |
| 290 | else |
| 291 | site_identity_status_ = SITE_IDENTITY_STATUS_ERROR; |
| 292 | |
| 293 | const string16 bullet = UTF8ToUTF16("\n • "); |
| 294 | std::vector<SSLErrorInfo> errors; |
| 295 | SSLErrorInfo::GetErrorsForCertStatus(ssl.cert_id, ssl.cert_status, |
| 296 | url, &errors); |
| 297 | for (size_t i = 0; i < errors.size(); ++i) { |
| 298 | site_identity_details_ += bullet; |
| 299 | site_identity_details_ += errors[i].short_description(); |
| 300 | } |
| 301 | |
| 302 | if (ssl.cert_status & net::CERT_STATUS_NON_UNIQUE_NAME) { |
| 303 | site_identity_details_ += ASCIIToUTF16("\n\n"); |
| 304 | site_identity_details_ += l10n_util::GetStringUTF16( |
| 305 | IDS_PAGE_INFO_SECURITY_TAB_NON_UNIQUE_NAME); |
| 306 | } |
| 307 | } |
| 308 | |
| 309 | // Site Connection |
| 310 | // We consider anything less than 80 bits encryption to be weak encryption. |
| 311 | // TODO(wtc): Bug 1198735: report mixed/unsafe content for unencrypted and |
| 312 | // weakly encrypted connections. |
| 313 | site_connection_status_ = SITE_CONNECTION_STATUS_UNKNOWN; |
| 314 | |
| 315 | if (!ssl.cert_id) { |
| 316 | // Not HTTPS. |
| 317 | DCHECK_EQ(ssl.security_style, content::SECURITY_STYLE_UNAUTHENTICATED); |
| 318 | if (ssl.security_style == content::SECURITY_STYLE_UNAUTHENTICATED) |
| 319 | site_connection_status_ = SITE_CONNECTION_STATUS_UNENCRYPTED; |
| 320 | else |
| 321 | site_connection_status_ = SITE_CONNECTION_STATUS_ENCRYPTED_ERROR; |
| 322 | |
| 323 | site_connection_details_.assign(l10n_util::GetStringFUTF16( |
| 324 | IDS_PAGE_INFO_SECURITY_TAB_NOT_ENCRYPTED_CONNECTION_TEXT, |
| 325 | subject_name)); |
| 326 | } else if (ssl.security_bits < 0) { |
| 327 | // Security strength is unknown. Say nothing. |
| 328 | site_connection_status_ = SITE_CONNECTION_STATUS_ENCRYPTED_ERROR; |
| 329 | } else if (ssl.security_bits == 0) { |
| 330 | DCHECK_NE(ssl.security_style, content::SECURITY_STYLE_UNAUTHENTICATED); |
| 331 | site_connection_status_ = SITE_CONNECTION_STATUS_ENCRYPTED_ERROR; |
| 332 | site_connection_details_.assign(l10n_util::GetStringFUTF16( |
| 333 | IDS_PAGE_INFO_SECURITY_TAB_NOT_ENCRYPTED_CONNECTION_TEXT, |
| 334 | subject_name)); |
| 335 | } else if (ssl.security_bits < 80) { |
| 336 | site_connection_status_ = SITE_CONNECTION_STATUS_ENCRYPTED_ERROR; |
| 337 | site_connection_details_.assign(l10n_util::GetStringFUTF16( |
| 338 | IDS_PAGE_INFO_SECURITY_TAB_WEAK_ENCRYPTION_CONNECTION_TEXT, |
| 339 | subject_name)); |
| 340 | } else { |
| 341 | site_connection_status_ = SITE_CONNECTION_STATUS_ENCRYPTED; |
| 342 | site_connection_details_.assign(l10n_util::GetStringFUTF16( |
| 343 | IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTED_CONNECTION_TEXT, |
| 344 | subject_name, |
| 345 | base::IntToString16(ssl.security_bits))); |
| 346 | if (ssl.content_status) { |
| 347 | bool ran_insecure_content = |
| 348 | !!(ssl.content_status & content::SSLStatus::RAN_INSECURE_CONTENT); |
| 349 | site_connection_status_ = ran_insecure_content ? |
| 350 | SITE_CONNECTION_STATUS_ENCRYPTED_ERROR |
| 351 | : SITE_CONNECTION_STATUS_MIXED_CONTENT; |
| 352 | site_connection_details_.assign(l10n_util::GetStringFUTF16( |
| 353 | IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTED_SENTENCE_LINK, |
| 354 | site_connection_details_, |
| 355 | l10n_util::GetStringUTF16(ran_insecure_content ? |
| 356 | IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTED_INSECURE_CONTENT_ERROR : |
| 357 | IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTED_INSECURE_CONTENT_WARNING))); |
| 358 | } |
| 359 | } |
| 360 | |
| 361 | uint16 cipher_suite = |
| 362 | net::SSLConnectionStatusToCipherSuite(ssl.connection_status); |
| 363 | if (ssl.security_bits > 0 && cipher_suite) { |
| 364 | int ssl_version = |
| 365 | net::SSLConnectionStatusToVersion(ssl.connection_status); |
| 366 | const char* ssl_version_str; |
| 367 | net::SSLVersionToString(&ssl_version_str, ssl_version); |
| 368 | site_connection_details_ += ASCIIToUTF16("\n\n"); |
| 369 | site_connection_details_ += l10n_util::GetStringFUTF16( |
| 370 | IDS_PAGE_INFO_SECURITY_TAB_SSL_VERSION, |
| 371 | ASCIIToUTF16(ssl_version_str)); |
| 372 | |
| 373 | bool did_fallback = (ssl.connection_status & |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 374 | net::SSL_CONNECTION_VERSION_FALLBACK) != 0; |
[email protected] | 03ef4b2a | 2012-03-06 15:04:20 | [diff] [blame] | 375 | bool no_renegotiation = |
| 376 | (ssl.connection_status & |
| 377 | net::SSL_CONNECTION_NO_RENEGOTIATION_EXTENSION) != 0; |
| 378 | const char *key_exchange, *cipher, *mac; |
| 379 | net::SSLCipherSuiteToStrings(&key_exchange, &cipher, &mac, cipher_suite); |
| 380 | |
| 381 | site_connection_details_ += ASCIIToUTF16("\n\n"); |
| 382 | site_connection_details_ += l10n_util::GetStringFUTF16( |
| 383 | IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTION_DETAILS, |
| 384 | ASCIIToUTF16(cipher), ASCIIToUTF16(mac), ASCIIToUTF16(key_exchange)); |
| 385 | |
| 386 | site_connection_details_ += ASCIIToUTF16("\n\n"); |
| 387 | uint8 compression_id = |
| 388 | net::SSLConnectionStatusToCompression(ssl.connection_status); |
| 389 | if (compression_id) { |
| 390 | const char* compression; |
| 391 | net::SSLCompressionToString(&compression, compression_id); |
| 392 | site_connection_details_ += l10n_util::GetStringFUTF16( |
| 393 | IDS_PAGE_INFO_SECURITY_TAB_COMPRESSION_DETAILS, |
| 394 | ASCIIToUTF16(compression)); |
| 395 | } else { |
| 396 | site_connection_details_ += l10n_util::GetStringUTF16( |
| 397 | IDS_PAGE_INFO_SECURITY_TAB_NO_COMPRESSION); |
| 398 | } |
| 399 | |
| 400 | if (did_fallback) { |
| 401 | // For now, only SSLv3 fallback will trigger a warning icon. |
| 402 | if (site_connection_status_ < SITE_CONNECTION_STATUS_MIXED_CONTENT) |
| 403 | site_connection_status_ = SITE_CONNECTION_STATUS_MIXED_CONTENT; |
| 404 | site_connection_details_ += ASCIIToUTF16("\n\n"); |
| 405 | site_connection_details_ += l10n_util::GetStringUTF16( |
| 406 | IDS_PAGE_INFO_SECURITY_TAB_FALLBACK_MESSAGE); |
| 407 | } |
| 408 | if (no_renegotiation) { |
| 409 | site_connection_details_ += ASCIIToUTF16("\n\n"); |
| 410 | site_connection_details_ += l10n_util::GetStringUTF16( |
| 411 | IDS_PAGE_INFO_SECURITY_TAB_RENEGOTIATION_MESSAGE); |
| 412 | } |
| 413 | } |
| 414 | } |
[email protected] | 0b9fdd7 | 2012-04-04 10:00:33 | [diff] [blame] | 415 | |
[email protected] | df81827 | 2012-04-20 13:10:50 | [diff] [blame] | 416 | void WebsiteSettings::PresentSitePermissions() { |
| 417 | PermissionInfoList permission_info_list; |
| 418 | |
| 419 | WebsiteSettingsUI::PermissionInfo permission_info; |
| 420 | for (size_t i = 0; i < arraysize(kPermissionType); ++i) { |
| 421 | permission_info.type = kPermissionType[i]; |
| 422 | |
| 423 | content_settings::SettingInfo info; |
| 424 | scoped_ptr<Value> value(content_settings_->GetWebsiteSetting( |
| 425 | site_url_, site_url_, permission_info.type, "", &info)); |
| 426 | DCHECK(value.get()); |
| 427 | permission_info.setting = |
| 428 | content_settings::ValueToContentSetting(value.get()); |
| 429 | |
[email protected] | b1d113d | 2012-06-27 21:27:34 | [diff] [blame] | 430 | if (info.primary_pattern == ContentSettingsPattern::Wildcard() && |
| 431 | info.secondary_pattern == ContentSettingsPattern::Wildcard()) { |
| 432 | permission_info.default_setting = permission_info.setting; |
| 433 | permission_info.setting = CONTENT_SETTING_DEFAULT; |
| 434 | } else { |
| 435 | permission_info.default_setting = |
| 436 | content_settings_->GetDefaultContentSetting(permission_info.type, |
| 437 | NULL); |
[email protected] | df81827 | 2012-04-20 13:10:50 | [diff] [blame] | 438 | } |
[email protected] | b1d113d | 2012-06-27 21:27:34 | [diff] [blame] | 439 | permission_info_list.push_back(permission_info); |
[email protected] | df81827 | 2012-04-20 13:10:50 | [diff] [blame] | 440 | } |
| 441 | |
| 442 | ui_->SetPermissionInfo(permission_info_list); |
[email protected] | 0b9fdd7 | 2012-04-04 10:00:33 | [diff] [blame] | 443 | } |
| 444 | |
[email protected] | df81827 | 2012-04-20 13:10:50 | [diff] [blame] | 445 | void WebsiteSettings::PresentSiteData() { |
| 446 | CookieInfoList cookie_info_list; |
[email protected] | e0ac3589 | 2012-05-15 12:53:34 | [diff] [blame] | 447 | const LocalSharedObjectsContainer& allowed_objects = |
| 448 | tab_specific_content_settings()->allowed_local_shared_objects(); |
| 449 | const LocalSharedObjectsContainer& blocked_objects = |
| 450 | tab_specific_content_settings()->blocked_local_shared_objects(); |
| 451 | |
| 452 | // Add first party cookie and site data counts. |
[email protected] | df81827 | 2012-04-20 13:10:50 | [diff] [blame] | 453 | WebsiteSettingsUI::CookieInfo cookie_info; |
[email protected] | e0ac3589 | 2012-05-15 12:53:34 | [diff] [blame] | 454 | std::string cookie_source = |
| 455 | net::RegistryControlledDomainService::GetDomainAndRegistry(site_url_); |
| 456 | if (cookie_source.empty()) |
| 457 | cookie_source = site_url_.host(); |
| 458 | cookie_info.cookie_source = cookie_source; |
| 459 | cookie_info.allowed = allowed_objects.GetObjectCountForDomain(site_url_); |
| 460 | cookie_info.blocked = blocked_objects.GetObjectCountForDomain(site_url_); |
| 461 | cookie_info_list.push_back(cookie_info); |
| 462 | |
| 463 | // Add third party cookie counts. |
| 464 | cookie_info.cookie_source = l10n_util::GetStringUTF8( |
| 465 | IDS_WEBSITE_SETTINGS_THIRD_PARTY_SITE_DATA); |
| 466 | cookie_info.allowed = allowed_objects.GetObjectCount() - cookie_info.allowed; |
| 467 | cookie_info.blocked = blocked_objects.GetObjectCount() - cookie_info.blocked; |
[email protected] | df81827 | 2012-04-20 13:10:50 | [diff] [blame] | 468 | cookie_info_list.push_back(cookie_info); |
[email protected] | 0b9fdd7 | 2012-04-04 10:00:33 | [diff] [blame] | 469 | |
[email protected] | df81827 | 2012-04-20 13:10:50 | [diff] [blame] | 470 | ui_->SetCookieInfo(cookie_info_list); |
[email protected] | 0b9fdd7 | 2012-04-04 10:00:33 | [diff] [blame] | 471 | } |
[email protected] | 16de6de | 2012-04-04 12:24:14 | [diff] [blame] | 472 | |
[email protected] | 24c8818c | 2012-04-25 09:57:41 | [diff] [blame] | 473 | void WebsiteSettings::PresentSiteIdentity() { |
| 474 | // After initialization the status about the site's connection |
| 475 | // and it's identity must be available. |
| 476 | DCHECK_NE(site_identity_status_, SITE_IDENTITY_STATUS_UNKNOWN); |
| 477 | DCHECK_NE(site_connection_status_, SITE_CONNECTION_STATUS_UNKNOWN); |
| 478 | WebsiteSettingsUI::IdentityInfo info; |
| 479 | if (site_identity_status_ == SITE_IDENTITY_STATUS_EV_CERT) |
| 480 | info.site_identity = UTF16ToUTF8(organization_name()); |
| 481 | else |
| 482 | info.site_identity = site_url_.host(); |
| 483 | |
| 484 | info.connection_status = site_connection_status_; |
| 485 | info.connection_status_description = |
| 486 | UTF16ToUTF8(site_connection_details_); |
| 487 | info.identity_status = site_identity_status_; |
| 488 | info.identity_status_description = |
| 489 | UTF16ToUTF8(site_identity_details_); |
[email protected] | f61c1ce | 2012-05-09 13:55:11 | [diff] [blame] | 490 | info.cert_id = cert_id_; |
[email protected] | 24c8818c | 2012-04-25 09:57:41 | [diff] [blame] | 491 | ui_->SetIdentityInfo(info); |
| 492 | } |
| 493 | |
[email protected] | 15b09254 | 2012-05-16 13:08:14 | [diff] [blame] | 494 | void WebsiteSettings::PresentHistoryInfo(base::Time first_visit) { |
| 495 | if (first_visit == base::Time()) { |
| 496 | ui_->SetFirstVisit(string16()); |
| 497 | return; |
| 498 | } |
| 499 | |
| 500 | bool visited_before_today = false; |
| 501 | base::Time today = base::Time::Now().LocalMidnight(); |
| 502 | base::Time first_visit_midnight = first_visit.LocalMidnight(); |
| 503 | visited_before_today = (first_visit_midnight < today); |
| 504 | |
| 505 | string16 first_visit_text; |
| 506 | if (visited_before_today) { |
| 507 | first_visit_text = l10n_util::GetStringFUTF16( |
| 508 | IDS_PAGE_INFO_SECURITY_TAB_VISITED_BEFORE_TODAY, |
| 509 | base::TimeFormatShortDate(first_visit)); |
| 510 | } else { |
| 511 | first_visit_text = l10n_util::GetStringUTF16( |
| 512 | IDS_PAGE_INFO_SECURITY_TAB_FIRST_VISITED_TODAY); |
| 513 | |
| 514 | } |
| 515 | ui_->SetFirstVisit(first_visit_text); |
| 516 | } |