diff --git a/common/bootstrap.js b/common/bootstrap.js index a09e50ec..cc27630c 100755 --- a/common/bootstrap.js +++ b/common/bootstrap.js @@ -61,6 +61,10 @@ function startup(data, reason) { addon = data; AddonManager.getAddonByID(addon.id, function (a) { addon = a; }); + // Temporary hack. + if (basePath.isDirectory() && JSMLoader.bump == null) + JSMLoader.bump = 1; + if (basePath.isDirectory()) getURI = function getURI(path) { let file = basePath.clone().QueryInterface(Ci.nsILocalFile); diff --git a/common/content/dactyl.js b/common/content/dactyl.js index 94045c14..870d07b7 100644 --- a/common/content/dactyl.js +++ b/common/content/dactyl.js @@ -934,7 +934,7 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), { * @param {number} level The logging level 0 - 15. */ log: function (msg, level) { - let verbose = prefs.get("extensions.dactyl.loglevel", 0); + let verbose = localPrefs.get("loglevel", 0); if (!level || level <= verbose) { if (isObject(msg)) diff --git a/common/modules/base.jsm b/common/modules/base.jsm index e4439df7..39e8b126 100644 --- a/common/modules/base.jsm +++ b/common/modules/base.jsm @@ -334,9 +334,10 @@ function deprecated(reason, fn) { function deprecatedMethod() { let frame = Components.stack.caller; let obj = this.className || this.constructor.className; - if (!set.add(deprecatedMethod.seen, frame.filename)) + let filename = frame.filename.replace(/.* -> /, ""); + if (!set.add(deprecatedMethod.seen, filename)) util.dactyl(fn).echoerr( - util.urlPath(frame.filename || "unknown") + ":" + frame.lineNumber + ": " + + util.urlPath(filename || "unknown") + ":" + frame.lineNumber + ": " + (obj ? obj + "." : "") + (fn.name || name) + " is deprecated: " + reason); return func.apply(this, arguments); } diff --git a/common/modules/prefs.jsm b/common/modules/prefs.jsm index b4b9e0a9..4ade793c 100644 --- a/common/modules/prefs.jsm +++ b/common/modules/prefs.jsm @@ -8,7 +8,7 @@ Components.utils.import("resource://dactyl/base.jsm"); defineModule("prefs", { - exports: ["Prefs", "prefs"], + exports: ["Prefs", "localPrefs", "prefs"], require: ["services", "util"], use: ["config", "template"] }); @@ -16,20 +16,21 @@ defineModule("prefs", { var Prefs = Module("prefs", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]), { SAVED: "extensions.dactyl.saved.", RESTORE: "extensions.dactyl.restore.", + INIT: {}, - init: function () { + init: function (branch) { this._prefContexts = []; util.addObserver(this); - this._branch = services.pref.getBranch("").QueryInterface(Ci.nsIPrefBranch2); - this._branch.addObserver("", this, false); + this.branch = services.pref.getBranch(branch || "").QueryInterface(Ci.nsIPrefBranch2); + this.branch.addObserver("", this, false); this._observers = {}; this.restore(); }, cleanup: function cleanup() { - this._branch.removeObserver("", this); + this.branch.removeObserver("", this); }, observe: { @@ -123,7 +124,7 @@ var Prefs = Module("prefs", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]) * @param {string} branch The branch in which to search preferences. * @default "" */ - getNames: function (branch) services.pref.getChildList(branch || "", { value: 0 }), + getNames: function (branch) this.branch.getChildList(branch || "", { value: 0 }), _checkSafe: function (name, message, value) { let curval = this._load(name, null, false); @@ -208,7 +209,7 @@ var Prefs = Module("prefs", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]) */ reset: function (name) { try { - services.pref.clearUserPref(name); + this.branch.clearUserPref(name); } catch (e) {} // ignore - thrown if not a user set value }, @@ -219,7 +220,7 @@ var Prefs = Module("prefs", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]) * @param {string} name The preference name. */ toggle: function (name) { - util.assert(services.pref.getPrefType(name) === Ci.nsIPrefBranch.PREF_BOOL, + util.assert(this.branch.getPrefType(name) === Ci.nsIPrefBranch.PREF_BOOL, "E488: Trailing characters: " + name + "!"); this.set(name, !this.get(name)); }, @@ -276,24 +277,24 @@ var Prefs = Module("prefs", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]) ? "E521: Number required after =: " + name + "=" + value : "E474: Invalid argument: " + name + "=" + value); - let type = services.pref.getPrefType(name); + let type = this.branch.getPrefType(name); switch (typeof value) { case "string": assertType(Ci.nsIPrefBranch.PREF_STRING); let supportString = Cc["@mozilla.org/supports-string;1"].createInstance(Ci.nsISupportsString); supportString.data = value; - services.pref.setComplexValue(name, Ci.nsISupportsString, supportString); + this.branch.setComplexValue(name, Ci.nsISupportsString, supportString); break; case "number": assertType(Ci.nsIPrefBranch.PREF_INT); - services.pref.setIntPref(name, value); + this.branch.setIntPref(name, value); break; case "boolean": assertType(Ci.nsIPrefBranch.PREF_BOOL); - services.pref.setBoolPref(name, value); + this.branch.setBoolPref(name, value); break; default: throw FailedAssertion("Unknown preference type: " + typeof value + " (" + name + "=" + value + ")"); @@ -304,14 +305,14 @@ var Prefs = Module("prefs", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]) if (defaultValue == null) defaultValue = null; - let branch = defaultBranch ? services.pref.getDefaultBranch("") : services.pref; - let type = services.pref.getPrefType(name); + let branch = defaultBranch ? services.pref.getDefaultBranch(this.branch.root) : this.branch; + let type = this.branch.getPrefType(name); try { switch (type) { case Ci.nsIPrefBranch.PREF_STRING: let value = branch.getComplexValue(name, Ci.nsISupportsString).data; // try in case it's a localized string (will throw an exception if not) - if (!services.pref.prefIsLocked(name) && !services.pref.prefHasUserValue(name) && + if (!this.branch.prefIsLocked(name) && !this.branch.prefHasUserValue(name) && RegExp("chrome://.+/locale/.+\\.properties").test(value)) value = branch.getComplexValue(name, Ci.nsIPrefLocalizedString).data; return value; @@ -339,10 +340,13 @@ var Prefs = Module("prefs", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]) }, javascript: function (dactyl, modules) { modules.JavaScript.setCompleter([this.get, this.safeSet, this.set, this.reset, this.toggle], - [function (context) (context.anchored=false, prefs.getNames().map(function (pref) [pref, ""]))]); + [function (context) (context.anchored=false, this.getNames().map(function (pref) [pref, ""]))]); } }); +var localPrefs = Prefs("extensions.dactyl."); +defineModule.modules.push(localPrefs); + endModule(); // catch(e){dump(e.fileName+":"+e.lineNumber+": "+e+"\n" + e.stack);} diff --git a/common/modules/sanitizer.jsm b/common/modules/sanitizer.jsm index 6cc7ffe8..08d5fa27 100644 --- a/common/modules/sanitizer.jsm +++ b/common/modules/sanitizer.jsm @@ -52,7 +52,7 @@ var Item = Class("Item", { shouldSanitize: function (shutdown) (!shutdown || this.builtin || this.persistent) && prefs.get(shutdown ? this.shutdownPref : this.pref) }, { - PREFIX: "extensions.dactyl.", + PREFIX: localPrefs.branch.root, BRANCH: "privacy.cpd.", SHUTDOWN_BRANCH: "privacy.clearOnShutdown." }); @@ -261,8 +261,8 @@ var Sanitizer = Module("sanitizer", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakRef } }, - get ranAtShutdown() prefs.get(Item.PREFIX + "didSanitizeOnShutdown"), - set ranAtShutdown(val) prefs.set(Item.PREFIX + "didSanitizeOnShutdown", Boolean(val)), + get ranAtShutdown() localPrefs.get("didSanitizeOnShutdown"), + set ranAtShutdown(val) localPrefs.set("didSanitizeOnShutdown", Boolean(val)), get runAtShutdown() prefs.get("privacy.sanitize.sanitizeOnShutdown"), set runAtShutdown(val) prefs.set("privacy.sanitize.sanitizeOnShutdown", Boolean(val)),