Check that pageview arguments are redundant in annot handler methods.

Change-Id: I072c7fd1220a3284f62dfab05f2fe32c6c973043
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/85151
Commit-Queue: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
diff --git a/fpdfsdk/cpdfsdk_baannothandler.cpp b/fpdfsdk/cpdfsdk_baannothandler.cpp
index 26fdbd4..f810881 100644
--- a/fpdfsdk/cpdfsdk_baannothandler.cpp
+++ b/fpdfsdk/cpdfsdk_baannothandler.cpp
@@ -21,6 +21,7 @@
 #include "fpdfsdk/formfiller/cffl_formfield.h"
 #include "public/fpdf_fwlevent.h"
 #include "third_party/base/check.h"
+#include "third_party/base/check_op.h"
 #include "third_party/base/containers/contains.h"
 
 namespace {
@@ -51,6 +52,7 @@
 std::unique_ptr<CPDFSDK_Annot> CPDFSDK_BAAnnotHandler::NewAnnot(
     CPDF_Annot* pAnnot,
     CPDFSDK_PageView* pPageView) {
+  CHECK(pPageView);
   return std::make_unique<CPDFSDK_BAAnnot>(pAnnot, pPageView);
 }
 
@@ -64,6 +66,7 @@
                                     CFX_RenderDevice* pDevice,
                                     const CFX_Matrix& mtUser2Device,
                                     bool bDrawAnnots) {
+  CHECK_EQ(pPageView, pAnnot->GetPageView());
   if (pAnnot->AsXFAWidget())
     return;
 
@@ -93,6 +96,7 @@
 void CPDFSDK_BAAnnotHandler::OnMouseEnter(CPDFSDK_PageView* pPageView,
                                           ObservedPtr<CPDFSDK_Annot>* pAnnot,
                                           Mask<FWL_EVENTFLAG> nFlag) {
+  CHECK_EQ(pPageView, (*pAnnot)->GetPageView());
   CPDFSDK_BAAnnot* pBAAnnot = (*pAnnot)->AsBAAnnot();
   pBAAnnot->SetOpenState(true);
   UpdateAnnotRects(pPageView, pBAAnnot);
@@ -101,6 +105,7 @@
 void CPDFSDK_BAAnnotHandler::OnMouseExit(CPDFSDK_PageView* pPageView,
                                          ObservedPtr<CPDFSDK_Annot>* pAnnot,
                                          Mask<FWL_EVENTFLAG> nFlag) {
+  CHECK_EQ(pPageView, (*pAnnot)->GetPageView());
   CPDFSDK_BAAnnot* pBAAnnot = (*pAnnot)->AsBAAnnot();
   pBAAnnot->SetOpenState(false);
   UpdateAnnotRects(pPageView, pBAAnnot);
@@ -110,6 +115,7 @@
                                            ObservedPtr<CPDFSDK_Annot>* pAnnot,
                                            Mask<FWL_EVENTFLAG> nFlags,
                                            const CFX_PointF& point) {
+  CHECK_EQ(pPageView, (*pAnnot)->GetPageView());
   return false;
 }
 
@@ -117,6 +123,7 @@
                                          ObservedPtr<CPDFSDK_Annot>* pAnnot,
                                          Mask<FWL_EVENTFLAG> nFlags,
                                          const CFX_PointF& point) {
+  CHECK_EQ(pPageView, (*pAnnot)->GetPageView());
   return false;
 }
 
@@ -124,6 +131,7 @@
                                              ObservedPtr<CPDFSDK_Annot>* pAnnot,
                                              Mask<FWL_EVENTFLAG> nFlags,
                                              const CFX_PointF& point) {
+  CHECK_EQ(pPageView, (*pAnnot)->GetPageView());
   return false;
 }
 
@@ -131,6 +139,7 @@
                                          ObservedPtr<CPDFSDK_Annot>* pAnnot,
                                          Mask<FWL_EVENTFLAG> nFlags,
                                          const CFX_PointF& point) {
+  CHECK_EQ(pPageView, (*pAnnot)->GetPageView());
   return false;
 }
 
@@ -139,6 +148,7 @@
                                           Mask<FWL_EVENTFLAG> nFlags,
                                           const CFX_PointF& point,
                                           const CFX_Vector& delta) {
+  CHECK_EQ(pPageView, (*pAnnot)->GetPageView());
   return false;
 }
 
@@ -146,6 +156,7 @@
                                            ObservedPtr<CPDFSDK_Annot>* pAnnot,
                                            Mask<FWL_EVENTFLAG> nFlags,
                                            const CFX_PointF& point) {
+  CHECK_EQ(pPageView, (*pAnnot)->GetPageView());
   return false;
 }
 
@@ -153,6 +164,7 @@
                                          ObservedPtr<CPDFSDK_Annot>* pAnnot,
                                          Mask<FWL_EVENTFLAG> nFlags,
                                          const CFX_PointF& point) {
+  CHECK_EQ(pPageView, (*pAnnot)->GetPageView());
   return false;
 }
 
@@ -160,6 +172,7 @@
                                              ObservedPtr<CPDFSDK_Annot>* pAnnot,
                                              Mask<FWL_EVENTFLAG> nFlags,
                                              const CFX_PointF& point) {
+  CHECK_EQ(pPageView, (*pAnnot)->GetPageView());
   return false;
 }
 
@@ -256,6 +269,7 @@
 
 CFX_FloatRect CPDFSDK_BAAnnotHandler::GetViewBBox(CPDFSDK_PageView* pPageView,
                                                   CPDFSDK_Annot* pAnnot) {
+  CHECK_EQ(pPageView, pAnnot->GetPageView());
   return pAnnot->GetRect();
 }
 
@@ -295,5 +309,6 @@
                                      const CFX_PointF& point) {
   DCHECK(pPageView);
   DCHECK(pAnnot);
+  CHECK_EQ(pPageView, pAnnot->GetPageView());
   return GetViewBBox(pPageView, pAnnot).Contains(point);
 }
