From 1aa11ffed66e212fae26c9a01b09206f2e923777 Mon Sep 17 00:00:00 2001 From: Nika Layzell Date: Fri, 13 May 2022 14:16:13 +0000 Subject: [PATCH] Bug 1754004 - Part 11: Simplify the IPCStream serialization API, r=asuth,necko-reviewers,kershaw As serializing IPCStream no longer requires a manager or FileDescriptor array, the arguments are no longer necessary, and can be removed. The AutoIPCStream helper can also be removed, as managed actors are no longer used for serialization, so a delayed start callback is not necessary. The delayed start parameter is also removed from nsIIPCSerializableInputStream instances, but is still present as `aAllowLazy` on the toplevel serialization methods. Differential Revision: https://phabricator.services.mozilla.com/D141048 --- dom/cache/AutoUtils.cpp | 54 +- dom/cache/AutoUtils.h | 3 - dom/cache/CacheStreamControlChild.cpp | 12 +- dom/cache/CacheStreamControlChild.h | 13 +- dom/cache/CacheStreamControlParent.cpp | 21 +- dom/cache/CacheStreamControlParent.h | 13 +- dom/cache/ReadStream.cpp | 36 +- dom/cache/ReadStream.h | 13 +- dom/cache/StreamControl.h | 14 +- dom/cache/TypeUtils.cpp | 32 +- dom/cache/TypeUtils.h | 22 +- dom/fetch/InternalResponse.cpp | 16 +- dom/fetch/InternalResponse.h | 6 +- dom/file/TemporaryFileBlobImpl.cpp | 16 +- dom/file/ipc/IPCBlobUtils.cpp | 8 +- dom/file/ipc/IPCBlobUtils.h | 5 +- dom/file/ipc/RemoteLazyInputStream.cpp | 19 +- dom/file/ipc/RemoteLazyInputStreamParent.cpp | 36 +- dom/ipc/ContentChild.h | 1 - dom/ipc/ContentParent.h | 30 +- dom/ipc/StructuredCloneData.cpp | 18 +- dom/ipc/StructuredCloneData.h | 8 - dom/network/UDPSocketChild.cpp | 10 +- dom/quota/DecryptingInputStream.cpp | 8 - dom/quota/DecryptingInputStream.h | 22 +- dom/quota/DecryptingInputStream_impl.h | 16 +- dom/serviceworkers/FetchEventOpProxyChild.cpp | 21 +- .../WebBrowserPersistDocumentChild.cpp | 8 +- ipc/glue/BackgroundChildImpl.h | 3 +- ipc/glue/BackgroundParentImpl.h | 3 +- ipc/glue/DataPipe.cpp | 20 +- ipc/glue/IPCStream.ipdlh | 5 +- ipc/glue/IPCStreamUtils.cpp | 478 +++--------------- ipc/glue/IPCStreamUtils.h | 209 +------- ipc/glue/InputStreamUtils.cpp | 94 +--- ipc/glue/InputStreamUtils.h | 45 +- ipc/glue/nsIIPCSerializableInputStream.h | 66 +-- netwerk/base/nsBufferedStreams.cpp | 34 +- netwerk/base/nsBufferedStreams.h | 6 - netwerk/base/nsFileStreams.cpp | 26 +- netwerk/base/nsFileStreams.h | 2 - netwerk/base/nsMIMEInputStream.cpp | 44 +- netwerk/ipc/SocketProcessChild.h | 4 +- netwerk/ipc/SocketProcessParent.h | 3 +- netwerk/protocol/gio/GIOChannelChild.cpp | 8 +- .../http/HttpBackgroundChannelParent.cpp | 6 +- netwerk/protocol/http/HttpChannelChild.cpp | 6 +- netwerk/protocol/http/HttpChannelParent.cpp | 10 +- .../protocol/http/HttpTransactionParent.cpp | 12 +- .../websocket/WebSocketChannelChild.cpp | 11 +- .../antitracking/ContentBlockingLog.cpp | 2 - xpcom/ds/nsTArray.h | 4 - xpcom/io/InputStreamLengthWrapper.cpp | 34 +- xpcom/io/InputStreamLengthWrapper.h | 6 - xpcom/io/NonBlockingAsyncInputStream.cpp | 32 +- xpcom/io/NonBlockingAsyncInputStream.h | 6 - xpcom/io/SlicedInputStream.cpp | 38 +- xpcom/io/SlicedInputStream.h | 6 - xpcom/io/nsMultiplexInputStream.cpp | 46 +- xpcom/io/nsStorageStream.cpp | 31 +- xpcom/io/nsStringStream.cpp | 31 +- .../gtest/TestNonBlockingAsyncInputStream.cpp | 11 +- 62 files changed, 366 insertions(+), 1457 deletions(-) diff --git a/dom/cache/AutoUtils.cpp b/dom/cache/AutoUtils.cpp index dd137c7cfe2f..52d3a39d430f 100644 --- a/dom/cache/AutoUtils.cpp +++ b/dom/cache/AutoUtils.cpp @@ -23,7 +23,6 @@ using mozilla::Maybe; using mozilla::Unused; using mozilla::dom::cache::CacheReadStream; -using mozilla::ipc::AutoIPCStream; using mozilla::ipc::PBackgroundParent; namespace { @@ -55,12 +54,6 @@ AutoChildOpArgs::AutoChildOpArgs(TypeUtils* aTypeUtils, : mTypeUtils(aTypeUtils), mOpArgs(aOpArgs), mSent(false) { MOZ_DIAGNOSTIC_ASSERT(mTypeUtils); MOZ_RELEASE_ASSERT(aEntryCount != 0); - // We are using AutoIPCStream objects to cleanup target IPCStream - // structures embedded in our CacheOpArgs. These IPCStream structs - // must not move once we attach our AutoIPCStream to them. Therefore, - // its important that any arrays containing streams are pre-sized for - // the number of entries we have in order to avoid realloc moving - // things around on us. if (mOpArgs.type() == CacheOpArgs::TCachePutAllArgs) { CachePutAllArgs& args = mOpArgs.get_CachePutAllArgs(); args.requestResponseList().SetCapacity(aEntryCount); @@ -117,8 +110,6 @@ AutoChildOpArgs::~AutoChildOpArgs() { // Other types do not need cleanup break; } - - mStreamCleanupList.Clear(); } void AutoChildOpArgs::Add(const InternalRequest& aRequest, @@ -130,7 +121,7 @@ void AutoChildOpArgs::Add(const InternalRequest& aRequest, case CacheOpArgs::TCacheMatchArgs: { CacheMatchArgs& args = mOpArgs.get_CacheMatchArgs(); mTypeUtils->ToCacheRequest(args.request(), aRequest, aBodyAction, - aSchemeAction, mStreamCleanupList, aRv); + aSchemeAction, aRv); break; } case CacheOpArgs::TCacheMatchAllArgs: { @@ -138,14 +129,13 @@ void AutoChildOpArgs::Add(const InternalRequest& aRequest, MOZ_DIAGNOSTIC_ASSERT(args.maybeRequest().isNothing()); args.maybeRequest().emplace(CacheRequest()); mTypeUtils->ToCacheRequest(args.maybeRequest().ref(), aRequest, - aBodyAction, aSchemeAction, mStreamCleanupList, - aRv); + aBodyAction, aSchemeAction, aRv); break; } case CacheOpArgs::TCacheDeleteArgs: { CacheDeleteArgs& args = mOpArgs.get_CacheDeleteArgs(); mTypeUtils->ToCacheRequest(args.request(), aRequest, aBodyAction, - aSchemeAction, mStreamCleanupList, aRv); + aSchemeAction, aRv); break; } case CacheOpArgs::TCacheKeysArgs: { @@ -153,14 +143,13 @@ void AutoChildOpArgs::Add(const InternalRequest& aRequest, MOZ_DIAGNOSTIC_ASSERT(args.maybeRequest().isNothing()); args.maybeRequest().emplace(CacheRequest()); mTypeUtils->ToCacheRequest(args.maybeRequest().ref(), aRequest, - aBodyAction, aSchemeAction, mStreamCleanupList, - aRv); + aBodyAction, aSchemeAction, aRv); break; } case CacheOpArgs::TStorageMatchArgs: { StorageMatchArgs& args = mOpArgs.get_StorageMatchArgs(); mTypeUtils->ToCacheRequest(args.request(), aRequest, aBodyAction, - aSchemeAction, mStreamCleanupList, aRv); + aSchemeAction, aRv); break; } default: @@ -273,10 +262,6 @@ void AutoChildOpArgs::Add(JSContext* aCx, const InternalRequest& aRequest, return; } - // Ensure that we don't realloc the array since this can result - // in our AutoIPCStream objects to reference the wrong memory - // location. This should never happen and is a UAF if it does. - // Therefore make this a release assertion. MOZ_RELEASE_ASSERT(args.requestResponseList().Length() < args.requestResponseList().Capacity()); @@ -292,10 +277,9 @@ void AutoChildOpArgs::Add(JSContext* aCx, const InternalRequest& aRequest, pair.response().body() = Nothing(); mTypeUtils->ToCacheRequest(pair.request(), aRequest, aBodyAction, - aSchemeAction, mStreamCleanupList, aRv); + aSchemeAction, aRv); if (!aRv.Failed()) { - mTypeUtils->ToCacheResponse(aCx, pair.response(), aResponse, - mStreamCleanupList, aRv); + mTypeUtils->ToCacheResponse(aCx, pair.response(), aResponse, aRv); } if (aRv.Failed()) { @@ -313,9 +297,6 @@ void AutoChildOpArgs::Add(JSContext* aCx, const InternalRequest& aRequest, const CacheOpArgs& AutoChildOpArgs::SendAsOpArgs() { MOZ_DIAGNOSTIC_ASSERT(!mSent); mSent = true; - for (UniquePtr& autoStream : mStreamCleanupList) { - autoStream->TakeOptionalValue(); - } return mOpArgs; } @@ -330,12 +311,6 @@ AutoParentOpResult::AutoParentOpResult( mSent(false) { MOZ_DIAGNOSTIC_ASSERT(mManager); MOZ_RELEASE_ASSERT(aEntryCount != 0); - // We are using AutoIPCStream objects to cleanup target IPCStream - // structures embedded in our CacheOpArgs. These IPCStream structs - // must not move once we attach our AutoIPCStream to them. Therefore, - // its important that any arrays containing streams are pre-sized for - // the number of entries we have in order to avoid realloc moving - // things around on us. if (mOpResult.type() == CacheOpResult::TCacheMatchAllResult) { CacheMatchAllResult& result = mOpResult.get_CacheMatchAllResult(); result.responseList().SetCapacity(aEntryCount); @@ -370,8 +345,6 @@ AutoParentOpResult::~AutoParentOpResult() { QM_WARNONLY_TRY( OkIf(PCacheStreamControlParent::Send__delete__(mStreamControl))); } - - mStreamCleanupList.Clear(); } void AutoParentOpResult::Add(CacheId aOpenedCacheId, @@ -399,10 +372,6 @@ void AutoParentOpResult::Add(const SavedResponse& aSavedResponse, } case CacheOpResult::TCacheMatchAllResult: { CacheMatchAllResult& result = mOpResult.get_CacheMatchAllResult(); - // Ensure that we don't realloc the array since this can result - // in our AutoIPCStream objects to reference the wrong memory - // location. This should never happen and is a UAF if it does. - // Therefore make this a release assertion. MOZ_RELEASE_ASSERT(result.responseList().Length() < result.responseList().Capacity()); result.responseList().AppendElement(aSavedResponse.mValue); @@ -430,10 +399,6 @@ void AutoParentOpResult::Add(const SavedRequest& aSavedRequest, switch (mOpResult.type()) { case CacheOpResult::TCacheKeysResult: { CacheKeysResult& result = mOpResult.get_CacheKeysResult(); - // Ensure that we don't realloc the array since this can result - // in our AutoIPCStream objects to reference the wrong memory - // location. This should never happen and is a UAF if it does. - // Therefore make this a release assertion. MOZ_RELEASE_ASSERT(result.requestList().Length() < result.requestList().Capacity()); result.requestList().AppendElement(aSavedRequest.mValue); @@ -457,9 +422,6 @@ void AutoParentOpResult::Add(const SavedRequest& aSavedRequest, const CacheOpResult& AutoParentOpResult::SendAsOpResult() { MOZ_DIAGNOSTIC_ASSERT(!mSent); mSent = true; - for (UniquePtr& autoStream : mStreamCleanupList) { - autoStream->TakeOptionalValue(); - } return mOpResult; } @@ -504,7 +466,7 @@ void AutoParentOpResult::SerializeReadStream(const nsID& aId, RefPtr readStream = ReadStream::Create(mStreamControl, aId, stream); ErrorResult rv; - readStream->Serialize(aReadStreamOut, mStreamCleanupList, rv); + readStream->Serialize(aReadStreamOut, rv); MOZ_DIAGNOSTIC_ASSERT(!rv.Failed()); } diff --git a/dom/cache/AutoUtils.h b/dom/cache/AutoUtils.h index fa798a22abb0..b24c07a37c9e 100644 --- a/dom/cache/AutoUtils.h +++ b/dom/cache/AutoUtils.h @@ -22,7 +22,6 @@ class ErrorResult; namespace ipc { class PBackgroundParent; -class AutoIPCStream; } // namespace ipc namespace dom { @@ -65,7 +64,6 @@ class MOZ_STACK_CLASS AutoChildOpArgs final { private: TypeUtils* mTypeUtils; CacheOpArgs mOpArgs; - nsTArray> mStreamCleanupList; bool mSent; }; @@ -92,7 +90,6 @@ class MOZ_STACK_CLASS AutoParentOpResult final { mozilla::ipc::PBackgroundParent* mManager; CacheOpResult mOpResult; CacheStreamControlParent* mStreamControl; - nsTArray> mStreamCleanupList; bool mSent; }; diff --git a/dom/cache/CacheStreamControlChild.cpp b/dom/cache/CacheStreamControlChild.cpp index aa9e3abe1b45..0da1d20b135f 100644 --- a/dom/cache/CacheStreamControlChild.cpp +++ b/dom/cache/CacheStreamControlChild.cpp @@ -17,7 +17,6 @@ namespace mozilla::dom::cache { -using mozilla::ipc::AutoIPCStream; using mozilla::ipc::FileDescriptor; // declared in ActorUtils.h @@ -73,15 +72,12 @@ void CacheStreamControlChild::SerializeControl( aReadStreamOut->controlChild() = this; } -void CacheStreamControlChild::SerializeStream( - CacheReadStream* aReadStreamOut, nsIInputStream* aStream, - nsTArray>& aStreamCleanupList) { +void CacheStreamControlChild::SerializeStream(CacheReadStream* aReadStreamOut, + nsIInputStream* aStream) { NS_ASSERT_OWNINGTHREAD(CacheStreamControlChild); MOZ_DIAGNOSTIC_ASSERT(aReadStreamOut); - UniquePtr autoStream( - new AutoIPCStream(aReadStreamOut->stream())); - autoStream->Serialize(aStream, Manager()); - aStreamCleanupList.AppendElement(std::move(autoStream)); + MOZ_ALWAYS_TRUE(mozilla::ipc::SerializeIPCStream( + do_AddRef(aStream), aReadStreamOut->stream(), /* aAllowLazy */ false)); } void CacheStreamControlChild::OpenStream(const nsID& aId, diff --git a/dom/cache/CacheStreamControlChild.h b/dom/cache/CacheStreamControlChild.h index 3ab3cc6e1843..fa78b8caf21f 100644 --- a/dom/cache/CacheStreamControlChild.h +++ b/dom/cache/CacheStreamControlChild.h @@ -12,11 +12,7 @@ #include "mozilla/dom/cache/StreamControl.h" #include "nsTObserverArray.h" -namespace mozilla { -namespace ipc { -class AutoIPCStream; -} // namespace ipc -namespace dom::cache { +namespace mozilla::dom::cache { class ReadStream; @@ -35,9 +31,7 @@ class CacheStreamControlChild final : public PCacheStreamControlChild, virtual void SerializeControl(CacheReadStream* aReadStreamOut) override; virtual void SerializeStream(CacheReadStream* aReadStreamOut, - nsIInputStream* aStream, - nsTArray>& - aStreamCleanupList) override; + nsIInputStream* aStream) override; virtual void OpenStream(const nsID& aId, InputStreamResolver&& aResolver) override; @@ -61,7 +55,6 @@ class CacheStreamControlChild final : public PCacheStreamControlChild, bool mDestroyDelayed; }; -} // namespace dom::cache -} // namespace mozilla +} // namespace mozilla::dom::cache #endif // mozilla_dom_cache_CacheStreamControlChild_h diff --git a/dom/cache/CacheStreamControlParent.cpp b/dom/cache/CacheStreamControlParent.cpp index 0ee31da4db6d..6bcca3b15ee6 100644 --- a/dom/cache/CacheStreamControlParent.cpp +++ b/dom/cache/CacheStreamControlParent.cpp @@ -18,7 +18,6 @@ namespace mozilla::dom::cache { -using mozilla::ipc::AutoIPCStream; using mozilla::ipc::FileDescriptor; // declared in ActorUtils.h @@ -44,18 +43,14 @@ void CacheStreamControlParent::SerializeControl( aReadStreamOut->controlParent() = this; } -void CacheStreamControlParent::SerializeStream( - CacheReadStream* aReadStreamOut, nsIInputStream* aStream, - nsTArray>& aStreamCleanupList) { +void CacheStreamControlParent::SerializeStream(CacheReadStream* aReadStreamOut, + nsIInputStream* aStream) { NS_ASSERT_OWNINGTHREAD(CacheStreamControlParent); MOZ_DIAGNOSTIC_ASSERT(aReadStreamOut); - UniquePtr autoStream( - new AutoIPCStream(aReadStreamOut->stream())); - DebugOnly ok = autoStream->Serialize(aStream, Manager()); + DebugOnly ok = mozilla::ipc::SerializeIPCStream( + do_AddRef(aStream), aReadStreamOut->stream(), /* aAllowLazy */ false); MOZ_ASSERT(ok); - - aStreamCleanupList.AppendElement(std::move(autoStream)); } void CacheStreamControlParent::OpenStream(const nsID& aId, @@ -120,9 +115,11 @@ mozilla::ipc::IPCResult CacheStreamControlParent::RecvOpenStream( OpenStream(aStreamId, [aResolver, self = RefPtr{this}]( nsCOMPtr&& aStream) { - AutoIPCStream autoStream; - if (self->CanSend() && autoStream.Serialize(aStream, self->Manager())) { - aResolver(autoStream.TakeOptionalValue()); + Maybe stream; + if (self->CanSend() && + mozilla::ipc::SerializeIPCStream(aStream.forget(), stream, + /* aAllowLazy */ false)) { + aResolver(stream); } else { aResolver(Nothing()); } diff --git a/dom/cache/CacheStreamControlParent.h b/dom/cache/CacheStreamControlParent.h index 2b4f236f4ca2..d069b2fcfa8c 100644 --- a/dom/cache/CacheStreamControlParent.h +++ b/dom/cache/CacheStreamControlParent.h @@ -12,11 +12,7 @@ #include "mozilla/dom/cache/StreamControl.h" #include "nsTObserverArray.h" -namespace mozilla { -namespace ipc { -class AutoIPCStream; -} // namespace ipc -namespace dom::cache { +namespace mozilla::dom::cache { class ReadStream; class StreamList; @@ -37,9 +33,7 @@ class CacheStreamControlParent final : public PCacheStreamControlParent, virtual void SerializeControl(CacheReadStream* aReadStreamOut) override; virtual void SerializeStream(CacheReadStream* aReadStreamOut, - nsIInputStream* aStream, - nsTArray>& - aStreamCleanupList) override; + nsIInputStream* aStream) override; virtual void OpenStream(const nsID& aId, InputStreamResolver&& aResolver) override; @@ -73,7 +67,6 @@ class CacheStreamControlParent final : public PCacheStreamControlParent, NS_INLINE_DECL_THREADSAFE_REFCOUNTING(CacheStreamControlParent, override) }; -} // namespace dom::cache -} // namespace mozilla +} // namespace mozilla::dom::cache #endif // mozilla_dom_cache_CacheStreamControlParent_h diff --git a/dom/cache/ReadStream.cpp b/dom/cache/ReadStream.cpp index 2fefa7cae43f..0044a23b9fa2 100644 --- a/dom/cache/ReadStream.cpp +++ b/dom/cache/ReadStream.cpp @@ -20,7 +20,6 @@ namespace mozilla::dom::cache { using mozilla::Unused; -using mozilla::ipc::AutoIPCStream; using mozilla::ipc::IPCStream; // ---------------------------------------------------------------------------- @@ -32,13 +31,9 @@ class ReadStream::Inner final : public ReadStream::Controllable { public: Inner(StreamControl* aControl, const nsID& aId, nsIInputStream* aStream); - void Serialize(Maybe* aReadStreamOut, - nsTArray>& aStreamCleanupList, - ErrorResult& aRv); + void Serialize(Maybe* aReadStreamOut, ErrorResult& aRv); - void Serialize(CacheReadStream* aReadStreamOut, - nsTArray>& aStreamCleanupList, - ErrorResult& aRv); + void Serialize(CacheReadStream* aReadStreamOut, ErrorResult& aRv); // ReadStream::Controllable methods virtual void CloseStream() override; @@ -191,18 +186,16 @@ ReadStream::Inner::Inner(StreamControl* aControl, const nsID& aId, mControl->AddReadStream(SafeRefPtrFromThis()); } -void ReadStream::Inner::Serialize( - Maybe* aReadStreamOut, - nsTArray>& aStreamCleanupList, ErrorResult& aRv) { +void ReadStream::Inner::Serialize(Maybe* aReadStreamOut, + ErrorResult& aRv) { MOZ_ASSERT(mOwningEventTarget->IsOnCurrentThread()); MOZ_DIAGNOSTIC_ASSERT(aReadStreamOut); aReadStreamOut->emplace(CacheReadStream()); - Serialize(&aReadStreamOut->ref(), aStreamCleanupList, aRv); + Serialize(&aReadStreamOut->ref(), aRv); } -void ReadStream::Inner::Serialize( - CacheReadStream* aReadStreamOut, - nsTArray>& aStreamCleanupList, ErrorResult& aRv) { +void ReadStream::Inner::Serialize(CacheReadStream* aReadStreamOut, + ErrorResult& aRv) { MOZ_ASSERT(mOwningEventTarget->IsOnCurrentThread()); MOZ_DIAGNOSTIC_ASSERT(aReadStreamOut); @@ -219,7 +212,7 @@ void ReadStream::Inner::Serialize( { MutexAutoLock lock(mMutex); - mControl->SerializeStream(aReadStreamOut, mStream, aStreamCleanupList); + mControl->SerializeStream(aReadStreamOut, mStream); } MOZ_DIAGNOSTIC_ASSERT(aReadStreamOut->stream().isNothing() || @@ -554,16 +547,13 @@ already_AddRefed ReadStream::Create( static_cast(aControl), aId, aStream)); } -void ReadStream::Serialize( - Maybe* aReadStreamOut, - nsTArray>& aStreamCleanupList, ErrorResult& aRv) { - mInner->Serialize(aReadStreamOut, aStreamCleanupList, aRv); +void ReadStream::Serialize(Maybe* aReadStreamOut, + ErrorResult& aRv) { + mInner->Serialize(aReadStreamOut, aRv); } -void ReadStream::Serialize( - CacheReadStream* aReadStreamOut, - nsTArray>& aStreamCleanupList, ErrorResult& aRv) { - mInner->Serialize(aReadStreamOut, aStreamCleanupList, aRv); +void ReadStream::Serialize(CacheReadStream* aReadStreamOut, ErrorResult& aRv) { + mInner->Serialize(aReadStreamOut, aRv); } ReadStream::ReadStream(SafeRefPtr aInner) diff --git a/dom/cache/ReadStream.h b/dom/cache/ReadStream.h index da533699e718..d6b4e1d97968 100644 --- a/dom/cache/ReadStream.h +++ b/dom/cache/ReadStream.h @@ -19,9 +19,6 @@ namespace mozilla { class ErrorResult; -namespace ipc { -class AutoIPCStream; -} // namespace ipc namespace dom::cache { class CacheReadStream; @@ -77,14 +74,8 @@ class ReadStream final : public nsIInputStream { PCacheStreamControlParent* aControl, const nsID& aId, nsIInputStream* aStream); - void Serialize( - Maybe* aReadStreamOut, - nsTArray>& aStreamCleanupList, - ErrorResult& aRv); - void Serialize( - CacheReadStream* aReadStreamOut, - nsTArray>& aStreamCleanupList, - ErrorResult& aRv); + void Serialize(Maybe* aReadStreamOut, ErrorResult& aRv); + void Serialize(CacheReadStream* aReadStreamOut, ErrorResult& aRv); private: class Inner; diff --git a/dom/cache/StreamControl.h b/dom/cache/StreamControl.h index 7aa6061c229c..4a5cdfc309f5 100644 --- a/dom/cache/StreamControl.h +++ b/dom/cache/StreamControl.h @@ -14,11 +14,7 @@ struct nsID; -namespace mozilla { -namespace ipc { -class AutoIPCStream; -} // namespace ipc -namespace dom::cache { +namespace mozilla::dom::cache { class CacheReadStream; @@ -30,9 +26,8 @@ class StreamControl { // abstract interface that must be implemented by child class virtual void SerializeControl(CacheReadStream* aReadStreamOut) = 0; - virtual void SerializeStream( - CacheReadStream* aReadStreamOut, nsIInputStream* aStream, - nsTArray>& aStreamCleanupList) = 0; + virtual void SerializeStream(CacheReadStream* aReadStreamOut, + nsIInputStream* aStream) = 0; virtual void OpenStream(const nsID& aId, InputStreamResolver&& aResolver) = 0; @@ -75,7 +70,6 @@ class StreamControl { ReadStreamList mReadStreamList; }; -} // namespace dom::cache -} // namespace mozilla +} // namespace mozilla::dom::cache #endif // mozilla_dom_cache_StreamControl_h diff --git a/dom/cache/TypeUtils.cpp b/dom/cache/TypeUtils.cpp index d9137556fbc1..8f4aa8022243 100644 --- a/dom/cache/TypeUtils.cpp +++ b/dom/cache/TypeUtils.cpp @@ -33,7 +33,6 @@ namespace mozilla::dom::cache { -using mozilla::ipc::AutoIPCStream; using mozilla::ipc::BackgroundChild; using mozilla::ipc::FileDescriptor; using mozilla::ipc::PBackgroundChild; @@ -111,10 +110,9 @@ SafeRefPtr TypeUtils::ToInternalRequest( return ToInternalRequest(aIn.GetAsUSVString(), aRv); } -void TypeUtils::ToCacheRequest( - CacheRequest& aOut, const InternalRequest& aIn, BodyAction aBodyAction, - SchemeAction aSchemeAction, - nsTArray>& aStreamCleanupList, ErrorResult& aRv) { +void TypeUtils::ToCacheRequest(CacheRequest& aOut, const InternalRequest& aIn, + BodyAction aBodyAction, + SchemeAction aSchemeAction, ErrorResult& aRv) { aIn.GetMethod(aOut.method()); nsCString url(aIn.GetURLWithoutFragment()); bool schemeValid; @@ -159,7 +157,7 @@ void TypeUtils::ToCacheRequest( nsCOMPtr stream; aIn.GetBody(getter_AddRefs(stream)); - SerializeCacheStream(stream, &aOut.body(), aStreamCleanupList, aRv); + SerializeCacheStream(stream, &aOut.body(), aRv); if (NS_WARN_IF(aRv.Failed())) { return; } @@ -202,9 +200,8 @@ void TypeUtils::ToCacheResponseWithoutBody(CacheResponse& aOut, aOut.paddingSize() = aIn.GetPaddingSize(); } -void TypeUtils::ToCacheResponse( - JSContext* aCx, CacheResponse& aOut, Response& aIn, - nsTArray>& aStreamCleanupList, ErrorResult& aRv) { +void TypeUtils::ToCacheResponse(JSContext* aCx, CacheResponse& aOut, + Response& aIn, ErrorResult& aRv) { bool bodyUsed = aIn.GetBodyUsed(aRv); if (NS_WARN_IF(aRv.Failed())) { return; @@ -229,7 +226,7 @@ void TypeUtils::ToCacheResponse( } } - SerializeCacheStream(stream, &aOut.body(), aStreamCleanupList, aRv); + SerializeCacheStream(stream, &aOut.body(), aRv); if (NS_WARN_IF(aRv.Failed())) { return; } @@ -482,9 +479,9 @@ SafeRefPtr TypeUtils::ToInternalRequest(const nsAString& aIn, return request->GetInternalRequest(); } -void TypeUtils::SerializeCacheStream( - nsIInputStream* aStream, Maybe* aStreamOut, - nsTArray>& aStreamCleanupList, ErrorResult& aRv) { +void TypeUtils::SerializeCacheStream(nsIInputStream* aStream, + Maybe* aStreamOut, + ErrorResult& aRv) { *aStreamOut = Nothing(); if (!aStream) { return; @@ -492,7 +489,7 @@ void TypeUtils::SerializeCacheStream( RefPtr controlled = do_QueryObject(aStream); if (controlled) { - controlled->Serialize(aStreamOut, aStreamCleanupList, aRv); + controlled->Serialize(aStreamOut, aRv); return; } @@ -502,10 +499,9 @@ void TypeUtils::SerializeCacheStream( cacheStream.controlChild() = nullptr; cacheStream.controlParent() = nullptr; - UniquePtr autoStream(new AutoIPCStream(cacheStream.stream())); - autoStream->Serialize(aStream, GetIPCManager()); - - aStreamCleanupList.AppendElement(std::move(autoStream)); + MOZ_ALWAYS_TRUE(mozilla::ipc::SerializeIPCStream(do_AddRef(aStream), + cacheStream.stream(), + /* aAllowLazy */ false)); } } // namespace mozilla::dom::cache diff --git a/dom/cache/TypeUtils.h b/dom/cache/TypeUtils.h index 628a7f8bcd50..5342ea3d7e22 100644 --- a/dom/cache/TypeUtils.h +++ b/dom/cache/TypeUtils.h @@ -21,7 +21,6 @@ namespace mozilla { namespace ipc { class PBackgroundChild; -class AutoIPCStream; } // namespace ipc namespace dom { @@ -73,19 +72,15 @@ class TypeUtils { JSContext* aCx, const OwningRequestOrUSVString& aIn, BodyAction aBodyAction, ErrorResult& aRv); - void ToCacheRequest( - CacheRequest& aOut, const InternalRequest& aIn, BodyAction aBodyAction, - SchemeAction aSchemeAction, - nsTArray>& aStreamCleanupList, - ErrorResult& aRv); + void ToCacheRequest(CacheRequest& aOut, const InternalRequest& aIn, + BodyAction aBodyAction, SchemeAction aSchemeAction, + ErrorResult& aRv); void ToCacheResponseWithoutBody(CacheResponse& aOut, InternalResponse& aIn, ErrorResult& aRv); - void ToCacheResponse( - JSContext* aCx, CacheResponse& aOut, Response& aIn, - nsTArray>& aStreamCleanupList, - ErrorResult& aRv); + void ToCacheResponse(JSContext* aCx, CacheResponse& aOut, Response& aIn, + ErrorResult& aRv); void ToCacheQueryParams(CacheQueryParams& aOut, const CacheQueryOptions& aIn); @@ -128,10 +123,9 @@ class TypeUtils { SafeRefPtr ToInternalRequest(const nsAString& aIn, ErrorResult& aRv); - void SerializeCacheStream( - nsIInputStream* aStream, Maybe* aStreamOut, - nsTArray>& aStreamCleanupList, - ErrorResult& aRv); + void SerializeCacheStream(nsIInputStream* aStream, + Maybe* aStreamOut, + ErrorResult& aRv); void SerializeSendStream(nsIInputStream* aStream, CacheReadStream& aReadStreamOut, ErrorResult& aRv); diff --git a/dom/fetch/InternalResponse.cpp b/dom/fetch/InternalResponse.cpp index 1b9b548d2c90..0eeac35337d2 100644 --- a/dom/fetch/InternalResponse.cpp +++ b/dom/fetch/InternalResponse.cpp @@ -134,9 +134,7 @@ InternalResponseMetadata InternalResponse::GetMetadata() { void InternalResponse::ToChildToParentInternalResponse( ChildToParentInternalResponse* aIPCResponse, - mozilla::ipc::PBackgroundChild* aManager, - UniquePtr& aAutoBodyStream, - UniquePtr& aAutoAlternativeBodyStream) { + mozilla::ipc::PBackgroundChild* aManager) { *aIPCResponse = ChildToParentInternalResponse(GetMetadata(), Nothing(), UNKNOWN_BODY_SIZE, Nothing()); @@ -148,9 +146,8 @@ void InternalResponse::ToChildToParentInternalResponse( aIPCResponse->body().emplace(ChildToParentStream()); aIPCResponse->bodySize() = bodySize; - aAutoBodyStream.reset( - new mozilla::ipc::AutoIPCStream(aIPCResponse->body()->stream())); - DebugOnly ok = aAutoBodyStream->Serialize(body, aManager); + DebugOnly ok = mozilla::ipc::SerializeIPCStream( + body.forget(), aIPCResponse->body()->stream(), /* aAllowLazy */ false); MOZ_ASSERT(ok); } @@ -158,10 +155,9 @@ void InternalResponse::ToChildToParentInternalResponse( if (alternativeBody) { aIPCResponse->alternativeBody().emplace(ChildToParentStream()); - aAutoAlternativeBodyStream.reset(new mozilla::ipc::AutoIPCStream( - aIPCResponse->alternativeBody()->stream())); - DebugOnly ok = - aAutoAlternativeBodyStream->Serialize(alternativeBody, aManager); + DebugOnly ok = mozilla::ipc::SerializeIPCStream( + alternativeBody.forget(), aIPCResponse->alternativeBody()->stream(), + /* aAllowLazy */ false); MOZ_ASSERT(ok); } } diff --git a/dom/fetch/InternalResponse.h b/dom/fetch/InternalResponse.h index ba91afab2754..41530db49ba3 100644 --- a/dom/fetch/InternalResponse.h +++ b/dom/fetch/InternalResponse.h @@ -23,7 +23,6 @@ namespace mozilla { namespace ipc { -class AutoIPCStream; class PBackgroundChild; class PBackgroundParent; class PrincipalInfo; @@ -52,12 +51,9 @@ class InternalResponse final : public AtomicSafeRefCounted { static SafeRefPtr FromIPC( const ParentToParentInternalResponse& aIPCResponse); - // Note: the AutoIPCStreams must outlive the ChildToParentInternalResponse. void ToChildToParentInternalResponse( ChildToParentInternalResponse* aIPCResponse, - mozilla::ipc::PBackgroundChild* aManager, - UniquePtr& aAutoBodyStream, - UniquePtr& aAutoAlternativeBodyStream); + mozilla::ipc::PBackgroundChild* aManager); ParentToParentInternalResponse ToParentToParentInternalResponse(); diff --git a/dom/file/TemporaryFileBlobImpl.cpp b/dom/file/TemporaryFileBlobImpl.cpp index 40fca94135ca..505d4a96d4bc 100644 --- a/dom/file/TemporaryFileBlobImpl.cpp +++ b/dom/file/TemporaryFileBlobImpl.cpp @@ -50,22 +50,12 @@ class TemporaryFileInputStream final : public nsFileInputStream { return NS_OK; } - void Serialize(InputStreamParams& aParams, - FileDescriptorArray& aFileDescriptors, bool aDelayedStart, - uint32_t aMaxSize, uint32_t* aSizeUsed, - ParentToChildStreamActorManager* aManager) override { + void Serialize(InputStreamParams& aParams, uint32_t aMaxSize, + uint32_t* aSizeUsed) override { MOZ_CRASH("This inputStream cannot be serialized."); } - void Serialize(InputStreamParams& aParams, - FileDescriptorArray& aFileDescriptors, bool aDelayedStart, - uint32_t aMaxSize, uint32_t* aSizeUsed, - ChildToParentStreamActorManager* aManager) override { - MOZ_CRASH("This inputStream cannot be serialized."); - } - - bool Deserialize(const InputStreamParams& aParams, - const FileDescriptorArray& aFileDescriptors) override { + bool Deserialize(const InputStreamParams& aParams) override { MOZ_CRASH("This inputStream cannot be deserialized."); return false; } diff --git a/dom/file/ipc/IPCBlobUtils.cpp b/dom/file/ipc/IPCBlobUtils.cpp index 866c84d587d9..00a4537b7416 100644 --- a/dom/file/ipc/IPCBlobUtils.cpp +++ b/dom/file/ipc/IPCBlobUtils.cpp @@ -136,12 +136,12 @@ nsresult SerializeInternal(BlobImpl* aBlobImpl, M* aManager, return NS_OK; } - mozilla::ipc::AutoIPCStream ipcStream(true /* delayed start */); - if (!ipcStream.Serialize(inputStream, aManager)) { + IPCStream stream; + if (!mozilla::ipc::SerializeIPCStream(inputStream.forget(), stream, + /* aAllowLazy */ true)) { return NS_ERROR_FAILURE; } - - aIPCBlob.inputStream() = ipcStream.TakeValue(); + aIPCBlob.inputStream() = stream; return NS_OK; } diff --git a/dom/file/ipc/IPCBlobUtils.h b/dom/file/ipc/IPCBlobUtils.h index e0e838e6073a..41b4350ac287 100644 --- a/dom/file/ipc/IPCBlobUtils.h +++ b/dom/file/ipc/IPCBlobUtils.h @@ -68,9 +68,8 @@ * stream except for huge memory streams. In this case we end up using * DataPipe. See more information in IPCStreamUtils.h. * - * In order to populate IPCStream correctly, we use AutoIPCStream as documented - * in IPCStreamUtils.h. Note that we use the 'delayed start' feature because, - * often, the stream doesn't need to be read on the parent side. + * In order to populate IPCStream correctly, we use SerializeIPCStream as + * documented in IPCStreamUtils.h. * * Parent to Child Blob Serialization * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/dom/file/ipc/RemoteLazyInputStream.cpp b/dom/file/ipc/RemoteLazyInputStream.cpp index 3d0ea442b2d5..ed6bbf184edc 100644 --- a/dom/file/ipc/RemoteLazyInputStream.cpp +++ b/dom/file/ipc/RemoteLazyInputStream.cpp @@ -885,27 +885,14 @@ void RemoteLazyInputStream::SerializedComplexity(uint32_t aMaxSize, *aTransferables = 1; } -void RemoteLazyInputStream::Serialize( - mozilla::ipc::InputStreamParams& aParams, - FileDescriptorArray& aFileDescriptors, bool aDelayedStart, - uint32_t aMaxSize, uint32_t* aSizeUsed, - mozilla::ipc::ParentToChildStreamActorManager* aManager) { - *aSizeUsed = 0; - aParams = mozilla::ipc::RemoteLazyInputStreamParams(this); -} - -void RemoteLazyInputStream::Serialize( - mozilla::ipc::InputStreamParams& aParams, - FileDescriptorArray& aFileDescriptors, bool aDelayedStart, - uint32_t aMaxSize, uint32_t* aSizeUsed, - mozilla::ipc::ChildToParentStreamActorManager* aManager) { +void RemoteLazyInputStream::Serialize(mozilla::ipc::InputStreamParams& aParams, + uint32_t aMaxSize, uint32_t* aSizeUsed) { *aSizeUsed = 0; aParams = mozilla::ipc::RemoteLazyInputStreamParams(this); } bool RemoteLazyInputStream::Deserialize( - const mozilla::ipc::InputStreamParams& aParams, - const FileDescriptorArray& aFileDescriptors) { + const mozilla::ipc::InputStreamParams& aParams) { MOZ_CRASH("This should never be called."); return false; } diff --git a/dom/file/ipc/RemoteLazyInputStreamParent.cpp b/dom/file/ipc/RemoteLazyInputStreamParent.cpp index 78da779339bf..d92c5295465b 100644 --- a/dom/file/ipc/RemoteLazyInputStreamParent.cpp +++ b/dom/file/ipc/RemoteLazyInputStreamParent.cpp @@ -66,41 +66,15 @@ mozilla::ipc::IPCResult RemoteLazyInputStreamParent::RecvStreamNeeded( return IPC_OK(); } - // XXX: This should be much cleaner once the API for serializing IPCStream has - // been simplified. - ipc::InputStreamParams params; - if (nsCOMPtr serializable = - do_QueryInterface(stream)) { - nsTArray unused; - uint32_t sizeUsed = 0; - serializable->Serialize( - params, unused, false, 128 * 1024, &sizeUsed, - (mozilla::ipc::ParentToChildStreamActorManager*)nullptr); - MOZ_ASSERT(unused.IsEmpty()); - } else { - RefPtr sender; - RefPtr receiver; - nsresult rv = NewDataPipe(ipc::kDefaultDataPipeCapacity, - getter_AddRefs(sender), getter_AddRefs(receiver)); - if (NS_WARN_IF(NS_FAILED(rv))) { - return IPC_FAIL(this, "NewDataPipe failed"); - } - - nsCOMPtr target = - do_GetService(NS_STREAMTRANSPORTSERVICE_CONTRACTID); - - rv = NS_AsyncCopy(stream, sender, target, NS_ASYNCCOPY_VIA_WRITESEGMENTS, - ipc::kDefaultDataPipeCapacity, nullptr, nullptr); - if (NS_WARN_IF(NS_FAILED(rv))) { - return IPC_FAIL(this, "NS_AsyncCopy failed"); - } - - params = ipc::DataPipeReceiverStreamParams(receiver); + Maybe ipcStream; + if (NS_WARN_IF(!SerializeIPCStream(stream.forget(), ipcStream, + /* aAllowLazy */ false))) { + return IPC_FAIL(this, "IPCStream serialization failed!"); } MOZ_LOG(gRemoteLazyStreamLog, LogLevel::Verbose, ("Parent::RecvStreamNeeded resolve %s", nsIDToCString(mID).get())); - aResolver(Some(IPCStream(params))); + aResolver(ipcStream); return IPC_OK(); } diff --git a/dom/ipc/ContentChild.h b/dom/ipc/ContentChild.h index 65561733077e..6dd8f79a1f33 100644 --- a/dom/ipc/ContentChild.h +++ b/dom/ipc/ContentChild.h @@ -68,7 +68,6 @@ enum class CallerType : uint32_t; class ContentChild final : public PContentChild, public nsIDOMProcessChild, public mozilla::ipc::IShmemAllocator, - public mozilla::ipc::ChildToParentStreamActorManager, public ProcessActor { using ClonedMessageData = mozilla::dom::ClonedMessageData; using FileDescriptor = mozilla::ipc::FileDescriptor; diff --git a/dom/ipc/ContentParent.h b/dom/ipc/ContentParent.h index d34347430608..3cfa725f35c8 100644 --- a/dom/ipc/ContentParent.h +++ b/dom/ipc/ContentParent.h @@ -105,22 +105,20 @@ struct CancelContentJSOptions; } \ } -class ContentParent final - : public PContentParent, - public nsIDOMProcessParent, - public nsIObserver, - public nsIDOMGeoPositionCallback, - public nsIDOMGeoPositionErrorCallback, - public nsIAsyncShutdownBlocker, - public nsIInterfaceRequestor, - public gfx::gfxVarReceiver, - public mozilla::LinkedListElement, - public gfx::GPUProcessListener, - public mozilla::MemoryReportingProcess, - public mozilla::dom::ipc::MessageManagerCallback, - public mozilla::ipc::IShmemAllocator, - public mozilla::ipc::ParentToChildStreamActorManager, - public ProcessActor { +class ContentParent final : public PContentParent, + public nsIDOMProcessParent, + public nsIObserver, + public nsIDOMGeoPositionCallback, + public nsIDOMGeoPositionErrorCallback, + public nsIAsyncShutdownBlocker, + public nsIInterfaceRequestor, + public gfx::gfxVarReceiver, + public mozilla::LinkedListElement, + public gfx::GPUProcessListener, + public mozilla::MemoryReportingProcess, + public mozilla::dom::ipc::MessageManagerCallback, + public mozilla::ipc::IShmemAllocator, + public ProcessActor { typedef mozilla::ipc::GeckoChildProcessHost GeckoChildProcessHost; typedef mozilla::ipc::TestShellParent TestShellParent; typedef mozilla::ipc::PrincipalInfo PrincipalInfo; diff --git a/dom/ipc/StructuredCloneData.cpp b/dom/ipc/StructuredCloneData.cpp index 84ba326fe611..7da3e76837b9 100644 --- a/dom/ipc/StructuredCloneData.cpp +++ b/dom/ipc/StructuredCloneData.cpp @@ -25,7 +25,6 @@ using namespace mozilla::ipc; namespace mozilla::dom::ipc { -using mozilla::ipc::AutoIPCStream; using mozilla::ipc::IPCStream; using mozilla::ipc::PBackgroundChild; using mozilla::ipc::PBackgroundParent; @@ -62,7 +61,6 @@ StructuredCloneData& StructuredCloneData::operator=( mBlobImplArray = std::move(aOther.mBlobImplArray); mExternalData = std::move(aOther.mExternalData); mSharedData = std::move(aOther.mSharedData); - mIPCStreams = std::move(aOther.mIPCStreams); mInitialized = aOther.mInitialized; return *this; @@ -181,24 +179,16 @@ bool BuildClonedMessageData(M* aManager, StructuredCloneData& aData, const nsTArray>& inputStreams = aData.InputStreams(); if (!inputStreams.IsEmpty()) { - if (NS_WARN_IF( - !aData.IPCStreams().SetCapacity(inputStreams.Length(), fallible))) { - return false; - } - nsTArray& streams = aClonedData.inputStreams(); uint32_t length = inputStreams.Length(); streams.SetCapacity(length); for (uint32_t i = 0; i < length; ++i) { - AutoIPCStream* stream = aData.IPCStreams().AppendElement(fallible); - if (NS_WARN_IF(!stream)) { + IPCStream value; + if (!mozilla::ipc::SerializeIPCStream(do_AddRef(inputStreams[i]), value, + /* aAllowLazy */ false)) { return false; } - - if (!stream->Serialize(inputStreams[i], aManager)) { - return false; - } - streams.AppendElement(stream->TakeValue()); + streams.AppendElement(value); } } diff --git a/dom/ipc/StructuredCloneData.h b/dom/ipc/StructuredCloneData.h index 4b380dfcad55..8b17e44027a3 100644 --- a/dom/ipc/StructuredCloneData.h +++ b/dom/ipc/StructuredCloneData.h @@ -23,7 +23,6 @@ class PickleIterator; namespace mozilla { namespace ipc { -class AutoIPCStream; class PBackgroundChild; class PBackgroundParent; @@ -275,10 +274,6 @@ class StructuredCloneData : public StructuredCloneHolder { bool SupportsTransferring() { return mSupportsTransferring; } - FallibleTArray& IPCStreams() { - return mIPCStreams; - } - // For IPC serialization void WriteIPCParams(IPC::MessageWriter* aWriter) const; bool ReadIPCParams(IPC::MessageReader* aReader); @@ -290,9 +285,6 @@ class StructuredCloneData : public StructuredCloneHolder { JSStructuredCloneData mExternalData; RefPtr mSharedData; - // This array is needed because AutoIPCStream DTOR must be executed after the - // sending of the data via IPC. This will be fixed by bug 1353475. - FallibleTArray mIPCStreams; bool mInitialized; }; diff --git a/dom/network/UDPSocketChild.cpp b/dom/network/UDPSocketChild.cpp index 83bfca685b29..d210fcccedda 100644 --- a/dom/network/UDPSocketChild.cpp +++ b/dom/network/UDPSocketChild.cpp @@ -142,13 +142,15 @@ nsresult UDPSocketChild::SendBinaryStream(const nsACString& aHost, nsIInputStream* aStream) { NS_ENSURE_ARG(aStream); - mozilla::ipc::AutoIPCStream autoStream; - autoStream.Serialize(aStream, static_cast( - gNeckoChild->Manager())); + mozilla::ipc::IPCStream stream; + if (NS_WARN_IF(!mozilla::ipc::SerializeIPCStream(do_AddRef(aStream), stream, + /* aAllowLazy */ false))) { + return NS_ERROR_UNEXPECTED; + } UDPSOCKET_LOG( ("%s: %s:%u", __FUNCTION__, PromiseFlatCString(aHost).get(), aPort)); - SendOutgoingData(UDPData(autoStream.TakeValue()), + SendOutgoingData(UDPData(stream), UDPSocketAddr(UDPAddressInfo(nsCString(aHost), aPort))); return NS_OK; diff --git a/dom/quota/DecryptingInputStream.cpp b/dom/quota/DecryptingInputStream.cpp index c02eafdec360..939b1e3ad759 100644 --- a/dom/quota/DecryptingInputStream.cpp +++ b/dom/quota/DecryptingInputStream.cpp @@ -86,14 +86,6 @@ void DecryptingInputStreamBase::SerializedComplexity(uint32_t aMaxSize, ->SerializedComplexity(aMaxSize, aSizeUsed, aPipes, aTransferables); } -void DecryptingInputStreamBase::Serialize( - mozilla::ipc::InputStreamParams& aParams, - FileDescriptorArray& aFileDescriptors, bool aDelayedStart, - uint32_t aMaxSize, uint32_t* aSizeUsed, - mozilla::ipc::ChildToParentStreamActorManager* aManager) { - MOZ_CRASH("Not implemented"); -} - size_t DecryptingInputStreamBase::PlainLength() const { MOZ_ASSERT(mNextByte <= mPlainBytes); return mPlainBytes - mNextByte; diff --git a/dom/quota/DecryptingInputStream.h b/dom/quota/DecryptingInputStream.h index df736b7aa172..7559ca860ee7 100644 --- a/dom/quota/DecryptingInputStream.h +++ b/dom/quota/DecryptingInputStream.h @@ -28,11 +28,6 @@ #include "nsTArray.h" #include "nscore.h" -namespace mozilla::ipc { -class ChildToParentStreamActorManager; -class ParentToChildStreamActorManager; -} // namespace mozilla::ipc - template class nsCOMPtr; @@ -57,12 +52,6 @@ class DecryptingInputStreamBase : public nsIInputStream, uint32_t* aPipes, uint32_t* aTransferables) override; - using nsIIPCSerializableInputStream::Serialize; - void Serialize(mozilla::ipc::InputStreamParams& aParams, - FileDescriptorArray& aFileDescriptors, bool aDelayedStart, - uint32_t aMaxSize, uint32_t* aSizeUsed, - mozilla::ipc::ChildToParentStreamActorManager* aManager) final; - protected: DecryptingInputStreamBase(MovingNotNull> aBaseStream, size_t aBlockSize); @@ -127,15 +116,10 @@ class DecryptingInputStream final : public DecryptingInputStreamBase { NS_IMETHOD Clone(nsIInputStream** _retval) override; - using DecryptingInputStreamBase::Serialize; - void Serialize( - mozilla::ipc::InputStreamParams& aParams, - FileDescriptorArray& aFileDescriptors, bool aDelayedStart, - uint32_t aMaxSize, uint32_t* aSizeUsed, - mozilla::ipc::ParentToChildStreamActorManager* aManager) override; + void Serialize(mozilla::ipc::InputStreamParams& aParams, uint32_t aMaxSize, + uint32_t* aSizeUsed) override; - bool Deserialize(const mozilla::ipc::InputStreamParams& aParams, - const FileDescriptorArray& aFileDescriptors) override; + bool Deserialize(const mozilla::ipc::InputStreamParams& aParams) override; private: ~DecryptingInputStream(); diff --git a/dom/quota/DecryptingInputStream_impl.h b/dom/quota/DecryptingInputStream_impl.h index 9a969afa8be7..169af92218c4 100644 --- a/dom/quota/DecryptingInputStream_impl.h +++ b/dom/quota/DecryptingInputStream_impl.h @@ -464,17 +464,14 @@ NS_IMETHODIMP DecryptingInputStream::Clone( template void DecryptingInputStream::Serialize( - mozilla::ipc::InputStreamParams& aParams, - FileDescriptorArray& aFileDescriptors, bool aDelayedStart, - uint32_t aMaxSize, uint32_t* aSizeUsed, - mozilla::ipc::ParentToChildStreamActorManager* aManager) { + mozilla::ipc::InputStreamParams& aParams, uint32_t aMaxSize, + uint32_t* aSizeUsed) { MOZ_ASSERT(mBaseStream); MOZ_ASSERT(mBaseIPCSerializableInputStream); mozilla::ipc::InputStreamParams baseStreamParams; (*mBaseIPCSerializableInputStream) - ->Serialize(baseStreamParams, aFileDescriptors, aDelayedStart, aMaxSize, - aSizeUsed, aManager); + ->Serialize(baseStreamParams, aMaxSize, aSizeUsed); MOZ_ASSERT(baseStreamParams.type() == mozilla::ipc::InputStreamParams::TFileInputStreamParams); @@ -491,8 +488,7 @@ void DecryptingInputStream::Serialize( template bool DecryptingInputStream::Deserialize( - const mozilla::ipc::InputStreamParams& aParams, - const FileDescriptorArray& aFileDescriptors) { + const mozilla::ipc::InputStreamParams& aParams) { MOZ_ASSERT(aParams.type() == mozilla::ipc::InputStreamParams::TEncryptedFileInputStreamParams); const auto& params = aParams.get_EncryptedFileInputStreamParams(); @@ -503,8 +499,8 @@ bool DecryptingInputStream::Deserialize( nsCOMPtr baseSerializable = do_QueryInterface(stream); - if (NS_WARN_IF(!baseSerializable->Deserialize(params.fileInputStreamParams(), - aFileDescriptors))) { + if (NS_WARN_IF( + !baseSerializable->Deserialize(params.fileInputStreamParams()))) { return false; } diff --git a/dom/serviceworkers/FetchEventOpProxyChild.cpp b/dom/serviceworkers/FetchEventOpProxyChild.cpp index d0aa29b0b0ed..94bdbaa4bbfc 100644 --- a/dom/serviceworkers/FetchEventOpProxyChild.cpp +++ b/dom/serviceworkers/FetchEventOpProxyChild.cpp @@ -37,8 +37,7 @@ namespace { nsresult GetIPCSynthesizeResponseArgs( ChildToParentSynthesizeResponseArgs* aIPCArgs, - SynthesizeResponseArgs&& aArgs, UniquePtr& aAutoBodyStream, - UniquePtr& aAutoAlternativeBodyStream) { + SynthesizeResponseArgs&& aArgs) { MOZ_ASSERT(RemoteWorkerService::Thread()->IsOnCurrentThread()); SafeRefPtr internalResponse; @@ -56,8 +55,7 @@ nsresult GetIPCSynthesizeResponseArgs( } internalResponse->ToChildToParentInternalResponse( - &aIPCArgs->internalResponse(), bgChild, aAutoBodyStream, - aAutoAlternativeBodyStream); + &aIPCArgs->internalResponse(), bgChild); return NS_OK; } @@ -149,13 +147,8 @@ void FetchEventOpProxyChild::Initialize( if (result.is()) { ChildToParentSynthesizeResponseArgs ipcArgs; - UniquePtr autoBodyStream = - MakeUnique(); - UniquePtr autoAlternativeBodyStream = - MakeUnique(); nsresult rv = GetIPCSynthesizeResponseArgs( - &ipcArgs, result.extract(), - autoBodyStream, autoAlternativeBodyStream); + &ipcArgs, result.extract()); if (NS_WARN_IF(NS_FAILED(rv))) { Unused << self->SendRespondWith( @@ -164,14 +157,6 @@ void FetchEventOpProxyChild::Initialize( } Unused << self->SendRespondWith(ipcArgs); - - if (ipcArgs.internalResponse().body()) { - autoBodyStream->TakeValue(); - } - - if (ipcArgs.internalResponse().alternativeBody()) { - autoAlternativeBodyStream->TakeValue(); - } } else if (result.is()) { Unused << self->SendRespondWith( result.extract()); diff --git a/dom/webbrowserpersist/WebBrowserPersistDocumentChild.cpp b/dom/webbrowserpersist/WebBrowserPersistDocumentChild.cpp index 82c4b0353c48..41159ab164a8 100644 --- a/dom/webbrowserpersist/WebBrowserPersistDocumentChild.cpp +++ b/dom/webbrowserpersist/WebBrowserPersistDocumentChild.cpp @@ -76,12 +76,12 @@ void WebBrowserPersistDocumentChild::Start( ENSURE(aDocument->GetPostData(getter_AddRefs(postDataStream))); #undef ENSURE - mozilla::ipc::AutoIPCStream autoStream; - autoStream.Serialize(postDataStream, - static_cast(Manager())); + Maybe stream; + mozilla::ipc::SerializeIPCStream(postDataStream.forget(), stream, + /* aAllowLazy */ false); mDocument = aDocument; - SendAttributes(attrs, autoStream.TakeOptionalValue()); + SendAttributes(attrs, stream); } mozilla::ipc::IPCResult WebBrowserPersistDocumentChild::RecvSetPersistFlags( diff --git a/ipc/glue/BackgroundChildImpl.h b/ipc/glue/BackgroundChildImpl.h index 008b91693428..08b54ac8e51f 100644 --- a/ipc/glue/BackgroundChildImpl.h +++ b/ipc/glue/BackgroundChildImpl.h @@ -29,8 +29,7 @@ namespace ipc { // Instances of this class should never be created directly. This class is meant // to be inherited in BackgroundImpl. -class BackgroundChildImpl : public PBackgroundChild, - public ChildToParentStreamActorManager { +class BackgroundChildImpl : public PBackgroundChild { public: class ThreadLocal; diff --git a/ipc/glue/BackgroundParentImpl.h b/ipc/glue/BackgroundParentImpl.h index f5516cb915f1..a0e78112e326 100644 --- a/ipc/glue/BackgroundParentImpl.h +++ b/ipc/glue/BackgroundParentImpl.h @@ -15,8 +15,7 @@ namespace mozilla::ipc { // Instances of this class should never be created directly. This class is meant // to be inherited in BackgroundImpl. -class BackgroundParentImpl : public PBackgroundParent, - public ParentToChildStreamActorManager { +class BackgroundParentImpl : public PBackgroundParent { protected: BackgroundParentImpl(); virtual ~BackgroundParentImpl(); diff --git a/ipc/glue/DataPipe.cpp b/ipc/glue/DataPipe.cpp index 5479d8d2e5cd..a87cee8a596f 100644 --- a/ipc/glue/DataPipe.cpp +++ b/ipc/glue/DataPipe.cpp @@ -669,27 +669,13 @@ void DataPipeReceiver::SerializedComplexity(uint32_t aMaxSize, *aTransferables = 1; } -void DataPipeReceiver::Serialize(InputStreamParams& aParams, - FileDescriptorArray& aFileDescriptors, - bool aDelayedStart, uint32_t aMaxSize, - uint32_t* aSizeUsed, - ParentToChildStreamActorManager* aManager) { +void DataPipeReceiver::Serialize(InputStreamParams& aParams, uint32_t aMaxSize, + uint32_t* aSizeUsed) { *aSizeUsed = 0; aParams = DataPipeReceiverStreamParams(this); } -void DataPipeReceiver::Serialize(InputStreamParams& aParams, - FileDescriptorArray& aFileDescriptors, - bool aDelayedStart, uint32_t aMaxSize, - uint32_t* aSizeUsed, - ChildToParentStreamActorManager* aManager) { - *aSizeUsed = 0; - aParams = DataPipeReceiverStreamParams(this); -} - -bool DataPipeReceiver::Deserialize( - const InputStreamParams& aParams, - const FileDescriptorArray& aFileDescriptors) { +bool DataPipeReceiver::Deserialize(const InputStreamParams& aParams) { MOZ_CRASH("Handled directly in `DeserializeInputStream`"); } diff --git a/ipc/glue/IPCStream.ipdlh b/ipc/glue/IPCStream.ipdlh index dff84a10809d..abf7ef771446 100644 --- a/ipc/glue/IPCStream.ipdlh +++ b/ipc/glue/IPCStream.ipdlh @@ -9,7 +9,10 @@ namespace mozilla { namespace ipc { // Use IPCStream in your ipdl to represent serialized nsIInputStreams. Then use -// AutoIPCStream from IPCStreamUtils.h to perform the serialization. +// SerializeIPCStream from IPCStreamUtils.h to perform the serialization. +// +// NOTE: If you don't need to handle nsIInputStream serialization failure, +// `nsIInputStream` may be used directly by IPDL protocols. struct IPCStream { InputStreamParams stream; diff --git a/ipc/glue/IPCStreamUtils.cpp b/ipc/glue/IPCStreamUtils.cpp index e55850627535..265cb1cff8d3 100644 --- a/ipc/glue/IPCStreamUtils.cpp +++ b/ipc/glue/IPCStreamUtils.cpp @@ -6,107 +6,28 @@ #include "IPCStreamUtils.h" +#include "ipc/IPCMessageUtilsSpecializations.h" + #include "nsIHttpHeaderVisitor.h" #include "nsIIPCSerializableInputStream.h" #include "mozIRemoteLazyInputStream.h" #include "mozilla/Assertions.h" -#include "mozilla/dom/ContentChild.h" -#include "mozilla/dom/ContentParent.h" #include "mozilla/dom/File.h" +#include "mozilla/ipc/IPCStream.h" #include "mozilla/ipc/InputStreamUtils.h" -#include "mozilla/net/SocketProcessChild.h" -#include "mozilla/net/SocketProcessParent.h" #include "mozilla/InputStreamLengthHelper.h" #include "mozilla/RemoteLazyInputStreamParent.h" #include "mozilla/Unused.h" #include "nsIMIMEInputStream.h" #include "nsNetCID.h" -#include "BackgroundParentImpl.h" -#include "BackgroundChildImpl.h" using namespace mozilla::dom; -namespace mozilla { -namespace ipc { +namespace mozilla::ipc { namespace { -// These serialization and cleanup functions could be externally exposed. For -// now, though, keep them private to encourage use of the safer RAII -// AutoIPCStream class. - -template -bool SerializeInputStreamWithFdsChild(nsIIPCSerializableInputStream* aStream, - IPCStream& aValue, bool aDelayedStart, - M* aManager) { - MOZ_RELEASE_ASSERT(aStream); - MOZ_ASSERT(aManager); - - // If you change this size, please also update the payload size in - // test_reload_large_postdata.html. - const uint64_t kTooLargeStream = 1024 * 1024; - - uint32_t sizeUsed = 0; - AutoTArray fds; - aStream->Serialize(aValue.stream(), fds, aDelayedStart, kTooLargeStream, - &sizeUsed, aManager); - - MOZ_ASSERT(sizeUsed <= kTooLargeStream); - - if (aValue.stream().type() == InputStreamParams::T__None) { - MOZ_CRASH("Serialize failed!"); - } - - MOZ_ASSERT(fds.IsEmpty(), "argument is unused"); - - return true; -} - -template -bool SerializeInputStreamWithFdsParent(nsIIPCSerializableInputStream* aStream, - IPCStream& aValue, bool aDelayedStart, - M* aManager) { - MOZ_RELEASE_ASSERT(aStream); - MOZ_ASSERT(aManager); - - const uint64_t kTooLargeStream = 1024 * 1024; - - uint32_t sizeUsed = 0; - AutoTArray fds; - aStream->Serialize(aValue.stream(), fds, aDelayedStart, kTooLargeStream, - &sizeUsed, aManager); - - MOZ_ASSERT(sizeUsed <= kTooLargeStream); - - if (aValue.stream().type() == InputStreamParams::T__None) { - MOZ_CRASH("Serialize failed!"); - } - - MOZ_ASSERT(fds.IsEmpty(), "argument is unused"); - - return true; -} - -template -bool SerializeInputStream(nsIInputStream* aStream, IPCStream& aValue, - M* aManager, bool aDelayedStart) { - MOZ_ASSERT(aStream); - MOZ_ASSERT(aManager); - - InputStreamParams params; - InputStreamHelper::SerializeInputStreamAsPipe(aStream, params, aDelayedStart, - aManager); - - if (params.type() == InputStreamParams::T__None) { - return false; - } - - aValue.stream() = params; - - return true; -} - class MIMEStreamHeaderVisitor final : public nsIHttpHeaderVisitor { public: explicit MIMEStreamHeaderVisitor( @@ -130,11 +51,9 @@ class MIMEStreamHeaderVisitor final : public nsIHttpHeaderVisitor { NS_IMPL_ISUPPORTS(MIMEStreamHeaderVisitor, nsIHttpHeaderVisitor) -template -bool SerializeLazyInputStream(nsIInputStream* aStream, IPCStream& aValue, - M* aManager) { +static bool SerializeLazyInputStream(nsIInputStream* aStream, + IPCStream& aValue) { MOZ_ASSERT(aStream); - MOZ_ASSERT(aManager); MOZ_ASSERT(XRE_IsParentProcess()); // If we're serializing a MIME stream, ensure we preserve header data which @@ -155,7 +74,7 @@ bool SerializeLazyInputStream(nsIInputStream* aStream, IPCStream& aValue, } if (dataStream) { IPCStream data; - if (!SerializeLazyInputStream(dataStream, data, aManager)) { + if (!SerializeLazyInputStream(dataStream, data)) { return false; } params.optionalStream().emplace(std::move(data.stream())); @@ -176,99 +95,66 @@ bool SerializeLazyInputStream(nsIInputStream* aStream, IPCStream& aValue, return true; } -template -bool SerializeInputStreamChild(nsIInputStream* aStream, M* aManager, - IPCStream* aValue, - Maybe* aOptionalValue, - bool aDelayedStart) { - MOZ_ASSERT(aStream); - MOZ_ASSERT(aManager); - MOZ_ASSERT(aValue || aOptionalValue); +} // anonymous namespace - nsCOMPtr serializable = - do_QueryInterface(aStream); - - if (serializable) { - if (aValue) { - return SerializeInputStreamWithFdsChild(serializable, *aValue, - aDelayedStart, aManager); - } - - return SerializeInputStreamWithFdsChild(serializable, aOptionalValue->ref(), - aDelayedStart, aManager); - } - - if (aValue) { - return SerializeInputStream(aStream, *aValue, aManager, aDelayedStart); - } - - return SerializeInputStream(aStream, aOptionalValue->ref(), aManager, - aDelayedStart); -} - -template -bool SerializeInputStreamParent(nsIInputStream* aStream, M* aManager, - IPCStream* aValue, - Maybe* aOptionalValue, - bool aDelayedStart) { - MOZ_ASSERT(aStream); - MOZ_ASSERT(aManager); - MOZ_ASSERT(aValue || aOptionalValue); - - // When requesting a delayed start stream from the parent process, serialize - // it as a remote lazy stream to avoid bloating payloads. - if (aDelayedStart && XRE_IsParentProcess()) { - if (aValue) { - return SerializeLazyInputStream(aStream, *aValue, aManager); - } - - return SerializeLazyInputStream(aStream, aOptionalValue->ref(), aManager); - } - - nsCOMPtr serializable = - do_QueryInterface(aStream); - - if (serializable) { - if (aValue) { - return SerializeInputStreamWithFdsParent(serializable, *aValue, - aDelayedStart, aManager); - } - - return SerializeInputStreamWithFdsParent( - serializable, aOptionalValue->ref(), aDelayedStart, aManager); - } - - if (aValue) { - return SerializeInputStream(aStream, *aValue, aManager, aDelayedStart); - } - - return SerializeInputStream(aStream, aOptionalValue->ref(), aManager, - aDelayedStart); -} - -// Returns false if the serialization should not proceed. This means that the -// inputStream is null. -bool NormalizeOptionalValue(nsIInputStream* aStream, IPCStream* aValue, - Maybe* aOptionalValue) { - if (aValue) { - // if aStream is null, we will crash when serializing. - return true; - } - - if (!aStream) { - aOptionalValue->reset(); +bool SerializeIPCStream(already_AddRefed aInputStream, + IPCStream& aValue, bool aAllowLazy) { + nsCOMPtr stream(std::move(aInputStream)); + if (!stream) { + MOZ_ASSERT_UNREACHABLE( + "Use the Maybe<...> overload to serialize optional nsIInputStreams"); return false; } - aOptionalValue->emplace(); + // When requesting a delayed start stream from the parent process, serialize + // it as a remote lazy stream to avoid bloating payloads. + if (aAllowLazy && XRE_IsParentProcess()) { + return SerializeLazyInputStream(stream, aValue); + } + + if (nsCOMPtr serializable = + do_QueryInterface(stream)) { + // If you change this size, please also update the payload size in + // test_reload_large_postdata.html. + const uint64_t kTooLargeStream = 1024 * 1024; + + uint32_t sizeUsed = 0; + serializable->Serialize(aValue.stream(), kTooLargeStream, &sizeUsed); + + MOZ_ASSERT(sizeUsed <= kTooLargeStream); + + if (aValue.stream().type() == InputStreamParams::T__None) { + MOZ_CRASH("Serialize failed!"); + } + return true; + } + + InputStreamHelper::SerializeInputStreamAsPipe(stream, aValue.stream()); + if (aValue.stream().type() == InputStreamParams::T__None) { + MOZ_ASSERT_UNREACHABLE("Serializing as a pipe failed"); + return false; + } return true; } -} // anonymous namespace +bool SerializeIPCStream(already_AddRefed aInputStream, + Maybe& aValue, bool aAllowLazy) { + nsCOMPtr stream(std::move(aInputStream)); + if (!stream) { + aValue.reset(); + return true; + } + + IPCStream value; + if (SerializeIPCStream(stream.forget(), value, aAllowLazy)) { + aValue = Some(value); + return true; + } + return false; +} already_AddRefed DeserializeIPCStream(const IPCStream& aValue) { - nsTArray fds; // NOTE: Unused, should be removed. - return InputStreamHelper::DeserializeInputStream(aValue.stream(), fds); + return InputStreamHelper::DeserializeInputStream(aValue.stream()); } already_AddRefed DeserializeIPCStream( @@ -280,250 +166,26 @@ already_AddRefed DeserializeIPCStream( return DeserializeIPCStream(aValue.ref()); } -AutoIPCStream::AutoIPCStream(bool aDelayedStart) - : mOptionalValue(&mInlineValue), mDelayedStart(aDelayedStart) {} +} // namespace mozilla::ipc -AutoIPCStream::AutoIPCStream(IPCStream& aTarget, bool aDelayedStart) - : mValue(&aTarget), mDelayedStart(aDelayedStart) {} +void IPC::ParamTraits::Write(IPC::MessageWriter* aWriter, + nsIInputStream* aParam) { + mozilla::Maybe stream; + if (!mozilla::ipc::SerializeIPCStream(do_AddRef(aParam), stream, + /* aAllowLazy */ true)) { + MOZ_CRASH("Failed to serialize nsIInputStream"); + } -AutoIPCStream::AutoIPCStream(Maybe& aTarget, bool aDelayedStart) - : mOptionalValue(&aTarget), mDelayedStart(aDelayedStart) { - mOptionalValue->reset(); + WriteParam(aWriter, stream); } -AutoIPCStream::~AutoIPCStream() { MOZ_ASSERT(mValue || mOptionalValue); } - -bool AutoIPCStream::Serialize(nsIInputStream* aStream, - dom::ContentChild* aManager) { - MOZ_ASSERT(aStream || !mValue); - MOZ_ASSERT(aManager); - MOZ_ASSERT(mValue || mOptionalValue); - MOZ_ASSERT(!mTaken); - MOZ_ASSERT(!IsSet()); - - // If NormalizeOptionalValue returns false, we don't have to proceed. - if (!NormalizeOptionalValue(aStream, mValue, mOptionalValue)) { - return true; - } - - if (!SerializeInputStreamChild(aStream, aManager, mValue, mOptionalValue, - mDelayedStart)) { - MOZ_CRASH("IPCStream creation failed!"); - } - - return true; -} - -bool AutoIPCStream::Serialize(nsIInputStream* aStream, - PBackgroundChild* aManager) { - MOZ_ASSERT(aStream || !mValue); - MOZ_ASSERT(aManager); - MOZ_ASSERT(mValue || mOptionalValue); - MOZ_ASSERT(!mTaken); - MOZ_ASSERT(!IsSet()); - - // If NormalizeOptionalValue returns false, we don't have to proceed. - if (!NormalizeOptionalValue(aStream, mValue, mOptionalValue)) { - return true; - } - - BackgroundChildImpl* impl = static_cast(aManager); - if (!SerializeInputStreamChild(aStream, impl, mValue, mOptionalValue, - mDelayedStart)) { - MOZ_CRASH("IPCStream creation failed!"); - } - - return true; -} - -bool AutoIPCStream::Serialize(nsIInputStream* aStream, - net::SocketProcessChild* aManager) { - MOZ_ASSERT(aStream || !mValue); - MOZ_ASSERT(aManager); - MOZ_ASSERT(mValue || mOptionalValue); - MOZ_ASSERT(!mTaken); - MOZ_ASSERT(!IsSet()); - - // If NormalizeOptionalValue returns false, we don't have to proceed. - if (!NormalizeOptionalValue(aStream, mValue, mOptionalValue)) { - return true; - } - - if (!SerializeInputStreamChild(aStream, aManager, mValue, mOptionalValue, - mDelayedStart)) { - MOZ_CRASH("IPCStream creation failed!"); - } - - return true; -} - -bool AutoIPCStream::Serialize(nsIInputStream* aStream, - dom::ContentParent* aManager) { - MOZ_ASSERT(aStream || !mValue); - MOZ_ASSERT(aManager); - MOZ_ASSERT(mValue || mOptionalValue); - MOZ_ASSERT(!mTaken); - MOZ_ASSERT(!IsSet()); - - // If NormalizeOptionalValue returns false, we don't have to proceed. - if (!NormalizeOptionalValue(aStream, mValue, mOptionalValue)) { - return true; - } - - if (!SerializeInputStreamParent(aStream, aManager, mValue, mOptionalValue, - mDelayedStart)) { - return false; - } - - return true; -} - -bool AutoIPCStream::Serialize(nsIInputStream* aStream, - PBackgroundParent* aManager) { - MOZ_ASSERT(aStream || !mValue); - MOZ_ASSERT(aManager); - MOZ_ASSERT(mValue || mOptionalValue); - MOZ_ASSERT(!mTaken); - MOZ_ASSERT(!IsSet()); - - // If NormalizeOptionalValue returns false, we don't have to proceed. - if (!NormalizeOptionalValue(aStream, mValue, mOptionalValue)) { - return true; - } - - BackgroundParentImpl* impl = static_cast(aManager); - if (!SerializeInputStreamParent(aStream, impl, mValue, mOptionalValue, - mDelayedStart)) { - return false; - } - - return true; -} - -bool AutoIPCStream::Serialize(nsIInputStream* aStream, - net::SocketProcessParent* aManager) { - MOZ_ASSERT(aStream || !mValue); - MOZ_ASSERT(aManager); - MOZ_ASSERT(mValue || mOptionalValue); - MOZ_ASSERT(!mTaken); - MOZ_ASSERT(!IsSet()); - - // If NormalizeOptionalValue returns false, we don't have to proceed. - if (!NormalizeOptionalValue(aStream, mValue, mOptionalValue)) { - return true; - } - - if (!SerializeInputStreamParent(aStream, aManager, mValue, mOptionalValue, - mDelayedStart)) { - return false; - } - - return true; -} - -bool AutoIPCStream::IsSet() const { - MOZ_ASSERT(mValue || mOptionalValue); - if (mValue) { - return mValue->stream().type() != InputStreamParams::T__None; - } else { - return mOptionalValue->isSome() && - mOptionalValue->ref().stream().type() != InputStreamParams::T__None; - } -} - -IPCStream& AutoIPCStream::TakeValue() { - MOZ_ASSERT(mValue || mOptionalValue); - MOZ_ASSERT(!mTaken); - MOZ_ASSERT(IsSet()); - - mTaken = true; - - if (mValue) { - return *mValue; - } - - IPCStream& value = mOptionalValue->ref(); - return value; -} - -Maybe& AutoIPCStream::TakeOptionalValue() { - MOZ_ASSERT(!mTaken); - MOZ_ASSERT(!mValue); - MOZ_ASSERT(mOptionalValue); - mTaken = true; - return *mOptionalValue; -} - -void IPDLParamTraits::Write(IPC::MessageWriter* aWriter, - IProtocol* aActor, - nsIInputStream* aParam) { - auto autoStream = MakeRefPtr(/* aDelayedStart */ true); - - bool ok = false; - bool found = false; - - // We can only serialize our nsIInputStream if it's going to be sent over one - // of the protocols we support, or a protocol which is managed by one of the - // protocols we support. - IProtocol* actor = aActor; - while (!found && actor) { - switch (actor->GetProtocolId()) { - case PContentMsgStart: - if (actor->GetSide() == mozilla::ipc::ParentSide) { - ok = autoStream->Serialize( - aParam, static_cast(actor)); - } else { - MOZ_RELEASE_ASSERT(actor->GetSide() == mozilla::ipc::ChildSide); - ok = autoStream->Serialize( - aParam, static_cast(actor)); - } - found = true; - break; - case PBackgroundMsgStart: - if (actor->GetSide() == mozilla::ipc::ParentSide) { - ok = autoStream->Serialize( - aParam, static_cast(actor)); - } else { - MOZ_RELEASE_ASSERT(actor->GetSide() == mozilla::ipc::ChildSide); - ok = autoStream->Serialize( - aParam, static_cast(actor)); - } - found = true; - break; - default: - break; - } - - // Try the actor's manager. - actor = actor->Manager(); - } - - if (!found) { - aActor->FatalError( - "Attempt to send nsIInputStream over an unsupported ipdl protocol"); - } - MOZ_RELEASE_ASSERT(ok, "Failed to serialize nsIInputStream"); - - WriteIPDLParam(aWriter, aActor, autoStream->TakeOptionalValue()); - - // Dispatch the autoStream to an async runnable, so that we guarantee it - // outlives this callstack, and doesn't shut down any actors we created - // until after we've finished sending the current message. - NS_ProxyRelease("IPDLParamTraits::Write::autoStream", - NS_GetCurrentThread(), autoStream.forget(), true); -} - -bool IPDLParamTraits::Read(IPC::MessageReader* aReader, - IProtocol* aActor, - RefPtr* aResult) { +bool IPC::ParamTraits::Read(IPC::MessageReader* aReader, + RefPtr* aResult) { mozilla::Maybe ipcStream; - if (!ReadIPDLParam(aReader, aActor, &ipcStream)) { + if (!ReadParam(aReader, &ipcStream)) { return false; } *aResult = mozilla::ipc::DeserializeIPCStream(ipcStream); return true; } - -} // namespace ipc -} // namespace mozilla diff --git a/ipc/glue/IPCStreamUtils.h b/ipc/glue/IPCStreamUtils.h index c7dd7c7baad7..c681f7cf1a2f 100644 --- a/ipc/glue/IPCStreamUtils.h +++ b/ipc/glue/IPCStreamUtils.h @@ -11,22 +11,23 @@ #include "nsCOMPtr.h" #include "nsIInputStream.h" -namespace mozilla { +namespace mozilla::ipc { -namespace dom { -class ContentChild; -class ContentParent; -} // namespace dom +// Serialize an IPCStream to be sent over IPC fallibly. +// +// If |aAllowLazy| is true the stream may be serialized as a +// RemoteLazyInputStream when being sent from child to parent. +// +// ParamTraits may be used instead if serialization cannot be +// fallible. +[[nodiscard]] bool SerializeIPCStream( + already_AddRefed aInputStream, IPCStream& aValue, + bool aAllowLazy); -namespace net { -class SocketProcessParent; -class SocketProcessChild; -} // namespace net - -namespace ipc { - -class PBackgroundChild; -class PBackgroundParent; +// If serialization fails, `aValue` will be initialized to `Nothing()`, so this +// return value is safe to ignore. +bool SerializeIPCStream(already_AddRefed aInputStream, + Maybe& aValue, bool aAllowLazy); // Deserialize an IPCStream received from an actor call. These methods // work in both the child and parent. @@ -35,184 +36,16 @@ already_AddRefed DeserializeIPCStream(const IPCStream& aValue); already_AddRefed DeserializeIPCStream( const Maybe& aValue); -// RAII helper class that serializes an nsIInputStream into an IPCStream struct. -// Any file descriptor actors are automatically managed correctly. -// -// Here is a simple example: -// -// // in ipdl file -// Protocol PMyStuff -// { -// parent: -// async DoStuff(IPCStream aStream); -// child: -// async StuffDone(IPCStream aStream); -// }; -// -// // in child c++ code -// void CallDoStuff(PMyStuffChild* aActor, nsIInputStream* aStream) -// { -// AutoIPCStream autoStream; -// autoStream.Serialize(aStream, aActor->Manager()); -// aActor->SendDoStuff(autoStream.TakeValue()); -// } -// -// // in parent c++ code -// bool -// MyStuffParent::RecvDoStuff(const IPCStream& aIPCStream) { -// nsCOMPtr stream = DeserializeIPCStream(aIPCStream); -// // Do something with stream... -// -// // You can also serialize streams from parent-to-child. -// AutoIPCStream anotherStream; -// anotherStream.Serialize(mFileStream, Manager()); -// SendStuffDone(anotherStream.TakeValue()); -// } -// -// The AutoIPCStream RAII class may also be used if your stream is embedded -// in a more complex IPDL structure. In this case you attach the AutoIPCStream -// to the embedded IPCStream and call TakeValue() after you pass the structure. -// For example: -// -// // in ipdl file -// struct Stuff -// { -// IPCStream stream; -// nsCString name; -// }; -// -// Protocol PMyStuff -// { -// parent: -// async DoStuff(Stuff aStream); -// }; -// -// // in child c++ code -// void CallDoStuff(PMyStuffChild* aActor, nsIInputStream* aStream) -// { -// Stuff stuff; -// AutoIPCStream autoStream(stuff.stream()); // attach to IPCStream here -// autoStream.Serialize(aStream, aActor->Manager()); -// aActor->SendDoStuff(stuff); -// autoStream.TakeValue(); // call take value after send -// } -// -// // in parent c++ code -// bool -// MyStuffParent::RecvDoStuff(const Stuff& aStuff) { -// nsCOMPtr stream = DeserializeIPCStream(aStuff.stream()); -// /* do something with the nsIInputStream */ -// } -// -// Note: This example is about child-to-parent inputStream, but AutoIPCStream -// works also parent-to-child. -// -// The AutoIPCStream class also supports Maybe values. As long as -// you did not initialize the object with a non-optional IPCStream, you can call -// TakeOptionalValue() instead. -// -// The AutoIPCStream class can also be used to serialize nsIInputStream objects -// on the parent side to send to the child. -// -// Like SerializeInputStream(), the AutoIPCStream will crash if -// serialization cannot be completed. -// -// NOTE: This is not a MOZ_STACK_CLASS so that it can be more easily integrated -// with complex ipdl structures. For example, you may want to create an -// array of RAII AutoIPCStream objects or build your own wrapping -// RAII object to handle other actors that need to be cleaned up. -class AutoIPCStream { - public: - // Implicitly create an Maybe value. Either - // TakeValue() or TakeOptionalValue() can be used. - explicit AutoIPCStream(bool aDelayedStart = false); +} // namespace mozilla::ipc - // Wrap an existing IPCStream. Only TakeValue() may be - // used. If a nullptr nsIInputStream is passed to SerializeOrSend() then - // a crash will be forced. - explicit AutoIPCStream(IPCStream& aTarget, bool aDelayedStart = false); - - // Wrap an existing Maybe. Either TakeValue() - // or TakeOptionalValue can be used. - explicit AutoIPCStream(Maybe& aTarget, bool aDelayedStart = false); - - AutoIPCStream(const AutoIPCStream&) = delete; - AutoIPCStream(AutoIPCStream&&) = delete; - - AutoIPCStream& operator=(const AutoIPCStream&) = delete; - AutoIPCStream& operator=(AutoIPCStream&&) = delete; - - ~AutoIPCStream(); - - // Serialize the input stream or create a SendStream actor using the PContent - // manager. If neither of these succeed, then crash. This should only be - // used on the main thread. - bool Serialize(nsIInputStream* aStream, dom::ContentChild* aManager); - - // Serialize the input stream or create a SendStream actor using the - // PBackground manager. If neither of these succeed, then crash. This can - // be called on the main thread or Worker threads. - bool Serialize(nsIInputStream* aStream, PBackgroundChild* aManager); - - // Serialize the input stream or create a SendStream actor using the - // SocketProcess manager. If neither of these succeed, then crash. This - // should only be used on the main thread. - bool Serialize(nsIInputStream* aStream, net::SocketProcessChild* aManager); - - // Serialize the input stream. - [[nodiscard]] bool Serialize(nsIInputStream* aStream, - dom::ContentParent* aManager); - - // Serialize the input stream. - [[nodiscard]] bool Serialize(nsIInputStream* aStream, - PBackgroundParent* aManager); - - // Serialize the input stream. - [[nodiscard]] bool Serialize(nsIInputStream* aStream, - net::SocketProcessParent* aManager); - - bool Serialize(nsIInputStream* aStream); - - // Get the IPCStream as a non-optional value. This will - // assert if a stream has not been serialized or if it has already been taken. - // This should only be called if the value is being, or has already been, sent - // to the other side. - IPCStream& TakeValue(); - - // Get the Maybe value. This will assert if the value has already - // been taken. This should only be called if the value is being, or has - // already been, sent to the other side. - Maybe& TakeOptionalValue(); - - private: - bool IsSet() const; - - Maybe mInlineValue; - IPCStream* const mValue = nullptr; - Maybe* const mOptionalValue = nullptr; - bool mTaken = false; - const bool mDelayedStart; -}; - -class HoldIPCStream final : public AutoIPCStream { - public: - NS_INLINE_DECL_REFCOUNTING(HoldIPCStream) - - using AutoIPCStream::AutoIPCStream; - - private: - ~HoldIPCStream() = default; -}; +namespace IPC { template <> -struct IPDLParamTraits { - static void Write(IPC::MessageWriter* aWriter, IProtocol* aActor, - nsIInputStream* aParam); - static bool Read(IPC::MessageReader* aReader, IProtocol* aActor, - RefPtr* aResult); +struct ParamTraits { + static void Write(MessageWriter* aWriter, nsIInputStream* aParam); + static bool Read(MessageReader* aReader, RefPtr* aResult); }; -} // namespace ipc -} // namespace mozilla +} // namespace IPC #endif // mozilla_ipc_IPCStreamUtils_h diff --git a/ipc/glue/InputStreamUtils.cpp b/ipc/glue/InputStreamUtils.cpp index 3ea368776793..46fd7477effa 100644 --- a/ipc/glue/InputStreamUtils.cpp +++ b/ipc/glue/InputStreamUtils.cpp @@ -42,14 +42,11 @@ using namespace mozilla::dom; namespace mozilla { namespace ipc { -namespace { - -template -void SerializeInputStreamInternal(nsIInputStream* aInputStream, - InputStreamParams& aParams, - nsTArray& aFileDescriptors, - bool aDelayedStart, uint32_t aMaxSize, - uint32_t* aSizeUsed, M* aManager) { +void InputStreamHelper::SerializedComplexity(nsIInputStream* aInputStream, + uint32_t aMaxSize, + uint32_t* aSizeUsed, + uint32_t* aPipes, + uint32_t* aTransferables) { MOZ_ASSERT(aInputStream); nsCOMPtr serializable = @@ -58,18 +55,31 @@ void SerializeInputStreamInternal(nsIInputStream* aInputStream, MOZ_CRASH("Input stream is not serializable!"); } - serializable->Serialize(aParams, aFileDescriptors, aDelayedStart, aMaxSize, - aSizeUsed, aManager); + serializable->SerializedComplexity(aMaxSize, aSizeUsed, aPipes, + aTransferables); +} + +void InputStreamHelper::SerializeInputStream(nsIInputStream* aInputStream, + InputStreamParams& aParams, + uint32_t aMaxSize, + uint32_t* aSizeUsed) { + MOZ_ASSERT(aInputStream); + + nsCOMPtr serializable = + do_QueryInterface(aInputStream); + if (!serializable) { + MOZ_CRASH("Input stream is not serializable!"); + } + + serializable->Serialize(aParams, aMaxSize, aSizeUsed); if (aParams.type() == InputStreamParams::T__None) { MOZ_CRASH("Serialize failed!"); } } -template -void SerializeInputStreamAsPipeInternal(nsIInputStream* aInputStream, - InputStreamParams& aParams, - bool aDelayedStart, M* aManager) { +void InputStreamHelper::SerializeInputStreamAsPipe(nsIInputStream* aInputStream, + InputStreamParams& aParams) { MOZ_ASSERT(aInputStream); // Let's try to take the length using InputStreamLengthHelper. If the length @@ -104,60 +114,8 @@ void SerializeInputStreamAsPipeInternal(nsIInputStream* aInputStream, } } -} // namespace - -void InputStreamHelper::SerializedComplexity(nsIInputStream* aInputStream, - uint32_t aMaxSize, - uint32_t* aSizeUsed, - uint32_t* aPipes, - uint32_t* aTransferables) { - MOZ_ASSERT(aInputStream); - - nsCOMPtr serializable = - do_QueryInterface(aInputStream); - if (!serializable) { - MOZ_CRASH("Input stream is not serializable!"); - } - - serializable->SerializedComplexity(aMaxSize, aSizeUsed, aPipes, - aTransferables); -} - -void InputStreamHelper::SerializeInputStream( - nsIInputStream* aInputStream, InputStreamParams& aParams, - nsTArray& aFileDescriptors, bool aDelayedStart, - uint32_t aMaxSize, uint32_t* aSizeUsed, - ParentToChildStreamActorManager* aManager) { - SerializeInputStreamInternal(aInputStream, aParams, aFileDescriptors, - aDelayedStart, aMaxSize, aSizeUsed, aManager); -} - -void InputStreamHelper::SerializeInputStream( - nsIInputStream* aInputStream, InputStreamParams& aParams, - nsTArray& aFileDescriptors, bool aDelayedStart, - uint32_t aMaxSize, uint32_t* aSizeUsed, - ChildToParentStreamActorManager* aManager) { - SerializeInputStreamInternal(aInputStream, aParams, aFileDescriptors, - aDelayedStart, aMaxSize, aSizeUsed, aManager); -} - -void InputStreamHelper::SerializeInputStreamAsPipe( - nsIInputStream* aInputStream, InputStreamParams& aParams, - bool aDelayedStart, ParentToChildStreamActorManager* aManager) { - SerializeInputStreamAsPipeInternal(aInputStream, aParams, aDelayedStart, - aManager); -} - -void InputStreamHelper::SerializeInputStreamAsPipe( - nsIInputStream* aInputStream, InputStreamParams& aParams, - bool aDelayedStart, ChildToParentStreamActorManager* aManager) { - SerializeInputStreamAsPipeInternal(aInputStream, aParams, aDelayedStart, - aManager); -} - already_AddRefed InputStreamHelper::DeserializeInputStream( - const InputStreamParams& aParams, - const nsTArray& aFileDescriptors) { + const InputStreamParams& aParams) { if (aParams.type() == InputStreamParams::TRemoteLazyInputStreamParams) { const RemoteLazyInputStreamParams& params = aParams.get_RemoteLazyInputStreamParams(); @@ -238,7 +196,7 @@ already_AddRefed InputStreamHelper::DeserializeInputStream( MOZ_ASSERT(serializable); - if (!serializable->Deserialize(aParams, aFileDescriptors)) { + if (!serializable->Deserialize(aParams)) { MOZ_ASSERT(false, "Deserialize failed!"); return nullptr; } diff --git a/ipc/glue/InputStreamUtils.h b/ipc/glue/InputStreamUtils.h index 71952e69c0e6..27a65b02e20c 100644 --- a/ipc/glue/InputStreamUtils.h +++ b/ipc/glue/InputStreamUtils.h @@ -17,12 +17,8 @@ namespace ipc { class FileDescriptor; -// TODO: These interfaces are no longer necessary and should be removed. -class ParentToChildStreamActorManager {}; - -class ChildToParentStreamActorManager {}; - -// If you want to serialize an inputStream, please use AutoIPCStream. +// If you want to serialize an inputStream, please use SerializeIPCStream or +// nsIInputStream directly. class InputStreamHelper { public: static void SerializedComplexity(nsIInputStream* aInputStream, @@ -33,40 +29,19 @@ class InputStreamHelper { // The manager is needed in case a stream needs to serialize itself as // IPCRemoteStream. // The stream serializes itself fully only if the resulting IPC message will - // be smaller than |aMaxSize|. Otherwise, the stream serializes itself as - // IPCRemoteStream, and, its content will be sent to the other side of the IPC - // pipe in chunks. This sending can start immediatelly or at the first read - // based on the value of |aDelayedStart|. The IPC message size is returned - // into |aSizeUsed|. - // XXX: The aManager and aFileDescriptors arguments are no longer necessary - // and should be removed. + // be smaller than |aMaxSize|. Otherwise, the stream serializes itself as a + // DataPipe, and, its content will be sent to the other side of the IPC pipe + // in chunks. The IPC message size is returned into |aSizeUsed|. static void SerializeInputStream(nsIInputStream* aInputStream, InputStreamParams& aParams, - nsTArray& aFileDescriptors, - bool aDelayedStart, uint32_t aMaxSize, - uint32_t* aSizeUsed, - ParentToChildStreamActorManager* aManager); + uint32_t aMaxSize, uint32_t* aSizeUsed); - static void SerializeInputStream(nsIInputStream* aInputStream, - InputStreamParams& aParams, - nsTArray& aFileDescriptors, - bool aDelayedStart, uint32_t aMaxSize, - uint32_t* aSizeUsed, - ChildToParentStreamActorManager* aManager); - - // When a stream wants to serialize itself as IPCRemoteStream, it uses one of - // these methods. - static void SerializeInputStreamAsPipe( - nsIInputStream* aInputStream, InputStreamParams& aParams, - bool aDelayedStart, ParentToChildStreamActorManager* aManager); - - static void SerializeInputStreamAsPipe( - nsIInputStream* aInputStream, InputStreamParams& aParams, - bool aDelayedStart, ChildToParentStreamActorManager* aManager); + // When a stream wants to serialize itself as a DataPipe, it uses this method. + static void SerializeInputStreamAsPipe(nsIInputStream* aInputStream, + InputStreamParams& aParams); static already_AddRefed DeserializeInputStream( - const InputStreamParams& aParams, - const nsTArray& aFileDescriptors); + const InputStreamParams& aParams); }; } // namespace ipc diff --git a/ipc/glue/nsIIPCSerializableInputStream.h b/ipc/glue/nsIIPCSerializableInputStream.h index 6d7e6e49035a..acc7594f66c2 100644 --- a/ipc/glue/nsIIPCSerializableInputStream.h +++ b/ipc/glue/nsIIPCSerializableInputStream.h @@ -17,8 +17,6 @@ namespace ipc { class FileDescriptor; class InputStreamParams; -class ChildToParentStreamActorManager; -class ParentToChildStreamActorManager; } // namespace ipc @@ -33,8 +31,6 @@ class ParentToChildStreamActorManager; class NS_NO_VTABLE nsIIPCSerializableInputStream : public nsISupports { public: - typedef nsTArray FileDescriptorArray; - NS_DECLARE_STATIC_IID_ACCESSOR(NS_IIPCSERIALIZABLEINPUTSTREAM_IID) // Determine the serialized complexity of this input stream, initializing @@ -70,39 +66,23 @@ class NS_NO_VTABLE nsIIPCSerializableInputStream : public nsISupports { uint32_t* aPipes, uint32_t* aTransferables) = 0; - virtual void Serialize( - mozilla::ipc::InputStreamParams& aParams, - FileDescriptorArray& aFileDescriptors, bool aDelayedStart, - uint32_t aMaxSize, uint32_t* aSizeUsed, - mozilla::ipc::ParentToChildStreamActorManager* aManager) = 0; + virtual void Serialize(mozilla::ipc::InputStreamParams& aParams, + uint32_t aMaxSize, uint32_t* aSizeUsed) = 0; - virtual void Serialize( - mozilla::ipc::InputStreamParams& aParams, - FileDescriptorArray& aFileDescriptors, bool aDelayedStart, - uint32_t aMaxSize, uint32_t* aSizeUsed, - mozilla::ipc::ChildToParentStreamActorManager* aManager) = 0; - - virtual bool Deserialize(const mozilla::ipc::InputStreamParams& aParams, - const FileDescriptorArray& aFileDescriptors) = 0; + virtual bool Deserialize(const mozilla::ipc::InputStreamParams& aParams) = 0; }; NS_DEFINE_STATIC_IID_ACCESSOR(nsIIPCSerializableInputStream, NS_IIPCSERIALIZABLEINPUTSTREAM_IID) -#define NS_DECL_NSIIPCSERIALIZABLEINPUTSTREAM \ - virtual void SerializedComplexity(uint32_t aMaxSize, uint32_t* aSizeUsed, \ - uint32_t* aPipes, \ - uint32_t* aTransferrables) override; \ - virtual void Serialize( \ - mozilla::ipc::InputStreamParams&, FileDescriptorArray&, bool, uint32_t, \ - uint32_t*, mozilla::ipc::ParentToChildStreamActorManager*) override; \ - \ - virtual void Serialize( \ - mozilla::ipc::InputStreamParams&, FileDescriptorArray&, bool, uint32_t, \ - uint32_t*, mozilla::ipc::ChildToParentStreamActorManager*) override; \ - \ - virtual bool Deserialize(const mozilla::ipc::InputStreamParams&, \ - const FileDescriptorArray&) override; +#define NS_DECL_NSIIPCSERIALIZABLEINPUTSTREAM \ + virtual void SerializedComplexity(uint32_t aMaxSize, uint32_t* aSizeUsed, \ + uint32_t* aPipes, \ + uint32_t* aTransferrables) override; \ + virtual void Serialize(mozilla::ipc::InputStreamParams&, uint32_t, \ + uint32_t*) override; \ + \ + virtual bool Deserialize(const mozilla::ipc::InputStreamParams&) override; #define NS_FORWARD_NSIIPCSERIALIZABLEINPUTSTREAM(_to) \ virtual void SerializedComplexity(uint32_t aMaxSize, uint32_t* aSizeUsed, \ @@ -111,28 +91,14 @@ NS_DEFINE_STATIC_IID_ACCESSOR(nsIIPCSerializableInputStream, _to SerializedComplexity(aMaxSize, aSizeUsed, aPipes, aTransferables); \ }; \ \ - virtual void Serialize( \ - mozilla::ipc::InputStreamParams& aParams, \ - FileDescriptorArray& aFileDescriptors, bool aDelayedStart, \ - uint32_t aMaxSize, uint32_t* aSizeUsed, \ - mozilla::ipc::ParentToChildStreamActorManager* aManager) override { \ - _to Serialize(aParams, aFileDescriptors, aDelayedStart, aMaxSize, \ - aSizeUsed, aManager); \ + virtual void Serialize(mozilla::ipc::InputStreamParams& aParams, \ + uint32_t aMaxSize, uint32_t* aSizeUsed) override { \ + _to Serialize(aParams, aMaxSize, aSizeUsed); \ } \ \ - virtual void Serialize( \ - mozilla::ipc::InputStreamParams& aParams, \ - FileDescriptorArray& aFileDescriptors, bool aDelayedStart, \ - uint32_t aMaxSize, uint32_t* aSizeUsed, \ - mozilla::ipc::ChildToParentStreamActorManager* aManager) override { \ - _to Serialize(aParams, aFileDescriptors, aDelayedStart, aMaxSize, \ - aSizeUsed, aManager); \ - } \ - \ - virtual bool Deserialize(const mozilla::ipc::InputStreamParams& aParams, \ - const FileDescriptorArray& aFileDescriptors) \ + virtual bool Deserialize(const mozilla::ipc::InputStreamParams& aParams) \ override { \ - return _to Deserialize(aParams, aFileDescriptors); \ + return _to Deserialize(aParams); \ } #endif // mozilla_ipc_nsIIPCSerializableInputStream_h diff --git a/netwerk/base/nsBufferedStreams.cpp b/netwerk/base/nsBufferedStreams.cpp index 4241338fee52..edba05644194 100644 --- a/netwerk/base/nsBufferedStreams.cpp +++ b/netwerk/base/nsBufferedStreams.cpp @@ -599,26 +599,8 @@ void nsBufferedInputStream::SerializedComplexity(uint32_t aMaxSize, } } -void nsBufferedInputStream::Serialize( - InputStreamParams& aParams, FileDescriptorArray& aFileDescriptors, - bool aDelayedStart, uint32_t aMaxSize, uint32_t* aSizeUsed, - mozilla::ipc::ParentToChildStreamActorManager* aManager) { - SerializeInternal(aParams, aFileDescriptors, aDelayedStart, aMaxSize, - aSizeUsed, aManager); -} - -void nsBufferedInputStream::Serialize( - InputStreamParams& aParams, FileDescriptorArray& aFileDescriptors, - bool aDelayedStart, uint32_t aMaxSize, uint32_t* aSizeUsed, - mozilla::ipc::ChildToParentStreamActorManager* aManager) { - SerializeInternal(aParams, aFileDescriptors, aDelayedStart, aMaxSize, - aSizeUsed, aManager); -} - -template -void nsBufferedInputStream::SerializeInternal( - InputStreamParams& aParams, FileDescriptorArray& aFileDescriptors, - bool aDelayedStart, uint32_t aMaxSize, uint32_t* aSizeUsed, M* aManager) { +void nsBufferedInputStream::Serialize(InputStreamParams& aParams, + uint32_t aMaxSize, uint32_t* aSizeUsed) { MOZ_ASSERT(aSizeUsed); *aSizeUsed = 0; @@ -629,9 +611,8 @@ void nsBufferedInputStream::SerializeInternal( MOZ_ASSERT(stream); InputStreamParams wrappedParams; - InputStreamHelper::SerializeInputStream(stream, wrappedParams, - aFileDescriptors, aDelayedStart, - aMaxSize, aSizeUsed, aManager); + InputStreamHelper::SerializeInputStream(stream, wrappedParams, aMaxSize, + aSizeUsed); params.optionalStream().emplace(wrappedParams); } @@ -641,9 +622,7 @@ void nsBufferedInputStream::SerializeInternal( aParams = params; } -bool nsBufferedInputStream::Deserialize( - const InputStreamParams& aParams, - const FileDescriptorArray& aFileDescriptors) { +bool nsBufferedInputStream::Deserialize(const InputStreamParams& aParams) { if (aParams.type() != InputStreamParams::TBufferedInputStreamParams) { NS_ERROR("Received unknown parameters from the other process!"); return false; @@ -655,8 +634,7 @@ bool nsBufferedInputStream::Deserialize( nsCOMPtr stream; if (wrappedParams.isSome()) { - stream = InputStreamHelper::DeserializeInputStream(wrappedParams.ref(), - aFileDescriptors); + stream = InputStreamHelper::DeserializeInputStream(wrappedParams.ref()); if (!stream) { NS_WARNING("Failed to deserialize wrapped stream!"); return false; diff --git a/netwerk/base/nsBufferedStreams.h b/netwerk/base/nsBufferedStreams.h index 50ac76b72b6c..38ce0c3a7260 100644 --- a/netwerk/base/nsBufferedStreams.h +++ b/netwerk/base/nsBufferedStreams.h @@ -112,12 +112,6 @@ class nsBufferedInputStream final : public nsBufferedStream, protected: virtual ~nsBufferedInputStream() = default; - template - void SerializeInternal(mozilla::ipc::InputStreamParams& aParams, - FileDescriptorArray& aFileDescriptors, - bool aDelayedStart, uint32_t aMaxSize, - uint32_t* aSizeUsed, M* aManager); - NS_IMETHOD Fill() override; NS_IMETHOD Flush() override { return NS_OK; } // no-op for input streams diff --git a/netwerk/base/nsFileStreams.cpp b/netwerk/base/nsFileStreams.cpp index df732821e52e..2987b2eb9c3c 100644 --- a/netwerk/base/nsFileStreams.cpp +++ b/netwerk/base/nsFileStreams.cpp @@ -547,29 +547,11 @@ void nsFileInputStream::SerializedComplexity(uint32_t aMaxSize, *aTransferables = 1; } -void nsFileInputStream::Serialize(InputStreamParams& aParams, - FileDescriptorArray& aFileDescriptors, - bool aDelayedStart, uint32_t aMaxSize, - uint32_t* aSizeUsed, - ParentToChildStreamActorManager* aManager) { +void nsFileInputStream::Serialize(InputStreamParams& aParams, uint32_t aMaxSize, + uint32_t* aSizeUsed) { MOZ_ASSERT(aSizeUsed); *aSizeUsed = 0; - SerializeInternal(aParams); -} - -void nsFileInputStream::Serialize(InputStreamParams& aParams, - FileDescriptorArray& aFileDescriptors, - bool aDelayedStart, uint32_t aMaxSize, - uint32_t* aSizeUsed, - ChildToParentStreamActorManager* aManager) { - MOZ_ASSERT(aSizeUsed); - *aSizeUsed = 0; - - SerializeInternal(aParams); -} - -void nsFileInputStream::SerializeInternal(InputStreamParams& aParams) { FileInputStreamParams params; if (NS_SUCCEEDED(DoPendingOpen())) { @@ -600,9 +582,7 @@ void nsFileInputStream::SerializeInternal(InputStreamParams& aParams) { aParams = params; } -bool nsFileInputStream::Deserialize( - const InputStreamParams& aParams, - const FileDescriptorArray& aFileDescriptors) { +bool nsFileInputStream::Deserialize(const InputStreamParams& aParams) { NS_ASSERTION(!mFD, "Already have a file descriptor?!"); NS_ASSERTION(mState == nsFileStreamBase::eUnitialized, "Deferring open?!"); NS_ASSERTION(!mFile, "Should never have a file here!"); diff --git a/netwerk/base/nsFileStreams.h b/netwerk/base/nsFileStreams.h index a9b8a0ed13bc..581063fe61c3 100644 --- a/netwerk/base/nsFileStreams.h +++ b/netwerk/base/nsFileStreams.h @@ -155,8 +155,6 @@ class nsFileInputStream : public nsFileStreamBase, protected: virtual ~nsFileInputStream() = default; - void SerializeInternal(mozilla::ipc::InputStreamParams& aParams); - nsresult SeekInternal(int32_t aWhence, int64_t aOffset, bool aClearBuf = true); diff --git a/netwerk/base/nsMIMEInputStream.cpp b/netwerk/base/nsMIMEInputStream.cpp index 5a283c1040d2..903812398904 100644 --- a/netwerk/base/nsMIMEInputStream.cpp +++ b/netwerk/base/nsMIMEInputStream.cpp @@ -59,12 +59,6 @@ class nsMIMEInputStream : public nsIMIMEInputStream, private: void InitStreams(); - template - void SerializeInternal(InputStreamParams& aParams, - FileDescriptorArray& aFileDescriptors, - bool aDelayedStart, uint32_t aMaxSize, - uint32_t* aSizeUsed, M* aManager); - struct MOZ_STACK_CLASS ReadSegmentsState { nsCOMPtr mThisStream; nsWriteSegmentFun mWriter{nullptr}; @@ -340,27 +334,8 @@ void nsMIMEInputStream::SerializedComplexity(uint32_t aMaxSize, } } -void nsMIMEInputStream::Serialize( - InputStreamParams& aParams, FileDescriptorArray& aFileDescriptors, - bool aDelayedStart, uint32_t aMaxSize, uint32_t* aSizeUsed, - mozilla::ipc::ParentToChildStreamActorManager* aManager) { - SerializeInternal(aParams, aFileDescriptors, aDelayedStart, aMaxSize, - aSizeUsed, aManager); -} - -void nsMIMEInputStream::Serialize( - InputStreamParams& aParams, FileDescriptorArray& aFileDescriptors, - bool aDelayedStart, uint32_t aMaxSize, uint32_t* aSizeUsed, - mozilla::ipc::ChildToParentStreamActorManager* aManager) { - SerializeInternal(aParams, aFileDescriptors, aDelayedStart, aMaxSize, - aSizeUsed, aManager); -} - -template -void nsMIMEInputStream::SerializeInternal(InputStreamParams& aParams, - FileDescriptorArray& aFileDescriptors, - bool aDelayedStart, uint32_t aMaxSize, - uint32_t* aSizeUsed, M* aManager) { +void nsMIMEInputStream::Serialize(InputStreamParams& aParams, uint32_t aMaxSize, + uint32_t* aSizeUsed) { MOZ_ASSERT(aSizeUsed); *aSizeUsed = 0; @@ -377,17 +352,15 @@ void nsMIMEInputStream::SerializeInternal(InputStreamParams& aParams, if (nsCOMPtr serializable = do_QueryInterface(mStream)) { - InputStreamHelper::SerializeInputStream(mStream, wrappedParams, - aFileDescriptors, aDelayedStart, - aMaxSize, aSizeUsed, aManager); + InputStreamHelper::SerializeInputStream(mStream, wrappedParams, aMaxSize, + aSizeUsed); } else { // Falling back to sending the underlying stream over a pipe when // sending an nsMIMEInputStream over IPC is potentially wasteful // if it is sent several times. This can possibly happen with // fission. There are two ways to improve this, see bug 1648369 // and bug 1648370. - InputStreamHelper::SerializeInputStreamAsPipe(mStream, wrappedParams, - aDelayedStart, aManager); + InputStreamHelper::SerializeInputStreamAsPipe(mStream, wrappedParams); } NS_ASSERTION(wrappedParams.type() != InputStreamParams::T__None, @@ -397,9 +370,7 @@ void nsMIMEInputStream::SerializeInternal(InputStreamParams& aParams, aParams = params; } -bool nsMIMEInputStream::Deserialize( - const InputStreamParams& aParams, - const FileDescriptorArray& aFileDescriptors) { +bool nsMIMEInputStream::Deserialize(const InputStreamParams& aParams) { if (aParams.type() != InputStreamParams::TMIMEInputStreamParams) { NS_ERROR("Received unknown parameters from the other process!"); return false; @@ -410,8 +381,7 @@ bool nsMIMEInputStream::Deserialize( if (wrappedParams.isSome()) { nsCOMPtr stream; - stream = InputStreamHelper::DeserializeInputStream(wrappedParams.ref(), - aFileDescriptors); + stream = InputStreamHelper::DeserializeInputStream(wrappedParams.ref()); if (!stream) { NS_WARNING("Failed to deserialize wrapped stream!"); return false; diff --git a/netwerk/ipc/SocketProcessChild.h b/netwerk/ipc/SocketProcessChild.h index 7a49023b667c..0554d2573175 100644 --- a/netwerk/ipc/SocketProcessChild.h +++ b/netwerk/ipc/SocketProcessChild.h @@ -25,9 +25,7 @@ class BackgroundDataBridgeParent; // The IPC actor implements PSocketProcessChild in child process. // This is allocated and kept alive by SocketProcessImpl. -class SocketProcessChild final - : public PSocketProcessChild, - public mozilla::ipc::ChildToParentStreamActorManager { +class SocketProcessChild final : public PSocketProcessChild { public: NS_INLINE_DECL_THREADSAFE_REFCOUNTING(SocketProcessChild) diff --git a/netwerk/ipc/SocketProcessParent.h b/netwerk/ipc/SocketProcessParent.h index d8d062d21245..35b3a8fb6eca 100644 --- a/netwerk/ipc/SocketProcessParent.h +++ b/netwerk/ipc/SocketProcessParent.h @@ -27,8 +27,7 @@ class SocketProcessHost; // by SocketProcessHost. class SocketProcessParent final : public PSocketProcessParent, - public ipc::CrashReporterHelper, - public ipc::ParentToChildStreamActorManager { + public ipc::CrashReporterHelper { public: friend class SocketProcessHost; diff --git a/netwerk/protocol/gio/GIOChannelChild.cpp b/netwerk/protocol/gio/GIOChannelChild.cpp index d41939bfa3fe..9aace97b8644 100644 --- a/netwerk/protocol/gio/GIOChannelChild.cpp +++ b/netwerk/protocol/gio/GIOChannelChild.cpp @@ -102,9 +102,9 @@ GIOChannelChild::AsyncOpen(nsIStreamListener* aListener) { mLoadGroup->AddRequest(this, nullptr); } - mozilla::ipc::AutoIPCStream autoStream; - autoStream.Serialize(mUploadStream, - static_cast(gNeckoChild->Manager())); + Maybe ipcStream; + mozilla::ipc::SerializeIPCStream(do_AddRef(mUploadStream), ipcStream, + /* aAllowLazy */ false); uint32_t loadFlags = 0; GetLoadFlags(&loadFlags); @@ -113,7 +113,7 @@ GIOChannelChild::AsyncOpen(nsIStreamListener* aListener) { SerializeURI(nsBaseChannel::URI(), openArgs.uri()); openArgs.startPos() = mStartPos; openArgs.entityID() = mEntityID; - openArgs.uploadStream() = autoStream.TakeOptionalValue(); + openArgs.uploadStream() = ipcStream; openArgs.loadFlags() = loadFlags; nsCOMPtr loadInfo = LoadInfo(); diff --git a/netwerk/protocol/http/HttpBackgroundChannelParent.cpp b/netwerk/protocol/http/HttpBackgroundChannelParent.cpp index f3579e2b1c7f..213c4bf48b2b 100644 --- a/netwerk/protocol/http/HttpBackgroundChannelParent.cpp +++ b/netwerk/protocol/http/HttpBackgroundChannelParent.cpp @@ -172,7 +172,6 @@ bool HttpBackgroundChannelParent::OnStartRequest( } HttpChannelAltDataStream altData; - ipc::AutoIPCStream altDataInputStream(true /* delay start */); if (aAltDataSource) { nsAutoCString altDataType; Unused << aAltDataSource->GetAltDataType(altDataType); @@ -182,11 +181,12 @@ bool HttpBackgroundChannelParent::OnStartRequest( nsresult rv = aAltDataSource->OpenAlternativeInputStream( altDataType, getter_AddRefs(inputStream)); if (NS_SUCCEEDED(rv)) { - Unused << altDataInputStream.Serialize(inputStream, Manager()); + Unused << mozilla::ipc::SerializeIPCStream(inputStream.forget(), + altData.altDataInputStream(), + /* aAllowLazy */ true); } } } - altData.altDataInputStream() = altDataInputStream.TakeOptionalValue(); return SendOnStartRequest(aResponseHead, aUseResponseHead, aRequestHeaders, aArgs, altData); diff --git a/netwerk/protocol/http/HttpChannelChild.cpp b/netwerk/protocol/http/HttpChannelChild.cpp index a5ac28eb9f5d..6dc355fe6fc3 100644 --- a/netwerk/protocol/http/HttpChannelChild.cpp +++ b/netwerk/protocol/http/HttpChannelChild.cpp @@ -2131,10 +2131,10 @@ nsresult HttpChannelChild::ContinueAsyncOpen() { openArgs.preferredAlternativeTypes() = mPreferredCachedAltDataTypes.Clone(); openArgs.referrerInfo() = mReferrerInfo; - AutoIPCStream autoStream(openArgs.uploadStream()); if (mUploadStream) { - autoStream.Serialize(mUploadStream, ContentChild::GetSingleton()); - autoStream.TakeOptionalValue(); + MOZ_ALWAYS_TRUE(SerializeIPCStream(do_AddRef(mUploadStream), + openArgs.uploadStream(), + /* aAllowLazy */ false)); } Maybe optionalCorsPreflightArgs; diff --git a/netwerk/protocol/http/HttpChannelParent.cpp b/netwerk/protocol/http/HttpChannelParent.cpp index ce1f9e324c0b..5798e87c8648 100644 --- a/netwerk/protocol/http/HttpChannelParent.cpp +++ b/netwerk/protocol/http/HttpChannelParent.cpp @@ -1456,19 +1456,17 @@ mozilla::ipc::IPCResult HttpChannelParent::RecvOpenOriginalCacheInputStream() { if (mIPCClosed) { return IPC_OK(); } - AutoIPCStream autoStream; + Maybe ipcStream; if (mCacheEntry) { nsCOMPtr inputStream; nsresult rv = mCacheEntry->OpenInputStream(0, getter_AddRefs(inputStream)); if (NS_SUCCEEDED(rv)) { - PContentParent* pcp = Manager()->Manager(); - Unused << autoStream.Serialize(inputStream, - static_cast(pcp)); + Unused << mozilla::ipc::SerializeIPCStream( + inputStream.forget(), ipcStream, /* aAllowLazy */ false); } } - Unused << SendOriginalCacheInputStreamAvailable( - autoStream.TakeOptionalValue()); + Unused << SendOriginalCacheInputStreamAvailable(ipcStream); return IPC_OK(); } diff --git a/netwerk/protocol/http/HttpTransactionParent.cpp b/netwerk/protocol/http/HttpTransactionParent.cpp index 0febb7be60ed..3d47010d9fc9 100644 --- a/netwerk/protocol/http/HttpTransactionParent.cpp +++ b/netwerk/protocol/http/HttpTransactionParent.cpp @@ -110,9 +110,9 @@ nsresult HttpTransactionParent::Init( HttpConnectionInfoCloneArgs infoArgs; nsHttpConnectionInfo::SerializeHttpConnectionInfo(cinfo, infoArgs); - mozilla::ipc::AutoIPCStream autoStream; - if (requestBody && - !autoStream.Serialize(requestBody, SocketProcessParent::GetSingleton())) { + Maybe ipcStream; + if (!mozilla::ipc::SerializeIPCStream(do_AddRef(requestBody), ipcStream, + /* aAllowLazy */ false)) { return NS_ERROR_FAILURE; } @@ -144,10 +144,8 @@ nsresult HttpTransactionParent::Init( // TODO: Figure out if we have to implement nsIThreadRetargetableRequest in // bug 1544378. - if (!SendInit(caps, infoArgs, *requestHead, - requestBody ? Some(autoStream.TakeValue()) : Nothing(), - requestContentLength, requestBodyHasHeaders, - topLevelOuterContentWindowId, + if (!SendInit(caps, infoArgs, *requestHead, ipcStream, requestContentLength, + requestBodyHasHeaders, topLevelOuterContentWindowId, static_cast(trafficCategory), requestContextID, classOfService, initialRwin, responseTimeoutEnabled, mChannelId, !!mTransactionObserver, pushedStreamArg, throttleQueue, diff --git a/netwerk/protocol/websocket/WebSocketChannelChild.cpp b/netwerk/protocol/websocket/WebSocketChannelChild.cpp index 9d3512c19695..45d7d1c3eaf0 100644 --- a/netwerk/protocol/websocket/WebSocketChannelChild.cpp +++ b/netwerk/protocol/websocket/WebSocketChannelChild.cpp @@ -700,9 +700,12 @@ WebSocketChannelChild::SendBinaryStream(nsIInputStream* aStream, LOG(("WebSocketChannelChild::SendBinaryStream() %p\n", this)); - AutoIPCStream autoStream; - autoStream.Serialize(aStream, static_cast( - gNeckoChild->Manager())); + IPCStream ipcStream; + if (NS_WARN_IF(!mozilla::ipc::SerializeIPCStream(do_AddRef(aStream), + ipcStream, + /* aAllowLazy */ false))) { + return NS_ERROR_UNEXPECTED; + } { MutexAutoLock lock(mMutex); @@ -711,7 +714,7 @@ WebSocketChannelChild::SendBinaryStream(nsIInputStream* aStream, } } - if (!SendSendBinaryStream(autoStream.TakeValue(), aLength)) { + if (!SendSendBinaryStream(ipcStream, aLength)) { return NS_ERROR_UNEXPECTED; } diff --git a/toolkit/components/antitracking/ContentBlockingLog.cpp b/toolkit/components/antitracking/ContentBlockingLog.cpp index bbccc3d9ba2a..c9b2d2e7fa76 100644 --- a/toolkit/components/antitracking/ContentBlockingLog.cpp +++ b/toolkit/components/antitracking/ContentBlockingLog.cpp @@ -22,8 +22,6 @@ namespace mozilla { -using ipc::AutoIPCStream; - typedef Telemetry::OriginMetricID OriginMetricID; // sync with TelemetryOriginData.inc diff --git a/xpcom/ds/nsTArray.h b/xpcom/ds/nsTArray.h index 0521440fac57..ea4ce0dc7cdd 100644 --- a/xpcom/ds/nsTArray.h +++ b/xpcom/ds/nsTArray.h @@ -95,7 +95,6 @@ class IndexCursorResponse; } // namespace mozilla::dom namespace mozilla::ipc { -class AutoIPCStream; class ContentSecurityPolicy; template class Endpoint; @@ -827,9 +826,6 @@ struct MOZ_NEEDS_MEMMOVABLE_TYPE nsTArray_RelocationStrategy { using Type = nsTArray_RelocateUsingMoveConstructor>; \ }; -// TODO mozilla::ipc::AutoIPCStream is not even movable, so memmovable use with -// nsTArray (in StructuredCloneData) seems at least quirky - MOZ_DECLARE_RELOCATE_USING_MOVE_CONSTRUCTOR_FOR_TEMPLATE(JS::Heap) MOZ_DECLARE_RELOCATE_USING_MOVE_CONSTRUCTOR_FOR_TEMPLATE(std::function) MOZ_DECLARE_RELOCATE_USING_MOVE_CONSTRUCTOR_FOR_TEMPLATE(mozilla::ipc::Endpoint) diff --git a/xpcom/io/InputStreamLengthWrapper.cpp b/xpcom/io/InputStreamLengthWrapper.cpp index 5225bbe57f87..7c09e7694351 100644 --- a/xpcom/io/InputStreamLengthWrapper.cpp +++ b/xpcom/io/InputStreamLengthWrapper.cpp @@ -255,35 +255,14 @@ void InputStreamLengthWrapper::SerializedComplexity(uint32_t aMaxSize, } void InputStreamLengthWrapper::Serialize( - mozilla::ipc::InputStreamParams& aParams, - FileDescriptorArray& aFileDescriptors, bool aDelayedStart, - uint32_t aMaxSize, uint32_t* aSizeUsed, - mozilla::ipc::ParentToChildStreamActorManager* aManager) { - SerializeInternal(aParams, aFileDescriptors, aDelayedStart, aMaxSize, - aSizeUsed, aManager); -} - -void InputStreamLengthWrapper::Serialize( - mozilla::ipc::InputStreamParams& aParams, - FileDescriptorArray& aFileDescriptors, bool aDelayedStart, - uint32_t aMaxSize, uint32_t* aSizeUsed, - mozilla::ipc::ChildToParentStreamActorManager* aManager) { - SerializeInternal(aParams, aFileDescriptors, aDelayedStart, aMaxSize, - aSizeUsed, aManager); -} - -template -void InputStreamLengthWrapper::SerializeInternal( - mozilla::ipc::InputStreamParams& aParams, - FileDescriptorArray& aFileDescriptors, bool aDelayedStart, - uint32_t aMaxSize, uint32_t* aSizeUsed, M* aManager) { + mozilla::ipc::InputStreamParams& aParams, uint32_t aMaxSize, + uint32_t* aSizeUsed) { MOZ_ASSERT(mInputStream); MOZ_ASSERT(mWeakIPCSerializableInputStream); InputStreamLengthWrapperParams params; InputStreamHelper::SerializeInputStream(mInputStream, params.stream(), - aFileDescriptors, aDelayedStart, - aMaxSize, aSizeUsed, aManager); + aMaxSize, aSizeUsed); params.length() = mLength; params.consumed() = mConsumed; @@ -291,8 +270,7 @@ void InputStreamLengthWrapper::SerializeInternal( } bool InputStreamLengthWrapper::Deserialize( - const mozilla::ipc::InputStreamParams& aParams, - const FileDescriptorArray& aFileDescriptors) { + const mozilla::ipc::InputStreamParams& aParams) { MOZ_ASSERT(!mInputStream); MOZ_ASSERT(!mWeakIPCSerializableInputStream); @@ -304,8 +282,8 @@ bool InputStreamLengthWrapper::Deserialize( const InputStreamLengthWrapperParams& params = aParams.get_InputStreamLengthWrapperParams(); - nsCOMPtr stream = InputStreamHelper::DeserializeInputStream( - params.stream(), aFileDescriptors); + nsCOMPtr stream = + InputStreamHelper::DeserializeInputStream(params.stream()); if (!stream) { NS_WARNING("Deserialize failed!"); return false; diff --git a/xpcom/io/InputStreamLengthWrapper.h b/xpcom/io/InputStreamLengthWrapper.h index 89b6233e35a6..a88d817b383d 100644 --- a/xpcom/io/InputStreamLengthWrapper.h +++ b/xpcom/io/InputStreamLengthWrapper.h @@ -59,12 +59,6 @@ class InputStreamLengthWrapper final : public nsIAsyncInputStream, private: ~InputStreamLengthWrapper(); - template - void SerializeInternal(mozilla::ipc::InputStreamParams& aParams, - FileDescriptorArray& aFileDescriptors, - bool aDelayedStart, uint32_t aMaxSize, - uint32_t* aSizeUsed, M* aManager); - void SetSourceStream(already_AddRefed aInputStream); nsCOMPtr mInputStream; diff --git a/xpcom/io/NonBlockingAsyncInputStream.cpp b/xpcom/io/NonBlockingAsyncInputStream.cpp index 31fee9b687cb..41dfeda14879 100644 --- a/xpcom/io/NonBlockingAsyncInputStream.cpp +++ b/xpcom/io/NonBlockingAsyncInputStream.cpp @@ -330,37 +330,15 @@ void NonBlockingAsyncInputStream::SerializedComplexity( } void NonBlockingAsyncInputStream::Serialize( - mozilla::ipc::InputStreamParams& aParams, - FileDescriptorArray& aFileDescriptors, bool aDelayedStart, - uint32_t aMaxSize, uint32_t* aSizeUsed, - mozilla::ipc::ParentToChildStreamActorManager* aManager) { - SerializeInternal(aParams, aFileDescriptors, aDelayedStart, aMaxSize, - aSizeUsed, aManager); -} - -void NonBlockingAsyncInputStream::Serialize( - mozilla::ipc::InputStreamParams& aParams, - FileDescriptorArray& aFileDescriptors, bool aDelayedStart, - uint32_t aMaxSize, uint32_t* aSizeUsed, - mozilla::ipc::ChildToParentStreamActorManager* aManager) { - SerializeInternal(aParams, aFileDescriptors, aDelayedStart, aMaxSize, - aSizeUsed, aManager); -} - -template -void NonBlockingAsyncInputStream::SerializeInternal( - mozilla::ipc::InputStreamParams& aParams, - FileDescriptorArray& aFileDescriptors, bool aDelayedStart, - uint32_t aMaxSize, uint32_t* aSizeUsed, M* aManager) { + mozilla::ipc::InputStreamParams& aParams, uint32_t aMaxSize, + uint32_t* aSizeUsed) { MOZ_ASSERT(mWeakIPCSerializableInputStream); - InputStreamHelper::SerializeInputStream(mInputStream, aParams, - aFileDescriptors, aDelayedStart, - aMaxSize, aSizeUsed, aManager); + InputStreamHelper::SerializeInputStream(mInputStream, aParams, aMaxSize, + aSizeUsed); } bool NonBlockingAsyncInputStream::Deserialize( - const mozilla::ipc::InputStreamParams& aParams, - const FileDescriptorArray& aFileDescriptors) { + const mozilla::ipc::InputStreamParams& aParams) { MOZ_CRASH("NonBlockingAsyncInputStream cannot be deserialized!"); return true; } diff --git a/xpcom/io/NonBlockingAsyncInputStream.h b/xpcom/io/NonBlockingAsyncInputStream.h index 0d065e312adb..6574e5df74fe 100644 --- a/xpcom/io/NonBlockingAsyncInputStream.h +++ b/xpcom/io/NonBlockingAsyncInputStream.h @@ -45,12 +45,6 @@ class NonBlockingAsyncInputStream final : public nsIAsyncInputStream, already_AddRefed aInputStream); ~NonBlockingAsyncInputStream(); - template - void SerializeInternal(mozilla::ipc::InputStreamParams& aParams, - FileDescriptorArray& aFileDescriptors, - bool aDelayedStart, uint32_t aMaxSize, - uint32_t* aSizeUsed, M* aManager); - class AsyncWaitRunnable; void RunAsyncWaitCallback(AsyncWaitRunnable* aRunnable, diff --git a/xpcom/io/SlicedInputStream.cpp b/xpcom/io/SlicedInputStream.cpp index e01fb93797f9..86b78e112f2d 100644 --- a/xpcom/io/SlicedInputStream.cpp +++ b/xpcom/io/SlicedInputStream.cpp @@ -441,44 +441,21 @@ void SlicedInputStream::SerializedComplexity(uint32_t aMaxSize, } } -void SlicedInputStream::Serialize( - mozilla::ipc::InputStreamParams& aParams, - FileDescriptorArray& aFileDescriptors, bool aDelayedStart, - uint32_t aMaxSize, uint32_t* aSizeUsed, - mozilla::ipc::ParentToChildStreamActorManager* aManager) { - SerializeInternal(aParams, aFileDescriptors, aDelayedStart, aMaxSize, - aSizeUsed, aManager); -} - -void SlicedInputStream::Serialize( - mozilla::ipc::InputStreamParams& aParams, - FileDescriptorArray& aFileDescriptors, bool aDelayedStart, - uint32_t aMaxSize, uint32_t* aSizeUsed, - mozilla::ipc::ChildToParentStreamActorManager* aManager) { - SerializeInternal(aParams, aFileDescriptors, aDelayedStart, aMaxSize, - aSizeUsed, aManager); -} - -template -void SlicedInputStream::SerializeInternal( - mozilla::ipc::InputStreamParams& aParams, - FileDescriptorArray& aFileDescriptors, bool aDelayedStart, - uint32_t aMaxSize, uint32_t* aSizeUsed, M* aManager) { +void SlicedInputStream::Serialize(mozilla::ipc::InputStreamParams& aParams, + uint32_t aMaxSize, uint32_t* aSizeUsed) { MOZ_ASSERT(mInputStream); MOZ_ASSERT(mWeakIPCSerializableInputStream); uint32_t sizeUsed = 0, pipes = 0, transferables = 0; SerializedComplexity(aMaxSize, &sizeUsed, &pipes, &transferables); if (pipes > 0 && transferables == 0) { - InputStreamHelper::SerializeInputStreamAsPipe(mInputStream, aParams, - aDelayedStart, aManager); + InputStreamHelper::SerializeInputStreamAsPipe(mInputStream, aParams); return; } SlicedInputStreamParams params; InputStreamHelper::SerializeInputStream(mInputStream, params.stream(), - aFileDescriptors, aDelayedStart, - aMaxSize, aSizeUsed, aManager); + aMaxSize, aSizeUsed); params.start() = mStart; params.length() = mLength; params.curPos() = mCurPos; @@ -488,8 +465,7 @@ void SlicedInputStream::SerializeInternal( } bool SlicedInputStream::Deserialize( - const mozilla::ipc::InputStreamParams& aParams, - const FileDescriptorArray& aFileDescriptors) { + const mozilla::ipc::InputStreamParams& aParams) { MOZ_ASSERT(!mInputStream); MOZ_ASSERT(!mWeakIPCSerializableInputStream); @@ -500,8 +476,8 @@ bool SlicedInputStream::Deserialize( const SlicedInputStreamParams& params = aParams.get_SlicedInputStreamParams(); - nsCOMPtr stream = InputStreamHelper::DeserializeInputStream( - params.stream(), aFileDescriptors); + nsCOMPtr stream = + InputStreamHelper::DeserializeInputStream(params.stream()); if (!stream) { NS_WARNING("Deserialize failed!"); return false; diff --git a/xpcom/io/SlicedInputStream.h b/xpcom/io/SlicedInputStream.h index c94b9683533a..f01e766dc09d 100644 --- a/xpcom/io/SlicedInputStream.h +++ b/xpcom/io/SlicedInputStream.h @@ -61,12 +61,6 @@ class SlicedInputStream final : public nsIAsyncInputStream, private: ~SlicedInputStream(); - template - void SerializeInternal(mozilla::ipc::InputStreamParams& aParams, - FileDescriptorArray& aFileDescriptors, - bool aDelayedStart, uint32_t aMaxSize, - uint32_t* aSizeUsed, M* aManager); - void SetSourceStream(already_AddRefed aInputStream); uint64_t AdjustRange(uint64_t aRange); diff --git a/xpcom/io/nsMultiplexInputStream.cpp b/xpcom/io/nsMultiplexInputStream.cpp index 14549c5f7e35..ede49fa3d661 100644 --- a/xpcom/io/nsMultiplexInputStream.cpp +++ b/xpcom/io/nsMultiplexInputStream.cpp @@ -124,12 +124,6 @@ class nsMultiplexInputStream final : public nsIMultiplexInputStream, uint32_t* aPipes, uint32_t* aTransferables, bool* aSerializeAsPipe); - template - void SerializeInternal(InputStreamParams& aParams, - FileDescriptorArray& aFileDescriptors, - bool aDelayedStart, uint32_t aMaxSize, - uint32_t* aSizeUsed, M* aManager); - static nsresult ReadSegCb(nsIInputStream* aIn, void* aClosure, const char* aFromRawSegment, uint32_t aToOffset, uint32_t aCount, uint32_t* aWriteCount); @@ -1033,26 +1027,8 @@ void nsMultiplexInputStream::SerializedComplexityInternal( } } -void nsMultiplexInputStream::Serialize( - InputStreamParams& aParams, FileDescriptorArray& aFileDescriptors, - bool aDelayedStart, uint32_t aMaxSize, uint32_t* aSizeUsed, - mozilla::ipc::ParentToChildStreamActorManager* aManager) { - SerializeInternal(aParams, aFileDescriptors, aDelayedStart, aMaxSize, - aSizeUsed, aManager); -} - -void nsMultiplexInputStream::Serialize( - InputStreamParams& aParams, FileDescriptorArray& aFileDescriptors, - bool aDelayedStart, uint32_t aMaxSize, uint32_t* aSizeUsed, - mozilla::ipc::ChildToParentStreamActorManager* aManager) { - SerializeInternal(aParams, aFileDescriptors, aDelayedStart, aMaxSize, - aSizeUsed, aManager); -} - -template -void nsMultiplexInputStream::SerializeInternal( - InputStreamParams& aParams, FileDescriptorArray& aFileDescriptors, - bool aDelayedStart, uint32_t aMaxSize, uint32_t* aSizeUsed, M* aManager) { +void nsMultiplexInputStream::Serialize(InputStreamParams& aParams, + uint32_t aMaxSize, uint32_t* aSizeUsed) { MutexAutoLock lock(mLock); // Check if we should serialize this stream as a pipe to reduce complexity. @@ -1063,8 +1039,7 @@ void nsMultiplexInputStream::SerializeInternal( if (serializeAsPipe) { *aSizeUsed = 0; MutexAutoUnlock unlock(mLock); - InputStreamHelper::SerializeInputStreamAsPipe(this, aParams, aDelayedStart, - aManager); + InputStreamHelper::SerializeInputStreamAsPipe(this, aParams); return; } @@ -1080,10 +1055,9 @@ void nsMultiplexInputStream::SerializeInternal( streams.SetCapacity(streamCount); for (uint32_t index = 0; index < streamCount; index++) { uint32_t sizeUsed = 0; - InputStreamHelper::SerializeInputStream( - mStreams[index].mOriginalStream, *streams.AppendElement(), - aFileDescriptors, aDelayedStart, maxSize.value(), &sizeUsed, - aManager); + InputStreamHelper::SerializeInputStream(mStreams[index].mOriginalStream, + *streams.AppendElement(), + maxSize.value(), &sizeUsed); MOZ_ASSERT(maxSize.value() >= sizeUsed); @@ -1105,9 +1079,7 @@ void nsMultiplexInputStream::SerializeInternal( *aSizeUsed = totalSizeUsed.value(); } -bool nsMultiplexInputStream::Deserialize( - const InputStreamParams& aParams, - const FileDescriptorArray& aFileDescriptors) { +bool nsMultiplexInputStream::Deserialize(const InputStreamParams& aParams) { if (aParams.type() != InputStreamParams::TMultiplexInputStreamParams) { NS_ERROR("Received unknown parameters from the other process!"); return false; @@ -1120,8 +1092,8 @@ bool nsMultiplexInputStream::Deserialize( uint32_t streamCount = streams.Length(); for (uint32_t index = 0; index < streamCount; index++) { - nsCOMPtr stream = InputStreamHelper::DeserializeInputStream( - streams[index], aFileDescriptors); + nsCOMPtr stream = + InputStreamHelper::DeserializeInputStream(streams[index]); if (!stream) { NS_WARNING("Deserialize failed!"); return false; diff --git a/xpcom/io/nsStorageStream.cpp b/xpcom/io/nsStorageStream.cpp index fd9fce73f74e..4cd542f0e4cc 100644 --- a/xpcom/io/nsStorageStream.cpp +++ b/xpcom/io/nsStorageStream.cpp @@ -377,10 +377,6 @@ class nsStorageInputStream final : public nsIInputStream, uint32_t SegOffset(uint32_t aPosition) { return aPosition & (mSegmentSize - 1); } - - template - void SerializeInternal(InputStreamParams& aParams, bool aDelayedStart, - uint32_t aMaxSize, uint32_t* aSizeUsed, M* aManager); }; NS_IMPL_ISUPPORTS(nsStorageInputStream, nsIInputStream, nsISeekableStream, @@ -589,25 +585,8 @@ void nsStorageInputStream::SerializedComplexity(uint32_t aMaxSize, } } -void nsStorageInputStream::Serialize( - InputStreamParams& aParams, FileDescriptorArray&, bool aDelayedStart, - uint32_t aMaxSize, uint32_t* aSizeUsed, - mozilla::ipc::ParentToChildStreamActorManager* aManager) { - SerializeInternal(aParams, aDelayedStart, aMaxSize, aSizeUsed, aManager); -} - -void nsStorageInputStream::Serialize( - InputStreamParams& aParams, FileDescriptorArray&, bool aDelayedStart, - uint32_t aMaxSize, uint32_t* aSizeUsed, - mozilla::ipc::ChildToParentStreamActorManager* aManager) { - SerializeInternal(aParams, aDelayedStart, aMaxSize, aSizeUsed, aManager); -} - -template -void nsStorageInputStream::SerializeInternal(InputStreamParams& aParams, - bool aDelayedStart, - uint32_t aMaxSize, - uint32_t* aSizeUsed, M* aManager) { +void nsStorageInputStream::Serialize(InputStreamParams& aParams, + uint32_t aMaxSize, uint32_t* aSizeUsed) { MOZ_ASSERT(aSizeUsed); *aSizeUsed = 0; @@ -616,8 +595,7 @@ void nsStorageInputStream::SerializeInternal(InputStreamParams& aParams, MOZ_ASSERT(NS_SUCCEEDED(rv)); if (remaining >= aMaxSize) { - mozilla::ipc::InputStreamHelper::SerializeInputStreamAsPipe( - this, aParams, aDelayedStart, aManager); + mozilla::ipc::InputStreamHelper::SerializeInputStreamAsPipe(this, aParams); return; } @@ -649,8 +627,7 @@ void nsStorageInputStream::SerializeInternal(InputStreamParams& aParams, aParams = params; } -bool nsStorageInputStream::Deserialize(const InputStreamParams& aParams, - const FileDescriptorArray&) { +bool nsStorageInputStream::Deserialize(const InputStreamParams& aParams) { MOZ_ASSERT_UNREACHABLE( "We should never attempt to deserialize a storage " "input stream."); diff --git a/xpcom/io/nsStringStream.cpp b/xpcom/io/nsStringStream.cpp index 49dc88c14848..78799c87656b 100644 --- a/xpcom/io/nsStringStream.cpp +++ b/xpcom/io/nsStringStream.cpp @@ -129,10 +129,6 @@ class nsStringInputStream final : public nsIStringInputStream, private: ~nsStringInputStream() = default; - template - void SerializeInternal(InputStreamParams& aParams, bool aDelayedStart, - uint32_t aMaxSize, uint32_t* aSizeUsed, M* aManager); - size_t Length() const { return mSource ? mSource->Data().Length() : 0; } size_t LengthRemaining() const { return Length() - mOffset; } @@ -463,25 +459,8 @@ void nsStringInputStream::SerializedComplexity(uint32_t aMaxSize, } } -void nsStringInputStream::Serialize( - InputStreamParams& aParams, FileDescriptorArray& /* aFDs */, - bool aDelayedStart, uint32_t aMaxSize, uint32_t* aSizeUsed, - mozilla::ipc::ParentToChildStreamActorManager* aManager) { - SerializeInternal(aParams, aDelayedStart, aMaxSize, aSizeUsed, aManager); -} - -void nsStringInputStream::Serialize( - InputStreamParams& aParams, FileDescriptorArray& /* aFDs */, - bool aDelayedStart, uint32_t aMaxSize, uint32_t* aSizeUsed, - mozilla::ipc::ChildToParentStreamActorManager* aManager) { - SerializeInternal(aParams, aDelayedStart, aMaxSize, aSizeUsed, aManager); -} - -template -void nsStringInputStream::SerializeInternal(InputStreamParams& aParams, - bool aDelayedStart, - uint32_t aMaxSize, - uint32_t* aSizeUsed, M* aManager) { +void nsStringInputStream::Serialize(InputStreamParams& aParams, + uint32_t aMaxSize, uint32_t* aSizeUsed) { ReentrantMonitorAutoEnter lock(mMon); MOZ_DIAGNOSTIC_ASSERT(!Closed(), "cannot send a closed stream!"); @@ -498,8 +477,7 @@ void nsStringInputStream::SerializeInternal(InputStreamParams& aParams, mSource = source; } - InputStreamHelper::SerializeInputStreamAsPipe(this, aParams, aDelayedStart, - aManager); + InputStreamHelper::SerializeInputStreamAsPipe(this, aParams); return; } @@ -510,8 +488,7 @@ void nsStringInputStream::SerializeInternal(InputStreamParams& aParams, aParams = params; } -bool nsStringInputStream::Deserialize(const InputStreamParams& aParams, - const FileDescriptorArray& /* aFDs */) { +bool nsStringInputStream::Deserialize(const InputStreamParams& aParams) { if (aParams.type() != InputStreamParams::TStringInputStreamParams) { NS_ERROR("Received unknown parameters from the other process!"); return false; diff --git a/xpcom/tests/gtest/TestNonBlockingAsyncInputStream.cpp b/xpcom/tests/gtest/TestNonBlockingAsyncInputStream.cpp index 043bc7a2bdcb..fa2ac810a7a1 100644 --- a/xpcom/tests/gtest/TestNonBlockingAsyncInputStream.cpp +++ b/xpcom/tests/gtest/TestNonBlockingAsyncInputStream.cpp @@ -284,14 +284,9 @@ class QIInputStream final : public nsIInputStream, // nsIIPCSerializableInputStream void SerializedComplexity(uint32_t, uint32_t*, uint32_t*, uint32_t*) override {} - void Serialize(mozilla::ipc::InputStreamParams&, FileDescriptorArray&, bool, - uint32_t, uint32_t*, - mozilla::ipc::ParentToChildStreamActorManager*) override {} - void Serialize(mozilla::ipc::InputStreamParams&, FileDescriptorArray&, bool, - uint32_t, uint32_t*, - mozilla::ipc::ChildToParentStreamActorManager*) override {} - bool Deserialize(const mozilla::ipc::InputStreamParams&, - const FileDescriptorArray&) override { + void Serialize(mozilla::ipc::InputStreamParams&, uint32_t, + uint32_t*) override {} + bool Deserialize(const mozilla::ipc::InputStreamParams&) override { return false; }