ma1 pushed to branch firefox-android-115.2.1-13.0-1 at The Tor Project / Applications / firefox-android
Commits: ae8ac932 by hackademix at 2024-06-10T20:31:40+02:00 Bug 1889066 - Adds property to LoadUrlAction to determine if we should include a parentEngineSession when loading a URL r=android-reviewers,amejiamarmol [bp tb42621]
- - - - -
9 changed files:
- android-components/components/browser/state/src/main/java/mozilla/components/browser/state/action/BrowserAction.kt - android-components/components/browser/state/src/main/java/mozilla/components/browser/state/engine/middleware/CreateEngineSessionMiddleware.kt - android-components/components/browser/state/src/main/java/mozilla/components/browser/state/engine/middleware/EngineDelegateMiddleware.kt - android-components/components/browser/state/src/main/java/mozilla/components/browser/state/engine/middleware/LinkingMiddleware.kt - android-components/components/browser/state/src/test/java/mozilla/components/browser/state/engine/middleware/EngineDelegateMiddlewareTest.kt - android-components/components/browser/state/src/test/java/mozilla/components/browser/state/engine/middleware/LinkingMiddlewareTest.kt - android-components/components/feature/session/src/main/java/mozilla/components/feature/session/SessionUseCases.kt - android-components/components/feature/session/src/test/java/mozilla/components/feature/session/SessionUseCasesTest.kt - android-components/components/feature/tabs/src/main/java/mozilla/components/feature/tabs/TabsUseCases.kt
Changes:
===================================== android-components/components/browser/state/src/main/java/mozilla/components/browser/state/action/BrowserAction.kt ===================================== @@ -959,6 +959,7 @@ sealed class EngineAction : BrowserAction() { override val tabId: String, val skipLoading: Boolean = false, val followupAction: BrowserAction? = null, + val includeParent: Boolean = false, ) : EngineAction(), ActionWithTab
/** @@ -969,6 +970,7 @@ sealed class EngineAction : BrowserAction() { val url: String, val flags: EngineSession.LoadUrlFlags = EngineSession.LoadUrlFlags.none(), val additionalHeaders: Map<String, String>? = null, + val includeParent: Boolean = false, ) : EngineAction(), ActionWithTab
/** @@ -1075,6 +1077,7 @@ sealed class EngineAction : BrowserAction() { val engineSession: EngineSession, val timestamp: Long = Clock.elapsedRealtime(), val skipLoading: Boolean = false, + val includeParent: Boolean = false, ) : EngineAction(), ActionWithTab
/**
===================================== android-components/components/browser/state/src/main/java/mozilla/components/browser/state/engine/middleware/CreateEngineSessionMiddleware.kt ===================================== @@ -68,6 +68,7 @@ internal class CreateEngineSessionMiddleware( logger, store, action.tabId, + action.includeParent, )
action.followupAction?.let { @@ -84,6 +85,7 @@ private fun getOrCreateEngineSession( logger: Logger, store: Store<BrowserState, BrowserAction>, tabId: String, + includeParent: Boolean, ): EngineSession? { val tab = store.state.findTabOrCustomTab(tabId) if (tab == null) { @@ -101,7 +103,7 @@ private fun getOrCreateEngineSession( return it }
- return createEngineSession(engine, logger, store, tab) + return createEngineSession(engine, logger, store, tab, includeParent) }
@MainThread @@ -110,6 +112,7 @@ private fun createEngineSession( logger: Logger, store: Store<BrowserState, BrowserAction>, tab: SessionState, + includeParent: Boolean, ): EngineSession { val engineSession = engine.createSession(tab.content.private, tab.contextId) logger.debug("Created engine session for tab ${tab.id}") @@ -126,6 +129,7 @@ private fun createEngineSession( tab.id, engineSession, skipLoading = skipLoading, + includeParent = includeParent, ), )
===================================== android-components/components/browser/state/src/main/java/mozilla/components/browser/state/engine/middleware/EngineDelegateMiddleware.kt ===================================== @@ -60,11 +60,11 @@ internal class EngineDelegateMiddleware( // session is already pointing to. Creating an EngineSession will do exactly // that in the linking step. So let's do that. Otherwise we would load the URL // twice. - store.dispatch(EngineAction.CreateEngineSessionAction(action.tabId)) + store.dispatch(EngineAction.CreateEngineSessionAction(action.tabId, includeParent = action.includeParent)) return@launch }
- val parentEngineSession = if (tab is TabSessionState) { + val parentEngineSession = if (action.includeParent && tab is TabSessionState) { tab.parentId?.let { store.state.findTabOrCustomTab(it)?.engineState?.engineSession } } else { null
===================================== android-components/components/browser/state/src/main/java/mozilla/components/browser/state/engine/middleware/LinkingMiddleware.kt ===================================== @@ -37,7 +37,13 @@ internal class LinkingMiddleware( when (action) { is TabListAction.AddTabAction -> { if (action.tab.engineState.engineSession != null && action.tab.engineState.engineObserver == null) { - engineObserver = link(context, action.tab.engineState.engineSession, action.tab) + engineObserver = link( + context, + action.tab.engineState.engineSession, + action.tab, + skipLoading = true, + includeParent = false, + ) } } is TabListAction.AddMultipleTabsAction -> { @@ -58,7 +64,7 @@ internal class LinkingMiddleware( when (action) { is EngineAction.LinkEngineSessionAction -> { context.state.findTabOrCustomTab(action.tabId)?.let { tab -> - engineObserver = link(context, action.engineSession, tab, action.skipLoading) + engineObserver = link(context, action.engineSession, tab, action.skipLoading, action.includeParent) } } else -> { @@ -77,6 +83,7 @@ internal class LinkingMiddleware( engineSession: EngineSession, tab: SessionState, skipLoading: Boolean = true, + includeParent: Boolean, ): Pair<String, EngineObserver> { val observer = EngineObserver(tab.id, context.store) engineSession.register(observer) @@ -91,7 +98,7 @@ internal class LinkingMiddleware( // tab, but opened by an extension e.g. via browser.tabs.update. performLoadOnMainThread(engineSession, tab.content.url, loadFlags = tab.engineState.initialLoadFlags) } else { - val parentEngineSession = if (tab is TabSessionState) { + val parentEngineSession = if (includeParent && tab is TabSessionState) { tab.parentId?.let { context.state.findTabOrCustomTab(it)?.engineState?.engineSession } } else { null
===================================== android-components/components/browser/state/src/test/java/mozilla/components/browser/state/engine/middleware/EngineDelegateMiddlewareTest.kt ===================================== @@ -258,6 +258,7 @@ class EngineDelegateMiddlewareTest { EngineAction.LoadUrlAction( "test-tab", "https://www.firefox.com", + includeParent = true, ), ).joinBlocking()
===================================== android-components/components/browser/state/src/test/java/mozilla/components/browser/state/engine/middleware/LinkingMiddlewareTest.kt ===================================== @@ -91,7 +91,9 @@ class LinkingMiddlewareTest { store.dispatch(EngineAction.LinkEngineSessionAction(parent.id, parentEngineSession)).joinBlocking()
val childEngineSession: EngineSession = mock() - store.dispatch(EngineAction.LinkEngineSessionAction(child.id, childEngineSession)).joinBlocking() + store.dispatch( + EngineAction.LinkEngineSessionAction(child.id, childEngineSession, includeParent = true), + ).joinBlocking()
dispatcher.scheduler.advanceUntilIdle()
===================================== android-components/components/feature/session/src/main/java/mozilla/components/feature/session/SessionUseCases.kt ===================================== @@ -86,14 +86,8 @@ class SessionUseCases( // If we already have an engine session load Url directly to prevent // context switches. if (engineSession != null) { - val parentEngineSession = if (tab is TabSessionState) { - tab.parentId?.let { store.state.findTabOrCustomTab(it)?.engineState?.engineSession } - } else { - null - } engineSession.loadUrl( url = url, - parent = parentEngineSession, flags = flags, additionalHeaders = additionalHeaders, )
===================================== android-components/components/feature/session/src/test/java/mozilla/components/feature/session/SessionUseCasesTest.kt ===================================== @@ -128,7 +128,6 @@ class SessionUseCasesTest { middleware.assertNotDispatched(EngineAction.LoadUrlAction::class) verify(childEngineSession).loadUrl( url = "https://www.mozilla.org/en-CA/firefox/browsers/mobile/", - parent = engineSession, ) middleware.assertLastAction(EngineAction.OptimizedLoadUrlTriggeredAction::class) { action -> assertEquals("bugzilla", action.tabId)
===================================== android-components/components/feature/tabs/src/main/java/mozilla/components/feature/tabs/TabsUseCases.kt ===================================== @@ -189,6 +189,7 @@ class TabsUseCases( tab.id, url, flags, + includeParent = true, ), ) } @@ -259,6 +260,7 @@ class TabsUseCases( tab.id, url, flags, + includeParent = true, ), ) } @@ -477,6 +479,7 @@ class TabsUseCases( tab.id, url, flags, + includeParent = true, ), ) tab.id
View it on GitLab: https://gitlab.torproject.org/tpo/applications/firefox-android/-/commit/ae8a...