blob: 48af6a2c3baf676a665a7c5b7db799cf836d17d3 [file] [log] [blame]
[email protected]03ef4b2a2012-03-06 15:04:201// Copyright (c) 2012 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]4237dd52012-06-05 00:00:325#include "chrome/browser/ui/website_settings/website_settings.h"
[email protected]03ef4b2a2012-03-06 15:04:206
davidben56a8aece2016-10-14 18:20:567#include <openssl/ssl.h>
avi655876a2015-12-25 07:18:158#include <stddef.h>
9#include <stdint.h>
10
[email protected]03ef4b2a2012-03-06 15:04:2011#include <string>
12#include <vector>
13
[email protected]eb2140c2013-07-29 12:37:3414#include "base/command_line.h"
[email protected]15b092542012-05-16 13:08:1415#include "base/i18n/time_formatting.h"
avi655876a2015-12-25 07:18:1516#include "base/macros.h"
[email protected]71cd5ef2014-08-13 21:22:0417#include "base/metrics/field_trial.h"
asvitkine75036032016-09-01 20:49:3418#include "base/metrics/histogram_macros.h"
[email protected]3ea1b182013-02-08 22:38:4119#include "base/strings/string_number_conversions.h"
jialiul02aad2d2015-04-01 18:56:0320#include "base/strings/stringprintf.h"
[email protected]774cc3c2013-06-07 20:26:4521#include "base/strings/utf_string_conversions.h"
[email protected]0b9fdd72012-04-04 10:00:3322#include "base/values.h"
avi655876a2015-12-25 07:18:1523#include "build/build_config.h"
jialiul02aad2d2015-04-01 18:56:0324#include "chrome/browser/browser_process.h"
[email protected]6b8a3c742014-07-25 00:25:3525#include "chrome/browser/browsing_data/browsing_data_channel_id_helper.h"
[email protected]b0cb5e82012-07-19 19:22:4726#include "chrome/browser/browsing_data/browsing_data_cookie_helper.h"
27#include "chrome/browser/browsing_data/browsing_data_database_helper.h"
28#include "chrome/browser/browsing_data/browsing_data_file_system_helper.h"
29#include "chrome/browser/browsing_data/browsing_data_indexed_db_helper.h"
30#include "chrome/browser/browsing_data/browsing_data_local_storage_helper.h"
peconn5100d432015-09-16 12:03:0831#include "chrome/browser/content_settings/host_content_settings_map_factory.h"
vabrbab3ffcb2016-10-04 10:08:1032#include "chrome/browser/content_settings/local_shared_objects_container.h"
[email protected]77a91c72012-08-13 16:19:3433#include "chrome/browser/history/history_service_factory.h"
palmerf2cba0d2015-08-27 23:15:0634#include "chrome/browser/infobars/infobar_service.h"
reillyg85f57db2016-01-12 23:14:3835#include "chrome/browser/permissions/chooser_context_base.h"
tsergeantf1e89352016-01-15 20:34:5436#include "chrome/browser/permissions/permission_uma_util.h"
37#include "chrome/browser/permissions/permission_util.h"
[email protected]03ef4b2a2012-03-06 15:04:2038#include "chrome/browser/profiles/profile.h"
[email protected]71cd5ef2014-08-13 21:22:0439#include "chrome/browser/ssl/chrome_ssl_host_state_delegate.h"
40#include "chrome/browser/ssl/chrome_ssl_host_state_delegate_factory.h"
[email protected]4237dd52012-06-05 00:00:3241#include "chrome/browser/ui/website_settings/website_settings_ui.h"
reillyg85f57db2016-01-12 23:14:3842#include "chrome/browser/usb/usb_chooser_context.h"
43#include "chrome/browser/usb/usb_chooser_context_factory.h"
[email protected]71cd5ef2014-08-13 21:22:0444#include "chrome/common/chrome_switches.h"
sievers2f1e8112015-12-04 18:43:5645#include "chrome/common/features.h"
jsbellddb849e2015-08-27 00:12:5646#include "chrome/common/url_constants.h"
thestig884a1602014-08-27 01:29:3947#include "chrome/grit/chromium_strings.h"
48#include "chrome/grit/generated_resources.h"
reillyg85f57db2016-01-12 23:14:3849#include "chrome/grit/theme_resources.h"
mukai8eaec822014-10-25 17:53:1650#include "components/content_settings/core/browser/content_settings_utils.h"
51#include "components/content_settings/core/browser/host_content_settings_map.h"
palmer0da10b32015-02-11 00:42:1952#include "components/content_settings/core/common/content_settings.h"
vasiliif62dbf92014-09-05 10:23:1353#include "components/content_settings/core/common/content_settings_pattern.h"
jialiul02aad2d2015-04-01 18:56:0354#include "components/rappor/rappor_utils.h"
felt2493b4452015-09-17 20:33:5955#include "components/ssl_errors/error_info.h"
thestig4a2e88e2016-08-27 23:23:5156#include "components/strings/grit/components_chromium_strings.h"
57#include "components/strings/grit/components_strings.h"
palmer153af982015-09-15 02:04:1958#include "components/url_formatter/elide_url.h"
[email protected]0b9fdd72012-04-04 10:00:3359#include "content/public/browser/browser_thread.h"
tsergeantf1e89352016-01-15 20:34:5460#include "content/public/browser/permission_type.h"
[email protected]e22d64f2012-09-10 09:03:2361#include "content/public/browser/user_metrics.h"
[email protected]eb2140c2013-07-29 12:37:3462#include "content/public/common/content_switches.h"
[email protected]03ef4b2a2012-03-06 15:04:2063#include "content/public/common/url_constants.h"
[email protected]6e7845ae2013-03-29 21:48:1164#include "net/cert/cert_status_flags.h"
65#include "net/cert/x509_certificate.h"
[email protected]536fd0b2013-03-14 17:41:5766#include "net/ssl/ssl_cipher_suite_names.h"
67#include "net/ssl/ssl_connection_status_flags.h"
[email protected]03ef4b2a2012-03-06 15:04:2068#include "ui/base/l10n/l10n_util.h"
[email protected]03ef4b2a2012-03-06 15:04:2069
[email protected]24a9f1c92013-11-13 12:33:3770#if defined(OS_CHROMEOS)
71#include "chrome/browser/chromeos/policy/policy_cert_service.h"
72#include "chrome/browser/chromeos/policy/policy_cert_service_factory.h"
73#endif
74
estade3feb83f2015-09-01 23:00:4975#if !defined(OS_ANDROID)
mgiucaa319f212016-01-14 03:30:1176#include "chrome/browser/ui/exclusive_access/exclusive_access_manager.h"
estade3feb83f2015-09-01 23:00:4977#include "chrome/browser/ui/website_settings/website_settings_infobar_delegate.h"
78#endif
79
[email protected]ab6df3b12013-12-24 23:32:2680using base::ASCIIToUTF16;
81using base::UTF8ToUTF16;
[email protected]f729d7a2013-12-26 07:07:5682using base::UTF16ToUTF8;
[email protected]0b9fdd72012-04-04 10:00:3383using content::BrowserThread;
estarkd9e54fb2016-01-11 19:37:1284using security_state::SecurityStateModel;
[email protected]0b9fdd72012-04-04 10:00:3385
86namespace {
87
jww1ed8ea72014-09-02 20:43:2588// Events for UMA. Do not reorder or change!
89enum SSLCertificateDecisionsDidRevoke {
90 USER_CERT_DECISIONS_NOT_REVOKED = 0,
91 USER_CERT_DECISIONS_REVOKED,
92 END_OF_SSL_CERTIFICATE_DECISIONS_DID_REVOKE_ENUM
93};
94
palmer0da10b32015-02-11 00:42:1995// The list of content settings types to display on the Website Settings UI. THE
96// ORDER OF THESE ITEMS IS IMPORTANT. To propose changing it, email
97// [email protected].
[email protected]0b9fdd72012-04-04 10:00:3398ContentSettingsType kPermissionType[] = {
sashab2b2a314f2015-01-17 06:42:2199 CONTENT_SETTINGS_TYPE_GEOLOCATION,
sashab2b2a314f2015-01-17 06:42:21100 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA,
101 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC,
palmer0da10b32015-02-11 00:42:19102 CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
palmer7715e332016-05-27 00:41:19103 CONTENT_SETTINGS_TYPE_JAVASCRIPT,
lshange085f202016-06-14 01:25:08104#if !defined(OS_ANDROID)
palmer7715e332016-05-27 00:41:19105 CONTENT_SETTINGS_TYPE_PLUGINS,
106 CONTENT_SETTINGS_TYPE_IMAGES,
lshange085f202016-06-14 01:25:08107#endif
palmer7715e332016-05-27 00:41:19108 CONTENT_SETTINGS_TYPE_POPUPS,
nsatragno670fe922016-04-08 14:10:50109 CONTENT_SETTINGS_TYPE_BACKGROUND_SYNC,
palmer7715e332016-05-27 00:41:19110 CONTENT_SETTINGS_TYPE_KEYGEN,
111 CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS,
lshange085f202016-06-14 01:25:08112#if !defined(OS_ANDROID)
palmer7715e332016-05-27 00:41:19113 CONTENT_SETTINGS_TYPE_MOUSELOCK,
lshange085f202016-06-14 01:25:08114#endif
palmer7715e332016-05-27 00:41:19115 CONTENT_SETTINGS_TYPE_FULLSCREEN,
finnur46cafd42016-09-22 10:27:17116 CONTENT_SETTINGS_TYPE_AUTOPLAY,
palmer7715e332016-05-27 00:41:19117 CONTENT_SETTINGS_TYPE_MIDI_SYSEX,
[email protected]0b9fdd72012-04-04 10:00:33118};
119
mgiucaa319f212016-01-14 03:30:11120// Determines whether to show permission |type| in the Website Settings UI. Only
121// applies to permissions listed in |kPermissionType|.
122bool ShouldShowPermission(ContentSettingsType type) {
mgiuca0f3e1f72016-05-13 01:56:27123 // TODO(mgiuca): When simplified-fullscreen-ui is enabled permanently on
124 // Android, remove these from kPermissionType, rather than having this check
mgiucaa319f212016-01-14 03:30:11125 // (http://crbug.com/577396).
126#if !defined(OS_ANDROID)
mgiuca0f3e1f72016-05-13 01:56:27127 // Fullscreen and mouselock settings are no longer shown (always allow).
finnur46cafd42016-09-22 10:27:17128 // Autoplay is Android-only at the moment.
129 if (type == CONTENT_SETTINGS_TYPE_AUTOPLAY ||
130 type == CONTENT_SETTINGS_TYPE_FULLSCREEN ||
mgiucaa319f212016-01-14 03:30:11131 type == CONTENT_SETTINGS_TYPE_MOUSELOCK) {
mgiuca0f3e1f72016-05-13 01:56:27132 return false;
mgiucaa319f212016-01-14 03:30:11133 }
134#endif
135
136 return true;
137}
138
estark00e83f12016-08-19 18:24:04139void CheckContentStatus(SecurityStateModel::ContentStatus content_status,
140 bool* displayed,
141 bool* ran) {
142 switch (content_status) {
143 case SecurityStateModel::CONTENT_STATUS_DISPLAYED:
144 *displayed = true;
145 break;
146 case SecurityStateModel::CONTENT_STATUS_RAN:
147 *ran = true;
148 break;
149 case SecurityStateModel::CONTENT_STATUS_DISPLAYED_AND_RAN:
150 *displayed = true;
151 *ran = true;
152 break;
153 case SecurityStateModel::CONTENT_STATUS_UNKNOWN:
154 case SecurityStateModel::CONTENT_STATUS_NONE:
155 break;
156 }
157}
158
159void CheckForInsecureContent(
160 const SecurityStateModel::SecurityInfo& security_info,
161 bool* displayed,
162 bool* ran) {
163 CheckContentStatus(security_info.mixed_content_status, displayed, ran);
164 // Only consider subresources with certificate errors if the main
165 // resource was loaded over HTTPS without major certificate errors. If
166 // the main resource had a certificate error, then it would not be
167 // that useful (and would potentially be confusing) to warn about
168 // subesources that had certificate errors too.
169 if (net::IsCertStatusError(security_info.cert_status) &&
170 !net::IsCertStatusMinorError(security_info.cert_status)) {
171 return;
172 }
173 CheckContentStatus(security_info.content_with_cert_errors_status, displayed,
174 ran);
175}
176
estark134a9822015-10-29 04:35:18177// Returns true if any of the given statuses match |status|.
178bool CertificateTransparencyStatusMatchAny(
estarka3121f6b2015-09-18 21:15:59179 const std::vector<net::ct::SCTVerifyStatus>& sct_verify_statuses,
[email protected]94c74b42013-12-02 15:19:49180 net::ct::SCTVerifyStatus status) {
estarka3121f6b2015-09-18 21:15:59181 for (const auto& verify_status : sct_verify_statuses) {
182 if (verify_status == status)
[email protected]94c74b42013-12-02 15:19:49183 return true;
184 }
[email protected]94c74b42013-12-02 15:19:49185 return false;
186}
187
188int GetSiteIdentityDetailsMessageByCTInfo(
estarka3121f6b2015-09-18 21:15:59189 const std::vector<net::ct::SCTVerifyStatus>& sct_verify_statuses,
[email protected]94c74b42013-12-02 15:19:49190 bool is_ev) {
191 // No SCTs - no CT information.
estarka3121f6b2015-09-18 21:15:59192 if (sct_verify_statuses.empty())
[email protected]94c74b42013-12-02 15:19:49193 return (is_ev ? IDS_PAGE_INFO_SECURITY_TAB_SECURE_IDENTITY_EV_NO_CT
194 : IDS_PAGE_INFO_SECURITY_TAB_SECURE_IDENTITY_NO_CT);
195
estark134a9822015-10-29 04:35:18196 // Any valid SCT.
197 if (CertificateTransparencyStatusMatchAny(sct_verify_statuses,
198 net::ct::SCT_STATUS_OK))
[email protected]94c74b42013-12-02 15:19:49199 return (is_ev ? IDS_PAGE_INFO_SECURITY_TAB_SECURE_IDENTITY_EV_CT_VERIFIED
200 : IDS_PAGE_INFO_SECURITY_TAB_SECURE_IDENTITY_CT_VERIFIED);
201
estark134a9822015-10-29 04:35:18202 // Any invalid SCT.
eranmb082a9ff2016-09-13 21:03:26203 if (CertificateTransparencyStatusMatchAny(
eranm194b45d2016-08-18 10:00:33204 sct_verify_statuses, net::ct::SCT_STATUS_INVALID_TIMESTAMP) ||
205 CertificateTransparencyStatusMatchAny(
206 sct_verify_statuses, net::ct::SCT_STATUS_INVALID_SIGNATURE))
[email protected]94c74b42013-12-02 15:19:49207 return (is_ev ? IDS_PAGE_INFO_SECURITY_TAB_SECURE_IDENTITY_EV_CT_INVALID
208 : IDS_PAGE_INFO_SECURITY_TAB_SECURE_IDENTITY_CT_INVALID);
209
estark134a9822015-10-29 04:35:18210 // All SCTs are from unknown logs.
[email protected]94c74b42013-12-02 15:19:49211 return (is_ev ? IDS_PAGE_INFO_SECURITY_TAB_SECURE_IDENTITY_EV_CT_UNVERIFIED
212 : IDS_PAGE_INFO_SECURITY_TAB_SECURE_IDENTITY_CT_UNVERIFIED);
213}
214
215// This function will return SITE_IDENTITY_STATUS_CERT or
estark134a9822015-10-29 04:35:18216// SITE_IDENTITY_STATUS_EV_CERT depending on |is_ev| unless all SCTs
217// failed verification, in which case it will return
[email protected]94c74b42013-12-02 15:19:49218// SITE_IDENTITY_STATUS_ERROR.
219WebsiteSettings::SiteIdentityStatus GetSiteIdentityStatusByCTInfo(
estarka3121f6b2015-09-18 21:15:59220 const std::vector<net::ct::SCTVerifyStatus>& sct_verify_statuses,
[email protected]94c74b42013-12-02 15:19:49221 bool is_ev) {
estark134a9822015-10-29 04:35:18222 if (sct_verify_statuses.empty() ||
223 CertificateTransparencyStatusMatchAny(sct_verify_statuses,
224 net::ct::SCT_STATUS_OK))
225 return is_ev ? WebsiteSettings::SITE_IDENTITY_STATUS_EV_CERT
226 : WebsiteSettings::SITE_IDENTITY_STATUS_CERT;
[email protected]94c74b42013-12-02 15:19:49227
estark134a9822015-10-29 04:35:18228 return WebsiteSettings::SITE_IDENTITY_STATUS_CT_ERROR;
[email protected]94c74b42013-12-02 15:19:49229}
230
jshin1fb76462016-04-05 22:13:03231base::string16 GetSimpleSiteName(const GURL& url) {
benwells2337b8102016-04-20 01:53:53232 return url_formatter::FormatUrlForSecurityDisplay(
233 url, url_formatter::SchemeDisplay::OMIT_HTTP_AND_HTTPS);
palmer153af982015-09-15 02:04:19234}
235
reillyg85f57db2016-01-12 23:14:38236ChooserContextBase* GetUsbChooserContext(Profile* profile) {
237 return UsbChooserContextFactory::GetForProfile(profile);
238}
239
240// The list of chooser types that need to display entries in the Website
241// Settings UI. THE ORDER OF THESE ITEMS IS IMPORTANT. To propose changing it,
242// email [email protected].
243WebsiteSettings::ChooserUIInfo kChooserUIInfo[] = {
reillyg58f82ab2016-08-03 01:49:52244 {CONTENT_SETTINGS_TYPE_USB_CHOOSER_DATA, &GetUsbChooserContext,
245 IDR_BLOCKED_USB, IDR_ALLOWED_USB, IDS_WEBSITE_SETTINGS_USB_DEVICE_LABEL,
reillyg85f57db2016-01-12 23:14:38246 IDS_WEBSITE_SETTINGS_DELETE_USB_DEVICE, "name"},
247};
248
[email protected]0b9fdd72012-04-04 10:00:33249} // namespace
250
251WebsiteSettings::WebsiteSettings(
252 WebsiteSettingsUI* ui,
253 Profile* profile,
[email protected]df818272012-04-20 13:10:50254 TabSpecificContentSettings* tab_specific_content_settings,
palmerf2cba0d2015-08-27 23:15:06255 content::WebContents* web_contents,
[email protected]0b9fdd72012-04-04 10:00:33256 const GURL& url,
jam8ae7cad2016-09-08 23:55:21257 const SecurityStateModel::SecurityInfo& security_info)
[email protected]df818272012-04-20 13:10:50258 : TabSpecificContentSettings::SiteDataObserver(
259 tab_specific_content_settings),
dominicknbdd53b5f2016-09-28 01:08:13260 content::WebContentsObserver(web_contents),
[email protected]df818272012-04-20 13:10:50261 ui_(ui),
[email protected]66f157312012-08-01 13:50:26262 show_info_bar_(false),
[email protected]0b9fdd72012-04-04 10:00:33263 site_url_(url),
264 site_identity_status_(SITE_IDENTITY_STATUS_UNKNOWN),
[email protected]03ef4b2a2012-03-06 15:04:20265 site_connection_status_(SITE_CONNECTION_STATUS_UNKNOWN),
peconn5100d432015-09-16 12:03:08266 content_settings_(HostContentSettingsMapFactory::GetForProfile(profile)),
[email protected]71cd5ef2014-08-13 21:22:04267 chrome_ssl_host_state_delegate_(
jww1ed8ea72014-09-02 20:43:25268 ChromeSSLHostStateDelegateFactory::GetForProfile(profile)),
palmer153af982015-09-15 02:04:19269 did_revoke_user_ssl_decisions_(false),
270 profile_(profile) {
estarka3121f6b2015-09-18 21:15:59271 Init(url, security_info);
[email protected]0b9fdd72012-04-04 10:00:33272
273 PresentSitePermissions();
[email protected]df818272012-04-20 13:10:50274 PresentSiteData();
[email protected]24c8818c2012-04-25 09:57:41275 PresentSiteIdentity();
[email protected]e22d64f2012-09-10 09:03:23276
277 // Every time the Website Settings UI is opened a |WebsiteSettings| object is
278 // created. So this counts how ofter the Website Settings UI is opened.
lgarron04a93502014-11-04 22:25:04279 RecordWebsiteSettingsAction(WEBSITE_SETTINGS_OPENED);
[email protected]03ef4b2a2012-03-06 15:04:20280}
281
[email protected]0b9fdd72012-04-04 10:00:33282WebsiteSettings::~WebsiteSettings() {
[email protected]03ef4b2a2012-03-06 15:04:20283}
284
lgarron04a93502014-11-04 22:25:04285void WebsiteSettings::RecordWebsiteSettingsAction(
286 WebsiteSettingsAction action) {
287 UMA_HISTOGRAM_ENUMERATION("WebsiteSettings.Action",
288 action,
289 WEBSITE_SETTINGS_COUNT);
290
291 // Use a separate histogram to record actions if they are done on a page with
292 // an HTTPS URL. Note that this *disregards* security status.
palmeree0e5af2015-06-05 03:10:40293 //
294
295 // TODO(palmer): Consider adding a new histogram for
296 // GURL::SchemeIsCryptographic. (We don't want to replace this call with a
297 // call to that function because we don't want to change the meanings of
298 // existing metrics.) This would inform the decision to mark non-secure
299 // origins as Dubious or Non-Secure; the overall bug for that is
300 // crbug.com/454579.
lgarron04a93502014-11-04 22:25:04301 if (site_url_.SchemeIs(url::kHttpsScheme)) {
302 UMA_HISTOGRAM_ENUMERATION("WebsiteSettings.Action.HttpsUrl",
303 action,
304 WEBSITE_SETTINGS_COUNT);
305 }
306}
307
[email protected]df818272012-04-20 13:10:50308void WebsiteSettings::OnSitePermissionChanged(ContentSettingsType type,
309 ContentSetting setting) {
[email protected]e22d64f2012-09-10 09:03:23310 // Count how often a permission for a specific content type is changed using
311 // the Website Settings UI.
raymes4a13d432015-09-08 00:44:07312 size_t num_values;
313 int histogram_value = ContentSettingTypeToHistogramValue(type, &num_values);
sashab9debecd2014-12-18 04:15:56314 UMA_HISTOGRAM_ENUMERATION("WebsiteSettings.OriginInfo.PermissionChanged",
raymes4a13d432015-09-08 00:44:07315 histogram_value, num_values);
sashab9debecd2014-12-18 04:15:56316
317 if (setting == ContentSetting::CONTENT_SETTING_ALLOW) {
318 UMA_HISTOGRAM_ENUMERATION(
319 "WebsiteSettings.OriginInfo.PermissionChanged.Allowed", histogram_value,
raymes4a13d432015-09-08 00:44:07320 num_values);
tommycli34cf29bf2016-09-08 05:46:25321
322 if (type == CONTENT_SETTINGS_TYPE_PLUGINS) {
323 rappor::SampleDomainAndRegistryFromGURL(
324 g_browser_process->rappor_service(),
325 "ContentSettings.Plugins.AddedAllowException", site_url_);
326 }
sashab9debecd2014-12-18 04:15:56327 } else if (setting == ContentSetting::CONTENT_SETTING_BLOCK) {
328 UMA_HISTOGRAM_ENUMERATION(
329 "WebsiteSettings.OriginInfo.PermissionChanged.Blocked", histogram_value,
raymes4a13d432015-09-08 00:44:07330 num_values);
sashab9debecd2014-12-18 04:15:56331 }
[email protected]e22d64f2012-09-10 09:03:23332
lgarron04a93502014-11-04 22:25:04333 // This is technically redundant given the histogram above, but putting the
334 // total count of permission changes in another histogram makes it easier to
335 // compare it against other kinds of actions in WebsiteSettings[PopupView].
336 RecordWebsiteSettingsAction(WEBSITE_SETTINGS_CHANGED_PERMISSION);
337
stefanocs8b3490cc2016-07-28 05:32:52338 PermissionUtil::ScopedRevocationReporter scoped_revocation_reporter(
339 this->profile_, this->site_url_, this->site_url_, type,
340 PermissionSourceUI::OIB);
341
raymesfbaaaaa2015-11-10 02:20:40342 content_settings_->SetNarrowestContentSetting(site_url_, site_url_, type,
343 setting);
[email protected]df818272012-04-20 13:10:50344
[email protected]66f157312012-08-01 13:50:26345 show_info_bar_ = true;
[email protected]2f45d542012-08-22 08:47:24346
[email protected]2f45d542012-08-22 08:47:24347 // Refresh the UI to reflect the new setting.
348 PresentSitePermissions();
[email protected]df818272012-04-20 13:10:50349}
350
reillyg85f57db2016-01-12 23:14:38351void WebsiteSettings::OnSiteChosenObjectDeleted(
352 const ChooserUIInfo& ui_info,
353 const base::DictionaryValue& object) {
354 // TODO(reillyg): Create metrics for revocations. crbug.com/556845
355 ChooserContextBase* context = ui_info.get_context(profile_);
reillyg36a7fab32016-01-28 19:15:10356 const GURL origin = site_url_.GetOrigin();
357 context->RevokeObjectPermission(origin, origin, object);
reillyg85f57db2016-01-12 23:14:38358
359 show_info_bar_ = true;
360
361 // Refresh the UI to reflect the changed settings.
362 PresentSitePermissions();
363}
364
[email protected]df818272012-04-20 13:10:50365void WebsiteSettings::OnSiteDataAccessed() {
366 PresentSiteData();
[email protected]0b9fdd72012-04-04 10:00:33367}
368
[email protected]66f157312012-08-01 13:50:26369void WebsiteSettings::OnUIClosing() {
estade3feb83f2015-09-01 23:00:49370#if defined(OS_ANDROID)
371 NOTREACHED();
372#else
dominicknbdd53b5f2016-09-28 01:08:13373 if (show_info_bar_ && web_contents() && !web_contents()->IsBeingDestroyed()) {
palmerf2cba0d2015-08-27 23:15:06374 InfoBarService* infobar_service =
dominicknbdd53b5f2016-09-28 01:08:13375 InfoBarService::FromWebContents(web_contents());
palmerf2cba0d2015-08-27 23:15:06376 if (infobar_service)
377 WebsiteSettingsInfoBarDelegate::Create(infobar_service);
378 }
jww1ed8ea72014-09-02 20:43:25379
380 SSLCertificateDecisionsDidRevoke user_decision =
381 did_revoke_user_ssl_decisions_ ? USER_CERT_DECISIONS_REVOKED
382 : USER_CERT_DECISIONS_NOT_REVOKED;
383
384 UMA_HISTOGRAM_ENUMERATION("interstitial.ssl.did_user_revoke_decisions",
385 user_decision,
386 END_OF_SSL_CERTIFICATE_DECISIONS_DID_REVOKE_ENUM);
estade3feb83f2015-09-01 23:00:49387#endif
jww1ed8ea72014-09-02 20:43:25388}
389
390void WebsiteSettings::OnRevokeSSLErrorBypassButtonPressed() {
391 DCHECK(chrome_ssl_host_state_delegate_);
jww6a55df72014-09-05 19:59:29392 chrome_ssl_host_state_delegate_->RevokeUserAllowExceptionsHard(
393 site_url().host());
jww1ed8ea72014-09-02 20:43:25394 did_revoke_user_ssl_decisions_ = true;
[email protected]66f157312012-08-01 13:50:26395}
396
estarka3121f6b2015-09-18 21:15:59397void WebsiteSettings::Init(
398 const GURL& url,
399 const SecurityStateModel::SecurityInfo& security_info) {
meacerde53fcff2016-10-12 19:21:57400#if !defined(OS_ANDROID) && !defined(OS_IOS)
401 // On desktop, internal URLs aren't handled by this class. Instead, a
402 // custom and simpler popup is shown.
403 DCHECK(!url.SchemeIs(content::kChromeUIScheme) &&
404 !url.SchemeIs(content::kChromeDevToolsScheme) &&
405 !url.SchemeIs(content::kViewSourceScheme) &&
406 !url.SchemeIs(content_settings::kExtensionScheme));
407#endif
408
sashab97894ce2014-10-22 10:08:33409 bool isChromeUINativeScheme = false;
sievers2f1e8112015-12-04 18:43:56410#if BUILDFLAG(ANDROID_JAVA_UI)
sashab97894ce2014-10-22 10:08:33411 isChromeUINativeScheme = url.SchemeIs(chrome::kChromeUINativeScheme);
412#endif
413
upendrag.gowda60886a6e2015-10-31 05:51:09414 if (url.SchemeIs(url::kAboutScheme)) {
415 // All about: URLs except about:blank are redirected.
416 DCHECK_EQ(url::kAboutBlankURL, url.spec());
417 site_identity_status_ = SITE_IDENTITY_STATUS_NO_CERT;
418 site_identity_details_ =
419 l10n_util::GetStringUTF16(IDS_PAGE_INFO_SECURITY_TAB_INSECURE_IDENTITY);
420 site_connection_status_ = SITE_CONNECTION_STATUS_UNENCRYPTED;
421 site_connection_details_ = l10n_util::GetStringFUTF16(
422 IDS_PAGE_INFO_SECURITY_TAB_NOT_ENCRYPTED_CONNECTION_TEXT,
423 UTF8ToUTF16(url.spec()));
424 return;
425 }
426
427 if (url.SchemeIs(content::kChromeUIScheme) || isChromeUINativeScheme) {
[email protected]03ef4b2a2012-03-06 15:04:20428 site_identity_status_ = SITE_IDENTITY_STATUS_INTERNAL_PAGE;
429 site_identity_details_ =
430 l10n_util::GetStringUTF16(IDS_PAGE_INFO_INTERNAL_PAGE);
431 site_connection_status_ = SITE_CONNECTION_STATUS_INTERNAL_PAGE;
432 return;
433 }
434
[email protected]03ef4b2a2012-03-06 15:04:20435 // Identity section.
jam8ae7cad2016-09-08 23:55:21436 certificate_ = security_info.certificate;
[email protected]f61c1ce2012-05-09 13:55:11437
estarka3121f6b2015-09-18 21:15:59438 // HTTPS with no or minor errors.
jam8ae7cad2016-09-08 23:55:21439 if (certificate_ &&
estarka3121f6b2015-09-18 21:15:59440 (!net::IsCertStatusError(security_info.cert_status) ||
441 net::IsCertStatusMinorError(security_info.cert_status))) {
[email protected]03ef4b2a2012-03-06 15:04:20442 // There are no major errors. Check for minor errors.
estarka3121f6b2015-09-18 21:15:59443 if (security_info.security_level ==
felt89f3f212016-09-27 00:20:30444 SecurityStateModel::SECURE_WITH_POLICY_INSTALLED_CERT) {
[email protected]eaf3f322013-04-25 21:53:59445 site_identity_status_ = SITE_IDENTITY_STATUS_ADMIN_PROVIDED_CERT;
[email protected]24a9f1c92013-11-13 12:33:37446 site_identity_details_ = l10n_util::GetStringFUTF16(
447 IDS_CERT_POLICY_PROVIDED_CERT_MESSAGE, UTF8ToUTF16(url.host()));
estarka3121f6b2015-09-18 21:15:59448 } else if (net::IsCertStatusMinorError(security_info.cert_status)) {
[email protected]03ef4b2a2012-03-06 15:04:20449 site_identity_status_ = SITE_IDENTITY_STATUS_CERT_REVOCATION_UNKNOWN;
jam8ae7cad2016-09-08 23:55:21450 base::string16 issuer_name(
451 UTF8ToUTF16(certificate_->issuer().GetDisplayName()));
[email protected]03ef4b2a2012-03-06 15:04:20452 if (issuer_name.empty()) {
453 issuer_name.assign(l10n_util::GetStringUTF16(
454 IDS_PAGE_INFO_SECURITY_TAB_UNKNOWN_PARTY));
455 }
[email protected]94c74b42013-12-02 15:19:49456
[email protected]03ef4b2a2012-03-06 15:04:20457 site_identity_details_.assign(l10n_util::GetStringFUTF16(
[email protected]94c74b42013-12-02 15:19:49458 GetSiteIdentityDetailsMessageByCTInfo(
estarka3121f6b2015-09-18 21:15:59459 security_info.sct_verify_statuses, false /* not EV */),
[email protected]94c74b42013-12-02 15:19:49460 issuer_name));
[email protected]03ef4b2a2012-03-06 15:04:20461
462 site_identity_details_ += ASCIIToUTF16("\n\n");
estarka3121f6b2015-09-18 21:15:59463 if (security_info.cert_status &
464 net::CERT_STATUS_UNABLE_TO_CHECK_REVOCATION) {
[email protected]03ef4b2a2012-03-06 15:04:20465 site_identity_details_ += l10n_util::GetStringUTF16(
466 IDS_PAGE_INFO_SECURITY_TAB_UNABLE_TO_CHECK_REVOCATION);
estarka3121f6b2015-09-18 21:15:59467 } else if (security_info.cert_status &
468 net::CERT_STATUS_NO_REVOCATION_MECHANISM) {
[email protected]03ef4b2a2012-03-06 15:04:20469 site_identity_details_ += l10n_util::GetStringUTF16(
470 IDS_PAGE_INFO_SECURITY_TAB_NO_REVOCATION_MECHANISM);
471 } else {
472 NOTREACHED() << "Need to specify string for this warning";
473 }
[email protected]03ef4b2a2012-03-06 15:04:20474 } else {
estarka3121f6b2015-09-18 21:15:59475 if (security_info.cert_status & net::CERT_STATUS_IS_EV) {
rsleevi4f8012722014-09-30 01:28:01476 // EV HTTPS page.
477 site_identity_status_ = GetSiteIdentityStatusByCTInfo(
estarka3121f6b2015-09-18 21:15:59478 security_info.sct_verify_statuses, true);
jam8ae7cad2016-09-08 23:55:21479 DCHECK(!certificate_->subject().organization_names.empty());
480 organization_name_ =
481 UTF8ToUTF16(certificate_->subject().organization_names[0]);
rsleevi4f8012722014-09-30 01:28:01482 // An EV Cert is required to have a city (localityName) and country but
483 // state is "if any".
jam8ae7cad2016-09-08 23:55:21484 DCHECK(!certificate_->subject().locality_name.empty());
485 DCHECK(!certificate_->subject().country_name.empty());
rsleevi4f8012722014-09-30 01:28:01486 base::string16 locality;
jam8ae7cad2016-09-08 23:55:21487 if (!certificate_->subject().state_or_province_name.empty()) {
rsleevi4f8012722014-09-30 01:28:01488 locality = l10n_util::GetStringFUTF16(
489 IDS_PAGEINFO_ADDRESS,
jam8ae7cad2016-09-08 23:55:21490 UTF8ToUTF16(certificate_->subject().locality_name),
491 UTF8ToUTF16(certificate_->subject().state_or_province_name),
492 UTF8ToUTF16(certificate_->subject().country_name));
rsleevi4f8012722014-09-30 01:28:01493 } else {
494 locality = l10n_util::GetStringFUTF16(
495 IDS_PAGEINFO_PARTIAL_ADDRESS,
jam8ae7cad2016-09-08 23:55:21496 UTF8ToUTF16(certificate_->subject().locality_name),
497 UTF8ToUTF16(certificate_->subject().country_name));
rsleevi4f8012722014-09-30 01:28:01498 }
jam8ae7cad2016-09-08 23:55:21499 DCHECK(!certificate_->subject().organization_names.empty());
rsleevi4f8012722014-09-30 01:28:01500 site_identity_details_.assign(l10n_util::GetStringFUTF16(
501 GetSiteIdentityDetailsMessageByCTInfo(
estarka3121f6b2015-09-18 21:15:59502 security_info.sct_verify_statuses, true /* is EV */),
jam8ae7cad2016-09-08 23:55:21503 UTF8ToUTF16(certificate_->subject().organization_names[0]),
504 locality,
505 UTF8ToUTF16(certificate_->issuer().GetDisplayName())));
rsleevi4f8012722014-09-30 01:28:01506 } else {
507 // Non-EV OK HTTPS page.
508 site_identity_status_ = GetSiteIdentityStatusByCTInfo(
estarka3121f6b2015-09-18 21:15:59509 security_info.sct_verify_statuses, false);
rsleevi4f8012722014-09-30 01:28:01510 base::string16 issuer_name(
jam8ae7cad2016-09-08 23:55:21511 UTF8ToUTF16(certificate_->issuer().GetDisplayName()));
rsleevi4f8012722014-09-30 01:28:01512 if (issuer_name.empty()) {
513 issuer_name.assign(l10n_util::GetStringUTF16(
514 IDS_PAGE_INFO_SECURITY_TAB_UNKNOWN_PARTY));
515 }
[email protected]94c74b42013-12-02 15:19:49516
rsleevi4f8012722014-09-30 01:28:01517 site_identity_details_.assign(l10n_util::GetStringFUTF16(
518 GetSiteIdentityDetailsMessageByCTInfo(
estarka3121f6b2015-09-18 21:15:59519 security_info.sct_verify_statuses, false /* not EV */),
rsleevi4f8012722014-09-30 01:28:01520 issuer_name));
521 }
lgarroncc53de22015-10-05 23:03:17522 switch (security_info.sha1_deprecation_status) {
523 case SecurityStateModel::DEPRECATED_SHA1_MINOR:
524 site_identity_status_ =
525 SITE_IDENTITY_STATUS_DEPRECATED_SIGNATURE_ALGORITHM_MINOR;
526 site_identity_details_ +=
527 UTF8ToUTF16("\n\n") +
528 l10n_util::GetStringUTF16(
529 IDS_PAGE_INFO_SECURITY_TAB_DEPRECATED_SIGNATURE_ALGORITHM_MINOR);
530 break;
531 case SecurityStateModel::DEPRECATED_SHA1_MAJOR:
532 site_identity_status_ =
533 SITE_IDENTITY_STATUS_DEPRECATED_SIGNATURE_ALGORITHM_MAJOR;
534 site_identity_details_ +=
535 UTF8ToUTF16("\n\n") +
536 l10n_util::GetStringUTF16(
537 IDS_PAGE_INFO_SECURITY_TAB_DEPRECATED_SIGNATURE_ALGORITHM_MAJOR);
538 break;
539 case SecurityStateModel::NO_DEPRECATED_SHA1:
540 // Nothing to do.
541 break;
felt61638452016-08-09 22:21:55542 case SecurityStateModel::UNKNOWN_SHA1:
543 // UNKNOWN_SHA1 should only appear when certificate info has not been
544 // initialized, in which case this if-statement should not be running
545 // because there is no other cert info.
546 NOTREACHED();
rsleevi4f8012722014-09-30 01:28:01547 }
[email protected]03ef4b2a2012-03-06 15:04:20548 }
549 } else {
550 // HTTP or HTTPS with errors (not warnings).
551 site_identity_details_.assign(l10n_util::GetStringUTF16(
552 IDS_PAGE_INFO_SECURITY_TAB_INSECURE_IDENTITY));
jam8ae7cad2016-09-08 23:55:21553 if (!security_info.scheme_is_cryptographic || !security_info.certificate)
[email protected]03ef4b2a2012-03-06 15:04:20554 site_identity_status_ = SITE_IDENTITY_STATUS_NO_CERT;
555 else
556 site_identity_status_ = SITE_IDENTITY_STATUS_ERROR;
557
[email protected]a04db822013-12-11 19:14:40558 const base::string16 bullet = UTF8ToUTF16("\n • ");
felt2493b4452015-09-17 20:33:59559 std::vector<ssl_errors::ErrorInfo> errors;
estarka3121f6b2015-09-18 21:15:59560 ssl_errors::ErrorInfo::GetErrorsForCertStatus(
jam8ae7cad2016-09-08 23:55:21561 certificate_, security_info.cert_status, url, &errors);
[email protected]03ef4b2a2012-03-06 15:04:20562 for (size_t i = 0; i < errors.size(); ++i) {
563 site_identity_details_ += bullet;
564 site_identity_details_ += errors[i].short_description();
565 }
566
estarka3121f6b2015-09-18 21:15:59567 if (security_info.cert_status & net::CERT_STATUS_NON_UNIQUE_NAME) {
[email protected]03ef4b2a2012-03-06 15:04:20568 site_identity_details_ += ASCIIToUTF16("\n\n");
569 site_identity_details_ += l10n_util::GetStringUTF16(
570 IDS_PAGE_INFO_SECURITY_TAB_NON_UNIQUE_NAME);
571 }
572 }
573
574 // Site Connection
575 // We consider anything less than 80 bits encryption to be weak encryption.
576 // TODO(wtc): Bug 1198735: report mixed/unsafe content for unencrypted and
577 // weakly encrypted connections.
578 site_connection_status_ = SITE_CONNECTION_STATUS_UNKNOWN;
579
jshin1fb76462016-04-05 22:13:03580 base::string16 subject_name(GetSimpleSiteName(url));
palmer153af982015-09-15 02:04:19581 if (subject_name.empty()) {
582 subject_name.assign(
583 l10n_util::GetStringUTF16(IDS_PAGE_INFO_SECURITY_TAB_UNKNOWN_PARTY));
584 }
585
jam8ae7cad2016-09-08 23:55:21586 if (!security_info.certificate || !security_info.scheme_is_cryptographic) {
estarka3121f6b2015-09-18 21:15:59587 // Page is still loading (so SSL status is not yet available) or
588 // loaded over HTTP or loaded over HTTPS with no cert.
[email protected]1c1051d2014-05-10 11:39:58589 site_connection_status_ = SITE_CONNECTION_STATUS_UNENCRYPTED;
590
591 site_connection_details_.assign(l10n_util::GetStringFUTF16(
592 IDS_PAGE_INFO_SECURITY_TAB_NOT_ENCRYPTED_CONNECTION_TEXT,
593 subject_name));
estarka3121f6b2015-09-18 21:15:59594 } else if (security_info.security_bits < 0) {
595 // Security strength is unknown. Say nothing.
[email protected]03ef4b2a2012-03-06 15:04:20596 site_connection_status_ = SITE_CONNECTION_STATUS_ENCRYPTED_ERROR;
estarka3121f6b2015-09-18 21:15:59597 } else if (security_info.security_bits == 0) {
598 DCHECK_NE(security_info.security_level, SecurityStateModel::NONE);
[email protected]03ef4b2a2012-03-06 15:04:20599 site_connection_status_ = SITE_CONNECTION_STATUS_ENCRYPTED_ERROR;
600 site_connection_details_.assign(l10n_util::GetStringFUTF16(
601 IDS_PAGE_INFO_SECURITY_TAB_NOT_ENCRYPTED_CONNECTION_TEXT,
602 subject_name));
[email protected]03ef4b2a2012-03-06 15:04:20603 } else {
604 site_connection_status_ = SITE_CONNECTION_STATUS_ENCRYPTED;
Adam Langley71c2b59b2014-11-13 00:34:22605
lgarron3e2c33e2016-08-25 06:33:43606 if (security_info.obsolete_ssl_status == net::OBSOLETE_SSL_NONE) {
Adam Langley71c2b59b2014-11-13 00:34:22607 site_connection_details_.assign(l10n_util::GetStringFUTF16(
608 IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTED_CONNECTION_TEXT,
609 subject_name));
610 } else {
611 site_connection_details_.assign(l10n_util::GetStringFUTF16(
612 IDS_PAGE_INFO_SECURITY_TAB_WEAK_ENCRYPTION_CONNECTION_TEXT,
613 subject_name));
614 }
615
estark00e83f12016-08-19 18:24:04616 bool ran_insecure_content = false;
617 bool displayed_insecure_content = false;
618 CheckForInsecureContent(security_info, &displayed_insecure_content,
619 &ran_insecure_content);
620 if (ran_insecure_content || displayed_insecure_content) {
621 site_connection_status_ =
622 ran_insecure_content
623 ? SITE_CONNECTION_STATUS_INSECURE_ACTIVE_SUBRESOURCE
624 : SITE_CONNECTION_STATUS_INSECURE_PASSIVE_SUBRESOURCE;
[email protected]03ef4b2a2012-03-06 15:04:20625 site_connection_details_.assign(l10n_util::GetStringFUTF16(
626 IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTED_SENTENCE_LINK,
627 site_connection_details_,
estark00e83f12016-08-19 18:24:04628 l10n_util::GetStringUTF16(
629 ran_insecure_content
630 ? IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTED_INSECURE_CONTENT_ERROR
631 : IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTED_INSECURE_CONTENT_WARNING)));
[email protected]03ef4b2a2012-03-06 15:04:20632 }
633 }
634
avi655876a2015-12-25 07:18:15635 uint16_t cipher_suite =
estarka3121f6b2015-09-18 21:15:59636 net::SSLConnectionStatusToCipherSuite(security_info.connection_status);
637 if (security_info.security_bits > 0 && cipher_suite) {
[email protected]03ef4b2a2012-03-06 15:04:20638 int ssl_version =
estarka3121f6b2015-09-18 21:15:59639 net::SSLConnectionStatusToVersion(security_info.connection_status);
[email protected]03ef4b2a2012-03-06 15:04:20640 const char* ssl_version_str;
641 net::SSLVersionToString(&ssl_version_str, ssl_version);
642 site_connection_details_ += ASCIIToUTF16("\n\n");
643 site_connection_details_ += l10n_util::GetStringFUTF16(
644 IDS_PAGE_INFO_SECURITY_TAB_SSL_VERSION,
645 ASCIIToUTF16(ssl_version_str));
646
[email protected]03ef4b2a2012-03-06 15:04:20647 bool no_renegotiation =
estarka3121f6b2015-09-18 21:15:59648 (security_info.connection_status &
649 net::SSL_CONNECTION_NO_RENEGOTIATION_EXTENSION) != 0;
[email protected]03ef4b2a2012-03-06 15:04:20650 const char *key_exchange, *cipher, *mac;
davidben56a8aece2016-10-14 18:20:56651 bool is_aead, is_tls13;
652 net::SSLCipherSuiteToStrings(&key_exchange, &cipher, &mac, &is_aead,
653 &is_tls13, cipher_suite);
[email protected]03ef4b2a2012-03-06 15:04:20654
655 site_connection_details_ += ASCIIToUTF16("\n\n");
[email protected]b6c1d9e82013-06-12 17:26:57656 if (is_aead) {
davidben56a8aece2016-10-14 18:20:56657 if (is_tls13) {
658 // For TLS 1.3 ciphers, report the group (historically, curve) as the
659 // key exchange.
660 key_exchange = SSL_get_curve_name(security_info.key_exchange_group);
661 if (!key_exchange) {
662 NOTREACHED();
663 key_exchange = "";
664 }
665 }
[email protected]b6c1d9e82013-06-12 17:26:57666 site_connection_details_ += l10n_util::GetStringFUTF16(
667 IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTION_DETAILS_AEAD,
668 ASCIIToUTF16(cipher), ASCIIToUTF16(key_exchange));
669 } else {
670 site_connection_details_ += l10n_util::GetStringFUTF16(
671 IDS_PAGE_INFO_SECURITY_TAB_ENCRYPTION_DETAILS,
672 ASCIIToUTF16(cipher), ASCIIToUTF16(mac), ASCIIToUTF16(key_exchange));
673 }
[email protected]03ef4b2a2012-03-06 15:04:20674
agl078d2102014-10-20 22:03:22675 if (ssl_version == net::SSL_CONNECTION_VERSION_SSL3 &&
estark00e83f12016-08-19 18:24:04676 site_connection_status_ <
677 SITE_CONNECTION_STATUS_INSECURE_PASSIVE_SUBRESOURCE) {
agl078d2102014-10-20 22:03:22678 site_connection_status_ = SITE_CONNECTION_STATUS_ENCRYPTED_ERROR;
679 }
680
[email protected]03ef4b2a2012-03-06 15:04:20681 if (no_renegotiation) {
682 site_connection_details_ += ASCIIToUTF16("\n\n");
683 site_connection_details_ += l10n_util::GetStringUTF16(
684 IDS_PAGE_INFO_SECURITY_TAB_RENEGOTIATION_MESSAGE);
685 }
686 }
[email protected]e583f752012-08-30 13:26:21687
[email protected]71cd5ef2014-08-13 21:22:04688 // Check if a user decision has been made to allow or deny certificates with
689 // errors on this site.
690 ChromeSSLHostStateDelegate* delegate =
estark7c6bfbf2015-09-16 22:20:50691 ChromeSSLHostStateDelegateFactory::GetForProfile(profile_);
[email protected]71cd5ef2014-08-13 21:22:04692 DCHECK(delegate);
jwwf806c362015-06-02 02:00:40693 // Only show an SSL decision revoke button if the user has chosen to bypass
694 // SSL host errors for this host in the past.
695 show_ssl_decision_revoke_button_ = delegate->HasAllowException(url.host());
[email protected]71cd5ef2014-08-13 21:22:04696
palmer82b1f7b2015-09-17 19:20:41697 // By default select the Permissions Tab that displays all the site
698 // permissions. In case of a connection error or an issue with the certificate
699 // presented by the website, select the Connection Tab to draw the user's
700 // attention to the issue. If the site does not provide a certificate because
701 // it was loaded over an unencrypted connection, don't select the Connection
702 // Tab.
[email protected]e583f752012-08-30 13:26:21703 WebsiteSettingsUI::TabId tab_id = WebsiteSettingsUI::TAB_ID_PERMISSIONS;
704 if (site_connection_status_ == SITE_CONNECTION_STATUS_ENCRYPTED_ERROR ||
estark00e83f12016-08-19 18:24:04705 site_connection_status_ ==
706 SITE_CONNECTION_STATUS_INSECURE_PASSIVE_SUBRESOURCE ||
707 site_connection_status_ ==
708 SITE_CONNECTION_STATUS_INSECURE_ACTIVE_SUBRESOURCE ||
[email protected]e583f752012-08-30 13:26:21709 site_identity_status_ == SITE_IDENTITY_STATUS_ERROR ||
estark134a9822015-10-29 04:35:18710 site_identity_status_ == SITE_IDENTITY_STATUS_CT_ERROR ||
[email protected]eaf3f322013-04-25 21:53:59711 site_identity_status_ == SITE_IDENTITY_STATUS_CERT_REVOCATION_UNKNOWN ||
rsleevi4f8012722014-09-30 01:28:01712 site_identity_status_ == SITE_IDENTITY_STATUS_ADMIN_PROVIDED_CERT ||
713 site_identity_status_ ==
lgarroncc53de22015-10-05 23:03:17714 SITE_IDENTITY_STATUS_DEPRECATED_SIGNATURE_ALGORITHM_MINOR ||
715 site_identity_status_ ==
716 SITE_IDENTITY_STATUS_DEPRECATED_SIGNATURE_ALGORITHM_MAJOR) {
[email protected]e583f752012-08-30 13:26:21717 tab_id = WebsiteSettingsUI::TAB_ID_CONNECTION;
lgarron04a93502014-11-04 22:25:04718 RecordWebsiteSettingsAction(
719 WEBSITE_SETTINGS_CONNECTION_TAB_SHOWN_IMMEDIATELY);
720 }
palmer82b1f7b2015-09-17 19:20:41721
[email protected]e583f752012-08-30 13:26:21722 ui_->SetSelectedTab(tab_id);
[email protected]03ef4b2a2012-03-06 15:04:20723}
[email protected]0b9fdd72012-04-04 10:00:33724
[email protected]df818272012-04-20 13:10:50725void WebsiteSettings::PresentSitePermissions() {
726 PermissionInfoList permission_info_list;
reillyg85f57db2016-01-12 23:14:38727 ChosenObjectInfoList chosen_object_info_list;
[email protected]df818272012-04-20 13:10:50728
729 WebsiteSettingsUI::PermissionInfo permission_info;
730 for (size_t i = 0; i < arraysize(kPermissionType); ++i) {
731 permission_info.type = kPermissionType[i];
732
mgiucaa319f212016-01-14 03:30:11733 if (!ShouldShowPermission(permission_info.type))
734 continue;
735
[email protected]df818272012-04-20 13:10:50736 content_settings::SettingInfo info;
dcheng9603ab92016-04-08 04:17:32737 std::unique_ptr<base::Value> value = content_settings_->GetWebsiteSetting(
738 site_url_, site_url_, permission_info.type, std::string(), &info);
sashab2b2a314f2015-01-17 06:42:21739 DCHECK(value.get());
740 if (value->GetType() == base::Value::TYPE_INTEGER) {
741 permission_info.setting =
742 content_settings::ValueToContentSetting(value.get());
[email protected]fe4686a2012-10-19 15:38:26743 } else {
sashab2b2a314f2015-01-17 06:42:21744 NOTREACHED();
[email protected]fe4686a2012-10-19 15:38:26745 }
746
[email protected]8bdf45c32012-08-04 00:12:55747 permission_info.source = info.source;
johnme9ed93882016-01-15 01:13:28748 permission_info.is_incognito = profile_->IsOffTheRecord();
[email protected]df818272012-04-20 13:10:50749
[email protected]b1d113d2012-06-27 21:27:34750 if (info.primary_pattern == ContentSettingsPattern::Wildcard() &&
sashab2b2a314f2015-01-17 06:42:21751 info.secondary_pattern == ContentSettingsPattern::Wildcard()) {
[email protected]b1d113d2012-06-27 21:27:34752 permission_info.default_setting = permission_info.setting;
753 permission_info.setting = CONTENT_SETTING_DEFAULT;
754 } else {
755 permission_info.default_setting =
756 content_settings_->GetDefaultContentSetting(permission_info.type,
757 NULL);
[email protected]df818272012-04-20 13:10:50758 }
palmer0da10b32015-02-11 00:42:19759
palmer64a099982016-03-09 21:26:11760 if (permission_info.type == CONTENT_SETTINGS_TYPE_KEYGEN &&
761 (permission_info.setting == CONTENT_SETTING_DEFAULT ||
762 permission_info.setting == permission_info.default_setting) &&
763 !tab_specific_content_settings()->IsContentBlocked(
764 permission_info.type)) {
765 continue;
palmer0da10b32015-02-11 00:42:19766 }
palmer64a099982016-03-09 21:26:11767 permission_info_list.push_back(permission_info);
[email protected]df818272012-04-20 13:10:50768 }
769
reillyg85f57db2016-01-12 23:14:38770 for (const ChooserUIInfo& ui_info : kChooserUIInfo) {
771 ChooserContextBase* context = ui_info.get_context(profile_);
reillyg36a7fab32016-01-28 19:15:10772 const GURL origin = site_url_.GetOrigin();
773 auto chosen_objects = context->GetGrantedObjects(origin, origin);
dcheng9603ab92016-04-08 04:17:32774 for (std::unique_ptr<base::DictionaryValue>& object : chosen_objects) {
reillyg85f57db2016-01-12 23:14:38775 chosen_object_info_list.push_back(
776 new WebsiteSettingsUI::ChosenObjectInfo(ui_info, std::move(object)));
777 }
778 }
779
780 ui_->SetPermissionInfo(permission_info_list, chosen_object_info_list);
[email protected]0b9fdd72012-04-04 10:00:33781}
782
[email protected]df818272012-04-20 13:10:50783void WebsiteSettings::PresentSiteData() {
784 CookieInfoList cookie_info_list;
vabrbab3ffcb2016-10-04 10:08:10785 const LocalSharedObjectsContainer& allowed_objects =
[email protected]e0ac35892012-05-15 12:53:34786 tab_specific_content_settings()->allowed_local_shared_objects();
vabrbab3ffcb2016-10-04 10:08:10787 const LocalSharedObjectsContainer& blocked_objects =
[email protected]e0ac35892012-05-15 12:53:34788 tab_specific_content_settings()->blocked_local_shared_objects();
789
790 // Add first party cookie and site data counts.
[email protected]df818272012-04-20 13:10:50791 WebsiteSettingsUI::CookieInfo cookie_info;
[email protected]e0ac35892012-05-15 12:53:34792 cookie_info.allowed = allowed_objects.GetObjectCountForDomain(site_url_);
793 cookie_info.blocked = blocked_objects.GetObjectCountForDomain(site_url_);
palmerb145264922015-08-28 23:53:15794 cookie_info.is_first_party = true;
[email protected]e0ac35892012-05-15 12:53:34795 cookie_info_list.push_back(cookie_info);
796
797 // Add third party cookie counts.
[email protected]e0ac35892012-05-15 12:53:34798 cookie_info.allowed = allowed_objects.GetObjectCount() - cookie_info.allowed;
799 cookie_info.blocked = blocked_objects.GetObjectCount() - cookie_info.blocked;
palmerb145264922015-08-28 23:53:15800 cookie_info.is_first_party = false;
[email protected]df818272012-04-20 13:10:50801 cookie_info_list.push_back(cookie_info);
[email protected]0b9fdd72012-04-04 10:00:33802
[email protected]df818272012-04-20 13:10:50803 ui_->SetCookieInfo(cookie_info_list);
[email protected]0b9fdd72012-04-04 10:00:33804}
[email protected]16de6de2012-04-04 12:24:14805
[email protected]24c8818c2012-04-25 09:57:41806void WebsiteSettings::PresentSiteIdentity() {
palmerf9b680a2015-07-09 18:56:04807 // After initialization the status about the site's connection and its
808 // identity must be available.
[email protected]24c8818c2012-04-25 09:57:41809 DCHECK_NE(site_identity_status_, SITE_IDENTITY_STATUS_UNKNOWN);
810 DCHECK_NE(site_connection_status_, SITE_CONNECTION_STATUS_UNKNOWN);
811 WebsiteSettingsUI::IdentityInfo info;
812 if (site_identity_status_ == SITE_IDENTITY_STATUS_EV_CERT)
813 info.site_identity = UTF16ToUTF8(organization_name());
814 else
jshin1fb76462016-04-05 22:13:03815 info.site_identity = UTF16ToUTF8(GetSimpleSiteName(site_url_));
[email protected]24c8818c2012-04-25 09:57:41816
817 info.connection_status = site_connection_status_;
818 info.connection_status_description =
819 UTF16ToUTF8(site_connection_details_);
820 info.identity_status = site_identity_status_;
821 info.identity_status_description =
822 UTF16ToUTF8(site_identity_details_);
jam8ae7cad2016-09-08 23:55:21823 info.certificate = certificate_;
[email protected]71cd5ef2014-08-13 21:22:04824 info.show_ssl_decision_revoke_button = show_ssl_decision_revoke_button_;
[email protected]24c8818c2012-04-25 09:57:41825 ui_->SetIdentityInfo(info);
826}