| OLD | NEW |
| 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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 #include "chrome/browser/ui/website_settings/website_settings_infobar_delegate.h
" | 78 #include "chrome/browser/ui/website_settings/website_settings_infobar_delegate.h
" |
| 78 #endif | 79 #endif |
| 79 | 80 |
| 80 using base::ASCIIToUTF16; | 81 using base::ASCIIToUTF16; |
| 81 using base::UTF8ToUTF16; | 82 using base::UTF8ToUTF16; |
| 82 using base::UTF16ToUTF8; | 83 using base::UTF16ToUTF8; |
| 83 using content::BrowserThread; | 84 using content::BrowserThread; |
| 84 | 85 |
| 85 namespace { | 86 namespace { |
| 86 | 87 |
| 88 // TODO(crbug.com/695725): Change this to FEATURE_DISABLED_BY_DEFAULT |
| 89 const base::Feature kPageInfoAlwaysShowAllPermissions{ |
| 90 "PageInfoAlwaysShowAllPermissions", base::FEATURE_ENABLED_BY_DEFAULT}; |
| 91 |
| 87 // Events for UMA. Do not reorder or change! | 92 // Events for UMA. Do not reorder or change! |
| 88 enum SSLCertificateDecisionsDidRevoke { | 93 enum SSLCertificateDecisionsDidRevoke { |
| 89 USER_CERT_DECISIONS_NOT_REVOKED = 0, | 94 USER_CERT_DECISIONS_NOT_REVOKED = 0, |
| 90 USER_CERT_DECISIONS_REVOKED, | 95 USER_CERT_DECISIONS_REVOKED, |
| 91 END_OF_SSL_CERTIFICATE_DECISIONS_DID_REVOKE_ENUM | 96 END_OF_SSL_CERTIFICATE_DECISIONS_DID_REVOKE_ENUM |
| 92 }; | 97 }; |
| 93 | 98 |
| 94 // The list of content settings types to display on the Website Settings UI. THE | 99 // 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 | 100 // ORDER OF THESE ITEMS IS IMPORTANT. To propose changing it, email |
| 96 // security-dev@chromium.org. | 101 // security-dev@chromium.org. |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 WebsiteSettingsUI* ui, | 216 WebsiteSettingsUI* ui, |
| 212 Profile* profile, | 217 Profile* profile, |
| 213 TabSpecificContentSettings* tab_specific_content_settings, | 218 TabSpecificContentSettings* tab_specific_content_settings, |
| 214 content::WebContents* web_contents, | 219 content::WebContents* web_contents, |
| 215 const GURL& url, | 220 const GURL& url, |
| 216 const security_state::SecurityInfo& security_info) | 221 const security_state::SecurityInfo& security_info) |
| 217 : TabSpecificContentSettings::SiteDataObserver( | 222 : TabSpecificContentSettings::SiteDataObserver( |
| 218 tab_specific_content_settings), | 223 tab_specific_content_settings), |
| 219 content::WebContentsObserver(web_contents), | 224 content::WebContentsObserver(web_contents), |
| 220 ui_(ui), | 225 ui_(ui), |
| 226 show_all_permissions_(false), |
| 221 show_info_bar_(false), | 227 show_info_bar_(false), |
| 222 site_url_(url), | 228 site_url_(url), |
| 223 site_identity_status_(SITE_IDENTITY_STATUS_UNKNOWN), | 229 site_identity_status_(SITE_IDENTITY_STATUS_UNKNOWN), |
| 224 site_connection_status_(SITE_CONNECTION_STATUS_UNKNOWN), | 230 site_connection_status_(SITE_CONNECTION_STATUS_UNKNOWN), |
| 225 show_ssl_decision_revoke_button_(false), | 231 show_ssl_decision_revoke_button_(false), |
| 226 content_settings_(HostContentSettingsMapFactory::GetForProfile(profile)), | 232 content_settings_(HostContentSettingsMapFactory::GetForProfile(profile)), |
| 227 chrome_ssl_host_state_delegate_( | 233 chrome_ssl_host_state_delegate_( |
| 228 ChromeSSLHostStateDelegateFactory::GetForProfile(profile)), | 234 ChromeSSLHostStateDelegateFactory::GetForProfile(profile)), |
| 229 did_revoke_user_ssl_decisions_(false), | 235 did_revoke_user_ssl_decisions_(false), |
| 230 profile_(profile), | 236 profile_(profile), |
| 231 security_level_(security_state::NONE) { | 237 security_level_(security_state::NONE) { |
| 232 Init(url, security_info); | 238 Init(url, security_info); |
| 233 | 239 |
| 240 if (base::FeatureList::IsEnabled(kPageInfoAlwaysShowAllPermissions)) { |
| 241 show_all_permissions_ = true; |
| 242 } |
| 243 |
| 234 PresentSitePermissions(); | 244 PresentSitePermissions(); |
| 235 PresentSiteData(); | 245 PresentSiteData(); |
| 236 PresentSiteIdentity(); | 246 PresentSiteIdentity(); |
| 237 | 247 |
| 238 // Every time the Website Settings UI is opened a |WebsiteSettings| object is | 248 // 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. | 249 // created. So this counts how ofter the Website Settings UI is opened. |
| 240 RecordWebsiteSettingsAction(WEBSITE_SETTINGS_OPENED); | 250 RecordWebsiteSettingsAction(WEBSITE_SETTINGS_OPENED); |
| 241 } | 251 } |
| 242 | 252 |
| 243 WebsiteSettings::~WebsiteSettings() { | 253 WebsiteSettings::~WebsiteSettings() { |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 311 PermissionUtil::ScopedRevocationReporter scoped_revocation_reporter( | 321 PermissionUtil::ScopedRevocationReporter scoped_revocation_reporter( |
| 312 this->profile_, this->site_url_, this->site_url_, type, | 322 this->profile_, this->site_url_, this->site_url_, type, |
| 313 PermissionSourceUI::OIB); | 323 PermissionSourceUI::OIB); |
| 314 | 324 |
| 315 content_settings_->SetNarrowestContentSetting(site_url_, site_url_, type, | 325 content_settings_->SetNarrowestContentSetting(site_url_, site_url_, type, |
| 316 setting); | 326 setting); |
| 317 | 327 |
| 318 show_info_bar_ = true; | 328 show_info_bar_ = true; |
| 319 | 329 |
| 320 // Refresh the UI to reflect the new setting. | 330 // Refresh the UI to reflect the new setting. |
| 331 #if defined(OS_MACOSX) |
| 332 // TODO(crbug.com/695690): This is currently only needed on Mac, and breaks |
| 333 // accessibility. |
| 334 PresentSitePermissions(); |
| 335 #endif |
| 336 } |
| 337 |
| 338 void WebsiteSettings::OnPresentAllSitePermissions() { |
| 339 show_all_permissions_ = true; |
| 321 PresentSitePermissions(); | 340 PresentSitePermissions(); |
| 322 } | 341 } |
| 323 | 342 |
| 324 void WebsiteSettings::OnSiteChosenObjectDeleted( | 343 void WebsiteSettings::OnSiteChosenObjectDeleted( |
| 325 const ChooserUIInfo& ui_info, | 344 const ChooserUIInfo& ui_info, |
| 326 const base::DictionaryValue& object) { | 345 const base::DictionaryValue& object) { |
| 327 // TODO(reillyg): Create metrics for revocations. crbug.com/556845 | 346 // TODO(reillyg): Create metrics for revocations. crbug.com/556845 |
| 328 ChooserContextBase* context = ui_info.get_context(profile_); | 347 ChooserContextBase* context = ui_info.get_context(profile_); |
| 329 const GURL origin = site_url_.GetOrigin(); | 348 const GURL origin = site_url_.GetOrigin(); |
| 330 context->RevokeObjectPermission(origin, origin, object); | 349 context->RevokeObjectPermission(origin, origin, object); |
| (...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 637 DCHECK(delegate); | 656 DCHECK(delegate); |
| 638 // Only show an SSL decision revoke button if the user has chosen to bypass | 657 // Only show an SSL decision revoke button if the user has chosen to bypass |
| 639 // SSL host errors for this host in the past. | 658 // SSL host errors for this host in the past. |
| 640 show_ssl_decision_revoke_button_ = delegate->HasAllowException(url.host()); | 659 show_ssl_decision_revoke_button_ = delegate->HasAllowException(url.host()); |
| 641 } | 660 } |
| 642 | 661 |
| 643 void WebsiteSettings::PresentSitePermissions() { | 662 void WebsiteSettings::PresentSitePermissions() { |
| 644 PermissionInfoList permission_info_list; | 663 PermissionInfoList permission_info_list; |
| 645 ChosenObjectInfoList chosen_object_info_list; | 664 ChosenObjectInfoList chosen_object_info_list; |
| 646 | 665 |
| 666 bool anyPermissionsShown = false; |
| 667 bool anyPermissionsHidden = false; |
| 668 |
| 647 WebsiteSettingsUI::PermissionInfo permission_info; | 669 WebsiteSettingsUI::PermissionInfo permission_info; |
| 648 for (size_t i = 0; i < arraysize(kPermissionType); ++i) { | 670 for (size_t i = 0; i < arraysize(kPermissionType); ++i) { |
| 649 permission_info.type = kPermissionType[i]; | 671 permission_info.type = kPermissionType[i]; |
| 650 | 672 |
| 651 if (!ShouldShowPermission(permission_info.type)) | 673 if (!ShouldShowPermission(permission_info.type)) |
| 652 continue; | 674 continue; |
| 653 | 675 |
| 654 content_settings::SettingInfo info; | 676 content_settings::SettingInfo info; |
| 655 std::unique_ptr<base::Value> value = content_settings_->GetWebsiteSetting( | 677 std::unique_ptr<base::Value> value = content_settings_->GetWebsiteSetting( |
| 656 site_url_, site_url_, permission_info.type, std::string(), &info); | 678 site_url_, site_url_, permission_info.type, std::string(), &info); |
| 679 |
| 657 DCHECK(value.get()); | 680 DCHECK(value.get()); |
| 658 if (value->GetType() == base::Value::Type::INTEGER) { | 681 if (value->GetType() == base::Value::Type::INTEGER) { |
| 659 permission_info.setting = | 682 permission_info.setting = |
| 660 content_settings::ValueToContentSetting(value.get()); | 683 content_settings::ValueToContentSetting(value.get()); |
| 661 } else { | 684 } else { |
| 662 NOTREACHED(); | 685 NOTREACHED(); |
| 663 } | 686 } |
| 664 | 687 |
| 665 permission_info.source = info.source; | 688 permission_info.source = info.source; |
| 666 permission_info.is_incognito = profile_->IsOffTheRecord(); | 689 permission_info.is_incognito = profile_->IsOffTheRecord(); |
| 667 | 690 |
| 668 if (info.primary_pattern == ContentSettingsPattern::Wildcard() && | 691 if (info.primary_pattern == ContentSettingsPattern::Wildcard() && |
| 669 info.secondary_pattern == ContentSettingsPattern::Wildcard()) { | 692 info.secondary_pattern == ContentSettingsPattern::Wildcard()) { |
| 670 permission_info.default_setting = permission_info.setting; | 693 permission_info.default_setting = permission_info.setting; |
| 671 permission_info.setting = CONTENT_SETTING_DEFAULT; | 694 permission_info.setting = CONTENT_SETTING_DEFAULT; |
| 672 } else { | 695 } else { |
| 673 permission_info.default_setting = | 696 permission_info.default_setting = |
| 674 content_settings_->GetDefaultContentSetting(permission_info.type, | 697 content_settings_->GetDefaultContentSetting(permission_info.type, |
| 675 NULL); | 698 NULL); |
| 676 } | 699 } |
| 677 | 700 |
| 678 permission_info_list.push_back(permission_info); | 701 if (show_all_permissions_ || |
| 702 permission_info.setting != CONTENT_SETTING_DEFAULT) { |
| 703 permission_info_list.push_back(permission_info); |
| 704 anyPermissionsShown = true; |
| 705 } else { |
| 706 anyPermissionsHidden = true; |
| 707 } |
| 679 } | 708 } |
| 680 | 709 |
| 681 for (const ChooserUIInfo& ui_info : kChooserUIInfo) { | 710 for (const ChooserUIInfo& ui_info : kChooserUIInfo) { |
| 682 ChooserContextBase* context = ui_info.get_context(profile_); | 711 ChooserContextBase* context = ui_info.get_context(profile_); |
| 683 const GURL origin = site_url_.GetOrigin(); | 712 const GURL origin = site_url_.GetOrigin(); |
| 684 auto chosen_objects = context->GetGrantedObjects(origin, origin); | 713 auto chosen_objects = context->GetGrantedObjects(origin, origin); |
| 685 for (std::unique_ptr<base::DictionaryValue>& object : chosen_objects) { | 714 for (std::unique_ptr<base::DictionaryValue>& object : chosen_objects) { |
| 686 chosen_object_info_list.push_back( | 715 chosen_object_info_list.push_back( |
| 687 base::MakeUnique<WebsiteSettingsUI::ChosenObjectInfo>( | 716 base::MakeUnique<WebsiteSettingsUI::ChosenObjectInfo>( |
| 688 ui_info, std::move(object))); | 717 ui_info, std::move(object))); |
| 718 anyPermissionsShown = true; |
| 689 } | 719 } |
| 690 } | 720 } |
| 691 | 721 |
| 692 ui_->SetPermissionInfo(permission_info_list, | 722 ui_->SetPermissionInfo(permission_info_list, |
| 693 std::move(chosen_object_info_list)); | 723 std::move(chosen_object_info_list)); |
| 724 |
| 725 WebsiteSettingsUI::VisiblePermissions visible_permissions; |
| 726 if (anyPermissionsShown) { |
| 727 if (anyPermissionsHidden) { |
| 728 visible_permissions = |
| 729 WebsiteSettingsUI::VISIBLE_PERMISSIONS_SOME_BUT_NOT_ALL; |
| 730 } else { |
| 731 visible_permissions = WebsiteSettingsUI::VISIBLE_PERMISSIONS_ALL; |
| 732 } |
| 733 } else { |
| 734 visible_permissions = WebsiteSettingsUI::VISIBLE_PERMISSIONS_NONE; |
| 735 } |
| 736 ui_->UpdatePermissionButton(visible_permissions); |
| 694 } | 737 } |
| 695 | 738 |
| 696 void WebsiteSettings::PresentSiteData() { | 739 void WebsiteSettings::PresentSiteData() { |
| 697 CookieInfoList cookie_info_list; | 740 CookieInfoList cookie_info_list; |
| 698 const LocalSharedObjectsContainer& allowed_objects = | 741 const LocalSharedObjectsContainer& allowed_objects = |
| 699 tab_specific_content_settings()->allowed_local_shared_objects(); | 742 tab_specific_content_settings()->allowed_local_shared_objects(); |
| 700 const LocalSharedObjectsContainer& blocked_objects = | 743 const LocalSharedObjectsContainer& blocked_objects = |
| 701 tab_specific_content_settings()->blocked_local_shared_objects(); | 744 tab_specific_content_settings()->blocked_local_shared_objects(); |
| 702 | 745 |
| 703 // Add first party cookie and site data counts. | 746 // Add first party cookie and site data counts. |
| (...skipping 26 matching lines...) Expand all Loading... |
| 730 info.connection_status = site_connection_status_; | 773 info.connection_status = site_connection_status_; |
| 731 info.connection_status_description = | 774 info.connection_status_description = |
| 732 UTF16ToUTF8(site_connection_details_); | 775 UTF16ToUTF8(site_connection_details_); |
| 733 info.identity_status = site_identity_status_; | 776 info.identity_status = site_identity_status_; |
| 734 info.identity_status_description = | 777 info.identity_status_description = |
| 735 UTF16ToUTF8(site_identity_details_); | 778 UTF16ToUTF8(site_identity_details_); |
| 736 info.certificate = certificate_; | 779 info.certificate = certificate_; |
| 737 info.show_ssl_decision_revoke_button = show_ssl_decision_revoke_button_; | 780 info.show_ssl_decision_revoke_button = show_ssl_decision_revoke_button_; |
| 738 ui_->SetIdentityInfo(info); | 781 ui_->SetIdentityInfo(info); |
| 739 } | 782 } |
| OLD | NEW |