From 4a96b44593885484d4ef691ca61be5a1410b18b9 Mon Sep 17 00:00:00 2001 From: Ben Turner Date: Wed, 22 Aug 2012 19:13:54 -0700 Subject: [PATCH] Bug 782649 - 'Remove old IPC::InputStream'. r=cjones+khuey. --- ipc/glue/IPCSerializableParams.ipdlh | 28 +++++ ipc/glue/InputStreamUtils.cpp | 78 +++++++++++- ipc/glue/InputStreamUtils.h | 11 ++ ipc/ipdl/ipdl/lower.py | 36 +++--- netwerk/base/src/Makefile.in | 5 +- netwerk/base/src/nsBufferedStreams.cpp | 80 ++++++++---- netwerk/base/src/nsBufferedStreams.h | 6 +- netwerk/base/src/nsMIMEInputStream.cpp | 116 +++++++++++------- netwerk/ipc/NeckoMessageUtils.h | 114 +---------------- netwerk/protocol/ftp/FTPChannelChild.cpp | 10 +- netwerk/protocol/ftp/FTPChannelParent.cpp | 7 +- netwerk/protocol/ftp/FTPChannelParent.h | 2 +- netwerk/protocol/ftp/PFTPChannel.ipdl | 4 +- netwerk/protocol/http/HttpChannelChild.cpp | 13 +- netwerk/protocol/http/HttpChannelParent.cpp | 7 +- netwerk/protocol/http/HttpChannelParent.h | 2 +- netwerk/protocol/http/PHttpChannel.ipdl | 5 +- netwerk/protocol/websocket/PWebSocket.ipdl | 4 +- .../websocket/WebSocketChannelChild.cpp | 8 +- .../websocket/WebSocketChannelParent.cpp | 11 +- .../websocket/WebSocketChannelParent.h | 2 +- xpcom/io/nsMultiplexInputStream.cpp | 54 +------- 22 files changed, 322 insertions(+), 281 deletions(-) diff --git a/ipc/glue/IPCSerializableParams.ipdlh b/ipc/glue/IPCSerializableParams.ipdlh index 21acd68508d..ef31b6ddfb0 100644 --- a/ipc/glue/IPCSerializableParams.ipdlh +++ b/ipc/glue/IPCSerializableParams.ipdlh @@ -2,6 +2,10 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +include "IPC/IPCMessageUtils.h"; + +using mozilla::void_t; + namespace mozilla { namespace ipc { @@ -37,8 +41,32 @@ union InputStreamParams StringInputStreamParams; FileInputStreamParams; PartialFileInputStreamParams; + BufferedInputStreamParams; + MIMEInputStreamParams; MultiplexInputStreamParams; }; +union OptionalInputStreamParams +{ + void_t; + InputStreamParams; +}; + +struct BufferedInputStreamParams +{ + OptionalInputStreamParams optionalStream; + uint32_t bufferSize; +}; + +struct MIMEInputStreamParams +{ + OptionalInputStreamParams optionalStream; + nsCString headers; + nsCString contentLength; + bool startedReading; + bool addContentLength; +}; + + } // namespace ipc } // namespace mozilla diff --git a/ipc/glue/InputStreamUtils.cpp b/ipc/glue/InputStreamUtils.cpp index 533326210bb..52fa598d3f0 100644 --- a/ipc/glue/InputStreamUtils.cpp +++ b/ipc/glue/InputStreamUtils.cpp @@ -10,6 +10,7 @@ #include "nsComponentManagerUtils.h" #include "nsDebug.h" #include "nsID.h" +#include "nsMIMEInputStream.h" #include "nsMultiplexInputStream.h" #include "nsNetCID.h" #include "nsStringStream.h" @@ -22,6 +23,8 @@ namespace { NS_DEFINE_CID(kStringInputStreamCID, NS_STRINGINPUTSTREAM_CID); NS_DEFINE_CID(kFileInputStreamCID, NS_LOCALFILEINPUTSTREAM_CID); NS_DEFINE_CID(kPartialFileInputStreamCID, NS_PARTIALLOCALFILEINPUTSTREAM_CID); +NS_DEFINE_CID(kBufferedInputStreamCID, NS_BUFFEREDINPUTSTREAM_CID); +NS_DEFINE_CID(kMIMEInputStreamCID, NS_MIMEINPUTSTREAM_CID); NS_DEFINE_CID(kMultiplexInputStreamCID, NS_MULTIPLEXINPUTSTREAM_CID); } // anonymous namespace @@ -29,6 +32,42 @@ NS_DEFINE_CID(kMultiplexInputStreamCID, NS_MULTIPLEXINPUTSTREAM_CID); namespace mozilla { namespace ipc { +void +SerializeInputStream(nsIInputStream* aInputStream, + InputStreamParams& aParams) +{ + MOZ_ASSERT(NS_IsMainThread()); + MOZ_ASSERT(aInputStream); + + nsCOMPtr serializable = + do_QueryInterface(aInputStream); + if (!serializable) { + NS_WARNING("Input stream is not serializable!"); + return; + } + + serializable->Serialize(aParams); + + NS_WARN_IF_FALSE(aParams.type() != InputStreamParams::T__None, + "Serialize failed!"); +} + +void +SerializeInputStream(nsIInputStream* aInputStream, + OptionalInputStreamParams& aParams) +{ + MOZ_ASSERT(NS_IsMainThread()); + + if (aInputStream) { + InputStreamParams params; + SerializeInputStream(aInputStream, params); + aParams = params; + } + else { + aParams = mozilla::void_t(); + } +} + already_AddRefed DeserializeInputStream(const InputStreamParams& aParams) { @@ -37,10 +76,6 @@ DeserializeInputStream(const InputStreamParams& aParams) nsCOMPtr serializable; switch (aParams.type()) { - case InputStreamParams::T__None: - NS_WARNING("This union has no type!"); - return nullptr; - case InputStreamParams::TStringInputStreamParams: serializable = do_CreateInstance(kStringInputStreamCID); break; @@ -53,19 +88,27 @@ DeserializeInputStream(const InputStreamParams& aParams) serializable = do_CreateInstance(kPartialFileInputStreamCID); break; + case InputStreamParams::TBufferedInputStreamParams: + serializable = do_CreateInstance(kBufferedInputStreamCID); + break; + + case InputStreamParams::TMIMEInputStreamParams: + serializable = do_CreateInstance(kMIMEInputStreamCID); + break; + case InputStreamParams::TMultiplexInputStreamParams: serializable = do_CreateInstance(kMultiplexInputStreamCID); break; default: - NS_WARNING("Unknown params!"); + MOZ_ASSERT(false, "Unknown params!"); return nullptr; } MOZ_ASSERT(serializable); if (!serializable->Deserialize(aParams)) { - NS_WARNING("Deserialize failed!"); + MOZ_ASSERT(false, "Deserialize failed!"); return nullptr; } @@ -75,5 +118,28 @@ DeserializeInputStream(const InputStreamParams& aParams) return stream.forget(); } +already_AddRefed +DeserializeInputStream(const OptionalInputStreamParams& aParams) +{ + MOZ_ASSERT(NS_IsMainThread()); + + nsCOMPtr stream; + + switch (aParams.type()) { + case OptionalInputStreamParams::Tvoid_t: + // Leave stream null. + break; + + case OptionalInputStreamParams::TInputStreamParams: + stream = DeserializeInputStream(aParams.get_InputStreamParams()); + break; + + default: + MOZ_ASSERT(false, "Unknown params!"); + } + + return stream.forget(); +} + } // namespace ipc } // namespace mozilla diff --git a/ipc/glue/InputStreamUtils.h b/ipc/glue/InputStreamUtils.h index 362488cf589..76cb447d910 100644 --- a/ipc/glue/InputStreamUtils.h +++ b/ipc/glue/InputStreamUtils.h @@ -12,9 +12,20 @@ namespace mozilla { namespace ipc { +void +SerializeInputStream(nsIInputStream* aInputStream, + InputStreamParams& aParams); + +void +SerializeInputStream(nsIInputStream* aInputStream, + OptionalInputStreamParams& aParams); + already_AddRefed DeserializeInputStream(const InputStreamParams& aParams); +already_AddRefed +DeserializeInputStream(const OptionalInputStreamParams& aParams); + } // namespace ipc } // namespace mozilla diff --git a/ipc/ipdl/ipdl/lower.py b/ipc/ipdl/ipdl/lower.py index f8f9e2b1d67..54683d59f06 100644 --- a/ipc/ipdl/ipdl/lower.py +++ b/ipc/ipdl/ipdl/lower.py @@ -1294,10 +1294,11 @@ with some new IPDL/C++ nodes that are tuned for C++ codegen.""" self.protocolName = None def visitTranslationUnit(self, tu): - if not isinstance(tu, TranslationUnit) and tu not in self.visitedTus: + if tu not in self.visitedTus: self.visitedTus.add(tu) ipdl.ast.Visitor.visitTranslationUnit(self, tu) - TranslationUnit.upgrade(tu) + if not isinstance(tu, TranslationUnit): + TranslationUnit.upgrade(tu) self.typedefs[:] = sorted(list(self.typedefSet)) def visitInclude(self, inc): @@ -1317,20 +1318,23 @@ with some new IPDL/C++ nodes that are tuned for C++ codegen.""" using.decl.shortname)) def visitStructDecl(self, sd): - sd.decl.special = 0 - newfields = [ ] - for f in sd.fields: - ftype = f.decl.type - if _hasVisibleActor(ftype): - sd.decl.special = 1 - # if ftype has a visible actor, we need both - # |ActorParent| and |ActorChild| fields - newfields.append(_StructField(ftype, f.name, sd, side='parent')) - newfields.append(_StructField(ftype, f.name, sd, side='child')) - else: - newfields.append(_StructField(ftype, f.name, sd)) - sd.fields = newfields - StructDecl.upgrade(sd) + if not isinstance(sd, StructDecl): + sd.decl.special = 0 + newfields = [ ] + for f in sd.fields: + ftype = f.decl.type + if _hasVisibleActor(ftype): + sd.decl.special = 1 + # if ftype has a visible actor, we need both + # |ActorParent| and |ActorChild| fields + newfields.append(_StructField(ftype, f.name, sd, + side='parent')) + newfields.append(_StructField(ftype, f.name, sd, + side='child')) + else: + newfields.append(_StructField(ftype, f.name, sd)) + sd.fields = newfields + StructDecl.upgrade(sd) if sd.decl.fullname is not None: self.typedefSet.add(Typedef(Type(sd.fqClassName()), sd.name)) diff --git a/netwerk/base/src/Makefile.in b/netwerk/base/src/Makefile.in index 0bd10657205..d9dfbdbdc0c 100644 --- a/netwerk/base/src/Makefile.in +++ b/netwerk/base/src/Makefile.in @@ -15,7 +15,10 @@ MODULE = necko LIBRARY_NAME = neckobase_s LIBXUL_LIBRARY = 1 -EXPORTS = nsURLHelper.h +EXPORTS = \ + nsMIMEInputStream.h \ + nsURLHelper.h \ + $(NULL) CPPSRCS = \ nsTransportUtils.cpp \ diff --git a/netwerk/base/src/nsBufferedStreams.cpp b/netwerk/base/src/nsBufferedStreams.cpp index f882483d1eb..f54384d1901 100644 --- a/netwerk/base/src/nsBufferedStreams.cpp +++ b/netwerk/base/src/nsBufferedStreams.cpp @@ -4,7 +4,6 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "IPC/IPCMessageUtils.h" -#include "mozilla/net/NeckoMessageUtils.h" #include "nsAlgorithm.h" #include "nsBufferedStreams.h" @@ -12,6 +11,8 @@ #include "nsCRT.h" #include "nsNetCID.h" #include "nsIClassInfoImpl.h" +#include "mozilla/ipc/InputStreamUtils.h" +#include "mozilla/ipc/IPCSerializableParams.h" #ifdef DEBUG_brendan # define METERING @@ -38,6 +39,8 @@ static struct { # define METER(x) /* nothing */ #endif +using namespace mozilla::ipc; + //////////////////////////////////////////////////////////////////////////////// // nsBufferedStream @@ -252,16 +255,15 @@ NS_INTERFACE_MAP_BEGIN(nsBufferedInputStream) NS_INTERFACE_MAP_ENTRY(nsIInputStream) NS_INTERFACE_MAP_ENTRY(nsIBufferedInputStream) NS_INTERFACE_MAP_ENTRY(nsIStreamBufferAccess) - NS_INTERFACE_MAP_ENTRY(nsIIPCSerializableObsolete) + NS_INTERFACE_MAP_ENTRY(nsIIPCSerializableInputStream) NS_IMPL_QUERY_CLASSINFO(nsBufferedInputStream) NS_INTERFACE_MAP_END_INHERITING(nsBufferedStream) -NS_IMPL_CI_INTERFACE_GETTER5(nsBufferedInputStream, +NS_IMPL_CI_INTERFACE_GETTER4(nsBufferedInputStream, nsIInputStream, nsIBufferedInputStream, nsISeekableStream, - nsIStreamBufferAccess, - nsIIPCSerializableObsolete) + nsIStreamBufferAccess) nsresult nsBufferedInputStream::Create(nsISupports *aOuter, REFNSIID aIID, void **aResult) @@ -484,34 +486,62 @@ nsBufferedInputStream::GetUnbufferedStream(nsISupports* *aStream) return NS_OK; } -bool -nsBufferedInputStream::Read(const IPC::Message *aMsg, void **aIter) +void +nsBufferedInputStream::Serialize(InputStreamParams& aParams) { - using IPC::ReadParam; + BufferedInputStreamParams params; - uint32_t bufferSize; - IPC::InputStream inputStream; - if (!ReadParam(aMsg, aIter, &bufferSize) || - !ReadParam(aMsg, aIter, &inputStream)) - return false; + if (mStream) { + nsCOMPtr stream = + do_QueryInterface(mStream); + NS_ASSERTION(stream, "Wrapped stream is not serializable!"); - nsCOMPtr stream(inputStream); - nsresult rv = Init(stream, bufferSize); - if (NS_FAILED(rv)) - return false; + InputStreamParams wrappedParams; + stream->Serialize(wrappedParams); - return true; + NS_ASSERTION(wrappedParams.type() != InputStreamParams::T__None, + "Wrapped stream failed to serialize!"); + + params.optionalStream() = wrappedParams; + } + else { + params.optionalStream() = mozilla::void_t(); + } + + params.bufferSize() = mBufferSize; + + aParams = params; } -void -nsBufferedInputStream::Write(IPC::Message *aMsg) +bool +nsBufferedInputStream::Deserialize(const InputStreamParams& aParams) { - using IPC::WriteParam; + if (aParams.type() != InputStreamParams::TBufferedInputStreamParams) { + NS_ERROR("Received unknown parameters from the other process!"); + return false; + } - WriteParam(aMsg, mBufferSize); + const BufferedInputStreamParams& params = + aParams.get_BufferedInputStreamParams(); + const OptionalInputStreamParams& wrappedParams = params.optionalStream(); - IPC::InputStream inputStream(Source()); - WriteParam(aMsg, inputStream); + nsCOMPtr stream; + if (wrappedParams.type() == OptionalInputStreamParams::TInputStreamParams) { + stream = DeserializeInputStream(wrappedParams.get_InputStreamParams()); + if (!stream) { + NS_WARNING("Failed to deserialize wrapped stream!"); + return false; + } + } + else { + NS_ASSERTION(wrappedParams.type() == OptionalInputStreamParams::Tvoid_t, + "Unknown type for OptionalInputStreamParams!"); + } + + nsresult rv = Init(stream, params.bufferSize()); + NS_ENSURE_SUCCESS(rv, false); + + return true; } //////////////////////////////////////////////////////////////////////////////// @@ -787,4 +817,4 @@ nsBufferedOutputStream::GetUnbufferedStream(nsISupports* *aStream) return NS_OK; } -//////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// \ No newline at end of file diff --git a/netwerk/base/src/nsBufferedStreams.h b/netwerk/base/src/nsBufferedStreams.h index 687295a819d..cc52f9e3bd0 100644 --- a/netwerk/base/src/nsBufferedStreams.h +++ b/netwerk/base/src/nsBufferedStreams.h @@ -13,7 +13,7 @@ #include "nsISeekableStream.h" #include "nsIStreamBufferAccess.h" #include "nsCOMPtr.h" -#include "nsIIPCSerializableObsolete.h" +#include "nsIIPCSerializableInputStream.h" //////////////////////////////////////////////////////////////////////////////// @@ -60,14 +60,14 @@ protected: class nsBufferedInputStream : public nsBufferedStream, public nsIBufferedInputStream, public nsIStreamBufferAccess, - public nsIIPCSerializableObsolete + public nsIIPCSerializableInputStream { public: NS_DECL_ISUPPORTS_INHERITED NS_DECL_NSIINPUTSTREAM NS_DECL_NSIBUFFEREDINPUTSTREAM NS_DECL_NSISTREAMBUFFERACCESS - NS_DECL_NSIIPCSERIALIZABLEOBSOLETE + NS_DECL_NSIIPCSERIALIZABLEINPUTSTREAM nsBufferedInputStream() : nsBufferedStream() {} virtual ~nsBufferedInputStream() {} diff --git a/netwerk/base/src/nsMIMEInputStream.cpp b/netwerk/base/src/nsMIMEInputStream.cpp index f7c6f93dafc..d58da2d50ae 100644 --- a/netwerk/base/src/nsMIMEInputStream.cpp +++ b/netwerk/base/src/nsMIMEInputStream.cpp @@ -9,7 +9,6 @@ */ #include "IPC/IPCMessageUtils.h" -#include "mozilla/net/NeckoMessageUtils.h" #include "nsCOMPtr.h" #include "nsComponentManagerUtils.h" @@ -19,12 +18,16 @@ #include "nsIStringStream.h" #include "nsString.h" #include "nsMIMEInputStream.h" -#include "nsIIPCSerializableObsolete.h" #include "nsIClassInfoImpl.h" +#include "nsIIPCSerializableInputStream.h" +#include "mozilla/ipc/InputStreamUtils.h" +#include "mozilla/ipc/IPCSerializableParams.h" + +using namespace mozilla::ipc; class nsMIMEInputStream : public nsIMIMEInputStream, public nsISeekableStream, - public nsIIPCSerializableObsolete + public nsIIPCSerializableInputStream { public: nsMIMEInputStream(); @@ -34,8 +37,8 @@ public: NS_DECL_NSIINPUTSTREAM NS_DECL_NSIMIMEINPUTSTREAM NS_DECL_NSISEEKABLESTREAM - NS_DECL_NSIIPCSERIALIZABLEOBSOLETE - + NS_DECL_NSIIPCSERIALIZABLEINPUTSTREAM + NS_METHOD Init(); private: @@ -73,12 +76,11 @@ NS_IMPL_QUERY_INTERFACE4_CI(nsMIMEInputStream, nsIMIMEInputStream, nsIInputStream, nsISeekableStream, - nsIIPCSerializableObsolete) -NS_IMPL_CI_INTERFACE_GETTER4(nsMIMEInputStream, + nsIIPCSerializableInputStream) +NS_IMPL_CI_INTERFACE_GETTER3(nsMIMEInputStream, nsIMIMEInputStream, nsIInputStream, - nsISeekableStream, - nsIIPCSerializableObsolete) + nsISeekableStream) nsMIMEInputStream::nsMIMEInputStream() : mAddContentLength(false), mStartedReading(false) @@ -293,51 +295,79 @@ nsMIMEInputStreamConstructor(nsISupports *outer, REFNSIID iid, void **result) return rv; } -bool -nsMIMEInputStream::Read(const IPC::Message *aMsg, void **aIter) +void +nsMIMEInputStream::Serialize(InputStreamParams& aParams) { - using IPC::ReadParam; + MIMEInputStreamParams params; - if (!ReadParam(aMsg, aIter, &mHeaders) || - !ReadParam(aMsg, aIter, &mContentLength) || - !ReadParam(aMsg, aIter, &mStartedReading)) + if (mData) { + nsCOMPtr stream = + do_QueryInterface(mData); + NS_ASSERTION(stream, "Wrapped stream is not serializable!"); + + InputStreamParams wrappedParams; + stream->Serialize(wrappedParams); + + NS_ASSERTION(wrappedParams.type() != InputStreamParams::T__None, + "Wrapped stream failed to serialize!"); + + params.optionalStream() = wrappedParams; + } + else { + params.optionalStream() = mozilla::void_t(); + } + + params.headers() = mHeaders; + params.contentLength() = mContentLength; + params.startedReading() = mStartedReading; + params.addContentLength() = mAddContentLength; + + aParams = params; +} + +bool +nsMIMEInputStream::Deserialize(const InputStreamParams& aParams) +{ + if (aParams.type() != InputStreamParams::TMIMEInputStreamParams) { + NS_ERROR("Received unknown parameters from the other process!"); return false; + } + + const MIMEInputStreamParams& params = + aParams.get_MIMEInputStreamParams(); + const OptionalInputStreamParams& wrappedParams = params.optionalStream(); + + mHeaders = params.headers(); + mContentLength = params.contentLength(); + mStartedReading = params.startedReading(); // nsMIMEInputStream::Init() already appended mHeaderStream & mCLStream mHeaderStream->ShareData(mHeaders.get(), - mStartedReading? mHeaders.Length() : 0); + mStartedReading ? mHeaders.Length() : 0); mCLStream->ShareData(mContentLength.get(), - mStartedReading? mContentLength.Length() : 0); + mStartedReading ? mContentLength.Length() : 0); - IPC::InputStream inputStream; - if (!ReadParam(aMsg, aIter, &inputStream)) - return false; - - nsCOMPtr stream(inputStream); - mData = stream; - if (stream) { - nsresult rv = mStream->AppendStream(mData); - if (NS_FAILED(rv)) + nsCOMPtr stream; + if (wrappedParams.type() == OptionalInputStreamParams::TInputStreamParams) { + stream = DeserializeInputStream(wrappedParams.get_InputStreamParams()); + if (!stream) { + NS_WARNING("Failed to deserialize wrapped stream!"); return false; + } + + mData = stream; + + if (NS_FAILED(mStream->AppendStream(mData))) { + NS_WARNING("Failed to append stream!"); + return false; + } + } + else { + NS_ASSERTION(wrappedParams.type() == OptionalInputStreamParams::Tvoid_t, + "Unknown type for OptionalInputStreamParams!"); } - if (!ReadParam(aMsg, aIter, &mAddContentLength)) - return false; + mAddContentLength = params.addContentLength(); return true; } - -void -nsMIMEInputStream::Write(IPC::Message *aMsg) -{ - using IPC::WriteParam; - - WriteParam(aMsg, mHeaders); - WriteParam(aMsg, mContentLength); - WriteParam(aMsg, mStartedReading); - - IPC::InputStream inputStream(mData); - WriteParam(aMsg, inputStream); - - WriteParam(aMsg, mAddContentLength); -} diff --git a/netwerk/ipc/NeckoMessageUtils.h b/netwerk/ipc/NeckoMessageUtils.h index ae713ebac60..9d044efa446 100644 --- a/netwerk/ipc/NeckoMessageUtils.h +++ b/netwerk/ipc/NeckoMessageUtils.h @@ -143,118 +143,6 @@ struct ParamTraits } }; -class InputStream { - public: - InputStream() : mStream(nullptr) {} - InputStream(nsIInputStream* aStream) : mStream(aStream) {} - operator nsIInputStream*() const { return mStream.get(); } - - friend struct ParamTraits; - - private: - // Unimplemented - InputStream& operator=(InputStream&); - - nsCOMPtr mStream; -}; - -template<> -struct ParamTraits -{ - typedef InputStream paramType; - - static void Write(Message* aMsg, const paramType& aParam) - { - bool isNull = !aParam.mStream; - aMsg->WriteBool(isNull); - - if (isNull) - return; - - nsCOMPtr serializable = - do_QueryInterface(aParam.mStream); - bool isSerializable = !!serializable; - WriteParam(aMsg, isSerializable); - - if (!serializable) { - NS_WARNING("nsIInputStream implementation doesn't support " - "nsIIPCSerializableObsolete; falling back to copying data"); - - nsCString streamString; - uint64_t bytes; - - nsresult rv = aParam.mStream->Available(&bytes); - if (NS_SUCCEEDED(rv) && bytes > 0) { - // Also, on 64-bit system, for an interoperability for 32-bit process - // and 64-bit process, we shouldn't handle over 4GB message. - NS_ABORT_IF_FALSE(bytes < PR_UINT32_MAX, "nsIInputStream has over 4GB data"); - mozilla::DebugOnly rv = - NS_ReadInputStreamToString(aParam.mStream, streamString, (uint32_t)bytes); - NS_ABORT_IF_FALSE(NS_SUCCEEDED(rv), "Can't read input stream into a string!"); - } - - WriteParam(aMsg, streamString); - return; - } - - nsCOMPtr classInfo = do_QueryInterface(aParam.mStream); - NS_ASSERTION(classInfo, "Must QI to nsIClassInfo for this to work!"); - - char cidStr[NSID_LENGTH]; - nsCID cid; - mozilla::DebugOnly 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 = nullptr; - return true; - } - - bool isSerializable; - if (!ReadParam(aMsg, aIter, &isSerializable)) - return false; - - nsCOMPtr 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 serializable = - do_QueryInterface(stream); - if (!serializable || !serializable->Read(aMsg, aIter)) - return false; - } - - stream.swap(aResult->mStream); - return true; - } -}; - // nsIPermissionManager utilities struct Permission @@ -365,4 +253,4 @@ struct ParamTraits } -#endif // mozilla_net_NeckoMessageUtils_h +#endif // mozilla_net_NeckoMessageUtils_h \ No newline at end of file diff --git a/netwerk/protocol/ftp/FTPChannelChild.cpp b/netwerk/protocol/ftp/FTPChannelChild.cpp index 3e83efb3de9..73f940931d6 100644 --- a/netwerk/protocol/ftp/FTPChannelChild.cpp +++ b/netwerk/protocol/ftp/FTPChannelChild.cpp @@ -16,6 +16,9 @@ #include "nsILoadContext.h" #include "nsCDefaultURIFixup.h" #include "base/compiler_specific.h" +#include "mozilla/ipc/InputStreamUtils.h" + +using namespace mozilla::ipc; #undef LOG #define LOG(args) PR_LOG(gFTPLog, PR_LOG_DEBUG, args) @@ -160,8 +163,11 @@ FTPChannelChild::AsyncOpen(::nsIStreamListener* listener, nsISupports* aContext) if (mLoadGroup) mLoadGroup->AddRequest(this, nullptr); - SendAsyncOpen(nsBaseChannel::URI(), mStartPos, mEntityID, - IPC::InputStream(mUploadStream), IPC::SerializedLoadContext(this)); + OptionalInputStreamParams uploadStream; + SerializeInputStream(mUploadStream, uploadStream); + + SendAsyncOpen(nsBaseChannel::URI(), mStartPos, mEntityID, uploadStream, + IPC::SerializedLoadContext(this)); // The socket transport layer in the chrome process now has a logical ref to // us until OnStopRequest is called. diff --git a/netwerk/protocol/ftp/FTPChannelParent.cpp b/netwerk/protocol/ftp/FTPChannelParent.cpp index 857642d7436..5329f7123fc 100644 --- a/netwerk/protocol/ftp/FTPChannelParent.cpp +++ b/netwerk/protocol/ftp/FTPChannelParent.cpp @@ -12,6 +12,9 @@ #include "nsIRedirectChannelRegistrar.h" #include "nsFtpProtocolHandler.h" #include "mozilla/LoadContext.h" +#include "mozilla/ipc/InputStreamUtils.h" + +using namespace mozilla::ipc; #undef LOG #define LOG(args) PR_LOG(gFTPLog, PR_LOG_DEBUG, args) @@ -58,7 +61,7 @@ bool FTPChannelParent::RecvAsyncOpen(const IPC::URI& aURI, const uint64_t& aStartPos, const nsCString& aEntityID, - const IPC::InputStream& aUploadStream, + const OptionalInputStreamParams& aUploadStream, const IPC::SerializedLoadContext& loadContext) { nsCOMPtr uri(aURI); @@ -82,7 +85,7 @@ FTPChannelParent::RecvAsyncOpen(const IPC::URI& aURI, mChannel = static_cast(chan.get()); - nsCOMPtr upload(aUploadStream); + nsCOMPtr upload = DeserializeInputStream(aUploadStream); if (upload) { // contentType and contentLength are ignored rv = mChannel->SetUploadStream(upload, EmptyCString(), 0); diff --git a/netwerk/protocol/ftp/FTPChannelParent.h b/netwerk/protocol/ftp/FTPChannelParent.h index 2be2df2ceec..6ffd9910ad1 100644 --- a/netwerk/protocol/ftp/FTPChannelParent.h +++ b/netwerk/protocol/ftp/FTPChannelParent.h @@ -37,7 +37,7 @@ protected: virtual bool RecvAsyncOpen(const IPC::URI& uri, const uint64_t& startPos, const nsCString& entityID, - const IPC::InputStream& uploadStream, + const OptionalInputStreamParams& uploadStream, const IPC::SerializedLoadContext& loadContext) MOZ_OVERRIDE; virtual bool RecvConnectChannel(const uint32_t& channelId) MOZ_OVERRIDE; virtual bool RecvCancel(const nsresult& status) MOZ_OVERRIDE; diff --git a/netwerk/protocol/ftp/PFTPChannel.ipdl b/netwerk/protocol/ftp/PFTPChannel.ipdl index 152a169e0cd..47fc8ebd404 100644 --- a/netwerk/protocol/ftp/PFTPChannel.ipdl +++ b/netwerk/protocol/ftp/PFTPChannel.ipdl @@ -8,9 +8,9 @@ include protocol PNecko; include "mozilla/net/NeckoMessageUtils.h"; +include IPCSerializableParams; using IPC::URI; -using IPC::InputStream; using IPC::SerializedLoadContext; using PRTime; @@ -27,7 +27,7 @@ parent: AsyncOpen(URI uri, uint64_t startPos, nsCString entityID, - InputStream uploadStream, + OptionalInputStreamParams uploadStream, SerializedLoadContext loadContext); ConnectChannel(uint32_t channelId); diff --git a/netwerk/protocol/http/HttpChannelChild.cpp b/netwerk/protocol/http/HttpChannelChild.cpp index 30f72e22c4b..924177fbd5d 100644 --- a/netwerk/protocol/http/HttpChannelChild.cpp +++ b/netwerk/protocol/http/HttpChannelChild.cpp @@ -16,6 +16,9 @@ #include "nsNetUtil.h" #include "nsSerializationHelper.h" #include "base/compiler_specific.h" +#include "mozilla/ipc/InputStreamUtils.h" + +using namespace mozilla::ipc; namespace mozilla { namespace net { @@ -1034,12 +1037,14 @@ HttpChannelChild::AsyncOpen(nsIStreamListener *listener, nsISupports *aContext) gNeckoChild->SendPHttpChannelConstructor(this, tabChild); + OptionalInputStreamParams uploadStream; + SerializeInputStream(mUploadStream, uploadStream); + SendAsyncOpen(IPC::URI(mURI), IPC::URI(mOriginalURI), IPC::URI(mDocumentURI), IPC::URI(mReferrer), mLoadFlags, - mClientSetRequestHeaders, mRequestHead.Method(), - IPC::InputStream(mUploadStream), mUploadStreamHasHeaders, - mPriority, mRedirectionLimit, mAllowPipelining, - mForceAllowThirdPartyCookie, mSendResumeAt, + mClientSetRequestHeaders, mRequestHead.Method(), uploadStream, + mUploadStreamHasHeaders, mPriority, mRedirectionLimit, + mAllowPipelining, mForceAllowThirdPartyCookie, mSendResumeAt, mStartPos, mEntityID, mChooseApplicationCache, appCacheClientId, mAllowSpdy, IPC::SerializedLoadContext(this)); diff --git a/netwerk/protocol/http/HttpChannelParent.cpp b/netwerk/protocol/http/HttpChannelParent.cpp index 24bc272e251..152dca3d2ba 100644 --- a/netwerk/protocol/http/HttpChannelParent.cpp +++ b/netwerk/protocol/http/HttpChannelParent.cpp @@ -24,6 +24,9 @@ #include "nsIRedirectChannelRegistrar.h" #include "mozilla/LoadContext.h" #include "prinit.h" +#include "mozilla/ipc/InputStreamUtils.h" + +using namespace mozilla::ipc; namespace mozilla { namespace net { @@ -108,7 +111,7 @@ HttpChannelParent::RecvAsyncOpen(const IPC::URI& aURI, const uint32_t& loadFlags, const RequestHeaderTuples& requestHeaders, const nsHttpAtom& requestMethod, - const IPC::InputStream& uploadStream, + const OptionalInputStreamParams& uploadStream, const bool& uploadStreamHasHeaders, const uint16_t& priority, const uint8_t& redirectionLimit, @@ -172,7 +175,7 @@ HttpChannelParent::RecvAsyncOpen(const IPC::URI& aURI, httpChan->SetRequestMethod(nsDependentCString(requestMethod.get())); - nsCOMPtr stream(uploadStream); + nsCOMPtr stream = DeserializeInputStream(uploadStream); if (stream) { httpChan->InternalSetUploadStream(stream); httpChan->SetUploadStreamHasHeaders(uploadStreamHasHeaders); diff --git a/netwerk/protocol/http/HttpChannelParent.h b/netwerk/protocol/http/HttpChannelParent.h index 51cf57efcbf..94d6ec84c96 100644 --- a/netwerk/protocol/http/HttpChannelParent.h +++ b/netwerk/protocol/http/HttpChannelParent.h @@ -52,7 +52,7 @@ protected: const uint32_t& loadFlags, const RequestHeaderTuples& requestHeaders, const nsHttpAtom& requestMethod, - const IPC::InputStream& uploadStream, + const OptionalInputStreamParams& uploadStream, const bool& uploadStreamHasHeaders, const uint16_t& priority, const uint8_t& redirectionLimit, diff --git a/netwerk/protocol/http/PHttpChannel.ipdl b/netwerk/protocol/http/PHttpChannel.ipdl index 089e39eb28f..404477f64d1 100644 --- a/netwerk/protocol/http/PHttpChannel.ipdl +++ b/netwerk/protocol/http/PHttpChannel.ipdl @@ -11,12 +11,13 @@ include "mozilla/net/PHttpChannelParams.h"; include "mozilla/net/NeckoMessageUtils.h"; include "prio.h"; +include IPCSerializableParams; + using RequestHeaderTuples; using nsHttpHeaderArray; using nsHttpResponseHead; using nsHttpAtom; using IPC::URI; -using IPC::InputStream; using IPC::SerializedLoadContext; using PRNetAddr; @@ -39,7 +40,7 @@ parent: uint32_t loadFlags, RequestHeaderTuples requestHeaders, nsHttpAtom requestMethod, - InputStream uploadStream, + OptionalInputStreamParams uploadStream, bool uploadStreamHasHeaders, uint16_t priority, uint8_t redirectionLimit, diff --git a/netwerk/protocol/websocket/PWebSocket.ipdl b/netwerk/protocol/websocket/PWebSocket.ipdl index f31e625620e..7b37290a829 100644 --- a/netwerk/protocol/websocket/PWebSocket.ipdl +++ b/netwerk/protocol/websocket/PWebSocket.ipdl @@ -9,9 +9,9 @@ include protocol PNecko; include protocol PBrowser; include "mozilla/net/NeckoMessageUtils.h"; +include IPCSerializableParams; using IPC::URI; -using IPC::InputStream; using IPC::SerializedLoadContext; namespace mozilla { @@ -31,7 +31,7 @@ parent: Close(uint16_t code, nsCString reason); SendMsg(nsCString aMsg); SendBinaryMsg(nsCString aMsg); - SendBinaryStream(InputStream aStream, uint32_t aLength); + SendBinaryStream(InputStreamParams aStream, uint32_t aLength); DeleteSelf(); diff --git a/netwerk/protocol/websocket/WebSocketChannelChild.cpp b/netwerk/protocol/websocket/WebSocketChannelChild.cpp index 75704744592..96bd0824b81 100644 --- a/netwerk/protocol/websocket/WebSocketChannelChild.cpp +++ b/netwerk/protocol/websocket/WebSocketChannelChild.cpp @@ -11,6 +11,9 @@ #include "nsITabChild.h" #include "nsILoadContext.h" #include "nsNetUtil.h" +#include "mozilla/ipc/InputStreamUtils.h" + +using namespace mozilla::ipc; namespace mozilla { namespace net { @@ -381,7 +384,10 @@ WebSocketChannelChild::SendBinaryStream(nsIInputStream *aStream, { LOG(("WebSocketChannelChild::SendBinaryStream() %p\n", this)); - if (!mIPCOpen || !SendSendBinaryStream(IPC::InputStream(aStream), aLength)) + OptionalInputStreamParams stream; + SerializeInputStream(aStream, stream); + + if (!mIPCOpen || !SendSendBinaryStream(stream, aLength)) return NS_ERROR_UNEXPECTED; return NS_OK; } diff --git a/netwerk/protocol/websocket/WebSocketChannelParent.cpp b/netwerk/protocol/websocket/WebSocketChannelParent.cpp index f4a0ebb0f9f..6769f998209 100644 --- a/netwerk/protocol/websocket/WebSocketChannelParent.cpp +++ b/netwerk/protocol/websocket/WebSocketChannelParent.cpp @@ -8,6 +8,9 @@ #include "WebSocketChannelParent.h" #include "nsIAuthPromptProvider.h" #include "mozilla/LoadContext.h" +#include "mozilla/ipc/InputStreamUtils.h" + +using namespace mozilla::ipc; namespace mozilla { namespace net { @@ -114,12 +117,16 @@ WebSocketChannelParent::RecvSendBinaryMsg(const nsCString& aMsg) } bool -WebSocketChannelParent::RecvSendBinaryStream(const InputStream& aStream, +WebSocketChannelParent::RecvSendBinaryStream(const InputStreamParams& aStream, const uint32_t& aLength) { LOG(("WebSocketChannelParent::RecvSendBinaryStream() %p\n", this)); if (mChannel) { - nsresult rv = mChannel->SendBinaryStream(aStream, aLength); + nsCOMPtr stream = DeserializeInputStream(aStream); + if (!stream) { + return false; + } + nsresult rv = mChannel->SendBinaryStream(stream, aLength); NS_ENSURE_SUCCESS(rv, true); } return true; diff --git a/netwerk/protocol/websocket/WebSocketChannelParent.h b/netwerk/protocol/websocket/WebSocketChannelParent.h index a83da67fd31..6555d3b3723 100644 --- a/netwerk/protocol/websocket/WebSocketChannelParent.h +++ b/netwerk/protocol/websocket/WebSocketChannelParent.h @@ -39,7 +39,7 @@ class WebSocketChannelParent : public PWebSocketParent, bool RecvClose(const uint16_t & code, const nsCString & reason); bool RecvSendMsg(const nsCString& aMsg); bool RecvSendBinaryMsg(const nsCString& aMsg); - bool RecvSendBinaryStream(const InputStream& aStream, + bool RecvSendBinaryStream(const InputStreamParams& aStream, const uint32_t& aLength); bool RecvDeleteSelf(); diff --git a/xpcom/io/nsMultiplexInputStream.cpp b/xpcom/io/nsMultiplexInputStream.cpp index 8e62d2f9696..107b16130c3 100644 --- a/xpcom/io/nsMultiplexInputStream.cpp +++ b/xpcom/io/nsMultiplexInputStream.cpp @@ -9,7 +9,6 @@ */ #include "IPC/IPCMessageUtils.h" -#include "mozilla/net/NeckoMessageUtils.h" #include "mozilla/Attributes.h" #include "nsMultiplexInputStream.h" @@ -27,7 +26,6 @@ using namespace mozilla::ipc; class nsMultiplexInputStream MOZ_FINAL : public nsIMultiplexInputStream, public nsISeekableStream, - public nsIIPCSerializableObsolete, public nsIIPCSerializableInputStream { public: @@ -37,7 +35,6 @@ public: NS_DECL_NSIINPUTSTREAM NS_DECL_NSIMULTIPLEXINPUTSTREAM NS_DECL_NSISEEKABLESTREAM - NS_DECL_NSIIPCSERIALIZABLEOBSOLETE NS_DECL_NSIIPCSERIALIZABLEINPUTSTREAM private: @@ -67,11 +64,10 @@ NS_IMPL_THREADSAFE_RELEASE(nsMultiplexInputStream) NS_IMPL_CLASSINFO(nsMultiplexInputStream, NULL, nsIClassInfo::THREADSAFE, NS_MULTIPLEXINPUTSTREAM_CID) -NS_IMPL_QUERY_INTERFACE5_CI(nsMultiplexInputStream, +NS_IMPL_QUERY_INTERFACE4_CI(nsMultiplexInputStream, nsIMultiplexInputStream, nsIInputStream, nsISeekableStream, - nsIIPCSerializableObsolete, nsIIPCSerializableInputStream) NS_IMPL_CI_INTERFACE_GETTER3(nsMultiplexInputStream, nsIMultiplexInputStream, @@ -596,52 +592,6 @@ nsMultiplexInputStreamConstructor(nsISupports *outer, return rv; } -bool -nsMultiplexInputStream::Read(const IPC::Message *aMsg, void **aIter) -{ - using IPC::ReadParam; - - uint32_t count; - if (!ReadParam(aMsg, aIter, &count)) - return false; - - for (uint32_t i = 0; i < count; i++) { - IPC::InputStream inputStream; - if (!ReadParam(aMsg, aIter, &inputStream)) - return false; - - nsCOMPtr stream(inputStream); - nsresult rv = AppendStream(stream); - if (NS_FAILED(rv)) - return false; - } - - if (!ReadParam(aMsg, aIter, &mCurrentStream) || - !ReadParam(aMsg, aIter, &mStartedReadingCurrent) || - !ReadParam(aMsg, aIter, &mStatus)) - return false; - - return true; -} - -void -nsMultiplexInputStream::Write(IPC::Message *aMsg) -{ - using IPC::WriteParam; - - uint32_t count = mStreams.Length(); - WriteParam(aMsg, count); - - for (uint32_t i = 0; i < count; i++) { - IPC::InputStream inputStream(mStreams[i]); - WriteParam(aMsg, inputStream); - } - - WriteParam(aMsg, mCurrentStream); - WriteParam(aMsg, mStartedReadingCurrent); - WriteParam(aMsg, mStatus); -} - void nsMultiplexInputStream::Serialize(InputStreamParams& aParams) { @@ -712,4 +662,4 @@ nsMultiplexInputStream::Deserialize(const InputStreamParams& aParams) mStartedReadingCurrent = params.startedReadingCurrent(); return true; -} +} \ No newline at end of file