Bug 1265730 - Decouple StyleEditorFront from StyleEditorActor;r=jryans

This commit is contained in:
Eddy Bruel 2016-06-02 13:10:41 +02:00
Родитель 91c45dd470
Коммит b33a96b184
3 изменённых файлов: 60 добавлений и 48 удалений

Просмотреть файл

@ -17,8 +17,7 @@ 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);
@ -554,13 +553,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.ActorClass({
typeName: "styleeditor",
var StyleEditorActor = exports.StyleEditorActor = protocol.ActorClassWithSpec(styleEditorSpec, {
/**
* The window we work with, taken from the parent actor.
*/
@ -575,13 +574,6 @@ var StyleEditorActor = exports.StyleEditorActor = protocol.ActorClass({
return this.window.document;
},
events: {
"document-load" : {
type: "documentLoad",
styleSheets: Arg(0, "array:old-stylesheet")
}
},
form: function ()
{
return { actor: this.actorID };
@ -609,6 +601,7 @@ var StyleEditorActor = exports.StyleEditorActor = protocol.ActorClass({
* Adds load listeners to document.
*/
newDocument: method(function () {
newDocument: function () {
// delete previous document's actors
this._clearStyleSheetActors();
@ -621,7 +614,7 @@ var StyleEditorActor = exports.StyleEditorActor = protocol.ActorClass({
this.window.addEventListener("load", this._onDocumentLoaded, false);
}
return {};
}),
},
/**
* Event handler for document loaded event. Add actor for each stylesheet
@ -743,7 +736,7 @@ var StyleEditorActor = exports.StyleEditorActor = protocol.ActorClass({
* @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");
@ -755,35 +748,6 @@ var StyleEditorActor = exports.StyleEditorActor = protocol.ActorClass({
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);
}
});
@ -792,10 +756,6 @@ 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.

Просмотреть файл

@ -5,7 +5,10 @@
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");
@ -79,3 +82,31 @@ 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;

Просмотреть файл

@ -38,3 +38,24 @@ 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;