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()
|
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");
|
|
|
|
}
|
2016-05-05 11:45:00 +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
|
|
|
}
|
|
|
|
|
|
|
|
PBlobParent*
|
|
|
|
ContentBridgeParent::SendPBlobConstructor(PBlobParent* actor,
|
|
|
|
const BlobConstructorParams& params)
|
|
|
|
{
|
|
|
|
return PContentBridgeParent::SendPBlobConstructor(actor, params);
|
|
|
|
}
|
|
|
|
|
|
|
|
PBrowserParent*
|
|
|
|
ContentBridgeParent::SendPBrowserConstructor(PBrowserParent* aActor,
|
2014-10-29 21:11:00 +03:00
|
|
|
const TabId& aTabId,
|
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,
|
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);
|
|
|
|
}
|
|
|
|
|
2014-06-11 09:44:13 +04:00
|
|
|
PBlobParent*
|
|
|
|
ContentBridgeParent::AllocPBlobParent(const BlobConstructorParams& aParams)
|
|
|
|
{
|
|
|
|
return nsIContentParent::AllocPBlobParent(aParams);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ContentBridgeParent::DeallocPBlobParent(PBlobParent* aActor)
|
|
|
|
{
|
|
|
|
return nsIContentParent::DeallocPBlobParent(aActor);
|
|
|
|
}
|
|
|
|
|
|
|
|
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,
|
|
|
|
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,
|
|
|
|
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) {
|
2016-05-05 11:45:00 +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
|