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 e191e7bd authored by Matthew Finkel's avatar Matthew Finkel
Browse files

Bug 40026: Integrate Security Level settings

parent 8a44eeda
......@@ -103,7 +103,8 @@ class Core(
fontInflationEnabled = context.settings().shouldUseAutoSize,
suspendMediaWhenInactive = false,
forceUserScalableContent = context.settings().forceEnableZoom,
loginAutofillEnabled = context.settings().shouldAutofillLogins
loginAutofillEnabled = context.settings().shouldAutofillLogins,
torSecurityLevel = context.settings().torSecurityLevel().intRepresentation
)
GeckoEngine(
......
......@@ -370,6 +370,8 @@ class DefaultSessionControlController(
}
override fun handleOpenSecurityLevelSettingsClicked() {
val directions = HomeFragmentDirections.actionGlobalTorSecurityLevelFragment()
navController.nav(R.id.homeFragment, directions)
}
override fun handleWhatsNewGetAnswersClicked() {
......
......@@ -11,6 +11,8 @@ import org.mozilla.fenix.R
import org.mozilla.fenix.ext.components
import org.mozilla.fenix.home.sessioncontrol.OnboardingInteractor
import org.mozilla.fenix.onboarding.OnboardingRadioButton
import org.mozilla.fenix.tor.SecurityLevel
import org.mozilla.fenix.tor.SecurityLevelUtil
import org.mozilla.fenix.utils.view.addToRadioGroup
class TorOnboardingSecurityLevelViewHolder(
......@@ -57,19 +59,33 @@ class TorOnboardingSecurityLevelViewHolder(
saferSecurityLevel.isChecked = securityLevel == SecurityLevel.SAFER
standardSecurityLevel.onClickListener {
updateSecurityLevel()
updateSecurityLevel(SecurityLevel.STANDARD)
}
saferSecurityLevel.onClickListener {
updateSecurityLevel()
updateSecurityLevel(SecurityLevel.SAFER)
}
safestSecurityLevel.onClickListener {
updateSecurityLevel()
updateSecurityLevel(SecurityLevel.SAFEST)
}
updateSecurityLevel(securityLevel)
}
private fun updateSecurityLevel() {
private fun updateSecurityLevel(newLevel: SecurityLevel) {
val resources = itemView.context.resources
val securityLevel = when (newLevel) {
SecurityLevel.STANDARD -> resources.getString(R.string.tor_security_level_standard_option)
SecurityLevel.SAFER -> resources.getString(R.string.tor_security_level_safer_option)
SecurityLevel.SAFEST -> resources.getString(R.string.tor_security_level_safest_option)
}
itemView.current_level.text = resources.getString(
R.string.tor_onboarding_chosen_security_level_label, securityLevel
)
itemView.context.components.let {
it.core.engine.settings.torSecurityLevel = newLevel.intRepresentation
}
}
companion object {
......
......@@ -224,6 +224,9 @@ class SettingsFragment : PreferenceFragmentCompat() {
resources.getString(R.string.pref_key_tor_network_settings) -> {
SettingsFragmentDirections.actionSettingsFragmentToTorNetworkSettingsFragment()
}
resources.getString(R.string.pref_key_tor_security_level_settings) -> {
SettingsFragmentDirections.actionSettingsFragmentToTorSecurityLevelFragment()
}
resources.getString(R.string.pref_key_tracking_protection_settings) -> {
requireContext().metrics.track(Event.TrackingProtectionSettings)
SettingsFragmentDirections.actionSettingsFragmentToTrackingProtectionFragment()
......
......@@ -40,6 +40,7 @@ import org.mozilla.fenix.settings.deletebrowsingdata.DeleteBrowsingDataOnQuitTyp
import org.mozilla.fenix.settings.logins.SavedLoginsSortingStrategyMenu
import org.mozilla.fenix.settings.logins.SortingStrategy
import org.mozilla.fenix.settings.registerOnSharedPreferenceChangeListener
import org.mozilla.fenix.tor.SecurityLevel
import java.security.InvalidParameterException
private const val AUTOPLAY_USER_SETTING = "AUTOPLAY_USER_SETTING"
......@@ -186,6 +187,33 @@ class Settings(private val appContext: Context) : PreferencesHolder {
false
)
var standardSecurityLevel by booleanPreference(
appContext.getPreferenceKey(SecurityLevel.STANDARD.preferenceKey),
default = true
)
var saferSecurityLevel by booleanPreference(
appContext.getPreferenceKey(SecurityLevel.SAFER.preferenceKey),
default = false
)
var safestSecurityLevel by booleanPreference(
appContext.getPreferenceKey(SecurityLevel.SAFEST.preferenceKey),
default = false
)
// torSecurityLevel is defined as the first |true| preference,
// beginning at the safest level.
// If multiple preferences are true, then that is a bug and the
// highest |true| security level is chosen.
// Standard is the default level.
fun torSecurityLevel(): SecurityLevel = when {
safestSecurityLevel -> SecurityLevel.SAFEST
saferSecurityLevel -> SecurityLevel.SAFER
standardSecurityLevel -> SecurityLevel.STANDARD
else -> SecurityLevel.STANDARD
}
// If any of the prefs have been modified, quit displaying the fenix moved tip
fun shouldDisplayFenixMovingTip(): Boolean =
preferences.getBoolean(
......
......@@ -32,9 +32,18 @@
android:textAppearance="@style/Body14TextStyle"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/header_text"
app:layout_constraintTop_toBottomOf="@id/current_level"
tools:text="@string/tor_onboarding_security_level_description" />
<TextView
android:id="@+id/current_level"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/header_text"
tools:text="@string/tor_onboarding_chosen_security_level_label" />
<org.mozilla.fenix.onboarding.OnboardingRadioButton
android:id="@+id/security_level_standard_option"
......
......@@ -58,6 +58,9 @@
<action
android:id="@+id/action_global_syncedTabsFragment"
app:destination="@id/syncedTabsFragment" />
<action
android:id="@+id/action_global_torSecurityLevelFragment"
app:destination="@id/torSecurityLevelFragment" />
<action
android:id="@+id/action_global_privateBrowsingFragment"
app:destination="@id/privateBrowsingFragment" />
......@@ -473,6 +476,13 @@
app:exitAnim="@anim/slide_out_left"
app:popEnterAnim="@anim/slide_in_left"
app:popExitAnim="@anim/slide_out_right" />
<action
android:id="@+id/action_settingsFragment_to_torSecurityLevelFragment"
app:destination="@id/torSecurityLevelFragment"
app:enterAnim="@anim/slide_in_right"
app:exitAnim="@anim/slide_out_left"
app:popEnterAnim="@anim/slide_in_left"
app:popExitAnim="@anim/slide_out_right" />
<action
android:id="@+id/action_settingsFragment_to_privateBrowsingFragment"
app:destination="@id/privateBrowsingFragment"
......
......@@ -20,6 +20,7 @@
<string name="tor_onboarding_security_level">Set your Security Level</string>
<string name="tor_onboarding_security_level_description">Disable certain web features that can be used to attack you, and harm your security, anonymity, and privacy.</string>
<string name="tor_onboarding_chosen_security_level_label">Current Security Level: %s</string>
<string name="tor_onboarding_security_settings_button">Open Security Settings</string>
<string name="tor_onboarding_donate_header">Donate and keep Tor safe</string>
<string name="tor_onboarding_donate_description">Tor is free to use because of donations from people like you.</string>
......@@ -54,6 +55,10 @@
<string name="preferences_tor_network_settings_restarting">Restarting</string>
<string name="preferences_tor_network_settings_bridges_enabled">Bridges are enabled: %s</string>
<!-- Preference title for security level settings -->
<string name="preferences_tor_security_level_settings">Security Settings</string>
<string name="preferences_tor_security_level_options">Security Level</string>
<!-- Description of security levels -->
<string name="tor_security_level_standard_option">Standard</string>
<string name="tor_security_level_standard_description">All Tor Browser and website features are enabled.</string>
......@@ -62,7 +67,4 @@
<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>
<!-- Preference title for security level settings -->
<string name="preferences_tor_security_level_settings">Security Settings</string>
<string name="preferences_tor_security_level_options">Security Level</string>
</resources>
......@@ -90,6 +90,11 @@
app:iconSpaceReserved="false"
android:layout="@layout/preference_category_main_style">
<androidx.preference.Preference
android:icon="@drawable/ic_tracking_protection_enabled"
android:key="@string/pref_key_tor_security_level_settings"
android:title="@string/preferences_tor_security_level_settings"/>
<androidx.preference.Preference
android:icon="@drawable/ic_private_browsing"
android:key="@string/pref_key_private_browsing"
......
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