clang-format all pdfium code.
[pdfium.git] / fpdfsdk / src / fsdk_actionhandler.cpp
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 "../include/fsdk_define.h"
8 #include "../include/fsdk_mgr.h"
9 #include "../include/fsdk_actionhandler.h"
10 #include "../include/javascript/IJavaScript.h"
11
12 /* -------------------------- CBA_ActionHandler -------------------------- */
13
14 CPDFSDK_ActionHandler::CPDFSDK_ActionHandler(CPDFDoc_Environment* pEvi)
15     : m_pFormActionHandler(new CPDFSDK_FormActionHandler),
16       m_pMediaActionHandler(NULL) {}
17
18 void CPDFSDK_ActionHandler::SetMediaActionHandler(
19     CPDFSDK_MediaActionHandler* pHandler) {
20   ASSERT(pHandler != NULL);
21   ASSERT(m_pMediaActionHandler == NULL);
22   m_pMediaActionHandler = pHandler;
23 }
24
25 // document open
26 FX_BOOL CPDFSDK_ActionHandler::DoAction_DocOpen(const CPDF_Action& action,
27                                                 CPDFSDK_Document* pDocument) {
28   CFX_PtrList list;
29   return ExecuteDocumentOpenAction(action, pDocument, list);
30 }
31
32 // document open
33 FX_BOOL CPDFSDK_ActionHandler::DoAction_JavaScript(
34     const CPDF_Action& JsAction,
35     CFX_WideString csJSName,
36     CPDFSDK_Document* pDocument) {
37   if (JsAction.GetType() == CPDF_Action::JavaScript) {
38     CFX_WideString swJS = JsAction.GetJavaScript();
39     if (!swJS.IsEmpty()) {
40       RunDocumentOpenJavaScript(pDocument, csJSName, swJS);
41       return TRUE;
42     }
43   }
44
45   return FALSE;
46 }
47
48 FX_BOOL CPDFSDK_ActionHandler::DoAction_FieldJavaScript(
49     const CPDF_Action& JsAction,
50     CPDF_AAction::AActionType type,
51     CPDFSDK_Document* pDocument,
52     CPDF_FormField* pFormField,
53     PDFSDK_FieldAction& data) {
54   CPDFDoc_Environment* pEnv = pDocument->GetEnv();
55   ASSERT(pEnv);
56   if (pEnv->IsJSInitiated() && JsAction.GetType() == CPDF_Action::JavaScript) {
57     CFX_WideString swJS = JsAction.GetJavaScript();
58     if (!swJS.IsEmpty()) {
59       RunFieldJavaScript(pDocument, pFormField, type, data, swJS);
60       return TRUE;
61     }
62   }
63   return FALSE;
64 }
65
66 FX_BOOL CPDFSDK_ActionHandler::DoAction_Page(
67     const CPDF_Action& action,
68     enum CPDF_AAction::AActionType eType,
69     CPDFSDK_Document* pDocument) {
70   CFX_PtrList list;
71   return ExecuteDocumentPageAction(action, eType, pDocument, list);
72 }
73
74 FX_BOOL CPDFSDK_ActionHandler::DoAction_Document(
75     const CPDF_Action& action,
76     enum CPDF_AAction::AActionType eType,
77     CPDFSDK_Document* pDocument) {
78   CFX_PtrList list;
79   return ExecuteDocumentPageAction(action, eType, pDocument, list);
80 }
81
82 FX_BOOL CPDFSDK_ActionHandler::DoAction_BookMark(CPDF_Bookmark* pBookMark,
83                                                  const CPDF_Action& action,
84                                                  CPDF_AAction::AActionType type,
85                                                  CPDFSDK_Document* pDocument) {
86   CFX_PtrList list;
87   return ExecuteBookMark(action, pDocument, pBookMark, list);
88 }
89
90 FX_BOOL CPDFSDK_ActionHandler::DoAction_Screen(const CPDF_Action& action,
91                                                CPDF_AAction::AActionType type,
92                                                CPDFSDK_Document* pDocument,
93                                                CPDFSDK_Annot* pScreen) {
94   CFX_PtrList list;
95   return ExecuteScreenAction(action, type, pDocument, pScreen, list);
96 }
97
98 FX_BOOL CPDFSDK_ActionHandler::DoAction_Link(const CPDF_Action& action,
99                                              CPDFSDK_Document* pDocument) {
100   CFX_PtrList list;
101   return ExecuteLinkAction(action, pDocument, list);
102 }
103
104 FX_BOOL CPDFSDK_ActionHandler::DoAction_Field(const CPDF_Action& action,
105                                               CPDF_AAction::AActionType type,
106                                               CPDFSDK_Document* pDocument,
107                                               CPDF_FormField* pFormField,
108                                               PDFSDK_FieldAction& data) {
109   CFX_PtrList list;
110   return ExecuteFieldAction(action, type, pDocument, pFormField, data, list);
111 }
112
113 FX_BOOL CPDFSDK_ActionHandler::ExecuteDocumentOpenAction(
114     const CPDF_Action& action,
115     CPDFSDK_Document* pDocument,
116     CFX_PtrList& list) {
117   CPDF_Dictionary* pDict = action.GetDict();
118   if (list.Find(pDict))
119     return FALSE;
120
121   list.AddTail(pDict);
122
123   CPDFDoc_Environment* pEnv = pDocument->GetEnv();
124   ASSERT(pEnv);
125   if (action.GetType() == CPDF_Action::JavaScript) {
126     if (pEnv->IsJSInitiated()) {
127       CFX_WideString swJS = action.GetJavaScript();
128       if (!swJS.IsEmpty()) {
129         RunDocumentOpenJavaScript(pDocument, L"", swJS);
130       }
131     }
132   } else {
133     DoAction_NoJs(action, pDocument);
134   }
135
136   for (int32_t i = 0, sz = action.GetSubActionsCount(); i < sz; i++) {
137     CPDF_Action subaction = action.GetSubAction(i);
138     if (!ExecuteDocumentOpenAction(subaction, pDocument, list))
139       return FALSE;
140   }
141
142   return TRUE;
143 }
144
145 FX_BOOL CPDFSDK_ActionHandler::ExecuteLinkAction(const CPDF_Action& action,
146                                                  CPDFSDK_Document* pDocument,
147                                                  CFX_PtrList& list) {
148   ASSERT(pDocument != NULL);
149
150   CPDF_Dictionary* pDict = action.GetDict();
151   if (list.Find(pDict))
152     return FALSE;
153
154   list.AddTail(pDict);
155
156   CPDFDoc_Environment* pEnv = pDocument->GetEnv();
157   ASSERT(pEnv);
158   if (action.GetType() == CPDF_Action::JavaScript) {
159     if (pEnv->IsJSInitiated()) {
160       CFX_WideString swJS = action.GetJavaScript();
161       if (!swJS.IsEmpty()) {
162         IFXJS_Runtime* pRuntime = pDocument->GetJsRuntime();  //????
163         ASSERT(pRuntime != NULL);
164
165         pRuntime->SetReaderDocument(pDocument);
166
167         IFXJS_Context* pContext = pRuntime->NewContext();
168         ASSERT(pContext != NULL);
169
170         pContext->OnLink_MouseUp(pDocument);
171
172         CFX_WideString csInfo;
173         FX_BOOL bRet = pContext->RunScript(swJS, csInfo);
174         if (!bRet) {
175           // FIXME: return error.
176         }
177
178         pRuntime->ReleaseContext(pContext);
179       }
180     }
181   } else {
182     DoAction_NoJs(action, pDocument);
183   }
184
185   for (int32_t i = 0, sz = action.GetSubActionsCount(); i < sz; i++) {
186     CPDF_Action subaction = action.GetSubAction(i);
187     if (!ExecuteLinkAction(subaction, pDocument, list))
188       return FALSE;
189   }
190
191   return TRUE;
192 }
193
194 FX_BOOL CPDFSDK_ActionHandler::ExecuteDocumentPageAction(
195     const CPDF_Action& action,
196     CPDF_AAction::AActionType type,
197     CPDFSDK_Document* pDocument,
198     CFX_PtrList& list) {
199   ASSERT(pDocument != NULL);
200
201   CPDF_Dictionary* pDict = action.GetDict();
202   if (list.Find(pDict))
203     return FALSE;
204
205   list.AddTail(pDict);
206
207   CPDFDoc_Environment* pEnv = pDocument->GetEnv();
208   ASSERT(pEnv);
209   if (action.GetType() == CPDF_Action::JavaScript) {
210     if (pEnv->IsJSInitiated()) {
211       CFX_WideString swJS = action.GetJavaScript();
212       if (!swJS.IsEmpty()) {
213         RunDocumentPageJavaScript(pDocument, type, swJS);
214       }
215     }
216   } else {
217     DoAction_NoJs(action, pDocument);
218   }
219
220   if (!IsValidDocView(pDocument))
221     return FALSE;
222
223   for (int32_t i = 0, sz = action.GetSubActionsCount(); i < sz; i++) {
224     CPDF_Action subaction = action.GetSubAction(i);
225     if (!ExecuteDocumentPageAction(subaction, type, pDocument, list))
226       return FALSE;
227   }
228
229   return TRUE;
230 }
231
232 FX_BOOL CPDFSDK_ActionHandler::IsValidField(CPDFSDK_Document* pDocument,
233                                             CPDF_Dictionary* pFieldDict) {
234   ASSERT(pDocument != NULL);
235   ASSERT(pFieldDict != NULL);
236
237   CPDFSDK_InterForm* pInterForm = pDocument->GetInterForm();
238   ASSERT(pInterForm != NULL);
239
240   CPDF_InterForm* pPDFInterForm = pInterForm->GetInterForm();
241   ASSERT(pPDFInterForm != NULL);
242
243   return pPDFInterForm->GetFieldByDict(pFieldDict) != NULL;
244 }
245
246 FX_BOOL CPDFSDK_ActionHandler::ExecuteFieldAction(
247     const CPDF_Action& action,
248     CPDF_AAction::AActionType type,
249     CPDFSDK_Document* pDocument,
250     CPDF_FormField* pFormField,
251     PDFSDK_FieldAction& data,
252     CFX_PtrList& list) {
253   ASSERT(pDocument != NULL);
254
255   CPDF_Dictionary* pDict = action.GetDict();
256   if (list.Find(pDict))
257     return FALSE;
258
259   list.AddTail(pDict);
260
261   CPDFDoc_Environment* pEnv = pDocument->GetEnv();
262   ASSERT(pEnv);
263   if (action.GetType() == CPDF_Action::JavaScript) {
264     if (pEnv->IsJSInitiated()) {
265       CFX_WideString swJS = action.GetJavaScript();
266       if (!swJS.IsEmpty()) {
267         RunFieldJavaScript(pDocument, pFormField, type, data, swJS);
268         if (!IsValidField(pDocument, pFormField->GetFieldDict()))
269           return FALSE;
270       }
271     }
272   } else {
273     DoAction_NoJs(action, pDocument);
274   }
275
276   for (int32_t i = 0, sz = action.GetSubActionsCount(); i < sz; i++) {
277     CPDF_Action subaction = action.GetSubAction(i);
278     if (!ExecuteFieldAction(subaction, type, pDocument, pFormField, data, list))
279       return FALSE;
280   }
281
282   return TRUE;
283 }
284
285 FX_BOOL CPDFSDK_ActionHandler::ExecuteScreenAction(
286     const CPDF_Action& action,
287     CPDF_AAction::AActionType type,
288     CPDFSDK_Document* pDocument,
289     CPDFSDK_Annot* pScreen,
290     CFX_PtrList& list) {
291   ASSERT(pDocument != NULL);
292
293   CPDF_Dictionary* pDict = action.GetDict();
294   if (list.Find(pDict))
295     return FALSE;
296
297   list.AddTail(pDict);
298
299   CPDFDoc_Environment* pEnv = pDocument->GetEnv();
300   ASSERT(pEnv);
301   if (action.GetType() == CPDF_Action::JavaScript) {
302     if (pEnv->IsJSInitiated()) {
303       CFX_WideString swJS = action.GetJavaScript();
304       if (!swJS.IsEmpty()) {
305         IFXJS_Runtime* pRuntime = pDocument->GetJsRuntime();
306         ASSERT(pRuntime != NULL);
307
308         pRuntime->SetReaderDocument(pDocument);
309
310         IFXJS_Context* pContext = pRuntime->NewContext();
311         ASSERT(pContext != NULL);
312
313         //                      switch (type)
314         //                      {
315         //                      case CPDF_AAction::CursorEnter:
316         //                              pContext->OnScreen_MouseEnter(IsCTRLpressed(),
317         // IsSHIFTpressed(), pScreen);
318         //                              break;
319         //                      case CPDF_AAction::CursorExit:
320         //                              pContext->OnScreen_MouseExit(IsCTRLpressed(),
321         // IsSHIFTpressed(), pScreen);
322         //                              break;
323         //                      case CPDF_AAction::ButtonDown:
324         //                              pContext->OnScreen_MouseDown(IsCTRLpressed(),
325         // IsSHIFTpressed(), pScreen);
326         //                              break;
327         //                      case CPDF_AAction::ButtonUp:
328         //                              pContext->OnScreen_MouseUp(IsCTRLpressed(),
329         // IsSHIFTpressed(), pScreen);
330         //                              break;
331         //                      case CPDF_AAction::GetFocus:
332         //                              pContext->OnScreen_Focus(IsCTRLpressed(),
333         // IsSHIFTpressed(), pScreen);
334         //                              break;
335         //                      case CPDF_AAction::LoseFocus:
336         //                              pContext->OnScreen_Blur(IsCTRLpressed(),
337         // IsSHIFTpressed(), pScreen);
338         //                              break;
339         //                      case CPDF_AAction::PageOpen:
340         //                              pContext->OnScreen_Open(IsCTRLpressed(),
341         // IsSHIFTpressed(), pScreen);
342         //                              break;
343         //                      case CPDF_AAction::PageClose:
344         //                              pContext->OnScreen_Close(IsCTRLpressed(),
345         // IsSHIFTpressed(), pScreen);
346         //                              break;
347         //                      case CPDF_AAction::PageVisible:
348         //                              pContext->OnScreen_InView(IsCTRLpressed(),
349         // IsSHIFTpressed(), pScreen);
350         //                              break;
351         //                      case CPDF_AAction::PageInvisible:
352         //                              pContext->OnScreen_OutView(IsCTRLpressed(),
353         // IsSHIFTpressed(), pScreen);
354         //                              break;
355         //                      default:
356         //                              ASSERT(FALSE);
357         //                              break;
358         //                      }
359
360         CFX_WideString csInfo;
361         FX_BOOL bRet = pContext->RunScript(swJS, csInfo);
362         if (!bRet) {
363           // CBCL_FormNotify::MsgBoxJSError(pPageView->GetPageViewWnd(),
364           // csInfo);
365         }
366
367         pRuntime->ReleaseContext(pContext);
368       }
369     }
370   } else {
371     DoAction_NoJs(action, pDocument);
372   }
373
374   for (int32_t i = 0, sz = action.GetSubActionsCount(); i < sz; i++) {
375     CPDF_Action subaction = action.GetSubAction(i);
376     if (!ExecuteScreenAction(subaction, type, pDocument, pScreen, list))
377       return FALSE;
378   }
379
380   return TRUE;
381 }
382
383 FX_BOOL CPDFSDK_ActionHandler::ExecuteBookMark(const CPDF_Action& action,
384                                                CPDFSDK_Document* pDocument,
385                                                CPDF_Bookmark* pBookmark,
386                                                CFX_PtrList& list) {
387   ASSERT(pDocument != NULL);
388
389   CPDF_Dictionary* pDict = action.GetDict();
390   if (list.Find(pDict))
391     return FALSE;
392
393   list.AddTail(pDict);
394
395   CPDFDoc_Environment* pEnv = pDocument->GetEnv();
396   ASSERT(pEnv);
397   if (action.GetType() == CPDF_Action::JavaScript) {
398     if (pEnv->IsJSInitiated()) {
399       CFX_WideString swJS = action.GetJavaScript();
400       if (!swJS.IsEmpty()) {
401         IFXJS_Runtime* pRuntime = pDocument->GetJsRuntime();
402         ASSERT(pRuntime != NULL);
403
404         pRuntime->SetReaderDocument(pDocument);
405
406         IFXJS_Context* pContext = pRuntime->NewContext();
407         ASSERT(pContext != NULL);
408
409         pContext->OnBookmark_MouseUp(pBookmark);
410
411         CFX_WideString csInfo;
412         FX_BOOL bRet = pContext->RunScript(swJS, csInfo);
413         if (!bRet) {
414           // CBCL_FormNotify::MsgBoxJSError(pPageView->GetPageViewWnd(),
415           // csInfo);
416         }
417
418         pRuntime->ReleaseContext(pContext);
419       }
420     }
421   } else {
422     DoAction_NoJs(action, pDocument);
423   }
424
425   for (int32_t i = 0, sz = action.GetSubActionsCount(); i < sz; i++) {
426     CPDF_Action subaction = action.GetSubAction(i);
427     if (!ExecuteBookMark(subaction, pDocument, pBookmark, list))
428       return FALSE;
429   }
430
431   return TRUE;
432 }
433
434 void CPDFSDK_ActionHandler::DoAction_NoJs(const CPDF_Action& action,
435                                           CPDFSDK_Document* pDocument) {
436   ASSERT(pDocument != NULL);
437
438   switch (action.GetType()) {
439     case CPDF_Action::GoTo:
440       DoAction_GoTo(pDocument, action);
441       break;
442     case CPDF_Action::GoToR:
443       DoAction_GoToR(pDocument, action);
444       break;
445     case CPDF_Action::GoToE:
446       break;
447     case CPDF_Action::Launch:
448       DoAction_Launch(pDocument, action);
449       break;
450     case CPDF_Action::Thread:
451       break;
452     case CPDF_Action::URI:
453       DoAction_URI(pDocument, action);
454       break;
455     case CPDF_Action::Sound:
456       if (m_pMediaActionHandler) {
457         m_pMediaActionHandler->DoAction_Sound(action, pDocument);
458       }
459       break;
460     case CPDF_Action::Movie:
461       if (m_pMediaActionHandler) {
462         m_pMediaActionHandler->DoAction_Movie(action, pDocument);
463       }
464       break;
465     case CPDF_Action::Hide:
466       if (m_pFormActionHandler) {
467         m_pFormActionHandler->DoAction_Hide(action, pDocument);
468       }
469       break;
470     case CPDF_Action::Named:
471       DoAction_Named(pDocument, action);
472       break;
473     case CPDF_Action::SubmitForm:
474       if (m_pFormActionHandler) {
475         m_pFormActionHandler->DoAction_SubmitForm(action, pDocument);
476       }
477       break;
478     case CPDF_Action::ResetForm:
479       if (m_pFormActionHandler) {
480         m_pFormActionHandler->DoAction_ResetForm(action, pDocument);
481       }
482       break;
483     case CPDF_Action::ImportData:
484       if (m_pFormActionHandler) {
485         m_pFormActionHandler->DoAction_ImportData(action, pDocument);
486       }
487       break;
488     case CPDF_Action::JavaScript:
489       ASSERT(FALSE);
490       break;
491     case CPDF_Action::SetOCGState:
492       DoAction_SetOCGState(pDocument, action);
493       break;
494     case CPDF_Action::Rendition:
495       if (m_pMediaActionHandler) {
496         m_pMediaActionHandler->DoAction_Rendition(action, pDocument);
497       }
498       break;
499     case CPDF_Action::Trans:
500       break;
501     case CPDF_Action::GoTo3DView:
502       break;
503     default:
504       break;
505   }
506 }
507
508 FX_BOOL CPDFSDK_ActionHandler::IsValidDocView(CPDFSDK_Document* pDocument) {
509   ASSERT(pDocument != NULL);
510   return TRUE;
511 }
512
513 void CPDFSDK_ActionHandler::DoAction_GoTo(CPDFSDK_Document* pDocument,
514                                           const CPDF_Action& action) {
515   ASSERT(action);
516
517   CPDF_Document* pPDFDocument = pDocument->GetDocument();
518   ASSERT(pPDFDocument != NULL);
519   CPDFDoc_Environment* pApp = pDocument->GetEnv();
520   ASSERT(pApp != NULL);
521
522   CPDF_Dest MyDest = action.GetDest(pPDFDocument);
523   int nPageIndex = MyDest.GetPageIndex(pPDFDocument);
524   int nFitType = MyDest.GetZoomMode();
525   const CPDF_Array* pMyArray = (CPDF_Array*)MyDest.GetObject();
526   float* pPosAry = NULL;
527   int sizeOfAry = 0;
528   if (pMyArray != NULL) {
529     pPosAry = new float[pMyArray->GetCount()];
530     int j = 0;
531     for (int i = 2; i < (int)pMyArray->GetCount(); i++) {
532       pPosAry[j++] = pMyArray->GetFloat(i);
533     }
534     sizeOfAry = j;
535   }
536   pApp->FFI_DoGoToAction(nPageIndex, nFitType, pPosAry, sizeOfAry);
537   if (pPosAry)
538     delete[] pPosAry;
539 }
540
541 void CPDFSDK_ActionHandler::DoAction_GoToR(CPDFSDK_Document* pDocument,
542                                            const CPDF_Action& action) {}
543
544 void CPDFSDK_ActionHandler::DoAction_Launch(CPDFSDK_Document* pDocument,
545                                             const CPDF_Action& action) {}
546
547 void 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());
555   pApp->FFI_DoURIAction(sURI.c_str());
556 }
557
558 void CPDFSDK_ActionHandler::DoAction_Named(CPDFSDK_Document* pDocument,
559                                            const CPDF_Action& action) {
560   ASSERT(action);
561
562   CFX_ByteString csName = action.GetNamedAction();
563   pDocument->GetEnv()->FFI_ExecuteNamedAction(csName);
564 }
565
566 void CPDFSDK_ActionHandler::DoAction_SetOCGState(CPDFSDK_Document* pDocument,
567                                                  const CPDF_Action& action) {}
568
569 void 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);
576
577   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);
631 }
632
633 void CPDFSDK_ActionHandler::RunDocumentOpenJavaScript(
634     CPDFSDK_Document* pDocument,
635     const CFX_WideString& sScriptName,
636     const CFX_WideString& script) {
637   ASSERT(pDocument != NULL);
638
639   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);
656 }
657
658 void CPDFSDK_ActionHandler::RunDocumentPageJavaScript(
659     CPDFSDK_Document* pDocument,
660     CPDF_AAction::AActionType type,
661     const CFX_WideString& script) {
662   ASSERT(pDocument != NULL);
663
664   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);
712 }
713
714 FX_BOOL CPDFSDK_FormActionHandler::DoAction_Hide(const CPDF_Action& action,
715                                                  CPDFSDK_Document* pDocument) {
716   ASSERT(pDocument != NULL);
717
718   CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm();
719   ASSERT(pInterForm != NULL);
720
721   if (pInterForm->DoAction_Hide(action)) {
722     pDocument->SetChangeMark();
723     return TRUE;
724   }
725
726   return FALSE;
727 }
728
729 FX_BOOL CPDFSDK_FormActionHandler::DoAction_SubmitForm(
730     const CPDF_Action& action,
731     CPDFSDK_Document* pDocument) {
732   ASSERT(pDocument != NULL);
733
734   CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm();
735   ASSERT(pInterForm != NULL);
736
737   return pInterForm->DoAction_SubmitForm(action);
738 }
739
740 FX_BOOL CPDFSDK_FormActionHandler::DoAction_ResetForm(
741     const CPDF_Action& action,
742     CPDFSDK_Document* pDocument) {
743   ASSERT(pDocument != NULL);
744
745   CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm();
746   ASSERT(pInterForm != NULL);
747
748   if (pInterForm->DoAction_ResetForm(action)) {
749     return TRUE;
750   }
751
752   return FALSE;
753 }
754
755 FX_BOOL CPDFSDK_FormActionHandler::DoAction_ImportData(
756     const CPDF_Action& action,
757     CPDFSDK_Document* pDocument) {
758   ASSERT(pDocument != NULL);
759
760   CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm();
761   ASSERT(pInterForm != NULL);
762
763   if (pInterForm->DoAction_ImportData(action)) {
764     pDocument->SetChangeMark();
765     return TRUE;
766   }
767
768   return FALSE;
769 }
770
771 FX_BOOL CPDFSDK_MediaActionHandler::DoAction_Rendition(
772     const CPDF_Action& action,
773     CPDFSDK_Document* pDocument) {
774   return FALSE;
775 }
776
777 FX_BOOL CPDFSDK_MediaActionHandler::DoAction_Sound(
778     const CPDF_Action& action,
779     CPDFSDK_Document* pDocument) {
780   return FALSE;
781 }
782
783 FX_BOOL CPDFSDK_MediaActionHandler::DoAction_Movie(
784     const CPDF_Action& action,
785     CPDFSDK_Document* pDocument) {
786   return FALSE;
787 }