From a81bd3bc10fe87ae3e885758f4d347d603ab711d Mon Sep 17 00:00:00 2001 From: Ben Turner Date: Fri, 11 Jul 2014 11:15:10 -0700 Subject: [PATCH] Bug 1037625 - Allow child processes to respond to 'inner-window-destroyed' notifications without possibly killing the process. r-khuey. --- dom/ipc/TabChild.cpp | 40 +++++++++++++++++++++++++++++++++++++++- dom/ipc/TabChild.h | 1 + 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/dom/ipc/TabChild.cpp b/dom/ipc/TabChild.cpp index 6321d56c8bb8..43676e892649 100644 --- a/dom/ipc/TabChild.cpp +++ b/dom/ipc/TabChild.cpp @@ -750,6 +750,39 @@ private: } }; +class TabChild::DelayedDeleteRunnable MOZ_FINAL + : public nsRunnable +{ + nsRefPtr mTabChild; + +public: + DelayedDeleteRunnable(TabChild* aTabChild) + : mTabChild(aTabChild) + { + MOZ_ASSERT(NS_IsMainThread()); + MOZ_ASSERT(aTabChild); + } + +private: + ~DelayedDeleteRunnable() + { + MOZ_ASSERT(NS_IsMainThread()); + MOZ_ASSERT(!mTabChild); + } + + NS_IMETHOD + Run() + { + MOZ_ASSERT(NS_IsMainThread()); + MOZ_ASSERT(mTabChild); + + unused << PBrowserChild::Send__delete__(mTabChild); + + mTabChild = nullptr; + return NS_OK; + } +}; + StaticRefPtr sPreallocatedTab; /*static*/ @@ -2748,7 +2781,12 @@ TabChild::RecvDestroy() // XXX what other code in ~TabChild() should we be running here? DestroyWindow(); - return Send__delete__(this); + // Bounce through the event loop once to allow any delayed teardown runnables + // that were just generated to have a chance to run. + nsCOMPtr deleteRunnable = new DelayedDeleteRunnable(this); + MOZ_ALWAYS_TRUE(NS_SUCCEEDED(NS_DispatchToCurrentThread(deleteRunnable))); + + return true; } bool diff --git a/dom/ipc/TabChild.h b/dom/ipc/TabChild.h index a81bcfe9a44b..732bdcc3fde5 100644 --- a/dom/ipc/TabChild.h +++ b/dom/ipc/TabChild.h @@ -583,6 +583,7 @@ private: class CachedFileDescriptorInfo; class CachedFileDescriptorCallbackRunnable; + class DelayedDeleteRunnable; TextureFactoryIdentifier mTextureFactoryIdentifier; nsCOMPtr mWebNav;