summaryrefslogtreecommitdiff
path: root/fpdfsdk/cpdfsdk_interform.cpp
diff options
context:
space:
mode:
authorHenrique Nakashima <hnakashima@chromium.org>2017-08-04 12:28:52 -0400
committerChromium commit bot <commit-bot@chromium.org>2017-08-04 16:48:53 +0000
commit5c09f4ca825652f910d3ff406fcbf64d25f56e23 (patch)
tree9af51506fcc914244bc682878801b8d362f6cfdd /fpdfsdk/cpdfsdk_interform.cpp
parenta2da7c5612f1fa26dde508da2a527a4bab381de0 (diff)
downloadpdfium-5c09f4ca825652f910d3ff406fcbf64d25f56e23.tar.xz
Remove CFX_ByteTextBuf from cpdfsdk_interform.cpp and others.chromium/3177
New version of the CL that include fpdf_parser_utility.cpp where there is an overload for CFX_ByteTextBuf << CPDF_Object* used by CFDF_Document. Bug: pdfium:731 Change-Id: I54f4e9ee7e10e94388f6f6584f3999f43689e84c Reviewed-on: https://pdfium-review.googlesource.com/10170 Reviewed-by: Tom Sepez <tsepez@chromium.org> Commit-Queue: Henrique Nakashima <hnakashima@chromium.org>
Diffstat (limited to 'fpdfsdk/cpdfsdk_interform.cpp')
-rw-r--r--fpdfsdk/cpdfsdk_interform.cpp68
1 files changed, 45 insertions, 23 deletions
diff --git a/fpdfsdk/cpdfsdk_interform.cpp b/fpdfsdk/cpdfsdk_interform.cpp
index 552bb31af2..27db1053c6 100644
--- a/fpdfsdk/cpdfsdk_interform.cpp
+++ b/fpdfsdk/cpdfsdk_interform.cpp
@@ -8,6 +8,8 @@
#include <algorithm>
#include <memory>
+#include <sstream>
+#include <string>
#include <vector>
#include "core/fpdfapi/page/cpdf_page.h"
@@ -436,21 +438,28 @@ bool CPDFSDK_InterForm::SubmitFields(const CFX_WideString& csDestination,
const std::vector<CPDF_FormField*>& fields,
bool bIncludeOrExclude,
bool bUrlEncoded) {
- CFX_ByteTextBuf textBuf;
- ExportFieldsToFDFTextBuf(fields, bIncludeOrExclude, textBuf);
+ CFX_ByteString textBuf = ExportFieldsToFDFTextBuf(fields, bIncludeOrExclude);
- uint8_t* pBuffer = textBuf.GetBuffer();
FX_STRSIZE nBufSize = textBuf.GetLength();
+ if (nBufSize == 0)
+ return false;
+
+ uint8_t* pLocalBuffer = FX_Alloc(uint8_t, nBufSize);
+ memcpy(pLocalBuffer, textBuf.c_str(), nBufSize);
+ uint8_t* pBuffer = pLocalBuffer;
- if (bUrlEncoded && !FDFToURLEncodedData(pBuffer, nBufSize))
+ if (bUrlEncoded && !FDFToURLEncodedData(pBuffer, nBufSize)) {
+ FX_Free(pLocalBuffer);
return false;
+ }
m_pFormFillEnv->JS_docSubmitForm(pBuffer, nBufSize, csDestination.c_str());
- return true;
-}
-bool CPDFSDK_InterForm::FDFToURLEncodedData(CFX_WideString csFDFFile,
- CFX_WideString csTxtFile) {
+ if (pBuffer != pLocalBuffer)
+ FX_Free(pBuffer);
+
+ FX_Free(pLocalBuffer);
+
return true;
}
@@ -469,7 +478,7 @@ bool CPDFSDK_InterForm::FDFToURLEncodedData(uint8_t*& pBuf,
if (!pFields)
return false;
- CFX_ByteTextBuf fdfEncodedData;
+ std::ostringstream fdfEncodedData;
for (uint32_t i = 0; i < pFields->GetCount(); i++) {
CPDF_Dictionary* pField = pFields->GetDictAt(i);
if (!pField)
@@ -490,19 +499,22 @@ bool CPDFSDK_InterForm::FDFToURLEncodedData(uint8_t*& pBuf,
fdfEncodedData << "&";
}
- nBufSize = fdfEncodedData.GetLength();
+ nBufSize = fdfEncodedData.tellp();
+ if (nBufSize == 0)
+ return false;
+
pBuf = FX_Alloc(uint8_t, nBufSize);
- memcpy(pBuf, fdfEncodedData.GetBuffer(), nBufSize);
+ memcpy(pBuf, fdfEncodedData.str().c_str(), nBufSize);
return true;
}
-bool CPDFSDK_InterForm::ExportFieldsToFDFTextBuf(
+CFX_ByteString CPDFSDK_InterForm::ExportFieldsToFDFTextBuf(
const std::vector<CPDF_FormField*>& fields,
- bool bIncludeOrExclude,
- CFX_ByteTextBuf& textBuf) {
+ bool bIncludeOrExclude) {
std::unique_ptr<CFDF_Document> pFDF = m_pInterForm->ExportToFDF(
m_pFormFillEnv->JS_docGetFilePath(), fields, bIncludeOrExclude, false);
- return pFDF ? pFDF->WriteBuf(textBuf) : false;
+
+ return pFDF ? pFDF->WriteToString() : CFX_ByteString();
}
CFX_WideString CPDFSDK_InterForm::GetTemporaryFileName(
@@ -523,26 +535,36 @@ bool CPDFSDK_InterForm::SubmitForm(const CFX_WideString& sDestination,
if (!pFDFDoc)
return false;
- CFX_ByteTextBuf FdfBuffer;
- if (!pFDFDoc->WriteBuf(FdfBuffer))
+ CFX_ByteString fdfBuffer = pFDFDoc->WriteToString();
+
+ FX_STRSIZE nBufSize = fdfBuffer.GetLength();
+ if (nBufSize == 0)
return false;
- uint8_t* pBuffer = FdfBuffer.GetBuffer();
- FX_STRSIZE nBufSize = FdfBuffer.GetLength();
- if (bUrlEncoded && !FDFToURLEncodedData(pBuffer, nBufSize))
+ uint8_t* pLocalBuffer = FX_Alloc(uint8_t, nBufSize);
+ memcpy(pLocalBuffer, fdfBuffer.c_str(), nBufSize);
+ uint8_t* pBuffer = pLocalBuffer;
+
+ if (bUrlEncoded && !FDFToURLEncodedData(pBuffer, nBufSize)) {
+ FX_Free(pLocalBuffer);
return false;
+ }
m_pFormFillEnv->JS_docSubmitForm(pBuffer, nBufSize, sDestination.c_str());
- if (bUrlEncoded)
+
+ if (pBuffer != pLocalBuffer)
FX_Free(pBuffer);
+ FX_Free(pLocalBuffer);
+
return true;
}
-bool CPDFSDK_InterForm::ExportFormToFDFTextBuf(CFX_ByteTextBuf& textBuf) {
+CFX_ByteString CPDFSDK_InterForm::ExportFormToFDFTextBuf() {
std::unique_ptr<CFDF_Document> pFDF =
m_pInterForm->ExportToFDF(m_pFormFillEnv->JS_docGetFilePath(), false);
- return pFDF && pFDF->WriteBuf(textBuf);
+
+ return pFDF ? pFDF->WriteToString() : CFX_ByteString();
}
bool CPDFSDK_InterForm::DoAction_ResetForm(const CPDF_Action& action) {