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

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

Issue 2251703003: Merge 2 CLs to M53. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@2785
Patch Set: Created 4 years, 4 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/javascript/JS_Object.h ('k') | fpdfsdk/javascript/app.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/JS_Object.h" 7 #include "fpdfsdk/javascript/JS_Object.h"
8 8
9 #include "fpdfsdk/include/fsdk_mgr.h" 9 #include "fpdfsdk/include/fsdk_mgr.h"
10 #include "fpdfsdk/javascript/JS_Define.h" 10 #include "fpdfsdk/javascript/JS_Define.h"
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 : m_nTimerID(0), 113 : m_nTimerID(0),
114 m_pEmbedObj(pObj), 114 m_pEmbedObj(pObj),
115 m_bProcessing(false), 115 m_bProcessing(false),
116 m_bValid(true), 116 m_bValid(true),
117 m_nType(nType), 117 m_nType(nType),
118 m_dwTimeOut(dwTimeOut), 118 m_dwTimeOut(dwTimeOut),
119 m_swJScript(script), 119 m_swJScript(script),
120 m_pRuntime(pRuntime), 120 m_pRuntime(pRuntime),
121 m_pApp(pApp) { 121 m_pApp(pApp) {
122 CFX_SystemHandler* pHandler = m_pApp->GetSysHandler(); 122 CFX_SystemHandler* pHandler = m_pApp->GetSysHandler();
123 m_nTimerID = pHandler->SetTimer(dwElapse, TimerProc); 123 m_nTimerID = pHandler->SetTimer(dwElapse, Trigger);
124 (*GetGlobalTimerMap())[m_nTimerID] = this; 124 (*GetGlobalTimerMap())[m_nTimerID] = this;
125 m_pRuntime->AddObserver(this); 125 m_pRuntime->AddObserver(this);
126 } 126 }
127 127
128 CJS_Timer::~CJS_Timer() { 128 CJS_Timer::~CJS_Timer() {
129 CJS_Runtime* pRuntime = GetRuntime(); 129 CJS_Runtime* pRuntime = GetRuntime();
130 if (pRuntime) 130 if (pRuntime)
131 pRuntime->RemoveObserver(this); 131 pRuntime->RemoveObserver(this);
132 KillJSTimer();
133 }
134 132
135 void CJS_Timer::KillJSTimer() { 133 if (!m_nTimerID)
136 if (m_nTimerID) { 134 return;
137 if (m_bValid) { 135
138 CFX_SystemHandler* pHandler = m_pApp->GetSysHandler(); 136 if (m_bValid)
139 pHandler->KillTimer(m_nTimerID); 137 m_pApp->GetSysHandler()->KillTimer(m_nTimerID);
140 } 138
141 GetGlobalTimerMap()->erase(m_nTimerID); 139 GetGlobalTimerMap()->erase(m_nTimerID);
142 m_nTimerID = 0;
143 }
144 } 140 }
145 141
146 // static 142 // static
147 void CJS_Timer::TimerProc(int idEvent) { 143 void CJS_Timer::Trigger(int nTimerID) {
148 auto it = GetGlobalTimerMap()->find(idEvent); 144 auto it = GetGlobalTimerMap()->find(nTimerID);
149 if (it == GetGlobalTimerMap()->end()) 145 if (it == GetGlobalTimerMap()->end())
150 return; 146 return;
151 147
152 CJS_Timer* pTimer = it->second; 148 CJS_Timer* pTimer = it->second;
153 if (pTimer->m_bProcessing) 149 if (pTimer->m_bProcessing)
154 return; 150 return;
155 151
156 pTimer->m_bProcessing = true; 152 pTimer->m_bProcessing = true;
157 if (pTimer->m_pEmbedObj) 153 if (pTimer->m_pEmbedObj)
158 pTimer->m_pEmbedObj->TimerProc(pTimer); 154 pTimer->m_pEmbedObj->TimerProc(pTimer);
159 155
160 // Timer proc may have destroyed timer, find it again. 156 // Timer proc may have destroyed timer, find it again.
161 it = GetGlobalTimerMap()->find(idEvent); 157 it = GetGlobalTimerMap()->find(nTimerID);
162 if (it == GetGlobalTimerMap()->end()) 158 if (it == GetGlobalTimerMap()->end())
163 return; 159 return;
164 160
165 pTimer = it->second; 161 pTimer = it->second;
166 pTimer->m_bProcessing = false; 162 pTimer->m_bProcessing = false;
163 if (pTimer->IsOneShot())
164 pTimer->m_pEmbedObj->CancelProc(pTimer);
167 } 165 }
168 166
169 // static 167 // static
168 void CJS_Timer::Cancel(int nTimerID) {
169 auto it = GetGlobalTimerMap()->find(nTimerID);
170 if (it == GetGlobalTimerMap()->end())
171 return;
172
173 CJS_Timer* pTimer = it->second;
174 pTimer->m_pEmbedObj->CancelProc(pTimer);
175 }
176
177 // static
170 CJS_Timer::TimerMap* CJS_Timer::GetGlobalTimerMap() { 178 CJS_Timer::TimerMap* CJS_Timer::GetGlobalTimerMap() {
171 // Leak the timer array at shutdown. 179 // Leak the timer array at shutdown.
172 static auto* s_TimerMap = new TimerMap; 180 static auto* s_TimerMap = new TimerMap;
173 return s_TimerMap; 181 return s_TimerMap;
174 } 182 }
175 183
176 void CJS_Timer::OnDestroyed() { 184 void CJS_Timer::OnDestroyed() {
177 m_bValid = false; 185 m_bValid = false;
178 } 186 }
OLDNEW
« no previous file with comments | « fpdfsdk/javascript/JS_Object.h ('k') | fpdfsdk/javascript/app.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698