Skip to content

Commit

Permalink
[Merge] Measurement APIs should be allowed regardeless of restrictions
Browse files Browse the repository at this point in the history
All the Ad Measurement APIs should be allowed regardless of the Privacy
Sandbox restricted status, when the notice-restricted param is enabled.

(cherry picked from commit eb63aa9)

Bug: 1450510
Change-Id: I697650ddd1a33fa2d49e15e85e5ded5439853001
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4578838
Reviewed-by: Theodore Olsauskas-Warren <sauski@google.com>
Commit-Queue: Nicola Tommasi <tommasin@chromium.org>
Cr-Original-Commit-Position: refs/heads/main@{#1151800}
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4593351
Auto-Submit: Nicola Tommasi <tommasin@chromium.org>
Cr-Commit-Position: refs/branch-heads/5790@{#404}
Cr-Branched-From: 1d71a33-refs/heads/main@{#1148114}
  • Loading branch information
Nicola Tommasi authored and Chromium LUCI CQ committed Jun 6, 2023
1 parent c261c37 commit 8f51274
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 4 deletions.
11 changes: 8 additions & 3 deletions components/privacy_sandbox/privacy_sandbox_settings_impl.cc
Expand Up @@ -651,12 +651,13 @@ PrivacySandboxSettingsImpl::GetSiteAccessAllowedStatus(
}

PrivacySandboxSettingsImpl::Status
PrivacySandboxSettingsImpl::GetPrivacySandboxAllowedStatus() const {
PrivacySandboxSettingsImpl::GetPrivacySandboxAllowedStatus(
bool should_ignore_restriction /*=false*/) const {
if (delegate_->IsIncognitoProfile()) {
return Status::kIncognitoProfile;
}

if (IsPrivacySandboxRestricted()) {
if (IsPrivacySandboxRestricted() && !should_ignore_restriction) {
return Status::kRestricted;
}

Expand All @@ -670,7 +671,11 @@ PrivacySandboxSettingsImpl::GetM1PrivacySandboxApiEnabledStatus(
pref_name == prefs::kPrivacySandboxM1FledgeEnabled ||
pref_name == prefs::kPrivacySandboxM1AdMeasurementEnabled);

PrivacySandboxSettingsImpl::Status status = GetPrivacySandboxAllowedStatus();
bool should_ignore_restriction =
pref_name == prefs::kPrivacySandboxM1AdMeasurementEnabled &&
IsRestrictedNoticeEnabled();
PrivacySandboxSettingsImpl::Status status =
GetPrivacySandboxAllowedStatus(should_ignore_restriction);
if (!IsAllowed(status)) {
return status;
}
Expand Down
3 changes: 2 additions & 1 deletion components/privacy_sandbox/privacy_sandbox_settings_impl.h
Expand Up @@ -130,7 +130,8 @@ class PrivacySandboxSettingsImpl : public PrivacySandboxSettings {
// Whether the privacy sandbox APIs can be allowed given the current
// environment. For example, the privacy sandbox is always disabled in
// Incognito and for restricted accounts.
Status GetPrivacySandboxAllowedStatus() const;
Status GetPrivacySandboxAllowedStatus(
bool should_ignore_restriction = false) const;

// Whether the privacy sandbox associated with the |pref_name| is enabled.
// For individual sites, check as well with GetSiteAccessAllowedStatus.
Expand Down
Expand Up @@ -1685,6 +1685,57 @@ TEST_F(PrivacySandboxSettingsM1Test, TopicsConsentStatus) {
static_cast<int>(Status::kApisDisabled)}});
}

class PrivacySandboxSettingsM1RestrictedNotice
: public PrivacySandboxSettingsM1Test {
void InitializeFeaturesBeforeStart() override {
feature_list_.InitAndEnableFeatureWithParameters(
privacy_sandbox::kPrivacySandboxSettings4,
{{"notice-required", "true"},
{privacy_sandbox::kPrivacySandboxSettings4RestrictedNotice.name,
"true"}});
}
};

TEST_F(PrivacySandboxSettingsM1RestrictedNotice,
AllApisAreOffExceptMeasurementForRestrictedAccounts) {
RunTestCase(
TestState{{MultipleStateKeys{kM1TopicsEnabledUserPrefValue,
kM1FledgeEnabledUserPrefValue,
kM1AdMeasurementEnabledUserPrefValue,
kIsRestrictedAccount},
true}},
TestInput{
{kTopFrameOrigin, url::Origin::Create(GURL("https://top-frame.com"))},
{kTopicsURL, GURL("https://embedded.com")},
{MultipleInputKeys{kFledgeAuctionPartyOrigin,
kAdMeasurementReportingOrigin, kAccessingOrigin},
url::Origin::Create(GURL("https://embedded.com"))},
{kAdMeasurementSourceOrigin,
url::Origin::Create(GURL("https://source-origin.com"))},
{kAdMeasurementDestinationOrigin,
url::Origin::Create(GURL("https://dest-origin.com"))}},
TestOutput{
{MultipleOutputKeys{kIsTopicsAllowed, kIsTopicsAllowedForContext,
kIsFledgeAllowed, kIsSharedStorageAllowed,
kIsSharedStorageSelectURLAllowed},
false},
{MultipleOutputKeys{
kIsTopicsAllowedMetric, kIsTopicsAllowedForContextMetric,
kIsFledgeAllowedMetric, kIsSharedStorageAllowedMetric,
kIsSharedStorageSelectURLAllowedMetric},
static_cast<int>(Status::kRestricted)},

{MultipleOutputKeys{kIsAttributionReportingAllowed,
kIsAttributionReportingEverAllowed,
kMaySendAttributionReport,
kIsPrivateAggregationAllowed},
true},
{MultipleOutputKeys{kIsAttributionReportingEverAllowedMetric,
kMaySendAttributionReportMetric,
kIsPrivateAggregationAllowedMetric},
static_cast<int>(Status::kAllowed)}});
}

class PrivacySandboxAttestationsTest : public PrivacySandboxSettingsTest {
void InitializeFeaturesBeforeStart() override {
feature_list_.InitAndEnableFeature(
Expand Down

0 comments on commit 8f51274

Please sign in to comment.