Bug 536289 - Part 1: Move IPC::InputStream to a more general location. r=jduell a=blocking-fennec

This commit is contained in:
Josh Matthews 2010-10-14 14:21:48 -04:00
Родитель b9d7ede18a
Коммит 33d17004e2
5 изменённых файлов: 107 добавлений и 107 удалений

Просмотреть файл

@ -37,7 +37,7 @@
#ifdef MOZ_IPC
#include "IPC/IPCMessageUtils.h"
#include "mozilla/net/PHttpChannelParams.h"
#include "mozilla/net/NeckoMessageUtils.h"
#endif
#include "nsBufferedStreams.h"

Просмотреть файл

@ -43,7 +43,7 @@
#ifdef MOZ_IPC
#include "IPC/IPCMessageUtils.h"
#include "mozilla/net/PHttpChannelParams.h"
#include "mozilla/net/NeckoMessageUtils.h"
#endif
#include "nsCOMPtr.h"

Просмотреть файл

@ -46,6 +46,7 @@
#include "nsIClassInfo.h"
#include "nsComponentManagerUtils.h"
#include "nsNetUtil.h"
#include "nsStringStream.h"
namespace IPC {
@ -174,6 +175,109 @@ struct ParamTraits<URI>
}
};
class InputStream {
public:
InputStream() : mStream(nsnull) {}
InputStream(nsIInputStream* aStream) : mStream(aStream) {}
operator nsIInputStream*() const { return mStream.get(); }
friend struct ParamTraits<InputStream>;
private:
// Unimplemented
InputStream& operator=(InputStream&);
nsCOMPtr<nsIInputStream> mStream;
};
template<>
struct ParamTraits<InputStream>
{
typedef InputStream paramType;
static void Write(Message* aMsg, const paramType& aParam)
{
bool isNull = !aParam.mStream;
aMsg->WriteBool(isNull);
if (isNull)
return;
nsCOMPtr<nsIIPCSerializable> serializable = do_QueryInterface(aParam.mStream);
bool isSerializable = !!serializable;
WriteParam(aMsg, isSerializable);
if (!serializable) {
NS_WARNING("nsIInputStream implementation doesn't support nsIIPCSerializable; falling back to copying data");
nsCString streamString;
PRUint32 bytes;
aParam.mStream->Available(&bytes);
if (bytes > 0) {
nsresult rv = NS_ReadInputStreamToString(aParam.mStream, streamString, bytes);
NS_ABORT_IF_FALSE(NS_SUCCEEDED(rv), "Can't read input stream into a string!");
}
WriteParam(aMsg, streamString);
return;
}
nsCOMPtr<nsIClassInfo> classInfo = do_QueryInterface(aParam.mStream);
char cidStr[NSID_LENGTH];
nsCID cid;
nsresult rv = classInfo->GetClassIDNoAlloc(&cid);
NS_ABORT_IF_FALSE(NS_SUCCEEDED(rv), "All IPDL streams must report a valid class ID");
cid.ToProvidedString(cidStr);
WriteParam(aMsg, nsCAutoString(cidStr));
serializable->Write(aMsg);
}
static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
{
bool isNull;
if (!ReadParam(aMsg, aIter, &isNull))
return false;
if (isNull) {
aResult->mStream = nsnull;
return true;
}
bool isSerializable;
if (!ReadParam(aMsg, aIter, &isSerializable))
return false;
nsCOMPtr<nsIInputStream> stream;
if (!isSerializable) {
nsCString streamString;
if (!ReadParam(aMsg, aIter, &streamString))
return false;
nsresult rv = NS_NewCStringInputStream(getter_AddRefs(stream), streamString);
if (NS_FAILED(rv))
return false;
} else {
nsCAutoString cidStr;
nsCID cid;
if (!ReadParam(aMsg, aIter, &cidStr) ||
!cid.Parse(cidStr.get()))
return false;
stream = do_CreateInstance(cid);
if (!stream)
return false;
nsCOMPtr<nsIIPCSerializable> serializable = do_QueryInterface(stream);
if (!serializable || !serializable->Read(aMsg, aIter))
return false;
}
stream.swap(aResult->mStream);
return true;
}
};
// nsIPermissionManager utilities
struct Permission

