/**
 * @namespace A shim to support cross browser Local Storage. This
 * shim mimics the localStorage API, but it will use alternate
 * storage mechanisms if localStorage is not available.
 */
var ls = {
  
  /**
   * Indicates whether the native localStorage API is available on the
   * current platform.
   */
  localStorageDefined: true,

  /**
   * Set an item to local storage. If the item is not a string, this
   * function will attempt to serialize it using the JSON.stringify
   * function.
   * @param {string|object} key is the string to store in key/value storage.
   * @param {string} value is the value to assign to the key.
   */
  setItem: function(key, value) {
    if ( typeof(value) !== "string" ){
      value = JSON.stringify(value);
    }

    if ( ls.localStorageDefined ) {
      localStorage.setItem(key, value);
    } else {
      ls.preferences.setCharPref(key, value);
    }

    return value;
  },

  /**
   * LocalStorage getter returns the stored value if it is defined.
   * The string value stored attempts to reconstruct an object using
   * the JSON.parse api. If parsing an object fails, the string will
   * be returned.
   * @param {string} key the value to retrieve from local storage.
   * @return {string|object} Representing the current value of the key.
   */
  getItem: function(key) {
    if ( ls.localStorageDefined ) {
      var value = localStorage.getItem(key);
      if (value === null){
        return undefined;
      }
      try {  // try to parse stored value as JSON
        var parsed = JSON.parse(value);
        return parsed;
      } catch(e) { // return original value
        return value;
      }
    } else {
      try {
        try { // try to parse stored value as JSON
          var value = JSON.parse(ls.preferences.getCharPref(key));
          return value;
        } catch(e){
          return ls.preferences.getCharPref(key);
        }
      } catch(e) {
        console.warn("Local Storage key was not in storage");
        return undefined;
      }
    }
  },

  /**
   * Remove an item from local storage.
   * @param {string} key the key to remove from storage.
   * @return {undefined} Returns undefined regardless
   * of whether the key existed in localStorage.
   */
  removeItem: function(key) {
    if ( ls.localStorageDefined ) {
      return localStorage.removeItem(key);
    } else {
      try {
        ls.preferences.clearUserPref(key);
      } catch(e) {
        console.warn("Local Storage key was not in storage when it was removed");
      }
      return undefined;
    }
  }
};

// Determine whether localstorage can be used directly
try { 
  localStorage;
} catch(e) {
  ls.localStorageDefined = false;
  
  // Assuming Xul firefox
  ls.preferences = Components.classes["@mozilla.org/preferences-service;1"]
                         .getService(Components.interfaces.nsIPrefService)
                         .getBranch("extensions.privly.");
}

@@ -2567,99 +2567,454 @@
 %7D;%0A%0A
-// Determine whether localstorage can be used directly%0Atry %7B %0A  
+try %7B%0A  localStorage;%0A%7D catch(e) %7B%0A  /**%0A   * Firefox: Jetpack simple-storage%0A   * Two Cases in which this file is run/used -- %0A   * 1. Loaded as a CommonJS module(reused as a Local Storage shim %0A   *    in lib/
 local
-S
+_s
 torage
-;%0A%7D catch(e) %7B%0A
+.js).%0A   * 2. Privileged JS code run in a chrome page. for eg:- ChromeFirstRun page. %0A   */ %0A  if (typeof module !== 'undefined' && module.exports) %7B%0A    // Case 1%0A    module.exports.ls = ls;   %0A  %7D else %7B%0A    // Case 2%0A  
   ls
@@ -3049,35 +3049,35 @@
 ;%0A  
-%0A
   // 
-Assuming Xul firefox%0A
+Preferences Storage%0A  
   ls
@@ -3147,18 +3147,18 @@
 vice;1%22%5D
+.
 %0A
- 
         
@@ -3172,18 +3172,16 @@
         
- .
 getServi
@@ -3220,16 +3220,17 @@
 Service)
+.
 %0A       
@@ -3249,11 +3249,8 @@
     
-  .
 getB
@@ -3278,10 +3278,14 @@
 vly.%22);%0A
+  %7D%0A
 %7D%0A

Allow reuse of LocalStorage shim