Commit ea3d79a2 authored by Alex Catarineu's avatar Alex Catarineu Committed by Beatriz Rizental
Browse files

TB 40087 [android]: Implement a switch for spoof English.

parent 88d8ddbb
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -1347,6 +1347,15 @@ class GeckoEngine(
        override var fdlibmMathEnabled: Boolean
            get() = runtime.settings.fdlibmMathEnabled
            set(value) { runtime.settings.setFdlibmMathEnabled(value) }

        override var spoofEnglish: Boolean
            get() = runtime.settings.spoofEnglish
            set(value) {
                value.let {
                    runtime.settings.spoofEnglish = it
                    localeUpdater.updateValue()
                }
            }
    }.apply {
        defaultSettings?.let {
            this.javascriptEnabled = it.javascriptEnabled
@@ -1377,6 +1386,7 @@ class GeckoEngine(
            this.fingerprintingProtectionOverrides = it.fingerprintingProtectionOverrides
            this.fdlibmMathEnabled = it.fdlibmMathEnabled
            this.emailTrackerBlockingPrivateBrowsing = it.emailTrackerBlockingPrivateBrowsing
            this.spoofEnglish = it.spoofEnglish
        }
    }

+3 −0
Original line number Diff line number Diff line
@@ -273,6 +273,8 @@ abstract class Settings {
     * Setting to control whehter to use fdlibm for Math.sin, Math.cos, and Math.tan.
     */
    open var fdlibmMathEnabled: Boolean by UnsupportedSetting()

    open var spoofEnglish: Boolean by UnsupportedSetting()
}

/**
@@ -327,6 +329,7 @@ data class DefaultSettings(
    override var queryParameterStrippingAllowList: String = "",
    override var queryParameterStrippingStripList: String = "",
    override var emailTrackerBlockingPrivateBrowsing: Boolean = false,
    override var spoofEnglish: Boolean = false,
) : Settings()

class UnsupportedSetting<T> {
+1 −0
Original line number Diff line number Diff line
@@ -176,6 +176,7 @@ class Core(
            cookieBannerHandlingGlobalRules = context.settings().shouldEnableCookieBannerGlobalRules,
            cookieBannerHandlingGlobalRulesSubFrames = context.settings().shouldEnableCookieBannerGlobalRulesSubFrame,
            emailTrackerBlockingPrivateBrowsing = false,
            spoofEnglish = context.settings().spoofEnglish,
        )

        GeckoEngine(
+5 −0
Original line number Diff line number Diff line
@@ -12,6 +12,7 @@ import mozilla.components.browser.state.store.BrowserStore
import mozilla.components.support.locale.LocaleManager
import mozilla.components.support.locale.LocaleUseCases
import org.mozilla.fenix.nimbus.FxNimbus
import org.mozilla.fenix.ext.components
import java.util.Locale

interface LocaleSettingsController {
@@ -83,5 +84,9 @@ class DefaultLocaleSettingsController(
        config.setLocale(locale)
        config.setLayoutDirection(locale)
        resources.updateConfiguration(config, resources.displayMetrics)
        // A slightly hacky way of triggering a `runtime.settings.locales` update,
        // so that the locales are updated in GeckoView.
        val spoofEnglish = context.components.core.engine.settings.spoofEnglish
        context.components.core.engine.settings.spoofEnglish = spoofEnglish
    }
}
+14 −1
Original line number Diff line number Diff line
@@ -23,6 +23,8 @@ import org.mozilla.fenix.R
import org.mozilla.fenix.components.StoreProvider
import org.mozilla.fenix.databinding.FragmentLocaleSettingsBinding
import org.mozilla.fenix.ext.components
import org.mozilla.fenix.ext.requireComponents
import org.mozilla.fenix.ext.settings
import org.mozilla.fenix.ext.showToolbar

class LocaleSettingsFragment : Fragment(), MenuProvider {
@@ -46,6 +48,8 @@ class LocaleSettingsFragment : Fragment(), MenuProvider {
        _binding = FragmentLocaleSettingsBinding.inflate(inflater, container, false)
        val view = binding.root

        bindEnableSwitch()

        val browserStore = requireContext().components.core.store
        val localeUseCase = LocaleUseCases(browserStore)

@@ -62,10 +66,19 @@ class LocaleSettingsFragment : Fragment(), MenuProvider {
                localeUseCase = localeUseCase,
            ),
        )
        localeView = LocaleSettingsView(binding.root, interactor)
        localeView = LocaleSettingsView(binding.localeContainer, interactor)
        return view
    }

    private fun bindEnableSwitch() {
        val switch = binding.enableSwitch
        switch.isChecked = requireComponents.core.engine.settings.spoofEnglish
        switch.setOnCheckedChangeListener { _, isChecked ->
            context?.settings()?.spoofEnglish = isChecked
            requireComponents.core.engine.settings.spoofEnglish = isChecked
        }
    }

    override fun onCreateMenu(menu: Menu, inflater: MenuInflater) {
        inflater.inflate(R.menu.languages_list, menu)
        val searchItem = menu.findItem(R.id.search)
Loading