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_CPDFSDK_ACTIONHANDLER_H_ 8 #define FPDFSDK_CPDFSDK_ACTIONHANDLER_H_ 9 10 #include <set> 11 #include <utility> 12 13 #include "core/fpdfdoc/cpdf_aaction.h" 14 #include "core/fpdfdoc/cpdf_action.h" 15 #include "core/fxcrt/fx_string.h" 16 #include "fpdfsdk/cpdfsdk_fieldaction.h" 17 18 class CPDFSDK_Annot; 19 class CPDFSDK_FormFillEnvironment; 20 class CPDF_Dictionary; 21 class CPDF_FormField; 22 class IJS_EventContext; 23 24 class CPDFSDK_ActionHandler { 25 public: 26 bool DoAction_DocOpen(const CPDF_Action& action, 27 CPDFSDK_FormFillEnvironment* pFormFillEnv); 28 bool DoAction_JavaScript(const CPDF_Action& JsAction, 29 WideString csJSName, 30 CPDFSDK_FormFillEnvironment* pFormFillEnv); 31 bool DoAction_Page(const CPDF_Action& action, 32 enum CPDF_AAction::AActionType eType, 33 CPDFSDK_FormFillEnvironment* pFormFillEnv); 34 bool DoAction_Document(const CPDF_Action& action, 35 enum CPDF_AAction::AActionType eType, 36 CPDFSDK_FormFillEnvironment* pFormFillEnv); 37 bool DoAction_Field(const CPDF_Action& action, 38 CPDF_AAction::AActionType type, 39 CPDFSDK_FormFillEnvironment* pFormFillEnv, 40 CPDF_FormField* pFormField, 41 CPDFSDK_FieldAction* data); 42 bool DoAction_FieldJavaScript(const CPDF_Action& JsAction, 43 CPDF_AAction::AActionType type, 44 CPDFSDK_FormFillEnvironment* pFormFillEnv, 45 CPDF_FormField* pFormField, 46 CPDFSDK_FieldAction* data); 47 48 private: 49 using RunScriptCallback = std::function<void(IJS_EventContext* context)>; 50 51 void RunScript(CPDFSDK_FormFillEnvironment* pFormFillEnv, 52 const WideString& script, 53 const RunScriptCallback& cb); 54 55 bool ExecuteDocumentOpenAction(const CPDF_Action& action, 56 CPDFSDK_FormFillEnvironment* pFormFillEnv, 57 std::set<const CPDF_Dictionary*>* visited); 58 bool ExecuteDocumentPageAction(const CPDF_Action& action, 59 CPDF_AAction::AActionType type, 60 CPDFSDK_FormFillEnvironment* pFormFillEnv, 61 std::set<const CPDF_Dictionary*>* visited); 62 bool ExecuteFieldAction(const CPDF_Action& action, 63 CPDF_AAction::AActionType type, 64 CPDFSDK_FormFillEnvironment* pFormFillEnv, 65 CPDF_FormField* pFormField, 66 CPDFSDK_FieldAction* data, 67 std::set<const CPDF_Dictionary*>* visited); 68 69 void DoAction_NoJs(const CPDF_Action& action, 70 CPDF_AAction::AActionType type, 71 CPDFSDK_FormFillEnvironment* pFormFillEnv); 72 void RunDocumentPageJavaScript(CPDFSDK_FormFillEnvironment* pFormFillEnv, 73 CPDF_AAction::AActionType type, 74 const WideString& script); 75 void RunDocumentOpenJavaScript(CPDFSDK_FormFillEnvironment* pFormFillEnv, 76 const WideString& sScriptName, 77 const WideString& script); 78 void RunFieldJavaScript(CPDFSDK_FormFillEnvironment* pFormFillEnv, 79 CPDF_FormField* pFormField, 80 CPDF_AAction::AActionType type, 81 CPDFSDK_FieldAction* data, 82 const WideString& script); 83 84 bool IsValidField(CPDFSDK_FormFillEnvironment* pFormFillEnv, 85 CPDF_Dictionary* pFieldDict); 86 87 void DoAction_GoTo(CPDFSDK_FormFillEnvironment* pFormFillEnv, 88 const CPDF_Action& action); 89 void DoAction_Launch(CPDFSDK_FormFillEnvironment* pFormFillEnv, 90 const CPDF_Action& action); 91 void DoAction_URI(CPDFSDK_FormFillEnvironment* pFormFillEnv, 92 const CPDF_Action& action); 93 void DoAction_Named(CPDFSDK_FormFillEnvironment* pFormFillEnv, 94 const CPDF_Action& action); 95 96 bool DoAction_Hide(const CPDF_Action& action, 97 CPDFSDK_FormFillEnvironment* pFormFillEnv); 98 bool DoAction_SubmitForm(const CPDF_Action& action, 99 CPDFSDK_FormFillEnvironment* pFormFillEnv); 100 void DoAction_ResetForm(const CPDF_Action& action, 101 CPDFSDK_FormFillEnvironment* pFormFillEnv); 102 }; 103 104 #endif // FPDFSDK_CPDFSDK_ACTIONHANDLER_H_ 105