Skip to content

Commit

Permalink
Firefox: different kind of vAPI.localStorage
Browse files Browse the repository at this point in the history
  • Loading branch information
Deathamns committed Mar 16, 2015
1 parent 32837de commit 5ae7687
Showing 1 changed file with 25 additions and 12 deletions.
37 changes: 25 additions & 12 deletions platform/firefox/vapi-common.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,21 +120,34 @@ vAPI.closePopup = function() {
// This storage is optional, but it is nice to have, for a more polished user
// experience.

Object.defineProperty(vAPI, 'localStorage', {
get: function() {
if ( this._localStorage ) {
return this._localStorage;
vAPI.localStorage = {
PB: Services.prefs.getBranch('extensions.' + location.host + '.'),
str: Components.classes['@mozilla.org/supports-string;1']
.createInstance(Components.interfaces.nsISupportsString),
getItem: function(key) {
try {
return this.PB.getComplexValue(
key, Components.interfaces.nsISupportsString
).data;
} catch (ex) {
return null;
}

this._localStorage = Services.domStorageManager.getLocalStorageForPrincipal(
Services.scriptSecurityManager.getCodebasePrincipal(
Services.io.newURI('http://ublock.raymondhill.net/', null, null)
),
''
},
setItem: function(key, value) {
this.str.data = value;
this.PB.setComplexValue(
key,
Components.interfaces.nsISupportsString,
this.str
);
return this._localStorage;
},
removeItem: function(key) {
this.PB.clearUserPref(key);
},
clear: function() {
this.PB.deleteBranch('');
}
});
};

/******************************************************************************/

Expand Down

0 comments on commit 5ae7687

Please sign in to comment.