Bug 1277673 - Decouple the ActorActorFront and ActorRegistryFront from the ActorActor and ActorRegistryActor respectively; r=ejpbruel
authorNick Fitzgerald <fitzgen@gmail.com>
Fri, 03 Jun 2016 10:45:10 -0700
changeset 300368 c28f29acfc2a43c8cdcfbdae3c7da64166d030d9
parent 300367 9ff998641a493cd21990e500850742007c2ee3b8
child 300369 03b6ea8fded30783e73cc947b4b111e7746c12c3
push id30312
push usercbook@mozilla.com
push dateMon, 06 Jun 2016 09:55:12 +0000
treeherdermozilla-central@c37d634eba0d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersejpbruel
bugs1277673
milestone49.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 1277673 - Decouple the ActorActorFront and ActorRegistryFront from the ActorActor and ActorRegistryActor respectively; r=ejpbruel
devtools/client/inspector/markup/test/head.js
devtools/client/shared/test/test-actor-registry.js
devtools/server/actors/actor-registry.js
devtools/server/tests/browser/browser_register_actor.js
devtools/server/tests/unit/test_actor-registry-actor.js
devtools/shared/fronts/actor-registry.js
devtools/shared/fronts/moz.build
devtools/shared/specs/actor-registry.js
devtools/shared/specs/moz.build
--- a/devtools/client/inspector/markup/test/head.js
+++ b/devtools/client/inspector/markup/test/head.js
@@ -7,17 +7,17 @@
 
 // Import the inspector's head.js first (which itself imports shared-head.js).
 Services.scriptloader.loadSubScript(
   "chrome://mochitests/content/browser/devtools/client/inspector/test/head.js",
   this);
 
 var {getInplaceEditorForSpan: inplaceEditor} = require("devtools/client/shared/inplace-editor");
 var clipboard = require("sdk/clipboard");
