diff --git a/dom/plugins/ipc/PluginInstanceChild.cpp b/dom/plugins/ipc/PluginInstanceChild.cpp index 4425fbc86c40..e978307323cc 100644 --- a/dom/plugins/ipc/PluginInstanceChild.cpp +++ b/dom/plugins/ipc/PluginInstanceChild.cpp @@ -2365,11 +2365,7 @@ PluginInstanceChild::RecvAsyncNPP_NewStream(PBrowserStreamChild* actor, BrowserStreamChild* child = static_cast(actor); NewStreamAsyncCall* task = new NewStreamAsyncCall(this, child, mimeType, seekable); - { - MutexAutoLock lock(mAsyncCallMutex); - mPendingAsyncCalls.AppendElement(task); - } - MessageLoop::current()->PostTask(FROM_HERE, task); + PostChildAsyncCall(task); return true; } @@ -3645,12 +3641,17 @@ void PluginInstanceChild::AsyncCall(PluginThreadCallback aFunc, void* aUserData) { ChildAsyncCall* task = new ChildAsyncCall(this, aFunc, aUserData); + PostChildAsyncCall(task); +} +void +PluginInstanceChild::PostChildAsyncCall(ChildAsyncCall* aTask) +{ { MutexAutoLock lock(mAsyncCallMutex); - mPendingAsyncCalls.AppendElement(task); + mPendingAsyncCalls.AppendElement(aTask); } - ProcessChild::message_loop()->PostTask(FROM_HERE, task); + ProcessChild::message_loop()->PostTask(FROM_HERE, aTask); } static PLDHashOperator diff --git a/dom/plugins/ipc/PluginInstanceChild.h b/dom/plugins/ipc/PluginInstanceChild.h index 04eaf2aacdd8..2fc5a75d66fc 100644 --- a/dom/plugins/ipc/PluginInstanceChild.h +++ b/dom/plugins/ipc/PluginInstanceChild.h @@ -245,6 +245,8 @@ public: void UnscheduleTimer(uint32_t id); void AsyncCall(PluginThreadCallback aFunc, void* aUserData); + // This function is a more general version of AsyncCall + void PostChildAsyncCall(ChildAsyncCall* aTask); int GetQuirks(); diff --git a/dom/plugins/ipc/PluginModuleChild.cpp b/dom/plugins/ipc/PluginModuleChild.cpp index 08d7af74d22c..513cddf01219 100644 --- a/dom/plugins/ipc/PluginModuleChild.cpp +++ b/dom/plugins/ipc/PluginModuleChild.cpp @@ -2177,6 +2177,26 @@ PluginModuleChild::AnswerSyncNPP_New(PPluginInstanceChild* aActor, NPError* rv) return true; } +class AsyncNewResultSender : public ChildAsyncCall +{ +public: + AsyncNewResultSender(PluginInstanceChild* aInstance, NPError aResult) + : ChildAsyncCall(aInstance, nullptr, nullptr) + , mResult(aResult) + { + } + + void Run() override + { + RemoveFromAsyncList(); + DebugOnly sendOk = mInstance->SendAsyncNPP_NewResult(mResult); + MOZ_ASSERT(sendOk); + } + +private: + NPError mResult; +}; + bool PluginModuleChild::RecvAsyncNPP_New(PPluginInstanceChild* aActor) { @@ -2185,7 +2205,8 @@ PluginModuleChild::RecvAsyncNPP_New(PPluginInstanceChild* aActor) reinterpret_cast(aActor); AssertPluginThread(); NPError rv = childInstance->DoNPP_New(); - childInstance->SendAsyncNPP_NewResult(rv); + AsyncNewResultSender* task = new AsyncNewResultSender(childInstance, rv); + childInstance->PostChildAsyncCall(task); return true; }