blob: 0567f5a544737b669630c72181d7e32c590b3ebc [file] [log] [blame]
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001// 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.
Tom Sepezc6ab1722015-02-05 15:27:25 -08004
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07005// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
Dan Sinclairf766ad22016-03-14 13:51:24 -04007#include "fpdfsdk/javascript/app.h"
Tom Sepez37458412015-10-06 11:33:46 -07008
Dan Sinclair85c8e7f2016-11-21 13:50:32 -05009#include <map>
Lei Zhangaa8bf7e2015-12-24 19:13:32 -080010#include <memory>
Dan Sinclair3ebd1212016-03-09 09:59:23 -050011#include <vector>
Lei Zhangaa8bf7e2015-12-24 19:13:32 -080012
dsinclair735606d2016-10-05 15:47:02 -070013#include "fpdfsdk/cpdfsdk_formfillenvironment.h"
dsinclair114e46a2016-09-29 17:18:21 -070014#include "fpdfsdk/cpdfsdk_interform.h"
Dan Sinclairf766ad22016-03-14 13:51:24 -040015#include "fpdfsdk/javascript/Document.h"
Dan Sinclairf766ad22016-03-14 13:51:24 -040016#include "fpdfsdk/javascript/JS_Define.h"
17#include "fpdfsdk/javascript/JS_EventHandler.h"
18#include "fpdfsdk/javascript/JS_Object.h"
Dan Sinclairf766ad22016-03-14 13:51:24 -040019#include "fpdfsdk/javascript/JS_Value.h"
Tom Sepezd6ae2af2017-02-16 11:49:55 -080020#include "fpdfsdk/javascript/cjs_event_context.h"
dsinclair64376be2016-03-31 20:03:24 -070021#include "fpdfsdk/javascript/cjs_runtime.h"
Dan Sinclairf766ad22016-03-14 13:51:24 -040022#include "fpdfsdk/javascript/resource.h"
tsepeza752edf2016-08-19 14:57:42 -070023#include "third_party/base/stl_util.h"
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070024
tsepez1c620542016-09-12 09:47:52 -070025class GlobalTimer {
tsepeze3ff76b2016-08-08 11:58:47 -070026 public:
27 GlobalTimer(app* pObj,
dsinclair82e17672016-10-11 12:38:01 -070028 CPDFSDK_FormFillEnvironment* pFormFillEnv,
tsepeze3ff76b2016-08-08 11:58:47 -070029 CJS_Runtime* pRuntime,
30 int nType,
Ryan Harrison275e2602017-09-18 14:23:18 -040031 const WideString& script,
tsepeze3ff76b2016-08-08 11:58:47 -070032 uint32_t dwElapse,
33 uint32_t dwTimeOut);
tsepez8832fbf2016-09-08 10:25:55 -070034 ~GlobalTimer();
tsepeze3ff76b2016-08-08 11:58:47 -070035
36 static void Trigger(int nTimerID);
37 static void Cancel(int nTimerID);
38
39 bool IsOneShot() const { return m_nType == 1; }
40 uint32_t GetTimeOut() const { return m_dwTimeOut; }
41 int GetTimerID() const { return m_nTimerID; }
tsepez1c620542016-09-12 09:47:52 -070042 CJS_Runtime* GetRuntime() const { return m_pRuntime.Get(); }
Ryan Harrison275e2602017-09-18 14:23:18 -040043 WideString GetJScript() const { return m_swJScript; }
tsepeze3ff76b2016-08-08 11:58:47 -070044
45 private:
dsinclair72177da2016-09-15 12:07:23 -070046 using TimerMap = std::map<uint32_t, GlobalTimer*>;
tsepeze3ff76b2016-08-08 11:58:47 -070047 static TimerMap* GetGlobalTimerMap();
48
tsepeze3ff76b2016-08-08 11:58:47 -070049 uint32_t m_nTimerID;
50 app* const m_pEmbedObj;
51 bool m_bProcessing;
tsepeze3ff76b2016-08-08 11:58:47 -070052
53 // data
54 const int m_nType; // 0:Interval; 1:TimeOut
55 const uint32_t m_dwTimeOut;
Ryan Harrison275e2602017-09-18 14:23:18 -040056 const WideString m_swJScript;
tsepez1c620542016-09-12 09:47:52 -070057 CJS_Runtime::ObservedPtr m_pRuntime;
Tom Sepez77f6d0f2017-02-23 12:14:10 -080058 CPDFSDK_FormFillEnvironment::ObservedPtr m_pFormFillEnv;
tsepeze3ff76b2016-08-08 11:58:47 -070059};
60
61GlobalTimer::GlobalTimer(app* pObj,
dsinclair82e17672016-10-11 12:38:01 -070062 CPDFSDK_FormFillEnvironment* pFormFillEnv,
tsepeze3ff76b2016-08-08 11:58:47 -070063 CJS_Runtime* pRuntime,
64 int nType,
Ryan Harrison275e2602017-09-18 14:23:18 -040065 const WideString& script,
tsepeze3ff76b2016-08-08 11:58:47 -070066 uint32_t dwElapse,
67 uint32_t dwTimeOut)
68 : m_nTimerID(0),
69 m_pEmbedObj(pObj),
70 m_bProcessing(false),
tsepeze3ff76b2016-08-08 11:58:47 -070071 m_nType(nType),
72 m_dwTimeOut(dwTimeOut),
73 m_swJScript(script),
74 m_pRuntime(pRuntime),
dsinclair82e17672016-10-11 12:38:01 -070075 m_pFormFillEnv(pFormFillEnv) {
76 CFX_SystemHandler* pHandler = m_pFormFillEnv->GetSysHandler();
tsepeze3ff76b2016-08-08 11:58:47 -070077 m_nTimerID = pHandler->SetTimer(dwElapse, Trigger);
tsepez6cf5eca2017-01-12 11:21:12 -080078 if (m_nTimerID)
79 (*GetGlobalTimerMap())[m_nTimerID] = this;
tsepeze3ff76b2016-08-08 11:58:47 -070080}
81
82GlobalTimer::~GlobalTimer() {
tsepeze3ff76b2016-08-08 11:58:47 -070083 if (!m_nTimerID)
84 return;
85
tsepez8832fbf2016-09-08 10:25:55 -070086 if (GetRuntime())
dsinclair82e17672016-10-11 12:38:01 -070087 m_pFormFillEnv->GetSysHandler()->KillTimer(m_nTimerID);
tsepeze3ff76b2016-08-08 11:58:47 -070088
89 GetGlobalTimerMap()->erase(m_nTimerID);
90}
91
92// static
93void GlobalTimer::Trigger(int nTimerID) {
94 auto it = GetGlobalTimerMap()->find(nTimerID);
95 if (it == GetGlobalTimerMap()->end())
96 return;
97
98 GlobalTimer* pTimer = it->second;
99 if (pTimer->m_bProcessing)
100 return;
101
102 pTimer->m_bProcessing = true;
103 if (pTimer->m_pEmbedObj)
104 pTimer->m_pEmbedObj->TimerProc(pTimer);
105
106 // Timer proc may have destroyed timer, find it again.
107 it = GetGlobalTimerMap()->find(nTimerID);
108 if (it == GetGlobalTimerMap()->end())
109 return;
110
111 pTimer = it->second;
112 pTimer->m_bProcessing = false;
113 if (pTimer->IsOneShot())
114 pTimer->m_pEmbedObj->CancelProc(pTimer);
115}
116
117// static
118void GlobalTimer::Cancel(int nTimerID) {
119 auto it = GetGlobalTimerMap()->find(nTimerID);
120 if (it == GetGlobalTimerMap()->end())
121 return;
122
123 GlobalTimer* pTimer = it->second;
124 pTimer->m_pEmbedObj->CancelProc(pTimer);
125}
126
127// static
128GlobalTimer::TimerMap* GlobalTimer::GetGlobalTimerMap() {
129 // Leak the timer array at shutdown.
130 static auto* s_TimerMap = new TimerMap;
131 return s_TimerMap;
132}
133
Tom Sepez04557b82017-02-16 09:43:10 -0800134JSConstSpec CJS_TimerObj::ConstSpecs[] = {{0, JSConstSpec::Number, 0, 0}};
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700135
Tom Sepez04557b82017-02-16 09:43:10 -0800136JSPropertySpec CJS_TimerObj::PropertySpecs[] = {{0, 0, 0}};
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700137
Tom Sepez04557b82017-02-16 09:43:10 -0800138JSMethodSpec CJS_TimerObj::MethodSpecs[] = {{0, 0}};
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700139
140IMPLEMENT_JS_CLASS(CJS_TimerObj, TimerObj)
141
142TimerObj::TimerObj(CJS_Object* pJSObject)
tsepez8ca63de2016-08-05 17:12:27 -0700143 : CJS_EmbedObj(pJSObject), m_nTimerID(0) {}
Tom Sepezc6ab1722015-02-05 15:27:25 -0800144
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700145TimerObj::~TimerObj() {}
146
tsepeze3ff76b2016-08-08 11:58:47 -0700147void TimerObj::SetTimer(GlobalTimer* pTimer) {
tsepez8ca63de2016-08-05 17:12:27 -0700148 m_nTimerID = pTimer->GetTimerID();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700149}
150
Tom Sepezd6278ba2015-09-08 16:34:37 -0700151#define JS_STR_VIEWERTYPE L"pdfium"
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700152#define JS_STR_VIEWERVARIATION L"Full"
153#define JS_STR_PLATFORM L"WIN"
dsinclairf51e4dc2016-10-13 07:43:19 -0700154#define JS_STR_LANGUAGE L"ENU"
Tom Sepezd6278ba2015-09-08 16:34:37 -0700155#define JS_NUM_VIEWERVERSION 8
Tom Sepez51da0932015-11-25 16:05:49 -0800156#ifdef PDF_ENABLE_XFA
Tom Sepezd6278ba2015-09-08 16:34:37 -0700157#define JS_NUM_VIEWERVERSION_XFA 11
Tom Sepez40e9ff32015-11-30 12:39:54 -0800158#endif // PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700159#define JS_NUM_FORMSVERSION 7
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700160
Tom Sepez04557b82017-02-16 09:43:10 -0800161JSConstSpec CJS_App::ConstSpecs[] = {{0, JSConstSpec::Number, 0, 0}};
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700162
Tom Sepez04557b82017-02-16 09:43:10 -0800163JSPropertySpec CJS_App::PropertySpecs[] = {
dan sinclaircbe23db2017-10-19 14:29:33 -0400164 {"activeDocs", get_active_docs_static, set_active_docs_static},
Tom Sepez4d5b8c52017-02-21 15:17:07 -0800165 {"calculate", get_calculate_static, set_calculate_static},
dan sinclaircbe23db2017-10-19 14:29:33 -0400166 {"formsVersion", get_forms_version_static, set_forms_version_static},
Tom Sepez4d5b8c52017-02-21 15:17:07 -0800167 {"fs", get_fs_static, set_fs_static},
168 {"fullscreen", get_fullscreen_static, set_fullscreen_static},
169 {"language", get_language_static, set_language_static},
170 {"media", get_media_static, set_media_static},
171 {"platform", get_platform_static, set_platform_static},
dan sinclaircbe23db2017-10-19 14:29:33 -0400172 {"runtimeHighlight", get_runtime_highlight_static,
173 set_runtime_highlight_static},
174 {"viewerType", get_viewer_type_static, set_viewer_type_static},
175 {"viewerVariation", get_viewer_variation_static,
176 set_viewer_variation_static},
177 {"viewerVersion", get_viewer_version_static, set_viewer_version_static},
Tom Sepez04557b82017-02-16 09:43:10 -0800178 {0, 0, 0}};
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700179
Tom Sepez9b99b632017-02-21 15:05:57 -0800180JSMethodSpec CJS_App::MethodSpecs[] = {{"alert", alert_static},
181 {"beep", beep_static},
182 {"browseForDoc", browseForDoc_static},
183 {"clearInterval", clearInterval_static},
184 {"clearTimeOut", clearTimeOut_static},
185 {"execDialog", execDialog_static},
186 {"execMenuItem", execMenuItem_static},
187 {"findComponent", findComponent_static},
188 {"goBack", goBack_static},
189 {"goForward", goForward_static},
190 {"launchURL", launchURL_static},
191 {"mailMsg", mailMsg_static},
192 {"newFDF", newFDF_static},
193 {"newDoc", newDoc_static},
194 {"openDoc", openDoc_static},
195 {"openFDF", openFDF_static},
196 {"popUpMenuEx", popUpMenuEx_static},
197 {"popUpMenu", popUpMenu_static},
198 {"response", response_static},
199 {"setInterval", setInterval_static},
200 {"setTimeOut", setTimeOut_static},
Tom Sepez04557b82017-02-16 09:43:10 -0800201 {0, 0}};
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700202
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700203IMPLEMENT_JS_CLASS(CJS_App, app)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700204
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700205app::app(CJS_Object* pJSObject)
206 : CJS_EmbedObj(pJSObject), m_bCalculate(true), m_bRuntimeHighLight(false) {}
207
Lei Zhang2b1a2d52015-08-14 22:16:22 -0700208app::~app() {
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700209}
210
dan sinclaircbe23db2017-10-19 14:29:33 -0400211bool app::get_active_docs(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400212 CJS_Value* vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400213 WideString* sError) {
dsinclair82e17672016-10-11 12:38:01 -0700214 CJS_Document* pJSDocument = nullptr;
215 v8::Local<v8::Object> pObj = pRuntime->GetThisObj();
Tom Sepezc5a14722017-02-24 15:31:12 -0800216 if (CFXJS_Engine::GetObjDefnID(pObj) == CJS_Document::g_nObjDefnID)
dsinclair82e17672016-10-11 12:38:01 -0700217 pJSDocument = static_cast<CJS_Document*>(pRuntime->GetObjectPrivate(pObj));
dsinclair82e17672016-10-11 12:38:01 -0700218
219 CJS_Array aDocs;
220 aDocs.SetElement(pRuntime, 0, CJS_Value(pRuntime, pJSDocument));
tsepezb4694242016-08-15 16:44:55 -0700221 if (aDocs.GetLength(pRuntime) > 0)
Dan Sinclair33d13f22017-10-23 09:44:30 -0400222 vp->Set(pRuntime, aDocs);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700223 else
Dan Sinclair33d13f22017-10-23 09:44:30 -0400224 vp->SetNull(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700225
tsepez4cf55152016-11-02 14:37:54 -0700226 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700227}
228
dan sinclaircbe23db2017-10-19 14:29:33 -0400229bool app::set_active_docs(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400230 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400231 WideString* sError) {
232 return false;
233}
234
235bool app::get_calculate(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400236 CJS_Value* vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400237 WideString* sError) {
Dan Sinclair33d13f22017-10-23 09:44:30 -0400238 vp->Set(pRuntime, m_bCalculate);
tsepez4cf55152016-11-02 14:37:54 -0700239 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700240}
241
dan sinclaircbe23db2017-10-19 14:29:33 -0400242bool app::set_calculate(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400243 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400244 WideString* sError) {
Dan Sinclair33d13f22017-10-23 09:44:30 -0400245 m_bCalculate = vp.ToBool(pRuntime);
dan sinclaircbe23db2017-10-19 14:29:33 -0400246 pRuntime->GetFormFillEnv()->GetInterForm()->EnableCalculate(m_bCalculate);
247 return true;
248}
tsepez4cf55152016-11-02 14:37:54 -0700249
dan sinclaircbe23db2017-10-19 14:29:33 -0400250bool app::get_forms_version(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400251 CJS_Value* vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400252 WideString* sError) {
Dan Sinclair33d13f22017-10-23 09:44:30 -0400253 vp->Set(pRuntime, JS_NUM_FORMSVERSION);
dan sinclaircbe23db2017-10-19 14:29:33 -0400254 return true;
255}
256
257bool app::set_forms_version(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400258 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400259 WideString* sError) {
tsepez4cf55152016-11-02 14:37:54 -0700260 return false;
261}
262
dan sinclaircbe23db2017-10-19 14:29:33 -0400263bool app::get_viewer_type(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400264 CJS_Value* vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400265 WideString* sError) {
Dan Sinclair33d13f22017-10-23 09:44:30 -0400266 vp->Set(pRuntime, JS_STR_VIEWERTYPE);
dan sinclaircbe23db2017-10-19 14:29:33 -0400267 return true;
268}
tsepez4cf55152016-11-02 14:37:54 -0700269
dan sinclaircbe23db2017-10-19 14:29:33 -0400270bool app::set_viewer_type(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400271 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400272 WideString* sError) {
tsepez4cf55152016-11-02 14:37:54 -0700273 return false;
274}
275
dan sinclaircbe23db2017-10-19 14:29:33 -0400276bool app::get_viewer_variation(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400277 CJS_Value* vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400278 WideString* sError) {
Dan Sinclair33d13f22017-10-23 09:44:30 -0400279 vp->Set(pRuntime, JS_STR_VIEWERVARIATION);
dan sinclaircbe23db2017-10-19 14:29:33 -0400280 return true;
281}
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700282
dan sinclaircbe23db2017-10-19 14:29:33 -0400283bool app::set_viewer_variation(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400284 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400285 WideString* sError) {
tsepez4cf55152016-11-02 14:37:54 -0700286 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700287}
288
dan sinclaircbe23db2017-10-19 14:29:33 -0400289bool app::get_viewer_version(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400290 CJS_Value* vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400291 WideString* sError) {
Tom Sepez51da0932015-11-25 16:05:49 -0800292#ifdef PDF_ENABLE_XFA
Tom Sepezb1670b52017-02-16 17:01:00 -0800293 CPDFXFA_Context* pXFAContext = pRuntime->GetFormFillEnv()->GetXFAContext();
Ryan Harrison854d71c2017-10-18 12:28:14 -0400294 if (pXFAContext->ContainsXFAForm()) {
Dan Sinclair33d13f22017-10-23 09:44:30 -0400295 vp->Set(pRuntime, JS_NUM_VIEWERVERSION_XFA);
tsepez4cf55152016-11-02 14:37:54 -0700296 return true;
Tom Sepezbf59a072015-10-21 14:07:23 -0700297 }
Tom Sepez40e9ff32015-11-30 12:39:54 -0800298#endif // PDF_ENABLE_XFA
Dan Sinclair33d13f22017-10-23 09:44:30 -0400299 vp->Set(pRuntime, JS_NUM_VIEWERVERSION);
tsepez4cf55152016-11-02 14:37:54 -0700300 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700301}
302
dan sinclaircbe23db2017-10-19 14:29:33 -0400303bool app::set_viewer_version(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400304 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400305 WideString* sError) {
306 return false;
307}
308
309bool app::get_platform(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400310 CJS_Value* vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400311 WideString* sError) {
Tom Sepez4d6fa832015-12-08 11:31:59 -0800312#ifdef PDF_ENABLE_XFA
Tom Sepezb1670b52017-02-16 17:01:00 -0800313 CPDFSDK_FormFillEnvironment* pFormFillEnv = pRuntime->GetFormFillEnv();
dsinclair82e17672016-10-11 12:38:01 -0700314 if (!pFormFillEnv)
tsepez4cf55152016-11-02 14:37:54 -0700315 return false;
dan sinclaircbe23db2017-10-19 14:29:33 -0400316
Ryan Harrison275e2602017-09-18 14:23:18 -0400317 WideString platfrom = pFormFillEnv->GetPlatform();
Tom Sepez4d6fa832015-12-08 11:31:59 -0800318 if (!platfrom.IsEmpty()) {
Dan Sinclair33d13f22017-10-23 09:44:30 -0400319 vp->Set(pRuntime, platfrom);
tsepez4cf55152016-11-02 14:37:54 -0700320 return true;
Tom Sepez4d6fa832015-12-08 11:31:59 -0800321 }
322#endif
Dan Sinclair33d13f22017-10-23 09:44:30 -0400323 vp->Set(pRuntime, JS_STR_PLATFORM);
tsepez4cf55152016-11-02 14:37:54 -0700324 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700325}
326
dan sinclaircbe23db2017-10-19 14:29:33 -0400327bool app::set_platform(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400328 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400329 WideString* sError) {
330 return false;
331}
332
333bool app::get_language(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400334 CJS_Value* vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400335 WideString* sError) {
Tom Sepez4d6fa832015-12-08 11:31:59 -0800336#ifdef PDF_ENABLE_XFA
Tom Sepezb1670b52017-02-16 17:01:00 -0800337 CPDFSDK_FormFillEnvironment* pFormFillEnv = pRuntime->GetFormFillEnv();
dsinclair82e17672016-10-11 12:38:01 -0700338 if (!pFormFillEnv)
tsepez4cf55152016-11-02 14:37:54 -0700339 return false;
dan sinclaircbe23db2017-10-19 14:29:33 -0400340
Ryan Harrison275e2602017-09-18 14:23:18 -0400341 WideString language = pFormFillEnv->GetLanguage();
Tom Sepez4d6fa832015-12-08 11:31:59 -0800342 if (!language.IsEmpty()) {
Dan Sinclair33d13f22017-10-23 09:44:30 -0400343 vp->Set(pRuntime, language);
tsepez4cf55152016-11-02 14:37:54 -0700344 return true;
Tom Sepez4d6fa832015-12-08 11:31:59 -0800345 }
346#endif
Dan Sinclair33d13f22017-10-23 09:44:30 -0400347 vp->Set(pRuntime, JS_STR_LANGUAGE);
tsepez4cf55152016-11-02 14:37:54 -0700348 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700349}
350
dan sinclaircbe23db2017-10-19 14:29:33 -0400351bool app::set_language(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400352 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400353 WideString* sError) {
354 return false;
355}
356
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700357// creates a new fdf object that contains no data
358// comment: need reader support
359// note:
dsinclair735606d2016-10-05 15:47:02 -0700360// CFDF_Document * CPDFSDK_FormFillEnvironment::NewFDF();
Tom Sepezb1670b52017-02-16 17:01:00 -0800361bool app::newFDF(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700362 const std::vector<CJS_Value>& params,
363 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -0400364 WideString& sError) {
tsepez4cf55152016-11-02 14:37:54 -0700365 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700366}
367// opens a specified pdf document and returns its document object
368// comment:need reader support
369// note: as defined in js reference, the proto of this function's fourth
370// parmeters, how old an fdf document while do not show it.
dsinclair735606d2016-10-05 15:47:02 -0700371// CFDF_Document * CPDFSDK_FormFillEnvironment::OpenFDF(string strPath,bool
372// bUserConv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700373
Tom Sepezb1670b52017-02-16 17:01:00 -0800374bool app::openFDF(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700375 const std::vector<CJS_Value>& params,
376 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -0400377 WideString& sError) {
tsepez4cf55152016-11-02 14:37:54 -0700378 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700379}
380
Tom Sepezb1670b52017-02-16 17:01:00 -0800381bool app::alert(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700382 const std::vector<CJS_Value>& params,
383 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -0400384 WideString& sError) {
Dan Sinclairc9708952017-10-23 09:40:59 -0400385 std::vector<CJS_Value> newParams = ExpandKeywordParams(
Tom Sepezbd932572016-01-29 09:10:41 -0800386 pRuntime, params, 4, L"cMsg", L"nIcon", L"nType", L"cTitle");
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700387
Tom Sepezbd932572016-01-29 09:10:41 -0800388 if (newParams[0].GetType() == CJS_Value::VT_unknown) {
tsepezcd5dc852016-09-08 11:23:24 -0700389 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);
tsepez4cf55152016-11-02 14:37:54 -0700390 return false;
Tom Sepezbd932572016-01-29 09:10:41 -0800391 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700392
dsinclair82e17672016-10-11 12:38:01 -0700393 CPDFSDK_FormFillEnvironment* pFormFillEnv = pRuntime->GetFormFillEnv();
394 if (!pFormFillEnv) {
tsepezf3dc8c62016-08-10 06:29:29 -0700395 vRet = CJS_Value(pRuntime, 0);
tsepez4cf55152016-11-02 14:37:54 -0700396 return true;
tsepeze1e7bd02016-08-08 13:03:16 -0700397 }
398
Ryan Harrison275e2602017-09-18 14:23:18 -0400399 WideString swMsg;
Tom Sepezbd932572016-01-29 09:10:41 -0800400 if (newParams[0].GetType() == CJS_Value::VT_object) {
Dan Sinclairc9708952017-10-23 09:40:59 -0400401 if (newParams[0].IsArrayObject()) {
402 CJS_Array carray = newParams[0].ToArray(pRuntime);
Tom Sepezbd932572016-01-29 09:10:41 -0800403 swMsg = L"[";
tsepezb4694242016-08-15 16:44:55 -0700404 for (int i = 0; i < carray.GetLength(pRuntime); ++i) {
Tom Sepezbd932572016-01-29 09:10:41 -0800405 if (i)
406 swMsg += L", ";
Dan Sinclairc9708952017-10-23 09:40:59 -0400407
408 CJS_Value element(carray.GetElement(pRuntime, i));
409 swMsg += element.ToWideString(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700410 }
Tom Sepezbd932572016-01-29 09:10:41 -0800411 swMsg += L"]";
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700412 } else {
Dan Sinclairc9708952017-10-23 09:40:59 -0400413 swMsg = newParams[0].ToWideString(pRuntime);
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700414 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700415 } else {
Dan Sinclairc9708952017-10-23 09:40:59 -0400416 swMsg = newParams[0].ToWideString(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700417 }
418
Tom Sepezbd932572016-01-29 09:10:41 -0800419 int iIcon = 0;
420 if (newParams[1].GetType() != CJS_Value::VT_unknown)
tsepezb4694242016-08-15 16:44:55 -0700421 iIcon = newParams[1].ToInt(pRuntime);
Tom Sepezbd932572016-01-29 09:10:41 -0800422
423 int iType = 0;
424 if (newParams[2].GetType() != CJS_Value::VT_unknown)
tsepezb4694242016-08-15 16:44:55 -0700425 iType = newParams[2].ToInt(pRuntime);
Tom Sepezbd932572016-01-29 09:10:41 -0800426
Ryan Harrison275e2602017-09-18 14:23:18 -0400427 WideString swTitle;
Tom Sepezbd932572016-01-29 09:10:41 -0800428 if (newParams[3].GetType() != CJS_Value::VT_unknown)
Dan Sinclairc9708952017-10-23 09:40:59 -0400429 swTitle = newParams[3].ToWideString(pRuntime);
Tom Sepezbd932572016-01-29 09:10:41 -0800430 else
tsepezcd5dc852016-09-08 11:23:24 -0700431 swTitle = JSGetStringFromID(IDS_STRING_JSALERT);
Tom Sepezbd932572016-01-29 09:10:41 -0800432
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700433 pRuntime->BeginBlock();
dsinclair7cbe68e2016-10-12 11:56:23 -0700434 pFormFillEnv->KillFocusAnnot(0);
tsepeze1e7bd02016-08-08 13:03:16 -0700435
dsinclair82e17672016-10-11 12:38:01 -0700436 vRet = CJS_Value(pRuntime, pFormFillEnv->JS_appAlert(
437 swMsg.c_str(), swTitle.c_str(), iType, iIcon));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700438 pRuntime->EndBlock();
tsepez4cf55152016-11-02 14:37:54 -0700439 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700440}
441
Tom Sepezb1670b52017-02-16 17:01:00 -0800442bool app::beep(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700443 const std::vector<CJS_Value>& params,
444 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -0400445 WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700446 if (params.size() == 1) {
dsinclair82e17672016-10-11 12:38:01 -0700447 pRuntime->GetFormFillEnv()->JS_appBeep(params[0].ToInt(pRuntime));
tsepez4cf55152016-11-02 14:37:54 -0700448 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700449 }
450
tsepezcd5dc852016-09-08 11:23:24 -0700451 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);
tsepez4cf55152016-11-02 14:37:54 -0700452 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700453}
454
Tom Sepezb1670b52017-02-16 17:01:00 -0800455bool app::findComponent(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700456 const std::vector<CJS_Value>& params,
457 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -0400458 WideString& sError) {
tsepez4cf55152016-11-02 14:37:54 -0700459 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700460}
461
Tom Sepezb1670b52017-02-16 17:01:00 -0800462bool app::popUpMenuEx(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700463 const std::vector<CJS_Value>& params,
464 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -0400465 WideString& sError) {
tsepez4cf55152016-11-02 14:37:54 -0700466 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700467}
468
Dan Sinclair33d13f22017-10-23 09:44:30 -0400469bool app::get_fs(CJS_Runtime* pRuntime, CJS_Value* vp, WideString* sError) {
dan sinclaircbe23db2017-10-19 14:29:33 -0400470 return false;
471}
472
473bool app::set_fs(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400474 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400475 WideString* sError) {
tsepez4cf55152016-11-02 14:37:54 -0700476 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700477}
478
Tom Sepezb1670b52017-02-16 17:01:00 -0800479bool app::setInterval(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700480 const std::vector<CJS_Value>& params,
481 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -0400482 WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700483 if (params.size() > 2 || params.size() == 0) {
tsepezcd5dc852016-09-08 11:23:24 -0700484 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);
tsepez4cf55152016-11-02 14:37:54 -0700485 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700486 }
Tom Sepezc6ab1722015-02-05 15:27:25 -0800487
Ryan Harrison275e2602017-09-18 14:23:18 -0400488 WideString script =
Dan Sinclairc9708952017-10-23 09:40:59 -0400489 params.size() > 0 ? params[0].ToWideString(pRuntime) : L"";
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700490 if (script.IsEmpty()) {
tsepezcd5dc852016-09-08 11:23:24 -0700491 sError = JSGetStringFromID(IDS_STRING_JSAFNUMBER_KEYSTROKE);
tsepez4cf55152016-11-02 14:37:54 -0700492 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700493 }
494
tsepezb4694242016-08-15 16:44:55 -0700495 uint32_t dwInterval = params.size() > 1 ? params[1].ToInt(pRuntime) : 1000;
dsinclair2eb7c7d2016-08-18 09:58:19 -0700496
dsinclair82e17672016-10-11 12:38:01 -0700497 GlobalTimer* timerRef = new GlobalTimer(this, pRuntime->GetFormFillEnv(),
498 pRuntime, 0, script, dwInterval, 0);
tsepeza752edf2016-08-19 14:57:42 -0700499 m_Timers.insert(std::unique_ptr<GlobalTimer>(timerRef));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700500
tsepezb4694242016-08-15 16:44:55 -0700501 v8::Local<v8::Object> pRetObj =
502 pRuntime->NewFxDynamicObj(CJS_TimerObj::g_nObjDefnID);
Tom Sepezc5a14722017-02-24 15:31:12 -0800503 if (pRetObj.IsEmpty())
504 return false;
505
tsepezb4694242016-08-15 16:44:55 -0700506 CJS_TimerObj* pJS_TimerObj =
507 static_cast<CJS_TimerObj*>(pRuntime->GetObjectPrivate(pRetObj));
tsepez41a53ad2016-03-28 16:59:30 -0700508 TimerObj* pTimerObj = static_cast<TimerObj*>(pJS_TimerObj->GetEmbedObject());
dsinclair2eb7c7d2016-08-18 09:58:19 -0700509 pTimerObj->SetTimer(timerRef);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700510
tsepezf3dc8c62016-08-10 06:29:29 -0700511 vRet = CJS_Value(pRuntime, pRetObj);
tsepez4cf55152016-11-02 14:37:54 -0700512 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700513}
514
Tom Sepezb1670b52017-02-16 17:01:00 -0800515bool app::setTimeOut(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700516 const std::vector<CJS_Value>& params,
517 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -0400518 WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700519 if (params.size() > 2 || params.size() == 0) {
tsepezcd5dc852016-09-08 11:23:24 -0700520 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);
tsepez4cf55152016-11-02 14:37:54 -0700521 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700522 }
Tom Sepezc6ab1722015-02-05 15:27:25 -0800523
Dan Sinclairc9708952017-10-23 09:40:59 -0400524 WideString script = params[0].ToWideString(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700525 if (script.IsEmpty()) {
tsepezcd5dc852016-09-08 11:23:24 -0700526 sError = JSGetStringFromID(IDS_STRING_JSAFNUMBER_KEYSTROKE);
tsepez4cf55152016-11-02 14:37:54 -0700527 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700528 }
529
tsepezb4694242016-08-15 16:44:55 -0700530 uint32_t dwTimeOut = params.size() > 1 ? params[1].ToInt(pRuntime) : 1000;
tsepeza752edf2016-08-19 14:57:42 -0700531 GlobalTimer* timerRef =
dsinclair82e17672016-10-11 12:38:01 -0700532 new GlobalTimer(this, pRuntime->GetFormFillEnv(), pRuntime, 1, script,
533 dwTimeOut, dwTimeOut);
tsepeza752edf2016-08-19 14:57:42 -0700534 m_Timers.insert(std::unique_ptr<GlobalTimer>(timerRef));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700535
tsepezb4694242016-08-15 16:44:55 -0700536 v8::Local<v8::Object> pRetObj =
537 pRuntime->NewFxDynamicObj(CJS_TimerObj::g_nObjDefnID);
Tom Sepezc5a14722017-02-24 15:31:12 -0800538 if (pRetObj.IsEmpty())
539 return false;
tsepez41a53ad2016-03-28 16:59:30 -0700540
tsepezb4694242016-08-15 16:44:55 -0700541 CJS_TimerObj* pJS_TimerObj =
542 static_cast<CJS_TimerObj*>(pRuntime->GetObjectPrivate(pRetObj));
tsepez41a53ad2016-03-28 16:59:30 -0700543 TimerObj* pTimerObj = static_cast<TimerObj*>(pJS_TimerObj->GetEmbedObject());
dsinclair2eb7c7d2016-08-18 09:58:19 -0700544 pTimerObj->SetTimer(timerRef);
tsepezf3dc8c62016-08-10 06:29:29 -0700545 vRet = CJS_Value(pRuntime, pRetObj);
tsepez4cf55152016-11-02 14:37:54 -0700546 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700547}
548
Tom Sepezb1670b52017-02-16 17:01:00 -0800549bool app::clearTimeOut(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700550 const std::vector<CJS_Value>& params,
551 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -0400552 WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700553 if (params.size() != 1) {
tsepezcd5dc852016-09-08 11:23:24 -0700554 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);
tsepez4cf55152016-11-02 14:37:54 -0700555 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700556 }
557
Tom Sepezb1670b52017-02-16 17:01:00 -0800558 app::ClearTimerCommon(pRuntime, params[0]);
tsepez4cf55152016-11-02 14:37:54 -0700559 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700560}
561
Tom Sepezb1670b52017-02-16 17:01:00 -0800562bool app::clearInterval(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700563 const std::vector<CJS_Value>& params,
564 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -0400565 WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700566 if (params.size() != 1) {
tsepezcd5dc852016-09-08 11:23:24 -0700567 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);
tsepez4cf55152016-11-02 14:37:54 -0700568 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700569 }
570
Tom Sepezb1670b52017-02-16 17:01:00 -0800571 app::ClearTimerCommon(pRuntime, params[0]);
tsepez4cf55152016-11-02 14:37:54 -0700572 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700573}
574
tsepezb4694242016-08-15 16:44:55 -0700575void app::ClearTimerCommon(CJS_Runtime* pRuntime, const CJS_Value& param) {
tsepez40faa792016-07-15 17:58:02 -0700576 if (param.GetType() != CJS_Value::VT_object)
tsepez41a53ad2016-03-28 16:59:30 -0700577 return;
578
tsepezb4694242016-08-15 16:44:55 -0700579 v8::Local<v8::Object> pObj = param.ToV8Object(pRuntime);
580 if (CFXJS_Engine::GetObjDefnID(pObj) != CJS_TimerObj::g_nObjDefnID)
tsepez41a53ad2016-03-28 16:59:30 -0700581 return;
582
Dan Sinclairc9708952017-10-23 09:40:59 -0400583 CJS_Object* pJSObj = param.ToObject(pRuntime);
tsepez41a53ad2016-03-28 16:59:30 -0700584 if (!pJSObj)
585 return;
586
587 TimerObj* pTimerObj = static_cast<TimerObj*>(pJSObj->GetEmbedObject());
588 if (!pTimerObj)
589 return;
590
tsepeze3ff76b2016-08-08 11:58:47 -0700591 GlobalTimer::Cancel(pTimerObj->GetTimerID());
tsepez41a53ad2016-03-28 16:59:30 -0700592}
593
Tom Sepezb1670b52017-02-16 17:01:00 -0800594bool app::execMenuItem(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700595 const std::vector<CJS_Value>& params,
596 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -0400597 WideString& sError) {
tsepez4cf55152016-11-02 14:37:54 -0700598 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700599}
600
tsepeze3ff76b2016-08-08 11:58:47 -0700601void app::TimerProc(GlobalTimer* pTimer) {
Lei Zhang2d5a0e12015-10-05 17:00:03 -0700602 CJS_Runtime* pRuntime = pTimer->GetRuntime();
tsepez8ca63de2016-08-05 17:12:27 -0700603 if (pRuntime && (!pTimer->IsOneShot() || pTimer->GetTimeOut() > 0))
604 RunJsScript(pRuntime, pTimer->GetJScript());
605}
Lei Zhang2d5a0e12015-10-05 17:00:03 -0700606
tsepeze3ff76b2016-08-08 11:58:47 -0700607void app::CancelProc(GlobalTimer* pTimer) {
tsepeza752edf2016-08-19 14:57:42 -0700608 m_Timers.erase(pdfium::FakeUniquePtr<GlobalTimer>(pTimer));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700609}
610
Ryan Harrison275e2602017-09-18 14:23:18 -0400611void app::RunJsScript(CJS_Runtime* pRuntime, const WideString& wsScript) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700612 if (!pRuntime->IsBlocking()) {
Tom Sepezd6ae2af2017-02-16 11:49:55 -0800613 IJS_EventContext* pContext = pRuntime->NewEventContext();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700614 pContext->OnExternal_Exec();
Ryan Harrison275e2602017-09-18 14:23:18 -0400615 WideString wtInfo;
Tom Sepez33420902015-10-13 15:00:10 -0700616 pContext->RunScript(wsScript, &wtInfo);
Tom Sepezd6ae2af2017-02-16 11:49:55 -0800617 pRuntime->ReleaseEventContext(pContext);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700618 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700619}
620
Tom Sepezb1670b52017-02-16 17:01:00 -0800621bool app::goBack(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700622 const std::vector<CJS_Value>& params,
623 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -0400624 WideString& sError) {
tsepez4cf55152016-11-02 14:37:54 -0700625 // Not supported.
626 return true;
627}
628
Tom Sepezb1670b52017-02-16 17:01:00 -0800629bool app::goForward(CJS_Runtime* pRuntime,
Lei Zhang945fdb72015-11-11 10:18:16 -0800630 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700631 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -0400632 WideString& sError) {
Tom Sepezc6ab1722015-02-05 15:27:25 -0800633 // Not supported.
tsepez4cf55152016-11-02 14:37:54 -0700634 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700635}
636
Tom Sepezb1670b52017-02-16 17:01:00 -0800637bool app::mailMsg(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700638 const std::vector<CJS_Value>& params,
639 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -0400640 WideString& sError) {
Tom Sepeze5fbd7a2016-01-29 17:05:08 -0800641 std::vector<CJS_Value> newParams =
Dan Sinclairc9708952017-10-23 09:40:59 -0400642 ExpandKeywordParams(pRuntime, params, 6, L"bUI", L"cTo", L"cCc", L"cBcc",
643 L"cSubject", L"cMsg");
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700644
Tom Sepeze5fbd7a2016-01-29 17:05:08 -0800645 if (newParams[0].GetType() == CJS_Value::VT_unknown) {
tsepezcd5dc852016-09-08 11:23:24 -0700646 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);
tsepez4cf55152016-11-02 14:37:54 -0700647 return false;
Tom Sepeze5fbd7a2016-01-29 17:05:08 -0800648 }
tsepezb4694242016-08-15 16:44:55 -0700649 bool bUI = newParams[0].ToBool(pRuntime);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700650
Ryan Harrison275e2602017-09-18 14:23:18 -0400651 WideString cTo;
Tom Sepeze5fbd7a2016-01-29 17:05:08 -0800652 if (newParams[1].GetType() != CJS_Value::VT_unknown) {
Dan Sinclairc9708952017-10-23 09:40:59 -0400653 cTo = newParams[1].ToWideString(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700654 } else {
Tom Sepeze5fbd7a2016-01-29 17:05:08 -0800655 if (!bUI) {
656 // cTo parameter required when UI not invoked.
tsepezcd5dc852016-09-08 11:23:24 -0700657 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);
tsepez4cf55152016-11-02 14:37:54 -0700658 return false;
Tom Sepeze5fbd7a2016-01-29 17:05:08 -0800659 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700660 }
Tom Sepezc6ab1722015-02-05 15:27:25 -0800661
Ryan Harrison275e2602017-09-18 14:23:18 -0400662 WideString cCc;
Tom Sepeze5fbd7a2016-01-29 17:05:08 -0800663 if (newParams[2].GetType() != CJS_Value::VT_unknown)
Dan Sinclairc9708952017-10-23 09:40:59 -0400664 cCc = newParams[2].ToWideString(pRuntime);
Tom Sepeze5fbd7a2016-01-29 17:05:08 -0800665
Ryan Harrison275e2602017-09-18 14:23:18 -0400666 WideString cBcc;
Tom Sepeze5fbd7a2016-01-29 17:05:08 -0800667 if (newParams[3].GetType() != CJS_Value::VT_unknown)
Dan Sinclairc9708952017-10-23 09:40:59 -0400668 cBcc = newParams[3].ToWideString(pRuntime);
Tom Sepeze5fbd7a2016-01-29 17:05:08 -0800669
Ryan Harrison275e2602017-09-18 14:23:18 -0400670 WideString cSubject;
Tom Sepeze5fbd7a2016-01-29 17:05:08 -0800671 if (newParams[4].GetType() != CJS_Value::VT_unknown)
Dan Sinclairc9708952017-10-23 09:40:59 -0400672 cSubject = newParams[4].ToWideString(pRuntime);
Tom Sepeze5fbd7a2016-01-29 17:05:08 -0800673
Ryan Harrison275e2602017-09-18 14:23:18 -0400674 WideString cMsg;
Tom Sepeze5fbd7a2016-01-29 17:05:08 -0800675 if (newParams[5].GetType() != CJS_Value::VT_unknown)
Dan Sinclairc9708952017-10-23 09:40:59 -0400676 cMsg = newParams[5].ToWideString(pRuntime);
Tom Sepeze5fbd7a2016-01-29 17:05:08 -0800677
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700678 pRuntime->BeginBlock();
Tom Sepezb1670b52017-02-16 17:01:00 -0800679 pRuntime->GetFormFillEnv()->JS_docmailForm(nullptr, 0, bUI, cTo.c_str(),
dsinclair4526faf2016-10-11 10:54:49 -0700680 cSubject.c_str(), cCc.c_str(),
681 cBcc.c_str(), cMsg.c_str());
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700682 pRuntime->EndBlock();
tsepez4cf55152016-11-02 14:37:54 -0700683 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700684}
685
Tom Sepezb1670b52017-02-16 17:01:00 -0800686bool app::launchURL(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700687 const std::vector<CJS_Value>& params,
688 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -0400689 WideString& sError) {
Tom Sepezc6ab1722015-02-05 15:27:25 -0800690 // Unsafe, not supported.
tsepez4cf55152016-11-02 14:37:54 -0700691 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700692}
693
dan sinclaircbe23db2017-10-19 14:29:33 -0400694bool app::get_runtime_highlight(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400695 CJS_Value* vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400696 WideString* sError) {
Dan Sinclair33d13f22017-10-23 09:44:30 -0400697 vp->Set(pRuntime, m_bRuntimeHighLight);
tsepez4cf55152016-11-02 14:37:54 -0700698 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700699}
700
dan sinclaircbe23db2017-10-19 14:29:33 -0400701bool app::set_runtime_highlight(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400702 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400703 WideString* sError) {
Dan Sinclair33d13f22017-10-23 09:44:30 -0400704 m_bRuntimeHighLight = vp.ToBool(pRuntime);
dan sinclaircbe23db2017-10-19 14:29:33 -0400705 return true;
706}
707
708bool app::get_fullscreen(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400709 CJS_Value* vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400710 WideString* sError) {
711 return false;
712}
713
714bool app::set_fullscreen(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400715 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400716 WideString* sError) {
tsepez4cf55152016-11-02 14:37:54 -0700717 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700718}
719
Tom Sepezb1670b52017-02-16 17:01:00 -0800720bool app::popUpMenu(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700721 const std::vector<CJS_Value>& params,
722 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -0400723 WideString& sError) {
tsepez4cf55152016-11-02 14:37:54 -0700724 return false;
725}
726
Tom Sepezb1670b52017-02-16 17:01:00 -0800727bool app::browseForDoc(CJS_Runtime* pRuntime,
Lei Zhang945fdb72015-11-11 10:18:16 -0800728 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700729 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -0400730 WideString& sError) {
Tom Sepezc6ab1722015-02-05 15:27:25 -0800731 // Unsafe, not supported.
tsepez4cf55152016-11-02 14:37:54 -0700732 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700733}
734
Ryan Harrison275e2602017-09-18 14:23:18 -0400735WideString app::SysPathToPDFPath(const WideString& sOldPath) {
736 WideString sRet = L"/";
Tom Sepez3c3e2712017-04-17 15:38:19 -0700737 for (const wchar_t& c : sOldPath) {
738 if (c != L':')
739 sRet += (c == L'\\') ? L'/' : c;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700740 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700741 return sRet;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700742}
743
Tom Sepezb1670b52017-02-16 17:01:00 -0800744bool app::newDoc(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700745 const std::vector<CJS_Value>& params,
746 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -0400747 WideString& sError) {
tsepez4cf55152016-11-02 14:37:54 -0700748 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700749}
750
Tom Sepezb1670b52017-02-16 17:01:00 -0800751bool app::openDoc(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700752 const std::vector<CJS_Value>& params,
753 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -0400754 WideString& sError) {
tsepez4cf55152016-11-02 14:37:54 -0700755 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700756}
757
Tom Sepezb1670b52017-02-16 17:01:00 -0800758bool app::response(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700759 const std::vector<CJS_Value>& params,
760 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -0400761 WideString& sError) {
Tom Sepez58fb36a2016-02-01 10:32:14 -0800762 std::vector<CJS_Value> newParams =
Dan Sinclairc9708952017-10-23 09:40:59 -0400763 ExpandKeywordParams(pRuntime, params, 5, L"cQuestion", L"cTitle",
764 L"cDefault", L"bPassword", L"cLabel");
Tom Sepez621d4de2014-07-29 14:01:21 -0700765
Tom Sepez58fb36a2016-02-01 10:32:14 -0800766 if (newParams[0].GetType() == CJS_Value::VT_unknown) {
tsepezcd5dc852016-09-08 11:23:24 -0700767 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);
tsepez4cf55152016-11-02 14:37:54 -0700768 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700769 }
Dan Sinclairc9708952017-10-23 09:40:59 -0400770 WideString swQuestion = newParams[0].ToWideString(pRuntime);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700771
Ryan Harrison275e2602017-09-18 14:23:18 -0400772 WideString swTitle = L"PDF";
Tom Sepez58fb36a2016-02-01 10:32:14 -0800773 if (newParams[1].GetType() != CJS_Value::VT_unknown)
Dan Sinclairc9708952017-10-23 09:40:59 -0400774 swTitle = newParams[1].ToWideString(pRuntime);
Tom Sepez58fb36a2016-02-01 10:32:14 -0800775
Ryan Harrison275e2602017-09-18 14:23:18 -0400776 WideString swDefault;
Tom Sepez58fb36a2016-02-01 10:32:14 -0800777 if (newParams[2].GetType() != CJS_Value::VT_unknown)
Dan Sinclairc9708952017-10-23 09:40:59 -0400778 swDefault = newParams[2].ToWideString(pRuntime);
Tom Sepez58fb36a2016-02-01 10:32:14 -0800779
780 bool bPassword = false;
781 if (newParams[3].GetType() != CJS_Value::VT_unknown)
tsepezb4694242016-08-15 16:44:55 -0700782 bPassword = newParams[3].ToBool(pRuntime);
Tom Sepez58fb36a2016-02-01 10:32:14 -0800783
Ryan Harrison275e2602017-09-18 14:23:18 -0400784 WideString swLabel;
Tom Sepez58fb36a2016-02-01 10:32:14 -0800785 if (newParams[4].GetType() != CJS_Value::VT_unknown)
Dan Sinclairc9708952017-10-23 09:40:59 -0400786 swLabel = newParams[4].ToWideString(pRuntime);
Tom Sepez621d4de2014-07-29 14:01:21 -0700787
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700788 const int MAX_INPUT_BYTES = 2048;
Tom Sepezd7188f72017-05-02 15:10:58 -0700789 std::vector<uint8_t> pBuff(MAX_INPUT_BYTES + 2);
Tom Sepezb1670b52017-02-16 17:01:00 -0800790 int nLengthBytes = pRuntime->GetFormFillEnv()->JS_appResponse(
Lei Zhangdb5256f2015-10-02 10:11:43 -0700791 swQuestion.c_str(), swTitle.c_str(), swDefault.c_str(), swLabel.c_str(),
Tom Sepezd7188f72017-05-02 15:10:58 -0700792 bPassword, pBuff.data(), MAX_INPUT_BYTES);
Tom Sepez58fb36a2016-02-01 10:32:14 -0800793
794 if (nLengthBytes < 0 || nLengthBytes > MAX_INPUT_BYTES) {
tsepezcd5dc852016-09-08 11:23:24 -0700795 sError = JSGetStringFromID(IDS_STRING_JSPARAM_TOOLONG);
tsepez4cf55152016-11-02 14:37:54 -0700796 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700797 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700798
Ryan Harrison275e2602017-09-18 14:23:18 -0400799 vRet = CJS_Value(pRuntime, WideString::FromUTF16LE(
Tom Sepezd7188f72017-05-02 15:10:58 -0700800 reinterpret_cast<uint16_t*>(pBuff.data()),
tsepezf3dc8c62016-08-10 06:29:29 -0700801 nLengthBytes / sizeof(uint16_t))
802 .c_str());
803
tsepez4cf55152016-11-02 14:37:54 -0700804 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700805}
806
Dan Sinclair33d13f22017-10-23 09:44:30 -0400807bool app::get_media(CJS_Runtime* pRuntime, CJS_Value* vp, WideString* sError) {
dan sinclaircbe23db2017-10-19 14:29:33 -0400808 return false;
809}
810
811bool app::set_media(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400812 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400813 WideString* sError) {
tsepez4cf55152016-11-02 14:37:54 -0700814 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700815}
816
Tom Sepezb1670b52017-02-16 17:01:00 -0800817bool app::execDialog(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700818 const std::vector<CJS_Value>& params,
819 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -0400820 WideString& sError) {
tsepez4cf55152016-11-02 14:37:54 -0700821 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700822}