summaryrefslogtreecommitdiff
path: root/xfa/fxfa/cxfa_ffdoc.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'xfa/fxfa/cxfa_ffdoc.cpp')
-rw-r--r--xfa/fxfa/cxfa_ffdoc.cpp40
1 files changed, 27 insertions, 13 deletions
diff --git a/xfa/fxfa/cxfa_ffdoc.cpp b/xfa/fxfa/cxfa_ffdoc.cpp
index 4c6ae67de7..c0bd7816fc 100644
--- a/xfa/fxfa/cxfa_ffdoc.cpp
+++ b/xfa/fxfa/cxfa_ffdoc.cpp
@@ -35,6 +35,7 @@
#include "xfa/fxfa/parser/cxfa_document.h"
#include "xfa/fxfa/parser/cxfa_dynamicrender.h"
#include "xfa/fxfa/parser/cxfa_node.h"
+#include "xfa/fxfa/parser/cxfa_simple_parser.h"
namespace {
@@ -165,13 +166,14 @@ CXFA_FFDoc::~CXFA_FFDoc() {
}
bool CXFA_FFDoc::Load() {
- m_pNotify = pdfium::MakeUnique<CXFA_FFNotify>(this);
- m_pDocumentParser = pdfium::MakeUnique<CXFA_DocumentParser>(m_pNotify.get());
- if (!m_pDocumentParser->Parse(m_pStream, XFA_PacketType::Xdp))
- return false;
if (!m_pPDFDoc)
return false;
+ m_pNotify = pdfium::MakeUnique<CXFA_FFNotify>(this);
+ m_pDocument = pdfium::MakeUnique<CXFA_Document>(m_pNotify.get());
+ if (!ParseDoc())
+ return false;
+
// At this point we've got an XFA document and we want to always return
// true to signify the load succeeded.
@@ -179,8 +181,7 @@ bool CXFA_FFDoc::Load() {
GetPDFDoc(), GetApp()->GetFDEFontMgr());
m_FormType = FormType::kXFAForeground;
- CXFA_Node* pConfig = ToNode(
- m_pDocumentParser->GetDocument()->GetXFAObject(XFA_HASHCODE_Config));
+ CXFA_Node* pConfig = ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Config));
if (!pConfig)
return true;
@@ -207,6 +208,19 @@ bool CXFA_FFDoc::Load() {
return true;
}
+bool CXFA_FFDoc::ParseDoc() {
+ // Note, we don't pass the document into the constructor as currently that
+ // triggers different behaviour in the parser.
+ CXFA_SimpleParser parser;
+ parser.SetFactory(m_pDocument.get());
+ if (!parser.Parse(m_pStream, XFA_PacketType::Xdp))
+ return false;
+
+ m_pXMLRoot = parser.GetXMLRoot();
+ m_pDocument->SetRoot(parser.GetRootNode());
+ return true;
+}
+
bool XFA_GetPDFContentsFromPDFXML(CFX_XMLNode* pPDFElement,
uint8_t*& pByteBuffer,
int32_t& iBufferSize) {
@@ -320,12 +334,13 @@ void CXFA_FFDoc::CloseDoc() {
m_DocView->RunDocClose();
m_DocView.reset();
}
- CXFA_Document* doc =
- m_pDocumentParser ? m_pDocumentParser->GetDocument() : nullptr;
- if (doc)
- doc->ClearLayoutData();
+ if (m_pDocument) {
+ m_pDocument->ReleaseXMLNodesIfNeeded();
+ m_pDocument->ClearLayoutData();
+ }
- m_pDocumentParser.reset();
+ m_pDocument.reset();
+ m_pXMLRoot.reset();
m_pNotify.reset();
m_pPDFFontMgr.reset();
m_HashToDibDpiMap.clear();
@@ -399,7 +414,6 @@ bool CXFA_FFDoc::SavePackage(CXFA_Node* pNode,
bool CXFA_FFDoc::ImportData(const RetainPtr<IFX_SeekableStream>& pStream,
bool bXDP) {
- auto importer =
- pdfium::MakeUnique<CXFA_DataImporter>(m_pDocumentParser->GetDocument());
+ auto importer = pdfium::MakeUnique<CXFA_DataImporter>(m_pDocument.get());
return importer->ImportData(pStream);
}