diff options
-rw-r--r-- | fpdfsdk/fpdfxfa/cpdfxfa_context.cpp | 10 | ||||
-rw-r--r-- | xfa/fxfa/cxfa_ffapp.cpp | 13 | ||||
-rw-r--r-- | xfa/fxfa/cxfa_ffapp.h | 2 | ||||
-rw-r--r-- | xfa/fxfa/cxfa_ffdoc.cpp | 105 | ||||
-rw-r--r-- | xfa/fxfa/cxfa_ffdoc.h | 14 |
5 files changed, 59 insertions, 85 deletions
diff --git a/fpdfsdk/fpdfxfa/cpdfxfa_context.cpp b/fpdfsdk/fpdfxfa/cpdfxfa_context.cpp index e28561dca1..e1721a3f86 100644 --- a/fpdfsdk/fpdfxfa/cpdfxfa_context.cpp +++ b/fpdfsdk/fpdfxfa/cpdfxfa_context.cpp @@ -90,14 +90,8 @@ bool CPDFXFA_Context::LoadXFADoc() { if (!pApp) return false; - m_pXFADoc = pApp->CreateDoc(&m_DocEnv, m_pPDFDoc.get()); - if (!m_pXFADoc) { - SetLastError(FPDF_ERR_XFALOAD); - return false; - } - - if (!m_pXFADoc->Load()) { - CloseXFADoc(); + m_pXFADoc = pdfium::MakeUnique<CXFA_FFDoc>(pApp, &m_DocEnv); + if (!m_pXFADoc->OpenDoc(m_pPDFDoc.get())) { SetLastError(FPDF_ERR_XFALOAD); return false; } diff --git a/xfa/fxfa/cxfa_ffapp.cpp b/xfa/fxfa/cxfa_ffapp.cpp index 21ac081629..777e2a4241 100644 --- a/xfa/fxfa/cxfa_ffapp.cpp +++ b/xfa/fxfa/cxfa_ffapp.cpp @@ -40,19 +40,6 @@ CXFA_FFApp::CXFA_FFApp(IXFA_AppProvider* pProvider) : m_pProvider(pProvider) { CXFA_FFApp::~CXFA_FFApp() {} -std::unique_ptr<CXFA_FFDoc> CXFA_FFApp::CreateDoc( - IXFA_DocEnvironment* pDocEnvironment, - CPDF_Document* pPDFDoc) { - if (!pPDFDoc) - return nullptr; - - auto pDoc = pdfium::MakeUnique<CXFA_FFDoc>(this, pDocEnvironment); - if (!pDoc->OpenDoc(pPDFDoc)) - return nullptr; - - return pDoc; -} - CFGAS_FontMgr* CXFA_FFApp::GetFDEFontMgr() { if (!m_pFDEFontMgr) { m_pFDEFontMgr = pdfium::MakeUnique<CFGAS_FontMgr>(); diff --git a/xfa/fxfa/cxfa_ffapp.h b/xfa/fxfa/cxfa_ffapp.h index bd4cf363fe..1b1b40a512 100644 --- a/xfa/fxfa/cxfa_ffapp.h +++ b/xfa/fxfa/cxfa_ffapp.h @@ -34,8 +34,6 @@ class CXFA_FFApp { explicit CXFA_FFApp(IXFA_AppProvider* pProvider); ~CXFA_FFApp(); - std::unique_ptr<CXFA_FFDoc> CreateDoc(IXFA_DocEnvironment* pDocEnvironment, - CPDF_Document* pPDFDoc); void SetDefaultFontMgr(std::unique_ptr<CFGAS_DefaultFontManager> pFontMgr); CXFA_FWLAdapterWidgetMgr* GetFWLAdapterWidgetMgr(); diff --git a/xfa/fxfa/cxfa_ffdoc.cpp b/xfa/fxfa/cxfa_ffdoc.cpp index c7642cf977..24a8a04c03 100644 --- a/xfa/fxfa/cxfa_ffdoc.cpp +++ b/xfa/fxfa/cxfa_ffdoc.cpp @@ -165,55 +165,27 @@ CXFA_FFDoc::~CXFA_FFDoc() { CloseDoc(); } -bool CXFA_FFDoc::Load() { - if (!m_pPDFDoc) - return false; - - m_pNotify = pdfium::MakeUnique<CXFA_FFNotify>(this); - m_pDocument = pdfium::MakeUnique<CXFA_Document>(m_pNotify.get()); - if (!ParseDoc()) +bool CXFA_FFDoc::ParseDoc(CPDF_Object* pElementXFA) { + std::vector<CPDF_Stream*> xfaStreams; + if (pElementXFA->IsArray()) { + CPDF_Array* pXFAArray = (CPDF_Array*)pElementXFA; + for (size_t i = 0; i < pXFAArray->GetCount() / 2; i++) { + if (CPDF_Stream* pStream = pXFAArray->GetStreamAt(i * 2 + 1)) + xfaStreams.push_back(pStream); + } + } else if (pElementXFA->IsStream()) { + xfaStreams.push_back(pElementXFA->AsStream()); + } + if (xfaStreams.empty()) return false; - // At this point we've got an XFA document and we want to always return - // true to signify the load succeeded. - - m_pPDFFontMgr = pdfium::MakeUnique<CFGAS_PDFFontMgr>( - GetPDFDoc(), GetApp()->GetFDEFontMgr()); - - m_FormType = FormType::kXFAForeground; - CXFA_Node* pConfig = ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Config)); - if (!pConfig) - return true; - - CXFA_Acrobat* pAcrobat = - pConfig->GetFirstChildByClass<CXFA_Acrobat>(XFA_Element::Acrobat); - if (!pAcrobat) - return true; - - CXFA_Acrobat7* pAcrobat7 = - pAcrobat->GetFirstChildByClass<CXFA_Acrobat7>(XFA_Element::Acrobat7); - if (!pAcrobat7) - return true; - - CXFA_DynamicRender* pDynamicRender = - pAcrobat7->GetFirstChildByClass<CXFA_DynamicRender>( - XFA_Element::DynamicRender); - if (!pDynamicRender) - return true; - - WideString wsType = pDynamicRender->JSObject()->GetContent(false); - if (wsType == L"required") - m_FormType = FormType::kXFAFull; - - return true; -} + auto stream = pdfium::MakeRetain<CFX_SeekableMultiStream>(xfaStreams); -bool CXFA_FFDoc::ParseDoc() { // Note, we don't pass the document into the constructor as currently that // triggers different behaviour in the parser. CXFA_DocumentParser parser; parser.SetFactory(m_pDocument.get()); - if (!parser.Parse(m_pStream, XFA_PacketType::Xdp)) + if (!parser.Parse(stream, XFA_PacketType::Xdp)) return false; m_pXMLRoot = parser.GetXMLRoot(); @@ -311,21 +283,44 @@ bool CXFA_FFDoc::OpenDoc(CPDF_Document* pPDFDoc) { if (!pElementXFA) return false; - std::vector<CPDF_Stream*> xfaStreams; - if (pElementXFA->IsArray()) { - CPDF_Array* pXFAArray = (CPDF_Array*)pElementXFA; - for (size_t i = 0; i < pXFAArray->GetCount() / 2; i++) { - if (CPDF_Stream* pStream = pXFAArray->GetStreamAt(i * 2 + 1)) - xfaStreams.push_back(pStream); - } - } else if (pElementXFA->IsStream()) { - xfaStreams.push_back((CPDF_Stream*)pElementXFA); - } - if (xfaStreams.empty()) + m_pPDFDoc = pPDFDoc; + + m_pNotify = pdfium::MakeUnique<CXFA_FFNotify>(this); + m_pDocument = pdfium::MakeUnique<CXFA_Document>(m_pNotify.get()); + if (!ParseDoc(pElementXFA)) return false; - m_pPDFDoc = pPDFDoc; - m_pStream = pdfium::MakeRetain<CFX_SeekableMultiStream>(xfaStreams); + // At this point we've got an XFA document and we want to always return + // true to signify the load succeeded. + + m_pPDFFontMgr = pdfium::MakeUnique<CFGAS_PDFFontMgr>( + GetPDFDoc(), GetApp()->GetFDEFontMgr()); + + m_FormType = FormType::kXFAForeground; + CXFA_Node* pConfig = ToNode(m_pDocument->GetXFAObject(XFA_HASHCODE_Config)); + if (!pConfig) + return true; + + CXFA_Acrobat* pAcrobat = + pConfig->GetFirstChildByClass<CXFA_Acrobat>(XFA_Element::Acrobat); + if (!pAcrobat) + return true; + + CXFA_Acrobat7* pAcrobat7 = + pAcrobat->GetFirstChildByClass<CXFA_Acrobat7>(XFA_Element::Acrobat7); + if (!pAcrobat7) + return true; + + CXFA_DynamicRender* pDynamicRender = + pAcrobat7->GetFirstChildByClass<CXFA_DynamicRender>( + XFA_Element::DynamicRender); + if (!pDynamicRender) + return true; + + WideString wsType = pDynamicRender->JSObject()->GetContent(false); + if (wsType == L"required") + m_FormType = FormType::kXFAFull; + return true; } diff --git a/xfa/fxfa/cxfa_ffdoc.h b/xfa/fxfa/cxfa_ffdoc.h index fd90471f23..dc656253ef 100644 --- a/xfa/fxfa/cxfa_ffdoc.h +++ b/xfa/fxfa/cxfa_ffdoc.h @@ -20,6 +20,7 @@ class CFGAS_PDFFontMgr; class CFX_ChecksumContext; class CFX_DIBitmap; class CPDF_Document; +class CPDF_Object; class CXFA_FFApp; class CXFA_FFNotify; class CXFA_FFDocView; @@ -59,11 +60,9 @@ class CXFA_FFDoc { } FormType GetFormType() const { return m_FormType; } - bool Load(); CXFA_FFDocView* CreateDocView(); - bool ParseDoc(); bool OpenDoc(CPDF_Document* pPDFDoc); void CloseDoc(); @@ -83,16 +82,17 @@ class CXFA_FFDoc { bool bXDP = true); private: + bool ParseDoc(CPDF_Object* pElementXFA); + UnownedPtr<IXFA_DocEnvironment> const m_pDocEnvironment; - 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; UnownedPtr<CPDF_Document> m_pPDFDoc; - std::map<uint32_t, FX_IMAGEDIB_AND_DPI> m_HashToDibDpiMap; + std::unique_ptr<CFX_XMLNode> m_pXMLRoot; + std::unique_ptr<CXFA_FFNotify> m_pNotify; + std::unique_ptr<CXFA_Document> m_pDocument; std::unique_ptr<CXFA_FFDocView> m_DocView; std::unique_ptr<CFGAS_PDFFontMgr> m_pPDFFontMgr; + std::map<uint32_t, FX_IMAGEDIB_AND_DPI> m_HashToDibDpiMap; FormType m_FormType = FormType::kXFAForeground; }; |