| OLD | NEW |
| 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 "../../include/javascript/JavaScript.h" | 7 #include "../../include/javascript/JavaScript.h" |
| 8 #include "../../include/javascript/IJavaScript.h" | 8 #include "../../include/javascript/IJavaScript.h" |
| 9 #include "../../include/javascript/JS_Define.h" | 9 #include "../../include/javascript/JS_Define.h" |
| 10 #include "../../include/javascript/JS_Object.h" | 10 #include "../../include/javascript/JS_Object.h" |
| 11 #include "../../include/javascript/JS_Context.h" | 11 #include "../../include/javascript/JS_Context.h" |
| 12 | 12 |
| 13 JSTimerMap* GetGlobalTimerMap() { | |
| 14 // Leak the timer array at shutdown. | |
| 15 static auto* timeMap = new JSTimerMap; | |
| 16 return timeMap; | |
| 17 } | |
| 18 | |
| 19 int FXJS_MsgBox(CPDFDoc_Environment* pApp, | 13 int FXJS_MsgBox(CPDFDoc_Environment* pApp, |
| 20 CPDFSDK_PageView* pPageView, | 14 CPDFSDK_PageView* pPageView, |
| 21 const FX_WCHAR* swMsg, | 15 const FX_WCHAR* swMsg, |
| 22 const FX_WCHAR* swTitle, | 16 const FX_WCHAR* swTitle, |
| 23 FX_UINT nType, | 17 FX_UINT nType, |
| 24 FX_UINT nIcon) { | 18 FX_UINT nIcon) { |
| 25 if (!pApp) | 19 if (!pApp) |
| 26 return 0; | 20 return 0; |
| 27 | 21 |
| 28 if (CPDFSDK_Document* pDoc = pApp->GetSDKDocument()) | 22 if (CPDFSDK_Document* pDoc = pApp->GetSDKDocument()) |
| 29 pDoc->KillFocusAnnot(); | 23 pDoc->KillFocusAnnot(); |
| 30 | 24 |
| 31 return pApp->JS_appAlert(swMsg, swTitle, nType, nIcon); | 25 return pApp->JS_appAlert(swMsg, swTitle, nType, nIcon); |
| 32 } | 26 } |
| 33 | 27 |
| 34 CPDFSDK_PageView* FXJS_GetPageView(IFXJS_Context* cc) { | 28 CPDFSDK_PageView* FXJS_GetPageView(IFXJS_Context* cc) { |
| 35 if (CJS_Context* pContext = (CJS_Context*)cc) { | 29 if (CJS_Context* pContext = (CJS_Context*)cc) { |
| 36 if (pContext->GetReaderDocument()) | 30 if (pContext->GetReaderDocument()) |
| 37 return NULL; | 31 return NULL; |
| 38 } | 32 } |
| 39 return NULL; | 33 return NULL; |
| 40 } | 34 } |
| 41 | 35 |
| 42 /* --------------------------------- CJS_EmbedObj | |
| 43 * --------------------------------- */ | |
| 44 | |
| 45 CJS_EmbedObj::CJS_EmbedObj(CJS_Object* pJSObject) : m_pJSObject(pJSObject) {} | 36 CJS_EmbedObj::CJS_EmbedObj(CJS_Object* pJSObject) : m_pJSObject(pJSObject) {} |
| 46 | 37 |
| 47 CJS_EmbedObj::~CJS_EmbedObj() { | 38 CJS_EmbedObj::~CJS_EmbedObj() { |
| 48 m_pJSObject = NULL; | 39 m_pJSObject = NULL; |
| 49 } | 40 } |
| 50 | 41 |
| 51 CPDFSDK_PageView* CJS_EmbedObj::JSGetPageView(IFXJS_Context* cc) { | 42 CPDFSDK_PageView* CJS_EmbedObj::JSGetPageView(IFXJS_Context* cc) { |
| 52 return FXJS_GetPageView(cc); | 43 return FXJS_GetPageView(cc); |
| 53 } | 44 } |
| 54 | 45 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 72 | 63 |
| 73 return pTimer; | 64 return pTimer; |
| 74 } | 65 } |
| 75 | 66 |
| 76 void CJS_EmbedObj::EndTimer(CJS_Timer* pTimer) { | 67 void CJS_EmbedObj::EndTimer(CJS_Timer* pTimer) { |
| 77 ASSERT(pTimer != NULL); | 68 ASSERT(pTimer != NULL); |
| 78 pTimer->KillJSTimer(); | 69 pTimer->KillJSTimer(); |
| 79 delete pTimer; | 70 delete pTimer; |
| 80 } | 71 } |
| 81 | 72 |
| 82 /* --------------------------------- CJS_Object | |
| 83 * --------------------------------- */ | |
| 84 void FreeObject(const v8::WeakCallbackInfo<CJS_Object>& data) { | 73 void FreeObject(const v8::WeakCallbackInfo<CJS_Object>& data) { |
| 85 CJS_Object* pJSObj = data.GetParameter(); | 74 CJS_Object* pJSObj = data.GetParameter(); |
| 86 pJSObj->ExitInstance(); | 75 pJSObj->ExitInstance(); |
| 87 delete pJSObj; | 76 delete pJSObj; |
| 88 JS_FreePrivate(data.GetInternalField(0)); | 77 JS_FreePrivate(data.GetInternalField(0)); |
| 89 } | 78 } |
| 90 | 79 |
| 91 void DisposeObject(const v8::WeakCallbackInfo<CJS_Object>& data) { | 80 void DisposeObject(const v8::WeakCallbackInfo<CJS_Object>& data) { |
| 92 CJS_Object* pJSObj = data.GetParameter(); | 81 CJS_Object* pJSObj = data.GetParameter(); |
| 93 pJSObj->Dispose(); | 82 pJSObj->Dispose(); |
| 94 data.SetSecondPassCallback(FreeObject); | 83 data.SetSecondPassCallback(FreeObject); |
| 95 } | 84 } |
| 96 | 85 |
| 97 CJS_Object::CJS_Object(JSFXObject pObject) : m_pEmbedObj(NULL) { | 86 CJS_Object::CJS_Object(JSFXObject pObject) : m_pEmbedObj(NULL) { |
| 98 v8::Local<v8::Context> context = pObject->CreationContext(); | 87 v8::Local<v8::Context> context = pObject->CreationContext(); |
| 99 m_pIsolate = context->GetIsolate(); | 88 m_pIsolate = context->GetIsolate(); |
| 100 m_pObject.Reset(m_pIsolate, pObject); | 89 m_pObject.Reset(m_pIsolate, pObject); |
| 101 }; | 90 }; |
| 102 | 91 |
| 103 CJS_Object::~CJS_Object(void) { | 92 CJS_Object::~CJS_Object(void) { |
| 104 delete m_pEmbedObj; | |
| 105 m_pEmbedObj = NULL; | |
| 106 | |
| 107 m_pObject.Reset(); | 93 m_pObject.Reset(); |
| 108 }; | 94 }; |
| 109 | 95 |
| 110 void CJS_Object::MakeWeak() { | 96 void CJS_Object::MakeWeak() { |
| 111 m_pObject.SetWeak(this, DisposeObject, v8::WeakCallbackType::kInternalFields); | 97 m_pObject.SetWeak(this, DisposeObject, v8::WeakCallbackType::kInternalFields); |
| 112 } | 98 } |
| 113 | 99 |
| 114 void CJS_Object::Dispose() { | 100 void CJS_Object::Dispose() { |
| 115 m_pObject.Reset(); | 101 m_pObject.Reset(); |
| 116 } | 102 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 130 | 116 |
| 131 void CJS_Object::Alert(CJS_Context* pContext, const FX_WCHAR* swMsg) { | 117 void CJS_Object::Alert(CJS_Context* pContext, const FX_WCHAR* swMsg) { |
| 132 ASSERT(pContext != NULL); | 118 ASSERT(pContext != NULL); |
| 133 | 119 |
| 134 if (pContext->IsMsgBoxEnabled()) { | 120 if (pContext->IsMsgBoxEnabled()) { |
| 135 CPDFDoc_Environment* pApp = pContext->GetReaderApp(); | 121 CPDFDoc_Environment* pApp = pContext->GetReaderApp(); |
| 136 if (pApp) | 122 if (pApp) |
| 137 pApp->JS_appAlert(swMsg, NULL, 0, 3); | 123 pApp->JS_appAlert(swMsg, NULL, 0, 3); |
| 138 } | 124 } |
| 139 } | 125 } |
| 126 |
| 127 FX_UINT CJS_Timer::SetJSTimer(FX_UINT nElapse) { |
| 128 if (m_nTimerID) |
| 129 KillJSTimer(); |
| 130 IFX_SystemHandler* pHandler = m_pApp->GetSysHandler(); |
| 131 m_nTimerID = pHandler->SetTimer(nElapse, TimerProc); |
| 132 (*GetGlobalTimerMap())[m_nTimerID] = this; |
| 133 m_dwElapse = nElapse; |
| 134 return m_nTimerID; |
| 135 } |
| 136 |
| 137 void CJS_Timer::KillJSTimer() { |
| 138 if (m_nTimerID) { |
| 139 IFX_SystemHandler* pHandler = m_pApp->GetSysHandler(); |
| 140 pHandler->KillTimer(m_nTimerID); |
| 141 GetGlobalTimerMap()->erase(m_nTimerID); |
| 142 m_nTimerID = 0; |
| 143 } |
| 144 } |
| 145 |
| 146 // static |
| 147 void CJS_Timer::TimerProc(int idEvent) { |
| 148 const auto it = GetGlobalTimerMap()->find(idEvent); |
| 149 if (it != GetGlobalTimerMap()->end()) { |
| 150 CJS_Timer* pTimer = it->second; |
| 151 if (!pTimer->m_bProcessing) { |
| 152 pTimer->m_bProcessing = TRUE; |
| 153 if (pTimer->m_pEmbedObj) |
| 154 pTimer->m_pEmbedObj->TimerProc(pTimer); |
| 155 pTimer->m_bProcessing = FALSE; |
| 156 } |
| 157 } |
| 158 } |
| 159 |
| 160 // static |
| 161 CJS_Timer::TimerMap* CJS_Timer::GetGlobalTimerMap() { |
| 162 // Leak the timer array at shutdown. |
| 163 static auto* s_TimerMap = new TimerMap; |
| 164 return s_TimerMap; |
| 165 } |
| OLD | NEW |