Bug 1532993 - Use DOMHelpers to wait for iframe load in widgets/Graphs.js;r=ochameau
☠☠ backed out by 54e502f0f78e ☠ ☠
authorJulian Descottes <jdescottes@mozilla.com>
Thu, 11 Apr 2019 09:03:41 +0000
changeset 468975 f1615630af59478b0c08764d96e3268b2cbeeeb8
parent 468974 ff05581f5fe0125940697e9e3332bd84481dad98
child 468976 f7050f15a28dbe22ef9f0f73a9778db0da794fbe
push id35856
push usercsabou@mozilla.com
push dateFri, 12 Apr 2019 03:19:48 +0000
treeherdermozilla-central@940684cd1065 [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