Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(250)

Side by Side Diff: chrome/browser/ui/website_settings/website_settings.cc

Issue 2702923002: Page Info: Hide default permissions with a value of Ask if the default is Ask. (Closed)
Patch Set: Fix #ifdef to allow testing MacViews. Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/website_settings/website_settings.h" 5 #include "chrome/browser/ui/website_settings/website_settings.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <string> 10 #include <string>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/command_line.h" 13 #include "base/command_line.h"
14 #include "base/feature_list.h"
14 #include "base/i18n/time_formatting.h" 15 #include "base/i18n/time_formatting.h"
15 #include "base/macros.h" 16 #include "base/macros.h"
16 #include "base/memory/ptr_util.h" 17 #include "base/memory/ptr_util.h"
17 #include "base/metrics/field_trial.h" 18 #include "base/metrics/field_trial.h"
18 #include "base/metrics/histogram_macros.h" 19 #include "base/metrics/histogram_macros.h"
19 #include "base/strings/string_number_conversions.h" 20 #include "base/strings/string_number_conversions.h"
20 #include "base/strings/utf_string_conversions.h" 21 #include "base/strings/utf_string_conversions.h"
21 #include "base/values.h" 22 #include "base/values.h"
22 #include "build/build_config.h" 23 #include "build/build_config.h"
23 #include "chrome/browser/browser_process.h" 24 #include "chrome/browser/browser_process.h"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 #include "content/public/browser/permission_type.h" 60 #include "content/public/browser/permission_type.h"
60 #include "content/public/browser/user_metrics.h" 61 #include "content/public/browser/user_metrics.h"
61 #include "content/public/common/content_switches.h" 62 #include "content/public/common/content_switches.h"
62 #include "content/public/common/url_constants.h" 63 #include "content/public/common/url_constants.h"
63 #include "net/cert/cert_status_flags.h" 64 #include "net/cert/cert_status_flags.h"
64 #include "net/cert/x509_certificate.h" 65 #include "net/cert/x509_certificate.h"
65 #include "net/ssl/ssl_cipher_suite_names.h" 66 #include "net/ssl/ssl_cipher_suite_names.h"
66 #include "net/ssl/ssl_connection_status_flags.h" 67 #include "net/ssl/ssl_connection_status_flags.h"
67 #include "third_party/boringssl/src/include/openssl/ssl.h" 68 #include "third_party/boringssl/src/include/openssl/ssl.h"
68 #include "ui/base/l10n/l10n_util.h" 69 #include "ui/base/l10n/l10n_util.h"
70 #include "ui/base/material_design/material_design_controller.h"
69 71
70 #if defined(OS_CHROMEOS) 72 #if defined(OS_CHROMEOS)
71 #include "chrome/browser/chromeos/policy/policy_cert_service.h" 73 #include "chrome/browser/chromeos/policy/policy_cert_service.h"
72 #include "chrome/browser/chromeos/policy/policy_cert_service_factory.h" 74 #include "chrome/browser/chromeos/policy/policy_cert_service_factory.h"
73 #endif 75 #endif
74 76
75 #if !defined(OS_ANDROID) 77 #if !defined(OS_ANDROID)
76 #include "chrome/browser/ui/exclusive_access/exclusive_access_manager.h" 78 #include "chrome/browser/ui/exclusive_access/exclusive_access_manager.h"
77 #include "chrome/browser/ui/website_settings/website_settings_infobar_delegate.h " 79 #include "chrome/browser/ui/website_settings/website_settings_infobar_delegate.h "
78 #endif 80 #endif
79 81
80 using base::ASCIIToUTF16; 82 using base::ASCIIToUTF16;
81 using base::UTF8ToUTF16; 83 using base::UTF8ToUTF16;
82 using base::UTF16ToUTF8; 84 using base::UTF16ToUTF8;
83 using content::BrowserThread; 85 using content::BrowserThread;
84 86
85 namespace { 87 namespace {
86 88
89 // TODO(crbug.com/695725): Change this to FEATURE_DISABLED_BY_DEFAULT
90 const base::Feature kPageInfoAlwaysShowAllPermissions{
91 "PageInfoAlwaysShowAllPermissions", base::FEATURE_ENABLED_BY_DEFAULT};
92
87 // Events for UMA. Do not reorder or change! 93 // Events for UMA. Do not reorder or change!
88 enum SSLCertificateDecisionsDidRevoke { 94 enum SSLCertificateDecisionsDidRevoke {
89 USER_CERT_DECISIONS_NOT_REVOKED = 0, 95 USER_CERT_DECISIONS_NOT_REVOKED = 0,
90 USER_CERT_DECISIONS_REVOKED, 96 USER_CERT_DECISIONS_REVOKED,
91 END_OF_SSL_CERTIFICATE_DECISIONS_DID_REVOKE_ENUM 97 END_OF_SSL_CERTIFICATE_DECISIONS_DID_REVOKE_ENUM
92 }; 98 };
93 99
94 // The list of content settings types to display on the Website Settings UI. THE 100 // The list of content settings types to display on the Website Settings UI. THE
95 // ORDER OF THESE ITEMS IS IMPORTANT. To propose changing it, email 101 // ORDER OF THESE ITEMS IS IMPORTANT. To propose changing it, email
96 // security-dev@chromium.org. 102 // security-dev@chromium.org.
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 WebsiteSettingsUI* ui, 217 WebsiteSettingsUI* ui,
212 Profile* profile, 218 Profile* profile,
213 TabSpecificContentSettings* tab_specific_content_settings, 219 TabSpecificContentSettings* tab_specific_content_settings,
214 content::WebContents* web_contents, 220 content::WebContents* web_contents,
215 const GURL& url, 221 const GURL& url,
216 const security_state::SecurityInfo& security_info) 222 const security_state::SecurityInfo& security_info)
217 : TabSpecificContentSettings::SiteDataObserver( 223 : TabSpecificContentSettings::SiteDataObserver(
218 tab_specific_content_settings), 224 tab_specific_content_settings),
219 content::WebContentsObserver(web_contents), 225 content::WebContentsObserver(web_contents),
220 ui_(ui), 226 ui_(ui),
227 show_all_permissions_(false),
221 show_info_bar_(false), 228 show_info_bar_(false),
222 site_url_(url), 229 site_url_(url),
223 site_identity_status_(SITE_IDENTITY_STATUS_UNKNOWN), 230 site_identity_status_(SITE_IDENTITY_STATUS_UNKNOWN),
224 site_connection_status_(SITE_CONNECTION_STATUS_UNKNOWN), 231 site_connection_status_(SITE_CONNECTION_STATUS_UNKNOWN),
225 show_ssl_decision_revoke_button_(false), 232 show_ssl_decision_revoke_button_(false),
226 content_settings_(HostContentSettingsMapFactory::GetForProfile(profile)), 233 content_settings_(HostContentSettingsMapFactory::GetForProfile(profile)),
227 chrome_ssl_host_state_delegate_( 234 chrome_ssl_host_state_delegate_(
228 ChromeSSLHostStateDelegateFactory::GetForProfile(profile)), 235 ChromeSSLHostStateDelegateFactory::GetForProfile(profile)),
229 did_revoke_user_ssl_decisions_(false), 236 did_revoke_user_ssl_decisions_(false),
230 profile_(profile), 237 profile_(profile),
231 security_level_(security_state::NONE) { 238 security_level_(security_state::NONE) {
232 Init(url, security_info); 239 Init(url, security_info);
233 240
241 if (base::FeatureList::IsEnabled(kPageInfoAlwaysShowAllPermissions)) {
242 show_all_permissions_ = true;
243 }
244
234 PresentSitePermissions(); 245 PresentSitePermissions();
235 PresentSiteData(); 246 PresentSiteData();
236 PresentSiteIdentity(); 247 PresentSiteIdentity();
237 248
238 // Every time the Website Settings UI is opened a |WebsiteSettings| object is 249 // Every time the Website Settings UI is opened a |WebsiteSettings| object is
239 // created. So this counts how ofter the Website Settings UI is opened. 250 // created. So this counts how ofter the Website Settings UI is opened.
240 RecordWebsiteSettingsAction(WEBSITE_SETTINGS_OPENED); 251 RecordWebsiteSettingsAction(WEBSITE_SETTINGS_OPENED);
241 } 252 }
242 253
243 WebsiteSettings::~WebsiteSettings() { 254 WebsiteSettings::~WebsiteSettings() {
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 321
311 PermissionUtil::ScopedRevocationReporter scoped_revocation_reporter( 322 PermissionUtil::ScopedRevocationReporter scoped_revocation_reporter(
312 this->profile_, this->site_url_, this->site_url_, type, 323 this->profile_, this->site_url_, this->site_url_, type,
313 PermissionSourceUI::OIB); 324 PermissionSourceUI::OIB);
314 325
315 content_settings_->SetNarrowestContentSetting(site_url_, site_url_, type, 326 content_settings_->SetNarrowestContentSetting(site_url_, site_url_, type,
316 setting); 327 setting);
317 328
318 show_info_bar_ = true; 329 show_info_bar_ = true;
319 330
320 // Refresh the UI to reflect the new setting. 331 #if defined(OS_MACOSX)
332 // TODO(crbug.com/695690, crbug.com/695723): This is currently only needed on
333 // Cocoa, and breaks accessibility.
334 if (!ui::MaterialDesignController::IsSecondaryUiMaterial()) {
335 // Refresh the UI to reflect the new setting.
336 PresentSitePermissions();
337 }
338 #endif
339 }
340
341 void WebsiteSettings::OnPresentAllSitePermissions() {
342 show_all_permissions_ = true;
321 PresentSitePermissions(); 343 PresentSitePermissions();
322 } 344 }
323 345
324 void WebsiteSettings::OnSiteChosenObjectDeleted( 346 void WebsiteSettings::OnSiteChosenObjectDeleted(
325 const ChooserUIInfo& ui_info, 347 const ChooserUIInfo& ui_info,
326 const base::DictionaryValue& object) { 348 const base::DictionaryValue& object) {
327 // TODO(reillyg): Create metrics for revocations. crbug.com/556845 349 // TODO(reillyg): Create metrics for revocations. crbug.com/556845
328 ChooserContextBase* context = ui_info.get_context(profile_); 350 ChooserContextBase* context = ui_info.get_context(profile_);
329 const GURL origin = site_url_.GetOrigin(); 351 const GURL origin = site_url_.GetOrigin();
330 context->RevokeObjectPermission(origin, origin, object); 352 context->RevokeObjectPermission(origin, origin, object);
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
637 DCHECK(delegate); 659 DCHECK(delegate);
638 // Only show an SSL decision revoke button if the user has chosen to bypass 660 // Only show an SSL decision revoke button if the user has chosen to bypass
639 // SSL host errors for this host in the past. 661 // SSL host errors for this host in the past.
640 show_ssl_decision_revoke_button_ = delegate->HasAllowException(url.host()); 662 show_ssl_decision_revoke_button_ = delegate->HasAllowException(url.host());
641 } 663 }
642 664
643 void WebsiteSettings::PresentSitePermissions() { 665 void WebsiteSettings::PresentSitePermissions() {
644 PermissionInfoList permission_info_list; 666 PermissionInfoList permission_info_list;
645 ChosenObjectInfoList chosen_object_info_list; 667 ChosenObjectInfoList chosen_object_info_list;
646 668
669 bool anyPermissionsShown = false;
670 bool anyPermissionsHidden = false;
671
647 WebsiteSettingsUI::PermissionInfo permission_info; 672 WebsiteSettingsUI::PermissionInfo permission_info;
648 for (size_t i = 0; i < arraysize(kPermissionType); ++i) { 673 for (size_t i = 0; i < arraysize(kPermissionType); ++i) {
649 permission_info.type = kPermissionType[i]; 674 permission_info.type = kPermissionType[i];
650 675
651 if (!ShouldShowPermission(permission_info.type)) 676 if (!ShouldShowPermission(permission_info.type))
652 continue; 677 continue;
653 678
654 content_settings::SettingInfo info; 679 content_settings::SettingInfo info;
655 std::unique_ptr<base::Value> value = content_settings_->GetWebsiteSetting( 680 std::unique_ptr<base::Value> value = content_settings_->GetWebsiteSetting(
656 site_url_, site_url_, permission_info.type, std::string(), &info); 681 site_url_, site_url_, permission_info.type, std::string(), &info);
682
657 DCHECK(value.get()); 683 DCHECK(value.get());
658 if (value->GetType() == base::Value::Type::INTEGER) { 684 if (value->GetType() == base::Value::Type::INTEGER) {
659 permission_info.setting = 685 permission_info.setting =
660 content_settings::ValueToContentSetting(value.get()); 686 content_settings::ValueToContentSetting(value.get());
661 } else { 687 } else {
662 NOTREACHED(); 688 NOTREACHED();
663 } 689 }
664 690
665 permission_info.source = info.source; 691 permission_info.source = info.source;
666 permission_info.is_incognito = profile_->IsOffTheRecord(); 692 permission_info.is_incognito = profile_->IsOffTheRecord();
667 693
668 if (info.primary_pattern == ContentSettingsPattern::Wildcard() && 694 if (info.primary_pattern == ContentSettingsPattern::Wildcard() &&
669 info.secondary_pattern == ContentSettingsPattern::Wildcard()) { 695 info.secondary_pattern == ContentSettingsPattern::Wildcard()) {
670 permission_info.default_setting = permission_info.setting; 696 permission_info.default_setting = permission_info.setting;
671 permission_info.setting = CONTENT_SETTING_DEFAULT; 697 permission_info.setting = CONTENT_SETTING_DEFAULT;
672 } else { 698 } else {
673 permission_info.default_setting = 699 permission_info.default_setting =
674 content_settings_->GetDefaultContentSetting(permission_info.type, 700 content_settings_->GetDefaultContentSetting(permission_info.type,
675 NULL); 701 NULL);
676 } 702 }
677 703
678 permission_info_list.push_back(permission_info); 704 if (show_all_permissions_ ||
705 permission_info.setting != CONTENT_SETTING_DEFAULT) {
706 permission_info_list.push_back(permission_info);
707 anyPermissionsShown = true;
708 } else {
709 anyPermissionsHidden = true;
710 }
679 } 711 }
680 712
681 for (const ChooserUIInfo& ui_info : kChooserUIInfo) { 713 for (const ChooserUIInfo& ui_info : kChooserUIInfo) {
682 ChooserContextBase* context = ui_info.get_context(profile_); 714 ChooserContextBase* context = ui_info.get_context(profile_);
683 const GURL origin = site_url_.GetOrigin(); 715 const GURL origin = site_url_.GetOrigin();
684 auto chosen_objects = context->GetGrantedObjects(origin, origin); 716 auto chosen_objects = context->GetGrantedObjects(origin, origin);
685 for (std::unique_ptr<base::DictionaryValue>& object : chosen_objects) { 717 for (std::unique_ptr<base::DictionaryValue>& object : chosen_objects) {
686 chosen_object_info_list.push_back( 718 chosen_object_info_list.push_back(
687 base::MakeUnique<WebsiteSettingsUI::ChosenObjectInfo>( 719 base::MakeUnique<WebsiteSettingsUI::ChosenObjectInfo>(
688 ui_info, std::move(object))); 720 ui_info, std::move(object)));
721 anyPermissionsShown = true;
689 } 722 }
690 } 723 }
691 724
692 ui_->SetPermissionInfo(permission_info_list, 725 ui_->SetPermissionInfo(permission_info_list,
693 std::move(chosen_object_info_list)); 726 std::move(chosen_object_info_list));
727
728 WebsiteSettingsUI::VisiblePermissions visible_permissions;
729 if (anyPermissionsShown) {
730 if (anyPermissionsHidden) {
731 visible_permissions =
732 WebsiteSettingsUI::VISIBLE_PERMISSIONS_SOME_BUT_NOT_ALL;
733 } else {
734 visible_permissions = WebsiteSettingsUI::VISIBLE_PERMISSIONS_ALL;
735 }
736 } else {
737 visible_permissions = WebsiteSettingsUI::VISIBLE_PERMISSIONS_NONE;
738 }
739 ui_->UpdatePermissionButton(visible_permissions);
694 } 740 }
695 741
696 void WebsiteSettings::PresentSiteData() { 742 void WebsiteSettings::PresentSiteData() {
697 CookieInfoList cookie_info_list; 743 CookieInfoList cookie_info_list;
698 const LocalSharedObjectsContainer& allowed_objects = 744 const LocalSharedObjectsContainer& allowed_objects =
699 tab_specific_content_settings()->allowed_local_shared_objects(); 745 tab_specific_content_settings()->allowed_local_shared_objects();
700 const LocalSharedObjectsContainer& blocked_objects = 746 const LocalSharedObjectsContainer& blocked_objects =
701 tab_specific_content_settings()->blocked_local_shared_objects(); 747 tab_specific_content_settings()->blocked_local_shared_objects();
702 748
703 // Add first party cookie and site data counts. 749 // Add first party cookie and site data counts.
(...skipping 26 matching lines...) Expand all
730 info.connection_status = site_connection_status_; 776 info.connection_status = site_connection_status_;
731 info.connection_status_description = 777 info.connection_status_description =
732 UTF16ToUTF8(site_connection_details_); 778 UTF16ToUTF8(site_connection_details_);
733 info.identity_status = site_identity_status_; 779 info.identity_status = site_identity_status_;
734 info.identity_status_description = 780 info.identity_status_description =
735 UTF16ToUTF8(site_identity_details_); 781 UTF16ToUTF8(site_identity_details_);
736 info.certificate = certificate_; 782 info.certificate = certificate_;
737 info.show_ssl_decision_revoke_button = show_ssl_decision_revoke_button_; 783 info.show_ssl_decision_revoke_button = show_ssl_decision_revoke_button_;
738 ui_->SetIdentityInfo(info); 784 ui_->SetIdentityInfo(info);
739 } 785 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/website_settings/website_settings.h ('k') | chrome/browser/ui/website_settings/website_settings_ui.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698