2
0
mirror of https://github.com/fork-maintainers/iceraven-browser synced 2024-11-19 09:25:34 +00:00
5332: For https://github.com/mozilla-mobile/fenix/issues/2483 https://github.com/mozilla-mobile/fenix/issues/2629: Close tab with no history on back press and return to parent if available r=ekager a=mawen7



Co-authored-by: mawen7 <mawen7@users.noreply.github.com>
This commit is contained in:
MozLando 2019-10-23 18:20:36 +00:00
commit 961254df94

View File

@ -76,6 +76,7 @@ import org.mozilla.fenix.ext.enterToImmersiveMode
import org.mozilla.fenix.ext.metrics import org.mozilla.fenix.ext.metrics
import org.mozilla.fenix.ext.nav import org.mozilla.fenix.ext.nav
import org.mozilla.fenix.ext.requireComponents import org.mozilla.fenix.ext.requireComponents
import org.mozilla.fenix.ext.sessionsOfType
import org.mozilla.fenix.ext.settings import org.mozilla.fenix.ext.settings
import org.mozilla.fenix.ext.getRootView import org.mozilla.fenix.ext.getRootView
import org.mozilla.fenix.isInExperiment import org.mozilla.fenix.isInExperiment
@ -511,12 +512,18 @@ abstract class BaseBrowserFragment : Fragment(), BackHandler, SessionManager.Obs
} }
/** /**
* Removes the session if it was opened by an ACTION_VIEW intent. * Removes the session if it was opened by an ACTION_VIEW intent
* or if it has no more history
*/ */
protected open fun removeSessionIfNeeded(): Boolean { protected open fun removeSessionIfNeeded(): Boolean {
getSessionById()?.let { session -> getSessionById()?.let { session ->
val sessionManager = requireComponents.core.sessionManager
if (session.source == Session.Source.ACTION_VIEW) { if (session.source == Session.Source.ACTION_VIEW) {
requireComponents.core.sessionManager.remove(session) sessionManager.remove(session)
} else {
val isLastSession = sessionManager.sessionsOfType(private = session.private).count() == 1
sessionManager.remove(session, true)
return !isLastSession // Jump to tab overview if last session was removed
} }
} }
return false return false