Files
firefox/devtools/client/responsive.html/utils/window.js
T
Kris Maglione e97c582e3f Bug 1463291: Move docShell getter from Document to Window. r=bz
DocShells are associated with outer DOM Windows, rather than Documents, so
having the getter on the document is a bit odd to begin with. But it's also
considerably less convenient, since most of the times when we want a docShell
from JS, we're dealing most directly with a window, and have to detour through
the document to get it.

MozReview-Commit-ID: LUj1H9nG3QL
2018-05-21 16:58:23 -07:00

45 lines
1.2 KiB
JavaScript

/* 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 Services = require("Services");
/**
* Returns the `nsIDOMWindow` toplevel window for any child/inner window
*/
function getToplevelWindow(window) {
return window.docShell.rootTreeItem.domWindow;
}
exports.getToplevelWindow = getToplevelWindow;
function getDOMWindowUtils(window) {
return window.windowUtils;
}
exports.getDOMWindowUtils = getDOMWindowUtils;
/**
* Check if the given browser window has finished the startup.
* @params {nsIDOMWindow} window
*/
const isStartupFinished = (window) =>
window.gBrowserInit &&
window.gBrowserInit.delayedStartupFinished;
function startup(window) {
return new Promise(resolve => {
if (isStartupFinished(window)) {
resolve(window);
return;
}
Services.obs.addObserver(function listener({ subject }) {
if (subject === window) {
Services.obs.removeObserver(listener, "browser-delayed-startup-finished");
resolve(window);
}
}, "browser-delayed-startup-finished");
});
}
exports.startup = startup;