Bug 983386 - Prevent initializing canvas highlighter on loading or destroyed documents. r=pbro
authorAlexandre Poirot <poirot.alex@gmail.com>
Mon, 24 Oct 2016 07:52:23 -0700
changeset 319753 892b7c6952f6dd0216ced9507ca1a735b8fa211f
parent 319752 27d928074eae4d08687e4594c7855285edd85eea
child 319754 0bab744bba82fed941beadf4416ef01c30f54abf
push id20748
push userphilringnalda@gmail.com
push dateFri, 28 Oct 2016 03:39:55 +0000
treeherderfx-team@715360440695 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspbro
bugs983386
milestone52.0a1
Bug 983386 - Prevent initializing canvas highlighter on loading or destroyed documents. r=pbro MozReview-Commit-ID: 3Pa3r3HTyE7
devtools/server/actors/highlighters.js
devtools/server/actors/highlighters/utils/markup.js
--- a/devtools/server/actors/highlighters.js
+++ b/devtools/server/actors/highlighters.js
@@ -191,17 +191,19 @@ var HighlighterActor = exports.Highlight
       this._highlighter.hide();
     }
   },
 
   /**
    * Hide the box model highlighting if it was shown before
    */
   hideBoxModel: function () {
-    this._highlighter.hide();
+    if (this._highlighter) {
+      this._highlighter.hide();
+    }
   },
 
   /**
    * Returns `true` if the event was dispatched from a window included in
    * the current highlighter environment; or if the highlighter environment has
    * chrome privileges
    *
    * The method is specifically useful on B2G, where we do not want that events
--- a/devtools/server/actors/highlighters/utils/markup.js
+++ b/devtools/server/actors/highlighters/utils/markup.js
@@ -237,17 +237,22 @@ exports.createNode = createNode;
 function CanvasFrameAnonymousContentHelper(highlighterEnv, nodeBuilder) {
   this.highlighterEnv = highlighterEnv;
   this.nodeBuilder = nodeBuilder;
   this.anonymousContentDocument = this.highlighterEnv.document;
   // XXX the next line is a wallpaper for bug 1123362.
   this.anonymousContentGlobal = Cu.getGlobalForObject(
                                 this.anonymousContentDocument);
 
-  this._insert();
+  // Only try to create the highlighter when the document is loaded,
+  // otherwise, wait for the navigate event to fire.
+  let doc = this.highlighterEnv.document;
+  if (doc.documentElement && doc.readyState != "uninitialized") {
+    this._insert();
+  }
 
   this._onNavigate = this._onNavigate.bind(this);
   this.highlighterEnv.on("navigate", this._onNavigate);
 
   this.listeners = new Map();
 }
 
 CanvasFrameAnonymousContentHelper.prototype = {