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 8a49393c authored by Matthew Finkel's avatar Matthew Finkel

Bug 34403: Disable Normal mode by default

parent 80311e41
......@@ -653,11 +653,17 @@ open class HomeActivity : LocaleAwareAppCompatActivity(), NavHostActivity {
internal fun getModeFromIntentOrLastKnown(intent: Intent?): BrowsingMode {
intent?.toSafeIntent()?.let {
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 settings().lastKnownMode
return when {
settings().shouldDisableNormalMode -> BrowsingMode.Private
settings().openLinksInAPrivateTab -> BrowsingMode.Private
else -> settings().lastKnownMode
}
}
/**
......@@ -674,12 +680,12 @@ open class HomeActivity : LocaleAwareAppCompatActivity(), NavHostActivity {
}
private fun checkPrivateShortcutEntryPoint(intent: Intent) {
if (intent.hasExtra(OPEN_TO_SEARCH) &&
(intent.getStringExtra(OPEN_TO_SEARCH) ==
val shouldStartPrivate = settings().shouldDisableNormalMode ||
intent.getStringExtra(OPEN_TO_SEARCH) ==
StartSearchIntentProcessor.STATIC_SHORTCUT_NEW_PRIVATE_TAB ||
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
}
}
......
......@@ -867,7 +867,17 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Session
}
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
......
......@@ -178,7 +178,8 @@ class DefaultToolbarMenu(
val shouldShowSaveToCollection = (context.asActivity() as? HomeActivity)
?.browsingModeManager?.mode == BrowsingMode.Normal
val shouldDeleteDataOnQuit = context.components.settings
.shouldDeleteBrowsingDataOnQuit
.shouldDeleteBrowsingDataOnQuit &&
!context.components.settings.shouldDisableNormalMode
val syncedTabsInTabsTray = context.components.settings
.syncedTabsInTabsTray
......
......@@ -29,6 +29,7 @@ import androidx.constraintlayout.widget.ConstraintSet.TOP
import androidx.coordinatorlayout.widget.CoordinatorLayout
import androidx.core.content.ContextCompat
import androidx.core.view.doOnLayout
import androidx.core.view.isGone
import androidx.core.view.isVisible
import androidx.core.view.updateLayoutParams
import androidx.fragment.app.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
// the CFR in.
view.toolbar_wrapper.doOnLayout {
......
......@@ -161,9 +161,11 @@ class HomeMenu(
}
val settings = context.components.settings
val shouldDeleteBrowsingDataOnQuit = settings.shouldDeleteBrowsingDataOnQuit &&
!settings.shouldDisableNormalMode
val menuItems = listOfNotNull(
if (settings.shouldDeleteBrowsingDataOnQuit) quitItem else null,
if (shouldDeleteBrowsingDataOnQuit) quitItem else null,
settingsItem,
BrowserMenuDivider(),
if (settings.syncedTabsInTabsTray) null else syncedTabsItem,
......
......@@ -189,6 +189,10 @@ class SettingsFragment : PreferenceFragmentCompat() {
requirePreference<Preference>(R.string.pref_key_tabs)
tabSettingsPreference.summary = context?.settings()?.getTabTimeoutString()
// Hide "Delete browsing data on quit" when in Private Browsing-only mode
deleteBrowsingDataPreference.isVisible =
!deleteBrowsingDataPreference.context.settings().shouldDisableNormalMode
setupPreferences()
if (shouldUpdateAccountUIState) {
......
......@@ -16,6 +16,7 @@ import androidx.cardview.widget.CardView
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.constraintlayout.widget.ConstraintSet
import androidx.core.content.ContextCompat
import androidx.core.view.isGone
import androidx.core.view.isVisible
import androidx.core.view.updateLayoutParams
import androidx.core.view.updatePadding
......@@ -43,6 +44,7 @@ import mozilla.components.browser.state.state.BrowserState
import mozilla.components.browser.tabstray.TabViewHolder
import mozilla.components.feature.syncedtabs.SyncedTabsFeature
import mozilla.components.support.base.feature.ViewBoundFeatureWrapper
import mozilla.components.support.base.log.logger.Logger
import org.mozilla.fenix.R
import org.mozilla.fenix.browser.InfoBanner
import org.mozilla.fenix.components.metrics.Event
......@@ -81,6 +83,8 @@ class TabTrayView(
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 concatAdapter = ConcatAdapter(tabsAdapter)
......@@ -96,6 +100,8 @@ class TabTrayView(
private var hasLoaded = false
private val logger = Logger("TabTrayView")
override val containerView: View?
get() = container
......@@ -112,6 +118,10 @@ class TabTrayView(
init {
components.analytics.metrics.track(Event.TabsTrayOpened)
if (!isPrivate && isNormalModeDisabled) {
logger.debug("TabTrayView: isNormalModeDisabled but not Private tabs")
}
toggleFabText(isPrivate)
behavior.addBottomSheetCallback(object : BottomSheetBehavior.BottomSheetCallback() {
......@@ -139,6 +149,15 @@ class TabTrayView(
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.selectTab(it, true)
}
......
......@@ -168,7 +168,7 @@ class Settings(private val appContext: Context) : PreferencesHolder {
var openLinksInAPrivateTab by booleanPreference(
appContext.getPreferenceKey(R.string.pref_key_open_links_in_a_private_tab),
default = false
default = true
)
var allowScreenshotsInPrivateMode by booleanPreference(
......@@ -534,11 +534,16 @@ class Settings(private val appContext: Context) : PreferencesHolder {
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() {
val lastKnownModeWasPrivate = preferences.getBoolean(
appContext.getPreferenceKey(R.string.pref_key_last_known_mode_private),
false
shouldDisableNormalMode
)
return if (lastKnownModeWasPrivate) {
......@@ -909,7 +914,8 @@ class Settings(private val appContext: Context) : PreferencesHolder {
numTimesPrivateModeOpened.value == CFR_COUNT_CONDITION_FOCUS_NOT_INSTALLED
}
if (showCondition && !showedPrivateModeContextualFeatureRecommender) {
if (!shouldDisableNormalMode && showCondition &&
!showedPrivateModeContextualFeatureRecommender) {
showedPrivateModeContextualFeatureRecommender = true
return true
}
......
......@@ -113,6 +113,9 @@
<action
android:id="@+id/action_global_tabSettingsFragment"
app:destination="@id/tabsSettingsFragment" />
<action
android:id="@+id/action_global_homeFragment"
app:destination="@id/homeFragment" />
<dialog
android:id="@+id/tabTrayDialogFragment"
......
......@@ -33,6 +33,7 @@
<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_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_addons" translatable="false">pref_key_addons</string>
<string name="pref_key_override_amo_user" translatable="false">pref_key_override_amo_user</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 @@
<androidx.preference.Preference
android:icon="@drawable/ic_private_browsing"
android:key="@string/pref_key_private_browsing"
app:isPreferenceVisible="false"
android:title="@string/preferences_private_browsing_options"/>
<androidx.preference.Preference
......
......@@ -4,6 +4,7 @@
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<Preference
android:defaultValue="false"
android:key="@string/pref_key_add_private_browsing_shortcut"
android:title="@string/preferences_add_private_browsing_shortcut" />
<SwitchPreference
......
......@@ -45,13 +45,13 @@ class SettingsTest {
fun launchLinksInPrivateTab() {
// When just created
// Then
assertFalse(settings.openLinksInAPrivateTab)
assertTrue(settings.openLinksInAPrivateTab)
// When
settings.openLinksInAPrivateTab = true
settings.openLinksInAPrivateTab = false
// Then
assertTrue(settings.openLinksInAPrivateTab)
assertFalse(settings.openLinksInAPrivateTab)
}
@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