blob: 8c63cebf17c9bfe2f193e78e67fc24bb62775dc7 [file] [log] [blame]
Dan Sinclairc0858352017-10-30 17:49:52 +00001// 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
Dan Sinclaire0345a42017-10-30 20:20:42 +00007#ifndef FXJS_GLOBAL_TIMER_H_
8#define FXJS_GLOBAL_TIMER_H_
Dan Sinclairc0858352017-10-30 17:49:52 +00009
Lei Zhang4c1ced52018-10-18 21:58:21 +000010#include "fpdfsdk/cpdfsdk_formfillenvironment.h"
11#include "fxjs/cjs_runtime.h"
12
13class CJS_App;
Dan Sinclairc0858352017-10-30 17:49:52 +000014
15class GlobalTimer {
16 public:
Lei Zhangde72ac42019-01-10 19:40:20 +000017 enum class Type : bool {
18 kRepeating = false,
19 kOneShot = true,
20 };
21
Dan Sinclairf7435522018-02-05 22:27:22 +000022 GlobalTimer(CJS_App* pObj,
Dan Sinclairc0858352017-10-30 17:49:52 +000023 CPDFSDK_FormFillEnvironment* pFormFillEnv,
24 CJS_Runtime* pRuntime,
Lei Zhangde72ac42019-01-10 19:40:20 +000025 Type nType,
Dan Sinclairc0858352017-10-30 17:49:52 +000026 const WideString& script,
27 uint32_t dwElapse,
28 uint32_t dwTimeOut);
29 ~GlobalTimer();
30
Lei Zhang5b166c02019-01-10 19:31:19 +000031 static void Trigger(int32_t nTimerID);
32 static void Cancel(int32_t nTimerID);
Dan Sinclairc0858352017-10-30 17:49:52 +000033
Lei Zhangde72ac42019-01-10 19:40:20 +000034 bool IsOneShot() const { return m_nType == Type::kOneShot; }
Dan Sinclairc0858352017-10-30 17:49:52 +000035 uint32_t GetTimeOut() const { return m_dwTimeOut; }
Lei Zhang5b166c02019-01-10 19:31:19 +000036 int32_t GetTimerID() const { return m_nTimerID; }
Dan Sinclairc0858352017-10-30 17:49:52 +000037 CJS_Runtime* GetRuntime() const { return m_pRuntime.Get(); }
38 WideString GetJScript() const { return m_swJScript; }
39
40 private:
Lei Zhangcb13a082019-01-10 19:34:49 +000041 bool HasValidID() const;
42
Lei Zhang5b166c02019-01-10 19:31:19 +000043 const int32_t m_nTimerID;
Dan Sinclairf7435522018-02-05 22:27:22 +000044 CJS_App* const m_pEmbedApp;
Lei Zhange3f18b22019-01-09 22:10:25 +000045 bool m_bProcessing = false;
Dan Sinclairc0858352017-10-30 17:49:52 +000046
47 // data
Lei Zhangde72ac42019-01-10 19:40:20 +000048 const Type m_nType;
Dan Sinclairc0858352017-10-30 17:49:52 +000049 const uint32_t m_dwTimeOut;
50 const WideString m_swJScript;
51 CJS_Runtime::ObservedPtr m_pRuntime;
52 CPDFSDK_FormFillEnvironment::ObservedPtr m_pFormFillEnv;
53};
54
Dan Sinclaire0345a42017-10-30 20:20:42 +000055#endif // FXJS_GLOBAL_TIMER_H_