-var {ActorRegistryFront} = require("devtools/server/actors/actor-registry");
+var {ActorRegistryFront} = require("devtools/shared/fronts/actor-registry");
 
 // If a test times out we want to see the complete log and not just the last few
 // lines.
 SimpleTest.requestCompleteLog();
 
 // Set the testing flag on DevToolsUtils and reset it when the test ends
 DevToolsUtils.testing = true;
 registerCleanupFunction(() => {
--- a/devtools/client/shared/test/test-actor-registry.js
+++ b/devtools/client/shared/test/test-actor-registry.js
@@ -20,17 +20,17 @@
 
 // Register a test actor that can operate on the remote document
   exports.registerTestActor = Task.async(function* (client) {
   // First, instanciate ActorRegistryFront to be able to dynamically
   // register an actor
     let deferred = promise.defer();
     client.listTabs(deferred.resolve);
     let response = yield deferred.promise;
-    let { ActorRegistryFront } = require("devtools/server/actors/actor-registry");
+    let { ActorRegistryFront } = require("devtools/shared/fronts/actor-registry");
     let registryFront = ActorRegistryFront(client, response);
 
   // Then ask to register our test-actor to retrieve its front
     let options = {
       type: { tab: true },
       constructor: "TestActor",
       prefix: "testActor"
     };
--- a/devtools/server/actors/actor-registry.js
+++ b/devtools/server/actors/actor-registry.js
@@ -6,121 +6,49 @@
 
 const protocol = require("devtools/shared/protocol");
 const { method, custom, Arg, Option, RetVal } = protocol;
 
 const { Cu, CC, components } = require("chrome");
 const Services = require("Services");
 const { DebuggerServer } = require("devtools/server/main");
 const { registerActor, unregisterActor } = require("devtools/server/actors/utils/actor-registry-utils");
-
-loader.lazyImporter(this, "NetUtil", "resource://gre/modules/NetUtil.jsm");
+const { actorActorSpec, actorRegistrySpec } = require("devtools/shared/specs/actor-registry");
 
 /**
  * The ActorActor gives you a handle to an actor you've dynamically
  * registered and allows you to unregister it.
  */
-const ActorActor = protocol.ActorClass({
-  typeName: "actorActor",
-
+const ActorActor = protocol.ActorClassWithSpec(actorActorSpec, {
   initialize: function (conn, options) {
     protocol.Actor.prototype.initialize.call(this, conn);
 
     this.options = options;
   },
 
-  unregister: method(function () {
+  unregister: function () {
     unregisterActor(this.options);
-  }, {
-    request: {},
-    response: {}
-  })
-});
-
-const ActorActorFront = protocol.FrontClass(ActorActor, {
-  initialize: function (client, form) {
-    protocol.Front.prototype.initialize.call(this, client, form);
   }
 });
 
-exports.ActorActorFront = ActorActorFront;
-
 /*
  * The ActorRegistryActor allows clients to define new actors on the
  * server. This is particularly useful for addons.
  */
-const ActorRegistryActor = protocol.ActorClass({
-  typeName: "actorRegistry",
-
+const ActorRegistryActor = protocol.ActorClassWithSpec(actorRegistrySpec, {
   initialize: function (conn) {
     protocol.Actor.prototype.initialize.call(this, conn);
   },
 
-  registerActor: method(function (sourceText, fileName, options) {
+  registerActor: function (sourceText, fileName, options) {
     return registerActor(sourceText, fileName, options).then(() => {
       let { constructor, type } = options;
 
       return ActorActor(this.conn, {
         name: constructor,
         tab: type.tab,
         global: type.global
       });
     });
-  }, {
-    request: {
-      sourceText: Arg(0, "string"),
-      filename: Arg(1, "string"),
-      options: Arg(2, "json")
-    },
-
-    response: {
-      actorActor: RetVal("actorActor")
-    }
-  })
+  }
 });
 
 exports.ActorRegistryActor = ActorRegistryActor;
-
-function request(uri) {
-  return new Promise((resolve, reject) => {
-    try {
-      uri = Services.io.newURI(uri, null, null);
-    } catch (e) {
-      reject(e);
-    }
-
-    NetUtil.asyncFetch({
-      uri,
-      loadUsingSystemPrincipal: true,
-    }, (stream, status, req) => {
-      if (!components.isSuccessCode(status)) {
-        reject(new Error("Request failed with status code = "
-                         + status
-                         + " after NetUtil.asyncFetch for url = "
-                         + uri));
-        return;
-      }
-
-      let source = NetUtil.readInputStreamToString(stream, stream.available());
-      stream.close();
-      resolve(source);
-    });
-  });
-}
-
-const ActorRegistryFront = protocol.FrontClass(ActorRegistryActor, {
-  initialize: function (client, form) {
-    protocol.Front.prototype.initialize.call(this, client,
-      { actor: form.actorRegistryActor });
-
-    this.manage(this);
-  },
-
-  registerActor: custom(function (uri, options) {
-    return request(uri, options)
-      .then(sourceText => {
-        return this._registerActor(sourceText, uri, options);
-      });
-  }, {
-    impl: "_registerActor"
-  })
-});
-exports.ActorRegistryFront = ActorRegistryFront;
--- a/devtools/server/tests/browser/browser_register_actor.js
+++ b/devtools/server/tests/browser/browser_register_actor.js
@@ -1,13 +1,13 @@
 var gClient;
 
 function test() {
   waitForExplicitFinish();
-  var {ActorRegistryFront} = require("devtools/server/actors/actor-registry");
+  var {ActorRegistryFront} = require("devtools/shared/fronts/actor-registry");
   var actorURL = "chrome://mochitests/content/chrome/devtools/server/tests/mochitest/hello-actor.js";
 
   if (!DebuggerServer.initialized) {
     DebuggerServer.init();
     DebuggerServer.addBrowserActors();
   }
 
   gClient = new DebuggerClient(DebuggerServer.connectPipe());
--- a/devtools/server/tests/unit/test_actor-registry-actor.js
+++ b/devtools/server/tests/unit/test_actor-registry-actor.js
@@ -5,17 +5,17 @@
  * Check that you can register new actors via the ActorRegistrationActor.
  */
 
 var gClient;
 var gRegistryFront;
 var gActorFront;
 var gOldPref;
 
-const { ActorRegistryFront } = require("devtools/server/actors/actor-registry");
+const { ActorRegistryFront } = require("devtools/shared/fronts/actor-registry");
 
 function run_test()
 {
   gOldPref = Services.prefs.getBoolPref("devtools.debugger.forbid-certified-apps");
   Services.prefs.setBoolPref("devtools.debugger.forbid-certified-apps", false);
   initTestDebuggerServer();
   DebuggerServer.addBrowserActors();
   gClient = new DebuggerClient(DebuggerServer.connectPipe());
new file mode 100644
--- /dev/null
+++ b/devtools/shared/fronts/actor-registry.js
@@ -0,0 +1,67 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+"use strict";
+
+const { components } = require("chrome");
+const Services = require("Services");
+const { actorActorSpec, actorRegistrySpec } = require("devtools/shared/specs/actor-registry");
+const protocol = require("devtools/shared/protocol");
+const { custom } = protocol;
+
+loader.lazyImporter(this, "NetUtil", "resource://gre/modules/NetUtil.jsm");
+
+const ActorActorFront = protocol.FrontClassWithSpec(actorActorSpec, {
+  initialize: function (client, form) {
+    protocol.Front.prototype.initialize.call(this, client, form);
+  }
+});
+
+exports.ActorActorFront = ActorActorFront;
+
+function request(uri) {
+  return new Promise((resolve, reject) => {
+    try {
+      uri = Services.io.newURI(uri, null, null);
+    } catch (e) {
+      reject(e);
+    }
+
+    NetUtil.asyncFetch({
+      uri,
+      loadUsingSystemPrincipal: true,
+    }, (stream, status, req) => {
+      if (!components.isSuccessCode(status)) {
+        reject(new Error("Request failed with status code = "
+                         + status
+                         + " after NetUtil.asyncFetch for url = "
+                         + uri));
+        return;
+      }
+
+      let source = NetUtil.readInputStreamToString(stream, stream.available());
+      stream.close();
+      resolve(source);
+    });
+  });
+}
+
+const ActorRegistryFront = protocol.FrontClassWithSpec(actorRegistrySpec, {
+  initialize: function (client, form) {
+    protocol.Front.prototype.initialize.call(this, client,
+                                             { actor: form.actorRegistryActor });
+
+    this.manage(this);
+  },
+
+  registerActor: custom(function (uri, options) {
+    return request(uri, options)
+      .then(sourceText => {
+        return this._registerActor(sourceText, uri, options);
+      });
+  }, {
+    impl: "_registerActor"
+  })
+});
+
+exports.ActorRegistryFront = ActorRegistryFront;
--- a/devtools/shared/fronts/moz.build
+++ b/devtools/shared/fronts/moz.build
@@ -1,15 +1,16 @@
 # -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*-
 # vim: set filetype=python:
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 DevToolsModules(
+    'actor-registry.js',
     'addons.js',
     'animation.js',
     'call-watcher.js',
     'css-properties.js',
     'highlighters.js',
     'inspector.js',
     'storage.js',
     'styles.js',
new file mode 100644
--- /dev/null
+++ b/devtools/shared/specs/actor-registry.js
@@ -0,0 +1,43 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+"use strict";
+
+const {
+  Arg,
+  RetVal,
+  generateActorSpec,
+} = require("devtools/shared/protocol");
+
+const actorActorSpec = generateActorSpec({
+  typeName: "actorActor",
+
+  methods: {
+    unregister: {
+      request: {},
+      response: {}
+    }
+  },
+});
+
+exports.actorActorSpec = actorActorSpec;
+
+const actorRegistrySpec = generateActorSpec({
+  typeName: "actorRegistry",
+
+  methods: {
+    registerActor: {
+      request: {
+        sourceText: Arg(0, "string"),
+        filename: Arg(1, "string"),
+        options: Arg(2, "json")
+      },
+
+      response: {
+        actorActor: RetVal("actorActor")
+      }
+    }
+  }
+});
+
+exports.actorRegistrySpec = actorRegistrySpec;
--- a/devtools/shared/specs/moz.build
+++ b/devtools/shared/specs/moz.build
@@ -1,15 +1,16 @@
 # -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*-
 # vim: set filetype=python:
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 DevToolsModules(
+    'actor-registry.js',
     'addons.js',
     'animation.js',
     'call-watcher.js',
     'css-properties.js',
     'heap-snapshot-file.js',
     'highlighters.js',
     'inspector.js',
     'node.js',