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

Side by Side Diff: fpdfsdk/src/javascript/JS_Object.cpp

Issue 1384883002: CJS_Timer should observe CJS_Runtime destruction. (Closed) Base URL: https://pdfium.googlesource.com/pdfium@master
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 | « fpdfsdk/include/javascript/JS_Runtime.h ('k') | fpdfsdk/src/javascript/JS_Runtime.cpp » ('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 "../../include/javascript/JavaScript.h" 7 #include "../../include/javascript/JavaScript.h"
8 #include "../../include/javascript/IJavaScript.h" 8 #include "../../include/javascript/IJavaScript.h"
9 #include "../../include/javascript/JS_Define.h" 9 #include "../../include/javascript/JS_Define.h"
10 #include "../../include/javascript/JS_Object.h" 10 #include "../../include/javascript/JS_Object.h"
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 const FX_WCHAR* swTitle, 49 const FX_WCHAR* swTitle,
50 FX_UINT nType, 50 FX_UINT nType,
51 FX_UINT nIcon) { 51 FX_UINT nIcon) {
52 return FXJS_MsgBox(pApp, pPageView, swMsg, swTitle, nType, nIcon); 52 return FXJS_MsgBox(pApp, pPageView, swMsg, swTitle, nType, nIcon);
53 } 53 }
54 54
55 void CJS_EmbedObj::Alert(CJS_Context* pContext, const FX_WCHAR* swMsg) { 55 void CJS_EmbedObj::Alert(CJS_Context* pContext, const FX_WCHAR* swMsg) {
56 CJS_Object::Alert(pContext, swMsg); 56 CJS_Object::Alert(pContext, swMsg);
57 } 57 }
58 58
59 CJS_Timer* CJS_EmbedObj::BeginTimer(CPDFDoc_Environment* pApp,
60 FX_UINT nElapse) {
61 CJS_Timer* pTimer = new CJS_Timer(this, pApp);
62 pTimer->SetJSTimer(nElapse);
63
64 return pTimer;
65 }
66
67 void CJS_EmbedObj::EndTimer(CJS_Timer* pTimer) {
68 ASSERT(pTimer != NULL);
69 pTimer->KillJSTimer();
70 delete pTimer;
71 }
72
73 void FreeObject(const v8::WeakCallbackInfo<CJS_Object>& data) { 59 void FreeObject(const v8::WeakCallbackInfo<CJS_Object>& data) {
74 CJS_Object* pJSObj = data.GetParameter(); 60 CJS_Object* pJSObj = data.GetParameter();
75 pJSObj->ExitInstance(); 61 pJSObj->ExitInstance();
76 delete pJSObj; 62 delete pJSObj;
77 FXJS_FreePrivate(data.GetInternalField(0)); 63 FXJS_FreePrivate(data.GetInternalField(0));
78 } 64 }
79 65
80 void DisposeObject(const v8::WeakCallbackInfo<CJS_Object>& data) { 66 void DisposeObject(const v8::WeakCallbackInfo<CJS_Object>& data) {
81 CJS_Object* pJSObj = data.GetParameter(); 67 CJS_Object* pJSObj = data.GetParameter();
82 pJSObj->Dispose(); 68 pJSObj->Dispose();
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 void CJS_Object::Alert(CJS_Context* pContext, const FX_WCHAR* swMsg) { 102 void CJS_Object::Alert(CJS_Context* pContext, const FX_WCHAR* swMsg) {
117 ASSERT(pContext != NULL); 103 ASSERT(pContext != NULL);
118 104
119 if (pContext->IsMsgBoxEnabled()) { 105 if (pContext->IsMsgBoxEnabled()) {
120 CPDFDoc_Environment* pApp = pContext->GetReaderApp(); 106 CPDFDoc_Environment* pApp = pContext->GetReaderApp();
121 if (pApp) 107 if (pApp)
122 pApp->JS_appAlert(swMsg, NULL, 0, 3); 108 pApp->JS_appAlert(swMsg, NULL, 0, 3);
123 } 109 }
124 } 110 }
125 111
126 FX_UINT CJS_Timer::SetJSTimer(FX_UINT nElapse) { 112 CJS_Timer::CJS_Timer(CJS_EmbedObj* pObj,
127 if (m_nTimerID) 113 CPDFDoc_Environment* pApp,
128 KillJSTimer(); 114 CJS_Runtime* pRuntime,
115 int nType,
116 const CFX_WideString& script,
117 FX_DWORD dwElapse,
118 FX_DWORD dwTimeOut)
119 : m_nTimerID(0),
120 m_pEmbedObj(pObj),
121 m_bProcessing(false),
122 m_bValid(true),
123 m_nType(nType),
124 m_dwTimeOut(dwTimeOut),
125 m_pRuntime(pRuntime),
126 m_pApp(pApp) {
129 IFX_SystemHandler* pHandler = m_pApp->GetSysHandler(); 127 IFX_SystemHandler* pHandler = m_pApp->GetSysHandler();
130 m_nTimerID = pHandler->SetTimer(nElapse, TimerProc); 128 m_nTimerID = pHandler->SetTimer(dwElapse, TimerProc);
131 (*GetGlobalTimerMap())[m_nTimerID] = this; 129 (*GetGlobalTimerMap())[m_nTimerID] = this;
132 m_dwElapse = nElapse; 130 m_pRuntime->AddObserver(this);
133 return m_nTimerID; 131 }
132
133 CJS_Timer::~CJS_Timer() {
134 CJS_Runtime* pRuntime = GetRuntime();
135 if (pRuntime)
136 pRuntime->RemoveObserver(this);
137 KillJSTimer();
134 } 138 }
135 139
136 void CJS_Timer::KillJSTimer() { 140 void CJS_Timer::KillJSTimer() {
137 if (m_nTimerID) { 141 if (m_nTimerID) {
138 IFX_SystemHandler* pHandler = m_pApp->GetSysHandler(); 142 if (m_bValid) {
139 pHandler->KillTimer(m_nTimerID); 143 IFX_SystemHandler* pHandler = m_pApp->GetSysHandler();
144 pHandler->KillTimer(m_nTimerID);
145 }
140 GetGlobalTimerMap()->erase(m_nTimerID); 146 GetGlobalTimerMap()->erase(m_nTimerID);
141 m_nTimerID = 0; 147 m_nTimerID = 0;
142 } 148 }
143 } 149 }
144 150
145 // static 151 // static
146 void CJS_Timer::TimerProc(int idEvent) { 152 void CJS_Timer::TimerProc(int idEvent) {
147 const auto it = GetGlobalTimerMap()->find(idEvent); 153 const auto it = GetGlobalTimerMap()->find(idEvent);
148 if (it != GetGlobalTimerMap()->end()) { 154 if (it != GetGlobalTimerMap()->end()) {
149 CJS_Timer* pTimer = it->second; 155 CJS_Timer* pTimer = it->second;
150 if (!pTimer->m_bProcessing) { 156 if (!pTimer->m_bProcessing) {
151 pTimer->m_bProcessing = TRUE; 157 CFX_AutoRestorer<bool> scoped_processing(&pTimer->m_bProcessing);
158 pTimer->m_bProcessing = true;
152 if (pTimer->m_pEmbedObj) 159 if (pTimer->m_pEmbedObj)
153 pTimer->m_pEmbedObj->TimerProc(pTimer); 160 pTimer->m_pEmbedObj->TimerProc(pTimer);
154 pTimer->m_bProcessing = FALSE;
155 } 161 }
156 } 162 }
157 } 163 }
158 164
159 // static 165 // static
160 CJS_Timer::TimerMap* CJS_Timer::GetGlobalTimerMap() { 166 CJS_Timer::TimerMap* CJS_Timer::GetGlobalTimerMap() {
161 // Leak the timer array at shutdown. 167 // Leak the timer array at shutdown.
162 static auto* s_TimerMap = new TimerMap; 168 static auto* s_TimerMap = new TimerMap;
163 return s_TimerMap; 169 return s_TimerMap;
164 } 170 }
171
172 void CJS_Timer::OnDestroyed() {
173 m_bValid = false;
174 }
OLDNEW
« no previous file with comments | « fpdfsdk/include/javascript/JS_Runtime.h ('k') | fpdfsdk/src/javascript/JS_Runtime.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698