From: Bill Erickson Date: Fri, 25 Jan 2013 20:46:39 +0000 (-0500) Subject: XUL localStorage interface X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=71c88b8bfee194b077e08e8dbf2346c30d28c0ea;p=evergreen%2Fequinox.git 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 does not work with the oils:// protocol. Signed-off-by: Bill Erickson --- diff --git a/Open-ILS/web/js/dojo/openils/XUL.js b/Open-ILS/web/js/dojo/openils/XUL.js index 9385091b90..1b6bbf1d4c 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() { @@ -165,5 +164,22 @@ 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() { + 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*/} }