diff options
author | tsepez <tsepez@chromium.org> | 2016-08-16 11:12:21 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-08-16 11:12:21 -0700 |
commit | 4540fbaa718b0b06e076321e0e1a61e80a161499 (patch) | |
tree | 0264321d30996058a3b120cff7707e93562bb425 /fpdfsdk | |
parent | 3421d2bd1f12dc51916df1869ec8beab8711faec (diff) | |
download | pdfium-4540fbaa718b0b06e076321e0e1a61e80a161499.tar.xz |
Get CPDF_Parser out of the document creation business.
Precursor to someday using possibly subclassed documents.
Review-Url: https://codereview.chromium.org/2248123002
Diffstat (limited to 'fpdfsdk')
-rw-r--r-- | fpdfsdk/fpdf_dataavail.cpp | 11 | ||||
-rw-r--r-- | fpdfsdk/fpdfview.cpp | 40 |
2 files changed, 27 insertions, 24 deletions
diff --git a/fpdfsdk/fpdf_dataavail.cpp b/fpdfsdk/fpdf_dataavail.cpp index b7b47f86a1..3cc7fc0347 100644 --- a/fpdfsdk/fpdf_dataavail.cpp +++ b/fpdfsdk/fpdf_dataavail.cpp @@ -136,18 +136,19 @@ FPDFAvail_GetDocument(FPDF_AVAIL avail, FPDF_BYTESTRING password) { if (!pDataAvail) return nullptr; - CPDF_Parser* pParser = new CPDF_Parser; + std::unique_ptr<CPDF_Parser> pParser(new CPDF_Parser); pParser->SetPassword(password); - CPDF_Parser::Error error = - pParser->StartAsyncParse(pDataAvail->m_pDataAvail->GetFileRead()); + + std::unique_ptr<CPDF_Document> pDocument(new CPDF_Document(pParser.get())); + CPDF_Parser::Error error = pParser->StartAsyncParse( + pDataAvail->m_pDataAvail->GetFileRead(), std::move(pDocument)); if (error != CPDF_Parser::SUCCESS) { - delete pParser; ProcessParseError(error); return nullptr; } pDataAvail->m_pDataAvail->SetDocument(pParser->GetDocument()); CheckUnSupportError(pParser->GetDocument(), FPDF_ERR_SUCCESS); - return FPDFDocumentFromCPDFDocument(pParser->GetDocument()); + return FPDFDocumentFromCPDFDocument(pParser.release()->GetDocument()); } DLLEXPORT int STDCALL FPDFAvail_GetFirstPageNum(FPDF_DOCUMENT doc) { diff --git a/fpdfsdk/fpdfview.cpp b/fpdfsdk/fpdfview.cpp index 8aebb550ff..29fe88d943 100644 --- a/fpdfsdk/fpdfview.cpp +++ b/fpdfsdk/fpdfview.cpp @@ -362,24 +362,25 @@ DLLEXPORT FPDF_DOCUMENT STDCALL FPDF_LoadDocument(FPDF_STRING file_path, return nullptr; } - CPDF_Parser* pParser = new CPDF_Parser; + std::unique_ptr<CPDF_Parser> pParser(new CPDF_Parser); pParser->SetPassword(password); - CPDF_Parser::Error error = pParser->StartParse(pFileAccess); + std::unique_ptr<CPDF_Document> pDocument(new CPDF_Document(pParser.get())); + CPDF_Parser::Error error = + pParser->StartParse(pFileAccess, std::move(pDocument)); if (error != CPDF_Parser::SUCCESS) { - delete pParser; ProcessParseError(error); return nullptr; } #ifdef PDF_ENABLE_XFA - CPDF_Document* pPDFDoc = pParser->GetDocument(); + CPDF_Document* pPDFDoc = pParser.release()->GetDocument(); if (!pPDFDoc) return nullptr; CPDFXFA_App* pProvider = CPDFXFA_App::GetInstance(); return new CPDFXFA_Document(pPDFDoc, pProvider); #else // PDF_ENABLE_XFA - return pParser->GetDocument(); + return pParser.release()->GetDocument(); #endif // PDF_ENABLE_XFA } @@ -446,35 +447,36 @@ class CMemFile final : public IFX_FileRead { DLLEXPORT FPDF_DOCUMENT STDCALL FPDF_LoadMemDocument(const void* data_buf, int size, FPDF_BYTESTRING password) { - CPDF_Parser* pParser = new CPDF_Parser; - pParser->SetPassword(password); CMemFile* pMemFile = new CMemFile((uint8_t*)data_buf, size); - CPDF_Parser::Error error = pParser->StartParse(pMemFile); + std::unique_ptr<CPDF_Parser> pParser(new CPDF_Parser); + pParser->SetPassword(password); + + std::unique_ptr<CPDF_Document> pDocument(new CPDF_Document(pParser.get())); + CPDF_Parser::Error error = + pParser->StartParse(pMemFile, std::move(pDocument)); if (error != CPDF_Parser::SUCCESS) { - delete pParser; ProcessParseError(error); return nullptr; } - CPDF_Document* pDoc = pParser ? pParser->GetDocument() : nullptr; - CheckUnSupportError(pDoc, error); - return FPDFDocumentFromCPDFDocument(pParser->GetDocument()); + CheckUnSupportError(pParser->GetDocument(), error); + return FPDFDocumentFromCPDFDocument(pParser.release()->GetDocument()); } DLLEXPORT FPDF_DOCUMENT STDCALL FPDF_LoadCustomDocument(FPDF_FILEACCESS* pFileAccess, FPDF_BYTESTRING password) { - CPDF_Parser* pParser = new CPDF_Parser; - pParser->SetPassword(password); CPDF_CustomAccess* pFile = new CPDF_CustomAccess(pFileAccess); - CPDF_Parser::Error error = pParser->StartParse(pFile); + std::unique_ptr<CPDF_Parser> pParser(new CPDF_Parser); + pParser->SetPassword(password); + + std::unique_ptr<CPDF_Document> pDocument(new CPDF_Document(pParser.get())); + CPDF_Parser::Error error = pParser->StartParse(pFile, std::move(pDocument)); if (error != CPDF_Parser::SUCCESS) { - delete pParser; ProcessParseError(error); return nullptr; } - CPDF_Document* pDoc = pParser ? pParser->GetDocument() : nullptr; - CheckUnSupportError(pDoc, error); - return FPDFDocumentFromCPDFDocument(pParser->GetDocument()); + CheckUnSupportError(pParser->GetDocument(), error); + return FPDFDocumentFromCPDFDocument(pParser.release()->GetDocument()); } DLLEXPORT FPDF_BOOL STDCALL FPDF_GetFileVersion(FPDF_DOCUMENT doc, |