Bug 1268134 - Setup fake toolbox host for standalone windows. r=ochameau draft
authorJ. Ryan Stinnett <jryans@gmail.com>
Thu, 14 Apr 2016 20:05:59 -0500
changeset 487699 bd457cb09af483ba3c2ce7c3bec26e638fee6dbd
parent 487698 8570d3c1d337db47140a00040a386154e532a412
child 488194 f4ff61096b02489a2c740b63e8beb4c3ea928bd6
child 488226 7813df8159ae3669926129277d59ba36c74311b7
child 488755 eccedb86a73f94be1d97ccd8fcc1f7ea45e2385c
push id46299
push userbmo:jryans@gmail.com
push dateWed, 22 Feb 2017 00:00:11 +0000
reviewersochameau
bugs1268134
milestone54.0a1
Bug 1268134 - Setup fake toolbox host for standalone windows. r=ochameau MozReview-Commit-ID: CHzE4EdVkBR
devtools/client/framework/toolbox-init.js
--- a/devtools/client/framework/toolbox-init.js
+++ b/devtools/client/framework/toolbox-init.js
@@ -1,12 +1,14 @@
 /* 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/. */
 
+/* eslint-env browser */
+
 "use strict";
 
 // URL constructor doesn't support about: scheme
 let href = window.location.href.replace("about:", "http://");
 let url = new window.URL(href);
 
 // Only use this method to attach the toolbox if some query parameters are given
 if (url.search.length > 1) {
@@ -21,16 +23,33 @@ if (url.search.length > 1) {
   const { DebuggerClient } = require("devtools/shared/client/main");
   const { Task } = require("devtools/shared/task");
 
   // `host` is the frame element loading the toolbox.
   let host = window.QueryInterface(Ci.nsIInterfaceRequestor)
                    .getInterface(Ci.nsIDOMWindowUtils)
                    .containerElement;
 
+  // If there's no containerElement (which happens when loading about:devtools-toolbox as
+  // a top level document), use the current window.
+  if (!host) {
+    host = {
+      contentWindow: window,
+      contentDocument: document,
+      // toolbox-host-manager.js wants to set attributes on the frame that contains it,
+      // but that is fine to skip and doesn't make sense when using the current window.
+      setAttribute() {},
+      ownerDocument: document,
+      // toolbox-host-manager.js wants to listen for unload events from outside the frame,
+      // but this is fine to skip since the toolbox code listens inside the frame as well,
+      // and there is no outer document in this case.
+      addEventListener() {},
+    };
+  }
+
   // Specify the default tool to open
   let tool = url.searchParams.get("tool");
 
   Task.spawn(function* () {
     let target;
     if (url.searchParams.has("target")) {
       // Attach toolbox to a given browser iframe (<xul:browser> or <html:iframe
       // mozbrowser>) whose reference is set on the host iframe.