diff options
author | Kris Maglione <maglione.k@gmail.com> | 2010-10-14 03:29:56 -0400 |
---|---|---|
committer | Kris Maglione <maglione.k@gmail.com> | 2010-10-14 03:29:56 -0400 |
commit | a703d0a3bf1d31e39444d643dfe993e630235e7c (patch) | |
tree | 2b0d0a33ab43a04244203aa0fc9a60b7d723db6b /common/modules/storage.jsm | |
parent | 9e42f55fa19936a18eb846d4801f9a880da3e152 (diff) | |
download | pentadactyl-a703d0a3bf1d31e39444d643dfe993e630235e7c.tar.gz |
Integrate sanitizer with host UI, sanitize at shutdown support, and control which items are sanitized when more thoroughly. Closes issue #70.
Diffstat (limited to 'common/modules/storage.jsm')
-rw-r--r-- | common/modules/storage.jsm | 39 |
1 files changed, 9 insertions, 30 deletions
diff --git a/common/modules/storage.jsm b/common/modules/storage.jsm index 74b78c46..0cd800e6 100644 --- a/common/modules/storage.jsm +++ b/common/modules/storage.jsm @@ -11,8 +11,6 @@ defineModule("storage", { require: ["services", "util"] }); -var prefService = services.get("pref").getBranch("extensions.dactyl.datastore."); - const win32 = /^win(32|nt)$/i.test(services.get("runtime").OS); function getFile(name) { @@ -21,38 +19,19 @@ function getFile(name) { return File(file); } -function getCharPref(name) { +function loadData(name, store, type) { try { - return prefService.getComplexValue(name, Ci.nsISupportsString).data; - } - catch (e) {} -} - -function setCharPref(name, value) { - var str = Cc['@mozilla.org/supports-string;1'].createInstance(Ci.nsISupportsString); - str.data = value; - return prefService.setComplexValue(name, Ci.nsISupportsString, str); -} - -function loadPref(name, store, type) { - try { - if (store) - var pref = getCharPref(name); - if (!pref && storage.infoPath) + if (storage.infoPath) var file = getFile(name).read(); - if (pref || file) - var result = services.get("json").decode(pref || file); - if (pref) { - prefService.clearUserPref(name); - savePref({ name: name, store: true, serial: pref }); - } + if (file) + var result = services.get("json").decode(file); if (result instanceof type) return result; } catch (e) {} } -function savePref(obj) { +function saveData(obj) { if (obj.privateData && storage.privateMode) return; if (obj.store && storage.infoPath) @@ -78,7 +57,7 @@ const StoreBase = Class("StoreBase", { this._object = this._load() || this._constructor(); this.fireEvent("change", null); }, - save: function () { savePref(this); }, + save: function () { saveData(this); }, }); const ArrayStore = Class("ArrayStore", StoreBase, { @@ -175,7 +154,7 @@ const Storage = Module("Storage", { if (!(key in keys) || params.reload || this.alwaysReload[key]) { if (key in this && !(params.reload || this.alwaysReload[key])) throw Error(); - let load = function () loadPref(key, params.store, params.type || myObject); + let load = function () loadData(key, params.store, params.type || myObject); keys[key] = new constructor(key, params.store, load, params); keys[key].timer = new Timer(1000, 10000, function () storage.save(key)); this.__defineGetter__(key, function () keys[key]); @@ -243,12 +222,12 @@ const Storage = Module("Storage", { }, save: function save(key) { - savePref(keys[key]); + saveData(keys[key]); }, saveAll: function storeAll() { for each (let obj in keys) - savePref(obj); + saveData(obj); }, _privateMode: false, |