• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 FXJS_CJS_APP_H_
8 #define FXJS_CJS_APP_H_
9 
10 #include <memory>
11 #include <set>
12 #include <vector>
13 
14 #include "fxjs/JS_Define.h"
15 
16 class CJS_Runtime;
17 class GlobalTimer;
18 
19 class app : public CJS_EmbedObj {
20  public:
21   explicit app(CJS_Object* pJSObject);
22   ~app() override;
23 
24   CJS_Return get_active_docs(CJS_Runtime* pRuntime);
25   CJS_Return set_active_docs(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp);
26 
27   CJS_Return get_calculate(CJS_Runtime* pRuntime);
28   CJS_Return set_calculate(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp);
29 
30   CJS_Return get_forms_version(CJS_Runtime* pRuntime);
31   CJS_Return set_forms_version(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp);
32 
33   CJS_Return get_fs(CJS_Runtime* pRuntime);
34   CJS_Return set_fs(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp);
35 
36   CJS_Return get_fullscreen(CJS_Runtime* pRuntime);
37   CJS_Return set_fullscreen(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp);
38 
39   CJS_Return get_language(CJS_Runtime* pRuntime);
40   CJS_Return set_language(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp);
41 
42   CJS_Return get_media(CJS_Runtime* pRuntime);
43   CJS_Return set_media(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp);
44 
45   CJS_Return get_platform(CJS_Runtime* pRuntime);
46   CJS_Return set_platform(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp);
47 
48   CJS_Return get_runtime_highlight(CJS_Runtime* pRuntime);
49   CJS_Return set_runtime_highlight(CJS_Runtime* pRuntime,
50                                    v8::Local<v8::Value> vp);
51 
52   CJS_Return get_viewer_type(CJS_Runtime* pRuntime);
53   CJS_Return set_viewer_type(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp);
54 
55   CJS_Return get_viewer_variation(CJS_Runtime* pRuntime);
56   CJS_Return set_viewer_variation(CJS_Runtime* pRuntime,
57                                   v8::Local<v8::Value> vp);
58 
59   CJS_Return get_viewer_version(CJS_Runtime* pRuntime);
60   CJS_Return set_viewer_version(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp);
61 
62   CJS_Return alert(CJS_Runtime* pRuntime,
63                    const std::vector<v8::Local<v8::Value>>& params);
64   CJS_Return beep(CJS_Runtime* pRuntime,
65                   const std::vector<v8::Local<v8::Value>>& params);
66   CJS_Return browseForDoc(CJS_Runtime* pRuntime,
67                           const std::vector<v8::Local<v8::Value>>& params);
68   CJS_Return clearInterval(CJS_Runtime* pRuntime,
69                            const std::vector<v8::Local<v8::Value>>& params);
70   CJS_Return clearTimeOut(CJS_Runtime* pRuntime,
71                           const std::vector<v8::Local<v8::Value>>& params);
72   CJS_Return execDialog(CJS_Runtime* pRuntime,
73                         const std::vector<v8::Local<v8::Value>>& params);
74   CJS_Return execMenuItem(CJS_Runtime* pRuntime,
75                           const std::vector<v8::Local<v8::Value>>& params);
76   CJS_Return findComponent(CJS_Runtime* pRuntime,
77                            const std::vector<v8::Local<v8::Value>>& params);
78   CJS_Return goBack(CJS_Runtime* pRuntime,
79                     const std::vector<v8::Local<v8::Value>>& params);
80   CJS_Return goForward(CJS_Runtime* pRuntime,
81                        const std::vector<v8::Local<v8::Value>>& params);
82   CJS_Return launchURL(CJS_Runtime* pRuntime,
83                        const std::vector<v8::Local<v8::Value>>& params);
84   CJS_Return mailMsg(CJS_Runtime* pRuntime,
85                      const std::vector<v8::Local<v8::Value>>& params);
86   CJS_Return newFDF(CJS_Runtime* pRuntime,
87                     const std::vector<v8::Local<v8::Value>>& params);
88   CJS_Return newDoc(CJS_Runtime* pRuntime,
89                     const std::vector<v8::Local<v8::Value>>& params);
90   CJS_Return openDoc(CJS_Runtime* pRuntime,
91                      const std::vector<v8::Local<v8::Value>>& params);
92   CJS_Return openFDF(CJS_Runtime* pRuntime,
93                      const std::vector<v8::Local<v8::Value>>& params);
94   CJS_Return popUpMenuEx(CJS_Runtime* pRuntime,
95                          const std::vector<v8::Local<v8::Value>>& params);
96   CJS_Return popUpMenu(CJS_Runtime* pRuntime,
97                        const std::vector<v8::Local<v8::Value>>& params);
98   CJS_Return response(CJS_Runtime* pRuntime,
99                       const std::vector<v8::Local<v8::Value>>& params);
100   CJS_Return setInterval(CJS_Runtime* pRuntime,
101                          const std::vector<v8::Local<v8::Value>>& params);
102   CJS_Return setTimeOut(CJS_Runtime* pRuntime,
103                         const std::vector<v8::Local<v8::Value>>& params);
104 
105   void TimerProc(GlobalTimer* pTimer);
106   void CancelProc(GlobalTimer* pTimer);
107 
108   static WideString SysPathToPDFPath(const WideString& sOldPath);
109 
110  private:
111   // CJS_EmbedObj
112   void RunJsScript(CJS_Runtime* pRuntime, const WideString& wsScript);
113 
114   void ClearTimerCommon(CJS_Runtime* pRuntime, v8::Local<v8::Value> param);
115 
116   bool m_bCalculate;
117   bool m_bRuntimeHighLight;
118   std::set<std::unique_ptr<GlobalTimer>> m_Timers;
119 };
120 
121 class CJS_App : public CJS_Object {
122  public:
123   static void DefineJSObjects(CFXJS_Engine* pEngine);
124 
CJS_App(v8::Local<v8::Object> pObject)125   explicit CJS_App(v8::Local<v8::Object> pObject) : CJS_Object(pObject) {}
~CJS_App()126   ~CJS_App() override {}
127 
128   JS_STATIC_PROP(activeDocs, active_docs, app);
129   JS_STATIC_PROP(calculate, calculate, app);
130   JS_STATIC_PROP(formsVersion, forms_version, app);
131   JS_STATIC_PROP(fs, fs, app);
132   JS_STATIC_PROP(fullscreen, fullscreen, app);
133   JS_STATIC_PROP(language, language, app);
134   JS_STATIC_PROP(media, media, app);
135   JS_STATIC_PROP(platform, platform, app);
136   JS_STATIC_PROP(runtimeHighlight, runtime_highlight, app);
137   JS_STATIC_PROP(viewerType, viewer_type, app);
138   JS_STATIC_PROP(viewerVariation, viewer_variation, app);
139   JS_STATIC_PROP(viewerVersion, viewer_version, app);
140 
141   JS_STATIC_METHOD(alert, app);
142   JS_STATIC_METHOD(beep, app);
143   JS_STATIC_METHOD(browseForDoc, app);
144   JS_STATIC_METHOD(clearInterval, app);
145   JS_STATIC_METHOD(clearTimeOut, app);
146   JS_STATIC_METHOD(execDialog, app);
147   JS_STATIC_METHOD(execMenuItem, app);
148   JS_STATIC_METHOD(findComponent, app);
149   JS_STATIC_METHOD(goBack, app);
150   JS_STATIC_METHOD(goForward, app);
151   JS_STATIC_METHOD(launchURL, app);
152   JS_STATIC_METHOD(mailMsg, app);
153   JS_STATIC_METHOD(newFDF, app);
154   JS_STATIC_METHOD(newDoc, app);
155   JS_STATIC_METHOD(openDoc, app);
156   JS_STATIC_METHOD(openFDF, app);
157   JS_STATIC_METHOD(popUpMenuEx, app);
158   JS_STATIC_METHOD(popUpMenu, app);
159   JS_STATIC_METHOD(response, app);
160   JS_STATIC_METHOD(setInterval, app);
161   JS_STATIC_METHOD(setTimeOut, app);
162 
163  private:
164   static int ObjDefnID;
165   static const JSPropertySpec PropertySpecs[];
166   static const JSMethodSpec MethodSpecs[];
167 };
168 
169 #endif  // FXJS_CJS_APP_H_
170