[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 | |
avi | 655876a | 2015-12-25 07:18:15 | [diff] [blame] | 7 | #include <stddef.h> |
| 8 | #include <stdint.h> |
| 9 | |
[email protected] | 03ef4b2a | 2012-03-06 15:04:20 | [diff] [blame] | 10 | #include <string> |
| 11 | #include <vector> |
| 12 | |
[email protected] | eb2140c | 2013-07-29 12:37:34 | [diff] [blame] | 13 | #include "base/command_line.h" |
[email protected] | 15b09254 | 2012-05-16 13:08:14 | [diff] [blame] | 14 | #include "base/i18n/time_formatting.h" |
avi | 655876a | 2015-12-25 07:18:15 | [diff] [blame] | 15 | #include "base/macros.h" |
[email protected] | 71cd5ef | 2014-08-13 21:22:04 | [diff] [blame] | 16 | #include "base/metrics/field_trial.h" |
[email protected] | 3ea1b18 | 2013-02-08 22:38:41 | [diff] [blame] | 17 | #include "base/metrics/histogram.h" |
| 18 | #include "base/strings/string_number_conversions.h" |
jialiul | 02aad2d | 2015-04-01 18:56:03 | [diff] [blame] | 19 | #include "base/strings/stringprintf.h" |
[email protected] | 774cc3c | 2013-06-07 20:26:45 | [diff] [blame] | 20 | #include "base/strings/utf_string_conversions.h" |
[email protected] | 0b9fdd7 | 2012-04-04 10:00:33 | [diff] [blame] | 21 | #include "base/values.h" |
avi | 655876a | 2015-12-25 07:18:15 | [diff] [blame] | 22 | #include "build/build_config.h" |
jialiul | 02aad2d | 2015-04-01 18:56:03 | [diff] [blame] | 23 | #include "chrome/browser/browser_process.h" |
[email protected] | 6b8a3c74 | 2014-07-25 00:25:35 | [diff] [blame] | 24 | #include "chrome/browser/browsing_data/browsing_data_channel_id_helper.h" |
[email protected] | b0cb5e8 | 2012-07-19 19:22:47 | [diff] [blame] | 25 | #include "chrome/browser/browsing_data/browsing_data_cookie_helper.h" |
| 26 | #include "chrome/browser/browsing_data/browsing_data_database_helper.h" |
| 27 | #include "chrome/browser/browsing_data/browsing_data_file_system_helper.h" |
| 28 | #include "chrome/browser/browsing_data/browsing_data_indexed_db_helper.h" |
| 29 | #include "chrome/browser/browsing_data/browsing_data_local_storage_helper.h" |
peconn | 5100d43 | 2015-09-16 12:03:08 | [diff] [blame] | 30 | #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
[email protected] | 77a91c7 | 2012-08-13 16:19:34 | [diff] [blame] | 31 | #include "chrome/browser/history/history_service_factory.h" |
palmer | f2cba0d | 2015-08-27 23:15:06 | [diff] [blame] | 32 | #include "chrome/browser/infobars/infobar_service.h" |
reillyg | 85f57db | 2016-01-12 23:14:38 | [diff] [blame] | 33 | #include "chrome/browser/permissions/chooser_context_base.h" |
[email protected] | 03ef4b2a | 2012-03-06 15:04:20 | [diff] [blame] | 34 | #include "chrome/browser/profiles/profile.h" |
[email protected] | 71cd5ef | 2014-08-13 21:22:04 | [diff] [blame] | 35 | #include "chrome/browser/ssl/chrome_ssl_host_state_delegate.h" |
| 36 | #include "chrome/browser/ssl/chrome_ssl_host_state_delegate_factory.h" |
[email protected] | 4237dd5 | 2012-06-05 00:00:32 | [diff] [blame] | 37 | #include "chrome/browser/ui/website_settings/website_settings_ui.h" |
reillyg | 85f57db | 2016-01-12 23:14:38 | [diff] [blame] | 38 | #include "chrome/browser/usb/usb_chooser_context.h" |
| 39 | #include "chrome/browser/usb/usb_chooser_context_factory.h" |
[email protected] | 71cd5ef | 2014-08-13 21:22:04 | [diff] [blame] | 40 | #include "chrome/common/chrome_switches.h" |
sievers | 2f1e811 | 2015-12-04 18:43:56 | [diff] [blame] | 41 | #include "chrome/common/features.h" |
palmer | 153af98 | 2015-09-15 02:04:19 | [diff] [blame] | 42 | #include "chrome/common/pref_names.h" |
jsbell | ddb849e | 2015-08-27 00:12:56 | [diff] [blame] | 43 | #include "chrome/common/url_constants.h" |
thestig | 884a160 | 2014-08-27 01:29:39 | [diff] [blame] | 44 | #include "chrome/grit/chromium_strings.h" |
| 45 | #include "chrome/grit/generated_resources.h" |
reillyg | 85f57db | 2016-01-12 23:14:38 | [diff] [blame] | 46 | #include "chrome/grit/theme_resources.h" |
mukai | 8eaec82 | 2014-10-25 17:53:16 | [diff] [blame] | 47 | #include "components/content_settings/core/browser/content_settings_utils.h" |
| 48 | #include "components/content_settings/core/browser/host_content_settings_map.h" |
vabr | 4856559 | 2014-10-08 15:06:02 | [diff] [blame] | 49 | #include "components/content_settings/core/browser/local_shared_objects_counter.h" |
palmer | 0da10b3 | 2015-02-11 00:42:19 | [diff] [blame] | 50 | #include "components/content_settings/core/common/content_settings.h" |
vasilii | f62dbf9 | 2014-09-05 10:23:13 | [diff] [blame] | 51 | #include "components/content_settings/core/common/content_settings_pattern.h" |
jialiul | 02aad2d | 2015-04-01 18:56:03 | [diff] [blame] | 52 | #include "components/rappor/rappor_utils.h" |
felt | 2493b445 | 2015-09-17 20:33:59 | [diff] [blame] | 53 | #include "components/ssl_errors/error_info.h" |
palmer | 153af98 | 2015-09-15 02:04:19 | [diff] [blame] | 54 | #include "components/url_formatter/elide_url.h" |
[email protected] | 0b9fdd7 | 2012-04-04 10:00:33 | [diff] [blame] | 55 | #include "content/public/browser/browser_thread.h" |
[email protected] | b59c6cf0 | 2012-03-12 20:51:42 | [diff] [blame] | 56 | #include "content/public/browser/cert_store.h" |
[email protected] | e22d64f | 2012-09-10 09:03:23 | [diff] [blame] | 57 | #include "content/public/browser/user_metrics.h" |
[email protected] | eb2140c | 2013-07-29 12:37:34 | [diff] [blame] | 58 | #include "content/public/common/content_switches.h" |
[email protected] | 03ef4b2a | 2012-03-06 15:04:20 | [diff] [blame] | 59 | #include "content/public/common/url_constants.h" |
[email protected] | 6e7845ae | 2013-03-29 21:48:11 | [diff] [blame] | 60 | #include "net/cert/cert_status_flags.h" |
| 61 | #include "net/cert/x509_certificate.h" |
[email protected] | 536fd0b | 2013-03-14 17:41:57 | [diff] [blame] | 62 | #include "net/ssl/ssl_cipher_suite_names.h" |
| 63 | #include "net/ssl/ssl_connection_status_flags.h" |
[email protected] | 03ef4b2a | 2012-03-06 15:04:20 | [diff] [blame] | 64 | #include "ui/base/l10n/l10n_util.h" |
[email protected] | 03ef4b2a | 2012-03-06 15:04:20 | [diff] [blame] | 65 | |
[email protected] | 24a9f1c9 | 2013-11-13 12:33:37 | [diff] [blame] | 66 | #if defined(OS_CHROMEOS) |
| 67 | #include "chrome/browser/chromeos/policy/policy_cert_service.h" |
| 68 | #include "chrome/browser/chromeos/policy/policy_cert_service_factory.h" |
| 69 | #endif |
| 70 | |
estade | 3feb83f | 2015-09-01 23:00:49 | [diff] [blame] | 71 | #if !defined(OS_ANDROID) |
mgiuca | a319f21 | 2016-01-14 03:30:11 | [diff] [blame^] | 72 | #include "chrome/browser/ui/exclusive_access/exclusive_access_manager.h" |
estade | 3feb83f | 2015-09-01 23:00:49 | [diff] [blame] | 73 | #include "chrome/browser/ui/website_settings/website_settings_infobar_delegate.h" |
| 74 | #endif |
| 75 | |
[email protected] | ab6df3b1 | 2013-12-24 23:32:26 | [diff] [blame] | 76 | using base::ASCIIToUTF16; |
| 77 | using base::UTF8ToUTF16; |
[email protected] | f729d7a | 2013-12-26 07:07:56 | [diff] [blame] | 78 | using base::UTF16ToUTF8; |
[email protected] | 0b9fdd7 | 2012-04-04 10:00:33 | [diff] [blame] | 79 | using content::BrowserThread; |
estark | d9e54fb | 2016-01-11 19:37:12 | [diff] [blame] | 80 | using security_state::SecurityStateModel; |
[email protected] | 0b9fdd7 | 2012-04-04 10:00:33 | [diff] [blame] | 81 | |
| 82 | namespace { |
| 83 | |
jww | 1ed8ea7 | 2014-09-02 20:43:25 | [diff] [blame] | 84 | // Events for UMA. Do not reorder or change! |
| 85 | enum SSLCertificateDecisionsDidRevoke { |
| 86 | USER_CERT_DECISIONS_NOT_REVOKED = 0, |
| 87 | USER_CERT_DECISIONS_REVOKED, |
| 88 | END_OF_SSL_CERTIFICATE_DECISIONS_DID_REVOKE_ENUM |
| 89 | }; |
| 90 | |
palmer | 0da10b3 | 2015-02-11 00:42:19 | [diff] [blame] | 91 | // The list of content settings types to display on the Website Settings UI. THE |
| 92 | // ORDER OF THESE ITEMS IS IMPORTANT. To propose changing it, email |
| 93 | // [email protected]. |
[email protected] | 0b9fdd7 | 2012-04-04 10:00:33 | [diff] [blame] | 94 | ContentSettingsType kPermissionType[] = { |
sashab | 2b2a314f | 2015-01-17 06:42:21 | [diff] [blame] | 95 | CONTENT_SETTINGS_TYPE_GEOLOCATION, |
sashab | 2b2a314f | 2015-01-17 06:42:21 | [diff] [blame] | 96 | CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, |
| 97 | CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, |
palmer | 0da10b3 | 2015-02-11 00:42:19 | [diff] [blame] | 98 | CONTENT_SETTINGS_TYPE_NOTIFICATIONS, |
| 99 | CONTENT_SETTINGS_TYPE_IMAGES, |
| 100 | CONTENT_SETTINGS_TYPE_JAVASCRIPT, |
| 101 | CONTENT_SETTINGS_TYPE_POPUPS, |
| 102 | CONTENT_SETTINGS_TYPE_FULLSCREEN, |
sashab | 2b2a314f | 2015-01-17 06:42:21 | [diff] [blame] | 103 | CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS, |
palmer | 0da10b3 | 2015-02-11 00:42:19 | [diff] [blame] | 104 | CONTENT_SETTINGS_TYPE_PLUGINS, |
| 105 | CONTENT_SETTINGS_TYPE_MOUSELOCK, |
sashab | 2b2a314f | 2015-01-17 06:42:21 | [diff] [blame] | 106 | CONTENT_SETTINGS_TYPE_MIDI_SYSEX, |
benwells | a68ed4b | 2014-11-13 03:25:36 | [diff] [blame] | 107 | #if defined(OS_ANDROID) |
sashab | 2b2a314f | 2015-01-17 06:42:21 | [diff] [blame] | 108 | CONTENT_SETTINGS_TYPE_PUSH_MESSAGING, |
benwells | a68ed4b | 2014-11-13 03:25:36 | [diff] [blame] | 109 | #endif |
[email protected] | 0b9fdd7 | 2012-04-04 10:00:33 | [diff] [blame] | 110 | }; |
| 111 | |
mgiuca | a319f21 | 2016-01-14 03:30:11 | [diff] [blame^] | 112 | // Determines whether to show permission |type| in the Website Settings UI. Only |
| 113 | // applies to permissions listed in |kPermissionType|. |
| 114 | bool ShouldShowPermission(ContentSettingsType type) { |
| 115 | // TODO(mgiuca): When simplified-fullscreen-ui is enabled on all platforms, |
| 116 | // remove these from kPermissionType, rather than having this check |
| 117 | // (http://crbug.com/577396). |
| 118 | #if !defined(OS_ANDROID) |
| 119 | // Fullscreen and mouselock settings are not shown in simplified fullscreen |
| 120 | // mode (always allow). |
| 121 | if (type == CONTENT_SETTINGS_TYPE_FULLSCREEN || |
| 122 | type == CONTENT_SETTINGS_TYPE_MOUSELOCK) { |
| 123 | return !ExclusiveAccessManager::IsSimplifiedFullscreenUIEnabled(); |
| 124 | } |
| 125 | #endif |
| 126 | |
| 127 | return true; |
| 128 | } |
| 129 | |
estark | 134a982 | 2015-10-29 04:35:18 | [diff] [blame] | 130 | // Returns true if any of the given statuses match |status|. |
| 131 | bool CertificateTransparencyStatusMatchAny( |
estark | a3121f6b | 2015-09-18 21:15:59 | [diff] [blame] | 132 | const std::vector<net::ct::SCTVerifyStatus>& sct_verify_statuses, |
[email protected] | 94c74b4 | 2013-12-02 15:19:49 | [diff] [blame] | 133 | net::ct::SCTVerifyStatus status) { |
estark | a3121f6b | 2015-09-18 21:15:59 | [diff] [blame] | 134 | for (const auto& verify_status : sct_verify_statuses) { |
| 135 | if (verify_status == status) |
[email protected] | 94c74b4 | 2013-12-02 15:19:49 | [diff] [blame] | 136 | return true; |
| 137 | } |
[email protected] | 94c74b4 | 2013-12-02 15:19:49 | [diff] [blame] | 138 | return false; |
| 139 | } |
| 140 | |
| 141 | int GetSiteIdentityDetailsMessageByCTInfo( |
estark | a3121f6b | 2015-09-18 21:15:59 | [diff] [blame] | 142 | const std::vector<net::ct::SCTVerifyStatus>& sct_verify_statuses, |
[email protected] | 94c74b4 | 2013-12-02 15:19:49 | [diff] [blame] | 143 | bool is_ev) { |
| 144 | // No SCTs - no CT information. |
estark | a3121f6b | 2015-09-18 21:15:59 | [diff] [blame] | 145 | if (sct_verify_statuses.empty()) |
[email protected] | 94c74b4 | 2013-12-02 15:19:49 | [diff] [blame] | 146 | return (is_ev ? IDS_PAGE_INFO_SECURITY_TAB_SECURE_IDENTITY_EV_NO_CT |
| 147 | : IDS_PAGE_INFO_SECURITY_TAB_SECURE_IDENTITY_NO_CT); |
| 148 | |
estark | 134a982 | 2015-10-29 04:35:18 | [diff] [blame] | 149 | // Any valid SCT. |
| 150 | if (CertificateTransparencyStatusMatchAny(sct_verify_statuses, |
| 151 | net::ct::SCT_STATUS_OK)) |
[email protected] | 94c74b4 | 2013-12-02 15:19:49 | [diff] [blame] | 152 | return (is_ev ? IDS_PAGE_INFO_SECURITY_TAB_SECURE_IDENTITY_EV_CT_VERIFIED |
| 153 | : IDS_PAGE_INFO_SECURITY_TAB_SECURE_IDENTITY_CT_VERIFIED); |
| 154 | |
estark | 134a982 | 2015-10-29 04:35:18 | [diff] [blame] | 155 | // Any invalid SCT. |
| 156 | if (CertificateTransparencyStatusMatchAny(sct_verify_statuses, |
| 157 | net::ct::SCT_STATUS_INVALID)) |
[email protected] | 94c74b4 | 2013-12-02 15:19:49 | [diff] [blame] | 158 | return (is_ev ? IDS_PAGE_INFO_SECURITY_TAB_SECURE_IDENTITY_EV_CT_INVALID |
| 159 | : IDS_PAGE_INFO_SECURITY_TAB_SECURE_IDENTITY_CT_INVALID); |
| 160 | |
estark | 134a982 | 2015-10-29 04:35:18 | [diff] [blame] | 161 | // All SCTs are from unknown logs. |
[email protected] | 94c74b4 | 2013-12-02 15:19:49 | [diff] [blame] | 162 | return (is_ev ? IDS_PAGE_INFO_SECURITY_TAB_SECURE_IDENTITY_EV_CT_UNVERIFIED |
| 163 | : IDS_PAGE_INFO_SECURITY_TAB_SECURE_IDENTITY_CT_UNVERIFIED); |
| 164 | } |
| 165 | |
| 166 | // This function will return SITE_IDENTITY_STATUS_CERT or |
estark | 134a982 | 2015-10-29 04:35:18 | [diff] [blame] | 167 | // SITE_IDENTITY_STATUS_EV_CERT depending on |is_ev| unless all SCTs |
| 168 | // failed verification, in which case it will return |
[email protected] | 94c74b4 | 2013-12-02 15:19:49 | [diff] [blame] | 169 | // SITE_IDENTITY_STATUS_ERROR. |
| 170 | WebsiteSettings::SiteIdentityStatus GetSiteIdentityStatusByCTInfo( |
estark | a3121f6b | 2015-09-18 21:15:59 | [diff] [blame] | 171 | const std::vector<net::ct::SCTVerifyStatus>& sct_verify_statuses, |
[email protected] | 94c74b4 | 2013-12-02 15:19:49 | [diff] [blame] | 172 | bool is_ev) { |
estark | 134a982 | 2015-10-29 04:35:18 | [diff] [blame] | 173 | if (sct_verify_statuses.empty() || |
| 174 | CertificateTransparencyStatusMatchAny(sct_verify_statuses, |
| 175 | net::ct::SCT_STATUS_OK)) |
| 176 | return is_ev ? WebsiteSettings::SITE_IDENTITY_STATUS_EV_CERT |
| 177 | : WebsiteSettings::SITE_IDENTITY_STATUS_CERT; |
[email protected] | 94c74b4 | 2013-12-02 15:19:49 | [diff] [blame] | 178 | |
estark | 134a982 | 2015-10-29 04:35:18 | [diff] [blame] | 179 | return WebsiteSettings::SITE_IDENTITY_STATUS_CT_ERROR; |
[email protected] | 94c74b4 | 2013-12-02 15:19:49 | [diff] [blame] | 180 | } |
| 181 | |
palmer | 153af98 | 2015-09-15 02:04:19 | [diff] [blame] | 182 | base::string16 GetSimpleSiteName(const GURL& url, Profile* profile) { |
| 183 | std::string languages; |
| 184 | if (profile) |
| 185 | languages = profile->GetPrefs()->GetString(prefs::kAcceptLanguages); |
| 186 | return url_formatter::FormatUrlForSecurityDisplayOmitScheme(url, languages); |
| 187 | } |
| 188 | |
reillyg | 85f57db | 2016-01-12 23:14:38 | [diff] [blame] | 189 | ChooserContextBase* GetUsbChooserContext(Profile* profile) { |
| 190 | return UsbChooserContextFactory::GetForProfile(profile); |
| 191 | } |
| 192 | |
| 193 | // The list of chooser types that need to display entries in the Website |
| 194 | // Settings UI. THE ORDER OF THESE ITEMS IS IMPORTANT. To propose changing it, |
| 195 | // email [email protected]. |
| 196 | WebsiteSettings::ChooserUIInfo kChooserUIInfo[] = { |
| 197 | {&GetUsbChooserContext, IDR_BLOCKED_USB, IDR_ALLOWED_USB, |
| 198 | IDS_WEBSITE_SETTINGS_USB_DEVICE_LABEL, |
| 199 | IDS_WEBSITE_SETTINGS_DELETE_USB_DEVICE, "name"}, |
| 200 | }; |
| 201 | |
[email protected] | 0b9fdd7 | 2012-04-04 10:00:33 | [diff] [blame] | 202 | } // namespace |
| 203 | |
| 204 | WebsiteSettings::WebsiteSettings( |
| 205 | WebsiteSettingsUI* ui, |
| 206 | Profile* profile, |
[email protected] | df81827 | 2012-04-20 13:10:50 | [diff] [blame] | 207 | TabSpecificContentSettings* tab_specific_content_settings, |
palmer | f2cba0d | 2015-08-27 23:15:06 | [diff] [blame] | 208 | content::WebContents* web_contents, |
[email protected] | 0b9fdd7 | 2012-04-04 10:00:33 | [diff] [blame] | 209 | const GURL& url, |
estark | a3121f6b | 2015-09-18 21:15:59 | [diff] [blame] | 210 | const SecurityStateModel::SecurityInfo& security_info, |
[email protected] | 0b9fdd7 | 2012-04-04 10:00:33 | [diff] [blame] | 211 | content::CertStore* cert_store) |
[email protected] | df81827 | 2012-04-20 13:10:50 | [diff] [blame] | 212 | : TabSpecificContentSettings::SiteDataObserver( |
| 213 | tab_specific_content_settings), |
| 214 | ui_(ui), |
palmer | f2cba0d | 2015-08-27 23:15:06 | [diff] [blame] | 215 | web_contents_(web_contents), |
[email protected] | 66f15731 | 2012-08-01 13:50:26 | [diff] [blame] | 216 | show_info_bar_(false), |
[email protected] | 0b9fdd7 | 2012-04-04 10:00:33 | [diff] [blame] | 217 | site_url_(url), |
| 218 | site_identity_status_(SITE_IDENTITY_STATUS_UNKNOWN), |
[email protected] | f61c1ce | 2012-05-09 13:55:11 | [diff] [blame] | 219 | cert_id_(0), |
[email protected] | 03ef4b2a | 2012-03-06 15:04:20 | [diff] [blame] | 220 | site_connection_status_(SITE_CONNECTION_STATUS_UNKNOWN), |
[email protected] | 0b9fdd7 | 2012-04-04 10:00:33 | [diff] [blame] | 221 | cert_store_(cert_store), |
peconn | 5100d43 | 2015-09-16 12:03:08 | [diff] [blame] | 222 | content_settings_(HostContentSettingsMapFactory::GetForProfile(profile)), |
[email protected] | 71cd5ef | 2014-08-13 21:22:04 | [diff] [blame] | 223 | chrome_ssl_host_state_delegate_( |
jww | 1ed8ea7 | 2014-09-02 20:43:25 | [diff] [blame] | 224 | ChromeSSLHostStateDelegateFactory::GetForProfile(profile)), |
palmer | 153af98 | 2015-09-15 02:04:19 | [diff] [blame] | 225 | did_revoke_user_ssl_decisions_(false), |
| 226 | profile_(profile) { |
estark | a3121f6b | 2015-09-18 21:15:59 | [diff] [blame] | 227 | Init(url, security_info); |
[email protected] | 0b9fdd7 | 2012-04-04 10:00:33 | [diff] [blame] | 228 | |
| 229 | PresentSitePermissions(); |
[email protected] | df81827 | 2012-04-20 13:10:50 | [diff] [blame] | 230 | PresentSiteData(); |
[email protected] | 24c8818c | 2012-04-25 09:57:41 | [diff] [blame] | 231 | PresentSiteIdentity(); |
[email protected] | e22d64f | 2012-09-10 09:03:23 | [diff] [blame] | 232 | |
| 233 | // Every time the Website Settings UI is opened a |WebsiteSettings| object is |
| 234 | // created. So this counts how ofter the Website Settings UI is opened. |
lgarron | 04a9350 | 2014-11-04 22:25:04 | [diff] [blame] | 235 | RecordWebsiteSettingsAction(WEBSITE_SETTINGS_OPENED); |
[email protected] | 03ef4b2a | 2012-03-06 15:04:20 | [diff] [blame] | 236 | } |
| 237 | |
[email protected] | 0b9fdd7 | 2012-04-04 10:00:33 | [diff] [blame] | 238 | WebsiteSettings::~WebsiteSettings() { |
[email protected] | 03ef4b2a | 2012-03-06 15:04:20 | [diff] [blame] | 239 | } |
| 240 | |
lgarron | 04a9350 | 2014-11-04 22:25:04 | [diff] [blame] | 241 | void WebsiteSettings::RecordWebsiteSettingsAction( |
| 242 | WebsiteSettingsAction action) { |
| 243 | UMA_HISTOGRAM_ENUMERATION("WebsiteSettings.Action", |
| 244 | action, |
| 245 | WEBSITE_SETTINGS_COUNT); |
| 246 | |
| 247 | // Use a separate histogram to record actions if they are done on a page with |
| 248 | // an HTTPS URL. Note that this *disregards* security status. |
palmer | ee0e5af | 2015-06-05 03:10:40 | [diff] [blame] | 249 | // |
| 250 | |
| 251 | // TODO(palmer): Consider adding a new histogram for |
| 252 | // GURL::SchemeIsCryptographic. (We don't want to replace this call with a |
| 253 | // call to that function because we don't want to change the meanings of |
| 254 | // existing metrics.) This would inform the decision to mark non-secure |
| 255 | // origins as Dubious or Non-Secure; the overall bug for that is |
| 256 | // crbug.com/454579. |
lgarron | 04a9350 | 2014-11-04 22:25:04 | [diff] [blame] | 257 | if (site_url_.SchemeIs(url::kHttpsScheme)) { |
| 258 | UMA_HISTOGRAM_ENUMERATION("WebsiteSettings.Action.HttpsUrl", |
| 259 | action, |
| 260 | WEBSITE_SETTINGS_COUNT); |
| 261 | } |
| 262 | } |
| 263 | |
raymes | 9d48b07b | 2015-10-19 04:32:35 | [diff] [blame] | 264 | // Get corresponding Rappor Metric. TODO(raymes): This should use the same |
| 265 | // code that's in permission_context_uma_util.cc. Figure out how to do that. |
| 266 | // crbug.com/544745. |
jialiul | 02aad2d | 2015-04-01 18:56:03 | [diff] [blame] | 267 | const std::string GetRapporMetric(ContentSettingsType permission) { |
| 268 | std::string permission_str; |
raymes | 9d48b07b | 2015-10-19 04:32:35 | [diff] [blame] | 269 | |
| 270 | if (permission == CONTENT_SETTINGS_TYPE_GEOLOCATION) { |
| 271 | permission_str = "Geolocation"; |
| 272 | } else if (permission == CONTENT_SETTINGS_TYPE_NOTIFICATIONS) { |
| 273 | permission_str = "Notifications"; |
| 274 | } else if (permission == CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC) { |
| 275 | permission_str = "Mic"; |
| 276 | } else if (permission == CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA) { |
| 277 | permission_str = "Camera"; |
jialiul | 02aad2d | 2015-04-01 18:56:03 | [diff] [blame] | 278 | } |
| 279 | |
| 280 | return base::StringPrintf("ContentSettings.PermissionActions_%s.Revoked.Url", |
| 281 | permission_str.c_str()); |
| 282 | } |
lgarron | 04a9350 | 2014-11-04 22:25:04 | [diff] [blame] | 283 | |
[email protected] | df81827 | 2012-04-20 13:10:50 | [diff] [blame] | 284 | void WebsiteSettings::OnSitePermissionChanged(ContentSettingsType type, |
| 285 | ContentSetting setting) { |
[email protected] | e22d64f | 2012-09-10 09:03:23 | [diff] [blame] | 286 | // Count how often a permission for a specific content type is changed using |
| 287 | // the Website Settings UI. |
raymes | 4a13d43 | 2015-09-08 00:44:07 | [diff] [blame] | 288 | size_t num_values; |
| 289 | int histogram_value = ContentSettingTypeToHistogramValue(type, &num_values); |
sashab | 9debecd | 2014-12-18 04:15:56 | [diff] [blame] | 290 | UMA_HISTOGRAM_ENUMERATION("WebsiteSettings.OriginInfo.PermissionChanged", |
raymes | 4a13d43 | 2015-09-08 00:44:07 | [diff] [blame] | 291 | histogram_value, num_values); |
sashab | 9debecd | 2014-12-18 04:15:56 | [diff] [blame] | 292 | |
| 293 | if (setting == ContentSetting::CONTENT_SETTING_ALLOW) { |
| 294 | UMA_HISTOGRAM_ENUMERATION( |
| 295 | "WebsiteSettings.OriginInfo.PermissionChanged.Allowed", histogram_value, |
raymes | 4a13d43 | 2015-09-08 00:44:07 | [diff] [blame] | 296 | num_values); |
sashab | 9debecd | 2014-12-18 04:15:56 | [diff] [blame] | 297 | } else if (setting == ContentSetting::CONTENT_SETTING_BLOCK) { |
| 298 | UMA_HISTOGRAM_ENUMERATION( |
| 299 | "WebsiteSettings.OriginInfo.PermissionChanged.Blocked", histogram_value, |
raymes | 4a13d43 | 2015-09-08 00:44:07 | [diff] [blame] | 300 | num_values); |
jialiul | 02aad2d | 2015-04-01 18:56:03 | [diff] [blame] | 301 | // Trigger Rappor sampling if it is a permission revoke action. |
| 302 | const std::string& rappor_metric = GetRapporMetric(type); |
| 303 | if (!rappor_metric.empty()) { |
| 304 | rappor::SampleDomainAndRegistryFromGURL( |
| 305 | g_browser_process->rappor_service(), rappor_metric, this->site_url_); |
| 306 | } |
sashab | 9debecd | 2014-12-18 04:15:56 | [diff] [blame] | 307 | } |
[email protected] | e22d64f | 2012-09-10 09:03:23 | [diff] [blame] | 308 | |
lgarron | 04a9350 | 2014-11-04 22:25:04 | [diff] [blame] | 309 | // This is technically redundant given the histogram above, but putting the |
| 310 | // total count of permission changes in another histogram makes it easier to |
| 311 | // compare it against other kinds of actions in WebsiteSettings[PopupView]. |
| 312 | RecordWebsiteSettingsAction(WEBSITE_SETTINGS_CHANGED_PERMISSION); |
| 313 | |
raymes | fbaaaaa | 2015-11-10 02:20:40 | [diff] [blame] | 314 | content_settings_->SetNarrowestContentSetting(site_url_, site_url_, type, |
| 315 | setting); |
[email protected] | df81827 | 2012-04-20 13:10:50 | [diff] [blame] | 316 | |
[email protected] | 66f15731 | 2012-08-01 13:50:26 | [diff] [blame] | 317 | show_info_bar_ = true; |
[email protected] | 2f45d54 | 2012-08-22 08:47:24 | [diff] [blame] | 318 | |
[email protected] | 2f45d54 | 2012-08-22 08:47:24 | [diff] [blame] | 319 | // Refresh the UI to reflect the new setting. |
| 320 | PresentSitePermissions(); |
[email protected] | df81827 | 2012-04-20 13:10:50 | [diff] [blame] | 321 | } |
| 322 | |
reillyg | 85f57db | 2016-01-12 23:14:38 | [diff] [blame] | 323 | void WebsiteSettings::OnSiteChosenObjectDeleted( |
| 324 | const ChooserUIInfo& ui_info, |
| 325 | const base::DictionaryValue& object) { |
| 326 | // TODO(reillyg): Create metrics for revocations. crbug.com/556845 |
| 327 | ChooserContextBase* context = ui_info.get_context(profile_); |
| 328 | context->RevokeObjectPermission(site_url_, site_url_, object); |
| 329 | |
| 330 | show_info_bar_ = true; |
| 331 | |
| 332 | // Refresh the UI to reflect the changed settings. |
| 333 | PresentSitePermissions(); |
| 334 | } |
| 335 | |
[email protected] | df81827 | 2012-04-20 13:10:50 | [diff] [blame] | 336 | void WebsiteSettings::OnSiteDataAccessed() { |
| 337 | PresentSiteData(); |
[email protected] | 0b9fdd7 | 2012-04-04 10:00:33 | [diff] [blame] | 338 | } |
| 339 | |
[email protected] | 66f15731 | 2012-08-01 13:50:26 | [diff] [blame] | 340 | void WebsiteSettings::OnUIClosing() { |
estade | 3feb83f | 2015-09-01 23:00:49 | [diff] [blame] | 341 | #if defined(OS_ANDROID) |
| 342 | NOTREACHED(); |
| 343 | #else |
palmer | f2cba0d | 2015-08-27 23:15:06 | [diff] [blame] | 344 | if (show_info_bar_ && web_contents_) { |
| 345 | InfoBarService* infobar_service = |
| 346 | InfoBarService::FromWebContents(web_contents_); |
| 347 | if (infobar_service) |
| 348 | WebsiteSettingsInfoBarDelegate::Create(infobar_service); |
| 349 | } |
jww | 1ed8ea7 | 2014-09-02 20:43:25 | [diff] [blame] | 350 | |
| 351 | SSLCertificateDecisionsDidRevoke user_decision = |
| 352 | did_revoke_user_ssl_decisions_ ? USER_CERT_DECISIONS_REVOKED |
| 353 | : USER_CERT_DECISIONS_NOT_REVOKED; |
| 354 | |
| 355 | UMA_HISTOGRAM_ENUMERATION("interstitial.ssl.did_user_revoke_decisions", |
| 356 | user_decision, |
| 357 | END_OF_SSL_CERTIFICATE_DECISIONS_DID_REVOKE_ENUM); |
estade | 3feb83f | 2015-09-01 23:00:49 | [diff] [blame] | 358 | #endif |
jww | 1ed8ea7 | 2014-09-02 20:43:25 | [diff] [blame] | 359 | } |
| 360 | |
| 361 | void WebsiteSettings::OnRevokeSSLErrorBypassButtonPressed() { |
| 362 | DCHECK(chrome_ssl_host_state_delegate_); |
jww | 6a55df7 | 2014-09-05 19:59:29 | [diff] [blame] | 363 | chrome_ssl_host_state_delegate_->RevokeUserAllowExceptionsHard( |
| 364 | site_url().host()); |
jww | 1ed8ea7 | 2014-09-02 20:43:25 | [diff] [blame] | 365 | did_revoke_user_ssl_decisions_ = true; |
[email protected] | 66f15731 | 2012-08-01 13:50:26 | [diff] [blame] | 366 | } |
| 367 | |
estark | a3121f6b | 2015-09-18 21:15:59 | [diff] [blame] | 368 | void WebsiteSettings::Init( |
| 369 | const GURL& url, |
| 370 | const SecurityStateModel::SecurityInfo& security_info) { |
sashab | 97894ce | 2014-10-22 10:08:33 | [diff] [blame] | 371 | bool isChromeUINativeScheme = false; |
sievers | 2f1e811 | 2015-12-04 18:43:56 | [diff] [blame] | 372 | #if BUILDFLAG(ANDROID_JAVA_UI) |
sashab | 97894ce | 2014-10-22 10:08:33 | [diff] [blame] | 373 | isChromeUINativeScheme = url.SchemeIs(chrome::kChromeUINativeScheme); |
| 374 | #endif |
| 375 | |
upendrag.gowda | 60886a6e | 2015-10-31 05:51:09 | [diff] [blame] | 376 | if (url.SchemeIs(url::kAboutScheme)) { |
| 377 | // All about: URLs except about:blank are redirected. |
| 378 | DCHECK_EQ(url::kAboutBlankURL, url.spec()); |
| 379 | site_identity_status_ = SITE_IDENTITY_STATUS_NO_CERT; |
| 380 | site_identity_details_ = |
| 381 | l10n_util::GetStringUTF16(IDS_PAGE_INFO_SECURITY_TAB_INSECURE_IDENTITY); |
| 382 | site_connection_status_ = SITE_CONNECTION_STATUS_UNENCRYPTED; |
| 383 | site_connection_details_ = l10n_util::GetStringFUTF16( |
| 384 | IDS_PAGE_INFO_SECURITY_TAB_NOT_ENCRYPTED_CONNECTION_TEXT, |
| 385 | UTF8ToUTF16(url.spec())); |
| 386 | return; |
| 387 | } |
| 388 | |
| 389 | if (url.SchemeIs(content::kChromeUIScheme) || isChromeUINativeScheme) { |
[email protected] | 03ef4b2a | 2012-03-06 15:04:20 | [diff] [blame] | 390 | site_identity_status_ = SITE_IDENTITY_STATUS_INTERNAL_PAGE; |
| 391 | site_identity_details_ = |
| 392 | l10n_util::GetStringUTF16(IDS_PAGE_INFO_INTERNAL_PAGE); |
| 393 | site_connection_status_ = SITE_CONNECTION_STATUS_INTERNAL_PAGE; |
| 394 | return; |
| 395 | } |
| 396 | |
[email protected] | 03ef4b2a | 2012-03-06 15:04:20 | [diff] [blame] | 397 | // Identity section. |
palmer | 153af98 | 2015-09-15 02:04:19 | [diff] [blame] | 398 | scoped_refptr<net::X509Certificate> cert; |
estark | a3121f6b | 2015-09-18 21:15:59 | [diff] [blame] | 399 | cert_id_ = security_info.cert_id; |
[email protected] | f61c1ce | 2012-05-09 13:55:11 | [diff] [blame] | 400 | |
estark | a3121f6b | 2015-09-18 21:15:59 | [diff] [blame] | 401 | // HTTPS with no or minor errors. |
| 402 | if (security_info.cert_id && |
| 403 | cert_store_->RetrieveCert(security_info.cert_id, &cert) && |
| 404 | (!net::IsCertStatusError(security_info.cert_status) || |
| 405 | net::IsCertStatusMinorError(security_info.cert_status))) { |
[email protected] | 03ef4b2a | 2012-03-06 15:04:20 | [diff] [blame] | 406 | // There are no major errors. Check for minor errors. |
estark | a3121f6b | 2015-09-18 21:15:59 | [diff] [blame] | 407 | if (security_info.security_level == |
| 408 | SecurityStateModel::SECURITY_POLICY_WARNING) { |
[email protected] | eaf3f32 | 2013-04-25 21:53:59 | [diff] [blame] | 409 | site_identity_status_ = SITE_IDENTITY_STATUS_ADMIN_PROVIDED_CERT; |
[email protected] | 24a9f1c9 | 2013-11-13 12:33:37 | [diff] [blame] | 410 | site_identity_details_ = l10n_util::GetStringFUTF16( |
| 411 | IDS_CERT_POLICY_PROVIDED_CERT_MESSAGE, UTF8ToUTF16(url.host())); |
estark | a3121f6b | 2015-09-18 21:15:59 | [diff] [blame] | 412 | } else if (net::IsCertStatusMinorError(security_info.cert_status)) { |
[email protected] | 03ef4b2a | 2012-03-06 15:04:20 | [diff] [blame] | 413 | site_identity_status_ = SITE_IDENTITY_STATUS_CERT_REVOCATION_UNKNOWN; |
[email protected] | a04db82 | 2013-12-11 19:14:40 | [diff] [blame] | 414 | base::string16 issuer_name(UTF8ToUTF16(cert->issuer().GetDisplayName())); |
[email protected] | 03ef4b2a | 2012-03-06 15:04:20 | [diff] [blame] | 415 | if (issuer_name.empty()) { |
| 416 | issuer_name.assign(l10n_util::GetStringUTF16( |
| 417 | IDS_PAGE_INFO_SECURITY_TAB_UNKNOWN_PARTY)); |
| 418 | } |
[email protected] | 94c74b4 | 2013-12-02 15:19:49 | [diff] [blame] | 419 | |
[email protected] | 03ef4b2a | 2012-03-06 15:04:20 | [diff] [blame] | 420 | site_identity_details_.assign(l10n_util::GetStringFUTF16( |
[email protected] | 94c74b4 | 2013-12-02 15:19:49 | [diff] [blame] | 421 | GetSiteIdentityDetailsMessageByCTInfo( |
estark | a3121f6b | 2015-09-18 21:15:59 | [diff] [blame] | 422 | security_info.sct_verify_statuses, false /* not EV */), |
[email protected] | 94c74b4 | 2013-12-02 15:19:49 | [diff] [blame] | 423 | issuer_name)); |
[email protected] | 03ef4b2a | 2012-03-06 15:04:20 | [diff] [blame] | 424 | |
| 425 | site_identity_details_ += ASCIIToUTF16("\n\n"); |
estark | a3121f6b | 2015-09-18 21:15:59 | [diff] [blame] | 426 | if (security_info.cert_status & |
| 427 | net::CERT_STATUS_UNABLE_TO_CHECK_REVOCATION) { |
[email protected] | 03ef4b2a | 2012-03-06 15:04:20 | [diff] [blame] | 428 | site_identity_details_ += l10n_util::GetStringUTF16( |
| 429 | IDS_PAGE_INFO_SECURITY_TAB_UNABLE_TO_CHECK_REVOCATION); |
estark | a3121f6b | 2015-09-18 21:15:59 | [diff] [blame] | 430 | } else if (security_info.cert_status & |
| 431 | net::CERT_STATUS_NO_REVOCATION_MECHANISM) { |
[email protected] | 03ef4b2a | 2012-03-06 15:04:20 | [diff] [blame] | 432 | site_identity_details_ += l10n_util::GetStringUTF16( |
| 433 | IDS_PAGE_INFO_SECURITY_TAB_NO_REVOCATION_MECHANISM); |
| 434 | } else { |
| 435 | NOTREACHED() << "Need to specify string for this warning"; |
| 436 | } |
[email protected] | 03ef4b2a | 2012-03-06 15:04:20 | [diff] [blame] | 437 | } else { |
estark | a3121f6b | 2015-09-18 21:15:59 | [diff] [blame] | 438 | if (security_info.cert_status & net::CERT_STATUS_IS_EV) { |
rsleevi | 4f801272 | 2014-09-30 01:28:01 | [diff] [blame] | 439 | // EV HTTPS page. |
| 440 | site_identity_status_ = GetSiteIdentityStatusByCTInfo( |
estark | a3121f6b | 2015-09-18 21:15:59 | [diff] [blame] | 441 | security_info.sct_verify_statuses, true); |
rsleevi | 4f801272 | 2014-09-30 01:28:01 | [diff] [blame] | 442 | DCHECK(!cert->subject().organization_names.empty()); |
| 443 | organization_name_ = UTF8ToUTF16(cert->subject().organization_names[0]); |
| 444 | // An EV Cert is required to have a city (localityName) and country but |
| 445 | // state is "if any". |
| 446 | DCHECK(!cert->subject().locality_name.empty()); |
| 447 | DCHECK(!cert->subject().country_name.empty()); |
| 448 | base::string16 locality; |
| 449 | if (!cert->subject().state_or_province_name.empty()) { |
| 450 | locality = l10n_util::GetStringFUTF16( |
| 451 | IDS_PAGEINFO_ADDRESS, |
| 452 | UTF8ToUTF16(cert->subject().locality_name), |
| 453 | UTF8ToUTF16(cert->subject().state_or_province_name), |
| 454 | UTF8ToUTF16(cert->subject().country_name)); |
| 455 | } else { |
| 456 | locality = l10n_util::GetStringFUTF16( |
| 457 | IDS_PAGEINFO_PARTIAL_ADDRESS, |
| 458 | UTF8ToUTF16(cert->subject().locality_name), |
| 459 | UTF8ToUTF16(cert->subject().country_name)); |
| 460 | } |
| 461 | DCHECK(!cert->subject().organization_names.empty()); |
| 462 | site_identity_details_.assign(l10n_util::GetStringFUTF16( |
| 463 | GetSiteIdentityDetailsMessageByCTInfo( |
estark | a3121f6b | 2015-09-18 21:15:59 | [diff] [blame] | 464 | security_info.sct_verify_statuses, true /* is EV */), |
| 465 | UTF8ToUTF16(cert->subject().organization_names[0]), locality, |
rsleevi | 4f801272 | 2014-09-30 01:28:01 | [diff] [blame] | 466 | UTF8ToUTF16(cert->issuer().GetDisplayName()))); |
| 467 | } else { |
| 468 | // Non-EV OK HTTPS page. |
| 469 | site_identity_status_ = GetSiteIdentityStatusByCTInfo( |
estark | a3121f6b | 2015-09-18 21:15:59 | [diff] [blame] | 470 | security_info.sct_verify_statuses, false); |
rsleevi | 4f801272 | 2014-09-30 01:28:01 | [diff] [blame] | 471 | base::string16 issuer_name( |
| 472 | UTF8ToUTF16(cert->issuer().GetDisplayName())); |
| 473 | if (issuer_name.empty()) { |
| 474 | issuer_name.assign(l10n_util::GetStringUTF16( |
| 475 | IDS_PAGE_INFO_SECURITY_TAB_UNKNOWN_PARTY)); |
| 476 | } |
[email protected] | 94c74b4 | 2013-12-02 15:19:49 | [diff] [blame] | 477 | |
rsleevi | 4f801272 | 2014-09-30 01:28:01 | [diff] [blame] | 478 | site_identity_details_.assign(l10n_util::GetStringFUTF16( |
| 479 | GetSiteIdentityDetailsMessageByCTInfo( |
estark | a3121f6b | 2015-09-18 21:15:59 | [diff] [blame] | 480 | security_info.sct_verify_statuses, false /* not EV */), |
rsleevi | 4f801272 | 2014-09-30 01:28:01 | [diff] [blame] | 481 | issuer_name)); |
| 482 | } |
lgarron | cc53de2 | 2015-10-05 23:03:17 | [diff] [blame] | 483 | switch (security_info.sha1_deprecation_status) { |
| 484 | case SecurityStateModel::DEPRECATED_SHA1_MINOR: |
| 485 | site_identity_status_ = |
| 486 | SITE_IDENTITY_STATUS_DEPRECATED_SIGNATURE_ALGORITHM_MINOR; |
| 487 | site_identity_details_ += |
| 488 | UTF8ToUTF16("\n\n") + |
| 489 | l10n_util::GetStringUTF16( |
| 490 | IDS_PAGE_INFO_SECURITY_TAB_DEPRECATED_SIGNATURE_ALGORITHM_MINOR); |
| 491 | break; |
| 492 | case SecurityStateModel::DEPRECATED_SHA1_MAJOR: |
| 493 | site_identity_status_ = |
| 494 | SITE_IDENTITY_STATUS_DEPRECATED_SIGNATURE_ALGORITHM_MAJOR; |
| 495 | site_identity_details_ += |
| 496 | UTF8ToUTF16("\n\n") + |
| 497 | l10n_util::GetStringUTF16( |
| 498 | IDS_PAGE_INFO_SECURITY_TAB_DEPRECATED_SIGNATURE_ALGORITHM_MAJOR); |
| 499 | break; |
| 500 | case SecurityStateModel::NO_DEPRECATED_SHA1: |
| 501 | // Nothing to do. |
| 502 | break; |
rsleevi | 4f801272 | 2014-09-30 01:28:01 | [diff] [blame] | 503 | } |
[email protected] | 03ef4b2a | 2012-03-06 15:04:20 | [diff] [blame] | 504 | } |
| 505 | } else { |
| 506 | // HTTP or HTTPS with errors (not warnings). |
| 507 | site_identity_details_.assign(l10n_util::GetStringUTF16( |
| 508 | IDS_PAGE_INFO_SECURITY_TAB_INSECURE_IDENTITY)); |
estark | a3121f6b | 2015-09-18 21:15:59 | [diff] [blame] | 509 | if (!security_info.scheme_is_cryptographic || !security_info.cert_id) |
[email protected] | 03ef4b2a | 2012-03-06 15:04:20 | [diff] [blame] | 510 | site_identity_status_ = SITE_IDENTITY_STATUS_NO_CERT; |
| 511 | else |
| 512 | site_identity_status_ = SITE_IDENTITY_STATUS_ERROR; |
| 513 | |
[email protected] | a04db82 | 2013-12-11 19:14:40 | [diff] [blame] | 514 | const base::string16 bullet = UTF8ToUTF16("\n • "); |
felt | 2493b445 | 2015-09-17 20:33:59 | [diff] [blame] | 515 | std::vector<ssl_errors::ErrorInfo> errors; |
estark | a3121f6b | 2015-09-18 21:15:59 | [diff] [blame] | 516 | ssl_errors::ErrorInfo::GetErrorsForCertStatus( |
| 517 | cert, security_info.cert_status, url, &errors); |
[email protected] | 03ef4b2a | 2012-03-06 15:04:20 | [diff] [blame] | 518 | for (size_t i = 0; i < errors.size(); ++i) { |
| 519 | site_identity_details_ += bullet; |
| 520 | site_identity_details_ += errors[i].short_description(); |
| 521 | } |
| 522 | |
estark | a3121f6b | 2015-09-18 21:15:59 | [diff] [blame] | 523 | if (security_info.cert_status & net::CERT_STATUS_NON_UNIQUE_NAME) { |
[email protected] | 03ef4b2a | 2012-03-06 15:04:20 | [diff] [blame] | 524 | site_identity_details_ += ASCIIToUTF16("\n\n"); |
| 525 | site_identity_details_ += l10n_util::GetStringUTF16( |
| 526 | IDS_PAGE_INFO_SECURITY_TAB_NON_UNIQUE_NAME); |
| 527 | } |
| 528 | } |
| 529 | |
| 530 | // Site Connection |
| 531 | // We consider anything less than 80 bits encryption to be weak encryption. |
| 532 | // TODO(wtc): Bug 1198735: report mixed/unsafe content for unencrypted and |
| 533 | // weakly encrypted connections. |
| 534 | site_connection_status_ = SITE_CONNECTION_STATUS_UNKNOWN; |
| 535 | |
palmer | 153af98 | 2015-09-15 02:04:19 | [diff] [blame] | 536 | base::string16 subject_name(GetSimpleSiteName(url, profile_)); |
| 537 | if (subject_name.empty()) { |
| 538 | subject_name.assign( |
| 539 | l10n_util::GetStringUTF16(IDS_PAGE_INFO_SECURITY_TAB_UNKNOWN_PARTY)); |
| 540 | } |
| 541 | |
estark | a3121f6b | 2015-09-18 21:15:59 | [diff] [blame] | 542 | if (!security_info.cert_id || !security_info.scheme_is_cryptographic) { |
| 543 | // Page is still loading (so SSL status is not yet available) or |
| 544 | // loaded over HTTP or loaded over HTTPS with no cert. |
[email protected] | 1c1051d | 2014-05-10 11:39:58 | [diff] [blame] | 545 | site_connection_status_ = SITE_CONNECTION_STATUS_UNENCRYPTED; |
| 546 | |
| 547 | site_connection_details_.assign(l10n_util::GetStringFUTF16( |
| 548 | IDS_PAGE_INFO_SECURITY_TAB_NOT_ENCRYPTED_CONNECTION_TEXT, |
| 549 | subject_name)); |
estark | a3121f6b | 2015-09-18 21:15:59 | [diff] [blame] | 550 | } else if (security_info.security_bits < 0) { |
| 551 | // Security strength is unknown. Say nothing. |
[email protected] | 03ef4b2a | 2012-03-06 15:04:20 | [diff] [blame] | 552 | site_connection_status_ = SITE_CONNECTION_STATUS_ENCRYPTED_ERROR; |
estark | a3121f6b | 2015-09-18 21:15:59 | [diff] [blame] | 553 | } else if (security_info.security_bits == 0) { |
| 554 | DCHECK_NE(security_info.security_level, SecurityStateModel::NONE); |
[email protected] | 03ef4b2a | 2012-03-06 15:04:20 | [diff] [blame] | 555 | site_connection_status_ = SITE_CONNECTION_STATUS_ENCRYPTED_ERROR; |
| 556 | site_connection_details_.assign(l10n_util::GetStringFUTF16( |
| 557 | IDS_PAGE_INFO_SECURITY_TAB_NOT_ENCRYPTED_CONNECTION_TEXT, |
| 558 | subject_name)); |
[email protected] | 03ef4b2a | 2012-03-06 15:04:20 | [diff] [blame] | 559 | } else { |
| 560 | site_connection_status_ = SITE_CONNECTION_STATUS_ENCRYPTED; |
Adam Langley | 71c2b59b | 2014-11-13 00:34:22 | [diff] [blame] | 561 | |
estark | fd5ca02 | 2015-10-29 21:07:55 | [diff] [blame] | 562 | if (security_info.is_secure_protocol_and_ciphersuite) { |
Adam Langley | 71c2b59b | 2014-11-13 00:34:22 | [diff] [blame] | 563 | site_connection_details_.assign(l10n_util::GetStringFUTF16( |
| 564 | IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTED_CONNECTION_TEXT, |
| 565 | subject_name)); |
| 566 | } else { |
| 567 | site_connection_details_.assign(l10n_util::GetStringFUTF16( |
| 568 | IDS_PAGE_INFO_SECURITY_TAB_WEAK_ENCRYPTION_CONNECTION_TEXT, |
| 569 | subject_name)); |
| 570 | } |
| 571 | |
estark | a3121f6b | 2015-09-18 21:15:59 | [diff] [blame] | 572 | if (security_info.mixed_content_status != |
| 573 | SecurityStateModel::NO_MIXED_CONTENT) { |
[email protected] | 03ef4b2a | 2012-03-06 15:04:20 | [diff] [blame] | 574 | bool ran_insecure_content = |
estark | a3121f6b | 2015-09-18 21:15:59 | [diff] [blame] | 575 | (security_info.mixed_content_status == |
| 576 | SecurityStateModel::RAN_MIXED_CONTENT || |
| 577 | security_info.mixed_content_status == |
| 578 | SecurityStateModel::RAN_AND_DISPLAYED_MIXED_CONTENT); |
palmer | cc7f5f8c | 2015-09-04 01:02:59 | [diff] [blame] | 579 | site_connection_status_ = ran_insecure_content |
| 580 | ? SITE_CONNECTION_STATUS_MIXED_SCRIPT |
| 581 | : SITE_CONNECTION_STATUS_MIXED_CONTENT; |
[email protected] | 03ef4b2a | 2012-03-06 15:04:20 | [diff] [blame] | 582 | site_connection_details_.assign(l10n_util::GetStringFUTF16( |
| 583 | IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTED_SENTENCE_LINK, |
| 584 | site_connection_details_, |
| 585 | l10n_util::GetStringUTF16(ran_insecure_content ? |
| 586 | IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTED_INSECURE_CONTENT_ERROR : |
| 587 | IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTED_INSECURE_CONTENT_WARNING))); |
| 588 | } |
| 589 | } |
| 590 | |
avi | 655876a | 2015-12-25 07:18:15 | [diff] [blame] | 591 | uint16_t cipher_suite = |
estark | a3121f6b | 2015-09-18 21:15:59 | [diff] [blame] | 592 | net::SSLConnectionStatusToCipherSuite(security_info.connection_status); |
| 593 | if (security_info.security_bits > 0 && cipher_suite) { |
[email protected] | 03ef4b2a | 2012-03-06 15:04:20 | [diff] [blame] | 594 | int ssl_version = |
estark | a3121f6b | 2015-09-18 21:15:59 | [diff] [blame] | 595 | net::SSLConnectionStatusToVersion(security_info.connection_status); |
[email protected] | 03ef4b2a | 2012-03-06 15:04:20 | [diff] [blame] | 596 | const char* ssl_version_str; |
| 597 | net::SSLVersionToString(&ssl_version_str, ssl_version); |
| 598 | site_connection_details_ += ASCIIToUTF16("\n\n"); |
| 599 | site_connection_details_ += l10n_util::GetStringFUTF16( |
| 600 | IDS_PAGE_INFO_SECURITY_TAB_SSL_VERSION, |
| 601 | ASCIIToUTF16(ssl_version_str)); |
| 602 | |
[email protected] | 03ef4b2a | 2012-03-06 15:04:20 | [diff] [blame] | 603 | bool no_renegotiation = |
estark | a3121f6b | 2015-09-18 21:15:59 | [diff] [blame] | 604 | (security_info.connection_status & |
| 605 | net::SSL_CONNECTION_NO_RENEGOTIATION_EXTENSION) != 0; |
[email protected] | 03ef4b2a | 2012-03-06 15:04:20 | [diff] [blame] | 606 | const char *key_exchange, *cipher, *mac; |
[email protected] | b6c1d9e8 | 2013-06-12 17:26:57 | [diff] [blame] | 607 | bool is_aead; |
| 608 | net::SSLCipherSuiteToStrings( |
| 609 | &key_exchange, &cipher, &mac, &is_aead, cipher_suite); |
[email protected] | 03ef4b2a | 2012-03-06 15:04:20 | [diff] [blame] | 610 | |
| 611 | site_connection_details_ += ASCIIToUTF16("\n\n"); |
[email protected] | b6c1d9e8 | 2013-06-12 17:26:57 | [diff] [blame] | 612 | if (is_aead) { |
| 613 | site_connection_details_ += l10n_util::GetStringFUTF16( |
| 614 | IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTION_DETAILS_AEAD, |
| 615 | ASCIIToUTF16(cipher), ASCIIToUTF16(key_exchange)); |
| 616 | } else { |
| 617 | site_connection_details_ += l10n_util::GetStringFUTF16( |
| 618 | IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTION_DETAILS, |
| 619 | ASCIIToUTF16(cipher), ASCIIToUTF16(mac), ASCIIToUTF16(key_exchange)); |
| 620 | } |
[email protected] | 03ef4b2a | 2012-03-06 15:04:20 | [diff] [blame] | 621 | |
agl | 078d210 | 2014-10-20 22:03:22 | [diff] [blame] | 622 | if (ssl_version == net::SSL_CONNECTION_VERSION_SSL3 && |
| 623 | site_connection_status_ < SITE_CONNECTION_STATUS_MIXED_CONTENT) { |
| 624 | site_connection_status_ = SITE_CONNECTION_STATUS_ENCRYPTED_ERROR; |
| 625 | } |
| 626 | |
estark | a3121f6b | 2015-09-18 21:15:59 | [diff] [blame] | 627 | const bool did_fallback = (security_info.connection_status & |
| 628 | net::SSL_CONNECTION_VERSION_FALLBACK) != 0; |
[email protected] | 03ef4b2a | 2012-03-06 15:04:20 | [diff] [blame] | 629 | if (did_fallback) { |
[email protected] | 03ef4b2a | 2012-03-06 15:04:20 | [diff] [blame] | 630 | site_connection_details_ += ASCIIToUTF16("\n\n"); |
| 631 | site_connection_details_ += l10n_util::GetStringUTF16( |
| 632 | IDS_PAGE_INFO_SECURITY_TAB_FALLBACK_MESSAGE); |
| 633 | } |
agl | 078d210 | 2014-10-20 22:03:22 | [diff] [blame] | 634 | |
[email protected] | 03ef4b2a | 2012-03-06 15:04:20 | [diff] [blame] | 635 | if (no_renegotiation) { |
| 636 | site_connection_details_ += ASCIIToUTF16("\n\n"); |
| 637 | site_connection_details_ += l10n_util::GetStringUTF16( |
| 638 | IDS_PAGE_INFO_SECURITY_TAB_RENEGOTIATION_MESSAGE); |
| 639 | } |
| 640 | } |
[email protected] | e583f75 | 2012-08-30 13:26:21 | [diff] [blame] | 641 | |
[email protected] | 71cd5ef | 2014-08-13 21:22:04 | [diff] [blame] | 642 | // Check if a user decision has been made to allow or deny certificates with |
| 643 | // errors on this site. |
| 644 | ChromeSSLHostStateDelegate* delegate = |
estark | 7c6bfbf | 2015-09-16 22:20:50 | [diff] [blame] | 645 | ChromeSSLHostStateDelegateFactory::GetForProfile(profile_); |
[email protected] | 71cd5ef | 2014-08-13 21:22:04 | [diff] [blame] | 646 | DCHECK(delegate); |
jww | f806c36 | 2015-06-02 02:00:40 | [diff] [blame] | 647 | // Only show an SSL decision revoke button if the user has chosen to bypass |
| 648 | // SSL host errors for this host in the past. |
| 649 | show_ssl_decision_revoke_button_ = delegate->HasAllowException(url.host()); |
[email protected] | 71cd5ef | 2014-08-13 21:22:04 | [diff] [blame] | 650 | |
palmer | 82b1f7b | 2015-09-17 19:20:41 | [diff] [blame] | 651 | // By default select the Permissions Tab that displays all the site |
| 652 | // permissions. In case of a connection error or an issue with the certificate |
| 653 | // presented by the website, select the Connection Tab to draw the user's |
| 654 | // attention to the issue. If the site does not provide a certificate because |
| 655 | // it was loaded over an unencrypted connection, don't select the Connection |
| 656 | // Tab. |
[email protected] | e583f75 | 2012-08-30 13:26:21 | [diff] [blame] | 657 | WebsiteSettingsUI::TabId tab_id = WebsiteSettingsUI::TAB_ID_PERMISSIONS; |
| 658 | if (site_connection_status_ == SITE_CONNECTION_STATUS_ENCRYPTED_ERROR || |
| 659 | site_connection_status_ == SITE_CONNECTION_STATUS_MIXED_CONTENT || |
estark | f62683e | 2015-09-17 17:52:06 | [diff] [blame] | 660 | site_connection_status_ == SITE_CONNECTION_STATUS_MIXED_SCRIPT || |
[email protected] | e583f75 | 2012-08-30 13:26:21 | [diff] [blame] | 661 | site_identity_status_ == SITE_IDENTITY_STATUS_ERROR || |
estark | 134a982 | 2015-10-29 04:35:18 | [diff] [blame] | 662 | site_identity_status_ == SITE_IDENTITY_STATUS_CT_ERROR || |
[email protected] | eaf3f32 | 2013-04-25 21:53:59 | [diff] [blame] | 663 | site_identity_status_ == SITE_IDENTITY_STATUS_CERT_REVOCATION_UNKNOWN || |
rsleevi | 4f801272 | 2014-09-30 01:28:01 | [diff] [blame] | 664 | site_identity_status_ == SITE_IDENTITY_STATUS_ADMIN_PROVIDED_CERT || |
| 665 | site_identity_status_ == |
lgarron | cc53de2 | 2015-10-05 23:03:17 | [diff] [blame] | 666 | SITE_IDENTITY_STATUS_DEPRECATED_SIGNATURE_ALGORITHM_MINOR || |
| 667 | site_identity_status_ == |
| 668 | SITE_IDENTITY_STATUS_DEPRECATED_SIGNATURE_ALGORITHM_MAJOR) { |
[email protected] | e583f75 | 2012-08-30 13:26:21 | [diff] [blame] | 669 | tab_id = WebsiteSettingsUI::TAB_ID_CONNECTION; |
lgarron | 04a9350 | 2014-11-04 22:25:04 | [diff] [blame] | 670 | RecordWebsiteSettingsAction( |
| 671 | WEBSITE_SETTINGS_CONNECTION_TAB_SHOWN_IMMEDIATELY); |
| 672 | } |
palmer | 82b1f7b | 2015-09-17 19:20:41 | [diff] [blame] | 673 | |
[email protected] | e583f75 | 2012-08-30 13:26:21 | [diff] [blame] | 674 | ui_->SetSelectedTab(tab_id); |
[email protected] | 03ef4b2a | 2012-03-06 15:04:20 | [diff] [blame] | 675 | } |
[email protected] | 0b9fdd7 | 2012-04-04 10:00:33 | [diff] [blame] | 676 | |
[email protected] | df81827 | 2012-04-20 13:10:50 | [diff] [blame] | 677 | void WebsiteSettings::PresentSitePermissions() { |
| 678 | PermissionInfoList permission_info_list; |
reillyg | 85f57db | 2016-01-12 23:14:38 | [diff] [blame] | 679 | ChosenObjectInfoList chosen_object_info_list; |
[email protected] | df81827 | 2012-04-20 13:10:50 | [diff] [blame] | 680 | |
| 681 | WebsiteSettingsUI::PermissionInfo permission_info; |
| 682 | for (size_t i = 0; i < arraysize(kPermissionType); ++i) { |
| 683 | permission_info.type = kPermissionType[i]; |
| 684 | |
mgiuca | a319f21 | 2016-01-14 03:30:11 | [diff] [blame^] | 685 | if (!ShouldShowPermission(permission_info.type)) |
| 686 | continue; |
| 687 | |
[email protected] | df81827 | 2012-04-20 13:10:50 | [diff] [blame] | 688 | content_settings::SettingInfo info; |
sashab | 2b2a314f | 2015-01-17 06:42:21 | [diff] [blame] | 689 | scoped_ptr<base::Value> value = |
raymes | 7dec6d86 | 2015-07-27 07:02:08 | [diff] [blame] | 690 | content_settings_->GetWebsiteSetting( |
sashab | 2b2a314f | 2015-01-17 06:42:21 | [diff] [blame] | 691 | site_url_, site_url_, permission_info.type, std::string(), &info); |
| 692 | DCHECK(value.get()); |
| 693 | if (value->GetType() == base::Value::TYPE_INTEGER) { |
| 694 | permission_info.setting = |
| 695 | content_settings::ValueToContentSetting(value.get()); |
[email protected] | fe4686a | 2012-10-19 15:38:26 | [diff] [blame] | 696 | } else { |
sashab | 2b2a314f | 2015-01-17 06:42:21 | [diff] [blame] | 697 | NOTREACHED(); |
[email protected] | fe4686a | 2012-10-19 15:38:26 | [diff] [blame] | 698 | } |
| 699 | |
[email protected] | 8bdf45c3 | 2012-08-04 00:12:55 | [diff] [blame] | 700 | permission_info.source = info.source; |
[email protected] | df81827 | 2012-04-20 13:10:50 | [diff] [blame] | 701 | |
[email protected] | b1d113d | 2012-06-27 21:27:34 | [diff] [blame] | 702 | if (info.primary_pattern == ContentSettingsPattern::Wildcard() && |
sashab | 2b2a314f | 2015-01-17 06:42:21 | [diff] [blame] | 703 | info.secondary_pattern == ContentSettingsPattern::Wildcard()) { |
[email protected] | b1d113d | 2012-06-27 21:27:34 | [diff] [blame] | 704 | permission_info.default_setting = permission_info.setting; |
| 705 | permission_info.setting = CONTENT_SETTING_DEFAULT; |
| 706 | } else { |
| 707 | permission_info.default_setting = |
| 708 | content_settings_->GetDefaultContentSetting(permission_info.type, |
| 709 | NULL); |
[email protected] | df81827 | 2012-04-20 13:10:50 | [diff] [blame] | 710 | } |
palmer | 0da10b3 | 2015-02-11 00:42:19 | [diff] [blame] | 711 | |
| 712 | if (permission_info.setting != CONTENT_SETTING_DEFAULT && |
| 713 | permission_info.setting != permission_info.default_setting) { |
| 714 | permission_info_list.push_back(permission_info); |
| 715 | } |
[email protected] | df81827 | 2012-04-20 13:10:50 | [diff] [blame] | 716 | } |
| 717 | |
reillyg | 85f57db | 2016-01-12 23:14:38 | [diff] [blame] | 718 | for (const ChooserUIInfo& ui_info : kChooserUIInfo) { |
| 719 | ChooserContextBase* context = ui_info.get_context(profile_); |
| 720 | auto chosen_objects = context->GetGrantedObjects(site_url_, site_url_); |
| 721 | for (scoped_ptr<base::DictionaryValue>& object : chosen_objects) { |
| 722 | chosen_object_info_list.push_back( |
| 723 | new WebsiteSettingsUI::ChosenObjectInfo(ui_info, std::move(object))); |
| 724 | } |
| 725 | } |
| 726 | |
| 727 | ui_->SetPermissionInfo(permission_info_list, chosen_object_info_list); |
[email protected] | 0b9fdd7 | 2012-04-04 10:00:33 | [diff] [blame] | 728 | } |
| 729 | |
[email protected] | df81827 | 2012-04-20 13:10:50 | [diff] [blame] | 730 | void WebsiteSettings::PresentSiteData() { |
| 731 | CookieInfoList cookie_info_list; |
vabr | d5e30cd | 2014-10-02 11:06:03 | [diff] [blame] | 732 | const LocalSharedObjectsCounter& allowed_objects = |
[email protected] | e0ac3589 | 2012-05-15 12:53:34 | [diff] [blame] | 733 | tab_specific_content_settings()->allowed_local_shared_objects(); |
vabr | d5e30cd | 2014-10-02 11:06:03 | [diff] [blame] | 734 | const LocalSharedObjectsCounter& blocked_objects = |
[email protected] | e0ac3589 | 2012-05-15 12:53:34 | [diff] [blame] | 735 | tab_specific_content_settings()->blocked_local_shared_objects(); |
| 736 | |
| 737 | // Add first party cookie and site data counts. |
[email protected] | df81827 | 2012-04-20 13:10:50 | [diff] [blame] | 738 | WebsiteSettingsUI::CookieInfo cookie_info; |
palmer | b14526492 | 2015-08-28 23:53:15 | [diff] [blame] | 739 | cookie_info.cookie_source = |
| 740 | l10n_util::GetStringUTF8(IDS_WEBSITE_SETTINGS_FIRST_PARTY_SITE_DATA); |
[email protected] | e0ac3589 | 2012-05-15 12:53:34 | [diff] [blame] | 741 | cookie_info.allowed = allowed_objects.GetObjectCountForDomain(site_url_); |
| 742 | cookie_info.blocked = blocked_objects.GetObjectCountForDomain(site_url_); |
palmer | b14526492 | 2015-08-28 23:53:15 | [diff] [blame] | 743 | cookie_info.is_first_party = true; |
[email protected] | e0ac3589 | 2012-05-15 12:53:34 | [diff] [blame] | 744 | cookie_info_list.push_back(cookie_info); |
| 745 | |
| 746 | // Add third party cookie counts. |
| 747 | cookie_info.cookie_source = l10n_util::GetStringUTF8( |
| 748 | IDS_WEBSITE_SETTINGS_THIRD_PARTY_SITE_DATA); |
| 749 | cookie_info.allowed = allowed_objects.GetObjectCount() - cookie_info.allowed; |
| 750 | cookie_info.blocked = blocked_objects.GetObjectCount() - cookie_info.blocked; |
palmer | b14526492 | 2015-08-28 23:53:15 | [diff] [blame] | 751 | cookie_info.is_first_party = false; |
[email protected] | df81827 | 2012-04-20 13:10:50 | [diff] [blame] | 752 | cookie_info_list.push_back(cookie_info); |
[email protected] | 0b9fdd7 | 2012-04-04 10:00:33 | [diff] [blame] | 753 | |
[email protected] | df81827 | 2012-04-20 13:10:50 | [diff] [blame] | 754 | ui_->SetCookieInfo(cookie_info_list); |
[email protected] | 0b9fdd7 | 2012-04-04 10:00:33 | [diff] [blame] | 755 | } |
[email protected] | 16de6de | 2012-04-04 12:24:14 | [diff] [blame] | 756 | |
[email protected] | 24c8818c | 2012-04-25 09:57:41 | [diff] [blame] | 757 | void WebsiteSettings::PresentSiteIdentity() { |
palmer | f9b680a | 2015-07-09 18:56:04 | [diff] [blame] | 758 | // After initialization the status about the site's connection and its |
| 759 | // identity must be available. |
[email protected] | 24c8818c | 2012-04-25 09:57:41 | [diff] [blame] | 760 | DCHECK_NE(site_identity_status_, SITE_IDENTITY_STATUS_UNKNOWN); |
| 761 | DCHECK_NE(site_connection_status_, SITE_CONNECTION_STATUS_UNKNOWN); |
| 762 | WebsiteSettingsUI::IdentityInfo info; |
| 763 | if (site_identity_status_ == SITE_IDENTITY_STATUS_EV_CERT) |
| 764 | info.site_identity = UTF16ToUTF8(organization_name()); |
| 765 | else |
palmer | 153af98 | 2015-09-15 02:04:19 | [diff] [blame] | 766 | info.site_identity = UTF16ToUTF8(GetSimpleSiteName(site_url_, profile_)); |
[email protected] | 24c8818c | 2012-04-25 09:57:41 | [diff] [blame] | 767 | |
| 768 | info.connection_status = site_connection_status_; |
| 769 | info.connection_status_description = |
| 770 | UTF16ToUTF8(site_connection_details_); |
| 771 | info.identity_status = site_identity_status_; |
| 772 | info.identity_status_description = |
| 773 | UTF16ToUTF8(site_identity_details_); |
[email protected] | f61c1ce | 2012-05-09 13:55:11 | [diff] [blame] | 774 | info.cert_id = cert_id_; |
[email protected] | 71cd5ef | 2014-08-13 21:22:04 | [diff] [blame] | 775 | info.show_ssl_decision_revoke_button = show_ssl_decision_revoke_button_; |
[email protected] | 24c8818c | 2012-04-25 09:57:41 | [diff] [blame] | 776 | ui_->SetIdentityInfo(info); |
| 777 | } |