Bug 1634029 - [remote] Simplify handling of created DOMWindow's. r=remote-protocol-reviewers,maja_zf

The changes align our code to other instances of nsIWindowMediatorListener
usage in-tree, which always rely on the "load" event. Also "interactive"
isn't a ready state a XULWindow can ever be in, it's only used for content
windows.

Differential Revision: https://phabricator.services.mozilla.com/D73043
This commit is contained in:
Henrik Skupin 2020-04-30 04:30:33 +00:00
parent 06d9e227d0
commit 9f2bbf709c
2 changed files with 18 additions and 25 deletions

View File

@ -5,7 +5,6 @@
"use strict";
var EXPORTED_SYMBOLS = [
"DOMContentLoadedPromise",
"EventPromise",
"executeSoon",
"MessagePromise",
@ -98,16 +97,6 @@ function executeSoon(fn) {
Services.tm.dispatchToMainThread(fn);
}
function DOMContentLoadedPromise(window, options = { mozSystemGroup: true }) {
if (
window.document.readyState == "complete" ||
window.document.readyState == "interactive"
) {
return Promise.resolve();
}
return new EventPromise(window, "DOMContentLoaded", options);
}
/**
* Awaits a single IPC message.
*

View File

@ -6,9 +6,7 @@
var EXPORTED_SYMBOLS = ["TabObserver"];
const { DOMContentLoadedPromise } = ChromeUtils.import(
"chrome://remote/content/Sync.jsm"
);
const { EventPromise } = ChromeUtils.import("chrome://remote/content/Sync.jsm");
const { EventEmitter } = ChromeUtils.import(
"resource://gre/modules/EventEmitter.jsm"
);
@ -41,8 +39,8 @@ class WindowObserver {
async start() {
if (this.registerExisting) {
for (const window of Services.wm.getEnumerator("navigator:browser")) {
await this.onOpenDOMWindow(window);
for (const win of Services.wm.getEnumerator("navigator:browser")) {
this.onOpenDOMWindow(win);
}
}
@ -53,15 +51,26 @@ class WindowObserver {
Services.wm.removeListener(this);
}
async onOpenDOMWindow(window) {
await new DOMContentLoadedPromise(window);
this.emit("open", window);
onOpenDOMWindow(win) {
this.emit("open", win);
}
// nsIWindowMediatorListener
async onOpenWindow(xulWindow) {
await this.onOpenDOMWindow(xulWindow.docShell.domWindow);
const win = xulWindow.docShell.domWindow;
await new EventPromise(win, "load");
// Return early if it's not a browser window
if (
win.document.documentElement.getAttribute("windowtype") !=
"navigator:browser"
) {
return;
}
this.onOpenDOMWindow(win);
}
onCloseWindow(xulWindow) {
@ -124,11 +133,6 @@ class TabObserver {
// WindowObserver
async onWindowOpen(eventName, window) {
// Return early if it's not a browser window
if (!window.gBrowser) {
return;
}
for (const tab of window.gBrowser.tabs) {
// a missing linkedBrowser means the tab is still initialising,
// and a TabOpen event will fire once it is ready