1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
7 #include "fpdfsdk/fsdk_actionhandler.h"
8
9 #include <set>
10 #include <vector>
11
12 #include "core/fpdfapi/parser/cpdf_array.h"
13 #include "core/fpdfdoc/cpdf_formfield.h"
14 #include "core/fpdfdoc/cpdf_interform.h"
15 #include "fpdfsdk/cpdfsdk_formfillenvironment.h"
16 #include "fpdfsdk/cpdfsdk_interform.h"
17 #include "fpdfsdk/fsdk_define.h"
18 #include "fxjs/ijs_event_context.h"
19 #include "fxjs/ijs_runtime.h"
20 #include "third_party/base/logging.h"
21 #include "third_party/base/stl_util.h"
22
DoAction_DocOpen(const CPDF_Action & action,CPDFSDK_FormFillEnvironment * pFormFillEnv)23 bool CPDFSDK_ActionHandler::DoAction_DocOpen(
24 const CPDF_Action& action,
25 CPDFSDK_FormFillEnvironment* pFormFillEnv) {
26 std::set<CPDF_Dictionary*> visited;
27 return ExecuteDocumentOpenAction(action, pFormFillEnv, &visited);
28 }
29
DoAction_JavaScript(const CPDF_Action & JsAction,WideString csJSName,CPDFSDK_FormFillEnvironment * pFormFillEnv)30 bool CPDFSDK_ActionHandler::DoAction_JavaScript(
31 const CPDF_Action& JsAction,
32 WideString csJSName,
33 CPDFSDK_FormFillEnvironment* pFormFillEnv) {
34 if (JsAction.GetType() == CPDF_Action::JavaScript) {
35 WideString swJS = JsAction.GetJavaScript();
36 if (!swJS.IsEmpty()) {
37 RunDocumentOpenJavaScript(pFormFillEnv, csJSName, swJS);
38 return true;
39 }
40 }
41
42 return false;
43 }
44
DoAction_FieldJavaScript(const CPDF_Action & JsAction,CPDF_AAction::AActionType type,CPDFSDK_FormFillEnvironment * pFormFillEnv,CPDF_FormField * pFormField,PDFSDK_FieldAction & data)45 bool CPDFSDK_ActionHandler::DoAction_FieldJavaScript(
46 const CPDF_Action& JsAction,
47 CPDF_AAction::AActionType type,
48 CPDFSDK_FormFillEnvironment* pFormFillEnv,
49 CPDF_FormField* pFormField,
50 PDFSDK_FieldAction& data) {
51 ASSERT(pFormFillEnv);
52 if (pFormFillEnv->IsJSInitiated() &&
53 JsAction.GetType() == CPDF_Action::JavaScript) {
54 WideString swJS = JsAction.GetJavaScript();
55 if (!swJS.IsEmpty()) {
56 RunFieldJavaScript(pFormFillEnv, pFormField, type, data, swJS);
57 return true;
58 }
59 }
60 return false;
61 }
62
DoAction_Page(const CPDF_Action & action,enum CPDF_AAction::AActionType eType,CPDFSDK_FormFillEnvironment * pFormFillEnv)63 bool CPDFSDK_ActionHandler::DoAction_Page(
64 const CPDF_Action& action,
65 enum CPDF_AAction::AActionType eType,
66 CPDFSDK_FormFillEnvironment* pFormFillEnv) {
67 std::set<CPDF_Dictionary*> visited;
68 return ExecuteDocumentPageAction(action, eType, pFormFillEnv, &visited);
69 }
70
DoAction_Document(const CPDF_Action & action,enum CPDF_AAction::AActionType eType,CPDFSDK_FormFillEnvironment * pFormFillEnv)71 bool CPDFSDK_ActionHandler::DoAction_Document(
72 const CPDF_Action& action,
73 enum CPDF_AAction::AActionType eType,
74 CPDFSDK_FormFillEnvironment* pFormFillEnv) {
75 std::set<CPDF_Dictionary*> visited;
76 return ExecuteDocumentPageAction(action, eType, pFormFillEnv, &visited);
77 }
78
DoAction_BookMark(CPDF_Bookmark * pBookMark,const CPDF_Action & action,CPDF_AAction::AActionType type,CPDFSDK_FormFillEnvironment * pFormFillEnv)79 bool CPDFSDK_ActionHandler::DoAction_BookMark(
80 CPDF_Bookmark* pBookMark,
81 const CPDF_Action& action,
82 CPDF_AAction::AActionType type,
83 CPDFSDK_FormFillEnvironment* pFormFillEnv) {
84 std::set<CPDF_Dictionary*> visited;
85 return ExecuteBookMark(action, pFormFillEnv, pBookMark, &visited);
86 }
87
DoAction_Screen(const CPDF_Action & action,CPDF_AAction::AActionType type,CPDFSDK_FormFillEnvironment * pFormFillEnv,CPDFSDK_Annot * pScreen)88 bool CPDFSDK_ActionHandler::DoAction_Screen(
89 const CPDF_Action& action,
90 CPDF_AAction::AActionType type,
91 CPDFSDK_FormFillEnvironment* pFormFillEnv,
92 CPDFSDK_Annot* pScreen) {
93 std::set<CPDF_Dictionary*> visited;
94 return ExecuteScreenAction(action, type, pFormFillEnv, pScreen, &visited);
95 }
96
DoAction_Link(const CPDF_Action & action,CPDFSDK_FormFillEnvironment * pFormFillEnv)97 bool CPDFSDK_ActionHandler::DoAction_Link(
98 const CPDF_Action& action,
99 CPDFSDK_FormFillEnvironment* pFormFillEnv) {
100 std::set<CPDF_Dictionary*> visited;
101 return ExecuteLinkAction(action, pFormFillEnv, &visited);
102 }
103
DoAction_Field(const CPDF_Action & action,CPDF_AAction::AActionType type,CPDFSDK_FormFillEnvironment * pFormFillEnv,CPDF_FormField * pFormField,PDFSDK_FieldAction & data)104 bool CPDFSDK_ActionHandler::DoAction_Field(
105 const CPDF_Action& action,
106 CPDF_AAction::AActionType type,
107 CPDFSDK_FormFillEnvironment* pFormFillEnv,
108 CPDF_FormField* pFormField,
109 PDFSDK_FieldAction& data) {
110 std::set<CPDF_Dictionary*> visited;
111 return ExecuteFieldAction(action, type, pFormFillEnv, pFormField, data,
112 &visited);
113 }
114
ExecuteDocumentOpenAction(const CPDF_Action & action,CPDFSDK_FormFillEnvironment * pFormFillEnv,std::set<CPDF_Dictionary * > * visited)115 bool CPDFSDK_ActionHandler::ExecuteDocumentOpenAction(
116 const CPDF_Action& action,
117 CPDFSDK_FormFillEnvironment* pFormFillEnv,
118 std::set<CPDF_Dictionary*>* visited) {
119 CPDF_Dictionary* pDict = action.GetDict();
120 if (pdfium::ContainsKey(*visited, pDict))
121 return false;
122
123 visited->insert(pDict);
124
125 ASSERT(pFormFillEnv);
126 if (action.GetType() == CPDF_Action::JavaScript) {
127 if (pFormFillEnv->IsJSInitiated()) {
128 WideString swJS = action.GetJavaScript();
129 if (!swJS.IsEmpty()) {
130 RunDocumentOpenJavaScript(pFormFillEnv, L"", swJS);
131 }
132 }
133 } else {
134 DoAction_NoJs(action, pFormFillEnv);
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, pFormFillEnv, visited))
140 return false;
141 }
142
143 return true;
144 }
145
ExecuteLinkAction(const CPDF_Action & action,CPDFSDK_FormFillEnvironment * pFormFillEnv,std::set<CPDF_Dictionary * > * visited)146 bool CPDFSDK_ActionHandler::ExecuteLinkAction(
147 const CPDF_Action& action,
148 CPDFSDK_FormFillEnvironment* pFormFillEnv,
149 std::set<CPDF_Dictionary*>* visited) {
150 CPDF_Dictionary* pDict = action.GetDict();
151 if (pdfium::ContainsKey(*visited, pDict))
152 return false;
153
154 visited->insert(pDict);
155
156 ASSERT(pFormFillEnv);
157 if (action.GetType() == CPDF_Action::JavaScript) {
158 if (pFormFillEnv->IsJSInitiated()) {
159 WideString swJS = action.GetJavaScript();
160 if (!swJS.IsEmpty()) {
161 IJS_Runtime* pRuntime = pFormFillEnv->GetJSRuntime();
162 IJS_EventContext* pContext = pRuntime->NewEventContext();
163 pContext->OnLink_MouseUp(pFormFillEnv);
164
165 WideString csInfo;
166 bool bRet = pContext->RunScript(swJS, &csInfo);
167 pRuntime->ReleaseEventContext(pContext);
168 if (!bRet) {
169 // FIXME: return error.
170 }
171 }
172 }
173 } else {
174 DoAction_NoJs(action, pFormFillEnv);
175 }
176
177 for (int32_t i = 0, sz = action.GetSubActionsCount(); i < sz; i++) {
178 CPDF_Action subaction = action.GetSubAction(i);
179 if (!ExecuteLinkAction(subaction, pFormFillEnv, visited))
180 return false;
181 }
182
183 return true;
184 }
185
ExecuteDocumentPageAction(const CPDF_Action & action,CPDF_AAction::AActionType type,CPDFSDK_FormFillEnvironment * pFormFillEnv,std::set<CPDF_Dictionary * > * visited)186 bool CPDFSDK_ActionHandler::ExecuteDocumentPageAction(
187 const CPDF_Action& action,
188 CPDF_AAction::AActionType type,
189 CPDFSDK_FormFillEnvironment* pFormFillEnv,
190 std::set<CPDF_Dictionary*>* visited) {
191 CPDF_Dictionary* pDict = action.GetDict();
192 if (pdfium::ContainsKey(*visited, pDict))
193 return false;
194
195 visited->insert(pDict);
196
197 ASSERT(pFormFillEnv);
198 if (action.GetType() == CPDF_Action::JavaScript) {
199 if (pFormFillEnv->IsJSInitiated()) {
200 WideString swJS = action.GetJavaScript();
201 if (!swJS.IsEmpty()) {
202 RunDocumentPageJavaScript(pFormFillEnv, type, swJS);
203 }
204 }
205 } else {
206 DoAction_NoJs(action, pFormFillEnv);
207 }
208
209 if (!IsValidDocView(pFormFillEnv))
210 return false;
211
212 for (int32_t i = 0, sz = action.GetSubActionsCount(); i < sz; i++) {
213 CPDF_Action subaction = action.GetSubAction(i);
214 if (!ExecuteDocumentPageAction(subaction, type, pFormFillEnv, visited))
215 return false;
216 }
217
218 return true;
219 }
220
IsValidField(CPDFSDK_FormFillEnvironment * pFormFillEnv,CPDF_Dictionary * pFieldDict)221 bool CPDFSDK_ActionHandler::IsValidField(
222 CPDFSDK_FormFillEnvironment* pFormFillEnv,
223 CPDF_Dictionary* pFieldDict) {
224 ASSERT(pFieldDict);
225
226 CPDFSDK_InterForm* pInterForm = pFormFillEnv->GetInterForm();
227 CPDF_InterForm* pPDFInterForm = pInterForm->GetInterForm();
228 return !!pPDFInterForm->GetFieldByDict(pFieldDict);
229 }
230
ExecuteFieldAction(const CPDF_Action & action,CPDF_AAction::AActionType type,CPDFSDK_FormFillEnvironment * pFormFillEnv,CPDF_FormField * pFormField,PDFSDK_FieldAction & data,std::set<CPDF_Dictionary * > * visited)231 bool CPDFSDK_ActionHandler::ExecuteFieldAction(
232 const CPDF_Action& action,
233 CPDF_AAction::AActionType type,
234 CPDFSDK_FormFillEnvironment* pFormFillEnv,
235 CPDF_FormField* pFormField,
236 PDFSDK_FieldAction& data,
237 std::set<CPDF_Dictionary*>* visited) {
238 CPDF_Dictionary* pDict = action.GetDict();
239 if (pdfium::ContainsKey(*visited, pDict))
240 return false;
241
242 visited->insert(pDict);
243
244 ASSERT(pFormFillEnv);
245 if (action.GetType() == CPDF_Action::JavaScript) {
246 if (pFormFillEnv->IsJSInitiated()) {
247 WideString swJS = action.GetJavaScript();
248 if (!swJS.IsEmpty()) {
249 RunFieldJavaScript(pFormFillEnv, pFormField, type, data, swJS);
250 if (!IsValidField(pFormFillEnv, pFormField->GetFieldDict()))
251 return false;
252 }
253 }
254 } else {
255 DoAction_NoJs(action, pFormFillEnv);
256 }
257
258 for (int32_t i = 0, sz = action.GetSubActionsCount(); i < sz; i++) {
259 CPDF_Action subaction = action.GetSubAction(i);
260 if (!ExecuteFieldAction(subaction, type, pFormFillEnv, pFormField, data,
261 visited))
262 return false;
263 }
264
265 return true;
266 }
267
ExecuteScreenAction(const CPDF_Action & action,CPDF_AAction::AActionType type,CPDFSDK_FormFillEnvironment * pFormFillEnv,CPDFSDK_Annot * pScreen,std::set<CPDF_Dictionary * > * visited)268 bool CPDFSDK_ActionHandler::ExecuteScreenAction(
269 const CPDF_Action& action,
270 CPDF_AAction::AActionType type,
271 CPDFSDK_FormFillEnvironment* pFormFillEnv,
272 CPDFSDK_Annot* pScreen,
273 std::set<CPDF_Dictionary*>* visited) {
274 CPDF_Dictionary* pDict = action.GetDict();
275 if (pdfium::ContainsKey(*visited, pDict))
276 return false;
277
278 visited->insert(pDict);
279
280 ASSERT(pFormFillEnv);
281 if (action.GetType() == CPDF_Action::JavaScript) {
282 if (pFormFillEnv->IsJSInitiated()) {
283 WideString swJS = action.GetJavaScript();
284 if (!swJS.IsEmpty()) {
285 IJS_Runtime* pRuntime = pFormFillEnv->GetJSRuntime();
286 IJS_EventContext* pContext = pRuntime->NewEventContext();
287 WideString csInfo;
288 bool bRet = pContext->RunScript(swJS, &csInfo);
289 pRuntime->ReleaseEventContext(pContext);
290 if (!bRet) {
291 // FIXME: return error.
292 }
293 }
294 }
295 } else {
296 DoAction_NoJs(action, pFormFillEnv);
297 }
298
299 for (int32_t i = 0, sz = action.GetSubActionsCount(); i < sz; i++) {
300 CPDF_Action subaction = action.GetSubAction(i);
301 if (!ExecuteScreenAction(subaction, type, pFormFillEnv, pScreen, visited))
302 return false;
303 }
304
305 return true;
306 }
307
ExecuteBookMark(const CPDF_Action & action,CPDFSDK_FormFillEnvironment * pFormFillEnv,CPDF_Bookmark * pBookmark,std::set<CPDF_Dictionary * > * visited)308 bool CPDFSDK_ActionHandler::ExecuteBookMark(
309 const CPDF_Action& action,
310 CPDFSDK_FormFillEnvironment* pFormFillEnv,
311 CPDF_Bookmark* pBookmark,
312 std::set<CPDF_Dictionary*>* visited) {
313 CPDF_Dictionary* pDict = action.GetDict();
314 if (pdfium::ContainsKey(*visited, pDict))
315 return false;
316
317 visited->insert(pDict);
318
319 ASSERT(pFormFillEnv);
320 if (action.GetType() == CPDF_Action::JavaScript) {
321 if (pFormFillEnv->IsJSInitiated()) {
322 WideString swJS = action.GetJavaScript();
323 if (!swJS.IsEmpty()) {
324 IJS_Runtime* pRuntime = pFormFillEnv->GetJSRuntime();
325 IJS_EventContext* pContext = pRuntime->NewEventContext();
326 pContext->OnBookmark_MouseUp(pBookmark);
327
328 WideString csInfo;
329 bool bRet = pContext->RunScript(swJS, &csInfo);
330 pRuntime->ReleaseEventContext(pContext);
331 if (!bRet) {
332 // FIXME: return error.
333 }
334 }
335 }
336 } else {
337 DoAction_NoJs(action, pFormFillEnv);
338 }
339
340 for (int32_t i = 0, sz = action.GetSubActionsCount(); i < sz; i++) {
341 CPDF_Action subaction = action.GetSubAction(i);
342 if (!ExecuteBookMark(subaction, pFormFillEnv, pBookmark, visited))
343 return false;
344 }
345
346 return true;
347 }
348
DoAction_NoJs(const CPDF_Action & action,CPDFSDK_FormFillEnvironment * pFormFillEnv)349 void CPDFSDK_ActionHandler::DoAction_NoJs(
350 const CPDF_Action& action,
351 CPDFSDK_FormFillEnvironment* pFormFillEnv) {
352 ASSERT(pFormFillEnv);
353
354 switch (action.GetType()) {
355 case CPDF_Action::GoTo:
356 DoAction_GoTo(pFormFillEnv, action);
357 break;
358 case CPDF_Action::GoToR:
359 DoAction_GoToR(pFormFillEnv, action);
360 break;
361 case CPDF_Action::GoToE:
362 break;
363 case CPDF_Action::Launch:
364 DoAction_Launch(pFormFillEnv, action);
365 break;
366 case CPDF_Action::Thread:
367 break;
368 case CPDF_Action::URI:
369 DoAction_URI(pFormFillEnv, action);
370 break;
371 case CPDF_Action::Sound:
372 break;
373 case CPDF_Action::Movie:
374 break;
375 case CPDF_Action::Hide:
376 DoAction_Hide(action, pFormFillEnv);
377 break;
378 case CPDF_Action::Named:
379 DoAction_Named(pFormFillEnv, action);
380 break;
381 case CPDF_Action::SubmitForm:
382 DoAction_SubmitForm(action, pFormFillEnv);
383 break;
384 case CPDF_Action::ResetForm:
385 DoAction_ResetForm(action, pFormFillEnv);
386 break;
387 case CPDF_Action::ImportData:
388 DoAction_ImportData(action, pFormFillEnv);
389 break;
390 case CPDF_Action::JavaScript:
391 NOTREACHED();
392 break;
393 case CPDF_Action::SetOCGState:
394 DoAction_SetOCGState(pFormFillEnv, action);
395 break;
396 case CPDF_Action::Rendition:
397 break;
398 case CPDF_Action::Trans:
399 break;
400 case CPDF_Action::GoTo3DView:
401 break;
402 default:
403 break;
404 }
405 }
406
IsValidDocView(CPDFSDK_FormFillEnvironment * pFormFillEnv)407 bool CPDFSDK_ActionHandler::IsValidDocView(
408 CPDFSDK_FormFillEnvironment* pFormFillEnv) {
409 ASSERT(pFormFillEnv);
410 return true;
411 }
412
DoAction_GoTo(CPDFSDK_FormFillEnvironment * pFormFillEnv,const CPDF_Action & action)413 void CPDFSDK_ActionHandler::DoAction_GoTo(
414 CPDFSDK_FormFillEnvironment* pFormFillEnv,
415 const CPDF_Action& action) {
416 ASSERT(action.GetDict());
417
418 CPDF_Document* pPDFDocument = pFormFillEnv->GetPDFDocument();
419 ASSERT(pPDFDocument);
420
421 CPDF_Dest MyDest = action.GetDest(pPDFDocument);
422 int nPageIndex = MyDest.GetPageIndex(pPDFDocument);
423 int nFitType = MyDest.GetZoomMode();
424 const CPDF_Array* pMyArray = ToArray(MyDest.GetObject());
425 std::vector<float> posArray;
426 if (pMyArray) {
427 for (size_t i = 2; i < pMyArray->GetCount(); i++)
428 posArray.push_back(pMyArray->GetFloatAt(i));
429 }
430 pFormFillEnv->DoGoToAction(nPageIndex, nFitType, posArray.data(),
431 posArray.size());
432 }
433
DoAction_GoToR(CPDFSDK_FormFillEnvironment * pFormFillEnv,const CPDF_Action & action)434 void CPDFSDK_ActionHandler::DoAction_GoToR(
435 CPDFSDK_FormFillEnvironment* pFormFillEnv,
436 const CPDF_Action& action) {}
437
DoAction_Launch(CPDFSDK_FormFillEnvironment * pFormFillEnv,const CPDF_Action & action)438 void CPDFSDK_ActionHandler::DoAction_Launch(
439 CPDFSDK_FormFillEnvironment* pFormFillEnv,
440 const CPDF_Action& action) {}
441
DoAction_URI(CPDFSDK_FormFillEnvironment * pFormFillEnv,const CPDF_Action & action)442 void CPDFSDK_ActionHandler::DoAction_URI(
443 CPDFSDK_FormFillEnvironment* pFormFillEnv,
444 const CPDF_Action& action) {
445 ASSERT(action.GetDict());
446
447 ByteString sURI = action.GetURI(pFormFillEnv->GetPDFDocument());
448 pFormFillEnv->DoURIAction(sURI.c_str());
449 }
450
DoAction_Named(CPDFSDK_FormFillEnvironment * pFormFillEnv,const CPDF_Action & action)451 void CPDFSDK_ActionHandler::DoAction_Named(
452 CPDFSDK_FormFillEnvironment* pFormFillEnv,
453 const CPDF_Action& action) {
454 ASSERT(action.GetDict());
455
456 ByteString csName = action.GetNamedAction();
457 pFormFillEnv->ExecuteNamedAction(csName.c_str());
458 }
459
DoAction_SetOCGState(CPDFSDK_FormFillEnvironment * pFormFillEnv,const CPDF_Action & action)460 void CPDFSDK_ActionHandler::DoAction_SetOCGState(
461 CPDFSDK_FormFillEnvironment* pFormFillEnv,
462 const CPDF_Action& action) {}
463
RunFieldJavaScript(CPDFSDK_FormFillEnvironment * pFormFillEnv,CPDF_FormField * pFormField,CPDF_AAction::AActionType type,PDFSDK_FieldAction & data,const WideString & script)464 void CPDFSDK_ActionHandler::RunFieldJavaScript(
465 CPDFSDK_FormFillEnvironment* pFormFillEnv,
466 CPDF_FormField* pFormField,
467 CPDF_AAction::AActionType type,
468 PDFSDK_FieldAction& data,
469 const WideString& script) {
470 ASSERT(type != CPDF_AAction::Calculate);
471 ASSERT(type != CPDF_AAction::Format);
472
473 IJS_Runtime* pRuntime = pFormFillEnv->GetJSRuntime();
474 IJS_EventContext* pContext = pRuntime->NewEventContext();
475 switch (type) {
476 case CPDF_AAction::CursorEnter:
477 pContext->OnField_MouseEnter(data.bModifier, data.bShift, pFormField);
478 break;
479 case CPDF_AAction::CursorExit:
480 pContext->OnField_MouseExit(data.bModifier, data.bShift, pFormField);
481 break;
482 case CPDF_AAction::ButtonDown:
483 pContext->OnField_MouseDown(data.bModifier, data.bShift, pFormField);
484 break;
485 case CPDF_AAction::ButtonUp:
486 pContext->OnField_MouseUp(data.bModifier, data.bShift, pFormField);
487 break;
488 case CPDF_AAction::GetFocus:
489 pContext->OnField_Focus(data.bModifier, data.bShift, pFormField,
490 data.sValue);
491 break;
492 case CPDF_AAction::LoseFocus:
493 pContext->OnField_Blur(data.bModifier, data.bShift, pFormField,
494 data.sValue);
495 break;
496 case CPDF_AAction::KeyStroke:
497 pContext->OnField_Keystroke(data.sChange, data.sChangeEx, data.bKeyDown,
498 data.bModifier, data.nSelEnd, data.nSelStart,
499 data.bShift, pFormField, data.sValue,
500 data.bWillCommit, data.bFieldFull, data.bRC);
501 break;
502 case CPDF_AAction::Validate:
503 pContext->OnField_Validate(data.sChange, data.sChangeEx, data.bKeyDown,
504 data.bModifier, data.bShift, pFormField,
505 data.sValue, data.bRC);
506 break;
507 default:
508 NOTREACHED();
509 break;
510 }
511
512 WideString csInfo;
513 bool bRet = pContext->RunScript(script, &csInfo);
514 pRuntime->ReleaseEventContext(pContext);
515 if (!bRet) {
516 // FIXME: return error.
517 }
518 }
519
RunDocumentOpenJavaScript(CPDFSDK_FormFillEnvironment * pFormFillEnv,const WideString & sScriptName,const WideString & script)520 void CPDFSDK_ActionHandler::RunDocumentOpenJavaScript(
521 CPDFSDK_FormFillEnvironment* pFormFillEnv,
522 const WideString& sScriptName,
523 const WideString& script) {
524 IJS_Runtime* pRuntime = pFormFillEnv->GetJSRuntime();
525 IJS_EventContext* pContext = pRuntime->NewEventContext();
526 pContext->OnDoc_Open(pFormFillEnv, sScriptName);
527
528 WideString csInfo;
529 bool bRet = pContext->RunScript(script, &csInfo);
530 pRuntime->ReleaseEventContext(pContext);
531 if (!bRet) {
532 // FIXME: return error.
533 }
534 }
535
RunDocumentPageJavaScript(CPDFSDK_FormFillEnvironment * pFormFillEnv,CPDF_AAction::AActionType type,const WideString & script)536 void CPDFSDK_ActionHandler::RunDocumentPageJavaScript(
537 CPDFSDK_FormFillEnvironment* pFormFillEnv,
538 CPDF_AAction::AActionType type,
539 const WideString& script) {
540 IJS_Runtime* pRuntime = pFormFillEnv->GetJSRuntime();
541 IJS_EventContext* pContext = pRuntime->NewEventContext();
542 switch (type) {
543 case CPDF_AAction::OpenPage:
544 pContext->OnPage_Open(pFormFillEnv);
545 break;
546 case CPDF_AAction::ClosePage:
547 pContext->OnPage_Close(pFormFillEnv);
548 break;
549 case CPDF_AAction::CloseDocument:
550 pContext->OnDoc_WillClose(pFormFillEnv);
551 break;
552 case CPDF_AAction::SaveDocument:
553 pContext->OnDoc_WillSave(pFormFillEnv);
554 break;
555 case CPDF_AAction::DocumentSaved:
556 pContext->OnDoc_DidSave(pFormFillEnv);
557 break;
558 case CPDF_AAction::PrintDocument:
559 pContext->OnDoc_WillPrint(pFormFillEnv);
560 break;
561 case CPDF_AAction::DocumentPrinted:
562 pContext->OnDoc_DidPrint(pFormFillEnv);
563 break;
564 case CPDF_AAction::PageVisible:
565 pContext->OnPage_InView(pFormFillEnv);
566 break;
567 case CPDF_AAction::PageInvisible:
568 pContext->OnPage_OutView(pFormFillEnv);
569 break;
570 default:
571 NOTREACHED();
572 break;
573 }
574
575 WideString csInfo;
576 bool bRet = pContext->RunScript(script, &csInfo);
577 pRuntime->ReleaseEventContext(pContext);
578 if (!bRet) {
579 // FIXME: return error.
580 }
581 }
582
DoAction_Hide(const CPDF_Action & action,CPDFSDK_FormFillEnvironment * pFormFillEnv)583 bool CPDFSDK_ActionHandler::DoAction_Hide(
584 const CPDF_Action& action,
585 CPDFSDK_FormFillEnvironment* pFormFillEnv) {
586 CPDFSDK_InterForm* pInterForm = pFormFillEnv->GetInterForm();
587 if (pInterForm->DoAction_Hide(action)) {
588 pFormFillEnv->SetChangeMark();
589 return true;
590 }
591
592 return false;
593 }
594
DoAction_SubmitForm(const CPDF_Action & action,CPDFSDK_FormFillEnvironment * pFormFillEnv)595 bool CPDFSDK_ActionHandler::DoAction_SubmitForm(
596 const CPDF_Action& action,
597 CPDFSDK_FormFillEnvironment* pFormFillEnv) {
598 CPDFSDK_InterForm* pInterForm = pFormFillEnv->GetInterForm();
599 return pInterForm->DoAction_SubmitForm(action);
600 }
601
DoAction_ResetForm(const CPDF_Action & action,CPDFSDK_FormFillEnvironment * pFormFillEnv)602 bool CPDFSDK_ActionHandler::DoAction_ResetForm(
603 const CPDF_Action& action,
604 CPDFSDK_FormFillEnvironment* pFormFillEnv) {
605 CPDFSDK_InterForm* pInterForm = pFormFillEnv->GetInterForm();
606 return pInterForm->DoAction_ResetForm(action);
607 }
608
DoAction_ImportData(const CPDF_Action & action,CPDFSDK_FormFillEnvironment * pFormFillEnv)609 bool CPDFSDK_ActionHandler::DoAction_ImportData(
610 const CPDF_Action& action,
611 CPDFSDK_FormFillEnvironment* pFormFillEnv) {
612 CPDFSDK_InterForm* pInterForm = pFormFillEnv->GetInterForm();
613 if (pInterForm->DoAction_ImportData(action)) {
614 pFormFillEnv->SetChangeMark();
615 return true;
616 }
617
618 return false;
619 }
620