blob: c72bdfd79bdd5759b0e39c33955474c75a9b6ab8 [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
13/* -------------------------- CBA_ActionHandler -------------------------- */
14
Tom Sepez2c286192015-06-18 12:47:11 -070015CPDFSDK_ActionHandler::CPDFSDK_ActionHandler(CPDFDoc_Environment* pEvi)
16 : m_pFormActionHandler(new CPDFSDK_FormActionHandler),
Nico Weber9d8ec5a2015-08-04 13:00:21 -070017 m_pMediaActionHandler(NULL) {}
18
19void CPDFSDK_ActionHandler::SetMediaActionHandler(
20 CPDFSDK_MediaActionHandler* pHandler) {
21 ASSERT(pHandler != NULL);
22 ASSERT(m_pMediaActionHandler == NULL);
23 m_pMediaActionHandler = pHandler;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070024}
25
Nico Weber9d8ec5a2015-08-04 13:00:21 -070026// document open
27FX_BOOL CPDFSDK_ActionHandler::DoAction_DocOpen(const CPDF_Action& action,
28 CPDFSDK_Document* pDocument) {
29 CFX_PtrList list;
30 return ExecuteDocumentOpenAction(action, pDocument, list);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070031}
32
Nico Weber9d8ec5a2015-08-04 13:00:21 -070033// document open
34FX_BOOL CPDFSDK_ActionHandler::DoAction_JavaScript(
35 const CPDF_Action& JsAction,
36 CFX_WideString csJSName,
37 CPDFSDK_Document* pDocument) {
38 if (JsAction.GetType() == CPDF_Action::JavaScript) {
39 CFX_WideString swJS = JsAction.GetJavaScript();
40 if (!swJS.IsEmpty()) {
41 RunDocumentOpenJavaScript(pDocument, csJSName, swJS);
42 return TRUE;
43 }
44 }
45
46 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070047}
48
Nico Weber9d8ec5a2015-08-04 13:00:21 -070049FX_BOOL CPDFSDK_ActionHandler::DoAction_FieldJavaScript(
50 const CPDF_Action& JsAction,
51 CPDF_AAction::AActionType type,
52 CPDFSDK_Document* pDocument,
53 CPDF_FormField* pFormField,
54 PDFSDK_FieldAction& data) {
55 CPDFDoc_Environment* pEnv = pDocument->GetEnv();
56 ASSERT(pEnv);
57 if (pEnv->IsJSInitiated() && JsAction.GetType() == CPDF_Action::JavaScript) {
58 CFX_WideString swJS = JsAction.GetJavaScript();
59 if (!swJS.IsEmpty()) {
60 RunFieldJavaScript(pDocument, pFormField, type, data, swJS);
61 return TRUE;
62 }
63 }
64 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070065}
66
Nico Weber9d8ec5a2015-08-04 13:00:21 -070067FX_BOOL CPDFSDK_ActionHandler::DoAction_Page(
68 const CPDF_Action& action,
69 enum CPDF_AAction::AActionType eType,
70 CPDFSDK_Document* pDocument) {
71 CFX_PtrList list;
72 return ExecuteDocumentPageAction(action, eType, pDocument, list);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070073}
74
Nico Weber9d8ec5a2015-08-04 13:00:21 -070075FX_BOOL CPDFSDK_ActionHandler::DoAction_Document(
76 const CPDF_Action& action,
77 enum CPDF_AAction::AActionType eType,
78 CPDFSDK_Document* pDocument) {
79 CFX_PtrList list;
80 return ExecuteDocumentPageAction(action, eType, pDocument, list);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070081}
82
Nico Weber9d8ec5a2015-08-04 13:00:21 -070083FX_BOOL CPDFSDK_ActionHandler::DoAction_BookMark(CPDF_Bookmark* pBookMark,
84 const CPDF_Action& action,
85 CPDF_AAction::AActionType type,
86 CPDFSDK_Document* pDocument) {
87 CFX_PtrList list;
88 return ExecuteBookMark(action, pDocument, pBookMark, list);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070089}
90
Nico Weber9d8ec5a2015-08-04 13:00:21 -070091FX_BOOL CPDFSDK_ActionHandler::DoAction_Screen(const CPDF_Action& action,
92 CPDF_AAction::AActionType type,
93 CPDFSDK_Document* pDocument,
94 CPDFSDK_Annot* pScreen) {
95 CFX_PtrList list;
96 return ExecuteScreenAction(action, type, pDocument, pScreen, list);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070097}
98
Nico Weber9d8ec5a2015-08-04 13:00:21 -070099FX_BOOL CPDFSDK_ActionHandler::DoAction_Link(const CPDF_Action& action,
100 CPDFSDK_Document* pDocument) {
101 CFX_PtrList list;
102 return ExecuteLinkAction(action, pDocument, list);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700103}
104
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700105FX_BOOL CPDFSDK_ActionHandler::DoAction_Field(const CPDF_Action& action,
106 CPDF_AAction::AActionType type,
107 CPDFSDK_Document* pDocument,
108 CPDF_FormField* pFormField,
109 PDFSDK_FieldAction& data) {
110 CFX_PtrList list;
111 return ExecuteFieldAction(action, type, pDocument, pFormField, data, list);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700112}
113
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700114FX_BOOL CPDFSDK_ActionHandler::ExecuteDocumentOpenAction(
115 const CPDF_Action& action,
116 CPDFSDK_Document* pDocument,
117 CFX_PtrList& list) {
118 CPDF_Dictionary* pDict = action.GetDict();
119 if (list.Find(pDict))
120 return FALSE;
121
122 list.AddTail(pDict);
123
124 CPDFDoc_Environment* pEnv = pDocument->GetEnv();
125 ASSERT(pEnv);
126 if (action.GetType() == CPDF_Action::JavaScript) {
127 if (pEnv->IsJSInitiated()) {
128 CFX_WideString swJS = action.GetJavaScript();
129 if (!swJS.IsEmpty()) {
130 RunDocumentOpenJavaScript(pDocument, L"", swJS);
131 }
132 }
133 } else {
134 DoAction_NoJs(action, pDocument);
135 }
136
137 for (int32_t i = 0, sz = action.GetSubActionsCount(); i < sz; i++) {
138 CPDF_Action subaction = action.GetSubAction(i);
139 if (!ExecuteDocumentOpenAction(subaction, pDocument, list))
140 return FALSE;
141 }
142
143 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700144}
145
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700146FX_BOOL CPDFSDK_ActionHandler::ExecuteLinkAction(const CPDF_Action& action,
147 CPDFSDK_Document* pDocument,
148 CFX_PtrList& list) {
149 ASSERT(pDocument != NULL);
Tom Sepez7b5bc262015-03-05 16:44:22 -0800150
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700151 CPDF_Dictionary* pDict = action.GetDict();
152 if (list.Find(pDict))
153 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700154
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700155 list.AddTail(pDict);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700156
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700157 CPDFDoc_Environment* pEnv = pDocument->GetEnv();
158 ASSERT(pEnv);
159 if (action.GetType() == CPDF_Action::JavaScript) {
160 if (pEnv->IsJSInitiated()) {
161 CFX_WideString swJS = action.GetJavaScript();
162 if (!swJS.IsEmpty()) {
163 IFXJS_Runtime* pRuntime = pDocument->GetJsRuntime(); //????
164 ASSERT(pRuntime != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700165
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700166 pRuntime->SetReaderDocument(pDocument);
167
168 IFXJS_Context* pContext = pRuntime->NewContext();
169 ASSERT(pContext != NULL);
170
171 pContext->OnLink_MouseUp(pDocument);
172
173 CFX_WideString csInfo;
174 FX_BOOL bRet = pContext->RunScript(swJS, csInfo);
175 if (!bRet) {
176 // FIXME: return error.
177 }
178
179 pRuntime->ReleaseContext(pContext);
180 }
181 }
182 } else {
183 DoAction_NoJs(action, pDocument);
184 }
185
186 for (int32_t i = 0, sz = action.GetSubActionsCount(); i < sz; i++) {
187 CPDF_Action subaction = action.GetSubAction(i);
188 if (!ExecuteLinkAction(subaction, pDocument, list))
189 return FALSE;
190 }
191
192 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700193}
194
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700195FX_BOOL CPDFSDK_ActionHandler::ExecuteDocumentPageAction(
196 const CPDF_Action& action,
197 CPDF_AAction::AActionType type,
198 CPDFSDK_Document* pDocument,
199 CFX_PtrList& list) {
200 ASSERT(pDocument != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700201
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700202 CPDF_Dictionary* pDict = action.GetDict();
203 if (list.Find(pDict))
204 return FALSE;
Tom Sepez7b5bc262015-03-05 16:44:22 -0800205
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700206 list.AddTail(pDict);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700207
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700208 CPDFDoc_Environment* pEnv = pDocument->GetEnv();
209 ASSERT(pEnv);
210 if (action.GetType() == CPDF_Action::JavaScript) {
211 if (pEnv->IsJSInitiated()) {
212 CFX_WideString swJS = action.GetJavaScript();
213 if (!swJS.IsEmpty()) {
214 RunDocumentPageJavaScript(pDocument, type, swJS);
215 }
216 }
217 } else {
218 DoAction_NoJs(action, pDocument);
219 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700220
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700221 if (!IsValidDocView(pDocument))
222 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700223
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700224 for (int32_t i = 0, sz = action.GetSubActionsCount(); i < sz; i++) {
225 CPDF_Action subaction = action.GetSubAction(i);
226 if (!ExecuteDocumentPageAction(subaction, type, pDocument, list))
227 return FALSE;
228 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700229
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700230 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700231}
232
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700233FX_BOOL CPDFSDK_ActionHandler::IsValidField(CPDFSDK_Document* pDocument,
234 CPDF_Dictionary* pFieldDict) {
Chris Palmer9047b8b2014-08-06 14:17:45 -0700235 ASSERT(pDocument != NULL);
236 ASSERT(pFieldDict != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700237
Chris Palmer9047b8b2014-08-06 14:17:45 -0700238 CPDFSDK_InterForm* pInterForm = pDocument->GetInterForm();
239 ASSERT(pInterForm != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700240
Chris Palmer9047b8b2014-08-06 14:17:45 -0700241 CPDF_InterForm* pPDFInterForm = pInterForm->GetInterForm();
242 ASSERT(pPDFInterForm != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700243
Chris Palmer9047b8b2014-08-06 14:17:45 -0700244 return pPDFInterForm->GetFieldByDict(pFieldDict) != NULL;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700245}
246
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700247FX_BOOL CPDFSDK_ActionHandler::ExecuteFieldAction(
248 const CPDF_Action& action,
249 CPDF_AAction::AActionType type,
250 CPDFSDK_Document* pDocument,
251 CPDF_FormField* pFormField,
252 PDFSDK_FieldAction& data,
253 CFX_PtrList& list) {
254 ASSERT(pDocument != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700255
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700256 CPDF_Dictionary* pDict = action.GetDict();
257 if (list.Find(pDict))
258 return FALSE;
Tom Sepez7b5bc262015-03-05 16:44:22 -0800259
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700260 list.AddTail(pDict);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700261
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700262 CPDFDoc_Environment* pEnv = pDocument->GetEnv();
263 ASSERT(pEnv);
264 if (action.GetType() == CPDF_Action::JavaScript) {
265 if (pEnv->IsJSInitiated()) {
266 CFX_WideString swJS = action.GetJavaScript();
267 if (!swJS.IsEmpty()) {
268 RunFieldJavaScript(pDocument, pFormField, type, data, swJS);
269 if (!IsValidField(pDocument, pFormField->GetFieldDict()))
270 return FALSE;
271 }
272 }
273 } else {
274 DoAction_NoJs(action, pDocument);
275 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700276
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700277 for (int32_t i = 0, sz = action.GetSubActionsCount(); i < sz; i++) {
278 CPDF_Action subaction = action.GetSubAction(i);
279 if (!ExecuteFieldAction(subaction, type, pDocument, pFormField, data, list))
280 return FALSE;
281 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700282
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700283 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700284}
285
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700286FX_BOOL CPDFSDK_ActionHandler::ExecuteScreenAction(
287 const CPDF_Action& action,
288 CPDF_AAction::AActionType type,
289 CPDFSDK_Document* pDocument,
290 CPDFSDK_Annot* pScreen,
291 CFX_PtrList& list) {
292 ASSERT(pDocument != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700293
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700294 CPDF_Dictionary* pDict = action.GetDict();
295 if (list.Find(pDict))
296 return FALSE;
Tom Sepez7b5bc262015-03-05 16:44:22 -0800297
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700298 list.AddTail(pDict);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700299
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700300 CPDFDoc_Environment* pEnv = pDocument->GetEnv();
301 ASSERT(pEnv);
302 if (action.GetType() == CPDF_Action::JavaScript) {
303 if (pEnv->IsJSInitiated()) {
304 CFX_WideString swJS = action.GetJavaScript();
305 if (!swJS.IsEmpty()) {
306 IFXJS_Runtime* pRuntime = pDocument->GetJsRuntime();
307 ASSERT(pRuntime != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700308
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700309 pRuntime->SetReaderDocument(pDocument);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700310
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700311 IFXJS_Context* pContext = pRuntime->NewContext();
312 ASSERT(pContext != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700313
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700314 // switch (type)
315 // {
316 // case CPDF_AAction::CursorEnter:
317 // pContext->OnScreen_MouseEnter(IsCTRLpressed(),
318 // IsSHIFTpressed(), pScreen);
319 // break;
320 // case CPDF_AAction::CursorExit:
321 // pContext->OnScreen_MouseExit(IsCTRLpressed(),
322 // IsSHIFTpressed(), pScreen);
323 // break;
324 // case CPDF_AAction::ButtonDown:
325 // pContext->OnScreen_MouseDown(IsCTRLpressed(),
326 // IsSHIFTpressed(), pScreen);
327 // break;
328 // case CPDF_AAction::ButtonUp:
329 // pContext->OnScreen_MouseUp(IsCTRLpressed(),
330 // IsSHIFTpressed(), pScreen);
331 // break;
332 // case CPDF_AAction::GetFocus:
333 // pContext->OnScreen_Focus(IsCTRLpressed(),
334 // IsSHIFTpressed(), pScreen);
335 // break;
336 // case CPDF_AAction::LoseFocus:
337 // pContext->OnScreen_Blur(IsCTRLpressed(),
338 // IsSHIFTpressed(), pScreen);
339 // break;
340 // case CPDF_AAction::PageOpen:
341 // pContext->OnScreen_Open(IsCTRLpressed(),
342 // IsSHIFTpressed(), pScreen);
343 // break;
344 // case CPDF_AAction::PageClose:
345 // pContext->OnScreen_Close(IsCTRLpressed(),
346 // IsSHIFTpressed(), pScreen);
347 // break;
348 // case CPDF_AAction::PageVisible:
349 // pContext->OnScreen_InView(IsCTRLpressed(),
350 // IsSHIFTpressed(), pScreen);
351 // break;
352 // case CPDF_AAction::PageInvisible:
353 // pContext->OnScreen_OutView(IsCTRLpressed(),
354 // IsSHIFTpressed(), pScreen);
355 // break;
356 // default:
357 // ASSERT(FALSE);
358 // break;
359 // }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700360
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700361 CFX_WideString csInfo;
362 FX_BOOL bRet = pContext->RunScript(swJS, csInfo);
363 if (!bRet) {
364 // CBCL_FormNotify::MsgBoxJSError(pPageView->GetPageViewWnd(),
365 // csInfo);
366 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700367
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700368 pRuntime->ReleaseContext(pContext);
369 }
370 }
371 } else {
372 DoAction_NoJs(action, pDocument);
373 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700374
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700375 for (int32_t i = 0, sz = action.GetSubActionsCount(); i < sz; i++) {
376 CPDF_Action subaction = action.GetSubAction(i);
377 if (!ExecuteScreenAction(subaction, type, pDocument, pScreen, list))
378 return FALSE;
379 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700380
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700381 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700382}
383
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700384FX_BOOL CPDFSDK_ActionHandler::ExecuteBookMark(const CPDF_Action& action,
385 CPDFSDK_Document* pDocument,
386 CPDF_Bookmark* pBookmark,
387 CFX_PtrList& list) {
388 ASSERT(pDocument != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700389
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700390 CPDF_Dictionary* pDict = action.GetDict();
391 if (list.Find(pDict))
392 return FALSE;
Tom Sepez7b5bc262015-03-05 16:44:22 -0800393
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700394 list.AddTail(pDict);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700395
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700396 CPDFDoc_Environment* pEnv = pDocument->GetEnv();
397 ASSERT(pEnv);
398 if (action.GetType() == CPDF_Action::JavaScript) {
399 if (pEnv->IsJSInitiated()) {
400 CFX_WideString swJS = action.GetJavaScript();
401 if (!swJS.IsEmpty()) {
402 IFXJS_Runtime* pRuntime = pDocument->GetJsRuntime();
403 ASSERT(pRuntime != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700404
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700405 pRuntime->SetReaderDocument(pDocument);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700406
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700407 IFXJS_Context* pContext = pRuntime->NewContext();
408 ASSERT(pContext != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700409
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700410 pContext->OnBookmark_MouseUp(pBookmark);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700411
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700412 CFX_WideString csInfo;
413 FX_BOOL bRet = pContext->RunScript(swJS, csInfo);
414 if (!bRet) {
415 // CBCL_FormNotify::MsgBoxJSError(pPageView->GetPageViewWnd(),
416 // csInfo);
417 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700418
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700419 pRuntime->ReleaseContext(pContext);
420 }
421 }
422 } else {
423 DoAction_NoJs(action, pDocument);
424 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700425
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700426 for (int32_t i = 0, sz = action.GetSubActionsCount(); i < sz; i++) {
427 CPDF_Action subaction = action.GetSubAction(i);
428 if (!ExecuteBookMark(subaction, pDocument, pBookmark, list))
429 return FALSE;
430 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700431
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700432 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700433}
434
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700435void CPDFSDK_ActionHandler::DoAction_NoJs(const CPDF_Action& action,
436 CPDFSDK_Document* pDocument) {
437 ASSERT(pDocument != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700438
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700439 switch (action.GetType()) {
440 case CPDF_Action::GoTo:
441 DoAction_GoTo(pDocument, action);
442 break;
443 case CPDF_Action::GoToR:
444 DoAction_GoToR(pDocument, action);
445 break;
446 case CPDF_Action::GoToE:
447 break;
448 case CPDF_Action::Launch:
449 DoAction_Launch(pDocument, action);
450 break;
451 case CPDF_Action::Thread:
452 break;
453 case CPDF_Action::URI:
454 DoAction_URI(pDocument, action);
455 break;
456 case CPDF_Action::Sound:
457 if (m_pMediaActionHandler) {
458 m_pMediaActionHandler->DoAction_Sound(action, pDocument);
459 }
460 break;
461 case CPDF_Action::Movie:
462 if (m_pMediaActionHandler) {
463 m_pMediaActionHandler->DoAction_Movie(action, pDocument);
464 }
465 break;
466 case CPDF_Action::Hide:
467 if (m_pFormActionHandler) {
468 m_pFormActionHandler->DoAction_Hide(action, pDocument);
469 }
470 break;
471 case CPDF_Action::Named:
472 DoAction_Named(pDocument, action);
473 break;
474 case CPDF_Action::SubmitForm:
475 if (m_pFormActionHandler) {
476 m_pFormActionHandler->DoAction_SubmitForm(action, pDocument);
477 }
478 break;
479 case CPDF_Action::ResetForm:
480 if (m_pFormActionHandler) {
481 m_pFormActionHandler->DoAction_ResetForm(action, pDocument);
482 }
483 break;
484 case CPDF_Action::ImportData:
485 if (m_pFormActionHandler) {
486 m_pFormActionHandler->DoAction_ImportData(action, pDocument);
487 }
488 break;
489 case CPDF_Action::JavaScript:
490 ASSERT(FALSE);
491 break;
492 case CPDF_Action::SetOCGState:
493 DoAction_SetOCGState(pDocument, action);
494 break;
495 case CPDF_Action::Rendition:
496 if (m_pMediaActionHandler) {
497 m_pMediaActionHandler->DoAction_Rendition(action, pDocument);
498 }
499 break;
500 case CPDF_Action::Trans:
501 break;
502 case CPDF_Action::GoTo3DView:
503 break;
504 default:
505 break;
506 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700507}
508
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700509FX_BOOL CPDFSDK_ActionHandler::IsValidDocView(CPDFSDK_Document* pDocument) {
510 ASSERT(pDocument != NULL);
511 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700512}
513
Tom Sepez7b5bc262015-03-05 16:44:22 -0800514void CPDFSDK_ActionHandler::DoAction_GoTo(CPDFSDK_Document* pDocument,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700515 const CPDF_Action& action) {
516 ASSERT(action);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700517
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700518 CPDF_Document* pPDFDocument = pDocument->GetDocument()->GetPDFDoc();
519 ASSERT(pPDFDocument != NULL);
520 CPDFDoc_Environment* pApp = pDocument->GetEnv();
521 ASSERT(pApp != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700522
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700523 CPDF_Dest MyDest = action.GetDest(pPDFDocument);
524 int nPageIndex = MyDest.GetPageIndex(pPDFDocument);
525 int nFitType = MyDest.GetZoomMode();
526 const CPDF_Array* pMyArray = (CPDF_Array*)MyDest.GetObject();
527 float* pPosAry = NULL;
528 int sizeOfAry = 0;
529 if (pMyArray != NULL) {
530 pPosAry = new float[pMyArray->GetCount()];
531 int j = 0;
532 for (int i = 2; i < (int)pMyArray->GetCount(); i++) {
533 pPosAry[j++] = pMyArray->GetFloat(i);
534 }
535 sizeOfAry = j;
536 }
537 pApp->FFI_DoGoToAction(nPageIndex, nFitType, pPosAry, sizeOfAry);
538 if (pPosAry)
539 delete[] pPosAry;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700540}
541
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700542void CPDFSDK_ActionHandler::DoAction_GoToR(CPDFSDK_Document* pDocument,
543 const CPDF_Action& action) {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700544
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700545void CPDFSDK_ActionHandler::DoAction_Launch(CPDFSDK_Document* pDocument,
546 const CPDF_Action& action) {}
547
548void CPDFSDK_ActionHandler::DoAction_URI(CPDFSDK_Document* pDocument,
549 const CPDF_Action& action) {
550 ASSERT(action);
551
552 CPDFDoc_Environment* pApp = pDocument->GetEnv();
553 ASSERT(pApp != NULL);
554
555 CFX_ByteString sURI = action.GetURI(pDocument->GetDocument()->GetPDFDoc());
556 pApp->FFI_DoURIAction(sURI.c_str());
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700557}
558
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700559void CPDFSDK_ActionHandler::DoAction_Named(CPDFSDK_Document* pDocument,
560 const CPDF_Action& action) {
561 ASSERT(action);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700562
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700563 CFX_ByteString csName = action.GetNamedAction();
564 pDocument->GetEnv()->FFI_ExecuteNamedAction(csName);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700565}
566
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700567void CPDFSDK_ActionHandler::DoAction_SetOCGState(CPDFSDK_Document* pDocument,
568 const CPDF_Action& action) {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700569
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700570void CPDFSDK_ActionHandler::RunFieldJavaScript(CPDFSDK_Document* pDocument,
571 CPDF_FormField* pFormField,
572 CPDF_AAction::AActionType type,
573 PDFSDK_FieldAction& data,
574 const CFX_WideString& script) {
575 ASSERT(type != CPDF_AAction::Calculate);
576 ASSERT(type != CPDF_AAction::Format);
Tom Sepezd7e5cc72015-06-10 14:33:37 -0700577
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700578 ASSERT(pDocument != NULL);
579
580 IFXJS_Runtime* pRuntime = pDocument->GetJsRuntime();
581 ASSERT(pRuntime != NULL);
582
583 pRuntime->SetReaderDocument(pDocument);
584
585 IFXJS_Context* pContext = pRuntime->NewContext();
586 ASSERT(pContext != NULL);
587
588 switch (type) {
589 case CPDF_AAction::CursorEnter:
590 pContext->OnField_MouseEnter(data.bModifier, data.bShift, pFormField);
591 break;
592 case CPDF_AAction::CursorExit:
593 pContext->OnField_MouseExit(data.bModifier, data.bShift, pFormField);
594 break;
595 case CPDF_AAction::ButtonDown:
596 pContext->OnField_MouseDown(data.bModifier, data.bShift, pFormField);
597 break;
598 case CPDF_AAction::ButtonUp:
599 pContext->OnField_MouseUp(data.bModifier, data.bShift, pFormField);
600 break;
601 case CPDF_AAction::GetFocus:
602 pContext->OnField_Focus(data.bModifier, data.bShift, pFormField,
603 data.sValue);
604 break;
605 case CPDF_AAction::LoseFocus:
606 pContext->OnField_Blur(data.bModifier, data.bShift, pFormField,
607 data.sValue);
608 break;
609 case CPDF_AAction::KeyStroke:
610 pContext->OnField_Keystroke(data.sChange, data.sChangeEx, data.bKeyDown,
611 data.bModifier, data.nSelEnd, data.nSelStart,
612 data.bShift, pFormField, data.sValue,
613 data.bWillCommit, data.bFieldFull, data.bRC);
614 break;
615 case CPDF_AAction::Validate:
616 pContext->OnField_Validate(data.sChange, data.sChangeEx, data.bKeyDown,
617 data.bModifier, data.bShift, pFormField,
618 data.sValue, data.bRC);
619 break;
620 default:
621 ASSERT(FALSE);
622 break;
623 }
624
625 CFX_WideString csInfo;
626 FX_BOOL bRet = pContext->RunScript(script, csInfo);
627 if (!bRet) {
628 // CBCL_FormNotify::MsgBoxJSError(pPageView->GetPageViewWnd(), csInfo);
629 }
630
631 pRuntime->ReleaseContext(pContext);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700632}
633
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700634void CPDFSDK_ActionHandler::RunDocumentOpenJavaScript(
635 CPDFSDK_Document* pDocument,
636 const CFX_WideString& sScriptName,
637 const CFX_WideString& script) {
638 ASSERT(pDocument != NULL);
Tom Sepez7b5bc262015-03-05 16:44:22 -0800639
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700640 IFXJS_Runtime* pRuntime = pDocument->GetJsRuntime();
641 ASSERT(pRuntime != NULL);
642
643 pRuntime->SetReaderDocument(pDocument);
644
645 IFXJS_Context* pContext = pRuntime->NewContext();
646 ASSERT(pContext != NULL);
647
648 pContext->OnDoc_Open(pDocument, sScriptName);
649
650 CFX_WideString csInfo;
651 FX_BOOL bRet = pContext->RunScript(script, csInfo);
652 if (!bRet) {
653 // CBCL_FormNotify::MsgBoxJSError(pPageView->GetPageViewWnd(), csInfo);
654 }
655
656 pRuntime->ReleaseContext(pContext);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700657}
658
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700659void CPDFSDK_ActionHandler::RunDocumentPageJavaScript(
660 CPDFSDK_Document* pDocument,
661 CPDF_AAction::AActionType type,
662 const CFX_WideString& script) {
663 ASSERT(pDocument != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700664
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700665 IFXJS_Runtime* pRuntime = pDocument->GetJsRuntime();
666 ASSERT(pRuntime != NULL);
667
668 pRuntime->SetReaderDocument(pDocument);
669
670 IFXJS_Context* pContext = pRuntime->NewContext();
671 ASSERT(pContext != NULL);
672
673 switch (type) {
674 case CPDF_AAction::OpenPage:
675 pContext->OnPage_Open(pDocument);
676 break;
677 case CPDF_AAction::ClosePage:
678 pContext->OnPage_Close(pDocument);
679 break;
680 case CPDF_AAction::CloseDocument:
681 pContext->OnDoc_WillClose(pDocument);
682 break;
683 case CPDF_AAction::SaveDocument:
684 pContext->OnDoc_WillSave(pDocument);
685 break;
686 case CPDF_AAction::DocumentSaved:
687 pContext->OnDoc_DidSave(pDocument);
688 break;
689 case CPDF_AAction::PrintDocument:
690 pContext->OnDoc_WillPrint(pDocument);
691 break;
692 case CPDF_AAction::DocumentPrinted:
693 pContext->OnDoc_DidPrint(pDocument);
694 break;
695 case CPDF_AAction::PageVisible:
696 pContext->OnPage_InView(pDocument);
697 break;
698 case CPDF_AAction::PageInvisible:
699 pContext->OnPage_OutView(pDocument);
700 break;
701 default:
702 ASSERT(FALSE);
703 break;
704 }
705
706 CFX_WideString csInfo;
707 FX_BOOL bRet = pContext->RunScript(script, csInfo);
708 if (!bRet) {
709 // CBCL_FormNotify::MsgBoxJSError(pPageView->GetPageViewWnd(), csInfo);
710 }
711
712 pRuntime->ReleaseContext(pContext);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700713}
714
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700715FX_BOOL CPDFSDK_FormActionHandler::DoAction_Hide(const CPDF_Action& action,
716 CPDFSDK_Document* pDocument) {
717 ASSERT(pDocument != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700718
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700719 CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm();
720 ASSERT(pInterForm != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700721
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700722 if (pInterForm->DoAction_Hide(action)) {
723 pDocument->SetChangeMark();
724 return TRUE;
725 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700726
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700727 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700728}
729
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700730FX_BOOL CPDFSDK_FormActionHandler::DoAction_SubmitForm(
731 const CPDF_Action& action,
732 CPDFSDK_Document* pDocument) {
733 ASSERT(pDocument != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700734
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700735 CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm();
736 ASSERT(pInterForm != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700737
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700738 return pInterForm->DoAction_SubmitForm(action);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700739}
740
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700741FX_BOOL CPDFSDK_FormActionHandler::DoAction_ResetForm(
742 const CPDF_Action& action,
743 CPDFSDK_Document* pDocument) {
744 ASSERT(pDocument != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700745
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700746 CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm();
747 ASSERT(pInterForm != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700748
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700749 if (pInterForm->DoAction_ResetForm(action)) {
750 return TRUE;
751 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700752
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700753 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700754}
755
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700756FX_BOOL CPDFSDK_FormActionHandler::DoAction_ImportData(
757 const CPDF_Action& action,
758 CPDFSDK_Document* pDocument) {
759 ASSERT(pDocument != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700760
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700761 CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm();
762 ASSERT(pInterForm != NULL);
Tom Sepez7b5bc262015-03-05 16:44:22 -0800763
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700764 if (pInterForm->DoAction_ImportData(action)) {
765 pDocument->SetChangeMark();
766 return TRUE;
767 }
Tom Sepez7b5bc262015-03-05 16:44:22 -0800768
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700769 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700770}
771
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700772FX_BOOL CPDFSDK_MediaActionHandler::DoAction_Rendition(
773 const CPDF_Action& action,
774 CPDFSDK_Document* pDocument) {
775 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700776}
777
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700778FX_BOOL CPDFSDK_MediaActionHandler::DoAction_Sound(
779 const CPDF_Action& action,
780 CPDFSDK_Document* pDocument) {
781 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700782}
783
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700784FX_BOOL CPDFSDK_MediaActionHandler::DoAction_Movie(
785 const CPDF_Action& action,
786 CPDFSDK_Document* pDocument) {
787 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700788}