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_SRC_JAVASCRIPT_APP_H_ 8 #define FPDFSDK_SRC_JAVASCRIPT_APP_H_ 9 10 #include "JS_Define.h" 11 12 class CJS_Runtime; 13 14 /* ---------------------------- TimerObj ---------------------------- */ 15 16 class CJS_Timer; 17 18 class TimerObj : public CJS_EmbedObj { 19 public: 20 TimerObj(CJS_Object* pJSObject); 21 ~TimerObj() override; 22 23 public: 24 void SetTimer(CJS_Timer* pTimer); 25 CJS_Timer* GetTimer() const; 26 27 private: 28 CJS_Timer* m_pTimer; 29 }; 30 31 class CJS_TimerObj : public CJS_Object { 32 public: 33 CJS_TimerObj(v8::Local<v8::Object> pObject) : CJS_Object(pObject) {} 34 ~CJS_TimerObj() override {} 35 36 DECLARE_JS_CLASS(); 37 }; 38 39 class app : public CJS_EmbedObj { 40 public: 41 app(CJS_Object* pJSObject); 42 ~app() override; 43 44 public: 45 FX_BOOL activeDocs(IJS_Context* cc, 46 CJS_PropValue& vp, 47 CFX_WideString& sError); 48 FX_BOOL calculate(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError); 49 FX_BOOL formsVersion(IJS_Context* cc, 50 CJS_PropValue& vp, 51 CFX_WideString& sError); 52 FX_BOOL fs(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError); 53 FX_BOOL fullscreen(IJS_Context* cc, 54 CJS_PropValue& vp, 55 CFX_WideString& sError); 56 FX_BOOL language(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError); 57 FX_BOOL media(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError); 58 FX_BOOL platform(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError); 59 FX_BOOL runtimeHighlight(IJS_Context* cc, 60 CJS_PropValue& vp, 61 CFX_WideString& sError); 62 FX_BOOL viewerType(IJS_Context* cc, 63 CJS_PropValue& vp, 64 CFX_WideString& sError); 65 FX_BOOL viewerVariation(IJS_Context* cc, 66 CJS_PropValue& vp, 67 CFX_WideString& sError); 68 FX_BOOL viewerVersion(IJS_Context* cc, 69 CJS_PropValue& vp, 70 CFX_WideString& sError); 71 72 FX_BOOL alert(IJS_Context* cc, 73 const std::vector<CJS_Value>& params, 74 CJS_Value& vRet, 75 CFX_WideString& sError); 76 FX_BOOL beep(IJS_Context* cc, 77 const std::vector<CJS_Value>& params, 78 CJS_Value& vRet, 79 CFX_WideString& sError); 80 FX_BOOL browseForDoc(IJS_Context* cc, 81 const std::vector<CJS_Value>& params, 82 CJS_Value& vRet, 83 CFX_WideString& sError); 84 FX_BOOL clearInterval(IJS_Context* cc, 85 const std::vector<CJS_Value>& params, 86 CJS_Value& vRet, 87 CFX_WideString& sError); 88 FX_BOOL clearTimeOut(IJS_Context* cc, 89 const std::vector<CJS_Value>& params, 90 CJS_Value& vRet, 91 CFX_WideString& sError); 92 FX_BOOL execDialog(IJS_Context* cc, 93 const std::vector<CJS_Value>& params, 94 CJS_Value& vRet, 95 CFX_WideString& sError); 96 FX_BOOL execMenuItem(IJS_Context* cc, 97 const std::vector<CJS_Value>& params, 98 CJS_Value& vRet, 99 CFX_WideString& sError); 100 FX_BOOL findComponent(IJS_Context* cc, 101 const std::vector<CJS_Value>& params, 102 CJS_Value& vRet, 103 CFX_WideString& sError); 104 FX_BOOL goBack(IJS_Context* cc, 105 const std::vector<CJS_Value>& params, 106 CJS_Value& vRet, 107 CFX_WideString& sError); 108 FX_BOOL goForward(IJS_Context* cc, 109 const std::vector<CJS_Value>& params, 110 CJS_Value& vRet, 111 CFX_WideString& sError); 112 FX_BOOL launchURL(IJS_Context* cc, 113 const std::vector<CJS_Value>& params, 114 CJS_Value& vRet, 115 CFX_WideString& sError); 116 FX_BOOL mailMsg(IJS_Context* cc, 117 const std::vector<CJS_Value>& params, 118 CJS_Value& vRet, 119 CFX_WideString& sError); 120 FX_BOOL newFDF(IJS_Context* cc, 121 const std::vector<CJS_Value>& params, 122 CJS_Value& vRet, 123 CFX_WideString& sError); 124 FX_BOOL newDoc(IJS_Context* cc, 125 const std::vector<CJS_Value>& params, 126 CJS_Value& vRet, 127 CFX_WideString& sError); 128 FX_BOOL openDoc(IJS_Context* cc, 129 const std::vector<CJS_Value>& params, 130 CJS_Value& vRet, 131 CFX_WideString& sError); 132 FX_BOOL openFDF(IJS_Context* cc, 133 const std::vector<CJS_Value>& params, 134 CJS_Value& vRet, 135 CFX_WideString& sError); 136 FX_BOOL popUpMenuEx(IJS_Context* cc, 137 const std::vector<CJS_Value>& params, 138 CJS_Value& vRet, 139 CFX_WideString& sError); 140 FX_BOOL popUpMenu(IJS_Context* cc, 141 const std::vector<CJS_Value>& params, 142 CJS_Value& vRet, 143 CFX_WideString& sError); 144 FX_BOOL response(IJS_Context* cc, 145 const std::vector<CJS_Value>& params, 146 CJS_Value& vRet, 147 CFX_WideString& sError); 148 FX_BOOL setInterval(IJS_Context* cc, 149 const std::vector<CJS_Value>& params, 150 CJS_Value& vRet, 151 CFX_WideString& sError); 152 FX_BOOL setTimeOut(IJS_Context* cc, 153 const std::vector<CJS_Value>& params, 154 CJS_Value& vRet, 155 CFX_WideString& sError); 156 157 static CFX_WideString SysPathToPDFPath(const CFX_WideString& sOldPath); 158 159 private: 160 // CJS_EmbedObj 161 void TimerProc(CJS_Timer* pTimer) override; 162 void RunJsScript(CJS_Runtime* pRuntime, const CFX_WideString& wsScript); 163 164 bool m_bCalculate; 165 bool m_bRuntimeHighLight; 166 CFX_ArrayTemplate<CJS_Timer*> m_aTimer; 167 }; 168 169 class CJS_App : public CJS_Object { 170 public: 171 explicit CJS_App(v8::Local<v8::Object> pObject) : CJS_Object(pObject) {} 172 ~CJS_App() override {} 173 174 DECLARE_JS_CLASS(); 175 176 JS_STATIC_PROP(activeDocs, app); 177 JS_STATIC_PROP(calculate, app); 178 JS_STATIC_PROP(formsVersion, app); 179 JS_STATIC_PROP(fs, app); 180 JS_STATIC_PROP(fullscreen, app); 181 JS_STATIC_PROP(language, app); 182 JS_STATIC_PROP(media, app); 183 JS_STATIC_PROP(platform, app); 184 JS_STATIC_PROP(runtimeHighlight, app); 185 JS_STATIC_PROP(viewerType, app); 186 JS_STATIC_PROP(viewerVariation, app); 187 JS_STATIC_PROP(viewerVersion, app); 188 189 JS_STATIC_METHOD(alert, app); 190 JS_STATIC_METHOD(beep, app); 191 JS_STATIC_METHOD(browseForDoc, app); 192 JS_STATIC_METHOD(clearInterval, app); 193 JS_STATIC_METHOD(clearTimeOut, app); 194 JS_STATIC_METHOD(execDialog, app); 195 JS_STATIC_METHOD(execMenuItem, app); 196 JS_STATIC_METHOD(findComponent, app); 197 JS_STATIC_METHOD(goBack, app); 198 JS_STATIC_METHOD(goForward, app); 199 JS_STATIC_METHOD(launchURL, app); 200 JS_STATIC_METHOD(mailMsg, app); 201 JS_STATIC_METHOD(newFDF, app); 202 JS_STATIC_METHOD(newDoc, app); 203 JS_STATIC_METHOD(openDoc, app); 204 JS_STATIC_METHOD(openFDF, app); 205 JS_STATIC_METHOD(popUpMenuEx, app); 206 JS_STATIC_METHOD(popUpMenu, app); 207 JS_STATIC_METHOD(response, app); 208 JS_STATIC_METHOD(setInterval, app); 209 JS_STATIC_METHOD(setTimeOut, app); 210 }; 211 212 #endif // FPDFSDK_SRC_JAVASCRIPT_APP_H_ 213