[fenix] For https://github.com/mozilla-mobile/fenix/issues/1084 - Update TP Policy for the current engineSession

pull/600/head
Emily Kager 6 years ago committed by Emily Kager
parent 58b29982c6
commit a8b73dcb04

@ -135,7 +135,7 @@ class Core(private val context: Context) {
* in private browsing mode, default to the current preference value. * in private browsing mode, default to the current preference value.
* @return the constructed tracking protection policy based on preferences. * @return the constructed tracking protection policy based on preferences.
*/ */
private fun createTrackingProtectionPolicy( fun createTrackingProtectionPolicy(
normalMode: Boolean = Settings.getInstance(context).shouldUseTrackingProtection, normalMode: Boolean = Settings.getInstance(context).shouldUseTrackingProtection,
privateMode: Boolean = true privateMode: Boolean = true
): TrackingProtectionPolicy { ): TrackingProtectionPolicy {
@ -153,11 +153,6 @@ class Core(private val context: Context) {
} }
} }
fun updateTrackingProtection(newValue: Boolean) {
engine.settings.trackingProtectionPolicy =
createTrackingProtectionPolicy(normalMode = newValue)
}
/** /**
* Sets Preferred Color scheme based on Dark/Light Theme Settings or Current Configuration * Sets Preferred Color scheme based on Dark/Light Theme Settings or Current Configuration
*/ */

@ -31,7 +31,15 @@ class TrackingProtectionFragment : PreferenceFragmentCompat() {
val preferenceTP = findPreference<Preference>(trackingProtectionKey) val preferenceTP = findPreference<Preference>(trackingProtectionKey)
preferenceTP?.onPreferenceChangeListener = preferenceTP?.onPreferenceChangeListener =
Preference.OnPreferenceChangeListener { _, newValue -> Preference.OnPreferenceChangeListener { _, newValue ->
requireComponents.core.updateTrackingProtection(newValue as Boolean) with(requireComponents.core) {
val policy =
createTrackingProtectionPolicy(newValue as Boolean)
engine.settings.trackingProtectionPolicy = policy
with(sessionManager) {
sessions.forEach { getEngineSession(it)?.enableTrackingProtection(policy) }
}
}
true true
} }

Loading…
Cancel
Save