diff --git a/app/src/main/java/org/mozilla/fenix/browser/BaseBrowserFragment.kt b/app/src/main/java/org/mozilla/fenix/browser/BaseBrowserFragment.kt index 94af3423f1..254740e31a 100644 --- a/app/src/main/java/org/mozilla/fenix/browser/BaseBrowserFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/browser/BaseBrowserFragment.kt @@ -211,6 +211,7 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Session isPrivate = (activity as HomeActivity).browsingModeManager.mode.isPrivate ), sessionManager = requireComponents.core.sessionManager, + sessionFeature = sessionFeature, findInPageLauncher = { findInPageIntegration.withFeature { it.launch() } }, engineView = engineView, swipeRefresh = swipeRefresh, diff --git a/app/src/main/java/org/mozilla/fenix/components/toolbar/BrowserToolbarController.kt b/app/src/main/java/org/mozilla/fenix/components/toolbar/BrowserToolbarController.kt index 0e32b8316c..41795a4462 100644 --- a/app/src/main/java/org/mozilla/fenix/components/toolbar/BrowserToolbarController.kt +++ b/app/src/main/java/org/mozilla/fenix/components/toolbar/BrowserToolbarController.kt @@ -19,6 +19,8 @@ import mozilla.components.browser.session.Session import mozilla.components.browser.session.SessionManager import mozilla.components.concept.engine.EngineView import mozilla.components.concept.engine.prompt.ShareData +import mozilla.components.feature.session.SessionFeature +import mozilla.components.support.base.feature.ViewBoundFeatureWrapper import mozilla.components.support.ktx.kotlin.isUrl import org.mozilla.fenix.HomeActivity import org.mozilla.fenix.NavGraphDirections @@ -61,6 +63,7 @@ class DefaultBrowserToolbarController( private val activity: HomeActivity, private val navController: NavController, private val readerModeController: ReaderModeController, + private val sessionFeature: ViewBoundFeatureWrapper, private val sessionManager: SessionManager, private val findInPageLauncher: () -> Unit, private val engineView: EngineView, @@ -260,8 +263,10 @@ class DefaultBrowserToolbarController( } } ToolbarMenu.Item.OpenInFenix -> { - // Release the session from this view so that it can immediately be rendered by a different view - engineView.release() + // Stop the SessionFeature from updating the EngineView and let it release the session + // from the EngineView so that it can immediately be rendered by a different view once + // we switch to the actual browser. + sessionFeature.get()?.release() // Strip the CustomTabConfig to turn this Session into a regular tab and then select it customTabSession!!.customTabConfig = null diff --git a/app/src/test/java/org/mozilla/fenix/components/toolbar/DefaultBrowserToolbarControllerTest.kt b/app/src/test/java/org/mozilla/fenix/components/toolbar/DefaultBrowserToolbarControllerTest.kt index 998a842323..462c8dd3ee 100644 --- a/app/src/test/java/org/mozilla/fenix/components/toolbar/DefaultBrowserToolbarControllerTest.kt +++ b/app/src/test/java/org/mozilla/fenix/components/toolbar/DefaultBrowserToolbarControllerTest.kt @@ -33,9 +33,11 @@ import mozilla.components.browser.state.state.createTab import mozilla.components.browser.state.store.BrowserStore import mozilla.components.concept.engine.EngineView import mozilla.components.feature.search.SearchUseCases +import mozilla.components.feature.session.SessionFeature import mozilla.components.feature.session.SessionUseCases import mozilla.components.feature.tab.collections.TabCollection import mozilla.components.feature.tabs.TabsUseCases +import mozilla.components.support.base.feature.ViewBoundFeatureWrapper import mozilla.components.support.test.rule.MainCoroutineRule import org.junit.After import org.junit.Assert.assertEquals @@ -93,6 +95,8 @@ class DefaultBrowserToolbarControllerTest { @RelaxedMockK private lateinit var tabCollectionStorage: TabCollectionStorage @RelaxedMockK private lateinit var topSiteStorage: TopSiteStorage @RelaxedMockK private lateinit var readerModeController: ReaderModeController + @RelaxedMockK private lateinit var sessionFeatureWrapper: ViewBoundFeatureWrapper + @RelaxedMockK private lateinit var sessionFeature: SessionFeature private val store: BrowserStore = BrowserStore(initialState = BrowserState( listOf( createTab("https://www.mozilla.org", id = "reader-inactive-tab"), @@ -124,6 +128,7 @@ class DefaultBrowserToolbarControllerTest { every { activity.components.core.sessionManager } returns sessionManager every { activity.components.core.store } returns store every { sessionManager.selectedSession } returns currentSession + every { sessionFeatureWrapper.get() } returns sessionFeature val onComplete = slot<() -> Unit>() every { browserAnimator.captureEngineViewAndDrawStatically(capture(onComplete)) } answers { onComplete.captured.invoke() } @@ -469,7 +474,7 @@ class DefaultBrowserToolbarControllerTest { controller.handleToolbarItemInteraction(item) - verify { engineView.release() } + verify { sessionFeature.release() } verify { currentSession.customTabConfig = null } verify { sessionManager.select(currentSession) } verify { activity.startActivity(openInFenixIntent) } @@ -571,6 +576,7 @@ class DefaultBrowserToolbarControllerTest { bookmarkTapped = bookmarkTapped, readerModeController = readerModeController, sessionManager = sessionManager, + sessionFeature = sessionFeatureWrapper, onTabCounterClicked = onTabCounterClicked, onCloseTab = onCloseTab ).apply {