Bug 1265730 - Decouple StyleEditorFront from StyleEditorActor;r=jryans
authorEddy Bruel <ejpbruel@mozilla.com>
Thu, 02 Jun 2016 17:42:24 +0200
changeset 341110 0979bb255f40483c20acd85843db49a4694f72f6
parent 341109 60b8c047de4c4551de50cb1f088615d49c2370c5
child 341111 fe57228e70aa503323bf177093e2cecb438a39cc
push id1183
push userraliiev@mozilla.com
push dateMon, 05 Sep 2016 20:01:49 +0000
treeherdermozilla-release@3148731bed45 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjryans
bugs1265730
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 1265730 - Decouple StyleEditorFront from StyleEditorActor;r=jryans
devtools/server/actors/styleeditor.js
devtools/shared/fronts/styleeditor.js
devtools/shared/specs/styleeditor.js
--- a/devtools/server/actors/styleeditor.js
+++ b/devtools/server/actors/styleeditor.js
@@ -12,18 +12,17 @@ Cu.import("resource://gre/modules/NetUti
 Cu.import("resource://gre/modules/FileUtils.jsm");
 
 const promise = require("promise");
 const events = require("sdk/event/core");
 const protocol = require("devtools/shared/protocol");
 const {Arg, Option, method, RetVal, types} = protocol;
 const {LongStringActor, ShortLongString} = require("devtools/server/actors/string");
 const {fetch} = require("devtools/shared/DevToolsUtils");
-const {OldStyleSheetFront} = require("devtools/shared/fronts/styleeditor");
-const {oldStyleSheetSpec} = require("devtools/shared/specs/styleeditor");
+const {oldStyleSheetSpec, styleEditorSpec} = require("devtools/shared/specs/styleeditor");
 
 loader.lazyGetter(this, "CssLogic", () => require("devtools/shared/inspector/css-logic").CssLogic);
 
 var TRANSITION_CLASS = "moz-styleeditor-transitioning";
 var TRANSITION_DURATION_MS = 500;
 var TRANSITION_RULE = "\
 :root.moz-styleeditor-transitioning, :root.moz-styleeditor-transitioning * {\
 transition-duration: " + TRANSITION_DURATION_MS + "ms !important; \
@@ -549,44 +548,37 @@ var StyleEditorFront = protocol.FrontCla
     return deferred.promise;
   },
 
   addStyleSheet: function (text) {
     return this.newStyleSheet(text);
   }
 });
 
+exports.OldStyleSheetActor = OldStyleSheetActor;
+
 /**
  * Creates a StyleEditorActor. StyleEditorActor provides remote access to the
  * stylesheets of a document.
  */
