1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2026-01-06 05:44:18 +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]));
const storage = modules.storage;
function Cache(name, store, serial)
function Cache(name, store)
{
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 self = this;
@@ -1052,7 +1052,7 @@ function QuickMarks() //{{{
////////////////////// PRIVATE SECTION /////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////{{{
var qmarks = storage.newMap("quickmarks", true);
var qmarks = storage.newMap("quickmarks", true, { privateData: true });
/////////////////////////////////////////////////////////////////////////////}}}
////////////////////// MAPPINGS ////////////////////////////////////////////////

View File

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

View File

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

View File

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

View File

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

View File

@@ -706,16 +706,17 @@ const util = { //{{{
/**
* Array utility methods.
*/
util.Array = function Array(ary) {
util.Array = function Array_(ary) {
var obj = {
__proto__: ary,
__iterator__: function () this.iteritems(),
__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))
return util.Array(res);
return res;
}
},
map: function() this.__noSuchMethod__("map", Array.slice(arguments)),
};
return obj;
}

View File

@@ -10,7 +10,6 @@ var EXPORTED_SYMBOLS = ["storage", "Timer"];
const Cc = Components.classes;
const Ci = Components.interfaces;
const Cr = Components.results;
const Cu = Components.utils;
// XXX: does not belong here
@@ -154,21 +153,38 @@ function loadPref(name, store, type)
function savePref(obj)
{
if (obj.privateData && storage.privateMode)
return;
if (obj.store && storage.infoPath)
writeFile(getFile(obj.name), obj.serial);
}
var prototype = {
OPTIONS: ["privateData"],
fireEvent: function (event, arg) { storage.fireEvent(this.name, event, arg) },
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.__defineGetter__("name", function () name);
this.reload = function reload()
{
object = load() || {};
this.fireEvent("change", null);
};
this.init.apply(this, arguments);
this.__defineGetter__("serial", function () json.encode(object));
this.set = function set(key, val)
@@ -201,12 +217,17 @@ function ObjectStore(name, store, data)
}
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.__defineGetter__("name", function () name);
this.reload = function reload()
{
array = load() || [];
this.fireEvent("change", null);
};
this.init.apply(this, arguments);
this.__defineGetter__("serial", function () json.encode(array));
this.__defineGetter__("length", function () array.length);
@@ -266,27 +287,28 @@ var observers = {};
var timers = {};
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 this && !reload)
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));
this.__defineGetter__(key, function () 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)
@@ -333,6 +355,8 @@ var storage = {
fireEvent: function fireEvent(key, event, arg)
{
if (!(key in this))
return;
this.removeDeadObservers();
// Safe, since we have our own Array object here.
for each (let observer in observers[key])
@@ -340,6 +364,12 @@ var storage = {
timers[key].tell();
},
load: function load(key)
{
if (this[key].store && this[key].reload)
this[key].reload();
},
save: function save(key)
{
savePref(keys[key]);
@@ -347,9 +377,19 @@ var storage = {
saveAll: function storeAll()
{
for each (obj in keys)
for each (let obj in keys)
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: