Bug 1266134 - Fix toolbox destroy when destroy-host isn't able to reach chrome code. r=jryans
MozReview-Commit-ID: EQuDm5c7PVO
--- 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) {