From 8a4476d697de824ca96a6271e7f74f1173d20934 Mon Sep 17 00:00:00 2001 From: uazo <29201891+uazo@users.noreply.github.com> Date: Mon, 15 Nov 2021 17:35:04 +0100 Subject: [PATCH] Disable privacy sandbox (#1581) Co-authored-by: Carmelo Messina --- build/patches/Disable-privacy-sandbox.patch | 143 ++++++++++++++++++++ 1 file changed, 143 insertions(+) create mode 100644 build/patches/Disable-privacy-sandbox.patch diff --git a/build/patches/Disable-privacy-sandbox.patch b/build/patches/Disable-privacy-sandbox.patch new file mode 100644 index 00000000..0c9541a7 --- /dev/null +++ b/build/patches/Disable-privacy-sandbox.patch @@ -0,0 +1,143 @@ +From: uazo +Date: Sat, 13 Nov 2021 09:17:06 +0000 +Subject: Disable privacy sandbox + +Remove the ui from the settings and set the flags to inactive +--- + .../java/res/xml/privacy_preferences.xml | 4 --- + .../privacy/settings/PrivacySettings.java | 19 ----------- + .../privacy_sandbox_settings.cc | 34 +++++++++---------- + 3 files changed, 16 insertions(+), 41 deletions(-) + +diff --git a/chrome/android/java/res/xml/privacy_preferences.xml b/chrome/android/java/res/xml/privacy_preferences.xml +--- a/chrome/android/java/res/xml/privacy_preferences.xml ++++ b/chrome/android/java/res/xml/privacy_preferences.xml +@@ -70,10 +70,6 @@ + android:title="@string/open_external_links_incognito_title" + android:summary="@string/open_external_links_incognito_summary" + android:defaultValue="false" /> +- + + { +- Bundle fragmentArgs = new Bundle(); +- fragmentArgs.putInt(PrivacySandboxSettingsFragment.PRIVACY_SANDBOX_REFERRER, +- PrivacySandboxReferrer.PRIVACY_SETTINGS); +- new SettingsLauncherImpl().launchSettingsActivity( +- getContext(), PrivacySandboxSettingsFragment.class, fragmentArgs); +- return true; +- }); +- + if (!ChromeFeatureList.isEnabled(ChromeFeatureList.PRIVACY_REVIEW)) { + getPreferenceScreen().removePreference(findPreference(PREF_PRIVACY_REVIEW)); + } +@@ -292,12 +279,6 @@ public class PrivacySettings + secureDnsPref.setSummary(SecureDnsSettings.getSummary(getContext())); + } + +- Preference privacySandboxPreference = findPreference(PREF_PRIVACY_SANDBOX); +- if (privacySandboxPreference != null) { +- privacySandboxPreference.setSummary( +- PrivacySandboxSettingsFragment.getStatusString(getContext())); +- } +- + ChromeSwitchPreference closeTabsOnExitPref = + (ChromeSwitchPreference) findPreference(PREF_CLOSE_TABS_ON_EXIT); + closeTabsOnExitPref.setOnPreferenceChangeListener(this); +diff --git a/chrome/browser/privacy_sandbox/privacy_sandbox_settings.cc b/chrome/browser/privacy_sandbox/privacy_sandbox_settings.cc +--- a/chrome/browser/privacy_sandbox/privacy_sandbox_settings.cc ++++ b/chrome/browser/privacy_sandbox/privacy_sandbox_settings.cc +@@ -111,23 +111,8 @@ bool ThirdPartyCookiesDisabledByPolicy( + bool ShouldDisablePrivacySandbox( + content_settings::CookieSettings* cookie_settings, + PrefService* prefs) { +- // If a user has already expressed control over the Privacy Sandbox preference +- // on any of their devices there is no need to disable it. +- if (prefs->GetBoolean(prefs::kPrivacySandboxManuallyControlled)) +- return false; +- +- auto cookie_controls_mode_value = +- static_cast( +- prefs->GetInteger(prefs::kCookieControlsMode)); +- +- auto default_cookie_setting = +- cookie_settings->GetDefaultCookieSetting(/*provider_id=*/nullptr); +- +- // The Privacy Sandbox preference should be disabled if 3P cookies or all +- // cookies are blocked. +- return (cookie_controls_mode_value == +- content_settings::CookieControlsMode::kBlockThirdParty || +- default_cookie_setting == ContentSetting::CONTENT_SETTING_BLOCK); ++ // privacy sandbox is always disabled ++ return true; + } + + // Returns whether FLoC is allowable by the current state of |pref_service|. +@@ -195,6 +180,8 @@ PrivacySandboxSettings::PrivacySandboxSettings( + base::BindRepeating(&PrivacySandboxSettings::OnPrivacySandboxPrefChanged, + base::Unretained(this))); + ++ // as default, privacy sandbox is disabled ++ pref_service_->SetBoolean(prefs::kPrivacySandboxApisEnabled, false); + // On first entering the privacy sandbox experiment, users may have the + // privacy sandbox disabled (or "reconciled") based on their current cookie + // settings (e.g. blocking 3P cookies). Depending on the state of the sync +@@ -393,7 +380,8 @@ bool PrivacySandboxSettings::IsPrivacySandboxManaged() { + + void PrivacySandboxSettings::SetPrivacySandboxEnabled(bool enabled) { + pref_service_->SetBoolean(prefs::kPrivacySandboxManuallyControlled, true); +- pref_service_->SetBoolean(prefs::kPrivacySandboxApisEnabled, enabled); ++ // never enable privacy sandbox ++ pref_service_->SetBoolean(prefs::kPrivacySandboxApisEnabled, false); + } + + void PrivacySandboxSettings::OnCookiesCleared() { +@@ -447,6 +435,10 @@ bool PrivacySandboxSettings::IsPrivacySandboxAllowedForContext( + const GURL& url, + const absl::optional& top_frame_origin, + const ContentSettingsForOneType& cookie_settings) const { ++ // even if prefs::kPrivacySandboxApisEnabled and ++ // prefs::kPrivacySandboxFlocEnabled are always false ++ if ((true)) ++ return false; // guard this code path + if (!pref_service_->GetBoolean(prefs::kPrivacySandboxApisEnabled)) + return false; + +@@ -459,6 +451,12 @@ bool PrivacySandboxSettings::IsPrivacySandboxAllowedForContext( + } + + void PrivacySandboxSettings::MaybeReconcilePrivacySandboxPref() { ++ // this code could be eliminated in the future, as initially ++ // the feauture was tied to the cookies flag ++ pref_service_->SetBoolean(prefs::kPrivacySandboxApisEnabled, false); ++ if((true)) ++ return; ++ + // No need to reconcile preferences if it has already happened. + if (pref_service_->GetBoolean(prefs::kPrivacySandboxPreferencesReconciled)) { + LogPrivacySandboxState(); +-- +2.20.1 +