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