summaryrefslogtreecommitdiff
path: root/xfa/fxfa/parser/xfa_document_datamerger_imp.cpp
diff options
context:
space:
mode:
authorDan Sinclair <dsinclair@chromium.org>2018-02-15 18:12:29 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-02-15 18:12:29 +0000
commite40678ed8a22ecd57421877af39cf7f281f618c4 (patch)
tree50bbf114829ad3b4852b3739f65c6385091c4ba0 /xfa/fxfa/parser/xfa_document_datamerger_imp.cpp
parent625e6fec9ddd1d023116f7bd22d2192ef9bc49c8 (diff)
downloadpdfium-e40678ed8a22ecd57421877af39cf7f281f618c4.tar.xz
Make the CFX_XMLNode a MaybeOwned pointer
This CL removes the HasOwnXML flag from the CXFA_Node objects and instead uses a MaybeOwned pointer to keep track of the XML nodes. Change-Id: Ie678258247ec21ecb15c639647b189e140586d25 Reviewed-on: https://pdfium-review.googlesource.com/26811 Reviewed-by: Tom Sepez <tsepez@chromium.org> Commit-Queue: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'xfa/fxfa/parser/xfa_document_datamerger_imp.cpp')
-rw-r--r--xfa/fxfa/parser/xfa_document_datamerger_imp.cpp22
1 files changed, 13 insertions, 9 deletions
diff --git a/xfa/fxfa/parser/xfa_document_datamerger_imp.cpp b/xfa/fxfa/parser/xfa_document_datamerger_imp.cpp
index 56508634c8..b7cab02b3d 100644
--- a/xfa/fxfa/parser/xfa_document_datamerger_imp.cpp
+++ b/xfa/fxfa/parser/xfa_document_datamerger_imp.cpp
@@ -7,6 +7,7 @@
#include "xfa/fxfa/parser/xfa_document_datamerger_imp.h"
#include <map>
+#include <utility>
#include <vector>
#include "core/fxcrt/fx_extension.h"
@@ -1368,17 +1369,21 @@ CXFA_Node* CXFA_Document::GetNotBindNode(
void CXFA_Document::DoDataMerge() {
CXFA_Node* pDatasetsRoot = ToNode(GetXFAObject(XFA_HASHCODE_Datasets));
if (!pDatasetsRoot) {
- CFX_XMLElement* pDatasetsXMLNode = new CFX_XMLElement(L"xfa:datasets");
+ // Ownership will be passed in the AppendChild below to the XML tree.
+ auto pDatasetsXMLNode = pdfium::MakeUnique<CFX_XMLElement>(L"xfa:datasets");
pDatasetsXMLNode->SetString(L"xmlns:xfa",
L"http://www.xfa.org/schema/xfa-data/1.0/");
pDatasetsRoot =
CreateNode(XFA_PacketType::Datasets, XFA_Element::DataModel);
pDatasetsRoot->JSObject()->SetCData(XFA_Attribute::Name, L"datasets", false,
false);
- m_pRootNode->GetXMLMappingNode()->AppendChild(pDatasetsXMLNode);
+
+ CFX_XMLElement* ref = pDatasetsXMLNode.get();
+ m_pRootNode->GetXMLMappingNode()->AppendChild(pDatasetsXMLNode.release());
m_pRootNode->InsertChild(pDatasetsRoot, nullptr);
- pDatasetsRoot->SetXMLMappingNode(pDatasetsXMLNode);
+ pDatasetsRoot->SetXMLMappingNode(ref);
}
+
CXFA_Node *pDataRoot = nullptr, *pDDRoot = nullptr;
WideString wsDatasetsURI =
pDatasetsRoot->JSObject()->TryNamespace().value_or(WideString());
@@ -1407,11 +1412,10 @@ void CXFA_Document::DoDataMerge() {
}
if (!pDataRoot) {
- CFX_XMLElement* pDataRootXMLNode = new CFX_XMLElement(L"xfa:data");
pDataRoot = CreateNode(XFA_PacketType::Datasets, XFA_Element::DataGroup);
pDataRoot->JSObject()->SetCData(XFA_Attribute::Name, L"data", false, false);
- pDataRoot->SetXMLMappingNode(pDataRootXMLNode);
- pDataRoot->SetFlag(XFA_NodeFlag_OwnXMLNode);
+ pDataRoot->SetXMLMappingNode(
+ pdfium::MakeUnique<CFX_XMLElement>(L"xfa:data"));
pDatasetsRoot->InsertChild(pDataRoot, nullptr);
}
@@ -1460,14 +1464,14 @@ void CXFA_Document::DoDataMerge() {
WideString wsFormName =
pSubformSetNode->JSObject()->GetCData(XFA_Attribute::Name);
WideString wsDataTopLevelName(wsFormName.IsEmpty() ? L"form" : wsFormName);
- CFX_XMLElement* pDataTopLevelXMLNode =
- new CFX_XMLElement(wsDataTopLevelName);
pDataTopLevel = static_cast<CXFA_DataGroup*>(
CreateNode(XFA_PacketType::Datasets, XFA_Element::DataGroup));
pDataTopLevel->JSObject()->SetCData(XFA_Attribute::Name, wsDataTopLevelName,
false, false);
- pDataTopLevel->SetXMLMappingNode(pDataTopLevelXMLNode);
+ pDataTopLevel->SetXMLMappingNode(
+ pdfium::MakeUnique<CFX_XMLElement>(wsDataTopLevelName));
+
CXFA_Node* pBeforeNode = pDataRoot->GetFirstChild();
pDataRoot->InsertChild(pDataTopLevel, pBeforeNode);
}