2017-03-14 14:29:43 +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 "IPCStreamDestination.h"
|
|
|
|
#include "IPCStreamSource.h"
|
|
|
|
|
|
|
|
#include "mozilla/Unused.h"
|
2019-02-25 23:04:49 +03:00
|
|
|
#include "mozilla/dom/ContentChild.h"
|
2017-03-14 14:29:43 +03:00
|
|
|
#include "mozilla/ipc/PBackgroundChild.h"
|
|
|
|
#include "mozilla/ipc/PChildToParentStreamChild.h"
|
|
|
|
#include "mozilla/ipc/PParentToChildStreamChild.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace ipc {
|
|
|
|
|
|
|
|
// Child to Parent implementation
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
class IPCStreamSourceChild final : public PChildToParentStreamChild,
|
|
|
|
public IPCStreamSource {
|
|
|
|
public:
|
|
|
|
static IPCStreamSourceChild* Create(nsIAsyncInputStream* aInputStream) {
|
|
|
|
MOZ_ASSERT(aInputStream);
|
|
|
|
|
|
|
|
IPCStreamSourceChild* source = new IPCStreamSourceChild(aInputStream);
|
|
|
|
if (!source->Initialize()) {
|
|
|
|
delete source;
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return source;
|
|
|
|
}
|
|
|
|
|
|
|
|
// PChildToParentStreamChild methods
|
|
|
|
|
|
|
|
void ActorDestroy(ActorDestroyReason aReason) override { ActorDestroyed(); }
|
|
|
|
|
2017-04-24 13:09:39 +03:00
|
|
|
IPCResult RecvStartReading() override {
|
|
|
|
Start();
|
|
|
|
return IPC_OK();
|
|
|
|
}
|
|
|
|
|
2017-03-14 14:29:43 +03:00
|
|
|
IPCResult RecvRequestClose(const nsresult& aRv) override {
|
|
|
|
OnEnd(aRv);
|
|
|
|
return IPC_OK();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Close(nsresult aRv) override {
|
|
|
|
MOZ_ASSERT(IPCStreamSource::mState == IPCStreamSource::eClosed);
|
|
|
|
Unused << SendClose(aRv);
|
|
|
|
}
|
|
|
|
|
2017-08-29 18:42:33 +03:00
|
|
|
void SendData(const wr::ByteBuffer& aBuffer) override {
|
2017-03-14 14:29:43 +03:00
|
|
|
Unused << SendBuffer(aBuffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
explicit IPCStreamSourceChild(nsIAsyncInputStream* aInputStream)
|
|
|
|
: IPCStreamSource(aInputStream) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
} // anonymous namespace
|
|
|
|
|
2019-02-26 01:08:36 +03:00
|
|
|
/* static */
|
|
|
|
PChildToParentStreamChild* IPCStreamSource::Create(
|
2019-02-25 23:04:49 +03:00
|
|
|
nsIAsyncInputStream* aInputStream, dom::ContentChild* aManager) {
|
2017-03-14 14:29:43 +03:00
|
|
|
MOZ_ASSERT(aInputStream);
|
|
|
|
MOZ_ASSERT(aManager);
|
|
|
|
|
|
|
|
// PContent can only be used on the main thread
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
IPCStreamSourceChild* source = IPCStreamSourceChild::Create(aInputStream);
|
|
|
|
if (!source) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!aManager->SendPChildToParentStreamConstructor(source)) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
source->ActorConstructed();
|
|
|
|
return source;
|
|
|
|
}
|
|
|
|
|
2019-02-26 01:08:36 +03:00
|
|
|
/* static */
|
|
|
|
PChildToParentStreamChild* IPCStreamSource::Create(
|
2017-03-14 14:29:43 +03:00
|
|
|
nsIAsyncInputStream* aInputStream, PBackgroundChild* aManager) {
|
|
|
|
MOZ_ASSERT(aInputStream);
|
|
|
|
MOZ_ASSERT(aManager);
|
|
|
|
|
|
|
|
IPCStreamSourceChild* source = IPCStreamSourceChild::Create(aInputStream);
|
|
|
|
if (!source) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!aManager->SendPChildToParentStreamConstructor(source)) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
source->ActorConstructed();
|
|
|
|
return source;
|
|
|
|
}
|
|
|
|
|
2019-02-26 01:08:36 +03:00
|
|
|
/* static */
|
|
|
|
IPCStreamSource* IPCStreamSource::Cast(PChildToParentStreamChild* aActor) {
|
2017-03-14 14:29:43 +03:00
|
|
|
MOZ_ASSERT(aActor);
|
|
|
|
return static_cast<IPCStreamSourceChild*>(aActor);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Parent to Child implementation
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
class IPCStreamDestinationChild final : public PParentToChildStreamChild,
|
|
|
|
public IPCStreamDestination {
|
|
|
|
public:
|
|
|
|
nsresult Initialize() { return IPCStreamDestination::Initialize(); }
|
|
|
|
|
|
|
|
~IPCStreamDestinationChild() {}
|
|
|
|
|
|
|
|
private:
|
|
|
|
// PParentToChildStreamChild methods
|
|
|
|
|
|
|
|
void ActorDestroy(ActorDestroyReason aReason) override { ActorDestroyed(); }
|
|
|
|
|
2017-08-29 18:42:33 +03:00
|
|
|
IPCResult RecvBuffer(const wr::ByteBuffer& aBuffer) override {
|
2017-03-14 14:29:43 +03:00
|
|
|
BufferReceived(aBuffer);
|
|
|
|
return IPC_OK();
|
|
|
|
}
|
|
|
|
|
|
|
|
IPCResult RecvClose(const nsresult& aRv) override {
|
|
|
|
CloseReceived(aRv);
|
|
|
|
return IPC_OK();
|
|
|
|
}
|
|
|
|
|
|
|
|
// IPCStreamDestination methods
|
|
|
|
|
2017-04-24 13:09:39 +03:00
|
|
|
void StartReading() override {
|
|
|
|
MOZ_ASSERT(HasDelayedStart());
|
|
|
|
Unused << SendStartReading();
|
|
|
|
}
|
|
|
|
|
2017-03-14 14:29:43 +03:00
|
|
|
void RequestClose(nsresult aRv) override { Unused << SendRequestClose(aRv); }
|
|
|
|
|
|
|
|
void TerminateDestination() override { Unused << Send__delete__(this); }
|
|
|
|
};
|
|
|
|
|
|
|
|
} // anonymous namespace
|
|
|
|
|
|
|
|
PParentToChildStreamChild* AllocPParentToChildStreamChild() {
|
|
|
|
IPCStreamDestinationChild* actor = new IPCStreamDestinationChild();
|
|
|
|
|
|
|
|
if (NS_WARN_IF(NS_FAILED(actor->Initialize()))) {
|
|
|
|
delete actor;
|
|
|
|
actor = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return actor;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DeallocPParentToChildStreamChild(PParentToChildStreamChild* aActor) {
|
|
|
|
delete aActor;
|
|
|
|
}
|
|
|
|
|
2019-02-26 01:08:36 +03:00
|
|
|
/* static */
|
|
|
|
IPCStreamDestination* IPCStreamDestination::Cast(
|
2017-03-14 14:29:43 +03:00
|
|
|
PParentToChildStreamChild* aActor) {
|
|
|
|
MOZ_ASSERT(aActor);
|
|
|
|
return static_cast<IPCStreamDestinationChild*>(aActor);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace ipc
|
|
|
|
} // namespace mozilla
|