1// Copyright 2016 PDFium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 6 7#include "xfa/fxfa/parser/cxfa_document_parser.h" 8 9#include "third_party/base/ptr_util.h" 10#include "xfa/fxfa/fxfa.h" 11#include "xfa/fxfa/parser/cxfa_document.h" 12 13CXFA_DocumentParser::CXFA_DocumentParser(CXFA_FFNotify* pNotify) 14 : m_nodeParser(nullptr, true), m_pNotify(pNotify) {} 15 16CXFA_DocumentParser::~CXFA_DocumentParser() { 17} 18 19int32_t CXFA_DocumentParser::StartParse( 20 const CFX_RetainPtr<IFX_SeekableReadStream>& pStream, 21 XFA_XDPPACKET ePacketID) { 22 m_pDocument.reset(); 23 m_nodeParser.CloseParser(); 24 25 int32_t nRetStatus = m_nodeParser.StartParse(pStream, ePacketID); 26 if (nRetStatus == XFA_PARSESTATUS_Ready) { 27 m_pDocument = pdfium::MakeUnique<CXFA_Document>(this); 28 m_nodeParser.SetFactory(m_pDocument.get()); 29 } 30 return nRetStatus; 31} 32 33int32_t CXFA_DocumentParser::DoParse(IFX_Pause* pPause) { 34 int32_t nRetStatus = m_nodeParser.DoParse(pPause); 35 if (nRetStatus >= XFA_PARSESTATUS_Done) { 36 ASSERT(m_pDocument); 37 m_pDocument->SetRoot(m_nodeParser.GetRootNode()); 38 } 39 return nRetStatus; 40} 41 42CFDE_XMLDoc* CXFA_DocumentParser::GetXMLDoc() const { 43 return m_nodeParser.GetXMLDoc(); 44} 45 46CXFA_FFNotify* CXFA_DocumentParser::GetNotify() const { 47 return m_pNotify; 48} 49 50CXFA_Document* CXFA_DocumentParser::GetDocument() const { 51 return m_pDocument.get(); 52} 53