Remove CPDFSDK_FormFillEnvironment from fxjs/global_timer.cpp

The lower-layer fxcrt::TimerHandlerIface is sufficient. CJS_Runtime,
however still references this object at the fxjs layer.

Change-Id: I37077301e1d2ea6283cdf14f2d78670c7eaadd3b
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/58951
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/fxjs/cjs_app.cpp b/fxjs/cjs_app.cpp
index 6459a00..3b79ced 100644
--- a/fxjs/cjs_app.cpp
+++ b/fxjs/cjs_app.cpp
@@ -310,8 +310,7 @@
 
   uint32_t dwInterval = params.size() > 1 ? pRuntime->ToInt32(params[1]) : 1000;
   auto timerRef = pdfium::MakeUnique<GlobalTimer>(
-      this, pRuntime->GetFormFillEnv(), pRuntime, GlobalTimer::Type::kRepeating,
-      script, dwInterval, 0);
+      this, pRuntime, GlobalTimer::Type::kRepeating, script, dwInterval, 0);
   GlobalTimer* pTimerRef = timerRef.get();
   m_Timers.insert(std::move(timerRef));
 
@@ -338,9 +337,9 @@
     return CJS_Result::Failure(JSMessage::kInvalidInputError);
 
   uint32_t dwTimeOut = params.size() > 1 ? pRuntime->ToInt32(params[1]) : 1000;
-  auto timerRef = pdfium::MakeUnique<GlobalTimer>(
-      this, pRuntime->GetFormFillEnv(), pRuntime, GlobalTimer::Type::kOneShot,
-      script, dwTimeOut, dwTimeOut);
+  auto timerRef = pdfium::MakeUnique<GlobalTimer>(this, pRuntime,
+                                                  GlobalTimer::Type::kOneShot,
+                                                  script, dwTimeOut, dwTimeOut);
   GlobalTimer* pTimerRef = timerRef.get();
   m_Timers.insert(std::move(timerRef));
 
diff --git a/fxjs/cjs_runtime.cpp b/fxjs/cjs_runtime.cpp
index e488c26..1cded27 100644
--- a/fxjs/cjs_runtime.cpp
+++ b/fxjs/cjs_runtime.cpp
@@ -142,6 +142,10 @@
                                      : m_EventContextArray.back().get();
 }
 
+TimerHandlerIface* CJS_Runtime::GetTimerHandler() const {
+  return m_pFormFillEnv ? m_pFormFillEnv->GetSysHandler() : nullptr;
+}
+
 void CJS_Runtime::SetFormFillEnvToDocument() {
   v8::Isolate::Scope isolate_scope(GetIsolate());
   v8::HandleScope handle_scope(GetIsolate());
diff --git a/fxjs/cjs_runtime.h b/fxjs/cjs_runtime.h
index 55eb766..4320c3d 100644
--- a/fxjs/cjs_runtime.h
+++ b/fxjs/cjs_runtime.h
@@ -13,12 +13,13 @@
 #include <vector>
 
 #include "core/fxcrt/observed_ptr.h"
-#include "fpdfsdk/cpdfsdk_formfillenvironment.h"
+#include "core/fxcrt/timerhandler_iface.h"
 #include "fxjs/cfxjs_engine.h"
 #include "fxjs/cjs_eventrecorder.h"
 #include "fxjs/ijs_runtime.h"
 
 class CJS_EventContext;
+class CPDFSDK_FormFillEnvironment;
 
 class CJS_Runtime final : public IJS_Runtime,
                           public CFXJS_Engine,
@@ -37,6 +38,7 @@
       const WideString& script) override;
 
   CJS_EventContext* GetCurrentEventContext() const;
+  TimerHandlerIface* GetTimerHandler() const;
 
   // Returns true if the event isn't already found in the set.
   bool AddEventToSet(const FieldEvent& event);
diff --git a/fxjs/global_timer.cpp b/fxjs/global_timer.cpp
index 88ea27b..75c0a42 100644
--- a/fxjs/global_timer.cpp
+++ b/fxjs/global_timer.cpp
@@ -23,19 +23,17 @@
 }  // namespace
 
 GlobalTimer::GlobalTimer(CJS_App* pObj,
-                         CPDFSDK_FormFillEnvironment* pFormFillEnv,
                          CJS_Runtime* pRuntime,
                          Type nType,
                          const WideString& script,
                          uint32_t dwElapse,
                          uint32_t dwTimeOut)
-    : m_nTimerID(pFormFillEnv->GetSysHandler()->SetTimer(dwElapse, Trigger)),
-      m_pEmbedApp(pObj),
-      m_nType(nType),
+    : m_nType(nType),
+      m_nTimerID(pRuntime->GetTimerHandler()->SetTimer(dwElapse, Trigger)),
       m_dwTimeOut(dwTimeOut),
       m_swJScript(script),
       m_pRuntime(pRuntime),
-      m_pFormFillEnv(pFormFillEnv) {
+      m_pEmbedApp(pObj) {
   if (HasValidID())
     (*GetGlobalTimerMap())[m_nTimerID] = this;
 }
@@ -44,8 +42,8 @@
   if (!HasValidID())
     return;
 
-  if (GetRuntime())
-    m_pFormFillEnv->GetSysHandler()->KillTimer(m_nTimerID);
+  if (m_pRuntime && m_pRuntime->GetTimerHandler())
+    m_pRuntime->GetTimerHandler()->KillTimer(m_nTimerID);
 
   GetGlobalTimerMap()->erase(m_nTimerID);
 }
@@ -86,5 +84,5 @@
 }
 
 bool GlobalTimer::HasValidID() const {
-  return m_nTimerID != CFX_SystemHandler::kInvalidTimerID;
+  return m_nTimerID != IPWL_SystemHandler::kInvalidTimerID;
 }
diff --git a/fxjs/global_timer.h b/fxjs/global_timer.h
index 0b8e8aa..ef6bbb6 100644
--- a/fxjs/global_timer.h
+++ b/fxjs/global_timer.h
@@ -7,7 +7,6 @@
 #ifndef FXJS_GLOBAL_TIMER_H_
 #define FXJS_GLOBAL_TIMER_H_
 
-#include "fpdfsdk/cpdfsdk_formfillenvironment.h"
 #include "fxjs/cjs_runtime.h"
 
 class CJS_App;
@@ -20,7 +19,6 @@
   };
 
   GlobalTimer(CJS_App* pObj,
-              CPDFSDK_FormFillEnvironment* pFormFillEnv,
               CJS_Runtime* pRuntime,
               Type nType,
               const WideString& script,
@@ -40,16 +38,13 @@
  private:
   bool HasValidID() const;
 
-  const int32_t m_nTimerID;
-  CJS_App* const m_pEmbedApp;
-  bool m_bProcessing = false;
-
-  // data
   const Type m_nType;
+  bool m_bProcessing = false;
+  const int32_t m_nTimerID;
   const uint32_t m_dwTimeOut;
   const WideString m_swJScript;
   ObservedPtr<CJS_Runtime> m_pRuntime;
-  ObservedPtr<CPDFSDK_FormFillEnvironment> m_pFormFillEnv;
+  CJS_App* const m_pEmbedApp;
 };
 
 #endif  // FXJS_GLOBAL_TIMER_H_