Bug 1353629 - PBlob refactoring - part 4 - IPCBlobInputStream, r=smaug
IPCBlobInputStream is a new type of nsIInputStream that is used only in content
process when a Blob is sent from parent to child. This inputStream is for now,
just cloneable.
When the parent process sends a Blob to a content process, it has the Blob and
its inputStream. With its inputStream it creates a IPCBlobInputStreamParent
actor. This actor keeps the inputStream alive for following uses (not part of
this patch).
On the child side we will have, of course, a IPCBlobInputStreamChild actor.
This actor is able to create a IPCBlobInputStream when CreateStream() is
called. This means that 1 IPCBlobInputStreamChild can manage multiple
IPCBlobInputStreams each time one of them is cloned. When the last one of this
stream is released, the child actor sends a __delete__ request to the parent
side; the parent will be deleted, and the original inputStream, on the parent
side, will be released as well.
IPCBlobInputStream is a special inputStream because each method, except for
Available() fails. Basically, this inputStream cannot be used on the content
process for nothing else than knowing the size of the original stream.
In the following patches, I'll introduce an async way to use it.
2017-04-24 13:09:40 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#include "IPCBlobInputStreamParent.h"
|
2017-04-24 13:09:40 +03:00
|
|
|
#include "IPCBlobInputStreamStorage.h"
|
2017-05-23 19:06:52 +03:00
|
|
|
#include "mozilla/ipc/IPCStreamUtils.h"
|
Bug 1353629 - PBlob refactoring - part 4 - IPCBlobInputStream, r=smaug
IPCBlobInputStream is a new type of nsIInputStream that is used only in content
process when a Blob is sent from parent to child. This inputStream is for now,
just cloneable.
When the parent process sends a Blob to a content process, it has the Blob and
its inputStream. With its inputStream it creates a IPCBlobInputStreamParent
actor. This actor keeps the inputStream alive for following uses (not part of
this patch).
On the child side we will have, of course, a IPCBlobInputStreamChild actor.
This actor is able to create a IPCBlobInputStream when CreateStream() is
called. This means that 1 IPCBlobInputStreamChild can manage multiple
IPCBlobInputStreams each time one of them is cloned. When the last one of this
stream is released, the child actor sends a __delete__ request to the parent
side; the parent will be deleted, and the original inputStream, on the parent
side, will be released as well.
IPCBlobInputStream is a special inputStream because each method, except for
Available() fails. Basically, this inputStream cannot be used on the content
process for nothing else than knowing the size of the original stream.
In the following patches, I'll introduce an async way to use it.
2017-04-24 13:09:40 +03:00
|
|
|
#include "nsContentUtils.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2017-04-24 13:09:40 +03:00
|
|
|
template<typename M>
|
Bug 1353629 - PBlob refactoring - part 4 - IPCBlobInputStream, r=smaug
IPCBlobInputStream is a new type of nsIInputStream that is used only in content
process when a Blob is sent from parent to child. This inputStream is for now,
just cloneable.
When the parent process sends a Blob to a content process, it has the Blob and
its inputStream. With its inputStream it creates a IPCBlobInputStreamParent
actor. This actor keeps the inputStream alive for following uses (not part of
this patch).
On the child side we will have, of course, a IPCBlobInputStreamChild actor.
This actor is able to create a IPCBlobInputStream when CreateStream() is
called. This means that 1 IPCBlobInputStreamChild can manage multiple
IPCBlobInputStreams each time one of them is cloned. When the last one of this
stream is released, the child actor sends a __delete__ request to the parent
side; the parent will be deleted, and the original inputStream, on the parent
side, will be released as well.
IPCBlobInputStream is a special inputStream because each method, except for
Available() fails. Basically, this inputStream cannot be used on the content
process for nothing else than knowing the size of the original stream.
In the following patches, I'll introduce an async way to use it.
2017-04-24 13:09:40 +03:00
|
|
|
/* static */ IPCBlobInputStreamParent*
|
|
|
|
IPCBlobInputStreamParent::Create(nsIInputStream* aInputStream, uint64_t aSize,
|
2017-05-31 08:41:11 +03:00
|
|
|
uint64_t aChildID, nsresult* aRv, M* aManager)
|
Bug 1353629 - PBlob refactoring - part 4 - IPCBlobInputStream, r=smaug
IPCBlobInputStream is a new type of nsIInputStream that is used only in content
process when a Blob is sent from parent to child. This inputStream is for now,
just cloneable.
When the parent process sends a Blob to a content process, it has the Blob and
its inputStream. With its inputStream it creates a IPCBlobInputStreamParent
actor. This actor keeps the inputStream alive for following uses (not part of
this patch).
On the child side we will have, of course, a IPCBlobInputStreamChild actor.
This actor is able to create a IPCBlobInputStream when CreateStream() is
called. This means that 1 IPCBlobInputStreamChild can manage multiple
IPCBlobInputStreams each time one of them is cloned. When the last one of this
stream is released, the child actor sends a __delete__ request to the parent
side; the parent will be deleted, and the original inputStream, on the parent
side, will be released as well.
IPCBlobInputStream is a special inputStream because each method, except for
Available() fails. Basically, this inputStream cannot be used on the content
process for nothing else than knowing the size of the original stream.
In the following patches, I'll introduce an async way to use it.
2017-04-24 13:09:40 +03:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(aInputStream);
|
|
|
|
MOZ_ASSERT(aRv);
|
|
|
|
|
|
|
|
nsID id;
|
|
|
|
*aRv = nsContentUtils::GenerateUUIDInPlace(id);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(*aRv))) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2017-05-31 08:41:11 +03:00
|
|
|
IPCBlobInputStreamStorage::Get()->AddStream(aInputStream, id, aChildID);
|
Bug 1353629 - PBlob refactoring - part 4 - IPCBlobInputStream, r=smaug
IPCBlobInputStream is a new type of nsIInputStream that is used only in content
process when a Blob is sent from parent to child. This inputStream is for now,
just cloneable.
When the parent process sends a Blob to a content process, it has the Blob and
its inputStream. With its inputStream it creates a IPCBlobInputStreamParent
actor. This actor keeps the inputStream alive for following uses (not part of
this patch).
On the child side we will have, of course, a IPCBlobInputStreamChild actor.
This actor is able to create a IPCBlobInputStream when CreateStream() is
called. This means that 1 IPCBlobInputStreamChild can manage multiple
IPCBlobInputStreams each time one of them is cloned. When the last one of this
stream is released, the child actor sends a __delete__ request to the parent
side; the parent will be deleted, and the original inputStream, on the parent
side, will be released as well.
IPCBlobInputStream is a special inputStream because each method, except for
Available() fails. Basically, this inputStream cannot be used on the content
process for nothing else than knowing the size of the original stream.
In the following patches, I'll introduce an async way to use it.
2017-04-24 13:09:40 +03:00
|
|
|
|
2017-04-24 13:09:40 +03:00
|
|
|
return new IPCBlobInputStreamParent(id, aSize, aManager);
|
Bug 1353629 - PBlob refactoring - part 4 - IPCBlobInputStream, r=smaug
IPCBlobInputStream is a new type of nsIInputStream that is used only in content
process when a Blob is sent from parent to child. This inputStream is for now,
just cloneable.
When the parent process sends a Blob to a content process, it has the Blob and
its inputStream. With its inputStream it creates a IPCBlobInputStreamParent
actor. This actor keeps the inputStream alive for following uses (not part of
this patch).
On the child side we will have, of course, a IPCBlobInputStreamChild actor.
This actor is able to create a IPCBlobInputStream when CreateStream() is
called. This means that 1 IPCBlobInputStreamChild can manage multiple
IPCBlobInputStreams each time one of them is cloned. When the last one of this
stream is released, the child actor sends a __delete__ request to the parent
side; the parent will be deleted, and the original inputStream, on the parent
side, will be released as well.
IPCBlobInputStream is a special inputStream because each method, except for
Available() fails. Basically, this inputStream cannot be used on the content
process for nothing else than knowing the size of the original stream.
In the following patches, I'll introduce an async way to use it.
2017-04-24 13:09:40 +03:00
|
|
|
}
|
|
|
|
|
2017-05-31 08:41:10 +03:00
|
|
|
/* static */ IPCBlobInputStreamParent*
|
|
|
|
IPCBlobInputStreamParent::Create(const nsID& aID, uint64_t aSize,
|
|
|
|
PBackgroundParent* aManager)
|
|
|
|
{
|
2017-05-31 08:41:10 +03:00
|
|
|
IPCBlobInputStreamParent* actor =
|
|
|
|
new IPCBlobInputStreamParent(aID, aSize, aManager);
|
|
|
|
|
|
|
|
actor->mCallback = IPCBlobInputStreamStorage::Get()->TakeCallback(aID);
|
|
|
|
|
|
|
|
return actor;
|
2017-05-31 08:41:10 +03:00
|
|
|
}
|
|
|
|
|
Bug 1353629 - PBlob refactoring - part 4 - IPCBlobInputStream, r=smaug
IPCBlobInputStream is a new type of nsIInputStream that is used only in content
process when a Blob is sent from parent to child. This inputStream is for now,
just cloneable.
When the parent process sends a Blob to a content process, it has the Blob and
its inputStream. With its inputStream it creates a IPCBlobInputStreamParent
actor. This actor keeps the inputStream alive for following uses (not part of
this patch).
On the child side we will have, of course, a IPCBlobInputStreamChild actor.
This actor is able to create a IPCBlobInputStream when CreateStream() is
called. This means that 1 IPCBlobInputStreamChild can manage multiple
IPCBlobInputStreams each time one of them is cloned. When the last one of this
stream is released, the child actor sends a __delete__ request to the parent
side; the parent will be deleted, and the original inputStream, on the parent
side, will be released as well.
IPCBlobInputStream is a special inputStream because each method, except for
Available() fails. Basically, this inputStream cannot be used on the content
process for nothing else than knowing the size of the original stream.
In the following patches, I'll introduce an async way to use it.
2017-04-24 13:09:40 +03:00
|
|
|
IPCBlobInputStreamParent::IPCBlobInputStreamParent(const nsID& aID,
|
2017-04-24 13:09:40 +03:00
|
|
|
uint64_t aSize,
|
|
|
|
nsIContentParent* aManager)
|
Bug 1353629 - PBlob refactoring - part 4 - IPCBlobInputStream, r=smaug
IPCBlobInputStream is a new type of nsIInputStream that is used only in content
process when a Blob is sent from parent to child. This inputStream is for now,
just cloneable.
When the parent process sends a Blob to a content process, it has the Blob and
its inputStream. With its inputStream it creates a IPCBlobInputStreamParent
actor. This actor keeps the inputStream alive for following uses (not part of
this patch).
On the child side we will have, of course, a IPCBlobInputStreamChild actor.
This actor is able to create a IPCBlobInputStream when CreateStream() is
called. This means that 1 IPCBlobInputStreamChild can manage multiple
IPCBlobInputStreams each time one of them is cloned. When the last one of this
stream is released, the child actor sends a __delete__ request to the parent
side; the parent will be deleted, and the original inputStream, on the parent
side, will be released as well.
IPCBlobInputStream is a special inputStream because each method, except for
Available() fails. Basically, this inputStream cannot be used on the content
process for nothing else than knowing the size of the original stream.
In the following patches, I'll introduce an async way to use it.
2017-04-24 13:09:40 +03:00
|
|
|
: mID(aID)
|
|
|
|
, mSize(aSize)
|
2017-04-24 13:09:40 +03:00
|
|
|
, mContentManager(aManager)
|
|
|
|
, mPBackgroundManager(nullptr)
|
2017-05-31 08:41:10 +03:00
|
|
|
, mMigrating(false)
|
2017-04-24 13:09:40 +03:00
|
|
|
{}
|
|
|
|
|
|
|
|
IPCBlobInputStreamParent::IPCBlobInputStreamParent(const nsID& aID,
|
|
|
|
uint64_t aSize,
|
|
|
|
PBackgroundParent* aManager)
|
|
|
|
: mID(aID)
|
|
|
|
, mSize(aSize)
|
|
|
|
, mContentManager(nullptr)
|
|
|
|
, mPBackgroundManager(aManager)
|
2017-05-31 08:41:10 +03:00
|
|
|
, mMigrating(false)
|
Bug 1353629 - PBlob refactoring - part 4 - IPCBlobInputStream, r=smaug
IPCBlobInputStream is a new type of nsIInputStream that is used only in content
process when a Blob is sent from parent to child. This inputStream is for now,
just cloneable.
When the parent process sends a Blob to a content process, it has the Blob and
its inputStream. With its inputStream it creates a IPCBlobInputStreamParent
actor. This actor keeps the inputStream alive for following uses (not part of
this patch).
On the child side we will have, of course, a IPCBlobInputStreamChild actor.
This actor is able to create a IPCBlobInputStream when CreateStream() is
called. This means that 1 IPCBlobInputStreamChild can manage multiple
IPCBlobInputStreams each time one of them is cloned. When the last one of this
stream is released, the child actor sends a __delete__ request to the parent
side; the parent will be deleted, and the original inputStream, on the parent
side, will be released as well.
IPCBlobInputStream is a special inputStream because each method, except for
Available() fails. Basically, this inputStream cannot be used on the content
process for nothing else than knowing the size of the original stream.
In the following patches, I'll introduce an async way to use it.
2017-04-24 13:09:40 +03:00
|
|
|
{}
|
|
|
|
|
|
|
|
void
|
|
|
|
IPCBlobInputStreamParent::ActorDestroy(IProtocol::ActorDestroyReason aReason)
|
|
|
|
{
|
2017-04-24 13:09:40 +03:00
|
|
|
MOZ_ASSERT(mContentManager || mPBackgroundManager);
|
|
|
|
|
|
|
|
mContentManager = nullptr;
|
|
|
|
mPBackgroundManager = nullptr;
|
|
|
|
|
2017-05-31 08:41:10 +03:00
|
|
|
RefPtr<IPCBlobInputStreamParentCallback> callback;
|
|
|
|
mCallback.swap(callback);
|
2017-05-18 10:50:57 +03:00
|
|
|
|
2017-05-31 08:41:10 +03:00
|
|
|
RefPtr<IPCBlobInputStreamStorage> storage = IPCBlobInputStreamStorage::Get();
|
2017-05-18 10:50:57 +03:00
|
|
|
|
2017-05-31 08:41:10 +03:00
|
|
|
if (mMigrating) {
|
|
|
|
if (callback && storage) {
|
|
|
|
// We need to assign this callback to the next parent.
|
|
|
|
IPCBlobInputStreamStorage::Get()->StoreCallback(mID, callback);
|
2017-05-31 08:41:10 +03:00
|
|
|
}
|
2017-05-31 08:41:10 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (storage) {
|
|
|
|
storage->ForgetStream(mID);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (callback) {
|
|
|
|
callback->ActorDestroyed(mID);
|
2017-05-18 10:50:57 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
IPCBlobInputStreamParent::SetCallback(
|
|
|
|
IPCBlobInputStreamParentCallback* aCallback)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aCallback);
|
|
|
|
MOZ_ASSERT(!mCallback);
|
|
|
|
|
|
|
|
mCallback = aCallback;
|
Bug 1353629 - PBlob refactoring - part 4 - IPCBlobInputStream, r=smaug
IPCBlobInputStream is a new type of nsIInputStream that is used only in content
process when a Blob is sent from parent to child. This inputStream is for now,
just cloneable.
When the parent process sends a Blob to a content process, it has the Blob and
its inputStream. With its inputStream it creates a IPCBlobInputStreamParent
actor. This actor keeps the inputStream alive for following uses (not part of
this patch).
On the child side we will have, of course, a IPCBlobInputStreamChild actor.
This actor is able to create a IPCBlobInputStream when CreateStream() is
called. This means that 1 IPCBlobInputStreamChild can manage multiple
IPCBlobInputStreams each time one of them is cloned. When the last one of this
stream is released, the child actor sends a __delete__ request to the parent
side; the parent will be deleted, and the original inputStream, on the parent
side, will be released as well.
IPCBlobInputStream is a special inputStream because each method, except for
Available() fails. Basically, this inputStream cannot be used on the content
process for nothing else than knowing the size of the original stream.
In the following patches, I'll introduce an async way to use it.
2017-04-24 13:09:40 +03:00
|
|
|
}
|
|
|
|
|
2017-04-24 13:09:40 +03:00
|
|
|
mozilla::ipc::IPCResult
|
|
|
|
IPCBlobInputStreamParent::RecvStreamNeeded()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mContentManager || mPBackgroundManager);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIInputStream> stream;
|
|
|
|
IPCBlobInputStreamStorage::Get()->GetStream(mID, getter_AddRefs(stream));
|
|
|
|
if (!stream) {
|
|
|
|
if (!SendStreamReady(void_t())) {
|
|
|
|
return IPC_FAIL(this, "SendStreamReady failed");
|
|
|
|
}
|
|
|
|
|
|
|
|
return IPC_OK();
|
|
|
|
}
|
|
|
|
|
2017-05-23 19:06:52 +03:00
|
|
|
mozilla::ipc::AutoIPCStream ipcStream;
|
2017-04-24 13:09:40 +03:00
|
|
|
bool ok = false;
|
|
|
|
|
|
|
|
if (mContentManager) {
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
ok = ipcStream.Serialize(stream, mContentManager);
|
|
|
|
} else {
|
|
|
|
MOZ_ASSERT(mPBackgroundManager);
|
|
|
|
ok = ipcStream.Serialize(stream, mPBackgroundManager);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NS_WARN_IF(!ok)) {
|
|
|
|
return IPC_FAIL(this, "SendStreamReady failed");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!SendStreamReady(ipcStream.TakeValue())) {
|
|
|
|
return IPC_FAIL(this, "SendStreamReady failed");
|
|
|
|
}
|
|
|
|
|
|
|
|
return IPC_OK();
|
|
|
|
}
|
|
|
|
|
2017-05-19 15:00:31 +03:00
|
|
|
mozilla::ipc::IPCResult
|
|
|
|
IPCBlobInputStreamParent::RecvClose()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mContentManager || mPBackgroundManager);
|
|
|
|
|
|
|
|
Unused << Send__delete__(this);
|
|
|
|
return IPC_OK();
|
|
|
|
}
|
|
|
|
|
2017-05-31 08:41:10 +03:00
|
|
|
mozilla::ipc::IPCResult
|
|
|
|
IPCBlobInputStreamParent::Recv__delete__()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mContentManager || mPBackgroundManager);
|
|
|
|
mMigrating = true;
|
|
|
|
return IPC_OK();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
IPCBlobInputStreamParent::HasValidStream() const
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIInputStream> stream;
|
|
|
|
IPCBlobInputStreamStorage::Get()->GetStream(mID, getter_AddRefs(stream));
|
|
|
|
return !!stream;
|
|
|
|
}
|
|
|
|
|
Bug 1353629 - PBlob refactoring - part 4 - IPCBlobInputStream, r=smaug
IPCBlobInputStream is a new type of nsIInputStream that is used only in content
process when a Blob is sent from parent to child. This inputStream is for now,
just cloneable.
When the parent process sends a Blob to a content process, it has the Blob and
its inputStream. With its inputStream it creates a IPCBlobInputStreamParent
actor. This actor keeps the inputStream alive for following uses (not part of
this patch).
On the child side we will have, of course, a IPCBlobInputStreamChild actor.
This actor is able to create a IPCBlobInputStream when CreateStream() is
called. This means that 1 IPCBlobInputStreamChild can manage multiple
IPCBlobInputStreams each time one of them is cloned. When the last one of this
stream is released, the child actor sends a __delete__ request to the parent
side; the parent will be deleted, and the original inputStream, on the parent
side, will be released as well.
IPCBlobInputStream is a special inputStream because each method, except for
Available() fails. Basically, this inputStream cannot be used on the content
process for nothing else than knowing the size of the original stream.
In the following patches, I'll introduce an async way to use it.
2017-04-24 13:09:40 +03:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|