Bug 1268134 - Setup fake toolbox host for standalone windows. r=ochameau
authorJ. Ryan Stinnett <jryans@gmail.com>
Thu, 14 Apr 2016 20:05:59 -0500
changeset 373298 073f05a135ccf1a0170f0b5e4fdcf63902ca713e
parent 373297 fac67b07571eb38f25209cc9ddc7a06d6b589433
child 373299 499739e68fada7112afe8e5a9ce4744d1e4f07e6
child 373342 1dcde4d265a4a7fdd9ad86bd216fd057670c74cb
push id10863
push userjlorenzo@mozilla.com
push dateMon, 06 Mar 2017 23:02:23 +0000
treeherdermozilla-aurora@0931190cd725 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
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.