From e7207f33f8024b59fc85abb1b4594b0fbab5361b Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Mon, 7 May 2018 20:26:46 +0000 Subject: 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 --- fpdfsdk/fpdf_editpage.cpp | 1 - fpdfsdk/fpdf_formfill.cpp | 26 ++++++++++++------- fpdfsdk/fpdfxfa/cpdfxfa_page.cpp | 56 +++++++++------------------------------- fpdfsdk/fpdfxfa/cpdfxfa_page.h | 2 -- 4 files changed, 28 insertions(+), 57 deletions(-) diff --git a/fpdfsdk/fpdf_editpage.cpp b/fpdfsdk/fpdf_editpage.cpp index 0647dc537f..f38c4ff800 100644 --- a/fpdfsdk/fpdf_editpage.cpp +++ b/fpdfsdk/fpdf_editpage.cpp @@ -182,7 +182,6 @@ FPDF_EXPORT FPDF_PAGE FPDF_CALLCONV FPDFPage_New(FPDF_DOCUMENT document, auto* pContext = static_cast(pDoc->GetExtension()); if (pContext) { auto pXFAPage = pdfium::MakeRetain(pContext, page_index); - pXFAPage->LoadPDFPage(pPageDict); return FPDFPageFromUnderlying(pXFAPage.Leak()); // Caller takes ownership. } // Eventually, fallthru into non-XFA case once page type is consistent. diff --git a/fpdfsdk/fpdf_formfill.cpp b/fpdfsdk/fpdf_formfill.cpp index 280ef62edb..c92fc7b718 100644 --- a/fpdfsdk/fpdf_formfill.cpp +++ b/fpdfsdk/fpdf_formfill.cpp @@ -621,7 +621,11 @@ FPDF_EXPORT void FPDF_CALLCONV FORM_DoDocumentAAction(FPDF_FORMHANDLE hHandle, if (!pDict) return; - CPDF_AAction aa(pDict->GetDictFor("AA")); + CPDF_Dictionary* pActionDict = pDict->GetDictFor("AA"); + if (!pActionDict) + return; + + CPDF_AAction aa(pActionDict); auto type = static_cast(aaType); if (aa.ActionExist(type)) { CPDF_Action action = aa.GetAction(type); @@ -641,20 +645,22 @@ FPDF_EXPORT void FPDF_CALLCONV FORM_DoPageAAction(FPDF_PAGE page, UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page); CPDF_Page* pPDFPage = CPDFPageFromFPDFPage(page); - if (!pPDFPage) - return; - - if (!pFormFillEnv->GetPageView(pPage, false)) + if (!pPDFPage || !pFormFillEnv->GetPageView(pPage, false)) return; CPDFSDK_ActionHandler* pActionHandler = pFormFillEnv->GetActionHandler(); CPDF_Dictionary* pPageDict = pPDFPage->m_pFormDict.Get(); - CPDF_AAction aa(pPageDict->GetDictFor("AA")); + if (!pPageDict) + return; + + CPDF_Dictionary* pActionDict = pPageDict->GetDictFor("AA"); + if (!pActionDict) + return; + + CPDF_AAction aa(pActionDict); CPDF_AAction::AActionType type = aaType == FPDFPAGE_AACTION_OPEN ? CPDF_AAction::OpenPage : CPDF_AAction::ClosePage; - if (aa.ActionExist(type)) { - CPDF_Action action = aa.GetAction(type); - pActionHandler->DoAction_Page(action, type, pFormFillEnv); - } + if (aa.ActionExist(type)) + pActionHandler->DoAction_Page(aa.GetAction(type), type, pFormFillEnv); } diff --git a/fpdfsdk/fpdfxfa/cpdfxfa_page.cpp b/fpdfsdk/fpdfxfa/cpdfxfa_page.cpp index 809214dec6..f1d7aa9ad3 100644 --- a/fpdfsdk/fpdfxfa/cpdfxfa_page.cpp +++ b/fpdfsdk/fpdfxfa/cpdfxfa_page.cpp @@ -18,32 +18,25 @@ #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) {} + : 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->GetPage(m_iPageIndex); + m_pPDFPage = pdfium::MakeUnique(pPDFDoc, pDict, true); + m_pPDFPage->SetPageExtension(this); +} CPDFXFA_Page::~CPDFXFA_Page() {} -bool CPDFXFA_Page::LoadPDFPage() { - if (!m_pContext) - return false; - - CPDF_Document* pPDFDoc = m_pContext->GetPDFDoc(); - if (!pPDFDoc) - return false; - - CPDF_Dictionary* pDict = pPDFDoc->GetPage(m_iPageIndex); - if (!pDict) +bool CPDFXFA_Page::LoadPage() { + if (!m_pContext || m_iPageIndex < 0) return false; - if (!m_pPDFPage || m_pPDFPage->m_pFormDict != pDict) { - m_pPDFPage = pdfium::MakeUnique(pPDFDoc, pDict, true); + if (m_pContext->GetFormType() != FormType::kXFAFull) { m_pPDFPage->ParseContent(); + return true; } - return true; -} - -bool CPDFXFA_Page::LoadXFAPageView() { - if (!m_pContext) - return false; CXFA_FFDoc* pXFADoc = m_pContext->GetXFADoc(); if (!pXFADoc) @@ -61,31 +54,6 @@ bool CPDFXFA_Page::LoadXFAPageView() { 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 4f4d6b0a22..faacf3e0b0 100644 --- a/fpdfsdk/fpdfxfa/cpdfxfa_page.h +++ b/fpdfsdk/fpdfxfa/cpdfxfa_page.h @@ -27,7 +27,6 @@ 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; @@ -57,7 +56,6 @@ 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