Bug 1440771 - Part 1: Add a ParamTraits impl for nsCOMPtr<nsIInputStream>, r=baku
MozReview-Commit-ID: dfZJH1cWnW
This commit is contained in:
@@ -9,8 +9,8 @@
|
|||||||
#include "nsIIPCSerializableInputStream.h"
|
#include "nsIIPCSerializableInputStream.h"
|
||||||
|
|
||||||
#include "mozilla/Assertions.h"
|
#include "mozilla/Assertions.h"
|
||||||
#include "mozilla/dom/nsIContentChild.h"
|
#include "mozilla/dom/ContentChild.h"
|
||||||
#include "mozilla/dom/PContentParent.h"
|
#include "mozilla/dom/ContentParent.h"
|
||||||
#include "mozilla/dom/File.h"
|
#include "mozilla/dom/File.h"
|
||||||
#include "mozilla/ipc/FileDescriptorSetChild.h"
|
#include "mozilla/ipc/FileDescriptorSetChild.h"
|
||||||
#include "mozilla/ipc/FileDescriptorSetParent.h"
|
#include "mozilla/ipc/FileDescriptorSetParent.h"
|
||||||
@@ -625,5 +625,69 @@ AutoIPCStream::TakeOptionalValue()
|
|||||||
return *mOptionalValue;
|
return *mOptionalValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
IPDLParamTraits<nsCOMPtr<nsIInputStream>>::Write(IPC::Message* aMsg,
|
||||||
|
IProtocol* aActor,
|
||||||
|
const nsCOMPtr<nsIInputStream>& aParam)
|
||||||
|
{
|
||||||
|
mozilla::ipc::AutoIPCStream autoStream;
|
||||||
|
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->GetProtocolTypeId()) {
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Try the actor's manager.
|
||||||
|
actor = actor->Manager();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!found) {
|
||||||
|
aActor->FatalError("Attempt to send nsIInputStream over an unsupported ipdl protocol");
|
||||||
|
}
|
||||||
|
MOZ_RELEASE_ASSERT(ok, "Failed to serialize nsIInputStream");
|
||||||
|
|
||||||
|
WriteIPDLParam(aMsg, aActor, autoStream.TakeOptionalValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
IPDLParamTraits<nsCOMPtr<nsIInputStream>>::Read(const IPC::Message* aMsg, PickleIterator* aIter,
|
||||||
|
IProtocol* aActor, nsCOMPtr<nsIInputStream>* aResult)
|
||||||
|
{
|
||||||
|
mozilla::ipc::OptionalIPCStream ipcStream;
|
||||||
|
if (!ReadIPDLParam(aMsg, aIter, aActor, &ipcStream)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
*aResult = mozilla::ipc::DeserializeIPCStream(ipcStream);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace ipc
|
} // namespace ipc
|
||||||
} // namespace mozilla
|
} // namespace mozilla
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
#define mozilla_ipc_IPCStreamUtils_h
|
#define mozilla_ipc_IPCStreamUtils_h
|
||||||
|
|
||||||
#include "mozilla/ipc/IPCStream.h"
|
#include "mozilla/ipc/IPCStream.h"
|
||||||
|
#include "nsCOMPtr.h"
|
||||||
#include "nsIInputStream.h"
|
#include "nsIInputStream.h"
|
||||||
|
|
||||||
namespace mozilla {
|
namespace mozilla {
|
||||||
@@ -187,6 +188,17 @@ private:
|
|||||||
AutoIPCStream& operator=(const AutoIPCStream&& aOther) = delete;
|
AutoIPCStream& operator=(const AutoIPCStream&& aOther) = delete;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template<>
|
||||||
|
struct IPDLParamTraits<nsCOMPtr<nsIInputStream>>
|
||||||
|
{
|
||||||
|
typedef nsCOMPtr<nsIInputStream> paramType;
|
||||||
|
|
||||||
|
static void Write(IPC::Message* aMsg, IProtocol* aActor,
|
||||||
|
const paramType& aParam);
|
||||||
|
static bool Read(const IPC::Message* aMsg, PickleIterator* aIter,
|
||||||
|
IProtocol* aActor, paramType* aResult);
|
||||||
|
};
|
||||||
|
|
||||||
} // namespace ipc
|
} // namespace ipc
|
||||||
} // namespace mozilla
|
} // namespace mozilla
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user