Bug 1827583 - Set event listener to current media control after switching process. r=geckoview-reviewers,amejiamarmol,jonalmeida

This issue is a timing issue of loading content via about:config etc.

Although `GeckoViewMediaControl` registers event listeners for
`MediaController` when enabling `MediaSessionDelegate`, if process
switching occurs, `browsingContenxt` and `MediaController` are re-created.

It means that we has to register newer `MediaController`.

To detect destroying current browser, I will add `onDestroyBrowser` to
`GeckoViewModule` again (This was removed by bug 1672262).

Differential Revision: https://phabricator.services.mozilla.com/D179177
This commit is contained in:
Makoto Kato 2023-05-30 23:57:40 +00:00
Родитель 2fa61e06de
Коммит 7af39f7f34
4 изменённых файлов: 59 добавлений и 13 удалений

Просмотреть файл

@ -403,6 +403,9 @@ class ModuleInfo {
* Called before the browser is removed * Called before the browser is removed
*/ */
onDestroyBrowser() { onDestroyBrowser() {
if (this._impl) {
this._impl.onDestroyBrowser();
}
this._contentModuleLoaded = false; this._contentModuleLoaded = false;
} }

Просмотреть файл

@ -996,4 +996,36 @@ class MediaSessionTest : BaseSessionTest() {
session.evaluateJS("document.querySelector('video').requestFullscreen()") session.evaluateJS("document.querySelector('video').requestFullscreen()")
sessionRule.waitForResult(resultFullscreen) sessionRule.waitForResult(resultFullscreen)
} }
@Test
fun switchingProcess() {
// TODO: bug 1810736
assumeThat(sessionRule.env.isIsolatedProcess, equalTo(false))
sessionRule.setPrefsUntilTestEnd(
mapOf(
"media.autoplay.default" to 0,
),
)
mainSession.loadUri("about:blank")
sessionRule.waitForPageStop()
mainSession.loadTestPath(VIDEO_WEBM_PATH)
sessionRule.waitForPageStop()
val onPlayCalled = GeckoResult<Void>()
mainSession.delegateUntilTestEnd(object : MediaSession.Delegate {
@AssertCalled(count = 1)
override fun onPlay(
session: GeckoSession,
mediaSession: MediaSession,
) {
onPlayCalled.complete(null)
}
})
mainSession.evaluateJS("document.querySelector('video').play()")
sessionRule.waitForResult(onPlayCalled)
}
} }

Просмотреть файл

@ -9,12 +9,8 @@ export class GeckoViewMediaControl extends GeckoViewModule {
debug`onInit`; debug`onInit`;
} }
onEnable() { onInitBrowser() {
debug`onEnable`; debug`onInitBrowser`;
if (this.controller.isActive) {
this.handleActivated();
}
const options = { const options = {
mozSystemGroup: true, mozSystemGroup: true,
@ -27,6 +23,25 @@ export class GeckoViewMediaControl extends GeckoViewModule {
this.controller.addEventListener("positionstatechange", this, options); this.controller.addEventListener("positionstatechange", this, options);
this.controller.addEventListener("metadatachange", this, options); this.controller.addEventListener("metadatachange", this, options);
this.controller.addEventListener("playbackstatechange", this, options); this.controller.addEventListener("playbackstatechange", this, options);
}
onDestroyBrowser() {
debug`onDestroyBrowser`;
this.controller.removeEventListener("activated", this);
this.controller.removeEventListener("deactivated", this);
this.controller.removeEventListener("supportedkeyschange", this);
this.controller.removeEventListener("positionstatechange", this);
this.controller.removeEventListener("metadatachange", this);
this.controller.removeEventListener("playbackstatechange", this);
}
onEnable() {
debug`onEnable`;
if (this.controller.isActive) {
this.handleActivated();
}
this.registerListener([ this.registerListener([
"GeckoView:MediaSession:Play", "GeckoView:MediaSession:Play",
@ -45,13 +60,6 @@ export class GeckoViewMediaControl extends GeckoViewModule {
onDisable() { onDisable() {
debug`onDisable`; debug`onDisable`;
this.controller.removeEventListener("activated", this);
this.controller.removeEventListener("deactivated", this);
this.controller.removeEventListener("supportedkeyschange", this);
this.controller.removeEventListener("positionstatechange", this);
this.controller.removeEventListener("metadatachange", this);
this.controller.removeEventListener("playbackstatechange", this);
this.unregisterListener(); this.unregisterListener();
} }

Просмотреть файл

@ -60,6 +60,9 @@ export class GeckoViewModule {
// Override to initialize the browser before it is bound to the window. // Override to initialize the browser before it is bound to the window.
onInitBrowser() {} onInitBrowser() {}
// Override to cleanup when the browser is destroyed.
onDestroyBrowser() {}
// Override to initialize module. // Override to initialize module.
onInit() {} onInit() {}