mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-20 23:17:59 +01:00
More bootstrap work.
--HG-- branch : bootstrapped
This commit is contained in:
@@ -13,6 +13,7 @@ syntax: glob
|
|||||||
*/contrib/vim/*.vba
|
*/contrib/vim/*.vba
|
||||||
*/bak/*
|
*/bak/*
|
||||||
downloads/*
|
downloads/*
|
||||||
|
.git/*
|
||||||
|
|
||||||
*.py[co]
|
*.py[co]
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ CHROME = chrome/
|
|||||||
JAR = $(CHROME)$(NAME).jar
|
JAR = $(CHROME)$(NAME).jar
|
||||||
|
|
||||||
XPI_BASES = $(JAR_BASES) $(TOP)/..
|
XPI_BASES = $(JAR_BASES) $(TOP)/..
|
||||||
XPI_FILES = install.rdf TODO AUTHORS Donors NEWS LICENSE.txt
|
XPI_FILES = bootstrap.js install.rdf TODO AUTHORS Donors NEWS LICENSE.txt
|
||||||
XPI_DIRS = modules components chrome defaults
|
XPI_DIRS = modules components chrome defaults
|
||||||
XPI_TEXTS = js jsm $(JAR_TEXTS)
|
XPI_TEXTS = js jsm $(JAR_TEXTS)
|
||||||
XPI_BINS = $(JAR_BINS)
|
XPI_BINS = $(JAR_BINS)
|
||||||
|
|||||||
169
common/bootstrap.js
vendored
Executable file
169
common/bootstrap.js
vendored
Executable file
@@ -0,0 +1,169 @@
|
|||||||
|
// 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");
|
||||||
|
|
||||||
|
const io = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
|
||||||
|
const resourceProto = io.getProtocolHandler("resource")
|
||||||
|
.QueryInterface(Ci.nsIResProtocolHandler);
|
||||||
|
const categoryManager = Cc["@mozilla.org/categorymanager;1"].getService(Ci.nsICategoryManager);
|
||||||
|
const manager = Components.manager.QueryInterface(Ci.nsIComponentRegistrar);
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
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),
|
||||||
|
init: function () {
|
||||||
|
manager.registerFactory(this.classID,
|
||||||
|
String(this.classID),
|
||||||
|
this.contractID,
|
||||||
|
this);
|
||||||
|
},
|
||||||
|
get module() {
|
||||||
|
Class.replaceProperty(this, "module", {});
|
||||||
|
Cu.import(this.url, this.module);
|
||||||
|
return this.module;
|
||||||
|
},
|
||||||
|
createInstance: function ()
|
||||||
|
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 = [];
|
||||||
|
let components = {};
|
||||||
|
|
||||||
|
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]].init();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "resource":
|
||||||
|
resourceProto.setSubstitution(fields[1], addon.getResourceURI(fields[2]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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(file.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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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 shutdown(data, reason) { dump("dactyl: bootstrap: shutdown\n") }
|
||||||
|
function uninstall(data, reason) { dump("dactyl: bootstrap: uninstall\n") }
|
||||||
|
|
||||||
@@ -48,5 +48,6 @@ if (XPCOMUtils.generateNSGetFactory)
|
|||||||
const NSGetFactory = XPCOMUtils.generateNSGetFactory([CommandLineHandler]);
|
const NSGetFactory = XPCOMUtils.generateNSGetFactory([CommandLineHandler]);
|
||||||
else
|
else
|
||||||
const NSGetModule = XPCOMUtils.generateNSGetModule([CommandLineHandler]);
|
const NSGetModule = XPCOMUtils.generateNSGetModule([CommandLineHandler]);
|
||||||
|
var EXPORTED_SYMBOLS = ["NSGetFactory"];
|
||||||
|
|
||||||
// vim: set fdm=marker sw=4 ts=4 et:
|
// vim: set fdm=marker sw=4 ts=4 et:
|
||||||
|
|||||||
@@ -12,13 +12,15 @@
|
|||||||
* By Kris Maglione, ideas from Ed Anuff's nsChromeExtensionHandler.
|
* By Kris Maglione, ideas from Ed Anuff's nsChromeExtensionHandler.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const Ci = Components.interfaces, Cc = Components.classes;
|
const NAME = "protocols";
|
||||||
|
const global = this;
|
||||||
|
const Cc = Components.classes;
|
||||||
|
const Ci = Components.interfaces;
|
||||||
|
const Cu = Components.utils;
|
||||||
|
|
||||||
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
|
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||||
|
|
||||||
const ioService = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
|
const ioService = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
|
||||||
const prefs = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefService)
|
|
||||||
.getBranch("extensions.dactyl.");
|
|
||||||
const systemPrincipal = Cc["@mozilla.org/systemprincipal;1"].getService(Ci.nsIPrincipal);
|
const systemPrincipal = Cc["@mozilla.org/systemprincipal;1"].getService(Ci.nsIPrincipal);
|
||||||
|
|
||||||
function dataURL(type, data) "data:" + (type || "application/xml;encoding=UTF-8") + "," + escape(data);
|
function dataURL(type, data) "data:" + (type || "application/xml;encoding=UTF-8") + "," + escape(data);
|
||||||
@@ -97,10 +99,15 @@ function Dactyl() {
|
|||||||
this.OVERLAY_MAP = {};
|
this.OVERLAY_MAP = {};
|
||||||
|
|
||||||
this.pages = {};
|
this.pages = {};
|
||||||
for each (let pref in ["appName", "fileExt", "host", "hostbin", "idName", "name"])
|
|
||||||
this[pref] = prefs.getComplexValue(pref, Ci.nsISupportsString).data;
|
|
||||||
|
|
||||||
this.addonID = this.name + "@dactyl.googlecode.com";
|
Cu.import("resource://dactyl/base.jsm");
|
||||||
|
require(global, "prefs");
|
||||||
|
|
||||||
|
["appName", "fileExt", "host", "hostbin", "idName", "name", "version"].forEach(function (pref)
|
||||||
|
this.__defineGetter__(pref, function () prefs.get("extensions.dactyl." + pref, "dactyl")),
|
||||||
|
this);
|
||||||
|
|
||||||
|
memoize(this, "addonID", function () this.name + "@dactyl.googlecode.com");
|
||||||
}
|
}
|
||||||
Dactyl.prototype = {
|
Dactyl.prototype = {
|
||||||
contractID: "@mozilla.org/network/protocol;1?name=dactyl",
|
contractID: "@mozilla.org/network/protocol;1?name=dactyl",
|
||||||
@@ -109,8 +116,6 @@ Dactyl.prototype = {
|
|||||||
QueryInterface: XPCOMUtils.generateQI([Ci.nsIProtocolHandler]),
|
QueryInterface: XPCOMUtils.generateQI([Ci.nsIProtocolHandler]),
|
||||||
_xpcom_factory: Factory(Dactyl),
|
_xpcom_factory: Factory(Dactyl),
|
||||||
|
|
||||||
get version() prefs.getComplexValue("version", Ci.nsISupportsString).data,
|
|
||||||
|
|
||||||
init: function (obj) {
|
init: function (obj) {
|
||||||
for each (let prop in ["HELP_TAGS", "FILE_MAP", "OVERLAY_MAP"]) {
|
for each (let prop in ["HELP_TAGS", "FILE_MAP", "OVERLAY_MAP"]) {
|
||||||
this[prop] = this[prop].constructor();
|
this[prop] = this[prop].constructor();
|
||||||
@@ -202,5 +207,6 @@ if (XPCOMUtils.generateNSGetFactory)
|
|||||||
const NSGetFactory = XPCOMUtils.generateNSGetFactory([AboutHandler, ChromeData, Dactyl, Shim]);
|
const NSGetFactory = XPCOMUtils.generateNSGetFactory([AboutHandler, ChromeData, Dactyl, Shim]);
|
||||||
else
|
else
|
||||||
const NSGetModule = XPCOMUtils.generateNSGetModule([AboutHandler, ChromeData, Dactyl, Shim]);
|
const NSGetModule = XPCOMUtils.generateNSGetModule([AboutHandler, ChromeData, Dactyl, Shim]);
|
||||||
|
var EXPORTED_SYMBOLS = ["NSGetFactory"];
|
||||||
|
|
||||||
// vim: set fdm=marker sw=4 ts=4 et:
|
// vim: set fdm=marker sw=4 ts=4 et:
|
||||||
|
|||||||
@@ -530,9 +530,9 @@ const CompletionContext = Class("CompletionContext", {
|
|||||||
// of the given string which also matches the current
|
// of the given string which also matches the current
|
||||||
// item's text.
|
// item's text.
|
||||||
let len = substring.length;
|
let len = substring.length;
|
||||||
let i = 0, m, n = len;
|
let i = 0, n = len;
|
||||||
while (n) {
|
while (n) {
|
||||||
m = Math.floor(n / 2);
|
let m = Math.floor(n / 2);
|
||||||
let keep = compare(fixCase(item.text), substring.substring(0, i + m));
|
let keep = compare(fixCase(item.text), substring.substring(0, i + m));
|
||||||
if (!keep)
|
if (!keep)
|
||||||
len = i + m - 1;
|
len = i + m - 1;
|
||||||
|
|||||||
@@ -391,7 +391,6 @@ const Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase),
|
|||||||
|
|
||||||
focus: function focus(elem, flags) {
|
focus: function focus(elem, flags) {
|
||||||
flags = flags || services.focus.FLAG_BYMOUSE;
|
flags = flags || services.focus.FLAG_BYMOUSE;
|
||||||
util.dumpStack();
|
|
||||||
try {
|
try {
|
||||||
if (elem instanceof Document)
|
if (elem instanceof Document)
|
||||||
elem = elem.defaultView;
|
elem = elem.defaultView;
|
||||||
|
|||||||
@@ -286,7 +286,6 @@ const Modes = Module("modes", {
|
|||||||
},
|
},
|
||||||
|
|
||||||
push: function push(mainMode, extendedMode, params) {
|
push: function push(mainMode, extendedMode, params) {
|
||||||
util.dumpStack();
|
|
||||||
this.set(mainMode, extendedMode, params, { push: this.topOfStack });
|
this.set(mainMode, extendedMode, params, { push: this.topOfStack });
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@@ -126,7 +126,7 @@ defineModule.dump = function dump_() {
|
|||||||
msg = util.objectToString(msg);
|
msg = util.objectToString(msg);
|
||||||
return msg;
|
return msg;
|
||||||
}).join(", ");
|
}).join(", ");
|
||||||
let name = loaded.services ? services["dactyl:"].name : "dactyl";
|
let name = loaded.services && loaded.prefs && services["dactyl:"] ? services["dactyl:"].name : "dactyl";
|
||||||
dump(String.replace(msg, /\n?$/, "\n")
|
dump(String.replace(msg, /\n?$/, "\n")
|
||||||
.replace(/^./gm, name + ": $&"));
|
.replace(/^./gm, name + ": $&"));
|
||||||
}
|
}
|
||||||
@@ -179,8 +179,8 @@ defineModule("base", {
|
|||||||
"call", "callable", "ctypes", "curry", "debuggerProperties", "defineModule",
|
"call", "callable", "ctypes", "curry", "debuggerProperties", "defineModule",
|
||||||
"deprecated", "endModule", "forEach", "isArray", "isGenerator",
|
"deprecated", "endModule", "forEach", "isArray", "isGenerator",
|
||||||
"isinstance", "isObject", "isString", "isSubclass", "iter", "iterAll",
|
"isinstance", "isObject", "isString", "isSubclass", "iter", "iterAll",
|
||||||
"keys", "memoize", "octal", "properties", "set", "update", "values",
|
"keys", "memoize", "octal", "properties", "require", "set", "update",
|
||||||
"withCallerGlobal"
|
"values", "withCallerGlobal"
|
||||||
],
|
],
|
||||||
use: ["services", "util"]
|
use: ["services", "util"]
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -8,8 +8,7 @@ try {
|
|||||||
|
|
||||||
Components.utils.import("resource://dactyl/base.jsm");
|
Components.utils.import("resource://dactyl/base.jsm");
|
||||||
defineModule("services", {
|
defineModule("services", {
|
||||||
exports: ["Services", "services"],
|
exports: ["AddonManager", "Services", "services"]
|
||||||
use: ["util"]
|
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -72,6 +71,9 @@ const Services = Module("Services", {
|
|||||||
this.addClass("Xmlhttp", "@mozilla.org/xmlextras/xmlhttprequest;1", Ci.nsIXMLHttpRequest);
|
this.addClass("Xmlhttp", "@mozilla.org/xmlextras/xmlhttprequest;1", Ci.nsIXMLHttpRequest);
|
||||||
this.addClass("ZipReader", "@mozilla.org/libjar/zip-reader;1", Ci.nsIZipReader, "open");
|
this.addClass("ZipReader", "@mozilla.org/libjar/zip-reader;1", Ci.nsIZipReader, "open");
|
||||||
this.addClass("ZipWriter", "@mozilla.org/zipwriter;1", Ci.nsIZipWriter);
|
this.addClass("ZipWriter", "@mozilla.org/zipwriter;1", Ci.nsIZipWriter);
|
||||||
|
|
||||||
|
if (!this.extensionManager)
|
||||||
|
Components.utils.import("resource://gre/modules/AddonManager.jsm");
|
||||||
},
|
},
|
||||||
|
|
||||||
_create: function (classes, ifaces, meth, init, args) {
|
_create: function (classes, ifaces, meth, init, args) {
|
||||||
@@ -85,7 +87,7 @@ const Services = Module("Services", {
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
util.dump("Service creation failed for '" + classes + "': " + e + "\n");
|
dump("dactyl: Service creation failed for '" + classes + "': " + e + "\n");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -105,8 +107,12 @@ const Services = Module("Services", {
|
|||||||
if (name in this && ifaces && !this.__lookupGetter__(name) && !(this[name] instanceof Ci.nsISupports))
|
if (name in this && ifaces && !this.__lookupGetter__(name) && !(this[name] instanceof Ci.nsISupports))
|
||||||
throw TypeError();
|
throw TypeError();
|
||||||
this.__defineGetter__(name, function () {
|
this.__defineGetter__(name, function () {
|
||||||
|
let res = self._create(class_, ifaces, meth);
|
||||||
|
if (!res)
|
||||||
|
return null;
|
||||||
|
|
||||||
delete this[name];
|
delete this[name];
|
||||||
return this[name] = self._create(class_, ifaces, meth);
|
return this[name] = res;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -140,10 +146,6 @@ const Services = Module("Services", {
|
|||||||
get: function (name) this[name],
|
get: function (name) this[name],
|
||||||
}, {
|
}, {
|
||||||
}, {
|
}, {
|
||||||
init: function (dactyl, modules) {
|
|
||||||
if (!modules.AddonManager && !this.get("extensionManager"))
|
|
||||||
Components.utils.import("resource://gre/modules/AddonManager.jsm", modules);
|
|
||||||
},
|
|
||||||
javascript: function (dactyl, modules) {
|
javascript: function (dactyl, modules) {
|
||||||
modules.JavaScript.setCompleter(this.get, [function () [[k, v] for ([k, v] in Iterator(services)) if (v instanceof Ci.nsISupports)]]);
|
modules.JavaScript.setCompleter(this.get, [function () [[k, v] for ([k, v] in Iterator(services)) if (v instanceof Ci.nsISupports)]]);
|
||||||
modules.JavaScript.setCompleter(this.create, [function () [[c, ""] for (c in services.classes)]]);
|
modules.JavaScript.setCompleter(this.create, [function () [[c, ""] for (c in services.classes)]]);
|
||||||
|
|||||||
1
pentadactyl/bootstrap.js
vendored
Symbolic link
1
pentadactyl/bootstrap.js
vendored
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
../common/bootstrap.js
|
||||||
@@ -8,7 +8,8 @@
|
|||||||
em:description="Firefox for Vim and Links addicts"
|
em:description="Firefox for Vim and Links addicts"
|
||||||
em:homepageURL="http://dactyl.sourceforge.net/pentadactyl"
|
em:homepageURL="http://dactyl.sourceforge.net/pentadactyl"
|
||||||
em:iconURL="chrome://pentadactyl/skin/icon.png"
|
em:iconURL="chrome://pentadactyl/skin/icon.png"
|
||||||
em:optionsURL="chrome://dactyl/content/preferences.xul">
|
em:optionsURL="chrome://dactyl/content/preferences.xul"
|
||||||
|
em:bootstrap="true">
|
||||||
|
|
||||||
<em:creator>Kris Maglione, Doug Kearns</em:creator>
|
<em:creator>Kris Maglione, Doug Kearns</em:creator>
|
||||||
<em:developer>Štěpán Němec</em:developer>
|
<em:developer>Štěpán Němec</em:developer>
|
||||||
|
|||||||
Reference in New Issue
Block a user