summaryrefslogtreecommitdiff
path: root/xfa
diff options
context:
space:
mode:
Diffstat (limited to 'xfa')
-rw-r--r--xfa/fxfa/cxfa_ffdoc.cpp40
-rw-r--r--xfa/fxfa/cxfa_ffdoc.h9
-rw-r--r--xfa/fxfa/parser/cxfa_document.cpp1
-rw-r--r--xfa/fxfa/parser/cxfa_document_parser.cpp45
-rw-r--r--xfa/fxfa/parser/cxfa_document_parser.h37
5 files changed, 33 insertions, 99 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);
}
diff --git a/xfa/fxfa/cxfa_ffdoc.h b/xfa/fxfa/cxfa_ffdoc.h
index 59b3f57cac..fd90471f23 100644
--- a/xfa/fxfa/cxfa_ffdoc.h
+++ b/xfa/fxfa/cxfa_ffdoc.h
@@ -10,10 +10,11 @@
#include <map>
#include <memory>
+#include "core/fxcrt/fx_stream.h"
#include "core/fxcrt/unowned_ptr.h"
+#include "core/fxcrt/xml/cfx_xmlnode.h"
#include "xfa/fxfa/fxfa.h"
#include "xfa/fxfa/parser/cxfa_document.h"
-#include "xfa/fxfa/parser/cxfa_document_parser.h"
class CFGAS_PDFFontMgr;
class CFX_ChecksumContext;
@@ -62,10 +63,11 @@ class CXFA_FFDoc {
CXFA_FFDocView* CreateDocView();
+ bool ParseDoc();
bool OpenDoc(CPDF_Document* pPDFDoc);
void CloseDoc();
- CXFA_Document* GetXFADoc() const { return m_pDocumentParser->GetDocument(); }
+ CXFA_Document* GetXFADoc() const { return m_pDocument.get(); }
CXFA_FFApp* GetApp() const { return m_pApp.Get(); }
CPDF_Document* GetPDFDoc() const { return m_pPDFDoc.Get(); }
CXFA_FFDocView* GetDocView(CXFA_LayoutProcessor* pLayout);
@@ -82,7 +84,8 @@ class CXFA_FFDoc {
private:
UnownedPtr<IXFA_DocEnvironment> const m_pDocEnvironment;
- std::unique_ptr<CXFA_DocumentParser> m_pDocumentParser;
+ std::unique_ptr<CFX_XMLNode> m_pXMLRoot;
+ std::unique_ptr<CXFA_Document> m_pDocument;
RetainPtr<IFX_SeekableStream> m_pStream;
UnownedPtr<CXFA_FFApp> const m_pApp;
std::unique_ptr<CXFA_FFNotify> m_pNotify;
diff --git a/xfa/fxfa/parser/cxfa_document.cpp b/xfa/fxfa/parser/cxfa_document.cpp
index d23e2bc2ce..cdfb7b45a6 100644
--- a/xfa/fxfa/parser/cxfa_document.cpp
+++ b/xfa/fxfa/parser/cxfa_document.cpp
@@ -20,7 +20,6 @@
#include "xfa/fxfa/parser/cscript_signaturepseudomodel.h"
#include "xfa/fxfa/parser/cxfa_bind.h"
#include "xfa/fxfa/parser/cxfa_datagroup.h"
-#include "xfa/fxfa/parser/cxfa_document_parser.h"
#include "xfa/fxfa/parser/cxfa_exdata.h"
#include "xfa/fxfa/parser/cxfa_form.h"
#include "xfa/fxfa/parser/cxfa_image.h"
diff --git a/xfa/fxfa/parser/cxfa_document_parser.cpp b/xfa/fxfa/parser/cxfa_document_parser.cpp
deleted file mode 100644
index 52b5e333c0..0000000000
--- a/xfa/fxfa/parser/cxfa_document_parser.cpp
+++ /dev/null
@@ -1,45 +0,0 @@
-// Copyright 2016 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#include "xfa/fxfa/parser/cxfa_document_parser.h"
-
-#include "core/fxcrt/xml/cfx_xmldoc.h"
-#include "third_party/base/ptr_util.h"
-#include "xfa/fxfa/fxfa.h"
-#include "xfa/fxfa/parser/cxfa_document.h"
-
-CXFA_DocumentParser::CXFA_DocumentParser(CXFA_FFNotify* pNotify)
- : m_pNotify(pNotify) {}
-
-CXFA_DocumentParser::~CXFA_DocumentParser() {
- m_pDocument->ReleaseXMLNodesIfNeeded();
-}
-
-bool CXFA_DocumentParser::Parse(const RetainPtr<IFX_SeekableStream>& pStream,
- XFA_PacketType ePacketID) {
- m_pDocument = pdfium::MakeUnique<CXFA_Document>(GetNotify());
-
- // 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(pStream, ePacketID))
- return false;
-
- m_pXMLRoot = parser.GetXMLRoot();
-
- m_pDocument->SetRoot(parser.GetRootNode());
- return true;
-}
-
-CXFA_FFNotify* CXFA_DocumentParser::GetNotify() const {
- return m_pNotify.Get();
-}
-
-CXFA_Document* CXFA_DocumentParser::GetDocument() const {
- return m_pDocument.get();
-}
diff --git a/xfa/fxfa/parser/cxfa_document_parser.h b/xfa/fxfa/parser/cxfa_document_parser.h
deleted file mode 100644
index 1075f48ef4..0000000000
--- a/xfa/fxfa/parser/cxfa_document_parser.h
+++ /dev/null
@@ -1,37 +0,0 @@
-// Copyright 2016 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#ifndef XFA_FXFA_PARSER_CXFA_DOCUMENT_PARSER_H_
-#define XFA_FXFA_PARSER_CXFA_DOCUMENT_PARSER_H_
-
-#include <memory>
-
-#include "xfa/fxfa/parser/cxfa_simple_parser.h"
-
-class CFX_XMLDoc;
-class CXFA_Document;
-class CXFA_FFNotify;
-class CXFA_Notify;
-class IFX_SeekableStream;
-
-class CXFA_DocumentParser {
- public:
- explicit CXFA_DocumentParser(CXFA_FFNotify* pNotify);
- ~CXFA_DocumentParser();
-
- bool Parse(const RetainPtr<IFX_SeekableStream>& pStream,
- XFA_PacketType ePacketID);
-
- CXFA_FFNotify* GetNotify() const;
- CXFA_Document* GetDocument() const;
-
- private:
- UnownedPtr<CXFA_FFNotify> const m_pNotify;
- std::unique_ptr<CFX_XMLNode> m_pXMLRoot;
- std::unique_ptr<CXFA_Document> m_pDocument;
-};
-
-#endif // XFA_FXFA_PARSER_CXFA_DOCUMENT_PARSER_H_