1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 import { GeckoViewActorChild } from "resource://gre/modules/GeckoViewActorChild.sys.mjs";
9 ChromeUtils.defineESModuleGetters(lazy, {
10 MediaUtils: "resource://gre/modules/MediaUtils.sys.mjs",
11 setTimeout: "resource://gre/modules/Timer.sys.mjs",
14 export class MediaControlDelegateChild extends GeckoViewActorChild {
16 debug`handleEvent: ${aEvent.type}`;
18 switch (aEvent.type) {
19 case "MozDOMFullscreen:Entered":
20 case "MozDOMFullscreen:Exited":
21 this.handleFullscreenChanged(true);
26 async handleFullscreenChanged(retry) {
27 debug`handleFullscreenChanged`;
29 const element = this.document.fullscreenElement;
30 const mediaElement = lazy.MediaUtils.findMediaElement(element);
32 if (element && !mediaElement) {
33 // Non-media element fullscreen.
34 debug`No fullscreen media element found.`;
37 const activated = await this.eventDispatcher.sendRequestForResult({
38 type: "GeckoView:MediaSession:Fullscreen",
39 metadata: lazy.MediaUtils.getMetadata(mediaElement) ?? {},
45 if (retry && element) {
46 // When media session is going to active, we have a race condition of
47 // full screen event because media session will be activated by full
49 // So we retry to call media session delegate for this situation.
50 lazy.setTimeout(() => {
51 this.handleFullscreenChanged(false);
57 const { debug } = MediaControlDelegateChild.initLogging(
58 "MediaControlDelegateChild"