1 // Copyright 2017 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 
7 #ifndef FXJS_GLOBAL_TIMER_H_
8 #define FXJS_GLOBAL_TIMER_H_
9 
10 #include <map>
11 
12 #include "fxjs/cjs_app.h"
13 
14 class GlobalTimer {
15  public:
16   GlobalTimer(app* pObj,
17               CPDFSDK_FormFillEnvironment* pFormFillEnv,
18               CJS_Runtime* pRuntime,
19               int nType,
20               const WideString& script,
21               uint32_t dwElapse,
22               uint32_t dwTimeOut);
23   ~GlobalTimer();
24 
25   static void Trigger(int nTimerID);
26   static void Cancel(int nTimerID);
27 
28   bool IsOneShot() const { return m_nType == 1; }
29   uint32_t GetTimeOut() const { return m_dwTimeOut; }
30   int GetTimerID() const { return m_nTimerID; }
31   CJS_Runtime* GetRuntime() const { return m_pRuntime.Get(); }
32   WideString GetJScript() const { return m_swJScript; }
33 
34  private:
35   using TimerMap = std::map<uint32_t, GlobalTimer*>;
36   static TimerMap* GetGlobalTimerMap();
37 
38   uint32_t m_nTimerID;
39   app* const m_pEmbedObj;
40   bool m_bProcessing;
41 
42   // data
43   const int m_nType;  // 0:Interval; 1:TimeOut
44   const uint32_t m_dwTimeOut;
45   const WideString m_swJScript;
46   CJS_Runtime::ObservedPtr m_pRuntime;
47   CPDFSDK_FormFillEnvironment::ObservedPtr m_pFormFillEnv;
48 };
49 
50 #endif  // FXJS_GLOBAL_TIMER_H_
51