diff --git a/netwerk/protocol/http/src/PHttpChannelParams.h b/netwerk/protocol/http/src/PHttpChannelParams.h index 4f9443b8336b..51f4561b6e0e 100644 --- a/netwerk/protocol/http/src/PHttpChannelParams.h +++ b/netwerk/protocol/http/src/PHttpChannelParams.h @@ -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 } }; +template<> +struct ParamTraits +{ + typedef nsIStringInputStream* paramType; + + static void Write(Message* aMsg, const paramType& aParam) + { + nsCAutoString value; + nsCOMPtr 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 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