Bug 566305. Serialize nsIStringInputStream. r=bzbarsky

This commit is contained in:
Jae-Seong Lee-Russo 2010-06-01 11:40:21 -04:00
Родитель 4ddd8b4cf8
Коммит bf9fb1e63e
1 изменённых файлов: 50 добавлений и 0 удалений

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

@ -49,6 +49,9 @@
#include "nsHttpHeaderArray.h"
#include "nsHttpResponseHead.h"
#include "nsIStringStream.h"
#include "nsISupportsPrimitives.h"
namespace mozilla {
namespace net {
@ -192,6 +195,53 @@ struct ParamTraits<nsHttpResponseHead>
}
};
template<>
struct ParamTraits<nsIStringInputStream*>
{
typedef nsIStringInputStream* paramType;
static void Write(Message* aMsg, const paramType& aParam)
{
nsCAutoString value;
nsCOMPtr<nsISupportsCString> cstr(do_QueryInterface(aParam));
if (cstr) {
cstr->GetData(value);
} else {
PRUint32 length;
aParam->Available(&length);
value.SetLength(length);
NS_ASSERTION(value.Length() == length, "SetLength failed");
char *c = value.BeginWriting();
PRUint32 bytesRead;
nsresult rv = aParam->Read(c, length, &bytesRead);
NS_ASSERTION(NS_SUCCEEDED(rv) && bytesRead == length, "Read failed");
}
WriteParam(aMsg, value);
}
static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
{
nsCAutoString value;
if (!ReadParam(aMsg, aIter, &value))
return false;
nsresult rv;
nsCOMPtr<nsIStringInputStream> stream
(do_CreateInstance("@mozilla.org/io/string-input-stream;1", &rv));
if (NS_FAILED(rv))
return false;
rv = stream->SetData(value.get(), value.Length());
if (NS_FAILED(rv))
return false;
stream.forget(aResult);
return true;
}
};
} // namespace IPC
#endif // mozilla_net_PHttpChannelParams_h