fune/browser/base/content/test/fullscreen/FullscreenFrame.jsm
Emilio Cobos Álvarez 3987c781d0 Bug 1635914 - Move active flag handling explicitly to BrowsingContext. r=nika
And have it mirror in the parent process more automatically.

The docShellIsActive setter in the browser-custom-element side needs to
be there rather than in the usual DidSet() calls because the
AsyncTabSwitcher code relies on getting an exact amount of notifications
as response to that specific setter. Not pretty, but...

BrowserChild no longer sets IsActive() on the docshell itself for OOP
iframes. This fixes bug 1679521. PresShell activeness is used to
throttle rAF as well, which handles OOP iframes nicely as well.

Differential Revision: https://phabricator.services.mozilla.com/D96072
2020-12-11 15:43:19 +00:00

105 lines
2.9 KiB
JavaScript

/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
/**
* test helper JSWindowActors used by the browser_fullscreen_api_fission.js test.
*/
var EXPORTED_SYMBOLS = ["FullscreenFrameChild"];
class FullscreenFrameChild extends JSWindowActorChild {
actorCreated() {
this.fullscreen_events = [];
}
changed() {
return new Promise(resolve => {
this.contentWindow.document.addEventListener(
"fullscreenchange",
() => resolve(),
{
once: true,
}
);
});
}
requestFullscreen() {
let doc = this.contentWindow.document;
let button = doc.createElement("button");
doc.body.appendChild(button);
return new Promise(resolve => {
button.onclick = () => {
doc.body.requestFullscreen().then(resolve);
doc.body.removeChild(button);
};
button.click();
});
}
receiveMessage(msg) {
switch (msg.name) {
case "WaitForChange":
return this.changed();
case "ExitFullscreen":
return this.contentWindow.document.exitFullscreen();
case "RequestFullscreen":
this.browsingContext.isActive = true;
return Promise.all([this.changed(), this.requestFullscreen()]);
case "CreateChild":
let child = msg.data;
let iframe = this.contentWindow.document.createElement("iframe");
iframe.allow = child.allow_fullscreen ? "fullscreen" : "";
iframe.name = child.name;
let loaded = new Promise(resolve => {
iframe.addEventListener(
"load",
() => resolve(iframe.browsingContext),
{ once: true }
);
});
iframe.src = child.url;
this.contentWindow.document.body.appendChild(iframe);
return loaded;
case "GetEvents":
return Promise.resolve(this.fullscreen_events);
case "ClearEvents":
this.fullscreen_events = [];
return Promise.resolve();
case "GetFullscreenElement":
let document = this.contentWindow.document;
let child_iframe = this.contentWindow.document.getElementsByTagName(
"iframe"
)
? this.contentWindow.document.getElementsByTagName("iframe")[0]
: null;
switch (document.fullscreenElement) {
case null:
return Promise.resolve("null");
case document:
return Promise.resolve("document");
case document.body:
return Promise.resolve("body");
case child_iframe:
return Promise.resolve("child_iframe");
default:
return Promise.resolve("other");
}
}
return Promise.reject("Unexpected Message");
}
async handleEvent(event) {
switch (event.type) {
case "fullscreenchange":
this.fullscreen_events.push(true);
break;
case "fullscreenerror":
this.fullscreen_events.push(false);
break;
}
}
}