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