diff options
Diffstat (limited to 'xfa')
-rw-r--r-- | xfa/fxfa/parser/cxfa_document_parser.cpp | 15 | ||||
-rw-r--r-- | xfa/fxfa/parser/cxfa_simple_parser.cpp | 60 | ||||
-rw-r--r-- | xfa/fxfa/parser/cxfa_simple_parser.h | 9 |
3 files changed, 27 insertions, 57 deletions
diff --git a/xfa/fxfa/parser/cxfa_document_parser.cpp b/xfa/fxfa/parser/cxfa_document_parser.cpp index 18f9955210..883f684768 100644 --- a/xfa/fxfa/parser/cxfa_document_parser.cpp +++ b/xfa/fxfa/parser/cxfa_document_parser.cpp @@ -20,18 +20,15 @@ CXFA_DocumentParser::~CXFA_DocumentParser() { int32_t CXFA_DocumentParser::Parse(const RetainPtr<IFX_SeekableStream>& pStream, XFA_PacketType ePacketID) { - m_pDocument.reset(); - m_nodeParser.CloseParser(); - m_pDocument = pdfium::MakeUnique<CXFA_Document>(GetNotify()); m_nodeParser.SetFactory(m_pDocument.get()); - int32_t nRetStatus = m_nodeParser.Parse(pStream, ePacketID); - if (nRetStatus == XFA_PARSESTATUS_Done) { - ASSERT(m_pDocument); - m_pDocument->SetRoot(m_nodeParser.GetRootNode()); - } - return nRetStatus; + if (!m_nodeParser.Parse(pStream, ePacketID)) + return XFA_PARSESTATUS_StatusErr; + + ASSERT(m_pDocument); + m_pDocument->SetRoot(m_nodeParser.GetRootNode()); + return XFA_PARSESTATUS_Done; } CXFA_FFNotify* CXFA_DocumentParser::GetNotify() const { diff --git a/xfa/fxfa/parser/cxfa_simple_parser.cpp b/xfa/fxfa/parser/cxfa_simple_parser.cpp index 225271fae8..232f1fbec8 100644 --- a/xfa/fxfa/parser/cxfa_simple_parser.cpp +++ b/xfa/fxfa/parser/cxfa_simple_parser.cpp @@ -100,11 +100,8 @@ const PacketInfo* GetPacketByName(const WideStringView& wsName) { return nullptr; } -CFX_XMLNode* GetDocumentNode(CFX_XMLDoc* pXMLDoc) { - if (!pXMLDoc) - return nullptr; - - for (CFX_XMLNode* pXMLNode = pXMLDoc->GetRoot()->GetFirstChild(); pXMLNode; +CFX_XMLNode* GetDocumentNode(CFX_XMLNode* pRootNode) { + for (CFX_XMLNode* pXMLNode = pRootNode->GetFirstChild(); pXMLNode; pXMLNode = pXMLNode->GetNextSibling()) { if (pXMLNode->GetType() != FX_XMLNODE_Element) continue; @@ -338,49 +335,33 @@ void CXFA_SimpleParser::SetFactory(CXFA_Document* pFactory) { m_pFactory = pFactory; } -int32_t CXFA_SimpleParser::Parse(const RetainPtr<IFX_SeekableStream>& pStream, - XFA_PacketType ePacketID) { - CloseParser(); - - m_pFileRead = pStream; - m_pStream = pdfium::MakeRetain<CFX_SeekableStreamProxy>(pStream, false); - uint16_t wCodePage = m_pStream->GetCodePage(); +bool CXFA_SimpleParser::Parse(const RetainPtr<IFX_SeekableStream>& pStream, + XFA_PacketType ePacketID) { + auto pStreamProxy = + pdfium::MakeRetain<CFX_SeekableStreamProxy>(pStream, false); + uint16_t wCodePage = pStreamProxy->GetCodePage(); if (wCodePage != FX_CODEPAGE_UTF16LE && wCodePage != FX_CODEPAGE_UTF16BE && wCodePage != FX_CODEPAGE_UTF8) { - m_pStream->SetCodePage(FX_CODEPAGE_UTF8); + pStreamProxy->SetCodePage(FX_CODEPAGE_UTF8); } - m_pXMLDoc = pdfium::MakeUnique<CFX_XMLDoc>(m_pStream); - if (!m_pXMLDoc) - return XFA_PARSESTATUS_StatusErr; - - int32_t iRet = m_pXMLDoc->Load(); - if (iRet < 0) - return XFA_PARSESTATUS_SyntaxErr; - if (iRet < 100) - return iRet / 2; - - m_pRootNode = ParseAsXDPPacket(GetDocumentNode(m_pXMLDoc.get()), ePacketID); - m_pXMLDoc->CloseXML(); - m_pStream.Reset(); - - if (!m_pRootNode) - return XFA_PARSESTATUS_StatusErr; + CFX_XMLDoc doc; + if (!doc.Load(pStreamProxy)) + return false; - return XFA_PARSESTATUS_Done; + m_pNodeTree = doc.GetTree(); + m_pRootNode = ParseAsXDPPacket(GetDocumentNode(m_pNodeTree.get()), ePacketID); + return !!m_pRootNode; } CFX_XMLNode* CXFA_SimpleParser::ParseXMLData(const ByteString& wsXML) { - CloseParser(); - auto pStream = pdfium::MakeRetain<CFX_SeekableStreamProxy>( const_cast<uint8_t*>(wsXML.raw_str()), wsXML.GetLength()); - m_pXMLDoc = pdfium::MakeUnique<CFX_XMLDoc>(pStream); + CFX_XMLDoc doc; + if (doc.Load(pStream)) + m_pNodeTree = doc.GetTree(); - int32_t iRet = m_pXMLDoc->Load(); - if (iRet < 0 || iRet >= 100) - m_pXMLDoc->CloseXML(); - return iRet < 100 ? nullptr : GetDocumentNode(m_pXMLDoc.get()); + return m_pNodeTree ? GetDocumentNode(m_pNodeTree.get()) : nullptr; } void CXFA_SimpleParser::ConstructXFANode(CXFA_Node* pXFANode, @@ -1180,8 +1161,3 @@ void CXFA_SimpleParser::ParseInstruction(CXFA_Node* pXFANode, } } } - -void CXFA_SimpleParser::CloseParser() { - m_pXMLDoc.reset(); - m_pStream.Reset(); -} diff --git a/xfa/fxfa/parser/cxfa_simple_parser.h b/xfa/fxfa/parser/cxfa_simple_parser.h index cef9c9af54..61edf8e8e6 100644 --- a/xfa/fxfa/parser/cxfa_simple_parser.h +++ b/xfa/fxfa/parser/cxfa_simple_parser.h @@ -25,13 +25,12 @@ class CXFA_SimpleParser { explicit CXFA_SimpleParser(CXFA_Document* pFactory); ~CXFA_SimpleParser(); - int32_t Parse(const RetainPtr<IFX_SeekableStream>& pStream, - XFA_PacketType ePacketID); + bool Parse(const RetainPtr<IFX_SeekableStream>& pStream, + XFA_PacketType ePacketID); CFX_XMLNode* ParseXMLData(const ByteString& wsXML); void ConstructXFANode(CXFA_Node* pXFANode, CFX_XMLNode* pXMLNode); CXFA_Node* GetRootNode() const; - void CloseParser(); // Called later for the ctor with no parameters. void SetFactory(CXFA_Document* pFactory); @@ -71,10 +70,8 @@ class CXFA_SimpleParser { CFX_XMLInstruction* pXMLInstruction, XFA_PacketType ePacketID); - std::unique_ptr<CFX_XMLDoc> m_pXMLDoc; - RetainPtr<CFX_SeekableStreamProxy> m_pStream; - RetainPtr<IFX_SeekableStream> m_pFileRead; UnownedPtr<CXFA_Document> m_pFactory; + std::unique_ptr<CFX_XMLNode> m_pNodeTree; // TODO(dsinclair): Figure out who owns this. CXFA_Node* m_pRootNode = nullptr; const bool m_bDocumentParser; |