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

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

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