summaryrefslogtreecommitdiff
path: root/fpdfsdk/cpdfsdk_interform.cpp
diff options
context:
space:
mode:
authorHenrique Nakashima <hnakashima@chromium.org>2017-08-04 15:41:58 +0000
committerChromium commit bot <commit-bot@chromium.org>2017-08-04 15:57:24 +0000
commit1952d17428ba5d509dc21cd8d49abba1bd2d2c5d (patch)
treebf3ec6ae6b2c69bd8636b4b3f4c0b9e8101c68fc /fpdfsdk/cpdfsdk_interform.cpp
parent6061c4167a690308e91ae0c99515c7c9e6380c99 (diff)
downloadpdfium-1952d17428ba5d509dc21cd8d49abba1bd2d2c5d.tar.xz
Revert "Remove CFX_ByteTextBuf from cpdfsdk_interform.cpp and others."
This reverts commit aea80dcc0abc0c310316fa502f91a359bc684758. Reason for revert: WriteBuf's behavior was altered Original change's description: > Remove CFX_ByteTextBuf from cpdfsdk_interform.cpp and others. > > Bug: pdfium:731 > Change-Id: I61d38ab3f2b0ac68b8479ade25bab50f3a73c27b > Reviewed-on: https://pdfium-review.googlesource.com/9770 > Reviewed-by: Tom Sepez <tsepez@chromium.org> > Commit-Queue: Henrique Nakashima <hnakashima@chromium.org> TBR=tsepez@chromium.org,hnakashima@chromium.org,rharrison@chromium.org # Not skipping CQ checks because original CL landed > 1 day ago. Bug: pdfium:731 Change-Id: Ic66a2641c259173fb3792f7a4206e19ee4707fc9 Reviewed-on: https://pdfium-review.googlesource.com/10150 Reviewed-by: Henrique Nakashima <hnakashima@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, 23 insertions, 45 deletions
diff --git a/fpdfsdk/cpdfsdk_interform.cpp b/fpdfsdk/cpdfsdk_interform.cpp
index 27db1053c6..552bb31af2 100644
--- a/fpdfsdk/cpdfsdk_interform.cpp
+++ b/fpdfsdk/cpdfsdk_interform.cpp
@@ -8,8 +8,6 @@
#include <algorithm>
#include <memory>
-#include <sstream>
-#include <string>
#include <vector>
#include "core/fpdfapi/page/cpdf_page.h"
@@ -438,28 +436,21 @@ bool CPDFSDK_InterForm::SubmitFields(const CFX_WideString& csDestination,
const std::vector<CPDF_FormField*>& fields,
bool bIncludeOrExclude,
bool bUrlEncoded) {
- CFX_ByteString textBuf = ExportFieldsToFDFTextBuf(fields, bIncludeOrExclude);
+ CFX_ByteTextBuf textBuf;
+ ExportFieldsToFDFTextBuf(fields, bIncludeOrExclude, textBuf);
+ 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)) {
- FX_Free(pLocalBuffer);
+ if (bUrlEncoded && !FDFToURLEncodedData(pBuffer, nBufSize))
return false;
- }
m_pFormFillEnv->JS_docSubmitForm(pBuffer, nBufSize, csDestination.c_str());
+ return true;
+}
- if (pBuffer != pLocalBuffer)
- FX_Free(pBuffer);
-
- FX_Free(pLocalBuffer);
-
+bool CPDFSDK_InterForm::FDFToURLEncodedData(CFX_WideString csFDFFile,
+ CFX_WideString csTxtFile) {
return true;
}
@@ -478,7 +469,7 @@ bool CPDFSDK_InterForm::FDFToURLEncodedData(uint8_t*& pBuf,
if (!pFields)
return false;
- std::ostringstream fdfEncodedData;
+ CFX_ByteTextBuf fdfEncodedData;
for (uint32_t i = 0; i < pFields->GetCount(); i++) {
CPDF_Dictionary* pField = pFields->GetDictAt(i);
if (!pField)
@@ -499,22 +490,19 @@ bool CPDFSDK_InterForm::FDFToURLEncodedData(uint8_t*& pBuf,
fdfEncodedData << "&";
}
- nBufSize = fdfEncodedData.tellp();
- if (nBufSize == 0)
- return false;
-
+ nBufSize = fdfEncodedData.GetLength();
pBuf = FX_Alloc(uint8_t, nBufSize);
- memcpy(pBuf, fdfEncodedData.str().c_str(), nBufSize);
+ memcpy(pBuf, fdfEncodedData.GetBuffer(), nBufSize);
return true;
}
-CFX_ByteString CPDFSDK_InterForm::ExportFieldsToFDFTextBuf(
+bool CPDFSDK_InterForm::ExportFieldsToFDFTextBuf(
const std::vector<CPDF_FormField*>& fields,
- bool bIncludeOrExclude) {
+ bool bIncludeOrExclude,
+ CFX_ByteTextBuf& textBuf) {
std::unique_ptr<CFDF_Document> pFDF = m_pInterForm->ExportToFDF(
m_pFormFillEnv->JS_docGetFilePath(), fields, bIncludeOrExclude, false);
-
- return pFDF ? pFDF->WriteToString() : CFX_ByteString();
+ return pFDF ? pFDF->WriteBuf(textBuf) : false;
}
CFX_WideString CPDFSDK_InterForm::GetTemporaryFileName(
@@ -535,36 +523,26 @@ bool CPDFSDK_InterForm::SubmitForm(const CFX_WideString& sDestination,
if (!pFDFDoc)
return false;
- CFX_ByteString fdfBuffer = pFDFDoc->WriteToString();
-
- FX_STRSIZE nBufSize = fdfBuffer.GetLength();
- if (nBufSize == 0)
+ CFX_ByteTextBuf FdfBuffer;
+ if (!pFDFDoc->WriteBuf(FdfBuffer))
return false;
- 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);
+ 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 (pBuffer != pLocalBuffer)
+ if (bUrlEncoded)
FX_Free(pBuffer);
- FX_Free(pLocalBuffer);
-
return true;
}
-CFX_ByteString CPDFSDK_InterForm::ExportFormToFDFTextBuf() {
+bool CPDFSDK_InterForm::ExportFormToFDFTextBuf(CFX_ByteTextBuf& textBuf) {
std::unique_ptr<CFDF_Document> pFDF =
m_pInterForm->ExportToFDF(m_pFormFillEnv->JS_docGetFilePath(), false);
-
- return pFDF ? pFDF->WriteToString() : CFX_ByteString();
+ return pFDF && pFDF->WriteBuf(textBuf);
}
bool CPDFSDK_InterForm::DoAction_ResetForm(const CPDF_Action& action) {