Bug 983386 - Prevent initializing canvas highlighter on loading or destroyed documents. r=pbro draft
authorAlexandre Poirot <poirot.alex@gmail.com>
Mon, 24 Oct 2016 07:52:23 -0700
changeset 429630 92a640dd85e7d186f696f4587b5039c9625a1c5e
parent 429629 ce370b7a2e5c99e05afcaff2c137ee5d60f6ca28
child 429631 f6b795f418262c045645252a2b20547a568fe546
push id33621
push userbmo:poirot.alex@gmail.com
push dateWed, 26 Oct 2016 08:49:33 +0000
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 = {