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/. */
7 // Hide our variables from the web content, even though the spec allows them
8 // (and the DOM) to be accessible (see bug 1474832)
10 // <video> is used for top-level audio documents as well
11 let videoElement = document.getElementsByTagName("video")[0];
13 let setFocusToVideoElement = function(e) {
14 // We don't want to retarget focus if it goes to the controls in
15 // the video element. Because they're anonymous content, the target
16 // will be the video element in that case. Avoid calling .focus()
18 if (e && e.target == videoElement) {
24 // Redirect focus to the video element whenever the document receives
26 document.addEventListener("focus", setFocusToVideoElement, true);
28 // Focus on the video in the newly created document.
29 setFocusToVideoElement();
31 // Opt out of moving focus away if the DOM tree changes (from add-on or web content)
32 let observer = new MutationObserver(() => {
33 observer.disconnect();
34 document.removeEventListener("focus", setFocusToVideoElement, true);
36 observer.observe(document.documentElement, {
41 // Handle fullscreen mode
42 document.addEventListener("keypress", ev => {
43 // Maximize the standalone video when pressing F11,
44 // but ignore audio elements
47 videoElement.videoWidth != 0 &&
48 videoElement.videoHeight != 0
50 // If we're in browser fullscreen mode, it means the user pressed F11
51 // while browser chrome or another tab had focus.
52 // Don't break leaving that mode, so do nothing here.
53 if (window.fullScreen) {
57 // If we're not in browser fullscreen mode, prevent entering into that,
58 // so we don't end up there after pressing Esc.
62 if (!document.fullscreenElement) {
63 videoElement.requestFullscreen();
65 document.exitFullscreen();