Bug 1401069 - Part 1. Check the value of mPDFDoc and early return if it's invalid in both RenderPageToDC and DrawPageToFile.
MozReview-Commit-ID: LQ9LTL8ZRKJ
--- 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();
}