summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authortsepez <tsepez@chromium.org>2016-11-30 15:10:55 -0800
committerCommit bot <commit-bot@chromium.org>2016-11-30 15:10:55 -0800
commit345d489b70a8e057587512524e69bd5692e2e14b (patch)
tree01a34c53a991ef069b503bed1b8d1845510cfe04 /core
parent47718fbaf24000877aff58d9512b9b1dea0af818 (diff)
downloadpdfium-345d489b70a8e057587512524e69bd5692e2e14b.tar.xz
Convert loose FX_Create* functions into static methods
Also remove a bool that is always false. Review-Url: https://codereview.chromium.org/2539203002
Diffstat (limited to 'core')
-rw-r--r--core/fpdfapi/parser/cfdf_document.cpp4
-rw-r--r--core/fpdfapi/parser/cpdf_data_avail.cpp9
-rw-r--r--core/fpdfapi/parser/cpdf_parser.cpp4
-rw-r--r--core/fpdfapi/parser/cpdf_parser_unittest.cpp3
-rw-r--r--core/fpdfapi/parser/cpdf_syntax_parser_unittest.cpp26
-rw-r--r--core/fxcrt/fx_extension.cpp36
-rw-r--r--core/fxcrt/fx_stream.h25
7 files changed, 58 insertions, 49 deletions
diff --git a/core/fpdfapi/parser/cfdf_document.cpp b/core/fpdfapi/parser/cfdf_document.cpp
index 41e285245d..a6045e7795 100644
--- a/core/fpdfapi/parser/cfdf_document.cpp
+++ b/core/fpdfapi/parser/cfdf_document.cpp
@@ -45,8 +45,8 @@ std::unique_ptr<CFDF_Document> CFDF_Document::ParseFile(
std::unique_ptr<CFDF_Document> CFDF_Document::ParseMemory(const uint8_t* pData,
uint32_t size) {
- return CFDF_Document::ParseFile(FX_CreateMemoryStream((uint8_t*)pData, size),
- true);
+ return CFDF_Document::ParseFile(
+ IFX_MemoryStream::Create((uint8_t*)pData, size), true);
}
void CFDF_Document::ParseStream(IFX_SeekableReadStream* pFile, bool bOwnFile) {
diff --git a/core/fpdfapi/parser/cpdf_data_avail.cpp b/core/fpdfapi/parser/cpdf_data_avail.cpp
index 1ac6e06a97..248748470c 100644
--- a/core/fpdfapi/parser/cpdf_data_avail.cpp
+++ b/core/fpdfapi/parser/cpdf_data_avail.cpp
@@ -718,7 +718,7 @@ bool CPDF_DataAvail::IsLinearizedFile(uint8_t* pData, uint32_t dwLen) {
if (m_pLinearized)
return true;
- ScopedFileStream file(FX_CreateMemoryStream(pData, (size_t)dwLen, false));
+ ScopedFileStream file(IFX_MemoryStream::Create(pData, (size_t)dwLen, false));
int32_t offset = GetHeaderOffset(file.get());
if (offset == -1) {
m_docStatus = PDF_DATAAVAIL_ERROR;
@@ -753,7 +753,8 @@ bool CPDF_DataAvail::CheckEnd(DownloadHints* pHints) {
uint8_t buffer[1024];
m_pFileRead->ReadBlock(buffer, req_pos, dwSize);
- ScopedFileStream file(FX_CreateMemoryStream(buffer, (size_t)dwSize, false));
+ ScopedFileStream file(
+ IFX_MemoryStream::Create(buffer, (size_t)dwSize, false));
m_syntaxParser.InitParser(file.get(), 0);
m_syntaxParser.RestorePos(dwSize - 1);
@@ -800,7 +801,7 @@ int32_t CPDF_DataAvail::CheckCrossRefStream(DownloadHints* pHints,
m_pFileRead->ReadBlock(pBuf, m_dwCurrentXRefSteam, iSize);
- ScopedFileStream file(FX_CreateMemoryStream(pBuf, (size_t)iSize, false));
+ ScopedFileStream file(IFX_MemoryStream::Create(pBuf, (size_t)iSize, false));
m_parser.m_pSyntax->InitParser(file.get(), 0);
bool bNumber;
@@ -1046,7 +1047,7 @@ bool CPDF_DataAvail::CheckTrailer(DownloadHints* pHints) {
if (!m_pFileRead->ReadBlock(pBuf, m_dwTrailerOffset, iSize))
return false;
- ScopedFileStream file(FX_CreateMemoryStream(pBuf, (size_t)iSize, false));
+ ScopedFileStream file(IFX_MemoryStream::Create(pBuf, (size_t)iSize, false));
m_syntaxParser.InitParser(file.get(), 0);
std::unique_ptr<CPDF_Object> pTrailer(
diff --git a/core/fpdfapi/parser/cpdf_parser.cpp b/core/fpdfapi/parser/cpdf_parser.cpp
index 2f432ed9f9..1fae0d641c 100644
--- a/core/fpdfapi/parser/cpdf_parser.cpp
+++ b/core/fpdfapi/parser/cpdf_parser.cpp
@@ -1124,7 +1124,7 @@ std::unique_ptr<CPDF_Object> CPDF_Parser::ParseIndirectObject(
if (!pObjStream)
return nullptr;
- ScopedFileStream file(FX_CreateMemoryStream(
+ ScopedFileStream file(IFX_MemoryStream::Create(
(uint8_t*)pObjStream->GetData(), (size_t)pObjStream->GetSize(), false));
CPDF_SyntaxParser syntax;
syntax.InitParser(file.get(), 0);
@@ -1204,7 +1204,7 @@ void CPDF_Parser::GetIndirectBinary(uint32_t objnum,
const uint8_t* pData = pObjStream->GetData();
uint32_t totalsize = pObjStream->GetSize();
ScopedFileStream file(
- FX_CreateMemoryStream((uint8_t*)pData, (size_t)totalsize, false));
+ IFX_MemoryStream::Create((uint8_t*)pData, (size_t)totalsize, false));
CPDF_SyntaxParser syntax;
syntax.InitParser(file.get(), 0);
diff --git a/core/fpdfapi/parser/cpdf_parser_unittest.cpp b/core/fpdfapi/parser/cpdf_parser_unittest.cpp
index 7148c54f30..0a70103d3a 100644
--- a/core/fpdfapi/parser/cpdf_parser_unittest.cpp
+++ b/core/fpdfapi/parser/cpdf_parser_unittest.cpp
@@ -45,7 +45,8 @@ class CPDF_TestParser : public CPDF_Parser {
// Setup reading from a file and initial states.
bool InitTestFromFile(const FX_CHAR* path) {
- IFX_SeekableReadStream* pFileAccess = FX_CreateFileRead(path);
+ IFX_SeekableReadStream* pFileAccess =
+ IFX_SeekableReadStream::CreateFromFilename(path);
if (!pFileAccess)
return false;
diff --git a/core/fpdfapi/parser/cpdf_syntax_parser_unittest.cpp b/core/fpdfapi/parser/cpdf_syntax_parser_unittest.cpp
index a23c0ed64e..f94b431c82 100644
--- a/core/fpdfapi/parser/cpdf_syntax_parser_unittest.cpp
+++ b/core/fpdfapi/parser/cpdf_syntax_parser_unittest.cpp
@@ -16,7 +16,7 @@ TEST(cpdf_syntax_parser, ReadHexString) {
{
// Empty string.
uint8_t data[] = "";
- ScopedFileStream stream(FX_CreateMemoryStream(data, 0, false));
+ ScopedFileStream stream(IFX_MemoryStream::Create(data, 0, false));
CPDF_SyntaxParser parser;
parser.InitParser(stream.get(), 0);
@@ -27,7 +27,7 @@ TEST(cpdf_syntax_parser, ReadHexString) {
{
// Blank string.
uint8_t data[] = " ";
- ScopedFileStream stream(FX_CreateMemoryStream(data, 2, false));
+ ScopedFileStream stream(IFX_MemoryStream::Create(data, 2, false));
CPDF_SyntaxParser parser;
parser.InitParser(stream.get(), 0);
@@ -38,7 +38,7 @@ TEST(cpdf_syntax_parser, ReadHexString) {
{
// Skips unknown characters.
uint8_t data[] = "z12b";
- ScopedFileStream stream(FX_CreateMemoryStream(data, 4, false));
+ ScopedFileStream stream(IFX_MemoryStream::Create(data, 4, false));
CPDF_SyntaxParser parser;
parser.InitParser(stream.get(), 0);
@@ -49,7 +49,7 @@ TEST(cpdf_syntax_parser, ReadHexString) {
{
// Skips unknown characters.
uint8_t data[] = "*<&*#$^&@1";
- ScopedFileStream stream(FX_CreateMemoryStream(data, 10, false));
+ ScopedFileStream stream(IFX_MemoryStream::Create(data, 10, false));
CPDF_SyntaxParser parser;
parser.InitParser(stream.get(), 0);
@@ -60,7 +60,7 @@ TEST(cpdf_syntax_parser, ReadHexString) {
{
// Skips unknown characters.
uint8_t data[] = "\x80zab";
- ScopedFileStream stream(FX_CreateMemoryStream(data, 4, false));
+ ScopedFileStream stream(IFX_MemoryStream::Create(data, 4, false));
CPDF_SyntaxParser parser;
parser.InitParser(stream.get(), 0);
@@ -71,7 +71,7 @@ TEST(cpdf_syntax_parser, ReadHexString) {
{
// Skips unknown characters.
uint8_t data[] = "\xffzab";
- ScopedFileStream stream(FX_CreateMemoryStream(data, 4, false));
+ ScopedFileStream stream(IFX_MemoryStream::Create(data, 4, false));
CPDF_SyntaxParser parser;
parser.InitParser(stream.get(), 0);
@@ -82,7 +82,7 @@ TEST(cpdf_syntax_parser, ReadHexString) {
{
// Regular conversion.
uint8_t data[] = "1A2b>abcd";
- ScopedFileStream stream(FX_CreateMemoryStream(data, 9, false));
+ ScopedFileStream stream(IFX_MemoryStream::Create(data, 9, false));
CPDF_SyntaxParser parser;
parser.InitParser(stream.get(), 0);
@@ -93,7 +93,7 @@ TEST(cpdf_syntax_parser, ReadHexString) {
{
// Position out of bounds.
uint8_t data[] = "12ab>";
- ScopedFileStream stream(FX_CreateMemoryStream(data, 5, false));
+ ScopedFileStream stream(IFX_MemoryStream::Create(data, 5, false));
CPDF_SyntaxParser parser;
parser.InitParser(stream.get(), 0);
@@ -117,7 +117,7 @@ TEST(cpdf_syntax_parser, ReadHexString) {
{
// Missing ending >.
uint8_t data[] = "1A2b";
- ScopedFileStream stream(FX_CreateMemoryStream(data, 4, false));
+ ScopedFileStream stream(IFX_MemoryStream::Create(data, 4, false));
CPDF_SyntaxParser parser;
parser.InitParser(stream.get(), 0);
@@ -128,7 +128,7 @@ TEST(cpdf_syntax_parser, ReadHexString) {
{
// Missing ending >.
uint8_t data[] = "12abz";
- ScopedFileStream stream(FX_CreateMemoryStream(data, 5, false));
+ ScopedFileStream stream(IFX_MemoryStream::Create(data, 5, false));
CPDF_SyntaxParser parser;
parser.InitParser(stream.get(), 0);
@@ -139,7 +139,7 @@ TEST(cpdf_syntax_parser, ReadHexString) {
{
// Uneven number of bytes.
uint8_t data[] = "1A2>asdf";
- ScopedFileStream stream(FX_CreateMemoryStream(data, 8, false));
+ ScopedFileStream stream(IFX_MemoryStream::Create(data, 8, false));
CPDF_SyntaxParser parser;
parser.InitParser(stream.get(), 0);
@@ -150,7 +150,7 @@ TEST(cpdf_syntax_parser, ReadHexString) {
{
// Uneven number of bytes.
uint8_t data[] = "1A2zasdf";
- ScopedFileStream stream(FX_CreateMemoryStream(data, 8, false));
+ ScopedFileStream stream(IFX_MemoryStream::Create(data, 8, false));
CPDF_SyntaxParser parser;
parser.InitParser(stream.get(), 0);
@@ -161,7 +161,7 @@ TEST(cpdf_syntax_parser, ReadHexString) {
{
// Just ending character.
uint8_t data[] = ">";
- ScopedFileStream stream(FX_CreateMemoryStream(data, 1, false));
+ ScopedFileStream stream(IFX_MemoryStream::Create(data, 1, false));
CPDF_SyntaxParser parser;
parser.InitParser(stream.get(), 0);
diff --git a/core/fxcrt/fx_extension.cpp b/core/fxcrt/fx_extension.cpp
index 39bf028205..6bf61f1fb5 100644
--- a/core/fxcrt/fx_extension.cpp
+++ b/core/fxcrt/fx_extension.cpp
@@ -40,7 +40,7 @@ void CFX_CRTFileAccess::GetPath(CFX_WideString& wsPath) {
}
IFX_SeekableStream* CFX_CRTFileAccess::CreateFileStream(uint32_t dwModes) {
- return FX_CreateFileStream(m_path.c_str(), dwModes);
+ return IFX_SeekableStream::CreateFromFilename(m_path.c_str(), dwModes);
}
bool CFX_CRTFileAccess::Init(const CFX_WideStringC& wsPath) {
@@ -338,33 +338,41 @@ IFX_FileAccess* FX_CreateDefaultFileAccess(const CFX_WideStringC& wsPath) {
}
#endif // PDF_ENABLE_XFA
-IFX_SeekableStream* FX_CreateFileStream(const FX_CHAR* filename,
- uint32_t dwModes) {
+// static
+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));
}
-IFX_SeekableStream* FX_CreateFileStream(const FX_WCHAR* filename,
- uint32_t dwModes) {
+// static
+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));
}
-IFX_SeekableReadStream* FX_CreateFileRead(const FX_CHAR* filename) {
- return FX_CreateFileStream(filename, FX_FILEMODE_ReadOnly);
-}
-IFX_SeekableReadStream* FX_CreateFileRead(const FX_WCHAR* filename) {
- return FX_CreateFileStream(filename, FX_FILEMODE_ReadOnly);
+
+// static
+IFX_SeekableReadStream* IFX_SeekableReadStream::CreateFromFilename(
+ const FX_CHAR* filename) {
+ return IFX_SeekableStream::CreateFromFilename(filename, FX_FILEMODE_ReadOnly);
}
-IFX_MemoryStream* FX_CreateMemoryStream(uint8_t* pBuffer,
- size_t dwSize,
- bool bTakeOver) {
+
+// static
+IFX_MemoryStream* IFX_MemoryStream::Create(uint8_t* pBuffer,
+ size_t dwSize,
+ bool bTakeOver) {
return new CFX_MemoryStream(pBuffer, dwSize, bTakeOver);
}
-IFX_MemoryStream* FX_CreateMemoryStream(bool bConsecutive) {
+
+// static
+IFX_MemoryStream* IFX_MemoryStream::Create(bool bConsecutive) {
return new CFX_MemoryStream(bConsecutive);
}
diff --git a/core/fxcrt/fx_stream.h b/core/fxcrt/fx_stream.h
index dc687cf653..fe92c939d9 100644
--- a/core/fxcrt/fx_stream.h
+++ b/core/fxcrt/fx_stream.h
@@ -85,6 +85,8 @@ class IFX_SeekableWriteStream : public IFX_WriteStream {
class IFX_SeekableReadStream : public IFX_ReadStream {
public:
+ static IFX_SeekableReadStream* CreateFromFilename(const FX_CHAR* filename);
+
// IFX_ReadStream:
void Release() override = 0;
bool IsEOF() override;
@@ -95,12 +97,14 @@ class IFX_SeekableReadStream : public IFX_ReadStream {
virtual FX_FILESIZE GetSize() = 0;
};
-IFX_SeekableReadStream* FX_CreateFileRead(const FX_CHAR* filename);
-IFX_SeekableReadStream* FX_CreateFileRead(const FX_WCHAR* filename);
-
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);
+
virtual IFX_SeekableStream* Retain() = 0;
// IFX_SeekableReadStream:
@@ -119,11 +123,6 @@ class IFX_SeekableStream : public IFX_SeekableReadStream,
bool Flush() override = 0;
};
-IFX_SeekableStream* FX_CreateFileStream(const FX_CHAR* filename,
- uint32_t dwModes);
-IFX_SeekableStream* FX_CreateFileStream(const FX_WCHAR* filename,
- uint32_t dwModes);
-
#ifdef PDF_ENABLE_XFA
class IFX_FileAccess {
public:
@@ -138,6 +137,11 @@ IFX_FileAccess* FX_CreateDefaultFileAccess(const CFX_WideStringC& wsPath);
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);
+
virtual bool IsConsecutive() const = 0;
virtual void EstimateSize(size_t nInitSize, size_t nGrowSize) = 0;
virtual uint8_t* GetBuffer() const = 0;
@@ -147,11 +151,6 @@ class IFX_MemoryStream : public IFX_SeekableStream {
virtual void DetachBuffer() = 0;
};
-IFX_MemoryStream* FX_CreateMemoryStream(uint8_t* pBuffer,
- size_t nSize,
- bool bTakeOver = false);
-IFX_MemoryStream* FX_CreateMemoryStream(bool bConsecutive = false);
-
class IFX_BufferRead : public IFX_ReadStream {
public:
// IFX_ReadStream: