summaryrefslogtreecommitdiff
path: root/fpdfsdk/fpdfxfa
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2018-04-11 21:11:28 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-04-11 21:11:28 +0000
commit1e934f6868465bca960f9f13489489ba1d649581 (patch)
tree36df9044ccd3327d3d60fb43ac523e2bc260cca6 /fpdfsdk/fpdfxfa
parent4796acb896dabefe6d9a2dbe6d8a61ff7e086dfd (diff)
downloadpdfium-1e934f6868465bca960f9f13489489ba1d649581.tar.xz
Remove use of GetBuffer()/ReleaseBuffer() when c_str() is sufficient.
Greatly simplify the code which was neither changing allocations nor doing any actual work. Eventually GetBuffer() will return a span, and this makes fewer places to change. Comment AsFPDFWideString() as a place where we may want a redundant copy, and make available outside the .cpp file. Fix one "const" along the way. Change-Id: I187758b69a0ba3501b3622f6c06280793cd5d464 Reviewed-on: https://pdfium-review.googlesource.com/30011 Reviewed-by: dsinclair <dsinclair@chromium.org> Commit-Queue: Tom Sepez <tsepez@chromium.org>
Diffstat (limited to 'fpdfsdk/fpdfxfa')
-rw-r--r--fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp54
1 files changed, 16 insertions, 38 deletions
diff --git a/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp b/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp
index c9087e8a0b..1b503b3fca 100644
--- a/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp
+++ b/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp
@@ -404,8 +404,7 @@ void CPDFXFA_DocEnvironment::GetTitle(CXFA_FFDoc* hDoc, WideString& wsTitle) {
return;
ByteString csTitle = pInfoDict->GetStringFor("Title");
- wsTitle = wsTitle.FromLocal(csTitle.GetBuffer(csTitle.GetLength()));
- csTitle.ReleaseBuffer(csTitle.GetLength());
+ wsTitle = WideString::FromLocal(csTitle.c_str());
}
void CPDFXFA_DocEnvironment::SetTitle(CXFA_FFDoc* hDoc,
@@ -442,11 +441,8 @@ void CPDFXFA_DocEnvironment::ExportData(CXFA_FFDoc* hDoc,
WideString filepath = pFormFillEnv->JS_fieldBrowse();
bs = filepath.UTF16LE_Encode();
}
- int len = bs.GetLength();
- FPDF_FILEHANDLER* pFileHandler =
- pFormFillEnv->OpenFile(bXDP ? FXFA_SAVEAS_XDP : FXFA_SAVEAS_XML,
- (FPDF_WIDESTRING)bs.GetBuffer(len), "wb");
- bs.ReleaseBuffer(len);
+ FPDF_FILEHANDLER* pFileHandler = pFormFillEnv->OpenFile(
+ bXDP ? FXFA_SAVEAS_XDP : FXFA_SAVEAS_XML, AsFPDFWideString(&bs), "wb");
if (!pFileHandler)
return;
@@ -662,16 +658,14 @@ bool CPDFXFA_DocEnvironment::OnBeforeNotifySubmit() {
WideString ws = WideString::FromLocal(IDS_XFA_Validate_Input);
ByteString bs = ws.UTF16LE_Encode();
- int len = bs.GetLength();
- pFormFillEnv->Alert((FPDF_WIDESTRING)bs.GetBuffer(len),
- (FPDF_WIDESTRING)L"", 0, 1);
- bs.ReleaseBuffer(len);
+ pFormFillEnv->Alert(AsFPDFWideString(&bs),
+ reinterpret_cast<FPDF_WIDESTRING>(L""), 0, 1);
return false;
}
pNode = it->MoveToNext();
}
- docView->UpdateDocView();
+ docView->UpdateDocView();
return true;
}
@@ -719,10 +713,8 @@ RetainPtr<IFX_SeekableReadStream> CPDFXFA_DocEnvironment::OpenLinkedFile(
return nullptr;
ByteString bs = wsLink.UTF16LE_Encode();
- int len = bs.GetLength();
FPDF_FILEHANDLER* pFileHandler =
- pFormFillEnv->OpenFile(0, (FPDF_WIDESTRING)bs.GetBuffer(len), "rb");
- bs.ReleaseBuffer(len);
+ pFormFillEnv->OpenFile(0, AsFPDFWideString(&bs), "rb");
if (!pFileHandler)
return nullptr;
@@ -919,10 +911,8 @@ bool CPDFXFA_DocEnvironment::SubmitInternal(CXFA_FFDoc* hDoc,
if (csURL.IsEmpty()) {
WideString ws = WideString::FromLocal("Submit cancelled.");
ByteString bs = ws.UTF16LE_Encode();
- int len = bs.GetLength();
- pFormFillEnv->Alert(reinterpret_cast<FPDF_WIDESTRING>(bs.GetBuffer(len)),
+ pFormFillEnv->Alert(AsFPDFWideString(&bs),
reinterpret_cast<FPDF_WIDESTRING>(L""), 0, 4);
- bs.ReleaseBuffer(len);
return false;
}
@@ -978,27 +968,15 @@ bool CPDFXFA_DocEnvironment::SubmitInternal(CXFA_FFDoc* hDoc,
ByteString bsBcc = WideString(csBCCAddress).UTF16LE_Encode();
ByteString bsSubject = WideString(csSubject).UTF16LE_Encode();
ByteString bsMsg = WideString(csMsg).UTF16LE_Encode();
- FPDF_WIDESTRING pTo = (FPDF_WIDESTRING)bsTo.GetBuffer(bsTo.GetLength());
- FPDF_WIDESTRING pCC = (FPDF_WIDESTRING)bsCC.GetBuffer(bsCC.GetLength());
- FPDF_WIDESTRING pBcc = (FPDF_WIDESTRING)bsBcc.GetBuffer(bsBcc.GetLength());
- FPDF_WIDESTRING pSubject =
- (FPDF_WIDESTRING)bsSubject.GetBuffer(bsSubject.GetLength());
- FPDF_WIDESTRING pMsg = (FPDF_WIDESTRING)bsMsg.GetBuffer(bsMsg.GetLength());
- pFormFillEnv->EmailTo(pFileHandler, pTo, pSubject, pCC, pBcc, pMsg);
- bsTo.ReleaseBuffer(bsTo.GetStringLength());
- bsCC.ReleaseBuffer(bsCC.GetStringLength());
- bsBcc.ReleaseBuffer(bsBcc.GetStringLength());
- bsSubject.ReleaseBuffer(bsSubject.GetStringLength());
- bsMsg.ReleaseBuffer(bsMsg.GetStringLength());
- } else {
- // HTTP or FTP
- WideString ws;
- ByteString bs = csURL.UTF16LE_Encode();
- int len = bs.GetLength();
- pFormFillEnv->UploadTo(pFileHandler, fileFlag,
- (FPDF_WIDESTRING)bs.GetBuffer(len));
- bs.ReleaseBuffer(len);
+ pFormFillEnv->EmailTo(pFileHandler, AsFPDFWideString(&bsTo),
+ AsFPDFWideString(&bsSubject), AsFPDFWideString(&bsCC),
+ AsFPDFWideString(&bsBcc), AsFPDFWideString(&bsMsg));
+ return true;
}
+
+ // HTTP or FTP
+ ByteString bs = csURL.UTF16LE_Encode();
+ pFormFillEnv->UploadTo(pFileHandler, fileFlag, AsFPDFWideString(&bs));
return true;
}