diff --git a/fpdfsdk/cpdfsdk_widgethandler.cpp b/fpdfsdk/cpdfsdk_widgethandler.cpp
index 662c773..b01d3a1 100644
--- a/fpdfsdk/cpdfsdk_widgethandler.cpp
+++ b/fpdfsdk/cpdfsdk_widgethandler.cpp
@@ -52,6 +52,7 @@
 std::unique_ptr<CPDFSDK_Annot> CPDFSDK_WidgetHandler::NewAnnot(
     CPDF_Annot* pAnnot,
     CPDFSDK_PageView* pPageView) {
+  CHECK(pPageView);
   CPDFSDK_InteractiveForm* pForm =
       GetFormFillEnvironment()->GetInteractiveForm();
   CPDF_InteractiveForm* pPDFForm = pForm->GetInteractiveForm();
@@ -82,6 +83,7 @@
                                    CFX_RenderDevice* pDevice,
                                    const CFX_Matrix& mtUser2Device,
                                    bool bDrawAnnots) {
+  CHECK_EQ(pPageView, pAnnot->GetPageView());
   if (pAnnot->IsSignatureWidget()) {
     pAnnot->AsBAAnnot()->DrawAppearance(
         pDevice, mtUser2Device, CPDF_Annot::AppearanceMode::kNormal, nullptr);
@@ -94,6 +96,7 @@
 void CPDFSDK_WidgetHandler::OnMouseEnter(CPDFSDK_PageView* pPageView,
                                          ObservedPtr<CPDFSDK_Annot>* pAnnot,
                                          Mask<FWL_EVENTFLAG> nFlag) {
+  CHECK_EQ(pPageView, (*pAnnot)->GetPageView());
   if (!(*pAnnot)->IsSignatureWidget()) {
     GetFormFillEnvironment()->GetInteractiveFormFiller()->OnMouseEnter(
         pPageView, pAnnot, nFlag);
@@ -103,6 +106,7 @@
 void CPDFSDK_WidgetHandler::OnMouseExit(CPDFSDK_PageView* pPageView,
                                         ObservedPtr<CPDFSDK_Annot>* pAnnot,
                                         Mask<FWL_EVENTFLAG> nFlag) {
+  CHECK_EQ(pPageView, (*pAnnot)->GetPageView());
   if (!(*pAnnot)->IsSignatureWidget()) {
     GetFormFillEnvironment()->GetInteractiveFormFiller()->OnMouseExit(
         pPageView, pAnnot, nFlag);
@@ -113,6 +117,7 @@
                                           ObservedPtr<CPDFSDK_Annot>* pAnnot,
                                           Mask<FWL_EVENTFLAG> nFlags,
                                           const CFX_PointF& point) {
+  CHECK_EQ(pPageView, (*pAnnot)->GetPageView());
   return !(*pAnnot)->IsSignatureWidget() &&
          GetFormFillEnvironment()->GetInteractiveFormFiller()->OnLButtonDown(
              pPageView, pAnnot, nFlags, point);
@@ -122,6 +127,7 @@
                                         ObservedPtr<CPDFSDK_Annot>* pAnnot,
                                         Mask<FWL_EVENTFLAG> nFlags,
                                         const CFX_PointF& point) {
+  CHECK_EQ(pPageView, (*pAnnot)->GetPageView());
   return !(*pAnnot)->IsSignatureWidget() &&
          GetFormFillEnvironment()->GetInteractiveFormFiller()->OnLButtonUp(
              pPageView, pAnnot, nFlags, point);
@@ -131,6 +137,7 @@
                                             ObservedPtr<CPDFSDK_Annot>* pAnnot,
                                             Mask<FWL_EVENTFLAG> nFlags,
                                             const CFX_PointF& point) {
+  CHECK_EQ(pPageView, (*pAnnot)->GetPageView());
   return !(*pAnnot)->IsSignatureWidget() &&
          GetFormFillEnvironment()->GetInteractiveFormFiller()->OnLButtonDblClk(
              pPageView, pAnnot, nFlags, point);
@@ -140,6 +147,7 @@
                                         ObservedPtr<CPDFSDK_Annot>* pAnnot,
                                         Mask<FWL_EVENTFLAG> nFlags,
                                         const CFX_PointF& point) {
+  CHECK_EQ(pPageView, (*pAnnot)->GetPageView());
   return !(*pAnnot)->IsSignatureWidget() &&
          GetFormFillEnvironment()->GetInteractiveFormFiller()->OnMouseMove(
              pPageView, pAnnot, nFlags, point);
@@ -150,6 +158,7 @@
                                          Mask<FWL_EVENTFLAG> nFlags,
                                          const CFX_PointF& point,
                                          const CFX_Vector& delta) {
+  CHECK_EQ(pPageView, (*pAnnot)->GetPageView());
   return !(*pAnnot)->IsSignatureWidget() &&
          GetFormFillEnvironment()->GetInteractiveFormFiller()->OnMouseWheel(
              pPageView, pAnnot, nFlags, point, delta);
@@ -159,6 +168,7 @@
                                           ObservedPtr<CPDFSDK_Annot>* pAnnot,
                                           Mask<FWL_EVENTFLAG> nFlags,
                                           const CFX_PointF& point) {
+  CHECK_EQ(pPageView, (*pAnnot)->GetPageView());
   return !(*pAnnot)->IsSignatureWidget() &&
          GetFormFillEnvironment()->GetInteractiveFormFiller()->OnRButtonDown(
              pPageView, pAnnot, nFlags, point);
@@ -168,6 +178,7 @@
                                         ObservedPtr<CPDFSDK_Annot>* pAnnot,
                                         Mask<FWL_EVENTFLAG> nFlags,
                                         const CFX_PointF& point) {
+  CHECK_EQ(pPageView, (*pAnnot)->GetPageView());
   return !(*pAnnot)->IsSignatureWidget() &&
          GetFormFillEnvironment()->GetInteractiveFormFiller()->OnRButtonUp(
              pPageView, pAnnot, nFlags, point);
@@ -177,6 +188,7 @@
                                             ObservedPtr<CPDFSDK_Annot>* pAnnot,
                                             Mask<FWL_EVENTFLAG> nFlags,
                                             const CFX_PointF& point) {
+  CHECK_EQ(pPageView, (*pAnnot)->GetPageView());
   return false;
 }
 
@@ -268,6 +280,7 @@
 
 CFX_FloatRect CPDFSDK_WidgetHandler::GetViewBBox(CPDFSDK_PageView* pPageView,
                                                  CPDFSDK_Annot* pAnnot) {
+  CHECK_EQ(pPageView, pAnnot->GetPageView());
   if (!pAnnot->IsSignatureWidget()) {
     return CFX_FloatRect(
         GetFormFillEnvironment()->GetInteractiveFormFiller()->GetViewBBox(
@@ -332,6 +345,7 @@
                                     const CFX_PointF& point) {
   DCHECK(pPageView);
   DCHECK(pAnnot);
+  CHECK_EQ(pPageView, pAnnot->GetPageView());
   return GetViewBBox(pPageView, pAnnot).Contains(point);
 }
 
diff --git a/fpdfsdk/fpdfxfa/cpdfxfa_widgethandler.cpp b/fpdfsdk/fpdfxfa/cpdfxfa_widgethandler.cpp
index 6da2e4a..4524b78 100644
--- a/fpdfsdk/fpdfxfa/cpdfxfa_widgethandler.cpp
+++ b/fpdfsdk/fpdfxfa/cpdfxfa_widgethandler.cpp
@@ -13,6 +13,7 @@
 #include "fpdfsdk/fpdfxfa/cpdfxfa_context.h"
 #include "fpdfsdk/fpdfxfa/cpdfxfa_widget.h"
 #include "third_party/base/check.h"
+#include "third_party/base/check_op.h"
 #include "xfa/fgas/graphics/cfgas_gegraphics.h"
 #include "xfa/fwl/cfwl_app.h"
 #include "xfa/fwl/fwl_widgetdef.h"
@@ -218,6 +219,7 @@
 std::unique_ptr<CPDFSDK_Annot> CPDFXFA_WidgetHandler::NewAnnotForXFA(
     CXFA_FFWidget* pAnnot,
     CPDFSDK_PageView* pPageView) {
+  CHECK(pPageView);
   return std::make_unique<CPDFXFA_Widget>(pAnnot, pPageView);
 }
 
@@ -226,6 +228,7 @@
                                    CFX_RenderDevice* pDevice,
                                    const CFX_Matrix& mtUser2Device,
                                    bool bDrawAnnots) {
+  CHECK_EQ(pPageView, pAnnot->GetPageView());
   CPDFXFA_Widget* pXFAWidget = ToXFAWidget(pAnnot);
   DCHECK(pXFAWidget);
 
@@ -248,6 +251,7 @@
 
 CFX_FloatRect CPDFXFA_WidgetHandler::GetViewBBox(CPDFSDK_PageView* pPageView,
                                                  CPDFSDK_Annot* pAnnot) {
+  CHECK_EQ(pPageView, pAnnot->GetPageView());
   CPDFXFA_Widget* pXFAWidget = ToXFAWidget(pAnnot);
   CXFA_Node* node = pXFAWidget->GetXFAFFWidget()->GetNode();
   DCHECK(node->IsWidgetReady());
@@ -338,6 +342,7 @@
 bool CPDFXFA_WidgetHandler::HitTest(CPDFSDK_PageView* pPageView,
                                     CPDFSDK_Annot* pAnnot,
                                     const CFX_PointF& point) {
+  CHECK_EQ(pPageView, pAnnot->GetPageView());
   if (!pPageView)
     return false;
 
@@ -363,6 +368,7 @@
 void CPDFXFA_WidgetHandler::OnMouseEnter(CPDFSDK_PageView* pPageView,
                                          ObservedPtr<CPDFSDK_Annot>* pAnnot,
                                          Mask<FWL_EVENTFLAG> nFlag) {
+  CHECK_EQ(pPageView, (*pAnnot)->GetPageView());
   if (!pPageView)
     return;
 
@@ -377,6 +383,7 @@
 void CPDFXFA_WidgetHandler::OnMouseExit(CPDFSDK_PageView* pPageView,
                                         ObservedPtr<CPDFSDK_Annot>* pAnnot,
                                         Mask<FWL_EVENTFLAG> nFlag) {
+  CHECK_EQ(pPageView, (*pAnnot)->GetPageView());
   if (!pPageView)
     return;
 
@@ -392,6 +399,7 @@
                                           ObservedPtr<CPDFSDK_Annot>* pAnnot,
                                           Mask<FWL_EVENTFLAG> nFlags,
                                           const CFX_PointF& point) {
+  CHECK_EQ(pPageView, (*pAnnot)->GetPageView());
   if (!pPageView)
     return false;
 
@@ -408,6 +416,7 @@
                                         ObservedPtr<CPDFSDK_Annot>* pAnnot,
                                         Mask<FWL_EVENTFLAG> nFlags,
                                         const CFX_PointF& point) {
+  CHECK_EQ(pPageView, (*pAnnot)->GetPageView());
   if (!pPageView)
     return false;
 
@@ -424,6 +433,7 @@
                                             ObservedPtr<CPDFSDK_Annot>* pAnnot,
                                             Mask<FWL_EVENTFLAG> nFlags,
                                             const CFX_PointF& point) {
+  CHECK_EQ(pPageView, (*pAnnot)->GetPageView());
   if (!pPageView)
     return false;
 
@@ -440,6 +450,7 @@
                                         ObservedPtr<CPDFSDK_Annot>* pAnnot,
                                         Mask<FWL_EVENTFLAG> nFlags,
                                         const CFX_PointF& point) {
+  CHECK_EQ(pPageView, (*pAnnot)->GetPageView());
   if (!pPageView)
     return false;
 
@@ -457,6 +468,7 @@
                                          Mask<FWL_EVENTFLAG> nFlags,
                                          const CFX_PointF& point,
                                          const CFX_Vector& delta) {
+  CHECK_EQ(pPageView, (*pAnnot)->GetPageView());
   if (!pPageView)
     return false;
 
@@ -473,6 +485,7 @@
                                           ObservedPtr<CPDFSDK_Annot>* pAnnot,
                                           Mask<FWL_EVENTFLAG> nFlags,
                                           const CFX_PointF& point) {
+  CHECK_EQ(pPageView, (*pAnnot)->GetPageView());
   if (!pPageView)
     return false;
 
@@ -489,6 +502,7 @@
                                         ObservedPtr<CPDFSDK_Annot>* pAnnot,
                                         Mask<FWL_EVENTFLAG> nFlags,
                                         const CFX_PointF& point) {
+  CHECK_EQ(pPageView, (*pAnnot)->GetPageView());
   if (!pPageView)
     return false;
 
@@ -505,6 +519,7 @@
                                             ObservedPtr<CPDFSDK_Annot>* pAnnot,
                                             Mask<FWL_EVENTFLAG> nFlags,
                                             const CFX_PointF& point) {
+  CHECK_EQ(pPageView, (*pAnnot)->GetPageView());
   if (!pPageView)
     return false;