• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2017 The PDFium Authors
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 "core/fxcrt/unowned_ptr.h"
11 #include "fxjs/cjs_runtime.h"
12 
13 class CJS_App;
14 
15 class GlobalTimer {
16  public:
17   enum class Type : bool {
18     kRepeating = false,
19     kOneShot = true,
20   };
21 
22   static void InitializeGlobals();
23   static void DestroyGlobals();
24 
25   GlobalTimer(CJS_App* pObj,
26               CJS_Runtime* pRuntime,
27               Type nType,
28               const WideString& script,
29               uint32_t dwElapse,
30               uint32_t dwTimeOut);
31   ~GlobalTimer();
32 
33   static void Trigger(int32_t nTimerID);
34   static void Cancel(int32_t nTimerID);
35 
IsOneShot()36   bool IsOneShot() const { return m_nType == Type::kOneShot; }
GetTimeOut()37   uint32_t GetTimeOut() const { return m_dwTimeOut; }
GetTimerID()38   int32_t GetTimerID() const { return m_nTimerID; }
GetRuntime()39   CJS_Runtime* GetRuntime() const { return m_pRuntime.Get(); }
GetJScript()40   WideString GetJScript() const { return m_swJScript; }
41 
42  private:
43   bool HasValidID() const;
44 
45   const Type m_nType;
46   bool m_bProcessing = false;
47   const int32_t m_nTimerID;
48   const uint32_t m_dwTimeOut;
49   const WideString m_swJScript;
50   ObservedPtr<CJS_Runtime> m_pRuntime;
51   UnownedPtr<CJS_App> const m_pEmbedApp;
52 };
53 
54 #endif  // FXJS_GLOBAL_TIMER_H_
55