--- a/toolkit/content/widgets/videocontrols.js
+++ b/toolkit/content/widgets/videocontrols.js
@@ -73,18 +73,16 @@ this.VideoControlsImplPageWidget = class
constructor(shadowRoot) {
this.shadowRoot = shadowRoot;
this.element = shadowRoot.host;
this.document = this.element.ownerDocument;
this.window = this.document.defaultView;
this.generateContent();
- this.randomID = 0;
-
this.Utils = {
debug: false,
video: null,
videocontrols: null,
controlBar: null,
playButton: null,
muteButton: null,
volumeControl: null,
@@ -96,17 +94,16 @@ this.VideoControlsImplPageWidget = class
statusOverlay: null,
controlsSpacer: null,
clickToPlay: null,
controlsOverlay: null,
fullscreenButton: null,
layoutControls: null,
textTracksCount: 0,
- randomID: 0,
videoEvents: ["play", "pause", "ended", "volumechange", "loadeddata",
"loadstart", "timeupdate", "progress",
"playing", "waiting", "canplay", "canplaythrough",
"seeking", "seeked", "emptied", "loadedmetadata",
"error", "suspend", "stalled",
"mozvideoonlyseekbegin", "mozvideoonlyseekcompleted"],
showHours: false,
@@ -180,19 +177,16 @@ this.VideoControlsImplPageWidget = class
/*
* Set the initial state of the controls. The binding is normally created along
* with video element, but could be attached at any point (eg, if the video is
* removed from the document and then reinserted). Thus, some one-time events may
* have already fired, and so we'll need to explicitly check the initial state.
*/
setupInitialState() {
- this.randomID = Math.random();
- this.videocontrols.randomID = this.randomID;
-
this.setPlayButtonState(this.video.paused);
this.setFullscreenButtonState();
var duration = Math.round(this.video.duration * 1000); // in ms
var currentTime = Math.round(this.video.currentTime * 1000); // in ms
this.log("Initial playback position is at " + currentTime + " of " + duration);
// It would be nice to retain maxCurrentTimeSeen, but it would be difficult
@@ -416,23 +410,16 @@ this.VideoControlsImplPageWidget = class
handleEvent(aEvent) {
if (!aEvent.isTrusted) {
this.log("Drop untrusted event ----> " + aEvent.type);
return;
}
this.log("Got event ----> " + aEvent.type);
- // If the binding is detached (or has been replaced by a
- // newer instance of the binding), nuke our event-listeners.
- if (this.videocontrols.randomID != this.randomID) {
- this.terminate();
- return;
- }
-
if (this.videoEvents.includes(aEvent.type)) {
this.handleVideoEvent(aEvent);
} else {
this.handleControlEvent(aEvent);
}
},
handleVideoEvent(aEvent) {
@@ -2042,20 +2029,16 @@ this.VideoControlsImplPageWidget = class
this.Utils.video.play();
this.firstShow = false;
}
this.toggleControls();
}
break;
}
-
- if (this.videocontrols.randomID != this.Utils.randomID) {
- this.terminate();
- }
},
terminate() {
try {
for (let { el, type, mozSystemGroup = true } of this.controlsEvents) {
el.removeEventListener(type, this, { mozSystemGroup });
}
} catch (ex) {}
@@ -2182,21 +2165,16 @@ this.VideoControlsImplPageWidget = class
</div>`, "application/xml");
this.shadowRoot.importNodeAndAppendChildAt(this.shadowRoot, parserDoc.documentElement, true);
}
destructor() {
this.Utils.terminate();
this.TouchUtils.terminate();
this.Utils.updateOrientationState(false);
- // randomID used to be a <field>, which meant that the XBL machinery
- // undefined the property when the element was unbound. The code in
- // this file actually depends on this, so now that randomID is an
- // expando, we need to make sure to explicitly delete it.
- delete this.randomID;
}
_setupEventListeners() {
this.shadowRoot.firstChild.addEventListener("mouseover", event => {
if (!this.isTouchControls) {
this.Utils.onMouseInOut(event);
}
});
@@ -2219,19 +2197,17 @@ this.NoControlsImplPageWidget = class {
constructor(shadowRoot) {
this.shadowRoot = shadowRoot;
this.element = shadowRoot.host;
this.document = this.element.ownerDocument;
this.window = this.document.defaultView;
this.generateContent();
- this.randomID = 0;
this.Utils = {
- randomID: 0,
videoEvents: ["play",
"playing",
"MozNoControlsBlockedVideo"],
terminate() {
for (let event of this.videoEvents) {
try {
this.video.removeEventListener(event, this, {
capture: true,
@@ -2245,23 +2221,16 @@ this.NoControlsImplPageWidget = class {
} catch (ex) {}
},
hasError() {
return (this.video.error != null || this.video.networkState == this.video.NETWORK_NO_SOURCE);
},
handleEvent(aEvent) {
- // If the binding is detached (or has been replaced by a
- // newer instance of the binding), nuke our event-listeners.
- if (this.videocontrols.randomID != this.randomID) {
- this.terminate();
- return;
- }
-
switch (aEvent.type) {
case "play":
this.noControlsOverlay.hidden = true;
break;
case "playing":
this.noControlsOverlay.hidden = true;
break;
case "MozNoControlsBlockedVideo":
@@ -2269,49 +2238,40 @@ this.NoControlsImplPageWidget = class {
break;
case "click":
this.clickToPlayClickHandler(aEvent);
break;
}
},
blockedVideoHandler() {
- if (this.videocontrols.randomID != this.randomID) {
- this.terminate();
- return;
- } else if (this.hasError()) {
+ if (this.hasError()) {
this.noControlsOverlay.hidden = true;
return;
}
this.noControlsOverlay.hidden = false;
},
clickToPlayClickHandler(e) {
- if (this.videocontrols.randomID != this.randomID) {
- this.terminate();
- return;
- } else if (e.button != 0) {
+ if (e.button != 0) {
return;
}
this.noControlsOverlay.hidden = true;
this.video.play();
},
init(shadowRoot) {
this.shadowRoot = shadowRoot;
this.video = shadowRoot.host;
this.videocontrols = shadowRoot.firstChild;
this.document = this.videocontrols.ownerDocument;
this.window = this.document.defaultView;
this.shadowRoot = shadowRoot;
- this.randomID = Math.random();
- this.videocontrols.randomID = this.randomID;
-
this.controlsContainer = this.shadowRoot.getElementById("controlsContainer");
this.clickToPlay = this.shadowRoot.getElementById("clickToPlay");
this.noControlsOverlay = this.shadowRoot.getElementById("controlsContainer");
let isMobile = this.window.navigator.appVersion.includes("Android");
if (isMobile) {
this.controlsContainer.classList.add("mobile");
}
@@ -2333,21 +2293,16 @@ this.NoControlsImplPageWidget = class {
}
};
this.Utils.init(this.shadowRoot);
this.Utils.video.dispatchEvent(new this.window.CustomEvent("MozNoControlsVideoBindingAttached"));
}
destructor() {
this.Utils.terminate();
- // randomID used to be a <field>, which meant that the XBL machinery
- // undefined the property when the element was unbound. The code in
- // this file actually depends on this, so now that randomID is an
- // expando, we need to make sure to explicitly delete it.
- delete this.randomID;
}
generateContent() {
/*
* Pass the markup through XML parser purely for the reason of loading the localization DTD.
* Remove it when migrate to Fluent.
*/
const parser = new this.window.DOMParser();