bug 1523104: remote: s/remote-protocol/remote/g; r=ochameau

This commit is contained in:
Andreas Tolfsen 2019-02-23 15:47:10 +00:00
Родитель a91a7da5b6
Коммит bb0fed23eb
2 изменённых файлов: 53 добавлений и 51 удалений

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

@ -17,8 +17,8 @@ class ContentProcessSession {
this.docShell = docShell;
this.domains = new Domains(this, ContentProcessDomains);
this.messageManager.addMessageListener("remote-protocol:request", this);
this.messageManager.addMessageListener("remote-protocol:destroy", this);
this.messageManager.addMessageListener("remote:request", this);
this.messageManager.addMessageListener("remote:destroy", this);
this.destroy = this.destroy.bind(this);
this.content.addEventListener("unload", this.destroy);
@ -26,12 +26,12 @@ class ContentProcessSession {
destroy() {
this.content.addEventListener("unload", this.destroy);
this.messageManager.removeMessageListener("remote-protocol:request", this);
this.messageManager.removeMessageListener("remote-protocol:destroy", this);
this.messageManager.removeMessageListener("remote:request", this);
this.messageManager.removeMessageListener("remote:destroy", this);
}
async receiveMessage({ name, data }) {
const { browsingContextId } = data;
async receiveMessage({name, data}) {
const {browsingContextId} = data;
// We may have more than one tab loaded in the same process,
// and debug the two at the same time. We want to ensure not
@ -44,37 +44,39 @@ class ContentProcessSession {
}
switch (name) {
case "remote-protocol:request":
try {
const { id, domainName, methodName, params } = data.request;
const inst = this.domains.get(domainName);
const methodFn = inst[methodName];
if (!methodFn || typeof methodFn != "function") {
throw new Error(`Method implementation of ${methodName} missing`);
}
case "remote:request":
try {
const {id, domainName, methodName, params} = data.request;
const result = await methodFn.call(inst, params);
this.messageManager.sendAsyncMessage("remote-protocol:result", {
browsingContextId,
id,
result,
});
} catch (e) {
this.messageManager.sendAsyncMessage("remote-protocol:error", {
browsingContextId,
id: data.request.id,
error: {
name: e.name || "exception",
message: e.message || String(e),
stack: e.stack,
},
});
const inst = this.domains.get(domainName);
const methodFn = inst[methodName];
if (!methodFn || typeof methodFn != "function") {
throw new Error(`Method implementation of ${methodName} missing`);
}
break;
case "remote-protocol:destroy":
this.destroy();
break;
const result = await methodFn.call(inst, params);
this.messageManager.sendAsyncMessage("remote:result", {
browsingContextId,
id,
result,
});
} catch (e) {
this.messageManager.sendAsyncMessage("remote:error", {
browsingContextId,
id: data.request.id,
error: {
name: e.name || "exception",
message: e.message || String(e),
stack: e.stack,
},
});
}
break;
case "remote:destroy":
this.destroy();
break;
}
}
@ -83,7 +85,7 @@ class ContentProcessSession {
// This method is called when any Domain emit any event
// Domains register "*" listener on each instantiated Domain.
onevent(eventName, params) {
this.messageManager.sendAsyncMessage("remote-protocol:event", {
this.messageManager.sendAsyncMessage("remote:event", {
browsingContextId: this.browsingContext.id,
event: {
method: eventName,

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

@ -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.messageManager.loadFrameScript("chrome://remote/content/frame-script.js", false);
this.messageManager.addMessageListener("remote-protocol:event", this);
this.messageManager.addMessageListener("remote-protocol:result", this);
this.messageManager.addMessageListener("remote-protocol:error", this);
this.connection.onmessage = this.dispatch.bind(this);
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.messageManager.loadFrameScript("chrome://remote/content/frame-script.js", false);
}
destructor() {
this.connection.onmessage = null;
this.messageManager.sendAsyncMessage("remote-protocol:destroy", {
this.messageManager.sendAsyncMessage("remote:destroy", {
browsingContextId: this.browsingContext.id,
});
this.messageManager.removeMessageListener("remote-protocol:event", this);
this.messageManager.removeMessageListener("remote-protocol:result", this);
this.messageManager.removeMessageListener("remote-protocol:error", this);
this.messageManager.removeMessageListener("remote:event", this);
this.messageManager.removeMessageListener("remote:result", this);
this.messageManager.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-protocol:request", {
this.messageManager.sendAsyncMessage("remote:request", {
browsingContextId: this.browsingContext.id,
request: {id, domainName, methodName, params},
});
@ -73,15 +73,15 @@ class Session {
const {id, result, event, error} = data;
switch (name) {
case "remote-protocol:result":
case "remote:result":
this.connection.send({id, result});
break;
case "remote-protocol:event":
case "remote:event":
this.connection.send(event);
break;
case "remote-protocol:error":
case "remote:error":
this.connection.send({id, error: formatError(error, {stack: true})});
break;
}