Bug 1286472: Replace serializing nsISHEntry.owner with nsISHEntry.triggeringPrincipal. r=bz,mikedeboer
authorChristoph Kerschbaumer <ckerschb@christophkerschbaumer.com>
Thu, 28 Jul 2016 09:23:25 +0200
changeset 349109 5edd4f66758902f3c7c1f810b92d582cb33bc5de
parent 349108 edb10ed57ed4f02c996cd35196ffe284ccd843ca
child 349110 af00de9bc66323412d4903d325d79f564b1fab01
push id1230
push userjlund@mozilla.com
push dateMon, 31 Oct 2016 18:13:35 +0000
treeherdermozilla-release@5e06e3766db2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz, mikedeboer
bugs1286472
milestone50.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1286472: Replace serializing nsISHEntry.owner with nsISHEntry.triggeringPrincipal. r=bz,mikedeboer
browser/components/sessionstore/SessionHistory.jsm
mobile/android/components/SessionStore.js
--- a/browser/components/sessionstore/SessionHistory.jsm
+++ b/browser/components/sessionstore/SessionHistory.jsm
@@ -165,26 +165,26 @@ var SessionHistoryInternal = {
       entry.scrollRestorationIsManual = true;
     } else {
       let x = {}, y = {};
       shEntry.getScrollPosition(x, y);
       if (x.value != 0 || y.value != 0)
         entry.scroll = x.value + "," + y.value;
     }
 
-    // Collect owner data for the current history entry.
+    // Collect triggeringPrincipal data for the current history entry.
     try {
-      let owner = this.serializeOwner(shEntry);
-      if (owner) {
-        entry.owner_b64 = owner;
+      let triggeringPrincipal = this.serializeTriggeringPrincipal(shEntry);
+      if (triggeringPrincipal) {
+        entry.triggeringPrincipal_b64 = triggeringPrincipal;
       }
     } catch (ex) {
       // Not catching anything specific here, just possible errors
       // from writeCompoundObject() and the like.
-      debug("Failed serializing owner data: " + ex);
+      debug("Failed serializing triggeringPrincipal data: " + ex);
     }
 
     entry.docIdentifier = shEntry.BFCacheEntry.ID;
 
     if (shEntry.stateData != null) {
       entry.structuredCloneState = shEntry.stateData.getDataAsBase64();
       entry.structuredCloneVersion = shEntry.stateData.formatVersion;
     }
@@ -214,46 +214,46 @@ var SessionHistoryInternal = {
         entry.children = children;
       }
     }
 
     return entry;
   },
 
   /**
-   * Serialize owner data contained in the given session history entry.
+   * Serialize triggeringPrincipal data contained in the given session history entry.
    *
    * @param shEntry
    *        The session history entry.
-   * @return The base64 encoded owner data.
+   * @return The base64 encoded triggeringPrincipal data.
    */
