blob: 89b93eff0116a2c343454edf523989af034c03f6 [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);
Lei Zhangda180e92015-08-14 22:22:13 -0700538 delete[] pPosAry;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700539}
540
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700541void CPDFSDK_ActionHandler::DoAction_GoToR(CPDFSDK_Document* pDocument,
542 const CPDF_Action& action) {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700543
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700544void CPDFSDK_ActionHandler::DoAction_Launch(CPDFSDK_Document* pDocument,
545 const CPDF_Action& action) {}
546
547void CPDFSDK_ActionHandler::DoAction_URI(CPDFSDK_Document* pDocument,
548 const CPDF_Action& action) {
549 ASSERT(action);
550
551 CPDFDoc_Environment* pApp = pDocument->GetEnv();
552 ASSERT(pApp != NULL);
553
554 CFX_ByteString sURI = action.GetURI(pDocument->GetDocument()->GetPDFDoc());
555 pApp->FFI_DoURIAction(sURI.c_str());
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700556}
557
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700558void CPDFSDK_ActionHandler::DoAction_Named(CPDFSDK_Document* pDocument,
559 const CPDF_Action& action) {
560 ASSERT(action);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700561
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700562 CFX_ByteString csName = action.GetNamedAction();
563 pDocument->GetEnv()->FFI_ExecuteNamedAction(csName);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700564}
565
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700566void CPDFSDK_ActionHandler::DoAction_SetOCGState(CPDFSDK_Document* pDocument,
567 const CPDF_Action& action) {}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700568
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700569void CPDFSDK_ActionHandler::RunFieldJavaScript(CPDFSDK_Document* pDocument,
570 CPDF_FormField* pFormField,
571 CPDF_AAction::AActionType type,
572 PDFSDK_FieldAction& data,
573 const CFX_WideString& script) {
574 ASSERT(type != CPDF_AAction::Calculate);
575 ASSERT(type != CPDF_AAction::Format);
Tom Sepezd7e5cc72015-06-10 14:33:37 -0700576
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700577 ASSERT(pDocument != NULL);
578
579 IFXJS_Runtime* pRuntime = pDocument->GetJsRuntime();
580 ASSERT(pRuntime != NULL);
581
582 pRuntime->SetReaderDocument(pDocument);
583
584 IFXJS_Context* pContext = pRuntime->NewContext();
585 ASSERT(pContext != NULL);
586
587 switch (type) {
588 case CPDF_AAction::CursorEnter:
589 pContext->OnField_MouseEnter(data.bModifier, data.bShift, pFormField);
590 break;
591 case CPDF_AAction::CursorExit:
592 pContext->OnField_MouseExit(data.bModifier, data.bShift, pFormField);
593 break;
594 case CPDF_AAction::ButtonDown:
595 pContext->OnField_MouseDown(data.bModifier, data.bShift, pFormField);
596 break;
597 case CPDF_AAction::ButtonUp:
598 pContext->OnField_MouseUp(data.bModifier, data.bShift, pFormField);
599 break;
600 case CPDF_AAction::GetFocus:
601 pContext->OnField_Focus(data.bModifier, data.bShift, pFormField,
602 data.sValue);
603 break;
604 case CPDF_AAction::LoseFocus:
605 pContext->OnField_Blur(data.bModifier, data.bShift, pFormField,
606 data.sValue);
607 break;
608 case CPDF_AAction::KeyStroke:
609 pContext->OnField_Keystroke(data.sChange, data.sChangeEx, data.bKeyDown,
610 data.bModifier, data.nSelEnd, data.nSelStart,
611 data.bShift, pFormField, data.sValue,
612 data.bWillCommit, data.bFieldFull, data.bRC);
613 break;
614 case CPDF_AAction::Validate:
615 pContext->OnField_Validate(data.sChange, data.sChangeEx, data.bKeyDown,
616 data.bModifier, data.bShift, pFormField,
617 data.sValue, data.bRC);
618 break;
619 default:
620 ASSERT(FALSE);
621 break;
622 }
623
624 CFX_WideString csInfo;
625 FX_BOOL bRet = pContext->RunScript(script, csInfo);
626 if (!bRet) {
627 // CBCL_FormNotify::MsgBoxJSError(pPageView->GetPageViewWnd(), csInfo);
628 }
629
630 pRuntime->ReleaseContext(pContext);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700631}
632
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700633void CPDFSDK_ActionHandler::RunDocumentOpenJavaScript(
634 CPDFSDK_Document* pDocument,
635 const CFX_WideString& sScriptName,
636 const CFX_WideString& script) {
637 ASSERT(pDocument != NULL);
Tom Sepez7b5bc262015-03-05 16:44:22 -0800638
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700639 IFXJS_Runtime* pRuntime = pDocument->GetJsRuntime();
640 ASSERT(pRuntime != NULL);
641
642 pRuntime->SetReaderDocument(pDocument);
643
644 IFXJS_Context* pContext = pRuntime->NewContext();
645 ASSERT(pContext != NULL);
646
647 pContext->OnDoc_Open(pDocument, sScriptName);
648
649 CFX_WideString csInfo;
650 FX_BOOL bRet = pContext->RunScript(script, csInfo);
651 if (!bRet) {
652 // CBCL_FormNotify::MsgBoxJSError(pPageView->GetPageViewWnd(), csInfo);
653 }
654
655 pRuntime->ReleaseContext(pContext);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700656}
657
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700658void CPDFSDK_ActionHandler::RunDocumentPageJavaScript(
659 CPDFSDK_Document* pDocument,
660 CPDF_AAction::AActionType type,
661 const CFX_WideString& script) {
662 ASSERT(pDocument != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700663
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700664 IFXJS_Runtime* pRuntime = pDocument->GetJsRuntime();
665 ASSERT(pRuntime != NULL);
666
667 pRuntime->SetReaderDocument(pDocument);
668
669 IFXJS_Context* pContext = pRuntime->NewContext();
670 ASSERT(pContext != NULL);
671
672 switch (type) {
673 case CPDF_AAction::OpenPage:
674 pContext->OnPage_Open(pDocument);
675 break;
676 case CPDF_AAction::ClosePage:
677 pContext->OnPage_Close(pDocument);
678 break;
679 case CPDF_AAction::CloseDocument:
680 pContext->OnDoc_WillClose(pDocument);
681 break;
682 case CPDF_AAction::SaveDocument:
683 pContext->OnDoc_WillSave(pDocument);
684 break;
685 case CPDF_AAction::DocumentSaved:
686 pContext->OnDoc_DidSave(pDocument);
687 break;
688 case CPDF_AAction::PrintDocument:
689 pContext->OnDoc_WillPrint(pDocument);
690 break;
691 case CPDF_AAction::DocumentPrinted:
692 pContext->OnDoc_DidPrint(pDocument);
693 break;
694 case CPDF_AAction::PageVisible:
695 pContext->OnPage_InView(pDocument);
696 break;
697 case CPDF_AAction::PageInvisible:
698 pContext->OnPage_OutView(pDocument);
699 break;
700 default:
701 ASSERT(FALSE);
702 break;
703 }
704
705 CFX_WideString csInfo;
706 FX_BOOL bRet = pContext->RunScript(script, csInfo);
707 if (!bRet) {
708 // CBCL_FormNotify::MsgBoxJSError(pPageView->GetPageViewWnd(), csInfo);
709 }
710
711 pRuntime->ReleaseContext(pContext);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700712}
713
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700714FX_BOOL CPDFSDK_FormActionHandler::DoAction_Hide(const CPDF_Action& action,
715 CPDFSDK_Document* pDocument) {
716 ASSERT(pDocument != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700717
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700718 CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm();
719 ASSERT(pInterForm != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700720
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700721 if (pInterForm->DoAction_Hide(action)) {
722 pDocument->SetChangeMark();
723 return TRUE;
724 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700725
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700726 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700727}
728
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700729FX_BOOL CPDFSDK_FormActionHandler::DoAction_SubmitForm(
730 const CPDF_Action& action,
731 CPDFSDK_Document* pDocument) {
732 ASSERT(pDocument != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700733
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700734 CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm();
735 ASSERT(pInterForm != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700736
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700737 return pInterForm->DoAction_SubmitForm(action);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700738}
739
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700740FX_BOOL CPDFSDK_FormActionHandler::DoAction_ResetForm(
741 const CPDF_Action& action,
742 CPDFSDK_Document* pDocument) {
743 ASSERT(pDocument != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700744
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700745 CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm();
746 ASSERT(pInterForm != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700747
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700748 if (pInterForm->DoAction_ResetForm(action)) {
749 return TRUE;
750 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700751
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700752 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700753}
754
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700755FX_BOOL CPDFSDK_FormActionHandler::DoAction_ImportData(
756 const CPDF_Action& action,
757 CPDFSDK_Document* pDocument) {
758 ASSERT(pDocument != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700759
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700760 CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm();
761 ASSERT(pInterForm != NULL);
Tom Sepez7b5bc262015-03-05 16:44:22 -0800762
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700763 if (pInterForm->DoAction_ImportData(action)) {
764 pDocument->SetChangeMark();
765 return TRUE;
766 }
Tom Sepez7b5bc262015-03-05 16:44:22 -0800767
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700768 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700769}
770
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700771FX_BOOL CPDFSDK_MediaActionHandler::DoAction_Rendition(
772 const CPDF_Action& action,
773 CPDFSDK_Document* pDocument) {
774 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700775}
776
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700777FX_BOOL CPDFSDK_MediaActionHandler::DoAction_Sound(
778 const CPDF_Action& action,
779 CPDFSDK_Document* pDocument) {
780 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700781}
782
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700783FX_BOOL CPDFSDK_MediaActionHandler::DoAction_Movie(
784 const CPDF_Action& action,
785 CPDFSDK_Document* pDocument) {
786 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700787}