blob: f1a39460a27f242c598c2edaf3f4259e19d10238 [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,
31 const CFX_WideString& script,
32 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(); }
tsepeze3ff76b2016-08-08 11:58:47 -070043 CFX_WideString GetJScript() const { return m_swJScript; }
44
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;
56 const CFX_WideString m_swJScript;
tsepez1c620542016-09-12 09:47:52 -070057 CJS_Runtime::ObservedPtr m_pRuntime;
dsinclair82e17672016-10-11 12:38:01 -070058 CPDFSDK_FormFillEnvironment* const 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,
65 const CFX_WideString& script,
66 uint32_t dwElapse,
67 uint32_t dwTimeOut)
68 : m_nTimerID(0),
69 m_pEmbedObj(pObj),
70 m_bProcessing(false),
tsepeze3ff76b2016-08-08 11:58:47 -070071 m_nType(nType),
72 m_dwTimeOut(dwTimeOut),
73 m_swJScript(script),
74 m_pRuntime(pRuntime),
dsinclair82e17672016-10-11 12:38:01 -070075 m_pFormFillEnv(pFormFillEnv) {
76 CFX_SystemHandler* pHandler = m_pFormFillEnv->GetSysHandler();
tsepeze3ff76b2016-08-08 11:58:47 -070077 m_nTimerID = pHandler->SetTimer(dwElapse, Trigger);
tsepez6cf5eca2017-01-12 11:21:12 -080078 if (m_nTimerID)
79 (*GetGlobalTimerMap())[m_nTimerID] = this;
tsepeze3ff76b2016-08-08 11:58:47 -070080}
81
82GlobalTimer::~GlobalTimer() {
tsepeze3ff76b2016-08-08 11:58:47 -070083 if (!m_nTimerID)
84 return;
85
tsepez8832fbf2016-09-08 10:25:55 -070086 if (GetRuntime())
dsinclair82e17672016-10-11 12:38:01 -070087 m_pFormFillEnv->GetSysHandler()->KillTimer(m_nTimerID);
tsepeze3ff76b2016-08-08 11:58:47 -070088
89 GetGlobalTimerMap()->erase(m_nTimerID);
90}
91
92// static
93void GlobalTimer::Trigger(int nTimerID) {
94 auto it = GetGlobalTimerMap()->find(nTimerID);
95 if (it == GetGlobalTimerMap()->end())
96 return;
97
98 GlobalTimer* pTimer = it->second;
99 if (pTimer->m_bProcessing)
100 return;
101
102 pTimer->m_bProcessing = true;
103 if (pTimer->m_pEmbedObj)
104 pTimer->m_pEmbedObj->TimerProc(pTimer);
105
106 // Timer proc may have destroyed timer, find it again.
107 it = GetGlobalTimerMap()->find(nTimerID);
108 if (it == GetGlobalTimerMap()->end())
109 return;
110
111 pTimer = it->second;
112 pTimer->m_bProcessing = false;
113 if (pTimer->IsOneShot())
114 pTimer->m_pEmbedObj->CancelProc(pTimer);
115}
116
117// static
118void GlobalTimer::Cancel(int nTimerID) {
119 auto it = GetGlobalTimerMap()->find(nTimerID);
120 if (it == GetGlobalTimerMap()->end())
121 return;
122
123 GlobalTimer* pTimer = it->second;
124 pTimer->m_pEmbedObj->CancelProc(pTimer);
125}
126
127// static
128GlobalTimer::TimerMap* GlobalTimer::GetGlobalTimerMap() {
129 // Leak the timer array at shutdown.
130 static auto* s_TimerMap = new TimerMap;
131 return s_TimerMap;
132}
133
Tom Sepez04557b82017-02-16 09:43:10 -0800134JSConstSpec CJS_TimerObj::ConstSpecs[] = {{0, JSConstSpec::Number, 0, 0}};
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700135
Tom Sepez04557b82017-02-16 09:43:10 -0800136JSPropertySpec CJS_TimerObj::PropertySpecs[] = {{0, 0, 0}};
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700137
Tom Sepez04557b82017-02-16 09:43:10 -0800138JSMethodSpec CJS_TimerObj::MethodSpecs[] = {{0, 0}};
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700139
140IMPLEMENT_JS_CLASS(CJS_TimerObj, TimerObj)
141
142TimerObj::TimerObj(CJS_Object* pJSObject)
tsepez8ca63de2016-08-05 17:12:27 -0700143 : CJS_EmbedObj(pJSObject), m_nTimerID(0) {}
Tom Sepezc6ab1722015-02-05 15:27:25 -0800144
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700145TimerObj::~TimerObj() {}
146
tsepeze3ff76b2016-08-08 11:58:47 -0700147void TimerObj::SetTimer(GlobalTimer* pTimer) {
tsepez8ca63de2016-08-05 17:12:27 -0700148 m_nTimerID = pTimer->GetTimerID();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700149}
150
Tom Sepezd6278ba2015-09-08 16:34:37 -0700151#define JS_STR_VIEWERTYPE L"pdfium"
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700152#define JS_STR_VIEWERVARIATION L"Full"
153#define JS_STR_PLATFORM L"WIN"
dsinclairf51e4dc2016-10-13 07:43:19 -0700154#define JS_STR_LANGUAGE L"ENU"
Tom Sepezd6278ba2015-09-08 16:34:37 -0700155#define JS_NUM_VIEWERVERSION 8
Tom Sepez51da0932015-11-25 16:05:49 -0800156#ifdef PDF_ENABLE_XFA
Tom Sepezd6278ba2015-09-08 16:34:37 -0700157#define JS_NUM_VIEWERVERSION_XFA 11
Tom Sepez40e9ff32015-11-30 12:39:54 -0800158#endif // PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700159#define JS_NUM_FORMSVERSION 7
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700160
Tom Sepez04557b82017-02-16 09:43:10 -0800161JSConstSpec CJS_App::ConstSpecs[] = {{0, JSConstSpec::Number, 0, 0}};
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700162
Tom Sepez04557b82017-02-16 09:43:10 -0800163JSPropertySpec CJS_App::PropertySpecs[] = {
164 {L"activeDocs", get_activeDocs_static, set_activeDocs_static},
165 {L"calculate", get_calculate_static, set_calculate_static},
166 {L"formsVersion", get_formsVersion_static, set_formsVersion_static},
167 {L"fs", get_fs_static, set_fs_static},
168 {L"fullscreen", get_fullscreen_static, set_fullscreen_static},
169 {L"language", get_language_static, set_language_static},
170 {L"media", get_media_static, set_media_static},
171 {L"platform", get_platform_static, set_platform_static},
172 {L"runtimeHighlight", get_runtimeHighlight_static,
173 set_runtimeHighlight_static},
174 {L"viewerType", get_viewerType_static, set_viewerType_static},
175 {L"viewerVariation", get_viewerVariation_static,
176 set_viewerVariation_static},
177 {L"viewerVersion", get_viewerVersion_static, set_viewerVersion_static},
178 {0, 0, 0}};
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700179
Tom Sepez9b99b632017-02-21 15:05:57 -0800180JSMethodSpec CJS_App::MethodSpecs[] = {{"alert", alert_static},
181 {"beep", beep_static},
182 {"browseForDoc", browseForDoc_static},
183 {"clearInterval", clearInterval_static},
184 {"clearTimeOut", clearTimeOut_static},
185 {"execDialog", execDialog_static},
186 {"execMenuItem", execMenuItem_static},
187 {"findComponent", findComponent_static},
188 {"goBack", goBack_static},
189 {"goForward", goForward_static},
190 {"launchURL", launchURL_static},
191 {"mailMsg", mailMsg_static},
192 {"newFDF", newFDF_static},
193 {"newDoc", newDoc_static},
194 {"openDoc", openDoc_static},
195 {"openFDF", openFDF_static},
196 {"popUpMenuEx", popUpMenuEx_static},
197 {"popUpMenu", popUpMenu_static},
198 {"response", response_static},
199 {"setInterval", setInterval_static},
200 {"setTimeOut", setTimeOut_static},
Tom Sepez04557b82017-02-16 09:43:10 -0800201 {0, 0}};
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700202
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700203IMPLEMENT_JS_CLASS(CJS_App, app)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700204
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700205app::app(CJS_Object* pJSObject)
206 : CJS_EmbedObj(pJSObject), m_bCalculate(true), m_bRuntimeHighLight(false) {}
207
Lei Zhang2b1a2d52015-08-14 22:16:22 -0700208app::~app() {
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700209}
210
Tom Sepezb1670b52017-02-16 17:01:00 -0800211bool app::activeDocs(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700212 CJS_PropValue& vp,
213 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700214 if (!vp.IsGetting())
tsepez4cf55152016-11-02 14:37:54 -0700215 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700216
dsinclair82e17672016-10-11 12:38:01 -0700217 CJS_Document* pJSDocument = nullptr;
218 v8::Local<v8::Object> pObj = pRuntime->GetThisObj();
219 if (CFXJS_Engine::GetObjDefnID(pObj) == CJS_Document::g_nObjDefnID) {
220 pJSDocument = static_cast<CJS_Document*>(pRuntime->GetObjectPrivate(pObj));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700221 }
dsinclair82e17672016-10-11 12:38:01 -0700222
223 CJS_Array aDocs;
224 aDocs.SetElement(pRuntime, 0, CJS_Value(pRuntime, pJSDocument));
225
tsepezb4694242016-08-15 16:44:55 -0700226 if (aDocs.GetLength(pRuntime) > 0)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700227 vp << aDocs;
228 else
tsepezf3dc8c62016-08-10 06:29:29 -0700229 vp.GetJSValue()->SetNull(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700230
tsepez4cf55152016-11-02 14:37:54 -0700231 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700232}
233
Tom Sepezb1670b52017-02-16 17:01:00 -0800234bool app::calculate(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700235 CJS_PropValue& vp,
236 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700237 if (vp.IsSetting()) {
238 bool bVP;
239 vp >> bVP;
tsepez4cf55152016-11-02 14:37:54 -0700240 m_bCalculate = (bool)bVP;
Tom Sepezb1670b52017-02-16 17:01:00 -0800241 pRuntime->GetFormFillEnv()->GetInterForm()->EnableCalculate(
tsepez4cf55152016-11-02 14:37:54 -0700242 (bool)m_bCalculate);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700243 } else {
244 vp << (bool)m_bCalculate;
245 }
tsepez4cf55152016-11-02 14:37:54 -0700246 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700247}
248
Tom Sepezb1670b52017-02-16 17:01:00 -0800249bool app::formsVersion(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700250 CJS_PropValue& vp,
251 CFX_WideString& sError) {
252 if (vp.IsGetting()) {
253 vp << JS_NUM_FORMSVERSION;
254 return true;
255 }
256
257 return false;
258}
259
Tom Sepezb1670b52017-02-16 17:01:00 -0800260bool app::viewerType(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700261 CJS_PropValue& vp,
262 CFX_WideString& sError) {
263 if (vp.IsGetting()) {
264 vp << JS_STR_VIEWERTYPE;
265 return true;
266 }
267
268 return false;
269}
270
Tom Sepezb1670b52017-02-16 17:01:00 -0800271bool app::viewerVariation(CJS_Runtime* pRuntime,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700272 CJS_PropValue& vp,
273 CFX_WideString& sError) {
274 if (vp.IsGetting()) {
tsepez4cf55152016-11-02 14:37:54 -0700275 vp << JS_STR_VIEWERVARIATION;
276 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700277 }
278
tsepez4cf55152016-11-02 14:37:54 -0700279 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700280}
281
Tom Sepezb1670b52017-02-16 17:01:00 -0800282bool app::viewerVersion(CJS_Runtime* pRuntime,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700283 CJS_PropValue& vp,
284 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700285 if (!vp.IsGetting())
tsepez4cf55152016-11-02 14:37:54 -0700286 return false;
Tom Sepez51da0932015-11-25 16:05:49 -0800287#ifdef PDF_ENABLE_XFA
Tom Sepezb1670b52017-02-16 17:01:00 -0800288 CPDFXFA_Context* pXFAContext = pRuntime->GetFormFillEnv()->GetXFAContext();
dsinclair521b7502016-11-02 13:02:28 -0700289 if (pXFAContext->GetDocType() == 1 || pXFAContext->GetDocType() == 2) {
Tom Sepezd6278ba2015-09-08 16:34:37 -0700290 vp << JS_NUM_VIEWERVERSION_XFA;
tsepez4cf55152016-11-02 14:37:54 -0700291 return true;
Tom Sepezbf59a072015-10-21 14:07:23 -0700292 }
Tom Sepez40e9ff32015-11-30 12:39:54 -0800293#endif // PDF_ENABLE_XFA
Tom Sepezbf59a072015-10-21 14:07:23 -0700294 vp << JS_NUM_VIEWERVERSION;
tsepez4cf55152016-11-02 14:37:54 -0700295 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700296}
297
Tom Sepezb1670b52017-02-16 17:01:00 -0800298bool app::platform(CJS_Runtime* pRuntime,
Tom Sepezd6ae2af2017-02-16 11:49:55 -0800299 CJS_PropValue& vp,
300 CFX_WideString& sError) {
Jun Fanga0217b62015-12-02 13:57:18 +0800301 if (!vp.IsGetting())
tsepez4cf55152016-11-02 14:37:54 -0700302 return false;
Tom Sepez4d6fa832015-12-08 11:31:59 -0800303#ifdef PDF_ENABLE_XFA
Tom Sepezb1670b52017-02-16 17:01:00 -0800304 CPDFSDK_FormFillEnvironment* pFormFillEnv = pRuntime->GetFormFillEnv();
dsinclair82e17672016-10-11 12:38:01 -0700305 if (!pFormFillEnv)
tsepez4cf55152016-11-02 14:37:54 -0700306 return false;
dsinclair82e17672016-10-11 12:38:01 -0700307 CFX_WideString platfrom = pFormFillEnv->GetPlatform();
Tom Sepez4d6fa832015-12-08 11:31:59 -0800308 if (!platfrom.IsEmpty()) {
Jun Fanga0217b62015-12-02 13:57:18 +0800309 vp << platfrom;
tsepez4cf55152016-11-02 14:37:54 -0700310 return true;
Tom Sepez4d6fa832015-12-08 11:31:59 -0800311 }
312#endif
313 vp << JS_STR_PLATFORM;
tsepez4cf55152016-11-02 14:37:54 -0700314 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700315}
316
Tom Sepezb1670b52017-02-16 17:01:00 -0800317bool app::language(CJS_Runtime* pRuntime,
Tom Sepezd6ae2af2017-02-16 11:49:55 -0800318 CJS_PropValue& vp,
319 CFX_WideString& sError) {
Jun Fang487d1a92015-12-02 13:20:03 +0800320 if (!vp.IsGetting())
tsepez4cf55152016-11-02 14:37:54 -0700321 return false;
Tom Sepez4d6fa832015-12-08 11:31:59 -0800322#ifdef PDF_ENABLE_XFA
Tom Sepezb1670b52017-02-16 17:01:00 -0800323 CPDFSDK_FormFillEnvironment* pFormFillEnv = pRuntime->GetFormFillEnv();
dsinclair82e17672016-10-11 12:38:01 -0700324 if (!pFormFillEnv)
tsepez4cf55152016-11-02 14:37:54 -0700325 return false;
dsinclair82e17672016-10-11 12:38:01 -0700326 CFX_WideString language = pFormFillEnv->GetLanguage();
Tom Sepez4d6fa832015-12-08 11:31:59 -0800327 if (!language.IsEmpty()) {
Jun Fang487d1a92015-12-02 13:20:03 +0800328 vp << language;
tsepez4cf55152016-11-02 14:37:54 -0700329 return true;
Tom Sepez4d6fa832015-12-08 11:31:59 -0800330 }
331#endif
dsinclairf51e4dc2016-10-13 07:43:19 -0700332 vp << JS_STR_LANGUAGE;
tsepez4cf55152016-11-02 14:37:54 -0700333 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700334}
335
336// creates a new fdf object that contains no data
337// comment: need reader support
338// note:
dsinclair735606d2016-10-05 15:47:02 -0700339// CFDF_Document * CPDFSDK_FormFillEnvironment::NewFDF();
Tom Sepezb1670b52017-02-16 17:01:00 -0800340bool app::newFDF(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700341 const std::vector<CJS_Value>& params,
342 CJS_Value& vRet,
343 CFX_WideString& sError) {
344 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700345}
346// opens a specified pdf document and returns its document object
347// comment:need reader support
348// note: as defined in js reference, the proto of this function's fourth
349// parmeters, how old an fdf document while do not show it.
dsinclair735606d2016-10-05 15:47:02 -0700350// CFDF_Document * CPDFSDK_FormFillEnvironment::OpenFDF(string strPath,bool
351// bUserConv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700352
Tom Sepezb1670b52017-02-16 17:01:00 -0800353bool app::openFDF(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700354 const std::vector<CJS_Value>& params,
355 CJS_Value& vRet,
356 CFX_WideString& sError) {
357 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700358}
359
Tom Sepezb1670b52017-02-16 17:01:00 -0800360bool app::alert(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700361 const std::vector<CJS_Value>& params,
362 CJS_Value& vRet,
363 CFX_WideString& sError) {
Tom Sepezbd932572016-01-29 09:10:41 -0800364 std::vector<CJS_Value> newParams = JS_ExpandKeywordParams(
365 pRuntime, params, 4, L"cMsg", L"nIcon", L"nType", L"cTitle");
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700366
Tom Sepezbd932572016-01-29 09:10:41 -0800367 if (newParams[0].GetType() == CJS_Value::VT_unknown) {
tsepezcd5dc852016-09-08 11:23:24 -0700368 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);
tsepez4cf55152016-11-02 14:37:54 -0700369 return false;
Tom Sepezbd932572016-01-29 09:10:41 -0800370 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700371
dsinclair82e17672016-10-11 12:38:01 -0700372 CPDFSDK_FormFillEnvironment* pFormFillEnv = pRuntime->GetFormFillEnv();
373 if (!pFormFillEnv) {
tsepezf3dc8c62016-08-10 06:29:29 -0700374 vRet = CJS_Value(pRuntime, 0);
tsepez4cf55152016-11-02 14:37:54 -0700375 return true;
tsepeze1e7bd02016-08-08 13:03:16 -0700376 }
377
Tom Sepezbd932572016-01-29 09:10:41 -0800378 CFX_WideString swMsg;
379 if (newParams[0].GetType() == CJS_Value::VT_object) {
tsepeze5aff742016-08-08 09:49:42 -0700380 CJS_Array carray;
tsepezb4694242016-08-15 16:44:55 -0700381 if (newParams[0].ConvertToArray(pRuntime, carray)) {
Tom Sepezbd932572016-01-29 09:10:41 -0800382 swMsg = L"[";
383 CJS_Value element(pRuntime);
tsepezb4694242016-08-15 16:44:55 -0700384 for (int i = 0; i < carray.GetLength(pRuntime); ++i) {
Tom Sepezbd932572016-01-29 09:10:41 -0800385 if (i)
386 swMsg += L", ";
tsepezb4694242016-08-15 16:44:55 -0700387 carray.GetElement(pRuntime, i, element);
388 swMsg += element.ToCFXWideString(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700389 }
Tom Sepezbd932572016-01-29 09:10:41 -0800390 swMsg += L"]";
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700391 } else {
tsepezb4694242016-08-15 16:44:55 -0700392 swMsg = newParams[0].ToCFXWideString(pRuntime);
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700393 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700394 } else {
tsepezb4694242016-08-15 16:44:55 -0700395 swMsg = newParams[0].ToCFXWideString(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700396 }
397
Tom Sepezbd932572016-01-29 09:10:41 -0800398 int iIcon = 0;
399 if (newParams[1].GetType() != CJS_Value::VT_unknown)
tsepezb4694242016-08-15 16:44:55 -0700400 iIcon = newParams[1].ToInt(pRuntime);
Tom Sepezbd932572016-01-29 09:10:41 -0800401
402 int iType = 0;
403 if (newParams[2].GetType() != CJS_Value::VT_unknown)
tsepezb4694242016-08-15 16:44:55 -0700404 iType = newParams[2].ToInt(pRuntime);
Tom Sepezbd932572016-01-29 09:10:41 -0800405
406 CFX_WideString swTitle;
407 if (newParams[3].GetType() != CJS_Value::VT_unknown)
tsepezb4694242016-08-15 16:44:55 -0700408 swTitle = newParams[3].ToCFXWideString(pRuntime);
Tom Sepezbd932572016-01-29 09:10:41 -0800409 else
tsepezcd5dc852016-09-08 11:23:24 -0700410 swTitle = JSGetStringFromID(IDS_STRING_JSALERT);
Tom Sepezbd932572016-01-29 09:10:41 -0800411
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700412 pRuntime->BeginBlock();
dsinclair7cbe68e2016-10-12 11:56:23 -0700413 pFormFillEnv->KillFocusAnnot(0);
tsepeze1e7bd02016-08-08 13:03:16 -0700414
dsinclair82e17672016-10-11 12:38:01 -0700415 vRet = CJS_Value(pRuntime, pFormFillEnv->JS_appAlert(
416 swMsg.c_str(), swTitle.c_str(), iType, iIcon));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700417 pRuntime->EndBlock();
tsepez4cf55152016-11-02 14:37:54 -0700418 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700419}
420
Tom Sepezb1670b52017-02-16 17:01:00 -0800421bool app::beep(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700422 const std::vector<CJS_Value>& params,
423 CJS_Value& vRet,
424 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700425 if (params.size() == 1) {
dsinclair82e17672016-10-11 12:38:01 -0700426 pRuntime->GetFormFillEnv()->JS_appBeep(params[0].ToInt(pRuntime));
tsepez4cf55152016-11-02 14:37:54 -0700427 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700428 }
429
tsepezcd5dc852016-09-08 11:23:24 -0700430 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);
tsepez4cf55152016-11-02 14:37:54 -0700431 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700432}
433
Tom Sepezb1670b52017-02-16 17:01:00 -0800434bool app::findComponent(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700435 const std::vector<CJS_Value>& params,
436 CJS_Value& vRet,
437 CFX_WideString& sError) {
438 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700439}
440
Tom Sepezb1670b52017-02-16 17:01:00 -0800441bool app::popUpMenuEx(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700442 const std::vector<CJS_Value>& params,
443 CJS_Value& vRet,
444 CFX_WideString& sError) {
445 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700446}
447
Tom Sepezb1670b52017-02-16 17:01:00 -0800448bool app::fs(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) {
tsepez4cf55152016-11-02 14:37:54 -0700449 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700450}
451
Tom Sepezb1670b52017-02-16 17:01:00 -0800452bool app::setInterval(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700453 const std::vector<CJS_Value>& params,
454 CJS_Value& vRet,
455 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700456 if (params.size() > 2 || params.size() == 0) {
tsepezcd5dc852016-09-08 11:23:24 -0700457 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);
tsepez4cf55152016-11-02 14:37:54 -0700458 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700459 }
Tom Sepezc6ab1722015-02-05 15:27:25 -0800460
tsepezf3dc8c62016-08-10 06:29:29 -0700461 CFX_WideString script =
tsepezb4694242016-08-15 16:44:55 -0700462 params.size() > 0 ? params[0].ToCFXWideString(pRuntime) : L"";
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700463 if (script.IsEmpty()) {
tsepezcd5dc852016-09-08 11:23:24 -0700464 sError = JSGetStringFromID(IDS_STRING_JSAFNUMBER_KEYSTROKE);
tsepez4cf55152016-11-02 14:37:54 -0700465 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700466 }
467
tsepezb4694242016-08-15 16:44:55 -0700468 uint32_t dwInterval = params.size() > 1 ? params[1].ToInt(pRuntime) : 1000;
dsinclair2eb7c7d2016-08-18 09:58:19 -0700469
dsinclair82e17672016-10-11 12:38:01 -0700470 GlobalTimer* timerRef = new GlobalTimer(this, pRuntime->GetFormFillEnv(),
471 pRuntime, 0, script, dwInterval, 0);
tsepeza752edf2016-08-19 14:57:42 -0700472 m_Timers.insert(std::unique_ptr<GlobalTimer>(timerRef));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700473
tsepezb4694242016-08-15 16:44:55 -0700474 v8::Local<v8::Object> pRetObj =
475 pRuntime->NewFxDynamicObj(CJS_TimerObj::g_nObjDefnID);
476 CJS_TimerObj* pJS_TimerObj =
477 static_cast<CJS_TimerObj*>(pRuntime->GetObjectPrivate(pRetObj));
tsepez41a53ad2016-03-28 16:59:30 -0700478 TimerObj* pTimerObj = static_cast<TimerObj*>(pJS_TimerObj->GetEmbedObject());
dsinclair2eb7c7d2016-08-18 09:58:19 -0700479 pTimerObj->SetTimer(timerRef);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700480
tsepezf3dc8c62016-08-10 06:29:29 -0700481 vRet = CJS_Value(pRuntime, pRetObj);
tsepez4cf55152016-11-02 14:37:54 -0700482 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700483}
484
Tom Sepezb1670b52017-02-16 17:01:00 -0800485bool app::setTimeOut(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700486 const std::vector<CJS_Value>& params,
487 CJS_Value& vRet,
488 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700489 if (params.size() > 2 || params.size() == 0) {
tsepezcd5dc852016-09-08 11:23:24 -0700490 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);
tsepez4cf55152016-11-02 14:37:54 -0700491 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700492 }
Tom Sepezc6ab1722015-02-05 15:27:25 -0800493
tsepezb4694242016-08-15 16:44:55 -0700494 CFX_WideString script = params[0].ToCFXWideString(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700495 if (script.IsEmpty()) {
tsepezcd5dc852016-09-08 11:23:24 -0700496 sError = JSGetStringFromID(IDS_STRING_JSAFNUMBER_KEYSTROKE);
tsepez4cf55152016-11-02 14:37:54 -0700497 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700498 }
499
tsepezb4694242016-08-15 16:44:55 -0700500 uint32_t dwTimeOut = params.size() > 1 ? params[1].ToInt(pRuntime) : 1000;
tsepeza752edf2016-08-19 14:57:42 -0700501 GlobalTimer* timerRef =
dsinclair82e17672016-10-11 12:38:01 -0700502 new GlobalTimer(this, pRuntime->GetFormFillEnv(), pRuntime, 1, script,
503 dwTimeOut, dwTimeOut);
tsepeza752edf2016-08-19 14:57:42 -0700504 m_Timers.insert(std::unique_ptr<GlobalTimer>(timerRef));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700505
tsepezb4694242016-08-15 16:44:55 -0700506 v8::Local<v8::Object> pRetObj =
507 pRuntime->NewFxDynamicObj(CJS_TimerObj::g_nObjDefnID);
tsepez41a53ad2016-03-28 16:59:30 -0700508
tsepezb4694242016-08-15 16:44:55 -0700509 CJS_TimerObj* pJS_TimerObj =
510 static_cast<CJS_TimerObj*>(pRuntime->GetObjectPrivate(pRetObj));
tsepez41a53ad2016-03-28 16:59:30 -0700511
512 TimerObj* pTimerObj = static_cast<TimerObj*>(pJS_TimerObj->GetEmbedObject());
dsinclair2eb7c7d2016-08-18 09:58:19 -0700513 pTimerObj->SetTimer(timerRef);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700514
tsepezf3dc8c62016-08-10 06:29:29 -0700515 vRet = CJS_Value(pRuntime, pRetObj);
tsepez4cf55152016-11-02 14:37:54 -0700516 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700517}
518
Tom Sepezb1670b52017-02-16 17:01:00 -0800519bool app::clearTimeOut(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700520 const std::vector<CJS_Value>& params,
521 CJS_Value& vRet,
522 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700523 if (params.size() != 1) {
tsepezcd5dc852016-09-08 11:23:24 -0700524 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);
tsepez4cf55152016-11-02 14:37:54 -0700525 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700526 }
527
Tom Sepezb1670b52017-02-16 17:01:00 -0800528 app::ClearTimerCommon(pRuntime, params[0]);
tsepez4cf55152016-11-02 14:37:54 -0700529 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700530}
531
Tom Sepezb1670b52017-02-16 17:01:00 -0800532bool app::clearInterval(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700533 const std::vector<CJS_Value>& params,
534 CJS_Value& vRet,
535 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700536 if (params.size() != 1) {
tsepezcd5dc852016-09-08 11:23:24 -0700537 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);
tsepez4cf55152016-11-02 14:37:54 -0700538 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700539 }
540
Tom Sepezb1670b52017-02-16 17:01:00 -0800541 app::ClearTimerCommon(pRuntime, params[0]);
tsepez4cf55152016-11-02 14:37:54 -0700542 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700543}
544
tsepezb4694242016-08-15 16:44:55 -0700545void app::ClearTimerCommon(CJS_Runtime* pRuntime, const CJS_Value& param) {
tsepez40faa792016-07-15 17:58:02 -0700546 if (param.GetType() != CJS_Value::VT_object)
tsepez41a53ad2016-03-28 16:59:30 -0700547 return;
548
tsepezb4694242016-08-15 16:44:55 -0700549 v8::Local<v8::Object> pObj = param.ToV8Object(pRuntime);
550 if (CFXJS_Engine::GetObjDefnID(pObj) != CJS_TimerObj::g_nObjDefnID)
tsepez41a53ad2016-03-28 16:59:30 -0700551 return;
552
tsepezb4694242016-08-15 16:44:55 -0700553 CJS_Object* pJSObj = param.ToCJSObject(pRuntime);
tsepez41a53ad2016-03-28 16:59:30 -0700554 if (!pJSObj)
555 return;
556
557 TimerObj* pTimerObj = static_cast<TimerObj*>(pJSObj->GetEmbedObject());
558 if (!pTimerObj)
559 return;
560
tsepeze3ff76b2016-08-08 11:58:47 -0700561 GlobalTimer::Cancel(pTimerObj->GetTimerID());
tsepez41a53ad2016-03-28 16:59:30 -0700562}
563
Tom Sepezb1670b52017-02-16 17:01:00 -0800564bool app::execMenuItem(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700565 const std::vector<CJS_Value>& params,
566 CJS_Value& vRet,
567 CFX_WideString& sError) {
568 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700569}
570
tsepeze3ff76b2016-08-08 11:58:47 -0700571void app::TimerProc(GlobalTimer* pTimer) {
Lei Zhang2d5a0e12015-10-05 17:00:03 -0700572 CJS_Runtime* pRuntime = pTimer->GetRuntime();
tsepez8ca63de2016-08-05 17:12:27 -0700573 if (pRuntime && (!pTimer->IsOneShot() || pTimer->GetTimeOut() > 0))
574 RunJsScript(pRuntime, pTimer->GetJScript());
575}
Lei Zhang2d5a0e12015-10-05 17:00:03 -0700576
tsepeze3ff76b2016-08-08 11:58:47 -0700577void app::CancelProc(GlobalTimer* pTimer) {
tsepeza752edf2016-08-19 14:57:42 -0700578 m_Timers.erase(pdfium::FakeUniquePtr<GlobalTimer>(pTimer));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700579}
580
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700581void app::RunJsScript(CJS_Runtime* pRuntime, const CFX_WideString& wsScript) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700582 if (!pRuntime->IsBlocking()) {
Tom Sepezd6ae2af2017-02-16 11:49:55 -0800583 IJS_EventContext* pContext = pRuntime->NewEventContext();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700584 pContext->OnExternal_Exec();
585 CFX_WideString wtInfo;
Tom Sepez33420902015-10-13 15:00:10 -0700586 pContext->RunScript(wsScript, &wtInfo);
Tom Sepezd6ae2af2017-02-16 11:49:55 -0800587 pRuntime->ReleaseEventContext(pContext);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700588 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700589}
590
Tom Sepezb1670b52017-02-16 17:01:00 -0800591bool app::goBack(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700592 const std::vector<CJS_Value>& params,
593 CJS_Value& vRet,
594 CFX_WideString& sError) {
595 // Not supported.
596 return true;
597}
598
Tom Sepezb1670b52017-02-16 17:01:00 -0800599bool app::goForward(CJS_Runtime* pRuntime,
Lei Zhang945fdb72015-11-11 10:18:16 -0800600 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700601 CJS_Value& vRet,
602 CFX_WideString& sError) {
Tom Sepezc6ab1722015-02-05 15:27:25 -0800603 // Not supported.
tsepez4cf55152016-11-02 14:37:54 -0700604 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700605}
606
Tom Sepezb1670b52017-02-16 17:01:00 -0800607bool app::mailMsg(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700608 const std::vector<CJS_Value>& params,
609 CJS_Value& vRet,
610 CFX_WideString& sError) {
Tom Sepeze5fbd7a2016-01-29 17:05:08 -0800611 std::vector<CJS_Value> newParams =
612 JS_ExpandKeywordParams(pRuntime, params, 6, L"bUI", L"cTo", L"cCc",
613 L"cBcc", L"cSubject", L"cMsg");
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700614
Tom Sepeze5fbd7a2016-01-29 17:05:08 -0800615 if (newParams[0].GetType() == CJS_Value::VT_unknown) {
tsepezcd5dc852016-09-08 11:23:24 -0700616 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);
tsepez4cf55152016-11-02 14:37:54 -0700617 return false;
Tom Sepeze5fbd7a2016-01-29 17:05:08 -0800618 }
tsepezb4694242016-08-15 16:44:55 -0700619 bool bUI = newParams[0].ToBool(pRuntime);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700620
Tom Sepeze5fbd7a2016-01-29 17:05:08 -0800621 CFX_WideString cTo;
622 if (newParams[1].GetType() != CJS_Value::VT_unknown) {
tsepezb4694242016-08-15 16:44:55 -0700623 cTo = newParams[1].ToCFXWideString(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700624 } else {
Tom Sepeze5fbd7a2016-01-29 17:05:08 -0800625 if (!bUI) {
626 // cTo parameter required when UI not invoked.
tsepezcd5dc852016-09-08 11:23:24 -0700627 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);
tsepez4cf55152016-11-02 14:37:54 -0700628 return false;
Tom Sepeze5fbd7a2016-01-29 17:05:08 -0800629 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700630 }
Tom Sepezc6ab1722015-02-05 15:27:25 -0800631
Tom Sepeze5fbd7a2016-01-29 17:05:08 -0800632 CFX_WideString cCc;
633 if (newParams[2].GetType() != CJS_Value::VT_unknown)
tsepezb4694242016-08-15 16:44:55 -0700634 cCc = newParams[2].ToCFXWideString(pRuntime);
Tom Sepeze5fbd7a2016-01-29 17:05:08 -0800635
636 CFX_WideString cBcc;
637 if (newParams[3].GetType() != CJS_Value::VT_unknown)
tsepezb4694242016-08-15 16:44:55 -0700638 cBcc = newParams[3].ToCFXWideString(pRuntime);
Tom Sepeze5fbd7a2016-01-29 17:05:08 -0800639
640 CFX_WideString cSubject;
641 if (newParams[4].GetType() != CJS_Value::VT_unknown)
tsepezb4694242016-08-15 16:44:55 -0700642 cSubject = newParams[4].ToCFXWideString(pRuntime);
Tom Sepeze5fbd7a2016-01-29 17:05:08 -0800643
644 CFX_WideString cMsg;
645 if (newParams[5].GetType() != CJS_Value::VT_unknown)
tsepezb4694242016-08-15 16:44:55 -0700646 cMsg = newParams[5].ToCFXWideString(pRuntime);
Tom Sepeze5fbd7a2016-01-29 17:05:08 -0800647
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700648 pRuntime->BeginBlock();
Tom Sepezb1670b52017-02-16 17:01:00 -0800649 pRuntime->GetFormFillEnv()->JS_docmailForm(nullptr, 0, bUI, cTo.c_str(),
dsinclair4526faf2016-10-11 10:54:49 -0700650 cSubject.c_str(), cCc.c_str(),
651 cBcc.c_str(), cMsg.c_str());
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700652 pRuntime->EndBlock();
tsepez4cf55152016-11-02 14:37:54 -0700653 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700654}
655
Tom Sepezb1670b52017-02-16 17:01:00 -0800656bool app::launchURL(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700657 const std::vector<CJS_Value>& params,
658 CJS_Value& vRet,
659 CFX_WideString& sError) {
Tom Sepezc6ab1722015-02-05 15:27:25 -0800660 // Unsafe, not supported.
tsepez4cf55152016-11-02 14:37:54 -0700661 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700662}
663
Tom Sepezb1670b52017-02-16 17:01:00 -0800664bool app::runtimeHighlight(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700665 CJS_PropValue& vp,
666 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700667 if (vp.IsSetting()) {
668 vp >> m_bRuntimeHighLight;
669 } else {
670 vp << m_bRuntimeHighLight;
671 }
tsepez4cf55152016-11-02 14:37:54 -0700672 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700673}
674
Tom Sepezb1670b52017-02-16 17:01:00 -0800675bool app::fullscreen(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700676 CJS_PropValue& vp,
677 CFX_WideString& sError) {
678 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700679}
680
Tom Sepezb1670b52017-02-16 17:01:00 -0800681bool app::popUpMenu(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700682 const std::vector<CJS_Value>& params,
683 CJS_Value& vRet,
684 CFX_WideString& sError) {
685 return false;
686}
687
Tom Sepezb1670b52017-02-16 17:01:00 -0800688bool app::browseForDoc(CJS_Runtime* pRuntime,
Lei Zhang945fdb72015-11-11 10:18:16 -0800689 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700690 CJS_Value& vRet,
691 CFX_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
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700696CFX_WideString app::SysPathToPDFPath(const CFX_WideString& sOldPath) {
697 CFX_WideString sRet = L"/";
Tom Sepezc6ab1722015-02-05 15:27:25 -0800698
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700699 for (int i = 0, sz = sOldPath.GetLength(); i < sz; i++) {
700 wchar_t c = sOldPath.GetAt(i);
701 if (c == L':') {
702 } else {
703 if (c == L'\\') {
704 sRet += L"/";
705 } else {
706 sRet += c;
707 }
708 }
709 }
Tom Sepezc6ab1722015-02-05 15:27:25 -0800710
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700711 return sRet;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700712}
713
Tom Sepezb1670b52017-02-16 17:01:00 -0800714bool app::newDoc(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700715 const std::vector<CJS_Value>& params,
716 CJS_Value& vRet,
717 CFX_WideString& sError) {
718 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700719}
720
Tom Sepezb1670b52017-02-16 17:01:00 -0800721bool app::openDoc(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700722 const std::vector<CJS_Value>& params,
723 CJS_Value& vRet,
724 CFX_WideString& sError) {
725 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700726}
727
Tom Sepezb1670b52017-02-16 17:01:00 -0800728bool app::response(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700729 const std::vector<CJS_Value>& params,
730 CJS_Value& vRet,
731 CFX_WideString& sError) {
Tom Sepez58fb36a2016-02-01 10:32:14 -0800732 std::vector<CJS_Value> newParams =
733 JS_ExpandKeywordParams(pRuntime, params, 5, L"cQuestion", L"cTitle",
734 L"cDefault", L"bPassword", L"cLabel");
Tom Sepez621d4de2014-07-29 14:01:21 -0700735
Tom Sepez58fb36a2016-02-01 10:32:14 -0800736 if (newParams[0].GetType() == CJS_Value::VT_unknown) {
tsepezcd5dc852016-09-08 11:23:24 -0700737 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);
tsepez4cf55152016-11-02 14:37:54 -0700738 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700739 }
tsepezb4694242016-08-15 16:44:55 -0700740 CFX_WideString swQuestion = newParams[0].ToCFXWideString(pRuntime);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700741
Tom Sepez58fb36a2016-02-01 10:32:14 -0800742 CFX_WideString swTitle = L"PDF";
743 if (newParams[1].GetType() != CJS_Value::VT_unknown)
tsepezb4694242016-08-15 16:44:55 -0700744 swTitle = newParams[1].ToCFXWideString(pRuntime);
Tom Sepez58fb36a2016-02-01 10:32:14 -0800745
746 CFX_WideString swDefault;
747 if (newParams[2].GetType() != CJS_Value::VT_unknown)
tsepezb4694242016-08-15 16:44:55 -0700748 swDefault = newParams[2].ToCFXWideString(pRuntime);
Tom Sepez58fb36a2016-02-01 10:32:14 -0800749
750 bool bPassword = false;
751 if (newParams[3].GetType() != CJS_Value::VT_unknown)
tsepezb4694242016-08-15 16:44:55 -0700752 bPassword = newParams[3].ToBool(pRuntime);
Tom Sepez58fb36a2016-02-01 10:32:14 -0800753
754 CFX_WideString swLabel;
755 if (newParams[4].GetType() != CJS_Value::VT_unknown)
tsepezb4694242016-08-15 16:44:55 -0700756 swLabel = newParams[4].ToCFXWideString(pRuntime);
Tom Sepez621d4de2014-07-29 14:01:21 -0700757
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700758 const int MAX_INPUT_BYTES = 2048;
Lei Zhangaa8bf7e2015-12-24 19:13:32 -0800759 std::unique_ptr<char[]> pBuff(new char[MAX_INPUT_BYTES + 2]);
Lei Zhangdb5256f2015-10-02 10:11:43 -0700760 memset(pBuff.get(), 0, MAX_INPUT_BYTES + 2);
Tom Sepez58fb36a2016-02-01 10:32:14 -0800761
Tom Sepezb1670b52017-02-16 17:01:00 -0800762 int nLengthBytes = pRuntime->GetFormFillEnv()->JS_appResponse(
Lei Zhangdb5256f2015-10-02 10:11:43 -0700763 swQuestion.c_str(), swTitle.c_str(), swDefault.c_str(), swLabel.c_str(),
Tom Sepez58fb36a2016-02-01 10:32:14 -0800764 bPassword, pBuff.get(), MAX_INPUT_BYTES);
765
766 if (nLengthBytes < 0 || nLengthBytes > MAX_INPUT_BYTES) {
tsepezcd5dc852016-09-08 11:23:24 -0700767 sError = JSGetStringFromID(IDS_STRING_JSPARAM_TOOLONG);
tsepez4cf55152016-11-02 14:37:54 -0700768 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700769 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700770
tsepezf3dc8c62016-08-10 06:29:29 -0700771 vRet = CJS_Value(pRuntime, CFX_WideString::FromUTF16LE(
772 reinterpret_cast<uint16_t*>(pBuff.get()),
773 nLengthBytes / sizeof(uint16_t))
774 .c_str());
775
tsepez4cf55152016-11-02 14:37:54 -0700776 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700777}
778
Tom Sepezb1670b52017-02-16 17:01:00 -0800779bool app::media(CJS_Runtime* pRuntime,
Tom Sepezd6ae2af2017-02-16 11:49:55 -0800780 CJS_PropValue& vp,
781 CFX_WideString& sError) {
tsepez4cf55152016-11-02 14:37:54 -0700782 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700783}
784
Tom Sepezb1670b52017-02-16 17:01:00 -0800785bool app::execDialog(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700786 const std::vector<CJS_Value>& params,
787 CJS_Value& vRet,
788 CFX_WideString& sError) {
789 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700790}