1
0
Fork 0
5332: For #2483 #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>
master
MozLando 2019-10-23 18:20:36 +00:00
commit cc9ee5a3d8
1 changed files with 9 additions and 2 deletions

View File

@ -76,6 +76,7 @@ import org.mozilla.fenix.ext.enterToImmersiveMode
import org.mozilla.fenix.ext.metrics
import org.mozilla.fenix.ext.nav
import org.mozilla.fenix.ext.requireComponents
import org.mozilla.fenix.ext.sessionsOfType
import org.mozilla.fenix.ext.settings
import org.mozilla.fenix.ext.getRootView
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 {
getSessionById()?.let { session ->
val sessionManager = requireComponents.core.sessionManager
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