Rename enum names and variant names to be more clear.
This CL changes the name of the ThirdPartyCookieBlockingSetting enum to be ThirdPartyBlockingOutcome, since it is used to describe the *outcome* of applying the setting, rather than describing the setting itself; and it's redundant to call it a cookie-related setting, since everything in the CookieSettings class is related to cookies. It also changes the names of the variants of the enum to be more clear. E.g., kThirdPartyStateAllowed was easy to misinterpret as meaning "the context is third-party and all cookies are allowed", but it's really used to mean "the third-party-cookie-blocking setting doesn't influence whether this cookie is accessible in this context". It also adds comments to indicate the semantics of each variant. No behavior is changed in this CL. Change-Id: I8af9ee7ab6a30110c7c3f1c232affa4fe27c6168 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3702840 Commit-Queue: Chris Fredrickson <cfredric@chromium.org> Reviewed-by: Dylan Cutler <dylancutler@google.com> Auto-Submit: Chris Fredrickson <cfredric@chromium.org> Cr-Commit-Position: refs/heads/main@{#1013678}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
7dae2da57d
commit
806fab3127
services/network
@ -176,14 +176,13 @@ net::NetworkDelegate::PrivacySetting CookieSettings::IsPrivacyModeEnabled(
|
||||
// No unpartitioned cookie should be sent on this request. The only other
|
||||
// options are to block all cookies, or allow just partitioned cookies.
|
||||
|
||||
switch (metadata.blocked_by_third_party_setting) {
|
||||
case ThirdPartyCookieBlockingSetting::kThirdPartyStateAllowed:
|
||||
switch (metadata.third_party_blocking_outcome) {
|
||||
case ThirdPartyBlockingOutcome::kIrrelevant:
|
||||
[[fallthrough]];
|
||||
case ThirdPartyCookieBlockingSetting::kThirdPartyStateDisallowed:
|
||||
case ThirdPartyBlockingOutcome::kAllStateDisallowed:
|
||||
return net::NetworkDelegate::PrivacySetting::kStateDisallowed;
|
||||
|
||||
case ThirdPartyCookieBlockingSetting::
|
||||
kPartitionedThirdPartyStateAllowedOnly:
|
||||
case ThirdPartyBlockingOutcome::kPartitionedStateAllowed:
|
||||
return net::NetworkDelegate::PrivacySetting::kPartitionedStateAllowedOnly;
|
||||
}
|
||||
}
|
||||
@ -196,20 +195,20 @@ CookieSettings::GetCookieSettingWithMetadata(
|
||||
if (ShouldAlwaysAllowCookies(url, first_party_url)) {
|
||||
return {
|
||||
/*cookie_setting=*/CONTENT_SETTING_ALLOW,
|
||||
/*blocked_by_third_party_setting=*/
|
||||
ThirdPartyCookieBlockingSetting::kThirdPartyStateAllowed,
|
||||
/*third_party_blocking_outcome=*/
|
||||
ThirdPartyBlockingOutcome::kIrrelevant,
|
||||
};
|
||||
}
|
||||
|
||||
// Default to allowing cookies.
|
||||
ContentSetting cookie_setting = CONTENT_SETTING_ALLOW;
|
||||
ThirdPartyCookieBlockingSetting blocked_by_third_party_setting =
|
||||
ThirdPartyCookieBlockingSetting::kThirdPartyStateAllowed;
|
||||
ThirdPartyBlockingOutcome third_party_blocking_outcome =
|
||||
ThirdPartyBlockingOutcome::kIrrelevant;
|
||||
if (block_third_party_cookies_ && is_third_party_request &&
|
||||
!base::Contains(third_party_cookies_allowed_schemes_,
|
||||
first_party_url.scheme())) {
|
||||
blocked_by_third_party_setting =
|
||||
ThirdPartyCookieBlockingSetting::kThirdPartyStateDisallowed;
|
||||
third_party_blocking_outcome =
|
||||
ThirdPartyBlockingOutcome::kAllStateDisallowed;
|
||||
}
|
||||
|
||||
if (const ContentSettingPatternSource* match =
|
||||
@ -217,27 +216,24 @@ CookieSettings::GetCookieSettingWithMetadata(
|
||||
match) {
|
||||
cookie_setting = match->GetContentSetting();
|
||||
if (cookie_setting == CONTENT_SETTING_BLOCK || IsExplicitSetting(*match)) {
|
||||
blocked_by_third_party_setting =
|
||||
ThirdPartyCookieBlockingSetting::kThirdPartyStateAllowed;
|
||||
third_party_blocking_outcome = ThirdPartyBlockingOutcome::kIrrelevant;
|
||||
}
|
||||
}
|
||||
|
||||
if (blocked_by_third_party_setting ==
|
||||
ThirdPartyCookieBlockingSetting::kThirdPartyStateDisallowed) {
|
||||
if (third_party_blocking_outcome ==
|
||||
ThirdPartyBlockingOutcome::kAllStateDisallowed) {
|
||||
if (const ContentSettingPatternSource* match =
|
||||
FindMatchingSetting(url, first_party_url, storage_access_grants_);
|
||||
match) {
|
||||
if (match->GetContentSetting() == CONTENT_SETTING_ALLOW) {
|
||||
blocked_by_third_party_setting =
|
||||
ThirdPartyCookieBlockingSetting::kThirdPartyStateAllowed;
|
||||
third_party_blocking_outcome = ThirdPartyBlockingOutcome::kIrrelevant;
|
||||
FireStorageAccessHistogram(net::cookie_util::StorageAccessResult::
|
||||
ACCESS_ALLOWED_STORAGE_ACCESS_GRANT);
|
||||
}
|
||||
}
|
||||
|
||||
if (blocked_by_third_party_setting ==
|
||||
CookieSettings::ThirdPartyCookieBlockingSetting::
|
||||
kThirdPartyStateDisallowed) {
|
||||
if (third_party_blocking_outcome ==
|
||||
ThirdPartyBlockingOutcome::kAllStateDisallowed) {
|
||||
// If the third-party cookie blocking setting is enabled, we check if the
|
||||
// user has any content settings for the first-party URL as the primary
|
||||
// pattern. If cookies are allowed for the first-party URL then we allow
|
||||
@ -245,8 +241,8 @@ CookieSettings::GetCookieSettingWithMetadata(
|
||||
if (const ContentSettingPatternSource* match = FindMatchingSetting(
|
||||
first_party_url, first_party_url, content_settings_);
|
||||
!match || match->GetContentSetting() == CONTENT_SETTING_ALLOW) {
|
||||
blocked_by_third_party_setting = ThirdPartyCookieBlockingSetting::
|
||||
kPartitionedThirdPartyStateAllowedOnly;
|
||||
third_party_blocking_outcome =
|
||||
ThirdPartyBlockingOutcome::kPartitionedStateAllowed;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@ -259,14 +255,13 @@ CookieSettings::GetCookieSettingWithMetadata(
|
||||
: net::cookie_util::StorageAccessResult::ACCESS_ALLOWED);
|
||||
}
|
||||
|
||||
if (blocked_by_third_party_setting !=
|
||||
ThirdPartyCookieBlockingSetting::kThirdPartyStateAllowed) {
|
||||
if (third_party_blocking_outcome != ThirdPartyBlockingOutcome::kIrrelevant) {
|
||||
cookie_setting = CONTENT_SETTING_BLOCK;
|
||||
FireStorageAccessHistogram(
|
||||
net::cookie_util::StorageAccessResult::ACCESS_BLOCKED);
|
||||
}
|
||||
|
||||
return {cookie_setting, blocked_by_third_party_setting};
|
||||
return {cookie_setting, third_party_blocking_outcome};
|
||||
}
|
||||
|
||||
CookieSettings::CookieSettingWithMetadata
|
||||
@ -348,12 +343,11 @@ bool CookieSettings::IsCookieAllowed(
|
||||
|
||||
bool CookieSettings::IsAllowedSamePartyCookie(
|
||||
bool is_same_party,
|
||||
ThirdPartyCookieBlockingSetting third_party_cookie_blocking_setting,
|
||||
ThirdPartyBlockingOutcome third_party_blocking_outcome,
|
||||
bool record_metrics) const {
|
||||
bool blocked_by_3p_but_same_party =
|
||||
is_same_party &&
|
||||
third_party_cookie_blocking_setting !=
|
||||
ThirdPartyCookieBlockingSetting::kThirdPartyStateAllowed;
|
||||
third_party_blocking_outcome != ThirdPartyBlockingOutcome::kIrrelevant;
|
||||
if (record_metrics && blocked_by_3p_but_same_party) {
|
||||
UMA_HISTOGRAM_BOOLEAN(
|
||||
"Cookie.SameParty.BlockedByThirdPartyCookieBlockingSetting",
|
||||
@ -367,10 +361,10 @@ bool CookieSettings::IsAllowedSamePartyCookie(
|
||||
// static
|
||||
bool CookieSettings::IsAllowedPartitionedCookie(
|
||||
bool is_partitioned,
|
||||
ThirdPartyCookieBlockingSetting third_party_cookie_blocking_setting) {
|
||||
return is_partitioned && third_party_cookie_blocking_setting ==
|
||||
ThirdPartyCookieBlockingSetting::
|
||||
kPartitionedThirdPartyStateAllowedOnly;
|
||||
ThirdPartyBlockingOutcome third_party_blocking_outcome) {
|
||||
return is_partitioned &&
|
||||
third_party_blocking_outcome ==
|
||||
ThirdPartyBlockingOutcome::kPartitionedStateAllowed;
|
||||
}
|
||||
|
||||
bool CookieSettings::IsHypotheticalCookieAllowed(
|
||||
@ -381,12 +375,11 @@ bool CookieSettings::IsHypotheticalCookieAllowed(
|
||||
DCHECK(!is_partitioned || !is_same_party);
|
||||
return IsAllowed(setting_with_metadata.cookie_setting) ||
|
||||
IsAllowedSamePartyCookie(
|
||||
is_same_party,
|
||||
setting_with_metadata.blocked_by_third_party_setting,
|
||||
is_same_party, setting_with_metadata.third_party_blocking_outcome,
|
||||
record_metrics) ||
|
||||
IsAllowedPartitionedCookie(
|
||||
is_partitioned,
|
||||
setting_with_metadata.blocked_by_third_party_setting);
|
||||
setting_with_metadata.third_party_blocking_outcome);
|
||||
}
|
||||
|
||||
bool CookieSettings::HasSessionOnlyOrigins() const {
|
||||
|
@ -154,17 +154,27 @@ class COMPONENT_EXPORT(NETWORK_SERVICE) CookieSettings
|
||||
bool is_third_party_request,
|
||||
content_settings::SettingSource* source) const override;
|
||||
|
||||
enum class ThirdPartyCookieBlockingSetting {
|
||||
kThirdPartyStateAllowed = 1,
|
||||
kThirdPartyStateDisallowed,
|
||||
kPartitionedThirdPartyStateAllowedOnly,
|
||||
// An enum that represents the result of applying the user's
|
||||
// third-party-cookie-blocking setting in a given context.
|
||||
enum class ThirdPartyBlockingOutcome {
|
||||
// Access is not blocked due to the third-party-cookie-blocking setting,
|
||||
// either because there's a more specific reason to block access, or because
|
||||
// the context isn't "third-party", or because the access isn't blocked at
|
||||
// all.
|
||||
kIrrelevant = 1,
|
||||
// Access to all cookies (partitioned or unpartitioned) is blocked in this
|
||||
// context.
|
||||
kAllStateDisallowed,
|
||||
// Access to unpartitioned cookies is blocked in this context, but access to
|
||||
// partitioned cookies is allowed.
|
||||
kPartitionedStateAllowed,
|
||||
};
|
||||
|
||||
struct CookieSettingWithMetadata {
|
||||
ContentSetting cookie_setting;
|
||||
// Only relevant if access to the cookie is blocked for some reason (i.e. if
|
||||
// `IsAllow(cookie_setting)` is false).
|
||||
ThirdPartyCookieBlockingSetting blocked_by_third_party_setting;
|
||||
ThirdPartyBlockingOutcome third_party_blocking_outcome;
|
||||
};
|
||||
|
||||
// Returns the cookie setting for the given request, along with metadata
|
||||
@ -192,19 +202,19 @@ class COMPONENT_EXPORT(NETWORK_SERVICE) CookieSettings
|
||||
|
||||
// Returns true iff a cookie with the given `is_same_party` property should be
|
||||
// accessible in a context with the given
|
||||
// `third_party_cookie_blocking_setting`. Records metrics iff `record_metrics`
|
||||
// `third_party_blocking_outcome`. Records metrics iff `record_metrics`
|
||||
// is true.
|
||||
bool IsAllowedSamePartyCookie(
|
||||
bool is_same_party,
|
||||
ThirdPartyCookieBlockingSetting third_party_cookie_blocking_setting,
|
||||
ThirdPartyBlockingOutcome third_party_blocking_outcome,
|
||||
bool record_metrics) const;
|
||||
|
||||
// Returns true iff a cookie with the given `is_partitioned` property should
|
||||
// be accessible in a context with the given
|
||||
// `third_party_cookie_blocking_setting`.
|
||||
// `third_party_blocking_outcome`.
|
||||
static bool IsAllowedPartitionedCookie(
|
||||
bool is_partitioned,
|
||||
ThirdPartyCookieBlockingSetting third_party_cookie_blocking_setting);
|
||||
ThirdPartyBlockingOutcome third_party_blocking_outcome);
|
||||
|
||||
// Returns whether *some* cookie would be allowed to be sent in this context,
|
||||
// according to the user's settings. Note that cookies may still be "excluded"
|
||||
|
Reference in New Issue
Block a user