1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
|
// https://wiki.mozilla.org/Extension_Manager:Bootstrapped_Extensions
const NAME = "bootstrap";
const global = this;
const Cc = Components.classes;
const Ci = Components.interfaces;
const Cu = Components.utils;
const Cr = Components.results;
Cu.import("resource://gre/modules/AddonManager.jsm");
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://gre/modules/Services.jsm");
const resourceProto = Services.io.getProtocolHandler("resource")
.QueryInterface(Ci.nsIResProtocolHandler);
const categoryManager = Cc["@mozilla.org/categorymanager;1"].getService(Ci.nsICategoryManager);
const manager = Components.manager.QueryInterface(Ci.nsIComponentRegistrar);
const storage = Cc["@mozilla.org/fuel/application;1"].getService(Ci.fuelIApplication);
function httpGet(url) {
let xmlhttp = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"].createInstance(Ci.nsIXMLHttpRequest);
xmlhttp.open("GET", url, false);
xmlhttp.send(null);
return xmlhttp;
}
function writeFile(file, buf) {
let fstream = Cc["@mozilla.org/network/file-output-stream;1"].createInstance(Ci.nsIFileOutputStream);
let stream = Cc["@mozilla.org/intl/converter-output-stream;1"].createInstance(Ci.nsIConverterOutputStream);
fstream.init(file, 0x02 | 0x08 | 0x20, parseInt("0644", 8), 0);
stream.init(fstream, "UTF-8", 0, "?");
stream.writeString(buf);
stream.close();
fstream.close();
}
let initialized = false;
let addon = null;
let basePath = null;
let components = {};
function startup(data, reason) {
dump("dactyl: bootstrap: startup\n");
basePath = data.installPath;
if (!initialized) {
initialized = true;
dump("dactyl: bootstrap: init" + " " + data.id + "\n");
AddonManager.getAddonByID(data.id, function (res) {
try {
addon = res;
init();
}
catch (e) {
dump("dactyl: bootstrap: " + e + "\n");
Cu.reportError(e);
}
});
}
}
function FactoryProxy(url, classID) {
this.url = url;
this.classID = Components.ID(classID);
}
FactoryProxy.prototype = {
QueryInterface: XPCOMUtils.generateQI(Ci.nsIFactory),
register: function () {
dump("dactyl: bootstrap: register: " + this.classID + " " + this.contractID + "\n");
manager.registerFactory(this.classID,
String(this.classID),
this.contractID,
this);
},
unregister: function () {
dump("dactyl: bootstrap: unregister: " + this.classID + " " + this.contractID + "\n");
manager.unregisterFactory(this.classID,
this);
},
get module() {
Object.defineProperty(this, "module", { value: {}, enumerable: true });
Cu.import(this.url, this.module);
return this.module;
},
createInstance: function (iids) {
dump("dactyl: bootstrap: createInstance: " + this.classID + " " + this.contractID + " " + iids + "\n");
return let (factory = this.module.NSGetFactory(this.classID))
factory.createInstance.apply(factory, arguments)
}
}
function init() {
dump("dactyl: bootstrap: init: " + addon + "\n");
let manifestURI = addon.getResourceURI("chrome.manifest");
let manifest = httpGet(manifestURI.spec)
.responseText
.replace(/^\s*|\s*$|#.*/g, "")
.replace(/^\s*\n/gm, "");
function url(path) addon.getResourceURI(path).spec;
let result = [];
for each (let line in manifest.split("\n")) {
let fields = line.split(/\s+/);
switch(fields[0]) {
case "content":
fields[2] = url(fields[2]);
default:
result.push(fields);
break;
case "locale":
case "skin":
fields[3] = url(fields[3]);
result.push(fields);
break;
case "category":
categoryManager.addCategoryEntry(fields[1], fields[2], fields[3], false, true);
break;
case "component":
components[fields[1]] = new FactoryProxy(url(fields[2]), fields[1]);
break;
case "contract":
components[fields[2]].contractID = fields[1];
components[fields[2]].register();
break;
case "resource":
resourceProto.setSubstitution(fields[1], addon.getResourceURI(fields[2]));
}
}
Cc["@dactyl.googlecode.com/base/xpc-interface-shim"].createInstance()
Services.obs.notifyObservers(null, "dactyl-rehash", null);
Cu.import("resource://dactyl/base.jsm");
require(global, "prefs");
require(global, "services");
services.subscriptLoader.loadSubScript(
url("defaults/preferences/dactyl.js"),
{
pref: function pref(name, val) {
if (prefs.get(name, null) == null)
prefs.set(name, val);
}
});
if (manifestURI instanceof Ci.nsIFileURL)
manager.autoRegister(manifestURI.QueryInterface(Ci.nsIFileURL).file);
else {
var file = basePath.parent;
file.append(addon.id + ".manifest");
writeFile(file, result.map(function (line) line.join(" ")).join("\n"));
manager.autoRegister(file);
file.remove(false);
}
require(global, "overlay");
}
function shutdown(data, reason) {
dump("dactyl: bootstrap: shutdown\n");
for (let factory in values(components))
// TODO: Categories;
factory.unregister();
services.observer.notifyObservers(null, "dactyl-cleanup", null);
}
function reasonToString(reason) {
for each (let name in ["disable", "downgrade", "enable",
"install", "shutdown", "startup",
"uninstall", "upgrade"])
if (reason == global["ADDON_" + name.toUpperCase()] ||
reason == global["APP_" + name.toUpperCase()])
return name;
}
function install(data, reason) { dump("dactyl: bootstrap: install\n") }
function uninstall(data, reason) { dump("dactyl: bootstrap: uninstall\n") }
|