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 #ifndef FPDFSDK_INCLUDE_FSDK_ACTIONHANDLER_H_
8 #define FPDFSDK_INCLUDE_FSDK_ACTIONHANDLER_H_
9 
10 #include <memory>
11 #include <set>
12 
13 #include "core/fpdfdoc/include/fpdf_doc.h"
14 #include "core/fxcrt/include/fx_string.h"
15 #include "fpdfsdk/include/fsdk_baseform.h"
16 
17 class CPDFSDK_Annot;
18 class CPDFSDK_Document;
19 class CPDF_Bookmark;
20 class CPDF_Dictionary;
21 
22 class CPDFSDK_FormActionHandler {
23  public:
24   FX_BOOL DoAction_Hide(const CPDF_Action& action, CPDFSDK_Document* pDocument);
25   FX_BOOL DoAction_SubmitForm(const CPDF_Action& action,
26                               CPDFSDK_Document* pDocument);
27   FX_BOOL DoAction_ResetForm(const CPDF_Action& action,
28                              CPDFSDK_Document* pDocument);
29   FX_BOOL DoAction_ImportData(const CPDF_Action& action,
30                               CPDFSDK_Document* pDocument);
31 };
32 
33 class CPDFSDK_ActionHandler {
34  public:
35   CPDFSDK_ActionHandler();
36   ~CPDFSDK_ActionHandler();
37 
38   FX_BOOL DoAction_DocOpen(const CPDF_Action& action,
39                            CPDFSDK_Document* pDocument);
40   FX_BOOL DoAction_JavaScript(const CPDF_Action& JsAction,
41                               CFX_WideString csJSName,
42                               CPDFSDK_Document* pDocument);
43   FX_BOOL DoAction_Page(const CPDF_Action& action,
44                         enum CPDF_AAction::AActionType eType,
45                         CPDFSDK_Document* pDocument);
46   FX_BOOL DoAction_Document(const CPDF_Action& action,
47                             enum CPDF_AAction::AActionType eType,
48                             CPDFSDK_Document* pDocument);
49   FX_BOOL DoAction_BookMark(CPDF_Bookmark* pBookMark,
50                             const CPDF_Action& action,
51                             CPDF_AAction::AActionType type,
52                             CPDFSDK_Document* pDocument);
53   FX_BOOL DoAction_Screen(const CPDF_Action& action,
54                           CPDF_AAction::AActionType type,
55                           CPDFSDK_Document* pDocument,
56                           CPDFSDK_Annot* pScreen);
57   FX_BOOL DoAction_Link(const CPDF_Action& action, CPDFSDK_Document* pDocument);
58   FX_BOOL DoAction_Field(const CPDF_Action& action,
59                          CPDF_AAction::AActionType type,
60                          CPDFSDK_Document* pDocument,
61                          CPDF_FormField* pFormField,
62                          PDFSDK_FieldAction& data);
63   FX_BOOL DoAction_FieldJavaScript(const CPDF_Action& JsAction,
64                                    CPDF_AAction::AActionType type,
65                                    CPDFSDK_Document* pDocument,
66                                    CPDF_FormField* pFormField,
67                                    PDFSDK_FieldAction& data);
68 
69  private:
70   FX_BOOL ExecuteDocumentOpenAction(const CPDF_Action& action,
71                                     CPDFSDK_Document* pDocument,
72                                     std::set<CPDF_Dictionary*>* visited);
73   FX_BOOL ExecuteDocumentPageAction(const CPDF_Action& action,
74                                     CPDF_AAction::AActionType type,
75                                     CPDFSDK_Document* pDocument,
76                                     std::set<CPDF_Dictionary*>* visited);
77   FX_BOOL ExecuteFieldAction(const CPDF_Action& action,
78                              CPDF_AAction::AActionType type,
79                              CPDFSDK_Document* pDocument,
80                              CPDF_FormField* pFormField,
81                              PDFSDK_FieldAction& data,
82                              std::set<CPDF_Dictionary*>* visited);
83   FX_BOOL ExecuteScreenAction(const CPDF_Action& action,
84                               CPDF_AAction::AActionType type,
85                               CPDFSDK_Document* pDocument,
86                               CPDFSDK_Annot* pScreen,
87                               std::set<CPDF_Dictionary*>* visited);
88   FX_BOOL ExecuteBookMark(const CPDF_Action& action,
89                           CPDFSDK_Document* pDocument,
90                           CPDF_Bookmark* pBookmark,
91                           std::set<CPDF_Dictionary*>* visited);
92   FX_BOOL ExecuteLinkAction(const CPDF_Action& action,
93                             CPDFSDK_Document* pDocument,
94                             std::set<CPDF_Dictionary*>* visited);
95 
96   void DoAction_NoJs(const CPDF_Action& action, CPDFSDK_Document* pDocument);
97   void RunDocumentPageJavaScript(CPDFSDK_Document* pDocument,
98                                  CPDF_AAction::AActionType type,
99                                  const CFX_WideString& script);
100   void RunDocumentOpenJavaScript(CPDFSDK_Document* pDocument,
101                                  const CFX_WideString& sScriptName,
102                                  const CFX_WideString& script);
103   void RunFieldJavaScript(CPDFSDK_Document* pDocument,
104                           CPDF_FormField* pFormField,
105                           CPDF_AAction::AActionType type,
106                           PDFSDK_FieldAction& data,
107                           const CFX_WideString& script);
108 
109   FX_BOOL IsValidField(CPDFSDK_Document* pDocument,
110                        CPDF_Dictionary* pFieldDict);
111   FX_BOOL IsValidDocView(CPDFSDK_Document* pDocument);
112 
113   void DoAction_GoTo(CPDFSDK_Document* pDocument, const CPDF_Action& action);
114   void DoAction_GoToR(CPDFSDK_Document* pDocument, const CPDF_Action& action);
115   void DoAction_Launch(CPDFSDK_Document* pDocument, const CPDF_Action& action);
116   void DoAction_URI(CPDFSDK_Document* pDocument, const CPDF_Action& action);
117   void DoAction_Named(CPDFSDK_Document* pDocument, const CPDF_Action& action);
118   void DoAction_SetOCGState(CPDFSDK_Document* pDocument,
119                             const CPDF_Action& action);
120 
121   std::unique_ptr<CPDFSDK_FormActionHandler> m_pFormActionHandler;
122 };
123 
124 #endif  // FPDFSDK_INCLUDE_FSDK_ACTIONHANDLER_H_
125