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

Don't save storage objects while in private mode, restore them on exit.

This commit is contained in:
Kris Maglione
2009-06-28 14:37:23 -04:00
parent 3f5dd13453
commit 55164325df
10 changed files with 95 additions and 38 deletions

View File

@@ -79,10 +79,10 @@ function Bookmarks() //{{{
].filter(function (item) item[1])); ].filter(function (item) item[1]));
const storage = modules.storage; const storage = modules.storage;
function Cache(name, store, serial) function Cache(name, store)
{ {
const rootFolders = [bookmarksService.toolbarFolder, bookmarksService.bookmarksMenuFolder, bookmarksService.unfiledBookmarksFolder]; const rootFolders = [bookmarksService.toolbarFolder, bookmarksService.bookmarksMenuFolder, bookmarksService.unfiledBookmarksFolder];
const sleep = liberator.sleep; const sleep = liberator.sleep; // Storage objects are global to all windows, 'liberator' isn't.
let bookmarks = []; let bookmarks = [];
let self = this; let self = this;
@@ -1052,7 +1052,7 @@ function QuickMarks() //{{{
////////////////////// PRIVATE SECTION ///////////////////////////////////////// ////////////////////// PRIVATE SECTION /////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////{{{ /////////////////////////////////////////////////////////////////////////////{{{
var qmarks = storage.newMap("quickmarks", true); var qmarks = storage.newMap("quickmarks", true, { privateData: true });
/////////////////////////////////////////////////////////////////////////////}}} /////////////////////////////////////////////////////////////////////////////}}}
////////////////////// MAPPINGS //////////////////////////////////////////////// ////////////////////// MAPPINGS ////////////////////////////////////////////////

View File

@@ -1630,8 +1630,8 @@ function Marks() //{{{
////////////////////// PRIVATE SECTION ///////////////////////////////////////// ////////////////////// PRIVATE SECTION /////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////{{{ /////////////////////////////////////////////////////////////////////////////{{{
var localMarks = storage.newMap("local-marks", true); var localMarks = storage.newMap("local-marks", true, { privateData: true });
var urlMarks = storage.newMap("url-marks", true); var urlMarks = storage.newMap("url-marks", true, { privateData: true });
var pendingJumps = []; var pendingJumps = [];
var appContent = document.getElementById("appcontent"); var appContent = document.getElementById("appcontent");

View File

@@ -345,7 +345,7 @@ function Events() //{{{
var lastFocus = null; var lastFocus = null;
var macros = storage.newMap("macros", true); var macros = storage.newMap("macros", true, { privateData: true });
var currentMacro = ""; var currentMacro = "";
var lastMacro = ""; var lastMacro = "";

View File

@@ -135,7 +135,7 @@ Highlights.prototype.CSS = <![CDATA[
* *
* @author Kris Maglione <maglione.k@gmail.com> * @author Kris Maglione <maglione.k@gmail.com>
*/ */
function Highlights(name, store, serial) function Highlights(name, store)
{ {
let self = this; let self = this;
let highlight = {}; let highlight = {};
@@ -247,7 +247,7 @@ function Highlights(name, store, serial)
* *
* @author Kris Maglione <maglione.k@gmail.com> * @author Kris Maglione <maglione.k@gmail.com>
*/ */
function Styles(name, store, serial) function Styles(name, store)
{ {
// Can't reference liberator or Components inside Styles -- // Can't reference liberator or Components inside Styles --
// they're members of the window object, which disappear // they're members of the window object, which disappear

View File

@@ -40,8 +40,8 @@ function CommandLine() //{{{
////////////////////// PRIVATE SECTION ///////////////////////////////////////// ////////////////////// PRIVATE SECTION /////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////{{{ /////////////////////////////////////////////////////////////////////////////{{{
storage.newArray("history-search", true); storage.newArray("history-search", true, { privateData: true });
storage.newArray("history-command", true); storage.newArray("history-command", true, { privateData: true });
var messageHistory = { // {{{ var messageHistory = { // {{{
_messages: [], _messages: [],

View File

@@ -706,16 +706,17 @@ const util = { //{{{
/** /**
* Array utility methods. * Array utility methods.
*/ */
util.Array = function Array(ary) { util.Array = function Array_(ary) {
var obj = { var obj = {
__proto__: ary, __proto__: ary,
__iterator__: function () this.iteritems(), __iterator__: function () this.iteritems(),
__noSuchMethod__: function (meth, args) { __noSuchMethod__: function (meth, args) {
let res = util.Array[meth].apply(null, [this.__proto__].concat(args)); let res = (util.Array[meth] || Array[meth]).apply(null, [this.__proto__].concat(args));
if (util.Array.isinstance(res)) if (util.Array.isinstance(res))
return util.Array(res); return util.Array(res);
return res; return res;
} },
map: function() this.__noSuchMethod__("map", Array.slice(arguments)),
}; };
return obj; return obj;
} }

View File

@@ -10,7 +10,6 @@ var EXPORTED_SYMBOLS = ["storage", "Timer"];
const Cc = Components.classes; const Cc = Components.classes;
const Ci = Components.interfaces; const Ci = Components.interfaces;
const Cr = Components.results;
const Cu = Components.utils; const Cu = Components.utils;
// XXX: does not belong here // XXX: does not belong here
@@ -154,21 +153,38 @@ function loadPref(name, store, type)
function savePref(obj) function savePref(obj)
{ {
if (obj.privateData && storage.privateMode)
return;
if (obj.store && storage.infoPath) if (obj.store && storage.infoPath)
writeFile(getFile(obj.name), obj.serial); writeFile(getFile(obj.name), obj.serial);
} }
var prototype = { var prototype = {
OPTIONS: ["privateData"],
fireEvent: function (event, arg) { storage.fireEvent(this.name, event, arg) }, fireEvent: function (event, arg) { storage.fireEvent(this.name, event, arg) },
save: function () { savePref(this) }, save: function () { savePref(this) },
init: function (name, store, data, options)
{
this.__defineGetter__("store", function () store);
this.__defineGetter__("name", function () name);
for (let [k, v] in Iterator(options))
if (this.OPTIONS.indexOf(k) >= 0)
this[k] = v;
this.reload();
}
}; };
function ObjectStore(name, store, data) function ObjectStore(name, store, load, options)
{ {
var object = data || {}; var object = {};
this.__defineGetter__("store", function () store); this.reload = function reload()
this.__defineGetter__("name", function () name); {
object = load() || {};
this.fireEvent("change", null);
};
this.init.apply(this, arguments);
this.__defineGetter__("serial", function () json.encode(object)); this.__defineGetter__("serial", function () json.encode(object));
this.set = function set(key, val) this.set = function set(key, val)
@@ -201,12 +217,17 @@ function ObjectStore(name, store, data)
} }
ObjectStore.prototype = prototype; ObjectStore.prototype = prototype;
function ArrayStore(name, store, data) function ArrayStore(name, store, load, options)
{ {
var array = data || []; var array = [];
this.__defineGetter__("store", function () store); this.reload = function reload()
this.__defineGetter__("name", function () name); {
array = load() || [];
this.fireEvent("change", null);
};
this.init.apply(this, arguments);
this.__defineGetter__("serial", function () json.encode(array)); this.__defineGetter__("serial", function () json.encode(array));
this.__defineGetter__("length", function () array.length); this.__defineGetter__("length", function () array.length);
@@ -266,27 +287,28 @@ var observers = {};
var timers = {}; var timers = {};
var storage = { var storage = {
newObject: function newObject(key, constructor, store, type, reload) newObject: function newObject(key, constructor, store, type, options, reload)
{ {
if (!(key in keys) || reload) if (!(key in keys) || reload)
{ {
if (key in this && !reload) if (key in this && !reload)
throw Error; throw Error;
keys[key] = new constructor(key, store, loadPref(key, store, type || Object)); let load = function() loadPref(key, store, type || Object);
keys[key] = new constructor(key, store, load, options || {});
timers[key] = new Timer(1000, 10000, function () storage.save(key)); timers[key] = new Timer(1000, 10000, function () storage.save(key));
this.__defineGetter__(key, function () keys[key]); this.__defineGetter__(key, function () keys[key]);
} }
return keys[key]; return keys[key];
}, },
newMap: function newMap(key, store) newMap: function newMap(key, store, options)
{ {
return this.newObject(key, ObjectStore, store); return this.newObject(key, ObjectStore, store, null, options);
}, },
newArray: function newArray(key, store) newArray: function newArray(key, store, options)
{ {
return this.newObject(key, ArrayStore, store, Array); return this.newObject(key, ArrayStore, store, Array, options);
}, },
addObserver: function addObserver(key, callback, ref) addObserver: function addObserver(key, callback, ref)
@@ -333,6 +355,8 @@ var storage = {
fireEvent: function fireEvent(key, event, arg) fireEvent: function fireEvent(key, event, arg)
{ {
if (!(key in this))
return;
this.removeDeadObservers(); this.removeDeadObservers();
// Safe, since we have our own Array object here. // Safe, since we have our own Array object here.
for each (let observer in observers[key]) for each (let observer in observers[key])
@@ -340,6 +364,12 @@ var storage = {
timers[key].tell(); timers[key].tell();
}, },
load: function load(key)
{
if (this[key].store && this[key].reload)
this[key].reload();
},
save: function save(key) save: function save(key)
{ {
savePref(keys[key]); savePref(keys[key]);
@@ -347,9 +377,19 @@ var storage = {
saveAll: function storeAll() saveAll: function storeAll()
{ {
for each (obj in keys) for each (let obj in keys)
savePref(obj); savePref(obj);
}, },
_privateMode: false,
get privateMode() this._privateMode,
set privateMode(val)
{
if (!val && this._privateMode)
for (let key in keys)
this.load(key);
return this._privateMode = Boolean(val);
},
}; };
// vim: set fdm=marker sw=4 sts=4 et ft=javascript: // vim: set fdm=marker sw=4 sts=4 et ft=javascript:

View File

@@ -13,9 +13,7 @@
{ arg: true, count: true, motion: true, route: true }); { arg: true, count: true, motion: true, route: true });
* IMPORTANT: shifted key notation now matches Vim's behaviour. E.g. <C-a> * IMPORTANT: shifted key notation now matches Vim's behaviour. E.g. <C-a>
and <C-A> are equivalent, to map the uppercase character use <C-S-A>. - Is this still true, or going to be true? --djk and <C-A> are equivalent, to map the uppercase character use <C-S-A>. - Is this still true, or going to be true? --djk
* add 'private' - enter private browsing mode IMPORTANT: this doesn't * add 'private' - enter private browsing mode
currently cause Vimperator-specific data like command-line history to be
purged.
* add -description option to :command * add -description option to :command
* command-line options are now supported via the host application's * command-line options are now supported via the host application's
-liberator option -liberator option

View File

@@ -478,9 +478,9 @@ const config = { //{{{
}); });
// only available in FF 3.5 // only available in FF 3.5
if (Ci.nsIPrivateBrowsingService) services.add("privateBrowsing", "@mozilla.org/privatebrowsing;1", Ci.nsIPrivateBrowsingService);
if (services.get("privateBrowsing"))
{ {
services.add("privateBrowsing", "@mozilla.org/privatebrowsing;1", Ci.nsIPrivateBrowsingService);
options.add(["private", "pornmode"], options.add(["private", "pornmode"],
"Set the 'private browsing' option", "Set the 'private browsing' option",
"boolean", false, "boolean", false,
@@ -494,6 +494,27 @@ const config = { //{{{
return services.get("privateBrowsing").privateBrowsingEnabled; return services.get("privateBrowsing").privateBrowsingEnabled;
} }
}); });
let services = modules.services; // Storage objects are global to all windows, 'modules' isn't.
storage.newObject("private-mode-observer", function () {
({
init: function () {
services.get("observer").addObserver(this, "private-browsing", false);
services.get("observer").addObserver(this, "quit-application", false);
this.private = services.get("privateBrowsing").privateBrowsingEnabled;
},
observe: function (subject, topic, data) {
if (topic == "private-browsing") {
if (data == "enter")
storage.privateMode = true;
else if (data == "exit")
storage.privateMode = false;
} else if (topic == "quit-application") {
services.get("observer").removeObserver(this, "quit-application");
services.get("observer").removeObserver(this, "private-browsing");
}
},
}).init();
}, false);
} }
// TODO: merge with Vimperator version and add Muttator version // TODO: merge with Vimperator version and add Muttator version
@@ -508,7 +529,7 @@ const config = { //{{{
elem.setAttribute("titlemodifier", value); elem.setAttribute("titlemodifier", value);
// TODO: remove this FF3.5 test when we no longer support 3.0 // TODO: remove this FF3.5 test when we no longer support 3.0
if (Ci.nsIPrivateBrowsingService) if (services.get("privateBrowsing"))
{ {
elem.setAttribute("titlemodifier_privatebrowsing", value); elem.setAttribute("titlemodifier_privatebrowsing", value);
elem.setAttribute("titlemodifier_normal", value); elem.setAttribute("titlemodifier_normal", value);

View File

@@ -453,9 +453,6 @@ files, cookies, form data, passwords, and download list entries are available
only for the duration of the private browsing session and deleted when only for the duration of the private browsing session and deleted when
returning to normal browsing mode. returning to normal browsing mode.
Warning: Vimperator specific data like command-line history is not yet purged
when exiting private browsing mode.
Note: this is only available in FF 3.5. Note: this is only available in FF 3.5.
____ ____