diff --git a/devtools/client/fronts/moz.build b/devtools/client/fronts/moz.build index 03d1b15e29e4..2114d4253710 100644 --- a/devtools/client/fronts/moz.build +++ b/devtools/client/fronts/moz.build @@ -1,7 +1,10 @@ +# -*- 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( 'storage.js', + 'stylesheets.js' ) diff --git a/devtools/client/fronts/stylesheets.js b/devtools/client/fronts/stylesheets.js new file mode 100644 index 000000000000..592de8b82a97 --- /dev/null +++ b/devtools/client/fronts/stylesheets.js @@ -0,0 +1,36 @@ +/* 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 { Front, FrontClassWithSpec } = require("devtools/server/protocol.js"); +const { originalSourceSpec } = require("devtools/shared/specs/stylesheets.js"); + +/** + * The client-side counterpart for an OriginalSourceActor. + */ +const OriginalSourceFront = FrontClassWithSpec(originalSourceSpec, { + initialize: function (client, form) { + Front.prototype.initialize.call(this, client, form); + + this.isOriginalSource = true; + }, + + form: function (form, detail) { + if (detail === "actorid") { + this.actorID = form; + return; + } + this.actorID = form.actor; + this._form = form; + }, + + get href() { + return this._form.url; + }, + get url() { + return this._form.url; + } +}); + +exports.OriginalSourceFront = OriginalSourceFront; diff --git a/devtools/server/actors/stylesheets.js b/devtools/server/actors/stylesheets.js index 555324115c8c..b2a49a4ab8cf 100644 --- a/devtools/server/actors/stylesheets.js +++ b/devtools/server/actors/stylesheets.js @@ -14,11 +14,13 @@ Cu.import("resource://gre/modules/Task.jsm"); const promise = require("promise"); const events = require("sdk/event/core"); +const {OriginalSourceFront} = require("devtools/client/fronts/stylesheets"); const protocol = require("devtools/server/protocol"); const {Arg, Option, method, RetVal, types} = protocol; const {LongStringActor, ShortLongString} = require("devtools/server/actors/string"); const {fetch} = require("devtools/shared/DevToolsUtils"); const {listenOnce} = require("devtools/shared/async-utils"); +const {originalSourceSpec} = require("devtools/shared/specs/stylesheets"); const {SourceMapConsumer} = require("source-map"); loader.lazyGetter(this, "CssLogic", () => require("devtools/shared/inspector/css-logic").CssLogic); @@ -66,9 +68,7 @@ let modifiedStyleSheets = new WeakMap(); * Actor representing an original source of a style sheet that was specified * in a source map. */ -var OriginalSourceActor = protocol.ActorClass({ - typeName: "originalsource", - +var OriginalSourceActor = protocol.ActorClassWithSpec(originalSourceSpec, { initialize: function(aUrl, aSourceMap, aParentActor) { protocol.Actor.prototype.initialize.call(this, null); @@ -110,43 +110,12 @@ var OriginalSourceActor = protocol.ActorClass({ /** * Protocol method to get the text of this source. */ - getText: method(function() { + getText: function() { return this._getText().then((text) => { return new LongStringActor(this.conn, text || ""); }); - }, { - response: { - text: RetVal("longstring") - } - }) -}) - -/** - * The client-side counterpart for an OriginalSourceActor. - */ -var OriginalSourceFront = protocol.FrontClass(OriginalSourceActor, { - initialize: function(client, form) { - protocol.Front.prototype.initialize.call(this, client, form); - - this.isOriginalSource = true; - }, - - form: function(form, detail) { - if (detail === "actorid") { - this.actorID = form; - return; - } - this.actorID = form.actor; - this._form = form; - }, - - get href() { - return this._form.url; - }, - get url() { - return this._form.url; } -}); +}) /** * A MediaRuleActor lives on the server and provides access to properties diff --git a/devtools/shared/moz.build b/devtools/shared/moz.build index d08ed96866c6..b6f6b6dfec45 100644 --- a/devtools/shared/moz.build +++ b/devtools/shared/moz.build @@ -22,8 +22,8 @@ DIRS += [ 'qrcode', 'security', 'sourcemap', - 'specs', 'shims', + 'specs', 'touch', 'transport', 'webconsole', diff --git a/devtools/shared/specs/moz.build b/devtools/shared/specs/moz.build index 5104f375e413..2114d4253710 100644 --- a/devtools/shared/specs/moz.build +++ b/devtools/shared/specs/moz.build @@ -5,5 +5,6 @@ # file, You can obtain one at http://mozilla.org/MPL/2.0/. DevToolsModules( - 'storage.js' + 'storage.js', + 'stylesheets.js' ) diff --git a/devtools/shared/specs/stylesheets.js b/devtools/shared/specs/stylesheets.js new file mode 100644 index 000000000000..61e5a639815f --- /dev/null +++ b/devtools/shared/specs/stylesheets.js @@ -0,0 +1,20 @@ +/* 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 { RetVal, generateActorSpec } = require("devtools/server/protocol.js"); + +const originalSourceSpec = generateActorSpec({ + typeName: "originalsource", + + methods: { + getText: { + response: { + text: RetVal("longstring") + } + } + } +}); + +exports.originalSourceSpec = originalSourceSpec;