зеркало из https://github.com/mozilla/gecko-dev.git
bug 1537775: remote: clarify method/domain/command terminology; r=ochameau
The remote agent currently uses "method" interchangably for the full method string as extracted from JSON input as well as for the function part following the first dot after the method has been split. To avoid namespace clashes, this patch makes a distinction between method, being the input JSON field; the first substring prior to the dot being the domain; and the rest that follows being called the command: method = "<domain>.<command>" This naming seems to be supported by chrome-remote-interface: https://github.com/cyrus-and/chrome-remote-interface/blob/master/lib/api.js#L32 Differential Revision: https://phabricator.services.mozilla.com/D25946 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
8731816b89
Коммит
da5a13b347
|
@ -39,8 +39,8 @@ class Domain {
|
|||
|
||||
// static
|
||||
|
||||
static implements(methodName) {
|
||||
return typeof this.prototype[methodName] == "function";
|
||||
static implements(command) {
|
||||
return command && typeof this.prototype[command] == "function";
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -56,15 +56,15 @@ class ContentProcessSession {
|
|||
switch (name) {
|
||||
case "remote:request":
|
||||
try {
|
||||
const {id, domain, method, params} = data.request;
|
||||
const {id, domain, command, params} = data.request;
|
||||
|
||||
const inst = this.domains.get(domain);
|
||||
const methodFn = inst[method];
|
||||
if (!methodFn || typeof methodFn != "function") {
|
||||
throw new Error(`Method implementation of ${method} missing`);
|
||||
const func = inst[command];
|
||||
if (!func || typeof func != "function") {
|
||||
throw new Error(`Implementation missing: ${domain}.${command}`);
|
||||
}
|
||||
|
||||
const result = await methodFn.call(inst, params);
|
||||
const result = await func.call(inst, params);
|
||||
|
||||
this.messageManager.sendAsyncMessage("remote:result", {
|
||||
browsingContextId,
|
||||
|
|
|
@ -61,16 +61,16 @@ class Session {
|
|||
throw new TypeError("Message missing 'method' field");
|
||||
}
|
||||
|
||||
const [domainName, methodName] = Domains.splitMethod(method);
|
||||
await this.execute(id, domainName, methodName, params);
|
||||
const [domain, command] = Domains.splitMethod(method);
|
||||
await this.execute(id, domain, command, params);
|
||||
} catch (e) {
|
||||
this.onError(id, e);
|
||||
}
|
||||
}
|
||||
|
||||
async execute(id, domain, method, params) {
|
||||
async execute(id, domain, command, params) {
|
||||
const inst = this.domains.get(domain);
|
||||
const result = await inst[method](params);
|
||||
const result = await inst[command](params);
|
||||
this.onResult(id, result);
|
||||
}
|
||||
|
||||
|
|
|
@ -60,25 +60,25 @@ class TabSession extends Session {
|
|||
throw new TypeError("Message missing 'method' field");
|
||||
}
|
||||
|
||||
const [domainName, methodName] = Domains.splitMethod(method);
|
||||
if (typeof domainName == "undefined" || typeof methodName == "undefined") {
|
||||
const [domain, command] = Domains.splitMethod(method);
|
||||
if (typeof domain == "undefined" || typeof command == "undefined") {
|
||||
throw new TypeError("'method' field is incorrect and doesn't define a domain " +
|
||||
"name and method separated by a dot.");
|
||||
}
|
||||
if (this.domains.has(domainName)) {
|
||||
await this.execute(id, domainName, methodName, params);
|
||||
if (this.domains.has(domain)) {
|
||||
await this.execute(id, domain, command, params);
|
||||
} else {
|
||||
this.executeInChild(id, domainName, methodName, params);
|
||||
this.executeInChild(id, domain, command, params);
|
||||
}
|
||||
} catch (e) {
|
||||
this.onError(id, e);
|
||||
}
|
||||
}
|
||||
|
||||
executeInChild(id, domain, method, params) {
|
||||
executeInChild(id, domain, command, params) {
|
||||
this.mm.sendAsyncMessage("remote:request", {
|
||||
browsingContextId: this.browsingContext.id,
|
||||
request: {id, domain, method, params},
|
||||
request: {id, domain, command, params},
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче