From 2a1feb9d190812a2054c2ad977a1d6540c6809d1 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Wed, 19 Jul 2017 17:22:05 +1000 Subject: [PATCH] Bug 1352573 (part 1) - Convert FlashThrottleAsyncMsg from a ChildAsyncCall to a CancelableRunnable. r=bsmedberg. This requires adding mPendingFlashThrottleMsgs to PluginInstanceChild. It also requires adding FlashThrottleMsg::mInstance, and a FlashThrottleMsg::Cancel() function that nulls mInstance. --HG-- extra : rebase_source : 87e5732ddf2ad57d4f3ff078ab66143797eac49f --- dom/plugins/ipc/PluginInstanceChild.cpp | 41 +++++++++++++++++-------- dom/plugins/ipc/PluginInstanceChild.h | 17 +++++----- 2 files changed, 38 insertions(+), 20 deletions(-) diff --git a/dom/plugins/ipc/PluginInstanceChild.cpp b/dom/plugins/ipc/PluginInstanceChild.cpp index da9406aa7974..c1cd85dbc985 100644 --- a/dom/plugins/ipc/PluginInstanceChild.cpp +++ b/dom/plugins/ipc/PluginInstanceChild.cpp @@ -2339,7 +2339,7 @@ PluginInstanceChild::SetupFlashMsgThrottle() } WNDPROC -PluginInstanceChild::FlashThrottleAsyncMsg::GetProc() +PluginInstanceChild::FlashThrottleMsg::GetProc() { if (mInstance) { return mWindowed ? mInstance->mPluginWndProc : @@ -2349,13 +2349,17 @@ PluginInstanceChild::FlashThrottleAsyncMsg::GetProc() } NS_IMETHODIMP -PluginInstanceChild::FlashThrottleAsyncMsg::Run() +PluginInstanceChild::FlashThrottleMsg::Run() { - RemoveFromAsyncList(); + if (!mInstance) { + return NS_OK; + } + + mInstance->mPendingFlashThrottleMsgs.RemoveElement(this); // GetProc() checks mInstance, and pulls the procedure from // PluginInstanceChild. We don't transport sub-class procedure - // ptrs around in FlashThrottleAsyncMsg msgs. + // ptrs around in FlashThrottleMsg msgs. if (!GetProc()) return NS_OK; @@ -2364,6 +2368,14 @@ PluginInstanceChild::FlashThrottleAsyncMsg::Run() return NS_OK; } +nsresult +PluginInstanceChild::FlashThrottleMsg::Cancel() +{ + MOZ_ASSERT(mInstance); + mInstance = nullptr; + return NS_OK; +} + void PluginInstanceChild::FlashThrottleMessage(HWND aWnd, UINT aMsg, @@ -2371,15 +2383,13 @@ PluginInstanceChild::FlashThrottleMessage(HWND aWnd, LPARAM aLParam, bool isWindowed) { - // We reuse ChildAsyncCall so we get the cancelation work - // that's done in Destroy. - RefPtr task = - new FlashThrottleAsyncMsg(this, aWnd, aMsg, aWParam, - aLParam, isWindowed); - { - MutexAutoLock lock(mAsyncCallMutex); - mPendingAsyncCalls.AppendElement(task); - } + // We save a reference to the FlashThrottleMsg so we can cancel it in + // Destroy if it's still alive. + RefPtr task = + new FlashThrottleMsg(this, aWnd, aMsg, aWParam, aLParam, isWindowed); + + mPendingFlashThrottleMsgs.AppendElement(task); + MessageLoop::current()->PostDelayedTask(task.forget(), kFlashWMUSERMessageThrottleDelayMs); } @@ -4262,6 +4272,11 @@ PluginInstanceChild::Destroy() DestroyWinlessPopupSurrogate(); UnhookWinlessFlashThrottle(); DestroyPluginWindow(); + + for (uint32_t i = 0; i < mPendingFlashThrottleMsgs.Length(); ++i) { + mPendingFlashThrottleMsgs[i]->Cancel(); + } + mPendingFlashThrottleMsgs.Clear(); #endif // Pending async calls are discarded, not delivered. This matches the diff --git a/dom/plugins/ipc/PluginInstanceChild.h b/dom/plugins/ipc/PluginInstanceChild.h index abd056fef388..21ac56eb88cf 100644 --- a/dom/plugins/ipc/PluginInstanceChild.h +++ b/dom/plugins/ipc/PluginInstanceChild.h @@ -348,15 +348,13 @@ private: static BOOL WINAPI ImmNotifyIME(HIMC aIMC, DWORD aAction, DWORD aIndex, DWORD aValue); - class FlashThrottleAsyncMsg : public ChildAsyncCall + class FlashThrottleMsg : public CancelableRunnable { public: - FlashThrottleAsyncMsg(); - FlashThrottleAsyncMsg(PluginInstanceChild* aInst, - HWND aWnd, UINT aMsg, - WPARAM aWParam, LPARAM aLParam, - bool isWindowed) - : ChildAsyncCall(aInst, nullptr, nullptr), + FlashThrottleMsg(PluginInstanceChild* aInstance, HWND aWnd, UINT aMsg, + WPARAM aWParam, LPARAM aLParam, bool isWindowed) + : CancelableRunnable("FlashThrottleMsg"), + mInstance(aInstance), mWnd(aWnd), mMsg(aMsg), mWParam(aWParam), @@ -365,6 +363,7 @@ private: {} NS_IMETHOD Run() override; + nsresult Cancel() override; WNDPROC GetProc(); HWND GetWnd() { return mWnd; } @@ -373,6 +372,7 @@ private: LPARAM GetLParam() { return mLParam; } private: + PluginInstanceChild* mInstance; HWND mWnd; UINT mMsg; WPARAM mWParam; @@ -450,6 +450,9 @@ private: friend class ChildAsyncCall; +#if defined(OS_WIN) + nsTArray mPendingFlashThrottleMsgs; +#endif Mutex mAsyncCallMutex; nsTArray mPendingAsyncCalls; nsTArray > mTimers;