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
This commit is contained in:
Nika Layzell 2022-05-10 22:27:46 +00:00
Родитель 45ada7cbee
Коммит 024c6e0c0a
62 изменённых файлов: 366 добавлений и 1457 удалений

54
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<AutoIPCStream>& 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<AutoIPCStream>& autoStream : mStreamCleanupList) {
autoStream->TakeOptionalValue();
}
return mOpResult;
}
@ -504,7 +466,7 @@ void AutoParentOpResult::SerializeReadStream(const nsID& aId,
RefPtr<ReadStream> readStream =
ReadStream::Create(mStreamControl, aId, stream);
ErrorResult rv;
readStream->Serialize(aReadStreamOut, mStreamCleanupList, rv);
readStream->Serialize(aReadStreamOut, rv);
MOZ_DIAGNOSTIC_ASSERT(!rv.Failed());
}

3
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<UniquePtr<mozilla::ipc::AutoIPCStream>> mStreamCleanupList;
bool mSent;
};
@ -92,7 +90,6 @@ class MOZ_STACK_CLASS AutoParentOpResult final {
mozilla::ipc::PBackgroundParent* mManager;
CacheOpResult mOpResult;
CacheStreamControlParent* mStreamControl;
nsTArray<UniquePtr<mozilla::ipc::AutoIPCStream>> mStreamCleanupList;
bool mSent;
};

