diff options
author | Ryan Harrison <rharrison@chromium.org> | 2018-09-18 17:50:35 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2018-09-18 17:50:35 +0000 |
commit | 7ea611fb82308b4b8f9dc150a9d79334435c53b6 (patch) | |
tree | de7b509e8d036d47c6cf3e49394f98ca198bfd92 /fxjs | |
parent | 6fc8d877d7450905623c6abb1094ab99f5bd80cb (diff) | |
download | pdfium-7ea611fb82308b4b8f9dc150a9d79334435c53b6.tar.xz |
Transfer ownership of nodes to top-level XML doc
For XFA, XML nodes are owned by the XML doc that they were created by,
but references to them are stored elsewhere. For a PDF document there
is one top-level XML document created and retained when the initial
XFA XML is parsed. Another can be created if loadXML is called by
JS. In the existing code the XML doc that owns the newly created nodes
is local to loadXML. So the nodes are destroyed right after putting
refernces to them into the main XFA data structures.
This CL adds in a method to transfer ownership of the XML nodes from
one doc to another, and uses it to correctly retain the newly created
nodes, by having them owned by the top-level XML doc.
BUG=chromium:884664
Change-Id: Id29b4edbfe44aefb9713328e4e217e830f7e9e14
Reviewed-on: https://pdfium-review.googlesource.com/42690
Reviewed-by: Henrique Nakashima <hnakashima@chromium.org>
Commit-Queue: Ryan Harrison <rharrison@chromium.org>
Diffstat (limited to 'fxjs')
-rw-r--r-- | fxjs/xfa/cjx_node.cpp | 19 |
1 files changed, 7 insertions, 12 deletions
diff --git a/fxjs/xfa/cjx_node.cpp b/fxjs/xfa/cjx_node.cpp index 8876628c3b..49cd041c88 100644 --- a/fxjs/xfa/cjx_node.cpp +++ b/fxjs/xfa/cjx_node.cpp @@ -221,6 +221,10 @@ CJS_Result CJX_Node::loadXML(CFX_V8* runtime, if (!pXMLNode) return CJS_Result::Success(); + CFX_XMLDocument* top_xml_doc = + GetXFANode()->GetDocument()->GetNotify()->GetHDOC()->GetXMLDocument(); + top_xml_doc->AppendNodesFrom(pParser->GetXMLDoc().get()); + if (bIgnoreRoot && (pXMLNode->GetType() != FX_XMLNODE_Element || XFA_RecognizeRichText(static_cast<CFX_XMLElement*>(pXMLNode)))) { @@ -239,19 +243,10 @@ CJS_Result CJX_Node::loadXML(CFX_V8* runtime, CFX_XMLNode* pThisXMLRoot = GetXFANode()->GetXMLMappingNode(); CFX_XMLNode* clone; if (pThisXMLRoot) { - clone = pThisXMLRoot->Clone(GetXFANode() - ->GetDocument() - ->GetNotify() - ->GetHDOC() - ->GetXMLDocument()); + clone = pThisXMLRoot->Clone(top_xml_doc); } else { - clone = GetXFANode() - ->GetDocument() - ->GetNotify() - ->GetHDOC() - ->GetXMLDocument() - ->CreateNode<CFX_XMLElement>( - WideString(GetXFANode()->GetClassName())); + clone = top_xml_doc->CreateNode<CFX_XMLElement>( + WideString(GetXFANode()->GetClassName())); } pFakeXMLRoot = clone; } |