From 741d5e1e0a64b85717ad054d3fd8807c66845a50 Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Mon, 9 Apr 2018 19:08:25 +0000 Subject: Merge CXFA_FFDoc::{Start|Do|Stop}Load methods The StartLoad, DoLoad and StopLoad methods are called in sequence from the CPDFXFA_Context. This CL merges the three methods into a single Load method. Change-Id: I7135502354fb4c64784c89fa39b74fc58c76b683 Reviewed-on: https://pdfium-review.googlesource.com/29990 Reviewed-by: Henrique Nakashima Commit-Queue: dsinclair --- fpdfsdk/fpdfxfa/cpdfxfa_context.cpp | 5 +-- xfa/fxfa/cxfa_ffdoc.cpp | 79 ++++++++++++++++++------------------- xfa/fxfa/cxfa_ffdoc.h | 4 +- 3 files changed, 42 insertions(+), 46 deletions(-) diff --git a/fpdfsdk/fpdfxfa/cpdfxfa_context.cpp b/fpdfsdk/fpdfxfa/cpdfxfa_context.cpp index 5553025371..0ba7f31995 100644 --- a/fpdfsdk/fpdfxfa/cpdfxfa_context.cpp +++ b/fpdfsdk/fpdfxfa/cpdfxfa_context.cpp @@ -96,14 +96,13 @@ bool CPDFXFA_Context::LoadXFADoc() { return false; } - m_pXFADoc->StartLoad(); - int iStatus = m_pXFADoc->DoLoad(); + int iStatus = m_pXFADoc->Load(); if (iStatus != XFA_PARSESTATUS_Done) { CloseXFADoc(); SetLastError(FPDF_ERR_XFALOAD); return false; } - m_pXFADoc->StopLoad(); + m_pXFADoc->GetXFADoc()->InitScriptContext(GetCJSRuntime()); if (m_pXFADoc->GetFormType() == FormType::kXFAFull) diff --git a/xfa/fxfa/cxfa_ffdoc.cpp b/xfa/fxfa/cxfa_ffdoc.cpp index 52ad5f692d..ad7bbd9531 100644 --- a/xfa/fxfa/cxfa_ffdoc.cpp +++ b/xfa/fxfa/cxfa_ffdoc.cpp @@ -165,10 +165,47 @@ CXFA_FFDoc::~CXFA_FFDoc() { CloseDoc(); } -int32_t CXFA_FFDoc::StartLoad() { +int32_t CXFA_FFDoc::Load() { m_pNotify = pdfium::MakeUnique(this); m_pDocumentParser = pdfium::MakeUnique(m_pNotify.get()); - return m_pDocumentParser->StartParse(m_pStream, XFA_PacketType::Xdp); + m_pDocumentParser->StartParse(m_pStream, XFA_PacketType::Xdp); + + int32_t iStatus = m_pDocumentParser->DoParse(); + if (iStatus != XFA_PARSESTATUS_Done) + return iStatus; + if (!m_pPDFDoc) + return XFA_PARSESTATUS_SyntaxErr; + + m_pPDFFontMgr = pdfium::MakeUnique( + GetPDFDoc(), GetApp()->GetFDEFontMgr()); + + m_FormType = FormType::kXFAForeground; + CXFA_Node* pConfig = ToNode( + m_pDocumentParser->GetDocument()->GetXFAObject(XFA_HASHCODE_Config)); + if (!pConfig) + return iStatus; + + CXFA_Acrobat* pAcrobat = + pConfig->GetFirstChildByClass(XFA_Element::Acrobat); + if (!pAcrobat) + return iStatus; + + CXFA_Acrobat7* pAcrobat7 = + pAcrobat->GetFirstChildByClass(XFA_Element::Acrobat7); + if (!pAcrobat7) + return iStatus; + + CXFA_DynamicRender* pDynamicRender = + pAcrobat7->GetFirstChildByClass( + XFA_Element::DynamicRender); + if (!pDynamicRender) + return iStatus; + + WideString wsType = pDynamicRender->JSObject()->GetContent(false); + if (wsType == L"required") + m_FormType = FormType::kXFAFull; + + return iStatus; } bool XFA_GetPDFContentsFromPDFXML(CFX_XMLNode* pPDFElement, @@ -229,44 +266,6 @@ void XFA_XPDPacket_MergeRootNode(CXFA_Node* pOriginRoot, CXFA_Node* pNewRoot) { } } -int32_t CXFA_FFDoc::DoLoad() { - int32_t iStatus = m_pDocumentParser->DoParse(); - if (iStatus == XFA_PARSESTATUS_Done && !m_pPDFDoc) - return XFA_PARSESTATUS_SyntaxErr; - return iStatus; -} - -void CXFA_FFDoc::StopLoad() { - m_pPDFFontMgr = pdfium::MakeUnique( - GetPDFDoc(), GetApp()->GetFDEFontMgr()); - - m_FormType = FormType::kXFAForeground; - CXFA_Node* pConfig = ToNode( - m_pDocumentParser->GetDocument()->GetXFAObject(XFA_HASHCODE_Config)); - if (!pConfig) - return; - - CXFA_Acrobat* pAcrobat = - pConfig->GetFirstChildByClass(XFA_Element::Acrobat); - if (!pAcrobat) - return; - - CXFA_Acrobat7* pAcrobat7 = - pAcrobat->GetFirstChildByClass(XFA_Element::Acrobat7); - if (!pAcrobat7) - return; - - CXFA_DynamicRender* pDynamicRender = - pAcrobat7->GetFirstChildByClass( - XFA_Element::DynamicRender); - if (!pDynamicRender) - return; - - WideString wsType = pDynamicRender->JSObject()->GetContent(false); - if (wsType == L"required") - m_FormType = FormType::kXFAFull; -} - CXFA_FFDocView* CXFA_FFDoc::CreateDocView() { if (!m_DocView) m_DocView = pdfium::MakeUnique(this); diff --git a/xfa/fxfa/cxfa_ffdoc.h b/xfa/fxfa/cxfa_ffdoc.h index ffa8bcc1d2..14bae5973a 100644 --- a/xfa/fxfa/cxfa_ffdoc.h +++ b/xfa/fxfa/cxfa_ffdoc.h @@ -58,9 +58,7 @@ class CXFA_FFDoc { } FormType GetFormType() const { return m_FormType; } - int32_t StartLoad(); - int32_t DoLoad(); - void StopLoad(); + int32_t Load(); CXFA_FFDocView* CreateDocView(); -- cgit v1.2.3