mirror of
https://github.com/fork-maintainers/iceraven-browser
synced 2024-11-03 23:15:31 +00:00
Bug 1825008 - Create a storage for submitted cookie banner site reports.
This commit is contained in:
parent
88214343c1
commit
01cce97266
@ -610,6 +610,7 @@ dependencies {
|
||||
implementation FenixDependencies.androidx_transition
|
||||
implementation FenixDependencies.androidx_work_ktx
|
||||
implementation FenixDependencies.androidx_datastore
|
||||
implementation FenixDependencies.androidx_data_store_preferences
|
||||
implementation FenixDependencies.protobuf_javalite
|
||||
implementation FenixDependencies.google_material
|
||||
|
||||
|
@ -11,10 +11,12 @@ import android.os.StrictMode
|
||||
import androidx.appcompat.content.res.AppCompatResources.getDrawable
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.graphics.drawable.toBitmap
|
||||
import androidx.datastore.preferences.preferencesDataStore
|
||||
import mozilla.components.browser.domains.autocomplete.BaseDomainAutocompleteProvider
|
||||
import mozilla.components.browser.domains.autocomplete.ShippedDomainsProvider
|
||||
import mozilla.components.browser.engine.gecko.GeckoEngine
|
||||
import mozilla.components.browser.engine.gecko.cookiebanners.GeckoCookieBannersStorage
|
||||
import mozilla.components.browser.engine.gecko.cookiebanners.ReportSiteDomainsRepository
|
||||
import mozilla.components.browser.engine.gecko.fetch.GeckoViewFetchClient
|
||||
import mozilla.components.browser.engine.gecko.permission.GeckoSitePermissionsStorage
|
||||
import mozilla.components.browser.icons.BrowserIcons
|
||||
@ -190,7 +192,16 @@ class Core(
|
||||
)
|
||||
}
|
||||
|
||||
val cookieBannersStorage by lazyMonitored { GeckoCookieBannersStorage(geckoRuntime) }
|
||||
private val Context.dataStore by preferencesDataStore(
|
||||
name = ReportSiteDomainsRepository.REPORT_SITE_DOMAINS_REPOSITORY_NAME,
|
||||
)
|
||||
|
||||
val cookieBannersStorage by lazyMonitored {
|
||||
GeckoCookieBannersStorage(
|
||||
geckoRuntime,
|
||||
ReportSiteDomainsRepository(context.dataStore),
|
||||
)
|
||||
}
|
||||
|
||||
val geckoSitePermissionsStorage by lazyMonitored {
|
||||
GeckoSitePermissionsStorage(geckoRuntime, OnDiskSitePermissionsStorage(context))
|
||||
|
@ -168,6 +168,9 @@ class DefaultCookieBannerDetailsController(
|
||||
FenixSnackbar.LENGTH_LONG,
|
||||
)
|
||||
}
|
||||
withContext(Dispatchers.IO) {
|
||||
cookieBannersStorage.saveSiteDomain(domain)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,10 +5,12 @@
|
||||
package org.mozilla.fenix.settings.quicksettings.protections.cookiebanners
|
||||
|
||||
import android.content.Context
|
||||
import androidx.core.net.toUri
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.withContext
|
||||
import mozilla.components.browser.state.state.SessionState
|
||||
import mozilla.components.concept.engine.cookiehandling.CookieBannersStorage
|
||||
import org.mozilla.fenix.ext.components
|
||||
import org.mozilla.fenix.ext.settings
|
||||
import org.mozilla.fenix.trackingprotection.CookieBannerUIMode
|
||||
import kotlin.coroutines.resume
|
||||
@ -22,9 +24,20 @@ suspend fun CookieBannersStorage.getCookieBannerUIMode(
|
||||
tab: SessionState,
|
||||
): CookieBannerUIMode {
|
||||
return if (context.settings().shouldUseCookieBanner) {
|
||||
val isSiteDomainReported = withContext(Dispatchers.IO) {
|
||||
val host = tab.content.url.toUri().host.orEmpty()
|
||||
val siteDomain = context.components.publicSuffixList.getPublicSuffixPlusOne(host).await()
|
||||
siteDomain?.let { isSiteDomainReported(it) }
|
||||
}
|
||||
|
||||
if (isSiteDomainReported == true) {
|
||||
return CookieBannerUIMode.REQUEST_UNSUPPORTED_SITE_SUBMITTED
|
||||
}
|
||||
|
||||
val hasException = withContext(Dispatchers.IO) {
|
||||
hasException(tab.content.url, tab.content.private)
|
||||
}
|
||||
|
||||
if (hasException) {
|
||||
CookieBannerUIMode.DISABLE
|
||||
} else {
|
||||
|
@ -234,7 +234,7 @@ internal class DefaultCookieBannerDetailsControllerTest {
|
||||
),
|
||||
)
|
||||
every { testContext.components.core.store } returns store
|
||||
coEvery { controller.getTabDomain(any()) } returns "https://www.amazon.de"
|
||||
coEvery { controller.getTabDomain(any()) } returns "mozilla.org"
|
||||
every { protectionsStore.dispatch(any()) } returns mockk()
|
||||
|
||||
controller.handleRequestSiteSupportPressed()
|
||||
@ -242,13 +242,13 @@ internal class DefaultCookieBannerDetailsControllerTest {
|
||||
assertNotNull(CookieBanners.reportDomainSiteButton.testGetValue())
|
||||
Pings.cookieBannerReportSite.testBeforeNextSubmit {
|
||||
assertNotNull(CookieBanners.reportSiteDomain.testGetValue())
|
||||
assertEquals("https://www.amazon.de", CookieBanners.reportSiteDomain.testGetValue())
|
||||
assertEquals("mozilla.org", CookieBanners.reportSiteDomain.testGetValue())
|
||||
}
|
||||
advanceUntilIdle()
|
||||
coVerifyOrder {
|
||||
protectionsStore.dispatch(
|
||||
ProtectionsAction.RequestReportSiteDomain(
|
||||
"https://www.amazon.de",
|
||||
"mozilla.org",
|
||||
),
|
||||
)
|
||||
protectionsStore.dispatch(
|
||||
@ -256,6 +256,7 @@ internal class DefaultCookieBannerDetailsControllerTest {
|
||||
cookieBannerUIMode = CookieBannerUIMode.REQUEST_UNSUPPORTED_SITE_SUBMITTED,
|
||||
),
|
||||
)
|
||||
cookieBannersStorage.saveSiteDomain("mozilla.org")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -40,6 +40,7 @@ object FenixVersions {
|
||||
const val androidx_transition = "1.4.0"
|
||||
const val androidx_work = "2.7.1"
|
||||
const val androidx_datastore = "1.0.0"
|
||||
const val androidx_datastore_preferences = "1.0.0"
|
||||
const val google_material = "1.2.1"
|
||||
const val google_accompanist = "0.28.0"
|
||||
|
||||
@ -110,6 +111,8 @@ object FenixDependencies {
|
||||
const val androidx_work_ktx = "androidx.work:work-runtime-ktx:${FenixVersions.androidx_work}"
|
||||
const val androidx_work_testing = "androidx.work:work-testing:${FenixVersions.androidx_work}"
|
||||
const val androidx_datastore = "androidx.datastore:datastore:${FenixVersions.androidx_datastore}"
|
||||
const val androidx_data_store_preferences = "androidx.datastore:datastore-preferences:${FenixVersions.androidx_datastore_preferences}"
|
||||
|
||||
const val google_material = "com.google.android.material:material:${FenixVersions.google_material}"
|
||||
const val google_accompanist_drawablepainter = "com.google.accompanist:accompanist-drawablepainter:${FenixVersions.google_accompanist}"
|
||||
const val google_accompanist_pager = "com.google.accompanist:accompanist-pager:${FenixVersions.google_accompanist}"
|
||||
|
Loading…
Reference in New Issue
Block a user