Bug 1532993 - Use DOMHelpers to wait for iframe load in widgets/Graphs.js;r=ochameau
authorJulian Descottes <jdescottes@mozilla.com>
Fri, 12 Apr 2019 07:33:48 +0000
changeset 469245 7bd34721fb35f036eb119d42593fa22c9ad09d91
parent 469244 659c30eda4f10747540e72a9d41ed459b9234db3
child 469246 5e86cf625b5407912d483908286f464c6037ec63
push id112776
push usershindli@mozilla.com
push dateFri, 12 Apr 2019 16:20:17 +0000
treeherdermozilla-inbound@b4501ced5619 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersochameau
bugs1532993
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 1532993 - Use DOMHelpers to wait for iframe load in widgets/Graphs.js;r=ochameau Depends on D26900 Fixes the blank chart and load issues for the old perf panel in about:devtools-toolbox (or type=content) Differential Revision: https://phabricator.services.mozilla.com/D26919
devtools/client/shared/widgets/Graphs.js
--- a/devtools/client/shared/widgets/Graphs.js
+++ b/devtools/client/shared/widgets/Graphs.js
@@ -1,15 +1,16 @@
 /* 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 { setNamedTimeout } = require("devtools/client/shared/widgets/view-helpers");
 const { getCurrentZoom } = require("devtools/shared/layout/utils");
+const { DOMHelpers } = require("resource://devtools/client/shared/DOMHelpers.jsm");
 
 loader.lazyRequireGetter(this, "EventEmitter",
   "devtools/shared/event-emitter");
 
 loader.lazyImporter(this, "DevToolsWorker",
   "resource://devtools/shared/worker/worker.js");
 
 const HTML_NS = "http://www.w3.org/1999/xhtml";
@@ -1231,29 +1232,33 @@ AbstractCanvasGraph.prototype = {
  * @param Node parent
  *        The desired parent node for the iframe.
  * @param function callback
  *        Invoked once the content is loaded, with the iframe as an argument.
  */
 AbstractCanvasGraph.createIframe = function(url, parent, callback) {
   const iframe = parent.ownerDocument.createElementNS(HTML_NS, "iframe");
 
-  iframe.addEventListener("DOMContentLoaded", function() {
-    callback(iframe);
-  }, {once: true});
-
   // Setting 100% width on the frame and flex on the parent allows the graph
   // to properly shrink when the window is resized to be smaller.
   iframe.setAttribute("frameborder", "0");
   iframe.style.width = "100%";
   iframe.style.minWidth = "50px";
-  iframe.src = url;
 
   parent.style.display = "flex";
   parent.appendChild(iframe);
+
+  // Use DOMHelpers to wait for the frame load. DOMHelpers relies on chromeEventHandler
+  // so this will still work if DevTools are loaded in a content frame.
+  const domHelper = new DOMHelpers(iframe.contentWindow);
+  domHelper.onceDOMReady(function() {
+    callback(iframe);
+  });
+
+  iframe.src = url;
 };
 
 /**
  * Gets a striped pattern used as a background in selections and regions.
  *
  * @param object data
  *        The following properties are required:
  *          - ownerDocument: the nsIDocumentElement owning the canvas