Bug 1823892 - Added option to not show 'Open in Firefox' and 'POWERED BY FIREFOX' menu items in Custom tab

fenix/113.0
t-p-white 1 year ago committed by mergify[bot]
parent 577dc4780a
commit 45a45e567b

@ -137,6 +137,7 @@ class BrowserToolbarView(
store = components.core.store,
sessionId = customTabSession?.id,
shouldReverseItems = settings.toolbarPosition == ToolbarPosition.TOP,
isSandboxCustomTab = false,
onItemTapped = {
it.performHapticIfNeeded(view)
interactor.onBrowserToolbarMenuItemTapped(it)

@ -34,6 +34,7 @@ import java.util.Locale
* @param store reference to the application's [BrowserStore].
* @param sessionId ID of the open custom tab session.
* @param shouldReverseItems If true, reverse the menu items.
* @param isSandboxCustomTab If true, menu should not show the "Open in Firefox" and "POWERED BY FIREFOX" items.
* @param onItemTapped Called when a menu item is tapped.
*/
class CustomTabToolbarMenu(
@ -41,6 +42,7 @@ class CustomTabToolbarMenu(
private val store: BrowserStore,
private val sessionId: String?,
private val shouldReverseItems: Boolean,
private val isSandboxCustomTab: Boolean,
private val onItemTapped: (ToolbarMenu.Item) -> Unit = {},
) : ToolbarMenu {
@ -116,12 +118,12 @@ class CustomTabToolbarMenu(
private val menuItems by lazy {
val menuItems = listOf(
poweredBy,
BrowserMenuDivider(),
poweredBy.apply { visible = { !isSandboxCustomTab } },
BrowserMenuDivider().apply { visible = { !isSandboxCustomTab } },
desktopMode,
findInPage,
openInApp.apply { visible = ::shouldShowOpenInApp },
openInFenix,
openInFenix.apply { visible = { !isSandboxCustomTab } },
BrowserMenuDivider(),
menuToolbar,
)

@ -25,6 +25,7 @@ class CustomTabsIntegration(
activity: Activity,
onItemTapped: (ToolbarMenu.Item) -> Unit = {},
shouldReverseItems: Boolean,
isSandboxCustomTab: Boolean,
isPrivate: Boolean,
) : LifecycleAwareFeature, UserInteractionHandler {
@ -50,6 +51,7 @@ class CustomTabsIntegration(
store,
sessionId,
shouldReverseItems,
isSandboxCustomTab,
onItemTapped = onItemTapped,
)
}

@ -20,6 +20,8 @@ import org.mozilla.fenix.NavGraphDirections
import org.mozilla.fenix.ext.components
import java.security.InvalidParameterException
const val EXTRA_IS_SANDBOX_CUSTOM_TAB = "org.mozilla.fenix.customtabs.EXTRA_IS_SANDBOX_CUSTOM_TAB"
/**
* Activity that holds the [ExternalAppBrowserFragment] that is launched within an external app,
* such as custom tabs and progressive web apps.
@ -77,6 +79,7 @@ open class ExternalAppBrowserActivity : HomeActivity() {
NavGraphDirections.actionGlobalExternalAppBrowser(
activeSessionId = customTabSessionId,
webAppManifest = manifest,
isSandboxCustomTab = intent.getBooleanExtra(EXTRA_IS_SANDBOX_CUSTOM_TAB, false),
)
else -> throw InvalidParameterException(
"Tried to navigate to ExternalAppBrowserFragment from $from",

@ -73,6 +73,7 @@ class ExternalAppBrowserFragment : BaseBrowserFragment(), UserInteractionHandler
onItemTapped = { browserToolbarInteractor.onBrowserToolbarMenuItemTapped(it) },
isPrivate = tab.content.private,
shouldReverseItems = !activity.settings().shouldUseBottomToolbar,
isSandboxCustomTab = args.isSandboxCustomTab,
),
owner = this,
view = view,

@ -102,7 +102,10 @@ fun Activity.openSetDefaultBrowserOption(
)
if (useCustomTab) {
startActivity(
SupportUtils.createCustomTabIntent(context = this, url = sumoDefaultBrowserUrl),
SupportUtils.createSandboxCustomTabIntent(
context = this,
url = sumoDefaultBrowserUrl,
),
)
} else {
(this as HomeActivity).openToBrowserAndLoad(

@ -14,6 +14,7 @@ import mozilla.components.support.ktx.android.content.getColorFromAttr
import org.mozilla.fenix.BuildConfig
import org.mozilla.fenix.IntentReceiverActivity
import org.mozilla.fenix.R
import org.mozilla.fenix.customtabs.EXTRA_IS_SANDBOX_CUSTOM_TAB
import org.mozilla.fenix.settings.account.AuthIntentReceiverActivity
import java.io.UnsupportedEncodingException
import java.net.URLEncoder
@ -114,6 +115,13 @@ object SupportUtils {
fun createAuthCustomTabIntent(context: Context, url: String): Intent =
createCustomTabIntent(context, url).setClassName(context, AuthIntentReceiverActivity::class.java.name)
/**
* Custom tab that cannot open the content in Firefox directly.
* This ensures the content is contained to this custom tab only.
*/
fun createSandboxCustomTabIntent(context: Context, url: String): Intent =
createCustomTabIntent(context, url).putExtra(EXTRA_IS_SANDBOX_CUSTOM_TAB, true)
private fun getEncodedTopicUTF8(topic: String): String {
try {
return URLEncoder.encode(topic, "UTF-8")

@ -284,6 +284,9 @@
android:name="webAppManifest"
app:argType="string"
app:nullable="true" />
<argument
android:name="isSandboxCustomTab"
app:argType="boolean" />
</fragment>
<fragment

@ -47,6 +47,7 @@ class CustomTabToolbarMenuTest {
store = store,
sessionId = firefoxCustomTab.id,
shouldReverseItems = false,
isSandboxCustomTab = false,
onItemTapped = { },
),
)

@ -26,6 +26,7 @@ import org.junit.Assert.assertTrue
import org.junit.Test
import org.junit.runner.RunWith
import org.mozilla.fenix.BrowserDirection
import org.mozilla.fenix.NavGraphDirections
import org.mozilla.fenix.browser.browsingmode.BrowsingMode
import org.mozilla.fenix.browser.browsingmode.BrowsingModeManager
import org.mozilla.fenix.ext.components
@ -93,6 +94,7 @@ class ExternalAppBrowserActivityTest {
val bundle: Bundle = mockk()
every { bundle.getString(any()) } returns ""
every { intent.extras } returns bundle
every { intent.getBooleanExtra(any(), any()) } returns false
return intent
}
},
@ -107,6 +109,76 @@ class ExternalAppBrowserActivityTest {
verify { activity.finishAndRemoveTask() }
}
@Test
fun `GIVEN intent isSandboxCustomTab is true WHEN getNavDirections called THEN actionGlobalExternalAppBrowser isSandboxCustomTab is true`() {
val activity = spyk(
object : ExternalAppBrowserActivity() {
public override fun getNavDirections(
from: BrowserDirection,
customTabSessionId: String?,
): NavDirections? {
return super.getNavDirections(from, customTabSessionId)
}
override fun getIntent(): Intent {
val intent: Intent = mockk()
val bundle: Bundle = mockk()
every { bundle.getString(any()) } returns ""
every { intent.getBooleanExtra(any(), any()) } returns true
every { intent.extras } returns bundle
return intent
}
},
)
val customTabSessionId = "id"
val directions = activity.getNavDirections(BrowserDirection.FromGlobal, customTabSessionId)
assertNotNull(directions)
verify(exactly = 0) { activity.finishAndRemoveTask() }
val expected = NavGraphDirections.actionGlobalExternalAppBrowser(
activeSessionId = customTabSessionId,
webAppManifest = null,
isSandboxCustomTab = true,
)
assertEquals(expected, directions)
}
@Test
fun `GIVEN intent isSandboxCustomTab is false WHEN getNavDirections called THEN actionGlobalExternalAppBrowser isSandboxCustomTab is false`() {
val activity = spyk(
object : ExternalAppBrowserActivity() {
public override fun getNavDirections(
from: BrowserDirection,
customTabSessionId: String?,
): NavDirections? {
return super.getNavDirections(from, customTabSessionId)
}
override fun getIntent(): Intent {
val intent: Intent = mockk()
val bundle: Bundle = mockk()
every { bundle.getString(any()) } returns ""
every { intent.getBooleanExtra(any(), any()) } returns false
every { intent.extras } returns bundle
return intent
}
},
)
val customTabSessionId = "id"
val directions = activity.getNavDirections(BrowserDirection.FromGlobal, customTabSessionId)
assertNotNull(directions)
verify(exactly = 0) { activity.finishAndRemoveTask() }
val expected = NavGraphDirections.actionGlobalExternalAppBrowser(
activeSessionId = customTabSessionId,
webAppManifest = null,
isSandboxCustomTab = false,
)
assertEquals(expected, directions)
}
@Test
fun `ExternalAppBrowserActivity with matching external tab`() {
val store = BrowserStore(

Loading…
Cancel
Save