Bug 511635 - Port bug 455070 [Make sessionStorage object conform the WHATWG spec] to SeaMonkey
authorMisak Khachatryan <misak@xter.net>
Wed, 16 Sep 2009 23:11:09 +0200
changeset 3820 3eb3ed8481ed3fe8d3128e17d4380517cf225b35
parent 3819 322f46abfa4450e813959e9751e431e394d47afb
child 3821 cc4c93a723de8a8ba54b7858d4a1cc15d2765847
push id2991
push usersgautherie.bz@free.fr
push dateWed, 16 Sep 2009 21:11:27 +0000
treeherdercomm-central@3eb3ed8481ed [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs511635, 455070
Bug 511635 - Port bug 455070 [Make sessionStorage object conform the WHATWG spec] to SeaMonkey r+sr=neil a-seamonkey2.0=kairo
suite/common/src/nsSessionStore.js
--- a/suite/common/src/nsSessionStore.js
+++ b/suite/common/src/nsSessionStore.js
@@ -1124,45 +1124,58 @@ SessionStoreService.prototype = {
    * @param aFullData
    *        always return privacy sensitive data (use with care)
    */
   _serializeSessionStorage:
     function sss_serializeSessionStorage(aTabData, aHistory, aDocShell, aFullData) {
     let storageData = {};
     let hasContent = false;
 
+#ifdef MOZILLA_1_9_1_BRANCH
+    aDocShell.QueryInterface(Components.interfaces.nsIDocShell_MOZILLA_1_9_1_SessionStorage);
+#endif
     for (let i = 0; i < aHistory.count; i++) {
       let uri = aHistory.getEntryAtIndex(i, false).URI;
-      // sessionStorage is saved per domain (cf. nsDocShell::GetSessionStorageForURI)
+      // sessionStorage is saved per origin (cf. nsDocShell::GetSessionStorageForURI)
       let domain = uri.spec;
       try {
         if (uri.host)
           domain = uri.prePath;
       }
       catch (ex) { /* this throws for host-less URIs (such as about: or jar:) */ }
       if (storageData[domain] || !(aFullData || this._checkPrivacyLevel(uri.schemeIs("https"))))
         continue;
 
       let storage, storageItemCount = 0;
       try {
+        var principal = Components.classes["@mozilla.org/scriptsecuritymanager;1"]
+                                  .getService(Components.interfaces.nsIScriptSecurityManager)
+                                  .getCodebasePrincipal(uri);
+
+        // Using getSessionStorageForPrincipal instead of getSessionStorageForURI
+        // just to be able to pass aCreate = false, that avoids creation of the
+        // sessionStorage object for the page earlier than the page really
+        // requires it. It was causing problems while accessing a storage when
+        // a page later changed its domain.
+        storage = aDocShell.getSessionStorageForPrincipal(principal, false);
+        if (storage)
+          storageItemCount = storage.length;
         storage = aDocShell.getSessionStorageForURI(uri);
         storageItemCount = storage.length;
       }
       catch (ex) { /* sessionStorage might throw if it's turned off, see bug 458954 */ }
       if (storageItemCount == 0)
         continue;
 
       let data = storageData[domain] = {};
       for (let j = 0; j < storageItemCount; j++) {
         try {
           let key = storage.key(j);
           let item = storage.getItem(key);
-          data[key] = { value: item.value };
-          if (uri.schemeIs("https") && item.secure)
-            data[key].secure = true;
+          data[key] = item;
         }
         catch (ex) { /* XXXzeniko this currently throws for secured items (cf. bug 442048) */ }
       }
       hasContent = true;
     }
 
     if (hasContent)
       aTabData.storage = storageData;
@@ -1943,24 +1956,25 @@ SessionStoreService.prototype = {
    * restores all sessionStorage "super cookies"
    * @param aStorageData
    *        Storage data to be restored
    * @param aDocShell
    *        A tab's docshell (containing the sessionStorage)
    */
   _deserializeSessionStorage: function sss_deserializeSessionStorage(aStorageData, aDocShell) {
     let ioService = Components.classes["@mozilla.org/network/io-service;1"].getService(Components.interfaces.nsIIOService);
+#ifdef MOZILLA_1_9_1_BRANCH
+    aDocShell.QueryInterface(Components.interfaces.nsIDocShell_MOZILLA_1_9_1_SessionStorage);
+#endif
     for (let url in aStorageData) {
       let uri = ioService.newURI(url, null, null);
       let storage = aDocShell.getSessionStorageForURI(uri);
       for (let key in aStorageData[url]) {
         try {
-          storage.setItem(key, aStorageData[url][key].value);
-          if (uri.schemeIs("https"))
-            storage.getItem(key).secure = aStorageData[url][key].secure || false;
+          storage.setItem(key, aStorageData[url][key]);
         }
         catch (ex) { Cu.reportError(ex); } // throws e.g. for URIs that can't have sessionStorage
       }
     }
   },
 
   /**
    * Restore properties to a loaded document