Bug 1265730 - Decouple StyleEditorFront from StyleEditorActor;r=jryans
☠☠ backed out by 486cf151cbef ☠ ☠
authorEddy Bruel <ejpbruel@mozilla.com>
Thu, 02 Jun 2016 13:10:41 +0200
changeset 339078 b6ba2b9fbe8a89a569222914c6990a31cfbd9b56
parent 339077 58ac3bd12914f8d2d683176139e5630b4e32c2ca
child 339079 f3bdf3ebaf4cbf3bb426d10cf95e702bc8e981f4
push id6249
push userjlund@mozilla.com
push dateMon, 01 Aug 2016 13:59:36 +0000
treeherdermozilla-beta@bad9d4f5bf7e [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);
 
@@ -604,29 +596,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 +731,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;