Cleanup dead code in CPDF_DIBSource::LoadJpxBitmap() and friends.
[pdfium.git] / fpdfsdk / src / javascript / JS_Context.cpp
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/IJavaScript.h"
8 #include "../../include/javascript/JS_Context.h"
9 #include "../../include/javascript/JS_EventHandler.h"
10 #include "../../include/javascript/JS_Runtime.h"
11 #include "../../include/javascript/JavaScript.h"
12 #include "../../include/javascript/resource.h"
13
14 /* -------------------------- CJS_Context -------------------------- */
15
16 CJS_Context::CJS_Context(CJS_Runtime* pRuntime)
17     : m_pRuntime(pRuntime), m_bBusy(FALSE), m_bMsgBoxEnable(TRUE) {
18   m_pEventHandler = new CJS_EventHandler(this);
19 }
20
21 CJS_Context::~CJS_Context() {
22   delete m_pEventHandler;
23 }
24
25 CPDFSDK_Document* CJS_Context::GetReaderDocument() {
26   return m_pRuntime->GetReaderDocument();
27 }
28
29 CPDFDoc_Environment* CJS_Context::GetReaderApp() {
30   ASSERT(m_pRuntime != NULL);
31
32   return m_pRuntime->GetReaderApp();
33 }
34
35 FX_BOOL CJS_Context::RunScript(const CFX_WideString& script,
36                                CFX_WideString& info) {
37   v8::Isolate::Scope isolate_scope(m_pRuntime->GetIsolate());
38   v8::HandleScope handle_scope(m_pRuntime->GetIsolate());
39   v8::Local<v8::Context> context = m_pRuntime->NewJSContext();
40   v8::Context::Scope context_scope(context);
41
42   if (m_bBusy) {
43     info = JSGetStringFromID(this, IDS_STRING_JSBUSY);
44     return FALSE;
45   }
46   m_bBusy = TRUE;
47
48   ASSERT(m_pEventHandler->IsValid());
49   if (!m_pRuntime->AddEventToLoop(m_pEventHandler->TargetName(),
50                                   m_pEventHandler->EventType())) {
51     info = JSGetStringFromID(this, IDS_STRING_JSEVENT);
52     return FALSE;
53   }
54
55   FXJSErr error = {NULL, NULL, 0};
56   int nRet = 0;
57   if (script.GetLength() > 0) {
58     nRet = JS_Execute(*m_pRuntime, this, script.c_str(), script.GetLength(),
59                       &error);
60   }
61
62   if (nRet < 0) {
63     CFX_WideString sLine;
64     sLine.Format(L"[ Line: %05d { %s } ] : %s", error.linnum - 1, error.srcline,
65                  error.message);
66     info += sLine;
67   } else {
68     info = JSGetStringFromID(this, IDS_STRING_RUN);
69   }
70
71   m_pRuntime->RemoveEventInLoop(m_pEventHandler->TargetName(),
72                                 m_pEventHandler->EventType());
73
74   m_pEventHandler->Destroy();
75   m_bBusy = FALSE;
76
77   return nRet >= 0;
78 }
79
80 void CJS_Context::OnApp_Init() {
81   m_pEventHandler->OnApp_Init();
82 }
83
84 void CJS_Context::OnDoc_Open(CPDFSDK_Document* pDoc,
85                              const CFX_WideString& strTargetName) {
86   m_pEventHandler->OnDoc_Open(pDoc, strTargetName);
87 }
88
89 void CJS_Context::OnDoc_WillPrint(CPDFSDK_Document* pDoc) {
90   m_pEventHandler->OnDoc_WillPrint(pDoc);
91 }
92
93 void CJS_Context::OnDoc_DidPrint(CPDFSDK_Document* pDoc) {
94   m_pEventHandler->OnDoc_DidPrint(pDoc);
95 }
96
97 void CJS_Context::OnDoc_WillSave(CPDFSDK_Document* pDoc) {
98   m_pEventHandler->OnDoc_WillSave(pDoc);
99 }
100
101 void CJS_Context::OnDoc_DidSave(CPDFSDK_Document* pDoc) {
102   m_pEventHandler->OnDoc_DidSave(pDoc);
103 }
104
105 void CJS_Context::OnDoc_WillClose(CPDFSDK_Document* pDoc) {
106   m_pEventHandler->OnDoc_WillClose(pDoc);
107 }
108
109 void CJS_Context::OnPage_Open(CPDFSDK_Document* pTarget) {
110   m_pEventHandler->OnPage_Open(pTarget);
111 }
112
113 void CJS_Context::OnPage_Close(CPDFSDK_Document* pTarget) {
114   m_pEventHandler->OnPage_Close(pTarget);
115 }
116
117 void CJS_Context::OnPage_InView(CPDFSDK_Document* pTarget) {
118   m_pEventHandler->OnPage_InView(pTarget);
119 }
120
121 void CJS_Context::OnPage_OutView(CPDFSDK_Document* pTarget) {
122   m_pEventHandler->OnPage_OutView(pTarget);
123 }
124
125 void CJS_Context::OnField_MouseDown(FX_BOOL bModifier,
126                                     FX_BOOL bShift,
127                                     CPDF_FormField* pTarget) {
128   m_pEventHandler->OnField_MouseDown(bModifier, bShift, pTarget);
129 }
130
131 void CJS_Context::OnField_MouseEnter(FX_BOOL bModifier,
132                                      FX_BOOL bShift,
133                                      CPDF_FormField* pTarget) {
134   m_pEventHandler->OnField_MouseEnter(bModifier, bShift, pTarget);
135 }
136
137 void CJS_Context::OnField_MouseExit(FX_BOOL bModifier,
138                                     FX_BOOL bShift,
139                                     CPDF_FormField* pTarget) {
140   m_pEventHandler->OnField_MouseExit(bModifier, bShift, pTarget);
141 }
142
143 void CJS_Context::OnField_MouseUp(FX_BOOL bModifier,
144                                   FX_BOOL bShift,
145                                   CPDF_FormField* pTarget) {
146   m_pEventHandler->OnField_MouseUp(bModifier, bShift, pTarget);
147 }
148
149 void CJS_Context::OnField_Focus(FX_BOOL bModifier,
150                                 FX_BOOL bShift,
151                                 CPDF_FormField* pTarget,
152                                 const CFX_WideString& Value) {
153   m_pEventHandler->OnField_Focus(bModifier, bShift, pTarget, Value);
154 }
155
156 void CJS_Context::OnField_Blur(FX_BOOL bModifier,
157                                FX_BOOL bShift,
158                                CPDF_FormField* pTarget,
159                                const CFX_WideString& Value) {
160   m_pEventHandler->OnField_Blur(bModifier, bShift, pTarget, Value);
161 }
162
163 void CJS_Context::OnField_Calculate(CPDF_FormField* pSource,
164                                     CPDF_FormField* pTarget,
165                                     CFX_WideString& Value,
166                                     FX_BOOL& bRc) {
167   m_pEventHandler->OnField_Calculate(pSource, pTarget, Value, bRc);
168 }
169
170 void CJS_Context::OnField_Format(CPDF_FormField* pTarget,
171                                  CFX_WideString& Value,
172                                  FX_BOOL bWillCommit) {
173   m_pEventHandler->OnField_Format(pTarget, Value, bWillCommit);
174 }
175
176 void CJS_Context::OnField_Keystroke(CFX_WideString& strChange,
177                                     const CFX_WideString& strChangeEx,
178                                     FX_BOOL bKeyDown,
179                                     FX_BOOL bModifier,
180                                     int& nSelEnd,
181                                     int& nSelStart,
182                                     FX_BOOL bShift,
183                                     CPDF_FormField* pTarget,
184                                     CFX_WideString& Value,
185                                     FX_BOOL bWillCommit,
186                                     FX_BOOL bFieldFull,
187                                     FX_BOOL& bRc) {
188   m_pEventHandler->OnField_Keystroke(
189       strChange, strChangeEx, bKeyDown, bModifier, nSelEnd, nSelStart, bShift,
190       pTarget, Value, bWillCommit, bFieldFull, bRc);
191 }
192
193 void CJS_Context::OnField_Validate(CFX_WideString& strChange,
194                                    const CFX_WideString& strChangeEx,
195                                    FX_BOOL bKeyDown,
196                                    FX_BOOL bModifier,
197                                    FX_BOOL bShift,
198                                    CPDF_FormField* pTarget,
199                                    CFX_WideString& Value,
200                                    FX_BOOL& bRc) {
201   m_pEventHandler->OnField_Validate(strChange, strChangeEx, bKeyDown, bModifier,
202                                     bShift, pTarget, Value, bRc);
203 }
204
205 void CJS_Context::OnScreen_Focus(FX_BOOL bModifier,
206                                  FX_BOOL bShift,
207                                  CPDFSDK_Annot* pScreen) {
208   m_pEventHandler->OnScreen_Focus(bModifier, bShift, pScreen);
209 }
210
211 void CJS_Context::OnScreen_Blur(FX_BOOL bModifier,
212                                 FX_BOOL bShift,
213                                 CPDFSDK_Annot* pScreen) {
214   m_pEventHandler->OnScreen_Blur(bModifier, bShift, pScreen);
215 }
216
217 void CJS_Context::OnScreen_Open(FX_BOOL bModifier,
218                                 FX_BOOL bShift,
219                                 CPDFSDK_Annot* pScreen) {
220   m_pEventHandler->OnScreen_Open(bModifier, bShift, pScreen);
221 }
222
223 void CJS_Context::OnScreen_Close(FX_BOOL bModifier,
224                                  FX_BOOL bShift,
225                                  CPDFSDK_Annot* pScreen) {
226   m_pEventHandler->OnScreen_Close(bModifier, bShift, pScreen);
227 }
228
229 void CJS_Context::OnScreen_MouseDown(FX_BOOL bModifier,
230                                      FX_BOOL bShift,
231                                      CPDFSDK_Annot* pScreen) {
232   m_pEventHandler->OnScreen_MouseDown(bModifier, bShift, pScreen);
233 }
234
235 void CJS_Context::OnScreen_MouseUp(FX_BOOL bModifier,
236                                    FX_BOOL bShift,
237                                    CPDFSDK_Annot* pScreen) {
238   m_pEventHandler->OnScreen_MouseUp(bModifier, bShift, pScreen);
239 }
240
241 void CJS_Context::OnScreen_MouseEnter(FX_BOOL bModifier,
242                                       FX_BOOL bShift,
243                                       CPDFSDK_Annot* pScreen) {
244   m_pEventHandler->OnScreen_MouseEnter(bModifier, bShift, pScreen);
245 }
246
247 void CJS_Context::OnScreen_MouseExit(FX_BOOL bModifier,
248                                      FX_BOOL bShift,
249                                      CPDFSDK_Annot* pScreen) {
250   m_pEventHandler->OnScreen_MouseExit(bModifier, bShift, pScreen);
251 }
252
253 void CJS_Context::OnScreen_InView(FX_BOOL bModifier,
254                                   FX_BOOL bShift,
255                                   CPDFSDK_Annot* pScreen) {
256   m_pEventHandler->OnScreen_InView(bModifier, bShift, pScreen);
257 }
258
259 void CJS_Context::OnScreen_OutView(FX_BOOL bModifier,
260                                    FX_BOOL bShift,
261                                    CPDFSDK_Annot* pScreen) {
262   m_pEventHandler->OnScreen_OutView(bModifier, bShift, pScreen);
263 }
264
265 void CJS_Context::OnBookmark_MouseUp(CPDF_Bookmark* pBookMark) {
266   m_pEventHandler->OnBookmark_MouseUp(pBookMark);
267 }
268
269 void CJS_Context::OnLink_MouseUp(CPDFSDK_Document* pTarget) {
270   m_pEventHandler->OnLink_MouseUp(pTarget);
271 }
272
273 void CJS_Context::OnConsole_Exec() {
274   m_pEventHandler->OnConsole_Exec();
275 }
276
277 void CJS_Context::OnExternal_Exec() {
278   m_pEventHandler->OnExternal_Exec();
279 }
280
281 void CJS_Context::OnBatchExec(CPDFSDK_Document* pTarget) {
282   m_pEventHandler->OnBatchExec(pTarget);
283 }
284
285 void CJS_Context::OnMenu_Exec(CPDFSDK_Document* pTarget,
286                               const CFX_WideString& strTargetName) {
287   m_pEventHandler->OnMenu_Exec(pTarget, strTargetName);
288 }