GitLab is used only for code review, issue tracking and project management. Canonical locations for source code are still https://gitweb.torproject.org/ https://git.torproject.org/ and git-rw.torproject.org.

Commit e022794d authored by Alex Catarineu's avatar Alex Catarineu Committed by Matthew Finkel

Bug 40087: Implement a switch for english locale spoofing

parent 1b4acefe
...@@ -104,7 +104,8 @@ class Core( ...@@ -104,7 +104,8 @@ class Core(
suspendMediaWhenInactive = false, suspendMediaWhenInactive = false,
forceUserScalableContent = context.settings().forceEnableZoom, forceUserScalableContent = context.settings().forceEnableZoom,
loginAutofillEnabled = context.settings().shouldAutofillLogins, loginAutofillEnabled = context.settings().shouldAutofillLogins,
torSecurityLevel = context.settings().torSecurityLevel().intRepresentation torSecurityLevel = context.settings().torSecurityLevel().intRepresentation,
spoofEnglish = context.settings().spoofEnglish
) )
GeckoEngine( GeckoEngine(
......
...@@ -7,6 +7,7 @@ package org.mozilla.fenix.settings.advanced ...@@ -7,6 +7,7 @@ package org.mozilla.fenix.settings.advanced
import android.app.Activity import android.app.Activity
import android.content.Context import android.content.Context
import mozilla.components.support.locale.LocaleManager import mozilla.components.support.locale.LocaleManager
import org.mozilla.fenix.ext.components
import java.util.Locale import java.util.Locale
interface LocaleSettingsController { interface LocaleSettingsController {
...@@ -55,5 +56,9 @@ class DefaultLocaleSettingsController( ...@@ -55,5 +56,9 @@ class DefaultLocaleSettingsController(
config.setLocale(locale) config.setLocale(locale)
config.setLayoutDirection(locale) config.setLayoutDirection(locale)
resources.updateConfiguration(config, resources.displayMetrics) 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
} }
} }
...@@ -19,6 +19,8 @@ import mozilla.components.lib.state.ext.consumeFrom ...@@ -19,6 +19,8 @@ import mozilla.components.lib.state.ext.consumeFrom
import mozilla.components.support.ktx.android.view.hideKeyboard import mozilla.components.support.ktx.android.view.hideKeyboard
import org.mozilla.fenix.R import org.mozilla.fenix.R
import org.mozilla.fenix.components.StoreProvider import org.mozilla.fenix.components.StoreProvider
import org.mozilla.fenix.ext.requireComponents
import org.mozilla.fenix.ext.settings
import org.mozilla.fenix.ext.showToolbar import org.mozilla.fenix.ext.showToolbar
class LocaleSettingsFragment : Fragment() { class LocaleSettingsFragment : Fragment() {
...@@ -37,7 +39,9 @@ class LocaleSettingsFragment : Fragment() { ...@@ -37,7 +39,9 @@ class LocaleSettingsFragment : Fragment() {
container: ViewGroup?, container: ViewGroup?,
savedInstanceState: Bundle? savedInstanceState: Bundle?
): View? { ): View? {
val view = inflater.inflate(R.layout.fragment_locale_settings, container, false) val view = inflater.inflate(R.layout.fragment_locale_settings, container, false).also {
bindEnableSwitch(it)
}
store = StoreProvider.get(this) { store = StoreProvider.get(this) {
LocaleSettingsStore( LocaleSettingsStore(
...@@ -54,6 +58,16 @@ class LocaleSettingsFragment : Fragment() { ...@@ -54,6 +58,16 @@ class LocaleSettingsFragment : Fragment() {
return view return view
} }
@SuppressWarnings("LongMethod")
private fun bindEnableSwitch(view: View) {
val switch = view.enable_switch
switch.isChecked = requireComponents.core.engine.settings.spoofEnglish
switch.setOnCheckedChangeListener { _, isChecked ->
context?.settings()?.spoofEnglish = isChecked
requireComponents.core.engine.settings.spoofEnglish = isChecked
}
}
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) { override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
inflater.inflate(R.menu.languages_list, menu) inflater.inflate(R.menu.languages_list, menu)
val searchItem = menu.findItem(R.id.search) val searchItem = menu.findItem(R.id.search)
......
...@@ -214,6 +214,11 @@ class Settings(private val appContext: Context) : PreferencesHolder { ...@@ -214,6 +214,11 @@ class Settings(private val appContext: Context) : PreferencesHolder {
else -> SecurityLevel.STANDARD else -> SecurityLevel.STANDARD
} }
var spoofEnglish by booleanPreference(
appContext.getPreferenceKey(R.string.pref_key_spoof_english),
default = false
)
// If any of the prefs have been modified, quit displaying the fenix moved tip // If any of the prefs have been modified, quit displaying the fenix moved tip
fun shouldDisplayFenixMovingTip(): Boolean = fun shouldDisplayFenixMovingTip(): Boolean =
preferences.getBoolean( preferences.getBoolean(
......
...@@ -7,13 +7,30 @@ ...@@ -7,13 +7,30 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent">
<com.google.android.material.switchmaterial.SwitchMaterial
android:id="@+id/enable_switch"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|end"
android:background="?android:attr/selectableItemBackground"
android:checked="true"
android:clickable="true"
android:focusable="true"
android:layout_marginStart="54dp"
android:padding="16dp"
android:text="@string/tor_spoof_english"
android:textColor="?primaryText"
android:textSize="16sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<FrameLayout <FrameLayout
android:id="@+id/locale_container" android:id="@+id/locale_container"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toBottomOf="@id/enable_switch" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
...@@ -263,4 +263,6 @@ ...@@ -263,4 +263,6 @@
<string name="pref_key_tor_network_settings_tor_ready">pref_key_tor_network_settings_tor_ready</string> <string name="pref_key_tor_network_settings_tor_ready">pref_key_tor_network_settings_tor_ready</string>
<string name="pref_key_tor_network_settings_state">pref_key_tor_network_settings_state</string> <string name="pref_key_tor_network_settings_state">pref_key_tor_network_settings_state</string>
<string name="pref_key_tor_network_settings_bridges_enabled">pref_key_tor_network_settings_bridges_enabled</string> <string name="pref_key_tor_network_settings_bridges_enabled">pref_key_tor_network_settings_bridges_enabled</string>
<string name="pref_key_spoof_english" translatable="false">pref_key_spoof_english</string>
</resources> </resources>
...@@ -70,4 +70,6 @@ ...@@ -70,4 +70,6 @@
<string name="tor_security_level_safest_option">Safest</string> <string name="tor_security_level_safest_option">Safest</string>
<string name="tor_security_level_safest_description">Only allow website features required for static sites and basic services. These changes affect images, media, and scripts.</string> <string name="tor_security_level_safest_description">Only allow website features required for static sites and basic services. These changes affect images, media, and scripts.</string>
<!-- Spoof locale to English -->
<string name="tor_spoof_english">Request English versions of web pages for enhanced privacy</string>
</resources> </resources>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment