blob: 7203c3bfa676d30ef93e3fa8ab0162e22a7f407d [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
Dan Sinclair4b172c42017-10-23 11:22:31 -0400140IMPLEMENT_JS_CLASS(CJS_TimerObj, TimerObj, TimerObj)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700141
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
Dan Sinclair4b172c42017-10-23 11:22:31 -0400203IMPLEMENT_JS_CLASS(CJS_App, 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;
Dan Sinclair1d8d9ac2017-10-24 11:23:25 -0400220 aDocs.SetElement(
221 pRuntime, 0,
222 pJSDocument ? CJS_Value(pJSDocument->ToV8Object()) : CJS_Value());
tsepezb4694242016-08-15 16:44:55 -0700223 if (aDocs.GetLength(pRuntime) > 0)
Dan Sinclaire4974922017-10-24 09:36:16 -0400224 vp->Set(aDocs.ToV8Array(pRuntime));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700225 else
Dan Sinclaire4974922017-10-24 09:36:16 -0400226 vp->Set(pRuntime->NewNull());
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700227
tsepez4cf55152016-11-02 14:37:54 -0700228 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700229}
230
dan sinclaircbe23db2017-10-19 14:29:33 -0400231bool app::set_active_docs(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400232 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400233 WideString* sError) {
234 return false;
235}
236
237bool app::get_calculate(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400238 CJS_Value* vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400239 WideString* sError) {
Dan Sinclaire4974922017-10-24 09:36:16 -0400240 vp->Set(pRuntime->NewBoolean(m_bCalculate));
tsepez4cf55152016-11-02 14:37:54 -0700241 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700242}
243
dan sinclaircbe23db2017-10-19 14:29:33 -0400244bool app::set_calculate(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400245 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400246 WideString* sError) {
Dan Sinclair33d13f22017-10-23 09:44:30 -0400247 m_bCalculate = vp.ToBool(pRuntime);
dan sinclaircbe23db2017-10-19 14:29:33 -0400248 pRuntime->GetFormFillEnv()->GetInterForm()->EnableCalculate(m_bCalculate);
249 return true;
250}
tsepez4cf55152016-11-02 14:37:54 -0700251
dan sinclaircbe23db2017-10-19 14:29:33 -0400252bool app::get_forms_version(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400253 CJS_Value* vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400254 WideString* sError) {
Dan Sinclaire4974922017-10-24 09:36:16 -0400255 vp->Set(pRuntime->NewNumber(JS_NUM_FORMSVERSION));
dan sinclaircbe23db2017-10-19 14:29:33 -0400256 return true;
257}
258
259bool app::set_forms_version(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400260 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400261 WideString* sError) {
tsepez4cf55152016-11-02 14:37:54 -0700262 return false;
263}
264
dan sinclaircbe23db2017-10-19 14:29:33 -0400265bool app::get_viewer_type(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400266 CJS_Value* vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400267 WideString* sError) {
Dan Sinclaire4974922017-10-24 09:36:16 -0400268 vp->Set(pRuntime->NewString(JS_STR_VIEWERTYPE));
dan sinclaircbe23db2017-10-19 14:29:33 -0400269 return true;
270}
tsepez4cf55152016-11-02 14:37:54 -0700271
dan sinclaircbe23db2017-10-19 14:29:33 -0400272bool app::set_viewer_type(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400273 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400274 WideString* sError) {
tsepez4cf55152016-11-02 14:37:54 -0700275 return false;
276}
277
dan sinclaircbe23db2017-10-19 14:29:33 -0400278bool app::get_viewer_variation(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400279 CJS_Value* vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400280 WideString* sError) {
Dan Sinclaire4974922017-10-24 09:36:16 -0400281 vp->Set(pRuntime->NewString(JS_STR_VIEWERVARIATION));
dan sinclaircbe23db2017-10-19 14:29:33 -0400282 return true;
283}
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700284
dan sinclaircbe23db2017-10-19 14:29:33 -0400285bool app::set_viewer_variation(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400286 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400287 WideString* sError) {
tsepez4cf55152016-11-02 14:37:54 -0700288 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700289}
290
dan sinclaircbe23db2017-10-19 14:29:33 -0400291bool app::get_viewer_version(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400292 CJS_Value* vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400293 WideString* sError) {
Tom Sepez51da0932015-11-25 16:05:49 -0800294#ifdef PDF_ENABLE_XFA
Tom Sepezb1670b52017-02-16 17:01:00 -0800295 CPDFXFA_Context* pXFAContext = pRuntime->GetFormFillEnv()->GetXFAContext();
Ryan Harrison854d71c2017-10-18 12:28:14 -0400296 if (pXFAContext->ContainsXFAForm()) {
Dan Sinclaire4974922017-10-24 09:36:16 -0400297 vp->Set(pRuntime->NewNumber(JS_NUM_VIEWERVERSION_XFA));
tsepez4cf55152016-11-02 14:37:54 -0700298 return true;
Tom Sepezbf59a072015-10-21 14:07:23 -0700299 }
Tom Sepez40e9ff32015-11-30 12:39:54 -0800300#endif // PDF_ENABLE_XFA
Dan Sinclaire4974922017-10-24 09:36:16 -0400301 vp->Set(pRuntime->NewNumber(JS_NUM_VIEWERVERSION));
tsepez4cf55152016-11-02 14:37:54 -0700302 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700303}
304
dan sinclaircbe23db2017-10-19 14:29:33 -0400305bool app::set_viewer_version(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400306 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400307 WideString* sError) {
308 return false;
309}
310
311bool app::get_platform(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400312 CJS_Value* vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400313 WideString* sError) {
Tom Sepez4d6fa832015-12-08 11:31:59 -0800314#ifdef PDF_ENABLE_XFA
Tom Sepezb1670b52017-02-16 17:01:00 -0800315 CPDFSDK_FormFillEnvironment* pFormFillEnv = pRuntime->GetFormFillEnv();
dsinclair82e17672016-10-11 12:38:01 -0700316 if (!pFormFillEnv)
tsepez4cf55152016-11-02 14:37:54 -0700317 return false;
dan sinclaircbe23db2017-10-19 14:29:33 -0400318
Ryan Harrison275e2602017-09-18 14:23:18 -0400319 WideString platfrom = pFormFillEnv->GetPlatform();
Tom Sepez4d6fa832015-12-08 11:31:59 -0800320 if (!platfrom.IsEmpty()) {
Dan Sinclaire4974922017-10-24 09:36:16 -0400321 vp->Set(pRuntime->NewString(platfrom.c_str()));
tsepez4cf55152016-11-02 14:37:54 -0700322 return true;
Tom Sepez4d6fa832015-12-08 11:31:59 -0800323 }
324#endif
Dan Sinclaire4974922017-10-24 09:36:16 -0400325 vp->Set(pRuntime->NewString(JS_STR_PLATFORM));
tsepez4cf55152016-11-02 14:37:54 -0700326 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700327}
328
dan sinclaircbe23db2017-10-19 14:29:33 -0400329bool app::set_platform(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400330 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400331 WideString* sError) {
332 return false;
333}
334
335bool app::get_language(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400336 CJS_Value* vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400337 WideString* sError) {
Tom Sepez4d6fa832015-12-08 11:31:59 -0800338#ifdef PDF_ENABLE_XFA
Tom Sepezb1670b52017-02-16 17:01:00 -0800339 CPDFSDK_FormFillEnvironment* pFormFillEnv = pRuntime->GetFormFillEnv();
dsinclair82e17672016-10-11 12:38:01 -0700340 if (!pFormFillEnv)
tsepez4cf55152016-11-02 14:37:54 -0700341 return false;
dan sinclaircbe23db2017-10-19 14:29:33 -0400342
Ryan Harrison275e2602017-09-18 14:23:18 -0400343 WideString language = pFormFillEnv->GetLanguage();
Tom Sepez4d6fa832015-12-08 11:31:59 -0800344 if (!language.IsEmpty()) {
Dan Sinclaire4974922017-10-24 09:36:16 -0400345 vp->Set(pRuntime->NewString(language.c_str()));
tsepez4cf55152016-11-02 14:37:54 -0700346 return true;
Tom Sepez4d6fa832015-12-08 11:31:59 -0800347 }
348#endif
Dan Sinclaire4974922017-10-24 09:36:16 -0400349 vp->Set(pRuntime->NewString(JS_STR_LANGUAGE));
tsepez4cf55152016-11-02 14:37:54 -0700350 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700351}
352
dan sinclaircbe23db2017-10-19 14:29:33 -0400353bool app::set_language(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400354 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400355 WideString* sError) {
356 return false;
357}
358
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700359// creates a new fdf object that contains no data
360// comment: need reader support
361// note:
dsinclair735606d2016-10-05 15:47:02 -0700362// CFDF_Document * CPDFSDK_FormFillEnvironment::NewFDF();
Tom Sepezb1670b52017-02-16 17:01:00 -0800363bool app::newFDF(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700364 const std::vector<CJS_Value>& params,
365 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -0400366 WideString& sError) {
tsepez4cf55152016-11-02 14:37:54 -0700367 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700368}
369// opens a specified pdf document and returns its document object
370// comment:need reader support
371// note: as defined in js reference, the proto of this function's fourth
372// parmeters, how old an fdf document while do not show it.
dsinclair735606d2016-10-05 15:47:02 -0700373// CFDF_Document * CPDFSDK_FormFillEnvironment::OpenFDF(string strPath,bool
374// bUserConv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700375
Tom Sepezb1670b52017-02-16 17:01:00 -0800376bool app::openFDF(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700377 const std::vector<CJS_Value>& params,
378 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -0400379 WideString& sError) {
tsepez4cf55152016-11-02 14:37:54 -0700380 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700381}
382
Tom Sepezb1670b52017-02-16 17:01:00 -0800383bool app::alert(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700384 const std::vector<CJS_Value>& params,
385 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -0400386 WideString& sError) {
Dan Sinclairc9708952017-10-23 09:40:59 -0400387 std::vector<CJS_Value> newParams = ExpandKeywordParams(
Tom Sepezbd932572016-01-29 09:10:41 -0800388 pRuntime, params, 4, L"cMsg", L"nIcon", L"nType", L"cTitle");
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700389
Tom Sepezbd932572016-01-29 09:10:41 -0800390 if (newParams[0].GetType() == CJS_Value::VT_unknown) {
tsepezcd5dc852016-09-08 11:23:24 -0700391 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);
tsepez4cf55152016-11-02 14:37:54 -0700392 return false;
Tom Sepezbd932572016-01-29 09:10:41 -0800393 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700394
dsinclair82e17672016-10-11 12:38:01 -0700395 CPDFSDK_FormFillEnvironment* pFormFillEnv = pRuntime->GetFormFillEnv();
396 if (!pFormFillEnv) {
Dan Sinclair1d8d9ac2017-10-24 11:23:25 -0400397 vRet = CJS_Value(pRuntime->NewNumber(0));
tsepez4cf55152016-11-02 14:37:54 -0700398 return true;
tsepeze1e7bd02016-08-08 13:03:16 -0700399 }
400
Ryan Harrison275e2602017-09-18 14:23:18 -0400401 WideString swMsg;
Tom Sepezbd932572016-01-29 09:10:41 -0800402 if (newParams[0].GetType() == CJS_Value::VT_object) {
Dan Sinclairc9708952017-10-23 09:40:59 -0400403 if (newParams[0].IsArrayObject()) {
404 CJS_Array carray = newParams[0].ToArray(pRuntime);
Tom Sepezbd932572016-01-29 09:10:41 -0800405 swMsg = L"[";
tsepezb4694242016-08-15 16:44:55 -0700406 for (int i = 0; i < carray.GetLength(pRuntime); ++i) {
Tom Sepezbd932572016-01-29 09:10:41 -0800407 if (i)
408 swMsg += L", ";
Dan Sinclairc9708952017-10-23 09:40:59 -0400409
410 CJS_Value element(carray.GetElement(pRuntime, i));
411 swMsg += element.ToWideString(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700412 }
Tom Sepezbd932572016-01-29 09:10:41 -0800413 swMsg += L"]";
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700414 } else {
Dan Sinclairc9708952017-10-23 09:40:59 -0400415 swMsg = newParams[0].ToWideString(pRuntime);
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700416 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700417 } else {
Dan Sinclairc9708952017-10-23 09:40:59 -0400418 swMsg = newParams[0].ToWideString(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700419 }
420
Tom Sepezbd932572016-01-29 09:10:41 -0800421 int iIcon = 0;
422 if (newParams[1].GetType() != CJS_Value::VT_unknown)
tsepezb4694242016-08-15 16:44:55 -0700423 iIcon = newParams[1].ToInt(pRuntime);
Tom Sepezbd932572016-01-29 09:10:41 -0800424
425 int iType = 0;
426 if (newParams[2].GetType() != CJS_Value::VT_unknown)
tsepezb4694242016-08-15 16:44:55 -0700427 iType = newParams[2].ToInt(pRuntime);
Tom Sepezbd932572016-01-29 09:10:41 -0800428
Ryan Harrison275e2602017-09-18 14:23:18 -0400429 WideString swTitle;
Tom Sepezbd932572016-01-29 09:10:41 -0800430 if (newParams[3].GetType() != CJS_Value::VT_unknown)
Dan Sinclairc9708952017-10-23 09:40:59 -0400431 swTitle = newParams[3].ToWideString(pRuntime);
Tom Sepezbd932572016-01-29 09:10:41 -0800432 else
tsepezcd5dc852016-09-08 11:23:24 -0700433 swTitle = JSGetStringFromID(IDS_STRING_JSALERT);
Tom Sepezbd932572016-01-29 09:10:41 -0800434
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700435 pRuntime->BeginBlock();
dsinclair7cbe68e2016-10-12 11:56:23 -0700436 pFormFillEnv->KillFocusAnnot(0);
tsepeze1e7bd02016-08-08 13:03:16 -0700437
Dan Sinclair1d8d9ac2017-10-24 11:23:25 -0400438 vRet = CJS_Value(pRuntime->NewNumber(
439 pFormFillEnv->JS_appAlert(swMsg.c_str(), swTitle.c_str(), iType, iIcon)));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700440 pRuntime->EndBlock();
tsepez4cf55152016-11-02 14:37:54 -0700441 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700442}
443
Tom Sepezb1670b52017-02-16 17:01:00 -0800444bool app::beep(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700445 const std::vector<CJS_Value>& params,
446 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -0400447 WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700448 if (params.size() == 1) {
dsinclair82e17672016-10-11 12:38:01 -0700449 pRuntime->GetFormFillEnv()->JS_appBeep(params[0].ToInt(pRuntime));
tsepez4cf55152016-11-02 14:37:54 -0700450 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700451 }
452
tsepezcd5dc852016-09-08 11:23:24 -0700453 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);
tsepez4cf55152016-11-02 14:37:54 -0700454 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700455}
456
Tom Sepezb1670b52017-02-16 17:01:00 -0800457bool app::findComponent(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700458 const std::vector<CJS_Value>& params,
459 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -0400460 WideString& sError) {
tsepez4cf55152016-11-02 14:37:54 -0700461 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700462}
463
Tom Sepezb1670b52017-02-16 17:01:00 -0800464bool app::popUpMenuEx(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700465 const std::vector<CJS_Value>& params,
466 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -0400467 WideString& sError) {
tsepez4cf55152016-11-02 14:37:54 -0700468 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700469}
470
Dan Sinclair33d13f22017-10-23 09:44:30 -0400471bool app::get_fs(CJS_Runtime* pRuntime, CJS_Value* vp, WideString* sError) {
dan sinclaircbe23db2017-10-19 14:29:33 -0400472 return false;
473}
474
475bool app::set_fs(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400476 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400477 WideString* sError) {
tsepez4cf55152016-11-02 14:37:54 -0700478 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700479}
480
Tom Sepezb1670b52017-02-16 17:01:00 -0800481bool app::setInterval(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700482 const std::vector<CJS_Value>& params,
483 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -0400484 WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700485 if (params.size() > 2 || params.size() == 0) {
tsepezcd5dc852016-09-08 11:23:24 -0700486 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);
tsepez4cf55152016-11-02 14:37:54 -0700487 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700488 }
Tom Sepezc6ab1722015-02-05 15:27:25 -0800489
Ryan Harrison275e2602017-09-18 14:23:18 -0400490 WideString script =
Dan Sinclairc9708952017-10-23 09:40:59 -0400491 params.size() > 0 ? params[0].ToWideString(pRuntime) : L"";
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700492 if (script.IsEmpty()) {
tsepezcd5dc852016-09-08 11:23:24 -0700493 sError = JSGetStringFromID(IDS_STRING_JSAFNUMBER_KEYSTROKE);
tsepez4cf55152016-11-02 14:37:54 -0700494 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700495 }
496
tsepezb4694242016-08-15 16:44:55 -0700497 uint32_t dwInterval = params.size() > 1 ? params[1].ToInt(pRuntime) : 1000;
dsinclair2eb7c7d2016-08-18 09:58:19 -0700498
dsinclair82e17672016-10-11 12:38:01 -0700499 GlobalTimer* timerRef = new GlobalTimer(this, pRuntime->GetFormFillEnv(),
500 pRuntime, 0, script, dwInterval, 0);
tsepeza752edf2016-08-19 14:57:42 -0700501 m_Timers.insert(std::unique_ptr<GlobalTimer>(timerRef));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700502
tsepezb4694242016-08-15 16:44:55 -0700503 v8::Local<v8::Object> pRetObj =
504 pRuntime->NewFxDynamicObj(CJS_TimerObj::g_nObjDefnID);
Tom Sepezc5a14722017-02-24 15:31:12 -0800505 if (pRetObj.IsEmpty())
506 return false;
507
tsepezb4694242016-08-15 16:44:55 -0700508 CJS_TimerObj* pJS_TimerObj =
509 static_cast<CJS_TimerObj*>(pRuntime->GetObjectPrivate(pRetObj));
tsepez41a53ad2016-03-28 16:59:30 -0700510 TimerObj* pTimerObj = static_cast<TimerObj*>(pJS_TimerObj->GetEmbedObject());
dsinclair2eb7c7d2016-08-18 09:58:19 -0700511 pTimerObj->SetTimer(timerRef);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700512
Dan Sinclaire4974922017-10-24 09:36:16 -0400513 vRet = CJS_Value(pRetObj);
tsepez4cf55152016-11-02 14:37:54 -0700514 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700515}
516
Tom Sepezb1670b52017-02-16 17:01:00 -0800517bool app::setTimeOut(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700518 const std::vector<CJS_Value>& params,
519 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -0400520 WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700521 if (params.size() > 2 || params.size() == 0) {
tsepezcd5dc852016-09-08 11:23:24 -0700522 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);
tsepez4cf55152016-11-02 14:37:54 -0700523 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700524 }
Tom Sepezc6ab1722015-02-05 15:27:25 -0800525
Dan Sinclairc9708952017-10-23 09:40:59 -0400526 WideString script = params[0].ToWideString(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700527 if (script.IsEmpty()) {
tsepezcd5dc852016-09-08 11:23:24 -0700528 sError = JSGetStringFromID(IDS_STRING_JSAFNUMBER_KEYSTROKE);
tsepez4cf55152016-11-02 14:37:54 -0700529 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700530 }
531
tsepezb4694242016-08-15 16:44:55 -0700532 uint32_t dwTimeOut = params.size() > 1 ? params[1].ToInt(pRuntime) : 1000;
tsepeza752edf2016-08-19 14:57:42 -0700533 GlobalTimer* timerRef =
dsinclair82e17672016-10-11 12:38:01 -0700534 new GlobalTimer(this, pRuntime->GetFormFillEnv(), pRuntime, 1, script,
535 dwTimeOut, dwTimeOut);
tsepeza752edf2016-08-19 14:57:42 -0700536 m_Timers.insert(std::unique_ptr<GlobalTimer>(timerRef));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700537
tsepezb4694242016-08-15 16:44:55 -0700538 v8::Local<v8::Object> pRetObj =
539 pRuntime->NewFxDynamicObj(CJS_TimerObj::g_nObjDefnID);
Tom Sepezc5a14722017-02-24 15:31:12 -0800540 if (pRetObj.IsEmpty())
541 return false;
tsepez41a53ad2016-03-28 16:59:30 -0700542
tsepezb4694242016-08-15 16:44:55 -0700543 CJS_TimerObj* pJS_TimerObj =
544 static_cast<CJS_TimerObj*>(pRuntime->GetObjectPrivate(pRetObj));
tsepez41a53ad2016-03-28 16:59:30 -0700545 TimerObj* pTimerObj = static_cast<TimerObj*>(pJS_TimerObj->GetEmbedObject());
dsinclair2eb7c7d2016-08-18 09:58:19 -0700546 pTimerObj->SetTimer(timerRef);
Dan Sinclaire4974922017-10-24 09:36:16 -0400547 vRet = CJS_Value(pRetObj);
tsepez4cf55152016-11-02 14:37:54 -0700548 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700549}
550
Tom Sepezb1670b52017-02-16 17:01:00 -0800551bool app::clearTimeOut(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700552 const std::vector<CJS_Value>& params,
553 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -0400554 WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700555 if (params.size() != 1) {
tsepezcd5dc852016-09-08 11:23:24 -0700556 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);
tsepez4cf55152016-11-02 14:37:54 -0700557 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700558 }
559
Tom Sepezb1670b52017-02-16 17:01:00 -0800560 app::ClearTimerCommon(pRuntime, params[0]);
tsepez4cf55152016-11-02 14:37:54 -0700561 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700562}
563
Tom Sepezb1670b52017-02-16 17:01:00 -0800564bool app::clearInterval(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700565 const std::vector<CJS_Value>& params,
566 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -0400567 WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700568 if (params.size() != 1) {
tsepezcd5dc852016-09-08 11:23:24 -0700569 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);
tsepez4cf55152016-11-02 14:37:54 -0700570 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700571 }
572
Tom Sepezb1670b52017-02-16 17:01:00 -0800573 app::ClearTimerCommon(pRuntime, params[0]);
tsepez4cf55152016-11-02 14:37:54 -0700574 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700575}
576
tsepezb4694242016-08-15 16:44:55 -0700577void app::ClearTimerCommon(CJS_Runtime* pRuntime, const CJS_Value& param) {
tsepez40faa792016-07-15 17:58:02 -0700578 if (param.GetType() != CJS_Value::VT_object)
tsepez41a53ad2016-03-28 16:59:30 -0700579 return;
580
tsepezb4694242016-08-15 16:44:55 -0700581 v8::Local<v8::Object> pObj = param.ToV8Object(pRuntime);
582 if (CFXJS_Engine::GetObjDefnID(pObj) != CJS_TimerObj::g_nObjDefnID)
tsepez41a53ad2016-03-28 16:59:30 -0700583 return;
584
Dan Sinclairc9708952017-10-23 09:40:59 -0400585 CJS_Object* pJSObj = param.ToObject(pRuntime);
tsepez41a53ad2016-03-28 16:59:30 -0700586 if (!pJSObj)
587 return;
588
589 TimerObj* pTimerObj = static_cast<TimerObj*>(pJSObj->GetEmbedObject());
590 if (!pTimerObj)
591 return;
592
tsepeze3ff76b2016-08-08 11:58:47 -0700593 GlobalTimer::Cancel(pTimerObj->GetTimerID());
tsepez41a53ad2016-03-28 16:59:30 -0700594}
595
Tom Sepezb1670b52017-02-16 17:01:00 -0800596bool app::execMenuItem(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700597 const std::vector<CJS_Value>& params,
598 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -0400599 WideString& sError) {
tsepez4cf55152016-11-02 14:37:54 -0700600 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700601}
602
tsepeze3ff76b2016-08-08 11:58:47 -0700603void app::TimerProc(GlobalTimer* pTimer) {
Lei Zhang2d5a0e12015-10-05 17:00:03 -0700604 CJS_Runtime* pRuntime = pTimer->GetRuntime();
tsepez8ca63de2016-08-05 17:12:27 -0700605 if (pRuntime && (!pTimer->IsOneShot() || pTimer->GetTimeOut() > 0))
606 RunJsScript(pRuntime, pTimer->GetJScript());
607}
Lei Zhang2d5a0e12015-10-05 17:00:03 -0700608
tsepeze3ff76b2016-08-08 11:58:47 -0700609void app::CancelProc(GlobalTimer* pTimer) {
tsepeza752edf2016-08-19 14:57:42 -0700610 m_Timers.erase(pdfium::FakeUniquePtr<GlobalTimer>(pTimer));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700611}
612
Ryan Harrison275e2602017-09-18 14:23:18 -0400613void app::RunJsScript(CJS_Runtime* pRuntime, const WideString& wsScript) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700614 if (!pRuntime->IsBlocking()) {
Tom Sepezd6ae2af2017-02-16 11:49:55 -0800615 IJS_EventContext* pContext = pRuntime->NewEventContext();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700616 pContext->OnExternal_Exec();
Ryan Harrison275e2602017-09-18 14:23:18 -0400617 WideString wtInfo;
Tom Sepez33420902015-10-13 15:00:10 -0700618 pContext->RunScript(wsScript, &wtInfo);
Tom Sepezd6ae2af2017-02-16 11:49:55 -0800619 pRuntime->ReleaseEventContext(pContext);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700620 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700621}
622
Tom Sepezb1670b52017-02-16 17:01:00 -0800623bool app::goBack(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700624 const std::vector<CJS_Value>& params,
625 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -0400626 WideString& sError) {
tsepez4cf55152016-11-02 14:37:54 -0700627 // Not supported.
628 return true;
629}
630
Tom Sepezb1670b52017-02-16 17:01:00 -0800631bool app::goForward(CJS_Runtime* pRuntime,
Lei Zhang945fdb72015-11-11 10:18:16 -0800632 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700633 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -0400634 WideString& sError) {
Tom Sepezc6ab1722015-02-05 15:27:25 -0800635 // Not supported.
tsepez4cf55152016-11-02 14:37:54 -0700636 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700637}
638
Tom Sepezb1670b52017-02-16 17:01:00 -0800639bool app::mailMsg(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700640 const std::vector<CJS_Value>& params,
641 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -0400642 WideString& sError) {
Tom Sepeze5fbd7a2016-01-29 17:05:08 -0800643 std::vector<CJS_Value> newParams =
Dan Sinclairc9708952017-10-23 09:40:59 -0400644 ExpandKeywordParams(pRuntime, params, 6, L"bUI", L"cTo", L"cCc", L"cBcc",
645 L"cSubject", L"cMsg");
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700646
Tom Sepeze5fbd7a2016-01-29 17:05:08 -0800647 if (newParams[0].GetType() == CJS_Value::VT_unknown) {
tsepezcd5dc852016-09-08 11:23:24 -0700648 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);
tsepez4cf55152016-11-02 14:37:54 -0700649 return false;
Tom Sepeze5fbd7a2016-01-29 17:05:08 -0800650 }
tsepezb4694242016-08-15 16:44:55 -0700651 bool bUI = newParams[0].ToBool(pRuntime);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700652
Ryan Harrison275e2602017-09-18 14:23:18 -0400653 WideString cTo;
Tom Sepeze5fbd7a2016-01-29 17:05:08 -0800654 if (newParams[1].GetType() != CJS_Value::VT_unknown) {
Dan Sinclairc9708952017-10-23 09:40:59 -0400655 cTo = newParams[1].ToWideString(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700656 } else {
Tom Sepeze5fbd7a2016-01-29 17:05:08 -0800657 if (!bUI) {
658 // cTo parameter required when UI not invoked.
tsepezcd5dc852016-09-08 11:23:24 -0700659 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);
tsepez4cf55152016-11-02 14:37:54 -0700660 return false;
Tom Sepeze5fbd7a2016-01-29 17:05:08 -0800661 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700662 }
Tom Sepezc6ab1722015-02-05 15:27:25 -0800663
Ryan Harrison275e2602017-09-18 14:23:18 -0400664 WideString cCc;
Tom Sepeze5fbd7a2016-01-29 17:05:08 -0800665 if (newParams[2].GetType() != CJS_Value::VT_unknown)
Dan Sinclairc9708952017-10-23 09:40:59 -0400666 cCc = newParams[2].ToWideString(pRuntime);
Tom Sepeze5fbd7a2016-01-29 17:05:08 -0800667
Ryan Harrison275e2602017-09-18 14:23:18 -0400668 WideString cBcc;
Tom Sepeze5fbd7a2016-01-29 17:05:08 -0800669 if (newParams[3].GetType() != CJS_Value::VT_unknown)
Dan Sinclairc9708952017-10-23 09:40:59 -0400670 cBcc = newParams[3].ToWideString(pRuntime);
Tom Sepeze5fbd7a2016-01-29 17:05:08 -0800671
Ryan Harrison275e2602017-09-18 14:23:18 -0400672 WideString cSubject;
Tom Sepeze5fbd7a2016-01-29 17:05:08 -0800673 if (newParams[4].GetType() != CJS_Value::VT_unknown)
Dan Sinclairc9708952017-10-23 09:40:59 -0400674 cSubject = newParams[4].ToWideString(pRuntime);
Tom Sepeze5fbd7a2016-01-29 17:05:08 -0800675
Ryan Harrison275e2602017-09-18 14:23:18 -0400676 WideString cMsg;
Tom Sepeze5fbd7a2016-01-29 17:05:08 -0800677 if (newParams[5].GetType() != CJS_Value::VT_unknown)
Dan Sinclairc9708952017-10-23 09:40:59 -0400678 cMsg = newParams[5].ToWideString(pRuntime);
Tom Sepeze5fbd7a2016-01-29 17:05:08 -0800679
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700680 pRuntime->BeginBlock();
Tom Sepezb1670b52017-02-16 17:01:00 -0800681 pRuntime->GetFormFillEnv()->JS_docmailForm(nullptr, 0, bUI, cTo.c_str(),
dsinclair4526faf2016-10-11 10:54:49 -0700682 cSubject.c_str(), cCc.c_str(),
683 cBcc.c_str(), cMsg.c_str());
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700684 pRuntime->EndBlock();
tsepez4cf55152016-11-02 14:37:54 -0700685 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700686}
687
Tom Sepezb1670b52017-02-16 17:01:00 -0800688bool app::launchURL(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700689 const std::vector<CJS_Value>& params,
690 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -0400691 WideString& sError) {
Tom Sepezc6ab1722015-02-05 15:27:25 -0800692 // Unsafe, not supported.
tsepez4cf55152016-11-02 14:37:54 -0700693 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700694}
695
dan sinclaircbe23db2017-10-19 14:29:33 -0400696bool app::get_runtime_highlight(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400697 CJS_Value* vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400698 WideString* sError) {
Dan Sinclaire4974922017-10-24 09:36:16 -0400699 vp->Set(pRuntime->NewBoolean(m_bRuntimeHighLight));
tsepez4cf55152016-11-02 14:37:54 -0700700 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700701}
702
dan sinclaircbe23db2017-10-19 14:29:33 -0400703bool app::set_runtime_highlight(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400704 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400705 WideString* sError) {
Dan Sinclair33d13f22017-10-23 09:44:30 -0400706 m_bRuntimeHighLight = vp.ToBool(pRuntime);
dan sinclaircbe23db2017-10-19 14:29:33 -0400707 return true;
708}
709
710bool app::get_fullscreen(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400711 CJS_Value* vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400712 WideString* sError) {
713 return false;
714}
715
716bool app::set_fullscreen(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400717 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400718 WideString* sError) {
tsepez4cf55152016-11-02 14:37:54 -0700719 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700720}
721
Tom Sepezb1670b52017-02-16 17:01:00 -0800722bool app::popUpMenu(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700723 const std::vector<CJS_Value>& params,
724 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -0400725 WideString& sError) {
tsepez4cf55152016-11-02 14:37:54 -0700726 return false;
727}
728
Tom Sepezb1670b52017-02-16 17:01:00 -0800729bool app::browseForDoc(CJS_Runtime* pRuntime,
Lei Zhang945fdb72015-11-11 10:18:16 -0800730 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700731 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -0400732 WideString& sError) {
Tom Sepezc6ab1722015-02-05 15:27:25 -0800733 // Unsafe, not supported.
tsepez4cf55152016-11-02 14:37:54 -0700734 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700735}
736
Ryan Harrison275e2602017-09-18 14:23:18 -0400737WideString app::SysPathToPDFPath(const WideString& sOldPath) {
738 WideString sRet = L"/";
Tom Sepez3c3e2712017-04-17 15:38:19 -0700739 for (const wchar_t& c : sOldPath) {
740 if (c != L':')
741 sRet += (c == L'\\') ? L'/' : c;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700742 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700743 return sRet;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700744}
745
Tom Sepezb1670b52017-02-16 17:01:00 -0800746bool app::newDoc(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700747 const std::vector<CJS_Value>& params,
748 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -0400749 WideString& sError) {
tsepez4cf55152016-11-02 14:37:54 -0700750 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700751}
752
Tom Sepezb1670b52017-02-16 17:01:00 -0800753bool app::openDoc(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700754 const std::vector<CJS_Value>& params,
755 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -0400756 WideString& sError) {
tsepez4cf55152016-11-02 14:37:54 -0700757 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700758}
759
Tom Sepezb1670b52017-02-16 17:01:00 -0800760bool app::response(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700761 const std::vector<CJS_Value>& params,
762 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -0400763 WideString& sError) {
Tom Sepez58fb36a2016-02-01 10:32:14 -0800764 std::vector<CJS_Value> newParams =
Dan Sinclairc9708952017-10-23 09:40:59 -0400765 ExpandKeywordParams(pRuntime, params, 5, L"cQuestion", L"cTitle",
766 L"cDefault", L"bPassword", L"cLabel");
Tom Sepez621d4de2014-07-29 14:01:21 -0700767
Tom Sepez58fb36a2016-02-01 10:32:14 -0800768 if (newParams[0].GetType() == CJS_Value::VT_unknown) {
tsepezcd5dc852016-09-08 11:23:24 -0700769 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);
tsepez4cf55152016-11-02 14:37:54 -0700770 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700771 }
Dan Sinclairc9708952017-10-23 09:40:59 -0400772 WideString swQuestion = newParams[0].ToWideString(pRuntime);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700773
Ryan Harrison275e2602017-09-18 14:23:18 -0400774 WideString swTitle = L"PDF";
Tom Sepez58fb36a2016-02-01 10:32:14 -0800775 if (newParams[1].GetType() != CJS_Value::VT_unknown)
Dan Sinclairc9708952017-10-23 09:40:59 -0400776 swTitle = newParams[1].ToWideString(pRuntime);
Tom Sepez58fb36a2016-02-01 10:32:14 -0800777
Ryan Harrison275e2602017-09-18 14:23:18 -0400778 WideString swDefault;
Tom Sepez58fb36a2016-02-01 10:32:14 -0800779 if (newParams[2].GetType() != CJS_Value::VT_unknown)
Dan Sinclairc9708952017-10-23 09:40:59 -0400780 swDefault = newParams[2].ToWideString(pRuntime);
Tom Sepez58fb36a2016-02-01 10:32:14 -0800781
782 bool bPassword = false;
783 if (newParams[3].GetType() != CJS_Value::VT_unknown)
tsepezb4694242016-08-15 16:44:55 -0700784 bPassword = newParams[3].ToBool(pRuntime);
Tom Sepez58fb36a2016-02-01 10:32:14 -0800785
Ryan Harrison275e2602017-09-18 14:23:18 -0400786 WideString swLabel;
Tom Sepez58fb36a2016-02-01 10:32:14 -0800787 if (newParams[4].GetType() != CJS_Value::VT_unknown)
Dan Sinclairc9708952017-10-23 09:40:59 -0400788 swLabel = newParams[4].ToWideString(pRuntime);
Tom Sepez621d4de2014-07-29 14:01:21 -0700789
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700790 const int MAX_INPUT_BYTES = 2048;
Tom Sepezd7188f72017-05-02 15:10:58 -0700791 std::vector<uint8_t> pBuff(MAX_INPUT_BYTES + 2);
Tom Sepezb1670b52017-02-16 17:01:00 -0800792 int nLengthBytes = pRuntime->GetFormFillEnv()->JS_appResponse(
Lei Zhangdb5256f2015-10-02 10:11:43 -0700793 swQuestion.c_str(), swTitle.c_str(), swDefault.c_str(), swLabel.c_str(),
Tom Sepezd7188f72017-05-02 15:10:58 -0700794 bPassword, pBuff.data(), MAX_INPUT_BYTES);
Tom Sepez58fb36a2016-02-01 10:32:14 -0800795
796 if (nLengthBytes < 0 || nLengthBytes > MAX_INPUT_BYTES) {
tsepezcd5dc852016-09-08 11:23:24 -0700797 sError = JSGetStringFromID(IDS_STRING_JSPARAM_TOOLONG);
tsepez4cf55152016-11-02 14:37:54 -0700798 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700799 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700800
Dan Sinclair1d8d9ac2017-10-24 11:23:25 -0400801 vRet = CJS_Value(pRuntime->NewString(
802 WideString::FromUTF16LE(reinterpret_cast<uint16_t*>(pBuff.data()),
803 nLengthBytes / sizeof(uint16_t))
804 .c_str()));
tsepezf3dc8c62016-08-10 06:29:29 -0700805
tsepez4cf55152016-11-02 14:37:54 -0700806 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700807}
808
Dan Sinclair33d13f22017-10-23 09:44:30 -0400809bool app::get_media(CJS_Runtime* pRuntime, CJS_Value* vp, WideString* sError) {
dan sinclaircbe23db2017-10-19 14:29:33 -0400810 return false;
811}
812
813bool app::set_media(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400814 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400815 WideString* sError) {
tsepez4cf55152016-11-02 14:37:54 -0700816 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700817}
818
Tom Sepezb1670b52017-02-16 17:01:00 -0800819bool app::execDialog(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700820 const std::vector<CJS_Value>& params,
821 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -0400822 WideString& sError) {
tsepez4cf55152016-11-02 14:37:54 -0700823 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700824}