2
0
mirror of https://github.com/fork-maintainers/iceraven-browser synced 2024-11-19 09:25:34 +00:00

[fenix] Use UpdateTrackingProtectionUseCase

https://github.com/mozilla-mobile/android-components/issues/2746
This commit is contained in:
Tiger Oakes 2019-05-17 09:45:43 -04:00 committed by Jeff Boek
parent 56a8f91a34
commit 20619bce23
4 changed files with 15 additions and 16 deletions

View File

@ -16,7 +16,7 @@ class Components(private val context: Context) {
val services by lazy { Services(backgroundServices.accountManager, useCases.tabsUseCases) }
val core by lazy { Core(context) }
val search by lazy { Search(context) }
val useCases by lazy { UseCases(context, core.sessionManager, search.searchEngineManager) }
val useCases by lazy { UseCases(context, core.sessionManager, core.engine.settings, search.searchEngineManager) }
val utils by lazy { Utilities(context, core.sessionManager, useCases.sessionUseCases, useCases.searchUseCases) }
val analytics by lazy { Analytics(context) }
}

View File

@ -7,8 +7,10 @@ package org.mozilla.fenix.components
import android.content.Context
import mozilla.components.browser.search.SearchEngineManager
import mozilla.components.browser.session.SessionManager
import mozilla.components.concept.engine.Settings
import mozilla.components.feature.search.SearchUseCases
import mozilla.components.feature.session.SessionUseCases
import mozilla.components.feature.session.SettingsUseCases
import mozilla.components.feature.tabs.TabsUseCases
import org.mozilla.fenix.test.Mockable
@ -20,6 +22,7 @@ import org.mozilla.fenix.test.Mockable
class UseCases(
private val context: Context,
private val sessionManager: SessionManager,
private val engineSettings: Settings,
private val searchEngineManager: SearchEngineManager
) {
/**
@ -36,4 +39,9 @@ class UseCases(
* Use cases that provide search engine integration.
*/
val searchUseCases by lazy { SearchUseCases(context, searchEngineManager, sessionManager) }
/**
* Use cases that provide settings management.
*/
val settingsUseCases by lazy { SettingsUseCases(engineSettings, sessionManager) }
}

View File

@ -12,7 +12,6 @@ import androidx.preference.PreferenceFragmentCompat
import androidx.preference.SwitchPreference
import org.mozilla.fenix.R
import org.mozilla.fenix.exceptions.ExceptionDomains
import org.mozilla.fenix.ext.components
import org.mozilla.fenix.ext.getPreferenceKey
import org.mozilla.fenix.ext.requireComponents
import org.mozilla.fenix.utils.Settings
@ -33,20 +32,12 @@ class TrackingProtectionFragment : PreferenceFragmentCompat() {
val preferenceTP = findPreference<SwitchPreference>(trackingProtectionKey)
preferenceTP?.onPreferenceChangeListener =
Preference.OnPreferenceChangeListener { _, newValue ->
Settings.getInstance(context!!).setTrackingProtection(newValue = newValue as Boolean)
with(requireComponents.core) {
val policy =
createTrackingProtectionPolicy(newValue)
engine.settings.trackingProtectionPolicy = policy
with(sessionManager) {
sessions.forEach {
if (newValue)
getEngineSession(it)?.enableTrackingProtection(policy) else
getEngineSession(it)?.disableTrackingProtection()
Settings.getInstance(requireContext()).setTrackingProtection(newValue = newValue as Boolean)
with(requireComponents) {
val policy = core.createTrackingProtectionPolicy(newValue)
useCases.settingsUseCases.updateTrackingProtection.invoke(policy)
useCases.sessionUseCases.reload.invoke()
}
}
}
requireContext().components.useCases.sessionUseCases.reload.invoke()
true
}

View File

@ -10,7 +10,7 @@ class TestComponents(private val context: Context) : Components(context) {
override val services by lazy { Services(backgroundServices.accountManager, useCases.tabsUseCases) }
override val core by lazy { TestCore(context) }
override val search by lazy { Search(context) }
override val useCases by lazy { UseCases(context, core.sessionManager, search.searchEngineManager) }
override val useCases by lazy { UseCases(context, core.sessionManager, core.engine.settings, search.searchEngineManager) }
override val utils by lazy {
Utilities(
context,