-var StyleEditorActor = exports.StyleEditorActor = protocol.ActorClass({
-  typeName: "styleeditor",
-
+var StyleEditorActor = exports.StyleEditorActor = protocol.ActorClassWithSpec(styleEditorSpec, {
   /**
    * The window we work with, taken from the parent actor.
    */
   get window() {
     return this.parentActor.window;
   },
 
   /**
    * The current content document of the window we work with.
    */
   get document() {
     return this.window.document;
   },
 
-  events: {
-    "document-load" : {
-      type: "documentLoad",
-      styleSheets: Arg(0, "array:old-stylesheet")
-    }
-  },
-
   form: function ()
   {
     return { actor: this.actorID };
   },
 
   initialize: function (conn, tabActor) {
     protocol.Actor.prototype.initialize.call(this, null);
 
@@ -603,30 +595,30 @@ var StyleEditorActor = exports.StyleEdit
   {
     this._sheets.clear();
   },
 
   /**
    * Called by client when target navigates to a new document.
    * Adds load listeners to document.
    */
-  newDocument: method(function () {
+  newDocument: function () {
     // delete previous document's actors
     this._clearStyleSheetActors();
 
     // Note: listening for load won't be necessary once
     // https://bugzilla.mozilla.org/show_bug.cgi?id=839103 is fixed
     if (this.document.readyState == "complete") {
       this._onDocumentLoaded();
     }
     else {
       this.window.addEventListener("load", this._onDocumentLoaded, false);
     }
     return {};
-  }),
+  },
 
   /**
    * Event handler for document loaded event. Add actor for each stylesheet
    * and send an event notifying of the load
    */
   _onDocumentLoaded: function (event) {
     if (event) {
       this.window.removeEventListener("load", this._onDocumentLoaded, false);
@@ -738,69 +730,36 @@ var StyleEditorActor = exports.StyleEdit
    * Create a new style sheet in the document with the given text.
    * Return an actor for it.
    *
    * @param  {object} request
    *         Debugging protocol request object, with 'text property'
    * @return {object}
    *         Object with 'styelSheet' property for form on new actor.
    */
-  newStyleSheet: method(function (text) {
+  newStyleSheet: function (text) {
     let parent = this.document.documentElement;
     let style = this.document.createElementNS("http://www.w3.org/1999/xhtml", "style");
     style.setAttribute("type", "text/css");
 
     if (text) {
       style.appendChild(this.document.createTextNode(text));
     }
     parent.appendChild(style);
 
     let actor = this._createStyleSheetActor(style.sheet);
     return actor;
-  }, {
-    request: { text: Arg(0, "string") },
-    response: { styleSheet: RetVal("old-stylesheet") }
-  })
-});
-
-/**
- * The corresponding Front object for the StyleEditorActor.
- */
-var StyleEditorFront = protocol.FrontClass(StyleEditorActor, {
-  initialize: function (client, tabForm) {
-    protocol.Front.prototype.initialize.call(this, client);
-    this.actorID = tabForm.styleEditorActor;
-    this.manage(this);
-  },
-
-  getStyleSheets: function () {
-    let deferred = promise.defer();
-
-    events.once(this, "document-load", (styleSheets) => {
-      deferred.resolve(styleSheets);
-    });
-    this.newDocument();
-
-    return deferred.promise;
-  },
-
-  addStyleSheet: function (text) {
-    return this.newStyleSheet(text);
   }
 });
 
 XPCOMUtils.defineLazyGetter(this, "DOMUtils", function () {
   return Cc["@mozilla.org/inspector/dom-utils;1"].getService(Ci.inIDOMUtils);
 });
 
 exports.StyleEditorActor = StyleEditorActor;
-exports.StyleEditorFront = StyleEditorFront;
-
-exports.OldStyleSheetActor = OldStyleSheetActor;
-exports.OldStyleSheetFront = OldStyleSheetFront;
 
 /**
  * Normalize multiple relative paths towards the base paths on the right.
  */
 function normalize(...aURLs) {
   let base = Services.io.newURI(aURLs.pop(), null, null);
   let url;
   while ((url = aURLs.pop())) {
--- a/devtools/shared/fronts/styleeditor.js
+++ b/devtools/shared/fronts/styleeditor.js
@@ -1,16 +1,19 @@
 /* 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 { ShortLongString } = require("devtools/server/actors/string");
 const { Front, FrontClassWithSpec } = require("devtools/shared/protocol");
-const { oldStyleSheetSpec } = require("devtools/shared/specs/styleeditor");
+const {
+  oldStyleSheetSpec,
+  styleEditorSpec
+} = require("devtools/shared/specs/styleeditor");
 const promise = require("promise");
 const events = require("sdk/event/core");
 
 /**
  * StyleSheetFront is the client-side counterpart to a StyleSheetActor.
  */
 const OldStyleSheetFront = FrontClassWithSpec(oldStyleSheetSpec, {
   initialize: function (conn, form, ctx, detail) {
@@ -74,8 +77,36 @@ const OldStyleSheetFront = FrontClassWit
     return this._form.styleSheetIndex;
   },
   get ruleCount() {
     return this._form.ruleCount;
   }
 });
 
 exports.OldStyleSheetFront = OldStyleSheetFront;
+
+/**
+ * The corresponding Front object for the StyleEditorActor.
+ */
+const StyleEditorFront = FrontClassWithSpec(styleEditorSpec, {
+  initialize: function (client, tabForm) {
+    Front.prototype.initialize.call(this, client);
+    this.actorID = tabForm.styleEditorActor;
+    this.manage(this);
+  },
+
+  getStyleSheets: function () {
+    let deferred = promise.defer();
+
+    events.once(this, "document-load", (styleSheets) => {
+      deferred.resolve(styleSheets);
+    });
+    this.newDocument();
+
+    return deferred.promise;
+  },
+
+  addStyleSheet: function (text) {
+    return this.newStyleSheet(text);
+  }
+});
+
+exports.StyleEditorFront = StyleEditorFront;
--- a/devtools/shared/specs/styleeditor.js
+++ b/devtools/shared/specs/styleeditor.js
@@ -33,8 +33,29 @@ const oldStyleSheetSpec = generateActorS
         text: Arg(0, "string"),
         transition: Arg(1, "boolean")
       }
     }
   }
 });
 
 exports.oldStyleSheetSpec = oldStyleSheetSpec;
+
+const styleEditorSpec = generateActorSpec({
+  typeName: "styleeditor",
+
+  events: {
+    "document-load": {
+      type: "documentLoad",
+      styleSheets: Arg(0, "array:old-stylesheet")
+    }
+  },
+
+  method: {
+    newDocument: {},
+    newStyleSheet: {
+      request: { text: Arg(0, "string") },
+      response: { styleSheet: RetVal("old-stylesheet") }
+    }
+  }
+});
+
+exports.styleEditorSpec = styleEditorSpec;