#include "chrome/browser/ui/content_settings/content_setting_image_model.h"
#include <string>
#include <utility>
#include "base/feature_list.h"
#include "base/memory/raw_ptr_exclusion.h"
#include "base/metrics/field_trial_params.h"
#include "base/metrics/user_metrics.h"
#include "base/metrics/user_metrics_action.h"
#include "base/ranges/algorithm.h"
#include "build/build_config.h"
#include "chrome/app/vector_icons/vector_icons.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/content_settings/cookie_settings_factory.h"
#include "chrome/browser/content_settings/host_content_settings_map_factory.h"
#include "chrome/browser/content_settings/page_specific_content_settings_delegate.h"
#include "chrome/browser/download/download_request_limiter.h"
#include "chrome/browser/permissions/quiet_notification_permission_ui_config.h"
#include "chrome/browser/permissions/quiet_notification_permission_ui_state.h"
#include "chrome/browser/permissions/system/system_permission_settings.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/blocked_content/framebust_block_tab_helper.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/content_settings/content_setting_image_model_states.h"
#include "chrome/browser/ui/layout_constants.h"
#include "chrome/browser/ui/ui_features.h"
#include "chrome/browser/ui/web_applications/app_browser_controller.h"
#include "chrome/common/chrome_features.h"
#include "chrome/common/pref_names.h"
#include "chrome/grit/branded_strings.h"
#include "chrome/grit/generated_resources.h"
#include "components/content_settings/browser/page_specific_content_settings.h"
#include "components/content_settings/core/browser/cookie_settings.h"
#include "components/content_settings/core/browser/host_content_settings_map.h"
#include "components/content_settings/core/common/content_settings_types.h"
#include "components/content_settings/core/common/features.h"
#include "components/no_state_prefetch/browser/no_state_prefetch_manager.h"
#include "components/permissions/features.h"
#include "components/permissions/permission_request_manager.h"
#include "components/prefs/pref_service.h"
#include "components/strings/grit/components_strings.h"
#include "components/vector_icons/vector_icons.h"
#include "content/public/browser/web_contents.h"
#include "net/base/schemeful_site.h"
#include "services/device/public/cpp/device_features.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/pointer/touch_ui_controller.h"
#include "ui/base/ui_base_features.h"
#include "ui/gfx/color_palette.h"
#include "ui/gfx/color_utils.h"
#include "ui/gfx/favicon_size.h"
#include "ui/gfx/paint_vector_icon.h"
#include "ui/gfx/vector_icon_types.h"
#if BUILDFLAG(IS_MAC)
#include "chrome/browser/browser_process_platform_part.h"
#include "chrome/browser/media/webrtc/system_media_capture_permissions_mac.h"
#include "chrome/browser/web_applications/os_integration/mac/app_shim_registry.h"
#include "chrome/browser/web_applications/web_app_tab_helper.h"
#endif
WebContents;
PageSpecificContentSettings;
constexpr bool kNotifyAccessibility = …;
class ContentSettingBlockedImageModel : public ContentSettingSimpleImageModel { … };
class ContentSettingGeolocationImageModel : public ContentSettingImageModel { … };
class ContentSettingRPHImageModel : public ContentSettingSimpleImageModel { … };
class ContentSettingMIDISysExImageModel
: public ContentSettingSimpleImageModel { … };
class ContentSettingDownloadsImageModel
: public ContentSettingSimpleImageModel { … };
class ContentSettingClipboardReadWriteImageModel
: public ContentSettingSimpleImageModel { … };
class ContentSettingMediaImageModel : public ContentSettingImageModel { … };
class ContentSettingSensorsImageModel : public ContentSettingSimpleImageModel { … };
class ContentSettingNotificationsImageModel
: public ContentSettingSimpleImageModel { … };
class ContentSettingPopupImageModel : public ContentSettingSimpleImageModel { … };
class ContentSettingStorageAccessImageModel
: public ContentSettingSimpleImageModel { … };
namespace {
struct ContentSettingsImageDetails { … };
const ContentSettingsImageDetails kImageDetails[] = …;
const ContentSettingsImageDetails* GetImageDetails(ContentSettingsType type) { … }
void GetIconChromeRefresh(ContentSettingsType type,
bool blocked,
raw_ptr<const gfx::VectorIcon>* icon) { … }
void GetIconFromType(ContentSettingsType type,
bool blocked,
raw_ptr<const gfx::VectorIcon>* icon,
raw_ptr<const gfx::VectorIcon>* badge) { … }
}
ContentSettingSimpleImageModel::ContentSettingSimpleImageModel(
ImageType image_type,
ContentSettingsType content_type,
bool image_type_should_notify_accessibility)
: … { … }
std::unique_ptr<ContentSettingBubbleModel>
ContentSettingSimpleImageModel::CreateBubbleModelImpl(
ContentSettingBubbleModel::Delegate* delegate,
WebContents* web_contents) { … }
std::unique_ptr<ContentSettingImageModel>
ContentSettingImageModel::CreateForContentType(ImageType image_type) { … }
void ContentSettingImageModel::Update(content::WebContents* contents) { … }
bool ContentSettingImageModel::ShouldRunAnimation(
content::WebContents* contents) { … }
void ContentSettingImageModel::SetAnimationHasRun(
content::WebContents* contents) { … }
bool ContentSettingImageModel::ShouldNotifyAccessibility(
content::WebContents* contents) const { … }
void ContentSettingImageModel::AccessibilityWasNotified(
content::WebContents* contents) { … }
bool ContentSettingImageModel::ShouldShowPromo(content::WebContents* contents) { … }
void ContentSettingImageModel::SetPromoWasShown(
content::WebContents* contents) { … }
bool ContentSettingImageModel::ShouldAutoOpenBubble(
content::WebContents* contents) { … }
void ContentSettingImageModel::SetBubbleWasAutoOpened(
content::WebContents* contents) { … }
void ContentSettingImageModel::SetIcon(ContentSettingsType type, bool blocked) { … }
void ContentSettingImageModel::SetFramebustBlockedIcon() { … }
ContentSettingBlockedImageModel::ContentSettingBlockedImageModel(
ImageType image_type,
ContentSettingsType content_type)
: … { … }
bool ContentSettingBlockedImageModel::UpdateAndGetVisibility(
WebContents* web_contents) { … }
ContentSettingGeolocationImageModel::ContentSettingGeolocationImageModel()
: … { … }
ContentSettingGeolocationImageModel::~ContentSettingGeolocationImageModel() { … }
bool ContentSettingGeolocationImageModel::UpdateAndGetVisibility(
WebContents* web_contents) { … }
std::unique_ptr<ContentSettingBubbleModel>
ContentSettingGeolocationImageModel::CreateBubbleModelImpl(
ContentSettingBubbleModel::Delegate* delegate,
WebContents* web_contents) { … }
ContentSettingRPHImageModel::ContentSettingRPHImageModel()
: … { … }
bool ContentSettingRPHImageModel::UpdateAndGetVisibility(
WebContents* web_contents) { … }
ContentSettingMIDISysExImageModel::ContentSettingMIDISysExImageModel()
: … { … }
bool ContentSettingMIDISysExImageModel::UpdateAndGetVisibility(
WebContents* web_contents) { … }
ContentSettingDownloadsImageModel::ContentSettingDownloadsImageModel()
: … { … }
bool ContentSettingDownloadsImageModel::UpdateAndGetVisibility(
WebContents* web_contents) { … }
ContentSettingClipboardReadWriteImageModel::
ContentSettingClipboardReadWriteImageModel()
: … { … }
bool ContentSettingClipboardReadWriteImageModel::UpdateAndGetVisibility(
WebContents* web_contents) { … }
ContentSettingMediaImageModel::ContentSettingMediaImageModel()
: … { … }
bool ContentSettingMediaImageModel::UpdateAndGetVisibility(
WebContents* web_contents) { … }
bool ContentSettingMediaImageModel::IsMicAccessed() { … }
bool ContentSettingMediaImageModel::IsCamAccessed() { … }
bool ContentSettingMediaImageModel::IsMicBlockedOnSiteLevel() { … }
bool ContentSettingMediaImageModel::IsCameraBlockedOnSiteLevel() { … }
#if BUILDFLAG(IS_MAC)
bool ContentSettingMediaImageModel::
DidCameraAccessFailBecauseOfSystemLevelBlock() {
return (IsCamAccessed() && !IsCameraBlockedOnSiteLevel() &&
system_media_permissions::CheckSystemVideoCapturePermission() ==
system_media_permissions::SystemPermission::kDenied);
}
bool ContentSettingMediaImageModel::
DidMicAccessFailBecauseOfSystemLevelBlock() {
return (IsMicAccessed() && !IsMicBlockedOnSiteLevel() &&
system_media_permissions::CheckSystemAudioCapturePermission() ==
system_media_permissions::SystemPermission::kDenied);
}
bool ContentSettingMediaImageModel::IsCameraAccessPendingOnSystemLevelPrompt() {
return (system_media_permissions::CheckSystemVideoCapturePermission() ==
system_media_permissions::SystemPermission::kNotDetermined &&
IsCamAccessed() && !IsCameraBlockedOnSiteLevel());
}
bool ContentSettingMediaImageModel::IsMicAccessPendingOnSystemLevelPrompt() {
return (system_media_permissions::CheckSystemAudioCapturePermission() ==
system_media_permissions::SystemPermission::kNotDetermined &&
IsMicAccessed() && !IsMicBlockedOnSiteLevel());
}
#endif
std::unique_ptr<ContentSettingBubbleModel>
ContentSettingMediaImageModel::CreateBubbleModelImpl(
ContentSettingBubbleModel::Delegate* delegate,
WebContents* web_contents) { … }
ContentSettingFramebustBlockImageModel::ContentSettingFramebustBlockImageModel()
: … { … }
bool ContentSettingFramebustBlockImageModel::UpdateAndGetVisibility(
WebContents* web_contents) { … }
std::unique_ptr<ContentSettingBubbleModel>
ContentSettingFramebustBlockImageModel::CreateBubbleModelImpl(
ContentSettingBubbleModel::Delegate* delegate,
WebContents* web_contents) { … }
ContentSettingSensorsImageModel::ContentSettingSensorsImageModel()
: … { … }
bool ContentSettingSensorsImageModel::UpdateAndGetVisibility(
WebContents* web_contents) { … }
ContentSettingPopupImageModel::ContentSettingPopupImageModel()
: … { … }
bool ContentSettingPopupImageModel::UpdateAndGetVisibility(
WebContents* web_contents) { … }
ContentSettingStorageAccessImageModel::ContentSettingStorageAccessImageModel()
: … { … }
bool ContentSettingStorageAccessImageModel::UpdateAndGetVisibility(
WebContents* web_contents) { … }
ContentSettingNotificationsImageModel::ContentSettingNotificationsImageModel()
: … { … }
bool ContentSettingNotificationsImageModel::UpdateAndGetVisibility(
WebContents* web_contents) { … }
void ContentSettingNotificationsImageModel::SetPromoWasShown(
content::WebContents* contents) { … }
std::unique_ptr<ContentSettingBubbleModel>
ContentSettingNotificationsImageModel::CreateBubbleModelImpl(
ContentSettingBubbleModel::Delegate* delegate,
WebContents* web_contents) { … }
gfx::Image ContentSettingImageModel::GetIcon(SkColor icon_color) const { … }
void ContentSettingImageModel::SetIconSize(int icon_size) { … }
int ContentSettingImageModel::AccessibilityAnnouncementStringId() const { … }
ContentSettingImageModel::ContentSettingImageModel(
ImageType image_type,
bool image_type_should_notify_accessibility)
: … { … }
std::unique_ptr<ContentSettingBubbleModel>
ContentSettingImageModel::CreateBubbleModel(
ContentSettingBubbleModel::Delegate* delegate,
content::WebContents* web_contents) { … }
std::vector<std::unique_ptr<ContentSettingImageModel>>
ContentSettingImageModel::GenerateContentSettingImageModels() { … }
size_t ContentSettingImageModel::GetContentSettingImageModelIndexForTesting(
ImageType image_type) { … }