Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warning text if the user has currently selected Block all cookies #27090

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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";
Expand Down Expand Up @@ -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";
Expand All @@ -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,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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(
"<LINK_1>",
"</LINK_1>",
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);

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down
5 changes: 5 additions & 0 deletions android/java/res/xml/brave_privacy_preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@
app:dialog_subtitle="@string/block_cookies_text"
app:dialog_entries="@array/blockCookiesTexts"
app:dialog_default_index="1" />
<!-- A description with hyperlink to explain more about block cross site cookies settings. -->
<org.chromium.components.browser_ui.settings.TextMessagePreference
app:icon="@drawable/ic_warning"
android:key="block_all_cross_site_cookies_learn_more"
app:iconTint="@color/wallet_error_text_color"/>
<org.chromium.chrome.browser.settings.BraveDialogPreference
android:key="fingerprinting_protection"
android:title="@string/block_fingerprinting"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class BravePrivacySettingsTest {
private static final String PREF_INCOGNITO_LOCK = "incognito_lock";
private static final String PREF_PHONE_AS_A_SECURITY_KEY = "phone_as_a_security_key";

private static final int BRAVE_PRIVACY_SETTINGS_NUMBER_OF_ITEMS = 29;
private static final int BRAVE_PRIVACY_SETTINGS_NUMBER_OF_ITEMS = 30;

private int mItemsLeft;

Expand Down
6 changes: 6 additions & 0 deletions app/brave_settings_strings.grdp
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,12 @@
<message name="IDS_SETTINGS_BRAVE_SHIELDS_COOKIE_CONTROL_LABEL" desc="Default Brave cookies control setting label">
Block cookies
</message>
<message name="IDS_SETTINGS_BRAVE_SHIELDS_COOKIE_CONTROL_BLOCK_ALL_DEPRECATED_LABEL" desc="Block all cookies deprecation warning">
Block all cookies option is deprecated. To force-enable,
</message>
<message name="IDS_SETTINGS_BRAVE_SHIELDS_COOKIE_CONTROL_BLOCK_ALL_DEPRECATED_LINK_LABEL" desc="Block all cookies learn more link text">
Learn more
</message>
<message name="IDS_SETTINGS_BLOCK_3RD_PARTY_COOKIES" desc="Select value">
Block third-party cookies
</message>
Expand Down
6 changes: 4 additions & 2 deletions browser/about_flags.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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), \
}, \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
cursor: pointer;
margin: 0 20px;
}
.block-all-cookies-warn {
cursor: pointer;
color: red;
}
</style>
<div hidden="[[isAdBlockRoute_]]">
<div class="settings-box first">
Expand Down Expand Up @@ -94,7 +98,15 @@
on-settings-boolean-control-change="onFingerprintingToggleControlChange_">
</settings-toggle-button>
<div class="settings-box">
<div class="start">$i18n{cookieControlLabel}</div>
<div class="start">
<div class="label">$i18n{cookieControlLabel}</div>
<div class="cr-secondary-text label block-all-cookies-warn" hidden="[[!controlEqual_('block', cookieControlType_)]]">
<span>$i18n{blockAllCookiesDeprecatedLabel}</span>
<a id="learnMore" href="https://github.com/brave/brave-browser/wiki/Block-all-cookies-global-Shields-setting" target="_blank">
$i18n{blockAllCookiesDeprecatedLinkLabel}
</a>
</div>
</div>
<select id="cookieControlType" class="md-select"
on-change="onCookieControlChange_">
<template is="dom-repeat" items="[[cookieControlTypes_]]">
Expand Down
6 changes: 6 additions & 0 deletions browser/ui/android/strings/android_brave_strings.grd
Original file line number Diff line number Diff line change
Expand Up @@ -1549,6 +1549,12 @@ Are you sure you want to do this?
<message name="IDS_BLOCK_TRACKERS_ADS_OPTION_3" desc="Text for block trackers and ads option.">
Allow all trackers &amp; ads
</message>
<message name="IDS_BLOCK_COOKIES_DEPRECATED_LABEL" desc="Block all cookies deprecation warning">
Block all cookies option is deprecated. To force-enable,
</message>
<message name="IDS_BLOCK_COOKIES_DEPRECATED_LINK_LABEL" desc="Block all cookies deprecation warning link">
<ph name="BEGIN_LINK_1">&lt;LINK_1&gt;</ph> learn more<ph name="END_LINK_1">&lt;/LINK_1&gt;</ph>
</message>
<message name="IDS_BLOCK_COOKIES" desc="Title for shields option.">
Block Cookies
</message>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Loading