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