diff options
author | tsepez <tsepez@chromium.org> | 2016-05-16 15:42:58 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-05-16 15:42:58 -0700 |
commit | fa34e805fd03ba81bcfe1148cf96b24fe63b39a0 (patch) | |
tree | eb9ca58d4b4e327da346491f107d9b54925c18e3 /xfa/fxfa | |
parent | 44d83f3f0b90f4c53ca42115d4f1ed614b25c3a7 (diff) | |
download | pdfium-fa34e805fd03ba81bcfe1148cf96b24fe63b39a0.tar.xz |
Replace Release() { delete this; } in fde_xml_imp.h
Review-Url: https://codereview.chromium.org/1981003002
Diffstat (limited to 'xfa/fxfa')
-rw-r--r-- | xfa/fxfa/app/xfa_ffdoc.cpp | 12 | ||||
-rw-r--r-- | xfa/fxfa/parser/xfa_document.h | 1 | ||||
-rw-r--r-- | xfa/fxfa/parser/xfa_document_imp.cpp | 6 | ||||
-rw-r--r-- | xfa/fxfa/parser/xfa_document_serialize.cpp | 27 | ||||
-rw-r--r-- | xfa/fxfa/parser/xfa_object_imp.cpp | 26 | ||||
-rw-r--r-- | xfa/fxfa/parser/xfa_parser.h | 2 | ||||
-rw-r--r-- | xfa/fxfa/parser/xfa_parser_imp.cpp | 22 | ||||
-rw-r--r-- | xfa/fxfa/parser/xfa_parser_imp.h | 18 |
8 files changed, 52 insertions, 62 deletions
diff --git a/xfa/fxfa/app/xfa_ffdoc.cpp b/xfa/fxfa/app/xfa_ffdoc.cpp index f33e4e0585..77c3b251a2 100644 --- a/xfa/fxfa/app/xfa_ffdoc.cpp +++ b/xfa/fxfa/app/xfa_ffdoc.cpp @@ -7,6 +7,7 @@ #include "xfa/fxfa/include/xfa_ffdoc.h" #include <algorithm> +#include <memory> #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" @@ -145,10 +146,11 @@ int32_t CXFA_FFDoc::DoLoad(IFX_Pause* pPause) { if (!OpenDoc(pPDFDocument)) { return XFA_PARSESTATUS_SyntaxErr; } - IXFA_Parser* pParser = IXFA_Parser::Create(m_pDocument, TRUE); - if (!pParser) { + std::unique_ptr<IXFA_Parser> pParser( + IXFA_Parser::Create(m_pDocument, TRUE)); + if (!pParser) return XFA_PARSESTATUS_SyntaxErr; - } + CXFA_Node* pRootNode = NULL; if (pParser->StartParse(m_pStream) == XFA_PARSESTATUS_Ready && pParser->DoParse(NULL) == XFA_PARSESTATUS_Done) { @@ -160,8 +162,6 @@ int32_t CXFA_FFDoc::DoLoad(IFX_Pause* pPause) { } else { iStatus = XFA_PARSESTATUS_StatusErr; } - pParser->Release(); - pParser = NULL; } return iStatus; } @@ -265,7 +265,7 @@ FX_BOOL CXFA_FFDoc::CloseDoc() { m_TypeToDocViewMap.clear(); if (m_pDocument) { - m_pDocument->GetParser()->Release(); + m_pDocument->DestroyParser(); m_pDocument = nullptr; } diff --git a/xfa/fxfa/parser/xfa_document.h b/xfa/fxfa/parser/xfa_document.h index 16428ea781..8501e5fc60 100644 --- a/xfa/fxfa/parser/xfa_document.h +++ b/xfa/fxfa/parser/xfa_document.h @@ -67,6 +67,7 @@ class CXFA_Document { ~CXFA_Document(); CXFA_Node* GetRoot() const { return m_pRootNode; } CXFA_DocumentParser* GetParser() const { return m_pParser; } + void DestroyParser(); CXFA_FFNotify* GetNotify() const; void SetRoot(CXFA_Node* pNewRoot); CXFA_Object* GetXFAObject(const CFX_WideStringC& wsNodeName); diff --git a/xfa/fxfa/parser/xfa_document_imp.cpp b/xfa/fxfa/parser/xfa_document_imp.cpp index 0421683e07..3f1737a7f8 100644 --- a/xfa/fxfa/parser/xfa_document_imp.cpp +++ b/xfa/fxfa/parser/xfa_document_imp.cpp @@ -77,6 +77,12 @@ void CXFA_Document::SetRoot(CXFA_Node* pNewRoot) { m_pRootNode = pNewRoot; RemovePurgeNode(pNewRoot); } + +void CXFA_Document::DestroyParser() { + delete m_pParser; + m_pParser = nullptr; +} + CXFA_FFNotify* CXFA_Document::GetNotify() const { return m_pParser->GetNotify(); } diff --git a/xfa/fxfa/parser/xfa_document_serialize.cpp b/xfa/fxfa/parser/xfa_document_serialize.cpp index ef85d0e266..2e300505b3 100644 --- a/xfa/fxfa/parser/xfa_document_serialize.cpp +++ b/xfa/fxfa/parser/xfa_document_serialize.cpp @@ -6,6 +6,8 @@ #include "xfa/fxfa/parser/xfa_document_serialize.h" +#include <memory> + #include "xfa/fde/xml/fde_xml_imp.h" #include "xfa/fgas/crt/fgas_codepage.h" #include "xfa/fxfa/fm2js/xfa_fm2jsapi.h" @@ -22,31 +24,26 @@ CXFA_DataImporter::CXFA_DataImporter(CXFA_Document* pDocument) : m_pDocument(pDocument) { ASSERT(m_pDocument); } + FX_BOOL CXFA_DataImporter::ImportData(IFX_FileRead* pDataDocument) { - IXFA_Parser* pDataDocumentParser = IXFA_Parser::Create(m_pDocument); - if (!pDataDocumentParser) { - return FALSE; - } + std::unique_ptr<IXFA_Parser> pDataDocumentParser( + IXFA_Parser::Create(m_pDocument)); if (pDataDocumentParser->StartParse(pDataDocument, XFA_XDPPACKET_Datasets) != XFA_PARSESTATUS_Ready) { - pDataDocumentParser->Release(); return FALSE; } - if (pDataDocumentParser->DoParse(NULL) < XFA_PARSESTATUS_Done) { - pDataDocumentParser->Release(); + if (pDataDocumentParser->DoParse(nullptr) < XFA_PARSESTATUS_Done) return FALSE; - } + CXFA_Node* pImportDataRoot = pDataDocumentParser->GetRootNode(); - if (!pImportDataRoot) { - pDataDocumentParser->Release(); + if (!pImportDataRoot) return FALSE; - } + CXFA_Node* pDataModel = ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Datasets)); - if (!pDataModel) { - pDataDocumentParser->Release(); + if (!pDataModel) return FALSE; - } + CXFA_Node* pDataNode = ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Data)); if (pDataNode) { pDataModel->RemoveChild(pDataNode); @@ -66,9 +63,9 @@ FX_BOOL CXFA_DataImporter::ImportData(IFX_FileRead* pDataDocument) { pDataModel->InsertChild(pImportDataRoot); } m_pDocument->DoDataRemerge(FALSE); - pDataDocumentParser->Release(); return TRUE; } + CFX_WideString XFA_ExportEncodeAttribute(const CFX_WideString& str) { CFX_WideTextBuf textBuf; int32_t iLen = str.GetLength(); diff --git a/xfa/fxfa/parser/xfa_object_imp.cpp b/xfa/fxfa/parser/xfa_object_imp.cpp index 0fbde1f160..f9887825f5 100644 --- a/xfa/fxfa/parser/xfa_object_imp.cpp +++ b/xfa/fxfa/parser/xfa_object_imp.cpp @@ -120,10 +120,10 @@ CXFA_Node::~CXFA_Node() { delete pNode; pNode = pNext; } - if (m_pXMLNode && HasFlag(XFA_NODEFLAG_OwnXMLNode)) { - m_pXMLNode->Release(); - } + if (m_pXMLNode && HasFlag(XFA_NODEFLAG_OwnXMLNode)) + delete m_pXMLNode; } + CXFA_Node* CXFA_Node::Clone(FX_BOOL bRecursive) { CXFA_Document* pFactory = m_pDocument->GetParser()->GetFactory(); CXFA_Node* pClone = pFactory->CreateNode(m_ePacket, m_eNodeClass); @@ -962,17 +962,12 @@ void CXFA_Node::Script_NodeClass_LoadXML(CFXJSE_Arguments* pArguments) { if (iLength >= 3) { bOverwrite = pArguments->GetInt32(2) == 0 ? FALSE : TRUE; } - IXFA_Parser* pParser = IXFA_Parser::Create(m_pDocument); - if (!pParser) { - return; - } + std::unique_ptr<IXFA_Parser> pParser(IXFA_Parser::Create(m_pDocument)); CFDE_XMLNode* pXMLNode = NULL; int32_t iParserStatus = pParser->ParseXMLData(wsExpression, pXMLNode, NULL); - if (iParserStatus != XFA_PARSESTATUS_Done || !pXMLNode) { - pParser->Release(); - pParser = NULL; + if (iParserStatus != XFA_PARSESTATUS_Done || !pXMLNode) return; - } + if (bIgnoreRoot && (pXMLNode->GetType() != FDE_XMLNODE_Element || XFA_RecognizeRichText(static_cast<CFDE_XMLElement*>(pXMLNode)))) { @@ -1059,14 +1054,11 @@ void CXFA_Node::Script_NodeClass_LoadXML(CFXJSE_Arguments* pArguments) { } pFakeRoot->SetFlag(XFA_NODEFLAG_HasRemoved, false); } else { - if (pFakeXMLRoot) { - pFakeXMLRoot->Release(); - pFakeXMLRoot = NULL; - } + delete pFakeXMLRoot; + pFakeXMLRoot = nullptr; } - pParser->Release(); - pParser = NULL; } + void CXFA_Node::Script_NodeClass_SaveFilteredXML(CFXJSE_Arguments* pArguments) { } diff --git a/xfa/fxfa/parser/xfa_parser.h b/xfa/fxfa/parser/xfa_parser.h index 5ccc1af199..656653698e 100644 --- a/xfa/fxfa/parser/xfa_parser.h +++ b/xfa/fxfa/parser/xfa_parser.h @@ -16,7 +16,7 @@ class IXFA_Parser { static IXFA_Parser* Create(CXFA_Document* pFactory, FX_BOOL bDocumentParser = FALSE); virtual ~IXFA_Parser() {} - virtual void Release() = 0; + virtual int32_t StartParse(IFX_FileRead* pStream, XFA_XDPPACKET ePacketID = XFA_XDPPACKET_XDP) = 0; virtual int32_t DoParse(IFX_Pause* pPause = NULL) = 0; diff --git a/xfa/fxfa/parser/xfa_parser_imp.cpp b/xfa/fxfa/parser/xfa_parser_imp.cpp index 01ea1d6fae..bb4ba864d5 100644 --- a/xfa/fxfa/parser/xfa_parser_imp.cpp +++ b/xfa/fxfa/parser/xfa_parser_imp.cpp @@ -680,10 +680,9 @@ CXFA_Node* CXFA_SimpleParser::ParseAsXDPPacket_Data( CXFA_Node* pNode = m_pFactory->CreateNode(XFA_XDPPACKET_Datasets, XFA_ELEMENT_DataGroup); if (!pNode) { - if (pDataXMLNode != pXMLDocumentNode) { - pDataXMLNode->Release(); - } - return NULL; + if (pDataXMLNode != pXMLDocumentNode) + delete pDataXMLNode; + return nullptr; } CFX_WideString wsLocalName; static_cast<CFDE_XMLElement*>(pDataXMLNode)->GetLocalTagName(wsLocalName); @@ -1335,13 +1334,11 @@ void CXFA_SimpleParser::ParseInstruction(CXFA_Node* pXFANode, } } void CXFA_SimpleParser::CloseParser() { - if (m_pXMLDoc) { - m_pXMLDoc->Release(); - m_pXMLDoc = NULL; - } + delete m_pXMLDoc; + m_pXMLDoc = nullptr; if (m_pStream) { m_pStream->Release(); - m_pStream = NULL; + m_pStream = nullptr; } } @@ -1410,17 +1407,16 @@ CXFA_XMLParser::CXFA_XMLParser(CFDE_XMLNode* pRoot, IFX_Stream* pStream) m_syntaxParserResult(FDE_XmlSyntaxResult::None) { ASSERT(m_pParent && m_pStream); m_NodeStack.Push(m_pParent); - m_pParser = new CFDE_XMLSyntaxParser; + m_pParser.reset(new CFDE_XMLSyntaxParser); m_pParser->Init(m_pStream, 32 * 1024, 1024 * 1024); } + CXFA_XMLParser::~CXFA_XMLParser() { - if (m_pParser) { - m_pParser->Release(); - } m_NodeStack.RemoveAll(); m_ws1.clear(); m_ws2.clear(); } + int32_t CXFA_XMLParser::DoParser(IFX_Pause* pPause) { if (m_syntaxParserResult == FDE_XmlSyntaxResult::Error) return -1; diff --git a/xfa/fxfa/parser/xfa_parser_imp.h b/xfa/fxfa/parser/xfa_parser_imp.h index 2485ddfcd2..eb98966398 100644 --- a/xfa/fxfa/parser/xfa_parser_imp.h +++ b/xfa/fxfa/parser/xfa_parser_imp.h @@ -7,18 +7,18 @@ #ifndef XFA_FXFA_PARSER_XFA_PARSER_IMP_H_ #define XFA_FXFA_PARSER_XFA_PARSER_IMP_H_ +#include <memory> + #include "xfa/fde/xml/fde_xml_imp.h" #include "xfa/fxfa/parser/xfa_parser.h" class CXFA_XMLParser; -class CXFA_SimpleParser : public IXFA_Parser { +class CXFA_SimpleParser final : public IXFA_Parser { public: CXFA_SimpleParser(CXFA_Document* pFactory, FX_BOOL bDocumentParser = FALSE); ~CXFA_SimpleParser() override; - void Release() override { delete this; } - int32_t StartParse(IFX_FileRead* pStream, XFA_XDPPACKET ePacketID = XFA_XDPPACKET_XDP) override; int32_t DoParse(IFX_Pause* pPause = NULL) override; @@ -82,12 +82,11 @@ class CXFA_SimpleParser : public IXFA_Parser { friend class CXFA_DocumentParser; }; -class CXFA_DocumentParser : public IXFA_Parser { +class CXFA_DocumentParser final : public IXFA_Parser { public: CXFA_DocumentParser(CXFA_FFNotify* pNotify); ~CXFA_DocumentParser() override; - void Release() override { delete this; } int32_t StartParse(IFX_FileRead* pStream, XFA_XDPPACKET ePacketID = XFA_XDPPACKET_XDP) override; int32_t DoParse(IFX_Pause* pPause = NULL) override; @@ -111,13 +110,12 @@ class CXFA_DocumentParser : public IXFA_Parser { }; typedef CFX_StackTemplate<CFDE_XMLNode*> CXFA_XMLNodeStack; -class CXFA_XMLParser : public CFDE_XMLParser { +class CXFA_XMLParser : public IFDE_XMLParser { public: CXFA_XMLParser(CFDE_XMLNode* pRoot, IFX_Stream* pStream); - ~CXFA_XMLParser(); + ~CXFA_XMLParser() override; - virtual void Release() { delete this; } - virtual int32_t DoParser(IFX_Pause* pPause); + int32_t DoParser(IFX_Pause* pPause) override; FX_FILESIZE m_nStart[2]; size_t m_nSize[2]; @@ -128,7 +126,7 @@ class CXFA_XMLParser : public CFDE_XMLParser { protected: CFDE_XMLNode* m_pRoot; IFX_Stream* m_pStream; - CFDE_XMLSyntaxParser* m_pParser; + std::unique_ptr<CFDE_XMLSyntaxParser> m_pParser; CFDE_XMLNode* m_pParent; CFDE_XMLNode* m_pChild; CXFA_XMLNodeStack m_NodeStack; |