| OLD | NEW |
| 1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | 6 |
| 7 #ifndef FPDFSDK_JAVASCRIPT_JS_OBJECT_H_ | 7 #ifndef FPDFSDK_JAVASCRIPT_JS_OBJECT_H_ |
| 8 #define FPDFSDK_JAVASCRIPT_JS_OBJECT_H_ | 8 #define FPDFSDK_JAVASCRIPT_JS_OBJECT_H_ |
| 9 | 9 |
| 10 #include <map> | 10 #include <map> |
| 11 #include <memory> | 11 #include <memory> |
| 12 | 12 |
| 13 #include "fpdfsdk/include/fsdk_define.h" | 13 #include "fpdfsdk/include/fsdk_define.h" |
| 14 #include "fpdfsdk/javascript/cjs_runtime.h" | 14 #include "fpdfsdk/javascript/cjs_runtime.h" |
| 15 #include "fxjs/include/fxjs_v8.h" | 15 #include "fxjs/include/fxjs_v8.h" |
| 16 | 16 |
| 17 class CJS_Context; | 17 class CJS_Context; |
| 18 class CJS_Object; | 18 class CJS_Object; |
| 19 class CJS_Timer; | |
| 20 class CPDFDoc_Environment; | 19 class CPDFDoc_Environment; |
| 21 | 20 |
| 22 class CJS_EmbedObj { | 21 class CJS_EmbedObj { |
| 23 public: | 22 public: |
| 24 explicit CJS_EmbedObj(CJS_Object* pJSObject); | 23 explicit CJS_EmbedObj(CJS_Object* pJSObject); |
| 25 virtual ~CJS_EmbedObj(); | 24 virtual ~CJS_EmbedObj(); |
| 26 | 25 |
| 27 virtual void TimerProc(CJS_Timer* pTimer) {} | |
| 28 virtual void CancelProc(CJS_Timer* pTimer) {} | |
| 29 | |
| 30 CJS_Object* GetJSObject() const { return m_pJSObject; } | 26 CJS_Object* GetJSObject() const { return m_pJSObject; } |
| 31 | 27 |
| 32 int MsgBox(CPDFDoc_Environment* pApp, | 28 int MsgBox(CPDFDoc_Environment* pApp, |
| 33 const FX_WCHAR* swMsg, | 29 const FX_WCHAR* swMsg, |
| 34 const FX_WCHAR* swTitle, | 30 const FX_WCHAR* swTitle, |
| 35 FX_UINT nType, | 31 FX_UINT nType, |
| 36 FX_UINT nIcon); | 32 FX_UINT nIcon); |
| 37 void Alert(CJS_Context* pContext, const FX_WCHAR* swMsg); | 33 void Alert(CJS_Context* pContext, const FX_WCHAR* swMsg); |
| 38 | 34 |
| 39 protected: | 35 protected: |
| (...skipping 20 matching lines...) Expand all Loading... |
| 60 static void Alert(CJS_Context* pContext, const FX_WCHAR* swMsg); | 56 static void Alert(CJS_Context* pContext, const FX_WCHAR* swMsg); |
| 61 | 57 |
| 62 v8::Isolate* GetIsolate() { return m_pIsolate; } | 58 v8::Isolate* GetIsolate() { return m_pIsolate; } |
| 63 | 59 |
| 64 protected: | 60 protected: |
| 65 std::unique_ptr<CJS_EmbedObj> m_pEmbedObj; | 61 std::unique_ptr<CJS_EmbedObj> m_pEmbedObj; |
| 66 v8::Global<v8::Object> m_pV8Object; | 62 v8::Global<v8::Object> m_pV8Object; |
| 67 v8::Isolate* m_pIsolate; | 63 v8::Isolate* m_pIsolate; |
| 68 }; | 64 }; |
| 69 | 65 |
| 70 class CJS_Timer : public CJS_Runtime::Observer { | |
| 71 public: | |
| 72 CJS_Timer(CJS_EmbedObj* pObj, | |
| 73 CPDFDoc_Environment* pApp, | |
| 74 CJS_Runtime* pRuntime, | |
| 75 int nType, | |
| 76 const CFX_WideString& script, | |
| 77 uint32_t dwElapse, | |
| 78 uint32_t dwTimeOut); | |
| 79 ~CJS_Timer() override; | |
| 80 | |
| 81 static void Trigger(int nTimerID); | |
| 82 static void Cancel(int nTimerID); | |
| 83 | |
| 84 bool IsOneShot() const { return m_nType == 1; } | |
| 85 uint32_t GetTimeOut() const { return m_dwTimeOut; } | |
| 86 int GetTimerID() const { return m_nTimerID; } | |
| 87 CJS_Runtime* GetRuntime() const { return m_bValid ? m_pRuntime : nullptr; } | |
| 88 CFX_WideString GetJScript() const { return m_swJScript; } | |
| 89 | |
| 90 private: | |
| 91 using TimerMap = std::map<FX_UINT, CJS_Timer*>; | |
| 92 static TimerMap* GetGlobalTimerMap(); | |
| 93 | |
| 94 // CJS_Runtime::Observer | |
| 95 void OnDestroyed() override; | |
| 96 | |
| 97 uint32_t m_nTimerID; | |
| 98 CJS_EmbedObj* const m_pEmbedObj; | |
| 99 bool m_bProcessing; | |
| 100 bool m_bValid; | |
| 101 | |
| 102 // data | |
| 103 const int m_nType; // 0:Interval; 1:TimeOut | |
| 104 const uint32_t m_dwTimeOut; | |
| 105 const CFX_WideString m_swJScript; | |
| 106 CJS_Runtime* const m_pRuntime; | |
| 107 CPDFDoc_Environment* const m_pApp; | |
| 108 }; | |
| 109 | 66 |
| 110 #endif // FPDFSDK_JAVASCRIPT_JS_OBJECT_H_ | 67 #endif // FPDFSDK_JAVASCRIPT_JS_OBJECT_H_ |
| OLD | NEW |