зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1468754 Part 1: Add a ChangesActor to devtools. r=pbro
MozReview-Commit-ID: 1Y8esljnLk9 Differential Revision: https://phabricator.services.mozilla.com/D4399 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
6ddd7d4134
Коммит
60b86d829a
|
@ -0,0 +1,70 @@
|
|||
/* 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 protocol = require("devtools/shared/protocol");
|
||||
const { changesSpec } = require("devtools/shared/specs/changes");
|
||||
const TrackChangeEmitter = require("devtools/server/actors/utils/track-change-emitter");
|
||||
|
||||
/**
|
||||
* The ChangesActor stores a stack of changes made by devtools on
|
||||
* the document in the associated tab.
|
||||
*/
|
||||
const ChangesActor = protocol.ActorClassWithSpec(changesSpec, {
|
||||
/**
|
||||
* Create a ChangesActor.
|
||||
*
|
||||
* @param {DebuggerServerConnection} conn
|
||||
* The server connection.
|
||||
* @param {TargetActor} targetActor
|
||||
* The top-level Actor for this tab.
|
||||
*/
|
||||
initialize: function(conn, targetActor) {
|
||||
protocol.Actor.prototype.initialize.call(this, conn);
|
||||
this.targetActor = targetActor;
|
||||
|
||||
this.onTrackChange = this.pushChange.bind(this);
|
||||
TrackChangeEmitter.on("track-change", this.onTrackChange);
|
||||
|
||||
this.changes = [];
|
||||
},
|
||||
|
||||
destroy: function() {
|
||||
this.clearChanges();
|
||||
TrackChangeEmitter.off("track-change", this.onTrackChange);
|
||||
protocol.Actor.prototype.destroy.call(this);
|
||||
},
|
||||
|
||||
changeCount: function() {
|
||||
return this.changes.length;
|
||||
},
|
||||
|
||||
change: function(index) {
|
||||
if (index >= 0 && index < this.changes.length) {
|
||||
// Return a copy of the change at index.
|
||||
return Object.assign({}, this.changes[index]);
|
||||
}
|
||||
// No change at that index -- return undefined.
|
||||
return undefined;
|
||||
},
|
||||
|
||||
allChanges: function() {
|
||||
return this.changes.slice();
|
||||
},
|
||||
|
||||
pushChange: function(change) {
|
||||
this.changes.push(change);
|
||||
},
|
||||
|
||||
popChange: function() {
|
||||
return this.changes.pop();
|
||||
},
|
||||
|
||||
clearChanges: function() {
|
||||
this.changes.length = 0;
|
||||
},
|
||||
});
|
||||
|
||||
exports.ChangesActor = ChangesActor;
|
|
@ -28,6 +28,7 @@ DevToolsModules(
|
|||
'array-buffer.js',
|
||||
'breakpoint.js',
|
||||
'canvas.js',
|
||||
'changes.js',
|
||||
'common.js',
|
||||
'css-properties.js',
|
||||
'csscoverage.js',
|
||||
|
|
|
@ -256,6 +256,11 @@ const ActorRegistry = {
|
|||
constructor: "ScreenshotActor",
|
||||
type: { target: true },
|
||||
});
|
||||
this.registerModule("devtools/server/actors/changes", {
|
||||
prefix: "changes",
|
||||
constructor: "ChangesActor",
|
||||
type: { target: true }
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
/* 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 protocol = require("devtools/shared/protocol");
|
||||
const {changesSpec} = require("devtools/shared/specs/changes");
|
||||
|
||||
/**
|
||||
* ChangesFront, the front object for the ChangesActor
|
||||
*/
|
||||
const ChangesFront = protocol.FrontClassWithSpec(changesSpec, {
|
||||
initialize: function (client, {changesActor}) {
|
||||
protocol.Front.prototype.initialize.call(this, client, {actor: changesActor});
|
||||
this.manage(this);
|
||||
},
|
||||
|
||||
destroy: function() {
|
||||
protocol.Front.prototype.destroy.call(this);
|
||||
},
|
||||
});
|
||||
|
||||
exports.ChangesFront = ChangesFront;
|
|
@ -14,6 +14,7 @@ DevToolsModules(
|
|||
'actor-registry.js',
|
||||
'animation.js',
|
||||
'canvas.js',
|
||||
'changes.js',
|
||||
'css-properties.js',
|
||||
'csscoverage.js',
|
||||
'device.js',
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
/* 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 {
|
||||
generateActorSpec,
|
||||
RetVal,
|
||||
} = require("devtools/shared/protocol");
|
||||
|
||||
const changesSpec = generateActorSpec({
|
||||
typeName: "changes",
|
||||
|
||||
methods: {
|
||||
"allChanges": {
|
||||
response: {
|
||||
changes: RetVal("array:json"),
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
exports.changesSpec = changesSpec;
|
|
@ -219,6 +219,11 @@ const Types = exports.__TypesForTests = [
|
|||
spec: "devtools/shared/specs/styles",
|
||||
front: "devtools/shared/fronts/styles",
|
||||
},
|
||||
{
|
||||
types: ["changes"],
|
||||
spec: "devtools/shared/specs/changes",
|
||||
front: "devtools/shared/fronts/changes",
|
||||
},
|
||||
{
|
||||
types: ["mediarule", "stylesheet", "stylesheets"],
|
||||
spec: "devtools/shared/specs/stylesheets",
|
||||
|
|
|
@ -16,6 +16,7 @@ DevToolsModules(
|
|||
'animation.js',
|
||||
'breakpoint.js',
|
||||
'canvas.js',
|
||||
'changes.js',
|
||||
'css-properties.js',
|
||||
'csscoverage.js',
|
||||
'device.js',
|
||||
|
|
Загрузка…
Ссылка в новой задаче