summaryrefslogtreecommitdiff
path: root/core/fxcrt/xml
diff options
context:
space:
mode:
authordsinclair <dsinclair@chromium.org>2018-04-23 18:34:57 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-04-23 18:34:57 +0000
commit857231a0723c0bf74ea6c13f1c3ce56548e23303 (patch)
tree262538d8f7f8e5b9703a7c37e7ec2f1b477aebe3 /core/fxcrt/xml
parentc6077a0164340fa084be03eb059d608bc2675b2b (diff)
downloadpdfium-857231a0723c0bf74ea6c13f1c3ce56548e23303.tar.xz
Revert "Make CFX_SeekableStreamProxy a subclass of IFX_SeekableReadStream"
This reverts commit c6077a0164340fa084be03eb059d608bc2675b2b. Reason for revert: Gerrit did not do what i expected. Original change's description: > Make CFX_SeekableStreamProxy a subclass of IFX_SeekableReadStream > > This CL changes CFX_SeekableStreamProxy to be an IFX_SeekableReadStream > subclass. > > Change-Id: I28ccb4771606fd6c9cc60e57297ae2e776fc5a9f > Reviewed-on: https://pdfium-review.googlesource.com/30879 > Commit-Queue: dsinclair <dsinclair@chromium.org> > Reviewed-by: Tom Sepez <tsepez@chromium.org> TBR=tsepez@chromium.org,dsinclair@chromium.org,hnakashima@chromium.org Change-Id: I65e7647221e9bad2c0db7d068638178996972437 No-Presubmit: true No-Tree-Checks: true No-Try: true Reviewed-on: https://pdfium-review.googlesource.com/31210 Reviewed-by: dsinclair <dsinclair@chromium.org> Commit-Queue: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'core/fxcrt/xml')
-rw-r--r--core/fxcrt/xml/cfx_xmlparser.cpp35
-rw-r--r--core/fxcrt/xml/cfx_xmlparser.h9
2 files changed, 31 insertions, 13 deletions
diff --git a/core/fxcrt/xml/cfx_xmlparser.cpp b/core/fxcrt/xml/cfx_xmlparser.cpp
index bf578291e6..7788a42907 100644
--- a/core/fxcrt/xml/cfx_xmlparser.cpp
+++ b/core/fxcrt/xml/cfx_xmlparser.cpp
@@ -11,7 +11,6 @@
#include <iterator>
#include <utility>
-#include "core/fxcrt/cfx_seekablestreamproxy.h"
#include "core/fxcrt/fx_codepage.h"
#include "core/fxcrt/fx_extension.h"
#include "core/fxcrt/fx_safe_types.h"
@@ -58,10 +57,13 @@ bool CFX_XMLParser::IsXMLNameChar(wchar_t ch, bool bFirstChar) {
}
CFX_XMLParser::CFX_XMLParser(CFX_XMLNode* pParent,
- const RetainPtr<IFX_SeekableReadStream>& pStream)
+ const RetainPtr<IFX_SeekableStream>& pStream)
: m_pParent(pParent),
m_pChild(nullptr),
+ m_pStream(pdfium::MakeRetain<CFX_SeekableStreamProxy>(pStream)),
m_iXMLPlaneSize(1024),
+ m_iCurrentPos(0),
+ m_bEOS(false),
m_Start(0),
m_End(0),
m_CurNodeType(FX_XMLNODE_Unknown),
@@ -75,19 +77,18 @@ CFX_XMLParser::CFX_XMLParser(CFX_XMLNode* pParent,
ASSERT(m_pParent);
ASSERT(pStream);
- auto proxy = pdfium::MakeRetain<CFX_SeekableStreamProxy>(pStream);
- uint16_t wCodePage = proxy->GetCodePage();
+ uint16_t wCodePage = m_pStream->GetCodePage();
if (wCodePage != FX_CODEPAGE_UTF16LE && wCodePage != FX_CODEPAGE_UTF16BE &&
wCodePage != FX_CODEPAGE_UTF8) {
- proxy->SetCodePage(FX_CODEPAGE_UTF8);
+ m_pStream->SetCodePage(FX_CODEPAGE_UTF8);
}
- m_pStream = proxy;
m_NodeStack.push(m_pParent);
m_iXMLPlaneSize =
std::min(m_iXMLPlaneSize,
- pdfium::base::checked_cast<size_t>(m_pStream->GetSize()));
+ pdfium::base::checked_cast<size_t>(m_pStream->GetLength()));
+ m_iCurrentPos = m_pStream->GetBOMLength();
FX_SAFE_SIZE_T alloc_size_safe = m_iXMLPlaneSize;
alloc_size_safe += 1; // For NUL.
@@ -216,20 +217,28 @@ FX_XmlSyntaxResult CFX_XMLParser::DoSyntaxParse() {
return m_syntaxParserResult;
}
+ FX_FILESIZE iStreamLength = m_pStream->GetLength();
+ FX_FILESIZE iPos;
+
FX_XmlSyntaxResult syntaxParserResult = FX_XmlSyntaxResult::None;
while (true) {
if (m_Start >= m_End) {
- if (m_pStream->IsEOF()) {
+ if (m_bEOS || m_iCurrentPos >= iStreamLength) {
m_syntaxParserResult = FX_XmlSyntaxResult::EndOfString;
return m_syntaxParserResult;
}
+ if (m_pStream->GetPosition() != m_iCurrentPos)
+ m_pStream->Seek(CFX_SeekableStreamProxy::From::Begin, m_iCurrentPos);
size_t buffer_chars =
- m_pStream->ReadBlock(m_Buffer.data(), m_iXMLPlaneSize);
+ m_pStream->ReadString(m_Buffer.data(), m_iXMLPlaneSize, &m_bEOS);
+ iPos = m_pStream->GetPosition();
if (buffer_chars == 0) {
+ m_iCurrentPos = iStreamLength;
m_syntaxParserResult = FX_XmlSyntaxResult::EndOfString;
return m_syntaxParserResult;
}
+ m_iCurrentPos = iPos;
m_Start = 0;
m_End = buffer_chars;
}
@@ -656,7 +665,13 @@ FX_XmlSyntaxResult CFX_XMLParser::DoSyntaxParse() {
}
bool CFX_XMLParser::GetStatus() const {
- return m_pStream && m_syntaxParserResult != FX_XmlSyntaxResult::Error;
+ if (!m_pStream)
+ return false;
+
+ int32_t iStreamLength = m_pStream->GetLength();
+ if (iStreamLength < 1)
+ return true;
+ return m_syntaxParserResult != FX_XmlSyntaxResult::Error;
}
void CFX_XMLParser::ParseTextChar(wchar_t character) {
diff --git a/core/fxcrt/xml/cfx_xmlparser.h b/core/fxcrt/xml/cfx_xmlparser.h
index 6405b61a64..f369453de1 100644
--- a/core/fxcrt/xml/cfx_xmlparser.h
+++ b/core/fxcrt/xml/cfx_xmlparser.h
@@ -12,13 +12,14 @@
#include <vector>
#include "core/fxcrt/cfx_blockbuffer.h"
+#include "core/fxcrt/cfx_seekablestreamproxy.h"
#include "core/fxcrt/fx_string.h"
#include "core/fxcrt/retain_ptr.h"
#include "core/fxcrt/xml/cfx_xmlnode.h"
class CFX_XMLElement;
class CFX_XMLNode;
-class IFX_SeekableReadStream;
+class IFX_SeekableStream;
enum class FX_XmlSyntaxResult {
None,
@@ -43,7 +44,7 @@ class CFX_XMLParser {
static bool IsXMLNameChar(wchar_t ch, bool bFirstChar);
CFX_XMLParser(CFX_XMLNode* pParent,
- const RetainPtr<IFX_SeekableReadStream>& pStream);
+ const RetainPtr<IFX_SeekableStream>& pStream);
virtual ~CFX_XMLParser();
bool Parse();
@@ -99,9 +100,11 @@ class CFX_XMLParser {
std::stack<CFX_XMLNode*> m_NodeStack;
WideString m_ws1;
- RetainPtr<IFX_SeekableReadStream> m_pStream;
+ RetainPtr<CFX_SeekableStreamProxy> m_pStream;
size_t m_iXMLPlaneSize;
+ FX_FILESIZE m_iCurrentPos;
std::vector<wchar_t> m_Buffer;
+ bool m_bEOS;
FX_FILESIZE m_Start; // Start position in m_Buffer
FX_FILESIZE m_End; // End position in m_Buffer
FX_XMLNODETYPE m_CurNodeType;