[fenix] Bug 1809507 - Update cookie banner to reject_all setting

pull/600/head
Arturo Mejia 2 years ago committed by mergify[bot]
parent fc362ea814
commit c992f258ec

@ -9,7 +9,7 @@ import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat
import androidx.preference.SwitchPreferenceCompat
import mozilla.components.concept.engine.EngineSession.CookieBannerHandlingMode.DISABLED
import mozilla.components.concept.engine.EngineSession.CookieBannerHandlingMode.REJECT_OR_ACCEPT_ALL
import mozilla.components.concept.engine.EngineSession.CookieBannerHandlingMode.REJECT_ALL
import mozilla.components.concept.engine.Settings
import org.mozilla.fenix.GleanMetrics.CookieBanners
import org.mozilla.fenix.R
@ -38,13 +38,15 @@ class CookieBannersFragment : PreferenceFragmentCompat() {
private fun setupPreferences() {
requirePreference<SwitchPreferenceCompat>(R.string.pref_key_cookie_banner_v1).apply {
summary =
getString(R.string.reduce_cookie_banner_summary_1, getString(R.string.app_name))
onPreferenceChangeListener = object : SharedPreferenceUpdater() {
override fun onPreferenceChange(
preference: Preference,
newValue: Any?,
): Boolean {
val (mode, metricTag) = if (newValue == true) {
REJECT_OR_ACCEPT_ALL to "reject_or_accept_all"
REJECT_ALL to "reject_all"
} else {
DISABLED to "disabled"
}

@ -28,11 +28,17 @@ abstract class LearnMoreSwitchPreference(context: Context, attrs: AttributeSet?)
override fun onBindViewHolder(holder: PreferenceViewHolder) {
super.onBindViewHolder(holder)
holder.itemView.isClickable = false
val switch = holder.findViewById(R.id.learn_more_switch) as SwitchCompat
switch.run {
isChecked = getSwitchValue()
setOnCheckedChangeListener { _, isChecked ->
onPreferenceChangeListener.onPreferenceChange(
this@LearnMoreSwitchPreference,
isChecked,
)
}
}
getDescription()?.let {

@ -75,10 +75,10 @@ class CookieBannerHandlingDetailsView(
if (isCookieBannerHandlingEnabled) {
R.string.reduce_cookie_banner_details_panel_description_off_for_site
} else {
R.string.reduce_cookie_banner_details_panel_description_on_for_site
R.string.reduce_cookie_banner_details_panel_description_on_for_site_1
}
val appName = context.getString(R.string.app_name)
binding.details.text = context.getString(stringID, appName, appName)
binding.details.text = context.getString(stringID, appName)
}
@VisibleForTesting

@ -10,7 +10,7 @@ import android.view.View
import android.view.ViewGroup
import androidx.compose.ui.platform.ComposeView
import androidx.fragment.app.DialogFragment
import mozilla.components.concept.engine.EngineSession.CookieBannerHandlingMode.REJECT_OR_ACCEPT_ALL
import mozilla.components.concept.engine.EngineSession.CookieBannerHandlingMode.REJECT_ALL
import mozilla.components.concept.engine.Settings
import mozilla.telemetry.glean.private.NoExtras
import org.mozilla.fenix.GleanMetrics.CookieBanners
@ -45,8 +45,8 @@ class CookieBannerReEngagementDialog : DialogFragment() {
onAllowButtonClicked = {
CookieBanners.allowReEngagementDialog.record(NoExtras())
requireContext().settings().shouldUseCookieBanner = true
getEngineSettings().cookieBannerHandlingModePrivateBrowsing = REJECT_OR_ACCEPT_ALL
getEngineSettings().cookieBannerHandlingMode = REJECT_OR_ACCEPT_ALL
getEngineSettings().cookieBannerHandlingModePrivateBrowsing = REJECT_ALL
getEngineSettings().cookieBannerHandlingMode = REJECT_ALL
reload()
requireContext().getRootView()?.let {
FenixSnackbar.make(

@ -32,7 +32,7 @@ object CookieBannerReEngagementDialogUtils {
CONTROL_VARIANT -> CookieBannerDialogVariant(
title = context.getString(R.string.reduce_cookie_banner_control_experiment_dialog_title),
message = context.getString(
R.string.reduce_cookie_banner_control_experiment_dialog_body,
R.string.reduce_cookie_banner_control_experiment_dialog_body_1,
),
positiveTextButton = context.getString(
R.string.reduce_cookie_banner_control_experiment_dialog_change_setting_button,
@ -41,7 +41,7 @@ object CookieBannerReEngagementDialogUtils {
VARIANT_ONE -> CookieBannerDialogVariant(
title = context.getString(R.string.reduce_cookie_banner_variant_1_experiment_dialog_title),
message = context.getString(
R.string.reduce_cookie_banner_variant_1_experiment_dialog_body,
R.string.reduce_cookie_banner_variant_1_experiment_dialog_body_1,
context.getString(R.string.app_name),
),
positiveTextButton = context.getString(
@ -51,7 +51,7 @@ object CookieBannerReEngagementDialogUtils {
VARIANT_TWO -> CookieBannerDialogVariant(
title = context.getString(R.string.reduce_cookie_banner_variant_2_experiment_dialog_title),
message = context.getString(
R.string.reduce_cookie_banner_variant_2_experiment_dialog_body,
R.string.reduce_cookie_banner_variant_2_experiment_dialog_body_1,
context.getString(R.string.app_name),
),
positiveTextButton = context.getString(
@ -62,7 +62,7 @@ object CookieBannerReEngagementDialogUtils {
CookieBannerDialogVariant(
title = context.getString(R.string.reduce_cookie_banner_control_experiment_dialog_title),
message = context.getString(
R.string.reduce_cookie_banner_control_experiment_dialog_body,
R.string.reduce_cookie_banner_control_experiment_dialog_body_1,
),
positiveTextButton = context.getString(
R.string.reduce_cookie_banner_control_experiment_dialog_change_setting_button,

@ -1506,7 +1506,7 @@ class Settings(private val appContext: Context) : PreferencesHolder {
*/
fun getCookieBannerHandling(): CookieBannerHandlingMode {
return when (shouldUseCookieBanner) {
true -> CookieBannerHandlingMode.REJECT_OR_ACCEPT_ALL
true -> CookieBannerHandlingMode.REJECT_ALL
false -> if (shouldShowCookieBannerUI && !userOptOutOfReEngageCookieBannerDialog) {
CookieBannerHandlingMode.DETECT_ONLY
} else {

@ -340,7 +340,9 @@
<!-- Preference for rejecting or removing as many cookie/consent banners as possible on sites. See reduce_cookie_banner_summary for additional context. -->
<string name="reduce_cookie_banner_option">Reduce cookie banners</string>
<!-- Summary for the preference for rejecting all cookies whenever possible. -->
<string name="reduce_cookie_banner_summary">Firefox automatically tries to reject cookie requests on cookie banners. If a reject option isnt available, Firefox may accept all cookies to dismiss the banner.</string>
<string name="reduce_cookie_banner_summary" moz:RemovedIn="110" tools:ignore="UnusedResources">Firefox automatically tries to reject cookie requests on cookie banners. If a reject option isnt available, Firefox may accept all cookies to dismiss the banner.</string>
<!-- Summary for the preference for rejecting all cookies whenever possible. The first parameter is the application name -->
<string name="reduce_cookie_banner_summary_1">%1$s automatically tries to reject cookie requests on cookie banners.</string>
<!-- Text for indicating cookie banner handling is off this site, this is shown as part of the protections panel with the tracking protection toggle -->
<string name="reduce_cookie_banner_off_for_site">Off for this site</string>
<!-- Text for indicating cookie banner handling is on this site, this is shown as part of the protections panel with the tracking protection toggle -->
@ -352,11 +354,15 @@
<!-- Long text for a detail explanation indicating what will happen if cookie banner handling is off for a site, this is shown as part of the cookie banner panel in the toolbar. The first parameter is the application name -->
<string name="reduce_cookie_banner_details_panel_description_off_for_site">%1$s will clear this sites cookies and refresh the page. Clearing all cookies may sign you out or empty shopping carts.</string>
<!-- Long text for a detail explanation indicating what will happen if cookie banner handling is on for a site, this is shown as part of the cookie banner panel in the toolbar. The first and second parameter are the application name -->
<string name="reduce_cookie_banner_details_panel_description_on_for_site">%1$s can try to automatically reject cookie requests. If a reject option isnt available, %2$s may accept all cookies to dismiss the banner.</string>
<string name="reduce_cookie_banner_details_panel_description_on_for_site" moz:RemovedIn="110" tools:ignore="UnusedResources">%1$s can try to automatically reject cookie requests. If a reject option isnt available, %2$s may accept all cookies to dismiss the banner.</string>
<!-- Long text for a detail explanation indicating what will happen if cookie banner handling is on for a site, this is shown as part of the cookie banner panel in the toolbar. The first and second parameter are the application name -->
<string name="reduce_cookie_banner_details_panel_description_on_for_site_1">%1$s can try to automatically reject cookie requests.</string>
<!-- Title text for the dialog use on the control branch of the experiment to determine which context users engaged the most -->
<string name="reduce_cookie_banner_control_experiment_dialog_title" tools:ignore="UnusedResources">Cookie banners begone!</string>
<!-- Body text for the dialog use on the control branch of the experiment to determine which context users engaged the most -->
<string name="reduce_cookie_banner_control_experiment_dialog_body" tools:ignore="UnusedResources">Automatically reject cookie requests, when possible. Otherwise, accept all cookies to dismiss cookie banners.</string>
<string name="reduce_cookie_banner_control_experiment_dialog_body" moz:RemovedIn="110" tools:ignore="UnusedResources">Automatically reject cookie requests, when possible. Otherwise, accept all cookies to dismiss cookie banners.</string>
<!-- Body text for the dialog use on the control branch of the experiment to determine which context users engaged the most -->
<string name="reduce_cookie_banner_control_experiment_dialog_body_1">Automatically reject cookie requests, when possible.</string>
<!-- Remind me later text button for the onboarding dialog -->
<string name="reduce_cookie_banner_dialog_not_now_button">Not Now</string>
<!-- Change setting text button, for the dialog use on the control branch of the experiment to determine which context users engaged the most -->
@ -366,13 +372,17 @@
<!-- Title text for the dialog use on the variant 1 branch of the experiment to determine which context users engaged the most -->
<string name="reduce_cookie_banner_variant_1_experiment_dialog_title">See fewer cookie pop-ups</string>
<!-- Body text for the dialog use on the variant 1 branch of the experiment to determine which context users engaged the most. The first parameter is the application name. -->
<string name="reduce_cookie_banner_variant_1_experiment_dialog_body">Automatically answer cookie pop-ups for distraction-free browsing. %1$s will reject all requests if possible, or accept all if not.</string>
<string name="reduce_cookie_banner_variant_1_experiment_dialog_body" moz:RemovedIn="110" tools:ignore="UnusedResources">Automatically answer cookie pop-ups for distraction-free browsing. %1$s will reject all requests if possible, or accept all if not.</string>
<!-- Body text for the dialog use on the variant 1 branch of the experiment to determine which context users engaged the most. The first parameter is the application name. -->
<string name="reduce_cookie_banner_variant_1_experiment_dialog_body_1">Automatically answer cookie pop-ups for distraction-free browsing. %1$s will reject all requests if possible.</string>
<!-- Change setting text button, for the onboarding dialog use on the variant 1 branch of the experiment to determine which context users engaged the most -->
<string name="reduce_cookie_banner_variant_1_experiment_dialog_change_setting_button">Dismiss Pop-ups</string>
<!-- Title text for the dialog use on the variant 2 branch of the experiment to determine which context users engaged the most -->
<string name="reduce_cookie_banner_variant_2_experiment_dialog_title">Cookie Banner Reduction</string>
<!-- Body text for the dialog use on the variant 2 branch of the experiment to determine which context users engaged the most. The first parameter is the application name. -->
<string name="reduce_cookie_banner_variant_2_experiment_dialog_body">Allow %1$s to decline a sites cookie consent request if possible or accept cookie access when not possible?</string>
<string name="reduce_cookie_banner_variant_2_experiment_dialog_body" moz:RemovedIn="110" tools:ignore="UnusedResources">Allow %1$s to decline a sites cookie consent request if possible or accept cookie access when not possible?</string>
<!-- Body text for the dialog use on the variant 2 branch of the experiment to determine which context users engaged the most. The first parameter is the application name. -->
<string name="reduce_cookie_banner_variant_2_experiment_dialog_body_1">Allow %1$s to decline a sites cookie consent request if possible?</string>
<!-- Change setting text button, for the dialog use on the variant 2 branch of the experiment to determine which context users engaged the most -->
<string name="reduce_cookie_banner_variant_2_experiment_dialog_change_setting_button">Allow</string>

@ -5,6 +5,5 @@
<org.mozilla.fenix.settings.CookieBannersSwitchPreference
android:defaultValue="false"
android:key="@string/pref_key_cookie_banner_v1"
android:summary="@string/reduce_cookie_banner_summary"
android:title="@string/reduce_cookie_banner_option" />
</androidx.preference.PreferenceScreen>

@ -152,7 +152,7 @@ class CookieBannerHandlingDetailsViewTest {
val appName = testContext.getString(R.string.app_name)
val expectedText =
testContext.getString(
R.string.reduce_cookie_banner_details_panel_description_on_for_site,
R.string.reduce_cookie_banner_details_panel_description_on_for_site_1,
appName,
appName,
)

Loading…
Cancel
Save