Remove another parameter from CPDF_AnnotList methods

Save the CPDF_Page pointer passed into the CPDF_AnnotList ctor and reuse
it, instead of making the caller pass it in multiple times.

Change-Id: I4222e51343dc3f82ab4c2d59ecc9b986b8bfe3ae
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/117454
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Thomas Sepez <tsepez@google.com>
Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/core/fpdfdoc/cpdf_annotlist.cpp b/core/fpdfdoc/cpdf_annotlist.cpp
index 5e76277..14c3d14 100644
--- a/core/fpdfdoc/cpdf_annotlist.cpp
+++ b/core/fpdfdoc/cpdf_annotlist.cpp
@@ -172,8 +172,8 @@
 }  // namespace
 
 CPDF_AnnotList::CPDF_AnnotList(CPDF_Page* pPage)
-    : m_pDocument(pPage->GetDocument()) {
-  RetainPtr<CPDF_Array> pAnnots = pPage->GetMutableAnnotsArray();
+    : m_pPage(pPage), m_pDocument(m_pPage->GetDocument()) {
+  RetainPtr<CPDF_Array> pAnnots = m_pPage->GetMutableAnnotsArray();
   if (!pAnnots)
     return;
 
@@ -205,7 +205,7 @@
   m_nAnnotCount = m_AnnotList.size();
   for (size_t i = 0; i < m_nAnnotCount; ++i) {
     std::unique_ptr<CPDF_Annot> pPopupAnnot =
-        CreatePopupAnnot(m_pDocument, pPage, m_AnnotList[i].get());
+        CreatePopupAnnot(m_pDocument, m_pPage, m_AnnotList[i].get());
     if (pPopupAnnot)
       m_AnnotList.push_back(std::move(pPopupAnnot));
   }
@@ -230,8 +230,7 @@
   return it != m_AnnotList.end();
 }
 
-void CPDF_AnnotList::DisplayPass(CPDF_Page* pPage,
-                                 CPDF_RenderContext* pContext,
+void CPDF_AnnotList::DisplayPass(CPDF_RenderContext* pContext,
                                  bool bPrinting,
                                  const CFX_Matrix& mtMatrix,
                                  bool bWidgetPass) {
@@ -251,18 +250,17 @@
     if (!bPrinting && (annot_flags & pdfium::annotation_flags::kNoView))
       continue;
 
-    pAnnot->DrawInContext(pPage, pContext, mtMatrix,
+    pAnnot->DrawInContext(m_pPage, pContext, mtMatrix,
                           CPDF_Annot::AppearanceMode::kNormal);
   }
 }
 
-void CPDF_AnnotList::DisplayAnnots(CPDF_Page* pPage,
-                                   CPDF_RenderContext* pContext,
+void CPDF_AnnotList::DisplayAnnots(CPDF_RenderContext* pContext,
                                    bool bPrinting,
                                    const CFX_Matrix& mtUser2Device,
                                    bool bShowWidget) {
   CHECK(pContext);
-  DisplayPass(pPage, pContext, bPrinting, mtUser2Device, false);
+  DisplayPass(pContext, bPrinting, mtUser2Device, false);
   if (bShowWidget)
-    DisplayPass(pPage, pContext, bPrinting, mtUser2Device, true);
+    DisplayPass(pContext, bPrinting, mtUser2Device, true);
 }
diff --git a/core/fpdfdoc/cpdf_annotlist.h b/core/fpdfdoc/cpdf_annotlist.h
index c6da73f..39a46f5 100644
--- a/core/fpdfdoc/cpdf_annotlist.h
+++ b/core/fpdfdoc/cpdf_annotlist.h
@@ -27,8 +27,7 @@
   explicit CPDF_AnnotList(CPDF_Page* pPage);
   ~CPDF_AnnotList() override;
 
-  void DisplayAnnots(CPDF_Page* pPage,
-                     CPDF_RenderContext* pContext,
+  void DisplayAnnots(CPDF_RenderContext* pContext,
                      bool bPrinting,
                      const CFX_Matrix& mtUser2Device,
                      bool bShowWidget);
@@ -38,12 +37,12 @@
   bool Contains(const CPDF_Annot* pAnnot) const;
 
  private:
-  void DisplayPass(CPDF_Page* pPage,
-                   CPDF_RenderContext* pContext,
+  void DisplayPass(CPDF_RenderContext* pContext,
                    bool bPrinting,
                    const CFX_Matrix& mtMatrix,
                    bool bWidget);
 
+  UnownedPtr<CPDF_Page> const m_pPage;
   UnownedPtr<CPDF_Document> const m_pDocument;
 
   // The first |m_nAnnotCount| elements are from the PDF itself. The rest are
diff --git a/fpdfsdk/cpdfsdk_renderpage.cpp b/fpdfsdk/cpdfsdk_renderpage.cpp
index eebbb26..6cfbd95 100644
--- a/fpdfsdk/cpdfsdk_renderpage.cpp
+++ b/fpdfsdk/cpdfsdk_renderpage.cpp
@@ -74,7 +74,7 @@
 
     // TODO(https://crbug.com/pdfium/993) - maybe pass true here.
     const bool bShowWidget = false;
-    pList->DisplayAnnots(pPage, pContext->m_pContext.get(), bPrinting, matrix,
+    pList->DisplayAnnots(pContext->m_pContext.get(), bPrinting, matrix,
                          bShowWidget);
   }