зеркало из https://github.com/mozilla/gecko-dev.git
bug 170585, Scriptable streams are broken; r=darinf, sr=dougt
add factories so js can create the nsIBinary*Stream objects, also adds read/writeByteArray functions
This commit is contained in:
Родитель
e073e1a415
Коммит
500958a09b
|
@ -48,6 +48,7 @@
|
|||
#include "nsIProperties.h"
|
||||
#include "nsPersistentProperties.h"
|
||||
#include "nsScriptableInputStream.h"
|
||||
#include "nsBinaryStream.h"
|
||||
|
||||
#include "nsMemoryImpl.h"
|
||||
#include "nsErrorService.h"
|
||||
|
@ -173,6 +174,8 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(nsAtomService);
|
|||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsExceptionService);
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsTimerImpl);
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsTimerManager);
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsBinaryOutputStream)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsBinaryInputStream)
|
||||
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(nsVariant);
|
||||
|
||||
|
@ -290,6 +293,8 @@ static const nsModuleComponentInfo components[] = {
|
|||
COMPONENT(ARENA, ArenaImpl::Create),
|
||||
COMPONENT(BYTEBUFFER, ByteBufferImpl::Create),
|
||||
COMPONENT(SCRIPTABLEINPUTSTREAM, nsScriptableInputStream::Create),
|
||||
COMPONENT(BINARYINPUTSTREAM, nsBinaryInputStreamConstructor),
|
||||
COMPONENT(BINARYOUTPUTSTREAM, nsBinaryOutputStreamConstructor),
|
||||
|
||||
#define NS_PROPERTIES_CLASSNAME "Properties"
|
||||
COMPONENT(PROPERTIES, nsProperties::Create),
|
||||
|
|
|
@ -797,7 +797,7 @@ nsOpaqueKey::nsOpaqueKey(nsIObjectInputStream* aStream, nsresult *aResult)
|
|||
{
|
||||
nsresult rv = aStream->Read32(&mBufLen);
|
||||
if (NS_SUCCEEDED(rv))
|
||||
rv = aStream->ReadBytes(&mBuf, mBufLen);
|
||||
rv = aStream->ReadBytes(mBufLen, &mBuf);
|
||||
*aResult = rv;
|
||||
MOZ_COUNT_CTOR(nsOpaqueKey);
|
||||
}
|
||||
|
|
|
@ -39,12 +39,7 @@
|
|||
#include "nsIStreamBufferAccess.h"
|
||||
#include "nsMemory.h"
|
||||
#include "prlong.h"
|
||||
|
||||
nsBinaryOutputStream::nsBinaryOutputStream(nsIOutputStream* aStream)
|
||||
: mOutputStream(aStream),
|
||||
mBufferAccess(do_QueryInterface(aStream))
|
||||
{
|
||||
}
|
||||
#include "nsGenericFactory.h"
|
||||
|
||||
NS_IMPL_ISUPPORTS1(nsBinaryOutputStream, nsIBinaryOutputStream)
|
||||
|
||||
|
@ -98,6 +93,7 @@ nsBinaryOutputStream::SetOutputStream(nsIOutputStream *aOutputStream)
|
|||
{
|
||||
NS_ENSURE_ARG_POINTER(aOutputStream);
|
||||
mOutputStream = aOutputStream;
|
||||
mBufferAccess = do_QueryInterface(aOutputStream);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -224,6 +220,12 @@ nsBinaryOutputStream::WriteBytes(const char *aString, PRUint32 aLength)
|
|||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsBinaryOutputStream::WriteByteArray(PRUint8 *aBytes, PRUint32 aLength)
|
||||
{
|
||||
return WriteBytes(NS_REINTERPRET_CAST(char *, aBytes), aLength);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsBinaryOutputStream::WriteObject(nsISupports* aObject, PRBool aIsStrongRef)
|
||||
{
|
||||
|
@ -269,12 +271,6 @@ nsBinaryOutputStream::PutBuffer(char* aBuffer, PRUint32 aLength)
|
|||
mBufferAccess->PutBuffer(aBuffer, aLength);
|
||||
}
|
||||
|
||||
nsBinaryInputStream::nsBinaryInputStream(nsIInputStream* aStream)
|
||||
: mInputStream(aStream),
|
||||
mBufferAccess(do_QueryInterface(aStream))
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS1(nsBinaryInputStream, nsIBinaryInputStream)
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
@ -342,6 +338,7 @@ nsBinaryInputStream::SetInputStream(nsIInputStream *aInputStream)
|
|||
{
|
||||
NS_ENSURE_ARG_POINTER(aInputStream);
|
||||
mInputStream = aInputStream;
|
||||
mBufferAccess = do_QueryInterface(aInputStream);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -580,7 +577,7 @@ nsBinaryInputStream::ReadString(nsAString& aString)
|
|||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsBinaryInputStream::ReadBytes(char* *aString, PRUint32 aLength)
|
||||
nsBinaryInputStream::ReadBytes(PRUint32 aLength, char* *_rval)
|
||||
{
|
||||
nsresult rv;
|
||||
PRUint32 bytesRead;
|
||||
|
@ -591,16 +588,25 @@ nsBinaryInputStream::ReadBytes(char* *aString, PRUint32 aLength)
|
|||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
rv = Read(s, aLength, &bytesRead);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
if (NS_FAILED(rv)) {
|
||||
nsMemory::Free(s);
|
||||
return rv;
|
||||
}
|
||||
if (bytesRead != aLength) {
|
||||
nsMemory::Free(s);
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
*aString = s;
|
||||
*_rval = s;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsBinaryInputStream::ReadByteArray(PRUint32 aLength, PRUint8* *_rval)
|
||||
{
|
||||
return ReadBytes(aLength, NS_REINTERPRET_CAST(char **, _rval));
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsBinaryInputStream::ReadObject(PRBool aIsStrongRef, nsISupports* *aObject)
|
||||
{
|
||||
|
|
|
@ -28,12 +28,23 @@
|
|||
#include "nsIObjectOutputStream.h"
|
||||
#include "nsIStreamBufferAccess.h"
|
||||
|
||||
#define NS_BINARYOUTPUTSTREAM_CID \
|
||||
{ /* 86c37b9a-74e7-4672-844e-6e7dd83ba484 */ \
|
||||
0x86c37b9a, \
|
||||
0x74e7, \
|
||||
0x4672, \
|
||||
{0x84, 0x4e, 0x6e, 0x7d, 0xd8, 0x3b, 0xa4, 0x84} \
|
||||
}
|
||||
|
||||
#define NS_BINARYOUTPUTSTREAM_CONTRACTID "@mozilla.org/binaryoutputstream;1"
|
||||
#define NS_BINARYOUTPUTSTREAM_CLASSNAME "Binary Output Stream"
|
||||
|
||||
// Derive from nsIObjectOutputStream so this class can be used as a superclass
|
||||
// by nsObjectOutputStream.
|
||||
class nsBinaryOutputStream : public nsIObjectOutputStream
|
||||
{
|
||||
public:
|
||||
nsBinaryOutputStream(nsIOutputStream *aStream);
|
||||
nsBinaryOutputStream() {};
|
||||
virtual ~nsBinaryOutputStream() {};
|
||||
|
||||
protected:
|
||||
|
@ -56,12 +67,23 @@ protected:
|
|||
nsCOMPtr<nsIStreamBufferAccess> mBufferAccess;
|
||||
};
|
||||
|
||||
#define NS_BINARYINPUTSTREAM_CID \
|
||||
{ /* c521a612-2aad-46db-b6ab-3b821fb150b1 */ \
|
||||
0xc521a612, \
|
||||
0x2aad, \
|
||||
0x46db, \
|
||||
{0xb6, 0xab, 0x3b, 0x82, 0x1f, 0xb1, 0x50, 0xb1} \
|
||||
}
|
||||
|
||||
#define NS_BINARYINPUTSTREAM_CONTRACTID "@mozilla.org/binaryinputstream;1"
|
||||
#define NS_BINARYINPUTSTREAM_CLASSNAME "Binary Input Stream"
|
||||
|
||||
// Derive from nsIObjectInputStream so this class can be used as a superclass
|
||||
// by nsObjectInputStream.
|
||||
class nsBinaryInputStream : public nsIObjectInputStream
|
||||
{
|
||||
public:
|
||||
nsBinaryInputStream(nsIInputStream *aStream);
|
||||
nsBinaryInputStream() {};
|
||||
virtual ~nsBinaryInputStream() {};
|
||||
|
||||
protected:
|
||||
|
|
|
@ -261,8 +261,8 @@ class nsFastLoadFileReader
|
|||
{
|
||||
public:
|
||||
nsFastLoadFileReader(nsIInputStream *aStream)
|
||||
: nsBinaryInputStream(aStream),
|
||||
mCurrentDocumentMapEntry(nsnull) {
|
||||
: mCurrentDocumentMapEntry(nsnull) {
|
||||
SetInputStream(aStream);
|
||||
MOZ_COUNT_CTOR(nsFastLoadFileReader);
|
||||
}
|
||||
|
||||
|
@ -403,10 +403,10 @@ class nsFastLoadFileWriter
|
|||
{
|
||||
public:
|
||||
nsFastLoadFileWriter(nsIOutputStream *aStream, nsIFastLoadFileIO* aFileIO)
|
||||
: nsBinaryOutputStream(aStream),
|
||||
mCurrentDocumentMapEntry(nsnull),
|
||||
: mCurrentDocumentMapEntry(nsnull),
|
||||
mFileIO(aFileIO)
|
||||
{
|
||||
SetOutputStream(aStream);
|
||||
mHeader.mChecksum = 0;
|
||||
mIDMap.ops = mObjectMap.ops = mDocumentMap.ops = mURIMap.ops = nsnull;
|
||||
mDependencyMap.ops = nsnull;
|
||||
|
|
|
@ -60,7 +60,15 @@ interface nsIBinaryInputStream : nsIInputStream {
|
|||
/**
|
||||
* Read an opaque byte array from a binary stream.
|
||||
*/
|
||||
void readBytes([size_is(aLength)] out string aString, in PRUint32 aLength);
|
||||
void readBytes(in PRUint32 aLength,
|
||||
[size_is(aLength), retval] out string aString);
|
||||
|
||||
/**
|
||||
* Read an opaque byte array from a binary stream, storing the results
|
||||
* as an array of PRUint8s.
|
||||
*/
|
||||
void readByteArray(in PRUint32 aLength,
|
||||
[array, size_is(aLength), retval] out PRUint8 aBytes);
|
||||
};
|
||||
|
||||
%{C++
|
||||
|
|
|
@ -68,6 +68,13 @@ interface nsIBinaryOutputStream : nsIOutputStream {
|
|||
* Write an opaque byte array to a binary stream.
|
||||
*/
|
||||
void writeBytes([size_is(aLength)] in string aString, in PRUint32 aLength);
|
||||
|
||||
/**
|
||||
* Write an opaque byte array to a binary stream.
|
||||
*/
|
||||
void writeByteArray([array, size_is(aLength)] in PRUint8 aBytes,
|
||||
in PRUint32 aLength);
|
||||
|
||||
};
|
||||
|
||||
%{C++
|
||||
|
|
Загрузка…
Ссылка в новой задаче