diff options
author | Dan Sinclair <dsinclair@chromium.org> | 2017-10-30 17:49:52 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-10-30 17:49:52 +0000 |
commit | c0858354f1e9ce1246b8af9ef2cd11623a1132dd (patch) | |
tree | 13db2ec010cdc05a8dd6f91cd06bbb0ccc6613f2 /fpdfsdk/javascript/global_timer.cpp | |
parent | a5c874c1240a0be86d6db0536940c1d0942b4c6d (diff) | |
download | pdfium-c0858354f1e9ce1246b8af9ef2cd11623a1132dd.tar.xz |
Rename app to cjs_app
This CL renames the app.{cpp|h} files to cjs_app.{cpp|h}. The
CJS_TimerObj and GlobalTimer objects have been moved to their own files.
Change-Id: I7a4063b212f1051b1517ec8902a0ee215854feaf
Reviewed-on: https://pdfium-review.googlesource.com/17040
Commit-Queue: dsinclair <dsinclair@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Diffstat (limited to 'fpdfsdk/javascript/global_timer.cpp')
-rw-r--r-- | fpdfsdk/javascript/global_timer.cpp | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/fpdfsdk/javascript/global_timer.cpp b/fpdfsdk/javascript/global_timer.cpp new file mode 100644 index 0000000000..8e30cf92f0 --- /dev/null +++ b/fpdfsdk/javascript/global_timer.cpp @@ -0,0 +1,80 @@ +// Copyright 2017 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "fpdfsdk/javascript/global_timer.h" + +GlobalTimer::GlobalTimer(app* pObj, + CPDFSDK_FormFillEnvironment* pFormFillEnv, + CJS_Runtime* pRuntime, + int nType, + const WideString& script, + uint32_t dwElapse, + uint32_t dwTimeOut) + : m_nTimerID(0), + m_pEmbedObj(pObj), + m_bProcessing(false), + m_nType(nType), + m_dwTimeOut(dwTimeOut), + m_swJScript(script), + m_pRuntime(pRuntime), + m_pFormFillEnv(pFormFillEnv) { + CFX_SystemHandler* pHandler = m_pFormFillEnv->GetSysHandler(); + m_nTimerID = pHandler->SetTimer(dwElapse, Trigger); + if (m_nTimerID) + (*GetGlobalTimerMap())[m_nTimerID] = this; +} + +GlobalTimer::~GlobalTimer() { + if (!m_nTimerID) + return; + + if (GetRuntime()) + m_pFormFillEnv->GetSysHandler()->KillTimer(m_nTimerID); + + GetGlobalTimerMap()->erase(m_nTimerID); +} + +// static +void GlobalTimer::Trigger(int nTimerID) { + auto it = GetGlobalTimerMap()->find(nTimerID); + if (it == GetGlobalTimerMap()->end()) + return; + + GlobalTimer* pTimer = it->second; + if (pTimer->m_bProcessing) + return; + + pTimer->m_bProcessing = true; + if (pTimer->m_pEmbedObj) + pTimer->m_pEmbedObj->TimerProc(pTimer); + + // Timer proc may have destroyed timer, find it again. + it = GetGlobalTimerMap()->find(nTimerID); + if (it == GetGlobalTimerMap()->end()) + return; + + pTimer = it->second; + pTimer->m_bProcessing = false; + if (pTimer->IsOneShot()) + pTimer->m_pEmbedObj->CancelProc(pTimer); +} + +// static +void GlobalTimer::Cancel(int nTimerID) { + auto it = GetGlobalTimerMap()->find(nTimerID); + if (it == GetGlobalTimerMap()->end()) + return; + + GlobalTimer* pTimer = it->second; + pTimer->m_pEmbedObj->CancelProc(pTimer); +} + +// static +GlobalTimer::TimerMap* GlobalTimer::GetGlobalTimerMap() { + // Leak the timer array at shutdown. + static auto* s_TimerMap = new TimerMap; + return s_TimerMap; +} |