Просмотреть файл

@ -49,7 +49,6 @@
#include "nsHttpHeaderArray.h"
#include "nsHttpResponseHead.h"
#include "nsStringStream.h"
#include "nsIIPCSerializable.h"
#include "nsIClassInfo.h"
#include "nsNetUtil.h"
@ -197,109 +196,6 @@ struct ParamTraits<nsHttpResponseHead>
}
};
class InputStream {
public:
InputStream() : mStream(nsnull) {}
InputStream(nsIInputStream* aStream) : mStream(aStream) {}
operator nsIInputStream*() const { return mStream.get(); }
friend struct ParamTraits<InputStream>;
private:
// Unimplemented
InputStream& operator=(InputStream&);
nsCOMPtr<nsIInputStream> mStream;
};
template<>
struct ParamTraits<InputStream>
{
typedef InputStream paramType;
static void Write(Message* aMsg, const paramType& aParam)
{
bool isNull = !aParam.mStream;
aMsg->WriteBool(isNull);
if (isNull)
return;
nsCOMPtr<nsIIPCSerializable> serializable = do_QueryInterface(aParam.mStream);
bool isSerializable = !!serializable;
WriteParam(aMsg, isSerializable);
if (!serializable) {
NS_WARNING("nsIInputStream implementation doesn't support nsIIPCSerializable; falling back to copying data");
nsCString streamString;
PRUint32 bytes;
aParam.mStream->Available(&bytes);
if (bytes > 0) {
nsresult rv = NS_ReadInputStreamToString(aParam.mStream, streamString, bytes);
NS_ABORT_IF_FALSE(NS_SUCCEEDED(rv), "Can't read input stream into a string!");
}
WriteParam(aMsg, streamString);
return;
}
nsCOMPtr<nsIClassInfo> classInfo = do_QueryInterface(aParam.mStream);
char cidStr[NSID_LENGTH];
nsCID cid;
nsresult rv = classInfo->GetClassIDNoAlloc(&cid);
NS_ABORT_IF_FALSE(NS_SUCCEEDED(rv), "All IPDL streams must report a valid class ID");
cid.ToProvidedString(cidStr);
WriteParam(aMsg, nsCAutoString(cidStr));
serializable->Write(aMsg);
}
static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
{
bool isNull;
if (!ReadParam(aMsg, aIter, &isNull))
return false;
if (isNull) {
aResult->mStream = nsnull;
return true;
}
bool isSerializable;
if (!ReadParam(aMsg, aIter, &isSerializable))
return false;
nsCOMPtr<nsIInputStream> stream;
if (!isSerializable) {
nsCString streamString;
if (!ReadParam(aMsg, aIter, &streamString))
return false;
nsresult rv = NS_NewCStringInputStream(getter_AddRefs(stream), streamString);
if (NS_FAILED(rv))
return false;
} else {
nsCAutoString cidStr;
nsCID cid;
if (!ReadParam(aMsg, aIter, &cidStr) ||
!cid.Parse(cidStr.get()))
return false;
stream = do_CreateInstance(cid);
if (!stream)
return false;
nsCOMPtr<nsIIPCSerializable> serializable = do_QueryInterface(stream);
if (!serializable || !serializable->Read(aMsg, aIter))
return false;
}
stream.swap(aResult->mStream);
return true;
}
};
} // namespace IPC
#endif // mozilla_net_PHttpChannelParams_h

Просмотреть файл

@ -43,7 +43,7 @@
#ifdef MOZ_IPC
#include "IPC/IPCMessageUtils.h"
#include "mozilla/net/PHttpChannelParams.h"
#include "mozilla/net/NeckoMessageUtils.h"
#endif
#include "nsMultiplexInputStream.h"