summaryrefslogtreecommitdiff
path: root/xfa
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2018-08-13 19:56:29 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-08-13 19:56:29 +0000
commit30029419ad4b9e5cd382767a8645677afbeff7fd (patch)
tree1b932ad14e5acf12aefdeeebac856ca8f5d89bfa /xfa
parent1a99f200c59a89fe297ac79658d2fe11b13b1553 (diff)
downloadpdfium-30029419ad4b9e5cd382767a8645677afbeff7fd.tar.xz
Use CFX_ReadOnlyMemoryStream in more places.
More const pointers, less const_casts. BUG=pdfium:263 Change-Id: I47fc6d8f2f837390e40ad22d8b67946065294eaa Reviewed-on: https://pdfium-review.googlesource.com/39879 Reviewed-by: Tom Sepez <tsepez@chromium.org> Commit-Queue: Lei Zhang <thestig@chromium.org>
Diffstat (limited to 'xfa')
-rw-r--r--xfa/fxfa/cxfa_ffdoc.cpp7
-rw-r--r--xfa/fxfa/parser/cxfa_document_parser.cpp6
-rw-r--r--xfa/fxfa/parser/cxfa_node.cpp23
-rw-r--r--xfa/fxfa/parser/cxfa_xmllocale.cpp4
4 files changed, 18 insertions, 22 deletions
diff --git a/xfa/fxfa/cxfa_ffdoc.cpp b/xfa/fxfa/cxfa_ffdoc.cpp
index 330572ff9c..7852d30036 100644
--- a/xfa/fxfa/cxfa_ffdoc.cpp
+++ b/xfa/fxfa/cxfa_ffdoc.cpp
@@ -14,7 +14,7 @@
#include "core/fpdfapi/parser/cpdf_document.h"
#include "core/fpdfapi/parser/fpdf_parser_decode.h"
#include "core/fpdfdoc/cpdf_nametree.h"
-#include "core/fxcrt/cfx_memorystream.h"
+#include "core/fxcrt/cfx_readonlymemorystream.h"
#include "core/fxcrt/cfx_seekablemultistream.h"
#include "core/fxcrt/fx_extension.h"
#include "core/fxcrt/fx_memory.h"
@@ -215,9 +215,8 @@ RetainPtr<CFX_DIBitmap> CXFA_FFDoc::GetPDFNamedImage(
auto pAcc = pdfium::MakeRetain<CPDF_StreamAcc>(pStream);
pAcc->LoadAllDataFiltered();
- RetainPtr<IFX_SeekableStream> pImageFileRead =
- pdfium::MakeRetain<CFX_MemoryStream>(
- const_cast<uint8_t*>(pAcc->GetData()), pAcc->GetSize(), false);
+ auto pImageFileRead = pdfium::MakeRetain<CFX_ReadOnlyMemoryStream>(
+ pAcc->GetData(), pAcc->GetSize());
RetainPtr<CFX_DIBitmap> pDibSource = XFA_LoadImageFromBuffer(
pImageFileRead, FXCODEC_IMAGE_UNKNOWN, iImageXDpi, iImageYDpi);
diff --git a/xfa/fxfa/parser/cxfa_document_parser.cpp b/xfa/fxfa/parser/cxfa_document_parser.cpp
index 96c031079b..5cb08863c8 100644
--- a/xfa/fxfa/parser/cxfa_document_parser.cpp
+++ b/xfa/fxfa/parser/cxfa_document_parser.cpp
@@ -10,7 +10,7 @@
#include <vector>
#include "core/fxcrt/autorestorer.h"
-#include "core/fxcrt/cfx_memorystream.h"
+#include "core/fxcrt/cfx_readonlymemorystream.h"
#include "core/fxcrt/cfx_widetextbuf.h"
#include "core/fxcrt/fx_codepage.h"
#include "core/fxcrt/fx_extension.h"
@@ -332,8 +332,8 @@ bool CXFA_DocumentParser::Parse(
}
CFX_XMLNode* CXFA_DocumentParser::ParseXMLData(const ByteString& wsXML) {
- auto pStream = pdfium::MakeRetain<CFX_MemoryStream>(
- const_cast<uint8_t*>(wsXML.raw_str()), wsXML.GetLength(), false);
+ auto pStream = pdfium::MakeRetain<CFX_ReadOnlyMemoryStream>(
+ wsXML.raw_str(), wsXML.GetLength());
xml_doc_ = LoadXML(pStream);
if (!xml_doc_)
return nullptr;
diff --git a/xfa/fxfa/parser/cxfa_node.cpp b/xfa/fxfa/parser/cxfa_node.cpp
index 8babe45ef3..06bbb0936a 100644
--- a/xfa/fxfa/parser/cxfa_node.cpp
+++ b/xfa/fxfa/parser/cxfa_node.cpp
@@ -15,7 +15,7 @@
#include "core/fxcrt/autorestorer.h"
#include "core/fxcrt/cfx_decimal.h"
-#include "core/fxcrt/cfx_memorystream.h"
+#include "core/fxcrt/cfx_readonlymemorystream.h"
#include "core/fxcrt/fx_codepage.h"
#include "core/fxcrt/fx_extension.h"
#include "core/fxcrt/locale_iface.h"
@@ -200,24 +200,22 @@ RetainPtr<CFX_DIBitmap> XFA_LoadImageData(CXFA_FFDoc* pDoc,
FXCODEC_IMAGE_TYPE type = XFA_GetImageType(pImage->GetContentType());
ByteString bsContent;
- uint8_t* pImageBuffer = nullptr;
+ std::vector<uint8_t> buffer;
RetainPtr<IFX_SeekableReadStream> pImageFileRead;
if (wsImage.GetLength() > 0) {
XFA_AttributeEnum iEncoding = pImage->GetTransferEncoding();
if (iEncoding == XFA_AttributeEnum::Base64) {
ByteString bsData = wsImage.UTF8Encode();
- int32_t iLength = bsData.GetLength();
- pImageBuffer = FX_Alloc(uint8_t, iLength);
- int32_t iRead = XFA_Base64Decode(bsData.c_str(), pImageBuffer);
+ buffer.resize(bsData.GetLength());
+ int32_t iRead = XFA_Base64Decode(bsData.c_str(), buffer.data());
if (iRead > 0) {
pImageFileRead =
- pdfium::MakeRetain<CFX_MemoryStream>(pImageBuffer, iRead, false);
+ pdfium::MakeRetain<CFX_ReadOnlyMemoryStream>(buffer.data(), iRead);
}
} else {
bsContent = wsImage.ToDefANSI();
- pImageFileRead = pdfium::MakeRetain<CFX_MemoryStream>(
- const_cast<uint8_t*>(bsContent.raw_str()), bsContent.GetLength(),
- false);
+ pImageFileRead = pdfium::MakeRetain<CFX_ReadOnlyMemoryStream>(
+ bsContent.raw_str(), bsContent.GetLength());
}
} else {
WideString wsURL = wsHref;
@@ -231,16 +229,15 @@ RetainPtr<CFX_DIBitmap> XFA_LoadImageData(CXFA_FFDoc* pDoc,
}
pImageFileRead = pDoc->GetDocEnvironment()->OpenLinkedFile(pDoc, wsURL);
}
- if (!pImageFileRead) {
- FX_Free(pImageBuffer);
+ if (!pImageFileRead)
return nullptr;
- }
+
bNameImage = false;
RetainPtr<CFX_DIBitmap> pBitmap =
XFA_LoadImageFromBuffer(pImageFileRead, type, iImageXDpi, iImageYDpi);
- FX_Free(pImageBuffer);
return pBitmap;
}
+
bool SplitDateTime(const WideString& wsDateTime,
WideString& wsDate,
WideString& wsTime) {
diff --git a/xfa/fxfa/parser/cxfa_xmllocale.cpp b/xfa/fxfa/parser/cxfa_xmllocale.cpp
index e4858e907e..2806a084d6 100644
--- a/xfa/fxfa/parser/cxfa_xmllocale.cpp
+++ b/xfa/fxfa/parser/cxfa_xmllocale.cpp
@@ -8,7 +8,7 @@
#include <utility>
-#include "core/fxcrt/cfx_memorystream.h"
+#include "core/fxcrt/cfx_readonlymemorystream.h"
#include "core/fxcrt/fx_codepage.h"
#include "core/fxcrt/xml/cfx_xmldocument.h"
#include "core/fxcrt/xml/cfx_xmlelement.h"
@@ -32,7 +32,7 @@ constexpr wchar_t kCurrencySymbol[] = L"currencySymbol";
std::unique_ptr<CXFA_XMLLocale> CXFA_XMLLocale::Create(
pdfium::span<uint8_t> data) {
auto stream =
- pdfium::MakeRetain<CFX_MemoryStream>(data.data(), data.size(), false);
+ pdfium::MakeRetain<CFX_ReadOnlyMemoryStream>(data.data(), data.size());
CFX_XMLParser parser(stream);
auto doc = parser.Parse();
if (!doc)