Bug 1114507 - Part 3: Remove PContetBridge channel when grandchild-process is killed. r=kanru

This commit is contained in:
chunminchang 2015-08-31 01:53:00 -04:00
parent 13015804f5
commit 905060ad28
6 changed files with 25 additions and 26 deletions

View File

@ -12,7 +12,6 @@
#include "mozilla/dom/ipc/BlobChild.h"
#include "mozilla/jsipc/CrossProcessObjectWrappers.h"
#include "mozilla/ipc/InputStreamUtils.h"
#include "nsIObserverService.h"
using namespace mozilla::ipc;
using namespace mozilla::jsipc;
@ -21,8 +20,7 @@ namespace mozilla {
namespace dom {
NS_IMPL_ISUPPORTS(ContentBridgeChild,
nsIContentChild,
nsIObserver)
nsIContentChild)
ContentBridgeChild::ContentBridgeChild(Transport* aTransport)
: mTransport(aTransport)
@ -36,10 +34,6 @@ ContentBridgeChild::~ContentBridgeChild()
void
ContentBridgeChild::ActorDestroy(ActorDestroyReason aWhy)
{
nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
if (os) {
os->RemoveObserver(this, "content-child-shutdown");
}
MessageLoop::current()->PostTask(
FROM_HERE,
NewRunnableMethod(this, &ContentBridgeChild::DeferredDestroy));
@ -55,11 +49,6 @@ ContentBridgeChild::Create(Transport* aTransport, ProcessId aOtherPid)
DebugOnly<bool> ok = bridge->Open(aTransport, aOtherPid, XRE_GetIOMessageLoop());
MOZ_ASSERT(ok);
nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
if (os) {
os->AddObserver(bridge, "content-child-shutdown", false);
}
return bridge;
}
@ -180,16 +169,5 @@ ContentBridgeChild::DeallocPBlobChild(PBlobChild* aActor)
return nsIContentChild::DeallocPBlobChild(aActor);
}
NS_IMETHODIMP
ContentBridgeChild::Observe(nsISupports* aSubject,
const char* aTopic,
const char16_t* aData)
{
if (!strcmp(aTopic, "content-child-shutdown")) {
Close();
}
return NS_OK;
}
} // namespace dom
} // namespace mozilla

View File

@ -9,20 +9,17 @@
#include "mozilla/dom/PContentBridgeChild.h"
#include "mozilla/dom/nsIContentChild.h"
#include "nsIObserver.h"
namespace mozilla {
namespace dom {
class ContentBridgeChild final : public PContentBridgeChild
, public nsIContentChild
, public nsIObserver
{
public:
explicit ContentBridgeChild(Transport* aTransport);
NS_DECL_ISUPPORTS
NS_DECL_NSIOBSERVER
static ContentBridgeChild*
Create(Transport* aTransport, ProcessId aOtherProcess);

View File

@ -163,6 +163,17 @@ ContentBridgeParent::DeallocPBrowserParent(PBrowserParent* aParent)
return nsIContentParent::DeallocPBrowserParent(aParent);
}
void
ContentBridgeParent::NotifyTabDestroyed()
{
int32_t numLiveTabs = ManagedPBrowserParent().Length();
if (numLiveTabs == 1) {
MessageLoop::current()->PostTask(
FROM_HERE,
NewRunnableMethod(this, &ContentBridgeParent::Close));
}
}
// 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.

View File

@ -28,6 +28,8 @@ public:
virtual void ActorDestroy(ActorDestroyReason aWhy) override;
void DeferredDestroy();
virtual bool IsContentBridgeParent() override { return true; }
void NotifyTabDestroyed();
static ContentBridgeParent*
Create(Transport* aTransport, ProcessId aOtherProcess);

View File

@ -10,6 +10,7 @@
#include "mozilla/Preferences.h"
#include "mozilla/dom/File.h"
#include "mozilla/dom/ContentParent.h"
#include "mozilla/dom/ContentBridgeParent.h"
#include "mozilla/dom/PTabContext.h"
#include "mozilla/dom/PermissionMessageUtils.h"
#include "mozilla/dom/StructuredCloneUtils.h"
@ -46,6 +47,13 @@ nsIContentParent::AsContentParent()
return static_cast<ContentParent*>(this);
}
ContentBridgeParent*
nsIContentParent::AsContentBridgeParent()
{
MOZ_ASSERT(IsContentBridgeParent());
return static_cast<ContentBridgeParent*>(this);
}
PJavaScriptParent*
nsIContentParent::AllocPJavaScriptParent()
{

View File

@ -38,6 +38,7 @@ class BlobConstructorParams;
class BlobImpl;
class BlobParent;
class ContentParent;
class ContentBridgeParent;
class IPCTabContext;
class PBlobParent;
class PBrowserParent;
@ -77,6 +78,8 @@ public:
virtual bool IsContentParent() { return false; }
ContentParent* AsContentParent();
virtual bool IsContentBridgeParent() { return false; }
ContentBridgeParent* AsContentBridgeParent();
protected: // methods
bool CanOpenBrowser(const IPCTabContext& aContext);