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_MsgBox.h" | |
12 // #include "../../include/javascript/JS_ResMgr.h" | |
13 #include "../../include/javascript/JS_Context.h" | 11 #include "../../include/javascript/JS_Context.h" |
14 | 12 |
15 JS_TIMER_MAPARRAY& GetTimeMap() | 13 JS_TIMER_MAPARRAY& GetTimeMap() |
16 { | 14 { |
17 // Leak the timer array at shutdown. | 15 // Leak the timer array at shutdown. |
18 static auto* timeMap = new JS_TIMER_MAPARRAY; | 16 static auto* timeMap = new JS_TIMER_MAPARRAY; |
19 return *timeMap; | 17 return *timeMap; |
20 } | 18 } |
21 | 19 |
22 int FXJS_MsgBox(CPDFDoc_Environment* pApp, CPDFSDK_PageView* pPageView, const FX
_WCHAR* swMsg, const FX_WCHAR* swTitle, FX_UINT nType, FX_UINT nIcon) | 20 int FXJS_MsgBox(CPDFDoc_Environment* pApp, CPDFSDK_PageView* pPageView, const FX
_WCHAR* swMsg, const FX_WCHAR* swTitle, FX_UINT nType, FX_UINT nIcon) |
23 { | 21 { |
24 » int nRet = 0; | 22 if (!pApp) |
| 23 return 0; |
25 | 24 |
26 » if(pApp) | 25 if (CPDFSDK_Document* pDoc = pApp->GetSDKDocument()) |
27 » { | 26 pDoc->KillFocusAnnot(); |
28 » » CPDFSDK_Document* pDoc = pApp->GetCurrentDoc(); | |
29 » » if(pDoc) | |
30 » » » pDoc->KillFocusAnnot(); | |
31 » » nRet = pApp->JS_appAlert(swMsg, swTitle, nType, nIcon); | |
32 » } | |
33 | 27 |
34 » return nRet; | 28 return pApp->JS_appAlert(swMsg, swTitle, nType, nIcon); |
35 } | 29 } |
36 | 30 |
37 CPDFSDK_PageView* FXJS_GetPageView(IFXJS_Context* cc) | 31 CPDFSDK_PageView* FXJS_GetPageView(IFXJS_Context* cc) |
38 { | 32 { |
39 » if (CJS_Context* pContext = (CJS_Context *)cc) | 33 if (CJS_Context* pContext = (CJS_Context *)cc) |
40 » { | 34 { |
41 » » if (pContext->GetReaderDocument()) | 35 if (pContext->GetReaderDocument()) |
42 » » » return NULL; | 36 return NULL; |
43 » } | 37 } |
44 » return NULL; | 38 return NULL; |
45 } | 39 } |
46 | 40 |
47 /* --------------------------------- CJS_EmbedObj -----------------------------
---- */ | 41 /* --------------------------------- CJS_EmbedObj -----------------------------
---- */ |
48 | 42 |
49 CJS_EmbedObj::CJS_EmbedObj(CJS_Object* pJSObject) : | 43 CJS_EmbedObj::CJS_EmbedObj(CJS_Object* pJSObject) : |
50 » m_pJSObject(pJSObject) | 44 m_pJSObject(pJSObject) |
51 { | 45 { |
52 } | 46 } |
53 | 47 |
54 CJS_EmbedObj::~CJS_EmbedObj() | 48 CJS_EmbedObj::~CJS_EmbedObj() |
55 { | 49 { |
56 » m_pJSObject = NULL; | 50 m_pJSObject = NULL; |
57 | 51 |
58 } | 52 } |
59 | 53 |
60 CPDFSDK_PageView* CJS_EmbedObj::JSGetPageView(IFXJS_Context* cc) | 54 CPDFSDK_PageView* CJS_EmbedObj::JSGetPageView(IFXJS_Context* cc) |
61 { | 55 { |
62 » return FXJS_GetPageView(cc); | 56 return FXJS_GetPageView(cc); |
63 } | 57 } |
64 | 58 |
65 int CJS_EmbedObj::MsgBox(CPDFDoc_Environment* pApp, CPDFSDK_PageView* pPageView,
const FX_WCHAR* swMsg,const FX_WCHAR* swTitle,FX_UINT nType,FX_UINT nIcon) | 59 int CJS_EmbedObj::MsgBox(CPDFDoc_Environment* pApp, CPDFSDK_PageView* pPageView,
const FX_WCHAR* swMsg,const FX_WCHAR* swTitle,FX_UINT nType,FX_UINT nIcon) |
66 { | 60 { |
67 » return FXJS_MsgBox(pApp, pPageView, swMsg, swTitle, nType, nIcon); | 61 return FXJS_MsgBox(pApp, pPageView, swMsg, swTitle, nType, nIcon); |
68 } | 62 } |
69 | 63 |
70 void CJS_EmbedObj::Alert(CJS_Context* pContext, const FX_WCHAR* swMsg) | 64 void CJS_EmbedObj::Alert(CJS_Context* pContext, const FX_WCHAR* swMsg) |
71 { | 65 { |
72 » CJS_Object::Alert(pContext, swMsg); | 66 CJS_Object::Alert(pContext, swMsg); |
73 } | 67 } |
74 | 68 |
75 CJS_Timer* CJS_EmbedObj::BeginTimer(CPDFDoc_Environment * pApp,FX_UINT nElapse) | 69 CJS_Timer* CJS_EmbedObj::BeginTimer(CPDFDoc_Environment * pApp,FX_UINT nElapse) |
76 { | 70 { |
77 » CJS_Timer* pTimer = new CJS_Timer(this,pApp); | 71 CJS_Timer* pTimer = new CJS_Timer(this,pApp); |
78 » pTimer->SetJSTimer(nElapse); | 72 pTimer->SetJSTimer(nElapse); |
79 | 73 |
80 » return pTimer; | 74 return pTimer; |
81 } | 75 } |
82 | 76 |
83 void CJS_EmbedObj::EndTimer(CJS_Timer* pTimer) | 77 void CJS_EmbedObj::EndTimer(CJS_Timer* pTimer) |
84 { | 78 { |
85 » ASSERT(pTimer != NULL); | 79 ASSERT(pTimer != NULL); |
86 » pTimer->KillJSTimer(); | 80 pTimer->KillJSTimer(); |
87 » delete pTimer; | 81 delete pTimer; |
88 } | 82 } |
89 | 83 |
90 /* --------------------------------- CJS_Object -------------------------------
-- */ | 84 /* --------------------------------- CJS_Object -------------------------------
-- */ |
91 void FreeObject(const v8::WeakCallbackInfo<CJS_Object>& data) | 85 void FreeObject(const v8::WeakCallbackInfo<CJS_Object>& data) |
92 { | 86 { |
93 » CJS_Object* pJSObj = data.GetParameter(); | 87 CJS_Object* pJSObj = data.GetParameter(); |
94 pJSObj->ExitInstance(); | 88 pJSObj->ExitInstance(); |
95 delete pJSObj; | 89 delete pJSObj; |
96 » JS_FreePrivate(data.GetInternalField(0)); | 90 JS_FreePrivate(data.GetInternalField(0)); |
97 } | 91 } |
98 | 92 |
99 void DisposeObject(const v8::WeakCallbackInfo<CJS_Object>& data) | 93 void DisposeObject(const v8::WeakCallbackInfo<CJS_Object>& data) |
100 { | 94 { |
101 » CJS_Object* pJSObj = data.GetParameter(); | 95 CJS_Object* pJSObj = data.GetParameter(); |
102 pJSObj->Dispose(); | 96 pJSObj->Dispose(); |
103 data.SetSecondPassCallback(FreeObject); | 97 data.SetSecondPassCallback(FreeObject); |
104 } | 98 } |
105 | 99 |
106 CJS_Object::CJS_Object(JSFXObject pObject) :m_pEmbedObj(NULL) | 100 CJS_Object::CJS_Object(JSFXObject pObject) :m_pEmbedObj(NULL) |
107 { | 101 { |
108 » v8::Local<v8::Context> context = pObject->CreationContext(); | 102 v8::Local<v8::Context> context = pObject->CreationContext(); |
109 » m_pIsolate = context->GetIsolate(); | 103 m_pIsolate = context->GetIsolate(); |
110 » m_pObject.Reset(m_pIsolate, pObject); | 104 m_pObject.Reset(m_pIsolate, pObject); |
111 }; | 105 }; |
112 | 106 |
113 CJS_Object::~CJS_Object(void) | 107 CJS_Object::~CJS_Object(void) |
114 { | 108 { |
115 » delete m_pEmbedObj; | 109 delete m_pEmbedObj; |
116 » m_pEmbedObj = NULL; | 110 m_pEmbedObj = NULL; |
117 | 111 |
118 » m_pObject.Reset(); | 112 m_pObject.Reset(); |
119 }; | 113 }; |
120 | 114 |
121 void» CJS_Object::MakeWeak() | 115 void CJS_Object::MakeWeak() |
122 { | 116 { |
123 » m_pObject.SetWeak( | 117 m_pObject.SetWeak( |
124 this, DisposeObject, v8::WeakCallbackType::kInternalFields); | 118 this, DisposeObject, v8::WeakCallbackType::kInternalFields); |
125 } | 119 } |
126 | 120 |
127 void CJS_Object::Dispose() | 121 void CJS_Object::Dispose() |
128 { | 122 { |
129 m_pObject.Reset(); | 123 m_pObject.Reset(); |
130 } | 124 } |
131 | 125 |
132 CPDFSDK_PageView* CJS_Object::JSGetPageView(IFXJS_Context* cc) | 126 CPDFSDK_PageView* CJS_Object::JSGetPageView(IFXJS_Context* cc) |
133 { | 127 { |
134 » return FXJS_GetPageView(cc); | 128 return FXJS_GetPageView(cc); |
135 } | 129 } |
136 | 130 |
137 int CJS_Object::MsgBox(CPDFDoc_Environment* pApp, CPDFSDK_PageView* pPageView, c
onst FX_WCHAR* swMsg, const FX_WCHAR* swTitle, FX_UINT nType, FX_UINT nIcon) | 131 int CJS_Object::MsgBox(CPDFDoc_Environment* pApp, CPDFSDK_PageView* pPageView, c
onst FX_WCHAR* swMsg, const FX_WCHAR* swTitle, FX_UINT nType, FX_UINT nIcon) |
138 { | 132 { |
139 » return FXJS_MsgBox(pApp, pPageView, swMsg, swTitle, nType, nIcon); | 133 return FXJS_MsgBox(pApp, pPageView, swMsg, swTitle, nType, nIcon); |
140 } | 134 } |
141 | 135 |
142 void CJS_Object::Alert(CJS_Context* pContext, const FX_WCHAR* swMsg) | 136 void CJS_Object::Alert(CJS_Context* pContext, const FX_WCHAR* swMsg) |
143 { | 137 { |
144 » ASSERT(pContext != NULL); | 138 ASSERT(pContext != NULL); |
145 | 139 |
146 » if (pContext->IsMsgBoxEnabled()) | 140 if (pContext->IsMsgBoxEnabled()) |
147 » { | 141 { |
148 » » CPDFDoc_Environment* pApp = pContext->GetReaderApp(); | 142 CPDFDoc_Environment* pApp = pContext->GetReaderApp(); |
149 » » if(pApp) | 143 if(pApp) |
150 » » » pApp->JS_appAlert(swMsg, NULL, 0, 3); | 144 pApp->JS_appAlert(swMsg, NULL, 0, 3); |
151 » } | 145 } |
152 } | 146 } |
153 | |
154 | |
OLD | NEW |