2
0
mirror of https://github.com/fork-maintainers/iceraven-browser synced 2024-11-05 21:20:45 +00:00

Bug 1816186 - Use detect-only just when we can show the re-engagement dialog

(cherry picked from commit afcbb55e7f89527b40a21ef90d0816f94df17b1a)
This commit is contained in:
Arturo Mejia 2023-02-14 10:09:21 -05:00 committed by mergify[bot]
parent c6b3ca1fea
commit e28eafe9ad
6 changed files with 46 additions and 23 deletions

View File

@ -132,6 +132,7 @@ import org.mozilla.fenix.settings.TrackingProtectionFragmentDirections
import org.mozilla.fenix.settings.about.AboutFragmentDirections
import org.mozilla.fenix.settings.logins.fragment.LoginDetailFragmentDirections
import org.mozilla.fenix.settings.logins.fragment.SavedLoginsAuthFragmentDirections
import org.mozilla.fenix.settings.quicksettings.protections.cookiebanners.dialog.CookieBannerReEngagementDialogUtils
import org.mozilla.fenix.settings.search.AddSearchEngineFragmentDirections
import org.mozilla.fenix.settings.search.EditCustomSearchEngineFragmentDirections
import org.mozilla.fenix.settings.studies.StudiesFragmentDirections
@ -445,6 +446,10 @@ open class HomeActivity : LocaleAwareAppCompatActivity(), NavHostActivity {
// and the user changes the system language
// More details here: https://github.com/mozilla-mobile/fenix/pull/27793#discussion_r1029892536
components.core.store.dispatch(SearchAction.RefreshSearchEnginesAction)
CookieBannerReEngagementDialogUtils.tryToEnableDetectOnlyModeIfNeeded(
components.settings,
components.core.engine.settings,
)
}
override fun onStart() {

View File

@ -140,7 +140,7 @@ class Core(
cookieBannerHandlingModePrivateBrowsing = context.settings().getCookieBannerHandling(),
cookieBannerHandlingMode = context.settings().getCookieBannerHandling(),
cookieBannerHandlingDetectOnlyMode = context.settings()
.shouldEnabledCookieBannerDetectOnlyMode(),
.shouldShowCookieBannerReEngagementDialog(),
)
GeckoEngine(

View File

@ -53,7 +53,7 @@ class CookieBannersFragment : PreferenceFragmentCompat() {
getEngineSettings().cookieBannerHandlingModePrivateBrowsing = mode
getEngineSettings().cookieBannerHandlingMode = mode
getEngineSettings().cookieBannerHandlingDetectOnlyMode =
requireContext().settings().shouldEnabledCookieBannerDetectOnlyMode()
requireContext().settings().shouldShowCookieBannerReEngagementDialog()
CookieBanners.settingChanged.record(CookieBanners.SettingChangedExtra(metricTag))
requireContext().components.useCases.sessionUseCases.reload()
return super.onPreferenceChange(preference, newValue)

View File

@ -62,13 +62,12 @@ class CookieBannerReEngagementDialog : DialogFragment() {
dismiss()
},
onNotNowButtonClicked = {
disabledCookieBannerHandlingDetectOnlyMode()
CookieBanners.notNowReEngagementDialog.record(NoExtras())
dismiss()
},
onCloseButtonClicked = {
getEngineSettings().cookieBannerHandlingDetectOnlyMode = false
getEngineSettings().cookieBannerHandlingModePrivateBrowsing = DISABLED
getEngineSettings().cookieBannerHandlingMode = DISABLED
disabledCookieBannerHandlingDetectOnlyMode()
requireContext().settings().userOptOutOfReEngageCookieBannerDialog = true
CookieBanners.optOutReEngagementDialog.record(NoExtras())
dismiss()
@ -78,6 +77,12 @@ class CookieBannerReEngagementDialog : DialogFragment() {
}
}
private fun disabledCookieBannerHandlingDetectOnlyMode() {
getEngineSettings().cookieBannerHandlingDetectOnlyMode = false
getEngineSettings().cookieBannerHandlingModePrivateBrowsing = DISABLED
getEngineSettings().cookieBannerHandlingMode = DISABLED
}
private fun getEngineSettings(): Settings {
return requireContext().components.core.engine.settings
}

View File

@ -6,6 +6,7 @@ package org.mozilla.fenix.settings.quicksettings.protections.cookiebanners.dialo
import android.content.Context
import androidx.navigation.NavController
import mozilla.components.concept.engine.EngineSession.CookieBannerHandlingMode.REJECT_ALL
import mozilla.components.concept.engine.EngineSession.CookieBannerHandlingStatus
import org.mozilla.fenix.R
import org.mozilla.fenix.browser.BrowserFragmentDirections
@ -13,6 +14,7 @@ import org.mozilla.fenix.ext.nav
import org.mozilla.fenix.nimbus.CookieBannersSection
import org.mozilla.fenix.nimbus.FxNimbus
import org.mozilla.fenix.utils.Settings
import mozilla.components.concept.engine.Settings as EngineSettings
private const val CONTROL_VARIANT = 0
private const val VARIANT_ONE = 1
@ -87,8 +89,13 @@ object CookieBannerReEngagementDialogUtils {
status: CookieBannerHandlingStatus,
navController: NavController,
) {
if (status == CookieBannerHandlingStatus.DETECTED &&
settings.shouldCookieBannerReEngagementDialog()
val tcpCFRAlreadyShown = if (settings.enabledTotalCookieProtectionCFR) {
!settings.shouldShowTotalCookieProtectionCFR
} else {
true
}
if (tcpCFRAlreadyShown && status == CookieBannerHandlingStatus.DETECTED &&
settings.shouldShowCookieBannerReEngagementDialog()
) {
settings.lastInteractionWithReEngageCookieBannerDialogInMs = System.currentTimeMillis()
settings.cookieBannerDetectedPreviously = true
@ -98,6 +105,21 @@ object CookieBannerReEngagementDialogUtils {
}
}
/**
* Tries to enable the detect only mode after the time limit for the cookie banner has been
* expired.
*/
fun tryToEnableDetectOnlyModeIfNeeded(
settings: Settings,
engineSettings: EngineSettings,
) {
if (settings.shouldShowCookieBannerReEngagementDialog()) {
engineSettings.cookieBannerHandlingDetectOnlyMode = true
engineSettings.cookieBannerHandlingModePrivateBrowsing = REJECT_ALL
engineSettings.cookieBannerHandlingMode = REJECT_ALL
}
}
/**
* Data class for cookie banner dialog variant
* @property title of the dialog

View File

@ -586,10 +586,10 @@ class Settings(private val appContext: Context) : PreferencesHolder {
* Indicates if we should should show the cookie banner dialog that invites the user to turn-on
* the setting.
*/
fun shouldCookieBannerReEngagementDialog(): Boolean {
fun shouldShowCookieBannerReEngagementDialog(): Boolean {
val shouldShowDialog =
shouldShowCookieBannerUI && !userOptOutOfReEngageCookieBannerDialog && !shouldUseCookieBanner
return if (!shouldShowTotalCookieProtectionCFR && shouldShowDialog) {
return if (shouldShowDialog) {
!cookieBannerDetectedPreviously ||
timeNowInMillis() - lastInteractionWithReEngageCookieBannerDialogInMs >= timerForCookieBannerDialog
} else {
@ -704,7 +704,10 @@ class Settings(private val appContext: Context) : PreferencesHolder {
val enabledTotalCookieProtection: Boolean
get() = Config.channel.isNightlyOrDebug || mr2022Sections[Mr2022Section.TCP_FEATURE] == true
private val enabledTotalCookieProtectionCFR: Boolean
/**
* Indicates if the total cookie protection CRF feature is enabled.
*/
val enabledTotalCookieProtectionCFR: Boolean
get() = Config.channel.isNightlyOrDebug || mr2022Sections[Mr2022Section.TCP_CFR] == true
/**
@ -1557,7 +1560,7 @@ class Settings(private val appContext: Context) : PreferencesHolder {
fun getCookieBannerHandling(): CookieBannerHandlingMode {
return when (shouldUseCookieBanner) {
true -> CookieBannerHandlingMode.REJECT_ALL
false -> if (shouldEnabledCookieBannerDetectOnlyMode()) {
false -> if (shouldShowCookieBannerReEngagementDialog()) {
CookieBannerHandlingMode.REJECT_ALL
} else {
CookieBannerHandlingMode.DISABLED
@ -1565,18 +1568,6 @@ class Settings(private val appContext: Context) : PreferencesHolder {
}
}
/**
* Indicates if the cookie banner detect only mode should be enabled.
*/
fun shouldEnabledCookieBannerDetectOnlyMode(): Boolean {
val tcpCFRAlreadyShown = if (enabledTotalCookieProtectionCFR) {
!userOptOutOfReEngageCookieBannerDialog
} else {
true
}
return shouldShowCookieBannerUI && tcpCFRAlreadyShown && !shouldUseCookieBanner
}
var setAsDefaultGrowthSent by booleanPreference(
key = appContext.getPreferenceKey(R.string.pref_key_growth_set_as_default),
default = false,