Bug 1563689 - Release DOM event listeners set on top level windows. r=remote-protocol-reviewers,jdescottes

Differential Revision: https://phabricator.services.mozilla.com/D38205

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Alexandre Poirot 2019-07-18 09:48:18 +00:00
parent 3342beba03
commit 6deb23fefc
2 changed files with 21 additions and 13 deletions

View File

@ -66,10 +66,6 @@ class RemoteAgentClass {
// an unregisterPathHandler method on nsHttpServer.
delete this.server._handler._overridePaths[target.path];
});
// Start watching for targets *after* registering the target listeners
// as this will fire event for already-existing targets.
await this.targets.watchForTargets();
}
get listening() {
@ -97,6 +93,10 @@ class RemoteAgentClass {
await this.init();
// Start watching for targets *after* registering the target listeners
// as this will fire event for already-existing targets.
await this.targets.watchForTargets();
try {
// Immediatly instantiate the main process target in order
// to be accessible via HTTP endpoint on startup

View File

@ -94,6 +94,8 @@ class TabObserver {
EventEmitter.decorate(this);
this.onWindowOpen = this.onWindowOpen.bind(this);
this.onWindowClose = this.onWindowClose.bind(this);
this.onTabOpen = this.onTabOpen.bind(this);
this.onTabClose = this.onTabClose.bind(this);
}
async start() {
@ -106,14 +108,19 @@ class TabObserver {
this.windows.off("open", this.onWindowOpen);
this.windows.off("close", this.onWindowClose);
this.windows.stop();
// Stop listening for events on still opened windows
for (const window of Services.wm.getEnumerator("navigator:browser")) {
this.onWindowClose(window);
}
}
onTabOpen(tab) {
this.emit("open", tab);
onTabOpen({ target }) {
this.emit("open", target);
}
onTabClose(tab) {
this.emit("close", tab);
onTabClose({ target }) {
this.emit("close", target);
}
// WindowObserver
@ -129,16 +136,17 @@ class TabObserver {
if (!tab.linkedBrowser) {
continue;
}
this.onTabOpen(tab);
this.onTabOpen({ target: tab });
}
window.addEventListener("TabOpen", ({ target }) => this.onTabOpen(target));
window.addEventListener("TabClose", ({ target }) =>
this.onTabClose(target)
);
window.addEventListener("TabOpen", this.onTabOpen);
window.addEventListener("TabClose", this.onTabClose);
}
onWindowClose(window) {
// TODO(ato): Is TabClose fired when the window closes?
window.removeEventListener("TabOpen", this.onTabOpen);
window.removeEventListener("TabClose", this.onTabClose);
}
}