diff --git a/app/src/main/java/org/mozilla/fenix/home/HomeFragment.kt b/app/src/main/java/org/mozilla/fenix/home/HomeFragment.kt index bb5bc21093..80b04c43cf 100644 --- a/app/src/main/java/org/mozilla/fenix/home/HomeFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/home/HomeFragment.kt @@ -401,7 +401,7 @@ class HomeFragment : Fragment(), CoroutineScope, AccountObserver { } } - @Suppress("ComplexMethod") + @Suppress("ComplexMethod", "NestedBlockDepth") private fun handleCollectionAction(action: CollectionAction) { when (action) { is CollectionAction.Expand -> { @@ -429,16 +429,39 @@ class HomeFragment : Fragment(), CoroutineScope, AccountObserver { } is CollectionAction.OpenTab -> { invokePendingDeleteJobs() - (activity as HomeActivity).openToBrowserAndLoad( - searchTermOrURL = action.tab.url, - newTab = true, - from = BrowserDirection.FromHome - ) + context?.let { context -> + val tabSnapshot = action.tab.restore(context, requireComponents.core.engine, action.tab) + if (tabSnapshot.isEmpty()) { + // We were unable to create a snapshot, so just load the tab instead + (activity as HomeActivity).openToBrowserAndLoad( + searchTermOrURL = action.tab.url, + newTab = true, + from = BrowserDirection.FromHome + ) + } else { + requireComponents.core.sessionManager.restore( + tabSnapshot, + true + ) + (activity as HomeActivity).openToBrowser(BrowserDirection.FromHome) + } + } } is CollectionAction.OpenTabs -> { invokePendingDeleteJobs() - action.collection.tabs.forEach { - requireComponents.useCases.tabsUseCases.addTab.invoke(it.url) + context?.let { context -> + action.collection.tabs.forEach { + val tabSnapshot = it.restore(context, requireComponents.core.engine, it) + if (tabSnapshot.isEmpty()) { + // We were unable to create a snapshot, so just load the tab instead + requireComponents.useCases.tabsUseCases.addTab.invoke(it.url) + } else { + requireComponents.core.sessionManager.restore( + tabSnapshot, + requireComponents.core.sessionManager.selectedSession == null + ) + } + } } } is CollectionAction.ShareTabs -> {