2
0
mirror of https://github.com/fork-maintainers/iceraven-browser synced 2024-11-03 23:15:31 +00:00

Fix site permissions breaking changes

This commit is contained in:
Arturo Mejia 2021-06-09 15:38:23 -04:00
parent 2339ab664e
commit 2f879f8e9d
25 changed files with 82 additions and 76 deletions

View File

@ -78,7 +78,7 @@ import mozilla.components.feature.session.FullScreenFeature
import mozilla.components.feature.session.PictureInPictureFeature
import mozilla.components.feature.session.SessionFeature
import mozilla.components.feature.session.SwipeRefreshFeature
import mozilla.components.feature.sitepermissions.SitePermissions
import mozilla.components.concept.engine.permission.SitePermissions
import mozilla.components.feature.sitepermissions.SitePermissionsFeature
import mozilla.components.lib.state.ext.consumeFlow
import mozilla.components.lib.state.ext.flowScoped
@ -650,7 +650,7 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Activit
sitePermissionsFeature.set(
feature = SitePermissionsFeature(
context = context,
storage = context.components.core.permissionStorage.permissionsStorage,
storage = context.components.core.geckoSitePermissionsStorage,
fragmentManager = parentFragmentManager,
promptsStyling = SitePermissionsFeature.PromptsStyling(
gravity = getAppropriateLayoutGravity(),

View File

@ -24,7 +24,7 @@ import mozilla.components.browser.toolbar.BrowserToolbar
import mozilla.components.feature.app.links.AppLinksUseCases
import mozilla.components.feature.contextmenu.ContextMenuCandidate
import mozilla.components.feature.readerview.ReaderViewFeature
import mozilla.components.feature.sitepermissions.SitePermissions
import mozilla.components.concept.engine.permission.SitePermissions
import mozilla.components.feature.tab.collections.TabCollection
import mozilla.components.feature.tabs.WindowFeature
import mozilla.components.support.base.feature.UserInteractionHandler

View File

@ -16,7 +16,6 @@ import mozilla.components.feature.addons.migration.SupportedAddonsChecker
import mozilla.components.feature.addons.update.AddonUpdater
import mozilla.components.feature.addons.update.DefaultAddonUpdater
import mozilla.components.feature.autofill.AutofillConfiguration
import mozilla.components.feature.sitepermissions.SitePermissionsStorage
import mozilla.components.lib.publicsuffixlist.PublicSuffixList
import mozilla.components.support.migration.state.MigrationStore
import org.mozilla.fenix.BuildConfig
@ -26,7 +25,6 @@ import org.mozilla.fenix.R
import org.mozilla.fenix.autofill.AutofillConfirmActivity
import org.mozilla.fenix.autofill.AutofillUnlockActivity
import org.mozilla.fenix.components.metrics.AppStartupTelemetry
import org.mozilla.fenix.ext.components
import org.mozilla.fenix.ext.settings
import org.mozilla.fenix.perf.AppStartReasonProvider
import org.mozilla.fenix.perf.StartupActivityLog
@ -143,10 +141,6 @@ class Components(private val context: Context) {
AddonManager(core.store, core.engine, addonCollectionProvider, addonUpdater)
}
val sitePermissionsStorage by lazyMonitored {
SitePermissionsStorage(context, context.components.core.engine)
}
val analytics by lazyMonitored { Analytics(context) }
val publicSuffixList by lazyMonitored { PublicSuffixList(context) }
val clipboardHandler by lazyMonitored { ClipboardHandler(context) }

View File

@ -13,6 +13,7 @@ import androidx.core.content.ContextCompat
import io.sentry.Sentry
import mozilla.components.browser.engine.gecko.GeckoEngine
import mozilla.components.browser.engine.gecko.fetch.GeckoViewFetchClient
import mozilla.components.browser.engine.gecko.permission.GeckoSitePermissionsStorage
import mozilla.components.browser.icons.BrowserIcons
import mozilla.components.browser.state.engine.EngineMiddleware
import mozilla.components.browser.session.storage.SessionStorage
@ -43,6 +44,7 @@ import mozilla.components.feature.search.region.RegionMiddleware
import mozilla.components.feature.session.HistoryDelegate
import mozilla.components.feature.session.middleware.LastAccessMiddleware
import mozilla.components.feature.session.middleware.undo.UndoMiddleware
import mozilla.components.feature.sitepermissions.OnDiskSitePermissionsStorage
import mozilla.components.feature.top.sites.DefaultTopSitesStorage
import mozilla.components.feature.top.sites.PinnedSiteStorage
import mozilla.components.feature.webcompat.WebCompatFeature
@ -77,6 +79,7 @@ import org.mozilla.fenix.settings.advanced.getSelectedLocale
import org.mozilla.fenix.telemetry.TelemetryMiddleware
import org.mozilla.fenix.utils.Mockable
import org.mozilla.fenix.utils.getUndoDelay
import org.mozilla.geckoview.GeckoRuntime
/**
* Component group for all core browser functionality.
@ -116,12 +119,7 @@ class Core(
GeckoEngine(
context,
defaultSettings,
GeckoProvider.getOrCreateRuntime(
context,
lazyAutofillStorage,
lazyPasswordsStorage,
trackingProtectionPolicyFactory.createTrackingProtectionPolicy()
)
geckoRuntime
).also {
WebCompatFeature.install(it)
@ -152,15 +150,23 @@ class Core(
val client: Client by lazyMonitored {
GeckoViewFetchClient(
context,
GeckoProvider.getOrCreateRuntime(
context,
lazyAutofillStorage,
lazyPasswordsStorage,
trackingProtectionPolicyFactory.createTrackingProtectionPolicy()
)
geckoRuntime
)
}
val geckoRuntime: GeckoRuntime by lazyMonitored {
GeckoProvider.getOrCreateRuntime(
context,
lazyAutofillStorage,
lazyPasswordsStorage,
trackingProtectionPolicyFactory.createTrackingProtectionPolicy()
)
}
val geckoSitePermissionsStorage by lazyMonitored {
GeckoSitePermissionsStorage(geckoRuntime, OnDiskSitePermissionsStorage(context))
}
val sessionStorage: SessionStorage by lazyMonitored {
SessionStorage(context, engine = engine)
}

View File

@ -9,8 +9,8 @@ import androidx.annotation.VisibleForTesting
import androidx.paging.DataSource
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import mozilla.components.feature.sitepermissions.SitePermissions
import mozilla.components.feature.sitepermissions.SitePermissionsStorage
import mozilla.components.concept.engine.permission.SitePermissions
import mozilla.components.concept.engine.permission.SitePermissionsStorage
import org.mozilla.fenix.ext.components
import org.mozilla.fenix.utils.Mockable
import kotlin.coroutines.CoroutineContext
@ -20,7 +20,7 @@ class PermissionStorage(
private val context: Context,
@VisibleForTesting internal val dispatcher: CoroutineContext = Dispatchers.IO,
@VisibleForTesting internal val permissionsStorage: SitePermissionsStorage =
context.components.sitePermissionsStorage
context.components.core.geckoSitePermissionsStorage
) {
suspend fun add(sitePermissions: SitePermissions) = withContext(dispatcher) {
@ -35,7 +35,7 @@ class PermissionStorage(
permissionsStorage.update(sitePermissions)
}
fun getSitePermissionsPaged(): DataSource.Factory<Int, SitePermissions> {
suspend fun getSitePermissionsPaged(): DataSource.Factory<Int, SitePermissions> {
return permissionsStorage.getSitePermissionsPaged()
}

View File

@ -23,7 +23,7 @@ import mozilla.components.feature.pwa.feature.ManifestUpdateFeature
import mozilla.components.feature.pwa.feature.WebAppActivityFeature
import mozilla.components.feature.pwa.feature.WebAppHideToolbarFeature
import mozilla.components.feature.pwa.feature.WebAppSiteControlsFeature
import mozilla.components.feature.sitepermissions.SitePermissions
import mozilla.components.concept.engine.permission.SitePermissions
import mozilla.components.support.base.feature.UserInteractionHandler
import mozilla.components.support.base.feature.ViewBoundFeatureWrapper
import mozilla.components.support.ktx.android.arch.lifecycle.addObservers

View File

@ -9,7 +9,7 @@ import androidx.annotation.StringRes
import androidx.appcompat.content.res.AppCompatResources
import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat
import mozilla.components.feature.sitepermissions.SitePermissions
import mozilla.components.concept.engine.permission.SitePermissions
import mozilla.components.support.ktx.android.content.res.resolveAttribute
import mozilla.components.support.ktx.android.view.putCompoundDrawablesRelative
import org.mozilla.fenix.ext.getPreferenceKey

View File

@ -11,7 +11,7 @@ import android.content.Context
import android.os.Parcelable
import androidx.annotation.StringRes
import kotlinx.android.parcel.Parcelize
import mozilla.components.feature.sitepermissions.SitePermissions
import mozilla.components.concept.engine.permission.SitePermissions
import mozilla.components.feature.sitepermissions.SitePermissionsRules
import mozilla.components.support.ktx.android.content.isPermissionGranted
import org.mozilla.fenix.R

View File

@ -13,7 +13,7 @@ import kotlinx.coroutines.launch
import mozilla.components.browser.state.selector.findTabOrCustomTab
import mozilla.components.browser.state.store.BrowserStore
import mozilla.components.feature.session.SessionUseCases.ReloadUrlUseCase
import mozilla.components.feature.sitepermissions.SitePermissions
import mozilla.components.concept.engine.permission.SitePermissions
import mozilla.components.feature.tabs.TabsUseCases.AddNewTabUseCase
import mozilla.components.support.base.feature.OnNeedToRequestPermissions
import org.mozilla.fenix.components.PermissionStorage

View File

@ -8,8 +8,8 @@ import android.content.Context
import androidx.annotation.ColorRes
import androidx.annotation.DrawableRes
import androidx.annotation.StringRes
import mozilla.components.feature.sitepermissions.SitePermissions
import mozilla.components.feature.sitepermissions.SitePermissions.AutoplayStatus
import mozilla.components.concept.engine.permission.SitePermissions
import mozilla.components.concept.engine.permission.SitePermissions.AutoplayStatus
import mozilla.components.feature.sitepermissions.SitePermissionsRules
import mozilla.components.feature.sitepermissions.SitePermissionsRules.AutoplayAction
import mozilla.components.lib.state.State

View File

@ -7,7 +7,7 @@ package org.mozilla.fenix.settings.quicksettings
import android.content.Context
import androidx.annotation.VisibleForTesting
import mozilla.components.browser.state.state.content.PermissionHighlightsState
import mozilla.components.feature.sitepermissions.SitePermissions
import mozilla.components.concept.engine.permission.SitePermissions
import mozilla.components.lib.state.Action
import mozilla.components.lib.state.Reducer
import mozilla.components.lib.state.State

View File

@ -5,7 +5,7 @@
package org.mozilla.fenix.settings.quicksettings.ext
import android.content.Context
import mozilla.components.feature.sitepermissions.SitePermissions
import mozilla.components.concept.engine.permission.SitePermissions
import org.mozilla.fenix.settings.PhoneFeature
import org.mozilla.fenix.utils.Settings

View File

@ -17,7 +17,7 @@ import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.Dispatchers.Main
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import mozilla.components.feature.sitepermissions.SitePermissions
import mozilla.components.concept.engine.permission.SitePermissions
import org.mozilla.fenix.R
import org.mozilla.fenix.ext.components
import org.mozilla.fenix.ext.navigateBlockingForAsyncNavGraph

View File

@ -24,9 +24,11 @@ import androidx.paging.PagedListAdapter
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Dispatchers.Main
import kotlinx.coroutines.launch
import mozilla.components.feature.sitepermissions.SitePermissions
import kotlinx.coroutines.withContext
import mozilla.components.concept.engine.permission.SitePermissions
import org.mozilla.fenix.NavHostActivity
import org.mozilla.fenix.R
import org.mozilla.fenix.ext.components
@ -57,20 +59,24 @@ class SitePermissionsExceptionsFragment :
recyclerView = rootView.findViewById(R.id.exceptions)
recyclerView.layoutManager = LinearLayoutManager(requireContext())
val sitePermissionsPaged = requireContext().components.core.permissionStorage.getSitePermissionsPaged()
viewLifecycleOwner.lifecycleScope.launch(Dispatchers.IO) {
val sitePermissionsPaged = requireContext().components.core.permissionStorage.getSitePermissionsPaged()
val adapter = ExceptionsAdapter(this)
val liveData = LivePagedListBuilder(sitePermissionsPaged, MAX_ITEMS_PER_PAGE).build()
withContext(Main) {
val adapter = ExceptionsAdapter(this@SitePermissionsExceptionsFragment)
val liveData = LivePagedListBuilder(sitePermissionsPaged, MAX_ITEMS_PER_PAGE).build()
liveData.observe(viewLifecycleOwner, Observer<PagedList<SitePermissions>> {
if (it.isEmpty()) {
showEmptyListMessage()
} else {
hideEmptyListMessage()
adapter.submitList(it)
recyclerView.adapter = adapter
liveData.observe(viewLifecycleOwner, Observer<PagedList<SitePermissions>> {
if (it.isEmpty()) {
showEmptyListMessage()
} else {
hideEmptyListMessage()
adapter.submitList(it)
recyclerView.adapter = adapter
}
})
}
})
}
}
private fun hideEmptyListMessage() {

View File

@ -23,9 +23,9 @@ import androidx.lifecycle.lifecycleScope
import androidx.navigation.fragment.navArgs
import kotlinx.coroutines.Dispatchers.Main
import kotlinx.coroutines.launch
import mozilla.components.feature.sitepermissions.SitePermissions
import mozilla.components.feature.sitepermissions.SitePermissions.Status.ALLOWED
import mozilla.components.feature.sitepermissions.SitePermissions.Status.BLOCKED
import mozilla.components.concept.engine.permission.SitePermissions
import mozilla.components.concept.engine.permission.SitePermissions.Status.ALLOWED
import mozilla.components.concept.engine.permission.SitePermissions.Status.BLOCKED
import org.mozilla.fenix.R
import org.mozilla.fenix.ext.requireComponents
import org.mozilla.fenix.ext.settings

View File

@ -754,7 +754,7 @@
app:argType="boolean" />
<argument
android:name="sitePermissions"
app:argType="mozilla.components.feature.sitepermissions.SitePermissions"
app:argType="mozilla.components.concept.engine.permission.SitePermissions"
app:nullable="true" />
<argument
android:name="gravity"
@ -867,7 +867,7 @@
app:argType="org.mozilla.fenix.settings.PhoneFeature" />
<argument
android:name="sitePermissions"
app:argType="mozilla.components.feature.sitepermissions.SitePermissions" />
app:argType="mozilla.components.concept.engine.permission.SitePermissions" />
</fragment>
<fragment
@ -879,7 +879,7 @@
app:popUpTo="@+id/sitePermissionsDetailsExceptionsFragment" />
<argument
android:name="sitePermissions"
app:argType="mozilla.components.feature.sitepermissions.SitePermissions" />
app:argType="mozilla.components.concept.engine.permission.SitePermissions" />
</fragment>
</navigation>

View File

@ -21,7 +21,7 @@ import mozilla.components.browser.state.state.createTab
import mozilla.components.concept.engine.EngineView
import mozilla.components.feature.contextmenu.ContextMenuCandidate
import mozilla.components.feature.session.behavior.EngineViewBrowserToolbarBehavior
import mozilla.components.feature.sitepermissions.SitePermissions
import mozilla.components.concept.engine.permission.SitePermissions
import mozilla.components.support.test.robolectric.testContext
import mozilla.components.ui.widgets.VerticalSwipeRefreshLayout
import org.junit.Before

View File

@ -5,13 +5,13 @@
package org.mozilla.fenix.components
import androidx.paging.DataSource
import io.mockk.every
import io.mockk.coEvery
import io.mockk.coVerify
import io.mockk.mockk
import io.mockk.verify
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.runBlockingTest
import mozilla.components.feature.sitepermissions.SitePermissions
import mozilla.components.feature.sitepermissions.SitePermissionsStorage
import mozilla.components.concept.engine.permission.SitePermissions
import mozilla.components.concept.engine.permission.SitePermissionsStorage
import mozilla.components.support.test.robolectric.testContext
import org.junit.Assert.assertEquals
import org.junit.Test
@ -30,7 +30,7 @@ class PermissionStorageTest {
storage.add(sitePermissions)
verify { sitePermissionsStorage.save(sitePermissions) }
coVerify { sitePermissionsStorage.save(sitePermissions) }
}
@Test
@ -39,11 +39,11 @@ class PermissionStorageTest {
val sitePermissionsStorage: SitePermissionsStorage = mockk(relaxed = true)
val storage = PermissionStorage(testContext, this.coroutineContext, sitePermissionsStorage)
every { sitePermissionsStorage.findSitePermissionsBy(any()) } returns sitePermissions
coEvery { sitePermissionsStorage.findSitePermissionsBy(any()) } returns sitePermissions
val result = storage.findSitePermissionsBy("origin")
verify { sitePermissionsStorage.findSitePermissionsBy("origin") }
coVerify { sitePermissionsStorage.findSitePermissionsBy("origin") }
assertEquals(sitePermissions, result)
}
@ -56,7 +56,7 @@ class PermissionStorageTest {
storage.updateSitePermissions(sitePermissions)
verify { sitePermissionsStorage.update(sitePermissions) }
coVerify { sitePermissionsStorage.update(sitePermissions) }
}
@Test
@ -65,11 +65,11 @@ class PermissionStorageTest {
val sitePermissionsStorage: SitePermissionsStorage = mockk(relaxed = true)
val storage = PermissionStorage(testContext, this.coroutineContext, sitePermissionsStorage)
every { sitePermissionsStorage.getSitePermissionsPaged() } returns dataSource
coEvery { sitePermissionsStorage.getSitePermissionsPaged() } returns dataSource
val result = storage.getSitePermissionsPaged()
verify { sitePermissionsStorage.getSitePermissionsPaged() }
coVerify { sitePermissionsStorage.getSitePermissionsPaged() }
assertEquals(dataSource, result)
}
@ -82,7 +82,7 @@ class PermissionStorageTest {
storage.deleteSitePermissions(sitePermissions)
verify { sitePermissionsStorage.remove(sitePermissions) }
coVerify { sitePermissionsStorage.remove(sitePermissions) }
}
@Test
@ -92,6 +92,6 @@ class PermissionStorageTest {
storage.deleteAllSitePermissions()
verify { sitePermissionsStorage.removeAll() }
coVerify { sitePermissionsStorage.removeAll() }
}
}

View File

@ -8,8 +8,8 @@ import android.Manifest
import io.mockk.MockKAnnotations
import io.mockk.every
import io.mockk.impl.annotations.MockK
import mozilla.components.feature.sitepermissions.SitePermissions
import mozilla.components.feature.sitepermissions.SitePermissions.Status
import mozilla.components.concept.engine.permission.SitePermissions
import mozilla.components.concept.engine.permission.SitePermissions.Status
import mozilla.components.feature.sitepermissions.SitePermissionsRules.Action
import mozilla.components.support.test.robolectric.testContext
import org.junit.Assert.assertEquals

View File

@ -7,8 +7,8 @@ package org.mozilla.fenix.settings.quicksettings
import io.mockk.MockKAnnotations
import io.mockk.every
import io.mockk.impl.annotations.MockK
import mozilla.components.feature.sitepermissions.SitePermissions
import mozilla.components.feature.sitepermissions.SitePermissions.AutoplayStatus
import mozilla.components.concept.engine.permission.SitePermissions
import mozilla.components.concept.engine.permission.SitePermissions.AutoplayStatus
import mozilla.components.feature.sitepermissions.SitePermissionsRules
import mozilla.components.feature.sitepermissions.SitePermissionsRules.AutoplayAction
import mozilla.components.feature.sitepermissions.SitePermissionsRules.Action

View File

@ -23,8 +23,8 @@ import mozilla.components.browser.state.state.TabSessionState
import mozilla.components.browser.state.state.createTab
import mozilla.components.browser.state.store.BrowserStore
import mozilla.components.feature.session.SessionUseCases
import mozilla.components.feature.sitepermissions.SitePermissions
import mozilla.components.feature.sitepermissions.SitePermissions.Status.NO_DECISION
import mozilla.components.concept.engine.permission.SitePermissions
import mozilla.components.concept.engine.permission.SitePermissions.Status.NO_DECISION
import mozilla.components.feature.tabs.TabsUseCases
import mozilla.components.support.test.mock
import mozilla.components.support.test.robolectric.testContext

View File

@ -14,7 +14,7 @@ import io.mockk.verify
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.runBlocking
import mozilla.components.browser.state.state.content.PermissionHighlightsState
import mozilla.components.feature.sitepermissions.SitePermissions
import mozilla.components.concept.engine.permission.SitePermissions
import mozilla.components.feature.sitepermissions.SitePermissionsRules
import mozilla.components.feature.sitepermissions.SitePermissionsRules.AutoplayAction
import mozilla.components.feature.sitepermissions.SitePermissionsRules.Action

View File

@ -8,7 +8,7 @@ import android.content.Context
import android.content.pm.PackageManager
import io.mockk.every
import io.mockk.mockk
import mozilla.components.feature.sitepermissions.SitePermissions
import mozilla.components.concept.engine.permission.SitePermissions
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Test

View File

@ -10,7 +10,7 @@ import io.mockk.every
import io.mockk.impl.annotations.MockK
import io.mockk.spyk
import io.mockk.verify
import mozilla.components.feature.sitepermissions.SitePermissions
import mozilla.components.concept.engine.permission.SitePermissions
import mozilla.components.support.test.robolectric.testContext
import org.junit.Assert.assertEquals
import org.junit.Before

View File

@ -14,8 +14,8 @@ import io.mockk.spyk
import io.mockk.verify
import io.mockk.MockKAnnotations
import io.mockk.impl.annotations.MockK
import mozilla.components.feature.sitepermissions.SitePermissions
import mozilla.components.feature.sitepermissions.SitePermissions.AutoplayStatus
import mozilla.components.concept.engine.permission.SitePermissions
import mozilla.components.concept.engine.permission.SitePermissions.AutoplayStatus
import mozilla.components.feature.sitepermissions.SitePermissionsRules
import mozilla.components.feature.sitepermissions.SitePermissionsRules.AutoplayAction
import mozilla.components.feature.sitepermissions.SitePermissionsRules.Action