blob: 5345d2533495490bced8af69798fdf92ca341d5f [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());
Dan Sinclair1b2a18e2017-10-24 13:56:29 -0400223 if (aDocs.GetLength(pRuntime) > 0) {
224 if (aDocs.ToV8Value().IsEmpty())
225 vp->Set(pRuntime->NewArray());
226 else
227 vp->Set(aDocs.ToV8Value());
228 } else {
Dan Sinclaire4974922017-10-24 09:36:16 -0400229 vp->Set(pRuntime->NewNull());
Dan Sinclair1b2a18e2017-10-24 13:56:29 -0400230 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700231
tsepez4cf55152016-11-02 14:37:54 -0700232 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700233}
234
dan sinclaircbe23db2017-10-19 14:29:33 -0400235bool app::set_active_docs(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400236 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400237 WideString* sError) {
238 return false;
239}
240
241bool app::get_calculate(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400242 CJS_Value* vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400243 WideString* sError) {
Dan Sinclaire4974922017-10-24 09:36:16 -0400244 vp->Set(pRuntime->NewBoolean(m_bCalculate));
tsepez4cf55152016-11-02 14:37:54 -0700245 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700246}
247
dan sinclaircbe23db2017-10-19 14:29:33 -0400248bool app::set_calculate(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400249 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400250 WideString* sError) {
Dan Sinclair1b2a18e2017-10-24 13:56:29 -0400251 m_bCalculate = pRuntime->ToBoolean(vp.ToV8Value());
dan sinclaircbe23db2017-10-19 14:29:33 -0400252 pRuntime->GetFormFillEnv()->GetInterForm()->EnableCalculate(m_bCalculate);
253 return true;
254}
tsepez4cf55152016-11-02 14:37:54 -0700255
dan sinclaircbe23db2017-10-19 14:29:33 -0400256bool app::get_forms_version(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400257 CJS_Value* vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400258 WideString* sError) {
Dan Sinclaire4974922017-10-24 09:36:16 -0400259 vp->Set(pRuntime->NewNumber(JS_NUM_FORMSVERSION));
dan sinclaircbe23db2017-10-19 14:29:33 -0400260 return true;
261}
262
263bool app::set_forms_version(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400264 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400265 WideString* sError) {
tsepez4cf55152016-11-02 14:37:54 -0700266 return false;
267}
268
dan sinclaircbe23db2017-10-19 14:29:33 -0400269bool app::get_viewer_type(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400270 CJS_Value* vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400271 WideString* sError) {
Dan Sinclaire4974922017-10-24 09:36:16 -0400272 vp->Set(pRuntime->NewString(JS_STR_VIEWERTYPE));
dan sinclaircbe23db2017-10-19 14:29:33 -0400273 return true;
274}
tsepez4cf55152016-11-02 14:37:54 -0700275
dan sinclaircbe23db2017-10-19 14:29:33 -0400276bool app::set_viewer_type(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400277 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400278 WideString* sError) {
tsepez4cf55152016-11-02 14:37:54 -0700279 return false;
280}
281
dan sinclaircbe23db2017-10-19 14:29:33 -0400282bool app::get_viewer_variation(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400283 CJS_Value* vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400284 WideString* sError) {
Dan Sinclaire4974922017-10-24 09:36:16 -0400285 vp->Set(pRuntime->NewString(JS_STR_VIEWERVARIATION));
dan sinclaircbe23db2017-10-19 14:29:33 -0400286 return true;
287}
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700288
dan sinclaircbe23db2017-10-19 14:29:33 -0400289bool app::set_viewer_variation(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400290 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400291 WideString* sError) {
tsepez4cf55152016-11-02 14:37:54 -0700292 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700293}
294
dan sinclaircbe23db2017-10-19 14:29:33 -0400295bool app::get_viewer_version(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400296 CJS_Value* vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400297 WideString* sError) {
Tom Sepez51da0932015-11-25 16:05:49 -0800298#ifdef PDF_ENABLE_XFA
Tom Sepezb1670b52017-02-16 17:01:00 -0800299 CPDFXFA_Context* pXFAContext = pRuntime->GetFormFillEnv()->GetXFAContext();
Ryan Harrison854d71c2017-10-18 12:28:14 -0400300 if (pXFAContext->ContainsXFAForm()) {
Dan Sinclaire4974922017-10-24 09:36:16 -0400301 vp->Set(pRuntime->NewNumber(JS_NUM_VIEWERVERSION_XFA));
tsepez4cf55152016-11-02 14:37:54 -0700302 return true;
Tom Sepezbf59a072015-10-21 14:07:23 -0700303 }
Tom Sepez40e9ff32015-11-30 12:39:54 -0800304#endif // PDF_ENABLE_XFA
Dan Sinclaire4974922017-10-24 09:36:16 -0400305 vp->Set(pRuntime->NewNumber(JS_NUM_VIEWERVERSION));
tsepez4cf55152016-11-02 14:37:54 -0700306 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700307}
308
dan sinclaircbe23db2017-10-19 14:29:33 -0400309bool app::set_viewer_version(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400310 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400311 WideString* sError) {
312 return false;
313}
314
315bool app::get_platform(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400316 CJS_Value* vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400317 WideString* sError) {
Tom Sepez4d6fa832015-12-08 11:31:59 -0800318#ifdef PDF_ENABLE_XFA
Tom Sepezb1670b52017-02-16 17:01:00 -0800319 CPDFSDK_FormFillEnvironment* pFormFillEnv = pRuntime->GetFormFillEnv();
dsinclair82e17672016-10-11 12:38:01 -0700320 if (!pFormFillEnv)
tsepez4cf55152016-11-02 14:37:54 -0700321 return false;
dan sinclaircbe23db2017-10-19 14:29:33 -0400322
Ryan Harrison275e2602017-09-18 14:23:18 -0400323 WideString platfrom = pFormFillEnv->GetPlatform();
Tom Sepez4d6fa832015-12-08 11:31:59 -0800324 if (!platfrom.IsEmpty()) {
Dan Sinclaire4974922017-10-24 09:36:16 -0400325 vp->Set(pRuntime->NewString(platfrom.c_str()));
tsepez4cf55152016-11-02 14:37:54 -0700326 return true;
Tom Sepez4d6fa832015-12-08 11:31:59 -0800327 }
328#endif
Dan Sinclaire4974922017-10-24 09:36:16 -0400329 vp->Set(pRuntime->NewString(JS_STR_PLATFORM));
tsepez4cf55152016-11-02 14:37:54 -0700330 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700331}
332
dan sinclaircbe23db2017-10-19 14:29:33 -0400333bool app::set_platform(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400334 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400335 WideString* sError) {
336 return false;
337}
338
339bool app::get_language(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400340 CJS_Value* vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400341 WideString* sError) {
Tom Sepez4d6fa832015-12-08 11:31:59 -0800342#ifdef PDF_ENABLE_XFA
Tom Sepezb1670b52017-02-16 17:01:00 -0800343 CPDFSDK_FormFillEnvironment* pFormFillEnv = pRuntime->GetFormFillEnv();
dsinclair82e17672016-10-11 12:38:01 -0700344 if (!pFormFillEnv)
tsepez4cf55152016-11-02 14:37:54 -0700345 return false;
dan sinclaircbe23db2017-10-19 14:29:33 -0400346
Ryan Harrison275e2602017-09-18 14:23:18 -0400347 WideString language = pFormFillEnv->GetLanguage();
Tom Sepez4d6fa832015-12-08 11:31:59 -0800348 if (!language.IsEmpty()) {
Dan Sinclaire4974922017-10-24 09:36:16 -0400349 vp->Set(pRuntime->NewString(language.c_str()));
tsepez4cf55152016-11-02 14:37:54 -0700350 return true;
Tom Sepez4d6fa832015-12-08 11:31:59 -0800351 }
352#endif
Dan Sinclaire4974922017-10-24 09:36:16 -0400353 vp->Set(pRuntime->NewString(JS_STR_LANGUAGE));
tsepez4cf55152016-11-02 14:37:54 -0700354 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700355}
356
dan sinclaircbe23db2017-10-19 14:29:33 -0400357bool app::set_language(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400358 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400359 WideString* sError) {
360 return false;
361}
362
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700363// creates a new fdf object that contains no data
364// comment: need reader support
365// note:
dsinclair735606d2016-10-05 15:47:02 -0700366// CFDF_Document * CPDFSDK_FormFillEnvironment::NewFDF();
Tom Sepezb1670b52017-02-16 17:01:00 -0800367bool app::newFDF(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700368 const std::vector<CJS_Value>& params,
369 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -0400370 WideString& sError) {
tsepez4cf55152016-11-02 14:37:54 -0700371 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700372}
373// opens a specified pdf document and returns its document object
374// comment:need reader support
375// note: as defined in js reference, the proto of this function's fourth
376// parmeters, how old an fdf document while do not show it.
dsinclair735606d2016-10-05 15:47:02 -0700377// CFDF_Document * CPDFSDK_FormFillEnvironment::OpenFDF(string strPath,bool
378// bUserConv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700379
Tom Sepezb1670b52017-02-16 17:01:00 -0800380bool app::openFDF(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700381 const std::vector<CJS_Value>& params,
382 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -0400383 WideString& sError) {
tsepez4cf55152016-11-02 14:37:54 -0700384 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700385}
386
Tom Sepezb1670b52017-02-16 17:01:00 -0800387bool app::alert(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700388 const std::vector<CJS_Value>& params,
389 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -0400390 WideString& sError) {
Dan Sinclairc9708952017-10-23 09:40:59 -0400391 std::vector<CJS_Value> newParams = ExpandKeywordParams(
Tom Sepezbd932572016-01-29 09:10:41 -0800392 pRuntime, params, 4, L"cMsg", L"nIcon", L"nType", L"cTitle");
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700393
Tom Sepezbd932572016-01-29 09:10:41 -0800394 if (newParams[0].GetType() == CJS_Value::VT_unknown) {
tsepezcd5dc852016-09-08 11:23:24 -0700395 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);
tsepez4cf55152016-11-02 14:37:54 -0700396 return false;
Tom Sepezbd932572016-01-29 09:10:41 -0800397 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700398
dsinclair82e17672016-10-11 12:38:01 -0700399 CPDFSDK_FormFillEnvironment* pFormFillEnv = pRuntime->GetFormFillEnv();
400 if (!pFormFillEnv) {
Dan Sinclair1d8d9ac2017-10-24 11:23:25 -0400401 vRet = CJS_Value(pRuntime->NewNumber(0));
tsepez4cf55152016-11-02 14:37:54 -0700402 return true;
tsepeze1e7bd02016-08-08 13:03:16 -0700403 }
404
Ryan Harrison275e2602017-09-18 14:23:18 -0400405 WideString swMsg;
Tom Sepezbd932572016-01-29 09:10:41 -0800406 if (newParams[0].GetType() == CJS_Value::VT_object) {
Dan Sinclairc9708952017-10-23 09:40:59 -0400407 if (newParams[0].IsArrayObject()) {
Dan Sinclair1b2a18e2017-10-24 13:56:29 -0400408 CJS_Array carray(pRuntime->ToArray(newParams[0].ToV8Value()));
Tom Sepezbd932572016-01-29 09:10:41 -0800409 swMsg = L"[";
tsepezb4694242016-08-15 16:44:55 -0700410 for (int i = 0; i < carray.GetLength(pRuntime); ++i) {
Tom Sepezbd932572016-01-29 09:10:41 -0800411 if (i)
412 swMsg += L", ";
Dan Sinclairc9708952017-10-23 09:40:59 -0400413
414 CJS_Value element(carray.GetElement(pRuntime, i));
Dan Sinclair1b2a18e2017-10-24 13:56:29 -0400415 swMsg += pRuntime->ToWideString(element.ToV8Value());
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700416 }
Tom Sepezbd932572016-01-29 09:10:41 -0800417 swMsg += L"]";
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700418 } else {
Dan Sinclair1b2a18e2017-10-24 13:56:29 -0400419 swMsg = pRuntime->ToWideString(newParams[0].ToV8Value());
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700420 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700421 } else {
Dan Sinclair1b2a18e2017-10-24 13:56:29 -0400422 swMsg = pRuntime->ToWideString(newParams[0].ToV8Value());
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700423 }
424
Tom Sepezbd932572016-01-29 09:10:41 -0800425 int iIcon = 0;
426 if (newParams[1].GetType() != CJS_Value::VT_unknown)
Dan Sinclair1b2a18e2017-10-24 13:56:29 -0400427 iIcon = pRuntime->ToInt32(newParams[1].ToV8Value());
Tom Sepezbd932572016-01-29 09:10:41 -0800428
429 int iType = 0;
430 if (newParams[2].GetType() != CJS_Value::VT_unknown)
Dan Sinclair1b2a18e2017-10-24 13:56:29 -0400431 iType = pRuntime->ToInt32(newParams[2].ToV8Value());
Tom Sepezbd932572016-01-29 09:10:41 -0800432
Ryan Harrison275e2602017-09-18 14:23:18 -0400433 WideString swTitle;
Tom Sepezbd932572016-01-29 09:10:41 -0800434 if (newParams[3].GetType() != CJS_Value::VT_unknown)
Dan Sinclair1b2a18e2017-10-24 13:56:29 -0400435 swTitle = pRuntime->ToWideString(newParams[3].ToV8Value());
Tom Sepezbd932572016-01-29 09:10:41 -0800436 else
tsepezcd5dc852016-09-08 11:23:24 -0700437 swTitle = JSGetStringFromID(IDS_STRING_JSALERT);
Tom Sepezbd932572016-01-29 09:10:41 -0800438
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700439 pRuntime->BeginBlock();
dsinclair7cbe68e2016-10-12 11:56:23 -0700440 pFormFillEnv->KillFocusAnnot(0);
tsepeze1e7bd02016-08-08 13:03:16 -0700441
Dan Sinclair1d8d9ac2017-10-24 11:23:25 -0400442 vRet = CJS_Value(pRuntime->NewNumber(
443 pFormFillEnv->JS_appAlert(swMsg.c_str(), swTitle.c_str(), iType, iIcon)));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700444 pRuntime->EndBlock();
tsepez4cf55152016-11-02 14:37:54 -0700445 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700446}
447
Tom Sepezb1670b52017-02-16 17:01:00 -0800448bool app::beep(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700449 const std::vector<CJS_Value>& params,
450 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -0400451 WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700452 if (params.size() == 1) {
Dan Sinclair1b2a18e2017-10-24 13:56:29 -0400453 pRuntime->GetFormFillEnv()->JS_appBeep(
454 pRuntime->ToInt32(params[0].ToV8Value()));
tsepez4cf55152016-11-02 14:37:54 -0700455 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700456 }
457
tsepezcd5dc852016-09-08 11:23:24 -0700458 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);
tsepez4cf55152016-11-02 14:37:54 -0700459 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700460}
461
Tom Sepezb1670b52017-02-16 17:01:00 -0800462bool app::findComponent(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 true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700467}
468
Tom Sepezb1670b52017-02-16 17:01:00 -0800469bool app::popUpMenuEx(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700470 const std::vector<CJS_Value>& params,
471 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -0400472 WideString& sError) {
tsepez4cf55152016-11-02 14:37:54 -0700473 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700474}
475
Dan Sinclair33d13f22017-10-23 09:44:30 -0400476bool app::get_fs(CJS_Runtime* pRuntime, CJS_Value* vp, WideString* sError) {
dan sinclaircbe23db2017-10-19 14:29:33 -0400477 return false;
478}
479
480bool app::set_fs(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400481 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400482 WideString* sError) {
tsepez4cf55152016-11-02 14:37:54 -0700483 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700484}
485
Tom Sepezb1670b52017-02-16 17:01:00 -0800486bool app::setInterval(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700487 const std::vector<CJS_Value>& params,
488 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -0400489 WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700490 if (params.size() > 2 || params.size() == 0) {
tsepezcd5dc852016-09-08 11:23:24 -0700491 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);
tsepez4cf55152016-11-02 14:37:54 -0700492 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700493 }
Tom Sepezc6ab1722015-02-05 15:27:25 -0800494
Ryan Harrison275e2602017-09-18 14:23:18 -0400495 WideString script =
Dan Sinclair1b2a18e2017-10-24 13:56:29 -0400496 params.size() > 0 ? pRuntime->ToWideString(params[0].ToV8Value()) : L"";
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700497 if (script.IsEmpty()) {
tsepezcd5dc852016-09-08 11:23:24 -0700498 sError = JSGetStringFromID(IDS_STRING_JSAFNUMBER_KEYSTROKE);
tsepez4cf55152016-11-02 14:37:54 -0700499 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700500 }
501
Dan Sinclair1b2a18e2017-10-24 13:56:29 -0400502 uint32_t dwInterval =
503 params.size() > 1 ? pRuntime->ToInt32(params[1].ToV8Value()) : 1000;
dsinclair2eb7c7d2016-08-18 09:58:19 -0700504
dsinclair82e17672016-10-11 12:38:01 -0700505 GlobalTimer* timerRef = new GlobalTimer(this, pRuntime->GetFormFillEnv(),
506 pRuntime, 0, script, dwInterval, 0);
tsepeza752edf2016-08-19 14:57:42 -0700507 m_Timers.insert(std::unique_ptr<GlobalTimer>(timerRef));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700508
tsepezb4694242016-08-15 16:44:55 -0700509 v8::Local<v8::Object> pRetObj =
510 pRuntime->NewFxDynamicObj(CJS_TimerObj::g_nObjDefnID);
Tom Sepezc5a14722017-02-24 15:31:12 -0800511 if (pRetObj.IsEmpty())
512 return false;
513
tsepezb4694242016-08-15 16:44:55 -0700514 CJS_TimerObj* pJS_TimerObj =
515 static_cast<CJS_TimerObj*>(pRuntime->GetObjectPrivate(pRetObj));
tsepez41a53ad2016-03-28 16:59:30 -0700516 TimerObj* pTimerObj = static_cast<TimerObj*>(pJS_TimerObj->GetEmbedObject());
dsinclair2eb7c7d2016-08-18 09:58:19 -0700517 pTimerObj->SetTimer(timerRef);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700518
Dan Sinclaire4974922017-10-24 09:36:16 -0400519 vRet = CJS_Value(pRetObj);
tsepez4cf55152016-11-02 14:37:54 -0700520 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700521}
522
Tom Sepezb1670b52017-02-16 17:01:00 -0800523bool app::setTimeOut(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700524 const std::vector<CJS_Value>& params,
525 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -0400526 WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700527 if (params.size() > 2 || params.size() == 0) {
tsepezcd5dc852016-09-08 11:23:24 -0700528 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);
tsepez4cf55152016-11-02 14:37:54 -0700529 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700530 }
Tom Sepezc6ab1722015-02-05 15:27:25 -0800531
Dan Sinclair1b2a18e2017-10-24 13:56:29 -0400532 WideString script = pRuntime->ToWideString(params[0].ToV8Value());
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700533 if (script.IsEmpty()) {
tsepezcd5dc852016-09-08 11:23:24 -0700534 sError = JSGetStringFromID(IDS_STRING_JSAFNUMBER_KEYSTROKE);
tsepez4cf55152016-11-02 14:37:54 -0700535 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700536 }
537
Dan Sinclair1b2a18e2017-10-24 13:56:29 -0400538 uint32_t dwTimeOut =
539 params.size() > 1 ? pRuntime->ToInt32(params[1].ToV8Value()) : 1000;
tsepeza752edf2016-08-19 14:57:42 -0700540 GlobalTimer* timerRef =
dsinclair82e17672016-10-11 12:38:01 -0700541 new GlobalTimer(this, pRuntime->GetFormFillEnv(), pRuntime, 1, script,
542 dwTimeOut, dwTimeOut);
tsepeza752edf2016-08-19 14:57:42 -0700543 m_Timers.insert(std::unique_ptr<GlobalTimer>(timerRef));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700544
tsepezb4694242016-08-15 16:44:55 -0700545 v8::Local<v8::Object> pRetObj =
546 pRuntime->NewFxDynamicObj(CJS_TimerObj::g_nObjDefnID);
Tom Sepezc5a14722017-02-24 15:31:12 -0800547 if (pRetObj.IsEmpty())
548 return false;
tsepez41a53ad2016-03-28 16:59:30 -0700549
tsepezb4694242016-08-15 16:44:55 -0700550 CJS_TimerObj* pJS_TimerObj =
551 static_cast<CJS_TimerObj*>(pRuntime->GetObjectPrivate(pRetObj));
tsepez41a53ad2016-03-28 16:59:30 -0700552 TimerObj* pTimerObj = static_cast<TimerObj*>(pJS_TimerObj->GetEmbedObject());
dsinclair2eb7c7d2016-08-18 09:58:19 -0700553 pTimerObj->SetTimer(timerRef);
Dan Sinclaire4974922017-10-24 09:36:16 -0400554 vRet = CJS_Value(pRetObj);
tsepez4cf55152016-11-02 14:37:54 -0700555 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700556}
557
Tom Sepezb1670b52017-02-16 17:01:00 -0800558bool app::clearTimeOut(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700559 const std::vector<CJS_Value>& params,
560 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -0400561 WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700562 if (params.size() != 1) {
tsepezcd5dc852016-09-08 11:23:24 -0700563 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);
tsepez4cf55152016-11-02 14:37:54 -0700564 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700565 }
566
Tom Sepezb1670b52017-02-16 17:01:00 -0800567 app::ClearTimerCommon(pRuntime, params[0]);
tsepez4cf55152016-11-02 14:37:54 -0700568 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700569}
570
Tom Sepezb1670b52017-02-16 17:01:00 -0800571bool app::clearInterval(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700572 const std::vector<CJS_Value>& params,
573 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -0400574 WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700575 if (params.size() != 1) {
tsepezcd5dc852016-09-08 11:23:24 -0700576 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);
tsepez4cf55152016-11-02 14:37:54 -0700577 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700578 }
579
Tom Sepezb1670b52017-02-16 17:01:00 -0800580 app::ClearTimerCommon(pRuntime, params[0]);
tsepez4cf55152016-11-02 14:37:54 -0700581 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700582}
583
tsepezb4694242016-08-15 16:44:55 -0700584void app::ClearTimerCommon(CJS_Runtime* pRuntime, const CJS_Value& param) {
tsepez40faa792016-07-15 17:58:02 -0700585 if (param.GetType() != CJS_Value::VT_object)
tsepez41a53ad2016-03-28 16:59:30 -0700586 return;
587
Dan Sinclair1b2a18e2017-10-24 13:56:29 -0400588 v8::Local<v8::Object> pObj = pRuntime->ToObject(param.ToV8Value());
tsepezb4694242016-08-15 16:44:55 -0700589 if (CFXJS_Engine::GetObjDefnID(pObj) != CJS_TimerObj::g_nObjDefnID)
tsepez41a53ad2016-03-28 16:59:30 -0700590 return;
591
Dan Sinclair1b2a18e2017-10-24 13:56:29 -0400592 CJS_Object* pJSObj =
593 static_cast<CJS_Object*>(pRuntime->GetObjectPrivate(pObj));
tsepez41a53ad2016-03-28 16:59:30 -0700594 if (!pJSObj)
595 return;
596
597 TimerObj* pTimerObj = static_cast<TimerObj*>(pJSObj->GetEmbedObject());
598 if (!pTimerObj)
599 return;
600
tsepeze3ff76b2016-08-08 11:58:47 -0700601 GlobalTimer::Cancel(pTimerObj->GetTimerID());
tsepez41a53ad2016-03-28 16:59:30 -0700602}
603
Tom Sepezb1670b52017-02-16 17:01:00 -0800604bool app::execMenuItem(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700605 const std::vector<CJS_Value>& params,
606 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -0400607 WideString& sError) {
tsepez4cf55152016-11-02 14:37:54 -0700608 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700609}
610
tsepeze3ff76b2016-08-08 11:58:47 -0700611void app::TimerProc(GlobalTimer* pTimer) {
Lei Zhang2d5a0e12015-10-05 17:00:03 -0700612 CJS_Runtime* pRuntime = pTimer->GetRuntime();
tsepez8ca63de2016-08-05 17:12:27 -0700613 if (pRuntime && (!pTimer->IsOneShot() || pTimer->GetTimeOut() > 0))
614 RunJsScript(pRuntime, pTimer->GetJScript());
615}
Lei Zhang2d5a0e12015-10-05 17:00:03 -0700616
tsepeze3ff76b2016-08-08 11:58:47 -0700617void app::CancelProc(GlobalTimer* pTimer) {
tsepeza752edf2016-08-19 14:57:42 -0700618 m_Timers.erase(pdfium::FakeUniquePtr<GlobalTimer>(pTimer));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700619}
620
Ryan Harrison275e2602017-09-18 14:23:18 -0400621void app::RunJsScript(CJS_Runtime* pRuntime, const WideString& wsScript) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700622 if (!pRuntime->IsBlocking()) {
Tom Sepezd6ae2af2017-02-16 11:49:55 -0800623 IJS_EventContext* pContext = pRuntime->NewEventContext();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700624 pContext->OnExternal_Exec();
Ryan Harrison275e2602017-09-18 14:23:18 -0400625 WideString wtInfo;
Tom Sepez33420902015-10-13 15:00:10 -0700626 pContext->RunScript(wsScript, &wtInfo);
Tom Sepezd6ae2af2017-02-16 11:49:55 -0800627 pRuntime->ReleaseEventContext(pContext);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700628 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700629}
630
Tom Sepezb1670b52017-02-16 17:01:00 -0800631bool app::goBack(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700632 const std::vector<CJS_Value>& params,
633 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -0400634 WideString& sError) {
tsepez4cf55152016-11-02 14:37:54 -0700635 // Not supported.
636 return true;
637}
638
Tom Sepezb1670b52017-02-16 17:01:00 -0800639bool app::goForward(CJS_Runtime* pRuntime,
Lei Zhang945fdb72015-11-11 10:18:16 -0800640 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700641 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -0400642 WideString& sError) {
Tom Sepezc6ab1722015-02-05 15:27:25 -0800643 // Not supported.
tsepez4cf55152016-11-02 14:37:54 -0700644 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700645}
646
Tom Sepezb1670b52017-02-16 17:01:00 -0800647bool app::mailMsg(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700648 const std::vector<CJS_Value>& params,
649 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -0400650 WideString& sError) {
Tom Sepeze5fbd7a2016-01-29 17:05:08 -0800651 std::vector<CJS_Value> newParams =
Dan Sinclairc9708952017-10-23 09:40:59 -0400652 ExpandKeywordParams(pRuntime, params, 6, L"bUI", L"cTo", L"cCc", L"cBcc",
653 L"cSubject", L"cMsg");
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700654
Tom Sepeze5fbd7a2016-01-29 17:05:08 -0800655 if (newParams[0].GetType() == CJS_Value::VT_unknown) {
tsepezcd5dc852016-09-08 11:23:24 -0700656 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);
tsepez4cf55152016-11-02 14:37:54 -0700657 return false;
Tom Sepeze5fbd7a2016-01-29 17:05:08 -0800658 }
Dan Sinclair1b2a18e2017-10-24 13:56:29 -0400659 bool bUI = pRuntime->ToBoolean(newParams[0].ToV8Value());
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700660
Ryan Harrison275e2602017-09-18 14:23:18 -0400661 WideString cTo;
Tom Sepeze5fbd7a2016-01-29 17:05:08 -0800662 if (newParams[1].GetType() != CJS_Value::VT_unknown) {
Dan Sinclair1b2a18e2017-10-24 13:56:29 -0400663 cTo = pRuntime->ToWideString(newParams[1].ToV8Value());
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700664 } else {
Tom Sepeze5fbd7a2016-01-29 17:05:08 -0800665 if (!bUI) {
666 // cTo parameter required when UI not invoked.
tsepezcd5dc852016-09-08 11:23:24 -0700667 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);
tsepez4cf55152016-11-02 14:37:54 -0700668 return false;
Tom Sepeze5fbd7a2016-01-29 17:05:08 -0800669 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700670 }
Tom Sepezc6ab1722015-02-05 15:27:25 -0800671
Ryan Harrison275e2602017-09-18 14:23:18 -0400672 WideString cCc;
Tom Sepeze5fbd7a2016-01-29 17:05:08 -0800673 if (newParams[2].GetType() != CJS_Value::VT_unknown)
Dan Sinclair1b2a18e2017-10-24 13:56:29 -0400674 cCc = pRuntime->ToWideString(newParams[2].ToV8Value());
Tom Sepeze5fbd7a2016-01-29 17:05:08 -0800675
Ryan Harrison275e2602017-09-18 14:23:18 -0400676 WideString cBcc;
Tom Sepeze5fbd7a2016-01-29 17:05:08 -0800677 if (newParams[3].GetType() != CJS_Value::VT_unknown)
Dan Sinclair1b2a18e2017-10-24 13:56:29 -0400678 cBcc = pRuntime->ToWideString(newParams[3].ToV8Value());
Tom Sepeze5fbd7a2016-01-29 17:05:08 -0800679
Ryan Harrison275e2602017-09-18 14:23:18 -0400680 WideString cSubject;
Tom Sepeze5fbd7a2016-01-29 17:05:08 -0800681 if (newParams[4].GetType() != CJS_Value::VT_unknown)
Dan Sinclair1b2a18e2017-10-24 13:56:29 -0400682 cSubject = pRuntime->ToWideString(newParams[4].ToV8Value());
Tom Sepeze5fbd7a2016-01-29 17:05:08 -0800683
Ryan Harrison275e2602017-09-18 14:23:18 -0400684 WideString cMsg;
Tom Sepeze5fbd7a2016-01-29 17:05:08 -0800685 if (newParams[5].GetType() != CJS_Value::VT_unknown)
Dan Sinclair1b2a18e2017-10-24 13:56:29 -0400686 cMsg = pRuntime->ToWideString(newParams[5].ToV8Value());
Tom Sepeze5fbd7a2016-01-29 17:05:08 -0800687
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700688 pRuntime->BeginBlock();
Tom Sepezb1670b52017-02-16 17:01:00 -0800689 pRuntime->GetFormFillEnv()->JS_docmailForm(nullptr, 0, bUI, cTo.c_str(),
dsinclair4526faf2016-10-11 10:54:49 -0700690 cSubject.c_str(), cCc.c_str(),
691 cBcc.c_str(), cMsg.c_str());
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700692 pRuntime->EndBlock();
tsepez4cf55152016-11-02 14:37:54 -0700693 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700694}
695
Tom Sepezb1670b52017-02-16 17:01:00 -0800696bool app::launchURL(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700697 const std::vector<CJS_Value>& params,
698 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -0400699 WideString& sError) {
Tom Sepezc6ab1722015-02-05 15:27:25 -0800700 // Unsafe, not supported.
tsepez4cf55152016-11-02 14:37:54 -0700701 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700702}
703
dan sinclaircbe23db2017-10-19 14:29:33 -0400704bool app::get_runtime_highlight(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400705 CJS_Value* vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400706 WideString* sError) {
Dan Sinclaire4974922017-10-24 09:36:16 -0400707 vp->Set(pRuntime->NewBoolean(m_bRuntimeHighLight));
tsepez4cf55152016-11-02 14:37:54 -0700708 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700709}
710
dan sinclaircbe23db2017-10-19 14:29:33 -0400711bool app::set_runtime_highlight(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400712 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400713 WideString* sError) {
Dan Sinclair1b2a18e2017-10-24 13:56:29 -0400714 m_bRuntimeHighLight = pRuntime->ToBoolean(vp.ToV8Value());
dan sinclaircbe23db2017-10-19 14:29:33 -0400715 return true;
716}
717
718bool app::get_fullscreen(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400719 CJS_Value* vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400720 WideString* sError) {
721 return false;
722}
723
724bool app::set_fullscreen(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400725 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400726 WideString* sError) {
tsepez4cf55152016-11-02 14:37:54 -0700727 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700728}
729
Tom Sepezb1670b52017-02-16 17:01:00 -0800730bool app::popUpMenu(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700731 const std::vector<CJS_Value>& params,
732 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -0400733 WideString& sError) {
tsepez4cf55152016-11-02 14:37:54 -0700734 return false;
735}
736
Tom Sepezb1670b52017-02-16 17:01:00 -0800737bool app::browseForDoc(CJS_Runtime* pRuntime,
Lei Zhang945fdb72015-11-11 10:18:16 -0800738 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700739 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -0400740 WideString& sError) {
Tom Sepezc6ab1722015-02-05 15:27:25 -0800741 // Unsafe, not supported.
tsepez4cf55152016-11-02 14:37:54 -0700742 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700743}
744
Ryan Harrison275e2602017-09-18 14:23:18 -0400745WideString app::SysPathToPDFPath(const WideString& sOldPath) {
746 WideString sRet = L"/";
Tom Sepez3c3e2712017-04-17 15:38:19 -0700747 for (const wchar_t& c : sOldPath) {
748 if (c != L':')
749 sRet += (c == L'\\') ? L'/' : c;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700750 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700751 return sRet;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700752}
753
Tom Sepezb1670b52017-02-16 17:01:00 -0800754bool app::newDoc(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700755 const std::vector<CJS_Value>& params,
756 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -0400757 WideString& sError) {
tsepez4cf55152016-11-02 14:37:54 -0700758 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700759}
760
Tom Sepezb1670b52017-02-16 17:01:00 -0800761bool app::openDoc(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700762 const std::vector<CJS_Value>& params,
763 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -0400764 WideString& sError) {
tsepez4cf55152016-11-02 14:37:54 -0700765 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700766}
767
Tom Sepezb1670b52017-02-16 17:01:00 -0800768bool app::response(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700769 const std::vector<CJS_Value>& params,
770 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -0400771 WideString& sError) {
Tom Sepez58fb36a2016-02-01 10:32:14 -0800772 std::vector<CJS_Value> newParams =
Dan Sinclairc9708952017-10-23 09:40:59 -0400773 ExpandKeywordParams(pRuntime, params, 5, L"cQuestion", L"cTitle",
774 L"cDefault", L"bPassword", L"cLabel");
Tom Sepez621d4de2014-07-29 14:01:21 -0700775
Tom Sepez58fb36a2016-02-01 10:32:14 -0800776 if (newParams[0].GetType() == CJS_Value::VT_unknown) {
tsepezcd5dc852016-09-08 11:23:24 -0700777 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);
tsepez4cf55152016-11-02 14:37:54 -0700778 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700779 }
Dan Sinclair1b2a18e2017-10-24 13:56:29 -0400780 WideString swQuestion = pRuntime->ToWideString(newParams[0].ToV8Value());
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700781
Ryan Harrison275e2602017-09-18 14:23:18 -0400782 WideString swTitle = L"PDF";
Tom Sepez58fb36a2016-02-01 10:32:14 -0800783 if (newParams[1].GetType() != CJS_Value::VT_unknown)
Dan Sinclair1b2a18e2017-10-24 13:56:29 -0400784 swTitle = pRuntime->ToWideString(newParams[1].ToV8Value());
Tom Sepez58fb36a2016-02-01 10:32:14 -0800785
Ryan Harrison275e2602017-09-18 14:23:18 -0400786 WideString swDefault;
Tom Sepez58fb36a2016-02-01 10:32:14 -0800787 if (newParams[2].GetType() != CJS_Value::VT_unknown)
Dan Sinclair1b2a18e2017-10-24 13:56:29 -0400788 swDefault = pRuntime->ToWideString(newParams[2].ToV8Value());
Tom Sepez58fb36a2016-02-01 10:32:14 -0800789
790 bool bPassword = false;
791 if (newParams[3].GetType() != CJS_Value::VT_unknown)
Dan Sinclair1b2a18e2017-10-24 13:56:29 -0400792 bPassword = pRuntime->ToBoolean(newParams[3].ToV8Value());
Tom Sepez58fb36a2016-02-01 10:32:14 -0800793
Ryan Harrison275e2602017-09-18 14:23:18 -0400794 WideString swLabel;
Tom Sepez58fb36a2016-02-01 10:32:14 -0800795 if (newParams[4].GetType() != CJS_Value::VT_unknown)
Dan Sinclair1b2a18e2017-10-24 13:56:29 -0400796 swLabel = pRuntime->ToWideString(newParams[4].ToV8Value());
Tom Sepez621d4de2014-07-29 14:01:21 -0700797
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700798 const int MAX_INPUT_BYTES = 2048;
Tom Sepezd7188f72017-05-02 15:10:58 -0700799 std::vector<uint8_t> pBuff(MAX_INPUT_BYTES + 2);
Tom Sepezb1670b52017-02-16 17:01:00 -0800800 int nLengthBytes = pRuntime->GetFormFillEnv()->JS_appResponse(
Lei Zhangdb5256f2015-10-02 10:11:43 -0700801 swQuestion.c_str(), swTitle.c_str(), swDefault.c_str(), swLabel.c_str(),
Tom Sepezd7188f72017-05-02 15:10:58 -0700802 bPassword, pBuff.data(), MAX_INPUT_BYTES);
Tom Sepez58fb36a2016-02-01 10:32:14 -0800803
804 if (nLengthBytes < 0 || nLengthBytes > MAX_INPUT_BYTES) {
tsepezcd5dc852016-09-08 11:23:24 -0700805 sError = JSGetStringFromID(IDS_STRING_JSPARAM_TOOLONG);
tsepez4cf55152016-11-02 14:37:54 -0700806 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700807 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700808
Dan Sinclair1d8d9ac2017-10-24 11:23:25 -0400809 vRet = CJS_Value(pRuntime->NewString(
810 WideString::FromUTF16LE(reinterpret_cast<uint16_t*>(pBuff.data()),
811 nLengthBytes / sizeof(uint16_t))
812 .c_str()));
tsepezf3dc8c62016-08-10 06:29:29 -0700813
tsepez4cf55152016-11-02 14:37:54 -0700814 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700815}
816
Dan Sinclair33d13f22017-10-23 09:44:30 -0400817bool app::get_media(CJS_Runtime* pRuntime, CJS_Value* vp, WideString* sError) {
dan sinclaircbe23db2017-10-19 14:29:33 -0400818 return false;
819}
820
821bool app::set_media(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400822 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400823 WideString* sError) {
tsepez4cf55152016-11-02 14:37:54 -0700824 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700825}
826
Tom Sepezb1670b52017-02-16 17:01:00 -0800827bool app::execDialog(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700828 const std::vector<CJS_Value>& params,
829 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -0400830 WideString& sError) {
tsepez4cf55152016-11-02 14:37:54 -0700831 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700832}