diff options
author | Dan Sinclair <dsinclair@chromium.org> | 2017-04-04 15:10:00 -0400 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-04-04 19:54:55 +0000 |
commit | 93bfc262074abf003ba4ab0ff1d9767d8dfa9a3d (patch) | |
tree | fd2c2c9d0a99923d397501f85e780498928a7e35 /xfa/fxfa/parser/cxfa_node.cpp | |
parent | b2fb20e0f8e7ea368c541d35ccb61506041f7ddd (diff) | |
download | pdfium-93bfc262074abf003ba4ab0ff1d9767d8dfa9a3d.tar.xz |
Cleanup CFDE_XMLCharData and CFDE_XMLText
This Cl switchs CFDE_XMLCharData to subclass CFDE_XMLText and cleans up
the code which was the same except for the accessor names.
Change-Id: I85ebf4f3f19f0d15be4dd77a71b89ca8083f4b1e
Reviewed-on: https://pdfium-review.googlesource.com/3672
Commit-Queue: dsinclair <dsinclair@chromium.org>
Reviewed-by: Nicolás Peña <npm@chromium.org>
Diffstat (limited to 'xfa/fxfa/parser/cxfa_node.cpp')
-rw-r--r-- | xfa/fxfa/parser/cxfa_node.cpp | 111 |
1 files changed, 55 insertions, 56 deletions
diff --git a/xfa/fxfa/parser/cxfa_node.cpp b/xfa/fxfa/parser/cxfa_node.cpp index 61107bf156..2079127dc9 100644 --- a/xfa/fxfa/parser/cxfa_node.cpp +++ b/xfa/fxfa/parser/cxfa_node.cpp @@ -517,22 +517,21 @@ CXFA_Node* CXFA_Node::Clone(bool bRecursive) { MergeAllData(pClone); pClone->UpdateNameHash(); if (IsNeedSavingXMLNode()) { - CFDE_XMLNode* pCloneXML = nullptr; + std::unique_ptr<CFDE_XMLNode> pCloneXML; if (IsAttributeInXML()) { CFX_WideString wsName; GetAttribute(XFA_ATTRIBUTE_Name, wsName, false); - CFDE_XMLElement* pCloneXMLElement = new CFDE_XMLElement(wsName); + auto pCloneXMLElement = pdfium::MakeUnique<CFDE_XMLElement>(wsName); CFX_WideStringC wsValue = GetCData(XFA_ATTRIBUTE_Value); if (!wsValue.IsEmpty()) { pCloneXMLElement->SetTextData(CFX_WideString(wsValue)); } - pCloneXML = pCloneXMLElement; - pCloneXMLElement = nullptr; + pCloneXML.reset(pCloneXMLElement.release()); pClone->SetEnum(XFA_ATTRIBUTE_Contains, XFA_ATTRIBUTEENUM_Unknown); } else { - pCloneXML = m_pXMLNode->Clone(false); + pCloneXML = m_pXMLNode->Clone(); } - pClone->SetXMLMappingNode(pCloneXML); + pClone->SetXMLMappingNode(pCloneXML.release()); pClone->SetFlag(XFA_NodeFlag_OwnXMLNode, false); } if (bRecursive) { @@ -1303,13 +1302,16 @@ void CXFA_Node::Script_NodeClass_LoadXML(CFXJSE_Arguments* pArguments) { pFakeRoot->SetCData(XFA_ATTRIBUTE_ContentType, CFX_WideString(wsContentType)); } - CFDE_XMLNode* pFakeXMLRoot = pFakeRoot->GetXMLMappingNode(); + + std::unique_ptr<CFDE_XMLNode> pFakeXMLRoot(pFakeRoot->GetXMLMappingNode()); if (!pFakeXMLRoot) { CFDE_XMLNode* pThisXMLRoot = GetXMLMappingNode(); - pFakeXMLRoot = pThisXMLRoot ? pThisXMLRoot->Clone(false) : nullptr; + pFakeXMLRoot = pThisXMLRoot ? pThisXMLRoot->Clone() : nullptr; + } + if (!pFakeXMLRoot) { + pFakeXMLRoot = + pdfium::MakeUnique<CFDE_XMLElement>(CFX_WideString(GetClassName())); } - if (!pFakeXMLRoot) - pFakeXMLRoot = new CFDE_XMLElement(CFX_WideString(GetClassName())); if (bIgnoreRoot) { CFDE_XMLNode* pXMLChild = pXMLNode->GetNodeItem(CFDE_XMLNode::FirstChild); @@ -1327,57 +1329,54 @@ void CXFA_Node::Script_NodeClass_LoadXML(CFXJSE_Arguments* pArguments) { } pFakeXMLRoot->InsertChildNode(pXMLNode); } - pParser->ConstructXFANode(pFakeRoot, pFakeXMLRoot); + pParser->ConstructXFANode(pFakeRoot, pFakeXMLRoot.get()); pFakeRoot = pParser->GetRootNode(); - if (pFakeRoot) { - if (bOverwrite) { - CXFA_Node* pChild = GetNodeItem(XFA_NODEITEM_FirstChild); - CXFA_Node* pNewChild = pFakeRoot->GetNodeItem(XFA_NODEITEM_FirstChild); - int32_t index = 0; - while (pNewChild) { - CXFA_Node* pItem = pNewChild->GetNodeItem(XFA_NODEITEM_NextSibling); - pFakeRoot->RemoveChild(pNewChild); - InsertChild(index++, pNewChild); - pNewChild->SetFlag(XFA_NodeFlag_Initialized, true); - pNewChild = pItem; - } - while (pChild) { - CXFA_Node* pItem = pChild->GetNodeItem(XFA_NODEITEM_NextSibling); - RemoveChild(pChild); - pFakeRoot->InsertChild(pChild); - pChild = pItem; - } - if (GetPacketID() == XFA_XDPPACKET_Form && - GetElementType() == XFA_Element::ExData) { - CFDE_XMLNode* pTempXMLNode = GetXMLMappingNode(); - SetXMLMappingNode(pFakeXMLRoot); - SetFlag(XFA_NodeFlag_OwnXMLNode, false); - if (pTempXMLNode && !pTempXMLNode->GetNodeItem(CFDE_XMLNode::Parent)) { - pFakeXMLRoot = pTempXMLNode; - } else { - pFakeXMLRoot = nullptr; - } - } - MoveBufferMapData(pFakeRoot, this, XFA_CalcData, true); - } else { - CXFA_Node* pChild = pFakeRoot->GetNodeItem(XFA_NODEITEM_FirstChild); - while (pChild) { - CXFA_Node* pItem = pChild->GetNodeItem(XFA_NODEITEM_NextSibling); - pFakeRoot->RemoveChild(pChild); - InsertChild(pChild); - pChild->SetFlag(XFA_NodeFlag_Initialized, true); - pChild = pItem; - } + if (!pFakeRoot) + return; + + if (bOverwrite) { + CXFA_Node* pChild = GetNodeItem(XFA_NODEITEM_FirstChild); + CXFA_Node* pNewChild = pFakeRoot->GetNodeItem(XFA_NODEITEM_FirstChild); + int32_t index = 0; + while (pNewChild) { + CXFA_Node* pItem = pNewChild->GetNodeItem(XFA_NODEITEM_NextSibling); + pFakeRoot->RemoveChild(pNewChild); + InsertChild(index++, pNewChild); + pNewChild->SetFlag(XFA_NodeFlag_Initialized, true); + pNewChild = pItem; + } + while (pChild) { + CXFA_Node* pItem = pChild->GetNodeItem(XFA_NODEITEM_NextSibling); + RemoveChild(pChild); + pFakeRoot->InsertChild(pChild); + pChild = pItem; } - if (pFakeXMLRoot) { - pFakeRoot->SetXMLMappingNode(pFakeXMLRoot); - pFakeRoot->SetFlag(XFA_NodeFlag_OwnXMLNode, false); + if (GetPacketID() == XFA_XDPPACKET_Form && + GetElementType() == XFA_Element::ExData) { + CFDE_XMLNode* pTempXMLNode = GetXMLMappingNode(); + SetXMLMappingNode(pFakeXMLRoot.release()); + SetFlag(XFA_NodeFlag_OwnXMLNode, false); + if (pTempXMLNode && !pTempXMLNode->GetNodeItem(CFDE_XMLNode::Parent)) + pFakeXMLRoot.reset(pTempXMLNode); + else + pFakeXMLRoot = nullptr; } - pFakeRoot->SetFlag(XFA_NodeFlag_HasRemovedChildren, false); + MoveBufferMapData(pFakeRoot, this, XFA_CalcData, true); } else { - delete pFakeXMLRoot; - pFakeXMLRoot = nullptr; + CXFA_Node* pChild = pFakeRoot->GetNodeItem(XFA_NODEITEM_FirstChild); + while (pChild) { + CXFA_Node* pItem = pChild->GetNodeItem(XFA_NODEITEM_NextSibling); + pFakeRoot->RemoveChild(pChild); + InsertChild(pChild); + pChild->SetFlag(XFA_NodeFlag_Initialized, true); + pChild = pItem; + } + } + if (pFakeXMLRoot) { + pFakeRoot->SetXMLMappingNode(pFakeXMLRoot.release()); + pFakeRoot->SetFlag(XFA_NodeFlag_OwnXMLNode, false); } + pFakeRoot->SetFlag(XFA_NodeFlag_HasRemovedChildren, false); } void CXFA_Node::Script_NodeClass_SaveFilteredXML(CFXJSE_Arguments* pArguments) { |