1 const Ci = Components.interfaces;
2 const Cu = Components.utils;
4 Cu.import("resource://gre/modules/Services.jsm");
6 // Useful piece of code from :bent
7 // http://mxr.mozilla.org/mozilla-central/source/dom/workers/test/extensions/bootstrap/bootstrap.js
8 function registerAddonResourceHandler(data) {
9 let file = data.installPath;
10 let fileuri = file.isDirectory() ?
11 Services.io.newFileURI(file) :
12 Services.io.newURI("jar:" + file.path + "!/", null, null);
13 let resourceName = encodeURIComponent(data.id.replace("@", "at"));
15 Services.io.getProtocolHandler("resource").
16 QueryInterface(Ci.nsIResProtocolHandler).
17 setSubstitution(resourceName, fileuri);
19 return "resource://" + resourceName + "/";
24 function install(data, reason) {}
25 function uninstall(data, reason) {}
27 function startup(data, reason) {
28 let uri = registerAddonResourceHandler(data);
31 Cu.import('resource://gre/modules/commonjs/toolkit/loader.js').Loader;
32 let { Loader, Require, Main } = loaderModule;
34 const { ConsoleAPI } = Cu.import("resource://gre/modules/devtools/Console.jsm");
39 "": "resource://gre/modules/commonjs/"
42 console: new ConsoleAPI({
47 "toolkit/loader": loaderModule,
50 version: data.version,
56 let require_ = Require(loader, { id: "./addon" });
57 mainModule = require_("./main");
60 function shutdown(data, reason) {
61 if (mainModule && mainModule.shutdown) {
62 mainModule.shutdown();
66 function uninstall(data, reason) {}