Clean: Fix some unneeded semi-colons and bad spacing.
[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   delete[] pPosAry;
538 }
539
540 void CPDFSDK_ActionHandler::DoAction_GoToR(CPDFSDK_Document* pDocument,
541                                            const CPDF_Action& action) {}
542
543 void CPDFSDK_ActionHandler::DoAction_Launch(CPDFSDK_Document* pDocument,
544                                             const CPDF_Action& action) {}
545
546 void CPDFSDK_ActionHandler::DoAction_URI(CPDFSDK_Document* pDocument,
547                                          const CPDF_Action& action) {
548   ASSERT(action);
549
550   CPDFDoc_Environment* pApp = pDocument->GetEnv();
551   ASSERT(pApp != NULL);
552
553   CFX_ByteString sURI = action.GetURI(pDocument->GetDocument());
554   pApp->FFI_DoURIAction(sURI.c_str());
555 }
556
557 void CPDFSDK_ActionHandler::DoAction_Named(CPDFSDK_Document* pDocument,
558                                            const CPDF_Action& action) {
559   ASSERT(action);
560
561   CFX_ByteString csName = action.GetNamedAction();
562   pDocument->GetEnv()->FFI_ExecuteNamedAction(csName);
563 }
564
565 void CPDFSDK_ActionHandler::DoAction_SetOCGState(CPDFSDK_Document* pDocument,
566                                                  const CPDF_Action& action) {}
567
568 void CPDFSDK_ActionHandler::RunFieldJavaScript(CPDFSDK_Document* pDocument,
569                                                CPDF_FormField* pFormField,
570                                                CPDF_AAction::AActionType type,
571                                                PDFSDK_FieldAction& data,
572                                                const CFX_WideString& script) {
573   ASSERT(type != CPDF_AAction::Calculate);
574   ASSERT(type != CPDF_AAction::Format);
575
576   ASSERT(pDocument != NULL);
577
578   IFXJS_Runtime* pRuntime = pDocument->GetJsRuntime();
579   ASSERT(pRuntime != NULL);
580
581   pRuntime->SetReaderDocument(pDocument);
582
583   IFXJS_Context* pContext = pRuntime->NewContext();
584   ASSERT(pContext != NULL);
585
586   switch (type) {
587     case CPDF_AAction::CursorEnter:
588       pContext->OnField_MouseEnter(data.bModifier, data.bShift, pFormField);
589       break;
590     case CPDF_AAction::CursorExit:
591       pContext->OnField_MouseExit(data.bModifier, data.bShift, pFormField);
592       break;
593     case CPDF_AAction::ButtonDown:
594       pContext->OnField_MouseDown(data.bModifier, data.bShift, pFormField);
595       break;
596     case CPDF_AAction::ButtonUp:
597       pContext->OnField_MouseUp(data.bModifier, data.bShift, pFormField);
598       break;
599     case CPDF_AAction::GetFocus:
600       pContext->OnField_Focus(data.bModifier, data.bShift, pFormField,
601                               data.sValue);
602       break;
603     case CPDF_AAction::LoseFocus:
604       pContext->OnField_Blur(data.bModifier, data.bShift, pFormField,
605                              data.sValue);
606       break;
607     case CPDF_AAction::KeyStroke:
608       pContext->OnField_Keystroke(data.sChange, data.sChangeEx, data.bKeyDown,
609                                   data.bModifier, data.nSelEnd, data.nSelStart,
610                                   data.bShift, pFormField, data.sValue,
611                                   data.bWillCommit, data.bFieldFull, data.bRC);
612       break;
613     case CPDF_AAction::Validate:
614       pContext->OnField_Validate(data.sChange, data.sChangeEx, data.bKeyDown,
615                                  data.bModifier, data.bShift, pFormField,
616                                  data.sValue, data.bRC);
617       break;
618     default:
619       ASSERT(FALSE);
620       break;
621   }
622
623   CFX_WideString csInfo;
624   FX_BOOL bRet = pContext->RunScript(script, csInfo);
625   if (!bRet) {
626     // CBCL_FormNotify::MsgBoxJSError(pPageView->GetPageViewWnd(), csInfo);
627   }
628
629   pRuntime->ReleaseContext(pContext);
630 }
631
632 void CPDFSDK_ActionHandler::RunDocumentOpenJavaScript(
633     CPDFSDK_Document* pDocument,
634     const CFX_WideString& sScriptName,
635     const CFX_WideString& script) {
636   ASSERT(pDocument != NULL);
637
638   IFXJS_Runtime* pRuntime = pDocument->GetJsRuntime();
639   ASSERT(pRuntime != NULL);
640
641   pRuntime->SetReaderDocument(pDocument);
642
643   IFXJS_Context* pContext = pRuntime->NewContext();
644   ASSERT(pContext != NULL);
645
646   pContext->OnDoc_Open(pDocument, sScriptName);
647
648   CFX_WideString csInfo;
649   FX_BOOL bRet = pContext->RunScript(script, csInfo);
650   if (!bRet) {
651     // CBCL_FormNotify::MsgBoxJSError(pPageView->GetPageViewWnd(), csInfo);
652   }
653
654   pRuntime->ReleaseContext(pContext);
655 }
656
657 void CPDFSDK_ActionHandler::RunDocumentPageJavaScript(
658     CPDFSDK_Document* pDocument,
659     CPDF_AAction::AActionType type,
660     const CFX_WideString& script) {
661   ASSERT(pDocument != NULL);
662
663   IFXJS_Runtime* pRuntime = pDocument->GetJsRuntime();
664   ASSERT(pRuntime != NULL);
665
666   pRuntime->SetReaderDocument(pDocument);
667
668   IFXJS_Context* pContext = pRuntime->NewContext();
669   ASSERT(pContext != NULL);
670
671   switch (type) {
672     case CPDF_AAction::OpenPage:
673       pContext->OnPage_Open(pDocument);
674       break;
675     case CPDF_AAction::ClosePage:
676       pContext->OnPage_Close(pDocument);
677       break;
678     case CPDF_AAction::CloseDocument:
679       pContext->OnDoc_WillClose(pDocument);
680       break;
681     case CPDF_AAction::SaveDocument:
682       pContext->OnDoc_WillSave(pDocument);
683       break;
684     case CPDF_AAction::DocumentSaved:
685       pContext->OnDoc_DidSave(pDocument);
686       break;
687     case CPDF_AAction::PrintDocument:
688       pContext->OnDoc_WillPrint(pDocument);
689       break;
690     case CPDF_AAction::DocumentPrinted:
691       pContext->OnDoc_DidPrint(pDocument);
692       break;
693     case CPDF_AAction::PageVisible:
694       pContext->OnPage_InView(pDocument);
695       break;
696     case CPDF_AAction::PageInvisible:
697       pContext->OnPage_OutView(pDocument);
698       break;
699     default:
700       ASSERT(FALSE);
701       break;
702   }
703
704   CFX_WideString csInfo;
705   FX_BOOL bRet = pContext->RunScript(script, csInfo);
706   if (!bRet) {
707     // CBCL_FormNotify::MsgBoxJSError(pPageView->GetPageViewWnd(), csInfo);
708   }
709
710   pRuntime->ReleaseContext(pContext);
711 }
712
713 FX_BOOL CPDFSDK_FormActionHandler::DoAction_Hide(const CPDF_Action& action,
714                                                  CPDFSDK_Document* pDocument) {
715   ASSERT(pDocument != NULL);
716
717   CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm();
718   ASSERT(pInterForm != NULL);
719
720   if (pInterForm->DoAction_Hide(action)) {
721     pDocument->SetChangeMark();
722     return TRUE;
723   }
724
725   return FALSE;
726 }
727
728 FX_BOOL CPDFSDK_FormActionHandler::DoAction_SubmitForm(
729     const CPDF_Action& action,
730     CPDFSDK_Document* pDocument) {
731   ASSERT(pDocument != NULL);
732
733   CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm();
734   ASSERT(pInterForm != NULL);
735
736   return pInterForm->DoAction_SubmitForm(action);
737 }
738
739 FX_BOOL CPDFSDK_FormActionHandler::DoAction_ResetForm(
740     const CPDF_Action& action,
741     CPDFSDK_Document* pDocument) {
742   ASSERT(pDocument != NULL);
743
744   CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm();
745   ASSERT(pInterForm != NULL);
746
747   if (pInterForm->DoAction_ResetForm(action)) {
748     return TRUE;
749   }
750
751   return FALSE;
752 }
753
754 FX_BOOL CPDFSDK_FormActionHandler::DoAction_ImportData(
755     const CPDF_Action& action,
756     CPDFSDK_Document* pDocument) {
757   ASSERT(pDocument != NULL);
758
759   CPDFSDK_InterForm* pInterForm = (CPDFSDK_InterForm*)pDocument->GetInterForm();
760   ASSERT(pInterForm != NULL);
761
762   if (pInterForm->DoAction_ImportData(action)) {
763     pDocument->SetChangeMark();
764     return TRUE;
765   }
766
767   return FALSE;
768 }
769
770 FX_BOOL CPDFSDK_MediaActionHandler::DoAction_Rendition(
771     const CPDF_Action& action,
772     CPDFSDK_Document* pDocument) {
773   return FALSE;
774 }
775
776 FX_BOOL CPDFSDK_MediaActionHandler::DoAction_Sound(
777     const CPDF_Action& action,
778     CPDFSDK_Document* pDocument) {
779   return FALSE;
780 }
781
782 FX_BOOL CPDFSDK_MediaActionHandler::DoAction_Movie(
783     const CPDF_Action& action,
784     CPDFSDK_Document* pDocument) {
785   return FALSE;
786 }