Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(162)

Side by Side Diff: xfa/fde/xml/fde_xml_imp.cpp

Issue 1980223002: Revert of Replace Release() { delete this; } in fde_xml_imp.h (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « xfa/fde/xml/fde_xml_imp.h ('k') | xfa/fxfa/app/xfa_ffdoc.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #include "xfa/fde/xml/fde_xml_imp.h" 7 #include "xfa/fde/xml/fde_xml_imp.h"
8 8
9 #include <algorithm> 9 #include <algorithm>
10 10
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 } 70 }
71 } 71 }
72 return FALSE; 72 return FALSE;
73 } 73 }
74 74
75 CFDE_XMLNode::CFDE_XMLNode() 75 CFDE_XMLNode::CFDE_XMLNode()
76 : m_pParent(NULL), m_pChild(NULL), m_pPrior(NULL), m_pNext(NULL) {} 76 : m_pParent(NULL), m_pChild(NULL), m_pPrior(NULL), m_pNext(NULL) {}
77 CFDE_XMLNode::~CFDE_XMLNode() { 77 CFDE_XMLNode::~CFDE_XMLNode() {
78 DeleteChildren(); 78 DeleteChildren();
79 } 79 }
80
81 void CFDE_XMLNode::DeleteChildren() { 80 void CFDE_XMLNode::DeleteChildren() {
82 CFDE_XMLNode* pChild = m_pChild; 81 CFDE_XMLNode *pChild = m_pChild, *pTemp;
83 while (pChild) { 82 while (pChild != NULL) {
84 CFDE_XMLNode* pNext = pChild->m_pNext; 83 pTemp = pChild->m_pNext;
85 delete pChild; 84 pChild->Release();
86 pChild = pNext; 85 pChild = pTemp;
87 } 86 }
88 m_pChild = nullptr; 87 m_pChild = NULL;
89 } 88 }
90
91 int32_t CFDE_XMLNode::CountChildNodes() const { 89 int32_t CFDE_XMLNode::CountChildNodes() const {
92 int32_t iCount = 0; 90 int32_t iCount = 0;
93 CFDE_XMLNode* pChild = m_pChild; 91 CFDE_XMLNode* pChild = m_pChild;
94 while (pChild != NULL) { 92 while (pChild != NULL) {
95 iCount++; 93 iCount++;
96 pChild = pChild->m_pNext; 94 pChild = pChild->m_pNext;
97 } 95 }
98 return iCount; 96 return iCount;
99 } 97 }
100 CFDE_XMLNode* CFDE_XMLNode::GetChildNode(int32_t index) const { 98 CFDE_XMLNode* CFDE_XMLNode::GetChildNode(int32_t index) const {
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after
505 pCloneNext->InsertNodeItem(CFDE_XMLNode::NextSibling, pChild); 503 pCloneNext->InsertNodeItem(CFDE_XMLNode::NextSibling, pChild);
506 pCloneNext = pChild; 504 pCloneNext = pChild;
507 pNext = pNext->m_pNext; 505 pNext = pNext->m_pNext;
508 } 506 }
509 } 507 }
510 508
511 CFDE_XMLInstruction::CFDE_XMLInstruction(const CFX_WideString& wsTarget) 509 CFDE_XMLInstruction::CFDE_XMLInstruction(const CFX_WideString& wsTarget)
512 : m_wsTarget(wsTarget) { 510 : m_wsTarget(wsTarget) {
513 ASSERT(m_wsTarget.GetLength() > 0); 511 ASSERT(m_wsTarget.GetLength() > 0);
514 } 512 }
515
516 CFDE_XMLInstruction::~CFDE_XMLInstruction() {}
517
518 CFDE_XMLNode* CFDE_XMLInstruction::Clone(FX_BOOL bRecursive) { 513 CFDE_XMLNode* CFDE_XMLInstruction::Clone(FX_BOOL bRecursive) {
519 CFDE_XMLInstruction* pClone = new CFDE_XMLInstruction(m_wsTarget); 514 CFDE_XMLInstruction* pClone = new CFDE_XMLInstruction(m_wsTarget);
520 if (!pClone) { 515 if (!pClone) {
521 return pClone; 516 return pClone;
522 } 517 }
523 pClone->m_Attributes.Copy(m_Attributes); 518 pClone->m_Attributes.Copy(m_Attributes);
524 pClone->m_TargetData.Copy(m_TargetData); 519 pClone->m_TargetData.Copy(m_TargetData);
525 if (bRecursive) { 520 if (bRecursive) {
526 CloneChildren(pClone); 521 CloneChildren(pClone);
527 } 522 }
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
825 pChild = pChild->m_pNext; 820 pChild = pChild->m_pNext;
826 } 821 }
827 wsText = buffer.AsStringC(); 822 wsText = buffer.AsStringC();
828 } 823 }
829 void CFDE_XMLElement::SetTextData(const CFX_WideString& wsText) { 824 void CFDE_XMLElement::SetTextData(const CFX_WideString& wsText) {
830 if (wsText.GetLength() < 1) { 825 if (wsText.GetLength() < 1) {
831 return; 826 return;
832 } 827 }
833 InsertChildNode(new CFDE_XMLText(wsText)); 828 InsertChildNode(new CFDE_XMLText(wsText));
834 } 829 }
835
836 CFDE_XMLText::CFDE_XMLText(const CFX_WideString& wsText) 830 CFDE_XMLText::CFDE_XMLText(const CFX_WideString& wsText)
837 : CFDE_XMLNode(), m_wsText(wsText) {} 831 : CFDE_XMLNode(), m_wsText(wsText) {}
838
839 CFDE_XMLText::~CFDE_XMLText() {}
840
841 CFDE_XMLNode* CFDE_XMLText::Clone(FX_BOOL bRecursive) { 832 CFDE_XMLNode* CFDE_XMLText::Clone(FX_BOOL bRecursive) {
842 CFDE_XMLText* pClone = new CFDE_XMLText(m_wsText); 833 CFDE_XMLText* pClone = new CFDE_XMLText(m_wsText);
843 return pClone; 834 return pClone;
844 } 835 }
845 836
846 CFDE_XMLCharData::CFDE_XMLCharData(const CFX_WideString& wsCData) 837 CFDE_XMLCharData::CFDE_XMLCharData(const CFX_WideString& wsCData)
847 : CFDE_XMLDeclaration(), m_wsCharData(wsCData) {} 838 : CFDE_XMLDeclaration(), m_wsCharData(wsCData) {}
848
849 CFDE_XMLCharData::~CFDE_XMLCharData() {}
850
851 CFDE_XMLNode* CFDE_XMLCharData::Clone(FX_BOOL bRecursive) { 839 CFDE_XMLNode* CFDE_XMLCharData::Clone(FX_BOOL bRecursive) {
852 CFDE_XMLCharData* pClone = new CFDE_XMLCharData(m_wsCharData); 840 CFDE_XMLCharData* pClone = new CFDE_XMLCharData(m_wsCharData);
853 return pClone; 841 return pClone;
854 } 842 }
855 843
856 CFDE_XMLDoc::CFDE_XMLDoc() 844 CFDE_XMLDoc::CFDE_XMLDoc()
857 : m_pRoot(NULL), m_pSyntaxParser(NULL), m_pXMLParser(NULL) { 845 : m_pRoot(NULL), m_pSyntaxParser(NULL), m_pXMLParser(NULL) {
858 Reset(TRUE); 846 Reset(TRUE);
859 CFDE_XMLInstruction* pXML = new CFDE_XMLInstruction(L"xml"); 847 CFDE_XMLInstruction* pXML = new CFDE_XMLInstruction(L"xml");
860 m_pRoot->InsertChildNode(pXML); 848 m_pRoot->InsertChildNode(pXML);
861 } 849 }
862 CFDE_XMLDoc::~CFDE_XMLDoc() { 850 CFDE_XMLDoc::~CFDE_XMLDoc() {
863 Reset(FALSE); 851 Reset(FALSE);
864 } 852 }
865 void CFDE_XMLDoc::Reset(FX_BOOL bInitRoot) { 853 void CFDE_XMLDoc::Reset(FX_BOOL bInitRoot) {
866 m_iStatus = 0; 854 m_iStatus = 0;
867 m_pStream = NULL; 855 m_pStream = NULL;
868 if (bInitRoot) { 856 if (bInitRoot) {
869 if (m_pRoot == NULL) { 857 if (m_pRoot == NULL) {
870 m_pRoot = new CFDE_XMLNode; 858 m_pRoot = new CFDE_XMLNode;
871 } else { 859 } else {
872 m_pRoot->DeleteChildren(); 860 m_pRoot->DeleteChildren();
873 } 861 }
874 } else { 862 } else {
875 delete m_pRoot; 863 if (m_pRoot != NULL) {
876 m_pRoot = nullptr; 864 m_pRoot->Release();
865 m_pRoot = NULL;
866 }
877 } 867 }
878 ReleaseParser(); 868 ReleaseParser();
879 } 869 }
880
881 void CFDE_XMLDoc::ReleaseParser() { 870 void CFDE_XMLDoc::ReleaseParser() {
882 delete m_pXMLParser; 871 if (m_pXMLParser != NULL) {
883 m_pXMLParser = nullptr; 872 m_pXMLParser->Release();
884 delete m_pSyntaxParser; 873 m_pXMLParser = NULL;
885 m_pSyntaxParser = nullptr; 874 }
875 if (m_pSyntaxParser != NULL) {
876 m_pSyntaxParser->Release();
877 m_pSyntaxParser = NULL;
878 }
886 } 879 }
887
888 FX_BOOL CFDE_XMLDoc::LoadXML(IFX_Stream* pXMLStream, 880 FX_BOOL CFDE_XMLDoc::LoadXML(IFX_Stream* pXMLStream,
889 int32_t iXMLPlaneSize, 881 int32_t iXMLPlaneSize,
890 int32_t iTextDataSize, 882 int32_t iTextDataSize,
891 FDE_XMLREADERHANDLER* pHandler) { 883 FDE_XMLREADERHANDLER* pHandler) {
892 if (pXMLStream == NULL) { 884 if (pXMLStream == NULL) {
893 return FALSE; 885 return FALSE;
894 } 886 }
895 Reset(TRUE); 887 Reset(TRUE);
896 iXMLPlaneSize = iXMLPlaneSize / 1024; 888 iXMLPlaneSize = iXMLPlaneSize / 1024;
897 if (iXMLPlaneSize < 1) { 889 if (iXMLPlaneSize < 1) {
(...skipping 22 matching lines...) Expand all
920 return FALSE; 912 return FALSE;
921 } 913 }
922 m_pSyntaxParser->Init(m_pStream, iXMLPlaneSize, iTextDataSize); 914 m_pSyntaxParser->Init(m_pStream, iXMLPlaneSize, iTextDataSize);
923 if (pHandler == NULL) { 915 if (pHandler == NULL) {
924 m_pXMLParser = new CFDE_XMLDOMParser(m_pRoot, m_pSyntaxParser); 916 m_pXMLParser = new CFDE_XMLDOMParser(m_pRoot, m_pSyntaxParser);
925 } else { 917 } else {
926 m_pXMLParser = new CFDE_XMLSAXParser(pHandler, m_pSyntaxParser); 918 m_pXMLParser = new CFDE_XMLSAXParser(pHandler, m_pSyntaxParser);
927 } 919 }
928 return TRUE; 920 return TRUE;
929 } 921 }
930 922 FX_BOOL CFDE_XMLDoc::LoadXML(CFDE_XMLParser* pXMLParser) {
931 FX_BOOL CFDE_XMLDoc::LoadXML(IFDE_XMLParser* pXMLParser) { 923 if (pXMLParser == NULL) {
932 if (!pXMLParser)
933 return FALSE; 924 return FALSE;
934 925 }
935 Reset(TRUE); 926 Reset(TRUE);
936 m_pXMLParser = pXMLParser; 927 m_pXMLParser = pXMLParser;
937 return TRUE; 928 return m_pXMLParser != NULL;
938 } 929 }
939
940 int32_t CFDE_XMLDoc::DoLoad(IFX_Pause* pPause) { 930 int32_t CFDE_XMLDoc::DoLoad(IFX_Pause* pPause) {
941 if (m_iStatus >= 100) { 931 if (m_iStatus >= 100) {
942 return m_iStatus; 932 return m_iStatus;
943 } 933 }
934 ASSERT(m_pXMLParser != NULL);
944 return m_iStatus = m_pXMLParser->DoParser(pPause); 935 return m_iStatus = m_pXMLParser->DoParser(pPause);
945 } 936 }
946
947 void CFDE_XMLDoc::CloseXML() { 937 void CFDE_XMLDoc::CloseXML() {
948 ReleaseParser(); 938 ReleaseParser();
949 } 939 }
950 void CFDE_XMLDoc::SaveXMLNode(IFX_Stream* pXMLStream, CFDE_XMLNode* pINode) { 940 void CFDE_XMLDoc::SaveXMLNode(IFX_Stream* pXMLStream, CFDE_XMLNode* pINode) {
951 CFDE_XMLNode* pNode = (CFDE_XMLNode*)pINode; 941 CFDE_XMLNode* pNode = (CFDE_XMLNode*)pINode;
952 ASSERT(pXMLStream != NULL && pNode != NULL); 942 ASSERT(pXMLStream != NULL && pNode != NULL);
953 switch (pNode->GetType()) { 943 switch (pNode->GetType()) {
954 case FDE_XMLNODE_Instruction: { 944 case FDE_XMLNODE_Instruction: {
955 CFX_WideString ws; 945 CFX_WideString ws;
956 CFDE_XMLInstruction* pInstruction = (CFDE_XMLInstruction*)pNode; 946 CFDE_XMLInstruction* pInstruction = (CFDE_XMLInstruction*)pNode;
(...skipping 1126 matching lines...) Expand 10 before | Expand all | Expand 10 after
2083 m_BlockBuffer.DeleteTextChars(m_iDataLength - m_iEntityStart, FALSE); 2073 m_BlockBuffer.DeleteTextChars(m_iDataLength - m_iEntityStart, FALSE);
2084 m_pCurrentBlock = m_BlockBuffer.GetAvailableBlock(m_iIndexInBlock); 2074 m_pCurrentBlock = m_BlockBuffer.GetAvailableBlock(m_iIndexInBlock);
2085 m_iEntityStart = -1; 2075 m_iEntityStart = -1;
2086 } else { 2076 } else {
2087 if (m_iEntityStart < 0 && ch == L'&') { 2077 if (m_iEntityStart < 0 && ch == L'&') {
2088 m_iEntityStart = m_iDataLength - 1; 2078 m_iEntityStart = m_iDataLength - 1;
2089 } 2079 }
2090 } 2080 }
2091 m_pStart++; 2081 m_pStart++;
2092 } 2082 }
OLDNEW
« no previous file with comments | « xfa/fde/xml/fde_xml_imp.h ('k') | xfa/fxfa/app/xfa_ffdoc.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698