diff --git a/ipc/glue/IPCStream.ipdlh b/ipc/glue/IPCStream.ipdlh index df9cd9af4a89..a4cd19c28d77 100644 --- a/ipc/glue/IPCStream.ipdlh +++ b/ipc/glue/IPCStream.ipdlh @@ -4,8 +4,10 @@ include protocol PChildToParentStream; include protocol PParentToChildStream; + include BlobTypes; include InputStreamParams; +include ProtocolTypes; namespace mozilla { namespace ipc { @@ -17,14 +19,24 @@ struct InputStreamParamsWithFds OptionalFileDescriptorSet optionalFds; }; +union IPCRemoteStreamType +{ + PChildToParentStream; + PParentToChildStream; +}; + +struct IPCRemoteStream +{ + IPCRemoteStreamType stream; +}; + // Use IPCStream or OptionalIPCStream in your ipdl to represent serialized // nsIInputStreams. Then use AutoIPCStream from IPCStreamUtils.h to perform // the serialization. union IPCStream { InputStreamParamsWithFds; - PChildToParentStream; - PParentToChildStream; + IPCRemoteStream; }; union OptionalIPCStream diff --git a/ipc/glue/IPCStreamUtils.cpp b/ipc/glue/IPCStreamUtils.cpp index 909a7d274d66..f1f27a275980 100644 --- a/ipc/glue/IPCStreamUtils.cpp +++ b/ipc/glue/IPCStreamUtils.cpp @@ -36,8 +36,7 @@ namespace { void AssertValidValueToTake(const IPCStream& aVal) { - MOZ_ASSERT(aVal.type() == IPCStream::TPChildToParentStreamChild || - aVal.type() == IPCStream::TPParentToChildStreamParent || + MOZ_ASSERT(aVal.type() == IPCStream::TIPCRemoteStream || aVal.type() == IPCStream::TInputStreamParamsWithFds); } @@ -164,7 +163,11 @@ SerializeInputStream(nsIInputStream* aStream, IPCStream& aValue, M* aManager) } MOZ_ASSERT(asyncStream); - aValue = IPCStreamSource::Create(asyncStream, aManager); + + IPCRemoteStream remoteStream; + remoteStream.stream() = IPCStreamSource::Create(asyncStream, aManager); + aValue = remoteStream; + return true; } @@ -292,12 +295,16 @@ CleanupIPCStream(IPCStream& aValue, bool aConsumedByIPC) return; } + MOZ_ASSERT(aValue.type() == IPCStream::TIPCRemoteStream); + IPCRemoteStreamType& remoteInputStream = + aValue.get_IPCRemoteStream().stream(); + IPCStreamSource* source = nullptr; - if (aValue.type() == IPCStream::TPChildToParentStreamChild) { - source = IPCStreamSource::Cast(aValue.get_PChildToParentStreamChild()); + if (remoteInputStream.type() == IPCRemoteStreamType::TPChildToParentStreamChild) { + source = IPCStreamSource::Cast(remoteInputStream.get_PChildToParentStreamChild()); } else { - MOZ_ASSERT(aValue.type() == IPCStream::TPParentToChildStreamParent); - source = IPCStreamSource::Cast(aValue.get_PParentToChildStreamParent()); + MOZ_ASSERT(remoteInputStream.type() == IPCRemoteStreamType::TPParentToChildStreamParent); + source = IPCStreamSource::Cast(remoteInputStream.get_PParentToChildStreamParent()); } MOZ_ASSERT(source); @@ -348,15 +355,19 @@ NormalizeOptionalValue(nsIInputStream* aStream, already_AddRefed DeserializeIPCStream(const IPCStream& aValue) { - if (aValue.type() == IPCStream::TPChildToParentStreamParent) { - auto sendStream = - IPCStreamDestination::Cast(aValue.get_PChildToParentStreamParent()); - return sendStream->TakeReader(); - } + if (aValue.type() == IPCStream::TIPCRemoteStream) { + const IPCRemoteStreamType& remoteInputStream = + aValue.get_IPCRemoteStream().stream(); + if (remoteInputStream.type() == IPCRemoteStreamType::TPChildToParentStreamParent) { + auto sendStream = + IPCStreamDestination::Cast(remoteInputStream.get_PChildToParentStreamParent()); + return sendStream->TakeReader(); + } + + MOZ_ASSERT(remoteInputStream.type() == IPCRemoteStreamType::TPParentToChildStreamChild); - if (aValue.type() == IPCStream::TPParentToChildStreamChild) { auto sendStream = - IPCStreamDestination::Cast(aValue.get_PParentToChildStreamChild()); + IPCStreamDestination::Cast(remoteInputStream.get_PParentToChildStreamChild()); return sendStream->TakeReader(); }