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.
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
7 #ifndef FPDFSDK_INCLUDE_JAVASCRIPT_JS_OBJECT_H_
8 #define FPDFSDK_INCLUDE_JAVASCRIPT_JS_OBJECT_H_
12 #include "../../../third_party/base/nonstd_unique_ptr.h"
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"
19 class CPDFSDK_PageView;
27 explicit CJS_EmbedObj(CJS_Object* pJSObject);
28 virtual ~CJS_EmbedObj();
30 virtual void TimerProc(CJS_Timer* pTimer) {}
31 CJS_Timer* BeginTimer(CPDFDoc_Environment* pApp, FX_UINT nElapse);
32 void EndTimer(CJS_Timer* pTimer);
34 CJS_Object* GetJSObject() const { return m_pJSObject; }
36 CPDFSDK_PageView* JSGetPageView(IFXJS_Context* cc);
37 int MsgBox(CPDFDoc_Environment* pApp,
38 CPDFSDK_PageView* pPageView,
39 const FX_WCHAR* swMsg,
40 const FX_WCHAR* swTitle = NULL,
43 void Alert(CJS_Context* pContext, const FX_WCHAR* swMsg);
46 CJS_Object* m_pJSObject;
51 explicit CJS_Object(v8::Local<v8::Object> pObject);
52 virtual ~CJS_Object();
57 virtual FX_BOOL IsType(const FX_CHAR* sClassName) { return TRUE; }
58 virtual CFX_ByteString GetClassName() { return ""; }
60 virtual FX_BOOL InitInstance(IFXJS_Context* cc) { return TRUE; }
61 virtual FX_BOOL ExitInstance() { return TRUE; }
63 operator v8::Local<v8::Object>() {
64 return v8::Local<v8::Object>::New(m_pIsolate, m_pObject);
67 // Takes ownership of |pObj|.
68 void SetEmbedObject(CJS_EmbedObj* pObj) { m_pEmbedObj.reset(pObj); }
69 CJS_EmbedObj* GetEmbedObject() const { return m_pEmbedObj.get(); }
71 static CPDFSDK_PageView* JSGetPageView(IFXJS_Context* cc);
72 static int MsgBox(CPDFDoc_Environment* pApp,
73 CPDFSDK_PageView* pPageView,
74 const FX_WCHAR* swMsg,
75 const FX_WCHAR* swTitle = NULL,
78 static void Alert(CJS_Context* pContext, const FX_WCHAR* swMsg);
80 v8::Isolate* GetIsolate() { return m_pIsolate; }
83 nonstd::unique_ptr<CJS_EmbedObj> m_pEmbedObj;
84 v8::Global<v8::Object> m_pObject;
85 v8::Isolate* m_pIsolate;
90 CJS_Timer(CJS_EmbedObj* pObj, CPDFDoc_Environment* pApp)
101 virtual ~CJS_Timer() { KillJSTimer(); }
104 FX_UINT SetJSTimer(FX_UINT nElapse);
107 void SetType(int nType) { m_nType = nType; }
108 int GetType() const { return m_nType; }
110 void SetStartTime(FX_DWORD dwStartTime) { m_dwStartTime = dwStartTime; }
111 FX_DWORD GetStartTime() const { return m_dwStartTime; }
113 void SetTimeOut(FX_DWORD dwTimeOut) { m_dwTimeOut = dwTimeOut; }
114 FX_DWORD GetTimeOut() const { return m_dwTimeOut; }
116 void SetRuntime(CJS_Runtime* pRuntime) { m_pRuntime = pRuntime; }
117 CJS_Runtime* GetRuntime() const { return m_pRuntime; }
119 void SetJScript(const CFX_WideString& script) { m_swJScript = script; }
120 CFX_WideString GetJScript() const { return m_swJScript; }
122 static void TimerProc(int idEvent);
125 using TimerMap = std::map<FX_UINT, CJS_Timer*>;
126 static TimerMap* GetGlobalTimerMap();
129 CJS_EmbedObj* m_pEmbedObj;
130 FX_BOOL m_bProcessing;
133 FX_DWORD m_dwStartTime;
134 FX_DWORD m_dwTimeOut;
136 CJS_Runtime* m_pRuntime;
137 CFX_WideString m_swJScript;
138 int m_nType; // 0:Interval; 1:TimeOut
140 CPDFDoc_Environment* m_pApp;
143 #endif // FPDFSDK_INCLUDE_JAVASCRIPT_JS_OBJECT_H_