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

Side by Side Diff: fpdfsdk/javascript/app.cpp

Issue 2322743002: Replace CJS_Runtime::Observer with CFX_Runtime<CJS_Runtime>::Observer (Closed)
Patch Set: Order matters Created 4 years, 3 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 | « core/fxcrt/include/cfx_observable.h ('k') | fpdfsdk/javascript/cjs_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 #include "fpdfsdk/javascript/app.h" 7 #include "fpdfsdk/javascript/app.h"
8 8
9 #include <memory> 9 #include <memory>
10 #include <vector> 10 #include <vector>
(...skipping 12 matching lines...) Expand all
23 23
24 class GlobalTimer : public CJS_Runtime::Observer { 24 class GlobalTimer : public CJS_Runtime::Observer {
25 public: 25 public:
26 GlobalTimer(app* pObj, 26 GlobalTimer(app* pObj,
27 CPDFDoc_Environment* pApp, 27 CPDFDoc_Environment* pApp,
28 CJS_Runtime* pRuntime, 28 CJS_Runtime* pRuntime,
29 int nType, 29 int nType,
30 const CFX_WideString& script, 30 const CFX_WideString& script,
31 uint32_t dwElapse, 31 uint32_t dwElapse,
32 uint32_t dwTimeOut); 32 uint32_t dwTimeOut);
33 ~GlobalTimer() override; 33 ~GlobalTimer();
34 34
35 static void Trigger(int nTimerID); 35 static void Trigger(int nTimerID);
36 static void Cancel(int nTimerID); 36 static void Cancel(int nTimerID);
37 37
38 bool IsOneShot() const { return m_nType == 1; } 38 bool IsOneShot() const { return m_nType == 1; }
39 uint32_t GetTimeOut() const { return m_dwTimeOut; } 39 uint32_t GetTimeOut() const { return m_dwTimeOut; }
40 int GetTimerID() const { return m_nTimerID; } 40 int GetTimerID() const { return m_nTimerID; }
41 CJS_Runtime* GetRuntime() const { return m_bValid ? m_pRuntime : nullptr; } 41 CJS_Runtime* GetRuntime() const { return m_pRuntime; }
42 CFX_WideString GetJScript() const { return m_swJScript; } 42 CFX_WideString GetJScript() const { return m_swJScript; }
43 43
44 private: 44 private:
45 using TimerMap = std::map<FX_UINT, GlobalTimer*>; 45 using TimerMap = std::map<FX_UINT, GlobalTimer*>;
46 static TimerMap* GetGlobalTimerMap(); 46 static TimerMap* GetGlobalTimerMap();
47 47
48 // CJS_Runtime::Observer
49 void OnDestroyed() override;
50
51 uint32_t m_nTimerID; 48 uint32_t m_nTimerID;
52 app* const m_pEmbedObj; 49 app* const m_pEmbedObj;
53 bool m_bProcessing; 50 bool m_bProcessing;
54 bool m_bValid;
55 51
56 // data 52 // data
57 const int m_nType; // 0:Interval; 1:TimeOut 53 const int m_nType; // 0:Interval; 1:TimeOut
58 const uint32_t m_dwTimeOut; 54 const uint32_t m_dwTimeOut;
59 const CFX_WideString m_swJScript; 55 const CFX_WideString m_swJScript;
60 CJS_Runtime* const m_pRuntime; 56 CJS_Runtime* m_pRuntime;
61 CPDFDoc_Environment* const m_pApp; 57 CPDFDoc_Environment* const m_pApp;
62 }; 58 };
63 59
64 GlobalTimer::GlobalTimer(app* pObj, 60 GlobalTimer::GlobalTimer(app* pObj,
65 CPDFDoc_Environment* pApp, 61 CPDFDoc_Environment* pApp,
66 CJS_Runtime* pRuntime, 62 CJS_Runtime* pRuntime,
67 int nType, 63 int nType,
68 const CFX_WideString& script, 64 const CFX_WideString& script,
69 uint32_t dwElapse, 65 uint32_t dwElapse,
70 uint32_t dwTimeOut) 66 uint32_t dwTimeOut)
71 : m_nTimerID(0), 67 : m_nTimerID(0),
72 m_pEmbedObj(pObj), 68 m_pEmbedObj(pObj),
73 m_bProcessing(false), 69 m_bProcessing(false),
74 m_bValid(true),
75 m_nType(nType), 70 m_nType(nType),
76 m_dwTimeOut(dwTimeOut), 71 m_dwTimeOut(dwTimeOut),
77 m_swJScript(script), 72 m_swJScript(script),
78 m_pRuntime(pRuntime), 73 m_pRuntime(pRuntime),
79 m_pApp(pApp) { 74 m_pApp(pApp) {
80 CFX_SystemHandler* pHandler = m_pApp->GetSysHandler(); 75 CFX_SystemHandler* pHandler = m_pApp->GetSysHandler();
81 m_nTimerID = pHandler->SetTimer(dwElapse, Trigger); 76 m_nTimerID = pHandler->SetTimer(dwElapse, Trigger);
82 (*GetGlobalTimerMap())[m_nTimerID] = this; 77 (*GetGlobalTimerMap())[m_nTimerID] = this;
83 m_pRuntime->AddObserver(this); 78 SetWatchedPtr(&m_pRuntime);
84 } 79 }
85 80
86 GlobalTimer::~GlobalTimer() { 81 GlobalTimer::~GlobalTimer() {
87 CJS_Runtime* pRuntime = GetRuntime();
88 if (pRuntime)
89 pRuntime->RemoveObserver(this);
90
91 if (!m_nTimerID) 82 if (!m_nTimerID)
92 return; 83 return;
93 84
94 if (m_bValid) 85 if (GetRuntime())
95 m_pApp->GetSysHandler()->KillTimer(m_nTimerID); 86 m_pApp->GetSysHandler()->KillTimer(m_nTimerID);
96 87
97 GetGlobalTimerMap()->erase(m_nTimerID); 88 GetGlobalTimerMap()->erase(m_nTimerID);
98 } 89 }
99 90
100 // static 91 // static
101 void GlobalTimer::Trigger(int nTimerID) { 92 void GlobalTimer::Trigger(int nTimerID) {
102 auto it = GetGlobalTimerMap()->find(nTimerID); 93 auto it = GetGlobalTimerMap()->find(nTimerID);
103 if (it == GetGlobalTimerMap()->end()) 94 if (it == GetGlobalTimerMap()->end())
104 return; 95 return;
(...skipping 27 matching lines...) Expand all
132 pTimer->m_pEmbedObj->CancelProc(pTimer); 123 pTimer->m_pEmbedObj->CancelProc(pTimer);
133 } 124 }
134 125
135 // static 126 // static
136 GlobalTimer::TimerMap* GlobalTimer::GetGlobalTimerMap() { 127 GlobalTimer::TimerMap* GlobalTimer::GetGlobalTimerMap() {
137 // Leak the timer array at shutdown. 128 // Leak the timer array at shutdown.
138 static auto* s_TimerMap = new TimerMap; 129 static auto* s_TimerMap = new TimerMap;
139 return s_TimerMap; 130 return s_TimerMap;
140 } 131 }
141 132
142 void GlobalTimer::OnDestroyed() {
143 m_bValid = false;
144 }
145
146 BEGIN_JS_STATIC_CONST(CJS_TimerObj) 133 BEGIN_JS_STATIC_CONST(CJS_TimerObj)
147 END_JS_STATIC_CONST() 134 END_JS_STATIC_CONST()
148 135
149 BEGIN_JS_STATIC_PROP(CJS_TimerObj) 136 BEGIN_JS_STATIC_PROP(CJS_TimerObj)
150 END_JS_STATIC_PROP() 137 END_JS_STATIC_PROP()
151 138
152 BEGIN_JS_STATIC_METHOD(CJS_TimerObj) 139 BEGIN_JS_STATIC_METHOD(CJS_TimerObj)
153 END_JS_STATIC_METHOD() 140 END_JS_STATIC_METHOD()
154 141
155 IMPLEMENT_JS_CLASS(CJS_TimerObj, TimerObj) 142 IMPLEMENT_JS_CLASS(CJS_TimerObj, TimerObj)
(...skipping 677 matching lines...) Expand 10 before | Expand all | Expand 10 after
833 FX_BOOL app::media(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) { 820 FX_BOOL app::media(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) {
834 return FALSE; 821 return FALSE;
835 } 822 }
836 823
837 FX_BOOL app::execDialog(IJS_Context* cc, 824 FX_BOOL app::execDialog(IJS_Context* cc,
838 const std::vector<CJS_Value>& params, 825 const std::vector<CJS_Value>& params,
839 CJS_Value& vRet, 826 CJS_Value& vRet,
840 CFX_WideString& sError) { 827 CFX_WideString& sError) {
841 return TRUE; 828 return TRUE;
842 } 829 }
OLDNEW
« no previous file with comments | « core/fxcrt/include/cfx_observable.h ('k') | fpdfsdk/javascript/cjs_runtime.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698