Remove CFX_SystemHandler.

CPDFSDK_FormFillEnvironment can implement these interfaces
itself without having another block of memory that does nothing
but point back at it.

Change-Id: I052931e8037d0185e89262bacc4cb22b0539a461
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/58954
Commit-Queue: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
diff --git a/fpdfsdk/BUILD.gn b/fpdfsdk/BUILD.gn
index 5909ada..5d0ef4d 100644
--- a/fpdfsdk/BUILD.gn
+++ b/fpdfsdk/BUILD.gn
@@ -8,8 +8,6 @@
 
 jumbo_source_set("fpdfsdk") {
   sources = [
-    "cfx_systemhandler.cpp",
-    "cfx_systemhandler.h",
     "cpdf_annotcontext.cpp",
     "cpdf_annotcontext.h",
     "cpdfsdk_actionhandler.cpp",
diff --git a/fpdfsdk/cfx_systemhandler.cpp b/fpdfsdk/cfx_systemhandler.cpp
deleted file mode 100644
index d14834f..0000000
--- a/fpdfsdk/cfx_systemhandler.cpp
+++ /dev/null
@@ -1,82 +0,0 @@
-// Copyright 2016 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#include "fpdfsdk/cfx_systemhandler.h"
-
-#include <memory>
-
-#include "core/fpdfapi/parser/cpdf_document.h"
-#include "core/fxcrt/fx_codepage.h"
-#include "core/fxge/cfx_gemodule.h"
-#include "fpdfsdk/cpdfsdk_annot.h"
-#include "fpdfsdk/cpdfsdk_formfillenvironment.h"
-#include "fpdfsdk/cpdfsdk_pageview.h"
-#include "fpdfsdk/cpdfsdk_widget.h"
-#include "fpdfsdk/formfiller/cffl_formfiller.h"
-#include "third_party/base/ptr_util.h"
-
-CFX_SystemHandler::CFX_SystemHandler(CPDFSDK_FormFillEnvironment* pFormFillEnv)
-    : m_pFormFillEnv(pFormFillEnv) {
-  ASSERT(m_pFormFillEnv);
-}
-
-CFX_SystemHandler::~CFX_SystemHandler() = default;
-
-void CFX_SystemHandler::InvalidateRect(PerWindowData* pWidgetData,
-                                       const CFX_FloatRect& rect) {
-  auto* pPrivateData = static_cast<CFFL_PrivateData*>(pWidgetData);
-  CPDFSDK_Widget* widget = pPrivateData->pWidget.Get();
-  if (!widget)
-    return;
-
-  CPDFSDK_PageView* pPageView = widget->GetPageView();
-  IPDF_Page* pPage = widget->GetPage();
-  if (!pPage || !pPageView)
-    return;
-
-  CFX_Matrix device2page = pPageView->GetCurrentMatrix().GetInverse();
-  CFX_PointF left_top = device2page.Transform(CFX_PointF(rect.left, rect.top));
-  CFX_PointF right_bottom =
-      device2page.Transform(CFX_PointF(rect.right, rect.bottom));
-
-  CFX_FloatRect rcPDF(left_top.x, right_bottom.y, right_bottom.x, left_top.y);
-  rcPDF.Normalize();
-  m_pFormFillEnv->Invalidate(pPage, rcPDF.GetOuterRect());
-}
-
-void CFX_SystemHandler::OutputSelectedRect(CFFL_FormFiller* pFormFiller,
-                                           const CFX_FloatRect& rect) {
-  if (!pFormFiller)
-    return;
-
-  CFX_PointF ptA = pFormFiller->PWLtoFFL(CFX_PointF(rect.left, rect.bottom));
-  CFX_PointF ptB = pFormFiller->PWLtoFFL(CFX_PointF(rect.right, rect.top));
-
-  CPDFSDK_Annot* pAnnot = pFormFiller->GetSDKAnnot();
-  IPDF_Page* pPage = pAnnot->GetPage();
-  ASSERT(pPage);
-
-  m_pFormFillEnv->OutputSelectedRect(pPage,
-                                     CFX_FloatRect(ptA.x, ptA.y, ptB.x, ptB.y));
-}
-
-bool CFX_SystemHandler::IsSelectionImplemented() const {
-  FPDF_FORMFILLINFO* pInfo = m_pFormFillEnv->GetFormFillInfo();
-  return pInfo && pInfo->FFI_OutputSelectedRect;
-}
-
-void CFX_SystemHandler::SetCursor(int32_t nCursorType) {
-  m_pFormFillEnv->SetCursor(nCursorType);
-}
-
-int32_t CFX_SystemHandler::SetTimer(int32_t uElapse,
-                                    TimerCallback lpTimerFunc) {
-  return m_pFormFillEnv->SetTimer(uElapse, lpTimerFunc);
-}
-
-void CFX_SystemHandler::KillTimer(int32_t nID) {
-  m_pFormFillEnv->KillTimer(nID);
-}
diff --git a/fpdfsdk/cfx_systemhandler.h b/fpdfsdk/cfx_systemhandler.h
deleted file mode 100644
index c72e587..0000000
--- a/fpdfsdk/cfx_systemhandler.h
+++ /dev/null
@@ -1,39 +0,0 @@
-// Copyright 2016 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
-
-#ifndef FPDFSDK_CFX_SYSTEMHANDLER_H_
-#define FPDFSDK_CFX_SYSTEMHANDLER_H_
-
-#include "core/fxcrt/fx_coordinates.h"
-#include "core/fxcrt/fx_system.h"
-#include "core/fxcrt/timerhandler_iface.h"
-#include "core/fxcrt/unowned_ptr.h"
-#include "fpdfsdk/pwl/ipwl_systemhandler.h"
-
-class CFFL_FormFiller;
-class CPDFSDK_FormFillEnvironment;
-class CPDFSDK_Widget;
-
-class CFX_SystemHandler final : public TimerHandlerIface,
-                                public IPWL_SystemHandler {
- public:
-  explicit CFX_SystemHandler(CPDFSDK_FormFillEnvironment* pFormFillEnv);
-  ~CFX_SystemHandler() override;
-
-  void InvalidateRect(PerWindowData* pWidgetData,
-                      const CFX_FloatRect& rect) override;
-  void OutputSelectedRect(CFFL_FormFiller* pFormFiller,
-                          const CFX_FloatRect& rect) override;
-  bool IsSelectionImplemented() const override;
-  void SetCursor(int32_t nCursorType) override;
-  int32_t SetTimer(int32_t uElapse, TimerCallback lpTimerFunc) override;
-  void KillTimer(int32_t nID) override;
-
- private:
-  UnownedPtr<CPDFSDK_FormFillEnvironment> const m_pFormFillEnv;
-};
-
-#endif  // FPDFSDK_CFX_SYSTEMHANDLER_H_
diff --git a/fpdfsdk/cpdfsdk_annot.h b/fpdfsdk/cpdfsdk_annot.h
index 3247248..a01b414 100644
--- a/fpdfsdk/cpdfsdk_annot.h
+++ b/fpdfsdk/cpdfsdk_annot.h
@@ -12,7 +12,6 @@
 #include "core/fpdfdoc/cpdf_defaultappearance.h"
 #include "core/fxcrt/observed_ptr.h"
 #include "core/fxcrt/unowned_ptr.h"
-#include "fpdfsdk/cfx_systemhandler.h"
 
 class CFX_Matrix;
 class CFX_RenderDevice;
diff --git a/fpdfsdk/cpdfsdk_baannot.h b/fpdfsdk/cpdfsdk_baannot.h
index d4b5b5c..61272e5 100644
--- a/fpdfsdk/cpdfsdk_baannot.h
+++ b/fpdfsdk/cpdfsdk_baannot.h
@@ -13,7 +13,6 @@
 #include "core/fxcrt/fx_coordinates.h"
 #include "core/fxcrt/fx_string.h"
 #include "core/fxge/cfx_renderdevice.h"
-#include "fpdfsdk/cfx_systemhandler.h"
 #include "fpdfsdk/cpdfsdk_annot.h"
 
 class CFX_Matrix;
diff --git a/fpdfsdk/cpdfsdk_formfillenvironment.cpp b/fpdfsdk/cpdfsdk_formfillenvironment.cpp
old mode 100755
new mode 100644
index 53bc723..49d83c0
--- a/fpdfsdk/cpdfsdk_formfillenvironment.cpp
+++ b/fpdfsdk/cpdfsdk_formfillenvironment.cpp
@@ -12,13 +12,13 @@
 #include "core/fpdfapi/parser/cpdf_array.h"
 #include "core/fpdfapi/parser/cpdf_dictionary.h"
 #include "core/fpdfdoc/cpdf_docjsactions.h"
-#include "fpdfsdk/cfx_systemhandler.h"
 #include "fpdfsdk/cpdfsdk_actionhandler.h"
 #include "fpdfsdk/cpdfsdk_annothandlermgr.h"
 #include "fpdfsdk/cpdfsdk_helpers.h"
 #include "fpdfsdk/cpdfsdk_interactiveform.h"
 #include "fpdfsdk/cpdfsdk_pageview.h"
 #include "fpdfsdk/cpdfsdk_widget.h"
+#include "fpdfsdk/formfiller/cffl_formfiller.h"
 #include "fpdfsdk/formfiller/cffl_interactiveformfiller.h"
 #include "fxjs/ijs_runtime.h"
 #include "third_party/base/ptr_util.h"
@@ -39,9 +39,7 @@
 CPDFSDK_FormFillEnvironment::CPDFSDK_FormFillEnvironment(
     CPDF_Document* pDoc,
     FPDF_FORMFILLINFO* pFFinfo)
-    : m_pInfo(pFFinfo),
-      m_pCPDFDoc(pDoc),
-      m_pSysHandler(pdfium::MakeUnique<CFX_SystemHandler>(this)) {}
+    : m_pInfo(pFFinfo), m_pCPDFDoc(pDoc) {}
 
 CPDFSDK_FormFillEnvironment::~CPDFSDK_FormFillEnvironment() {
   m_bBeingDestroyed = true;
@@ -64,6 +62,47 @@
     m_pInfo->Release(m_pInfo);
 }
 
+void CPDFSDK_FormFillEnvironment::InvalidateRect(PerWindowData* pWidgetData,
+                                                 const CFX_FloatRect& rect) {
+  auto* pPrivateData = static_cast<CFFL_PrivateData*>(pWidgetData);
+  CPDFSDK_Widget* widget = pPrivateData->pWidget.Get();
+  if (!widget)
+    return;
+
+  CPDFSDK_PageView* pPageView = widget->GetPageView();
+  IPDF_Page* pPage = widget->GetPage();
+  if (!pPage || !pPageView)
+    return;
+
+  CFX_Matrix device2page = pPageView->GetCurrentMatrix().GetInverse();
+  CFX_PointF left_top = device2page.Transform(CFX_PointF(rect.left, rect.top));
+  CFX_PointF right_bottom =
+      device2page.Transform(CFX_PointF(rect.right, rect.bottom));
+
+  CFX_FloatRect rcPDF(left_top.x, right_bottom.y, right_bottom.x, left_top.y);
+  rcPDF.Normalize();
+  Invalidate(pPage, rcPDF.GetOuterRect());
+}
+
+void CPDFSDK_FormFillEnvironment::OutputSelectedRect(
+    CFFL_FormFiller* pFormFiller,
+    const CFX_FloatRect& rect) {
+  if (!pFormFiller || !m_pInfo || !m_pInfo->FFI_OutputSelectedRect)
+    return;
+
+  auto* pPage = FPDFPageFromIPDFPage(pFormFiller->GetSDKAnnot()->GetPage());
+  ASSERT(pPage);
+
+  CFX_PointF ptA = pFormFiller->PWLtoFFL(CFX_PointF(rect.left, rect.bottom));
+  CFX_PointF ptB = pFormFiller->PWLtoFFL(CFX_PointF(rect.right, rect.top));
+  m_pInfo->FFI_OutputSelectedRect(m_pInfo, pPage, ptA.x, ptB.y, ptB.x, ptA.y);
+}
+
+bool CPDFSDK_FormFillEnvironment::IsSelectionImplemented() const {
+  FPDF_FORMFILLINFO* pInfo = GetFormFillInfo();
+  return pInfo && pInfo->FFI_OutputSelectedRect;
+}
+
 #ifdef PDF_ENABLE_V8
 int CPDFSDK_FormFillEnvironment::JS_appAlert(const WideString& Msg,
                                              const WideString& Title,
@@ -244,16 +283,6 @@
   }
 }
 
-void CPDFSDK_FormFillEnvironment::OutputSelectedRect(
-    IPDF_Page* page,
-    const CFX_FloatRect& rect) {
-  if (m_pInfo && m_pInfo->FFI_OutputSelectedRect) {
-    m_pInfo->FFI_OutputSelectedRect(m_pInfo, FPDFPageFromIPDFPage(page),
-                                    rect.left, rect.top, rect.right,
-                                    rect.bottom);
-  }
-}
-
 void CPDFSDK_FormFillEnvironment::SetCursor(int nCursorType) {
   if (m_pInfo && m_pInfo->FFI_SetCursor)
     m_pInfo->FFI_SetCursor(m_pInfo, nCursorType);
@@ -263,7 +292,7 @@
                                           TimerCallback lpTimerFunc) {
   if (m_pInfo && m_pInfo->FFI_SetTimer)
     return m_pInfo->FFI_SetTimer(m_pInfo, uElapse, lpTimerFunc);
-  return CFX_SystemHandler::kInvalidTimerID;
+  return TimerHandlerIface::kInvalidTimerID;
 }
 
 void CPDFSDK_FormFillEnvironment::KillTimer(int nTimerID) {
diff --git a/fpdfsdk/cpdfsdk_formfillenvironment.h b/fpdfsdk/cpdfsdk_formfillenvironment.h
index 48a0ec6..9453cd2 100644
--- a/fpdfsdk/cpdfsdk_formfillenvironment.h
+++ b/fpdfsdk/cpdfsdk_formfillenvironment.h
@@ -15,8 +15,9 @@
 #include "core/fpdfapi/page/cpdf_page.h"
 #include "core/fpdfapi/parser/cpdf_document.h"
 #include "core/fxcrt/observed_ptr.h"
-#include "fpdfsdk/cfx_systemhandler.h"
+#include "core/fxcrt/timerhandler_iface.h"
 #include "fpdfsdk/cpdfsdk_annot.h"
+#include "fpdfsdk/pwl/ipwl_systemhandler.h"
 #include "public/fpdf_formfill.h"
 
 class CFFL_InteractiveFormFiller;
@@ -45,10 +46,24 @@
 // hierarcy back to the form fill environment itself, so as to flag any
 // lingering lifetime issues via the memory tools.
 
-class CPDFSDK_FormFillEnvironment final : public Observable {
+class CPDFSDK_FormFillEnvironment final : public Observable,
+                                          public TimerHandlerIface,
+                                          public IPWL_SystemHandler {
  public:
   CPDFSDK_FormFillEnvironment(CPDF_Document* pDoc, FPDF_FORMFILLINFO* pFFinfo);
-  ~CPDFSDK_FormFillEnvironment();
+  ~CPDFSDK_FormFillEnvironment() override;
+
+  // TimerHandlerIface:
+  int32_t SetTimer(int32_t uElapse, TimerCallback lpTimerFunc) override;
+  void KillTimer(int32_t nID) override;
+
+  // IPWL_SystemHandler:
+  void InvalidateRect(PerWindowData* pWidgetData,
+                      const CFX_FloatRect& rect) override;
+  void OutputSelectedRect(CFFL_FormFiller* pFormFiller,
+                          const CFX_FloatRect& rect) override;
+  bool IsSelectionImplemented() const override;
+  void SetCursor(int32_t nCursorType) override;
 
   CPDFSDK_PageView* GetPageView(IPDF_Page* pUnderlyingPage, bool renew);
   CPDFSDK_PageView* GetPageView(int nIndex);
@@ -81,13 +96,7 @@
 
   void ProcJavascriptFun();
   bool ProcOpenAction();
-
   void Invalidate(IPDF_Page* page, const FX_RECT& rect);
-  void OutputSelectedRect(IPDF_Page* page, const CFX_FloatRect& rect);
-
-  void SetCursor(int nCursorType);
-  int SetTimer(int uElapse, TimerCallback lpTimerFunc);
-  void KillTimer(int nTimerID);
 
 #ifdef PDF_ENABLE_V8
   FPDF_PAGE GetCurrentPage() const;
@@ -197,8 +206,8 @@
   void JS_docSubmitForm(void* formData, int length, const WideString& URL);
 
   ByteString GetAppName() const { return ByteString(); }
-  TimerHandlerIface* GetTimerHandler() const { return m_pSysHandler.get(); }
-  IPWL_SystemHandler* GetSysHandler() const { return m_pSysHandler.get(); }
+  TimerHandlerIface* GetTimerHandler() { return this; }
+  IPWL_SystemHandler* GetSysHandler() { return this; }
   FPDF_FORMFILLINFO* GetFormFillInfo() const { return m_pInfo; }
 
   // Creates if not present.
@@ -220,7 +229,6 @@
   ObservedPtr<CPDFSDK_Annot> m_pFocusAnnot;
   UnownedPtr<CPDF_Document> const m_pCPDFDoc;
   std::unique_ptr<CFFL_InteractiveFormFiller> m_pFormFiller;
-  std::unique_ptr<CFX_SystemHandler> m_pSysHandler;
   bool m_bChangeMask = false;
   bool m_bBeingDestroyed = false;
 };