diff --git a/widget/windows/PDFiumProcessParent.cpp b/widget/windows/PDFiumProcessParent.cpp index a0a26690b8a4..1ac98dd1ca98 100644 --- a/widget/windows/PDFiumProcessParent.cpp +++ b/widget/windows/PDFiumProcessParent.cpp @@ -26,17 +26,47 @@ PDFiumProcessParent::PDFiumProcessParent() PDFiumProcessParent::~PDFiumProcessParent() { MOZ_COUNT_DTOR(PDFiumProcessParent); + + if (mPDFiumParentActor) { + mPDFiumParentActor->Close(); + } } bool PDFiumProcessParent::Launch() { - return SyncLaunch(); + mLaunchThread = NS_GetCurrentThread(); + + if (!SyncLaunch()) { + return false; + } + + // Open the top level protocol for PDFium process. + MOZ_ASSERT(!mPDFiumParentActor); + mPDFiumParentActor = new PDFiumParent(); + return mPDFiumParentActor->Init(GetChannel(), + base::GetProcId(GetChildProcessHandle())); } void PDFiumProcessParent::Delete() { + // PDFiumProcessParent::Launch is not called, protocol is not created. + // It is safe to destroy this object on any thread. + if (!mLaunchThread) { + delete this; + return; + } + + if (mLaunchThread == NS_GetCurrentThread()) { + delete this; + return; + } + + mLaunchThread->Dispatch( + NewNonOwningRunnableMethod("PDFiumProcessParent::Delete", + this, + &PDFiumProcessParent::Delete)); } } // namespace widget diff --git a/widget/windows/PDFiumProcessParent.h b/widget/windows/PDFiumProcessParent.h index eab4f606701c..8fab592a2434 100644 --- a/widget/windows/PDFiumProcessParent.h +++ b/widget/windows/PDFiumProcessParent.h @@ -11,6 +11,15 @@ #include "mozilla/ipc/GeckoChildProcessHost.h" class nsIRunnable; +class nsDeviceContextSpecWin; + +#ifdef MOZ_ENABLE_SKIA_PDF +namespace mozilla { +namespace widget { +class PDFiumParent; +} +} +#endif namespace mozilla { namespace widget { @@ -30,6 +39,9 @@ public: private: DISALLOW_COPY_AND_ASSIGN(PDFiumProcessParent); + + RefPtr mPDFiumParentActor; + nsCOMPtr mLaunchThread; }; } // namespace widget