diff --git a/android/java/org/chromium/chrome/browser/privacy/settings/BravePrivacySettings.java b/android/java/org/chromium/chrome/browser/privacy/settings/BravePrivacySettings.java index 80363d488fd7..5cfb40bc9585 100644 --- a/android/java/org/chromium/chrome/browser/privacy/settings/BravePrivacySettings.java +++ b/android/java/org/chromium/chrome/browser/privacy/settings/BravePrivacySettings.java @@ -7,6 +7,10 @@ import android.content.SharedPreferences; import android.os.Bundle; +import android.text.Spannable; +import android.text.SpannableString; +import android.text.SpannableStringBuilder; +import android.text.style.ForegroundColorSpan; import androidx.preference.Preference; import androidx.preference.PreferenceCategory; @@ -33,18 +37,25 @@ import org.chromium.chrome.browser.settings.BravePreferenceDialogFragment; import org.chromium.chrome.browser.settings.BraveWebrtcPolicyPreference; import org.chromium.chrome.browser.shields.FilterListServiceFactory; +import org.chromium.chrome.browser.util.TabUtils; import org.chromium.chrome.browser.webcompat_reporter.WebcompatReporterServiceFactory; import org.chromium.components.browser_ui.settings.ChromeBasePreference; import org.chromium.components.browser_ui.settings.ChromeSwitchPreference; import org.chromium.components.browser_ui.settings.SettingsUtils; +import org.chromium.components.browser_ui.settings.TextMessagePreference; import org.chromium.components.user_prefs.UserPrefs; import org.chromium.gms.ChromiumPlayServicesAvailability; import org.chromium.mojo.bindings.ConnectionErrorHandler; import org.chromium.mojo.system.MojoException; +import org.chromium.ui.text.NoUnderlineClickableSpan; +import org.chromium.ui.text.SpanApplier; import org.chromium.webcompat_reporter.mojom.WebcompatReporterHandler; /** Fragment to keep track of the all the brave privacy related preferences. */ public class BravePrivacySettings extends PrivacySettings implements ConnectionErrorHandler { + private static final String BLOCK_ALL_COOKIES_LEARN_MORE_LINK = + "https://github.com/brave/brave-browser/wiki/Block-all-cookies-global-Shields-setting"; + // Chromium Prefs private static final String PREF_CAN_MAKE_PAYMENT = "can_make_payment"; private static final String PREF_NETWORK_PREDICTIONS = "preload_pages"; @@ -102,6 +113,8 @@ public class BravePrivacySettings extends PrivacySettings implements ConnectionE public static final String PREF_BLOCK_TRACKERS_ADS = "block_trackers_ads"; private static final String PREF_BLOCK_CROSS_SITE_COOKIES = "block_cross_site_cookies"; + private static final String BLOCK_CROSS_SITE_COOKIES_LEARN_MORE = + "block_all_cross_site_cookies_learn_more"; private static final String PREF_SHIELDS_SUMMARY = "shields_summary"; private static final String PREF_CLEAR_ON_EXIT = "clear_on_exit"; private static final String PREF_HTTPS_UPGRADE = "https_upgrade"; @@ -117,6 +130,7 @@ public class BravePrivacySettings extends PrivacySettings implements ConnectionE PREF_HTTPS_FIRST_MODE, PREF_BLOCK_SCRIPTS, PREF_BLOCK_CROSS_SITE_COOKIES, + BLOCK_CROSS_SITE_COOKIES_LEARN_MORE, PREF_FINGERPRINTING_PROTECTION, PREF_FINGERPRINTING_PROTECTION2, PREF_FINGERPRINT_LANGUAGE, @@ -163,6 +177,7 @@ public class BravePrivacySettings extends PrivacySettings implements ConnectionE private ChromeSwitchPreference mCanMakePayment; private BraveDialogPreference mAdsTrakersBlockPref; private BraveDialogPreference mBlockCrosssiteCookies; + private TextMessagePreference mBlockCrosssiteCookiesLearnMore; private ChromeSwitchPreference mDeAmpPref; private ChromeSwitchPreference mDebouncePref; private ChromeSwitchPreference mHttpsFirstModePref; @@ -280,6 +295,37 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { (BraveDialogPreference) findPreference(PREF_BLOCK_CROSS_SITE_COOKIES); mBlockCrosssiteCookies.setOnPreferenceChangeListener(this); + mBlockCrosssiteCookiesLearnMore = + (TextMessagePreference) findPreference(BLOCK_CROSS_SITE_COOKIES_LEARN_MORE); + if (mBlockCrosssiteCookiesLearnMore != null) { + SpannableString blockAllCookiesDeprecatedWarning = + new SpannableString(getString(R.string.block_cookies_deprecated_label)); + blockAllCookiesDeprecatedWarning.setSpan( + new ForegroundColorSpan(getContext().getColor(R.color.wallet_error_text_color)), + 0, + blockAllCookiesDeprecatedWarning.length(), + Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); + + SpannableString learnMoreDesc = + SpanApplier.applySpans( + getString(R.string.block_cookies_deprecated_link_label), + new SpanApplier.SpanInfo( + "", + "", + new NoUnderlineClickableSpan( + requireContext(), + R.color.brave_link, + result -> { + TabUtils.openUrlInCustomTab( + requireContext(), + BLOCK_ALL_COOKIES_LEARN_MORE_LINK); + }))); + SpannableStringBuilder spannableBuilder = new SpannableStringBuilder(); + spannableBuilder.append(blockAllCookiesDeprecatedWarning); + spannableBuilder.append(learnMoreDesc); + mBlockCrosssiteCookiesLearnMore.setSummary(spannableBuilder); + } + mBlockScriptsPref = (ChromeSwitchPreference) findPreference(PREF_BLOCK_SCRIPTS); mBlockScriptsPref.setOnPreferenceChangeListener(this); @@ -511,6 +557,8 @@ public boolean onPreferenceChange(Preference preference, Object newValue) { 0, ChromeFeatureList.isEnabled(BraveFeatureList.BRAVE_BLOCK_ALL_COOKIES_TOGGLE) || (int) newValue == STRICT); + mBlockCrosssiteCookiesLearnMore.setVisible(STRICT == (int) newValue); + mBlockCrosssiteCookiesLearnMore.setDividerAllowedAbove(false); switch ((int) newValue) { case STRICT: BraveShieldsContentSettings.setCookiesPref( @@ -642,6 +690,8 @@ private void updateBravePreferences() { 0, ChromeFeatureList.isEnabled(BraveFeatureList.BRAVE_BLOCK_ALL_COOKIES_TOGGLE) || cookiesBlockPref == STRICT); + mBlockCrosssiteCookiesLearnMore.setVisible(STRICT == (int) cookiesBlockPref); + mBlockCrosssiteCookiesLearnMore.setDividerAllowedAbove(false); if (cookiesBlockPref == STRICT) { mBlockCrosssiteCookies.setCheckedIndex(0); mBlockCrosssiteCookies.setSummary( diff --git a/android/java/res/xml/brave_privacy_preferences.xml b/android/java/res/xml/brave_privacy_preferences.xml index 7b109d8c5109..f2f76d2a59d5 100644 --- a/android/java/res/xml/brave_privacy_preferences.xml +++ b/android/java/res/xml/brave_privacy_preferences.xml @@ -34,6 +34,11 @@ app:dialog_subtitle="@string/block_cookies_text" app:dialog_entries="@array/blockCookiesTexts" app:dialog_default_index="1" /> + + Block cookies + + Block all cookies option is deprecated. To force-enable, + + + Learn more + Block third-party cookies diff --git a/browser/about_flags.cc b/browser/about_flags.cc index ecb7abbe79e6..ec5befc05f5a 100644 --- a/browser/about_flags.cc +++ b/browser/about_flags.cc @@ -691,8 +691,10 @@ }, \ { \ "block-all-cookies-toggle", \ - "If the feature flag is on, we show the Block all Cookies toggle", \ - "If the feature flag is on, we show the Block all Cookies toggle", \ + "'Block all cookies' option in Shields global defaults", \ + "Shows the 'Block all cookies' toggle in Shields global defaults. " \ + "This global setting prevents all websites from storing cookies " \ + "on your device, but is also very likely to lead to site breakage.", \ kOsAll, \ FEATURE_VALUE_TYPE(brave_shields::features::kBlockAllCookiesToggle), \ }, \ diff --git a/browser/resources/settings/default_brave_shields_page/default_brave_shields_page.html b/browser/resources/settings/default_brave_shields_page/default_brave_shields_page.html index eb767bbb4df2..082c555b61b9 100644 --- a/browser/resources/settings/default_brave_shields_page/default_brave_shields_page.html +++ b/browser/resources/settings/default_brave_shields_page/default_brave_shields_page.html @@ -28,6 +28,10 @@ cursor: pointer; margin: 0 20px; } + .block-all-cookies-warn { + cursor: pointer; + color: red; + } @@ -94,7 +98,15 @@ on-settings-boolean-control-change="onFingerprintingToggleControlChange_"> - $i18n{cookieControlLabel} + + $i18n{cookieControlLabel} + + $i18n{blockAllCookiesDeprecatedLabel} + + $i18n{blockAllCookiesDeprecatedLinkLabel} + + + diff --git a/browser/ui/android/strings/android_brave_strings.grd b/browser/ui/android/strings/android_brave_strings.grd index f5889345702d..bc1d41c1bc08 100644 --- a/browser/ui/android/strings/android_brave_strings.grd +++ b/browser/ui/android/strings/android_brave_strings.grd @@ -1549,6 +1549,12 @@ Are you sure you want to do this? Allow all trackers & ads + + Block all cookies option is deprecated. To force-enable, + + + <LINK_1> learn more</LINK_1> + Block Cookies diff --git a/browser/ui/webui/settings/brave_settings_localized_strings_provider.cc b/browser/ui/webui/settings/brave_settings_localized_strings_provider.cc index 1897ad99cf96..375c1fd324a7 100644 --- a/browser/ui/webui/settings/brave_settings_localized_strings_provider.cc +++ b/browser/ui/webui/settings/brave_settings_localized_strings_provider.cc @@ -344,6 +344,10 @@ void BraveAddCommonStrings(content::WebUIDataSource* html_source, {"advancedView", IDS_SETTINGS_BRAVE_SHIELDS_DEFAULTS_ADVANCED_VIEW_LABEL}, {"adControlLabel", IDS_SETTINGS_BRAVE_SHIELDS_AD_CONTROL_LABEL}, {"cookieControlLabel", IDS_SETTINGS_BRAVE_SHIELDS_COOKIE_CONTROL_LABEL}, + {"blockAllCookiesDeprecatedLabel", + IDS_SETTINGS_BRAVE_SHIELDS_COOKIE_CONTROL_BLOCK_ALL_DEPRECATED_LABEL}, + {"blockAllCookiesDeprecatedLinkLabel", + IDS_SETTINGS_BRAVE_SHIELDS_COOKIE_CONTROL_BLOCK_ALL_DEPRECATED_LINK_LABEL}, {"fingerprintingControlLabel", IDS_SETTINGS_BRAVE_SHIELDS_FINGERPRINTING_CONTROL_LABEL}, {"httpsUpgradeControlLabel",