1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
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);
|