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_JAVASCRIPT_IJAVASCRIPT_H_ 8 #define FPDFSDK_INCLUDE_JAVASCRIPT_IJAVASCRIPT_H_ 9 10 #include "core/include/fxcrt/fx_string.h" 11 #include "core/include/fxcrt/fx_system.h" 12 13 #ifdef PDF_ENABLE_XFA 14 #include "xfa/include/fxjse/fxjse.h" 15 #endif // PDF_ENABLE_XFA 16 17 class CPDFDoc_Environment; 18 class CPDFSDK_Annot; 19 class CPDFSDK_Document; 20 class CPDF_Bookmark; 21 class CPDF_FormField; 22 23 // Records the details of an event and triggers JS execution for it. 24 class IJS_Context { 25 public: 26 virtual FX_BOOL RunScript(const CFX_WideString& script, 27 CFX_WideString* info) = 0; 28 29 virtual void OnApp_Init() = 0; 30 31 virtual void OnDoc_Open(CPDFSDK_Document* pDoc, 32 const CFX_WideString& strTargetName) = 0; 33 virtual void OnDoc_WillPrint(CPDFSDK_Document* pDoc) = 0; 34 virtual void OnDoc_DidPrint(CPDFSDK_Document* pDoc) = 0; 35 virtual void OnDoc_WillSave(CPDFSDK_Document* pDoc) = 0; 36 virtual void OnDoc_DidSave(CPDFSDK_Document* pDoc) = 0; 37 virtual void OnDoc_WillClose(CPDFSDK_Document* pDoc) = 0; 38 39 virtual void OnPage_Open(CPDFSDK_Document* pTarget) = 0; 40 virtual void OnPage_Close(CPDFSDK_Document* pTarget) = 0; 41 virtual void OnPage_InView(CPDFSDK_Document* pTarget) = 0; 42 virtual void OnPage_OutView(CPDFSDK_Document* pTarget) = 0; 43 44 virtual void OnField_MouseDown(FX_BOOL bModifier, 45 FX_BOOL bShift, 46 CPDF_FormField* pTarget) = 0; 47 virtual void OnField_MouseEnter(FX_BOOL bModifier, 48 FX_BOOL bShift, 49 CPDF_FormField* pTarget) = 0; 50 virtual void OnField_MouseExit(FX_BOOL bModifier, 51 FX_BOOL bShift, 52 CPDF_FormField* pTarget) = 0; 53 virtual void OnField_MouseUp(FX_BOOL bModifier, 54 FX_BOOL bShift, 55 CPDF_FormField* pTarget) = 0; 56 virtual void OnField_Focus(FX_BOOL bModifier, 57 FX_BOOL bShift, 58 CPDF_FormField* pTarget, 59 const CFX_WideString& Value) = 0; 60 virtual void OnField_Blur(FX_BOOL bModifier, 61 FX_BOOL bShift, 62 CPDF_FormField* pTarget, 63 const CFX_WideString& Value) = 0; 64 65 virtual void OnField_Calculate(CPDF_FormField* pSource, 66 CPDF_FormField* pTarget, 67 CFX_WideString& Value, 68 FX_BOOL& bRc) = 0; 69 virtual void OnField_Format(CPDF_FormField* pTarget, 70 CFX_WideString& Value, 71 FX_BOOL bWillCommit) = 0; 72 virtual void OnField_Keystroke(CFX_WideString& strChange, 73 const CFX_WideString& strChangeEx, 74 FX_BOOL KeyDown, 75 FX_BOOL bModifier, 76 int& nSelEnd, 77 int& nSelStart, 78 FX_BOOL bShift, 79 CPDF_FormField* pTarget, 80 CFX_WideString& Value, 81 FX_BOOL bWillCommit, 82 FX_BOOL bFieldFull, 83 FX_BOOL& bRc) = 0; 84 virtual void OnField_Validate(CFX_WideString& strChange, 85 const CFX_WideString& strChangeEx, 86 FX_BOOL bKeyDown, 87 FX_BOOL bModifier, 88 FX_BOOL bShift, 89 CPDF_FormField* pTarget, 90 CFX_WideString& Value, 91 FX_BOOL& bRc) = 0; 92 93 virtual void OnScreen_Focus(FX_BOOL bModifier, 94 FX_BOOL bShift, 95 CPDFSDK_Annot* pScreen) = 0; 96 virtual void OnScreen_Blur(FX_BOOL bModifier, 97 FX_BOOL bShift, 98 CPDFSDK_Annot* pScreen) = 0; 99 virtual void OnScreen_Open(FX_BOOL bModifier, 100 FX_BOOL bShift, 101 CPDFSDK_Annot* pScreen) = 0; 102 virtual void OnScreen_Close(FX_BOOL bModifier, 103 FX_BOOL bShift, 104 CPDFSDK_Annot* pScreen) = 0; 105 virtual void OnScreen_MouseDown(FX_BOOL bModifier, 106 FX_BOOL bShift, 107 CPDFSDK_Annot* pScreen) = 0; 108 virtual void OnScreen_MouseUp(FX_BOOL bModifier, 109 FX_BOOL bShift, 110 CPDFSDK_Annot* pScreen) = 0; 111 virtual void OnScreen_MouseEnter(FX_BOOL bModifier, 112 FX_BOOL bShift, 113 CPDFSDK_Annot* pScreen) = 0; 114 virtual void OnScreen_MouseExit(FX_BOOL bModifier, 115 FX_BOOL bShift, 116 CPDFSDK_Annot* pScreen) = 0; 117 virtual void OnScreen_InView(FX_BOOL bModifier, 118 FX_BOOL bShift, 119 CPDFSDK_Annot* pScreen) = 0; 120 virtual void OnScreen_OutView(FX_BOOL bModifier, 121 FX_BOOL bShift, 122 CPDFSDK_Annot* pScreen) = 0; 123 124 virtual void OnBookmark_MouseUp(CPDF_Bookmark* pBookMark) = 0; 125 virtual void OnLink_MouseUp(CPDFSDK_Document* pTarget) = 0; 126 127 virtual void OnMenu_Exec(CPDFSDK_Document* pTarget, 128 const CFX_WideString&) = 0; 129 virtual void OnBatchExec(CPDFSDK_Document* pTarget) = 0; 130 virtual void OnConsole_Exec() = 0; 131 virtual void OnExternal_Exec() = 0; 132 133 virtual void EnableMessageBox(FX_BOOL bEnable) = 0; 134 135 protected: ~IJS_Context()136 virtual ~IJS_Context() {} 137 }; 138 139 // Owns the FJXS objects needed to actually execute JS. 140 class IJS_Runtime { 141 public: 142 static void Initialize(unsigned int slot, void* isolate); 143 static IJS_Runtime* Create(CPDFDoc_Environment* pEnv); ~IJS_Runtime()144 virtual ~IJS_Runtime() {} 145 146 virtual IJS_Context* NewContext() = 0; 147 virtual void ReleaseContext(IJS_Context* pContext) = 0; 148 virtual IJS_Context* GetCurrentContext() = 0; 149 virtual void SetReaderDocument(CPDFSDK_Document* pReaderDoc) = 0; 150 virtual CPDFSDK_Document* GetReaderDocument() = 0; 151 virtual int Execute(IJS_Context* cc, 152 const wchar_t* script, 153 CFX_WideString* info) = 0; 154 155 #ifdef PDF_ENABLE_XFA 156 virtual FX_BOOL GetHValueByName(const CFX_ByteStringC& utf8Name, 157 FXJSE_HVALUE hValue) = 0; 158 virtual FX_BOOL SetHValueByName(const CFX_ByteStringC& utf8Name, 159 FXJSE_HVALUE hValue) = 0; 160 #endif // PDF_ENABLE_XFA 161 162 protected: IJS_Runtime()163 IJS_Runtime() {} 164 }; 165 166 #endif // FPDFSDK_INCLUDE_JAVASCRIPT_IJAVASCRIPT_H_ 167