Bug 878472 - Let local debugger clients find the DebuggerServerConnection. r=past
authorDave Camp <dcamp@mozilla.com>
Mon, 03 Jun 2013 09:05:29 -0700
changeset 145306 94cae09bda18a513c06c7445d390f20943814b69
parent 145227 198e38876f7e06d49be862710f76881f79abf1d7
child 145307 52806760a6da1fe3ad78aee51fad5e4570044d54
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)
reviewerspast
bugs878472
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 878472 - Let local debugger clients find the DebuggerServerConnection. r=past
browser/devtools/debugger/test/browser_dbg_globalactor-01.js
toolkit/devtools/server/main.js
--- a/browser/devtools/debugger/test/browser_dbg_globalactor-01.js
+++ b/browser/devtools/debugger/test/browser_dbg_globalactor-01.js
@@ -22,36 +22,33 @@ function test()
          "testTabActor's actorPrefix should be used.");
       gClient.request({ to: globalActor, type: "ping" }, function(aResponse) {
         is(aResponse.pong, "pong", "Actor should respond to requests.");
         // Send another ping to see if the same actor is used.
         gClient.request({ to: globalActor, type: "ping" }, function(aResponse) {
           is(aResponse.pong, "pong", "Actor should respond to requests.");
 
           // Make sure that lazily-created actors are created only once.
-          let connections = Object.keys(DebuggerServer._connections);
-          info(connections.length + " connections are established.");
-          let connPrefix = connections[connections.length - 1];
-          ok(DebuggerServer._connections[connPrefix],
-             connPrefix + " is a valid connection.");
+          let conn = transport._serverConnection;
           // First we look for the pool of global actors.
-          let extraPools = DebuggerServer._connections[connPrefix]._extraPools;
+          let extraPools = conn._extraPools;
+
           let globalPool;
           for (let pool of extraPools) {
             if (Object.keys(pool._actors).some(function(elem) {
               // Tab actors are in the global pool.
-              let re = new RegExp(connPrefix + "tab", "g");
+              let re = new RegExp(conn._prefix + "tab", "g");
               return elem.match(re) !== null;
             })) {
               globalPool = pool;
               break;
             }
           }
           // Then we look if the global pool contains only one test actor.
-          let actorPrefix = connPrefix + "testone";
+          let actorPrefix = conn._prefix + "testone";
           let actors = Object.keys(globalPool._actors).join();
           info("Global actors: " + actors);
           isnot(actors.indexOf(actorPrefix), -1, "The test actor exists in the pool.");
           is(actors.indexOf(actorPrefix), actors.lastIndexOf(actorPrefix),
              "Only one actor exists in the pool.");
 
           finish_test();
         });
--- a/toolkit/devtools/server/main.js
+++ b/toolkit/devtools/server/main.js
@@ -262,21 +262,39 @@ var DebuggerServer = {
    *          the newly-created connection.
    */
   connectPipe: function DS_connectPipe() {
     this._checkInit();
 
     let serverTransport = new LocalDebuggerTransport;
     let clientTransport = new LocalDebuggerTransport(serverTransport);
     serverTransport.other = clientTransport;
-    this._onConnection(serverTransport);
+    let connection = this._onConnection(serverTransport);
+
+    // I'm putting this here because I trust you.
+    //
+    // There are times, when using a local connection, when you're going
+    // to be tempted to just get direct access to the server.  Resist that
+    // temptation!  If you succumb to that temptation, you will make the
+    // fine developers that work on Fennec and Firefox OS sad.  They're
+    // professionals, they'll try to act like they understand, but deep
+    // down you'll know that you hurt them.
+    //
+    // This reference allows you to give in to that temptation.  There are
+    // times this makes sense: tests, for example, and while porting a
+    // previously local-only codebase to the remote protocol.
+    //
+    // But every time you use this, you will feel the shame of having
+    // used a property that starts with a '_'.
+    clientTransport._serverConnection = connection;
 
     return clientTransport;
   },
 
+
   // nsIServerSocketListener implementation
 
   onSocketAccepted:
   makeInfallible(function DS_onSocketAccepted(aSocket, aTransport) {
     if (!this._allowConnection()) {
       return;
     }
     dumpn("New debugging connection on " + aTransport.host + ":" + aTransport.port);
@@ -313,16 +331,18 @@ var DebuggerServer = {
     let conn = new DebuggerServerConnection(connID, aTransport);
     this._connections[connID] = conn;
 
     // Create a root actor for the connection and send the hello packet.
     conn.rootActor = this.createRootActor(conn);
     conn.addActor(conn.rootActor);
     aTransport.send(conn.rootActor.sayHello());
     aTransport.ready();
+
+    return conn;
   },
 
   /**
    * Remove the connection from the debugging server.
    */
   _connectionClosed: function DS_connectionClosed(aConnection) {
     delete this._connections[aConnection.prefix];
   },