Bug 1818056 - Delay TCP CFR until dismissing the cookie banner re-engagement dialog

(cherry picked from commit 57cc7b0eaa2cd733b8dff74d4e71837416d26229)
pull/600/head
Arturo Mejia 1 year ago committed by mergify[bot]
parent 52f18956c1
commit 6cecf5acf1

@ -29,6 +29,7 @@ class ContextualHintsTest {
isTCPCFREnabled = true, isTCPCFREnabled = true,
isPocketEnabled = false, isPocketEnabled = false,
isRecentlyVisitedFeatureEnabled = false, isRecentlyVisitedFeatureEnabled = false,
isCookieBannerReductionDialogEnabled = false,
) )
@Before @Before

@ -12,14 +12,12 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.text.style.TextDecoration import androidx.compose.ui.text.style.TextDecoration
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import androidx.core.content.ContextCompat.getColor import androidx.core.content.ContextCompat.getColor
import androidx.navigation.findNavController
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.cancel import kotlinx.coroutines.cancel
import kotlinx.coroutines.flow.filter import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.flow.mapNotNull import kotlinx.coroutines.flow.mapNotNull
import kotlinx.coroutines.flow.transformWhile import kotlinx.coroutines.flow.transformWhile
import mozilla.components.browser.state.selector.findCustomTabOrSelectedTab import mozilla.components.browser.state.selector.findCustomTabOrSelectedTab
import mozilla.components.browser.state.selector.selectedTab
import mozilla.components.browser.state.store.BrowserStore import mozilla.components.browser.state.store.BrowserStore
import mozilla.components.browser.toolbar.BrowserToolbar import mozilla.components.browser.toolbar.BrowserToolbar
import mozilla.components.compose.cfr.CFRPopup import mozilla.components.compose.cfr.CFRPopup
@ -32,7 +30,6 @@ import org.mozilla.fenix.R
import org.mozilla.fenix.ext.components import org.mozilla.fenix.ext.components
import org.mozilla.fenix.settings.SupportUtils import org.mozilla.fenix.settings.SupportUtils
import org.mozilla.fenix.settings.SupportUtils.SumoTopic.TOTAL_COOKIE_PROTECTION import org.mozilla.fenix.settings.SupportUtils.SumoTopic.TOTAL_COOKIE_PROTECTION
import org.mozilla.fenix.settings.quicksettings.protections.cookiebanners.dialog.CookieBannerReEngagementDialogUtils
import org.mozilla.fenix.theme.FirefoxTheme import org.mozilla.fenix.theme.FirefoxTheme
import org.mozilla.fenix.utils.Settings import org.mozilla.fenix.utils.Settings
@ -41,6 +38,11 @@ import org.mozilla.fenix.utils.Settings
*/ */
private const val CFR_TO_ANCHOR_VERTICAL_PADDING = -6 private const val CFR_TO_ANCHOR_VERTICAL_PADDING = -6
/**
* The minimum number of opened tabs to show the CFR.
*/
private const val CRF_MINIMUM_NUMBER_OPENED_TABS = 5
/** /**
* Delegate for handling all the business logic for showing CFRs in the toolbar. * Delegate for handling all the business logic for showing CFRs in the toolbar.
* *
@ -68,7 +70,7 @@ class BrowserToolbarCFRPresenter(
*/ */
@Suppress("MagicNumber") @Suppress("MagicNumber")
fun start() { fun start() {
if (settings.shouldShowTotalCookieProtectionCFR) { if (shouldShowCFR()) {
tcpCfrScope = browserStore.flowScoped { flow -> tcpCfrScope = browserStore.flowScoped { flow ->
flow flow
.mapNotNull { it.findCustomTabOrSelectedTab(sessionId)?.content?.progress } .mapNotNull { it.findCustomTabOrSelectedTab(sessionId)?.content?.progress }
@ -86,6 +88,13 @@ class BrowserToolbarCFRPresenter(
} }
} }
private fun shouldShowCFR(): Boolean {
return settings.shouldShowTotalCookieProtectionCFR && (
!settings.shouldShowCookieBannerReEngagementDialog() ||
settings.openTabsCount >= CRF_MINIMUM_NUMBER_OPENED_TABS
)
}
/** /**
* Stop listening for [browserStore] updates. * Stop listening for [browserStore] updates.
* CFRs already shown are not automatically dismissed. * CFRs already shown are not automatically dismissed.
@ -119,7 +128,6 @@ class BrowserToolbarCFRPresenter(
true -> TrackingProtection.tcpCfrExplicitDismissal.record(NoExtras()) true -> TrackingProtection.tcpCfrExplicitDismissal.record(NoExtras())
false -> TrackingProtection.tcpCfrImplicitDismissal.record(NoExtras()) false -> TrackingProtection.tcpCfrImplicitDismissal.record(NoExtras())
} }
tryToShowCookieBannerDialogIfNeeded()
}, },
text = { text = {
FirefoxTheme { FirefoxTheme {
@ -158,15 +166,4 @@ class BrowserToolbarCFRPresenter(
TrackingProtection.tcpCfrShown.record(NoExtras()) TrackingProtection.tcpCfrShown.record(NoExtras())
} }
} }
@VisibleForTesting
internal fun tryToShowCookieBannerDialogIfNeeded() {
browserStore.state.selectedTab?.let { tab ->
CookieBannerReEngagementDialogUtils.tryToShowReEngagementDialog(
settings = settings,
status = tab.cookieBanner,
navController = toolbar.findNavController(),
)
}
}
} }

@ -89,12 +89,7 @@ object CookieBannerReEngagementDialogUtils {
status: CookieBannerHandlingStatus, status: CookieBannerHandlingStatus,
navController: NavController, navController: NavController,
) { ) {
val tcpCFRAlreadyShown = if (settings.enabledTotalCookieProtectionCFR) { if (status == CookieBannerHandlingStatus.DETECTED &&
!settings.shouldShowTotalCookieProtectionCFR
} else {
true
}
if (tcpCFRAlreadyShown && status == CookieBannerHandlingStatus.DETECTED &&
settings.shouldShowCookieBannerReEngagementDialog() settings.shouldShowCookieBannerReEngagementDialog()
) { ) {
settings.lastInteractionWithReEngageCookieBannerDialogInMs = System.currentTimeMillis() settings.lastInteractionWithReEngageCookieBannerDialogInMs = System.currentTimeMillis()

@ -138,6 +138,7 @@ class BrowserToolbarCFRPresenterTest {
val presenter = createPresenter( val presenter = createPresenter(
settings = mockk { settings = mockk {
every { shouldShowTotalCookieProtectionCFR } returns false every { shouldShowTotalCookieProtectionCFR } returns false
every { shouldShowCookieBannerReEngagementDialog() } returns false
}, },
) )
@ -193,7 +194,10 @@ class BrowserToolbarCFRPresenterTest {
context: Context = mockk(), context: Context = mockk(),
anchor: View = mockk(), anchor: View = mockk(),
browserStore: BrowserStore = mockk(), browserStore: BrowserStore = mockk(),
settings: Settings = mockk { every { shouldShowTotalCookieProtectionCFR } returns true }, settings: Settings = mockk {
every { shouldShowTotalCookieProtectionCFR } returns true
every { shouldShowCookieBannerReEngagementDialog() } returns false
},
toolbar: BrowserToolbar = mockk(), toolbar: BrowserToolbar = mockk(),
sessionId: String? = null, sessionId: String? = null,
) = spyk(createPresenter(context, anchor, browserStore, settings, toolbar, sessionId)) { ) = spyk(createPresenter(context, anchor, browserStore, settings, toolbar, sessionId)) {
@ -211,7 +215,10 @@ class BrowserToolbarCFRPresenterTest {
}, },
anchor: View = mockk(), anchor: View = mockk(),
browserStore: BrowserStore = mockk(), browserStore: BrowserStore = mockk(),
settings: Settings = mockk(relaxed = true) { every { shouldShowTotalCookieProtectionCFR } returns true }, settings: Settings = mockk(relaxed = true) {
every { shouldShowTotalCookieProtectionCFR } returns true
every { shouldShowCookieBannerReEngagementDialog() } returns false
},
toolbar: BrowserToolbar = mockk { toolbar: BrowserToolbar = mockk {
every { findViewById<View>(R.id.mozac_browser_toolbar_security_indicator) } returns anchor every { findViewById<View>(R.id.mozac_browser_toolbar_security_indicator) } returns anchor
}, },

Loading…
Cancel
Save