Bug 878901: Create a separate client front object, RootClient, for communicating with root actors. r=dcamp
authorJim Blandy <jimb@mozilla.com>
Fri, 14 Jun 2013 13:14:29 -0700
changeset 146615 d1edee344c9875ad7b92b1942354e7b6a5ce906a
parent 146614 f0c61b755de986d2b1d0d24aad422155424be42c
child 146616 70aac30d291d141d37309bd61ed1e5bfbdcd7690
push id2697
push userbbajaj@mozilla.com
push dateMon, 05 Aug 2013 18:49:53 +0000
treeherdermozilla-beta@dfec938c7b63 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdcamp
bugs878901
milestone24.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 878901: Create a separate client front object, RootClient, for communicating with root actors. r=dcamp
toolkit/devtools/client/dbg-client.jsm
--- a/toolkit/devtools/client/dbg-client.jsm
+++ b/toolkit/devtools/client/dbg-client.jsm
@@ -7,16 +7,17 @@
 "use strict";
 const Ci = Components.interfaces;
 const Cc = Components.classes;
 const Cu = Components.utils;
 const Cr = Components.results;
 
 this.EXPORTED_SYMBOLS = ["DebuggerTransport",
                          "DebuggerClient",
+                         "RootClient",
                          "debuggerSocketConnect",
                          "LongStringClient",
                          "GripClient"];
 
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 Cu.import("resource://gre/modules/NetUtil.jsm");
 Cu.import("resource://gre/modules/Services.jsm");
 Cu.import("resource://gre/modules/commonjs/sdk/core/promise.js");
@@ -199,18 +200,16 @@ const UnsolicitedNotifications = {
 const UnsolicitedPauses = {
   "resumeLimit": "resumeLimit",
   "debuggerStatement": "debuggerStatement",
   "breakpoint": "breakpoint",
   "watchpoint": "watchpoint",
   "exception": "exception"
 };
 
-const ROOT_ACTOR_NAME = "root";
-
 /**
  * Creates a client for the remote debugging protocol server. This client
  * provides the means to communicate with the server and exchange the messages
  * required by the protocol in a traditional JavaScript API.
  */
 this.DebuggerClient = function DebuggerClient(aTransport)
 {
   this._transport = aTransport;
@@ -218,16 +217,19 @@ this.DebuggerClient = function DebuggerC
   this._threadClients = {};
   this._tabClients = {};
   this._consoleClients = {};
 
   this._pendingRequests = [];
   this._activeRequests = {};
   this._eventsEnabled = true;
 
+  /* The root actor for this client's main connection. */
+  this.mainRoot = null;
+
   this.compat = new ProtocolCompatibility(this, [
     new SourcesShim(),
   ]);
 
   this.request = this.request.bind(this);
 }
 
 /**
@@ -384,28 +386,21 @@ DebuggerClient.prototype = {
     }
 
     function closeTransport() {
       self._transport.close();
       self._transport = null;
     }
   },
 
-  /**
-   * List the open tabs.
-   *
-   * @param function aOnResponse
-   *        Called with the response packet.
+  /*
+   * This function exists only to preserve DebuggerClient's interface;
+   * new code should say 'client.mainRoot.listTabs()'.
    */
-  listTabs: DebuggerClient.requester({
-    to: ROOT_ACTOR_NAME,
-    type: "listTabs"
-  }, {
-    telemetry: "LISTTABS"
-  }),
+  listTabs: function(aOnResponse) { return this.mainRoot.listTabs(aOnResponse); },
 
   /**
    * Attach to a tab actor.
    *
    * @param string aTabActor
    *        The actor ID for the tab to attach.
    * @param function aOnResponse
    *        Called with the response packet and a TabClient
@@ -576,16 +571,17 @@ DebuggerClient.prototype = {
     let packet = aIgnoreCompatibility
       ? aPacket
       : this.compat.onPacket(aPacket);
 
     resolve(packet).then((aPacket) => {
       if (!this._connected) {
         // Hello packet.
         this._connected = true;
+        this.mainRoot = new RootClient(this, aPacket);
         this.notify("connected",
                     aPacket.applicationType,
                     aPacket.traits);
         return;
       }
 
       if (!aPacket.from) {
         let msg = "Server did not specify an actor, dropping packet: " +
@@ -876,16 +872,64 @@ TabClient.prototype = {
     },
     telemetry: "TABDETACH"
   }),
 };
 
 eventSource(TabClient.prototype);
 
 /**
+ * A RootClient object represents a root actor on the server. Each
+ * DebuggerClient keeps a RootClient instance representing the root actor
+ * for the initial connection; DebuggerClient's 'listTabs' and
+ * 'listChildProcesses' methods forward to that root actor.
+ *
+ * @param aClient object
+ *      The client connection to which this actor belongs.
+ * @param aGreeting string
+ *      The greeting packet from the root actor we're to represent.
+ *
+ * Properties of a RootClient instance:
+ *
+ * @property actor string
+ *      The name of this child's root actor.
+ * @property applicationType string
+ *      The application type, as given in the root actor's greeting packet.
+ * @property traits object
+ *      The traits object, as given in the root actor's greeting packet.
+ */
+function RootClient(aClient, aGreeting) {
+  this._client = aClient;
+  this.actor = aGreeting.from;
+  this.applicationType = aGreeting.applicationType;
+  this.traits = aGreeting.traits;
+}
+
+RootClient.prototype = {
+  constructor: RootClient,
+
+  /**
+   * List the open tabs.
+   *
+   * @param function aOnResponse
+   *        Called with the response packet.
+   */
+  listTabs: DebuggerClient.requester({ type: "listTabs" },
+                                     { telemetry: "LISTTABS" }),
+
+  /*
+   * Methods constructed by DebuggerClient.requester require these forwards
+   * on their 'this'.
+   */
+  get _transport() { return this._client._transport; },
+  get request()    { return this._client.request;    }
+};
+
+
+/**
  * Creates a thread client for the remote debugging protocol server. This client
  * is a front to the thread actor created in the server side, hiding the
  * protocol details in a traditional JavaScript API.
  *
  * @param aClient DebuggerClient
  *        The debugger client parent.
  * @param aActor string
  *        The actor ID for this thread.