| 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 "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" |
| 11 #include "fpdfsdk/javascript/cjs_context.h" | 11 #include "fpdfsdk/javascript/cjs_context.h" |
| 12 | 12 |
| 13 namespace { | |
| 14 | |
| 15 int FXJS_MsgBox(CPDFDoc_Environment* pApp, | |
| 16 const FX_WCHAR* swMsg, | |
| 17 const FX_WCHAR* swTitle, | |
| 18 FX_UINT nType, | |
| 19 FX_UINT nIcon) { | |
| 20 if (!pApp) | |
| 21 return 0; | |
| 22 | |
| 23 if (CPDFSDK_Document* pDoc = pApp->GetSDKDocument()) | |
| 24 pDoc->KillFocusAnnot(); | |
| 25 | |
| 26 return pApp->JS_appAlert(swMsg, swTitle, nType, nIcon); | |
| 27 } | |
| 28 | |
| 29 } // namespace | |
| 30 | |
| 31 CJS_EmbedObj::CJS_EmbedObj(CJS_Object* pJSObject) : m_pJSObject(pJSObject) {} | 13 CJS_EmbedObj::CJS_EmbedObj(CJS_Object* pJSObject) : m_pJSObject(pJSObject) {} |
| 32 | 14 |
| 33 CJS_EmbedObj::~CJS_EmbedObj() { | 15 CJS_EmbedObj::~CJS_EmbedObj() { |
| 34 m_pJSObject = nullptr; | 16 m_pJSObject = nullptr; |
| 35 } | 17 } |
| 36 | 18 |
| 37 int CJS_EmbedObj::MsgBox(CPDFDoc_Environment* pApp, | 19 int CJS_EmbedObj::MsgBox(CPDFDoc_Environment* pApp, |
| 38 const FX_WCHAR* swMsg, | 20 const FX_WCHAR* swMsg, |
| 39 const FX_WCHAR* swTitle, | 21 const FX_WCHAR* swTitle, |
| 40 FX_UINT nType, | 22 FX_UINT nType, |
| 41 FX_UINT nIcon) { | 23 FX_UINT nIcon) { |
| 42 return FXJS_MsgBox(pApp, swMsg, swTitle, nType, nIcon); | 24 if (!pApp) |
| 25 return 0; |
| 26 |
| 27 if (CPDFSDK_Document* pDoc = pApp->GetSDKDocument()) |
| 28 pDoc->KillFocusAnnot(); |
| 29 |
| 30 return pApp->JS_appAlert(swMsg, swTitle, nType, nIcon); |
| 43 } | 31 } |
| 44 | 32 |
| 45 void CJS_EmbedObj::Alert(CJS_Context* pContext, const FX_WCHAR* swMsg) { | 33 void CJS_EmbedObj::Alert(CJS_Context* pContext, const FX_WCHAR* swMsg) { |
| 46 CJS_Object::Alert(pContext, swMsg); | 34 CJS_Object::Alert(pContext, swMsg); |
| 47 } | 35 } |
| 48 | 36 |
| 49 void FreeObject(const v8::WeakCallbackInfo<CJS_Object>& data) { | 37 void FreeObject(const v8::WeakCallbackInfo<CJS_Object>& data) { |
| 50 CJS_Object* pJSObj = data.GetParameter(); | 38 CJS_Object* pJSObj = data.GetParameter(); |
| 51 pJSObj->ExitInstance(); | 39 pJSObj->ExitInstance(); |
| 52 delete pJSObj; | 40 delete pJSObj; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 73 | 61 |
| 74 void CJS_Object::Dispose() { | 62 void CJS_Object::Dispose() { |
| 75 m_pV8Object.Reset(); | 63 m_pV8Object.Reset(); |
| 76 } | 64 } |
| 77 | 65 |
| 78 void CJS_Object::InitInstance(IJS_Runtime* pIRuntime) {} | 66 void CJS_Object::InitInstance(IJS_Runtime* pIRuntime) {} |
| 79 | 67 |
| 80 void CJS_Object::ExitInstance() {} | 68 void CJS_Object::ExitInstance() {} |
| 81 | 69 |
| 82 void CJS_Object::Alert(CJS_Context* pContext, const FX_WCHAR* swMsg) { | 70 void CJS_Object::Alert(CJS_Context* pContext, const FX_WCHAR* swMsg) { |
| 83 if (pContext->IsMsgBoxEnabled()) { | 71 CPDFDoc_Environment* pApp = pContext->GetReaderApp(); |
| 84 CPDFDoc_Environment* pApp = pContext->GetReaderApp(); | 72 if (pApp) |
| 85 if (pApp) | 73 pApp->JS_appAlert(swMsg, nullptr, 0, 3); |
| 86 pApp->JS_appAlert(swMsg, nullptr, 0, 3); | |
| 87 } | |
| 88 } | 74 } |
| 89 | 75 |
| 90 CJS_Timer::CJS_Timer(CJS_EmbedObj* pObj, | 76 CJS_Timer::CJS_Timer(CJS_EmbedObj* pObj, |
| 91 CPDFDoc_Environment* pApp, | 77 CPDFDoc_Environment* pApp, |
| 92 CJS_Runtime* pRuntime, | 78 CJS_Runtime* pRuntime, |
| 93 int nType, | 79 int nType, |
| 94 const CFX_WideString& script, | 80 const CFX_WideString& script, |
| 95 uint32_t dwElapse, | 81 uint32_t dwElapse, |
| 96 uint32_t dwTimeOut) | 82 uint32_t dwTimeOut) |
| 97 : m_nTimerID(0), | 83 : m_nTimerID(0), |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 // static | 130 // static |
| 145 CJS_Timer::TimerMap* CJS_Timer::GetGlobalTimerMap() { | 131 CJS_Timer::TimerMap* CJS_Timer::GetGlobalTimerMap() { |
| 146 // Leak the timer array at shutdown. | 132 // Leak the timer array at shutdown. |
| 147 static auto* s_TimerMap = new TimerMap; | 133 static auto* s_TimerMap = new TimerMap; |
| 148 return s_TimerMap; | 134 return s_TimerMap; |
| 149 } | 135 } |
| 150 | 136 |
| 151 void CJS_Timer::OnDestroyed() { | 137 void CJS_Timer::OnDestroyed() { |
| 152 m_bValid = false; | 138 m_bValid = false; |
| 153 } | 139 } |
| OLD | NEW |