[PALEMOON] Replace serializing nsISHEntry.owner with nsISHEntry.triggeringPrincipal

This commit is contained in:
JustOff 2018-04-30 17:26:04 +03:00 • committed by Roy Tam
commit a964b09e43

View file

@ -2085,7 +2085,7 @@ var SessionStoreInternal = {
} }
catch (ex) { debug(ex); } // POSTDATA is tricky - especially since some extensions don't get it right catch (ex) { debug(ex); } // POSTDATA is tricky - especially since some extensions don't get it right
if (aEntry.owner) { if (aEntry.triggeringPrincipal) {
// Not catching anything specific here, just possible errors // Not catching anything specific here, just possible errors
// from writeCompoundObject and the like. // from writeCompoundObject and the like.
try { try {
@ -2094,19 +2094,19 @@ var SessionStoreInternal = {
var pipe = Cc["@mozilla.org/pipe;1"].createInstance(Ci.nsIPipe); var pipe = Cc["@mozilla.org/pipe;1"].createInstance(Ci.nsIPipe);
pipe.init(false, false, 0, 0xffffffff, null); pipe.init(false, false, 0, 0xffffffff, null);
binaryStream.setOutputStream(pipe.outputStream); binaryStream.setOutputStream(pipe.outputStream);
binaryStream.writeCompoundObject(aEntry.owner, Ci.nsISupports, true); binaryStream.writeCompoundObject(aEntry.triggeringPrincipal, Ci.nsIPrincipal, true);
binaryStream.close(); binaryStream.close();
// Now we want to read the data from the pipe's input end and encode it. // Now we want to read the data from the pipe's input end and encode it.
var scriptableStream = Cc["@mozilla.org/binaryinputstream;1"]. var scriptableStream = Cc["@mozilla.org/binaryinputstream;1"].
createInstance(Ci.nsIBinaryInputStream); createInstance(Ci.nsIBinaryInputStream);
scriptableStream.setInputStream(pipe.inputStream); scriptableStream.setInputStream(pipe.inputStream);
var ownerBytes = var triggeringPrincipalBytes =
scriptableStream.readByteArray(scriptableStream.available()); scriptableStream.readByteArray(scriptableStream.available());
// We can stop doing base64 encoding once our serialization into JSON // We can stop doing base64 encoding once our serialization into JSON
// is guaranteed to handle all chars in strings, including embedded // is guaranteed to handle all chars in strings, including embedded
// nulls. // nulls.
entry.owner_b64 = btoa(String.fromCharCode.apply(null, ownerBytes)); entry.triggeringPrincipal_b64 = btoa(String.fromCharCode.apply(null, triggeringPrincipalBytes));
} }
catch (ex) { debug(ex); } catch (ex) { debug(ex); }
} }
@ -3400,16 +3400,24 @@ var SessionStoreInternal = {
} }
} }
if (aEntry.owner_b64) { // The field aEntry.owner_b64 got renamed to aEntry.triggeringPricipal_b64 in
var ownerInput = Cc["@mozilla.org/io/string-input-stream;1"]. // Bug 1286472. To remain backward compatible we still have to support that
createInstance(Ci.nsIStringInputStream); // field for a few cycles before we can remove it within Bug 1289785.
var binaryData = atob(aEntry.owner_b64); if (aEntry.owner_b64) {
ownerInput.setData(binaryData, binaryData.length); aEntry.triggeringPrincipal_b64 = aEntry.owner_b64;
delete aEntry.owner_b64;
}
if (aEntry.triggeringPrincipal_b64) {
var triggeringPrincipalInput = Cc["@mozilla.org/io/string-input-stream;1"].
createInstance(Ci.nsIStringInputStream);
var binaryData = atob(aEntry.triggeringPrincipal_b64);
triggeringPrincipalInput.setData(binaryData, binaryData.length);
var binaryStream = Cc["@mozilla.org/binaryinputstream;1"]. var binaryStream = Cc["@mozilla.org/binaryinputstream;1"].
createInstance(Ci.nsIObjectInputStream); createInstance(Ci.nsIObjectInputStream);
binaryStream.setInputStream(ownerInput); binaryStream.setInputStream(triggeringPrincipalInput);
try { // Catch possible deserialization exceptions try { // Catch possible deserialization exceptions
shEntry.owner = binaryStream.readObject(true); shEntry.triggeringPrincipal = binaryStream.readObject(true);
} catch (ex) { debug(ex); } } catch (ex) { debug(ex); }
} }