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

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

Issue 2222043002: Rename CJS_Timer to GlobalTimer and make private to app.cpp (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Fix comment in app.h 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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 65
66 void CJS_Object::InitInstance(IJS_Runtime* pIRuntime) {} 66 void CJS_Object::InitInstance(IJS_Runtime* pIRuntime) {}
67 67
68 void CJS_Object::ExitInstance() {} 68 void CJS_Object::ExitInstance() {}
69 69
70 void CJS_Object::Alert(CJS_Context* pContext, const FX_WCHAR* swMsg) { 70 void CJS_Object::Alert(CJS_Context* pContext, const FX_WCHAR* swMsg) {
71 CPDFDoc_Environment* pApp = pContext->GetReaderApp(); 71 CPDFDoc_Environment* pApp = pContext->GetReaderApp();
72 if (pApp) 72 if (pApp)
73 pApp->JS_appAlert(swMsg, nullptr, 0, 3); 73 pApp->JS_appAlert(swMsg, nullptr, 0, 3);
74 } 74 }
75
76 CJS_Timer::CJS_Timer(CJS_EmbedObj* pObj,
77 CPDFDoc_Environment* pApp,
78 CJS_Runtime* pRuntime,
79 int nType,
80 const CFX_WideString& script,
81 uint32_t dwElapse,
82 uint32_t dwTimeOut)
83 : m_nTimerID(0),
84 m_pEmbedObj(pObj),
85 m_bProcessing(false),
86 m_bValid(true),
87 m_nType(nType),
88 m_dwTimeOut(dwTimeOut),
89 m_swJScript(script),
90 m_pRuntime(pRuntime),
91 m_pApp(pApp) {
92 CFX_SystemHandler* pHandler = m_pApp->GetSysHandler();
93 m_nTimerID = pHandler->SetTimer(dwElapse, Trigger);
94 (*GetGlobalTimerMap())[m_nTimerID] = this;
95 m_pRuntime->AddObserver(this);
96 }
97
98 CJS_Timer::~CJS_Timer() {
99 CJS_Runtime* pRuntime = GetRuntime();
100 if (pRuntime)
101 pRuntime->RemoveObserver(this);
102
103 if (!m_nTimerID)
104 return;
105
106 if (m_bValid)
107 m_pApp->GetSysHandler()->KillTimer(m_nTimerID);
108
109 GetGlobalTimerMap()->erase(m_nTimerID);
110 }
111
112 // static
113 void CJS_Timer::Trigger(int nTimerID) {
114 auto it = GetGlobalTimerMap()->find(nTimerID);
115 if (it == GetGlobalTimerMap()->end())
116 return;
117
118 CJS_Timer* pTimer = it->second;
119 if (pTimer->m_bProcessing)
120 return;
121
122 pTimer->m_bProcessing = true;
123 if (pTimer->m_pEmbedObj)
124 pTimer->m_pEmbedObj->TimerProc(pTimer);
125
126 // Timer proc may have destroyed timer, find it again.
127 it = GetGlobalTimerMap()->find(nTimerID);
128 if (it == GetGlobalTimerMap()->end())
129 return;
130
131 pTimer = it->second;
132 pTimer->m_bProcessing = false;
133 if (pTimer->IsOneShot())
134 pTimer->m_pEmbedObj->CancelProc(pTimer);
135 }
136
137 // static
138 void CJS_Timer::Cancel(int nTimerID) {
139 auto it = GetGlobalTimerMap()->find(nTimerID);
140 if (it == GetGlobalTimerMap()->end())
141 return;
142
143 CJS_Timer* pTimer = it->second;
144 pTimer->m_pEmbedObj->CancelProc(pTimer);
145 }
146
147 // static
148 CJS_Timer::TimerMap* CJS_Timer::GetGlobalTimerMap() {
149 // Leak the timer array at shutdown.
150 static auto* s_TimerMap = new TimerMap;
151 return s_TimerMap;
152 }
153
154 void CJS_Timer::OnDestroyed() {
155 m_bValid = false;
156 }
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