-  serializeOwner: function (shEntry) {
-    if (!shEntry.owner) {
+  serializeTriggeringPrincipal: function (shEntry) {
+    if (!shEntry.triggeringPrincipal) {
       return null;
     }
 
     let binaryStream = Cc["@mozilla.org/binaryoutputstream;1"].
                        createInstance(Ci.nsIObjectOutputStream);
     let pipe = Cc["@mozilla.org/pipe;1"].createInstance(Ci.nsIPipe);
     pipe.init(false, false, 0, 0xffffffff, null);
     binaryStream.setOutputStream(pipe.outputStream);
-    binaryStream.writeCompoundObject(shEntry.owner, Ci.nsISupports, true);
+    binaryStream.writeCompoundObject(shEntry.triggeringPrincipal, Ci.nsIPrincipal, true);
     binaryStream.close();
 
     // Now we want to read the data from the pipe's input end and encode it.
     let scriptableStream = Cc["@mozilla.org/binaryinputstream;1"].
                            createInstance(Ci.nsIBinaryInputStream);
     scriptableStream.setInputStream(pipe.inputStream);
-    let ownerBytes =
+    let triggeringPrincipalBytes =
       scriptableStream.readByteArray(scriptableStream.available());
 
     // We can stop doing base64 encoding once our serialization into JSON
     // is guaranteed to handle all chars in strings, including embedded
     // nulls.
-    return btoa(String.fromCharCode.apply(null, ownerBytes));
+    return btoa(String.fromCharCode.apply(null, triggeringPrincipalBytes));
   },
 
   /**
    * Restores session history data for a given docShell.
    *
    * @param docShell
    *        The docShell that owns the session history.
    * @param tabData
@@ -374,26 +374,34 @@ var SessionHistoryInternal = {
         docIdentMap[entry.docIdentifier] = matchingEntry;
       }
       else {
         shEntry.adoptBFCacheEntry(matchingEntry.shEntry);
         childDocIdents = matchingEntry.childDocIdents;
       }
     }
 
+    // The field entry.owner_b64 got renamed to entry.triggeringPricipal_b64 in
+    // Bug 1286472. To remain backward compatible we still have to support that
+    // field for a few cycles before we can remove it within Bug 1289785.
     if (entry.owner_b64) {
-      var ownerInput = Cc["@mozilla.org/io/string-input-stream;1"].
-                       createInstance(Ci.nsIStringInputStream);
-      var binaryData = atob(entry.owner_b64);
-      ownerInput.setData(binaryData, binaryData.length);
+      entry.triggeringPricipal_b64 = entry.owner_b64;
+      delete entry.owner_b64;
+    }
+
+    if (entry.triggeringPrincipal_b64) {
+      var triggeringPrincipalInput = Cc["@mozilla.org/io/string-input-stream;1"]
+                                       .createInstance(Ci.nsIStringInputStream);
+      var binaryData = atob(entry.triggeringPrincipal_b64);
+      triggeringPrincipalInput.setData(binaryData, binaryData.length);
       var binaryStream = Cc["@mozilla.org/binaryinputstream;1"].
                          createInstance(Ci.nsIObjectInputStream);
-      binaryStream.setInputStream(ownerInput);
+      binaryStream.setInputStream(triggeringPrincipalInput);
       try { // Catch possible deserialization exceptions
-        shEntry.owner = binaryStream.readObject(true);
+        shEntry.triggeringPrincipal = binaryStream.readObject(true);
       } catch (ex) { debug(ex); }
     }
 
     if (entry.children && shEntry instanceof Ci.nsISHContainer) {
       for (var i = 0; i < entry.children.length; i++) {
         //XXXzpao Wallpaper patch for bug 514751
         if (!entry.children[i].url)
           continue;
--- a/mobile/android/components/SessionStore.js
+++ b/mobile/android/components/SessionStore.js
@@ -1112,33 +1112,34 @@ SessionStore.prototype = {
     } else {
       let x = {}, y = {};
       aEntry.getScrollPosition(x, y);
       if (x.value != 0 || y.value != 0) {
         entry.scroll = x.value + "," + y.value;
       }
     }
 
-    if (aEntry.owner) {
+    if (aEntry.triggeringPrincipal) {
       try {
         let binaryStream = Cc["@mozilla.org/binaryoutputstream;1"].createInstance(Ci.nsIObjectOutputStream);
         let pipe = Cc["@mozilla.org/pipe;1"].createInstance(Ci.nsIPipe);
         pipe.init(false, false, 0, 0xffffffff, null);
         binaryStream.setOutputStream(pipe.outputStream);
-        binaryStream.writeCompoundObject(aEntry.owner, Ci.nsISupports, true);
+        binaryStream.writeCompoundObject(aEntry.triggeringPrincipal, Ci.nsIPrincipal, true);
         binaryStream.close();
 
         // Now we want to read the data from the pipe's input end and encode it.
         let scriptableStream = Cc["@mozilla.org/binaryinputstream;1"].createInstance(Ci.nsIBinaryInputStream);
         scriptableStream.setInputStream(pipe.inputStream);
-        let ownerBytes = scriptableStream.readByteArray(scriptableStream.available());
+        let triggeringPrincipalBytes = scriptableStream.readByteArray(scriptableStream.available());
         // We can stop doing base64 encoding once our serialization into JSON
         // is guaranteed to handle all chars in strings, including embedded
         // nulls.
-        entry.owner_b64 = btoa(String.fromCharCode.apply(null, ownerBytes));
+        entry.triggeringPrincipal_b64 =
+          btoa(String.fromCharCode.apply(null, triggeringPrincipalBytes));
       } catch (e) { dump(e); }
     }
 
     entry.docIdentifier = aEntry.BFCacheEntry.ID;
 
     if (aEntry.stateData != null) {
       entry.structuredCloneState = aEntry.stateData.getDataAsBase64();
       entry.structuredCloneVersion = aEntry.stateData.formatVersion;
@@ -1244,25 +1245,35 @@ SessionStore.prototype = {
         matchingEntry = {shEntry: shEntry, childDocIdents: childDocIdents};
         aDocIdentMap[aEntry.docIdentifier] = matchingEntry;
       } else {
         shEntry.adoptBFCacheEntry(matchingEntry.shEntry);
         childDocIdents = matchingEntry.childDocIdents;
       }
     }
 
+    // The field aEntry.owner_b64 got renamed to aEntry.triggeringPricipal_b64 in
+    // Bug 1286472. To remain backward compatible we still have to support that
+    // field for a few cycles before we can remove it within Bug 1289785.
     if (aEntry.owner_b64) {
-      let ownerInput = Cc["@mozilla.org/io/string-input-stream;1"].createInstance(Ci.nsIStringInputStream);
-      let binaryData = atob(aEntry.owner_b64);
-      ownerInput.setData(binaryData, binaryData.length);
-      let binaryStream = Cc["@mozilla.org/binaryinputstream;1"].createInstance(Ci.nsIObjectInputStream);
-      binaryStream.setInputStream(ownerInput);
+      aEntry.triggeringPricipal_b64 = aEntry.owner_b64;
+      delete aEntry.owner_b64;
+    }
+
+    if (aEntry.triggeringPrincipal_b64) {
+      let triggeringPrincipalInput = Cc["@mozilla.org/io/string-input-stream;1"]
+                                       .createInstance(Ci.nsIStringInputStream);
+      let binaryData = atob(aEntry.triggeringPrincipal_b64);
+      triggeringPrincipalInput.setData(binaryData, binaryData.length);
+      let binaryStream = Cc["@mozilla.org/binaryinputstream;1"]
+                           .createInstance(Ci.nsIObjectInputStream);
+      binaryStream.setInputStream(triggeringPrincipalInput);
       try { // Catch possible deserialization exceptions
-        shEntry.owner = binaryStream.readObject(true);
-      } catch (ex) { dump(ex); }
+        shEntry.triggeringPrincipal = binaryStream.readObject(true);
+      } catch (ex) { Cu.reportError("SessionStore: " + ex); }
     }
 
     if (aEntry.children && shEntry instanceof Ci.nsISHContainer) {
       for (let i = 0; i < aEntry.children.length; i++) {
         if (!aEntry.children[i].url) {
           continue;
         }