Bug 1448499 - Destroy deviceFront when destroying the toolbox;r=jryans
MozReview-Commit-ID: IMlKbiaUKu7
--- a/devtools/client/framework/toolbox.js
+++ b/devtools/client/framework/toolbox.js
@@ -66,16 +66,18 @@ loader.lazyRequireGetter(this, "SourceMa
loader.lazyRequireGetter(this, "HUDService",
"devtools/client/webconsole/hudservice", true);
loader.lazyRequireGetter(this, "viewSource",
"devtools/client/shared/view-source");
loader.lazyRequireGetter(this, "StyleSheetsFront",
"devtools/shared/fronts/stylesheets", true);
loader.lazyRequireGetter(this, "buildHarLog",
"devtools/client/netmonitor/src/har/har-builder-utils", true);
+loader.lazyRequireGetter(this, "getKnownDeviceFront",
+ "devtools/shared/fronts/device", true);
loader.lazyGetter(this, "domNodeConstants", () => {
return require("devtools/shared/dom-node-constants");
});
loader.lazyGetter(this, "registerHarOverlay", () => {
return require("devtools/client/netmonitor/src/har/toolbox-overlay").register;
});
@@ -2760,16 +2762,24 @@ Toolbox.prototype = {
outstanding.push(this.destroyPreference());
// Destroy the style sheet front.
if (this._styleSheets) {
this._styleSheets.destroy();
this._styleSheets = null;
}
+ // Destroy the device front for the current client if any.
+ // A given DeviceFront instance can cached and shared between different panels, so
+ // destroying it is the responsibility of the toolbox.
+ let deviceFront = getKnownDeviceFront(this.target.client);
+ if (deviceFront) {
+ deviceFront.destroy();
+ }
+
// Detach the thread
detachThread(this._threadClient);
this._threadClient = null;
// Unregister buttons listeners
this.toolbarButtons.forEach(button => {
if (typeof button.teardown == "function") {
// teardown arguments have already been bound in _createButtonState
--- a/devtools/shared/fronts/device.js
+++ b/devtools/shared/fronts/device.js
@@ -33,16 +33,27 @@ const DeviceFront = protocol.FrontClassW
return deferred.promise;
});
});
},
});
const _knownDeviceFronts = new WeakMap();
+/**
+ * Retrieve the device front already created for the provided client, if available.
+ */
+exports.getKnownDeviceFront = function(client) {
+ return _knownDeviceFronts.get(client);
+};
+
+/**
+ * Only one DeviceFront is created for a given client, afterwards the instance is cached
+ * and returned immediately.
+ */
exports.getDeviceFront = function(client, form) {
if (!form.deviceActor) {
return null;
}
if (_knownDeviceFronts.has(client)) {
return _knownDeviceFronts.get(client);
}