Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(368)

Side by Side Diff: fpdfsdk/include/javascript/JS_Object.h

Issue 1386053002: Merge to XFA: CJS_Timer should observe CJS_Runtime destruction. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@xfa
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | fpdfsdk/include/javascript/JS_Runtime.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_INCLUDE_JAVASCRIPT_JS_OBJECT_H_ 7 #ifndef FPDFSDK_INCLUDE_JAVASCRIPT_JS_OBJECT_H_
8 #define FPDFSDK_INCLUDE_JAVASCRIPT_JS_OBJECT_H_ 8 #define FPDFSDK_INCLUDE_JAVASCRIPT_JS_OBJECT_H_
9 9
10 #include <map> 10 #include <map>
11 11
12 #include "../../../third_party/base/nonstd_unique_ptr.h" 12 #include "../../../third_party/base/nonstd_unique_ptr.h"
13 13
14 #include "../fsdk_define.h" // For FX_UINT 14 #include "../fsdk_define.h" // For FX_UINT
15 #include "../fsdk_mgr.h" // For CPDFDoc_Environment 15 #include "../fsdk_mgr.h" // For CPDFDoc_Environment
16 #include "../fx_systemhandler.h" // For IFX_SystemHandler 16 #include "../fx_systemhandler.h" // For IFX_SystemHandler
17 #include "../jsapi/fxjs_v8.h" 17 #include "../jsapi/fxjs_v8.h"
18 #include "JS_Runtime.h"
18 19
19 class CPDFSDK_PageView; 20 class CPDFSDK_PageView;
20 class CJS_Context; 21 class CJS_Context;
21 class CJS_Object; 22 class CJS_Object;
22 class CJS_Runtime;
23 class CJS_Timer; 23 class CJS_Timer;
24 24
25 class CJS_EmbedObj { 25 class CJS_EmbedObj {
26 public: 26 public:
27 explicit CJS_EmbedObj(CJS_Object* pJSObject); 27 explicit CJS_EmbedObj(CJS_Object* pJSObject);
28 virtual ~CJS_EmbedObj(); 28 virtual ~CJS_EmbedObj();
29 29
30 virtual void TimerProc(CJS_Timer* pTimer) {} 30 virtual void TimerProc(CJS_Timer* pTimer) {}
31 CJS_Timer* BeginTimer(CPDFDoc_Environment* pApp, FX_UINT nElapse);
32 void EndTimer(CJS_Timer* pTimer);
33 31
34 CJS_Object* GetJSObject() const { return m_pJSObject; } 32 CJS_Object* GetJSObject() const { return m_pJSObject; }
35 33
36 CPDFSDK_PageView* JSGetPageView(IFXJS_Context* cc); 34 CPDFSDK_PageView* JSGetPageView(IFXJS_Context* cc);
37 int MsgBox(CPDFDoc_Environment* pApp, 35 int MsgBox(CPDFDoc_Environment* pApp,
38 CPDFSDK_PageView* pPageView, 36 CPDFSDK_PageView* pPageView,
39 const FX_WCHAR* swMsg, 37 const FX_WCHAR* swMsg,
40 const FX_WCHAR* swTitle = NULL, 38 const FX_WCHAR* swTitle = NULL,
41 FX_UINT nType = 0, 39 FX_UINT nType = 0,
42 FX_UINT nIcon = 0); 40 FX_UINT nIcon = 0);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 static void Alert(CJS_Context* pContext, const FX_WCHAR* swMsg); 74 static void Alert(CJS_Context* pContext, const FX_WCHAR* swMsg);
77 75
78 v8::Isolate* GetIsolate() { return m_pIsolate; } 76 v8::Isolate* GetIsolate() { return m_pIsolate; }
79 77
80 protected: 78 protected:
81 nonstd::unique_ptr<CJS_EmbedObj> m_pEmbedObj; 79 nonstd::unique_ptr<CJS_EmbedObj> m_pEmbedObj;
82 v8::Global<v8::Object> m_pV8Object; 80 v8::Global<v8::Object> m_pV8Object;
83 v8::Isolate* m_pIsolate; 81 v8::Isolate* m_pIsolate;
84 }; 82 };
85 83
86 class CJS_Timer { 84 class CJS_Timer : public CJS_Runtime::Observer {
87 public: 85 public:
88 CJS_Timer(CJS_EmbedObj* pObj, CPDFDoc_Environment* pApp) 86 CJS_Timer(CJS_EmbedObj* pObj,
89 : m_nTimerID(0), 87 CPDFDoc_Environment* pApp,
90 m_pEmbedObj(pObj), 88 CJS_Runtime* pRuntime,
91 m_bProcessing(FALSE), 89 int nType,
92 m_dwStartTime(0), 90 const CFX_WideString& script,
93 m_dwTimeOut(0), 91 FX_DWORD dwElapse,
94 m_dwElapse(0), 92 FX_DWORD dwTimeOut);
95 m_pRuntime(NULL), 93 ~CJS_Timer() override;
96 m_nType(0),
97 m_pApp(pApp) {}
98 94
99 virtual ~CJS_Timer() { KillJSTimer(); }
100
101 public:
102 FX_UINT SetJSTimer(FX_UINT nElapse);
103 void KillJSTimer(); 95 void KillJSTimer();
104 96
105 void SetType(int nType) { m_nType = nType; }
106 int GetType() const { return m_nType; } 97 int GetType() const { return m_nType; }
107
108 void SetStartTime(FX_DWORD dwStartTime) { m_dwStartTime = dwStartTime; }
109 FX_DWORD GetStartTime() const { return m_dwStartTime; }
110
111 void SetTimeOut(FX_DWORD dwTimeOut) { m_dwTimeOut = dwTimeOut; }
112 FX_DWORD GetTimeOut() const { return m_dwTimeOut; } 98 FX_DWORD GetTimeOut() const { return m_dwTimeOut; }
113 99 CJS_Runtime* GetRuntime() const { return m_bValid ? m_pRuntime : nullptr; }
114 void SetRuntime(CJS_Runtime* pRuntime) { m_pRuntime = pRuntime; }
115 CJS_Runtime* GetRuntime() const { return m_pRuntime; }
116
117 void SetJScript(const CFX_WideString& script) { m_swJScript = script; }
118 CFX_WideString GetJScript() const { return m_swJScript; } 100 CFX_WideString GetJScript() const { return m_swJScript; }
119 101
120 static void TimerProc(int idEvent); 102 static void TimerProc(int idEvent);
121 103
122 private: 104 private:
123 using TimerMap = std::map<FX_UINT, CJS_Timer*>; 105 using TimerMap = std::map<FX_UINT, CJS_Timer*>;
124 static TimerMap* GetGlobalTimerMap(); 106 static TimerMap* GetGlobalTimerMap();
125 107
126 FX_UINT m_nTimerID; 108 // CJS_Runtime::Observer
127 CJS_EmbedObj* m_pEmbedObj; 109 void OnDestroyed() override;
128 FX_BOOL m_bProcessing; 110
111 FX_DWORD m_nTimerID;
112 CJS_EmbedObj* const m_pEmbedObj;
113 bool m_bProcessing;
114 bool m_bValid;
129 115
130 // data 116 // data
131 FX_DWORD m_dwStartTime; 117 const int m_nType; // 0:Interval; 1:TimeOut
132 FX_DWORD m_dwTimeOut; 118 const FX_DWORD m_dwTimeOut;
133 FX_DWORD m_dwElapse; 119 const CFX_WideString m_swJScript;
134 CJS_Runtime* m_pRuntime; 120 CJS_Runtime* const m_pRuntime;
135 CFX_WideString m_swJScript; 121 CPDFDoc_Environment* const m_pApp;
136 int m_nType; // 0:Interval; 1:TimeOut
137
138 CPDFDoc_Environment* m_pApp;
139 }; 122 };
140 123
141 #endif // FPDFSDK_INCLUDE_JAVASCRIPT_JS_OBJECT_H_ 124 #endif // FPDFSDK_INCLUDE_JAVASCRIPT_JS_OBJECT_H_
OLDNEW
« no previous file with comments | « no previous file | fpdfsdk/include/javascript/JS_Runtime.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698