Bug 1266134 - Fix toolbox destroy when destroy-host isn't able to reach chrome code. r=jryans draft
authorAlexandre Poirot <poirot.alex@gmail.com>
Tue, 06 Sep 2016 08:19:35 -0700
changeset 410263 7da9c8df7b21eb85da6c8f3650fb3b007fc01e97
parent 410117 5a4d0c837db7f8308e3fa247f876272a5e6b96ad
child 410264 ee5226f146885f15e1f510c019307a8171647b3e
push id28705
push userbmo:poirot.alex@gmail.com
push dateTue, 06 Sep 2016 15:24:10 +0000
reviewersjryans
bugs1266134
milestone51.0a1
Bug 1266134 - Fix toolbox destroy when destroy-host isn't able to reach chrome code. r=jryans MozReview-Commit-ID: EQuDm5c7PVO
devtools/client/framework/toolbox-wrapper.js
--- a/devtools/client/framework/toolbox-wrapper.js
+++ b/devtools/client/framework/toolbox-wrapper.js
@@ -37,17 +37,17 @@ function ToolboxWrapper(target, hostType
 }
 
 ToolboxWrapper.prototype = {
   create(toolId) {
     return this.host.create()
       .then(() => {
         this.host.frame.setAttribute("aria-label", L10N.getStr("toolbox.label"));
         this.host.frame.ownerDocument.defaultView.addEventListener("message", this);
-        this.host.frame.addEventListener("unload", this);
+        this.host.frame.addEventListener("unload", this, true);
 
         let toolbox = new Toolbox(this.target, toolId, this.host.type, this.host.frame.contentWindow, this.frameId);
 
         // Prevent reloading the toolbox when loading the tools in a tab (e.g. from about:debugging)
         if (!this.host.frame.contentWindow.location.href.startsWith("about:devtools-toolbox")) {
           this.host.frame.setAttribute("src", "about:devtools-toolbox");
         }
 
@@ -56,17 +56,21 @@ ToolboxWrapper.prototype = {
   },
 
   handleEvent(event) {
     switch(event.type) {
       case "message":
         this.onMessage(event);
         break;
       case "unload":
-        if (event.target.location.href == "about:blank") {
+        // On unload, host iframe already lost its contentWindow attribute, so
+        // we can only compare against locations. Here we filter two very
+        // different cases: preliminary about:blank document as well as iframes
+        // like tool iframes.
+        if (!event.target.location.href.startsWith("about:devtools-toolbox")) {
           break;
         }
         this.destroy();
         break;
     }
   },
 
   onMessage(event) {