Fix nsStandardURL serialization/deserialization to properly restore all state. Bug 396389, r+sr=biesi, a=bsmedberg

This commit is contained in:
bzbarsky@mit.edu 2007-09-17 15:23:12 -07:00
parent 2f0c7d5b24
commit 56d122cc1c
2 changed files with 35 additions and 2 deletions

View File

@ -82,7 +82,7 @@ const char XUL_FASTLOAD_FILE_BASENAME[] = "XUL";
// (opaque to XPCOM FastLoad code) format of XUL-specific XDR serializations.
// See also JSXDR_BYTECODE_VERSION in jsxdrapi.h, which tracks incompatible JS
// bytecode version changes.
#define XUL_FASTLOAD_FILE_VERSION (0xfeedbeef - 23)
#define XUL_FASTLOAD_FILE_VERSION (0xfeedbeef - 24)
#define XUL_SERIALIZATION_BUFFER_SIZE (64 * 1024)
#define XUL_DESERIALIZATION_BUFFER_SIZE (8 * 1024)

View File

@ -2631,6 +2631,10 @@ nsStandardURL::SetMutable(PRBool value)
NS_IMETHODIMP
nsStandardURL::Read(nsIObjectInputStream *stream)
{
NS_PRECONDITION(!mHostA, "Shouldn't have cached ASCII host");
NS_PRECONDITION(mSpecEncoding == eEncoding_Unknown,
"Shouldn't have spec encoding here");
nsresult rv;
PRUint32 urlType;
@ -2706,9 +2710,30 @@ nsStandardURL::Read(nsIObjectInputStream *stream)
PRBool isMutable;
rv = stream->ReadBoolean(&isMutable);
if (NS_FAILED(rv)) return rv;
if (isMutable != PR_TRUE && isMutable != PR_FALSE) {
NS_WARNING("Unexpected boolean value");
return NS_ERROR_UNEXPECTED;
}
mMutable = isMutable;
PRBool supportsFileURL;
rv = stream->ReadBoolean(&supportsFileURL);
if (NS_FAILED(rv)) return rv;
if (supportsFileURL != PR_TRUE && supportsFileURL != PR_FALSE) {
NS_WARNING("Unexpected boolean value");
return NS_ERROR_UNEXPECTED;
}
mSupportsFileURL = supportsFileURL;
PRUint32 hostEncoding;
rv = stream->Read32(&hostEncoding);
if (NS_FAILED(rv)) return rv;
if (hostEncoding != eEncoding_ASCII && hostEncoding != eEncoding_UTF8) {
NS_WARNING("Unexpected host encoding");
return NS_ERROR_UNEXPECTED;
}
mHostEncoding = hostEncoding;
return NS_OK;
}
@ -2774,6 +2799,14 @@ nsStandardURL::Write(nsIObjectOutputStream *stream)
rv = stream->WriteBoolean(mMutable);
if (NS_FAILED(rv)) return rv;
rv = stream->WriteBoolean(mSupportsFileURL);
if (NS_FAILED(rv)) return rv;
rv = stream->Write32(mHostEncoding);
if (NS_FAILED(rv)) return rv;
// mSpecEncoding and mHostA are just caches that can be recovered as needed.
return NS_OK;
}