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

Commit

Permalink
For #1084 - Update TP Policy for the current engineSession
Browse files Browse the repository at this point in the history
  • Loading branch information
ekager committed Apr 15, 2019
1 parent 658f6dc commit 43e0588
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
7 changes: 1 addition & 6 deletions app/src/main/java/org/mozilla/fenix/components/Core.kt
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ class Core(private val context: Context) {
* in private browsing mode, default to the current preference value.
* @return the constructed tracking protection policy based on preferences.
*/
private fun createTrackingProtectionPolicy(
fun createTrackingProtectionPolicy(
normalMode: Boolean = Settings.getInstance(context).shouldUseTrackingProtection,
privateMode: Boolean = true
): TrackingProtectionPolicy {
Expand All @@ -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
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,15 @@ class TrackingProtectionFragment : PreferenceFragmentCompat() {
val preferenceTP = findPreference<Preference>(trackingProtectionKey)
preferenceTP?.onPreferenceChangeListener =
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
}

Expand Down

0 comments on commit 43e0588

Please sign in to comment.