#include "chrome/browser/storage_access_api/storage_access_grant_permission_context.h"
#include "base/check.h"
#include "base/check_op.h"
#include "base/feature_list.h"
#include "base/functional/bind.h"
#include "base/metrics/field_trial_params.h"
#include "base/metrics/histogram_functions.h"
#include "base/notreached.h"
#include "base/ranges/algorithm.h"
#include "base/time/time.h"
#include "chrome/browser/content_settings/cookie_settings_factory.h"
#include "chrome/browser/content_settings/host_content_settings_map_factory.h"
#include "chrome/browser/dips/dips_service.h"
#include "chrome/browser/first_party_sets/first_party_sets_policy_service.h"
#include "chrome/browser/first_party_sets/first_party_sets_policy_service_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/webid/federated_identity_auto_reauthn_permission_context.h"
#include "chrome/browser/webid/federated_identity_auto_reauthn_permission_context_factory.h"
#include "chrome/browser/webid/federated_identity_permission_context.h"
#include "chrome/browser/webid/federated_identity_permission_context_factory.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.h"
#include "components/content_settings/core/common/content_settings_constraints.h"
#include "components/content_settings/core/common/content_settings_types.h"
#include "components/content_settings/core/common/content_settings_utils.h"
#include "components/permissions/constants.h"
#include "components/permissions/features.h"
#include "components/permissions/permission_request_id.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/runtime_feature_state/runtime_feature_state_document_data.h"
#include "content/public/browser/storage_partition.h"
#include "content/public/common/content_features.h"
#include "net/base/schemeful_site.h"
#include "net/cookies/cookie_setting_override.h"
#include "net/cookies/site_for_cookies.h"
#include "net/first_party_sets/first_party_set_entry.h"
#include "net/first_party_sets/first_party_set_metadata.h"
#include "services/network/public/mojom/cookie_manager.mojom.h"
#include "third_party/blink/public/common/features.h"
#include "third_party/blink/public/common/features_generated.h"
#include "third_party/blink/public/common/runtime_feature_state/runtime_feature_state_read_context.h"
#include "third_party/blink/public/mojom/devtools/console_message.mojom-shared.h"
#include "third_party/blink/public/mojom/permissions_policy/permissions_policy_feature.mojom-shared.h"
namespace {
static int implicit_grant_limit = …;
constexpr base::TimeDelta kStorageAccessAPITopLevelUserInteractionBound = …;
bool IsUserDecidedPersistableOutcome(RequestOutcome outcome) { … }
bool ShouldDisplayOutcomeInOmnibox(RequestOutcome outcome) { … }
RequestOutcome RequestOutcomeFromPrompt(ContentSetting content_setting,
bool persist) { … }
void RecordOutcomeSample(RequestOutcome outcome) { … }
content_settings::ContentSettingConstraints ComputeConstraints(
RequestOutcome outcome,
base::Time now) { … }
bool ShouldPersistSetting(bool permission_allowed, RequestOutcome outcome) { … }
bool AreFedCmAutograntsEnabled(content::RenderFrameHost* rfh) { … }
enum class AutograntViaFedCmOutcome { … };
void RecordAutograntViaFedCmOutcomeSample(AutograntViaFedCmOutcome outcome) { … }
FederatedIdentityPermissionContext* IsAutograntViaFedCmAllowed(
content::BrowserContext* browser_context,
content::RenderFrameHost* rfh,
const url::Origin& embedding_origin,
const net::SchemefulSite& embedding_site,
const net::SchemefulSite& requesting_site) { … }
}
int StorageAccessGrantPermissionContext::GetImplicitGrantLimitForTesting() { … }
void StorageAccessGrantPermissionContext::SetImplicitGrantLimitForTesting(
int limit) { … }
StorageAccessGrantPermissionContext::StorageAccessGrantPermissionContext(
content::BrowserContext* browser_context)
: … { … }
StorageAccessGrantPermissionContext::~StorageAccessGrantPermissionContext() =
default;
void StorageAccessGrantPermissionContext::DecidePermissionForTesting(
permissions::PermissionRequestData request_data,
permissions::BrowserPermissionCallback callback) { … }
void StorageAccessGrantPermissionContext::DecidePermission(
permissions::PermissionRequestData request_data,
permissions::BrowserPermissionCallback callback) { … }
void StorageAccessGrantPermissionContext::CheckForAutoGrantOrAutoDenial(
permissions::PermissionRequestData request_data,
permissions::BrowserPermissionCallback callback,
net::FirstPartySetMetadata metadata) { … }
void StorageAccessGrantPermissionContext::OnCheckedUserInteractionHeuristic(
permissions::PermissionRequestData request_data,
permissions::BrowserPermissionCallback callback,
bool had_top_level_user_interaction) { … }
ContentSetting StorageAccessGrantPermissionContext::GetPermissionStatusInternal(
content::RenderFrameHost* render_frame_host,
const GURL& requesting_origin,
const GURL& embedding_origin) const { … }
void StorageAccessGrantPermissionContext::NotifyPermissionSet(
const permissions::PermissionRequestID& id,
const GURL& requesting_origin,
const GURL& embedding_origin,
permissions::BrowserPermissionCallback callback,
bool persist,
ContentSetting content_setting,
bool is_one_time,
bool is_final_decision) { … }
void StorageAccessGrantPermissionContext::NotifyPermissionSetInternal(
const permissions::PermissionRequestID& id,
const GURL& requesting_origin,
const GURL& embedding_origin,
permissions::BrowserPermissionCallback callback,
bool persist,
ContentSetting content_setting,
RequestOutcome outcome) { … }
void StorageAccessGrantPermissionContext::UpdateContentSetting(
const GURL& requesting_origin,
const GURL& embedding_origin,
ContentSetting content_setting,
bool is_one_time) { … }