X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=common%2Fmodules%2Fsanitizer.jsm;h=01b0ecad1b750f0ee7238f0b9da099182bdf589d;hb=3d837eb266a3a01d424192aa4ec1a167366178c5;hp=bbe36e2e244f9c7e6d9eb964e7f9c7a85a6f9317;hpb=5ebd29f56d17f62011cdd596b1d351947ee534ff;p=dactyl.git diff --git a/common/modules/sanitizer.jsm b/common/modules/sanitizer.jsm index bbe36e2..01b0eca 100644 --- a/common/modules/sanitizer.jsm +++ b/common/modules/sanitizer.jsm @@ -1,9 +1,9 @@ // Copyright (c) 2009 by Doug Kearns -// Copyright (c) 2009-2011 by Kris Maglione +// Copyright (c) 2009-2012 Kris Maglione // // This work is licensed for reuse under an MIT license. Details are // given in the LICENSE.txt file included with this file. -/* use strict */ +"use strict"; // TODO: // - fix Sanitize autocommand @@ -12,16 +12,15 @@ // FIXME: // - finish 1.9.0 support if we're going to support sanitizing in Melodactyl -Components.utils.import("resource://dactyl/bootstrap.jsm"); defineModule("sanitizer", { exports: ["Range", "Sanitizer", "sanitizer"], require: ["config", "prefs", "services", "util"] -}, this); +}); -this.lazyRequire("messages", ["_"]); -this.lazyRequire("overlay", ["overlay"]); -this.lazyRequire("storage", ["storage"]); -this.lazyRequire("template", ["teplate"]); +lazyRequire("messages", ["_"]); +lazyRequire("overlay", ["overlay"]); +lazyRequire("storage", ["storage"]); +lazyRequire("template", ["template"]); let tmp = Object.create(this); JSMLoader.loadSubScript("chrome://browser/content/sanitize.js", tmp); @@ -71,7 +70,6 @@ var Sanitizer = Module("sanitizer", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakRef util.addObserver(this); - services.add("contentPrefs", "@mozilla.org/content-pref/service;1", Ci.nsIContentPrefService); services.add("cookies", "@mozilla.org/cookiemanager;1", [Ci.nsICookieManager, Ci.nsICookieManager2, Ci.nsICookieService]); services.add("loginManager", "@mozilla.org/login-manager;1", Ci.nsILoginManager); @@ -122,12 +120,16 @@ var Sanitizer = Module("sanitizer", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakRef }, override: true }); - if (services.has("privateBrowsing")) + try { + var { ForgetAboutSite } = Cu.import("resource://gre/modules/ForgetAboutSite.jsm", {}); + } + catch (e) {} + if (ForgetAboutSite) this.addItem("host", { description: "All data from the given host", action: function (range, host) { if (host) - services.privateBrowsing.removeDataFromDomain(host); + ForgetAboutSite.removeDataFromDomain(host); } }); this.addItem("sitesettings", { @@ -166,13 +168,12 @@ var Sanitizer = Module("sanitizer", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakRef ]; function prefOverlay(branch, persistent, local) update(Object.create(local), { - before: array.toObject([ - [branch.substr(Item.PREFIX.length) + "history", - { - template.map(ourItems(persistent), function (item) - ) - }.*::*] - ]), + before: [ + ["preferences", { id: branch.substr(Item.PREFIX.length) + "history", + xmlns: "xul" }, + template.map(ourItems(persistent), function (item) + ["preference", { type: "bool", id: branch + item.name, name: branch + item.name }])] + ], init: function init(win) { let pane = win.document.getElementById("SanitizeDialogPane"); for (let [, pref] in iter(pane.preferences)) @@ -188,20 +189,18 @@ var Sanitizer = Module("sanitizer", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakRef function (win) prefOverlay(branch, true, { append: { SanitizeDialogPane: - - - - - { + ["groupbox", { orient: "horizontal", xmlns: "xul" }, + ["caption", { label: config.appName + /*L*/" (see :help privacy)" }], + ["grid", { flex: "1" }, + ["columns", {}, + ["column", { flex: "1" }], + ["column", { flex: "1" }]], + ["rows", {}, let (items = ourItems(true)) template.map(util.range(0, Math.ceil(items.length / 2)), function (i) - { - template.map(items.slice(i * 2, i * 2 + 2), function (item) - ) - }) - } - - + ["row", {}, + template.map(items.slice(i * 2, i * 2 + 2), function (item) + ["checkbox", { xmlns: XUL, label: item.description, preference: branch + item.name }])])]]] } })); } @@ -209,16 +208,14 @@ var Sanitizer = Module("sanitizer", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakRef overlay.overlayWindow("chrome://browser/content/sanitize.xul", function (win) prefOverlay(branch, false, { append: { - itemList: <> - - { - template.map(ourItems(), function ([item, desc]) - ) - } - + itemList: [ + ["listitem", { xmlns: "xul", label: /*L*/"See :help privacy for the following:", + disabled: "true", style: "font-style: italic; font-weight: bold;" }], + template.map(ourItems(), function ([item, desc]) + ["listitem", { xmlns: "xul", preference: branch + item, + type: "checkbox", label: config.appName + ", " + desc, + onsyncfrompreference: "return gSanitizePromptDialog.onReadGeneric();" }]) + ] }, ready: function ready(win) { let elem = win.document.getElementById("itemList"); @@ -296,12 +293,32 @@ var Sanitizer = Module("sanitizer", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakRef } }, + /** + * Returns a load context for the given thing, to be used with + * interfaces needing one for per-window private browsing support. + * + * @param {Window|Document|Node} thing The thing for which to return + * a load context. + */ + getContext: function getContext(thing) { + if (!Ci.nsILoadContext) + return null; + + if (thing instanceof Ci.nsIDOMNode && thing.ownerDocument) + thing = thing.ownerDocument; + if (thing instanceof Ci.nsIDOMDocument) + thing = thing.defaultView; + if (thing instanceof Ci.nsIInterfaceRequestor) + thing = thing.getInterface(Ci.nsIWebNavigation); + return thing.QueryInterface(Ci.nsILoadContext); + }, + get ranAtShutdown() config.prefs.get("didSanitizeOnShutdown"), set ranAtShutdown(val) config.prefs.set("didSanitizeOnShutdown", Boolean(val)), get runAtShutdown() prefs.get("privacy.sanitize.sanitizeOnShutdown"), set runAtShutdown(val) prefs.set("privacy.sanitize.sanitizeOnShutdown", Boolean(val)), - sanitize: function (items, range) + sanitize: function sanitize(items, range) this.withSavedValues(["sanitizing"], function () { this.sanitizing = true; let errors = this.sanitizeItems(items, range, null); @@ -325,7 +342,7 @@ var Sanitizer = Module("sanitizer", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakRef return errors; }), - sanitizeItems: function (items, range, host, key) + sanitizeItems: function sanitizeItems(items, range, host, key) this.withSavedValues(["sanitizing"], function () { this.sanitizing = true; if (items == null) @@ -387,12 +404,12 @@ var Sanitizer = Module("sanitizer", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakRef yield p; } }, { - load: function (dactyl, modules, window) { + load: function initLoad(dactyl, modules, window) { if (!sanitizer.firstRun++ && sanitizer.runAtShutdown && !sanitizer.ranAtShutdown) sanitizer.sanitizeItems(null, Range(), null, "shutdown"); sanitizer.ranAtShutdown = false; }, - autocommands: function (dactyl, modules, window) { + autocommands: function initAutocommands(dactyl, modules, window) { const { autocommands } = modules; storage.addObserver("private-mode", @@ -407,7 +424,7 @@ var Sanitizer = Module("sanitizer", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakRef autocommands.trigger("Sanitize", { name: event.substr("clear-".length), domain: value[1] }); }, window); }, - commands: function (dactyl, modules, window) { + commands: function initCommands(dactyl, modules, window) { const { commands } = modules; commands.add(["sa[nitize]"], "Clear private data", @@ -490,7 +507,7 @@ var Sanitizer = Module("sanitizer", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakRef description: "Timespan for which to sanitize items", completer: function (context) modules.options.get("sanitizetimespan").completer(context), type: modules.CommandOption.STRING, - validator: function (arg) modules.options.get("sanitizetimespan").validator(arg), + validator: function (arg) modules.options.get("sanitizetimespan").validator(arg) } ], privateData: true @@ -504,7 +521,7 @@ var Sanitizer = Module("sanitizer", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakRef } function setPerms(host, perm) { let uri = util.createURI(host); - services.permissions.remove(uri, "cookie"); + services.permissions.remove(uri.host, "cookie"); services.permissions.add(uri, "cookie", Sanitizer.PERMS[perm]); } commands.add(["cookies", "ck"], @@ -534,7 +551,7 @@ var Sanitizer = Module("sanitizer", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakRef ["Host", "Expiry (UTC)", "Path", "Name", "Value"], ["padding-right: 1em", "padding-right: 1em", "padding-right: 1em", "max-width: 12em; overflow: hidden;", "padding-left: 1ex;"], ([c.host, - c.isSession ? session + c.isSession ? ["span", { highlight: "Enabled" }, "session"] : (new Date(c.expiry * 1000).toJSON() || "Never").replace(/:\d\d\.000Z/, "").replace("T", " ").replace(/-/g, "/"), c.path, c.name, @@ -556,7 +573,7 @@ var Sanitizer = Module("sanitizer", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakRef let count = [0, 0]; for (let c in Sanitizer.iterCookies(host)) count[c.isSession + 0]++; - return <>{Sanitizer.COMMANDS[getPerms(host)]} (session: {count[1]} persistent: {count[0]}); + return [Sanitizer.COMMANDS[getPerms(host)], " (session: ", count[1], " persistent: ", count[0], ")"].join(""); }; break; case 1: @@ -566,7 +583,7 @@ var Sanitizer = Module("sanitizer", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakRef }, }); }, - completion: function (dactyl, modules, window) { + completion: function initCompletion(dactyl, modules, window) { modules.completion.visibleHosts = function completeHosts(context) { let res = util.visibleHosts(window.content); if (context.filter && !res.some(function (host) host.indexOf(context.filter) >= 0)) @@ -579,21 +596,8 @@ var Sanitizer = Module("sanitizer", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakRef context.completions = res; }; }, - options: function (dactyl, modules) { + options: function initOptions(dactyl, modules) { const options = modules.options; - if (services.has("privateBrowsing")) - options.add(["private", "pornmode"], - "Set the 'private browsing' option", - "boolean", false, - { - initialValue: true, - getter: function () services.privateBrowsing.privateBrowsingEnabled, - setter: function (value) { - if (services.privateBrowsing.privateBrowsingEnabled != value) - services.privateBrowsing.privateBrowsingEnabled = value; - }, - persist: false - }); options.add(["sanitizeitems", "si"], "The default list of private items to sanitize", @@ -713,4 +717,4 @@ endModule(); // catch(e){dump(e.fileName+":"+e.lineNumber+": "+e+"\n" + e.stack);} -// vim: set fdm=marker sw=4 ts=4 et ft=javascript: +// vim: set fdm=marker sw=4 sts=4 ts=8 et ft=javascript: