From 7b094f81483240f50dfc12e51cf545a8f0d5933d Mon Sep 17 00:00:00 2001 From: Henrique Nakashima Date: Tue, 8 May 2018 20:32:08 +0000 Subject: Revert "Ensure that XFA Pages always have a corresponding PDF page" This reverts commit e7207f33f8024b59fc85abb1b4594b0fbab5361b. Reason for revert: Causes crash in some XFA forms - crbug.com/840922 This is a merge, not a clean revert. Original change's description: > Ensure that XFA Pages always have a corresponding PDF page > > The PDF page may be blank, un-numbered, or untracked by CPDF, but > this provides a place for all XFA pages to "extend" from down the > road. > > Change-Id: If1003be0f261154e61e9793ccba7e1f43cd73104 > Reviewed-on: https://pdfium-review.googlesource.com/31771 > Commit-Queue: Tom Sepez > Reviewed-by: dsinclair Change-Id: Ia7f286321552b225a95f461aa8a6aef979f5c991 No-Presubmit: true No-Tree-Checks: true No-Try: true Bug: chromium:840922 Reviewed-on: https://pdfium-review.googlesource.com/32210 Reviewed-by: dsinclair Commit-Queue: Henrique Nakashima --- fpdfsdk/fpdfxfa/cpdfxfa_page.cpp | 56 +++++++++++++++++++++++++++++++--------- fpdfsdk/fpdfxfa/cpdfxfa_page.h | 2 ++ 2 files changed, 46 insertions(+), 12 deletions(-) (limited to 'fpdfsdk/fpdfxfa') diff --git a/fpdfsdk/fpdfxfa/cpdfxfa_page.cpp b/fpdfsdk/fpdfxfa/cpdfxfa_page.cpp index 9fe63f435f..da1c1e521a 100644 --- a/fpdfsdk/fpdfxfa/cpdfxfa_page.cpp +++ b/fpdfsdk/fpdfxfa/cpdfxfa_page.cpp @@ -18,25 +18,32 @@ #include "xfa/fxfa/cxfa_ffpageview.h" CPDFXFA_Page::CPDFXFA_Page(CPDFXFA_Context* pContext, int page_index) - : m_pXFAPageView(nullptr), m_pContext(pContext), m_iPageIndex(page_index) { - CPDF_Document* pPDFDoc = m_pContext->GetPDFDoc(); - CPDF_Dictionary* pDict = nullptr; - if (pPDFDoc && m_pContext->GetFormType() != FormType::kXFAFull) - pDict = pPDFDoc->GetPageDictionary(m_iPageIndex); - m_pPDFPage = pdfium::MakeUnique(pPDFDoc, pDict, true); - m_pPDFPage->SetPageExtension(this); -} + : m_pXFAPageView(nullptr), m_pContext(pContext), m_iPageIndex(page_index) {} CPDFXFA_Page::~CPDFXFA_Page() {} -bool CPDFXFA_Page::LoadPage() { - if (!m_pContext || m_iPageIndex < 0) +bool CPDFXFA_Page::LoadPDFPage() { + if (!m_pContext) return false; - if (m_pContext->GetFormType() != FormType::kXFAFull) { + CPDF_Document* pPDFDoc = m_pContext->GetPDFDoc(); + if (!pPDFDoc) + return false; + + CPDF_Dictionary* pDict = pPDFDoc->GetPageDictionary(m_iPageIndex); + if (!pDict) + return false; + + if (!m_pPDFPage || m_pPDFPage->GetFormDict() != pDict) { + m_pPDFPage = pdfium::MakeUnique(pPDFDoc, pDict, true); m_pPDFPage->ParseContent(); - return true; } + return true; +} + +bool CPDFXFA_Page::LoadXFAPageView() { + if (!m_pContext) + return false; CXFA_FFDoc* pXFADoc = m_pContext->GetXFADoc(); if (!pXFADoc) @@ -54,6 +61,31 @@ bool CPDFXFA_Page::LoadPage() { return true; } +bool CPDFXFA_Page::LoadPage() { + if (!m_pContext || m_iPageIndex < 0) + return false; + + switch (m_pContext->GetFormType()) { + case FormType::kNone: + case FormType::kAcroForm: + case FormType::kXFAForeground: + return LoadPDFPage(); + case FormType::kXFAFull: + return LoadXFAPageView(); + } + return false; +} + +bool CPDFXFA_Page::LoadPDFPage(CPDF_Dictionary* pageDict) { + if (!m_pContext || m_iPageIndex < 0 || !pageDict) + return false; + + m_pPDFPage = + pdfium::MakeUnique(m_pContext->GetPDFDoc(), pageDict, true); + m_pPDFPage->ParseContent(); + return true; +} + CPDF_Document::Extension* CPDFXFA_Page::GetDocumentExtension() const { return m_pContext.Get(); } diff --git a/fpdfsdk/fpdfxfa/cpdfxfa_page.h b/fpdfsdk/fpdfxfa/cpdfxfa_page.h index faacf3e0b0..4f4d6b0a22 100644 --- a/fpdfsdk/fpdfxfa/cpdfxfa_page.h +++ b/fpdfsdk/fpdfxfa/cpdfxfa_page.h @@ -27,6 +27,7 @@ class CPDFXFA_Page : public CPDF_Page::Extension { friend RetainPtr pdfium::MakeRetain(Args&&... args); bool LoadPage(); + bool LoadPDFPage(CPDF_Dictionary* pageDict); // CPDF_Page::Extension: CPDF_Document::Extension* GetDocumentExtension() const override; @@ -56,6 +57,7 @@ class CPDFXFA_Page : public CPDF_Page::Extension { CPDFXFA_Page(CPDFXFA_Context* pContext, int page_index); ~CPDFXFA_Page() override; + bool LoadPDFPage(); bool LoadXFAPageView(); private: -- cgit v1.2.3