12
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<UniquePtr<AutoIPCStream>>& aStreamCleanupList) {
void CacheStreamControlChild::SerializeStream(CacheReadStream* aReadStreamOut,
nsIInputStream* aStream) {
NS_ASSERT_OWNINGTHREAD(CacheStreamControlChild);
MOZ_DIAGNOSTIC_ASSERT(aReadStreamOut);
UniquePtr<AutoIPCStream> 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,

13
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<UniquePtr<mozilla::ipc::AutoIPCStream>>&
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

21
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<UniquePtr<AutoIPCStream>>& aStreamCleanupList) {
void CacheStreamControlParent::SerializeStream(CacheReadStream* aReadStreamOut,
nsIInputStream* aStream) {
NS_ASSERT_OWNINGTHREAD(CacheStreamControlParent);
MOZ_DIAGNOSTIC_ASSERT(aReadStreamOut);
UniquePtr<AutoIPCStream> autoStream(
new AutoIPCStream(aReadStreamOut->stream()));
DebugOnly<bool> ok = autoStream->Serialize(aStream, Manager());
DebugOnly<bool> 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<nsIInputStream>&& aStream) {
AutoIPCStream autoStream;
if (self->CanSend() && autoStream.Serialize(aStream, self->Manager())) {
aResolver(autoStream.TakeOptionalValue());
Maybe<IPCStream> stream;
if (self->CanSend() &&
mozilla::ipc::SerializeIPCStream(aStream.forget(), stream,
/* aAllowLazy */ false)) {
aResolver(stream);
} else {
aResolver(Nothing());
}

13
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<UniquePtr<mozilla::ipc::AutoIPCStream>>&
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

36
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<CacheReadStream>* aReadStreamOut,
nsTArray<UniquePtr<AutoIPCStream>>& aStreamCleanupList,
ErrorResult& aRv);
void Serialize(Maybe<CacheReadStream>* aReadStreamOut, ErrorResult& aRv);
void Serialize(CacheReadStream* aReadStreamOut,
nsTArray<UniquePtr<AutoIPCStream>>& 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<CacheReadStream>* aReadStreamOut,
nsTArray<UniquePtr<AutoIPCStream>>& aStreamCleanupList, ErrorResult& aRv) {
void ReadStream::Inner::Serialize(Maybe<CacheReadStream>* 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<UniquePtr<AutoIPCStream>>& 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> ReadStream::Create(
static_cast<CacheStreamControlParent*>(aControl), aId, aStream));
}
void ReadStream::Serialize(
Maybe<CacheReadStream>* aReadStreamOut,
nsTArray<UniquePtr<AutoIPCStream>>& aStreamCleanupList, ErrorResult& aRv) {
mInner->Serialize(aReadStreamOut, aStreamCleanupList, aRv);
void ReadStream::Serialize(Maybe<CacheReadStream>* aReadStreamOut,
ErrorResult& aRv) {
mInner->Serialize(aReadStreamOut, aRv);
}
void ReadStream::Serialize(
CacheReadStream* aReadStreamOut,
nsTArray<UniquePtr<AutoIPCStream>>& aStreamCleanupList, ErrorResult& aRv) {
mInner->Serialize(aReadStreamOut, aStreamCleanupList, aRv);
void ReadStream::Serialize(CacheReadStream* aReadStreamOut, ErrorResult& aRv) {
mInner->Serialize(aReadStreamOut, aRv);
}
ReadStream::ReadStream(SafeRefPtr<ReadStream::Inner> aInner)

13
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<CacheReadStream>* aReadStreamOut,
nsTArray<UniquePtr<mozilla::ipc::AutoIPCStream>>& aStreamCleanupList,
ErrorResult& aRv);
void Serialize(
CacheReadStream* aReadStreamOut,
nsTArray<UniquePtr<mozilla::ipc::AutoIPCStream>>& aStreamCleanupList,
ErrorResult& aRv);
void Serialize(Maybe<CacheReadStream>* aReadStreamOut, ErrorResult& aRv);
void Serialize(CacheReadStream* aReadStreamOut, ErrorResult& aRv);
private:
class Inner;

14
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<UniquePtr<mozilla::ipc::AutoIPCStream>>& 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

32
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<InternalRequest> TypeUtils::ToInternalRequest(
return ToInternalRequest(aIn.GetAsUSVString(), aRv);
}
void TypeUtils::ToCacheRequest(
CacheRequest& aOut, const InternalRequest& aIn, BodyAction aBodyAction,
SchemeAction aSchemeAction,
nsTArray<UniquePtr<AutoIPCStream>>& 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<nsIInputStream> 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<UniquePtr<AutoIPCStream>>& 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<InternalRequest> TypeUtils::ToInternalRequest(const nsAString& aIn,
return request->GetInternalRequest();
}
void TypeUtils::SerializeCacheStream(
nsIInputStream* aStream, Maybe<CacheReadStream>* aStreamOut,
nsTArray<UniquePtr<AutoIPCStream>>& aStreamCleanupList, ErrorResult& aRv) {
void TypeUtils::SerializeCacheStream(nsIInputStream* aStream,
Maybe<CacheReadStream>* aStreamOut,
ErrorResult& aRv) {
*aStreamOut = Nothing();
if (!aStream) {
return;
@ -492,7 +489,7 @@ void TypeUtils::SerializeCacheStream(
RefPtr<ReadStream> 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<AutoIPCStream> 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

16
dom/cache/TypeUtils.h поставляемый
Просмотреть файл

@ -21,7 +21,6 @@ namespace mozilla {
namespace ipc {
class PBackgroundChild;
class AutoIPCStream;
} // namespace ipc
namespace dom {
@ -73,18 +72,14 @@ class TypeUtils {
JSContext* aCx, const OwningRequestOrUSVString& aIn,
BodyAction aBodyAction, ErrorResult& aRv);
void ToCacheRequest(
CacheRequest& aOut, const InternalRequest& aIn, BodyAction aBodyAction,
SchemeAction aSchemeAction,
nsTArray<UniquePtr<mozilla::ipc::AutoIPCStream>>& aStreamCleanupList,
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<UniquePtr<mozilla::ipc::AutoIPCStream>>& aStreamCleanupList,
void ToCacheResponse(JSContext* aCx, CacheResponse& aOut, Response& aIn,
ErrorResult& aRv);
void ToCacheQueryParams(CacheQueryParams& aOut, const CacheQueryOptions& aIn);
@ -128,9 +123,8 @@ class TypeUtils {
SafeRefPtr<InternalRequest> ToInternalRequest(const nsAString& aIn,
ErrorResult& aRv);
void SerializeCacheStream(
nsIInputStream* aStream, Maybe<CacheReadStream>* aStreamOut,
nsTArray<UniquePtr<mozilla::ipc::AutoIPCStream>>& aStreamCleanupList,
void SerializeCacheStream(nsIInputStream* aStream,
Maybe<CacheReadStream>* aStreamOut,
ErrorResult& aRv);
void SerializeSendStream(nsIInputStream* aStream,

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

@ -134,9 +134,7 @@ InternalResponseMetadata InternalResponse::GetMetadata() {
void InternalResponse::ToChildToParentInternalResponse(
ChildToParentInternalResponse* aIPCResponse,
mozilla::ipc::PBackgroundChild* aManager,
UniquePtr<mozilla::ipc::AutoIPCStream>& aAutoBodyStream,
UniquePtr<mozilla::ipc::AutoIPCStream>& 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<bool> ok = aAutoBodyStream->Serialize(body, aManager);
DebugOnly<bool> 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<bool> ok =
aAutoAlternativeBodyStream->Serialize(alternativeBody, aManager);
DebugOnly<bool> ok = mozilla::ipc::SerializeIPCStream(
alternativeBody.forget(), aIPCResponse->alternativeBody()->stream(),
/* aAllowLazy */ false);
MOZ_ASSERT(ok);
}
}

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

@ -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<InternalResponse> {
static SafeRefPtr<InternalResponse> FromIPC(
const ParentToParentInternalResponse& aIPCResponse);
// Note: the AutoIPCStreams must outlive the ChildToParentInternalResponse.
void ToChildToParentInternalResponse(
ChildToParentInternalResponse* aIPCResponse,
mozilla::ipc::PBackgroundChild* aManager,
UniquePtr<mozilla::ipc::AutoIPCStream>& aAutoBodyStream,
UniquePtr<mozilla::ipc::AutoIPCStream>& aAutoAlternativeBodyStream);
mozilla::ipc::PBackgroundChild* aManager);
ParentToParentInternalResponse ToParentToParentInternalResponse();

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

@ -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;
}

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

@ -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;
}

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

@ -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
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

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

@ -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;
}

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

@ -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<nsIIPCSerializableInputStream> serializable =
do_QueryInterface(stream)) {
nsTArray<FileDescriptor> unused;
uint32_t sizeUsed = 0;
serializable->Serialize(
params, unused, false, 128 * 1024, &sizeUsed,
(mozilla::ipc::ParentToChildStreamActorManager*)nullptr);
MOZ_ASSERT(unused.IsEmpty());
} else {
RefPtr<ipc::DataPipeSender> sender;
RefPtr<ipc::DataPipeReceiver> 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<nsIEventTarget> 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> 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();
}

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

@ -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;

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

@ -105,8 +105,7 @@ struct CancelContentJSOptions;
} \
}
class ContentParent final
: public PContentParent,
class ContentParent final : public PContentParent,
public nsIDOMProcessParent,
public nsIObserver,
public nsIDOMGeoPositionCallback,
@ -119,7 +118,6 @@ class ContentParent final
public mozilla::MemoryReportingProcess,
public mozilla::dom::ipc::MessageManagerCallback,
public mozilla::ipc::IShmemAllocator,
public mozilla::ipc::ParentToChildStreamActorManager,
public ProcessActor {
typedef mozilla::ipc::GeckoChildProcessHost GeckoChildProcessHost;
typedef mozilla::ipc::TestShellParent TestShellParent;

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

@ -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<nsCOMPtr<nsIInputStream>>& inputStreams = aData.InputStreams();
if (!inputStreams.IsEmpty()) {
if (NS_WARN_IF(
!aData.IPCStreams().SetCapacity(inputStreams.Length(), fallible))) {
return false;
}
nsTArray<IPCStream>& 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);
}
}

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

@ -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<mozilla::ipc::AutoIPCStream>& 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<SharedJSAllocatedData> 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<mozilla::ipc::AutoIPCStream> mIPCStreams;
bool mInitialized;
};

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

@ -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<mozilla::dom::ContentChild*>(
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;

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

@ -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;

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

@ -28,11 +28,6 @@
#include "nsTArray.h"
#include "nscore.h"
namespace mozilla::ipc {
class ChildToParentStreamActorManager;
class ParentToChildStreamActorManager;
} // namespace mozilla::ipc
template <class T>
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<nsCOMPtr<nsIInputStream>> 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();

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

@ -464,17 +464,14 @@ NS_IMETHODIMP DecryptingInputStream<CipherStrategy>::Clone(
template <typename CipherStrategy>
void DecryptingInputStream<CipherStrategy>::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<CipherStrategy>::Serialize(
template <typename CipherStrategy>
bool DecryptingInputStream<CipherStrategy>::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<CipherStrategy>::Deserialize(
nsCOMPtr<nsIIPCSerializableInputStream> baseSerializable =
do_QueryInterface(stream);
if (NS_WARN_IF(!baseSerializable->Deserialize(params.fileInputStreamParams(),
aFileDescriptors))) {
if (NS_WARN_IF(
!baseSerializable->Deserialize(params.fileInputStreamParams()))) {
return false;
}

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

@ -37,8 +37,7 @@ namespace {
nsresult GetIPCSynthesizeResponseArgs(
ChildToParentSynthesizeResponseArgs* aIPCArgs,
SynthesizeResponseArgs&& aArgs, UniquePtr<AutoIPCStream>& aAutoBodyStream,
UniquePtr<AutoIPCStream>& aAutoAlternativeBodyStream) {
SynthesizeResponseArgs&& aArgs) {
MOZ_ASSERT(RemoteWorkerService::Thread()->IsOnCurrentThread());
SafeRefPtr<InternalResponse> internalResponse;
@ -56,8 +55,7 @@ nsresult GetIPCSynthesizeResponseArgs(
}
internalResponse->ToChildToParentInternalResponse(
&aIPCArgs->internalResponse(), bgChild, aAutoBodyStream,
aAutoAlternativeBodyStream);
&aIPCArgs->internalResponse(), bgChild);
return NS_OK;
}
@ -135,13 +133,8 @@ void FetchEventOpProxyChild::Initialize(
if (result.is<SynthesizeResponseArgs>()) {
ChildToParentSynthesizeResponseArgs ipcArgs;
UniquePtr<AutoIPCStream> autoBodyStream =
MakeUnique<AutoIPCStream>();
UniquePtr<AutoIPCStream> autoAlternativeBodyStream =
MakeUnique<AutoIPCStream>();
nsresult rv = GetIPCSynthesizeResponseArgs(
&ipcArgs, result.extract<SynthesizeResponseArgs>(),
autoBodyStream, autoAlternativeBodyStream);
&ipcArgs, result.extract<SynthesizeResponseArgs>());
if (NS_WARN_IF(NS_FAILED(rv))) {
Unused << self->SendRespondWith(
@ -150,14 +143,6 @@ void FetchEventOpProxyChild::Initialize(
}
Unused << self->SendRespondWith(ipcArgs);
if (ipcArgs.internalResponse().body()) {
autoBodyStream->TakeValue();
}
if (ipcArgs.internalResponse().alternativeBody()) {
autoAlternativeBodyStream->TakeValue();
}
} else if (result.is<ResetInterceptionArgs>()) {
Unused << self->SendRespondWith(
result.extract<ResetInterceptionArgs>());

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

@ -76,12 +76,12 @@ void WebBrowserPersistDocumentChild::Start(
ENSURE(aDocument->GetPostData(getter_AddRefs(postDataStream)));
#undef ENSURE
mozilla::ipc::AutoIPCStream autoStream;
autoStream.Serialize(postDataStream,
static_cast<mozilla::dom::ContentChild*>(Manager()));
Maybe<mozilla::ipc::IPCStream> stream;
mozilla::ipc::SerializeIPCStream(postDataStream.forget(), stream,
/* aAllowLazy */ false);
mDocument = aDocument;
SendAttributes(attrs, autoStream.TakeOptionalValue());
SendAttributes(attrs, stream);
}
mozilla::ipc::IPCResult WebBrowserPersistDocumentChild::RecvSetPersistFlags(

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

@ -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;

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

@ -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();

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

@ -665,27 +665,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`");
}

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

@ -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;

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

@ -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 <typename M>
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<FileDescriptor, 4> 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 <typename M>
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<FileDescriptor, 4> 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 <typename M>
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 <typename M>
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 <typename M>
bool SerializeInputStreamChild(nsIInputStream* aStream, M* aManager,
IPCStream* aValue,
Maybe<IPCStream>* aOptionalValue,
bool aDelayedStart) {
MOZ_ASSERT(aStream);
MOZ_ASSERT(aManager);
MOZ_ASSERT(aValue || aOptionalValue);
} // anonymous namespace
nsCOMPtr<nsIIPCSerializableInputStream> 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 <typename M>
bool SerializeInputStreamParent(nsIInputStream* aStream, M* aManager,
IPCStream* aValue,
Maybe<IPCStream>* 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<nsIIPCSerializableInputStream> 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<IPCStream>* aOptionalValue) {
if (aValue) {
// if aStream is null, we will crash when serializing.
return true;
}
if (!aStream) {
aOptionalValue->reset();
bool SerializeIPCStream(already_AddRefed<nsIInputStream> aInputStream,
IPCStream& aValue, bool aAllowLazy) {
nsCOMPtr<nsIInputStream> 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<nsIIPCSerializableInputStream> 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;
}
} // anonymous namespace
InputStreamHelper::SerializeInputStreamAsPipe(stream, aValue.stream());
if (aValue.stream().type() == InputStreamParams::T__None) {
MOZ_ASSERT_UNREACHABLE("Serializing as a pipe failed");
return false;
}
return true;
}
bool SerializeIPCStream(already_AddRefed<nsIInputStream> aInputStream,
Maybe<IPCStream>& aValue, bool aAllowLazy) {
nsCOMPtr<nsIInputStream> 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<nsIInputStream> DeserializeIPCStream(const IPCStream& aValue) {
nsTArray<FileDescriptor> fds; // NOTE: Unused, should be removed.
return InputStreamHelper::DeserializeInputStream(aValue.stream(), fds);
return InputStreamHelper::DeserializeInputStream(aValue.stream());
}
already_AddRefed<nsIInputStream> DeserializeIPCStream(
@ -280,250 +166,26 @@ already_AddRefed<nsIInputStream> 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) {}
AutoIPCStream::AutoIPCStream(Maybe<IPCStream>& aTarget, bool aDelayedStart)
: mOptionalValue(&aTarget), mDelayedStart(aDelayedStart) {
mOptionalValue->reset();
}
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<BackgroundChildImpl*>(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<BackgroundParentImpl*>(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<IPCStream>& AutoIPCStream::TakeOptionalValue() {
MOZ_ASSERT(!mTaken);
MOZ_ASSERT(!mValue);
MOZ_ASSERT(mOptionalValue);
mTaken = true;
return *mOptionalValue;
}
void IPDLParamTraits<nsIInputStream*>::Write(IPC::MessageWriter* aWriter,
IProtocol* aActor,
void IPC::ParamTraits<nsIInputStream*>::Write(IPC::MessageWriter* aWriter,
nsIInputStream* aParam) {
auto autoStream = MakeRefPtr<HoldIPCStream>(/* 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<mozilla::dom::ContentParent*>(actor));
} else {
MOZ_RELEASE_ASSERT(actor->GetSide() == mozilla::ipc::ChildSide);
ok = autoStream->Serialize(
aParam, static_cast<mozilla::dom::ContentChild*>(actor));
}
found = true;
break;
case PBackgroundMsgStart:
if (actor->GetSide() == mozilla::ipc::ParentSide) {
ok = autoStream->Serialize(
aParam, static_cast<mozilla::ipc::PBackgroundParent*>(actor));
} else {
MOZ_RELEASE_ASSERT(actor->GetSide() == mozilla::ipc::ChildSide);
ok = autoStream->Serialize(
aParam, static_cast<mozilla::ipc::PBackgroundChild*>(actor));
}
found = true;
break;
default:
break;
mozilla::Maybe<mozilla::ipc::IPCStream> stream;
if (!mozilla::ipc::SerializeIPCStream(do_AddRef(aParam), stream,
/* aAllowLazy */ true)) {
MOZ_CRASH("Failed to serialize nsIInputStream");
}
// Try the actor's manager.
actor = actor->Manager();
WriteParam(aWriter, stream);
}
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<nsIInputStream*>::Write::autoStream",
NS_GetCurrentThread(), autoStream.forget(), true);
}
bool IPDLParamTraits<nsIInputStream*>::Read(IPC::MessageReader* aReader,
IProtocol* aActor,
bool IPC::ParamTraits<nsIInputStream*>::Read(IPC::MessageReader* aReader,
RefPtr<nsIInputStream>* aResult) {
mozilla::Maybe<mozilla::ipc::IPCStream> ipcStream;
if (!ReadIPDLParam(aReader, aActor, &ipcStream)) {
if (!ReadParam(aReader, &ipcStream)) {
return false;
}
*aResult = mozilla::ipc::DeserializeIPCStream(ipcStream);
return true;
}
} // namespace ipc
} // namespace mozilla

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

@ -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<nsIInputStream> may be used instead if serialization cannot be
// fallible.
[[nodiscard]] bool SerializeIPCStream(
already_AddRefed<nsIInputStream> 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<nsIInputStream> aInputStream,
Maybe<IPCStream>& 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<nsIInputStream> DeserializeIPCStream(const IPCStream& aValue);
already_AddRefed<nsIInputStream> DeserializeIPCStream(
const Maybe<IPCStream>& 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<nsIInputStream> 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<nsIInputStream> 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<IPCStream> 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<IPCStream> 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<IPCStream>. Either TakeValue()
// or TakeOptionalValue can be used.
explicit AutoIPCStream(Maybe<IPCStream>& 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<IPCStream> 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<IPCStream>& TakeOptionalValue();
private:
bool IsSet() const;
Maybe<IPCStream> mInlineValue;
IPCStream* const mValue = nullptr;
Maybe<IPCStream>* 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<nsIInputStream*> {
static void Write(IPC::MessageWriter* aWriter, IProtocol* aActor,
nsIInputStream* aParam);
static bool Read(IPC::MessageReader* aReader, IProtocol* aActor,
RefPtr<nsIInputStream>* aResult);
struct ParamTraits<nsIInputStream*> {
static void Write(MessageWriter* aWriter, nsIInputStream* aParam);
static bool Read(MessageReader* aReader, RefPtr<nsIInputStream>* aResult);
};
} // namespace ipc
} // namespace mozilla
} // namespace IPC
#endif // mozilla_ipc_IPCStreamUtils_h

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

@ -42,14 +42,11 @@ using namespace mozilla::dom;
namespace mozilla {
namespace ipc {
namespace {
template <typename M>
void SerializeInputStreamInternal(nsIInputStream* aInputStream,
InputStreamParams& aParams,
nsTArray<FileDescriptor>& 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<nsIIPCSerializableInputStream> 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<nsIIPCSerializableInputStream> 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 <typename M>
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<nsIIPCSerializableInputStream> 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<FileDescriptor>& 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<FileDescriptor>& 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<nsIInputStream> InputStreamHelper::DeserializeInputStream(
const InputStreamParams& aParams,
const nsTArray<FileDescriptor>& aFileDescriptors) {
const InputStreamParams& aParams) {
if (aParams.type() == InputStreamParams::TRemoteLazyInputStreamParams) {
const RemoteLazyInputStreamParams& params =
aParams.get_RemoteLazyInputStreamParams();
@ -238,7 +196,7 @@ already_AddRefed<nsIInputStream> InputStreamHelper::DeserializeInputStream(
MOZ_ASSERT(serializable);
if (!serializable->Deserialize(aParams, aFileDescriptors)) {
if (!serializable->Deserialize(aParams)) {
MOZ_ASSERT(false, "Deserialize failed!");
return nullptr;
}

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

@ -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<FileDescriptor>& 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<FileDescriptor>& 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<nsIInputStream> DeserializeInputStream(
const InputStreamParams& aParams,
const nsTArray<FileDescriptor>& aFileDescriptors);
const InputStreamParams& aParams);
};
} // namespace ipc

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

@ -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<mozilla::ipc::FileDescriptor> FileDescriptorArray;
NS_DECLARE_STATIC_IID_ACCESSOR(NS_IIPCSERIALIZABLEINPUTSTREAM_IID)
// Determine the serialized complexity of this input stream, initializing
@ -70,20 +66,10 @@ 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,
@ -93,16 +79,10 @@ NS_DEFINE_STATIC_IID_ACCESSOR(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&, uint32_t, \
uint32_t*) 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;
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

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

@ -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 <typename M>
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<nsIInputStream> 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;

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

@ -112,12 +112,6 @@ class nsBufferedInputStream final : public nsBufferedStream,
protected:
virtual ~nsBufferedInputStream() = default;
template <typename M>
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

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

@ -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!");

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

@ -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);

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

@ -59,12 +59,6 @@ class nsMIMEInputStream : public nsIMIMEInputStream,
private:
void InitStreams();
template <typename M>
void SerializeInternal(InputStreamParams& aParams,
FileDescriptorArray& aFileDescriptors,
bool aDelayedStart, uint32_t aMaxSize,
uint32_t* aSizeUsed, M* aManager);
struct MOZ_STACK_CLASS ReadSegmentsState {
nsCOMPtr<nsIInputStream> 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 <typename M>
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<nsIIPCSerializableInputStream> 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<nsIInputStream> stream;
stream = InputStreamHelper::DeserializeInputStream(wrappedParams.ref(),
aFileDescriptors);
stream = InputStreamHelper::DeserializeInputStream(wrappedParams.ref());
if (!stream) {
NS_WARNING("Failed to deserialize wrapped stream!");
return false;

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

@ -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)

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

@ -27,8 +27,7 @@ class SocketProcessHost;
// by SocketProcessHost.
class SocketProcessParent final
: public PSocketProcessParent,
public ipc::CrashReporterHelper<GeckoProcessType_Socket>,
public ipc::ParentToChildStreamActorManager {
public ipc::CrashReporterHelper<GeckoProcessType_Socket> {
public:
friend class SocketProcessHost;

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

@ -102,9 +102,9 @@ GIOChannelChild::AsyncOpen(nsIStreamListener* aListener) {
mLoadGroup->AddRequest(this, nullptr);
}
mozilla::ipc::AutoIPCStream autoStream;
autoStream.Serialize(mUploadStream,
static_cast<ContentChild*>(gNeckoChild->Manager()));
Maybe<mozilla::ipc::IPCStream> 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<nsILoadInfo> loadInfo = LoadInfo();

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

@ -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);

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

@ -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<CorsPreflightArgs> optionalCorsPreflightArgs;

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

@ -1456,19 +1456,17 @@ mozilla::ipc::IPCResult HttpChannelParent::RecvOpenOriginalCacheInputStream() {
if (mIPCClosed) {
return IPC_OK();
}
AutoIPCStream autoStream;
Maybe<IPCStream> ipcStream;
if (mCacheEntry) {
nsCOMPtr<nsIInputStream> inputStream;
nsresult rv = mCacheEntry->OpenInputStream(0, getter_AddRefs(inputStream));
if (NS_SUCCEEDED(rv)) {
PContentParent* pcp = Manager()->Manager();
Unused << autoStream.Serialize(inputStream,
static_cast<ContentParent*>(pcp));
Unused << mozilla::ipc::SerializeIPCStream(
inputStream.forget(), ipcStream, /* aAllowLazy */ false);
}
}
Unused << SendOriginalCacheInputStreamAvailable(
autoStream.TakeOptionalValue());
Unused << SendOriginalCacheInputStreamAvailable(ipcStream);
return IPC_OK();
}

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

@ -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<mozilla::ipc::IPCStream> 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<uint8_t>(trafficCategory), requestContextID,
classOfService, initialRwin, responseTimeoutEnabled, mChannelId,
!!mTransactionObserver, pushedStreamArg, throttleQueue,

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

@ -700,9 +700,12 @@ WebSocketChannelChild::SendBinaryStream(nsIInputStream* aStream,
LOG(("WebSocketChannelChild::SendBinaryStream() %p\n", this));
AutoIPCStream autoStream;
autoStream.Serialize(aStream, static_cast<mozilla::dom::ContentChild*>(
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;
}

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

@ -22,8 +22,6 @@
namespace mozilla {
using ipc::AutoIPCStream;
typedef Telemetry::OriginMetricID OriginMetricID;
// sync with TelemetryOriginData.inc

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

@ -95,7 +95,6 @@ class IndexCursorResponse;
} // namespace mozilla::dom
namespace mozilla::ipc {
class AutoIPCStream;
class ContentSecurityPolicy;
template <class T>
class Endpoint;
@ -827,9 +826,6 @@ struct MOZ_NEEDS_MEMMOVABLE_TYPE nsTArray_RelocationStrategy {
using Type = nsTArray_RelocateUsingMoveConstructor<T<S>>; \
};
// 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)

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

@ -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 <typename M>
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<nsIInputStream> stream = InputStreamHelper::DeserializeInputStream(
params.stream(), aFileDescriptors);
nsCOMPtr<nsIInputStream> stream =
InputStreamHelper::DeserializeInputStream(params.stream());
if (!stream) {
NS_WARNING("Deserialize failed!");
return false;

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

@ -59,12 +59,6 @@ class InputStreamLengthWrapper final : public nsIAsyncInputStream,
private:
~InputStreamLengthWrapper();
template <typename M>
void SerializeInternal(mozilla::ipc::InputStreamParams& aParams,
FileDescriptorArray& aFileDescriptors,
bool aDelayedStart, uint32_t aMaxSize,
uint32_t* aSizeUsed, M* aManager);
void SetSourceStream(already_AddRefed<nsIInputStream> aInputStream);
nsCOMPtr<nsIInputStream> mInputStream;

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

@ -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 <typename M>
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;
}

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

@ -45,12 +45,6 @@ class NonBlockingAsyncInputStream final : public nsIAsyncInputStream,
already_AddRefed<nsIInputStream> aInputStream);
~NonBlockingAsyncInputStream();
template <typename M>
void SerializeInternal(mozilla::ipc::InputStreamParams& aParams,
FileDescriptorArray& aFileDescriptors,
bool aDelayedStart, uint32_t aMaxSize,
uint32_t* aSizeUsed, M* aManager);
class AsyncWaitRunnable;
void RunAsyncWaitCallback(AsyncWaitRunnable* aRunnable,

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

@ -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 <typename M>
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<nsIInputStream> stream = InputStreamHelper::DeserializeInputStream(
params.stream(), aFileDescriptors);
nsCOMPtr<nsIInputStream> stream =
InputStreamHelper::DeserializeInputStream(params.stream());
if (!stream) {
NS_WARNING("Deserialize failed!");
return false;

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

@ -61,12 +61,6 @@ class SlicedInputStream final : public nsIAsyncInputStream,
private:
~SlicedInputStream();
template <typename M>
void SerializeInternal(mozilla::ipc::InputStreamParams& aParams,
FileDescriptorArray& aFileDescriptors,
bool aDelayedStart, uint32_t aMaxSize,
uint32_t* aSizeUsed, M* aManager);
void SetSourceStream(already_AddRefed<nsIInputStream> aInputStream);
uint64_t AdjustRange(uint64_t aRange);

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

@ -124,12 +124,6 @@ class nsMultiplexInputStream final : public nsIMultiplexInputStream,
uint32_t* aPipes, uint32_t* aTransferables,
bool* aSerializeAsPipe);
template <typename M>
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 <typename M>
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<nsIInputStream> stream = InputStreamHelper::DeserializeInputStream(
streams[index], aFileDescriptors);
nsCOMPtr<nsIInputStream> stream =
InputStreamHelper::DeserializeInputStream(streams[index]);
if (!stream) {
NS_WARNING("Deserialize failed!");
return false;

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

@ -377,10 +377,6 @@ class nsStorageInputStream final : public nsIInputStream,
uint32_t SegOffset(uint32_t aPosition) {
return aPosition & (mSegmentSize - 1);
}
template <typename M>
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 <typename M>
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.");

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

@ -129,10 +129,6 @@ class nsStringInputStream final : public nsIStringInputStream,
private:
~nsStringInputStream() = default;
template <typename M>
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 <typename M>
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;

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

@ -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;
}