[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" |
[email protected] | eb2140c | 2013-07-29 12:37:34 | [diff] [blame] | 12 | #include "base/command_line.h" |
[email protected] | 15b09254 | 2012-05-16 13:08:14 | [diff] [blame] | 13 | #include "base/i18n/time_formatting.h" |
[email protected] | 3ea1b18 | 2013-02-08 22:38:41 | [diff] [blame] | 14 | #include "base/metrics/histogram.h" |
| 15 | #include "base/strings/string_number_conversions.h" |
[email protected] | 774cc3c | 2013-06-07 20:26:45 | [diff] [blame] | 16 | #include "base/strings/utf_string_conversions.h" |
[email protected] | 0b9fdd7 | 2012-04-04 10:00:33 | [diff] [blame] | 17 | #include "base/values.h" |
[email protected] | 6b8a3c74 | 2014-07-25 00:25:35 | [diff] [blame^] | 18 | #include "chrome/browser/browsing_data/browsing_data_channel_id_helper.h" |
[email protected] | b0cb5e8 | 2012-07-19 19:22:47 | [diff] [blame] | 19 | #include "chrome/browser/browsing_data/browsing_data_cookie_helper.h" |
| 20 | #include "chrome/browser/browsing_data/browsing_data_database_helper.h" |
| 21 | #include "chrome/browser/browsing_data/browsing_data_file_system_helper.h" |
| 22 | #include "chrome/browser/browsing_data/browsing_data_indexed_db_helper.h" |
| 23 | #include "chrome/browser/browsing_data/browsing_data_local_storage_helper.h" |
[email protected] | 0b9fdd7 | 2012-04-04 10:00:33 | [diff] [blame] | 24 | #include "chrome/browser/content_settings/content_settings_utils.h" |
| 25 | #include "chrome/browser/content_settings/host_content_settings_map.h" |
[email protected] | df81827 | 2012-04-20 13:10:50 | [diff] [blame] | 26 | #include "chrome/browser/content_settings/local_shared_objects_container.h" |
[email protected] | 77a91c7 | 2012-08-13 16:19:34 | [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/profiles/profile.h" |
| 29 | #include "chrome/browser/ssl/ssl_error_info.h" |
[email protected] | 66f15731 | 2012-08-01 13:50:26 | [diff] [blame] | 30 | #include "chrome/browser/ui/website_settings/website_settings_infobar_delegate.h" |
[email protected] | 4237dd5 | 2012-06-05 00:00:32 | [diff] [blame] | 31 | #include "chrome/browser/ui/website_settings/website_settings_ui.h" |
[email protected] | 0b9fdd7 | 2012-04-04 10:00:33 | [diff] [blame] | 32 | #include "chrome/common/content_settings_pattern.h" |
| 33 | #include "content/public/browser/browser_thread.h" |
[email protected] | b59c6cf0 | 2012-03-12 20:51:42 | [diff] [blame] | 34 | #include "content/public/browser/cert_store.h" |
[email protected] | e22d64f | 2012-09-10 09:03:23 | [diff] [blame] | 35 | #include "content/public/browser/user_metrics.h" |
[email protected] | eb2140c | 2013-07-29 12:37:34 | [diff] [blame] | 36 | #include "content/public/common/content_switches.h" |
[email protected] | 03ef4b2a | 2012-03-06 15:04:20 | [diff] [blame] | 37 | #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] | be28b5f4 | 2012-07-20 11:31:25 | [diff] [blame] | 41 | #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
[email protected] | 6e7845ae | 2013-03-29 21:48:11 | [diff] [blame] | 42 | #include "net/cert/cert_status_flags.h" |
| 43 | #include "net/cert/x509_certificate.h" |
[email protected] | 536fd0b | 2013-03-14 17:41:57 | [diff] [blame] | 44 | #include "net/ssl/ssl_cipher_suite_names.h" |
| 45 | #include "net/ssl/ssl_connection_status_flags.h" |
[email protected] | 03ef4b2a | 2012-03-06 15:04:20 | [diff] [blame] | 46 | #include "ui/base/l10n/l10n_util.h" |
| 47 | #include "ui/base/resource/resource_bundle.h" |
| 48 | |
[email protected] | 24a9f1c9 | 2013-11-13 12:33:37 | [diff] [blame] | 49 | #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] | ab6df3b1 | 2013-12-24 23:32:26 | [diff] [blame] | 54 | using base::ASCIIToUTF16; |
| 55 | using base::UTF8ToUTF16; |
[email protected] | f729d7a | 2013-12-26 07:07:56 | [diff] [blame] | 56 | using base::UTF16ToUTF8; |
[email protected] | 0b9fdd7 | 2012-04-04 10:00:33 | [diff] [blame] | 57 | using content::BrowserThread; |
| 58 | |
| 59 | namespace { |
| 60 | |
[email protected] | b1d113d | 2012-06-27 21:27:34 | [diff] [blame] | 61 | // The list of content settings types to display on the Website Settings UI. |
[email protected] | 0b9fdd7 | 2012-04-04 10:00:33 | [diff] [blame] | 62 | ContentSettingsType kPermissionType[] = { |
[email protected] | b1d113d | 2012-06-27 21:27:34 | [diff] [blame] | 63 | CONTENT_SETTINGS_TYPE_IMAGES, |
| 64 | CONTENT_SETTINGS_TYPE_JAVASCRIPT, |
[email protected] | 0b9fdd7 | 2012-04-04 10:00:33 | [diff] [blame] | 65 | CONTENT_SETTINGS_TYPE_PLUGINS, |
[email protected] | b1d113d | 2012-06-27 21:27:34 | [diff] [blame] | 66 | CONTENT_SETTINGS_TYPE_POPUPS, |
[email protected] | 0b9fdd7 | 2012-04-04 10:00:33 | [diff] [blame] | 67 | CONTENT_SETTINGS_TYPE_GEOLOCATION, |
[email protected] | b1d113d | 2012-06-27 21:27:34 | [diff] [blame] | 68 | CONTENT_SETTINGS_TYPE_NOTIFICATIONS, |
| 69 | CONTENT_SETTINGS_TYPE_FULLSCREEN, |
| 70 | CONTENT_SETTINGS_TYPE_MOUSELOCK, |
| 71 | CONTENT_SETTINGS_TYPE_MEDIASTREAM, |
[email protected] | 62167c1 | 2013-07-10 23:02:08 | [diff] [blame] | 72 | CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS, |
[email protected] | eb2140c | 2013-07-29 12:37:34 | [diff] [blame] | 73 | CONTENT_SETTINGS_TYPE_MIDI_SYSEX, |
[email protected] | 0b9fdd7 | 2012-04-04 10:00:33 | [diff] [blame] | 74 | }; |
| 75 | |
[email protected] | 94c74b4 | 2013-12-02 15:19:49 | [diff] [blame] | 76 | bool CertificateTransparencyStatusMatch( |
| 77 | const content::SignedCertificateTimestampIDStatusList& scts, |
| 78 | net::ct::SCTVerifyStatus status) { |
| 79 | for (content::SignedCertificateTimestampIDStatusList::const_iterator it = |
| 80 | scts.begin(); |
| 81 | it != scts.end(); |
| 82 | ++it) { |
| 83 | if (it->status == status) |
| 84 | return true; |
| 85 | } |
| 86 | |
| 87 | return false; |
| 88 | } |
| 89 | |
| 90 | int GetSiteIdentityDetailsMessageByCTInfo( |
| 91 | const content::SignedCertificateTimestampIDStatusList& scts, |
| 92 | bool is_ev) { |
| 93 | // No SCTs - no CT information. |
| 94 | if (scts.empty()) |
| 95 | return (is_ev ? IDS_PAGE_INFO_SECURITY_TAB_SECURE_IDENTITY_EV_NO_CT |
| 96 | : IDS_PAGE_INFO_SECURITY_TAB_SECURE_IDENTITY_NO_CT); |
| 97 | |
| 98 | if (CertificateTransparencyStatusMatch(scts, net::ct::SCT_STATUS_OK)) |
| 99 | return (is_ev ? IDS_PAGE_INFO_SECURITY_TAB_SECURE_IDENTITY_EV_CT_VERIFIED |
| 100 | : IDS_PAGE_INFO_SECURITY_TAB_SECURE_IDENTITY_CT_VERIFIED); |
| 101 | |
| 102 | if (CertificateTransparencyStatusMatch(scts, net::ct::SCT_STATUS_INVALID)) |
| 103 | return (is_ev ? IDS_PAGE_INFO_SECURITY_TAB_SECURE_IDENTITY_EV_CT_INVALID |
| 104 | : IDS_PAGE_INFO_SECURITY_TAB_SECURE_IDENTITY_CT_INVALID); |
| 105 | |
| 106 | // status is SCT_STATUS_LOG_UNKNOWN |
| 107 | return (is_ev ? IDS_PAGE_INFO_SECURITY_TAB_SECURE_IDENTITY_EV_CT_UNVERIFIED |
| 108 | : IDS_PAGE_INFO_SECURITY_TAB_SECURE_IDENTITY_CT_UNVERIFIED); |
| 109 | } |
| 110 | |
| 111 | // This function will return SITE_IDENTITY_STATUS_CERT or |
| 112 | // SITE_IDENTITY_STATUS_EV_CERT depending on |is_ev| unless there are SCTs |
| 113 | // which failed verification, in which case it will return |
| 114 | // SITE_IDENTITY_STATUS_ERROR. |
| 115 | WebsiteSettings::SiteIdentityStatus GetSiteIdentityStatusByCTInfo( |
| 116 | const content::SignedCertificateTimestampIDStatusList& scts, |
| 117 | bool is_ev) { |
| 118 | if (CertificateTransparencyStatusMatch(scts, net::ct::SCT_STATUS_INVALID)) |
| 119 | return WebsiteSettings::SITE_IDENTITY_STATUS_ERROR; |
| 120 | |
| 121 | return is_ev ? WebsiteSettings::SITE_IDENTITY_STATUS_EV_CERT |
| 122 | : WebsiteSettings::SITE_IDENTITY_STATUS_CERT; |
| 123 | } |
| 124 | |
[email protected] | 0b9fdd7 | 2012-04-04 10:00:33 | [diff] [blame] | 125 | } // namespace |
| 126 | |
| 127 | WebsiteSettings::WebsiteSettings( |
| 128 | WebsiteSettingsUI* ui, |
| 129 | Profile* profile, |
[email protected] | df81827 | 2012-04-20 13:10:50 | [diff] [blame] | 130 | TabSpecificContentSettings* tab_specific_content_settings, |
[email protected] | 4f822f02 | 2012-12-20 19:11:42 | [diff] [blame] | 131 | InfoBarService* infobar_service, |
[email protected] | 0b9fdd7 | 2012-04-04 10:00:33 | [diff] [blame] | 132 | const GURL& url, |
| 133 | const content::SSLStatus& ssl, |
| 134 | content::CertStore* cert_store) |
[email protected] | df81827 | 2012-04-20 13:10:50 | [diff] [blame] | 135 | : TabSpecificContentSettings::SiteDataObserver( |
| 136 | tab_specific_content_settings), |
| 137 | ui_(ui), |
[email protected] | 4f822f02 | 2012-12-20 19:11:42 | [diff] [blame] | 138 | infobar_service_(infobar_service), |
[email protected] | 66f15731 | 2012-08-01 13:50:26 | [diff] [blame] | 139 | show_info_bar_(false), |
[email protected] | 0b9fdd7 | 2012-04-04 10:00:33 | [diff] [blame] | 140 | site_url_(url), |
| 141 | site_identity_status_(SITE_IDENTITY_STATUS_UNKNOWN), |
[email protected] | f61c1ce | 2012-05-09 13:55:11 | [diff] [blame] | 142 | cert_id_(0), |
[email protected] | 03ef4b2a | 2012-03-06 15:04:20 | [diff] [blame] | 143 | site_connection_status_(SITE_CONNECTION_STATUS_UNKNOWN), |
[email protected] | 0b9fdd7 | 2012-04-04 10:00:33 | [diff] [blame] | 144 | cert_store_(cert_store), |
| 145 | content_settings_(profile->GetHostContentSettingsMap()) { |
[email protected] | 03ef4b2a | 2012-03-06 15:04:20 | [diff] [blame] | 146 | Init(profile, url, ssl); |
[email protected] | 0b9fdd7 | 2012-04-04 10:00:33 | [diff] [blame] | 147 | |
[email protected] | 78a1fd90a | 2012-07-19 08:11:25 | [diff] [blame] | 148 | HistoryService* history_service = HistoryServiceFactory::GetForProfile( |
| 149 | profile, Profile::EXPLICIT_ACCESS); |
[email protected] | 15b09254 | 2012-05-16 13:08:14 | [diff] [blame] | 150 | if (history_service) { |
| 151 | history_service->GetVisibleVisitCountToHost( |
| 152 | site_url_, |
[email protected] | 15b09254 | 2012-05-16 13:08:14 | [diff] [blame] | 153 | base::Bind(&WebsiteSettings::OnGotVisitCountToHost, |
[email protected] | e800fe74 | 2014-07-01 10:38:19 | [diff] [blame] | 154 | base::Unretained(this)), |
| 155 | &visit_count_task_tracker_); |
[email protected] | 15b09254 | 2012-05-16 13:08:14 | [diff] [blame] | 156 | } |
| 157 | |
[email protected] | 0b9fdd7 | 2012-04-04 10:00:33 | [diff] [blame] | 158 | PresentSitePermissions(); |
[email protected] | df81827 | 2012-04-20 13:10:50 | [diff] [blame] | 159 | PresentSiteData(); |
[email protected] | 24c8818c | 2012-04-25 09:57:41 | [diff] [blame] | 160 | PresentSiteIdentity(); |
[email protected] | 15b09254 | 2012-05-16 13:08:14 | [diff] [blame] | 161 | PresentHistoryInfo(base::Time()); |
[email protected] | e22d64f | 2012-09-10 09:03:23 | [diff] [blame] | 162 | |
| 163 | // Every time the Website Settings UI is opened a |WebsiteSettings| object is |
| 164 | // created. So this counts how ofter the Website Settings UI is opened. |
[email protected] | e6e30ac | 2014-01-13 21:24:39 | [diff] [blame] | 165 | content::RecordAction(base::UserMetricsAction("WebsiteSettings_Opened")); |
[email protected] | 03ef4b2a | 2012-03-06 15:04:20 | [diff] [blame] | 166 | } |
| 167 | |
[email protected] | 0b9fdd7 | 2012-04-04 10:00:33 | [diff] [blame] | 168 | WebsiteSettings::~WebsiteSettings() { |
[email protected] | 03ef4b2a | 2012-03-06 15:04:20 | [diff] [blame] | 169 | } |
| 170 | |
[email protected] | df81827 | 2012-04-20 13:10:50 | [diff] [blame] | 171 | void WebsiteSettings::OnSitePermissionChanged(ContentSettingsType type, |
| 172 | ContentSetting setting) { |
[email protected] | e22d64f | 2012-09-10 09:03:23 | [diff] [blame] | 173 | // Count how often a permission for a specific content type is changed using |
| 174 | // the Website Settings UI. |
| 175 | UMA_HISTOGRAM_COUNTS("WebsiteSettings.PermissionChanged", type); |
| 176 | |
[email protected] | df81827 | 2012-04-20 13:10:50 | [diff] [blame] | 177 | ContentSettingsPattern primary_pattern; |
| 178 | ContentSettingsPattern secondary_pattern; |
| 179 | switch (type) { |
| 180 | case CONTENT_SETTINGS_TYPE_GEOLOCATION: |
[email protected] | eb2140c | 2013-07-29 12:37:34 | [diff] [blame] | 181 | case CONTENT_SETTINGS_TYPE_MIDI_SYSEX: |
[email protected] | df81827 | 2012-04-20 13:10:50 | [diff] [blame] | 182 | // TODO(markusheintz): The rule we create here should also change the |
| 183 | // location permission for iframed content. |
| 184 | primary_pattern = ContentSettingsPattern::FromURLNoWildcard(site_url_); |
| 185 | secondary_pattern = ContentSettingsPattern::FromURLNoWildcard(site_url_); |
| 186 | break; |
| 187 | case CONTENT_SETTINGS_TYPE_NOTIFICATIONS: |
| 188 | primary_pattern = ContentSettingsPattern::FromURLNoWildcard(site_url_); |
| 189 | secondary_pattern = ContentSettingsPattern::Wildcard(); |
| 190 | break; |
[email protected] | b1d113d | 2012-06-27 21:27:34 | [diff] [blame] | 191 | case CONTENT_SETTINGS_TYPE_IMAGES: |
| 192 | case CONTENT_SETTINGS_TYPE_JAVASCRIPT: |
[email protected] | df81827 | 2012-04-20 13:10:50 | [diff] [blame] | 193 | case CONTENT_SETTINGS_TYPE_PLUGINS: |
| 194 | case CONTENT_SETTINGS_TYPE_POPUPS: |
[email protected] | b1d113d | 2012-06-27 21:27:34 | [diff] [blame] | 195 | case CONTENT_SETTINGS_TYPE_FULLSCREEN: |
| 196 | case CONTENT_SETTINGS_TYPE_MOUSELOCK: |
[email protected] | ad635b1 | 2013-07-22 21:53:27 | [diff] [blame] | 197 | case CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS: |
[email protected] | df81827 | 2012-04-20 13:10:50 | [diff] [blame] | 198 | primary_pattern = ContentSettingsPattern::FromURL(site_url_); |
| 199 | secondary_pattern = ContentSettingsPattern::Wildcard(); |
| 200 | break; |
[email protected] | 0bacc191 | 2012-12-11 11:05:34 | [diff] [blame] | 201 | case CONTENT_SETTINGS_TYPE_MEDIASTREAM: { |
| 202 | // We need to use the same same patterns as other places like infobar code |
| 203 | // to override the existing rule instead of creating the new one. |
| 204 | primary_pattern = ContentSettingsPattern::FromURLNoWildcard(site_url_); |
| 205 | secondary_pattern = ContentSettingsPattern::Wildcard(); |
| 206 | // Set permission for both microphone and camera. |
| 207 | content_settings_->SetContentSetting( |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 208 | primary_pattern, |
| 209 | secondary_pattern, |
| 210 | CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, |
| 211 | std::string(), |
| 212 | setting); |
[email protected] | 0bacc191 | 2012-12-11 11:05:34 | [diff] [blame] | 213 | |
| 214 | content_settings_->SetContentSetting( |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 215 | primary_pattern, |
| 216 | secondary_pattern, |
| 217 | CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, |
| 218 | std::string(), |
| 219 | setting); |
[email protected] | 0bacc191 | 2012-12-11 11:05:34 | [diff] [blame] | 220 | break; |
| 221 | } |
[email protected] | df81827 | 2012-04-20 13:10:50 | [diff] [blame] | 222 | default: |
| 223 | NOTREACHED() << "ContentSettingsType " << type << "is not supported."; |
| 224 | break; |
[email protected] | 0b9fdd7 | 2012-04-04 10:00:33 | [diff] [blame] | 225 | } |
| 226 | |
[email protected] | 0bacc191 | 2012-12-11 11:05:34 | [diff] [blame] | 227 | if (type != CONTENT_SETTINGS_TYPE_MEDIASTREAM) { |
| 228 | // Permission settings are specified via rules. There exists always at least |
| 229 | // one rule for the default setting. Get the rule that currently defines |
| 230 | // the permission for the given permission |type|. Then test whether the |
| 231 | // existing rule is more specific than the rule we are about to create. If |
| 232 | // the existing rule is more specific, than change the existing rule instead |
| 233 | // of creating a new rule that would be hidden behind the existing rule. |
| 234 | // This is not a concern for CONTENT_SETTINGS_TYPE_MEDIASTREAM since users |
| 235 | // can not create media settings exceptions by hand. |
| 236 | content_settings::SettingInfo info; |
[email protected] | 2c95d10 | 2013-12-23 20:42:16 | [diff] [blame] | 237 | scoped_ptr<base::Value> v(content_settings_->GetWebsiteSetting( |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 238 | site_url_, site_url_, type, std::string(), &info)); |
[email protected] | 0bacc191 | 2012-12-11 11:05:34 | [diff] [blame] | 239 | DCHECK(info.source == content_settings::SETTING_SOURCE_USER); |
| 240 | ContentSettingsPattern::Relation r1 = |
| 241 | info.primary_pattern.Compare(primary_pattern); |
| 242 | DCHECK(r1 != ContentSettingsPattern::DISJOINT_ORDER_POST && |
| 243 | r1 != ContentSettingsPattern::DISJOINT_ORDER_PRE); |
| 244 | if (r1 == ContentSettingsPattern::PREDECESSOR) { |
| 245 | primary_pattern = info.primary_pattern; |
| 246 | } else if (r1 == ContentSettingsPattern::IDENTITY) { |
| 247 | ContentSettingsPattern::Relation r2 = |
| 248 | info.secondary_pattern.Compare(secondary_pattern); |
| 249 | DCHECK(r2 != ContentSettingsPattern::DISJOINT_ORDER_POST && |
| 250 | r2 != ContentSettingsPattern::DISJOINT_ORDER_PRE); |
| 251 | if (r2 == ContentSettingsPattern::PREDECESSOR) |
| 252 | secondary_pattern = info.secondary_pattern; |
| 253 | } |
| 254 | |
[email protected] | 2c95d10 | 2013-12-23 20:42:16 | [diff] [blame] | 255 | base::Value* value = NULL; |
[email protected] | 0bacc191 | 2012-12-11 11:05:34 | [diff] [blame] | 256 | if (setting != CONTENT_SETTING_DEFAULT) |
[email protected] | a7965a4 | 2014-07-22 02:35:56 | [diff] [blame] | 257 | value = new base::FundamentalValue(setting); |
[email protected] | 0bacc191 | 2012-12-11 11:05:34 | [diff] [blame] | 258 | content_settings_->SetWebsiteSetting( |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 259 | primary_pattern, secondary_pattern, type, std::string(), value); |
[email protected] | df81827 | 2012-04-20 13:10:50 | [diff] [blame] | 260 | } |
| 261 | |
[email protected] | 66f15731 | 2012-08-01 13:50:26 | [diff] [blame] | 262 | show_info_bar_ = true; |
[email protected] | 2f45d54 | 2012-08-22 08:47:24 | [diff] [blame] | 263 | |
[email protected] | 7695593 | 2012-12-06 11:01:10 | [diff] [blame] | 264 | // TODO(markusheintz): This is a temporary hack to fix issue: |
| 265 | // http://crbug.com/144203. |
[email protected] | e379ba4 | 2012-08-22 22:40:25 | [diff] [blame] | 266 | #if defined(OS_MACOSX) |
[email protected] | 2f45d54 | 2012-08-22 08:47:24 | [diff] [blame] | 267 | // Refresh the UI to reflect the new setting. |
| 268 | PresentSitePermissions(); |
[email protected] | e379ba4 | 2012-08-22 22:40:25 | [diff] [blame] | 269 | #endif |
[email protected] | df81827 | 2012-04-20 13:10:50 | [diff] [blame] | 270 | } |
| 271 | |
[email protected] | e800fe74 | 2014-07-01 10:38:19 | [diff] [blame] | 272 | void WebsiteSettings::OnGotVisitCountToHost(bool found_visits, |
[email protected] | 15b09254 | 2012-05-16 13:08:14 | [diff] [blame] | 273 | int visit_count, |
| 274 | base::Time first_visit) { |
| 275 | if (!found_visits) { |
| 276 | // This indicates an error, such as the page's URL scheme wasn't |
| 277 | // http/https. |
| 278 | first_visit = base::Time(); |
| 279 | } else if (visit_count == 0) { |
| 280 | first_visit = base::Time::Now(); |
| 281 | } |
| 282 | PresentHistoryInfo(first_visit); |
| 283 | } |
| 284 | |
[email protected] | df81827 | 2012-04-20 13:10:50 | [diff] [blame] | 285 | void WebsiteSettings::OnSiteDataAccessed() { |
| 286 | PresentSiteData(); |
[email protected] | 0b9fdd7 | 2012-04-04 10:00:33 | [diff] [blame] | 287 | } |
| 288 | |
[email protected] | 66f15731 | 2012-08-01 13:50:26 | [diff] [blame] | 289 | void WebsiteSettings::OnUIClosing() { |
[email protected] | 0be0993 | 2013-01-08 02:03:50 | [diff] [blame] | 290 | if (show_info_bar_) |
[email protected] | ed9bc65 | 2013-07-11 17:17:36 | [diff] [blame] | 291 | WebsiteSettingsInfoBarDelegate::Create(infobar_service_); |
[email protected] | 66f15731 | 2012-08-01 13:50:26 | [diff] [blame] | 292 | } |
| 293 | |
[email protected] | 0b9fdd7 | 2012-04-04 10:00:33 | [diff] [blame] | 294 | void WebsiteSettings::Init(Profile* profile, |
| 295 | const GURL& url, |
| 296 | const content::SSLStatus& ssl) { |
[email protected] | 2d9748b2 | 2014-02-11 00:17:29 | [diff] [blame] | 297 | if (url.SchemeIs(content::kChromeUIScheme)) { |
[email protected] | 03ef4b2a | 2012-03-06 15:04:20 | [diff] [blame] | 298 | site_identity_status_ = SITE_IDENTITY_STATUS_INTERNAL_PAGE; |
| 299 | site_identity_details_ = |
| 300 | l10n_util::GetStringUTF16(IDS_PAGE_INFO_INTERNAL_PAGE); |
| 301 | site_connection_status_ = SITE_CONNECTION_STATUS_INTERNAL_PAGE; |
| 302 | return; |
| 303 | } |
| 304 | |
| 305 | scoped_refptr<net::X509Certificate> cert; |
| 306 | |
| 307 | // Identity section. |
[email protected] | a04db82 | 2013-12-11 19:14:40 | [diff] [blame] | 308 | base::string16 subject_name(UTF8ToUTF16(url.host())); |
[email protected] | 03ef4b2a | 2012-03-06 15:04:20 | [diff] [blame] | 309 | if (subject_name.empty()) { |
| 310 | subject_name.assign( |
| 311 | l10n_util::GetStringUTF16(IDS_PAGE_INFO_SECURITY_TAB_UNKNOWN_PARTY)); |
[email protected] | 03ef4b2a | 2012-03-06 15:04:20 | [diff] [blame] | 312 | } |
| 313 | |
[email protected] | f61c1ce | 2012-05-09 13:55:11 | [diff] [blame] | 314 | cert_id_ = ssl.cert_id; |
| 315 | |
[email protected] | 3d6d34b1 | 2013-12-23 00:34:02 | [diff] [blame] | 316 | if (ssl.cert_id && !ssl.signed_certificate_timestamp_ids.empty()) { |
| 317 | signed_certificate_timestamp_ids_.assign( |
| 318 | ssl.signed_certificate_timestamp_ids.begin(), |
| 319 | ssl.signed_certificate_timestamp_ids.end()); |
| 320 | } |
| 321 | |
[email protected] | 03ef4b2a | 2012-03-06 15:04:20 | [diff] [blame] | 322 | if (ssl.cert_id && |
| 323 | cert_store_->RetrieveCert(ssl.cert_id, &cert) && |
| 324 | (!net::IsCertStatusError(ssl.cert_status) || |
| 325 | net::IsCertStatusMinorError(ssl.cert_status))) { |
| 326 | // There are no major errors. Check for minor errors. |
[email protected] | 24a9f1c9 | 2013-11-13 12:33:37 | [diff] [blame] | 327 | #if defined(OS_CHROMEOS) |
| 328 | policy::PolicyCertService* service = |
| 329 | policy::PolicyCertServiceFactory::GetForProfile(profile); |
| 330 | const bool used_policy_certs = service && service->UsedPolicyCertificates(); |
| 331 | #else |
| 332 | const bool used_policy_certs = false; |
| 333 | #endif |
| 334 | if (used_policy_certs) { |
[email protected] | eaf3f32 | 2013-04-25 21:53:59 | [diff] [blame] | 335 | site_identity_status_ = SITE_IDENTITY_STATUS_ADMIN_PROVIDED_CERT; |
[email protected] | 24a9f1c9 | 2013-11-13 12:33:37 | [diff] [blame] | 336 | site_identity_details_ = l10n_util::GetStringFUTF16( |
| 337 | IDS_CERT_POLICY_PROVIDED_CERT_MESSAGE, UTF8ToUTF16(url.host())); |
[email protected] | eaf3f32 | 2013-04-25 21:53:59 | [diff] [blame] | 338 | } else if (net::IsCertStatusMinorError(ssl.cert_status)) { |
[email protected] | 03ef4b2a | 2012-03-06 15:04:20 | [diff] [blame] | 339 | site_identity_status_ = SITE_IDENTITY_STATUS_CERT_REVOCATION_UNKNOWN; |
[email protected] | a04db82 | 2013-12-11 19:14:40 | [diff] [blame] | 340 | base::string16 issuer_name(UTF8ToUTF16(cert->issuer().GetDisplayName())); |
[email protected] | 03ef4b2a | 2012-03-06 15:04:20 | [diff] [blame] | 341 | if (issuer_name.empty()) { |
| 342 | issuer_name.assign(l10n_util::GetStringUTF16( |
| 343 | IDS_PAGE_INFO_SECURITY_TAB_UNKNOWN_PARTY)); |
| 344 | } |
[email protected] | 94c74b4 | 2013-12-02 15:19:49 | [diff] [blame] | 345 | |
[email protected] | 03ef4b2a | 2012-03-06 15:04:20 | [diff] [blame] | 346 | site_identity_details_.assign(l10n_util::GetStringFUTF16( |
[email protected] | 94c74b4 | 2013-12-02 15:19:49 | [diff] [blame] | 347 | GetSiteIdentityDetailsMessageByCTInfo( |
| 348 | ssl.signed_certificate_timestamp_ids, false /* not EV */), |
| 349 | issuer_name)); |
[email protected] | 03ef4b2a | 2012-03-06 15:04:20 | [diff] [blame] | 350 | |
| 351 | site_identity_details_ += ASCIIToUTF16("\n\n"); |
| 352 | if (ssl.cert_status & net::CERT_STATUS_UNABLE_TO_CHECK_REVOCATION) { |
| 353 | site_identity_details_ += l10n_util::GetStringUTF16( |
| 354 | IDS_PAGE_INFO_SECURITY_TAB_UNABLE_TO_CHECK_REVOCATION); |
| 355 | } else if (ssl.cert_status & net::CERT_STATUS_NO_REVOCATION_MECHANISM) { |
| 356 | site_identity_details_ += l10n_util::GetStringUTF16( |
| 357 | IDS_PAGE_INFO_SECURITY_TAB_NO_REVOCATION_MECHANISM); |
| 358 | } else { |
| 359 | NOTREACHED() << "Need to specify string for this warning"; |
| 360 | } |
| 361 | } else if (ssl.cert_status & net::CERT_STATUS_IS_EV) { |
| 362 | // EV HTTPS page. |
[email protected] | 94c74b4 | 2013-12-02 15:19:49 | [diff] [blame] | 363 | site_identity_status_ = GetSiteIdentityStatusByCTInfo( |
| 364 | ssl.signed_certificate_timestamp_ids, true); |
[email protected] | 03ef4b2a | 2012-03-06 15:04:20 | [diff] [blame] | 365 | DCHECK(!cert->subject().organization_names.empty()); |
| 366 | organization_name_ = UTF8ToUTF16(cert->subject().organization_names[0]); |
| 367 | // An EV Cert is required to have a city (localityName) and country but |
| 368 | // state is "if any". |
| 369 | DCHECK(!cert->subject().locality_name.empty()); |
| 370 | DCHECK(!cert->subject().country_name.empty()); |
[email protected] | a04db82 | 2013-12-11 19:14:40 | [diff] [blame] | 371 | base::string16 locality; |
[email protected] | 03ef4b2a | 2012-03-06 15:04:20 | [diff] [blame] | 372 | if (!cert->subject().state_or_province_name.empty()) { |
| 373 | locality = l10n_util::GetStringFUTF16( |
| 374 | IDS_PAGEINFO_ADDRESS, |
| 375 | UTF8ToUTF16(cert->subject().locality_name), |
| 376 | UTF8ToUTF16(cert->subject().state_or_province_name), |
| 377 | UTF8ToUTF16(cert->subject().country_name)); |
| 378 | } else { |
| 379 | locality = l10n_util::GetStringFUTF16( |
| 380 | IDS_PAGEINFO_PARTIAL_ADDRESS, |
| 381 | UTF8ToUTF16(cert->subject().locality_name), |
| 382 | UTF8ToUTF16(cert->subject().country_name)); |
| 383 | } |
| 384 | DCHECK(!cert->subject().organization_names.empty()); |
| 385 | site_identity_details_.assign(l10n_util::GetStringFUTF16( |
[email protected] | 94c74b4 | 2013-12-02 15:19:49 | [diff] [blame] | 386 | GetSiteIdentityDetailsMessageByCTInfo( |
| 387 | ssl.signed_certificate_timestamp_ids, true /* is EV */), |
[email protected] | 03ef4b2a | 2012-03-06 15:04:20 | [diff] [blame] | 388 | UTF8ToUTF16(cert->subject().organization_names[0]), |
| 389 | locality, |
| 390 | UTF8ToUTF16(cert->issuer().GetDisplayName()))); |
[email protected] | 03ef4b2a | 2012-03-06 15:04:20 | [diff] [blame] | 391 | } else { |
| 392 | // Non-EV OK HTTPS page. |
[email protected] | 94c74b4 | 2013-12-02 15:19:49 | [diff] [blame] | 393 | site_identity_status_ = GetSiteIdentityStatusByCTInfo( |
| 394 | ssl.signed_certificate_timestamp_ids, false); |
[email protected] | a04db82 | 2013-12-11 19:14:40 | [diff] [blame] | 395 | base::string16 issuer_name(UTF8ToUTF16(cert->issuer().GetDisplayName())); |
[email protected] | 03ef4b2a | 2012-03-06 15:04:20 | [diff] [blame] | 396 | if (issuer_name.empty()) { |
| 397 | issuer_name.assign(l10n_util::GetStringUTF16( |
| 398 | IDS_PAGE_INFO_SECURITY_TAB_UNKNOWN_PARTY)); |
| 399 | } |
[email protected] | 94c74b4 | 2013-12-02 15:19:49 | [diff] [blame] | 400 | |
[email protected] | 03ef4b2a | 2012-03-06 15:04:20 | [diff] [blame] | 401 | site_identity_details_.assign(l10n_util::GetStringFUTF16( |
[email protected] | 94c74b4 | 2013-12-02 15:19:49 | [diff] [blame] | 402 | GetSiteIdentityDetailsMessageByCTInfo( |
| 403 | ssl.signed_certificate_timestamp_ids, false /* not EV */), |
| 404 | issuer_name)); |
[email protected] | 03ef4b2a | 2012-03-06 15:04:20 | [diff] [blame] | 405 | } |
| 406 | } else { |
| 407 | // HTTP or HTTPS with errors (not warnings). |
| 408 | site_identity_details_.assign(l10n_util::GetStringUTF16( |
| 409 | IDS_PAGE_INFO_SECURITY_TAB_INSECURE_IDENTITY)); |
| 410 | if (ssl.security_style == content::SECURITY_STYLE_UNAUTHENTICATED) |
| 411 | site_identity_status_ = SITE_IDENTITY_STATUS_NO_CERT; |
| 412 | else |
| 413 | site_identity_status_ = SITE_IDENTITY_STATUS_ERROR; |
| 414 | |
[email protected] | a04db82 | 2013-12-11 19:14:40 | [diff] [blame] | 415 | const base::string16 bullet = UTF8ToUTF16("\n • "); |
[email protected] | 03ef4b2a | 2012-03-06 15:04:20 | [diff] [blame] | 416 | std::vector<SSLErrorInfo> errors; |
| 417 | SSLErrorInfo::GetErrorsForCertStatus(ssl.cert_id, ssl.cert_status, |
| 418 | url, &errors); |
| 419 | for (size_t i = 0; i < errors.size(); ++i) { |
| 420 | site_identity_details_ += bullet; |
| 421 | site_identity_details_ += errors[i].short_description(); |
| 422 | } |
| 423 | |
| 424 | if (ssl.cert_status & net::CERT_STATUS_NON_UNIQUE_NAME) { |
| 425 | site_identity_details_ += ASCIIToUTF16("\n\n"); |
| 426 | site_identity_details_ += l10n_util::GetStringUTF16( |
| 427 | IDS_PAGE_INFO_SECURITY_TAB_NON_UNIQUE_NAME); |
| 428 | } |
| 429 | } |
| 430 | |
| 431 | // Site Connection |
| 432 | // We consider anything less than 80 bits encryption to be weak encryption. |
| 433 | // TODO(wtc): Bug 1198735: report mixed/unsafe content for unencrypted and |
| 434 | // weakly encrypted connections. |
| 435 | site_connection_status_ = SITE_CONNECTION_STATUS_UNKNOWN; |
| 436 | |
[email protected] | 1c1051d | 2014-05-10 11:39:58 | [diff] [blame] | 437 | if (ssl.security_style == content::SECURITY_STYLE_UNKNOWN) { |
| 438 | // Page is still loading, so SSL status is not yet available. Say nothing. |
| 439 | DCHECK_EQ(ssl.security_bits, -1); |
| 440 | site_connection_status_ = SITE_CONNECTION_STATUS_UNENCRYPTED; |
| 441 | |
| 442 | site_connection_details_.assign(l10n_util::GetStringFUTF16( |
| 443 | IDS_PAGE_INFO_SECURITY_TAB_NOT_ENCRYPTED_CONNECTION_TEXT, |
| 444 | subject_name)); |
| 445 | } else if (ssl.security_style == content::SECURITY_STYLE_UNAUTHENTICATED) { |
| 446 | // HTTPS without a certificate, or not HTTPS. |
| 447 | DCHECK(!ssl.cert_id); |
| 448 | site_connection_status_ = SITE_CONNECTION_STATUS_UNENCRYPTED; |
[email protected] | 03ef4b2a | 2012-03-06 15:04:20 | [diff] [blame] | 449 | |
| 450 | site_connection_details_.assign(l10n_util::GetStringFUTF16( |
| 451 | IDS_PAGE_INFO_SECURITY_TAB_NOT_ENCRYPTED_CONNECTION_TEXT, |
| 452 | subject_name)); |
| 453 | } else if (ssl.security_bits < 0) { |
| 454 | // Security strength is unknown. Say nothing. |
| 455 | site_connection_status_ = SITE_CONNECTION_STATUS_ENCRYPTED_ERROR; |
| 456 | } else if (ssl.security_bits == 0) { |
| 457 | DCHECK_NE(ssl.security_style, content::SECURITY_STYLE_UNAUTHENTICATED); |
| 458 | site_connection_status_ = SITE_CONNECTION_STATUS_ENCRYPTED_ERROR; |
| 459 | site_connection_details_.assign(l10n_util::GetStringFUTF16( |
| 460 | IDS_PAGE_INFO_SECURITY_TAB_NOT_ENCRYPTED_CONNECTION_TEXT, |
| 461 | subject_name)); |
| 462 | } else if (ssl.security_bits < 80) { |
| 463 | site_connection_status_ = SITE_CONNECTION_STATUS_ENCRYPTED_ERROR; |
| 464 | site_connection_details_.assign(l10n_util::GetStringFUTF16( |
| 465 | IDS_PAGE_INFO_SECURITY_TAB_WEAK_ENCRYPTION_CONNECTION_TEXT, |
| 466 | subject_name)); |
| 467 | } else { |
| 468 | site_connection_status_ = SITE_CONNECTION_STATUS_ENCRYPTED; |
| 469 | site_connection_details_.assign(l10n_util::GetStringFUTF16( |
| 470 | IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTED_CONNECTION_TEXT, |
| 471 | subject_name, |
| 472 | base::IntToString16(ssl.security_bits))); |
| 473 | if (ssl.content_status) { |
| 474 | bool ran_insecure_content = |
| 475 | !!(ssl.content_status & content::SSLStatus::RAN_INSECURE_CONTENT); |
| 476 | site_connection_status_ = ran_insecure_content ? |
| 477 | SITE_CONNECTION_STATUS_ENCRYPTED_ERROR |
| 478 | : SITE_CONNECTION_STATUS_MIXED_CONTENT; |
| 479 | site_connection_details_.assign(l10n_util::GetStringFUTF16( |
| 480 | IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTED_SENTENCE_LINK, |
| 481 | site_connection_details_, |
| 482 | l10n_util::GetStringUTF16(ran_insecure_content ? |
| 483 | IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTED_INSECURE_CONTENT_ERROR : |
| 484 | IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTED_INSECURE_CONTENT_WARNING))); |
| 485 | } |
| 486 | } |
| 487 | |
| 488 | uint16 cipher_suite = |
| 489 | net::SSLConnectionStatusToCipherSuite(ssl.connection_status); |
| 490 | if (ssl.security_bits > 0 && cipher_suite) { |
| 491 | int ssl_version = |
| 492 | net::SSLConnectionStatusToVersion(ssl.connection_status); |
| 493 | const char* ssl_version_str; |
| 494 | net::SSLVersionToString(&ssl_version_str, ssl_version); |
| 495 | site_connection_details_ += ASCIIToUTF16("\n\n"); |
| 496 | site_connection_details_ += l10n_util::GetStringFUTF16( |
| 497 | IDS_PAGE_INFO_SECURITY_TAB_SSL_VERSION, |
| 498 | ASCIIToUTF16(ssl_version_str)); |
| 499 | |
| 500 | bool did_fallback = (ssl.connection_status & |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 501 | net::SSL_CONNECTION_VERSION_FALLBACK) != 0; |
[email protected] | 03ef4b2a | 2012-03-06 15:04:20 | [diff] [blame] | 502 | bool no_renegotiation = |
| 503 | (ssl.connection_status & |
| 504 | net::SSL_CONNECTION_NO_RENEGOTIATION_EXTENSION) != 0; |
| 505 | const char *key_exchange, *cipher, *mac; |
[email protected] | b6c1d9e8 | 2013-06-12 17:26:57 | [diff] [blame] | 506 | bool is_aead; |
| 507 | net::SSLCipherSuiteToStrings( |
| 508 | &key_exchange, &cipher, &mac, &is_aead, cipher_suite); |
[email protected] | 03ef4b2a | 2012-03-06 15:04:20 | [diff] [blame] | 509 | |
| 510 | site_connection_details_ += ASCIIToUTF16("\n\n"); |
[email protected] | b6c1d9e8 | 2013-06-12 17:26:57 | [diff] [blame] | 511 | if (is_aead) { |
| 512 | site_connection_details_ += l10n_util::GetStringFUTF16( |
| 513 | IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTION_DETAILS_AEAD, |
| 514 | ASCIIToUTF16(cipher), ASCIIToUTF16(key_exchange)); |
| 515 | } else { |
| 516 | site_connection_details_ += l10n_util::GetStringFUTF16( |
| 517 | IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTION_DETAILS, |
| 518 | ASCIIToUTF16(cipher), ASCIIToUTF16(mac), ASCIIToUTF16(key_exchange)); |
| 519 | } |
[email protected] | 03ef4b2a | 2012-03-06 15:04:20 | [diff] [blame] | 520 | |
[email protected] | 03ef4b2a | 2012-03-06 15:04:20 | [diff] [blame] | 521 | if (did_fallback) { |
| 522 | // For now, only SSLv3 fallback will trigger a warning icon. |
| 523 | if (site_connection_status_ < SITE_CONNECTION_STATUS_MIXED_CONTENT) |
| 524 | site_connection_status_ = SITE_CONNECTION_STATUS_MIXED_CONTENT; |
| 525 | site_connection_details_ += ASCIIToUTF16("\n\n"); |
| 526 | site_connection_details_ += l10n_util::GetStringUTF16( |
| 527 | IDS_PAGE_INFO_SECURITY_TAB_FALLBACK_MESSAGE); |
| 528 | } |
| 529 | if (no_renegotiation) { |
| 530 | site_connection_details_ += ASCIIToUTF16("\n\n"); |
| 531 | site_connection_details_ += l10n_util::GetStringUTF16( |
| 532 | IDS_PAGE_INFO_SECURITY_TAB_RENEGOTIATION_MESSAGE); |
| 533 | } |
| 534 | } |
[email protected] | e583f75 | 2012-08-30 13:26:21 | [diff] [blame] | 535 | |
| 536 | // By default select the permissions tab that displays all the site |
| 537 | // permissions. In case of a connection error or an issue with the |
| 538 | // certificate presented by the website, select the connection tab to draw |
| 539 | // the user's attention to the issue. If the site does not provide a |
| 540 | // certificate because it was loaded over an unencrypted connection, don't |
| 541 | // select the connection tab. |
| 542 | WebsiteSettingsUI::TabId tab_id = WebsiteSettingsUI::TAB_ID_PERMISSIONS; |
| 543 | if (site_connection_status_ == SITE_CONNECTION_STATUS_ENCRYPTED_ERROR || |
| 544 | site_connection_status_ == SITE_CONNECTION_STATUS_MIXED_CONTENT || |
| 545 | site_identity_status_ == SITE_IDENTITY_STATUS_ERROR || |
[email protected] | eaf3f32 | 2013-04-25 21:53:59 | [diff] [blame] | 546 | site_identity_status_ == SITE_IDENTITY_STATUS_CERT_REVOCATION_UNKNOWN || |
| 547 | site_identity_status_ == SITE_IDENTITY_STATUS_ADMIN_PROVIDED_CERT) |
[email protected] | e583f75 | 2012-08-30 13:26:21 | [diff] [blame] | 548 | tab_id = WebsiteSettingsUI::TAB_ID_CONNECTION; |
| 549 | ui_->SetSelectedTab(tab_id); |
[email protected] | 03ef4b2a | 2012-03-06 15:04:20 | [diff] [blame] | 550 | } |
[email protected] | 0b9fdd7 | 2012-04-04 10:00:33 | [diff] [blame] | 551 | |
[email protected] | df81827 | 2012-04-20 13:10:50 | [diff] [blame] | 552 | void WebsiteSettings::PresentSitePermissions() { |
| 553 | PermissionInfoList permission_info_list; |
| 554 | |
| 555 | WebsiteSettingsUI::PermissionInfo permission_info; |
| 556 | for (size_t i = 0; i < arraysize(kPermissionType); ++i) { |
| 557 | permission_info.type = kPermissionType[i]; |
[email protected] | eb2140c | 2013-07-29 12:37:34 | [diff] [blame] | 558 | if (permission_info.type == CONTENT_SETTINGS_TYPE_MIDI_SYSEX) { |
| 559 | const CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 560 | if (!command_line->HasSwitch(switches::kEnableWebMIDI)) |
| 561 | continue; |
| 562 | } |
[email protected] | df81827 | 2012-04-20 13:10:50 | [diff] [blame] | 563 | |
| 564 | content_settings::SettingInfo info; |
[email protected] | 0bacc191 | 2012-12-11 11:05:34 | [diff] [blame] | 565 | if (permission_info.type == CONTENT_SETTINGS_TYPE_MEDIASTREAM) { |
| 566 | scoped_ptr<base::Value> mic_value(content_settings_->GetWebsiteSetting( |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 567 | site_url_, |
| 568 | site_url_, |
| 569 | CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, |
| 570 | std::string(), |
| 571 | &info)); |
[email protected] | 0bacc191 | 2012-12-11 11:05:34 | [diff] [blame] | 572 | ContentSetting mic_setting = |
| 573 | content_settings::ValueToContentSetting(mic_value.get()); |
| 574 | |
| 575 | scoped_ptr<base::Value> camera_value(content_settings_->GetWebsiteSetting( |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 576 | site_url_, |
| 577 | site_url_, |
| 578 | CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, |
| 579 | std::string(), |
| 580 | &info)); |
[email protected] | 0bacc191 | 2012-12-11 11:05:34 | [diff] [blame] | 581 | ContentSetting camera_setting = |
| 582 | content_settings::ValueToContentSetting(camera_value.get()); |
| 583 | |
| 584 | if (mic_setting != camera_setting || mic_setting == CONTENT_SETTING_ASK) |
| 585 | permission_info.setting = CONTENT_SETTING_DEFAULT; |
| 586 | else |
| 587 | permission_info.setting = mic_setting; |
[email protected] | fe4686a | 2012-10-19 15:38:26 | [diff] [blame] | 588 | } else { |
[email protected] | 2c95d10 | 2013-12-23 20:42:16 | [diff] [blame] | 589 | scoped_ptr<base::Value> value(content_settings_->GetWebsiteSetting( |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 590 | site_url_, site_url_, permission_info.type, std::string(), &info)); |
[email protected] | 0bacc191 | 2012-12-11 11:05:34 | [diff] [blame] | 591 | DCHECK(value.get()); |
[email protected] | 2c95d10 | 2013-12-23 20:42:16 | [diff] [blame] | 592 | if (value->GetType() == base::Value::TYPE_INTEGER) { |
[email protected] | 0bacc191 | 2012-12-11 11:05:34 | [diff] [blame] | 593 | permission_info.setting = |
| 594 | content_settings::ValueToContentSetting(value.get()); |
| 595 | } else { |
| 596 | NOTREACHED(); |
| 597 | } |
[email protected] | fe4686a | 2012-10-19 15:38:26 | [diff] [blame] | 598 | } |
| 599 | |
[email protected] | 8bdf45c3 | 2012-08-04 00:12:55 | [diff] [blame] | 600 | permission_info.source = info.source; |
[email protected] | df81827 | 2012-04-20 13:10:50 | [diff] [blame] | 601 | |
[email protected] | b1d113d | 2012-06-27 21:27:34 | [diff] [blame] | 602 | if (info.primary_pattern == ContentSettingsPattern::Wildcard() && |
[email protected] | 0bacc191 | 2012-12-11 11:05:34 | [diff] [blame] | 603 | info.secondary_pattern == ContentSettingsPattern::Wildcard() && |
| 604 | permission_info.type != CONTENT_SETTINGS_TYPE_MEDIASTREAM) { |
[email protected] | b1d113d | 2012-06-27 21:27:34 | [diff] [blame] | 605 | permission_info.default_setting = permission_info.setting; |
| 606 | permission_info.setting = CONTENT_SETTING_DEFAULT; |
| 607 | } else { |
| 608 | permission_info.default_setting = |
| 609 | content_settings_->GetDefaultContentSetting(permission_info.type, |
| 610 | NULL); |
[email protected] | df81827 | 2012-04-20 13:10:50 | [diff] [blame] | 611 | } |
[email protected] | b1d113d | 2012-06-27 21:27:34 | [diff] [blame] | 612 | permission_info_list.push_back(permission_info); |
[email protected] | df81827 | 2012-04-20 13:10:50 | [diff] [blame] | 613 | } |
| 614 | |
| 615 | ui_->SetPermissionInfo(permission_info_list); |
[email protected] | 0b9fdd7 | 2012-04-04 10:00:33 | [diff] [blame] | 616 | } |
| 617 | |
[email protected] | df81827 | 2012-04-20 13:10:50 | [diff] [blame] | 618 | void WebsiteSettings::PresentSiteData() { |
| 619 | CookieInfoList cookie_info_list; |
[email protected] | e0ac3589 | 2012-05-15 12:53:34 | [diff] [blame] | 620 | const LocalSharedObjectsContainer& allowed_objects = |
| 621 | tab_specific_content_settings()->allowed_local_shared_objects(); |
| 622 | const LocalSharedObjectsContainer& blocked_objects = |
| 623 | tab_specific_content_settings()->blocked_local_shared_objects(); |
| 624 | |
| 625 | // Add first party cookie and site data counts. |
[email protected] | df81827 | 2012-04-20 13:10:50 | [diff] [blame] | 626 | WebsiteSettingsUI::CookieInfo cookie_info; |
[email protected] | e0ac3589 | 2012-05-15 12:53:34 | [diff] [blame] | 627 | std::string cookie_source = |
[email protected] | ed32c21 | 2013-05-14 20:49:29 | [diff] [blame] | 628 | net::registry_controlled_domains::GetDomainAndRegistry( |
| 629 | site_url_, |
[email protected] | aabe179 | 2014-01-30 21:37:46 | [diff] [blame] | 630 | net::registry_controlled_domains::INCLUDE_PRIVATE_REGISTRIES); |
[email protected] | e0ac3589 | 2012-05-15 12:53:34 | [diff] [blame] | 631 | if (cookie_source.empty()) |
| 632 | cookie_source = site_url_.host(); |
| 633 | cookie_info.cookie_source = cookie_source; |
| 634 | cookie_info.allowed = allowed_objects.GetObjectCountForDomain(site_url_); |
| 635 | cookie_info.blocked = blocked_objects.GetObjectCountForDomain(site_url_); |
| 636 | cookie_info_list.push_back(cookie_info); |
| 637 | |
| 638 | // Add third party cookie counts. |
| 639 | cookie_info.cookie_source = l10n_util::GetStringUTF8( |
| 640 | IDS_WEBSITE_SETTINGS_THIRD_PARTY_SITE_DATA); |
| 641 | cookie_info.allowed = allowed_objects.GetObjectCount() - cookie_info.allowed; |
| 642 | cookie_info.blocked = blocked_objects.GetObjectCount() - cookie_info.blocked; |
[email protected] | df81827 | 2012-04-20 13:10:50 | [diff] [blame] | 643 | cookie_info_list.push_back(cookie_info); |
[email protected] | 0b9fdd7 | 2012-04-04 10:00:33 | [diff] [blame] | 644 | |
[email protected] | df81827 | 2012-04-20 13:10:50 | [diff] [blame] | 645 | ui_->SetCookieInfo(cookie_info_list); |
[email protected] | 0b9fdd7 | 2012-04-04 10:00:33 | [diff] [blame] | 646 | } |
[email protected] | 16de6de | 2012-04-04 12:24:14 | [diff] [blame] | 647 | |
[email protected] | 24c8818c | 2012-04-25 09:57:41 | [diff] [blame] | 648 | void WebsiteSettings::PresentSiteIdentity() { |
| 649 | // After initialization the status about the site's connection |
| 650 | // and it's identity must be available. |
| 651 | DCHECK_NE(site_identity_status_, SITE_IDENTITY_STATUS_UNKNOWN); |
| 652 | DCHECK_NE(site_connection_status_, SITE_CONNECTION_STATUS_UNKNOWN); |
| 653 | WebsiteSettingsUI::IdentityInfo info; |
| 654 | if (site_identity_status_ == SITE_IDENTITY_STATUS_EV_CERT) |
| 655 | info.site_identity = UTF16ToUTF8(organization_name()); |
| 656 | else |
| 657 | info.site_identity = site_url_.host(); |
| 658 | |
| 659 | info.connection_status = site_connection_status_; |
| 660 | info.connection_status_description = |
| 661 | UTF16ToUTF8(site_connection_details_); |
| 662 | info.identity_status = site_identity_status_; |
| 663 | info.identity_status_description = |
| 664 | UTF16ToUTF8(site_identity_details_); |
[email protected] | f61c1ce | 2012-05-09 13:55:11 | [diff] [blame] | 665 | info.cert_id = cert_id_; |
[email protected] | 3d6d34b1 | 2013-12-23 00:34:02 | [diff] [blame] | 666 | info.signed_certificate_timestamp_ids.assign( |
| 667 | signed_certificate_timestamp_ids_.begin(), |
| 668 | signed_certificate_timestamp_ids_.end()); |
[email protected] | 24c8818c | 2012-04-25 09:57:41 | [diff] [blame] | 669 | ui_->SetIdentityInfo(info); |
| 670 | } |
| 671 | |
[email protected] | 15b09254 | 2012-05-16 13:08:14 | [diff] [blame] | 672 | void WebsiteSettings::PresentHistoryInfo(base::Time first_visit) { |
| 673 | if (first_visit == base::Time()) { |
[email protected] | b959d7d4 | 2013-12-13 17:26:37 | [diff] [blame] | 674 | ui_->SetFirstVisit(base::string16()); |
[email protected] | 15b09254 | 2012-05-16 13:08:14 | [diff] [blame] | 675 | return; |
| 676 | } |
| 677 | |
| 678 | bool visited_before_today = false; |
| 679 | base::Time today = base::Time::Now().LocalMidnight(); |
| 680 | base::Time first_visit_midnight = first_visit.LocalMidnight(); |
| 681 | visited_before_today = (first_visit_midnight < today); |
| 682 | |
[email protected] | a04db82 | 2013-12-11 19:14:40 | [diff] [blame] | 683 | base::string16 first_visit_text; |
[email protected] | 15b09254 | 2012-05-16 13:08:14 | [diff] [blame] | 684 | if (visited_before_today) { |
| 685 | first_visit_text = l10n_util::GetStringFUTF16( |
| 686 | IDS_PAGE_INFO_SECURITY_TAB_VISITED_BEFORE_TODAY, |
| 687 | base::TimeFormatShortDate(first_visit)); |
| 688 | } else { |
| 689 | first_visit_text = l10n_util::GetStringUTF16( |
| 690 | IDS_PAGE_INFO_SECURITY_TAB_FIRST_VISITED_TODAY); |
[email protected] | 15b09254 | 2012-05-16 13:08:14 | [diff] [blame] | 691 | } |
| 692 | ui_->SetFirstVisit(first_visit_text); |
| 693 | } |