Bug 1397214 - Prevent ContentChild::RecvSetXPCOMProcessAttributes from running after shutdown. r=ehsan

Since ContentChild itself may be created before the observer service is
started, we cannot create an observer to simply listen for the
xpcom-shutdown event. Thankfully we do not need to do anything special
upon receiving the event -- we just need to know if it has been fired
when we called RecvSetXPCOMProcessAttributes. As such, this patch
creates a canary using ClearOnShutdown. If the canary is cleared, then
we know xpcom-shutdown has been issued, and we should abort the
initialization process.

fixup
This commit is contained in:
Andrew Osmond 2017-09-15 18:48:37 -04:00
parent 400f2bdf9d
commit 132cacdc6f
2 changed files with 22 additions and 0 deletions

View File

@ -516,7 +516,11 @@ PendingInputEventHangAnnotator PendingInputEventHangAnnotator::sSingleton;
NS_IMPL_ISUPPORTS(BackgroundChildPrimer, nsIIPCBackgroundChildCreateCallback)
class ContentChild::ShutdownCanary final
{ };
ContentChild* ContentChild::sSingleton;
StaticAutoPtr<ContentChild::ShutdownCanary> ContentChild::sShutdownCanary;
ContentChild::ContentChild()
: mID(uint64_t(-1))
@ -530,6 +534,16 @@ ContentChild::ContentChild()
// This process is a content process, so it's clearly running in
// multiprocess mode!
nsDebugImpl::SetMultiprocessMode("Child");
// When ContentChild is created, the observer service does not even exist.
// When ContentChild::RecvSetXPCOMProcessAttributes is called (the first
// IPDL call made on this object), shutdown may have already happened. Thus
// we create a canary here that relies upon getting cleared if shutdown
// happens without requiring the observer service at this time.
if (!sShutdownCanary) {
sShutdownCanary = new ShutdownCanary();
ClearOnShutdown(&sShutdownCanary, ShutdownPhase::Shutdown);
}
}
#ifdef _MSC_VER
@ -561,6 +575,10 @@ ContentChild::RecvSetXPCOMProcessAttributes(const XPCOMInitData& aXPCOMInit,
nsTArray<LookAndFeelInt>&& aLookAndFeelIntCache,
nsTArray<FontFamilyListEntry>&& aFontFamilyList)
{
if (!sShutdownCanary) {
return IPC_OK();
}
mLookAndFeelCache = Move(aLookAndFeelIntCache);
mFontFamilies = Move(aFontFamilyList);
gfx::gfxVars::SetValuesForInitialize(aXPCOMInit.gfxNonDefaultVarUpdates());

View File

@ -13,6 +13,7 @@
#include "mozilla/dom/nsIContentChild.h"
#include "mozilla/dom/PBrowserOrId.h"
#include "mozilla/dom/PContentChild.h"
#include "mozilla/StaticPtr.h"
#include "nsAutoPtr.h"
#include "nsHashKeys.h"
#include "nsIObserver.h"
@ -773,6 +774,9 @@ private:
static ContentChild* sSingleton;
class ShutdownCanary;
static StaticAutoPtr<ShutdownCanary> sShutdownCanary;
nsCOMPtr<nsIDomainPolicy> mPolicy;
nsCOMPtr<nsITimer> mForceKillTimer;