|
|
|
@ -38,13 +38,15 @@ import kotlinx.coroutines.flow.mapNotNull
|
|
|
|
|
import kotlinx.coroutines.launch
|
|
|
|
|
import kotlinx.coroutines.withContext
|
|
|
|
|
import mozilla.appservices.places.BookmarkRoot
|
|
|
|
|
import mozilla.components.browser.session.Session
|
|
|
|
|
import mozilla.components.browser.state.action.ContentAction
|
|
|
|
|
import mozilla.components.browser.state.selector.findCustomTab
|
|
|
|
|
import mozilla.components.browser.state.selector.findCustomTabOrSelectedTab
|
|
|
|
|
import mozilla.components.browser.state.selector.findTab
|
|
|
|
|
import mozilla.components.browser.state.selector.findTabOrCustomTab
|
|
|
|
|
import mozilla.components.browser.state.selector.findTabOrCustomTabOrSelectedTab
|
|
|
|
|
import mozilla.components.browser.state.selector.getNormalOrPrivateTabs
|
|
|
|
|
import mozilla.components.browser.state.selector.selectedTab
|
|
|
|
|
import mozilla.components.browser.state.state.CustomTabSessionState
|
|
|
|
|
import mozilla.components.browser.state.state.SessionState
|
|
|
|
|
import mozilla.components.browser.state.state.TabSessionState
|
|
|
|
|
import mozilla.components.browser.state.state.content.DownloadState
|
|
|
|
@ -254,7 +256,6 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Activit
|
|
|
|
|
@CallSuper
|
|
|
|
|
internal open fun initializeUI(view: View, tab: SessionState) {
|
|
|
|
|
val context = requireContext()
|
|
|
|
|
val sessionManager = context.components.core.sessionManager
|
|
|
|
|
val store = context.components.core.store
|
|
|
|
|
val activity = requireActivity() as HomeActivity
|
|
|
|
|
|
|
|
|
@ -350,7 +351,7 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Activit
|
|
|
|
|
container = view.browserLayout,
|
|
|
|
|
toolbarPosition = context.settings().toolbarPosition,
|
|
|
|
|
interactor = browserInteractor,
|
|
|
|
|
customTabSession = customTabSessionId?.let { sessionManager.findSessionById(it) },
|
|
|
|
|
customTabSession = customTabSessionId?.let { store.state.findCustomTab(it) },
|
|
|
|
|
lifecycleOwner = viewLifecycleOwner
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
@ -551,7 +552,7 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Activit
|
|
|
|
|
val directions = NavGraphDirections.actionGlobalShareFragment(
|
|
|
|
|
data = arrayOf(shareData),
|
|
|
|
|
showPage = true,
|
|
|
|
|
sessionId = getSessionById()?.id
|
|
|
|
|
sessionId = getCurrentTab()?.id
|
|
|
|
|
)
|
|
|
|
|
findNavController().navigate(directions)
|
|
|
|
|
}
|
|
|
|
@ -585,14 +586,14 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Activit
|
|
|
|
|
|
|
|
|
|
searchFeature.set(
|
|
|
|
|
feature = SearchFeature(store, customTabSessionId) { request, tabId ->
|
|
|
|
|
val parentSession = sessionManager.findSessionById(tabId)
|
|
|
|
|
val parentSession = store.state.findTabOrCustomTab(tabId)
|
|
|
|
|
val useCase = if (request.isPrivate) {
|
|
|
|
|
requireComponents.useCases.searchUseCases.newPrivateTabSearch
|
|
|
|
|
} else {
|
|
|
|
|
requireComponents.useCases.searchUseCases.newTabSearch
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (parentSession?.isCustomTabSession() == true) {
|
|
|
|
|
if (parentSession is CustomTabSessionState) {
|
|
|
|
|
useCase.invoke(request.query)
|
|
|
|
|
requireActivity().startActivity(openInFenixIntent)
|
|
|
|
|
} else {
|
|
|
|
@ -1016,7 +1017,7 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Activit
|
|
|
|
|
final override fun onViewStateRestored(savedInstanceState: Bundle?) {
|
|
|
|
|
super.onViewStateRestored(savedInstanceState)
|
|
|
|
|
savedInstanceState?.getString(KEY_CUSTOM_TAB_SESSION_ID)?.let {
|
|
|
|
|
if (requireComponents.core.sessionManager.findSessionById(it)?.customTabConfig != null) {
|
|
|
|
|
if (requireComponents.core.store.state.findCustomTab(it) != null) {
|
|
|
|
|
customTabSessionId = it
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -1054,22 +1055,18 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Activit
|
|
|
|
|
* or if it has a parent session and no more history
|
|
|
|
|
*/
|
|
|
|
|
protected open fun removeSessionIfNeeded(): Boolean {
|
|
|
|
|
getSessionById()?.let { session ->
|
|
|
|
|
getCurrentTab()?.let { session ->
|
|
|
|
|
return if (session.source == SessionState.Source.ACTION_VIEW) {
|
|
|
|
|
activity?.finish()
|
|
|
|
|
requireComponents.useCases.tabsUseCases.removeTab(session.id)
|
|
|
|
|
true
|
|
|
|
|
} else {
|
|
|
|
|
if (session.hasParentSession) {
|
|
|
|
|
// The removeTab use case does not currently select a parent session, so
|
|
|
|
|
// we are using sessionManager.remove
|
|
|
|
|
requireComponents.core.sessionManager.remove(
|
|
|
|
|
session,
|
|
|
|
|
selectParentIfExists = true
|
|
|
|
|
)
|
|
|
|
|
val hasParentSession = session is TabSessionState && session.parentId != null
|
|
|
|
|
if (hasParentSession) {
|
|
|
|
|
requireComponents.useCases.tabsUseCases.removeTab(session.id, selectParentIfExists = true)
|
|
|
|
|
}
|
|
|
|
|
// We want to return to home if this session didn't have a parent session to select.
|
|
|
|
|
val goToOverview = !session.hasParentSession
|
|
|
|
|
val goToOverview = !hasParentSession
|
|
|
|
|
!goToOverview
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -1134,19 +1131,6 @@ abstract class BaseBrowserFragment : Fragment(), UserInteractionHandler, Activit
|
|
|
|
|
(activity as HomeActivity).browsingModeManager.mode = sessionMode
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the current session.
|
|
|
|
|
*/
|
|
|
|
|
protected fun getSessionById(): Session? {
|
|
|
|
|
val sessionManager = requireComponents.core.sessionManager
|
|
|
|
|
val localCustomTabId = customTabSessionId
|
|
|
|
|
return if (localCustomTabId != null) {
|
|
|
|
|
sessionManager.findSessionById(localCustomTabId)
|
|
|
|
|
} else {
|
|
|
|
|
sessionManager.selectedSession
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@VisibleForTesting
|
|
|
|
|
internal fun getCurrentTab(): SessionState? {
|
|
|
|
|
return requireComponents.core.store.state.findCustomTabOrSelectedTab(customTabSessionId)
|
|
|
|
|