diff options
author | tsepez <tsepez@chromium.org> | 2016-11-28 17:30:09 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-11-28 17:30:09 -0800 |
commit | 05e01698444726fae302cd335fa4880932d7c543 (patch) | |
tree | 011f7693d29e4c6726966fa1b13d5a075a1a8dea /fpdfsdk | |
parent | 405ac0f09e1622d7ff3cf60314d290851ac9f7fd (diff) | |
download | pdfium-05e01698444726fae302cd335fa4880932d7c543.tar.xz |
Make FDF document creation return unique_ptrs
Review-Url: https://codereview.chromium.org/2538533003
Diffstat (limited to 'fpdfsdk')
-rw-r--r-- | fpdfsdk/cpdfsdk_interform.cpp | 28 |
1 files changed, 9 insertions, 19 deletions
diff --git a/fpdfsdk/cpdfsdk_interform.cpp b/fpdfsdk/cpdfsdk_interform.cpp index f8fd3b3db5..a2f07b488f 100644 --- a/fpdfsdk/cpdfsdk_interform.cpp +++ b/fpdfsdk/cpdfsdk_interform.cpp @@ -463,7 +463,8 @@ bool CPDFSDK_InterForm::FDFToURLEncodedData(CFX_WideString csFDFFile, bool CPDFSDK_InterForm::FDFToURLEncodedData(uint8_t*& pBuf, FX_STRSIZE& nBufSize) { - CFDF_Document* pFDF = CFDF_Document::ParseMemory(pBuf, nBufSize); + std::unique_ptr<CFDF_Document> pFDF = + CFDF_Document::ParseMemory(pBuf, nBufSize); if (!pFDF) return true; @@ -506,9 +507,9 @@ bool CPDFSDK_InterForm::ExportFieldsToFDFTextBuf( const std::vector<CPDF_FormField*>& fields, bool bIncludeOrExclude, CFX_ByteTextBuf& textBuf) { - std::unique_ptr<CFDF_Document> pFDF( + std::unique_ptr<CFDF_Document> pFDF = m_pInterForm->ExportToFDF(m_pFormFillEnv->JS_docGetFilePath().AsStringC(), - fields, bIncludeOrExclude, false)); + fields, bIncludeOrExclude, false); return pFDF ? pFDF->WriteBuf(textBuf) : false; } @@ -525,26 +526,21 @@ bool CPDFSDK_InterForm::SubmitForm(const CFX_WideString& sDestination, if (!m_pFormFillEnv || !m_pInterForm) return false; - CFX_WideString wsPDFFilePath = m_pFormFillEnv->JS_docGetFilePath(); - CFDF_Document* pFDFDoc = - m_pInterForm->ExportToFDF(wsPDFFilePath.AsStringC(), false); + std::unique_ptr<CFDF_Document> pFDFDoc = m_pInterForm->ExportToFDF( + m_pFormFillEnv->JS_docGetFilePath().AsStringC(), false); if (!pFDFDoc) return false; CFX_ByteTextBuf FdfBuffer; - bool bRet = pFDFDoc->WriteBuf(FdfBuffer); - delete pFDFDoc; - if (!bRet) + if (!pFDFDoc->WriteBuf(FdfBuffer)) return false; uint8_t* pBuffer = FdfBuffer.GetBuffer(); FX_STRSIZE nBufSize = FdfBuffer.GetLength(); - if (bUrlEncoded && !FDFToURLEncodedData(pBuffer, nBufSize)) return false; m_pFormFillEnv->JS_docSubmitForm(pBuffer, nBufSize, sDestination.c_str()); - if (bUrlEncoded) FX_Free(pBuffer); @@ -552,15 +548,9 @@ bool CPDFSDK_InterForm::SubmitForm(const CFX_WideString& sDestination, } bool CPDFSDK_InterForm::ExportFormToFDFTextBuf(CFX_ByteTextBuf& textBuf) { - CFDF_Document* pFDF = m_pInterForm->ExportToFDF( + std::unique_ptr<CFDF_Document> pFDF = m_pInterForm->ExportToFDF( m_pFormFillEnv->JS_docGetFilePath().AsStringC(), false); - if (!pFDF) - return false; - - bool bRet = pFDF->WriteBuf(textBuf); - delete pFDF; - - return bRet; + return pFDF && pFDF->WriteBuf(textBuf); } bool CPDFSDK_InterForm::DoAction_ResetForm(const CPDF_Action& action) { |