summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/fpdfapi/edit/cpdf_creator.h3
-rw-r--r--core/fpdfapi/edit/fpdf_edit_create.cpp11
-rw-r--r--core/fpdfapi/page/cpdf_image.cpp3
-rw-r--r--core/fpdfapi/page/cpdf_image.h2
-rw-r--r--core/fpdfapi/parser/cfdf_document.cpp26
-rw-r--r--core/fpdfapi/parser/cfdf_document.h11
-rw-r--r--core/fpdfapi/parser/cpdf_data_avail.cpp32
-rw-r--r--core/fpdfapi/parser/cpdf_data_avail.h8
-rw-r--r--core/fpdfapi/parser/cpdf_parser.cpp47
-rw-r--r--core/fpdfapi/parser/cpdf_parser.h12
-rw-r--r--core/fpdfapi/parser/cpdf_parser_unittest.cpp20
-rw-r--r--core/fpdfapi/parser/cpdf_stream.cpp5
-rw-r--r--core/fpdfapi/parser/cpdf_stream.h4
-rw-r--r--core/fpdfapi/parser/cpdf_syntax_parser.cpp5
-rw-r--r--core/fpdfapi/parser/cpdf_syntax_parser.h6
-rw-r--r--core/fpdfapi/parser/cpdf_syntax_parser_unittest.cpp52
-rw-r--r--core/fpdfapi/parser/fpdf_parser_utility.cpp2
-rw-r--r--core/fpdfapi/parser/fpdf_parser_utility.h3
-rw-r--r--core/fxcodec/codec/ccodec_progressivedecoder.h12
-rw-r--r--core/fxcodec/codec/ccodec_tiffmodule.h4
-rw-r--r--core/fxcodec/codec/fx_codec_progress.cpp2
-rw-r--r--core/fxcodec/codec/fx_codec_tiff.cpp22
-rw-r--r--core/fxcrt/fx_basic.h7
-rw-r--r--core/fxcrt/fx_basic_buffer.cpp5
-rw-r--r--core/fxcrt/fx_ext.h6
-rw-r--r--core/fxcrt/fx_extension.cpp72
-rw-r--r--core/fxcrt/fx_stream.h39
-rw-r--r--core/fxcrt/fx_xml.h9
-rw-r--r--core/fxcrt/fx_xml_parser.cpp70
-rw-r--r--core/fxcrt/xml_int.h9
-rw-r--r--core/fxge/android/cfpf_skiafilefont.h6
-rw-r--r--core/fxge/android/cfpf_skiafontmgr.cpp20
-rw-r--r--core/fxge/android/cfpf_skiafontmgr.h2
-rw-r--r--core/fxge/fx_font.h2
-rw-r--r--core/fxge/ge/cfx_font.cpp18
35 files changed, 254 insertions, 303 deletions
diff --git a/core/fpdfapi/edit/cpdf_creator.h b/core/fpdfapi/edit/cpdf_creator.h
index c04db6eb37..aeb7d6675c 100644
--- a/core/fpdfapi/edit/cpdf_creator.h
+++ b/core/fpdfapi/edit/cpdf_creator.h
@@ -9,6 +9,7 @@
#include <memory>
+#include "core/fxcrt/cfx_retain_ptr.h"
#include "core/fxcrt/fx_basic.h"
class CPDF_Array;
@@ -32,7 +33,7 @@ class CPDF_Creator {
~CPDF_Creator();
void RemoveSecurity();
- bool Create(IFX_WriteStream* pFile, uint32_t flags = 0);
+ bool Create(const CFX_RetainPtr<IFX_WriteStream>& pFile, uint32_t flags = 0);
int32_t Continue(IFX_Pause* pPause = nullptr);
bool SetFileVersion(int32_t fileVersion = 17);
diff --git a/core/fpdfapi/edit/fpdf_edit_create.cpp b/core/fpdfapi/edit/fpdf_edit_create.cpp
index b8757ae903..62314f43f5 100644
--- a/core/fpdfapi/edit/fpdf_edit_create.cpp
+++ b/core/fpdfapi/edit/fpdf_edit_create.cpp
@@ -1479,7 +1479,8 @@ int32_t CPDF_Creator::WriteDoc_Stage1(IFX_Pause* pPause) {
InitOldObjNumOffsets();
m_iStage = 20;
} else {
- IFX_SeekableReadStream* pSrcFile = m_pParser->GetFileAccess();
+ CFX_RetainPtr<IFX_SeekableReadStream> pSrcFile =
+ m_pParser->GetFileAccess();
m_Offset = pSrcFile->GetSize();
m_Pos = (void*)(uintptr_t)m_Offset;
m_iStage = 15;
@@ -1487,8 +1488,9 @@ int32_t CPDF_Creator::WriteDoc_Stage1(IFX_Pause* pPause) {
}
if (m_iStage == 15) {
if ((m_dwFlags & FPDFCREATE_NO_ORIGINAL) == 0 && m_Pos) {
- IFX_SeekableReadStream* pSrcFile = m_pParser->GetFileAccess();
- uint8_t buffer[4096];
+ CFX_RetainPtr<IFX_SeekableReadStream> pSrcFile =
+ m_pParser->GetFileAccess();
+ uint8_t buffer[4096]; // TODO(tsepez): don't stack allocate.
uint32_t src_size = (uint32_t)(uintptr_t)m_Pos;
while (src_size) {
uint32_t block_size = src_size > 4096 ? 4096 : src_size;
@@ -1904,7 +1906,8 @@ void CPDF_Creator::Clear() {
m_pIDArray.reset();
}
-bool CPDF_Creator::Create(IFX_WriteStream* pFile, uint32_t flags) {
+bool CPDF_Creator::Create(const CFX_RetainPtr<IFX_WriteStream>& pFile,
+ uint32_t flags) {
m_File.AttachFile(pFile);
return Create(flags);
}
diff --git a/core/fpdfapi/page/cpdf_image.cpp b/core/fpdfapi/page/cpdf_image.cpp
index 5d1d51de89..a17222e343 100644
--- a/core/fpdfapi/page/cpdf_image.cpp
+++ b/core/fpdfapi/page/cpdf_image.cpp
@@ -116,7 +116,8 @@ std::unique_ptr<CPDF_Dictionary> CPDF_Image::InitJPEG(uint8_t* pData,
return pDict;
}
-void CPDF_Image::SetJpegImage(IFX_SeekableReadStream* pFile) {
+void CPDF_Image::SetJpegImage(
+ const CFX_RetainPtr<IFX_SeekableReadStream>& pFile) {
uint32_t size = pdfium::base::checked_cast<uint32_t>(pFile->GetSize());
if (!size)
return;
diff --git a/core/fpdfapi/page/cpdf_image.h b/core/fpdfapi/page/cpdf_image.h
index 38c7e3e728..1b0d74f123 100644
--- a/core/fpdfapi/page/cpdf_image.h
+++ b/core/fpdfapi/page/cpdf_image.h
@@ -51,7 +51,7 @@ class CPDF_Image {
bool bLoadMask = false) const;
void SetImage(const CFX_DIBitmap* pDIBitmap);
- void SetJpegImage(IFX_SeekableReadStream* pFile);
+ void SetJpegImage(const CFX_RetainPtr<IFX_SeekableReadStream>& pFile);
void ResetCache(CPDF_Page* pPage, const CFX_DIBitmap* pDIBitmap);
diff --git a/core/fpdfapi/parser/cfdf_document.cpp b/core/fpdfapi/parser/cfdf_document.cpp
index a6045e7795..65755520c0 100644
--- a/core/fpdfapi/parser/cfdf_document.cpp
+++ b/core/fpdfapi/parser/cfdf_document.cpp
@@ -15,15 +15,9 @@
#include "third_party/base/ptr_util.h"
CFDF_Document::CFDF_Document()
- : CPDF_IndirectObjectHolder(),
- m_pRootDict(nullptr),
- m_pFile(nullptr),
- m_bOwnFile(false) {}
-
-CFDF_Document::~CFDF_Document() {
- if (m_bOwnFile && m_pFile)
- m_pFile->Release();
-}
+ : CPDF_IndirectObjectHolder(), m_pRootDict(nullptr) {}
+
+CFDF_Document::~CFDF_Document() {}
std::unique_ptr<CFDF_Document> CFDF_Document::CreateNewDoc() {
auto pDoc = pdfium::MakeUnique<CFDF_Document>();
@@ -33,25 +27,23 @@ std::unique_ptr<CFDF_Document> CFDF_Document::CreateNewDoc() {
}
std::unique_ptr<CFDF_Document> CFDF_Document::ParseFile(
- IFX_SeekableReadStream* pFile,
- bool bOwnFile) {
+ const CFX_RetainPtr<IFX_SeekableReadStream>& pFile) {
if (!pFile)
return nullptr;
auto pDoc = pdfium::MakeUnique<CFDF_Document>();
- pDoc->ParseStream(pFile, bOwnFile);
+ pDoc->ParseStream(pFile);
return pDoc->m_pRootDict ? std::move(pDoc) : nullptr;
}
-std::unique_ptr<CFDF_Document> CFDF_Document::ParseMemory(const uint8_t* pData,
+std::unique_ptr<CFDF_Document> CFDF_Document::ParseMemory(uint8_t* pData,
uint32_t size) {
- return CFDF_Document::ParseFile(
- IFX_MemoryStream::Create((uint8_t*)pData, size), true);
+ return CFDF_Document::ParseFile(IFX_MemoryStream::Create(pData, size));
}
-void CFDF_Document::ParseStream(IFX_SeekableReadStream* pFile, bool bOwnFile) {
+void CFDF_Document::ParseStream(
+ const CFX_RetainPtr<IFX_SeekableReadStream>& pFile) {
m_pFile = pFile;
- m_bOwnFile = bOwnFile;
CPDF_SyntaxParser parser;
parser.InitParser(m_pFile, 0);
while (1) {
diff --git a/core/fpdfapi/parser/cfdf_document.h b/core/fpdfapi/parser/cfdf_document.h
index 1b47368458..f83adc1a30 100644
--- a/core/fpdfapi/parser/cfdf_document.h
+++ b/core/fpdfapi/parser/cfdf_document.h
@@ -18,9 +18,9 @@ class CPDF_Dictionary;
class CFDF_Document : public CPDF_IndirectObjectHolder {
public:
static std::unique_ptr<CFDF_Document> CreateNewDoc();
- static std::unique_ptr<CFDF_Document> ParseFile(IFX_SeekableReadStream* pFile,
- bool bOwnFile = false);
- static std::unique_ptr<CFDF_Document> ParseMemory(const uint8_t* pData,
+ static std::unique_ptr<CFDF_Document> ParseFile(
+ const CFX_RetainPtr<IFX_SeekableReadStream>& pFile);
+ static std::unique_ptr<CFDF_Document> ParseMemory(uint8_t* pData,
uint32_t size);
CFDF_Document();
@@ -30,11 +30,10 @@ class CFDF_Document : public CPDF_IndirectObjectHolder {
CPDF_Dictionary* GetRoot() const { return m_pRootDict; }
protected:
- void ParseStream(IFX_SeekableReadStream* pFile, bool bOwnFile);
+ void ParseStream(const CFX_RetainPtr<IFX_SeekableReadStream>& pFile);
CPDF_Dictionary* m_pRootDict;
- IFX_SeekableReadStream* m_pFile;
- bool m_bOwnFile;
+ CFX_RetainPtr<IFX_SeekableReadStream> m_pFile;
};
#endif // CORE_FPDFAPI_PARSER_CFDF_DOCUMENT_H_
diff --git a/core/fpdfapi/parser/cpdf_data_avail.cpp b/core/fpdfapi/parser/cpdf_data_avail.cpp
index 248748470c..76ea73d80f 100644
--- a/core/fpdfapi/parser/cpdf_data_avail.cpp
+++ b/core/fpdfapi/parser/cpdf_data_avail.cpp
@@ -33,9 +33,10 @@ CPDF_DataAvail::DownloadHints::~DownloadHints() {}
// static
int CPDF_DataAvail::s_CurrentDataAvailRecursionDepth = 0;
-CPDF_DataAvail::CPDF_DataAvail(FileAvail* pFileAvail,
- IFX_SeekableReadStream* pFileRead,
- bool bSupportHintTable)
+CPDF_DataAvail::CPDF_DataAvail(
+ FileAvail* pFileAvail,
+ const CFX_RetainPtr<IFX_SeekableReadStream>& pFileRead,
+ bool bSupportHintTable)
: m_pFileAvail(pFileAvail), m_pFileRead(pFileRead) {
m_Pos = 0;
m_dwFileLen = 0;
@@ -72,7 +73,6 @@ CPDF_DataAvail::CPDF_DataAvail(FileAvail* pFileAvail,
m_pPageDict = nullptr;
m_pPageResource = nullptr;
m_docStatus = PDF_DATAAVAIL_HEADER;
- m_parser.m_bOwnFileRead = false;
m_bTotalLoadPageTree = false;
m_bCurPageDictLoadOK = false;
m_bLinearedDataOK = false;
@@ -320,7 +320,6 @@ bool CPDF_DataAvail::LoadAllFile(DownloadHints* pHints) {
bool CPDF_DataAvail::LoadAllXref(DownloadHints* pHints) {
m_parser.m_pSyntax->InitParser(m_pFileRead, (uint32_t)m_dwHeaderOffset);
- m_parser.m_bOwnFileRead = false;
if (!m_parser.LoadAllCrossRefV4(m_dwLastXRefOffset) &&
!m_parser.LoadAllCrossRefV5(m_dwLastXRefOffset)) {
m_docStatus = PDF_DATAAVAIL_LOADALLFILE;
@@ -718,15 +717,16 @@ bool CPDF_DataAvail::IsLinearizedFile(uint8_t* pData, uint32_t dwLen) {
if (m_pLinearized)
return true;
- ScopedFileStream file(IFX_MemoryStream::Create(pData, (size_t)dwLen, false));
- int32_t offset = GetHeaderOffset(file.get());
+ CFX_RetainPtr<IFX_MemoryStream> file =
+ IFX_MemoryStream::Create(pData, (size_t)dwLen, false);
+ int32_t offset = GetHeaderOffset(file);
if (offset == -1) {
m_docStatus = PDF_DATAAVAIL_ERROR;
return false;
}
m_dwHeaderOffset = offset;
- m_syntaxParser.InitParser(file.get(), offset);
+ m_syntaxParser.InitParser(file, offset);
m_syntaxParser.RestorePos(m_syntaxParser.m_HeaderOffset + 9);
bool bNumber;
@@ -753,9 +753,9 @@ bool CPDF_DataAvail::CheckEnd(DownloadHints* pHints) {
uint8_t buffer[1024];
m_pFileRead->ReadBlock(buffer, req_pos, dwSize);
- ScopedFileStream file(
- IFX_MemoryStream::Create(buffer, (size_t)dwSize, false));
- m_syntaxParser.InitParser(file.get(), 0);
+ CFX_RetainPtr<IFX_MemoryStream> file =
+ IFX_MemoryStream::Create(buffer, (size_t)dwSize, false);
+ m_syntaxParser.InitParser(file, 0);
m_syntaxParser.RestorePos(dwSize - 1);
if (m_syntaxParser.SearchWord("startxref", true, false, dwSize)) {
@@ -801,8 +801,9 @@ int32_t CPDF_DataAvail::CheckCrossRefStream(DownloadHints* pHints,
m_pFileRead->ReadBlock(pBuf, m_dwCurrentXRefSteam, iSize);
- ScopedFileStream file(IFX_MemoryStream::Create(pBuf, (size_t)iSize, false));
- m_parser.m_pSyntax->InitParser(file.get(), 0);
+ CFX_RetainPtr<IFX_MemoryStream> file =
+ IFX_MemoryStream::Create(pBuf, (size_t)iSize, false);
+ m_parser.m_pSyntax->InitParser(file, 0);
bool bNumber;
CFX_ByteString objnum = m_parser.m_pSyntax->GetNextWord(&bNumber);
@@ -1047,8 +1048,9 @@ bool CPDF_DataAvail::CheckTrailer(DownloadHints* pHints) {
if (!m_pFileRead->ReadBlock(pBuf, m_dwTrailerOffset, iSize))
return false;
- ScopedFileStream file(IFX_MemoryStream::Create(pBuf, (size_t)iSize, false));
- m_syntaxParser.InitParser(file.get(), 0);
+ CFX_RetainPtr<IFX_MemoryStream> file =
+ IFX_MemoryStream::Create(pBuf, (size_t)iSize, false);
+ m_syntaxParser.InitParser(file, 0);
std::unique_ptr<CPDF_Object> pTrailer(
m_syntaxParser.GetObject(nullptr, 0, 0, true));
diff --git a/core/fpdfapi/parser/cpdf_data_avail.h b/core/fpdfapi/parser/cpdf_data_avail.h
index e81d705bcd..1ced2a2133 100644
--- a/core/fpdfapi/parser/cpdf_data_avail.h
+++ b/core/fpdfapi/parser/cpdf_data_avail.h
@@ -95,7 +95,7 @@ class CPDF_DataAvail final {
};
CPDF_DataAvail(FileAvail* pFileAvail,
- IFX_SeekableReadStream* pFileRead,
+ const CFX_RetainPtr<IFX_SeekableReadStream>& pFileRead,
bool bSupportHintTable);
~CPDF_DataAvail();
@@ -107,7 +107,9 @@ class CPDF_DataAvail final {
DocLinearizationStatus IsLinearizedPDF();
bool IsLinearized();
void GetLinearizedMainXRefInfo(FX_FILESIZE* pPos, uint32_t* pSize);
- IFX_SeekableReadStream* GetFileRead() const { return m_pFileRead; }
+ CFX_RetainPtr<IFX_SeekableReadStream> GetFileRead() const {
+ return m_pFileRead;
+ }
int GetPageCount() const;
CPDF_Dictionary* GetPage(int index);
@@ -195,7 +197,7 @@ class CPDF_DataAvail final {
bool ValidateForm();
FileAvail* const m_pFileAvail;
- IFX_SeekableReadStream* const m_pFileRead;
+ CFX_RetainPtr<IFX_SeekableReadStream> m_pFileRead;
CPDF_Parser m_parser;
CPDF_SyntaxParser m_syntaxParser;
std::unique_ptr<CPDF_Object> m_pRoot;
diff --git a/core/fpdfapi/parser/cpdf_parser.cpp b/core/fpdfapi/parser/cpdf_parser.cpp
index 1fae0d641c..47c5c4eab4 100644
--- a/core/fpdfapi/parser/cpdf_parser.cpp
+++ b/core/fpdfapi/parser/cpdf_parser.cpp
@@ -52,7 +52,6 @@ int32_t GetStreamFirst(CPDF_StreamAcc* pObjStream) {
CPDF_Parser::CPDF_Parser()
: m_pDocument(nullptr),
m_bHasParsed(false),
- m_bOwnFileRead(true),
m_bXRefStream(false),
m_bVersionUpdated(false),
m_FileVersion(0),
@@ -64,11 +63,6 @@ CPDF_Parser::CPDF_Parser()
CPDF_Parser::~CPDF_Parser() {
ReleaseEncryptHandler();
SetEncryptDictionary(nullptr);
-
- if (m_bOwnFileRead && m_pSyntax->m_pFileAccess) {
- m_pSyntax->m_pFileAccess->Release();
- m_pSyntax->m_pFileAccess = nullptr;
- }
}
uint32_t CPDF_Parser::GetLastObjNum() const {
@@ -109,7 +103,7 @@ CPDF_CryptoHandler* CPDF_Parser::GetCryptoHandler() {
return m_pSyntax->m_pCryptoHandler.get();
}
-IFX_SeekableReadStream* CPDF_Parser::GetFileAccess() const {
+CFX_RetainPtr<IFX_SeekableReadStream> CPDF_Parser::GetFileAccess() const {
return m_pSyntax->m_pFileAccess;
}
@@ -129,31 +123,30 @@ void CPDF_Parser::ShrinkObjectMap(uint32_t objnum) {
m_ObjectInfo[objnum - 1].pos = 0;
}
-CPDF_Parser::Error CPDF_Parser::StartParse(IFX_SeekableReadStream* pFileAccess,
- CPDF_Document* pDocument) {
+CPDF_Parser::Error CPDF_Parser::StartParse(
+ const CFX_RetainPtr<IFX_SeekableReadStream>& pFileAccess,
+ CPDF_Document* pDocument) {
ASSERT(!m_bHasParsed);
m_bHasParsed = true;
-
m_bXRefStream = false;
m_LastXRefOffset = 0;
- m_bOwnFileRead = true;
int32_t offset = GetHeaderOffset(pFileAccess);
- if (offset == -1) {
- if (pFileAccess)
- pFileAccess->Release();
+ if (offset == -1)
return FORMAT_ERROR;
- }
+
m_pSyntax->InitParser(pFileAccess, offset);
uint8_t ch;
if (!m_pSyntax->GetCharAt(5, ch))
return FORMAT_ERROR;
+
if (std::isdigit(ch))
m_FileVersion = FXSYS_toDecimalDigit(static_cast<FX_WCHAR>(ch)) * 10;
if (!m_pSyntax->GetCharAt(7, ch))
return FORMAT_ERROR;
+
if (std::isdigit(ch))
m_FileVersion += FXSYS_toDecimalDigit(static_cast<FX_WCHAR>(ch));
@@ -1124,10 +1117,10 @@ std::unique_ptr<CPDF_Object> CPDF_Parser::ParseIndirectObject(
if (!pObjStream)
return nullptr;
- ScopedFileStream file(IFX_MemoryStream::Create(
- (uint8_t*)pObjStream->GetData(), (size_t)pObjStream->GetSize(), false));
+ CFX_RetainPtr<IFX_MemoryStream> file = IFX_MemoryStream::Create(
+ (uint8_t*)pObjStream->GetData(), (size_t)pObjStream->GetSize(), false);
CPDF_SyntaxParser syntax;
- syntax.InitParser(file.get(), 0);
+ syntax.InitParser(file, 0);
const int32_t offset = GetStreamFirst(pObjStream);
// Read object numbers from |pObjStream| into a cache.
@@ -1203,11 +1196,11 @@ void CPDF_Parser::GetIndirectBinary(uint32_t objnum,
int32_t offset = GetStreamFirst(pObjStream);
const uint8_t* pData = pObjStream->GetData();
uint32_t totalsize = pObjStream->GetSize();
- ScopedFileStream file(
- IFX_MemoryStream::Create((uint8_t*)pData, (size_t)totalsize, false));
-
+ CFX_RetainPtr<IFX_MemoryStream> file =
+ IFX_MemoryStream::Create((uint8_t*)pData, (size_t)totalsize, false);
CPDF_SyntaxParser syntax;
- syntax.InitParser(file.get(), 0);
+ syntax.InitParser(file, 0);
+
for (int i = GetStreamNCount(pObjStream); i > 0; --i) {
uint32_t thisnum = syntax.GetDirectNum();
uint32_t thisoff = syntax.GetDirectNum();
@@ -1420,8 +1413,9 @@ uint32_t CPDF_Parser::GetPermissions() const {
return dwPermission;
}
-bool CPDF_Parser::IsLinearizedFile(IFX_SeekableReadStream* pFileAccess,
- uint32_t offset) {
+bool CPDF_Parser::IsLinearizedFile(
+ const CFX_RetainPtr<IFX_SeekableReadStream>& pFileAccess,
+ uint32_t offset) {
m_pSyntax->InitParser(pFileAccess, offset);
m_pSyntax->RestorePos(m_pSyntax->m_HeaderOffset + 9);
@@ -1454,13 +1448,11 @@ bool CPDF_Parser::IsLinearizedFile(IFX_SeekableReadStream* pFileAccess,
}
CPDF_Parser::Error CPDF_Parser::StartLinearizedParse(
- IFX_SeekableReadStream* pFileAccess,
+ const CFX_RetainPtr<IFX_SeekableReadStream>& pFileAccess,
CPDF_Document* pDocument) {
ASSERT(!m_bHasParsed);
-
m_bXRefStream = false;
m_LastXRefOffset = 0;
- m_bOwnFileRead = true;
int32_t offset = GetHeaderOffset(pFileAccess);
if (offset == -1)
@@ -1474,7 +1466,6 @@ CPDF_Parser::Error CPDF_Parser::StartLinearizedParse(
m_pDocument = pDocument;
FX_FILESIZE dwFirstXRefOffset = m_pSyntax->SavePos();
-
bool bXRefRebuilt = false;
bool bLoadV4 = LoadCrossRefV4(dwFirstXRefOffset, 0, false);
if (!bLoadV4 && !LoadCrossRefV5(&dwFirstXRefOffset, true)) {
diff --git a/core/fpdfapi/parser/cpdf_parser.h b/core/fpdfapi/parser/cpdf_parser.h
index 5e2cdea08d..f8ff7a17ec 100644
--- a/core/fpdfapi/parser/cpdf_parser.h
+++ b/core/fpdfapi/parser/cpdf_parser.h
@@ -43,8 +43,9 @@ class CPDF_Parser {
CPDF_Parser();
~CPDF_Parser();
- Error StartParse(IFX_SeekableReadStream* pFile, CPDF_Document* pDocument);
- Error StartLinearizedParse(IFX_SeekableReadStream* pFile,
+ Error StartParse(const CFX_RetainPtr<IFX_SeekableReadStream>& pFile,
+ CPDF_Document* pDocument);
+ Error StartLinearizedParse(const CFX_RetainPtr<IFX_SeekableReadStream>& pFile,
CPDF_Document* pDocument);
void SetPassword(const FX_CHAR* password) { m_Password = password; }
@@ -71,7 +72,7 @@ class CPDF_Parser {
bool IsVersionUpdated() const { return m_bVersionUpdated; }
bool IsObjectFreeOrNull(uint32_t objnum) const;
CPDF_CryptoHandler* GetCryptoHandler();
- IFX_SeekableReadStream* GetFileAccess() const;
+ CFX_RetainPtr<IFX_SeekableReadStream> GetFileAccess() const;
FX_FILESIZE GetObjectOffset(uint32_t objnum) const;
FX_FILESIZE GetObjectSize(uint32_t objnum) const;
@@ -140,7 +141,9 @@ class CPDF_Parser {
bool LoadLinearizedAllCrossRefV5(FX_FILESIZE pos);
Error LoadLinearizedMainXRefTable();
CPDF_StreamAcc* GetObjectStream(uint32_t number);
- bool IsLinearizedFile(IFX_SeekableReadStream* pFileAccess, uint32_t offset);
+ bool IsLinearizedFile(
+ const CFX_RetainPtr<IFX_SeekableReadStream>& pFileAccess,
+ uint32_t offset);
void SetEncryptDictionary(CPDF_Dictionary* pDict);
void ShrinkObjectMap(uint32_t size);
// A simple check whether the cross reference table matches with
@@ -149,7 +152,6 @@ class CPDF_Parser {
CPDF_Document* m_pDocument; // not owned
bool m_bHasParsed;
- bool m_bOwnFileRead;
bool m_bXRefStream;
bool m_bVersionUpdated;
int m_FileVersion;
diff --git a/core/fpdfapi/parser/cpdf_parser_unittest.cpp b/core/fpdfapi/parser/cpdf_parser_unittest.cpp
index 61496a1562..3518f7d16b 100644
--- a/core/fpdfapi/parser/cpdf_parser_unittest.cpp
+++ b/core/fpdfapi/parser/cpdf_parser_unittest.cpp
@@ -7,6 +7,7 @@
#include "core/fpdfapi/parser/cpdf_parser.h"
#include "core/fpdfapi/parser/cpdf_syntax_parser.h"
+#include "core/fxcrt/cfx_retain_ptr.h"
#include "core/fxcrt/fx_ext.h"
#include "core/fxcrt/fx_stream.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -15,11 +16,12 @@
// Provide a way to read test data from a buffer instead of a file.
class CFX_TestBufferRead : public IFX_SeekableReadStream {
public:
- CFX_TestBufferRead(const unsigned char* buffer_in, size_t buf_size)
- : buffer_(buffer_in), total_size_(buf_size) {}
-
- // IFX_ReadStream:
- void Release() override { delete this; }
+ static CFX_RetainPtr<CFX_TestBufferRead> Create(
+ const unsigned char* buffer_in,
+ size_t buf_size) {
+ return CFX_RetainPtr<CFX_TestBufferRead>(
+ new CFX_TestBufferRead(buffer_in, buf_size));
+ }
// IFX_SeekableReadStream:
bool ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) override {
@@ -33,6 +35,9 @@ class CFX_TestBufferRead : public IFX_SeekableReadStream {
FX_FILESIZE GetSize() override { return (FX_FILESIZE)total_size_; };
protected:
+ CFX_TestBufferRead(const unsigned char* buffer_in, size_t buf_size)
+ : buffer_(buffer_in), total_size_(buf_size) {}
+
const unsigned char* buffer_;
size_t total_size_;
};
@@ -45,7 +50,7 @@ class CPDF_TestParser : public CPDF_Parser {
// Setup reading from a file and initial states.
bool InitTestFromFile(const FX_CHAR* path) {
- IFX_SeekableReadStream* pFileAccess =
+ CFX_RetainPtr<IFX_SeekableReadStream> pFileAccess =
IFX_SeekableReadStream::CreateFromFilename(path);
if (!pFileAccess)
return false;
@@ -57,7 +62,8 @@ class CPDF_TestParser : public CPDF_Parser {
// Setup reading from a buffer and initial states.
bool InitTestFromBuffer(const unsigned char* buffer, size_t len) {
- CFX_TestBufferRead* buffer_reader = new CFX_TestBufferRead(buffer, len);
+ CFX_RetainPtr<CFX_TestBufferRead> buffer_reader =
+ CFX_TestBufferRead::Create(buffer, len);
// For the test file, the header is set at the beginning.
m_pSyntax->InitParser(buffer_reader, 0);
diff --git a/core/fpdfapi/parser/cpdf_stream.cpp b/core/fpdfapi/parser/cpdf_stream.cpp
index de69bfae7b..4f76ec1c63 100644
--- a/core/fpdfapi/parser/cpdf_stream.cpp
+++ b/core/fpdfapi/parser/cpdf_stream.cpp
@@ -62,8 +62,9 @@ void CPDF_Stream::InitStream(const uint8_t* pData,
m_pDict->SetNewFor<CPDF_Number>("Length", static_cast<int>(m_dwSize));
}
-void CPDF_Stream::InitStreamFromFile(IFX_SeekableReadStream* pFile,
- std::unique_ptr<CPDF_Dictionary> pDict) {
+void CPDF_Stream::InitStreamFromFile(
+ const CFX_RetainPtr<IFX_SeekableReadStream>& pFile,
+ std::unique_ptr<CPDF_Dictionary> pDict) {
m_pDict = std::move(pDict);
m_bMemoryBased = false;
m_pDataBuf.reset();
diff --git a/core/fpdfapi/parser/cpdf_stream.h b/core/fpdfapi/parser/cpdf_stream.h
index fb2b67cd82..cd4113b22b 100644
--- a/core/fpdfapi/parser/cpdf_stream.h
+++ b/core/fpdfapi/parser/cpdf_stream.h
@@ -43,7 +43,7 @@ class CPDF_Stream : public CPDF_Object {
void InitStream(const uint8_t* pData,
uint32_t size,
std::unique_ptr<CPDF_Dictionary> pDict);
- void InitStreamFromFile(IFX_SeekableReadStream* pFile,
+ void InitStreamFromFile(const CFX_RetainPtr<IFX_SeekableReadStream>& pFile,
std::unique_ptr<CPDF_Dictionary> pDict);
bool ReadRawData(FX_FILESIZE start_pos,
@@ -62,7 +62,7 @@ class CPDF_Stream : public CPDF_Object {
uint32_t m_dwSize = 0;
std::unique_ptr<CPDF_Dictionary> m_pDict;
std::unique_ptr<uint8_t, FxFreeDeleter> m_pDataBuf;
- IFX_SeekableReadStream* m_pFile = nullptr;
+ CFX_RetainPtr<IFX_SeekableReadStream> m_pFile;
};
inline CPDF_Stream* ToStream(CPDF_Object* obj) {
diff --git a/core/fpdfapi/parser/cpdf_syntax_parser.cpp b/core/fpdfapi/parser/cpdf_syntax_parser.cpp
index 9beae0b7f7..2a20e43591 100644
--- a/core/fpdfapi/parser/cpdf_syntax_parser.cpp
+++ b/core/fpdfapi/parser/cpdf_syntax_parser.cpp
@@ -756,8 +756,9 @@ std::unique_ptr<CPDF_Stream> CPDF_SyntaxParser::ReadStream(
return pStream;
}
-void CPDF_SyntaxParser::InitParser(IFX_SeekableReadStream* pFileAccess,
- uint32_t HeaderOffset) {
+void CPDF_SyntaxParser::InitParser(
+ const CFX_RetainPtr<IFX_SeekableReadStream>& pFileAccess,
+ uint32_t HeaderOffset) {
FX_Free(m_pFileBuf);
m_pFileBuf = FX_Alloc(uint8_t, m_BufSize);
diff --git a/core/fpdfapi/parser/cpdf_syntax_parser.h b/core/fpdfapi/parser/cpdf_syntax_parser.h
index 1e8f736c17..8dd9103f1b 100644
--- a/core/fpdfapi/parser/cpdf_syntax_parser.h
+++ b/core/fpdfapi/parser/cpdf_syntax_parser.h
@@ -26,7 +26,9 @@ class CPDF_SyntaxParser {
explicit CPDF_SyntaxParser(const CFX_WeakPtr<CFX_ByteStringPool>& pPool);
~CPDF_SyntaxParser();
- void InitParser(IFX_SeekableReadStream* pFileAccess, uint32_t HeaderOffset);
+ void InitParser(const CFX_RetainPtr<IFX_SeekableReadStream>& pFileAccess,
+ uint32_t HeaderOffset);
+
FX_FILESIZE SavePos() const { return m_Pos; }
void RestorePos(FX_FILESIZE pos) { m_Pos = pos; }
@@ -87,7 +89,7 @@ class CPDF_SyntaxParser {
FX_FILESIZE m_Pos;
uint32_t m_MetadataObjnum;
- IFX_SeekableReadStream* m_pFileAccess;
+ CFX_RetainPtr<IFX_SeekableReadStream> m_pFileAccess;
FX_FILESIZE m_HeaderOffset;
FX_FILESIZE m_FileLen;
uint8_t* m_pFileBuf;
diff --git a/core/fpdfapi/parser/cpdf_syntax_parser_unittest.cpp b/core/fpdfapi/parser/cpdf_syntax_parser_unittest.cpp
index f94b431c82..faaa83dd19 100644
--- a/core/fpdfapi/parser/cpdf_syntax_parser_unittest.cpp
+++ b/core/fpdfapi/parser/cpdf_syntax_parser_unittest.cpp
@@ -16,10 +16,8 @@ TEST(cpdf_syntax_parser, ReadHexString) {
{
// Empty string.
uint8_t data[] = "";
- ScopedFileStream stream(IFX_MemoryStream::Create(data, 0, false));
-
CPDF_SyntaxParser parser;
- parser.InitParser(stream.get(), 0);
+ parser.InitParser(IFX_MemoryStream::Create(data, 0, false), 0);
EXPECT_EQ("", parser.ReadHexString());
EXPECT_EQ(0, parser.SavePos());
}
@@ -27,10 +25,8 @@ TEST(cpdf_syntax_parser, ReadHexString) {
{
// Blank string.
uint8_t data[] = " ";
- ScopedFileStream stream(IFX_MemoryStream::Create(data, 2, false));
-
CPDF_SyntaxParser parser;
- parser.InitParser(stream.get(), 0);
+ parser.InitParser(IFX_MemoryStream::Create(data, 2, false), 0);
EXPECT_EQ("", parser.ReadHexString());
EXPECT_EQ(2, parser.SavePos());
}
@@ -38,10 +34,8 @@ TEST(cpdf_syntax_parser, ReadHexString) {
{
// Skips unknown characters.
uint8_t data[] = "z12b";
- ScopedFileStream stream(IFX_MemoryStream::Create(data, 4, false));
-
CPDF_SyntaxParser parser;
- parser.InitParser(stream.get(), 0);
+ parser.InitParser(IFX_MemoryStream::Create(data, 4, false), 0);
EXPECT_EQ("\x12\xb0", parser.ReadHexString());
EXPECT_EQ(4, parser.SavePos());
}
@@ -49,10 +43,8 @@ TEST(cpdf_syntax_parser, ReadHexString) {
{
// Skips unknown characters.
uint8_t data[] = "*<&*#$^&@1";
- ScopedFileStream stream(IFX_MemoryStream::Create(data, 10, false));
-
CPDF_SyntaxParser parser;
- parser.InitParser(stream.get(), 0);
+ parser.InitParser(IFX_MemoryStream::Create(data, 10, false), 0);
EXPECT_EQ("\x10", parser.ReadHexString());
EXPECT_EQ(10, parser.SavePos());
}
@@ -60,10 +52,8 @@ TEST(cpdf_syntax_parser, ReadHexString) {
{
// Skips unknown characters.
uint8_t data[] = "\x80zab";
- ScopedFileStream stream(IFX_MemoryStream::Create(data, 4, false));
-
CPDF_SyntaxParser parser;
- parser.InitParser(stream.get(), 0);
+ parser.InitParser(IFX_MemoryStream::Create(data, 4, false), 0);
EXPECT_EQ("\xab", parser.ReadHexString());
EXPECT_EQ(4, parser.SavePos());
}
@@ -71,10 +61,8 @@ TEST(cpdf_syntax_parser, ReadHexString) {
{
// Skips unknown characters.
uint8_t data[] = "\xffzab";
- ScopedFileStream stream(IFX_MemoryStream::Create(data, 4, false));
-
CPDF_SyntaxParser parser;
- parser.InitParser(stream.get(), 0);
+ parser.InitParser(IFX_MemoryStream::Create(data, 4, false), 0);
EXPECT_EQ("\xab", parser.ReadHexString());
EXPECT_EQ(4, parser.SavePos());
}
@@ -82,10 +70,8 @@ TEST(cpdf_syntax_parser, ReadHexString) {
{
// Regular conversion.
uint8_t data[] = "1A2b>abcd";
- ScopedFileStream stream(IFX_MemoryStream::Create(data, 9, false));
-
CPDF_SyntaxParser parser;
- parser.InitParser(stream.get(), 0);
+ parser.InitParser(IFX_MemoryStream::Create(data, 9, false), 0);
EXPECT_EQ("\x1a\x2b", parser.ReadHexString());
EXPECT_EQ(5, parser.SavePos());
}
@@ -93,10 +79,8 @@ TEST(cpdf_syntax_parser, ReadHexString) {
{
// Position out of bounds.
uint8_t data[] = "12ab>";
- ScopedFileStream stream(IFX_MemoryStream::Create(data, 5, false));
-
CPDF_SyntaxParser parser;
- parser.InitParser(stream.get(), 0);
+ parser.InitParser(IFX_MemoryStream::Create(data, 5, false), 0);
parser.RestorePos(5);
EXPECT_EQ("", parser.ReadHexString());
@@ -117,10 +101,8 @@ TEST(cpdf_syntax_parser, ReadHexString) {
{
// Missing ending >.
uint8_t data[] = "1A2b";
- ScopedFileStream stream(IFX_MemoryStream::Create(data, 4, false));
-
CPDF_SyntaxParser parser;
- parser.InitParser(stream.get(), 0);
+ parser.InitParser(IFX_MemoryStream::Create(data, 4, false), 0);
EXPECT_EQ("\x1a\x2b", parser.ReadHexString());
EXPECT_EQ(4, parser.SavePos());
}
@@ -128,10 +110,8 @@ TEST(cpdf_syntax_parser, ReadHexString) {
{
// Missing ending >.
uint8_t data[] = "12abz";
- ScopedFileStream stream(IFX_MemoryStream::Create(data, 5, false));
-
CPDF_SyntaxParser parser;
- parser.InitParser(stream.get(), 0);
+ parser.InitParser(IFX_MemoryStream::Create(data, 5, false), 0);
EXPECT_EQ("\x12\xab", parser.ReadHexString());
EXPECT_EQ(5, parser.SavePos());
}
@@ -139,10 +119,8 @@ TEST(cpdf_syntax_parser, ReadHexString) {
{
// Uneven number of bytes.
uint8_t data[] = "1A2>asdf";
- ScopedFileStream stream(IFX_MemoryStream::Create(data, 8, false));
-
CPDF_SyntaxParser parser;
- parser.InitParser(stream.get(), 0);
+ parser.InitParser(IFX_MemoryStream::Create(data, 8, false), 0);
EXPECT_EQ("\x1a\x20", parser.ReadHexString());
EXPECT_EQ(4, parser.SavePos());
}
@@ -150,10 +128,8 @@ TEST(cpdf_syntax_parser, ReadHexString) {
{
// Uneven number of bytes.
uint8_t data[] = "1A2zasdf";
- ScopedFileStream stream(IFX_MemoryStream::Create(data, 8, false));
-
CPDF_SyntaxParser parser;
- parser.InitParser(stream.get(), 0);
+ parser.InitParser(IFX_MemoryStream::Create(data, 8, false), 0);
EXPECT_EQ("\x1a\x2a\xdf", parser.ReadHexString());
EXPECT_EQ(8, parser.SavePos());
}
@@ -161,10 +137,8 @@ TEST(cpdf_syntax_parser, ReadHexString) {
{
// Just ending character.
uint8_t data[] = ">";
- ScopedFileStream stream(IFX_MemoryStream::Create(data, 1, false));
-
CPDF_SyntaxParser parser;
- parser.InitParser(stream.get(), 0);
+ parser.InitParser(IFX_MemoryStream::Create(data, 1, false), 0);
EXPECT_EQ("", parser.ReadHexString());
EXPECT_EQ(1, parser.SavePos());
}
diff --git a/core/fpdfapi/parser/fpdf_parser_utility.cpp b/core/fpdfapi/parser/fpdf_parser_utility.cpp
index ef37d8f39e..9583ea70bc 100644
--- a/core/fpdfapi/parser/fpdf_parser_utility.cpp
+++ b/core/fpdfapi/parser/fpdf_parser_utility.cpp
@@ -69,7 +69,7 @@ const char PDF_CharType[256] = {
'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R', 'R',
'R', 'R', 'R', 'R', 'R', 'R', 'R', 'W'};
-int32_t GetHeaderOffset(IFX_SeekableReadStream* pFile) {
+int32_t GetHeaderOffset(const CFX_RetainPtr<IFX_SeekableReadStream>& pFile) {
const size_t kBufSize = 4;
uint8_t buf[kBufSize];
for (int32_t offset = 0; offset <= 1024; ++offset) {
diff --git a/core/fpdfapi/parser/fpdf_parser_utility.h b/core/fpdfapi/parser/fpdf_parser_utility.h
index 589171f1a4..29f54ee853 100644
--- a/core/fpdfapi/parser/fpdf_parser_utility.h
+++ b/core/fpdfapi/parser/fpdf_parser_utility.h
@@ -7,6 +7,7 @@
#ifndef CORE_FPDFAPI_PARSER_FPDF_PARSER_UTILITY_H_
#define CORE_FPDFAPI_PARSER_FPDF_PARSER_UTILITY_H_
+#include "core/fxcrt/cfx_retain_ptr.h"
#include "core/fxcrt/fx_string.h"
#include "core/fxcrt/fx_system.h"
@@ -33,7 +34,7 @@ inline bool PDFCharIsLineEnding(uint8_t c) {
return c == '\r' || c == '\n';
}
-int32_t GetHeaderOffset(IFX_SeekableReadStream* pFile);
+int32_t GetHeaderOffset(const CFX_RetainPtr<IFX_SeekableReadStream>& pFile);
int32_t GetDirectInteger(CPDF_Dictionary* pDict, const CFX_ByteString& key);
#endif // CORE_FPDFAPI_PARSER_FPDF_PARSER_UTILITY_H_
diff --git a/core/fxcodec/codec/ccodec_progressivedecoder.h b/core/fxcodec/codec/ccodec_progressivedecoder.h
index de7542e485..614146f79d 100644
--- a/core/fxcodec/codec/ccodec_progressivedecoder.h
+++ b/core/fxcodec/codec/ccodec_progressivedecoder.h
@@ -10,6 +10,7 @@
#include <vector>
#include "core/fxcodec/fx_codec_def.h"
+#include "core/fxcrt/cfx_retain_ptr.h"
#include "core/fxcrt/fx_system.h"
#include "core/fxge/fx_dib.h"
@@ -45,10 +46,11 @@ class CCodec_ProgressiveDecoder {
explicit CCodec_ProgressiveDecoder(CCodec_ModuleMgr* pCodecMgr);
~CCodec_ProgressiveDecoder();
- FXCODEC_STATUS LoadImageInfo(IFX_SeekableReadStream* pFile,
- FXCODEC_IMAGE_TYPE imageType,
- CFX_DIBAttribute* pAttribute,
- bool bSkipImageTypeCheck);
+ FXCODEC_STATUS LoadImageInfo(
+ const CFX_RetainPtr<IFX_SeekableReadStream>& pFile,
+ FXCODEC_IMAGE_TYPE imageType,
+ CFX_DIBAttribute* pAttribute,
+ bool bSkipImageTypeCheck);
FXCODEC_IMAGE_TYPE GetType() const { return m_imagType; }
int32_t GetWidth() const { return m_SrcWidth; }
@@ -125,7 +127,7 @@ class CCodec_ProgressiveDecoder {
std::vector<uint8_t> m_pWeightTables;
};
- IFX_SeekableReadStream* m_pFile;
+ CFX_RetainPtr<IFX_SeekableReadStream> m_pFile;
CCodec_ModuleMgr* m_pCodecMgr;
FXJPEG_Context* m_pJpegContext;
FXPNG_Context* m_pPngContext;
diff --git a/core/fxcodec/codec/ccodec_tiffmodule.h b/core/fxcodec/codec/ccodec_tiffmodule.h
index 37d40821a6..dd2cbd768c 100644
--- a/core/fxcodec/codec/ccodec_tiffmodule.h
+++ b/core/fxcodec/codec/ccodec_tiffmodule.h
@@ -7,6 +7,7 @@
#ifndef CORE_FXCODEC_CODEC_CCODEC_TIFFMODULE_H_
#define CORE_FXCODEC_CODEC_CCODEC_TIFFMODULE_H_
+#include "core/fxcrt/cfx_retain_ptr.h"
#include "core/fxcrt/fx_system.h"
class CCodec_TiffContext;
@@ -18,7 +19,8 @@ class CCodec_TiffModule {
public:
~CCodec_TiffModule() {}
- CCodec_TiffContext* CreateDecoder(IFX_SeekableReadStream* file_ptr);
+ CCodec_TiffContext* CreateDecoder(
+ const CFX_RetainPtr<IFX_SeekableReadStream>& file_ptr);
bool LoadFrameInfo(CCodec_TiffContext* ctx,
int32_t frame,
diff --git a/core/fxcodec/codec/fx_codec_progress.cpp b/core/fxcodec/codec/fx_codec_progress.cpp
index 8d29a7b3f3..386b66a7e6 100644
--- a/core/fxcodec/codec/fx_codec_progress.cpp
+++ b/core/fxcodec/codec/fx_codec_progress.cpp
@@ -1295,7 +1295,7 @@ bool CCodec_ProgressiveDecoder::DetectImageType(FXCODEC_IMAGE_TYPE imageType,
}
FXCODEC_STATUS CCodec_ProgressiveDecoder::LoadImageInfo(
- IFX_SeekableReadStream* pFile,
+ const CFX_RetainPtr<IFX_SeekableReadStream>& pFile,
FXCODEC_IMAGE_TYPE imageType,
CFX_DIBAttribute* pAttribute,
bool bSkipImageTypeCheck) {
diff --git a/core/fxcodec/codec/fx_codec_tiff.cpp b/core/fxcodec/codec/fx_codec_tiff.cpp
index 8046f1cc39..be9c7d447f 100644
--- a/core/fxcodec/codec/fx_codec_tiff.cpp
+++ b/core/fxcodec/codec/fx_codec_tiff.cpp
@@ -8,8 +8,10 @@
#include "core/fxcodec/codec/codec_int.h"
#include "core/fxcodec/fx_codec.h"
+#include "core/fxcrt/cfx_retain_ptr.h"
#include "core/fxcrt/fx_safe_types.h"
#include "core/fxge/fx_dib.h"
+#include "third_party/base/ptr_util.h"
extern "C" {
#include "third_party/libtiff/tiffiop.h"
@@ -20,7 +22,7 @@ class CCodec_TiffContext {
CCodec_TiffContext();
~CCodec_TiffContext();
- bool InitDecoder(IFX_SeekableReadStream* file_ptr);
+ bool InitDecoder(const CFX_RetainPtr<IFX_SeekableReadStream>& file_ptr);
bool LoadFrameInfo(int32_t frame,
int32_t* width,
int32_t* height,
@@ -29,7 +31,7 @@ class CCodec_TiffContext {
CFX_DIBAttribute* pAttribute);
bool Decode(CFX_DIBitmap* pDIBitmap);
- IFX_SeekableReadStream* io_in() const { return m_io_in; }
+ CFX_RetainPtr<IFX_SeekableReadStream> io_in() const { return m_io_in; }
uint32_t offset() const { return m_offset; }
void set_offset(uint32_t offset) { m_offset = offset; }
@@ -52,7 +54,7 @@ class CCodec_TiffContext {
uint16_t bps,
uint16_t spp);
- IFX_SeekableReadStream* m_io_in;
+ CFX_RetainPtr<IFX_SeekableReadStream> m_io_in;
uint32_t m_offset;
TIFF* m_tif_ctx;
};
@@ -215,7 +217,8 @@ CCodec_TiffContext::~CCodec_TiffContext() {
TIFFClose(m_tif_ctx);
}
-bool CCodec_TiffContext::InitDecoder(IFX_SeekableReadStream* file_ptr) {
+bool CCodec_TiffContext::InitDecoder(
+ const CFX_RetainPtr<IFX_SeekableReadStream>& file_ptr) {
m_io_in = file_ptr;
m_tif_ctx = tiff_open(this, "r");
return !!m_tif_ctx;
@@ -462,13 +465,12 @@ bool CCodec_TiffContext::Decode(CFX_DIBitmap* pDIBitmap) {
}
CCodec_TiffContext* CCodec_TiffModule::CreateDecoder(
- IFX_SeekableReadStream* file_ptr) {
- CCodec_TiffContext* pDecoder = new CCodec_TiffContext;
- if (!pDecoder->InitDecoder(file_ptr)) {
- delete pDecoder;
+ const CFX_RetainPtr<IFX_SeekableReadStream>& file_ptr) {
+ auto pDecoder = pdfium::MakeUnique<CCodec_TiffContext>();
+ if (!pDecoder->InitDecoder(file_ptr))
return nullptr;
- }
- return pDecoder;
+
+ return pDecoder.release();
}
bool CCodec_TiffModule::LoadFrameInfo(CCodec_TiffContext* ctx,
diff --git a/core/fxcrt/fx_basic.h b/core/fxcrt/fx_basic.h
index 9034398983..2f581b0d5e 100644
--- a/core/fxcrt/fx_basic.h
+++ b/core/fxcrt/fx_basic.h
@@ -10,6 +10,7 @@
#include <algorithm>
#include <memory>
+#include "core/fxcrt/cfx_retain_ptr.h"
#include "core/fxcrt/fx_memory.h"
#include "core/fxcrt/fx_stream.h"
#include "core/fxcrt/fx_string.h"
@@ -119,16 +120,14 @@ class CFX_FileBufferArchive {
int32_t AppendByte(uint8_t byte);
int32_t AppendDWord(uint32_t i);
int32_t AppendString(const CFX_ByteStringC& lpsz);
-
- // |pFile| must outlive the CFX_FileBufferArchive.
- void AttachFile(IFX_WriteStream* pFile);
+ void AttachFile(const CFX_RetainPtr<IFX_WriteStream>& pFile);
private:
static const size_t kBufSize = 32768;
size_t m_Length;
std::unique_ptr<uint8_t, FxFreeDeleter> m_pBuffer;
- IFX_WriteStream* m_pFile;
+ CFX_RetainPtr<IFX_WriteStream> m_pFile;
};
class CFX_CharMap {
diff --git a/core/fxcrt/fx_basic_buffer.cpp b/core/fxcrt/fx_basic_buffer.cpp
index 8466e88c56..e6d05528ae 100644
--- a/core/fxcrt/fx_basic_buffer.cpp
+++ b/core/fxcrt/fx_basic_buffer.cpp
@@ -234,7 +234,7 @@ CFX_FileBufferArchive::~CFX_FileBufferArchive() {}
void CFX_FileBufferArchive::Clear() {
m_Length = 0;
m_pBuffer.reset();
- m_pFile = nullptr;
+ m_pFile.Reset();
}
bool CFX_FileBufferArchive::Flush() {
@@ -285,7 +285,8 @@ int32_t CFX_FileBufferArchive::AppendString(const CFX_ByteStringC& lpsz) {
return AppendBlock(lpsz.raw_str(), lpsz.GetLength());
}
-void CFX_FileBufferArchive::AttachFile(IFX_WriteStream* pFile) {
+void CFX_FileBufferArchive::AttachFile(
+ const CFX_RetainPtr<IFX_WriteStream>& pFile) {
ASSERT(pFile);
m_pFile = pFile;
}
diff --git a/core/fxcrt/fx_ext.h b/core/fxcrt/fx_ext.h
index 7d8529e333..737ea849c9 100644
--- a/core/fxcrt/fx_ext.h
+++ b/core/fxcrt/fx_ext.h
@@ -15,12 +15,6 @@
#define FX_INVALID_OFFSET static_cast<uint32_t>(-1)
-// TODO(thestig) Using unique_ptr with ReleaseDeleter is still not ideal.
-// Come up or wait for something better. This appears in this file rather
-// than fx_stream.h due to include ordering restrictions.
-using ScopedFileStream =
- std::unique_ptr<IFX_SeekableStream, ReleaseDeleter<IFX_SeekableStream>>;
-
FX_FLOAT FXSYS_tan(FX_FLOAT a);
FX_FLOAT FXSYS_logb(FX_FLOAT b, FX_FLOAT x);
FX_FLOAT FXSYS_strtof(const FX_CHAR* pcsStr,
diff --git a/core/fxcrt/fx_extension.cpp b/core/fxcrt/fx_extension.cpp
index 1bb9a3a5f6..cbbb86f26b 100644
--- a/core/fxcrt/fx_extension.cpp
+++ b/core/fxcrt/fx_extension.cpp
@@ -32,7 +32,7 @@ class CFX_CRTFileAccess : public IFX_FileAccess {
void Release() override;
IFX_FileAccess* Retain() override;
void GetPath(CFX_WideString& wsPath) override;
- IFX_SeekableStream* CreateFileStream(uint32_t dwModes) override;
+ CFX_RetainPtr<IFX_SeekableStream> CreateFileStream(uint32_t dwModes) override;
bool Init(const CFX_WideStringC& wsPath);
@@ -59,7 +59,8 @@ void CFX_CRTFileAccess::GetPath(CFX_WideString& wsPath) {
wsPath = m_path;
}
-IFX_SeekableStream* CFX_CRTFileAccess::CreateFileStream(uint32_t dwModes) {
+CFX_RetainPtr<IFX_SeekableStream> CFX_CRTFileAccess::CreateFileStream(
+ uint32_t dwModes) {
return IFX_SeekableStream::CreateFromFilename(m_path.c_str(), dwModes);
}
@@ -77,8 +78,6 @@ class CFX_CRTFileStream final : public IFX_SeekableStream {
~CFX_CRTFileStream() override;
// IFX_SeekableStream:
- IFX_SeekableStream* Retain() override;
- void Release() override;
FX_FILESIZE GetSize() override;
bool IsEOF() override;
FX_FILESIZE GetPosition() override;
@@ -89,23 +88,12 @@ class CFX_CRTFileStream final : public IFX_SeekableStream {
private:
std::unique_ptr<IFXCRT_FileAccess> m_pFile;
- uint32_t m_dwCount;
};
CFX_CRTFileStream::CFX_CRTFileStream(std::unique_ptr<IFXCRT_FileAccess> pFA)
- : m_pFile(std::move(pFA)), m_dwCount(1) {}
+ : m_pFile(std::move(pFA)) {}
CFX_CRTFileStream::~CFX_CRTFileStream() {}
-IFX_SeekableStream* CFX_CRTFileStream::Retain() {
- m_dwCount++;
- return this;
-}
-
-void CFX_CRTFileStream::Release() {
- uint32_t nCount = --m_dwCount;
- if (!nCount)
- delete this;
-}
FX_FILESIZE CFX_CRTFileStream::GetSize() {
return m_pFile->GetSize();
@@ -150,8 +138,6 @@ class CFX_MemoryStream final : public IFX_MemoryStream {
~CFX_MemoryStream() override;
// IFX_MemoryStream
- IFX_SeekableStream* Retain() override;
- void Release() override;
FX_FILESIZE GetSize() override;
bool IsEOF() override;
FX_FILESIZE GetPosition() override;
@@ -168,19 +154,18 @@ class CFX_MemoryStream final : public IFX_MemoryStream {
void DetachBuffer() override;
private:
+ bool ExpandBlocks(size_t size);
+
CFX_ArrayTemplate<uint8_t*> m_Blocks;
- uint32_t m_dwCount;
size_t m_nTotalSize;
size_t m_nCurSize;
size_t m_nCurPos;
size_t m_nGrowSize;
uint32_t m_dwFlags;
- bool ExpandBlocks(size_t size);
};
CFX_MemoryStream::CFX_MemoryStream(bool bConsecutive)
- : m_dwCount(1),
- m_nTotalSize(0),
+ : m_nTotalSize(0),
m_nCurSize(0),
m_nCurPos(0),
m_nGrowSize(FX_MEMSTREAM_BlockSize) {
@@ -191,8 +176,7 @@ CFX_MemoryStream::CFX_MemoryStream(bool bConsecutive)
CFX_MemoryStream::CFX_MemoryStream(uint8_t* pBuffer,
size_t nSize,
bool bTakeOver)
- : m_dwCount(1),
- m_nTotalSize(nSize),
+ : m_nTotalSize(nSize),
m_nCurSize(nSize),
m_nCurPos(0),
m_nGrowSize(FX_MEMSTREAM_BlockSize) {
@@ -210,19 +194,6 @@ CFX_MemoryStream::~CFX_MemoryStream() {
m_Blocks.RemoveAll();
}
-IFX_SeekableStream* CFX_MemoryStream::Retain() {
- m_dwCount++;
- return this;
-}
-
-void CFX_MemoryStream::Release() {
- uint32_t nCount = --m_dwCount;
- if (nCount) {
- return;
- }
- delete this;
-}
-
FX_FILESIZE CFX_MemoryStream::GetSize() {
return (FX_FILESIZE)m_nCurSize;
}
@@ -419,41 +390,44 @@ IFX_FileAccess* IFX_FileAccess::CreateDefault(const CFX_WideStringC& wsPath) {
#endif // PDF_ENABLE_XFA
// static
-IFX_SeekableStream* IFX_SeekableStream::CreateFromFilename(
+CFX_RetainPtr<IFX_SeekableStream> IFX_SeekableStream::CreateFromFilename(
const FX_CHAR* filename,
uint32_t dwModes) {
std::unique_ptr<IFXCRT_FileAccess> pFA(IFXCRT_FileAccess::Create());
if (!pFA->Open(filename, dwModes))
return nullptr;
- return new CFX_CRTFileStream(std::move(pFA));
+ return CFX_RetainPtr<IFX_SeekableStream>(
+ new CFX_CRTFileStream(std::move(pFA)));
}
// static
-IFX_SeekableStream* IFX_SeekableStream::CreateFromFilename(
+CFX_RetainPtr<IFX_SeekableStream> IFX_SeekableStream::CreateFromFilename(
const FX_WCHAR* filename,
uint32_t dwModes) {
std::unique_ptr<IFXCRT_FileAccess> pFA(IFXCRT_FileAccess::Create());
if (!pFA->Open(filename, dwModes))
return nullptr;
- return new CFX_CRTFileStream(std::move(pFA));
+ return CFX_RetainPtr<IFX_SeekableStream>(
+ new CFX_CRTFileStream(std::move(pFA)));
}
// static
-IFX_SeekableReadStream* IFX_SeekableReadStream::CreateFromFilename(
- const FX_CHAR* filename) {
+CFX_RetainPtr<IFX_SeekableReadStream>
+IFX_SeekableReadStream::CreateFromFilename(const FX_CHAR* filename) {
return IFX_SeekableStream::CreateFromFilename(filename, FX_FILEMODE_ReadOnly);
}
// static
-IFX_MemoryStream* IFX_MemoryStream::Create(uint8_t* pBuffer,
- size_t dwSize,
- bool bTakeOver) {
- return new CFX_MemoryStream(pBuffer, dwSize, bTakeOver);
+CFX_RetainPtr<IFX_MemoryStream> IFX_MemoryStream::Create(uint8_t* pBuffer,
+ size_t dwSize,
+ bool bTakeOver) {
+ return CFX_RetainPtr<IFX_MemoryStream>(
+ new CFX_MemoryStream(pBuffer, dwSize, bTakeOver));
}
// static
-IFX_MemoryStream* IFX_MemoryStream::Create(bool bConsecutive) {
- return new CFX_MemoryStream(bConsecutive);
+CFX_RetainPtr<IFX_MemoryStream> IFX_MemoryStream::Create(bool bConsecutive) {
+ return CFX_RetainPtr<IFX_MemoryStream>(new CFX_MemoryStream(bConsecutive));
}
FX_FLOAT FXSYS_tan(FX_FLOAT a) {
diff --git a/core/fxcrt/fx_stream.h b/core/fxcrt/fx_stream.h
index 711b66472b..b998761742 100644
--- a/core/fxcrt/fx_stream.h
+++ b/core/fxcrt/fx_stream.h
@@ -7,6 +7,7 @@
#ifndef CORE_FXCRT_FX_STREAM_H_
#define CORE_FXCRT_FX_STREAM_H_
+#include "core/fxcrt/cfx_retain_ptr.h"
#include "core/fxcrt/fx_string.h"
#include "core/fxcrt/fx_system.h"
@@ -48,18 +49,13 @@ FX_WCHAR FX_GetFolderSeparator();
#define FX_FILEMODE_ReadOnly 1
#define FX_FILEMODE_Truncate 2
-class IFX_WriteStream {
+class IFX_WriteStream : virtual public CFX_Retainable {
public:
- virtual ~IFX_WriteStream() {}
- virtual void Release() = 0;
virtual bool WriteBlock(const void* pData, size_t size) = 0;
};
-class IFX_ReadStream {
+class IFX_ReadStream : virtual public CFX_Retainable {
public:
- virtual ~IFX_ReadStream() {}
-
- virtual void Release() = 0;
virtual bool IsEOF() = 0;
virtual FX_FILESIZE GetPosition() = 0;
virtual size_t ReadBlock(void* buffer, size_t size) = 0;
@@ -69,6 +65,7 @@ class IFX_SeekableWriteStream : public IFX_WriteStream {
public:
// IFX_WriteStream:
bool WriteBlock(const void* pData, size_t size) override;
+
virtual FX_FILESIZE GetSize() = 0;
virtual bool Flush() = 0;
virtual bool WriteBlock(const void* pData,
@@ -78,10 +75,10 @@ class IFX_SeekableWriteStream : public IFX_WriteStream {
class IFX_SeekableReadStream : public IFX_ReadStream {
public:
- static IFX_SeekableReadStream* CreateFromFilename(const FX_CHAR* filename);
+ static CFX_RetainPtr<IFX_SeekableReadStream> CreateFromFilename(
+ const FX_CHAR* filename);
// IFX_ReadStream:
- void Release() override = 0;
bool IsEOF() override;
FX_FILESIZE GetPosition() override;
size_t ReadBlock(void* buffer, size_t size) override;
@@ -93,15 +90,15 @@ class IFX_SeekableReadStream : public IFX_ReadStream {
class IFX_SeekableStream : public IFX_SeekableReadStream,
public IFX_SeekableWriteStream {
public:
- static IFX_SeekableStream* CreateFromFilename(const FX_CHAR* filename,
- uint32_t dwModes);
- static IFX_SeekableStream* CreateFromFilename(const FX_WCHAR* filename,
- uint32_t dwModes);
+ static CFX_RetainPtr<IFX_SeekableStream> CreateFromFilename(
+ const FX_CHAR* filename,
+ uint32_t dwModes);
- virtual IFX_SeekableStream* Retain() = 0;
+ static CFX_RetainPtr<IFX_SeekableStream> CreateFromFilename(
+ const FX_WCHAR* filename,
+ uint32_t dwModes);
// IFX_SeekableReadStream:
- void Release() override = 0;
bool IsEOF() override = 0;
FX_FILESIZE GetPosition() override = 0;
size_t ReadBlock(void* buffer, size_t size) override = 0;
@@ -118,10 +115,10 @@ class IFX_SeekableStream : public IFX_SeekableReadStream,
class IFX_MemoryStream : public IFX_SeekableStream {
public:
- static IFX_MemoryStream* Create(uint8_t* pBuffer,
- size_t nSize,
- bool bTakeOver = false);
- static IFX_MemoryStream* Create(bool bConsecutive = false);
+ static CFX_RetainPtr<IFX_MemoryStream> Create(uint8_t* pBuffer,
+ size_t nSize,
+ bool bTakeOver = false);
+ static CFX_RetainPtr<IFX_MemoryStream> Create(bool bConsecutive = false);
virtual bool IsConsecutive() const = 0;
virtual void EstimateSize(size_t nInitSize, size_t nGrowSize) = 0;
@@ -135,7 +132,6 @@ class IFX_MemoryStream : public IFX_SeekableStream {
class IFX_BufferedReadStream : public IFX_ReadStream {
public:
// IFX_ReadStream:
- void Release() override = 0;
bool IsEOF() override = 0;
FX_FILESIZE GetPosition() override = 0;
size_t ReadBlock(void* buffer, size_t size) override = 0;
@@ -155,7 +151,8 @@ class IFX_FileAccess {
virtual void Release() = 0;
virtual IFX_FileAccess* Retain() = 0;
virtual void GetPath(CFX_WideString& wsPath) = 0;
- virtual IFX_SeekableStream* CreateFileStream(uint32_t dwModes) = 0;
+ virtual CFX_RetainPtr<IFX_SeekableStream> CreateFileStream(
+ uint32_t dwModes) = 0;
};
#endif // PDF_ENABLE_XFA
diff --git a/core/fxcrt/fx_xml.h b/core/fxcrt/fx_xml.h
index 03337d0142..7f42a7fa9b 100644
--- a/core/fxcrt/fx_xml.h
+++ b/core/fxcrt/fx_xml.h
@@ -58,12 +58,13 @@ class CXML_Element {
size_t size,
bool bSaveSpaceChars = false,
FX_FILESIZE* pParsedSize = nullptr);
- static CXML_Element* Parse(IFX_SeekableReadStream* pFile,
- bool bSaveSpaceChars = false,
- FX_FILESIZE* pParsedSize = nullptr);
- static CXML_Element* Parse(IFX_BufferedReadStream* pBuffer,
+ static CXML_Element* Parse(const CFX_RetainPtr<IFX_SeekableReadStream>& pFile,
bool bSaveSpaceChars = false,
FX_FILESIZE* pParsedSize = nullptr);
+ static CXML_Element* Parse(
+ const CFX_RetainPtr<IFX_BufferedReadStream>& pBuffer,
+ bool bSaveSpaceChars = false,
+ FX_FILESIZE* pParsedSize = nullptr);
CXML_Element(const CFX_ByteStringC& qSpace, const CFX_ByteStringC& tagName);
explicit CXML_Element(const CFX_ByteStringC& qTagName);
diff --git a/core/fxcrt/fx_xml_parser.cpp b/core/fxcrt/fx_xml_parser.cpp
index 803ba597e5..ab30926387 100644
--- a/core/fxcrt/fx_xml_parser.cpp
+++ b/core/fxcrt/fx_xml_parser.cpp
@@ -74,7 +74,6 @@ class CXML_DataBufAcc : public IFX_BufferedReadStream {
~CXML_DataBufAcc() override;
// IFX_BufferedReadStream
- void Release() override;
bool IsEOF() override;
FX_FILESIZE GetPosition() override;
size_t ReadBlock(void* buffer, size_t size) override;
@@ -94,10 +93,6 @@ CXML_DataBufAcc::CXML_DataBufAcc(const uint8_t* pBuffer, size_t size)
CXML_DataBufAcc::~CXML_DataBufAcc() {}
-void CXML_DataBufAcc::Release() {
- delete this;
-}
-
bool CXML_DataBufAcc::IsEOF() {
return m_dwCurPos >= m_dwSize;
}
@@ -135,11 +130,11 @@ FX_FILESIZE CXML_DataBufAcc::GetBlockOffset() {
class CXML_DataStmAcc : public IFX_BufferedReadStream {
public:
- explicit CXML_DataStmAcc(IFX_SeekableReadStream* pFileRead);
+ explicit CXML_DataStmAcc(
+ const CFX_RetainPtr<IFX_SeekableReadStream>& pFileRead);
~CXML_DataStmAcc() override;
// IFX_BufferedReadStream
- void Release() override;
bool IsEOF() override;
FX_FILESIZE GetPosition() override;
size_t ReadBlock(void* buffer, size_t size) override;
@@ -149,13 +144,14 @@ class CXML_DataStmAcc : public IFX_BufferedReadStream {
FX_FILESIZE GetBlockOffset() override;
private:
- IFX_SeekableReadStream* m_pFileRead;
+ CFX_RetainPtr<IFX_SeekableReadStream> m_pFileRead;
uint8_t* m_pBuffer;
FX_FILESIZE m_nStart;
size_t m_dwSize;
};
-CXML_DataStmAcc::CXML_DataStmAcc(IFX_SeekableReadStream* pFileRead)
+CXML_DataStmAcc::CXML_DataStmAcc(
+ const CFX_RetainPtr<IFX_SeekableReadStream>& pFileRead)
: m_pFileRead(pFileRead), m_pBuffer(nullptr), m_nStart(0), m_dwSize(0) {
ASSERT(m_pFileRead);
}
@@ -164,10 +160,6 @@ CXML_DataStmAcc::~CXML_DataStmAcc() {
FX_Free(m_pBuffer);
}
-void CXML_DataStmAcc::Release() {
- delete this;
-}
-
bool CXML_DataStmAcc::IsEOF() {
return m_nStart + (FX_FILESIZE)m_dwSize >= m_pFileRead->GetSize();
}
@@ -213,41 +205,34 @@ FX_FILESIZE CXML_DataStmAcc::GetBlockOffset() {
} // namespace
CXML_Parser::CXML_Parser()
- : m_pDataAcc(nullptr),
- m_bOwnedStream(false),
- m_nOffset(0),
+ : m_nOffset(0),
m_bSaveSpaceChars(false),
m_pBuffer(nullptr),
m_dwBufferSize(0),
m_nBufferOffset(0),
m_dwIndex(0) {}
-CXML_Parser::~CXML_Parser() {
- if (m_bOwnedStream) {
- m_pDataAcc->Release();
- }
-}
+CXML_Parser::~CXML_Parser() {}
bool CXML_Parser::Init(uint8_t* pBuffer, size_t size) {
- m_pDataAcc = new CXML_DataBufAcc(pBuffer, size);
- return Init(true);
+ m_pDataAcc.Reset(new CXML_DataBufAcc(pBuffer, size));
+ return Init();
}
-bool CXML_Parser::Init(IFX_SeekableReadStream* pFileRead) {
- m_pDataAcc = new CXML_DataStmAcc(pFileRead);
- return Init(true);
+bool CXML_Parser::Init(const CFX_RetainPtr<IFX_SeekableReadStream>& pFileRead) {
+ m_pDataAcc.Reset(new CXML_DataStmAcc(pFileRead));
+ return Init();
}
-bool CXML_Parser::Init(IFX_BufferedReadStream* pBuffer) {
+bool CXML_Parser::Init(const CFX_RetainPtr<IFX_BufferedReadStream>& pBuffer) {
if (!pBuffer)
return false;
m_pDataAcc = pBuffer;
- return Init(false);
+ return Init();
}
-bool CXML_Parser::Init(bool bOwndedStream) {
- m_bOwnedStream = bOwndedStream;
+bool CXML_Parser::Init() {
m_nOffset = 0;
return ReadNextBlock();
}
@@ -701,24 +686,29 @@ CXML_Element* CXML_Element::Parse(const void* pBuffer,
}
return XML_ContinueParse(parser, bSaveSpaceChars, pParsedSize);
}
-CXML_Element* CXML_Element::Parse(IFX_SeekableReadStream* pFile,
- bool bSaveSpaceChars,
- FX_FILESIZE* pParsedSize) {
+
+CXML_Element* CXML_Element::Parse(
+ const CFX_RetainPtr<IFX_SeekableReadStream>& pFile,
+ bool bSaveSpaceChars,
+ FX_FILESIZE* pParsedSize) {
CXML_Parser parser;
- if (!parser.Init(pFile)) {
+ if (!parser.Init(pFile))
return nullptr;
- }
+
return XML_ContinueParse(parser, bSaveSpaceChars, pParsedSize);
}
-CXML_Element* CXML_Element::Parse(IFX_BufferedReadStream* pBuffer,
- bool bSaveSpaceChars,
- FX_FILESIZE* pParsedSize) {
+
+CXML_Element* CXML_Element::Parse(
+ const CFX_RetainPtr<IFX_BufferedReadStream>& pBuffer,
+ bool bSaveSpaceChars,
+ FX_FILESIZE* pParsedSize) {
CXML_Parser parser;
- if (!parser.Init(pBuffer)) {
+ if (!parser.Init(pBuffer))
return nullptr;
- }
+
return XML_ContinueParse(parser, bSaveSpaceChars, pParsedSize);
}
+
CXML_Element::CXML_Element() : m_QSpaceName(), m_TagName(), m_AttrMap() {}
CXML_Element::CXML_Element(const CFX_ByteStringC& qSpace,
const CFX_ByteStringC& tagName)
diff --git a/core/fxcrt/xml_int.h b/core/fxcrt/xml_int.h
index f5beaef9ae..e617a777f3 100644
--- a/core/fxcrt/xml_int.h
+++ b/core/fxcrt/xml_int.h
@@ -20,9 +20,9 @@ class CXML_Parser {
~CXML_Parser();
bool Init(uint8_t* pBuffer, size_t size);
- bool Init(IFX_SeekableReadStream* pFileRead);
- bool Init(IFX_BufferedReadStream* pBuffer);
- bool Init(bool bOwndedStream);
+ bool Init(const CFX_RetainPtr<IFX_SeekableReadStream>& pFileRead);
+ bool Init(const CFX_RetainPtr<IFX_BufferedReadStream>& pBuffer);
+ bool Init();
bool ReadNextBlock();
bool IsEOF();
bool HaveAvailData();
@@ -41,8 +41,7 @@ class CXML_Parser {
CXML_Element* pElement);
void InsertCDATASegment(CFX_UTF8Decoder& decoder, CXML_Element* pElement);
- IFX_BufferedReadStream* m_pDataAcc;
- bool m_bOwnedStream;
+ CFX_RetainPtr<IFX_BufferedReadStream> m_pDataAcc;
FX_FILESIZE m_nOffset;
bool m_bSaveSpaceChars;
const uint8_t* m_pBuffer;
diff --git a/core/fxge/android/cfpf_skiafilefont.h b/core/fxge/android/cfpf_skiafilefont.h
index b6657bf978..2c9fc90ad2 100644
--- a/core/fxge/android/cfpf_skiafilefont.h
+++ b/core/fxge/android/cfpf_skiafilefont.h
@@ -7,6 +7,7 @@
#ifndef CORE_FXGE_ANDROID_CFPF_SKIAFILEFONT_H_
#define CORE_FXGE_ANDROID_CFPF_SKIAFILEFONT_H_
+#include "core/fxcrt/cfx_retain_ptr.h"
#include "core/fxge/android/cfpf_skiafontdescriptor.h"
class IFX_SeekableReadStream;
@@ -15,11 +16,12 @@ class IFX_SeekableReadStream;
class CFPF_SkiaFileFont : public CFPF_SkiaFontDescriptor {
public:
- CFPF_SkiaFileFont() : m_pFile(nullptr) {}
+ CFPF_SkiaFileFont() {}
// CFPF_SkiaFontDescriptor
int32_t GetType() const override { return FPF_SKIAFONTTYPE_File; }
- IFX_SeekableReadStream* m_pFile;
+
+ CFX_RetainPtr<IFX_SeekableReadStream> m_pFile;
};
#endif // CORE_FXGE_ANDROID_CFPF_SKIAFILEFONT_H_
diff --git a/core/fxge/android/cfpf_skiafontmgr.cpp b/core/fxge/android/cfpf_skiafontmgr.cpp
index 6463e8b531..e3511be67a 100644
--- a/core/fxge/android/cfpf_skiafontmgr.cpp
+++ b/core/fxge/android/cfpf_skiafontmgr.cpp
@@ -28,14 +28,17 @@ static unsigned long FPF_SkiaStream_Read(FXFT_Stream stream,
unsigned long offset,
unsigned char* buffer,
unsigned long count) {
+ if (count == 0)
+ return 0;
+
IFX_SeekableReadStream* pFileRead =
- (IFX_SeekableReadStream*)stream->descriptor.pointer;
+ static_cast<IFX_SeekableReadStream*>(stream->descriptor.pointer);
if (!pFileRead)
return 0;
- if (count > 0) {
- if (!pFileRead->ReadBlock(buffer, (FX_FILESIZE)offset, (size_t)count))
- return 0;
- }
+
+ if (!pFileRead->ReadBlock(buffer, (FX_FILESIZE)offset, (size_t)count))
+ return 0;
+
return count;
}
@@ -358,8 +361,9 @@ CFPF_SkiaFont* CFPF_SkiaFontMgr::CreateFont(const CFX_ByteStringC& bsFamilyname,
return nullptr;
}
-FXFT_Face CFPF_SkiaFontMgr::GetFontFace(IFX_SeekableReadStream* pFileRead,
- int32_t iFaceIndex) {
+FXFT_Face CFPF_SkiaFontMgr::GetFontFace(
+ const CFX_RetainPtr<IFX_SeekableReadStream>& pFileRead,
+ int32_t iFaceIndex) {
if (!pFileRead)
return nullptr;
if (pFileRead->GetSize() == 0)
@@ -369,7 +373,7 @@ FXFT_Face CFPF_SkiaFontMgr::GetFontFace(IFX_SeekableReadStream* pFileRead,
FXFT_StreamRec streamRec;
FXSYS_memset(&streamRec, 0, sizeof(FXFT_StreamRec));
streamRec.size = pFileRead->GetSize();
- streamRec.descriptor.pointer = pFileRead;
+ streamRec.descriptor.pointer = static_cast<void*>(pFileRead.Get());
streamRec.read = FPF_SkiaStream_Read;
streamRec.close = FPF_SkiaStream_Close;
FXFT_Open_Args args;
diff --git a/core/fxge/android/cfpf_skiafontmgr.h b/core/fxge/android/cfpf_skiafontmgr.h
index 7d89c6edb8..4d0ea0e0d2 100644
--- a/core/fxge/android/cfpf_skiafontmgr.h
+++ b/core/fxge/android/cfpf_skiafontmgr.h
@@ -31,7 +31,7 @@ class CFPF_SkiaFontMgr {
uint32_t dwMatch = 0);
bool InitFTLibrary();
- FXFT_Face GetFontFace(IFX_SeekableReadStream* pFileRead,
+ FXFT_Face GetFontFace(const CFX_RetainPtr<IFX_SeekableReadStream>& pFileRead,
int32_t iFaceIndex = 0);
FXFT_Face GetFontFace(const CFX_ByteStringC& bsFile, int32_t iFaceIndex = 0);
FXFT_Face GetFontFace(const uint8_t* pBuffer,
diff --git a/core/fxge/fx_font.h b/core/fxge/fx_font.h
index 6bb4bdea34..96396af15e 100644
--- a/core/fxge/fx_font.h
+++ b/core/fxge/fx_font.h
@@ -111,7 +111,7 @@ class CFX_Font {
CFX_SubstFont* GetSubstFont() const { return m_pSubstFont.get(); }
#ifdef PDF_ENABLE_XFA
- bool LoadFile(IFX_SeekableReadStream* pFile,
+ bool LoadFile(const CFX_RetainPtr<IFX_SeekableReadStream>& pFile,
int nFaceIndex = 0,
int* pFaceCount = nullptr);
diff --git a/core/fxge/ge/cfx_font.cpp b/core/fxge/ge/cfx_font.cpp
index b85709040b..7be300ff66 100644
--- a/core/fxge/ge/cfx_font.cpp
+++ b/core/fxge/ge/cfx_font.cpp
@@ -47,21 +47,27 @@ unsigned long FTStreamRead(FXFT_Stream stream,
IFX_SeekableReadStream* pFile =
static_cast<IFX_SeekableReadStream*>(stream->descriptor.pointer);
- return pFile->ReadBlock(buffer, offset, count) ? count : 0;
+ if (!pFile)
+ return 0;
+
+ if (!pFile->ReadBlock(buffer, offset, count))
+ return 0;
+
+ return count;
}
void FTStreamClose(FXFT_Stream stream) {}
bool LoadFileImp(FXFT_Library library,
FXFT_Face* Face,
- IFX_SeekableReadStream* pFile,
+ const CFX_RetainPtr<IFX_SeekableReadStream>& pFile,
int32_t faceIndex,
std::unique_ptr<FXFT_StreamRec>* stream) {
- std::unique_ptr<FXFT_StreamRec> stream1(new FXFT_StreamRec());
+ auto stream1 = pdfium::MakeUnique<FXFT_StreamRec>();
stream1->base = nullptr;
stream1->size = static_cast<unsigned long>(pFile->GetSize());
stream1->pos = 0;
- stream1->descriptor.pointer = pFile;
+ stream1->descriptor.pointer = static_cast<void*>(pFile.Get());
stream1->close = FTStreamClose;
stream1->read = FTStreamRead;
FXFT_Open_Args args;
@@ -338,15 +344,15 @@ void CFX_Font::LoadSubst(const CFX_ByteString& face_name,
}
#ifdef PDF_ENABLE_XFA
-bool CFX_Font::LoadFile(IFX_SeekableReadStream* pFile,
+bool CFX_Font::LoadFile(const CFX_RetainPtr<IFX_SeekableReadStream>& pFile,
int nFaceIndex,
int* pFaceCount) {
m_bEmbedded = false;
CFX_FontMgr* pFontMgr = CFX_GEModule::Get()->GetFontMgr();
pFontMgr->InitFTLibrary();
- FXFT_Library library = pFontMgr->GetFTLibrary();
+ FXFT_Library library = pFontMgr->GetFTLibrary();
std::unique_ptr<FXFT_StreamRec> stream;
if (!LoadFileImp(library, &m_Face, pFile, nFaceIndex, &stream))
return false;