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

Bug 34403: Disable Normal mode by default

parent 5aaf26e7
...@@ -560,11 +560,17 @@ open class HomeActivity : LocaleAwareAppCompatActivity(), NavHostActivity { ...@@ -560,11 +560,17 @@ open class HomeActivity : LocaleAwareAppCompatActivity(), NavHostActivity {
internal fun getModeFromIntentOrLastKnown(intent: Intent?): BrowsingMode { internal fun getModeFromIntentOrLastKnown(intent: Intent?): BrowsingMode {
intent?.toSafeIntent()?.let { intent?.toSafeIntent()?.let {
if (it.hasExtra(PRIVATE_BROWSING_MODE)) { if (it.hasExtra(PRIVATE_BROWSING_MODE)) {
val startPrivateMode = it.getBooleanExtra(PRIVATE_BROWSING_MODE, false) val startPrivateMode = settings().shouldDisableNormalMode ||
it.getBooleanExtra(PRIVATE_BROWSING_MODE, settings().openLinksInAPrivateTab)
return BrowsingMode.fromBoolean(isPrivate = startPrivateMode) return BrowsingMode.fromBoolean(isPrivate = startPrivateMode)
} }
} }
return settings().lastKnownMode return when {
settings().shouldDisableNormalMode -> BrowsingMode.Private
settings().openLinksInAPrivateTab -> BrowsingMode.Private
else -> settings().lastKnownMode
}
} }
/** /**
...@@ -581,12 +587,12 @@ open class HomeActivity : LocaleAwareAppCompatActivity(), NavHostActivity { ...@@ -581,12 +587,12 @@ open class HomeActivity : LocaleAwareAppCompatActivity(), NavHostActivity {
} }
private fun checkPrivateShortcutEntryPoint(intent: Intent) { private fun checkPrivateShortcutEntryPoint(intent: Intent) {
if (intent.hasExtra(OPEN_TO_SEARCH) && val shouldStartPrivate = settings().shouldDisableNormalMode ||
(intent.getStringExtra(OPEN_TO_SEARCH) == intent.getStringExtra(OPEN_TO_SEARCH) ==
StartSearchIntentProcessor.STATIC_SHORTCUT_NEW_PRIVATE_TAB || StartSearchIntentProcessor.STATIC_SHORTCUT_NEW_PRIVATE_TAB ||
intent.getStringExtra(OPEN_TO_SEARCH) == intent.getStringExtra(OPEN_TO_SEARCH) ==
StartSearchIntentProcessor.PRIVATE_BROWSING_PINNED_SHORTCUT) StartSearchIntentProcessor.PRIVATE_BROWSING_PINNED_SHORTCUT
) { if (intent.hasExtra(OPEN_TO_SEARCH) && shouldStartPrivate) {
PrivateNotificationService.isStartedFromPrivateShortcut = true PrivateNotificationService.isStartedFromPrivateShortcut = true
} }
} }
......
...@@ -829,7 +829,17 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Session ...@@ -829,7 +829,17 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Session
} }
hideToolbar() hideToolbar()
getSessionById()?.let { updateThemeForSession(it) } getSessionById()?.let {
// If the most-recent session was a tab in Normal mode, and now Normal mode is disabled,
// then load the Private Mode home screen, instead.
if (!it.private && requireContext().settings().shouldDisableNormalMode) {
findNavController().nav(
R.id.browserFragment,
BrowserFragmentDirections.actionGlobalHomeFragment()
)
}
updateThemeForSession(it)
}
} }
@CallSuper @CallSuper
......
...@@ -175,7 +175,8 @@ class DefaultToolbarMenu( ...@@ -175,7 +175,8 @@ class DefaultToolbarMenu(
val shouldShowSaveToCollection = (context.asActivity() as? HomeActivity) val shouldShowSaveToCollection = (context.asActivity() as? HomeActivity)
?.browsingModeManager?.mode == BrowsingMode.Normal ?.browsingModeManager?.mode == BrowsingMode.Normal
val shouldDeleteDataOnQuit = context.components.settings val shouldDeleteDataOnQuit = context.components.settings
.shouldDeleteBrowsingDataOnQuit .shouldDeleteBrowsingDataOnQuit &&
!context.components.settings.shouldDisableNormalMode
val syncedTabsInTabsTray = context.components.settings val syncedTabsInTabsTray = context.components.settings
.syncedTabsInTabsTray .syncedTabsInTabsTray
......
...@@ -28,6 +28,7 @@ import androidx.constraintlayout.widget.ConstraintSet.TOP ...@@ -28,6 +28,7 @@ import androidx.constraintlayout.widget.ConstraintSet.TOP
import androidx.coordinatorlayout.widget.CoordinatorLayout import androidx.coordinatorlayout.widget.CoordinatorLayout
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
import androidx.core.view.doOnLayout import androidx.core.view.doOnLayout
import androidx.core.view.isGone
import androidx.core.view.isVisible import androidx.core.view.isVisible
import androidx.core.view.updateLayoutParams import androidx.core.view.updateLayoutParams
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
...@@ -427,6 +428,8 @@ class HomeFragment : Fragment() { ...@@ -427,6 +428,8 @@ class HomeFragment : Fragment() {
} }
} }
privateBrowsingButton.isGone = view.context.settings().shouldDisableNormalMode
// We call this onLayout so that the bottom bar width is correctly set for us to center // We call this onLayout so that the bottom bar width is correctly set for us to center
// the CFR in. // the CFR in.
view.toolbar_wrapper.doOnLayout { view.toolbar_wrapper.doOnLayout {
......
...@@ -161,9 +161,11 @@ class HomeMenu( ...@@ -161,9 +161,11 @@ class HomeMenu(
} }
val settings = context.components.settings val settings = context.components.settings
val shouldDeleteBrowsingDataOnQuit = settings.shouldDeleteBrowsingDataOnQuit &&
!settings.shouldDisableNormalMode
val menuItems = listOfNotNull( val menuItems = listOfNotNull(
if (settings.shouldDeleteBrowsingDataOnQuit) quitItem else null, if (shouldDeleteBrowsingDataOnQuit) quitItem else null,
settingsItem, settingsItem,
BrowserMenuDivider(), BrowserMenuDivider(),
if (settings.syncedTabsInTabsTray) null else syncedTabsItem, if (settings.syncedTabsInTabsTray) null else syncedTabsItem,
......
...@@ -174,6 +174,10 @@ class SettingsFragment : PreferenceFragmentCompat() { ...@@ -174,6 +174,10 @@ class SettingsFragment : PreferenceFragmentCompat() {
requirePreference<Preference>(R.string.pref_key_close_tabs) requirePreference<Preference>(R.string.pref_key_close_tabs)
tabSettingsPreference.summary = context?.settings()?.getTabTimeoutString() tabSettingsPreference.summary = context?.settings()?.getTabTimeoutString()
// Hide "Delete browsing data on quit" when in Private Browsing-only mode
deleteBrowsingDataPreference.isVisible =
!deleteBrowsingDataPreference.context.settings().shouldDisableNormalMode
setupPreferences() setupPreferences()
if (shouldUpdateAccountUIState) { if (shouldUpdateAccountUIState) {
......
...@@ -14,6 +14,7 @@ import androidx.cardview.widget.CardView ...@@ -14,6 +14,7 @@ import androidx.cardview.widget.CardView
import androidx.constraintlayout.widget.ConstraintLayout import androidx.constraintlayout.widget.ConstraintLayout
import androidx.constraintlayout.widget.ConstraintSet import androidx.constraintlayout.widget.ConstraintSet
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
import androidx.core.view.isGone
import androidx.core.view.isVisible import androidx.core.view.isVisible
import androidx.core.view.updateLayoutParams import androidx.core.view.updateLayoutParams
import androidx.core.view.updatePadding import androidx.core.view.updatePadding
...@@ -40,6 +41,7 @@ import mozilla.components.browser.state.state.BrowserState ...@@ -40,6 +41,7 @@ import mozilla.components.browser.state.state.BrowserState
import mozilla.components.browser.tabstray.TabViewHolder import mozilla.components.browser.tabstray.TabViewHolder
import mozilla.components.feature.syncedtabs.SyncedTabsFeature import mozilla.components.feature.syncedtabs.SyncedTabsFeature
import mozilla.components.support.base.feature.ViewBoundFeatureWrapper import mozilla.components.support.base.feature.ViewBoundFeatureWrapper
import mozilla.components.support.base.log.logger.Logger
import mozilla.components.support.ktx.android.util.dpToPx import mozilla.components.support.ktx.android.util.dpToPx
import org.mozilla.fenix.R import org.mozilla.fenix.R
import org.mozilla.fenix.components.metrics.Event import org.mozilla.fenix.components.metrics.Event
...@@ -78,6 +80,8 @@ class TabTrayView( ...@@ -78,6 +80,8 @@ class TabTrayView(
private val isPrivateModeSelected: Boolean get() = view.tab_layout.selectedTabPosition == PRIVATE_TAB_ID private val isPrivateModeSelected: Boolean get() = view.tab_layout.selectedTabPosition == PRIVATE_TAB_ID
private val isNormalModeDisabled = container.context.settings().shouldDisableNormalMode
private val behavior = BottomSheetBehavior.from(view.tab_wrapper) private val behavior = BottomSheetBehavior.from(view.tab_wrapper)
private val concatAdapter = ConcatAdapter(tabsAdapter) private val concatAdapter = ConcatAdapter(tabsAdapter)
...@@ -92,6 +96,8 @@ class TabTrayView( ...@@ -92,6 +96,8 @@ class TabTrayView(
private var hasLoaded = false private var hasLoaded = false
private val logger = Logger("TabTrayView")
override val containerView: View? override val containerView: View?
get() = container get() = container
...@@ -100,6 +106,10 @@ class TabTrayView( ...@@ -100,6 +106,10 @@ class TabTrayView(
init { init {
components.analytics.metrics.track(Event.TabsTrayOpened) components.analytics.metrics.track(Event.TabsTrayOpened)
if (!isPrivate && isNormalModeDisabled) {
logger.debug("TabTrayView: isNormalModeDisabled but not Private tabs")
}
toggleFabText(isPrivate) toggleFabText(isPrivate)
behavior.addBottomSheetCallback(object : BottomSheetBehavior.BottomSheetCallback() { behavior.addBottomSheetCallback(object : BottomSheetBehavior.BottomSheetCallback() {
...@@ -127,6 +137,15 @@ class TabTrayView( ...@@ -127,6 +137,15 @@ class TabTrayView(
PRIVATE_TAB_ID PRIVATE_TAB_ID
} }
// Find non-private mode tab and set visibility
view.tab_layout.getTabAt(DEFAULT_TAB_ID)?.getCustomView()?.apply {
// The View we get from getCustomView() is only a sub-component
// of the actual tab (for example, the tab-count box). We need
// the "Custom View"'s parent for controlling the visibility
// of the entire tab.
(getParent() as? View)?.isGone = isNormalModeDisabled
}
view.tab_layout.getTabAt(selectedTabIndex)?.also { view.tab_layout.getTabAt(selectedTabIndex)?.also {
view.tab_layout.selectTab(it, true) view.tab_layout.selectTab(it, true)
} }
......
...@@ -155,7 +155,7 @@ class Settings(private val appContext: Context) : PreferencesHolder { ...@@ -155,7 +155,7 @@ class Settings(private val appContext: Context) : PreferencesHolder {
var openLinksInAPrivateTab by booleanPreference( var openLinksInAPrivateTab by booleanPreference(
appContext.getPreferenceKey(R.string.pref_key_open_links_in_a_private_tab), appContext.getPreferenceKey(R.string.pref_key_open_links_in_a_private_tab),
default = false default = true
) )
var allowScreenshotsInPrivateMode by booleanPreference( var allowScreenshotsInPrivateMode by booleanPreference(
...@@ -477,11 +477,16 @@ class Settings(private val appContext: Context) : PreferencesHolder { ...@@ -477,11 +477,16 @@ class Settings(private val appContext: Context) : PreferencesHolder {
return touchExplorationIsEnabled || switchServiceIsEnabled return touchExplorationIsEnabled || switchServiceIsEnabled
} }
var lastKnownMode: BrowsingMode = BrowsingMode.Normal val shouldDisableNormalMode by booleanPreference(
appContext.getPreferenceKey(R.string.pref_key_disable_normal_mode),
true
)
var lastKnownMode: BrowsingMode = BrowsingMode.Private
get() { get() {
val lastKnownModeWasPrivate = preferences.getBoolean( val lastKnownModeWasPrivate = preferences.getBoolean(
appContext.getPreferenceKey(R.string.pref_key_last_known_mode_private), appContext.getPreferenceKey(R.string.pref_key_last_known_mode_private),
false shouldDisableNormalMode
) )
return if (lastKnownModeWasPrivate) { return if (lastKnownModeWasPrivate) {
...@@ -813,7 +818,8 @@ class Settings(private val appContext: Context) : PreferencesHolder { ...@@ -813,7 +818,8 @@ class Settings(private val appContext: Context) : PreferencesHolder {
numTimesPrivateModeOpened.value == CFR_COUNT_CONDITION_FOCUS_NOT_INSTALLED numTimesPrivateModeOpened.value == CFR_COUNT_CONDITION_FOCUS_NOT_INSTALLED
} }
if (showCondition && !showedPrivateModeContextualFeatureRecommender) { if (!shouldDisableNormalMode && showCondition &&
!showedPrivateModeContextualFeatureRecommender) {
showedPrivateModeContextualFeatureRecommender = true showedPrivateModeContextualFeatureRecommender = true
return true return true
} }
......
...@@ -113,6 +113,9 @@ ...@@ -113,6 +113,9 @@
<action <action
android:id="@+id/action_global_closeTabSettingsFragment" android:id="@+id/action_global_closeTabSettingsFragment"
app:destination="@id/closeTabsSettingsFragment" /> app:destination="@id/closeTabsSettingsFragment" />
<action
android:id="@+id/action_global_homeFragment"
app:destination="@id/homeFragment" />
<dialog <dialog
android:id="@+id/tabTrayDialogFragment" android:id="@+id/tabTrayDialogFragment"
......
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
<string name="pref_key_delete_caches_now" translatable="false">pref_key_delete_caches_now</string> <string name="pref_key_delete_caches_now" translatable="false">pref_key_delete_caches_now</string>
<string name="pref_key_delete_permissions_now" translatable="false">pref_key_delete_permissions_now</string> <string name="pref_key_delete_permissions_now" translatable="false">pref_key_delete_permissions_now</string>
<string name="pref_key_delete_browsing_data_on_quit_categories" translatable="false">pref_key_delete_browsing_data_on_quit_categories</string> <string name="pref_key_delete_browsing_data_on_quit_categories" translatable="false">pref_key_delete_browsing_data_on_quit_categories</string>
<string name="pref_key_disable_normal_mode" translatable="false">pref_key_disable_normal_mode</string>
<string name="pref_key_last_known_mode_private" translatable="false">pref_key_last_known_mode_private</string> <string name="pref_key_last_known_mode_private" translatable="false">pref_key_last_known_mode_private</string>
<string name="pref_key_addons" translatable="false">pref_key_addons</string> <string name="pref_key_addons" translatable="false">pref_key_addons</string>
<string name="pref_key_last_maintenance" translatable="false">pref_key_last_maintenance</string> <string name="pref_key_last_maintenance" translatable="false">pref_key_last_maintenance</string>
......
<?xml version="1.0" encoding="utf-8" standalone="yes"?><!-- 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/. -->
<resources>
<!-- Preference for enabling non-Private Browsing Mode-->
<string name="preferences_disable_normal_mode">Allow Only Private Browsing Mode</string>
</resources>
...@@ -92,6 +92,7 @@ ...@@ -92,6 +92,7 @@
<androidx.preference.Preference <androidx.preference.Preference
android:icon="@drawable/ic_private_browsing" android:icon="@drawable/ic_private_browsing"
android:key="@string/pref_key_private_browsing" android:key="@string/pref_key_private_browsing"
app:isPreferenceVisible="false"
android:title="@string/preferences_private_browsing_options"/> android:title="@string/preferences_private_browsing_options"/>
<androidx.preference.Preference <androidx.preference.Preference
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
- file, You can obtain one at http://mozilla.org/MPL/2.0/. --> - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"> <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<Preference <Preference
android:defaultValue="false"
android:key="@string/pref_key_add_private_browsing_shortcut" android:key="@string/pref_key_add_private_browsing_shortcut"
android:title="@string/preferences_add_private_browsing_shortcut" /> android:title="@string/preferences_add_private_browsing_shortcut" />
<SwitchPreference <SwitchPreference
......
...@@ -44,13 +44,13 @@ class SettingsTest { ...@@ -44,13 +44,13 @@ class SettingsTest {
fun launchLinksInPrivateTab() { fun launchLinksInPrivateTab() {
// When just created // When just created
// Then // Then
assertFalse(settings.openLinksInAPrivateTab) assertTrue(settings.openLinksInAPrivateTab)
// When // When
settings.openLinksInAPrivateTab = true settings.openLinksInAPrivateTab = false
// Then // Then
assertTrue(settings.openLinksInAPrivateTab) assertFalse(settings.openLinksInAPrivateTab)
} }
@Test @Test
......
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