mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2026-01-09 01:04:12 +01:00
Fix some cleanup issues. Better error pages for bad dactyl: URLs. Remove some dead code. Other cleanup.
This commit is contained in:
@@ -851,7 +851,7 @@ Class.extend = function extend(subclass, superclass, overrides) {
|
||||
* property's value.
|
||||
* @returns {Class.Property}
|
||||
*/
|
||||
Class.memoize = function memoize(getter, wait)
|
||||
Class.Memoize = Class.memoize = function Memoize(getter, wait)
|
||||
Class.Property({
|
||||
configurable: true,
|
||||
enumerable: true,
|
||||
@@ -893,6 +893,19 @@ Class.memoize = function memoize(getter, wait)
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Updates the given object with the object in the target class's
|
||||
* prototype.
|
||||
*/
|
||||
Class.Update = function Update(obj)
|
||||
Class.Property({
|
||||
configurable: true,
|
||||
enumerable: true,
|
||||
init: function (key, target) {
|
||||
this.value = update({}, target[key], obj);
|
||||
}
|
||||
});
|
||||
|
||||
Class.replaceProperty = function replaceProperty(obj, prop, value) {
|
||||
Object.defineProperty(obj, prop, { configurable: true, enumerable: true, value: value, writable: true });
|
||||
return value;
|
||||
|
||||
@@ -14,11 +14,6 @@ var BOOTSTRAP_CONTRACT = "@dactyl.googlecode.com/base/bootstrap";
|
||||
var JSMLoader = BOOTSTRAP_CONTRACT in Components.classes &&
|
||||
Components.classes[BOOTSTRAP_CONTRACT].getService().wrappedJSObject.loader;
|
||||
|
||||
if (!JSMLoader && "@mozilla.org/fuel/application;1" in Components.classes)
|
||||
JSMLoader = Components.classes["@mozilla.org/fuel/application;1"]
|
||||
.getService(Components.interfaces.extIApplication)
|
||||
.storage.get("dactyl.JSMLoader", null);
|
||||
|
||||
if (JSMLoader && JSMLoader.bump === 6)
|
||||
JSMLoader.global = this;
|
||||
else
|
||||
@@ -133,6 +128,8 @@ else
|
||||
purge: function purge() {
|
||||
dump("dactyl: JSMLoader: purge\n");
|
||||
|
||||
this.bootstrap = null;
|
||||
|
||||
if (Cu.unload) {
|
||||
Object.keys(this.modules).reverse().forEach(function (url) {
|
||||
try {
|
||||
|
||||
@@ -309,7 +309,7 @@ var ConfigBase = Class("ConfigBase", {
|
||||
version: Class.memoize(function () {
|
||||
if (this.VCSPath)
|
||||
return io.system(["hg", "-R", this.VCSPath, "log", "-r.",
|
||||
"--template=hg{rev}." + this.branch]).output;
|
||||
"--template=hg{rev}-{branch}"]).output;
|
||||
|
||||
return this.addon.version;
|
||||
}),
|
||||
@@ -504,13 +504,6 @@ var ConfigBase = Class("ConfigBase", {
|
||||
*/
|
||||
host: null,
|
||||
|
||||
/**
|
||||
* @property {[[]]} An array of application specific mode specifications.
|
||||
* The values of each mode are passed to modes.addMode during
|
||||
* dactyl startup.
|
||||
*/
|
||||
modes: [],
|
||||
|
||||
/**
|
||||
* @property {string} The name of the extension.
|
||||
* Required.
|
||||
|
||||
@@ -44,7 +44,7 @@ var Prefs = Module("prefs", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference])
|
||||
|
||||
cleanup: function cleanup(reason) {
|
||||
if (this.defaults != this)
|
||||
this.defaults.cleanup();
|
||||
this.defaults.cleanup(reason);
|
||||
|
||||
this._observers = {};
|
||||
if (this.observe) {
|
||||
@@ -62,7 +62,7 @@ var Prefs = Module("prefs", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference])
|
||||
this.branches.saved.resetBranch();
|
||||
}
|
||||
|
||||
if (reason == "uninstall" && this == prefs)
|
||||
if (reason == "uninstall")
|
||||
localPrefs.resetBranch();
|
||||
}
|
||||
},
|
||||
|
||||
@@ -12,12 +12,10 @@ defineModule("protocol", {
|
||||
|
||||
var systemPrincipal = Cc["@mozilla.org/systemprincipal;1"].getService(Ci.nsIPrincipal);
|
||||
|
||||
var DNE = "resource://gre/does/not/exist";
|
||||
|
||||
function Channel(url, orig, noFake) {
|
||||
function Channel(url, orig, noErrorChannel) {
|
||||
try {
|
||||
if (url == null)
|
||||
return noFake ? null : FakeChannel(orig);
|
||||
return noErrorChannel ? null : NetError(orig);
|
||||
|
||||
if (url instanceof Ci.nsIChannel)
|
||||
return url;
|
||||
@@ -29,17 +27,28 @@ function Channel(url, orig, noFake) {
|
||||
return let ([type, data] = url) StringChannel(data, type, orig);
|
||||
|
||||
let uri = services.io.newURI(url, null, null);
|
||||
return (new XMLChannel(uri, null, noFake)).channel;
|
||||
return (new XMLChannel(uri, null, noErrorChannel)).channel;
|
||||
}
|
||||
catch (e) {
|
||||
util.reportError(e);
|
||||
util.dump(url);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
function FakeChannel(orig) {
|
||||
let channel = services.io.newChannel(DNE, null, null);
|
||||
channel.originalURI = orig;
|
||||
return channel;
|
||||
function NetError(orig, error) {
|
||||
return services.InterfacePointer({
|
||||
QueryInterface: XPCOMUtils.generateQI([Ci.nsIChannel]),
|
||||
|
||||
name: orig.spec,
|
||||
|
||||
URI: orig,
|
||||
|
||||
originalURI: orig,
|
||||
|
||||
asyncOpen: function () { throw error || Cr.NS_ERROR_FILE_NOT_FOUND },
|
||||
|
||||
open: function () { throw error || Cr.NS_ERROR_FILE_NOT_FOUND }
|
||||
}).data.QueryInterface(Ci.nsIChannel);
|
||||
}
|
||||
function RedirectChannel(to, orig, time) {
|
||||
let html = <html><head><meta http-equiv="Refresh" content={(time || 0) + ";" + to}/></head></html>.toXMLString();
|
||||
@@ -68,7 +77,19 @@ function ProtocolBase() {
|
||||
this.wrappedJSObject = this;
|
||||
|
||||
this.pages = {};
|
||||
this.providers = {};
|
||||
this.providers = {
|
||||
"content": function (uri, path) this.pages[path] || this.contentBase + path,
|
||||
|
||||
"data": function (uri) {
|
||||
var channel = services.io.newChannel(uri.path.replace(/^\/(.*)(?:#.*)?/, "data:$1"),
|
||||
null, null);
|
||||
|
||||
channel.contentCharset = "UTF-8";
|
||||
channel.owner = systemPrincipal;
|
||||
channel.originalURI = uri;
|
||||
return channel;
|
||||
}
|
||||
};
|
||||
}
|
||||
ProtocolBase.prototype = {
|
||||
get contractID() "@mozilla.org/network/protocol;1?name=" + this.scheme,
|
||||
@@ -92,34 +113,17 @@ ProtocolBase.prototype = {
|
||||
try {
|
||||
uri.QueryInterface(Ci.nsIURL);
|
||||
|
||||
let path = decodeURIComponent(uri.filePath.substr(1));
|
||||
if (uri.host in this.providers)
|
||||
return Channel(this.providers[uri.host](uri, uri.filePath.substr(1)), uri);
|
||||
return Channel(this.providers[uri.host].call(this, uri, path),
|
||||
uri);
|
||||
|
||||
let path = decodeURIComponent(uri.path.replace(/^\/|#.*/g, ""));
|
||||
switch(uri.host) {
|
||||
case "content":
|
||||
return Channel(this.pages[path] || this.contentBase + path, uri);
|
||||
case "data":
|
||||
try {
|
||||
var channel = services.io.newChannel(uri.path.replace(/^\/(.*)(?:#.*)?/, "data:$1"),
|
||||
null, null);
|
||||
}
|
||||
catch (e) {
|
||||
var error = e;
|
||||
break;
|
||||
}
|
||||
channel.contentCharset = "UTF-8";
|
||||
channel.owner = systemPrincipal;
|
||||
channel.originalURI = uri;
|
||||
return channel;
|
||||
}
|
||||
return NetError(uri);
|
||||
}
|
||||
catch (e) {
|
||||
util.reportError(e);
|
||||
throw e;
|
||||
}
|
||||
if (error)
|
||||
throw error;
|
||||
return FakeChannel(uri);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -131,7 +135,7 @@ function LocaleChannel(pkg, locale, path, orig) {
|
||||
return channel;
|
||||
}
|
||||
|
||||
return FakeChannel(orig);
|
||||
return NetError(orig);
|
||||
}
|
||||
|
||||
function StringChannel(data, contentType, uri) {
|
||||
@@ -146,13 +150,13 @@ function StringChannel(data, contentType, uri) {
|
||||
return channel;
|
||||
}
|
||||
|
||||
function XMLChannel(uri, contentType, noFake) {
|
||||
function XMLChannel(uri, contentType, noErrorChannel) {
|
||||
try {
|
||||
var channel = services.io.newChannelFromURI(uri);
|
||||
var channelStream = channel.open();
|
||||
}
|
||||
catch (e) {
|
||||
this.channel = noFake ? null : FakeChannel(uri);
|
||||
this.channel = noErrorChannel ? null : NetError(uri);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -254,12 +254,14 @@ var Styles = Module("Styles", {
|
||||
this.cleanup();
|
||||
this.allSheets = {};
|
||||
|
||||
services["dactyl:"].providers["style"] = function styleProvider(uri) {
|
||||
let id = /^\/(\d*)/.exec(uri.path)[1];
|
||||
if (Set.has(styles.allSheets, id))
|
||||
return ["text/css", styles.allSheets[id].fullCSS];
|
||||
return null;
|
||||
};
|
||||
update(services["dactyl:"].providers, {
|
||||
"style": function styleProvider(uri, path) {
|
||||
let id = parseInt(path);
|
||||
if (Set.has(styles.allSheets, id))
|
||||
return ["text/css", styles.allSheets[id].fullCSS];
|
||||
return null;
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
cleanup: function cleanup() {
|
||||
|
||||
@@ -1589,8 +1589,8 @@ var DOM = Class("DOM", {
|
||||
|
||||
attrHooks: array.toObject([
|
||||
["", {
|
||||
href: { get: function (elem) elem.href },
|
||||
src: { get: function (elem) elem.src }
|
||||
href: { get: function (elem) elem.href || elem.getAttribute("href") },
|
||||
src: { get: function (elem) elem.src || elem.getAttribute("src") }
|
||||
}]
|
||||
]),
|
||||
|
||||
@@ -1843,7 +1843,7 @@ var DOM = Class("DOM", {
|
||||
*/
|
||||
get style() {
|
||||
let node = this[0];
|
||||
while (!(node instanceof Ci.nsIDOMElement) && node.parentNode)
|
||||
while (node && !(node instanceof Ci.nsIDOMElement) && node.parentNode)
|
||||
node = node.parentNode;
|
||||
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user