1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-20 20:27:58 +01:00

Allow the creation of language pack XPIs.

This commit is contained in:
Kris Maglione
2011-03-04 18:59:24 -05:00
parent c82138567e
commit f3c14e861c
3 changed files with 97 additions and 79 deletions

View File

@@ -21,13 +21,15 @@ var global = this;
var Cc = Components.classes; var Cc = Components.classes;
var Ci = Components.interfaces; var Ci = Components.interfaces;
var Cu = Components.utils; var Cu = Components.utils;
var DNE = "resource://dactyl/content/does/not/exist";
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
var ioService = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService); var ioService = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
var systemPrincipal = Cc["@mozilla.org/systemprincipal;1"].getService(Ci.nsIPrincipal); var systemPrincipal = Cc["@mozilla.org/systemprincipal;1"].getService(Ci.nsIPrincipal);
var DNE = "resource://dactyl/content/does/not/exist";
var _DNE = ioService.newChannel(DNE, null, null).name;
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
function makeChannel(url, orig) { function makeChannel(url, orig) {
try { try {
if (url == null) if (url == null)
@@ -216,11 +218,12 @@ Dactyl.prototype = {
} }
}; };
function LocaleChannel(base, path, orig) { function LocaleChannel(pkg, path, orig) {
for each (let locale in [config.locale, "en-US"]) { for each (let locale in [config.locale, "en-US"])
var channel = makeChannel(["resource:/", base, config.locale, path].join("/"), orig); for each (let sep in "-/") {
if (channel.name !== DNE) var channel = makeChannel(["resource:/", pkg + sep + config.locale, path].join("/"), orig);
break; if (channel.name !== _DNE)
return channel;
} }
return channel; return channel;
} }
@@ -238,8 +241,8 @@ function StringChannel(data, contentType, uri) {
} }
function XMLChannel(uri, contentType) { function XMLChannel(uri, contentType) {
var channel = services.io.newChannelFromURI(uri);
try { try {
var channel = services.io.newChannelFromURI(uri);
var channelStream = channel.open(); var channelStream = channel.open();
} }
catch (e) { catch (e) {

View File

@@ -91,15 +91,29 @@ var ConfigBase = Class("ConfigBase", {
let jar = io.isJarURL(uri); let jar = io.isJarURL(uri);
if (jar) { if (jar) {
let prefix = getDir(jar.JAREntry); let prefix = getDir(jar.JAREntry);
return iter(s.slice(prefix.length).replace(/\/.*/, "") for (s in io.listJar(jar.JARFile, prefix))) var res = iter(s.slice(prefix.length).replace(/\/.*/, "") for (s in io.listJar(jar.JARFile, prefix)))
.uniq().toArray(); .toArray();
} }
else { else {
return array(f.leafName res = array(f.leafName
// Fails on FF3: for (f in util.getFile(uri).iterDirectory()) // Fails on FF3: for (f in util.getFile(uri).iterDirectory())
for (f in values(util.getFile(uri).readDirectory())) for (f in values(util.getFile(uri).readDirectory()))
if (f.isDirectory())).array; if (f.isDirectory())).array;
} }
function exists(pkg) {
try {
services["resource:"].getSubstitution(pkg);
return true;
}
catch (e) {
return false;
}
}
return array.uniq([this.appLocale, this.appLocale.replace(/-.*/, "")]
.filter(function (locale) exists("dactyl-locale-" + locale))
.concat(res));
}), }),
/** /**

View File

@@ -20,71 +20,72 @@ var Services = Module("Services", {
init: function () { init: function () {
this.services = {}; this.services = {};
this.add("annotation", "@mozilla.org/browser/annotation-service;1", Ci.nsIAnnotationService); this.add("annotation", "@mozilla.org/browser/annotation-service;1", "nsIAnnotationService");
this.add("appShell", "@mozilla.org/appshell/appShellService;1", Ci.nsIAppShellService); this.add("appShell", "@mozilla.org/appshell/appShellService;1", "nsIAppShellService");
this.add("appStartup", "@mozilla.org/toolkit/app-startup;1", Ci.nsIAppStartup); this.add("appStartup", "@mozilla.org/toolkit/app-startup;1", "nsIAppStartup");
this.add("autoCompleteSearch", "@mozilla.org/autocomplete/search;1?name=history", Ci.nsIAutoCompleteSearch); this.add("autoCompleteSearch", "@mozilla.org/autocomplete/search;1?name=history", "nsIAutoCompleteSearch");
this.add("bookmarks", "@mozilla.org/browser/nav-bookmarks-service;1", Ci.nsINavBookmarksService); this.add("bookmarks", "@mozilla.org/browser/nav-bookmarks-service;1", "nsINavBookmarksService");
this.add("browserSearch", "@mozilla.org/browser/search-service;1", Ci.nsIBrowserSearchService); this.add("browserSearch", "@mozilla.org/browser/search-service;1", "nsIBrowserSearchService");
this.add("cache", "@mozilla.org/network/cache-service;1", Ci.nsICacheService); this.add("cache", "@mozilla.org/network/cache-service;1", "nsICacheService");
this.add("charset", "@mozilla.org/charset-converter-manager;1", Ci.nsICharsetConverterManager); this.add("charset", "@mozilla.org/charset-converter-manager;1", "nsICharsetConverterManager");
this.add("chromeRegistry", "@mozilla.org/chrome/chrome-registry;1", Ci.nsIXULChromeRegistry); this.add("chromeRegistry", "@mozilla.org/chrome/chrome-registry;1", "nsIXULChromeRegistry");
this.add("commandLineHandler", "@mozilla.org/commandlinehandler/general-startup;1?type=dactyl"); this.add("commandLineHandler", "@mozilla.org/commandlinehandler/general-startup;1?type=dactyl");
this.add("console", "@mozilla.org/consoleservice;1", Ci.nsIConsoleService); this.add("console", "@mozilla.org/consoleservice;1", "nsIConsoleService");
this.add("dactyl:", "@mozilla.org/network/protocol;1?name=dactyl"); this.add("dactyl:", "@mozilla.org/network/protocol;1?name=dactyl");
this.add("debugger", "@mozilla.org/js/jsd/debugger-service;1", Ci.jsdIDebuggerService); this.add("debugger", "@mozilla.org/js/jsd/debugger-service;1", "jsdIDebuggerService");
this.add("directory", "@mozilla.org/file/directory_service;1", Ci.nsIProperties); this.add("directory", "@mozilla.org/file/directory_service;1", "nsIProperties");
this.add("downloadManager", "@mozilla.org/download-manager;1", Ci.nsIDownloadManager); this.add("downloadManager", "@mozilla.org/download-manager;1", "nsIDownloadManager");
this.add("environment", "@mozilla.org/process/environment;1", Ci.nsIEnvironment); this.add("environment", "@mozilla.org/process/environment;1", "nsIEnvironment");
this.add("extensionManager", "@mozilla.org/extensions/manager;1", Ci.nsIExtensionManager); this.add("extensionManager", "@mozilla.org/extensions/manager;1", "nsIExtensionManager");
this.add("externalProtocol", "@mozilla.org/uriloader/external-protocol-service;1", Ci.nsIExternalProtocolService); this.add("externalProtocol", "@mozilla.org/uriloader/external-protocol-service;1", "nsIExternalProtocolService");
this.add("favicon", "@mozilla.org/browser/favicon-service;1", Ci.nsIFaviconService); this.add("favicon", "@mozilla.org/browser/favicon-service;1", "nsIFaviconService");
this.add("focus", "@mozilla.org/focus-manager;1", Ci.nsIFocusManager); this.add("focus", "@mozilla.org/focus-manager;1", "nsIFocusManager");
this.add("history", "@mozilla.org/browser/global-history;2", this.add("history", "@mozilla.org/browser/global-history;2",
[Ci.nsIBrowserHistory, Ci.nsIGlobalHistory3, Ci.nsINavHistoryService, Ci.nsPIPlacesDatabase]); ["nsIBrowserHistory", "nsIGlobalHistory3", "nsINavHistoryService", "nsPIPlacesDatabase"]);
this.add("io", "@mozilla.org/network/io-service;1", Ci.nsIIOService); this.add("io", "@mozilla.org/network/io-service;1", "nsIIOService");
this.add("json", "@mozilla.org/dom/json;1", Ci.nsIJSON, "createInstance"); this.add("json", "@mozilla.org/dom/json;1", "nsIJSON", "createInstance");
this.add("livemark", "@mozilla.org/browser/livemark-service;2", Ci.nsILivemarkService); this.add("livemark", "@mozilla.org/browser/livemark-service;2", "nsILivemarkService");
this.add("mime", "@mozilla.org/mime;1", Ci.nsIMIMEService); this.add("mime", "@mozilla.org/mime;1", "nsIMIMEService");
this.add("observer", "@mozilla.org/observer-service;1", Ci.nsIObserverService); this.add("observer", "@mozilla.org/observer-service;1", "nsIObserverService");
this.add("pref", "@mozilla.org/preferences-service;1", [Ci.nsIPrefBranch2, Ci.nsIPrefService]); this.add("pref", "@mozilla.org/preferences-service;1", ["nsIPrefBranch2", "nsIPrefService"]);
this.add("privateBrowsing", "@mozilla.org/privatebrowsing;1", Ci.nsIPrivateBrowsingService); this.add("privateBrowsing", "@mozilla.org/privatebrowsing;1", "nsIPrivateBrowsingService");
this.add("profile", "@mozilla.org/toolkit/profile-service;1", Ci.nsIToolkitProfileService); this.add("profile", "@mozilla.org/toolkit/profile-service;1", "nsIToolkitProfileService");
this.add("runtime", "@mozilla.org/xre/runtime;1", [Ci.nsIXULAppInfo, Ci.nsIXULRuntime]); this.add("resource:", "@mozilla.org/network/protocol;1?name=resource", ["nsIProtocolHandler", "nsIResProtocolHandler"]);
this.add("rdf", "@mozilla.org/rdf/rdf-service;1", Ci.nsIRDFService); this.add("runtime", "@mozilla.org/xre/runtime;1", ["nsIXULAppInfo", "nsIXULRuntime"]);
this.add("sessionStore", "@mozilla.org/browser/sessionstore;1", Ci.nsISessionStore); this.add("rdf", "@mozilla.org/rdf/rdf-service;1", "nsIRDFService");
this.add("stringBundle", "@mozilla.org/intl/stringbundle;1", Ci.nsIStringBundleService); this.add("sessionStore", "@mozilla.org/browser/sessionstore;1", "nsISessionStore");
this.add("stylesheet", "@mozilla.org/content/style-sheet-service;1", Ci.nsIStyleSheetService); this.add("stringBundle", "@mozilla.org/intl/stringbundle;1", "nsIStringBundleService");
this.add("subscriptLoader", "@mozilla.org/moz/jssubscript-loader;1", Ci.mozIJSSubScriptLoader); this.add("stylesheet", "@mozilla.org/content/style-sheet-service;1", "nsIStyleSheetService");
this.add("tagging", "@mozilla.org/browser/tagging-service;1", Ci.nsITaggingService); this.add("subscriptLoader", "@mozilla.org/moz/jssubscript-loader;1", "mozIJSSubScriptLoader");
this.add("threading", "@mozilla.org/thread-manager;1", Ci.nsIThreadManager); this.add("tagging", "@mozilla.org/browser/tagging-service;1", "nsITaggingService");
this.add("urifixup", "@mozilla.org/docshell/urifixup;1", Ci.nsIURIFixup); this.add("threading", "@mozilla.org/thread-manager;1", "nsIThreadManager");
this.add("versionCompare", "@mozilla.org/xpcom/version-comparator;1", Ci.nsIVersionComparator); this.add("urifixup", "@mozilla.org/docshell/urifixup;1", "nsIURIFixup");
this.add("windowMediator", "@mozilla.org/appshell/window-mediator;1", Ci.nsIWindowMediator); this.add("versionCompare", "@mozilla.org/xpcom/version-comparator;1", "nsIVersionComparator");
this.add("windowWatcher", "@mozilla.org/embedcomp/window-watcher;1", Ci.nsIWindowWatcher); this.add("windowMediator", "@mozilla.org/appshell/window-mediator;1", "nsIWindowMediator");
this.add("zipReader", "@mozilla.org/libjar/zip-reader-cache;1", Ci.nsIZipReaderCache); this.add("windowWatcher", "@mozilla.org/embedcomp/window-watcher;1", "nsIWindowWatcher");
this.add("zipReader", "@mozilla.org/libjar/zip-reader-cache;1", "nsIZipReaderCache");
this.addClass("CharsetConv", "@mozilla.org/intl/scriptableunicodeconverter", Ci.nsIScriptableUnicodeConverter, "charset"); this.addClass("CharsetConv", "@mozilla.org/intl/scriptableunicodeconverter", "nsIScriptableUnicodeConverter", "charset");
this.addClass("File", "@mozilla.org/file/local;1", Ci.nsILocalFile); this.addClass("File", "@mozilla.org/file/local;1", "nsILocalFile");
this.addClass("file:", "@mozilla.org/network/protocol;1?name=file", Ci.nsIFileProtocolHandler); this.addClass("file:", "@mozilla.org/network/protocol;1?name=file", "nsIFileProtocolHandler");
this.addClass("Find", "@mozilla.org/embedcomp/rangefind;1", Ci.nsIFind); this.addClass("Find", "@mozilla.org/embedcomp/rangefind;1", "nsIFind");
this.addClass("HtmlConverter","@mozilla.org/widget/htmlformatconverter;1", Ci.nsIFormatConverter); this.addClass("HtmlConverter","@mozilla.org/widget/htmlformatconverter;1", "nsIFormatConverter");
this.addClass("HtmlEncoder", "@mozilla.org/layout/htmlCopyEncoder;1", Ci.nsIDocumentEncoder); this.addClass("HtmlEncoder", "@mozilla.org/layout/htmlCopyEncoder;1", "nsIDocumentEncoder");
this.addClass("InputStream", "@mozilla.org/scriptableinputstream;1", Ci.nsIScriptableInputStream, "init"); this.addClass("InputStream", "@mozilla.org/scriptableinputstream;1", "nsIScriptableInputStream", "init");
this.addClass("Persist", "@mozilla.org/embedding/browser/nsWebBrowserPersist;1", Ci.nsIWebBrowserPersist); this.addClass("Persist", "@mozilla.org/embedding/browser/nsWebBrowserPersist;1", "nsIWebBrowserPersist");
this.addClass("Pipe", "@mozilla.org/pipe;1", Ci.nsIPipe, "init"); this.addClass("Pipe", "@mozilla.org/pipe;1", "nsIPipe", "init");
this.addClass("Process", "@mozilla.org/process/util;1", Ci.nsIProcess, "init"); this.addClass("Process", "@mozilla.org/process/util;1", "nsIProcess", "init");
this.addClass("StreamChannel","@mozilla.org/network/input-stream-channel;1", this.addClass("StreamChannel","@mozilla.org/network/input-stream-channel;1",
[Ci.nsIChannel, Ci.nsIInputStreamChannel, Ci.nsIRequest], "setURI"); ["nsIChannel", "nsIInputStreamChannel", "nsIRequest"], "setURI");
this.addClass("StreamCopier", "@mozilla.org/network/async-stream-copier;1",Ci.nsIAsyncStreamCopier, "init"); this.addClass("StreamCopier", "@mozilla.org/network/async-stream-copier;1","nsIAsyncStreamCopier", "init");
this.addClass("String", "@mozilla.org/supports-string;1", Ci.nsISupportsString, "data"); this.addClass("String", "@mozilla.org/supports-string;1", "nsISupportsString", "data");
this.addClass("StringStream", "@mozilla.org/io/string-input-stream;1", Ci.nsIStringInputStream, "data"); this.addClass("StringStream", "@mozilla.org/io/string-input-stream;1", "nsIStringInputStream", "data");
this.addClass("Transfer", "@mozilla.org/transfer;1", Ci.nsITransfer, "init"); this.addClass("Transfer", "@mozilla.org/transfer;1", "nsITransfer", "init");
this.addClass("Timer", "@mozilla.org/timer;1", Ci.nsITimer, "initWithCallback"); this.addClass("Timer", "@mozilla.org/timer;1", "nsITimer", "initWithCallback");
this.addClass("Xmlhttp", "@mozilla.org/xmlextras/xmlhttprequest;1", Ci.nsIXMLHttpRequest); this.addClass("Xmlhttp", "@mozilla.org/xmlextras/xmlhttprequest;1", "nsIXMLHttpRequest");
this.addClass("XPathEvaluator", "@mozilla.org/dom/xpath-evaluator;1", Ci.nsIDOMXPathEvaluator); this.addClass("XPathEvaluator", "@mozilla.org/dom/xpath-evaluator;1", "nsIDOMXPathEvaluator");
this.addClass("ZipReader", "@mozilla.org/libjar/zip-reader;1", Ci.nsIZipReader, "open"); this.addClass("ZipReader", "@mozilla.org/libjar/zip-reader;1", "nsIZipReader", "open");
this.addClass("ZipWriter", "@mozilla.org/zipwriter;1", Ci.nsIZipWriter); this.addClass("ZipWriter", "@mozilla.org/zipwriter;1", "nsIZipWriter");
}, },
reinit: function () {}, reinit: function () {},
@@ -93,7 +94,7 @@ var Services = Module("Services", {
let res = Cc[classes][meth || "getService"](); let res = Cc[classes][meth || "getService"]();
if (!ifaces) if (!ifaces)
return res["wrapped" + "JSObject"]; // Kill stupid validator warning return res["wrapped" + "JSObject"]; // Kill stupid validator warning
Array.concat(ifaces).forEach(function (iface) res.QueryInterface(iface)); Array.concat(ifaces).forEach(function (iface) res.QueryInterface(Ci[iface]));
if (init && args.length) { if (init && args.length) {
try { try {
var isCallable = callable(res[init]); var isCallable = callable(res[init]);
@@ -121,7 +122,7 @@ var Services = Module("Services", {
* *
* @param {string} name The service's cache key. * @param {string} name The service's cache key.
* @param {string} class The class's contract ID. * @param {string} class The class's contract ID.
* @param {nsISupports|nsISupports[]} ifaces The interface or array of * @param {string|string[]} ifaces The interface or array of
* interfaces implemented by this service. * interfaces implemented by this service.
* @param {string} meth The name of the function used to instantiate * @param {string} meth The name of the function used to instantiate
* the service. * the service.
@@ -147,7 +148,7 @@ var Services = Module("Services", {
addClass: function (name, class_, ifaces, init) { addClass: function (name, class_, ifaces, init) {
const self = this; const self = this;
this[name] = function () self._create(class_, ifaces, "createInstance", init, arguments); this[name] = function () self._create(class_, ifaces, "createInstance", init, arguments);
update.apply(null, [this[name]].concat(ifaces)); update.apply(null, [this[name]].concat([Ci[i] for each (i in ifaces)]));
return this[name]; return this[name];
}, },