Bug 1544749 - Add shared helper to retrieve the top window r=bgrins

Some classes in DevTools will not have an easy way to get access to the toolbox.
However they might still want to use the topmost chrome window.
Extract the logic from toolbox.js to a shared helper.

Differential Revision: https://phabricator.services.mozilla.com/D27672

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Julian Descottes 2019-04-18 09:06:32 +00:00
parent a15a27b2f0
commit bbcab0f303
2 changed files with 13 additions and 1 deletions

View File

@ -66,6 +66,8 @@ loader.lazyRequireGetter(this, "remoteClientManager",
"devtools/client/shared/remote-debugging/remote-client-manager.js", true);
loader.lazyRequireGetter(this, "ResponsiveUIManager",
"devtools/client/responsive.html/manager", true);
loader.lazyRequireGetter(this, "DevToolsUtils",
"devtools/shared/DevToolsUtils");
loader.lazyGetter(this, "domNodeConstants", () => {
return require("devtools/shared/dom-node-constants");
@ -387,7 +389,7 @@ Toolbox.prototype = {
* regardless of the frame type. See Bug 1539979.
*/
get topWindow() {
return this.win.windowRoot.ownerGlobal;
return DevToolsUtils.getTopWindow(this.win);
},
/**

View File

@ -812,3 +812,13 @@ function* makeDebuggeeIterator(object) {
}
exports.makeDebuggeeIterator = makeDebuggeeIterator;
/**
* Shared helper to retrieve the topmost window. This can be used to retrieve the chrome
* window embedding the DevTools frame.
*/
function getTopWindow(win) {
return win.windowRoot ? win.windowRoot.ownerGlobal : win.top;
}
exports.getTopWindow = getTopWindow;