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 | |
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')
-rw-r--r-- | fpdfsdk/javascript/cjs_app.cpp (renamed from fpdfsdk/javascript/app.cpp) | 149 | ||||
-rw-r--r-- | fpdfsdk/javascript/cjs_app.h (renamed from fpdfsdk/javascript/app.h) | 30 | ||||
-rw-r--r-- | fpdfsdk/javascript/cjs_document.cpp | 2 | ||||
-rw-r--r-- | fpdfsdk/javascript/cjs_runtime.cpp | 3 | ||||
-rw-r--r-- | fpdfsdk/javascript/cjs_timerobj.cpp | 32 | ||||
-rw-r--r-- | fpdfsdk/javascript/cjs_timerobj.h | 38 | ||||
-rw-r--r-- | fpdfsdk/javascript/global_timer.cpp | 80 | ||||
-rw-r--r-- | fpdfsdk/javascript/global_timer.h | 50 |
8 files changed, 210 insertions, 174 deletions
diff --git a/fpdfsdk/javascript/app.cpp b/fpdfsdk/javascript/cjs_app.cpp index 3e8ca0bf1a..bd28fefc4e 100644 --- a/fpdfsdk/javascript/app.cpp +++ b/fpdfsdk/javascript/cjs_app.cpp @@ -4,22 +4,13 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#include "fpdfsdk/javascript/app.h" +#include "fpdfsdk/javascript/cjs_app.h" -#include <map> -#include <memory> -#include <vector> - -#include "fpdfsdk/cpdfsdk_formfillenvironment.h" #include "fpdfsdk/cpdfsdk_interform.h" -#include "fpdfsdk/javascript/JS_Define.h" #include "fpdfsdk/javascript/cjs_document.h" -#include "fpdfsdk/javascript/cjs_event_context.h" -#include "fpdfsdk/javascript/cjs_eventhandler.h" -#include "fpdfsdk/javascript/cjs_object.h" -#include "fpdfsdk/javascript/cjs_runtime.h" -#include "fpdfsdk/javascript/resource.h" -#include "third_party/base/stl_util.h" +#include "fpdfsdk/javascript/cjs_timerobj.h" +#include "fpdfsdk/javascript/global_timer.h" +#include "fpdfsdk/javascript/ijs_event_context.h" namespace { @@ -32,138 +23,6 @@ bool IsTypeKnown(v8::Local<v8::Value> value) { } // namespace -class GlobalTimer { - public: - GlobalTimer(app* pObj, - CPDFSDK_FormFillEnvironment* pFormFillEnv, - CJS_Runtime* pRuntime, - int nType, - const WideString& script, - uint32_t dwElapse, - uint32_t dwTimeOut); - ~GlobalTimer(); - - static void Trigger(int nTimerID); - static void Cancel(int nTimerID); - - bool IsOneShot() const { return m_nType == 1; } - uint32_t GetTimeOut() const { return m_dwTimeOut; } - int GetTimerID() const { return m_nTimerID; } - CJS_Runtime* GetRuntime() const { return m_pRuntime.Get(); } - WideString GetJScript() const { return m_swJScript; } - - private: - using TimerMap = std::map<uint32_t, GlobalTimer*>; - static TimerMap* GetGlobalTimerMap(); - - uint32_t m_nTimerID; - app* const m_pEmbedObj; - bool m_bProcessing; - - // data - const int m_nType; // 0:Interval; 1:TimeOut - const uint32_t m_dwTimeOut; - const WideString m_swJScript; - CJS_Runtime::ObservedPtr m_pRuntime; - CPDFSDK_FormFillEnvironment::ObservedPtr m_pFormFillEnv; -}; - -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; -} - -int CJS_TimerObj::ObjDefnID = -1; - -// static -int CJS_TimerObj::GetObjDefnID() { - return ObjDefnID; -} - -// static -void CJS_TimerObj::DefineJSObjects(CFXJS_Engine* pEngine) { - ObjDefnID = pEngine->DefineObj("TimerObj", FXJSOBJTYPE_DYNAMIC, - JSConstructor<CJS_TimerObj, TimerObj>, - JSDestructor<CJS_TimerObj>); -} - -TimerObj::TimerObj(CJS_Object* pJSObject) - : CJS_EmbedObj(pJSObject), m_nTimerID(0) {} - -TimerObj::~TimerObj() {} - -void TimerObj::SetTimer(GlobalTimer* pTimer) { - m_nTimerID = pTimer->GetTimerID(); -} - #define JS_STR_VIEWERTYPE L"pdfium" #define JS_STR_VIEWERVARIATION L"Full" #define JS_STR_PLATFORM L"WIN" diff --git a/fpdfsdk/javascript/app.h b/fpdfsdk/javascript/cjs_app.h index ea95398c80..b385d66186 100644 --- a/fpdfsdk/javascript/app.h +++ b/fpdfsdk/javascript/cjs_app.h @@ -4,8 +4,8 @@ // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com -#ifndef FPDFSDK_JAVASCRIPT_APP_H_ -#define FPDFSDK_JAVASCRIPT_APP_H_ +#ifndef FPDFSDK_JAVASCRIPT_CJS_APP_H_ +#define FPDFSDK_JAVASCRIPT_CJS_APP_H_ #include <memory> #include <set> @@ -16,30 +16,6 @@ class CJS_Runtime; class GlobalTimer; -class TimerObj : public CJS_EmbedObj { - public: - explicit TimerObj(CJS_Object* pJSObject); - ~TimerObj() override; - - void SetTimer(GlobalTimer* pTimer); - int GetTimerID() const { return m_nTimerID; } - - private: - int m_nTimerID; // Weak reference to GlobalTimer through global map. -}; - -class CJS_TimerObj : public CJS_Object { - public: - static int GetObjDefnID(); - static void DefineJSObjects(CFXJS_Engine* pEngine); - - explicit CJS_TimerObj(v8::Local<v8::Object> pObject) : CJS_Object(pObject) {} - ~CJS_TimerObj() override {} - - private: - static int ObjDefnID; -}; - class app : public CJS_EmbedObj { public: explicit app(CJS_Object* pJSObject); @@ -190,4 +166,4 @@ class CJS_App : public CJS_Object { static const JSMethodSpec MethodSpecs[]; }; -#endif // FPDFSDK_JAVASCRIPT_APP_H_ +#endif // FPDFSDK_JAVASCRIPT_CJS_APP_H_ diff --git a/fpdfsdk/javascript/cjs_document.cpp b/fpdfsdk/javascript/cjs_document.cpp index df7001bd8f..1791db563b 100644 --- a/fpdfsdk/javascript/cjs_document.cpp +++ b/fpdfsdk/javascript/cjs_document.cpp @@ -19,8 +19,8 @@ #include "fpdfsdk/cpdfsdk_annotiteration.h" #include "fpdfsdk/cpdfsdk_interform.h" #include "fpdfsdk/cpdfsdk_pageview.h" -#include "fpdfsdk/javascript/app.h" #include "fpdfsdk/javascript/cjs_annot.h" +#include "fpdfsdk/javascript/cjs_app.h" #include "fpdfsdk/javascript/cjs_delaydata.h" #include "fpdfsdk/javascript/cjs_field.h" #include "fpdfsdk/javascript/cjs_icon.h" diff --git a/fpdfsdk/javascript/cjs_runtime.cpp b/fpdfsdk/javascript/cjs_runtime.cpp index b6b99ca839..d940f082d3 100644 --- a/fpdfsdk/javascript/cjs_runtime.cpp +++ b/fpdfsdk/javascript/cjs_runtime.cpp @@ -11,8 +11,8 @@ #include "fpdfsdk/cpdfsdk_formfillenvironment.h" #include "fpdfsdk/javascript/JS_Define.h" #include "fpdfsdk/javascript/JS_GlobalData.h" -#include "fpdfsdk/javascript/app.h" #include "fpdfsdk/javascript/cjs_annot.h" +#include "fpdfsdk/javascript/cjs_app.h" #include "fpdfsdk/javascript/cjs_border.h" #include "fpdfsdk/javascript/cjs_display.h" #include "fpdfsdk/javascript/cjs_document.h" @@ -32,6 +32,7 @@ #include "fpdfsdk/javascript/cjs_scalehow.h" #include "fpdfsdk/javascript/cjs_scalewhen.h" #include "fpdfsdk/javascript/cjs_style.h" +#include "fpdfsdk/javascript/cjs_timerobj.h" #include "fpdfsdk/javascript/cjs_zoomtype.h" #include "fpdfsdk/javascript/color.h" #include "fpdfsdk/javascript/console.h" diff --git a/fpdfsdk/javascript/cjs_timerobj.cpp b/fpdfsdk/javascript/cjs_timerobj.cpp new file mode 100644 index 0000000000..f0b90292c6 --- /dev/null +++ b/fpdfsdk/javascript/cjs_timerobj.cpp @@ -0,0 +1,32 @@ +// 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/cjs_timerobj.h" + +#include "fpdfsdk/javascript/global_timer.h" + +int CJS_TimerObj::ObjDefnID = -1; + +// static +int CJS_TimerObj::GetObjDefnID() { + return ObjDefnID; +} + +// static +void CJS_TimerObj::DefineJSObjects(CFXJS_Engine* pEngine) { + ObjDefnID = pEngine->DefineObj("TimerObj", FXJSOBJTYPE_DYNAMIC, + JSConstructor<CJS_TimerObj, TimerObj>, + JSDestructor<CJS_TimerObj>); +} + +TimerObj::TimerObj(CJS_Object* pJSObject) + : CJS_EmbedObj(pJSObject), m_nTimerID(0) {} + +TimerObj::~TimerObj() {} + +void TimerObj::SetTimer(GlobalTimer* pTimer) { + m_nTimerID = pTimer->GetTimerID(); +} diff --git a/fpdfsdk/javascript/cjs_timerobj.h b/fpdfsdk/javascript/cjs_timerobj.h new file mode 100644 index 0000000000..6ee7758a5c --- /dev/null +++ b/fpdfsdk/javascript/cjs_timerobj.h @@ -0,0 +1,38 @@ +// 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 + +#ifndef FPDFSDK_JAVASCRIPT_CJS_TIMEROBJ_H_ +#define FPDFSDK_JAVASCRIPT_CJS_TIMEROBJ_H_ + +#include "fpdfsdk/javascript/JS_Define.h" + +class GlobalTimer; + +class TimerObj : public CJS_EmbedObj { + public: + explicit TimerObj(CJS_Object* pJSObject); + ~TimerObj() override; + + void SetTimer(GlobalTimer* pTimer); + int GetTimerID() const { return m_nTimerID; } + + private: + int m_nTimerID; // Weak reference to GlobalTimer through global map. +}; + +class CJS_TimerObj : public CJS_Object { + public: + static int GetObjDefnID(); + static void DefineJSObjects(CFXJS_Engine* pEngine); + + explicit CJS_TimerObj(v8::Local<v8::Object> pObject) : CJS_Object(pObject) {} + ~CJS_TimerObj() override {} + + private: + static int ObjDefnID; +}; + +#endif // FPDFSDK_JAVASCRIPT_CJS_TIMEROBJ_H_ 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; +} diff --git a/fpdfsdk/javascript/global_timer.h b/fpdfsdk/javascript/global_timer.h new file mode 100644 index 0000000000..bc65b976a9 --- /dev/null +++ b/fpdfsdk/javascript/global_timer.h @@ -0,0 +1,50 @@ +// 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 + +#ifndef FPDFSDK_JAVASCRIPT_GLOBAL_TIMER_H_ +#define FPDFSDK_JAVASCRIPT_GLOBAL_TIMER_H_ + +#include <map> + +#include "fpdfsdk/javascript/cjs_app.h" + +class GlobalTimer { + public: + GlobalTimer(app* pObj, + CPDFSDK_FormFillEnvironment* pFormFillEnv, + CJS_Runtime* pRuntime, + int nType, + const WideString& script, + uint32_t dwElapse, + uint32_t dwTimeOut); + ~GlobalTimer(); + + static void Trigger(int nTimerID); + static void Cancel(int nTimerID); + + bool IsOneShot() const { return m_nType == 1; } + uint32_t GetTimeOut() const { return m_dwTimeOut; } + int GetTimerID() const { return m_nTimerID; } + CJS_Runtime* GetRuntime() const { return m_pRuntime.Get(); } + WideString GetJScript() const { return m_swJScript; } + + private: + using TimerMap = std::map<uint32_t, GlobalTimer*>; + static TimerMap* GetGlobalTimerMap(); + + uint32_t m_nTimerID; + app* const m_pEmbedObj; + bool m_bProcessing; + + // data + const int m_nType; // 0:Interval; 1:TimeOut + const uint32_t m_dwTimeOut; + const WideString m_swJScript; + CJS_Runtime::ObservedPtr m_pRuntime; + CPDFSDK_FormFillEnvironment::ObservedPtr m_pFormFillEnv; +}; + +#endif // FPDFSDK_JAVASCRIPT_GLOBAL_TIMER_H_ |