From e0345a4aecfd16264d393234cf8fe22250d771fe Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Mon, 30 Oct 2017 20:20:42 +0000 Subject: Move fpdfsdk/javascript to fxjs/ This CL moves all of the CJS files into fxjs. The :javascript build rule is removed and :fxjs is used instead. Change-Id: I1701b308f51317d0346c7401b43812c3f43a27bf Reviewed-on: https://pdfium-review.googlesource.com/17047 Commit-Queue: dsinclair Reviewed-by: Tom Sepez --- fxjs/global_timer.cpp | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 fxjs/global_timer.cpp (limited to 'fxjs/global_timer.cpp') diff --git a/fxjs/global_timer.cpp b/fxjs/global_timer.cpp new file mode 100644 index 0000000000..6f7f09c673 --- /dev/null +++ b/fxjs/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 "fxjs/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; +} -- cgit v1.2.3