From 56b08b1f2bb8a4eb9330963bff3a626603499730 Mon Sep 17 00:00:00 2001 From: Lei Zhang Date: Mon, 4 Dec 2017 06:04:35 +0000 Subject: Make CXFA_SimpleParser members const or Unowned. Fix ownership issues, and simplify CXFA_SimpleParser ctors. Change-Id: Ie083080297c5c2586ae3e6a8355839fcb86ee9ea Reviewed-on: https://pdfium-review.googlesource.com/20130 Reviewed-by: dsinclair Commit-Queue: Lei Zhang --- fxjs/cjx_node.cpp | 2 +- xfa/fxfa/parser/cxfa_dataimporter.cpp | 2 +- xfa/fxfa/parser/cxfa_document_parser.cpp | 2 +- xfa/fxfa/parser/cxfa_document_parser.h | 4 ++-- xfa/fxfa/parser/cxfa_simple_parser.cpp | 14 ++++++-------- xfa/fxfa/parser/cxfa_simple_parser.h | 17 ++++++++++------- 6 files changed, 21 insertions(+), 20 deletions(-) diff --git a/fxjs/cjx_node.cpp b/fxjs/cjx_node.cpp index 479bb8fa3d..58e2cdeb7c 100644 --- a/fxjs/cjx_node.cpp +++ b/fxjs/cjx_node.cpp @@ -705,7 +705,7 @@ void CJX_Node::Script_NodeClass_LoadXML(CFXJSE_Arguments* pArguments) { if (iLength >= 3) bOverwrite = !!pArguments->GetInt32(2); - auto pParser = pdfium::MakeUnique(GetDocument(), false); + auto pParser = pdfium::MakeUnique(GetDocument()); if (!pParser) return; diff --git a/xfa/fxfa/parser/cxfa_dataimporter.cpp b/xfa/fxfa/parser/cxfa_dataimporter.cpp index 28d0a8ce2a..2967c30304 100644 --- a/xfa/fxfa/parser/cxfa_dataimporter.cpp +++ b/xfa/fxfa/parser/cxfa_dataimporter.cpp @@ -27,7 +27,7 @@ CXFA_DataImporter::~CXFA_DataImporter() {} bool CXFA_DataImporter::ImportData( const RetainPtr& pDataDocument) { auto pDataDocumentParser = - pdfium::MakeUnique(m_pDocument.Get(), false); + pdfium::MakeUnique(m_pDocument.Get()); if (pDataDocumentParser->StartParse( pDataDocument, XFA_PacketType::Datasets) != XFA_PARSESTATUS_Ready) { return false; diff --git a/xfa/fxfa/parser/cxfa_document_parser.cpp b/xfa/fxfa/parser/cxfa_document_parser.cpp index 0cc03b94d0..df7d789781 100644 --- a/xfa/fxfa/parser/cxfa_document_parser.cpp +++ b/xfa/fxfa/parser/cxfa_document_parser.cpp @@ -12,7 +12,7 @@ #include "xfa/fxfa/parser/cxfa_document.h" CXFA_DocumentParser::CXFA_DocumentParser(CXFA_FFNotify* pNotify) - : m_nodeParser(nullptr, true), m_pNotify(pNotify) {} + : m_pNotify(pNotify) {} CXFA_DocumentParser::~CXFA_DocumentParser() { } diff --git a/xfa/fxfa/parser/cxfa_document_parser.h b/xfa/fxfa/parser/cxfa_document_parser.h index a3c2365b7b..6629101457 100644 --- a/xfa/fxfa/parser/cxfa_document_parser.h +++ b/xfa/fxfa/parser/cxfa_document_parser.h @@ -31,9 +31,9 @@ class CXFA_DocumentParser { CXFA_Document* GetDocument() const; private: - CXFA_SimpleParser m_nodeParser; - CXFA_FFNotify* m_pNotify; + CXFA_FFNotify* const m_pNotify; std::unique_ptr m_pDocument; + CXFA_SimpleParser m_nodeParser; }; #endif // XFA_FXFA_PARSER_CXFA_DOCUMENT_PARSER_H_ diff --git a/xfa/fxfa/parser/cxfa_simple_parser.cpp b/xfa/fxfa/parser/cxfa_simple_parser.cpp index 22b02ccdc8..b3965ed6a2 100644 --- a/xfa/fxfa/parser/cxfa_simple_parser.cpp +++ b/xfa/fxfa/parser/cxfa_simple_parser.cpp @@ -299,18 +299,15 @@ bool XFA_RecognizeRichText(CFX_XMLElement* pRichTextXMLNode) { L"http://www.w3.org/1999/xhtml"; } -CXFA_SimpleParser::CXFA_SimpleParser(CXFA_Document* pFactory, - bool bDocumentParser) - : m_pXMLParser(nullptr), - m_pFactory(pFactory), - m_pRootNode(nullptr), - m_ePacketID(XFA_PacketType::User), - m_bParseStarted(false), - m_bDocumentParser(bDocumentParser) {} +CXFA_SimpleParser::CXFA_SimpleParser() : m_bDocumentParser(true) {} + +CXFA_SimpleParser::CXFA_SimpleParser(CXFA_Document* pFactory) + : m_pFactory(pFactory), m_bDocumentParser(false) {} CXFA_SimpleParser::~CXFA_SimpleParser() {} void CXFA_SimpleParser::SetFactory(CXFA_Document* pFactory) { + ASSERT(m_bDocumentParser); m_pFactory = pFactory; } @@ -348,6 +345,7 @@ int32_t CXFA_SimpleParser::DoParse() { return iRet / 2; m_pRootNode = ParseAsXDPPacket(GetDocumentNode(m_pXMLDoc.get()), m_ePacketID); + m_pXMLParser.Release(); m_pXMLDoc->CloseXML(); m_pStream.Reset(); diff --git a/xfa/fxfa/parser/cxfa_simple_parser.h b/xfa/fxfa/parser/cxfa_simple_parser.h index 2ccb2c3b1a..52bb60fac5 100644 --- a/xfa/fxfa/parser/cxfa_simple_parser.h +++ b/xfa/fxfa/parser/cxfa_simple_parser.h @@ -22,7 +22,8 @@ class CFX_SeekableStreamProxy; class CXFA_SimpleParser { public: - CXFA_SimpleParser(CXFA_Document* pFactory, bool bDocumentParser); + CXFA_SimpleParser(); + explicit CXFA_SimpleParser(CXFA_Document* pFactory); ~CXFA_SimpleParser(); int32_t StartParse(const RetainPtr& pStream, @@ -34,6 +35,7 @@ class CXFA_SimpleParser { CFX_XMLDoc* GetXMLDoc() const; void CloseParser(); + // Called later for the ctor with no parameters. void SetFactory(CXFA_Document* pFactory); private: @@ -71,15 +73,16 @@ class CXFA_SimpleParser { CFX_XMLInstruction* pXMLInstruction, XFA_PacketType ePacketID); - CFX_XMLParser* m_pXMLParser; + UnownedPtr m_pXMLParser; // Owned by |m_pXMLDoc| std::unique_ptr m_pXMLDoc; RetainPtr m_pStream; RetainPtr m_pFileRead; - CXFA_Document* m_pFactory; - CXFA_Node* m_pRootNode; - XFA_PacketType m_ePacketID; - bool m_bParseStarted; - bool m_bDocumentParser; + UnownedPtr m_pFactory; + // TODO(dsinclair): Figure out who owns this. + CXFA_Node* m_pRootNode = nullptr; + XFA_PacketType m_ePacketID = XFA_PacketType::User; + bool m_bParseStarted = false; + const bool m_bDocumentParser; }; #endif // XFA_FXFA_PARSER_CXFA_SIMPLE_PARSER_H_ -- cgit v1.2.3