Skip to content

Commit c111ed8

Browse files
committed
Attach to the backend within the Toolbox overlay
1 parent 5fdd3ed commit c111ed8

File tree

2 files changed

+80
-73
lines changed

2 files changed

+80
-73
lines changed

lib/console-overlay.js

Lines changed: 0 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -9,30 +9,18 @@ module.metadata = {
99
// Add-on SDK
1010
const options = require("@loader/options");
1111
const { Cu, Ci } = require("chrome");
12-
const { on, off, emit } = require("sdk/event/core");
13-
const { defer, resolve } = require("sdk/core/promise");
1412
const { Class } = require("sdk/core/heritage");
1513
const { loadSheet, removeSheet } = require("sdk/stylesheet/utils");
1614

1715
// Firebug SDK
1816
const { Trace, TraceError } = require("firebug.sdk/lib/core/trace.js").get(module.id);
1917
const { PanelOverlay } = require("firebug.sdk/lib/panel-overlay.js");
2018
const { ToolbarButton } = require("firebug.sdk/lib/toolbar-button.js");
21-
const { Rdp } = require("firebug.sdk/lib/core/rdp.js");
22-
23-
// DevTools
24-
const { devtools } = Cu.import("resource://gre/modules/devtools/Loader.jsm", {});
25-
const { makeInfallible } = devtools["require"]("devtools/toolkit/DevToolsUtils.js");
2619

2720
// FireQuery
28-
const { FireQueryFront } = require("./firequery-front");
2921
const { JQueryRenderer } = require("./jquery-renderer");
3022
const { getJQuerifyCode } = require("./jquerify-code");
3123

32-
// URL of the {@FireQueryActor} module. This module will be
33-
// installed and loaded on the backend.
34-
const actorModuleUrl = options.prefixURI + "lib/firequery-actor.js";
35-
3624
/**
3725
* @overlay This object represents an overlay for the existing
3826
* Console panel and is responsible for Console customization.
@@ -60,8 +48,6 @@ const ConsoleOverlay = Class(
6048

6149
let win = this.getPanelWindow();
6250
removeSheet(win, "chrome://firequery/skin/firequery.css", "author");
63-
64-
this.detach();
6551
},
6652

6753
// Events
@@ -90,8 +76,6 @@ const ConsoleOverlay = Class(
9076

9177
let win = this.getPanelWindow();
9278
loadSheet(win, "chrome://firequery/skin/firequery.css", "author");
93-
94-
this.attach();
9579
},
9680

9781
onReady: function(options) {
@@ -100,58 +84,6 @@ const ConsoleOverlay = Class(
10084
Trace.sysout("ConsoleOverlay.onReady;", options);
10185
},
10286

103-
// Backend
104-
105-
/**
106-
* Attach to the backend FireQuery actor.
107-
*/
108-
attach: makeInfallible(function() {
109-
Trace.sysout("ConsoleOverlay.attach;");
110-
111-
if (this.deferredAttach) {
112-
return this.deferredAttach.promise;
113-
}
114-
115-
let config = {
116-
prefix: FireQueryFront.prototype.typeName,
117-
actorClass: "FireQueryActor",
118-
frontClass: FireQueryFront,
119-
moduleUrl: actorModuleUrl
120-
};
121-
122-
this.deferredAttach = defer();
123-
let client = this.toolbox.target.client;
124-
125-
// Register as tab actor.
126-
Rdp.registerTabActor(client, config).then(({registrar, front}) => {
127-
FBTrace.sysout("ConsoleOverlay.attach; READY", front);
128-
129-
this.front = front;
130-
131-
// xxxHonza: Unregister at shutdown
132-
this.registrar = registrar;
133-
134-
// Emit an event indicating that the attach process is done. This
135-
// can be used e.g. by tests.
136-
emit(this, "attached", front);
137-
138-
// Resolve the 'attach promise'.
139-
this.deferredAttach.resolve(front);
140-
});
141-
142-
return this.deferredAttach.promise;
143-
}),
144-
145-
detach: function() {
146-
Trace.sysout("ConsoleOverlay.detach;");
147-
148-
// xxxHonza: TODO
149-
},
150-
151-
getJQueryFront: function() {
152-
return this.attach();
153-
},
154-
15587
// Commands
15688

15789
onJQuerify: function() {

lib/firequery-toolbox-overlay.js

Lines changed: 80 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,39 @@ module.metadata = {
66
"stability": "stable"
77
};
88

9+
// Add-on SDK
910
const options = require("@loader/options");
10-
1111
const { Cu, Ci } = require("chrome");
12-
const { Trace, TraceError } = require("firebug.sdk/lib/core/trace.js").get(module.id);
1312
const { Class } = require("sdk/core/heritage");
13+
const { defer, resolve } = require("sdk/core/promise");
14+
const { on, off, emit } = require("sdk/event/core");
15+
16+
// DevTools
17+
const { devtools } = Cu.import("resource://gre/modules/devtools/Loader.jsm", {});
18+
const { makeInfallible } = devtools["require"]("devtools/toolkit/DevToolsUtils.js");
19+
20+
// Firebug SDK
21+
const { Trace, TraceError } = require("firebug.sdk/lib/core/trace.js").get(module.id);
1422
const { Locale } = require("firebug.sdk/lib/core/locale.js");
1523
const { ToolboxOverlay } = require("firebug.sdk/lib/toolbox-overlay.js");
24+
const { Rdp } = require("firebug.sdk/lib/core/rdp.js");
25+
26+
// FireQuery
27+
const { FireQueryFront } = require("./firequery-front");
28+
29+
// URL of the {@FireQueryActor} module. This module will be
30+
// installed and loaded on the backend.
31+
const actorModuleUrl = options.prefixURI + "lib/firequery-actor.js";
1632

1733
/**
1834
* @overlay This object represents an overlay for the Toolbox. The
1935
* overlay is created when the Toolbox is opened and destroyed when
2036
* the Toolbox is closed. There is one instance of the overlay per
2137
* Toolbox, and so there can be more overlay instances created per
2238
* one browser session.
39+
*
40+
* FireQuery uses the overlay to register and attach/detach the
41+
* backend actor.
2342
*/
2443
const FireQueryToolboxOverlay = Class(
2544
/** @lends FireQueryToolboxOverlay */
@@ -41,9 +60,7 @@ const FireQueryToolboxOverlay = Class(
4160

4261
Trace.sysout("FireQueryToolboxOverlay.destroy;", arguments);
4362

44-
if (this.pixelPerfectPopup) {
45-
this.pixelPerfectPopup.destroy();
46-
}
63+
this.detach();
4764
},
4865

4966
// Events
@@ -52,6 +69,64 @@ const FireQueryToolboxOverlay = Class(
5269
ToolboxOverlay.prototype.onReady.apply(this, arguments);
5370

5471
Trace.sysout("FireQueryToolboxOverlay.onReady;", options);
72+
73+
this.attach();
74+
},
75+
76+
// Backend
77+
78+
/**
79+
* Attach to the backend FireQuery actor.
80+
*/
81+
attach: makeInfallible(function() {
82+
Trace.sysout("ConsoleOverlay.attach;");
83+
84+
if (this.deferredAttach) {
85+
return this.deferredAttach.promise;
86+
}
87+
88+
let config = {
89+
prefix: FireQueryFront.prototype.typeName,
90+
actorClass: "FireQueryActor",
91+
frontClass: FireQueryFront,
92+
moduleUrl: actorModuleUrl
93+
};
94+
95+
this.deferredAttach = defer();
96+
let client = this.toolbox.target.client;
97+
98+
// Register as tab actor.
99+
Rdp.registerTabActor(client, config).then(({registrar, front}) => {
100+
FBTrace.sysout("ConsoleOverlay.attach; READY", front);
101+
102+
this.front = front;
103+
104+
// xxxHonza: Unregister at shutdown
105+
this.registrar = registrar;
106+
107+
// Emit an event indicating that the attach process is done. This
108+
// can be used e.g. by tests.
109+
emit(this, "attached", front);
110+
111+
// Resolve the 'attach promise'.
112+
this.deferredAttach.resolve(front);
113+
});
114+
115+
return this.deferredAttach.promise;
116+
}),
117+
118+
detach: makeInfallible(function() {
119+
Trace.sysout("ConsoleOverlay.detach;");
120+
121+
// xxxHonza: TODO
122+
123+
// Emit an event indicating that the attach process is done. This
124+
// can be used e.g. by tests.
125+
emit(this, "attached", front);
126+
}),
127+
128+
getJQueryFront: function() {
129+
return this.attach();
55130
},
56131
});
57132

0 commit comments

Comments
 (0)