| OLD | NEW |
| (Empty) |
| 1 // Copyright 2014 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 FPDFSDK_INCLUDE_JAVASCRIPT_JS_OBJECT_H_ | |
| 8 #define FPDFSDK_INCLUDE_JAVASCRIPT_JS_OBJECT_H_ | |
| 9 | |
| 10 #include <map> | |
| 11 | |
| 12 #include "../../../third_party/base/nonstd_unique_ptr.h" | |
| 13 | |
| 14 #include "../fsdk_define.h" // For FX_UINT | |
| 15 #include "../fsdk_mgr.h" // For CPDFDoc_Environment | |
| 16 #include "../fx_systemhandler.h" // For IFX_SystemHandler | |
| 17 #include "../jsapi/fxjs_v8.h" | |
| 18 #include "JS_Runtime.h" | |
| 19 | |
| 20 class CJS_Context; | |
| 21 class CJS_Object; | |
| 22 class CJS_Timer; | |
| 23 | |
| 24 class CJS_EmbedObj { | |
| 25 public: | |
| 26 explicit CJS_EmbedObj(CJS_Object* pJSObject); | |
| 27 virtual ~CJS_EmbedObj(); | |
| 28 | |
| 29 virtual void TimerProc(CJS_Timer* pTimer) {} | |
| 30 | |
| 31 CJS_Object* GetJSObject() const { return m_pJSObject; } | |
| 32 | |
| 33 int MsgBox(CPDFDoc_Environment* pApp, | |
| 34 const FX_WCHAR* swMsg, | |
| 35 const FX_WCHAR* swTitle, | |
| 36 FX_UINT nType, | |
| 37 FX_UINT nIcon); | |
| 38 void Alert(CJS_Context* pContext, const FX_WCHAR* swMsg); | |
| 39 | |
| 40 protected: | |
| 41 CJS_Object* m_pJSObject; | |
| 42 }; | |
| 43 | |
| 44 class CJS_Object { | |
| 45 public: | |
| 46 explicit CJS_Object(v8::Local<v8::Object> pObject); | |
| 47 virtual ~CJS_Object(); | |
| 48 | |
| 49 void MakeWeak(); | |
| 50 void Dispose(); | |
| 51 | |
| 52 virtual FX_BOOL IsType(const FX_CHAR* sClassName) { return TRUE; } | |
| 53 virtual CFX_ByteString GetClassName() { return ""; } | |
| 54 | |
| 55 virtual FX_BOOL InitInstance(IFXJS_Context* cc) { return TRUE; } | |
| 56 virtual FX_BOOL ExitInstance() { return TRUE; } | |
| 57 | |
| 58 v8::Local<v8::Object> ToV8Object() { return m_pV8Object.Get(m_pIsolate); } | |
| 59 | |
| 60 // Takes ownership of |pObj|. | |
| 61 void SetEmbedObject(CJS_EmbedObj* pObj) { m_pEmbedObj.reset(pObj); } | |
| 62 CJS_EmbedObj* GetEmbedObject() const { return m_pEmbedObj.get(); } | |
| 63 | |
| 64 static int MsgBox(CPDFDoc_Environment* pApp, | |
| 65 const FX_WCHAR* swMsg, | |
| 66 const FX_WCHAR* swTitle, | |
| 67 FX_UINT nType, | |
| 68 FX_UINT nIcon); | |
| 69 static void Alert(CJS_Context* pContext, const FX_WCHAR* swMsg); | |
| 70 | |
| 71 v8::Isolate* GetIsolate() { return m_pIsolate; } | |
| 72 | |
| 73 protected: | |
| 74 nonstd::unique_ptr<CJS_EmbedObj> m_pEmbedObj; | |
| 75 v8::Global<v8::Object> m_pV8Object; | |
| 76 v8::Isolate* m_pIsolate; | |
| 77 }; | |
| 78 | |
| 79 class CJS_Timer : public CJS_Runtime::Observer { | |
| 80 public: | |
| 81 CJS_Timer(CJS_EmbedObj* pObj, | |
| 82 CPDFDoc_Environment* pApp, | |
| 83 CJS_Runtime* pRuntime, | |
| 84 int nType, | |
| 85 const CFX_WideString& script, | |
| 86 FX_DWORD dwElapse, | |
| 87 FX_DWORD dwTimeOut); | |
| 88 ~CJS_Timer() override; | |
| 89 | |
| 90 void KillJSTimer(); | |
| 91 | |
| 92 int GetType() const { return m_nType; } | |
| 93 FX_DWORD GetTimeOut() const { return m_dwTimeOut; } | |
| 94 CJS_Runtime* GetRuntime() const { return m_bValid ? m_pRuntime : nullptr; } | |
| 95 CFX_WideString GetJScript() const { return m_swJScript; } | |
| 96 | |
| 97 static void TimerProc(int idEvent); | |
| 98 | |
| 99 private: | |
| 100 using TimerMap = std::map<FX_UINT, CJS_Timer*>; | |
| 101 static TimerMap* GetGlobalTimerMap(); | |
| 102 | |
| 103 // CJS_Runtime::Observer | |
| 104 void OnDestroyed() override; | |
| 105 | |
| 106 FX_DWORD m_nTimerID; | |
| 107 CJS_EmbedObj* const m_pEmbedObj; | |
| 108 bool m_bProcessing; | |
| 109 bool m_bValid; | |
| 110 | |
| 111 // data | |
| 112 const int m_nType; // 0:Interval; 1:TimeOut | |
| 113 const FX_DWORD m_dwTimeOut; | |
| 114 const CFX_WideString m_swJScript; | |
| 115 CJS_Runtime* const m_pRuntime; | |
| 116 CPDFDoc_Environment* const m_pApp; | |
| 117 }; | |
| 118 | |
| 119 #endif // FPDFSDK_INCLUDE_JAVASCRIPT_JS_OBJECT_H_ | |
| OLD | NEW |