#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "components/permissions/permission_decision_auto_blocker.h"
#include <algorithm>
#include <memory>
#include <string>
#include <utility>
#include "base/feature_list.h"
#include "base/metrics/field_trial_params.h"
#include "base/strings/string_number_conversions.h"
#include "base/values.h"
#include "components/content_settings/core/browser/host_content_settings_map.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h"
#include "components/permissions/features.h"
#include "components/permissions/permission_util.h"
#include "url/gurl.h"
namespace permissions {
namespace {
PermissionStatus;
constexpr int kDefaultDismissalsBeforeBlock = …;
constexpr int kDefaultIgnoresBeforeBlock = …;
constexpr int kDefaultDismissalsBeforeBlockWithQuietUi = …;
constexpr int kDefaultIgnoresBeforeBlockWithQuietUi = …;
constexpr int kDefaultEmbargoDays = …;
constexpr int kFederatedIdentityApiDismissalsBeforeBlock = …;
constexpr base::TimeDelta kFederatedIdentityApiEmbargoDurationDismiss[] = …;
constexpr base::TimeDelta kFederatedIdentityAutoReauthnEmbargoDuration = …;
constexpr base::TimeDelta kSubAppInstallationPromptsFirstTimeEmbargoDuration = …;
int g_dismissals_before_block = …;
int g_ignores_before_block = …;
int g_dismissals_before_block_with_quiet_ui = …;
int g_ignores_before_block_with_quiet_ui = …;
int g_dismissal_embargo_days = …;
int g_ignore_embargo_days = …;
std::string GetStringForContentType(ContentSettingsType content_type) { … }
base::Value::Dict GetOriginAutoBlockerData(HostContentSettingsMap* settings,
const GURL& origin_url) { … }
base::Value::Dict* GetOrCreatePermissionDict(base::Value::Dict& origin_dict,
const std::string& permission) { … }
int RecordActionInWebsiteSettings(const GURL& url,
ContentSettingsType permission,
const char* key,
HostContentSettingsMap* settings_map) { … }
int GetActionCount(const GURL& url,
ContentSettingsType permission,
const char* key,
HostContentSettingsMap* settings_map) { … }
int GetDismissalsBeforeBlockForContentSettingsType(
ContentSettingsType permission) { … }
base::TimeDelta GetEmbargoDurationForContentSettingsType(
ContentSettingsType permission,
int dismiss_count) { … }
base::Time GetEmbargoStartTime(base::Value::Dict* permission_dict,
const base::Feature& feature,
const char* key) { … }
bool IsUnderEmbargo(base::Value::Dict* permission_dict,
const base::Feature& feature,
const char* key,
base::Time current_time,
base::TimeDelta offset) { … }
void UpdateValueFromVariation(const std::string& variation_value,
int* value_store,
const int default_value) { … }
}
const char PermissionDecisionAutoBlocker::kPromptDismissCountKey[] = …;
const char PermissionDecisionAutoBlocker::kPromptIgnoreCountKey[] = …;
const char PermissionDecisionAutoBlocker::kPromptDismissCountWithQuietUiKey[] = …;
const char PermissionDecisionAutoBlocker::kPromptIgnoreCountWithQuietUiKey[] = …;
const char PermissionDecisionAutoBlocker::kPermissionDismissalEmbargoKey[] = …;
const char PermissionDecisionAutoBlocker::kPermissionIgnoreEmbargoKey[] = …;
const char PermissionDecisionAutoBlocker::kPermissionDisplayEmbargoKey[] = …;
bool PermissionDecisionAutoBlocker::IsEnabledForContentSetting(
ContentSettingsType content_setting) { … }
std::optional<content::PermissionResult>
PermissionDecisionAutoBlocker::GetEmbargoResult(
HostContentSettingsMap* settings_map,
const GURL& request_origin,
ContentSettingsType permission,
base::Time current_time) { … }
void PermissionDecisionAutoBlocker::UpdateFromVariations() { … }
bool PermissionDecisionAutoBlocker::IsEmbargoed(
const GURL& request_origin,
ContentSettingsType permission) { … }
std::optional<content::PermissionResult>
PermissionDecisionAutoBlocker::GetEmbargoResult(
const GURL& request_origin,
ContentSettingsType permission) { … }
base::Time PermissionDecisionAutoBlocker::GetEmbargoStartTime(
const GURL& request_origin,
ContentSettingsType permission) { … }
std::set<GURL> PermissionDecisionAutoBlocker::GetEmbargoedOrigins(
ContentSettingsType content_type) { … }
std::set<GURL> PermissionDecisionAutoBlocker::GetEmbargoedOrigins(
std::vector<ContentSettingsType> content_types) { … }
int PermissionDecisionAutoBlocker::GetDismissCount(
const GURL& url,
ContentSettingsType permission) { … }
int PermissionDecisionAutoBlocker::GetIgnoreCount(
const GURL& url,
ContentSettingsType permission) { … }
bool PermissionDecisionAutoBlocker::RecordDismissAndEmbargo(
const GURL& url,
ContentSettingsType permission,
bool dismissed_prompt_was_quiet) { … }
bool PermissionDecisionAutoBlocker::RecordIgnoreAndEmbargo(
const GURL& url,
ContentSettingsType permission,
bool ignored_prompt_was_quiet) { … }
bool PermissionDecisionAutoBlocker::RecordDisplayAndEmbargo(
const GURL& url,
ContentSettingsType permission) { … }
void PermissionDecisionAutoBlocker::RemoveEmbargoAndResetCounts(
const GURL& url,
ContentSettingsType permission) { … }
void PermissionDecisionAutoBlocker::RemoveEmbargoAndResetCounts(
base::RepeatingCallback<bool(const GURL& url)> filter) { … }
void PermissionDecisionAutoBlocker::AddObserver(Observer* obs) { … }
void PermissionDecisionAutoBlocker::RemoveObserver(Observer* obs) { … }
const char*
PermissionDecisionAutoBlocker::GetPromptDismissCountKeyForTesting() { … }
PermissionDecisionAutoBlocker::PermissionDecisionAutoBlocker(
HostContentSettingsMap* settings_map)
: … { … }
PermissionDecisionAutoBlocker::~PermissionDecisionAutoBlocker() { … }
void PermissionDecisionAutoBlocker::PlaceUnderEmbargo(
const GURL& request_origin,
ContentSettingsType permission,
const char* key) { … }
void PermissionDecisionAutoBlocker::NotifyEmbargoStarted(
const GURL& origin,
ContentSettingsType content_setting) { … }
void PermissionDecisionAutoBlocker::SetClockForTesting(base::Clock* clock) { … }
}