Chromium Code Reviews| Index: fpdfsdk/javascript/JS_Object.cpp |
| diff --git a/fpdfsdk/javascript/JS_Object.cpp b/fpdfsdk/javascript/JS_Object.cpp |
| index 9ec316303dc3b4c0a2a8919ee92e04858365bad2..1c9abe06c6132935f78c126b380cb28eeed05e7d 100644 |
| --- a/fpdfsdk/javascript/JS_Object.cpp |
| +++ b/fpdfsdk/javascript/JS_Object.cpp |
| @@ -90,7 +90,7 @@ CJS_Timer::CJS_Timer(CJS_EmbedObj* pObj, |
| m_pRuntime(pRuntime), |
| m_pApp(pApp) { |
| CFX_SystemHandler* pHandler = m_pApp->GetSysHandler(); |
| - m_nTimerID = pHandler->SetTimer(dwElapse, TimerProc); |
| + m_nTimerID = pHandler->SetTimer(dwElapse, Trigger); |
| (*GetGlobalTimerMap())[m_nTimerID] = this; |
| m_pRuntime->AddObserver(this); |
| } |
| @@ -99,23 +99,19 @@ CJS_Timer::~CJS_Timer() { |
| CJS_Runtime* pRuntime = GetRuntime(); |
| if (pRuntime) |
| pRuntime->RemoveObserver(this); |
| - KillJSTimer(); |
| -} |
| -void CJS_Timer::KillJSTimer() { |
| - if (m_nTimerID) { |
| - if (m_bValid) { |
| - CFX_SystemHandler* pHandler = m_pApp->GetSysHandler(); |
| - pHandler->KillTimer(m_nTimerID); |
| - } |
| - GetGlobalTimerMap()->erase(m_nTimerID); |
| - m_nTimerID = 0; |
| - } |
| + if (!m_nTimerID) |
|
Lei Zhang
2016/08/05 22:29:54
I wonder if this can eval to true.
Tom Sepez
2016/08/05 23:11:42
Probably not. The CTOR sets this to zero, so if w
|
| + return; |
| + |
| + if (m_bValid) |
| + m_pApp->GetSysHandler()->KillTimer(m_nTimerID); |
| + |
| + GetGlobalTimerMap()->erase(m_nTimerID); |
| } |
| // static |
| -void CJS_Timer::TimerProc(int idEvent) { |
| - auto it = GetGlobalTimerMap()->find(idEvent); |
| +void CJS_Timer::Trigger(int nTimerID) { |
| + auto it = GetGlobalTimerMap()->find(nTimerID); |
| if (it == GetGlobalTimerMap()->end()) |
| return; |
| @@ -128,12 +124,24 @@ void CJS_Timer::TimerProc(int idEvent) { |
| pTimer->m_pEmbedObj->TimerProc(pTimer); |
| // Timer proc may have destroyed timer, find it again. |
| - it = GetGlobalTimerMap()->find(idEvent); |
| + it = GetGlobalTimerMap()->find(nTimerID); |
| if (it == GetGlobalTimerMap()->end()) |
| return; |
| pTimer = it->second; |
| pTimer->m_bProcessing = false; |
| + if (pTimer->IsOneTime()) |
| + pTimer->m_pEmbedObj->CancelProc(pTimer); |
| +} |
| + |
| +// static |
| +void CJS_Timer::Cancel(int nTimerID) { |
| + auto it = GetGlobalTimerMap()->find(nTimerID); |
| + if (it == GetGlobalTimerMap()->end()) |
| + return; |
| + |
| + CJS_Timer* pTimer = it->second; |
| + pTimer->m_pEmbedObj->CancelProc(pTimer); |
| } |
| // static |