2014-06-11 09:44:13 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2015-05-03 22:32:37 +03:00
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2014-06-11 09:44:13 +04:00
|
|
|
/* 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 "mozilla/dom/ContentBridgeChild.h"
|
|
|
|
#include "mozilla/dom/ContentChild.h"
|
2014-10-08 20:15:23 +04:00
|
|
|
#include "mozilla/dom/File.h"
|
2014-06-11 09:44:13 +04:00
|
|
|
#include "mozilla/dom/TabChild.h"
|
2017-05-02 12:57:51 +03:00
|
|
|
#include "mozilla/dom/TabGroup.h"
|
2015-01-27 00:32:18 +03:00
|
|
|
#include "mozilla/jsipc/CrossProcessObjectWrappers.h"
|
2014-06-11 09:44:13 +04:00
|
|
|
#include "mozilla/ipc/InputStreamUtils.h"
|
2016-05-13 01:15:43 +03:00
|
|
|
#include "base/task.h"
|
2014-06-11 09:44:13 +04:00
|
|
|
|
|
|
|
using namespace mozilla::ipc;
|
|
|
|
using namespace mozilla::jsipc;
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2015-06-10 20:08:00 +03:00
|
|
|
NS_IMPL_ISUPPORTS(ContentBridgeChild, nsIContentChild)
|
2014-06-11 09:44:13 +04:00
|
|
|
|
2017-01-27 02:05:36 +03:00
|
|
|
ContentBridgeChild::ContentBridgeChild() {}
|
2014-06-11 09:44:13 +04:00
|
|
|
|
|
|
|
ContentBridgeChild::~ContentBridgeChild() {}
|
|
|
|
|
|
|
|
void ContentBridgeChild::ActorDestroy(ActorDestroyReason aWhy) {
|
2017-06-12 22:34:10 +03:00
|
|
|
MessageLoop::current()->PostTask(
|
|
|
|
NewRunnableMethod("dom::ContentBridgeChild::DeferredDestroy", this,
|
|
|
|
&ContentBridgeChild::DeferredDestroy));
|
2014-06-11 09:44:13 +04:00
|
|
|
}
|
|
|
|
|
2017-01-27 01:40:17 +03:00
|
|
|
/*static*/ void ContentBridgeChild::Create(
|
|
|
|
Endpoint<PContentBridgeChild>&& aEndpoint) {
|
2017-01-27 02:05:36 +03:00
|
|
|
RefPtr<ContentBridgeChild> bridge = new ContentBridgeChild();
|
2014-06-11 09:44:13 +04:00
|
|
|
bridge->mSelfRef = bridge;
|
|
|
|
|
2017-01-27 01:40:17 +03:00
|
|
|
DebugOnly<bool> ok = aEndpoint.Bind(bridge);
|
2014-06-11 09:44:13 +04:00
|
|
|
MOZ_ASSERT(ok);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ContentBridgeChild::DeferredDestroy() {
|
|
|
|
mSelfRef = nullptr;
|
|
|
|
// |this| was just destroyed, hands off
|
|
|
|
}
|
|
|
|
|
|
|
|
mozilla::ipc::IPCResult ContentBridgeChild::RecvAsyncMessage(
|
2015-01-16 22:58:52 +03:00
|
|
|
const nsString& aMsg, InfallibleTArray<jsipc::CpowEntry>&& aCpows,
|
2016-04-09 16:50:59 +03:00
|
|
|
const IPC::Principal& aPrincipal, const ClonedMessageData& aData) {
|
2018-05-30 22:15:35 +03:00
|
|
|
return nsIContentChild::RecvAsyncMessage(aMsg, std::move(aCpows), aPrincipal,
|
|
|
|
aData);
|
2014-06-11 09:44:13 +04:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-06-11 09:44:13 +04:00
|
|
|
bool ContentBridgeChild::SendPBrowserConstructor(
|
2017-04-07 02:46:18 +03:00
|
|
|
PBrowserChild* aActor, const TabId& aTabId, const TabId& aSameTabGroupAs,
|
2014-06-11 09:44:13 +04:00
|
|
|
const IPCTabContext& aContext, const uint32_t& aChromeFlags,
|
2014-10-24 04:28:00 +04:00
|
|
|
const ContentParentId& aCpID, const bool& aIsForBrowser) {
|
2014-06-11 09:44:13 +04:00
|
|
|
return PContentBridgeChild::SendPBrowserConstructor(
|
2017-04-07 02:46:18 +03:00
|
|
|
aActor, aTabId, aSameTabGroupAs, aContext, aChromeFlags, aCpID,
|
2014-06-11 09:44:13 +04:00
|
|
|
aIsForBrowser);
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-09-21 13:27:26 +03:00
|
|
|
PFileDescriptorSetChild* ContentBridgeChild::SendPFileDescriptorSetConstructor(
|
|
|
|
const FileDescriptor& aFD) {
|
|
|
|
return PContentBridgeChild::SendPFileDescriptorSetConstructor(aFD);
|
|
|
|
}
|
|
|
|
|
2017-03-14 14:28:58 +03:00
|
|
|
PChildToParentStreamChild*
|
|
|
|
ContentBridgeChild::SendPChildToParentStreamConstructor(
|
|
|
|
PChildToParentStreamChild* aActor) {
|
|
|
|
return PContentBridgeChild::SendPChildToParentStreamConstructor(aActor);
|
2016-09-21 13:27:26 +03:00
|
|
|
}
|
|
|
|
|
2014-06-11 09:44:13 +04:00
|
|
|
// This implementation is identical to ContentChild::GetCPOWManager but we can't
|
|
|
|
// move it to nsIContentChild because it calls ManagedPJavaScriptChild() which
|
|
|
|
// only exists in PContentChild and PContentBridgeChild.
|
|
|
|
jsipc::CPOWManager* ContentBridgeChild::GetCPOWManager() {
|
2015-12-22 18:14:23 +03:00
|
|
|
if (PJavaScriptChild* c =
|
|
|
|
LoneManagedOrNullAsserts(ManagedPJavaScriptChild())) {
|
2015-10-08 03:15:56 +03:00
|
|
|
return CPOWManagerFor(c);
|
2014-06-11 09:44:13 +04:00
|
|
|
}
|
2015-01-27 00:32:18 +03:00
|
|
|
return CPOWManagerFor(SendPJavaScriptConstructor());
|
2014-06-11 09:44:13 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
mozilla::jsipc::PJavaScriptChild* ContentBridgeChild::AllocPJavaScriptChild() {
|
|
|
|
return nsIContentChild::AllocPJavaScriptChild();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ContentBridgeChild::DeallocPJavaScriptChild(PJavaScriptChild* child) {
|
|
|
|
return nsIContentChild::DeallocPJavaScriptChild(child);
|
|
|
|
}
|
|
|
|
|
2014-10-29 21:11:00 +03:00
|
|
|
PBrowserChild* ContentBridgeChild::AllocPBrowserChild(
|
2017-04-07 02:46:18 +03:00
|
|
|
const TabId& aTabId, const TabId& aSameTabGroupAs,
|
2014-06-11 09:44:13 +04:00
|
|
|
const IPCTabContext& aContext, const uint32_t& aChromeFlags,
|
2014-10-24 04:28:00 +04:00
|
|
|
const ContentParentId& aCpID, const bool& aIsForBrowser) {
|
2014-10-29 21:11:00 +03:00
|
|
|
return nsIContentChild::AllocPBrowserChild(
|
2017-04-07 02:46:18 +03:00
|
|
|
aTabId, aSameTabGroupAs, aContext, aChromeFlags, aCpID, aIsForBrowser);
|
2014-06-11 09:44:13 +04:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-06-11 09:44:13 +04:00
|
|
|
bool ContentBridgeChild::DeallocPBrowserChild(PBrowserChild* aChild) {
|
|
|
|
return nsIContentChild::DeallocPBrowserChild(aChild);
|
|
|
|
}
|
|
|
|
|
|
|
|
mozilla::ipc::IPCResult ContentBridgeChild::RecvPBrowserConstructor(
|
2017-04-07 02:46:18 +03:00
|
|
|
PBrowserChild* aActor, const TabId& aTabId, const TabId& aSameTabGroupAs,
|
2014-06-11 09:44:13 +04:00
|
|
|
const IPCTabContext& aContext, const uint32_t& aChromeFlags,
|
2014-10-24 04:28:00 +04:00
|
|
|
const ContentParentId& aCpID, const bool& aIsForBrowser) {
|
2016-12-01 06:16:28 +03:00
|
|
|
return nsIContentChild::RecvPBrowserConstructor(
|
2017-04-07 02:46:18 +03:00
|
|
|
aActor, aTabId, aSameTabGroupAs, aContext, aChromeFlags, aCpID,
|
2016-12-01 06:16:28 +03:00
|
|
|
aIsForBrowser);
|
2014-06-11 09:44:13 +04:00
|
|
|
}
|
2018-11-30 13:46:48 +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
|
|
|
PIPCBlobInputStreamChild* ContentBridgeChild::AllocPIPCBlobInputStreamChild(
|
|
|
|
const nsID& aID, const uint64_t& aSize) {
|
|
|
|
return nsIContentChild::AllocPIPCBlobInputStreamChild(aID, aSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ContentBridgeChild::DeallocPIPCBlobInputStreamChild(
|
|
|
|
PIPCBlobInputStreamChild* aActor) {
|
|
|
|
return nsIContentChild::DeallocPIPCBlobInputStreamChild(aActor);
|
|
|
|
}
|
|
|
|
|
2017-03-14 14:28:58 +03:00
|
|
|
PChildToParentStreamChild*
|
|
|
|
ContentBridgeChild::AllocPChildToParentStreamChild() {
|
|
|
|
return nsIContentChild::AllocPChildToParentStreamChild();
|
2016-09-21 13:27:26 +03:00
|
|
|
}
|
|
|
|
|
2017-03-14 14:28:58 +03:00
|
|
|
bool ContentBridgeChild::DeallocPChildToParentStreamChild(
|
|
|
|
PChildToParentStreamChild* aActor) {
|
|
|
|
return nsIContentChild::DeallocPChildToParentStreamChild(aActor);
|
2016-09-21 13:27:26 +03:00
|
|
|
}
|
|
|
|
|
2017-03-14 14:29:43 +03:00
|
|
|
PParentToChildStreamChild*
|
|
|
|
ContentBridgeChild::AllocPParentToChildStreamChild() {
|
|
|
|
return nsIContentChild::AllocPParentToChildStreamChild();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ContentBridgeChild::DeallocPParentToChildStreamChild(
|
|
|
|
PParentToChildStreamChild* aActor) {
|
|
|
|
return nsIContentChild::DeallocPParentToChildStreamChild(aActor);
|
|
|
|
}
|
|
|
|
|
2016-09-21 13:27:26 +03:00
|
|
|
PFileDescriptorSetChild* ContentBridgeChild::AllocPFileDescriptorSetChild(
|
|
|
|
const FileDescriptor& aFD) {
|
|
|
|
return nsIContentChild::AllocPFileDescriptorSetChild(aFD);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ContentBridgeChild::DeallocPFileDescriptorSetChild(
|
|
|
|
PFileDescriptorSetChild* aActor) {
|
|
|
|
return nsIContentChild::DeallocPFileDescriptorSetChild(aActor);
|
|
|
|
}
|
|
|
|
|
2017-03-15 04:00:00 +03:00
|
|
|
mozilla::ipc::IPCResult ContentBridgeChild::RecvActivate(PBrowserChild* aTab) {
|
|
|
|
TabChild* tab = static_cast<TabChild*>(aTab);
|
|
|
|
return tab->RecvActivate();
|
|
|
|
}
|
|
|
|
|
|
|
|
mozilla::ipc::IPCResult ContentBridgeChild::RecvDeactivate(
|
|
|
|
PBrowserChild* aTab) {
|
|
|
|
TabChild* tab = static_cast<TabChild*>(aTab);
|
|
|
|
return tab->RecvDeactivate();
|
|
|
|
}
|
|
|
|
|
2017-05-02 12:57:51 +03:00
|
|
|
already_AddRefed<nsIEventTarget> ContentBridgeChild::GetConstructedEventTarget(
|
|
|
|
const Message& aMsg) {
|
|
|
|
// Currently we only set targets for PBrowser.
|
|
|
|
if (aMsg.type() != PContentBridge::Msg_PBrowserConstructor__ID) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsIContentChild::GetConstructedEventTarget(aMsg);
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<nsIEventTarget> ContentBridgeChild::GetEventTargetFor(
|
|
|
|
TabChild* aTabChild) {
|
|
|
|
return IToplevelProtocol::GetActorEventTarget(aTabChild);
|
|
|
|
}
|
|
|
|
|
2014-06-11 09:44:13 +04:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|