Skip to content

Commit 5fdd3ed

Browse files
committed
Inspector panel customization + temp NodeActor patch
1 parent 5d4be2c commit 5fdd3ed

File tree

2 files changed

+68
-4
lines changed

2 files changed

+68
-4
lines changed

lib/firequery-actor.js

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,21 @@
55
/**
66
* This module is loaded on the backend (can be a remote device) where
77
* some module or features (such as Tracing console) don't have to
8-
* be available.
8+
* be available. Also Firebug SDK isn't available on the backend.
99
*/
1010

11+
// Add-on SDK
1112
const { Cu } = require("chrome");
1213

13-
// Remote Debugging Protocol API
14+
// DevTools
1415
const { DebuggerServer } = Cu.import("resource://gre/modules/devtools/dbg-server.jsm", {});
1516
const { devtools } = Cu.import("resource://gre/modules/devtools/Loader.jsm", {});
1617
const protocol = devtools["require"]("devtools/server/protocol");
1718
const { method, RetVal, ActorClass, Actor, Arg } = protocol;
1819
const Events = require("sdk/event/core");
1920
const { makeInfallible } = devtools["require"]("devtools/toolkit/DevToolsUtils.js");
2021
const DevToolsUtils = devtools["require"]("devtools/toolkit/DevToolsUtils");
22+
const { NodeActor } = devtools["require"]("devtools/server/actors/inspector");
2123

2224
const Previewers = DebuggerServer.ObjectActorPreviewers;
2325

@@ -79,6 +81,8 @@ var FireQueryActor = ActorClass(
7981

8082
this.parent = parent;
8183
this.state = "detached";
84+
85+
this.onDomNodeForm = this.onDomNodeForm.bind(this);
8286
},
8387

8488
/**
@@ -117,6 +121,8 @@ var FireQueryActor = ActorClass(
117121
this.state = "attached";
118122

119123
Previewers.Object.unshift(this.onBuildPreview.bind(this));
124+
125+
DebuggerServer.on("domnode-form", this.onDomNodeForm);
120126
}), {
121127
request: {},
122128
response: {
@@ -202,6 +208,12 @@ var FireQueryActor = ActorClass(
202208
type: "detached"
203209
}
204210
}),
211+
212+
// Debugger Server Events
213+
214+
onDomNodeForm: function(eventId, nodeActor, form) {
215+
form.jQueryCacheData = hasJQueryCache(nodeActor.rawNode);
216+
}
205217
});
206218

207219
// Helpers
@@ -245,5 +257,14 @@ function hasJQueryCache(object) {
245257
}
246258
};
247259

260+
// Patching NodeActor (add custom info into actor form)
261+
// xxxHonza: Bug 1036949 - New API: MarkupView customization
262+
let originalForm = NodeActor.prototype.form;
263+
NodeActor.prototype.form = function(detail) {
264+
let form = originalForm.apply(this, arguments);
265+
DebuggerServer.emit("domnode-form", this, form);
266+
return form;
267+
}
268+
248269
// Exports from this module
249270
exports.FireQueryActor = FireQueryActor;

lib/inspector-overlay.js

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,17 @@ module.metadata = {
66
"stability": "stable"
77
};
88

9+
// Add-on SDK
910
const { Cu, Ci } = require("chrome");
10-
const { Trace, TraceError } = require("firebug.sdk/lib/core/trace.js").get(module.id);
1111
const { Class } = require("sdk/core/heritage");
12+
13+
// Firebug SDK
14+
const { Trace, TraceError } = require("firebug.sdk/lib/core/trace.js").get(module.id);
1215
const { PanelOverlay } = require("firebug.sdk/lib/panel-overlay.js");
1316

17+
// Constants
18+
const XHTML_NS = "http://www.w3.org/1999/xhtml";
19+
1420
/**
1521
* @overlay This object represents an overlay for the existing
1622
* Inspector panel it's responsible for the panel customization.
@@ -22,14 +28,17 @@ const InspectorOverlay = Class(
2228
extends: PanelOverlay,
2329

2430
overlayId: "fireQueryInspectorOverlay",
25-
panelId: "webconsole",
31+
panelId: "inspector",
2632

2733
// Initialization
2834

2935
initialize: function(options) {
3036
PanelOverlay.prototype.initialize.apply(this, arguments);
3137

3238
Trace.sysout("InspectorOverlay.initialize;", options);
39+
40+
this.onMarkupViewRender = this.onMarkupViewRender.bind(this);
41+
this.onMarkupViewLoaded = this.onMarkupViewLoaded.bind(this);
3342
},
3443

3544
destroy: function() {
@@ -42,13 +51,47 @@ const InspectorOverlay = Class(
4251
PanelOverlay.prototype.onBuild.apply(this, arguments);
4352

4453
Trace.sysout("InspectorOverlay.onBuild;", options);
54+
55+
// Handle MarkupView events.
56+
this.panel.on("markupview-render", this.onMarkupViewRender);
57+
this.panel.on("markuploaded", this.onMarkupViewLoaded);
4558
},
4659

4760
onReady: function(options) {
4861
PanelOverlay.prototype.onReady.apply(this, arguments);
4962

5063
Trace.sysout("InspectorOverlay.onReady;", options);
5164
},
65+
66+
// MarkupView Event Handlers
67+
68+
onMarkupViewRender: function(eventId, node, type, data, options) {
69+
if (type != "element") {
70+
return;
71+
}
72+
73+
let value;
74+
let nodeFront = data.node;
75+
let cache = nodeFront._form.jQueryCacheData;
76+
77+
if (!cache) {
78+
return;
79+
}
80+
81+
let doc = node.ownerDocument;
82+
83+
for (var data in cache) {
84+
if (cache.hasOwnProperty(data)) {
85+
let label = doc.createElementNS(XHTML_NS, "span");
86+
label.innerHTML = cache[data];
87+
node.appendChild(label);
88+
}
89+
}
90+
},
91+
92+
onMarkupViewLoaded: function() {
93+
Trace.sysout("inspectorOverlay.onMarkupViewLoaded;");
94+
},
5295
});
5396

5497
// Exports from this module

0 commit comments

Comments
 (0)