diff options
author | Dan Sinclair <dsinclair@chromium.org> | 2018-04-12 13:21:48 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2018-04-12 13:21:48 +0000 |
commit | 2efb11c89ee200473f5675ba3d3a946d5606e813 (patch) | |
tree | 52b46b0ef3ee3bc91046b217c65aa13e5dd9a06d /xfa/fxfa/parser | |
parent | a995d6fd9b862dbd37aebb9c323766bb5d11d389 (diff) | |
download | pdfium-2efb11c89ee200473f5675ba3d3a946d5606e813.tar.xz |
Retrieve the XML tree in the DocumentParser
This CL changes the document parser to store the parsed XML tree. That
way we no longer need to store the pointer to the CXFA_SimpleParser in
the CXFA_DocumentParser.
Change-Id: I9272150e73613411cb1bb59c3cf77c7af6cc799d
Reviewed-on: https://pdfium-review.googlesource.com/30211
Reviewed-by: Henrique Nakashima <hnakashima@chromium.org>
Commit-Queue: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'xfa/fxfa/parser')
-rw-r--r-- | xfa/fxfa/parser/cxfa_dataimporter.cpp | 3 | ||||
-rw-r--r-- | xfa/fxfa/parser/cxfa_document_parser.cpp | 21 | ||||
-rw-r--r-- | xfa/fxfa/parser/cxfa_document_parser.h | 8 | ||||
-rw-r--r-- | xfa/fxfa/parser/cxfa_simple_parser.h | 5 |
4 files changed, 21 insertions, 16 deletions
diff --git a/xfa/fxfa/parser/cxfa_dataimporter.cpp b/xfa/fxfa/parser/cxfa_dataimporter.cpp index 01e95b1c3a..b44e5e0552 100644 --- a/xfa/fxfa/parser/cxfa_dataimporter.cpp +++ b/xfa/fxfa/parser/cxfa_dataimporter.cpp @@ -27,8 +27,7 @@ CXFA_DataImporter::~CXFA_DataImporter() {} bool CXFA_DataImporter::ImportData( const RetainPtr<IFX_SeekableStream>& pDataDocument) { CXFA_SimpleParser parser(m_pDocument.Get()); - int status = parser.Parse(pDataDocument, XFA_PacketType::Datasets); - if (status < XFA_PARSESTATUS_Done) + if (!parser.Parse(pDataDocument, XFA_PacketType::Datasets)) return false; CXFA_Node* pImportDataRoot = parser.GetRootNode(); diff --git a/xfa/fxfa/parser/cxfa_document_parser.cpp b/xfa/fxfa/parser/cxfa_document_parser.cpp index 883f684768..52b5e333c0 100644 --- a/xfa/fxfa/parser/cxfa_document_parser.cpp +++ b/xfa/fxfa/parser/cxfa_document_parser.cpp @@ -18,17 +18,22 @@ CXFA_DocumentParser::~CXFA_DocumentParser() { m_pDocument->ReleaseXMLNodesIfNeeded(); } -int32_t CXFA_DocumentParser::Parse(const RetainPtr<IFX_SeekableStream>& pStream, - XFA_PacketType ePacketID) { +bool CXFA_DocumentParser::Parse(const RetainPtr<IFX_SeekableStream>& pStream, + XFA_PacketType ePacketID) { m_pDocument = pdfium::MakeUnique<CXFA_Document>(GetNotify()); - m_nodeParser.SetFactory(m_pDocument.get()); - if (!m_nodeParser.Parse(pStream, ePacketID)) - return XFA_PARSESTATUS_StatusErr; + // Note, we don't pass the document into the constructor as currently that + // triggers different behaviour in the parser. + CXFA_SimpleParser parser; + parser.SetFactory(m_pDocument.get()); - ASSERT(m_pDocument); - m_pDocument->SetRoot(m_nodeParser.GetRootNode()); - return XFA_PARSESTATUS_Done; + if (!parser.Parse(pStream, ePacketID)) + return false; + + m_pXMLRoot = parser.GetXMLRoot(); + + m_pDocument->SetRoot(parser.GetRootNode()); + return true; } CXFA_FFNotify* CXFA_DocumentParser::GetNotify() const { diff --git a/xfa/fxfa/parser/cxfa_document_parser.h b/xfa/fxfa/parser/cxfa_document_parser.h index c7056c215a..1075f48ef4 100644 --- a/xfa/fxfa/parser/cxfa_document_parser.h +++ b/xfa/fxfa/parser/cxfa_document_parser.h @@ -22,18 +22,16 @@ class CXFA_DocumentParser { explicit CXFA_DocumentParser(CXFA_FFNotify* pNotify); ~CXFA_DocumentParser(); - int32_t Parse(const RetainPtr<IFX_SeekableStream>& pStream, - XFA_PacketType ePacketID); + bool Parse(const RetainPtr<IFX_SeekableStream>& pStream, + XFA_PacketType ePacketID); CXFA_FFNotify* GetNotify() const; CXFA_Document* GetDocument() const; private: UnownedPtr<CXFA_FFNotify> const m_pNotify; - // Note, the |m_nodeParser| has an unowned pointer to the |m_pDocument| so - // the |m_nodeParser| must be cleaned up first. + std::unique_ptr<CFX_XMLNode> m_pXMLRoot; std::unique_ptr<CXFA_Document> m_pDocument; - CXFA_SimpleParser m_nodeParser; }; #endif // XFA_FXFA_PARSER_CXFA_DOCUMENT_PARSER_H_ diff --git a/xfa/fxfa/parser/cxfa_simple_parser.h b/xfa/fxfa/parser/cxfa_simple_parser.h index 61edf8e8e6..157983fe8e 100644 --- a/xfa/fxfa/parser/cxfa_simple_parser.h +++ b/xfa/fxfa/parser/cxfa_simple_parser.h @@ -8,14 +8,15 @@ #define XFA_FXFA_PARSER_CXFA_SIMPLE_PARSER_H_ #include <memory> +#include <utility> +#include "core/fxcrt/xml/cfx_xmlnode.h" #include "xfa/fxfa/fxfa_basic.h" class CXFA_Document; class CXFA_Node; class CFX_XMLDoc; class CFX_XMLInstruction; -class CFX_XMLNode; class IFX_SeekableStream; class CFX_SeekableStreamProxy; @@ -30,6 +31,8 @@ class CXFA_SimpleParser { CFX_XMLNode* ParseXMLData(const ByteString& wsXML); void ConstructXFANode(CXFA_Node* pXFANode, CFX_XMLNode* pXMLNode); + + std::unique_ptr<CFX_XMLNode> GetXMLRoot() { return std::move(m_pNodeTree); } CXFA_Node* GetRootNode() const; // Called later for the ctor with no parameters. |