Bug 1358076 - Part1. Create an API to load a PDF file by |const char*|
MozReview-Commit-ID: FKyrJtwGTmR
--- 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,