diff --git a/devtools/server/actors/styleeditor.js b/devtools/server/actors/styleeditor.js index 250c6634195f..1abf2fda85cd 100644 --- a/devtools/server/actors/styleeditor.js +++ b/devtools/server/actors/styleeditor.js @@ -17,7 +17,8 @@ const protocol = require("devtools/shared/protocol"); const {Arg, Option, method, RetVal, types} = protocol; const {LongStringActor} = require("devtools/server/actors/string"); const {fetch} = require("devtools/shared/DevToolsUtils"); -const {oldStyleSheetSpec, styleEditorSpec} = require("devtools/shared/specs/styleeditor"); +const {OldStyleSheetFront} = require("devtools/shared/fronts/styleeditor"); +const {oldStyleSheetSpec} = require("devtools/shared/specs/styleeditor"); loader.lazyGetter(this, "CssLogic", () => require("devtools/shared/inspector/css-logic").CssLogic); @@ -553,13 +554,13 @@ var StyleEditorFront = protocol.FrontClass(StyleEditorActor, { } }); -exports.OldStyleSheetActor = OldStyleSheetActor; - /** * Creates a StyleEditorActor. StyleEditorActor provides remote access to the * stylesheets of a document. */ -var StyleEditorActor = exports.StyleEditorActor = protocol.ActorClassWithSpec(styleEditorSpec, { +var StyleEditorActor = exports.StyleEditorActor = protocol.ActorClass({ + typeName: "styleeditor", + /** * The window we work with, taken from the parent actor. */ @@ -574,6 +575,13 @@ var StyleEditorActor = exports.StyleEditorActor = protocol.ActorClassWithSpec(st return this.window.document; }, + events: { + "document-load" : { + type: "documentLoad", + styleSheets: Arg(0, "array:old-stylesheet") + } + }, + form: function () { return { actor: this.actorID }; @@ -601,7 +609,6 @@ var StyleEditorActor = exports.StyleEditorActor = protocol.ActorClassWithSpec(st * Adds load listeners to document. */ newDocument: method(function () { - newDocument: function () { // delete previous document's actors this._clearStyleSheetActors(); @@ -614,7 +621,7 @@ var StyleEditorActor = exports.StyleEditorActor = protocol.ActorClassWithSpec(st this.window.addEventListener("load", this._onDocumentLoaded, false); } return {}; - }, + }), /** * Event handler for document loaded event. Add actor for each stylesheet @@ -736,7 +743,7 @@ var StyleEditorActor = exports.StyleEditorActor = protocol.ActorClassWithSpec(st * @return {object} * Object with 'styelSheet' property for form on new actor. */ - newStyleSheet: function (text) { + newStyleSheet: method(function (text) { let parent = this.document.documentElement; let style = this.document.createElementNS("http://www.w3.org/1999/xhtml", "style"); style.setAttribute("type", "text/css"); @@ -748,6 +755,35 @@ var StyleEditorActor = exports.StyleEditorActor = protocol.ActorClassWithSpec(st 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); } }); @@ -756,6 +792,10 @@ XPCOMUtils.defineLazyGetter(this, "DOMUtils", function () { }); exports.StyleEditorActor = StyleEditorActor; +exports.StyleEditorFront = StyleEditorFront; + +exports.OldStyleSheetActor = OldStyleSheetActor; +exports.OldStyleSheetFront = OldStyleSheetFront; /** * Normalize multiple relative paths towards the base paths on the right. diff --git a/devtools/shared/fronts/styleeditor.js b/devtools/shared/fronts/styleeditor.js index a9dc2e0b4a2c..c586d5378151 100644 --- a/devtools/shared/fronts/styleeditor.js +++ b/devtools/shared/fronts/styleeditor.js @@ -5,10 +5,7 @@ const { SimpleStringFront } = require("devtools/server/actors/string"); const { Front, FrontClassWithSpec } = require("devtools/shared/protocol"); -const { - oldStyleSheetSpec, - styleEditorSpec -} = require("devtools/shared/specs/styleeditor"); +const { oldStyleSheetSpec } = require("devtools/shared/specs/styleeditor"); const promise = require("promise"); const events = require("sdk/event/core"); @@ -82,31 +79,3 @@ const OldStyleSheetFront = FrontClassWithSpec(oldStyleSheetSpec, { }); 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; diff --git a/devtools/shared/specs/styleeditor.js b/devtools/shared/specs/styleeditor.js index e93b7e56fa23..94e1a4056900 100644 --- a/devtools/shared/specs/styleeditor.js +++ b/devtools/shared/specs/styleeditor.js @@ -38,24 +38,3 @@ const oldStyleSheetSpec = generateActorSpec({ }); 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;