#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "components/page_info/page_info_ui.h"
#include <utility>
#include "base/command_line.h"
#include "base/containers/span.h"
#include "base/feature_list.h"
#include "base/strings/utf_string_conversions.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "components/content_settings/core/common/content_settings.h"
#include "components/content_settings/core/common/content_settings_types.h"
#include "components/page_info/core/features.h"
#include "components/page_info/page_info.h"
#include "components/page_info/page_info_ui_delegate.h"
#include "components/permissions/permission_decision_auto_blocker.h"
#include "components/permissions/permission_manager.h"
#include "components/permissions/permission_util.h"
#include "components/prefs/pref_service.h"
#include "components/safe_browsing/buildflags.h"
#include "components/safe_browsing/core/common/features.h"
#include "components/security_interstitials/core/common_string_util.h"
#include "components/strings/grit/components_branded_strings.h"
#include "components/strings/grit/components_strings.h"
#include "components/url_formatter/elide_url.h"
#include "content/public/browser/permission_result.h"
#include "content/public/common/content_features.h"
#include "ppapi/buildflags/buildflags.h"
#include "services/device/public/cpp/device_features.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/l10n/time_format.h"
#include "url/gurl.h"
#include "url/origin.h"
#if BUILDFLAG(IS_ANDROID)
#include "components/resources/android/theme_resources.h"
#else
#include "ui/gfx/color_palette.h"
#include "ui/gfx/color_utils.h"
#include "ui/native_theme/native_theme.h"
#endif
#if BUILDFLAG(FULL_SAFE_BROWSING)
#include "components/safe_browsing/content/browser/password_protection/password_protection_service.h"
#endif
namespace {
SettingSource;
const int kInvalidResourceID = …;
const int kPermissionButtonTextIDPolicyManaged[] = …;
static_assert …;
const int kPermissionButtonTextIDExtensionManaged[] = …;
static_assert …;
const int kPermissionButtonTextIDUserManaged[] = …;
static_assert …;
const int kPermissionButtonTextIDDefaultSetting[] = …;
static_assert …;
#if !BUILDFLAG(IS_ANDROID)
const int kSoundPermissionButtonTextIDUserManaged[] = …;
static_assert …;
const int kSoundPermissionButtonTextIDDefaultSetting[] = …;
static_assert …;
#endif
base::span<const PageInfoUI::PermissionUIInfo> GetContentSettingsUIInfo() { … }
std::unique_ptr<PageInfoUI::SecurityDescription> CreateSecurityDescription(
PageInfoUI::SecuritySummaryColor style,
int summary_id,
int details_id,
PageInfoUI::SecurityDescriptionType type) { … }
std::unique_ptr<PageInfoUI::SecurityDescription>
CreateSecurityDescriptionForSafetyTip(
const security_state::SafetyTipStatus& safety_tip_status,
const GURL& safe_url) { … }
ContentSetting GetEffectiveSetting(ContentSettingsType type,
ContentSetting setting,
ContentSetting default_setting) { … }
void CreateOppositeToDefaultSiteException(
PageInfo::PermissionInfo& permission,
ContentSetting opposite_to_block_setting) { … }
std::u16string GetPermissionAskStateString(ContentSettingsType type) { … }
}
PageInfoUI::CookiesNewInfo::CookiesNewInfo() = default;
PageInfoUI::CookiesNewInfo::CookiesNewInfo(CookiesNewInfo&& cookie_info) =
default;
PageInfoUI::CookiesNewInfo::~CookiesNewInfo() = default;
PageInfoUI::CookiesRwsInfo::CookiesRwsInfo(const std::u16string& owner_name)
: … { … }
PageInfoUI::CookiesRwsInfo::~CookiesRwsInfo() = default;
PageInfoUI::ChosenObjectInfo::ChosenObjectInfo(
const PageInfo::ChooserUIInfo& ui_info,
std::unique_ptr<permissions::ObjectPermissionContextBase::Object>
chooser_object)
: … { … }
PageInfoUI::ChosenObjectInfo::~ChosenObjectInfo() = default;
PageInfoUI::IdentityInfo::IdentityInfo()
: … { … }
PageInfoUI::IdentityInfo::~IdentityInfo() = default;
PageInfoUI::PageFeatureInfo::PageFeatureInfo()
: … { … }
bool PageInfoUI::AdPersonalizationInfo::is_empty() const { … }
PageInfoUI::AdPersonalizationInfo::AdPersonalizationInfo() = default;
PageInfoUI::AdPersonalizationInfo::~AdPersonalizationInfo() = default;
std::unique_ptr<PageInfoUI::SecurityDescription>
PageInfoUI::GetSecurityDescription(const IdentityInfo& identity_info) const { … }
PageInfoUI::~PageInfoUI() = default;
std::u16string PageInfoUI::PermissionTypeToUIString(ContentSettingsType type) { … }
std::u16string PageInfoUI::PermissionTypeToUIStringMidSentence(
ContentSettingsType type) { … }
std::u16string PageInfoUI::PermissionTooltipUiString(
ContentSettingsType type,
const std::optional<url::Origin>& requesting_origin) { … }
std::u16string PageInfoUI::PermissionSubpageButtonTooltipString(
ContentSettingsType type) { … }
base::span<const PageInfoUI::PermissionUIInfo>
PageInfoUI::GetContentSettingsUIInfoForTesting() { … }
std::u16string PageInfoUI::PermissionActionToUIString(
PageInfoUiDelegate* delegate,
ContentSettingsType type,
ContentSetting setting,
ContentSetting default_setting,
SettingSource source,
bool is_one_time) { … }
std::u16string PageInfoUI::PermissionStateToUIString(
PageInfoUiDelegate* delegate,
const PageInfo::PermissionInfo& permission) { … }
std::u16string PageInfoUI::PermissionMainPageStateToUIString(
PageInfoUiDelegate* delegate,
const PageInfo::PermissionInfo& permission) { … }
std::u16string PageInfoUI::PermissionManagedTooltipToUIString(
PageInfoUiDelegate* delegate,
const PageInfo::PermissionInfo& permission) { … }
std::u16string PageInfoUI::PermissionAutoBlockedToUIString(
PageInfoUiDelegate* delegate,
const PageInfo::PermissionInfo& permission) { … }
void PageInfoUI::ToggleBetweenAllowAndBlock(
PageInfo::PermissionInfo& permission) { … }
void PageInfoUI::ToggleBetweenRememberAndForget(
PageInfo::PermissionInfo& permission) { … }
bool PageInfoUI::IsToggleOn(const PageInfo::PermissionInfo& permission) { … }
SkColor PageInfoUI::GetSecondaryTextColor() { … }
#if BUILDFLAG(IS_ANDROID)
int PageInfoUI::GetIdentityIconID(PageInfo::SiteIdentityStatus status) {
switch (status) {
case PageInfo::SITE_IDENTITY_STATUS_UNKNOWN:
case PageInfo::SITE_IDENTITY_STATUS_INTERNAL_PAGE:
case PageInfo::SITE_IDENTITY_STATUS_CERT:
case PageInfo::SITE_IDENTITY_STATUS_EV_CERT:
case PageInfo::SITE_IDENTITY_STATUS_ISOLATED_WEB_APP:
return IDR_PAGEINFO_GOOD;
case PageInfo::SITE_IDENTITY_STATUS_NO_CERT:
case PageInfo::SITE_IDENTITY_STATUS_ERROR:
case PageInfo::SITE_IDENTITY_STATUS_ADMIN_PROVIDED_CERT:
case PageInfo::SITE_IDENTITY_STATUS_DEPRECATED_SIGNATURE_ALGORITHM:
return IDR_PAGEINFO_BAD;
}
return 0;
}
int PageInfoUI::GetConnectionIconID(PageInfo::SiteConnectionStatus status) {
switch (status) {
case PageInfo::SITE_CONNECTION_STATUS_UNKNOWN:
case PageInfo::SITE_CONNECTION_STATUS_INTERNAL_PAGE:
case PageInfo::SITE_CONNECTION_STATUS_ENCRYPTED:
case PageInfo::SITE_CONNECTION_STATUS_ISOLATED_WEB_APP:
return IDR_PAGEINFO_GOOD;
case PageInfo::SITE_CONNECTION_STATUS_INSECURE_PASSIVE_SUBRESOURCE:
case PageInfo::SITE_CONNECTION_STATUS_INSECURE_FORM_ACTION:
case PageInfo::SITE_CONNECTION_STATUS_UNENCRYPTED:
case PageInfo::SITE_CONNECTION_STATUS_INSECURE_ACTIVE_SUBRESOURCE:
case PageInfo::SITE_CONNECTION_STATUS_ENCRYPTED_ERROR:
return IDR_PAGEINFO_BAD;
}
return 0;
}
int PageInfoUI::GetIdentityIconColorID(PageInfo::SiteIdentityStatus status) {
switch (status) {
case PageInfo::SITE_IDENTITY_STATUS_UNKNOWN:
case PageInfo::SITE_IDENTITY_STATUS_INTERNAL_PAGE:
case PageInfo::SITE_IDENTITY_STATUS_CERT:
case PageInfo::SITE_IDENTITY_STATUS_EV_CERT:
case PageInfo::SITE_IDENTITY_STATUS_ISOLATED_WEB_APP:
return IDR_PAGEINFO_GOOD_COLOR;
case PageInfo::SITE_IDENTITY_STATUS_ADMIN_PROVIDED_CERT:
case PageInfo::SITE_IDENTITY_STATUS_NO_CERT:
case PageInfo::SITE_IDENTITY_STATUS_DEPRECATED_SIGNATURE_ALGORITHM:
return IDR_PAGEINFO_WARNING_COLOR;
case PageInfo::SITE_IDENTITY_STATUS_ERROR:
return IDR_PAGEINFO_BAD_COLOR;
}
return 0;
}
int PageInfoUI::GetConnectionIconColorID(
PageInfo::SiteConnectionStatus status) {
switch (status) {
case PageInfo::SITE_CONNECTION_STATUS_UNKNOWN:
case PageInfo::SITE_CONNECTION_STATUS_INTERNAL_PAGE:
case PageInfo::SITE_CONNECTION_STATUS_ENCRYPTED:
case PageInfo::SITE_CONNECTION_STATUS_ISOLATED_WEB_APP:
return IDR_PAGEINFO_GOOD_COLOR;
case PageInfo::SITE_CONNECTION_STATUS_INSECURE_PASSIVE_SUBRESOURCE:
case PageInfo::SITE_CONNECTION_STATUS_INSECURE_FORM_ACTION:
case PageInfo::SITE_CONNECTION_STATUS_UNENCRYPTED:
return IDR_PAGEINFO_WARNING_COLOR;
case PageInfo::SITE_CONNECTION_STATUS_INSECURE_ACTIVE_SUBRESOURCE:
case PageInfo::SITE_CONNECTION_STATUS_ENCRYPTED_ERROR:
return IDR_PAGEINFO_BAD_COLOR;
}
return 0;
}
#endif
bool PageInfoUI::ContentSettingsTypeInPageInfo(ContentSettingsType type) { … }
std::unique_ptr<PageInfoUI::SecurityDescription>
PageInfoUI::CreateSafetyTipSecurityDescription(
const security_state::SafetyTipInfo& info) { … }