From 30540a95637256412eab3e87f954ee2b9793678f Mon Sep 17 00:00:00 2001 From: Lei Zhang Date: Thu, 4 Oct 2018 22:31:12 +0000 Subject: Remove unreachable code in CPDFXFA_Page. Also disambiguate LoadPDFPage() and do some cleanups. Change-Id: I591295cd5e742a14e41149b63e9d11d8c3d5b7fd Reviewed-on: https://pdfium-review.googlesource.com/c/43460 Commit-Queue: Lei Zhang Reviewed-by: Tom Sepez --- fpdfsdk/fpdf_editpage.cpp | 2 +- fpdfsdk/fpdfxfa/cpdfxfa_page.cpp | 34 +++++++++++----------------------- fpdfsdk/fpdfxfa/cpdfxfa_page.h | 4 ++-- 3 files changed, 14 insertions(+), 26 deletions(-) (limited to 'fpdfsdk') diff --git a/fpdfsdk/fpdf_editpage.cpp b/fpdfsdk/fpdf_editpage.cpp index c71f7e27be..d9a9bef26a 100644 --- a/fpdfsdk/fpdf_editpage.cpp +++ b/fpdfsdk/fpdf_editpage.cpp @@ -223,7 +223,7 @@ 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); + pXFAPage->LoadPDFPageFromDict(pPageDict); return FPDFPageFromIPDFPage(pXFAPage.Leak()); // Caller takes ownership. } #endif // PDF_ENABLE_XFA diff --git a/fpdfsdk/fpdfxfa/cpdfxfa_page.cpp b/fpdfsdk/fpdfxfa/cpdfxfa_page.cpp index e4618e3bbe..6c5ff63394 100644 --- a/fpdfsdk/fpdfxfa/cpdfxfa_page.cpp +++ b/fpdfsdk/fpdfxfa/cpdfxfa_page.cpp @@ -18,9 +18,12 @@ #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_pContext(pContext), m_iPageIndex(page_index) { + ASSERT(m_pContext); + ASSERT(m_iPageIndex >= 0); +} -CPDFXFA_Page::~CPDFXFA_Page() {} +CPDFXFA_Page::~CPDFXFA_Page() = default; CPDF_Page* CPDFXFA_Page::AsPDFPage() { return m_pPDFPage.Get(); @@ -31,17 +34,11 @@ CPDFXFA_Page* CPDFXFA_Page::AsXFAPage() { } CPDF_Document* CPDFXFA_Page::GetDocument() const { - return GetDocumentExtension()->GetPDFDoc(); + return m_pContext->GetPDFDoc(); } bool CPDFXFA_Page::LoadPDFPage() { - if (!m_pContext) - return false; - - CPDF_Document* pPDFDoc = m_pContext->GetPDFDoc(); - if (!pPDFDoc) - return false; - + CPDF_Document* pPDFDoc = GetDocument(); CPDF_Dictionary* pDict = pPDFDoc->GetPageDictionary(m_iPageIndex); if (!pDict) return false; @@ -54,9 +51,6 @@ bool CPDFXFA_Page::LoadPDFPage() { } bool CPDFXFA_Page::LoadXFAPageView() { - if (!m_pContext) - return false; - CXFA_FFDoc* pXFADoc = m_pContext->GetXFADoc(); if (!pXFADoc) return false; @@ -74,9 +68,6 @@ bool CPDFXFA_Page::LoadXFAPageView() { } bool CPDFXFA_Page::LoadPage() { - if (!m_pContext || m_iPageIndex < 0) - return false; - switch (m_pContext->GetFormType()) { case FormType::kNone: case FormType::kAcroForm: @@ -85,17 +76,14 @@ bool CPDFXFA_Page::LoadPage() { case FormType::kXFAFull: return LoadXFAPageView(); } + NOTREACHED(); return false; } -bool CPDFXFA_Page::LoadPDFPage(CPDF_Dictionary* pageDict) { - if (!m_pContext || m_iPageIndex < 0 || !pageDict) - return false; - - m_pPDFPage = - pdfium::MakeRetain(m_pContext->GetPDFDoc(), pageDict, true); +void CPDFXFA_Page::LoadPDFPageFromDict(CPDF_Dictionary* pPageDict) { + ASSERT(pPageDict); + m_pPDFPage = pdfium::MakeRetain(GetDocument(), pPageDict, true); m_pPDFPage->ParseContent(); - return true; } CPDF_Document::Extension* CPDFXFA_Page::GetDocumentExtension() const { diff --git a/fpdfsdk/fpdfxfa/cpdfxfa_page.h b/fpdfsdk/fpdfxfa/cpdfxfa_page.h index 1664c2a775..3e2118df6f 100644 --- a/fpdfsdk/fpdfxfa/cpdfxfa_page.h +++ b/fpdfsdk/fpdfxfa/cpdfxfa_page.h @@ -42,7 +42,7 @@ class CPDFXFA_Page final : public IPDF_Page { const CFX_PointF& page_point) const override; bool LoadPage(); - bool LoadPDFPage(CPDF_Dictionary* pageDict); + void LoadPDFPageFromDict(CPDF_Dictionary* pPageDict); CPDF_Document::Extension* GetDocumentExtension() const; int GetPageIndex() const { return m_iPageIndex; } CXFA_FFPageView* GetXFAPageView() const { return m_pXFAPageView; } @@ -59,7 +59,7 @@ class CPDFXFA_Page final : public IPDF_Page { bool LoadXFAPageView(); RetainPtr m_pPDFPage; - CXFA_FFPageView* m_pXFAPageView; + CXFA_FFPageView* m_pXFAPageView = nullptr; UnownedPtr const m_pContext; const int m_iPageIndex; }; -- cgit v1.2.3