| OLD | NEW |
| 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/fxfa/parser/xfa_object.h" | 7 #include "xfa/fxfa/parser/xfa_object.h" |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 | 10 |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 CXFA_Node::~CXFA_Node() { | 113 CXFA_Node::~CXFA_Node() { |
| 114 ASSERT(m_pParent == NULL); | 114 ASSERT(m_pParent == NULL); |
| 115 RemoveMapModuleKey(); | 115 RemoveMapModuleKey(); |
| 116 CXFA_Node *pNext, *pNode = m_pChild; | 116 CXFA_Node *pNext, *pNode = m_pChild; |
| 117 while (pNode) { | 117 while (pNode) { |
| 118 pNext = pNode->m_pNext; | 118 pNext = pNode->m_pNext; |
| 119 pNode->m_pParent = NULL; | 119 pNode->m_pParent = NULL; |
| 120 delete pNode; | 120 delete pNode; |
| 121 pNode = pNext; | 121 pNode = pNext; |
| 122 } | 122 } |
| 123 if (m_pXMLNode && HasFlag(XFA_NODEFLAG_OwnXMLNode)) { | 123 if (m_pXMLNode && HasFlag(XFA_NODEFLAG_OwnXMLNode)) |
| 124 m_pXMLNode->Release(); | 124 delete m_pXMLNode; |
| 125 } | |
| 126 } | 125 } |
| 126 |
| 127 CXFA_Node* CXFA_Node::Clone(FX_BOOL bRecursive) { | 127 CXFA_Node* CXFA_Node::Clone(FX_BOOL bRecursive) { |
| 128 CXFA_Document* pFactory = m_pDocument->GetParser()->GetFactory(); | 128 CXFA_Document* pFactory = m_pDocument->GetParser()->GetFactory(); |
| 129 CXFA_Node* pClone = pFactory->CreateNode(m_ePacket, m_eNodeClass); | 129 CXFA_Node* pClone = pFactory->CreateNode(m_ePacket, m_eNodeClass); |
| 130 if (!pClone) { | 130 if (!pClone) { |
| 131 return NULL; | 131 return NULL; |
| 132 } | 132 } |
| 133 MergeAllData(pClone); | 133 MergeAllData(pClone); |
| 134 pClone->UpdateNameHash(); | 134 pClone->UpdateNameHash(); |
| 135 if (IsNeedSavingXMLNode()) { | 135 if (IsNeedSavingXMLNode()) { |
| 136 CFDE_XMLNode* pCloneXML = NULL; | 136 CFDE_XMLNode* pCloneXML = NULL; |
| (...skipping 818 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 955 if (wsExpression.IsEmpty()) { | 955 if (wsExpression.IsEmpty()) { |
| 956 return; | 956 return; |
| 957 } | 957 } |
| 958 } | 958 } |
| 959 if (iLength >= 2) { | 959 if (iLength >= 2) { |
| 960 bIgnoreRoot = pArguments->GetInt32(1) == 0 ? FALSE : TRUE; | 960 bIgnoreRoot = pArguments->GetInt32(1) == 0 ? FALSE : TRUE; |
| 961 } | 961 } |
| 962 if (iLength >= 3) { | 962 if (iLength >= 3) { |
| 963 bOverwrite = pArguments->GetInt32(2) == 0 ? FALSE : TRUE; | 963 bOverwrite = pArguments->GetInt32(2) == 0 ? FALSE : TRUE; |
| 964 } | 964 } |
| 965 IXFA_Parser* pParser = IXFA_Parser::Create(m_pDocument); | 965 std::unique_ptr<IXFA_Parser> pParser(IXFA_Parser::Create(m_pDocument)); |
| 966 if (!pParser) { | |
| 967 return; | |
| 968 } | |
| 969 CFDE_XMLNode* pXMLNode = NULL; | 966 CFDE_XMLNode* pXMLNode = NULL; |
| 970 int32_t iParserStatus = pParser->ParseXMLData(wsExpression, pXMLNode, NULL); | 967 int32_t iParserStatus = pParser->ParseXMLData(wsExpression, pXMLNode, NULL); |
| 971 if (iParserStatus != XFA_PARSESTATUS_Done || !pXMLNode) { | 968 if (iParserStatus != XFA_PARSESTATUS_Done || !pXMLNode) |
| 972 pParser->Release(); | |
| 973 pParser = NULL; | |
| 974 return; | 969 return; |
| 975 } | 970 |
| 976 if (bIgnoreRoot && | 971 if (bIgnoreRoot && |
| 977 (pXMLNode->GetType() != FDE_XMLNODE_Element || | 972 (pXMLNode->GetType() != FDE_XMLNODE_Element || |
| 978 XFA_RecognizeRichText(static_cast<CFDE_XMLElement*>(pXMLNode)))) { | 973 XFA_RecognizeRichText(static_cast<CFDE_XMLElement*>(pXMLNode)))) { |
| 979 bIgnoreRoot = FALSE; | 974 bIgnoreRoot = FALSE; |
| 980 } | 975 } |
| 981 CXFA_Node* pFakeRoot = Clone(FALSE); | 976 CXFA_Node* pFakeRoot = Clone(FALSE); |
| 982 CFX_WideStringC wsContentType = GetCData(XFA_ATTRIBUTE_ContentType); | 977 CFX_WideStringC wsContentType = GetCData(XFA_ATTRIBUTE_ContentType); |
| 983 if (!wsContentType.IsEmpty()) { | 978 if (!wsContentType.IsEmpty()) { |
| 984 pFakeRoot->SetCData(XFA_ATTRIBUTE_ContentType, | 979 pFakeRoot->SetCData(XFA_ATTRIBUTE_ContentType, |
| 985 CFX_WideString(wsContentType)); | 980 CFX_WideString(wsContentType)); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1052 pChild->SetFlag(XFA_NODEFLAG_Initialized, true); | 1047 pChild->SetFlag(XFA_NODEFLAG_Initialized, true); |
| 1053 pChild = pItem; | 1048 pChild = pItem; |
| 1054 } | 1049 } |
| 1055 } | 1050 } |
| 1056 if (pFakeXMLRoot) { | 1051 if (pFakeXMLRoot) { |
| 1057 pFakeRoot->SetXMLMappingNode(pFakeXMLRoot); | 1052 pFakeRoot->SetXMLMappingNode(pFakeXMLRoot); |
| 1058 pFakeRoot->SetFlag(XFA_NODEFLAG_OwnXMLNode, false); | 1053 pFakeRoot->SetFlag(XFA_NODEFLAG_OwnXMLNode, false); |
| 1059 } | 1054 } |
| 1060 pFakeRoot->SetFlag(XFA_NODEFLAG_HasRemoved, false); | 1055 pFakeRoot->SetFlag(XFA_NODEFLAG_HasRemoved, false); |
| 1061 } else { | 1056 } else { |
| 1062 if (pFakeXMLRoot) { | 1057 delete pFakeXMLRoot; |
| 1063 pFakeXMLRoot->Release(); | 1058 pFakeXMLRoot = nullptr; |
| 1064 pFakeXMLRoot = NULL; | |
| 1065 } | |
| 1066 } | 1059 } |
| 1067 pParser->Release(); | |
| 1068 pParser = NULL; | |
| 1069 } | 1060 } |
| 1061 |
| 1070 void CXFA_Node::Script_NodeClass_SaveFilteredXML(CFXJSE_Arguments* pArguments) { | 1062 void CXFA_Node::Script_NodeClass_SaveFilteredXML(CFXJSE_Arguments* pArguments) { |
| 1071 } | 1063 } |
| 1072 | 1064 |
| 1073 void CXFA_Node::Script_NodeClass_SaveXML(CFXJSE_Arguments* pArguments) { | 1065 void CXFA_Node::Script_NodeClass_SaveXML(CFXJSE_Arguments* pArguments) { |
| 1074 int32_t iLength = pArguments->GetLength(); | 1066 int32_t iLength = pArguments->GetLength(); |
| 1075 if (iLength < 0 || iLength > 1) { | 1067 if (iLength < 0 || iLength > 1) { |
| 1076 ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"saveXML"); | 1068 ThrowScriptErrorMessage(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"saveXML"); |
| 1077 return; | 1069 return; |
| 1078 } | 1070 } |
| 1079 FX_BOOL bPrettyMode = FALSE; | 1071 FX_BOOL bPrettyMode = FALSE; |
| (...skipping 4285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5365 return m_pAttachNode->InsertChild(pNewNode, pBeforeNode); | 5357 return m_pAttachNode->InsertChild(pNewNode, pBeforeNode); |
| 5366 } | 5358 } |
| 5367 FX_BOOL CXFA_AttachNodeList::Remove(CXFA_Node* pNode) { | 5359 FX_BOOL CXFA_AttachNodeList::Remove(CXFA_Node* pNode) { |
| 5368 return m_pAttachNode->RemoveChild(pNode); | 5360 return m_pAttachNode->RemoveChild(pNode); |
| 5369 } | 5361 } |
| 5370 CXFA_Node* CXFA_AttachNodeList::Item(int32_t iIndex) { | 5362 CXFA_Node* CXFA_AttachNodeList::Item(int32_t iIndex) { |
| 5371 return m_pAttachNode->GetChild( | 5363 return m_pAttachNode->GetChild( |
| 5372 iIndex, XFA_ELEMENT_UNKNOWN, | 5364 iIndex, XFA_ELEMENT_UNKNOWN, |
| 5373 m_pAttachNode->GetClassID() == XFA_ELEMENT_Subform); | 5365 m_pAttachNode->GetClassID() == XFA_ELEMENT_Subform); |
| 5374 } | 5366 } |
| OLD | NEW |