summaryrefslogtreecommitdiffstats
path: root/mobile/android/chrome/geckoview/GeckoViewMediaControlChild.js
diff options
context:
space:
mode:
Diffstat (limited to 'mobile/android/chrome/geckoview/GeckoViewMediaControlChild.js')
-rw-r--r--mobile/android/chrome/geckoview/GeckoViewMediaControlChild.js74
1 files changed, 74 insertions, 0 deletions
diff --git a/mobile/android/chrome/geckoview/GeckoViewMediaControlChild.js b/mobile/android/chrome/geckoview/GeckoViewMediaControlChild.js
new file mode 100644
index 0000000000..e245eb1a5b
--- /dev/null
+++ b/mobile/android/chrome/geckoview/GeckoViewMediaControlChild.js
@@ -0,0 +1,74 @@
+/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+const { GeckoViewChildModule } = ChromeUtils.import(
+ "resource://gre/modules/GeckoViewChildModule.jsm"
+);
+
+const { XPCOMUtils } = ChromeUtils.import(
+ "resource://gre/modules/XPCOMUtils.jsm"
+);
+
+XPCOMUtils.defineLazyModuleGetters(this, {
+ MediaUtils: "resource://gre/modules/MediaUtils.jsm",
+});
+
+class GeckoViewMediaControl extends GeckoViewChildModule {
+ onInit() {
+ debug`onEnable`;
+ }
+
+ onEnable() {
+ debug`onEnable`;
+
+ addEventListener("MozDOMFullscreen:Entered", this, false);
+ addEventListener("MozDOMFullscreen:Exited", this, false);
+ }
+
+ onDisable() {
+ debug`onDisable`;
+
+ removeEventListener("MozDOMFullscreen:Entered", this);
+ removeEventListener("MozDOMFullscreen:Exited", this);
+ }
+
+ handleEvent(aEvent) {
+ debug`handleEvent: ${aEvent.type}`;
+
+ switch (aEvent.type) {
+ case "MozDOMFullscreen:Entered":
+ case "MozDOMFullscreen:Exited":
+ this.handleFullscreenChanged();
+ break;
+ }
+ }
+
+ handleFullscreenChanged() {
+ debug`handleFullscreenChanged`;
+
+ const element = content && content.document.fullscreenElement;
+ const mediaElement = MediaUtils.findMediaElement(element);
+
+ if (element && !mediaElement) {
+ // Non-media element fullscreen.
+ debug`No fullscreen media element found.`;
+ }
+
+ const message = {
+ metadata: MediaUtils.getMetadata(mediaElement) ?? {},
+ enabled: !!element,
+ };
+
+ this.messageManager.sendAsyncMessage(
+ "GeckoView:MediaControl:Fullscreen",
+ message
+ );
+ }
+}
+
+const { debug } = GeckoViewMediaControl.initLogging("GeckoViewMediaControl");
+const module = GeckoViewMediaControl.create(this);