From 2317ed132b4db57973650569c23c3a31f1ead737 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Fri, 25 Jan 2013 15:46:39 -0500 Subject: [PATCH] XUL localStorage interface localStorage is so much better than cookies. To use it inside of XUL-embedded web pages, we have to use the XUL localStorage interface, since window.localStorage is not available within the oils:// protocol. Signed-off-by: Bill Erickson Signed-off-by: Ben Shum --- Open-ILS/web/js/dojo/openils/XUL.js | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/Open-ILS/web/js/dojo/openils/XUL.js b/Open-ILS/web/js/dojo/openils/XUL.js index d5f7cc1808..656c055a7e 100644 --- a/Open-ILS/web/js/dojo/openils/XUL.js +++ b/Open-ILS/web/js/dojo/openils/XUL.js @@ -1,7 +1,6 @@ if(!dojo._hasResource["openils.XUL"]) { dojo.provide("openils.XUL"); - dojo.require('dojo.cookie'); dojo.declare('openils.XUL', null, {}); openils.XUL.isXUL = function() { @@ -175,5 +174,27 @@ if(!dojo._hasResource["openils.XUL"]) { return 0; } }; + + // returns a ref to a XUL localStorage interface + // localStorage is not directly accessible within oils:// + // http://fartersoft.com/blog/2011/03/07/using-localstorage-in-firefox-extensions-for-persistent-data-storage/ + openils.XUL.localStorage = function() { + + // in browser mode, use the standard localStorage interface + if (!openils.XUL.isXUL()) + return window.localStorage; + + var url = location.protocol + '//' + location.hostname; + var ios = Components.classes["@mozilla.org/network/io-service;1"] + .getService(Components.interfaces.nsIIOService); + var ssm = Components.classes["@mozilla.org/scriptsecuritymanager;1"] + .getService(Components.interfaces.nsIScriptSecurityManager); + var dsm = Components.classes["@mozilla.org/dom/storagemanager;1"] + .getService(Components.interfaces.nsIDOMStorageManager); + var uri = ios.newURI(url, "", null); + var principal = ssm.getCodebasePrincipal(uri); + return dsm.getLocalStorageForPrincipal(principal, ""); + }; + }catch (e) {/*meh*/} } -- 2.43.2