Bug 1399787 - Part 4. Launch the PDFium process. draft
authorcku <cku@mozilla.com>
Tue, 17 Oct 2017 12:35:06 +0800
changeset 686696 1653e0f0e1b271c8d5bfca169e9b36ed695fde8f
parent 686695 5392184da9fbc0ee261c98a70f6d2c140df88e98
child 686697 1e9cf0c5635e1f94339f49adb30aa9164d173473
push id86258
push usercku@mozilla.com
push dateThu, 26 Oct 2017 08:49:17 +0000
bugs1399787
milestone58.0a1
Bug 1399787 - Part 4. Launch the PDFium process. MozReview-Commit-ID: FK4jdb9hvgB
widget/windows/nsDeviceContextSpecWin.cpp
widget/windows/nsDeviceContextSpecWin.h
--- a/widget/windows/nsDeviceContextSpecWin.cpp
+++ b/widget/windows/nsDeviceContextSpecWin.cpp
@@ -36,16 +36,17 @@
 
 #ifdef MOZ_ENABLE_SKIA_PDF
 #include "mozilla/gfx/PrintTargetSkPDF.h"
 #include "nsIUUIDGenerator.h"
 #include "mozilla/widget/PDFViaEMFPrintHelper.h"
 #include "nsDirectoryServiceDefs.h"
 #include "nsPrintfCString.h"
 #include "nsThreadUtils.h"
+#include "PDFiumProcessParent.h"
 #endif
 
 static mozilla::LazyLogModule kWidgetPrintingLogMod("printing-widget");
 #define PR_PL(_p1)  MOZ_LOG(kWidgetPrintingLogMod, mozilla::LogLevel::Debug, _p1)
 
 using namespace mozilla;
 using namespace mozilla::gfx;
 
@@ -99,16 +100,17 @@ nsDeviceContextSpecWin::nsDeviceContextS
 {
   mDevMode       = nullptr;
 #ifdef MOZ_ENABLE_SKIA_PDF
   mPrintViaSkPDF          = false;
   mDC                     = NULL;
   mPDFPageCount           = 0;
   mPDFCurrentPageNum      = 0;
   mPrintViaPDFInProgress  = false;
+  mPDFiumProcess = nullptr;
 #endif
 }
 
 
 //----------------------------------------------------------------------------------
 
 NS_IMPL_ISUPPORTS(nsDeviceContextSpecWin, nsIDeviceContextSpec)
 
@@ -371,16 +373,21 @@ nsDeviceContextSpecWin::CleanupPrintViaP
   if (mDC != NULL) {
     if (mPrintViaPDFInProgress) {
       ::EndDoc(mDC);
       mPrintViaPDFInProgress = false;
     }
     ::DeleteDC(mDC);
     mDC = NULL;
   }
+
+  if (mPDFiumProcess) {
+    mPDFiumProcess->Delete();
+    mPDFiumProcess = nullptr;
+  }
 }
 
 void
 nsDeviceContextSpecWin::FinishPrintViaPDF()
 {
   MOZ_ASSERT(mDC != NULL);
   MOZ_ASSERT(mPDFPrintHelper);
   MOZ_ASSERT(mPDFTempFile);
@@ -449,16 +456,20 @@ nsDeviceContextSpecWin::BeginDocument(co
 
     if (::StartDocW(mDC, &di) <= 0) {
       // Defer calling CleanupPrintViaPDF() in destructor because PDF temp file
       // is not ready yet.
       return NS_ERROR_FAILURE;
     }
 
     mPrintViaPDFInProgress = true;
+
+    MOZ_ASSERT(!mPDFiumProcess);
+    mPDFiumProcess = new PDFiumProcessParent();
+    NS_ENSURE_TRUE(mPDFiumProcess->Launch(), NS_ERROR_FAILURE);
   }
 #endif
 
   return NS_OK;
 }
 
 nsresult
 nsDeviceContextSpecWin::EndDocument()
--- a/widget/windows/nsDeviceContextSpecWin.h
+++ b/widget/windows/nsDeviceContextSpecWin.h
@@ -16,24 +16,26 @@
 #include "mozilla/RefPtr.h"
 
 class nsIWidget;
 
 #ifdef MOZ_ENABLE_SKIA_PDF
 namespace mozilla {
 namespace widget {
 class PDFViaEMFPrintHelper;
+class PDFiumProcessParent;
 }
 }
 #endif
 
 class nsDeviceContextSpecWin : public nsIDeviceContextSpec
 {
 #ifdef MOZ_ENABLE_SKIA_PDF
   typedef mozilla::widget::PDFViaEMFPrintHelper PDFViaEMFPrintHelper;
+  typedef mozilla::widget::PDFiumProcessParent PDFiumProcessParent;
 #endif
 
 public:
   nsDeviceContextSpecWin();
 
   NS_DECL_ISUPPORTS
 
   virtual already_AddRefed<PrintTarget> MakePrintTarget() final;
@@ -88,16 +90,18 @@ protected:
   // whether print-to-PDF uses Skia.
   bool mPrintViaSkPDF;
   nsCOMPtr<nsIFile> mPDFTempFile;
   HDC mDC;
   bool mPrintViaPDFInProgress;
   mozilla::UniquePtr<PDFViaEMFPrintHelper> mPDFPrintHelper;
   int mPDFPageCount;
   int mPDFCurrentPageNum;
+
+  PDFiumProcessParent* mPDFiumProcess;
 #endif
 };
 
 
 //-------------------------------------------------------------------------
 // Printer Enumerator
 //-------------------------------------------------------------------------
 class nsPrinterEnumeratorWin final : public nsIPrinterEnumerator