summaryrefslogtreecommitdiff
path: root/fpdfsdk/src/javascript/JS_Object.cpp
diff options
context:
space:
mode:
authorLei Zhang <thestig@chromium.org>2015-10-04 16:01:52 -0700
committerLei Zhang <thestig@chromium.org>2015-10-04 16:01:52 -0700
commit794c9b67d3d519342aa7e15052766f7d4a99f551 (patch)
treee21fdbf59ce171b978126b9f94e69085ff30d211 /fpdfsdk/src/javascript/JS_Object.cpp
parent4f277fc8d41303cbf007335dfbbff60b81fffde0 (diff)
downloadpdfium-794c9b67d3d519342aa7e15052766f7d4a99f551.tar.xz
CJS_Timer should observe CJS_Runtime destruction.
Also remove dead CJS_EmbedObj::{Begin,End}Timer code. BUG=539107 R=tsepez@chromium.org Review URL: https://codereview.chromium.org/1384883002 .
Diffstat (limited to 'fpdfsdk/src/javascript/JS_Object.cpp')
-rw-r--r--fpdfsdk/src/javascript/JS_Object.cpp58
1 files changed, 34 insertions, 24 deletions
diff --git a/fpdfsdk/src/javascript/JS_Object.cpp b/fpdfsdk/src/javascript/JS_Object.cpp
index 3cffec785d..7520a99778 100644
--- a/fpdfsdk/src/javascript/JS_Object.cpp
+++ b/fpdfsdk/src/javascript/JS_Object.cpp
@@ -56,20 +56,6 @@ void CJS_EmbedObj::Alert(CJS_Context* pContext, const FX_WCHAR* swMsg) {
CJS_Object::Alert(pContext, swMsg);
}
-CJS_Timer* CJS_EmbedObj::BeginTimer(CPDFDoc_Environment* pApp,
- FX_UINT nElapse) {
- CJS_Timer* pTimer = new CJS_Timer(this, pApp);
- pTimer->SetJSTimer(nElapse);
-
- return pTimer;
-}
-
-void CJS_EmbedObj::EndTimer(CJS_Timer* pTimer) {
- ASSERT(pTimer != NULL);
- pTimer->KillJSTimer();
- delete pTimer;
-}
-
void FreeObject(const v8::WeakCallbackInfo<CJS_Object>& data) {
CJS_Object* pJSObj = data.GetParameter();
pJSObj->ExitInstance();
@@ -123,20 +109,40 @@ void CJS_Object::Alert(CJS_Context* pContext, const FX_WCHAR* swMsg) {
}
}
-FX_UINT CJS_Timer::SetJSTimer(FX_UINT nElapse) {
- if (m_nTimerID)
- KillJSTimer();
+CJS_Timer::CJS_Timer(CJS_EmbedObj* pObj,
+ CPDFDoc_Environment* pApp,
+ CJS_Runtime* pRuntime,
+ int nType,
+ const CFX_WideString& script,
+ FX_DWORD dwElapse,
+ FX_DWORD dwTimeOut)
+ : m_nTimerID(0),
+ m_pEmbedObj(pObj),
+ m_bProcessing(false),
+ m_bValid(true),
+ m_nType(nType),
+ m_dwTimeOut(dwTimeOut),
+ m_pRuntime(pRuntime),
+ m_pApp(pApp) {
IFX_SystemHandler* pHandler = m_pApp->GetSysHandler();
- m_nTimerID = pHandler->SetTimer(nElapse, TimerProc);
+ m_nTimerID = pHandler->SetTimer(dwElapse, TimerProc);
(*GetGlobalTimerMap())[m_nTimerID] = this;
- m_dwElapse = nElapse;
- return m_nTimerID;
+ m_pRuntime->AddObserver(this);
+}
+
+CJS_Timer::~CJS_Timer() {
+ CJS_Runtime* pRuntime = GetRuntime();
+ if (pRuntime)
+ pRuntime->RemoveObserver(this);
+ KillJSTimer();
}
void CJS_Timer::KillJSTimer() {
if (m_nTimerID) {
- IFX_SystemHandler* pHandler = m_pApp->GetSysHandler();
- pHandler->KillTimer(m_nTimerID);
+ if (m_bValid) {
+ IFX_SystemHandler* pHandler = m_pApp->GetSysHandler();
+ pHandler->KillTimer(m_nTimerID);
+ }
GetGlobalTimerMap()->erase(m_nTimerID);
m_nTimerID = 0;
}
@@ -148,10 +154,10 @@ void CJS_Timer::TimerProc(int idEvent) {
if (it != GetGlobalTimerMap()->end()) {
CJS_Timer* pTimer = it->second;
if (!pTimer->m_bProcessing) {
- pTimer->m_bProcessing = TRUE;
+ CFX_AutoRestorer<bool> scoped_processing(&pTimer->m_bProcessing);
+ pTimer->m_bProcessing = true;
if (pTimer->m_pEmbedObj)
pTimer->m_pEmbedObj->TimerProc(pTimer);
- pTimer->m_bProcessing = FALSE;
}
}
}
@@ -162,3 +168,7 @@ CJS_Timer::TimerMap* CJS_Timer::GetGlobalTimerMap() {
static auto* s_TimerMap = new TimerMap;
return s_TimerMap;
}
+
+void CJS_Timer::OnDestroyed() {
+ m_bValid = false;
+}