Bug 1399787 - Part 8. Open PDFium protocol channel. draft
authorcku <cku@mozilla.com>
Tue, 17 Oct 2017 12:48:30 +0800
changeset 710604 8d83f08b89f3d3c4e0a5c0a5f1e8791c53219a9c
parent 710603 b27ad0e0ab569b7a6e68f4e783f14d53833a0b82
child 710605 6ee4003807cbcf7e0a5b7df83471df2e38a3599a
push id92855
push usercku@mozilla.com
push dateMon, 11 Dec 2017 02:44:26 +0000
bugs1399787
milestone59.0a1
Bug 1399787 - Part 8. Open PDFium protocol channel. MozReview-Commit-ID: F9W9ykEtVmK
widget/windows/PDFiumProcessParent.cpp
widget/windows/PDFiumProcessParent.h
--- a/widget/windows/PDFiumProcessParent.cpp
+++ b/widget/windows/PDFiumProcessParent.cpp
@@ -21,23 +21,53 @@ PDFiumProcessParent::PDFiumProcessParent
   : GeckoChildProcessHost(GeckoProcessType_PDFium)
 {
   MOZ_COUNT_CTOR(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
 } // namespace mozilla
--- a/widget/windows/PDFiumProcessParent.h
+++ b/widget/windows/PDFiumProcessParent.h
@@ -6,16 +6,25 @@
 
 #ifndef PDFIUMPROCESSPARENT_H
 #define PDFIUMPROCESSPARENT_H
 
 #include "chrome/common/child_process_host.h"
 #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 {
 
 class PDFiumProcessParent final : public mozilla::ipc::GeckoChildProcessHost
 {
 public:
   PDFiumProcessParent();
@@ -25,14 +34,17 @@ public:
 
   void Delete();
 
   bool CanShutdown() override { return true; }
 
 private:
 
   DISALLOW_COPY_AND_ASSIGN(PDFiumProcessParent);
+
+  RefPtr<PDFiumParent> mPDFiumParentActor;
+  nsCOMPtr<nsIThread> mLaunchThread;
 };
 
 } // namespace widget
 } // namespace mozilla
 
 #endif // ifndef PDFIUMPROCESSPARENT_H