Bug 1807545 - Add new "Open in regular tab" feature.

This feature allows a private tab to be reopened as a regular tab. The
feature is only enabled for users with the "Open links in a private tab"
option enabled - such users who follow links from external applications
will always have these tabs opened as private, so may wish to "opt-out"
of individual tabs being private.
Users without this option set will not have private tabs opened by
default, so have already opted-in to each private tab - thus, those users
are unlikely to benefit from this feature.

The feature is added to the main menu - however, as above, it will only
be visible when a private tab is open *and* "Open links in a private tab"
is enabled, so will only be seen by a minority of users.

The feature is also enabled only for Nightly while it is polished, but
the intention is that it eventually ride to release.
fenix/121.0
Mark Hammond 9 months ago committed by mergify[bot]
parent f9996f57ab
commit 41120b4c4f

@ -94,6 +94,7 @@ class DefaultBrowserToolbarMenuController(
override fun handleToolbarItemInteraction(item: ToolbarMenu.Item) {
val sessionUseCases = activity.components.useCases.sessionUseCases
val customTabUseCases = activity.components.useCases.customTabsUseCases
val tabsUseCases = activity.components.useCases.tabsUseCases
trackToolbarItemInteraction(item)
when (item) {
@ -254,6 +255,13 @@ class DefaultBrowserToolbarMenuController(
)
}
}
is ToolbarMenu.Item.OpenInRegularTab -> {
currentSession?.let { session ->
getProperUrl(session)?.let { url ->
tabsUseCases.migratePrivateTabUseCase.invoke(session.id, url)
}
}
}
is ToolbarMenu.Item.AddToTopSites -> {
scope.launch {
val context = snackbarParent.context
@ -443,6 +451,8 @@ class DefaultBrowserToolbarMenuController(
} else {
Events.browserMenuAction.record(Events.BrowserMenuActionExtra("desktop_view_off"))
}
is ToolbarMenu.Item.OpenInRegularTab ->
Events.browserMenuAction.record(Events.BrowserMenuActionExtra("open_in_regular_tab"))
is ToolbarMenu.Item.FindInPage ->
Events.browserMenuAction.record(Events.BrowserMenuActionExtra("find_in_page"))
is ToolbarMenu.Item.SaveToCollection ->

@ -35,12 +35,14 @@ import mozilla.components.feature.webcompat.reporter.WebCompatReporterFeature
import mozilla.components.lib.state.ext.flowScoped
import mozilla.components.support.ktx.android.content.getColorFromAttr
import mozilla.components.support.ktx.kotlinx.coroutines.flow.ifAnyChanged
import org.mozilla.fenix.Config
import org.mozilla.fenix.R
import org.mozilla.fenix.components.accounts.FenixAccountManager
import org.mozilla.fenix.ext.components
import org.mozilla.fenix.ext.settings
import org.mozilla.fenix.nimbus.FxNimbus
import org.mozilla.fenix.theme.ThemeManager
import org.mozilla.fenix.utils.Settings
/**
* Builds the toolbar object used with the 3-dot menu in the browser fragment.
@ -168,6 +170,19 @@ open class DefaultToolbarMenu(
selectedSession != null && isPinningSupported &&
context.components.useCases.webAppUseCases.isInstallable()
/**
* Should the "Open in regular tab" menu item be visible?
*/
@VisibleForTesting(otherwise = PRIVATE)
fun shouldShowOpenInRegularTab(): Boolean = selectedSession?.let { session ->
// This feature is gated behind Nightly for the time being.
Config.channel.isNightlyOrDebug &&
// This feature is explicitly for users opening links in private tabs.
context.settings().openLinksInAPrivateTab &&
// and is only visible in private tabs.
session.content.private
} ?: false
@VisibleForTesting(otherwise = PRIVATE)
fun shouldShowOpenInApp(): Boolean = selectedSession?.let { session ->
val appLink = context.components.useCases.appLinksUseCases.appLinkRedirect
@ -243,6 +258,13 @@ open class DefaultToolbarMenu(
onItemTapped.invoke(ToolbarMenu.Item.RequestDesktop(checked))
}
private val openInRegularTabItem = BrowserMenuImageText(
label = context.getString(R.string.browser_menu_open_in_regular_tab),
imageResource = R.drawable.ic_open_in_regular_tab,
) {
onItemTapped.invoke(ToolbarMenu.Item.OpenInRegularTab)
}
private val customizeReaderView = BrowserMenuImageText(
label = context.getString(R.string.browser_menu_customize_reader_view),
imageResource = R.drawable.ic_readermode_appearance,
@ -384,6 +406,7 @@ open class DefaultToolbarMenu(
BrowserMenuDivider(),
findInPageItem,
desktopSiteItem,
openInRegularTabItem.apply { visible = ::shouldShowOpenInRegularTab },
customizeReaderView.apply { visible = ::shouldShowReaderViewCustomization },
openInApp.apply { visible = ::shouldShowOpenInApp },
reportSiteIssuePlaceholder,

@ -12,6 +12,11 @@ interface ToolbarMenu {
sealed class Item {
object Settings : Item()
data class RequestDesktop(val isChecked: Boolean) : Item()
/**
* Opens the current private tabs in a regular tab.
*/
object OpenInRegularTab : Item()
object FindInPage : Item()
object Share : Item()
data class Back(val viewHistory: Boolean) : Item()

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- 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/. -->
<!--
NOTE: This is a copy of ic_open_in_new.xml with the following changes:
* All widths and heights on the <vector> element are 24 instead of 18.
* A containing group with "translate" values so the image is centered vertically
and horizontally.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<group
android:translateX="3"
android:translateY="3"
>
<path
android:fillColor="?attr/textPrimary"
android:fillType="evenOdd"
android:pathData="M9,0a1.005,1.005 0,1 1,0 2.012L4.557,2.012a2.55,2.55 0,0 0,-2.547 2.547v8.883a2.55,2.55 0,0 0,2.547 2.547h8.883a2.55,2.55 0,0 0,2.547 -2.547L15.987,8.97a1.006,1.006 0,1 1,2.011 0v4.472A4.564,4.564 0,0 1,13.441 18L4.558,18A4.564,4.564 0,0 1,0 13.442L0,4.559a4.564,4.564 0,0 1,4.56 -4.56zM17,0a1,1 0,0 1,1 1v4a1,1 0,1 1,-2 0L16,3.414l-5.293,5.293a0.999,0.999 0,1 1,-1.414 -1.414L14.586,2L13,2a1,1 0,1 1,0 -2z" />
</group>
</vector>

@ -199,6 +199,8 @@
<string name="browser_menu_library">Library</string>
<!-- Browser menu toggle that requests a desktop site -->
<string name="browser_menu_desktop_site">Desktop site</string>
<!-- Browser menu button that reopens a private tab as a regular tab -->
<string name="browser_menu_open_in_regular_tab">Open in regular tab</string>
<!-- Browser menu toggle that adds a shortcut to the site on the device home screen. -->
<string name="browser_menu_add_to_homescreen">Add to Home screen</string>
<!-- Browser menu toggle that installs a Progressive Web App shortcut to the site on the device home screen. -->

Loading…
Cancel
Save