Skip to content

Commit a4ff7bf

Browse files
committed
working fbtrace and http response adapters
1 parent 5a99a08 commit a4ff7bf

8 files changed

Lines changed: 129 additions & 36 deletions

File tree

client/.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
/bootstrap.js
2-
/install.rdf
2+
/install.rdf
3+
/data/bundles/

client/data/bundle.js

Lines changed: 0 additions & 8 deletions
This file was deleted.

client/lib/main.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
const { Extension:EXTENSION } = require("./extension.js");
66
const { Panel:PANEL } = require("./panel.js");
7-
const { Cu:CU } = require("chrome");
7+
const { Cc: CC, Cu:CU, Ci:CI } = require("chrome");
88
const { gDevTools:GDEVTOOLS } = CU.import("resource:///modules/devtools/gDevTools.jsm", {});
99

1010
const { data:DATA } = require("sdk/self");
@@ -23,10 +23,16 @@ function main(options, callbacks) {
2323
GDEVTOOLS.on("webconsole-init", onConsoleInit);
2424

2525

26-
SANDBOX(DATA.url("bundle.js"), function(sandbox) {
26+
SANDBOX(DATA.url("bundles/components/main.js"), function(sandbox) {
2727

28-
sandbox.main();
28+
sandbox.main({
29+
CC: CC,
30+
CU: CU,
31+
CI: CI,
32+
GDEVTOOLS: GDEVTOOLS
33+
});
2934
});
35+
3036
}
3137

3238
function onUnload(reason) {

components/adapters/fbtrace.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
2+
exports.for = function (API) {
3+
4+
// TODO Externalise this constant.
5+
const PREF_DOMAIN = "extensions.firephp-for-firebug-next";
6+
7+
var FBTrace = {};
8+
try {
9+
var scope = {};
10+
API.CU["import"]("resource://fbtrace/firebug-trace-service.js", scope);
11+
FBTrace = scope.traceConsoleService.getTracer(PREF_DOMAIN);
12+
} catch(err) {
13+
}
14+
15+
16+
function log (label, obj) {
17+
if (typeof object === "undefined") {
18+
object = label;
19+
label = ("" + obj);
20+
}
21+
FBTrace.sysout(label, obj);
22+
}
23+
API.on("log", log);
24+
25+
26+
var Console = function (context) {
27+
var self = this;
28+
29+
self._context = context;
30+
31+
self._prefixLabel = function (label) {
32+
if (self._context.name) {
33+
label = "[" + self._context.name + "] " + label;
34+
}
35+
return label;
36+
}
37+
}
38+
Console.prototype.for = function (context) {
39+
return (new Console(context));
40+
}
41+
Console.prototype.log = function (label, obj) {
42+
return log(this._prefixLabel(label || ("" + obj)), obj);
43+
}
44+
Console.prototype.error = function (label, obj) {
45+
return log(this._prefixLabel("ERROR: " + (label || ("" + obj))), obj);
46+
}
47+
48+
49+
return {
50+
FBTrace: FBTrace,
51+
console: new Console(API)
52+
};
53+
}

components/adapters/http-response-observer.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
exports.main = function (API) {
2+
exports.for = function (API) {
33

44
const OBSERVER_SERVICE = API.CC["@mozilla.org/observer-service;1"].getService(API.CI.nsIObserverService);
55

@@ -34,19 +34,23 @@ exports.main = function (API) {
3434

3535
requestIndex += 1;
3636

37-
API.emit("response", {
37+
var response = {
3838
"request": {
3939
"id": requestId || "id:" + httpChannel.URI.spec + ":" + requestIndex,
4040
"url": httpChannel.URI.spec,
4141
"hostname": httpChannel.URI.host,
4242
"port": httpChannel.URI.port,
4343
"method": httpChannel.requestMethod,
4444
"headers": requestHeaders
45-
}
45+
},
4646
"status": httpChannel.responseStatus,
4747
"contentType": contentType,
4848
"headers": responseHeaders
49-
});
49+
};
50+
51+
API.console.log("response", response);
52+
53+
API.emit("response", response);
5054

5155
} catch (err) {
5256
API.console.error(err);
@@ -61,4 +65,6 @@ exports.main = function (API) {
6165
API.on("destroy", function () {
6266
OBSERVER_SERVICE.removeObserver(LISTENER, "http-on-examine-response");
6367
});
68+
69+
return {};
6470
}

components/main.js

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,52 @@
11

2+
const EVENTS = require("eventemitter2");
23

3-
exports.main = function () {
44

5-
console.log("CALLED MAIN IN ADAPTER!")
5+
exports.main = function (API) {
66

7+
const FBTRACE_API = makeAPI(API, {
8+
name: "fbtrace"
9+
});
10+
const FBTRACE_EXPORTS = require("./adapters/fbtrace").for(FBTRACE_API);
11+
//FBTRACE_EXPORTS.console.log("CALLED MAIN IN ADAPTER 4444!");
12+
//FBTRACE_API.emit("log", "CALLED MAIN IN ADAPTER 5555!");
13+
14+
API.console = FBTRACE_EXPORTS.console;
15+
var console = makeAPI(API, {
16+
name: "main"
17+
}).console;
18+
19+
20+
console.log("Init components");
21+
22+
23+
const HTTP_RESPONSE_OBSERVER_API = makeAPI(API, {
24+
name: "http-response-observer"
25+
});
26+
const HTTP_RESPONSE_OBSERVER_EXPORTS = require("./adapters/http-response-observer").for(HTTP_RESPONSE_OBSERVER_API);
27+
28+
29+
HTTP_RESPONSE_OBSERVER_API.on("response", function (response) {
30+
31+
API.console.log("response in MAIN", response);
32+
33+
});
34+
}
35+
36+
37+
function makeAPI (_API, extra) {
38+
var API = new EVENTS();
39+
for (var name in extra) {
40+
API[name] = extra[name];
41+
}
42+
for (var name in _API) {
43+
API[name] = _API[name];
44+
if (
45+
name === "console" &&
46+
typeof (API[name].for) === "function"
47+
) {
48+
API[name] = API[name].for(API);
49+
}
50+
}
51+
return API;
752
}

components/package.json

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,14 @@
66
"main.js": "./main.js"
77
}
88
},
9-
"upstream": {
10-
"packages": {
11-
"top": [
12-
"../../../../_upstream/os-inception/*",
13-
"../../*",
14-
"../../../*",
15-
"../../../../../*"
16-
]
17-
}
9+
"dependencies": {
10+
"eventemitter2": "~0.4.14"
1811
},
19-
"mappings": {
20-
"to.pinf.lib": "top/to.pinf.lib"
12+
"directories": {
13+
"bundles": "../client/data/bundles/components"
2114
},
2215
"scripts": {
2316
"install": "../node_modules/.bin/smi install",
24-
"build": "rm -Rf .rt ; ../node_modules/.bin/pinf-bundle"
25-
},
26-
"config": {
27-
"smi.cli": {
28-
"packagesDirectory": "node_modules"
29-
}
17+
"build": "rm -Rf .rt ; ../node_modules/to.pinf.lib/bin/pinf-bundle"
3018
}
3119
}

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@
66
"upstream": {
77
"packages": {
88
"top": [
9+
"../../../_upstream/os-inception/*",
910
"../../lib/*",
1011
"/opt/services/*"
1112
]
1213
}
1314
},
1415
"mappings": {
15-
"./client/node_modules/pinf-for-mozilla-addon-sdk": "top/pinf-for-mozilla-addon-sdk"
16+
"./client/node_modules/pinf-for-mozilla-addon-sdk": "top/pinf-for-mozilla-addon-sdk",
17+
"to.pinf.lib": "top/to.pinf.lib"
1618
},
1719
"scripts": {
1820
"install": "./node_modules/.bin/smi install ; cd components ; npm install --unsafe-perm ; cd .. ; cd ./server; npm install --unsafe-perm",

0 commit comments

Comments
 (0)