Bug 1401069 - Part 1. Check the value of mPDFDoc and early return if it's invalid in both RenderPageToDC and DrawPageToFile. r=fatseng
authorcku <cku@mozilla.com>
Mon, 18 Sep 2017 23:59:29 +0800
changeset 431678 74f2aee990a98f2dd905fb2f62cab340dfc1b8b4
parent 431677 b37909c3b506a2196d9e7c41c8f72e23b15eb3c9
child 431679 44ec9e64a5e3c9a8c54b441e9660621a7278d84f
push id7785
push userryanvm@gmail.com
push dateThu, 21 Sep 2017 13:39:55 +0000
treeherdermozilla-beta@06d4034a8a03 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfatseng
bugs1401069
milestone57.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1401069 - Part 1. Check the value of mPDFDoc and early return if it's invalid in both RenderPageToDC and DrawPageToFile. r=fatseng MozReview-Commit-ID: LQ9LTL8ZRKJ
widget/windows/PDFViaEMFPrintHelper.cpp
--- a/widget/windows/PDFViaEMFPrintHelper.cpp
+++ b/widget/windows/PDFViaEMFPrintHelper.cpp
@@ -110,27 +110,35 @@ PDFViaEMFPrintHelper::RenderPageToDC(HDC
 
   return true;
 }
 
 bool
 PDFViaEMFPrintHelper::DrawPage(HDC aPrinterDC, unsigned int aPageIndex,
                                int aPageWidth, int aPageHeight)
 {
+  MOZ_ASSERT(aPrinterDC);
+
+  // OpenDocument might fail.
+  if (!mPDFDoc) {
+    MOZ_ASSERT_UNREACHABLE("Make sure OpenDocument return true before"
+                           "using DrawPage.");
+    return false;
+  }
+
   // There is a comment in Chromium.
   // https://cs.chromium.org/chromium/src/pdf/pdfium/pdfium_engine.cc?rcl=9ad9f6860b4d6a4ec7f7f975b2c99672e02d5d49&l=4008
   // Some PDFs seems to render very slowly if RenderPageToDC is directly used
   // on a printer DC.
   // The way Chromium works around the issue at the code linked above is to
   // print to a bitmap and send that to a printer.  Instead of doing that we
   // render to an EMF file and replay that on the printer DC.  It is unclear
   // whether our approach will avoid the performance issues though.  Bug
   // 1359298 covers investigating that.
 
-  MOZ_ASSERT(aPrinterDC);
   WindowsEMF emf;
   bool result = emf.InitForDrawing();
   NS_ENSURE_TRUE(result, false);
 
   result = RenderPageToDC(emf.GetDC(), aPageIndex, aPageWidth, aPageHeight);
   NS_ENSURE_TRUE(result, false);
 
   RECT printRect = {0, 0, aPageWidth, aPageHeight};
@@ -138,16 +146,23 @@ PDFViaEMFPrintHelper::DrawPage(HDC aPrin
   return result;
 }
 
 bool
 PDFViaEMFPrintHelper::DrawPageToFile(const wchar_t* aFilePath,
                                      unsigned int aPageIndex,
                                      int aPageWidth, int aPageHeight)
 {
+  // OpenDocument might fail.
+  if (!mPDFDoc) {
+    MOZ_ASSERT_UNREACHABLE("Make sure OpenDocument return true before"
+                           "using DrawPageToFile.");
+    return false;
+  }
+
   WindowsEMF emf;
   bool result = emf.InitForDrawing(aFilePath);
   NS_ENSURE_TRUE(result, false);
 
   result = RenderPageToDC(emf.GetDC(), aPageIndex, aPageWidth, aPageHeight);
   NS_ENSURE_TRUE(result, false);
   return emf.SaveToFile();
 }