blob: c2e26f7501b3fa571d60ecc877ecc3b2defefca4 [file] [log] [blame]
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001// 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.
Tom Sepez7b5bc262015-03-05 16:44:22 -08004
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07005// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
7#include "../include/fsdk_define.h"
Bo Xufdc00a72014-10-28 23:03:33 -07008#include "../include/fpdfxfa/fpdfxfa_doc.h"
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07009#include "../include/fsdk_mgr.h"
10#include "../include/fsdk_actionhandler.h"
11#include "../include/javascript/IJavaScript.h"
12
Tom Sepez3b5f1242015-09-01 14:06:55 -070013CPDFSDK_ActionHandler::CPDFSDK_ActionHandler()
14 : m_pFormActionHandler(new CPDFSDK_FormActionHandler) {
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070015}
16
Nico Weber9d8ec5a2015-08-04 13:00:21 -070017FX_BOOL CPDFSDK_ActionHandler::DoAction_DocOpen(const CPDF_Action& action,
18 CPDFSDK_Document* pDocument) {
19 CFX_PtrList list;
20 return ExecuteDocumentOpenAction(action, pDocument, list);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070021}
22
Nico Weber9d8ec5a2015-08-04 13:00:21 -070023FX_BOOL CPDFSDK_ActionHandler::DoAction_JavaScript(
24 const CPDF_Action& JsAction,
25 CFX_WideString csJSName,
26 CPDFSDK_Document* pDocument) {
27 if (JsAction.GetType() == CPDF_Action::JavaScript) {
28 CFX_WideString swJS = JsAction.GetJavaScript();
29 if (!swJS.IsEmpty()) {
30 RunDocumentOpenJavaScript(pDocument, csJSName, swJS);
31 return TRUE;
32 }
33 }
34
35 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070036}
37
Nico Weber9d8ec5a2015-08-04 13:00:21 -070038FX_BOOL CPDFSDK_ActionHandler::DoAction_FieldJavaScript(
39 const CPDF_Action& JsAction,
40 CPDF_AAction::AActionType type,
41 CPDFSDK_Document* pDocument,
42 CPDF_FormField* pFormField,
43 PDFSDK_FieldAction& data) {
44 CPDFDoc_Environment* pEnv = pDocument->GetEnv();
45 ASSERT(pEnv);
46 if (pEnv->IsJSInitiated() && JsAction.GetType() == CPDF_Action::JavaScript) {
47 CFX_WideString swJS = JsAction.GetJavaScript();
48 if (!swJS.IsEmpty()) {
49 RunFieldJavaScript(pDocument, pFormField, type, data, swJS);
50 return TRUE;
51 }
52 }
53 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070054}
55
Nico Weber9d8ec5a2015-08-04 13:00:21 -070056FX_BOOL CPDFSDK_ActionHandler::DoAction_Page(
57 const CPDF_Action& action,
58 enum CPDF_AAction::AActionType eType,
59 CPDFSDK_Document* pDocument) {
60 CFX_PtrList list;
61 return ExecuteDocumentPageAction(action, eType, pDocument, list);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070062}
63
Nico Weber9d8ec5a2015-08-04 13:00:21 -070064FX_BOOL CPDFSDK_ActionHandler::DoAction_Document(
65 const CPDF_Action& action,
66 enum CPDF_AAction::AActionType eType,
67 CPDFSDK_Document* pDocument) {
68 CFX_PtrList list;
69 return ExecuteDocumentPageAction(action, eType, pDocument, list);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070070}
71
Nico Weber9d8ec5a2015-08-04 13:00:21 -070072FX_BOOL CPDFSDK_ActionHandler::DoAction_BookMark(CPDF_Bookmark* pBookMark,
73 const CPDF_Action& action,
74 CPDF_AAction::AActionType type,
75 CPDFSDK_Document* pDocument) {
76 CFX_PtrList list;
77 return ExecuteBookMark(action, pDocument, pBookMark, list);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070078}
79
Nico Weber9d8ec5a2015-08-04 13:00:21 -070080FX_BOOL CPDFSDK_ActionHandler::DoAction_Screen(const CPDF_Action& action,
81 CPDF_AAction::AActionType type,
82 CPDFSDK_Document* pDocument,
83 CPDFSDK_Annot* pScreen) {
84 CFX_PtrList list;
85 return ExecuteScreenAction(action, type, pDocument, pScreen, list);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070086}
87
Nico Weber9d8ec5a2015-08-04 13:00:21 -070088FX_BOOL CPDFSDK_ActionHandler::DoAction_Link(const CPDF_Action& action,
89 CPDFSDK_Document* pDocument) {
90 CFX_PtrList list;
91 return ExecuteLinkAction(action, pDocument, list);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070092}
93
Nico Weber9d8ec5a2015-08-04 13:00:21 -070094FX_BOOL CPDFSDK_ActionHandler::DoAction_Field(const CPDF_Action& action,
95 CPDF_AAction::AActionType type,
96 CPDFSDK_Document* pDocument,
97 CPDF_FormField* pFormField,
98 PDFSDK_FieldAction& data) {
99 CFX_PtrList list;
100 return ExecuteFieldAction(action, type, pDocument, pFormField, data, list);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700101}
102
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700103FX_BOOL CPDFSDK_ActionHandler::ExecuteDocumentOpenAction(
104 const CPDF_Action& action,
105 CPDFSDK_Document* pDocument,
106 CFX_PtrList& list) {
107 CPDF_Dictionary* pDict = action.GetDict();
108 if (list.Find(pDict))
109 return FALSE;
110
111 list.AddTail(pDict);
112
113 CPDFDoc_Environment* pEnv = pDocument->GetEnv();
114 ASSERT(pEnv);
115 if (action.GetType() == CPDF_Action::JavaScript) {
116 if (pEnv->IsJSInitiated()) {
117 CFX_WideString swJS = action.GetJavaScript();
118 if (!swJS.IsEmpty()) {
119 RunDocumentOpenJavaScript(pDocument, L"", swJS);
120 }
121 }
122 } else {
123 DoAction_NoJs(action, pDocument);
124 }
125
126 for (int32_t i = 0, sz = action.GetSubActionsCount(); i < sz; i++) {
127 CPDF_Action subaction = action.GetSubAction(i);
128 if (!ExecuteDocumentOpenAction(subaction, pDocument, list))
129 return FALSE;
130 }
131
132 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700133}
134
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700135FX_BOOL CPDFSDK_ActionHandler::ExecuteLinkAction(const CPDF_Action& action,
136 CPDFSDK_Document* pDocument,
137 CFX_PtrList& list) {
138 ASSERT(pDocument != NULL);
Tom Sepez7b5bc262015-03-05 16:44:22 -0800139
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700140 CPDF_Dictionary* pDict = action.GetDict();
141 if (list.Find(pDict))
142 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700143
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700144 list.AddTail(pDict);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700145
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700146 CPDFDoc_Environment* pEnv = pDocument->GetEnv();
147 ASSERT(pEnv);
148 if (action.GetType() == CPDF_Action::JavaScript) {
149 if (pEnv->IsJSInitiated()) {
150 CFX_WideString swJS = action.GetJavaScript();
151 if (!swJS.IsEmpty()) {
152 IFXJS_Runtime* pRuntime = pDocument->GetJsRuntime(); //????
153 ASSERT(pRuntime != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700154
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700155 pRuntime->SetReaderDocument(pDocument);
156
157 IFXJS_Context* pContext = pRuntime->NewContext();
158 ASSERT(pContext != NULL);
159
160 pContext->OnLink_MouseUp(pDocument);
161
162 CFX_WideString csInfo;
163 FX_BOOL bRet = pContext->RunScript(swJS, csInfo);
164 if (!bRet) {
165 // FIXME: return error.
166 }
167
168 pRuntime->ReleaseContext(pContext);
169 }
170 }
171 } else {
172 DoAction_NoJs(action, pDocument);
173 }
174
175 for (int32_t i = 0, sz = action.GetSubActionsCount(); i < sz; i++) {
176 CPDF_Action subaction = action.GetSubAction(i);
177 if (!ExecuteLinkAction(subaction, pDocument, list))
178 return FALSE;
179 }
180
181 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700182}
183
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700184FX_BOOL CPDFSDK_ActionHandler::ExecuteDocumentPageAction(
185 const CPDF_Action& action,
186 CPDF_AAction::AActionType type,
187 CPDFSDK_Document* pDocument,
188 CFX_PtrList& list) {
189 ASSERT(pDocument != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700190
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700191 CPDF_Dictionary* pDict = action.GetDict();
192 if (list.Find(pDict))
193 return FALSE;
Tom Sepez7b5bc262015-03-05 16:44:22 -0800194
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700195 list.AddTail(pDict);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700196
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700197 CPDFDoc_Environment* pEnv = pDocument->GetEnv();
198 ASSERT(pEnv);
199 if (action.GetType() == CPDF_Action::JavaScript) {
200 if (pEnv->IsJSInitiated()) {
201 CFX_WideString swJS = action.GetJavaScript();
202 if (!swJS.IsEmpty()) {
203 RunDocumentPageJavaScript(pDocument, type, swJS);
204 }
205 }
206 } else {
207 DoAction_NoJs(action, pDocument);
208 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700209
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700210 if (!IsValidDocView(pDocument))
211 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700212
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700213 for (int32_t i = 0, sz = action.GetSubActionsCount(); i < sz; i++) {
214 CPDF_Action subaction = action.GetSubAction(i);
215 if (!ExecuteDocumentPageAction(subaction, type, pDocument, list))
216 return FALSE;
217 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700218
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700219 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700220}
221
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700222FX_BOOL CPDFSDK_ActionHandler::IsValidField(CPDFSDK_Document* pDocument,
223 CPDF_Dictionary* pFieldDict) {
Chris Palmer9047b8b2014-08-06 14:17:45 -0700224 ASSERT(pDocument != NULL);
225 ASSERT(pFieldDict != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700226
Chris Palmer9047b8b2014-08-06 14:17:45 -0700227 CPDFSDK_InterForm* pInterForm = pDocument->GetInterForm();
228 ASSERT(pInterForm != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700229
Chris Palmer9047b8b2014-08-06 14:17:45 -0700230 CPDF_InterForm* pPDFInterForm = pInterForm->GetInterForm();
231 ASSERT(pPDFInterForm != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700232
Chris Palmer9047b8b2014-08-06 14:17:45 -0700233 return pPDFInterForm->GetFieldByDict(pFieldDict) != NULL;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700234}
235
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700236FX_BOOL CPDFSDK_ActionHandler::ExecuteFieldAction(
237 const CPDF_Action& action,
238 CPDF_AAction::AActionType type,
239 CPDFSDK_Document* pDocument,
240 CPDF_FormField* pFormField,
241 PDFSDK_FieldAction& data,
242 CFX_PtrList& list) {
243 ASSERT(pDocument != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700244
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700245 CPDF_Dictionary* pDict = action.GetDict();
246 if (list.Find(pDict))
247 return FALSE;
Tom Sepez7b5bc262015-03-05 16:44:22 -0800248
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700249 list.AddTail(pDict);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700250
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700251 CPDFDoc_Environment* pEnv = pDocument->GetEnv();
252 ASSERT(pEnv);
253 if (action.GetType() == CPDF_Action::JavaScript) {
254 if (pEnv->IsJSInitiated()) {
255 CFX_WideString swJS = action.GetJavaScript();
256 if (!swJS.IsEmpty()) {
257 RunFieldJavaScript(pDocument, pFormField, type, data, swJS);
258 if (!IsValidField(pDocument, pFormField->GetFieldDict()))
259 return FALSE;
260 }
261 }
262 } else {
263 DoAction_NoJs(action, pDocument);
264 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700265
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700266 for (int32_t i = 0, sz = action.GetSubActionsCount(); i < sz; i++) {
267 CPDF_Action subaction = action.GetSubAction(i);
268 if (!ExecuteFieldAction(subaction, type, pDocument, pFormField, data, list))
269 return FALSE;
270 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700271
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700272 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700273}
274
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700275FX_BOOL CPDFSDK_ActionHandler::ExecuteScreenAction(
276 const CPDF_Action& action,
277 CPDF_AAction::AActionType type,
278 CPDFSDK_Document* pDocument,
279 CPDFSDK_Annot* pScreen,
280 CFX_PtrList& list) {
281 ASSERT(pDocument != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700282
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700283 CPDF_Dictionary* pDict = action.GetDict();
284 if (list.Find(pDict))
285 return FALSE;
Tom Sepez7b5bc262015-03-05 16:44:22 -0800286
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700287 list.AddTail(pDict);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700288
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700289 CPDFDoc_Environment* pEnv = pDocument->GetEnv();
290 ASSERT(pEnv);
291 if (action.GetType() == CPDF_Action::JavaScript) {
292 if (pEnv->IsJSInitiated()) {
293 CFX_WideString swJS = action.GetJavaScript();
294 if (!swJS.IsEmpty()) {
295 IFXJS_Runtime* pRuntime = pDocument->GetJsRuntime();
296 ASSERT(pRuntime != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700297
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700298 pRuntime->SetReaderDocument(pDocument);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700299
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700300 IFXJS_Context* pContext = pRuntime->NewContext();
301 ASSERT(pContext != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700302
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700303 // switch (type)
304 // {
305 // case CPDF_AAction::CursorEnter:
306 // pContext->OnScreen_MouseEnter(IsCTRLpressed(),
307 // IsSHIFTpressed(), pScreen);
308 // break;
309 // case CPDF_AAction::CursorExit:
310 // pContext->OnScreen_MouseExit(IsCTRLpressed(),
311 // IsSHIFTpressed(), pScreen);
312 // break;
313 // case CPDF_AAction::ButtonDown:
314 // pContext->OnScreen_MouseDown(IsCTRLpressed(),
315 // IsSHIFTpressed(), pScreen);
316 // break;
317 // case CPDF_AAction::ButtonUp:
318 // pContext->OnScreen_MouseUp(IsCTRLpressed(),
319 // IsSHIFTpressed(), pScreen);
320 // break;
321 // case CPDF_AAction::GetFocus:
322 // pContext->OnScreen_Focus(IsCTRLpressed(),
323 // IsSHIFTpressed(), pScreen);
324 // break;
325 // case CPDF_AAction::LoseFocus:
326 // pContext->OnScreen_Blur(IsCTRLpressed(),
327 // IsSHIFTpressed(), pScreen);
328 // break;
329 // case CPDF_AAction::PageOpen:
330 // pContext->OnScreen_Open(IsCTRLpressed(),
331 // IsSHIFTpressed(), pScreen);
332 // break;
333 // case CPDF_AAction::PageClose:
334 // pContext->OnScreen_Close(IsCTRLpressed(),
335 // IsSHIFTpressed(), pScreen);
336 // break;
337 // case CPDF_AAction::PageVisible:
338 // pContext->OnScreen_InView(IsCTRLpressed(),
339 // IsSHIFTpressed(), pScreen);
340 // break;
341 // case CPDF_AAction::PageInvisible:
342 // pContext->OnScreen_OutView(IsCTRLpressed(),
343 // IsSHIFTpressed(), pScreen);
344 // break;
345 // default:
346 // ASSERT(FALSE);
347 // break;
348 // }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700349
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700350 CFX_WideString csInfo;
351 FX_BOOL bRet = pContext->RunScript(swJS, csInfo);
352 if (!bRet) {
353 // CBCL_FormNotify::MsgBoxJSError(pPageView->GetPageViewWnd(),
354 // csInfo);
355 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700356
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700357 pRuntime->ReleaseContext(pContext);
358 }
359 }
360 } else {
361 DoAction_NoJs(action, pDocument);
362 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700363
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700364 for (int32_t i = 0, sz = action.GetSubActionsCount(); i < sz; i++) {
365 CPDF_Action subaction = action.GetSubAction(i);
366 if (!ExecuteScreenAction(subaction, type, pDocument, pScreen, list))
367 return FALSE;
368 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700369
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700370 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700371}
372
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700373FX_BOOL CPDFSDK_ActionHandler::ExecuteBookMark(const CPDF_Action& action,
374 CPDFSDK_Document* pDocument,
375 CPDF_Bookmark* pBookmark,
376 CFX_PtrList& list) {
377 ASSERT(pDocument != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700378
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700379 CPDF_Dictionary* pDict = action.GetDict();
380 if (list.Find(pDict))
381 return FALSE;
Tom Sepez7b5bc262015-03-05 16:44:22 -0800382
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700383 list.AddTail(pDict);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700384
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700385 CPDFDoc_Environment* pEnv = pDocument->GetEnv();
386 ASSERT(pEnv);
387 if (action.GetType() == CPDF_Action::JavaScript) {
388 if (pEnv->IsJSInitiated()) {
389 CFX_WideString swJS = action.GetJavaScript();
390 if (!swJS.IsEmpty()) {
391 IFXJS_Runtime* pRuntime = pDocument->GetJsRuntime();
392 ASSERT(pRuntime != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700393
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700394 pRuntime->SetReaderDocument(pDocument);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700395
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700396 IFXJS_Context* pContext = pRuntime->NewContext();
397 ASSERT(pContext != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700398
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700399 pContext->OnBookmark_MouseUp(pBookmark);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700400
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700401 CFX_WideString csInfo;
402 FX_BOOL bRet = pContext->RunScript(swJS, csInfo);
403 if (!bRet) {
404 // CBCL_FormNotify::MsgBoxJSError(pPageView->GetPageViewWnd(),
405 // csInfo);
406 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700407
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700408 pRuntime->ReleaseContext(pContext);
409 }
410 }
411 } else {
412 DoAction_NoJs(action, pDocument);
413 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700414
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700415 for (int32_t i = 0, sz = action.GetSubActionsCount(); i < sz; i++) {
416 CPDF_Action subaction = action.GetSubAction(i);
417 if (!ExecuteBookMark(subaction, pDocument, pBookmark, list))
418 return FALSE;
419 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700420
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700421 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700422}
423
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700424void CPDFSDK_ActionHandler::DoAction_NoJs(const CPDF_Action& action,
425 CPDFSDK_Document* pDocument) {
426 ASSERT(pDocument != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700427
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700428 switch (action.GetType()) {
429 case CPDF_Action::GoTo:
430 DoAction_GoTo(pDocument, action);
431 break;
432 case CPDF_Action::GoToR:
433 DoAction_GoToR(pDocument, action);
434 break;
435 case CPDF_Action::GoToE:
436 break;
437 case CPDF_Action::Launch:
438 DoAction_Launch(pDocument, action);
439 break;
440 case CPDF_Action::Thread:
441 break;
442 case CPDF_Action::URI:
443 DoAction_URI(pDocument, action);
444 break;
445 case CPDF_Action::Sound:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700446 break;
447 case CPDF_Action::Movie:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700448 break;
449 case CPDF_Action::Hide:
450 if (m_pFormActionHandler) {
451 m_pFormActionHandler->DoAction_Hide(action, pDocument);
452 }
453 break;
454 case CPDF_Action::Named:
455 DoAction_Named(pDocument, action);
456 break;
457 case CPDF_Action::SubmitForm:
458 if (m_pFormActionHandler) {
459 m_pFormActionHandler->DoAction_SubmitForm(action, pDocument);
460 }
461 break;
462 case CPDF_Action::ResetForm:
463 if (m_pFormActionHandler) {
464 m_pFormActionHandler->DoAction_ResetForm(action, pDocument);
465 }
466 break;
467 case CPDF_Action::ImportData:
468 if (m_pFormActionHandler) {
469 m_pFormActionHandler->DoAction_ImportData(action, pDocument);
470 }
471 break;
472 case CPDF_Action::JavaScript:
473 ASSERT(FALSE);
474 break;
475 case CPDF_Action::SetOCGState:
476 DoAction_SetOCGState(pDocument, action);
477 break;
478 case CPDF_Action::Rendition:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700479 break;
480 case CPDF_Action::Trans:
481 break;
482 case CPDF_Action::GoTo3DView:
483 break;
484 default:
485 break;
486 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700487}
488
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700489FX_BOOL CPDFSDK_ActionHandler::IsValidDocView(CPDFSDK_Document* pDocument) {
490 ASSERT(pDocument != NULL);
491 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700492}
493
Tom Sepez7b5bc262015-03-05 16:44:22 -0800494void CPDFSDK_ActionHandler::DoAction_GoTo(CPDFSDK_Document* pDocument,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700495 const CPDF_Action& action) {
496 ASSERT(action);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700497
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700498 CPDF_Document* pPDFDocument = pDocument->GetDocument()->GetPDFDoc();
499 ASSERT(pPDFDocument != NULL);
500 CPDFDoc_Environment* pApp = pDocument->GetEnv();
501 ASSERT(pApp != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700502
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700503 CPDF_Dest MyDest = action.GetDest(pPDFDocument);
504 int nPageIndex = MyDest.GetPageIndex(pPDFDocument);
505 int nFitType = MyDest.GetZoomMode();
506 const CPDF_Array* pMyArray = (CPDF_Array*)MyDest.GetObject();
507 float* pPosAry = NULL;
508 int sizeOfAry = 0;
509 if (pMyArray != NULL) {
510 pPosAry = new float[pMyArray->GetCount()];
511 int j = 0;
512 for (int i = 2; i < (int)pMyArray->GetCount(); i++) {
513 pPosAry[j++] = pMyArray->GetFloat(i);
514 }
515 sizeOfAry = j;
516 }
517 pApp->FFI_DoGoToAction(nPageIndex, nFitType, pPosAry, sizeOfAry);
Lei Zhangda180e92015-08-14 22:22:13 -0700518 delete[] pPosAry;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700519}
520
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700521void CPDFSDK_ActionHandler::DoAction_GoToR(CPDFSDK_Document* pDocument,
522 const CPDF_Action& action) {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700523
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700524void CPDFSDK_ActionHandler::DoAction_Launch(CPDFSDK_Document* pDocument,
525 const CPDF_Action& action) {}
526
527void CPDFSDK_ActionHandler::DoAction_URI(CPDFSDK_Document* pDocument,
528 const CPDF_Action& action) {
529 ASSERT(action);
530
531 CPDFDoc_Environment* pApp = pDocument->GetEnv();
532 ASSERT(pApp != NULL);
533
534 CFX_ByteString sURI = action.GetURI(pDocument->GetDocument()->GetPDFDoc());
535 pApp->FFI_DoURIAction(sURI.c_str());
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700536}
537
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700538void CPDFSDK_ActionHandler::DoAction_Named(CPDFSDK_Document* pDocument,
539 const CPDF_Action& action) {
540 ASSERT(action);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700541
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700542 CFX_ByteString csName = action.GetNamedAction();
543 pDocument->GetEnv()->FFI_ExecuteNamedAction(csName);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700544}
545
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700546void CPDFSDK_ActionHandler::DoAction_SetOCGState(CPDFSDK_Document* pDocument,
547 const CPDF_Action& action) {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700548
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700549void CPDFSDK_ActionHandler::RunFieldJavaScript(CPDFSDK_Document* pDocument,
550 CPDF_FormField* pFormField,
551 CPDF_AAction::AActionType type,
552 PDFSDK_FieldAction& data,
553 const CFX_WideString& script) {
554 ASSERT(type != CPDF_AAction::Calculate);
555 ASSERT(type != CPDF_AAction::Format);
Tom Sepezd7e5cc72015-06-10 14:33:37 -0700556
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700557 ASSERT(pDocument != NULL);
558
559 IFXJS_Runtime* pRuntime = pDocument->GetJsRuntime();
560 ASSERT(pRuntime != NULL);
561
562 pRuntime->SetReaderDocument(pDocument);
563
564 IFXJS_Context* pContext = pRuntime->NewContext();
565 ASSERT(pContext != NULL);
566
567 switch (type) {
568 case CPDF_AAction::CursorEnter:
569 pContext->OnField_MouseEnter(data.bModifier, data.bShift, pFormField);
570 break;
571 case CPDF_AAction::CursorExit:
572 pContext->OnField_MouseExit(data.bModifier, data.bShift, pFormField);
573 break;
574 case CPDF_AAction::ButtonDown:
575 pContext->OnField_MouseDown(data.bModifier, data.bShift, pFormField);
576 break;
577 case CPDF_AAction::ButtonUp:
578 pContext->OnField_MouseUp(data.bModifier, data.bShift, pFormField);
579 break;
580 case CPDF_AAction::GetFocus:
581 pContext->OnField_Focus(data.bModifier, data.bShift, pFormField,
582 data.sValue);
583 break;
584 case CPDF_AAction::LoseFocus:
585 pContext->OnField_Blur(data.bModifier, data.bShift, pFormField,
586 data.sValue);
587 break;
588 case CPDF_AAction::KeyStroke:
589 pContext->OnField_Keystroke(data.sChange, data.sChangeEx, data.bKeyDown,
590 data.bModifier, data.nSelEnd, data.nSelStart,
591 data.bShift, pFormField, data.sValue,
592 data.bWillCommit, data.bFieldFull, data.bRC);
593 break;
594 case CPDF_AAction::Validate:
595 pContext->OnField_Validate(data.sChange, data.sChangeEx, data.bKeyDown,
596 data.bModifier, data.bShift, pFormField,
597 data.sValue, data.bRC);
598 break;
599 default:
600 ASSERT(FALSE);
601 break;
602 }
603
604 CFX_WideString csInfo;
605 FX_BOOL bRet = pContext->RunScript(script, csInfo);
606 if (!bRet) {
607 // CBCL_FormNotify::MsgBoxJSError(pPageView->GetPageViewWnd(), csInfo);
608 }
609
610 pRuntime->ReleaseContext(pContext);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700611}
612
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700613void CPDFSDK_ActionHandler::RunDocumentOpenJavaScript(
614 CPDFSDK_Document* pDocument,
615 const CFX_WideString& sScriptName,
616 const CFX_WideString& script) {
617 ASSERT(pDocument != NULL);
Tom Sepez7b5bc262015-03-05 16:44:22 -0800618
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700619 IFXJS_Runtime* pRuntime = pDocument->GetJsRuntime();
620 ASSERT(pRuntime != NULL);
621
622 pRuntime->SetReaderDocument(pDocument);
623
624 IFXJS_Context* pContext = pRuntime->NewContext();
625 ASSERT(pContext != NULL);
626
627 pContext->OnDoc_Open(pDocument, sScriptName);
628
629 CFX_WideString csInfo;
630 FX_BOOL bRet = pContext->RunScript(script, csInfo);
631 if (!bRet) {
632 // CBCL_FormNotify::MsgBoxJSError(pPageView->GetPageViewWnd(), csInfo);
633 }
634
635 pRuntime->ReleaseContext(pContext);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700636}
637
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700638void CPDFSDK_ActionHandler::RunDocumentPageJavaScript(
639 CPDFSDK_Document* pDocument,
640 CPDF_AAction::AActionType type,
641 const CFX_WideString& script) {
642 ASSERT(pDocument != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700643
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700644 IFXJS_Runtime* pRuntime = pDocument->GetJsRuntime();
645 ASSERT(pRuntime != NULL);
646
647 pRuntime->SetReaderDocument(pDocument);
648
649 IFXJS_Context* pContext = pRuntime->NewContext();
650 ASSERT(pContext != NULL);
651
652 switch (type) {
653 case CPDF_AAction::OpenPage:
654 pContext->OnPage_Open(pDocument);
655 break;
656 case CPDF_AAction::ClosePage:
657 pContext->OnPage_Close(pDocument);
658 break;
659 case CPDF_AAction::CloseDocument:
660 pContext->OnDoc_WillClose(pDocument);
661 break;
662 case CPDF_AAction::SaveDocument:
663 pContext->OnDoc_WillSave(pDocument);
664 break;
665 case CPDF_AAction::DocumentSaved:
666 pContext->OnDoc_DidSave(pDocument);
667 break;
668 case CPDF_AAction::PrintDocument:
669 pContext->OnDoc_WillPrint(pDocument);
670 break;
671 case CPDF_AAction::DocumentPrinted:
672 pContext->OnDoc_DidPrint(pDocument);
673 break;
674 case CPDF_AAction::PageVisible:
675 pContext->OnPage_InView(pDocument);
676 break;
677 case CPDF_AAction::PageInvisible:
678 pContext->OnPage_OutView(pDocument);
679 break;
680 default:
681 ASSERT(FALSE);
682 break;
683 }
684
685 CFX_WideString csInfo;
686 FX_BOOL bRet = pContext->RunScript(script, csInfo);
687 if (!bRet) {
688 // CBCL_FormNotify::MsgBoxJSError(pPageView->GetPageViewWnd(), csInfo);
689 }
690
691 pRuntime->ReleaseContext(pContext);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700692}
693
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700694FX_BOOL CPDFSDK_FormActionHandler::DoAction_Hide(const CPDF_Action& action,
695 CPDFSDK_Document* pDocument) {
696 ASSERT(pDocument != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700697
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700698 CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm();
699 ASSERT(pInterForm != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700700
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700701 if (pInterForm->DoAction_Hide(action)) {
702 pDocument->SetChangeMark();
703 return TRUE;
704 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700705
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700706 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700707}
708
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700709FX_BOOL CPDFSDK_FormActionHandler::DoAction_SubmitForm(
710 const CPDF_Action& action,
711 CPDFSDK_Document* pDocument) {
712 ASSERT(pDocument != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700713
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700714 CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm();
715 ASSERT(pInterForm != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700716
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700717 return pInterForm->DoAction_SubmitForm(action);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700718}
719
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700720FX_BOOL CPDFSDK_FormActionHandler::DoAction_ResetForm(
721 const CPDF_Action& action,
722 CPDFSDK_Document* pDocument) {
723 ASSERT(pDocument != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700724
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700725 CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm();
726 ASSERT(pInterForm != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700727
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700728 if (pInterForm->DoAction_ResetForm(action)) {
729 return TRUE;
730 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700731
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700732 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700733}
734
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700735FX_BOOL CPDFSDK_FormActionHandler::DoAction_ImportData(
736 const CPDF_Action& action,
737 CPDFSDK_Document* pDocument) {
738 ASSERT(pDocument != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700739
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700740 CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm();
741 ASSERT(pInterForm != NULL);
Tom Sepez7b5bc262015-03-05 16:44:22 -0800742
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700743 if (pInterForm->DoAction_ImportData(action)) {
744 pDocument->SetChangeMark();
745 return TRUE;
746 }
Tom Sepez7b5bc262015-03-05 16:44:22 -0800747
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700748 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700749}