зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1286472: Replace serializing nsISHEntry.owner with nsISHEntry.triggeringPrincipal. r=bz,mikedeboer
This commit is contained in:
Родитель
caedb13ef1
Коммит
706065f96d
|
@ -170,16 +170,16 @@ var SessionHistoryInternal = {
|
|||
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;
|
||||
|
@ -219,14 +219,14 @@ var SessionHistoryInternal = {
|
|||
},
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
|
@ -235,20 +235,20 @@ var SessionHistoryInternal = {
|
|||
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));
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -379,16 +379,24 @@ var SessionHistoryInternal = {
|
|||
}
|
||||
}
|
||||
|
||||
// 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); }
|
||||
}
|
||||
|
||||
|
|
|
@ -1117,23 +1117,24 @@ SessionStore.prototype = {
|
|||
}
|
||||
}
|
||||
|
||||
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); }
|
||||
}
|
||||
|
||||
|
@ -1249,15 +1250,25 @@ SessionStore.prototype = {
|
|||
}
|
||||
}
|
||||
|
||||
// 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) {
|
||||
|
|
Загрузка…
Ссылка в новой задаче