Bug 1399787 - Part 7. Have PrintTargetEMF launch the PDFium process. draft
authorcku <cku@mozilla.com>
Wed, 29 Nov 2017 17:15:31 +0800
changeset 710603 b27ad0e0ab569b7a6e68f4e783f14d53833a0b82
parent 710602 353fb3919b056e20ffc75f05ef9f5073fc65fa4a
child 710604 8d83f08b89f3d3c4e0a5c0a5f1e8791c53219a9c
push id92855
push usercku@mozilla.com
push dateMon, 11 Dec 2017 02:44:26 +0000
bugs1399787
milestone59.0a1
Bug 1399787 - Part 7. Have PrintTargetEMF launch the PDFium process. MozReview-Commit-ID: CVfB81ifV2p
gfx/thebes/PrintTargetEMF.cpp
gfx/thebes/PrintTargetEMF.h
widget/windows/moz.build
--- a/gfx/thebes/PrintTargetEMF.cpp
+++ b/gfx/thebes/PrintTargetEMF.cpp
@@ -1,28 +1,37 @@
 /* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "PrintTargetEMF.h"
 #include "nsAnonymousTemporaryFile.h"
 #include "nsIFile.h"
+#include "mozilla/widget/PDFiumProcessParent.h"
 
 using mozilla::gfx::DrawTarget;
 
 namespace mozilla {
 namespace gfx {
 
 PrintTargetEMF::PrintTargetEMF(HDC aDC, const IntSize& aSize)
   : PrintTarget(/* not using cairo_surface_t */ nullptr, aSize)
+  , mPDFiumProcess(nullptr)
   , mPrinterDC(aDC)
 {
 }
 
+PrintTargetEMF::~PrintTargetEMF()
+{
+  if (mPDFiumProcess) {
+    mPDFiumProcess->Delete();
+  }
+}
+
 /* static */ already_AddRefed<PrintTargetEMF>
 PrintTargetEMF::CreateOrNull(HDC aDC, const IntSize& aSizeInPoints)
 {
   return do_AddRef(new PrintTargetEMF(aDC, aSizeInPoints));
 }
 
 nsresult
 PrintTargetEMF::BeginPrinting(const nsAString& aTitle,
@@ -46,16 +55,19 @@ PrintTargetEMF::BeginPrinting(const nsAS
   docinfo.cbSize = sizeof(docinfo);
   docinfo.lpszDocName = titleStr.Length() > 0 ? titleStr.get() : L"Mozilla Document";
   docinfo.lpszOutput = docName.Length() > 0 ? docName.get() : nullptr;
   docinfo.lpszDatatype = nullptr;
   docinfo.fwType = 0;
 
   ::StartDocW(mPrinterDC, &docinfo);
 
+  mPDFiumProcess = new PDFiumProcessParent();
+  NS_ENSURE_TRUE(mPDFiumProcess->Launch(), NS_ERROR_FAILURE);
+
   return NS_OK;
 }
 
 nsresult
 PrintTargetEMF::EndPrinting()
 {
   return (::EndDoc(mPrinterDC) <= 0) ? NS_ERROR_FAILURE : NS_OK;
 }
--- a/gfx/thebes/PrintTargetEMF.h
+++ b/gfx/thebes/PrintTargetEMF.h
@@ -7,30 +7,37 @@
 #define MOZILLA_GFX_PRINTTARGETEMF_H
 
 #include "PrintTargetSkPDF.h"
 
 /* include windows.h for the HDC definitions that we need. */
 #include <windows.h>
 
 namespace mozilla {
+namespace widget {
+  class PDFiumProcessParent;
+}
+}
+
+namespace mozilla {
 namespace gfx {
 
 /**
  * A new subclass of PrintTarget.
  * 1. It uses PrintTargetSkPDF to generate one PDF file for one page.
  * 2. It then passes the FileDescriptor of that generated PDF file to the
  *    PDFium process for EMF conversion.
  * 3. After getting the converted EMF contents from the PDFium process, it then
  *    draws it onto the printer DC to finish one page printing task.
  */
 class PrintTargetEMF final : public mozilla::gfx::PrintTarget
 {
 public:
   typedef gfx::IntSize IntSize;
+  typedef mozilla::widget::PDFiumProcessParent PDFiumProcessParent;
 
   static already_AddRefed<PrintTargetEMF>
   CreateOrNull(HDC aDC, const IntSize& aSizeInPoints);
 
   nsresult BeginPrinting(const nsAString& aTitle,
                                  const nsAString& aPrintToFileName,
                                  int32_t aStartPage,
                                  int32_t aEndPage) final;
@@ -43,20 +50,22 @@ public:
   MakeDrawTarget(const IntSize& aSize,
                  DrawEventRecorder* aRecorder = nullptr) final;
 
   already_AddRefed<DrawTarget>
   GetReferenceDrawTarget(DrawEventRecorder* aRecorder) final;
 
 private:
   PrintTargetEMF(HDC aDC, const IntSize& aSize);
+  ~PrintTargetEMF() override;
 
   nsString mTitle;
   RefPtr<PrintTargetSkPDF> mTargetForCurrentPage;
   nsCOMPtr<nsIFile>        mPDFFileForOnePage;
   RefPtr<PrintTargetSkPDF> mRefTarget;
+  PDFiumProcessParent*     mPDFiumProcess;
   HDC mPrinterDC;
 };
 
 } // namespace gfx
 } // namespace mozilla
 
 #endif /* MOZILLA_GFX_PRINTTARGETEMF_H */
--- a/widget/windows/moz.build
+++ b/widget/windows/moz.build
@@ -22,16 +22,17 @@ EXPORTS.mozilla.widget += [
     'AudioSession.h',
     'CompositorWidgetChild.h',
     'CompositorWidgetParent.h',
     'InProcessWinCompositorWidget.h',
     'PDFiumChild.h',
     'PDFiumEngineShim.h',
     'PDFiumParent.h',
     'PDFiumProcessChild.h',
+    'PDFiumProcessParent.h',
     'PDFViaEMFPrintHelper.h',
     'WinCompositorWidget.h',
     'WinMessages.h',
     'WinModifierKeyState.h',
     'WinNativeEventData.h',
 ]
 
 UNIFIED_SOURCES += [