Bug 1358076 - Part1. Create an API to load a PDF file by |const char*| draft
authorFarmer Tseng <fatseng@mozilla.com>
Tue, 11 Jul 2017 16:04:05 +0800
changeset 606657 1b621c7707f79dcd06c64e37dcb20a004c0b9b53
parent 606656 ccbfda9a51a833dc659dfe4e2d209fa59500d003
child 606658 b2cb9e6348428feaeb38e744d870c661518025c3
push id67764
push userbmo:fatseng@mozilla.com
push dateTue, 11 Jul 2017 08:05:10 +0000
bugs1358076
milestone56.0a1
Bug 1358076 - Part1. Create an API to load a PDF file by |const char*| MozReview-Commit-ID: FKyrJtwGTmR
widget/windows/PDFViaEMFPrintHelper.cpp
widget/windows/PDFViaEMFPrintHelper.h
--- a/widget/windows/PDFViaEMFPrintHelper.cpp
+++ b/widget/windows/PDFViaEMFPrintHelper.cpp
@@ -38,33 +38,40 @@ PDFViaEMFPrintHelper::~PDFViaEMFPrintHel
 {
   CloseDocument();
 }
 
 nsresult
 PDFViaEMFPrintHelper::OpenDocument(nsIFile *aFile)
 {
   MOZ_ASSERT(aFile);
+
+  nsAutoCString nativePath;
+  nsresult rv = aFile->GetNativePath(nativePath);
+  if (NS_FAILED(rv)) {
+    return rv;
+  }
+
+  return OpenDocument(nativePath.get());
+}
+
+nsresult
+PDFViaEMFPrintHelper::OpenDocument(const char* aFile)
+{
   if (mPDFDoc) {
     MOZ_ASSERT_UNREACHABLE("We can only open one PDF at a time");
     return NS_ERROR_FAILURE;
   }
 
   if (!mPDFiumEngine) {
     mPDFiumEngine = PDFiumEngineShim::GetInstanceOrNull();
     NS_ENSURE_TRUE(mPDFiumEngine, NS_ERROR_FAILURE);
   }
 
-  nsAutoCString nativePath;
-  nsresult rv = aFile->GetNativePath(nativePath);
-  if (NS_FAILED(rv)) {
-    return rv;
-  }
-
-  mPDFDoc = mPDFiumEngine->LoadDocument(nativePath.get(), nullptr);
+  mPDFDoc = mPDFiumEngine->LoadDocument(aFile, nullptr);
   if (!mPDFDoc) {
     return NS_ERROR_FAILURE;
   }
 
   if (mPDFiumEngine->GetPageCount(mPDFDoc) < 1) {
     CloseDocument();
     return NS_ERROR_FAILURE;
   }
--- a/widget/windows/PDFViaEMFPrintHelper.h
+++ b/widget/windows/PDFViaEMFPrintHelper.h
@@ -28,16 +28,17 @@ namespace widget {
 class PDFViaEMFPrintHelper
 {
 public:
   PDFViaEMFPrintHelper();
   ~PDFViaEMFPrintHelper();
 
   /** Loads the specified PDF file. */
   NS_IMETHOD OpenDocument(nsIFile *aFile);
+  NS_IMETHOD OpenDocument(const char* aFile);
 
   /** Releases document buffer. */
   void CloseDocument();
 
   int GetPageCount() { return mPDFiumEngine->GetPageCount(mPDFDoc); }
 
   /** Convert specified PDF page to EMF and draw the EMF onto the given DC. */
   bool DrawPage(HDC aPrinterDC, unsigned int aPageIndex,