Bug 912646 - Part 1: Refactor debug targets for more reuse. r=dcamp

* * *
imported patch cleanup-target-listeners
* * *
imported patch target-cleanup
This commit is contained in:
J. Ryan Stinnett 2013-09-06 17:34:56 -05:00
parent ab62b37e1d
commit 76b1063325

View File

@ -332,6 +332,19 @@ TabTarget.prototype = {
this.tab.ownerDocument.defaultView.addEventListener("unload", this);
},
/**
* Teardown event listeners.
*/
_teardownListeners: function TabTarget__teardownListeners() {
if (this._webProgressListener) {
this._webProgressListener.destroy();
}
this._tab.ownerDocument.defaultView.removeEventListener("unload", this);
this._tab.removeEventListener("TabClose", this);
this._tab.parentNode.removeEventListener("TabSelect", this);
},
/**
* Setup listeners for remote debugging, updating existing ones as necessary.
*/
@ -358,6 +371,14 @@ TabTarget.prototype = {
this.client.addListener("tabNavigated", this._onTabNavigated);
},
/**
* Teardown listeners for remote debugging.
*/
_teardownRemoteListeners: function TabTarget__teardownRemoteListeners() {
this.client.removeListener("tabNavigated", this._onTabNavigated);
this.client.removeListener("tabDetached", this.destroy);
},
/**
* Handle tabs events.
*/
@ -412,49 +433,43 @@ TabTarget.prototype = {
this.off("thread-paused", this._handleThreadState);
if (this._tab) {
if (this._webProgressListener) {
this._webProgressListener.destroy();
}
this._tab.ownerDocument.defaultView.removeEventListener("unload", this);
this._tab.removeEventListener("TabClose", this);
this._tab.parentNode.removeEventListener("TabSelect", this);
this._teardownListeners();
}
// If this target was not remoted, the promise will be resolved before the
// function returns.
if (this._tab && !this._client) {
targets.delete(this._tab);
this._tab = null;
this._client = null;
this._form = null;
this._remote = null;
this._cleanup();
this._destroyer.resolve(null);
} else if (this._client) {
// If, on the other hand, this target was remoted, the promise will be
// resolved after the remote connection is closed.
this.client.removeListener("tabNavigated", this._onTabNavigated);
this.client.removeListener("tabDetached", this.destroy);
this._client.close(function onClosed() {
if (this._tab) {
targets.delete(this._tab);
} else {
promiseTargets.delete(this._form);
}
this._client = null;
this._tab = null;
this._form = null;
this._remote = null;
this._teardownRemoteListeners();
this._client.close(() => {
this._cleanup();
this._destroyer.resolve(null);
}.bind(this));
});
}
return this._destroyer.promise;
},
/**
* Clean up references to what this target points to.
*/
_cleanup: function TabTarget__cleanup() {
if (this._tab) {
targets.delete(this._tab);
} else {
promiseTargets.delete(this._form);
}
this._client = null;
this._tab = null;
this._form = null;
this._remote = null;
},
toString: function() {
return 'TabTarget:' + (this._tab ? this._tab : (this._form && this._form.actor));
},