1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2026-02-09 12:55:45 +01:00

Fix about:pentadactyl by registering the component manually. Et cetera.

This commit is contained in:
Kris Maglione
2011-01-03 17:06:28 -05:00
parent e8c5664c8f
commit 30ec5fc393
9 changed files with 98 additions and 46 deletions

View File

@@ -7,7 +7,9 @@
if (!JSMLoader)
var JSMLoader = {
builtin: Components.utils.Sandbox(this),
factories: [],
globals: {},
manager: Components.manager.QueryInterface(Components.interfaces.nsIComponentRegistrar),
stale: {},
load: function load(url, target) {
if (this.stale[url]) {
@@ -32,6 +34,10 @@ if (!JSMLoader)
}
Components.utils.import(url, target);
},
cleanup: function unregister() {
for each (let factory in this.factories.splice(0))
this.manager.unregisterFactory(factory.classID, factory);
},
purge: function purge() {
for (let [url, global] in Iterator(this.globals))
this.stale[url] = true;
@@ -39,6 +45,13 @@ if (!JSMLoader)
registerGlobal: function registerGlobal(uri, obj) {
if (Cu.getGlobalForObject)
this.globals[uri.replace(/.* -> /, "")] = Cu.getGlobalForObject(obj);
},
registerFactory: function registerFactory(factory) {
this.manager.registerFactory(factory.classID,
String(factory.classID),
factory.contractID,
factory);
this.factories.push(factory);
}
};

View File

@@ -26,6 +26,8 @@ var ModuleBase = Class("ModuleBase", {
var Overlay = Module("Overlay", {
init: function () {
services["dactyl:"]; // Hack. Force module initialization.
util.overlayWindow(config.overlayChrome, function (window) ({
init: function (document) {
/**

View File

@@ -40,8 +40,8 @@ var Services = Module("Services", {
this.add("favicon", "@mozilla.org/browser/favicon-service;1", Ci.nsIFaviconService);
this.add("focus", "@mozilla.org/focus-manager;1", Ci.nsIFocusManager);
this.add("fuel", "@mozilla.org/fuel/application;1", Ci.extIApplication);
this.add("history", "@mozilla.org/browser/global-history;2", [Ci.nsIBrowserHistory, Ci.nsIGlobalHistory3,
Ci.nsINavHistoryService, Ci.nsPIPlacesDatabase]);
this.add("history", "@mozilla.org/browser/global-history;2",
[Ci.nsIBrowserHistory, Ci.nsIGlobalHistory3, Ci.nsINavHistoryService, Ci.nsPIPlacesDatabase]);
this.add("io", "@mozilla.org/network/io-service;1", Ci.nsIIOService);
this.add("json", "@mozilla.org/dom/json;1", Ci.nsIJSON, "createInstance");
this.add("livemark", "@mozilla.org/browser/livemark-service;2", Ci.nsILivemarkService);
@@ -69,15 +69,20 @@ var Services = Module("Services", {
this.addClass("Find", "@mozilla.org/embedcomp/rangefind;1", Ci.nsIFind);
this.addClass("HtmlConverter","@mozilla.org/widget/htmlformatconverter;1", Ci.nsIFormatConverter);
this.addClass("HtmlEncoder", "@mozilla.org/layout/htmlCopyEncoder;1", Ci.nsIDocumentEncoder);
this.addClass("StreamChannel","@mozilla.org/network/input-stream-channel;1",
[Ci.nsIChannel, Ci.nsIInputStreamChannel, Ci.nsIRequest], "setURI");
this.addClass("Persist", "@mozilla.org/embedding/browser/nsWebBrowserPersist;1", Ci.nsIWebBrowserPersist);
this.addClass("Pipe", "@mozilla.org/pipe;1", Ci.nsIPipe, "init");
this.addClass("Process", "@mozilla.org/process/util;1", Ci.nsIProcess, "init");
this.addClass("String", "@mozilla.org/supports-string;1", Ci.nsISupportsString, "data");
this.addClass("StringStream", "@mozilla.org/io/string-input-stream;1", Ci.nsIStringInputStream, "data");
this.addClass("Timer", "@mozilla.org/timer;1", Ci.nsITimer, "initWithCallback");
this.addClass("StreamCopier", "@mozilla.org/network/async-stream-copier;1",Ci.nsIAsyncStreamCopier, "init");
this.addClass("Xmlhttp", "@mozilla.org/xmlextras/xmlhttprequest;1", Ci.nsIXMLHttpRequest);
this.addClass("ZipReader", "@mozilla.org/libjar/zip-reader;1", Ci.nsIZipReader, "open");
this.addClass("ZipWriter", "@mozilla.org/zipwriter;1", Ci.nsIZipWriter);
if (!this.extensionManager)
if (!Ci.nsIExtensionManager || !this.extensionManager)
Components.utils.import("resource://gre/modules/AddonManager.jsm");
else
global.AddonManager = {
@@ -162,15 +167,24 @@ var Services = Module("Services", {
if (!ifaces)
return res.wrappedJSObject;
Array.concat(ifaces).forEach(function (iface) res.QueryInterface(iface));
if (init && args.length)
if (callable(res[init]))
if (init && args.length) {
try {
var isCallable = callable(res[init]);
}
catch (e) {} // Ugh.
if (isCallable)
res[init].apply(res, args);
else
res[init] = args[0];
}
return res;
}
catch (e) {
dump("dactyl: Service creation failed for '" + classes + "': " + e + "\n");
if (typeof util !== "undefined")
util.reportError(e);
else
dump("dactyl: Service creation failed for '" + classes + "': " + e + "\n" + (e.stack || Error(e).stack));
return null;
}
},

View File

@@ -478,7 +478,7 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
stackLines: function (stack) {
let lines = [];
let match, re = /([^]*?)(@.*?)(?:\n|$)/g;
let match, re = /([^]*?)(@[^@\n]*)(?:\n|$)/g;
while (match = re.exec(stack))
lines.push(match[1].replace(/\n/g, "\\n").substr(0, 80) + match[2]);
return lines;
@@ -930,6 +930,8 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
util.trapErrors(module.cleanup, module);
}
JSMLoader.cleanup();
services.observer.addObserver(this, "dactyl-rehash", true);
},
"dactyl-rehash": function () {