<commit_before>/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

package org.mozilla.focus.engine

import android.content.Context
import android.content.SharedPreferences
import org.mozilla.focus.R
import org.mozilla.focus.ext.components
import org.mozilla.focus.utils.Settings

/**
 * SharedPreference listener that will update the engine whenever the user changes settings.
 */
class EngineSharedPreferencesListener(
    private val context: Context
) : SharedPreferences.OnSharedPreferenceChangeListener {
    override fun onSharedPreferenceChanged(preferences: SharedPreferences, key: String) {
        when (key) {
            context.getString(R.string.pref_key_privacy_block_social),
            context.getString(R.string.pref_key_privacy_block_ads),
            context.getString(R.string.pref_key_privacy_block_analytics),
            context.getString(R.string.pref_key_privacy_block_other) ->
                updateTrackingProtectionPolicy()

            context.getString(R.string.pref_key_safe_browsing) ->
                updateSafeBrowsingPolicy()

            context.getString(R.string.pref_key_performance_block_javascript) ->
                updateJavaScriptSetting()

            context.getString(R.string.pref_key_remote_debugging) ->
                updateRemoteDebugging()

            context.getString(R.string.pref_key_performance_block_webfonts) ->
                updateWebFontsBlocking()
        }
    }

    private fun updateTrackingProtectionPolicy() {
        val policy = Settings.getInstance(context).createTrackingProtectionPolicy()
        val components = context.components

        components.engineDefaultSettings.trackingProtectionPolicy = policy
        components.settingsUseCases.updateTrackingProtection(policy)
    }
<commit_msg>For issue #4540: Update tracking protection policy when cookie setting changes<commit_after>/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

package org.mozilla.focus.engine

import android.content.Context
import android.content.SharedPreferences
import org.mozilla.focus.R
import org.mozilla.focus.ext.components
import org.mozilla.focus.utils.Settings

/**
 * SharedPreference listener that will update the engine whenever the user changes settings.
 */
class EngineSharedPreferencesListener(
    private val context: Context
) : SharedPreferences.OnSharedPreferenceChangeListener {
    override fun onSharedPreferenceChanged(preferences: SharedPreferences, key: String) {
        when (key) {
            context.getString(R.string.pref_key_privacy_block_social),
            context.getString(R.string.pref_key_privacy_block_ads),
            context.getString(R.string.pref_key_privacy_block_analytics),
            context.getString(R.string.pref_key_privacy_block_other),
            context.getString(R.string.pref_key_performance_enable_cookies) ->
                updateTrackingProtectionPolicy()

            context.getString(R.string.pref_key_safe_browsing) ->
                updateSafeBrowsingPolicy()

            context.getString(R.string.pref_key_performance_block_javascript) ->
                updateJavaScriptSetting()

            context.getString(R.string.pref_key_remote_debugging) ->
                updateRemoteDebugging()

            context.getString(R.string.pref_key_performance_block_webfonts) ->
                updateWebFontsBlocking()
        }
    }

    private fun updateTrackingProtectionPolicy() {
        val policy = Settings.getInstance(context).createTrackingProtectionPolicy()
        val components = context.components

        components.engineDefaultSettings.trackingProtectionPolicy = policy
        components.settingsUseCases.updateTrackingProtection(policy)
    }

{'fraction_non_alphanumeric': 0.07581047381546134, 'fraction_numerical': 0.0029925187032418953, 'mean_word_length': 3.3268608414239482, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3023306', 'n_tokens_mistral': 1072, 'n_tokens_neox': 1014, 'n_words': 209}