bug 1537775: remote: clarify method/domain/command terminology; r=ochameau
authorAndreas Tolfsen <ato@sny.no>
Thu, 04 Apr 2019 11:35:24 +0000
changeset 467983 28eb8a6b33f63322188eb1ca0e4bcb3b3fb43432
parent 467982 95484a7dc30b364232a5cc905bdfdf4f665d369b
child 467984 2bccb12b0ee60033ee4555d7ef6fdf26970d0a89
push id112667
push useraiakab@mozilla.com
push dateThu, 04 Apr 2019 16:12:45 +0000
treeherdermozilla-inbound@230bb363f2f3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersochameau
bugs1537775
milestone68.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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
remote/domains/Domain.jsm
remote/sessions/ContentProcessSession.jsm
remote/sessions/Session.jsm
remote/sessions/TabSession.jsm
--- a/remote/domains/Domain.jsm
+++ b/remote/domains/Domain.jsm
@@ -34,18 +34,18 @@ class Domain {
     if (typeof listener != "function" && !isEventHandler(listener)) {
       throw new TypeError();
     }
     this.eventListeners_.add(listener);
   }
 
   // static
 
-  static implements(methodName) {
-    return typeof this.prototype[methodName] == "function";
+  static implements(command) {
+    return command && typeof this.prototype[command] == "function";
   }
 }
 
 function isEventHandler(listener) {
   return listener &&
       "onEvent" in listener &&
       typeof listener.onEvent == "function";
 }
--- a/remote/sessions/ContentProcessSession.jsm
+++ b/remote/sessions/ContentProcessSession.jsm
@@ -51,25 +51,25 @@ class ContentProcessSession {
     // the two message managers.
     if (browsingContextId != this.browsingContext.id) {
       return;
     }
 
     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,
           id,
           result,
         });
       } catch (e) {
         this.messageManager.sendAsyncMessage("remote:error", {
--- a/remote/sessions/Session.jsm
+++ b/remote/sessions/Session.jsm
@@ -56,26 +56,26 @@ class Session {
     try {
       if (typeof id == "undefined") {
         throw new TypeError("Message missing 'id' field");
       }
       if (typeof method == "undefined") {
         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);
   }
 
   onResult(id, result) {
     this.connection.send({
       id,
       sessionId: this.id,
       result,
--- a/remote/sessions/TabSession.jsm
+++ b/remote/sessions/TabSession.jsm
@@ -55,35 +55,35 @@ class TabSession extends Session {
     try {
       if (typeof id == "undefined") {
         throw new TypeError("Message missing 'id' field");
       }
       if (typeof method == "undefined") {
         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},
     });
   }
 
   onResult(id, result) {
     super.onResult(id, result);
 
     // When `Target.sendMessageToTarget` is used, we should forward the responses
     // to the parent session from which we called `sendMessageToTarget`.