bug 1523104: remote: destruct domain instances on closing session; r=ochameau

This commit is contained in:
Andreas Tolfsen 2019-02-23 16:12:03 +00:00
Родитель bb0fed23eb
Коммит 748084b37b
2 изменённых файлов: 46 добавлений и 14 удалений

Просмотреть файл

@ -13,29 +13,29 @@ const {formatError} = ChromeUtils.import("chrome://remote/content/Error.jsm");
class Session {
constructor(connection, target) {
this.connection = connection;
this.target = target;
this.connection.onmessage = this.dispatch.bind(this);
this.browsingContext = target.browser.browsingContext;
this.messageManager = target.browser.messageManager;
this.domains = new Domains(this, ParentProcessDomains);
this.messageManager.addMessageListener("remote:event", this);
this.messageManager.addMessageListener("remote:result", this);
this.messageManager.addMessageListener("remote:error", this);
this.mm.addMessageListener("remote:event", this);
this.mm.addMessageListener("remote:result", this);
this.mm.addMessageListener("remote:error", this);
this.messageManager.loadFrameScript("chrome://remote/content/frame-script.js", false);
this.mm.loadFrameScript("chrome://remote/content/frame-script.js", false);
}
destructor() {
this.domains.clear();
this.connection.onmessage = null;
this.messageManager.sendAsyncMessage("remote:destroy", {
this.mm.sendAsyncMessage("remote:destroy", {
browsingContextId: this.browsingContext.id,
});
this.messageManager.removeMessageListener("remote:event", this);
this.messageManager.removeMessageListener("remote:result", this);
this.messageManager.removeMessageListener("remote:error", this);
this.mm.removeMessageListener("remote:event", this);
this.mm.removeMessageListener("remote:result", this);
this.mm.removeMessageListener("remote:error", this);
}
async dispatch({id, method, params}) {
@ -58,7 +58,7 @@ class Session {
const result = await methodFn.call(inst, params);
this.connection.send({id, result});
} else {
this.messageManager.sendAsyncMessage("remote:request", {
this.mm.sendAsyncMessage("remote:request", {
browsingContextId: this.browsingContext.id,
request: {id, domainName, methodName, params},
});
@ -69,6 +69,16 @@ class Session {
}
}
get mm() {
return this.target.mm;
}
get browsingContext() {
return this.target.browsingContext;
}
// nsIMessageListener
receiveMessage({name, data}) {
const {id, result, event, error} = data;
@ -87,6 +97,8 @@ class Session {
}
}
// EventEmitter
onevent(eventName, params) {
this.connection.send({
method: eventName,

Просмотреть файл

@ -3,13 +3,33 @@
"use strict";
const {EventEmitter} = ChromeUtils.import("chrome://remote/content/EventEmitter.jsm");
const {Session} = ChromeUtils.import("chrome://remote/content/Session.jsm");
const connection = {onmessage: () => {}};
class MockTarget {
constructor() {
EventEmitter.decorate(this);
}
get browsingContext() {
return {id: 42};
}
get mm() {
return {
addMessageListener() {},
removeMessageListener() {},
loadFrameScript() {},
sendAsyncMessage() {},
};
}
}
add_test(function test_Session_destructor() {
const session = new Session(connection);
session.domains.get("Log");
const session = new Session(connection, new MockTarget());
session.domains.get("Browser");
equal(session.domains.size, 1);
session.destructor();
equal(session.domains.size, 0);