summaryrefslogtreecommitdiff
path: root/xfa/fxfa/cxfa_ffdoc.cpp
diff options
context:
space:
mode:
authorDan Sinclair <dsinclair@chromium.org>2018-04-12 13:23:08 +0000
committerChromium commit bot <commit-bot@chromium.org>2018-04-12 13:23:08 +0000
commit0cad1163af80cfcc987a3d431fbd05fa3e09151b (patch)
treeef67e8051351985ed66e467683084e8f88b8e24f /xfa/fxfa/cxfa_ffdoc.cpp
parent2efb11c89ee200473f5675ba3d3a946d5606e813 (diff)
downloadpdfium-0cad1163af80cfcc987a3d431fbd05fa3e09151b.tar.xz
Fold CXFA_DocumentParser into CXFA_FFDoc
The CXFA_DocumentParser is a thin wrapper around CXFA_SimpleParser. This CL folds CXFA_DocumentParser into a ParseDoc method of CXFA_FFDoc. Change-Id: I7e7073899436f0435c4ebfd548241ae842a2a276 Reviewed-on: https://pdfium-review.googlesource.com/30213 Reviewed-by: Henrique Nakashima <hnakashima@chromium.org> Commit-Queue: dsinclair <dsinclair@chromium.org>
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);
}