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/ContentBridgeParent.h"
|
|
|
|
#include "mozilla/dom/TabParent.h"
|
2015-01-27 00:32:18 +03:00
|
|
|
#include "mozilla/jsipc/CrossProcessObjectWrappers.h"
|
2014-06-11 09:44:13 +04:00
|
|
|
#include "nsXULAppAPI.h"
|
2015-03-10 14:10:00 +03:00
|
|
|
#include "nsIObserverService.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-03-10 14:10:00 +03:00
|
|
|
NS_IMPL_ISUPPORTS(ContentBridgeParent,
|
|
|
|
nsIContentParent,
|
|
|
|
nsIObserver)
|
2014-06-11 09:44:13 +04:00
|
|
|
|
2017-01-27 02:05:36 +03:00
|
|
|
ContentBridgeParent::ContentBridgeParent()
|
2017-05-29 13:38:46 +03:00
|
|
|
: mIsForJSPlugin(false)
|
2014-06-11 09:44:13 +04:00
|
|
|
{}
|
|
|
|
|
|
|
|
ContentBridgeParent::~ContentBridgeParent()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ContentBridgeParent::ActorDestroy(ActorDestroyReason aWhy)
|
|
|
|
{
|
2015-03-10 14:10:00 +03:00
|
|
|
nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
|
|
|
|
if (os) {
|
|
|
|
os->RemoveObserver(this, "content-child-shutdown");
|
|
|
|
}
|
2017-06-21 14:59:26 +03:00
|
|
|
MessageLoop::current()->PostTask(NewRunnableMethod(this, &ContentBridgeParent::DeferredDestroy));
|
2014-06-11 09:44:13 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*static*/ ContentBridgeParent*
|
2017-01-27 01:40:17 +03:00
|
|
|
ContentBridgeParent::Create(Endpoint<PContentBridgeParent>&& aEndpoint)
|
2014-06-11 09:44:13 +04:00
|
|
|
{
|
2017-01-27 02:05:36 +03:00
|
|
|
RefPtr<ContentBridgeParent> bridge = new ContentBridgeParent();
|
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);
|
2015-03-06 04:03:25 +03:00
|
|
|
|
2015-03-10 14:10:00 +03:00
|
|
|
nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
|
|
|
|
if (os) {
|
|
|
|
os->AddObserver(bridge, "content-child-shutdown", false);
|
|
|
|
}
|
|
|
|
|
2015-03-06 04:03:25 +03:00
|
|
|
// Initialize the message manager (and load delayed scripts) now that we
|
|
|
|
// have established communications with the child.
|
|
|
|
bridge->mMessageManager->InitWithCallback(bridge);
|
|
|
|
|
2014-06-11 09:44:13 +04:00
|
|
|
return bridge.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ContentBridgeParent::DeferredDestroy()
|
|
|
|
{
|
|
|
|
mSelfRef = nullptr;
|
|
|
|
// |this| was just destroyed, hands off
|
|
|
|
}
|
|
|
|
|
2016-11-15 06:26:00 +03:00
|
|
|
mozilla::ipc::IPCResult
|
2014-06-11 09:44:13 +04:00
|
|
|
ContentBridgeParent::RecvSyncMessage(const nsString& aMsg,
|
|
|
|
const ClonedMessageData& aData,
|
2015-01-16 22:58:52 +03:00
|
|
|
InfallibleTArray<jsipc::CpowEntry>&& aCpows,
|
2014-06-11 09:44:13 +04:00
|
|
|
const IPC::Principal& aPrincipal,
|
2015-09-10 23:50:58 +03:00
|
|
|
nsTArray<StructuredCloneData>* aRetvals)
|
2014-06-11 09:44:13 +04:00
|
|
|
{
|
2015-01-16 22:58:52 +03:00
|
|
|
return nsIContentParent::RecvSyncMessage(aMsg, aData, Move(aCpows),
|
|
|
|
aPrincipal, aRetvals);
|
2014-06-11 09:44:13 +04:00
|
|
|
}
|
|
|
|
|
2016-11-15 06:26:00 +03:00
|
|
|
mozilla::ipc::IPCResult
|
2014-06-11 09:44:13 +04:00
|
|
|
ContentBridgeParent::RecvAsyncMessage(const nsString& aMsg,
|
2015-01-16 22:58:52 +03:00
|
|
|
InfallibleTArray<jsipc::CpowEntry>&& aCpows,
|
2016-04-09 16:50:59 +03:00
|
|
|
const IPC::Principal& aPrincipal,
|
|
|
|
const ClonedMessageData& aData)
|
2014-06-11 09:44:13 +04:00
|
|
|
{
|
2016-04-09 16:50:59 +03:00
|
|
|
return nsIContentParent::RecvAsyncMessage(aMsg, Move(aCpows),
|
|
|
|
aPrincipal, aData);
|
2014-06-11 09:44:13 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
PBrowserParent*
|
|
|
|
ContentBridgeParent::SendPBrowserConstructor(PBrowserParent* aActor,
|
2014-10-29 21:11:00 +03:00
|
|
|
const TabId& aTabId,
|
2017-04-07 02:46:18 +03:00
|
|
|
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,
|
2014-06-11 09:44:13 +04:00
|
|
|
const bool& aIsForBrowser)
|
|
|
|
{
|
|
|
|
return PContentBridgeParent::SendPBrowserConstructor(aActor,
|
2014-10-29 21:11:00 +03:00
|
|
|
aTabId,
|
2017-04-07 02:46:18 +03:00
|
|
|
aSameTabGroupAs,
|
2014-06-11 09:44:13 +04:00
|
|
|
aContext,
|
|
|
|
aChromeFlags,
|
2014-10-24 04:28:00 +04:00
|
|
|
aCpID,
|
2014-06-11 09:44:13 +04:00
|
|
|
aIsForBrowser);
|
|
|
|
}
|
|
|
|
|
2017-03-14 14:29:43 +03:00
|
|
|
PParentToChildStreamParent*
|
|
|
|
ContentBridgeParent::SendPParentToChildStreamConstructor(PParentToChildStreamParent* aActor)
|
|
|
|
{
|
|
|
|
return PContentBridgeParent::SendPParentToChildStreamConstructor(aActor);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
PIPCBlobInputStreamParent*
|
|
|
|
ContentBridgeParent::SendPIPCBlobInputStreamConstructor(PIPCBlobInputStreamParent* aActor,
|
|
|
|
const nsID& aID,
|
|
|
|
const uint64_t& aSize)
|
|
|
|
{
|
|
|
|
return
|
|
|
|
PContentBridgeParent::SendPIPCBlobInputStreamConstructor(aActor, aID, aSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
PIPCBlobInputStreamParent*
|
|
|
|
ContentBridgeParent::AllocPIPCBlobInputStreamParent(const nsID& aID,
|
|
|
|
const uint64_t& aSize)
|
|
|
|
{
|
|
|
|
return nsIContentParent::AllocPIPCBlobInputStreamParent(aID, aSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ContentBridgeParent::DeallocPIPCBlobInputStreamParent(PIPCBlobInputStreamParent* aActor)
|
|
|
|
{
|
|
|
|
return nsIContentParent::DeallocPIPCBlobInputStreamParent(aActor);
|
|
|
|
}
|
|
|
|
|
2014-06-11 09:44:13 +04:00
|
|
|
mozilla::jsipc::PJavaScriptParent *
|
|
|
|
ContentBridgeParent::AllocPJavaScriptParent()
|
|
|
|
{
|
|
|
|
return nsIContentParent::AllocPJavaScriptParent();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ContentBridgeParent::DeallocPJavaScriptParent(PJavaScriptParent *parent)
|
|
|
|
{
|
|
|
|
return nsIContentParent::DeallocPJavaScriptParent(parent);
|
|
|
|
}
|
|
|
|
|
|
|
|
PBrowserParent*
|
2014-10-29 21:11:00 +03:00
|
|
|
ContentBridgeParent::AllocPBrowserParent(const TabId& aTabId,
|
2017-04-07 02:46:18 +03:00
|
|
|
const TabId& aSameTabGroupAs,
|
2014-10-29 21:11:00 +03:00
|
|
|
const IPCTabContext &aContext,
|
2014-06-11 09:44:13 +04:00
|
|
|
const uint32_t& aChromeFlags,
|
2014-10-24 04:28:00 +04:00
|
|
|
const ContentParentId& aCpID,
|
2014-06-11 09:44:13 +04:00
|
|
|
const bool& aIsForBrowser)
|
|
|
|
{
|
2014-10-29 21:11:00 +03:00
|
|
|
return nsIContentParent::AllocPBrowserParent(aTabId,
|
2017-04-07 02:46:18 +03:00
|
|
|
aSameTabGroupAs,
|
2014-10-29 21:11:00 +03:00
|
|
|
aContext,
|
2014-06-11 09:44:13 +04:00
|
|
|
aChromeFlags,
|
2014-10-24 04:28:00 +04:00
|
|
|
aCpID,
|
2014-06-11 09:44:13 +04:00
|
|
|
aIsForBrowser);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ContentBridgeParent::DeallocPBrowserParent(PBrowserParent* aParent)
|
|
|
|
{
|
|
|
|
return nsIContentParent::DeallocPBrowserParent(aParent);
|
|
|
|
}
|
|
|
|
|
2015-08-31 08:53:00 +03:00
|
|
|
void
|
|
|
|
ContentBridgeParent::NotifyTabDestroyed()
|
|
|
|
{
|
2015-10-07 21:30:33 +03:00
|
|
|
int32_t numLiveTabs = ManagedPBrowserParent().Count();
|
2015-08-31 08:53:00 +03:00
|
|
|
if (numLiveTabs == 1) {
|
2017-06-21 14:59:26 +03:00
|
|
|
MessageLoop::current()->PostTask(NewRunnableMethod(this, &ContentBridgeParent::Close));
|
2015-08-31 08:53:00 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-11 09:44:13 +04:00
|
|
|
// This implementation is identical to ContentParent::GetCPOWManager but we can't
|
|
|
|
// move it to nsIContentParent because it calls ManagedPJavaScriptParent() which
|
|
|
|
// only exists in PContentParent and PContentBridgeParent.
|
2015-01-27 00:32:18 +03:00
|
|
|
jsipc::CPOWManager*
|
2014-06-11 09:44:13 +04:00
|
|
|
ContentBridgeParent::GetCPOWManager()
|
|
|
|
{
|
2015-12-22 18:14:23 +03:00
|
|
|
if (PJavaScriptParent* p = LoneManagedOrNullAsserts(ManagedPJavaScriptParent())) {
|
2015-10-08 03:15:56 +03:00
|
|
|
return CPOWManagerFor(p);
|
2014-06-11 09:44:13 +04:00
|
|
|
}
|
2015-10-09 10:25:00 +03:00
|
|
|
return nullptr;
|
2014-06-11 09:44:13 +04:00
|
|
|
}
|
|
|
|
|
2015-03-10 14:10:00 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
ContentBridgeParent::Observe(nsISupports* aSubject,
|
|
|
|
const char* aTopic,
|
|
|
|
const char16_t* aData)
|
|
|
|
{
|
|
|
|
if (!strcmp(aTopic, "content-child-shutdown")) {
|
|
|
|
Close();
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2017-03-14 14:29:43 +03:00
|
|
|
PFileDescriptorSetParent*
|
|
|
|
ContentBridgeParent::SendPFileDescriptorSetConstructor(const FileDescriptor& aFD)
|
|
|
|
{
|
|
|
|
return PContentBridgeParent::SendPFileDescriptorSetConstructor(aFD);
|
|
|
|
}
|
|
|
|
|
2016-09-21 13:27:26 +03:00
|
|
|
PFileDescriptorSetParent*
|
|
|
|
ContentBridgeParent::AllocPFileDescriptorSetParent(const FileDescriptor& aFD)
|
|
|
|
{
|
|
|
|
return nsIContentParent::AllocPFileDescriptorSetParent(aFD);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ContentBridgeParent::DeallocPFileDescriptorSetParent(PFileDescriptorSetParent* aActor)
|
|
|
|
{
|
|
|
|
return nsIContentParent::DeallocPFileDescriptorSetParent(aActor);
|
|
|
|
}
|
|
|
|
|
2017-03-14 14:28:58 +03:00
|
|
|
PChildToParentStreamParent*
|
|
|
|
ContentBridgeParent::AllocPChildToParentStreamParent()
|
2016-09-21 13:27:26 +03:00
|
|
|
{
|
2017-03-14 14:28:58 +03:00
|
|
|
return nsIContentParent::AllocPChildToParentStreamParent();
|
2016-09-21 13:27:26 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2017-03-14 14:28:58 +03:00
|
|
|
ContentBridgeParent::DeallocPChildToParentStreamParent(PChildToParentStreamParent* aActor)
|
2016-09-21 13:27:26 +03:00
|
|
|
{
|
2017-03-14 14:28:58 +03:00
|
|
|
return nsIContentParent::DeallocPChildToParentStreamParent(aActor);
|
2016-09-21 13:27:26 +03:00
|
|
|
}
|
|
|
|
|
2017-03-14 14:29:43 +03:00
|
|
|
PParentToChildStreamParent*
|
|
|
|
ContentBridgeParent::AllocPParentToChildStreamParent()
|
|
|
|
{
|
|
|
|
return nsIContentParent::AllocPParentToChildStreamParent();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ContentBridgeParent::DeallocPParentToChildStreamParent(PParentToChildStreamParent* aActor)
|
|
|
|
{
|
|
|
|
return nsIContentParent::DeallocPParentToChildStreamParent(aActor);
|
|
|
|
}
|
|
|
|
|
2014-06-11 09:44:13 +04:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|