Bug 1544749 - Add shared helper to retrieve the top window r=bgrins
authorJulian Descottes <jdescottes@mozilla.com>
Thu, 18 Apr 2019 09:06:32 +0000
changeset 470039 46afb0a8df4b337ba5882613e51225de204642f4
parent 470038 f4de96f2d275f0bff16042ef322a69366b79cb81
child 470040 ad0f4d97dd1efd4bbbe4150f552a701e88aedbbc
push id112839
push userapavel@mozilla.com
push dateThu, 18 Apr 2019 21:50:57 +0000
treeherdermozilla-inbound@e0a826fcd85b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbgrins
bugs1544749
milestone68.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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
devtools/client/framework/toolbox.js
devtools/shared/DevToolsUtils.js
--- a/devtools/client/framework/toolbox.js
+++ b/devtools/client/framework/toolbox.js
@@ -61,16 +61,18 @@ loader.lazyRequireGetter(this, "NetMonit
 loader.lazyRequireGetter(this, "sortPanelDefinitions",
   "devtools/client/framework/toolbox-tabs-order-manager", true);
 loader.lazyRequireGetter(this, "createEditContextMenu",
   "devtools/client/framework/toolbox-context-menu", true);
 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");
 });
 
 loader.lazyGetter(this, "DEBUG_TARGET_TYPES", () => {
   return require("devtools/client/shared/remote-debugging/constants").DEBUG_TARGET_TYPES;
 });
@@ -382,17 +384,17 @@ Toolbox.prototype = {
   },
 
   /**
    * When the toolbox is loaded in a frame with type="content", win.parent will not return
    * the parent Chrome window. This getter should return the parent Chrome window
    * regardless of the frame type. See Bug 1539979.
    */
   get topWindow() {
-    return this.win.windowRoot.ownerGlobal;
+    return DevToolsUtils.getTopWindow(this.win);
   },
 
   /**
    * Shortcut to the document containing the toolbox UI
    */
   get doc() {
     return this.win.document;
   },
--- a/devtools/shared/DevToolsUtils.js
+++ b/devtools/shared/DevToolsUtils.js
@@ -807,8 +807,18 @@ function* makeDebuggeeIterator(object) {
     if (exports.getProperty(nextValue, "done")) {
       break;
     }
     yield exports.getProperty(nextValue, "value");
   }
 }
 
 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;