John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 1 | // Copyright 2014 PDFium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | |
| 7 | #include "../../include/javascript/JavaScript.h" |
| 8 | #include "../../include/javascript/IJavaScript.h" |
| 9 | #include "../../include/javascript/JS_Define.h" |
| 10 | #include "../../include/javascript/JS_Object.h" |
| 11 | // #include "../../include/javascript/JS_MsgBox.h" |
| 12 | // #include "../../include/javascript/JS_ResMgr.h" |
| 13 | #include "../../include/javascript/JS_Context.h" |
| 14 | |
Bruce Dawson | b4649dc | 2015-01-05 13:26:17 -0800 | [diff] [blame] | 15 | JS_TIMER_MAPARRAY& GetTimeMap() |
| 16 | { |
| 17 | // Leak the timer array at shutdown. |
| 18 | static auto* timeMap = new JS_TIMER_MAPARRAY; |
| 19 | return *timeMap; |
| 20 | } |
| 21 | |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 22 | int FXJS_MsgBox(CPDFDoc_Environment* pApp, CPDFSDK_PageView* pPageView, FX_LPCWSTR swMsg, FX_LPCWSTR swTitle, FX_UINT nType, FX_UINT nIcon) |
| 23 | { |
| 24 | int nRet = 0; |
| 25 | |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 26 | if (pApp) |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 27 | { |
| 28 | CPDFSDK_Document* pDoc = pApp->GetCurrentDoc(); |
| 29 | if(pDoc) |
| 30 | pDoc->KillFocusAnnot(); |
| 31 | nRet = pApp->JS_appAlert(swMsg, swTitle, nType, nIcon); |
| 32 | } |
| 33 | |
| 34 | return nRet; |
| 35 | } |
| 36 | |
| 37 | CPDFSDK_PageView* FXJS_GetPageView(IFXJS_Context* cc) |
| 38 | { |
| 39 | if (CJS_Context* pContext = (CJS_Context *)cc) |
| 40 | { |
| 41 | if (pContext->GetReaderDocument()) |
| 42 | return NULL; |
| 43 | } |
| 44 | return NULL; |
| 45 | } |
| 46 | |
| 47 | /* --------------------------------- CJS_EmbedObj --------------------------------- */ |
| 48 | |
| 49 | CJS_EmbedObj::CJS_EmbedObj(CJS_Object* pJSObject) : |
| 50 | m_pJSObject(pJSObject) |
| 51 | { |
| 52 | } |
| 53 | |
| 54 | CJS_EmbedObj::~CJS_EmbedObj() |
| 55 | { |
| 56 | m_pJSObject = NULL; |
| 57 | |
| 58 | } |
| 59 | |
| 60 | CPDFSDK_PageView* CJS_EmbedObj::JSGetPageView(IFXJS_Context* cc) |
| 61 | { |
| 62 | return FXJS_GetPageView(cc); |
| 63 | } |
| 64 | |
| 65 | int CJS_EmbedObj::MsgBox(CPDFDoc_Environment* pApp, CPDFSDK_PageView* pPageView,FX_LPCWSTR swMsg,FX_LPCWSTR swTitle,FX_UINT nType,FX_UINT nIcon) |
| 66 | { |
| 67 | return FXJS_MsgBox(pApp, pPageView, swMsg, swTitle, nType, nIcon); |
| 68 | } |
| 69 | |
| 70 | void CJS_EmbedObj::Alert(CJS_Context* pContext, FX_LPCWSTR swMsg) |
| 71 | { |
| 72 | CJS_Object::Alert(pContext, swMsg); |
| 73 | } |
| 74 | |
Bo Xu | fdc00a7 | 2014-10-28 23:03:33 -0700 | [diff] [blame] | 75 | CJS_Timer* CJS_EmbedObj::BeginTimer(CPDFDoc_Environment* pApp, FX_UINT nElapse) |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 76 | { |
| 77 | CJS_Timer* pTimer = new CJS_Timer(this,pApp); |
| 78 | pTimer->SetJSTimer(nElapse); |
| 79 | |
| 80 | return pTimer; |
| 81 | } |
| 82 | |
| 83 | void CJS_EmbedObj::EndTimer(CJS_Timer* pTimer) |
| 84 | { |
| 85 | ASSERT(pTimer != NULL); |
| 86 | pTimer->KillJSTimer(); |
| 87 | delete pTimer; |
| 88 | } |
| 89 | |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 90 | /* --------------------------------- CJS_Object --------------------------------- */ |
Jochen Eisinger | dfa2c99 | 2015-05-19 00:38:00 +0200 | [diff] [blame^] | 91 | void FreeObject(const v8::WeakCallbackInfo<CJS_Object>& data) |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 92 | { |
| 93 | CJS_Object* pJSObj = data.GetParameter(); |
Jochen Eisinger | dfa2c99 | 2015-05-19 00:38:00 +0200 | [diff] [blame^] | 94 | pJSObj->ExitInstance(); |
| 95 | delete pJSObj; |
| 96 | JS_FreePrivate(data.GetInternalField(0)); |
| 97 | } |
| 98 | |
| 99 | void DisposeObject(const v8::WeakCallbackInfo<CJS_Object>& data) |
| 100 | { |
| 101 | CJS_Object* pJSObj = data.GetParameter(); |
| 102 | pJSObj->Dispose(); |
| 103 | data.SetSecondPassCallback(FreeObject); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | CJS_Object::CJS_Object(JSFXObject pObject) :m_pEmbedObj(NULL) |
| 107 | { |
| 108 | v8::Local<v8::Context> context = pObject->CreationContext(); |
| 109 | m_pIsolate = context->GetIsolate(); |
| 110 | m_pObject.Reset(m_pIsolate, pObject); |
| 111 | }; |
| 112 | |
| 113 | CJS_Object::~CJS_Object(void) |
| 114 | { |
| 115 | delete m_pEmbedObj; |
| 116 | m_pEmbedObj = NULL; |
| 117 | |
| 118 | m_pObject.Reset(); |
| 119 | }; |
| 120 | |
| 121 | void CJS_Object::MakeWeak() |
| 122 | { |
Jochen Eisinger | dfa2c99 | 2015-05-19 00:38:00 +0200 | [diff] [blame^] | 123 | m_pObject.SetWeak( |
| 124 | this, DisposeObject, v8::WeakCallbackType::kInternalFields); |
| 125 | } |
| 126 | |
| 127 | void CJS_Object::Dispose() |
| 128 | { |
| 129 | m_pObject.Reset(); |
John Abd-El-Malek | 3f3b45c | 2014-05-23 17:28:10 -0700 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | CPDFSDK_PageView* CJS_Object::JSGetPageView(IFXJS_Context* cc) |
| 133 | { |
| 134 | return FXJS_GetPageView(cc); |
| 135 | } |
| 136 | |
| 137 | int CJS_Object::MsgBox(CPDFDoc_Environment* pApp, CPDFSDK_PageView* pPageView, FX_LPCWSTR swMsg, FX_LPCWSTR swTitle, FX_UINT nType, FX_UINT nIcon) |
| 138 | { |
| 139 | return FXJS_MsgBox(pApp, pPageView, swMsg, swTitle, nType, nIcon); |
| 140 | } |
| 141 | |
| 142 | void CJS_Object::Alert(CJS_Context* pContext, FX_LPCWSTR swMsg) |
| 143 | { |
| 144 | ASSERT(pContext != NULL); |
| 145 | |
| 146 | if (pContext->IsMsgBoxEnabled()) |
| 147 | { |
| 148 | CPDFDoc_Environment* pApp = pContext->GetReaderApp(); |
| 149 | if(pApp) |
| 150 | pApp->JS_appAlert(swMsg, NULL, 0, 3); |
| 151 | } |
| 152 | } |
| 153 | |
| 154 | |