2014-06-11 09:44:13 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=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 "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"
|
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
|
|
|
|
|
|
|
ContentBridgeParent::ContentBridgeParent(Transport* aTransport)
|
|
|
|
: mTransport(aTransport)
|
|
|
|
{}
|
|
|
|
|
|
|
|
ContentBridgeParent::~ContentBridgeParent()
|
|
|
|
{
|
|
|
|
XRE_GetIOMessageLoop()->PostTask(FROM_HERE, new DeleteTask<Transport>(mTransport));
|
|
|
|
}
|
|
|
|
|
|
|
|
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");
|
|
|
|
}
|
2014-06-11 09:44:13 +04:00
|
|
|
MessageLoop::current()->PostTask(
|
|
|
|
FROM_HERE,
|
|
|
|
NewRunnableMethod(this, &ContentBridgeParent::DeferredDestroy));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*static*/ ContentBridgeParent*
|
2015-04-01 11:40:35 +03:00
|
|
|
ContentBridgeParent::Create(Transport* aTransport, ProcessId aOtherPid)
|
2014-06-11 09:44:13 +04:00
|
|
|
{
|
|
|
|
nsRefPtr<ContentBridgeParent> bridge =
|
|
|
|
new ContentBridgeParent(aTransport);
|
|
|
|
bridge->mSelfRef = bridge;
|
|
|
|
|
2015-04-01 11:40:35 +03:00
|
|
|
DebugOnly<bool> ok = bridge->Open(aTransport, aOtherPid,
|
|
|
|
XRE_GetIOMessageLoop());
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
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,
|
|
|
|
InfallibleTArray<nsString>* aRetvals)
|
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ContentBridgeParent::RecvAsyncMessage(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-01-16 22:58:52 +03:00
|
|
|
return nsIContentParent::RecvAsyncMessage(aMsg, aData, Move(aCpows),
|
|
|
|
aPrincipal);
|
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& aIsForApp,
|
|
|
|
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
|
|
|
aIsForApp,
|
|
|
|
aIsForBrowser);
|
|
|
|
}
|
|
|
|
|
|
|
|
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& aIsForApp,
|
|
|
|
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
|
|
|
aIsForApp,
|
|
|
|
aIsForBrowser);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
ContentBridgeParent::DeallocPBrowserParent(PBrowserParent* aParent)
|
|
|
|
{
|
|
|
|
return nsIContentParent::DeallocPBrowserParent(aParent);
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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()
|
|
|
|
{
|
|
|
|
if (ManagedPJavaScriptParent().Length()) {
|
2015-01-27 00:32:18 +03:00
|
|
|
return CPOWManagerFor(ManagedPJavaScriptParent()[0]);
|
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
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2014-06-11 09:44:13 +04:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|