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 <thestig@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
diff --git a/fpdfsdk/fpdf_editpage.cpp b/fpdfsdk/fpdf_editpage.cpp
index c71f7e2..d9a9bef 100644
--- a/fpdfsdk/fpdf_editpage.cpp
+++ b/fpdfsdk/fpdf_editpage.cpp
@@ -223,7 +223,7 @@
   auto* pContext = static_cast<CPDFXFA_Context*>(pDoc->GetExtension());
   if (pContext) {
     auto pXFAPage = pdfium::MakeRetain<CPDFXFA_Page>(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 e4618e3..6c5ff63 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 @@
 }
 
 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::LoadXFAPageView() {
-  if (!m_pContext)
-    return false;
-
   CXFA_FFDoc* pXFADoc = m_pContext->GetXFADoc();
   if (!pXFADoc)
     return false;
@@ -74,9 +68,6 @@
 }
 
 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 @@
     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<CPDF_Page>(m_pContext->GetPDFDoc(), pageDict, true);
+void CPDFXFA_Page::LoadPDFPageFromDict(CPDF_Dictionary* pPageDict) {
+  ASSERT(pPageDict);
+  m_pPDFPage = pdfium::MakeRetain<CPDF_Page>(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 1664c2a..3e2118d 100644
--- a/fpdfsdk/fpdfxfa/cpdfxfa_page.h
+++ b/fpdfsdk/fpdfxfa/cpdfxfa_page.h
@@ -42,7 +42,7 @@
       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 @@
   bool LoadXFAPageView();
 
   RetainPtr<CPDF_Page> m_pPDFPage;
-  CXFA_FFPageView* m_pXFAPageView;
+  CXFA_FFPageView* m_pXFAPageView = nullptr;
   UnownedPtr<CPDFXFA_Context> const m_pContext;
   const int m_iPageIndex;
 };