Bug 1796146 - Add UI for the Cookie Banner preferences

fork
owlishDeveloper 2 years ago committed by mergify[bot]
parent c87589bef2
commit 8589aec0a0

@ -1,4 +1,12 @@
---
cookie-banners:
description: Features for cookie banner handling.
hasExposure: true
exposureDescription: ""
variables:
sections-enabled:
type: json
description: This property provides a lookup table of whether or not the given section should be enabled.
growth-data:
description: A feature measuring campaign growth data
hasExposure: true

@ -6795,6 +6795,45 @@ autoplay:
tags:
- SitePermissions
cookie_banners:
visited_setting:
type: event
description: A user visited the cookie banner handling screen
bugs:
- https://bugzilla.mozilla.org/show_bug.cgi?id=1796146
data_reviews:
- https://github.com/mozilla-mobile/fenix/pull/27561
data_sensitivity:
- interaction
notification_emails:
- android-probes@mozilla.com
expires: 118
metadata:
tags:
- Privacy&Security
setting_changed:
type: event
description: |
A user changed their setting.
extra_keys:
cookie_banner_setting:
description: |
The new setting for cookie banners: disabled,reject_all,
or reject_or_accept_all.
type: string
bugs:
- https://bugzilla.mozilla.org/show_bug.cgi?id=1796146
data_reviews:
- https://github.com/mozilla-mobile/fenix/pull/27561
data_sensitivity:
- interaction
notification_emails:
- android-probes@mozilla.com
expires: 118
metadata:
tags:
- Privacy&Security
site_permissions:
prompt_shown:
type: event

@ -132,6 +132,8 @@ class Core(
R.color.fx_mobile_layer_color_1,
),
httpsOnlyMode = context.settings().getHttpsOnlyMode(),
cookieBannerHandlingModePrivateBrowsing = context.settings().getCookieBannerHandling(),
cookieBannerHandlingMode = context.settings().getCookieBannerHandling(),
)
GeckoEngine(

@ -0,0 +1,61 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.mozilla.fenix.settings
import android.os.Bundle
import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat
import androidx.preference.SwitchPreference
import mozilla.components.concept.engine.EngineSession.CookieBannerHandlingMode.DISABLED
import mozilla.components.concept.engine.EngineSession.CookieBannerHandlingMode.REJECT_OR_ACCEPT_ALL
import mozilla.components.concept.engine.Settings
import org.mozilla.fenix.GleanMetrics.CookieBanners
import org.mozilla.fenix.R
import org.mozilla.fenix.ext.components
import org.mozilla.fenix.ext.settings
import org.mozilla.fenix.ext.showToolbar
/**
* Lets the user set up the cookie banners handling preferences.
*/
class CookieBannersFragment : PreferenceFragmentCompat() {
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
setPreferencesFromResource(R.xml.cookie_banner_preferences, rootKey)
setupPreferences()
}
override fun onResume() {
super.onResume()
showToolbar(getString(R.string.preferences_cookie_banner_reduction))
}
private fun getEngineSettings(): Settings {
return requireContext().components.core.engine.settings
}
private fun setupPreferences() {
requirePreference<SwitchPreference>(R.string.pref_key_cookie_banner).apply {
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"
} else {
DISABLED to "disabled"
}
requireContext().settings().shouldUseCookieBanner = newValue as Boolean
getEngineSettings().cookieBannerHandlingModePrivateBrowsing = mode
getEngineSettings().cookieBannerHandlingMode = mode
CookieBanners.settingChanged.record(CookieBanners.SettingChangedExtra(metricTag))
requireContext().components.useCases.sessionUseCases.reload()
return super.onPreferenceChange(preference, newValue)
}
}
}
}
}

