From a46e2d8e4439017eeaeb92147826f49586a64ade Mon Sep 17 00:00:00 2001 From: cku Date: Tue, 17 Oct 2017 12:48:30 +0800 Subject: [PATCH] Bug 1399787 - Part 8. Open PDFium protocol channel. r=jwatt MozReview-Commit-ID: F9W9ykEtVmK --HG-- extra : rebase_source : 41936e4b7ffdb5ec00a005d4aeaa2754fe2f6daa extra : intermediate-source : f9ef88f9ddc9ddb114633075472f5a20985d8c39 extra : source : 63e98299090e4fb98c2fb50aa9eaac35f35ca232 --- widget/windows/PDFiumProcessParent.cpp | 32 +++++++++++++++++++++++++- widget/windows/PDFiumProcessParent.h | 12 ++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) 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