Skip to content
This repository has been archived by the owner on Feb 20, 2023. It is now read-only.

Commit

Permalink
Merge branch 'main' into import-l10n
Browse files Browse the repository at this point in the history
  • Loading branch information
mergify[bot] authored Jan 6, 2023
2 parents 6cdf7fb + 804d286 commit 2490e8c
Show file tree
Hide file tree
Showing 41 changed files with 664 additions and 118 deletions.
66 changes: 66 additions & 0 deletions app/metrics.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6932,6 +6932,72 @@ cookie_banners:
metadata:
tags:
- Privacy&Security
visited_re_engagement_dialog:
type: event
description: An user visited the cookie banner re-engagement dialog
bugs:
- https://bugzilla.mozilla.org/show_bug.cgi?id=1797593
data_reviews:
- https://github.com/mozilla-mobile/fenix/pull/28405#issuecomment-1372489596
data_sensitivity:
- interaction
notification_emails:
- [email protected]
expires: 118
metadata:
tags:
- Privacy&Security
opt_out_re_engagement_dialog:
type: event
description: |
An user opt out the cookie banner re-engagement
dialog by clicking the X button
bugs:
- https://bugzilla.mozilla.org/show_bug.cgi?id=1797593
data_reviews:
- https://github.com/mozilla-mobile/fenix/pull/28405#issuecomment-1372489596
data_sensitivity:
- interaction
notification_emails:
- [email protected]
expires: 118
metadata:
tags:
- Privacy&Security
not_now_re_engagement_dialog:
type: event
description: |
An user clicked the not now button on
the cookie banner re-engagement dialog
bugs:
- https://bugzilla.mozilla.org/show_bug.cgi?id=1797593
data_reviews:
- https://github.com/mozilla-mobile/fenix/pull/28405#issuecomment-1372489596
data_sensitivity:
- interaction
notification_emails:
- [email protected]
expires: 118
metadata:
tags:
- Privacy&Security
allow_re_engagement_dialog:
type: event
description: |
An user clicked the dismiss banner button
on the cookie banner re-engagement dialog
bugs:
- https://bugzilla.mozilla.org/show_bug.cgi?id=1797593
data_reviews:
- https://github.com/mozilla-mobile/fenix/pull/28405#issuecomment-1372489596
data_sensitivity:
- interaction
notification_emails:
- [email protected]
expires: 118
metadata:
tags:
- Privacy&Security
site_permissions:
prompt_shown:
type: event
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import org.junit.Rule
import org.junit.Test
import org.mozilla.fenix.R
import org.mozilla.fenix.customannotations.SmokeTest
import org.mozilla.fenix.ext.settings
import org.mozilla.fenix.helpers.AndroidAssetDispatcher
import org.mozilla.fenix.helpers.HomeActivityIntentTestRule
import org.mozilla.fenix.helpers.TestAssetHelper
Expand Down Expand Up @@ -53,6 +54,7 @@ class SettingsPrivacyTest {
@Before
fun setUp() {
mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
appContext.settings().userOptOutOfReEngageCookieBannerDialog = true
mockWebServer = MockWebServer().apply {
dispatcher = AndroidAssetDispatcher()
start()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ import org.junit.Ignore
import org.junit.Rule
import org.junit.Test
import org.mozilla.fenix.customannotations.SmokeTest
import org.mozilla.fenix.ext.settings
import org.mozilla.fenix.helpers.AndroidAssetDispatcher
import org.mozilla.fenix.helpers.Constants.defaultTopSitesList
import org.mozilla.fenix.helpers.HomeActivityIntentTestRule
import org.mozilla.fenix.helpers.TestAssetHelper
import org.mozilla.fenix.helpers.TestHelper
import org.mozilla.fenix.helpers.TestHelper.exitMenu
import org.mozilla.fenix.helpers.TestHelper.getSponsoredShortcutTitle
import org.mozilla.fenix.ui.robots.homeScreen
Expand All @@ -37,6 +39,7 @@ class SponsoredShortcutsTest {

@Before
fun setUp() {
TestHelper.appContext.settings().userOptOutOfReEngageCookieBannerDialog = true
mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
mockWebServer = MockWebServer().apply {
dispatcher = AndroidAssetDispatcher()
Expand Down
44 changes: 38 additions & 6 deletions app/src/main/java/org/mozilla/fenix/browser/BrowserFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,14 @@ import androidx.lifecycle.lifecycleScope
import androidx.navigation.fragment.findNavController
import com.google.android.material.snackbar.Snackbar
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.mapNotNull
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import mozilla.components.browser.state.selector.findCustomTabOrSelectedTab
import mozilla.components.browser.state.selector.findTab
import mozilla.components.browser.state.state.SessionState
import mozilla.components.browser.state.state.TabSessionState
import mozilla.components.browser.state.store.BrowserStore
import mozilla.components.browser.thumbnails.BrowserThumbnails
import mozilla.components.browser.toolbar.BrowserToolbar
import mozilla.components.concept.engine.permission.SitePermissions
Expand All @@ -28,9 +31,11 @@ import mozilla.components.feature.contextmenu.ContextMenuCandidate
import mozilla.components.feature.readerview.ReaderViewFeature
import mozilla.components.feature.tab.collections.TabCollection
import mozilla.components.feature.tabs.WindowFeature
import mozilla.components.lib.state.ext.consumeFlow
import mozilla.components.service.glean.private.NoExtras
import mozilla.components.support.base.feature.UserInteractionHandler
import mozilla.components.support.base.feature.ViewBoundFeatureWrapper
import mozilla.components.support.ktx.kotlinx.coroutines.flow.ifAnyChanged
import org.mozilla.fenix.GleanMetrics.ReaderMode
import org.mozilla.fenix.R
import org.mozilla.fenix.components.FenixSnackbar
Expand All @@ -43,6 +48,7 @@ import org.mozilla.fenix.ext.requireComponents
import org.mozilla.fenix.ext.runIfFragmentIsAttached
import org.mozilla.fenix.ext.settings
import org.mozilla.fenix.nimbus.FxNimbus
import org.mozilla.fenix.settings.quicksettings.protections.cookiebanners.dialog.CookieBannerReEngagementDialogUtils
import org.mozilla.fenix.shortcut.PwaOnboardingObserver
import org.mozilla.fenix.theme.ThemeManager

Expand Down Expand Up @@ -173,6 +179,9 @@ class BrowserFragment : BaseBrowserFragment(), UserInteractionHandler {
view = view,
)
}
if (!context.settings().shouldUseCookieBanner && !context.settings().userOptOutOfReEngageCookieBannerDialog) {
observeCookieBannerHandlingState(context.components.core.store)
}
}

override fun onUpdateToolbarForConfigurationChange(toolbar: BrowserToolbarView) {
Expand Down Expand Up @@ -370,12 +379,17 @@ class BrowserFragment : BaseBrowserFragment(), UserInteractionHandler {
useCase.containsException(tab.id) { hasTrackingProtectionException ->
lifecycleScope.launch(Dispatchers.Main) {
val cookieBannersStorage = requireComponents.core.cookieBannersStorage
val hasCookieBannerException = withContext(Dispatchers.IO) {
cookieBannersStorage.hasException(
tab.content.url,
tab.content.private,
)
}
val hasCookieBannerException =
if (requireContext().settings().shouldUseCookieBanner) {
withContext(Dispatchers.IO) {
cookieBannersStorage.hasException(
tab.content.url,
tab.content.private,
)
}
} else {
false
}
runIfFragmentIsAttached {
val isTrackingProtectionEnabled =
tab.trackingProtection.enabled && !hasTrackingProtectionException
Expand Down Expand Up @@ -476,4 +490,22 @@ class BrowserFragment : BaseBrowserFragment(), UserInteractionHandler {
internal fun updateLastBrowseActivity() {
requireContext().settings().lastBrowseActivity = System.currentTimeMillis()
}

private fun observeCookieBannerHandlingState(store: BrowserStore) {
consumeFlow(store) { flow ->
flow.mapNotNull { state ->
state.findCustomTabOrSelectedTab(customTabSessionId)
}.ifAnyChanged { tab ->
arrayOf(
tab.cookieBanner,
)
}.collect {
CookieBannerReEngagementDialogUtils.tryToShowReEngagementDialog(
settings = requireContext().settings(),
status = it.cookieBanner,
navController = findNavController(),
)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ import androidx.compose.material.Text
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.style.TextDecoration
import androidx.compose.ui.unit.dp
import androidx.navigation.findNavController
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.cancel
import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.flow.mapNotNull
import kotlinx.coroutines.flow.transformWhile
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.toolbar.BrowserToolbar
import mozilla.components.lib.state.ext.flowScoped
Expand All @@ -29,6 +31,7 @@ import org.mozilla.fenix.compose.cfr.CFRPopupProperties
import org.mozilla.fenix.ext.components
import org.mozilla.fenix.settings.SupportUtils
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.utils.Settings

Expand Down Expand Up @@ -111,6 +114,7 @@ class BrowserToolbarCFRPresenter(
true -> TrackingProtection.tcpCfrExplicitDismissal.record(NoExtras())
false -> TrackingProtection.tcpCfrImplicitDismissal.record(NoExtras())
}
tryToShowCookieBannerDialogIfNeeded()
},
) {
Text(
Expand All @@ -137,4 +141,15 @@ class BrowserToolbarCFRPresenter(
TrackingProtection.tcpCfrShown.record(NoExtras())
}
}

@VisibleForTesting
internal fun tryToShowCookieBannerDialogIfNeeded() {
browserStore.state.selectedTab?.let { tab ->
CookieBannerReEngagementDialogUtils.tryToShowReEngagementDialog(
settings = settings,
status = tab.cookieBanner,
navController = toolbar.findNavController(),
)
}
}
}
9 changes: 3 additions & 6 deletions app/src/main/java/org/mozilla/fenix/compose/Divider.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

package org.mozilla.fenix.compose

import android.content.res.Configuration
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
Expand All @@ -16,8 +15,8 @@ import androidx.compose.foundation.layout.width
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import org.mozilla.fenix.compose.annotation.LightDarkPreview
import org.mozilla.fenix.theme.FirefoxTheme

/**
Expand All @@ -39,8 +38,7 @@ fun Divider(
* An example of a vertical divider.
*/
@Composable
@Preview(uiMode = Configuration.UI_MODE_NIGHT_YES)
@Preview(uiMode = Configuration.UI_MODE_NIGHT_NO)
@LightDarkPreview
private fun VerticalDividerPreview() {
FirefoxTheme {
Box(
Expand Down Expand Up @@ -74,8 +72,7 @@ private fun VerticalDividerPreview() {
* An example of divider usage in a list menu.
*/
@Composable
@Preview(uiMode = Configuration.UI_MODE_NIGHT_YES)
@Preview(uiMode = Configuration.UI_MODE_NIGHT_NO)
@LightDarkPreview
private fun HorizontalDividerPreview() {
FirefoxTheme {
Box(
Expand Down
12 changes: 4 additions & 8 deletions app/src/main/java/org/mozilla/fenix/compose/ListItemTabLarge.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

package org.mozilla.fenix.compose

import android.content.res.Configuration
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
Expand All @@ -22,9 +21,9 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import org.mozilla.fenix.compose.annotation.LightDarkPreview
import org.mozilla.fenix.theme.FirefoxTheme

/**
Expand Down Expand Up @@ -167,8 +166,7 @@ fun ListItemTabSurface(
}

@Composable
@Preview(uiMode = Configuration.UI_MODE_NIGHT_YES)
@Preview(uiMode = Configuration.UI_MODE_NIGHT_NO)
@LightDarkPreview
private fun ListItemTabLargePreview() {
FirefoxTheme {
ListItemTabLarge(
Expand All @@ -180,8 +178,7 @@ private fun ListItemTabLargePreview() {
}

@Composable
@Preview(uiMode = Configuration.UI_MODE_NIGHT_YES)
@Preview(uiMode = Configuration.UI_MODE_NIGHT_NO)
@LightDarkPreview
private fun ListItemTabSurfacePreview() {
FirefoxTheme {
ListItemTabSurface(
Expand All @@ -197,8 +194,7 @@ private fun ListItemTabSurfacePreview() {
}

@Composable
@Preview(uiMode = Configuration.UI_MODE_NIGHT_YES)
@Preview(uiMode = Configuration.UI_MODE_NIGHT_NO)
@LightDarkPreview
private fun ListItemTabSurfaceWithCustomBackgroundPreview() {
FirefoxTheme {
ListItemTabSurface(
Expand Down
12 changes: 4 additions & 8 deletions app/src/main/java/org/mozilla/fenix/compose/MessageCard.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

package org.mozilla.fenix.compose

import android.content.res.Configuration
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
Expand All @@ -26,10 +25,10 @@ import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import org.mozilla.fenix.R
import org.mozilla.fenix.compose.annotation.LightDarkPreview
import org.mozilla.fenix.compose.button.PrimaryButton
import org.mozilla.fenix.theme.FirefoxTheme

Expand Down Expand Up @@ -199,8 +198,7 @@ data class MessageCardColors(
}

@Composable
@Preview(uiMode = Configuration.UI_MODE_NIGHT_YES)
@Preview(uiMode = Configuration.UI_MODE_NIGHT_NO)
@LightDarkPreview
private fun MessageCardPreview() {
FirefoxTheme {
Box(
Expand All @@ -219,8 +217,7 @@ private fun MessageCardPreview() {
}

@Composable
@Preview(uiMode = Configuration.UI_MODE_NIGHT_YES)
@Preview(uiMode = Configuration.UI_MODE_NIGHT_NO)
@LightDarkPreview
private fun MessageCardWithoutTitlePreview() {
FirefoxTheme {
Box(
Expand All @@ -238,8 +235,7 @@ private fun MessageCardWithoutTitlePreview() {
}

@Composable
@Preview(uiMode = Configuration.UI_MODE_NIGHT_YES)
@Preview(uiMode = Configuration.UI_MODE_NIGHT_NO)
@LightDarkPreview
private fun MessageCardWithButtonLabelPreview() {
FirefoxTheme {
Box(
Expand Down
Loading

0 comments on commit 2490e8c

Please sign in to comment.