@ -40,6 +40,7 @@ import org.mozilla.fenix.BrowserDirection
import org.mozilla.fenix.Config
import org.mozilla.fenix.FeatureFlags
import org.mozilla.fenix.GleanMetrics.Addons
import org.mozilla.fenix.GleanMetrics.CookieBanners
import org.mozilla.fenix.GleanMetrics.Events
import org.mozilla.fenix.GleanMetrics.TrackingProtection
import org.mozilla.fenix.HomeActivity
@ -279,6 +280,10 @@ class SettingsFragment : PreferenceFragmentCompat() {
resources.getString(R.string.pref_key_https_only_settings) -> {
SettingsFragmentDirections.actionSettingsFragmentToHttpsOnlyFragment()
}
resources.getString(R.string.pref_key_cookie_banner_settings) -> {
CookieBanners.visitedSetting.record(mozilla.components.service.glean.private.NoExtras())
SettingsFragmentDirections.actionSettingsFragmentToCookieBannerFragment()
}
resources.getString(R.string.pref_key_accessibility) -> {
SettingsFragmentDirections.actionSettingsFragmentToAccessibilityFragment()
}
@ -436,6 +441,7 @@ class SettingsFragment : PreferenceFragmentCompat() {
val preferenceOpenLinksInExternalApp =
findPreference<Preference>(getPreferenceKey(R.string.pref_key_open_links_in_external_app))
if (!Config.channel.isReleased) {
preferenceLeakCanary?.setOnPreferenceChangeListener { _, newValue ->
val isEnabled = newValue == true
@ -464,6 +470,8 @@ class SettingsFragment : PreferenceFragmentCompat() {
findPreference<Preference>(getPreferenceKey(R.string.pref_key_start_profiler))
with(requireContext().settings()) {
findPreference<Preference>(getPreferenceKey(R.string.pref_key_cookie_banner_settings))
?.isVisible = shouldShowCookieBannerUI
findPreference<Preference>(
getPreferenceKey(R.string.pref_key_nimbus_experiments),
)?.isVisible = showSecretDebugMenuThisSession

@ -16,6 +16,7 @@ import androidx.annotation.VisibleForTesting
import androidx.annotation.VisibleForTesting.Companion.PRIVATE
import androidx.lifecycle.LifecycleOwner
import mozilla.components.concept.engine.Engine.HttpsOnlyMode
import mozilla.components.concept.engine.EngineSession.CookieBannerHandlingMode
import mozilla.components.feature.sitepermissions.SitePermissionsRules
import mozilla.components.feature.sitepermissions.SitePermissionsRules.Action
import mozilla.components.feature.sitepermissions.SitePermissionsRules.AutoplayAction
@ -40,6 +41,7 @@ import org.mozilla.fenix.components.settings.lazyFeatureFlagPreference
import org.mozilla.fenix.components.toolbar.ToolbarPosition
import org.mozilla.fenix.ext.components
import org.mozilla.fenix.ext.getPreferenceKey
import org.mozilla.fenix.nimbus.CookieBannersSection
import org.mozilla.fenix.nimbus.FxNimbus
import org.mozilla.fenix.nimbus.HomeScreenSection
import org.mozilla.fenix.nimbus.Mr2022Section
@ -535,6 +537,15 @@ class Settings(private val appContext: Context) : PreferencesHolder {
default = true,
)
var shouldUseCookieBanner by lazyFeatureFlagPreference(
appContext.getPreferenceKey(R.string.pref_key_cookie_banner),
featureFlag = true,
default = { cookieBannersSection[CookieBannersSection.FEATURE_SETTING_VALUE] == true },
)
val shouldShowCookieBannerUI: Boolean
get() = cookieBannersSection[CookieBannersSection.FEATURE_UI] == true
/**
* Declared as a function for performance purposes. This could be declared as a variable using
* booleanPreference like other members of this class. However, doing so will make it so it will
@ -1255,6 +1266,10 @@ class Settings(private val appContext: Context) : PreferencesHolder {
get() =
FxNimbus.features.mr2022.value().sectionsEnabled
private val cookieBannersSection: Map<CookieBannersSection, Boolean>
get() =
FxNimbus.features.cookieBanners.value().sectionsEnabled
private val homescreenSections: Map<HomeScreenSection, Boolean>
get() =
FxNimbus.features.homescreen.value().sectionsEnabled
@ -1410,6 +1425,16 @@ class Settings(private val appContext: Context) : PreferencesHolder {
}
}
/**
* Get the current mode for cookie banner handling
*/
fun getCookieBannerHandling(): CookieBannerHandlingMode {
return when (shouldUseCookieBanner) {
true -> CookieBannerHandlingMode.REJECT_OR_ACCEPT_ALL
false -> CookieBannerHandlingMode.DISABLED
}
}
var setAsDefaultGrowthSent by booleanPreference(
key = appContext.getPreferenceKey(R.string.pref_key_growth_set_as_default),
default = false,

@ -603,6 +603,13 @@
app:exitAnim="@anim/slide_out_left"
app:popEnterAnim="@anim/slide_in_left"
app:popExitAnim="@anim/slide_out_right" />
<action
android:id="@+id/action_settingsFragment_to_cookieBannerFragment"
app:destination="@id/cookieBannerFragment"
app:enterAnim="@anim/slide_in_right"
app:exitAnim="@anim/slide_out_left"
app:popEnterAnim="@anim/slide_in_left"
app:popExitAnim="@anim/slide_out_right" />
<action
android:id="@+id/action_settingsFragment_to_trackingProtectionFragment"
app:destination="@id/trackingProtectionFragment"
@ -817,6 +824,10 @@
android:id="@+id/httpsOnlyFragment"
android:name="org.mozilla.fenix.settings.HttpsOnlyFragment"
android:label="@string/preferences_https_only_title" />
<fragment
android:id="@+id/cookieBannerFragment"
android:name="org.mozilla.fenix.settings.CookieBannersFragment"
android:label="@string/preferences_cookie_banner_reduction" />
<fragment
android:id="@+id/trackingProtectionFragment"
android:name="org.mozilla.fenix.settings.TrackingProtectionFragment">

@ -147,6 +147,10 @@
<string name="pref_key_https_only_in_all_tabs" translatable="false">pref_key_https_only_in_all_tabs</string>
<string name="pref_key_https_only_in_private_tabs" translatable="false">pref_key_https_only_in_private_tabs</string>
<!-- Cookie Banner Reduction Settings-->
<string name="pref_key_cookie_banner_settings" translatable="false">pref_key_cookie_banner_settings</string>
<string name="pref_key_cookie_banner" translatable="false">pref_key_cookie_banner</string>
<!-- Tracking Protection Settings -->
<string name="pref_key_etp_learn_more" translatable="false">pref_key_etp_learn_more</string>
<string name="pref_key_tracking_protection_settings" translatable="false">pref_key_tracking_protection_settings</string>

@ -316,6 +316,14 @@
<string name="preferences_add_private_browsing_shortcut">Add private browsing shortcut</string>
<!-- Preference for enabling "HTTPS-Only" mode -->
<string name="preferences_https_only_title">HTTPS-Only Mode</string>
<!-- Description of the cookie banner reduction setting. -->
<string name="preferences_cookie_banner_reduction">Cookie Banner Reduction</string>
<!-- Preference for rejecting all cookies whenever possible. -->
<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>
<!-- Description of the preference to enable "HTTPS-Only" mode. -->
<string name="preferences_https_only_summary">Automatically attempts to connect to sites using HTTPS encryption protocol for increased security.</string>
<!-- Summary of tracking protection preference if tracking protection is set to on -->

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?><!-- This Source Code Form is subject to the terms of the Mozilla Public
- License, v. 2.0. If a copy of the MPL was not distributed with this
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
<androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<SwitchPreference
android:defaultValue="true"
android:key="@string/pref_key_cookie_banner"
android:summary="@string/reduce_cookie_banner_summary"
android:title="@string/reduce_cookie_banner_option" />
</androidx.preference.PreferenceScreen>

@ -102,6 +102,12 @@
app:iconSpaceReserved="false"
android:title="@string/preferences_https_only_title" />
<androidx.preference.Preference
android:key="@string/pref_key_cookie_banner_settings"
app:iconSpaceReserved="false"
android:title="@string/preferences_cookie_banner_reduction"
app:isPreferenceVisible="false" />
<androidx.preference.Preference
android:key="@string/pref_key_tracking_protection_settings"
app:iconSpaceReserved="false"

@ -207,6 +207,32 @@ features:
}
}
cookie-banners:
description: Features for cookie banner handling.
variables:
sections-enabled:
description: "This property provides a lookup table of whether or not the given section should be enabled."
type: Map<CookieBannersSection, Boolean>
default:
{
"feature-ui": false,
"feature-setting-value": false,
}
defaults:
- channel: developer
value: {
"sections-enabled": {
"feature-ui": true,
"feature-setting-value": true,
}
}
- channel: nightly
value: {
"sections-enabled": {
"feature-ui": true,
"feature-setting-value": true,
}
}
unified-search:
description: A feature allowing user to easily search for specified results directly in the search bar.
variables:
@ -344,3 +370,10 @@ types:
description: CFR for the first time you use the browse with Total Cookie Protection on the browser screen.
tcp-feature:
description: Controls the Total Cookie Protection feature.
CookieBannersSection:
description: The identifiers for the sections of the MR 2022.
variants:
feature-ui:
description: Indicates if the user interfaces should be visible.
feature-setting-value:
description: Indicates if the cookie handling setting should be enabled.

Loading…
Cancel
Save