summaryrefslogtreecommitdiff
path: root/core/fxcrt
diff options
context:
space:
mode:
authorDan Sinclair <dsinclair@chromium.org>2018-04-12 13:15:59 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-04-12 13:15:59 +0000
commita995d6fd9b862dbd37aebb9c323766bb5d11d389 (patch)
treedb204479d0c854d1e30840794972d5115cbe80f4 /core/fxcrt
parent332139df2c3c0826069fa61bcd436309fcdf5a6f (diff)
downloadpdfium-a995d6fd9b862dbd37aebb9c323766bb5d11d389.tar.xz
Allow retrieving the XML tree from the CFX_XMLDoc
This CL allows the CXFA_SimpleParser to retrieve the XML tree from the CFX_XMLDoc. This way, we don't have to keep the doc around and can store the pointer to the tree in the CXFA_SimpleParser. Change-Id: I5b478acbe61e6f1ca5fa04d03133a2b327a0cb1c Reviewed-on: https://pdfium-review.googlesource.com/30210 Reviewed-by: Henrique Nakashima <hnakashima@chromium.org> Commit-Queue: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'core/fxcrt')
-rw-r--r--core/fxcrt/xml/cfx_xmldoc.cpp16
-rw-r--r--core/fxcrt/xml/cfx_xmldoc.h10
-rw-r--r--core/fxcrt/xml/cfx_xmlparser.cpp28
-rw-r--r--core/fxcrt/xml/cfx_xmlparser.h2
4 files changed, 21 insertions, 35 deletions
diff --git a/core/fxcrt/xml/cfx_xmldoc.cpp b/core/fxcrt/xml/cfx_xmldoc.cpp
index 57be180f9a..c14255d432 100644
--- a/core/fxcrt/xml/cfx_xmldoc.cpp
+++ b/core/fxcrt/xml/cfx_xmldoc.cpp
@@ -18,20 +18,14 @@
#include "third_party/base/ptr_util.h"
#include "third_party/base/stl_util.h"
-CFX_XMLDoc::CFX_XMLDoc(const RetainPtr<CFX_SeekableStreamProxy>& pStream)
- : m_pRoot(pdfium::MakeUnique<CFX_XMLNode>()),
- m_pXMLParser(pdfium::MakeUnique<CFX_XMLParser>(m_pRoot.get(), pStream)) {
- ASSERT(pStream);
-
+CFX_XMLDoc::CFX_XMLDoc() : m_pRoot(pdfium::MakeUnique<CFX_XMLNode>()) {
m_pRoot->AppendChild(new CFX_XMLInstruction(L"xml"));
}
CFX_XMLDoc::~CFX_XMLDoc() {}
-int32_t CFX_XMLDoc::Load() {
- return m_pXMLParser->Parse();
-}
-
-void CFX_XMLDoc::CloseXML() {
- m_pXMLParser.reset();
+bool CFX_XMLDoc::Load(const RetainPtr<CFX_SeekableStreamProxy>& pStream) {
+ ASSERT(pStream);
+ CFX_XMLParser parser(m_pRoot.get(), pStream);
+ return parser.Parse();
}
diff --git a/core/fxcrt/xml/cfx_xmldoc.h b/core/fxcrt/xml/cfx_xmldoc.h
index 55976b01b3..915acd325d 100644
--- a/core/fxcrt/xml/cfx_xmldoc.h
+++ b/core/fxcrt/xml/cfx_xmldoc.h
@@ -8,6 +8,7 @@
#define CORE_FXCRT_XML_CFX_XMLDOC_H_
#include <memory>
+#include <utility>
#include "core/fxcrt/cfx_seekablestreamproxy.h"
#include "core/fxcrt/retain_ptr.h"
@@ -16,18 +17,15 @@
class CFX_XMLDoc {
public:
- explicit CFX_XMLDoc(const RetainPtr<CFX_SeekableStreamProxy>& pStream);
+ CFX_XMLDoc();
~CFX_XMLDoc();
- int32_t Load();
- void CloseXML();
+ bool Load(const RetainPtr<CFX_SeekableStreamProxy>& pStream);
- CFX_XMLNode* GetRoot() const { return m_pRoot.get(); }
- CFX_XMLParser* GetParser() const { return m_pXMLParser.get(); }
+ std::unique_ptr<CFX_XMLNode> GetTree() { return std::move(m_pRoot); }
private:
std::unique_ptr<CFX_XMLNode> m_pRoot;
- std::unique_ptr<CFX_XMLParser> m_pXMLParser;
};
#endif // CORE_FXCRT_XML_CFX_XMLDOC_H_
diff --git a/core/fxcrt/xml/cfx_xmlparser.cpp b/core/fxcrt/xml/cfx_xmlparser.cpp
index 39196d0264..d0acbc7818 100644
--- a/core/fxcrt/xml/cfx_xmlparser.cpp
+++ b/core/fxcrt/xml/cfx_xmlparser.cpp
@@ -132,36 +132,36 @@ CFX_XMLParser::CFX_XMLParser(CFX_XMLNode* pParent,
CFX_XMLParser::~CFX_XMLParser() {}
-int32_t CFX_XMLParser::Parse() {
+bool CFX_XMLParser::Parse() {
int32_t iCount = 0;
while (true) {
FX_XmlSyntaxResult result = DoSyntaxParse();
if (result == FX_XmlSyntaxResult::Error)
- return -1;
+ return false;
if (result == FX_XmlSyntaxResult::EndOfString)
break;
switch (result) {
case FX_XmlSyntaxResult::InstructionClose:
if (m_pChild && m_pChild->GetType() != FX_XMLNODE_Instruction)
- return -1;
+ return false;
m_pChild = m_pParent;
break;
case FX_XmlSyntaxResult::ElementClose:
if (m_pChild->GetType() != FX_XMLNODE_Element)
- return -1;
+ return false;
m_ws1 = GetTagName();
if (m_ws1.GetLength() > 0 &&
m_ws1 != static_cast<CFX_XMLElement*>(m_pChild)->GetName()) {
- return -1;
+ return false;
}
if (!m_NodeStack.empty())
m_NodeStack.pop();
if (m_NodeStack.empty())
- return -1;
+ return false;
m_pParent = m_NodeStack.top();
m_pChild = m_pParent;
@@ -209,7 +209,7 @@ int32_t CFX_XMLParser::Parse() {
case FX_XmlSyntaxResult::TargetData:
if (m_pChild) {
if (m_pChild->GetType() != FX_XMLNODE_Instruction)
- return -1;
+ return false;
auto* instruction = static_cast<CFX_XMLInstruction*>(m_pChild);
if (!m_ws1.IsEmpty())
@@ -226,7 +226,7 @@ int32_t CFX_XMLParser::Parse() {
break;
}
}
- return m_NodeStack.size() != 1 ? -1 : GetStatus();
+ return m_NodeStack.size() != 1 ? false : GetStatus();
}
FX_XmlSyntaxResult CFX_XMLParser::DoSyntaxParse() {
@@ -698,18 +698,12 @@ FX_XmlSyntaxResult CFX_XMLParser::DoSyntaxParse() {
int32_t CFX_XMLParser::GetStatus() const {
if (!m_pStream)
- return -1;
+ return false;
int32_t iStreamLength = m_pStream->GetLength();
if (iStreamLength < 1)
- return 100;
-
- if (m_syntaxParserResult == FX_XmlSyntaxResult::Error)
- return -1;
-
- if (m_syntaxParserResult == FX_XmlSyntaxResult::EndOfString)
- return 100;
- return m_iParsedBytes * 100 / iStreamLength;
+ return true;
+ return m_syntaxParserResult != FX_XmlSyntaxResult::Error;
}
FX_FILESIZE CFX_XMLParser::GetCurrentBinaryPos() const {
diff --git a/core/fxcrt/xml/cfx_xmlparser.h b/core/fxcrt/xml/cfx_xmlparser.h
index c7587e9151..f4e3c03ee7 100644
--- a/core/fxcrt/xml/cfx_xmlparser.h
+++ b/core/fxcrt/xml/cfx_xmlparser.h
@@ -47,7 +47,7 @@ class CFX_XMLParser {
const RetainPtr<CFX_SeekableStreamProxy>& pStream);
virtual ~CFX_XMLParser();
- int32_t Parse();
+ bool Parse();
protected:
FX_XmlSyntaxResult DoSyntaxParse();