blob: 3a8bf088f361fc04bb768227f416a6a61b1430dd [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;
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,
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[] = {
Tom Sepez4d5b8c52017-02-21 15:17:07 -0800164 {"activeDocs", get_activeDocs_static, set_activeDocs_static},
165 {"calculate", get_calculate_static, set_calculate_static},
166 {"formsVersion", get_formsVersion_static, set_formsVersion_static},
167 {"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},
172 {"runtimeHighlight", get_runtimeHighlight_static,
Tom Sepez04557b82017-02-16 09:43:10 -0800173 set_runtimeHighlight_static},
Tom Sepez4d5b8c52017-02-21 15:17:07 -0800174 {"viewerType", get_viewerType_static, set_viewerType_static},
175 {"viewerVariation", get_viewerVariation_static, set_viewerVariation_static},
176 {"viewerVersion", get_viewerVersion_static, set_viewerVersion_static},
Tom Sepez04557b82017-02-16 09:43:10 -0800177 {0, 0, 0}};
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700178
Tom Sepez9b99b632017-02-21 15:05:57 -0800179JSMethodSpec CJS_App::MethodSpecs[] = {{"alert", alert_static},
180 {"beep", beep_static},
181 {"browseForDoc", browseForDoc_static},
182 {"clearInterval", clearInterval_static},
183 {"clearTimeOut", clearTimeOut_static},
184 {"execDialog", execDialog_static},
185 {"execMenuItem", execMenuItem_static},
186 {"findComponent", findComponent_static},
187 {"goBack", goBack_static},
188 {"goForward", goForward_static},
189 {"launchURL", launchURL_static},
190 {"mailMsg", mailMsg_static},
191 {"newFDF", newFDF_static},
192 {"newDoc", newDoc_static},
193 {"openDoc", openDoc_static},
194 {"openFDF", openFDF_static},
195 {"popUpMenuEx", popUpMenuEx_static},
196 {"popUpMenu", popUpMenu_static},
197 {"response", response_static},
198 {"setInterval", setInterval_static},
199 {"setTimeOut", setTimeOut_static},
Tom Sepez04557b82017-02-16 09:43:10 -0800200 {0, 0}};
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700201
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700202IMPLEMENT_JS_CLASS(CJS_App, app)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700203
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700204app::app(CJS_Object* pJSObject)
205 : CJS_EmbedObj(pJSObject), m_bCalculate(true), m_bRuntimeHighLight(false) {}
206
Lei Zhang2b1a2d52015-08-14 22:16:22 -0700207app::~app() {
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700208}
209
Tom Sepezb1670b52017-02-16 17:01:00 -0800210bool app::activeDocs(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700211 CJS_PropValue& vp,
212 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700213 if (!vp.IsGetting())
tsepez4cf55152016-11-02 14:37:54 -0700214 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700215
dsinclair82e17672016-10-11 12:38:01 -0700216 CJS_Document* pJSDocument = nullptr;
217 v8::Local<v8::Object> pObj = pRuntime->GetThisObj();
Tom Sepezc5a14722017-02-24 15:31:12 -0800218 if (CFXJS_Engine::GetObjDefnID(pObj) == CJS_Document::g_nObjDefnID)
dsinclair82e17672016-10-11 12:38:01 -0700219 pJSDocument = static_cast<CJS_Document*>(pRuntime->GetObjectPrivate(pObj));
dsinclair82e17672016-10-11 12:38:01 -0700220
221 CJS_Array aDocs;
222 aDocs.SetElement(pRuntime, 0, CJS_Value(pRuntime, pJSDocument));
tsepezb4694242016-08-15 16:44:55 -0700223 if (aDocs.GetLength(pRuntime) > 0)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700224 vp << aDocs;
225 else
tsepezf3dc8c62016-08-10 06:29:29 -0700226 vp.GetJSValue()->SetNull(pRuntime);
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
Tom Sepezb1670b52017-02-16 17:01:00 -0800231bool app::calculate(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700232 CJS_PropValue& vp,
233 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700234 if (vp.IsSetting()) {
235 bool bVP;
236 vp >> bVP;
tsepez4cf55152016-11-02 14:37:54 -0700237 m_bCalculate = (bool)bVP;
Tom Sepezb1670b52017-02-16 17:01:00 -0800238 pRuntime->GetFormFillEnv()->GetInterForm()->EnableCalculate(
tsepez4cf55152016-11-02 14:37:54 -0700239 (bool)m_bCalculate);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700240 } else {
241 vp << (bool)m_bCalculate;
242 }
tsepez4cf55152016-11-02 14:37:54 -0700243 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700244}
245
Tom Sepezb1670b52017-02-16 17:01:00 -0800246bool app::formsVersion(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700247 CJS_PropValue& vp,
248 CFX_WideString& sError) {
249 if (vp.IsGetting()) {
250 vp << JS_NUM_FORMSVERSION;
251 return true;
252 }
253
254 return false;
255}
256
Tom Sepezb1670b52017-02-16 17:01:00 -0800257bool app::viewerType(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700258 CJS_PropValue& vp,
259 CFX_WideString& sError) {
260 if (vp.IsGetting()) {
261 vp << JS_STR_VIEWERTYPE;
262 return true;
263 }
264
265 return false;
266}
267
Tom Sepezb1670b52017-02-16 17:01:00 -0800268bool app::viewerVariation(CJS_Runtime* pRuntime,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700269 CJS_PropValue& vp,
270 CFX_WideString& sError) {
271 if (vp.IsGetting()) {
tsepez4cf55152016-11-02 14:37:54 -0700272 vp << JS_STR_VIEWERVARIATION;
273 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700274 }
275
tsepez4cf55152016-11-02 14:37:54 -0700276 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700277}
278
Tom Sepezb1670b52017-02-16 17:01:00 -0800279bool app::viewerVersion(CJS_Runtime* pRuntime,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700280 CJS_PropValue& vp,
281 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700282 if (!vp.IsGetting())
tsepez4cf55152016-11-02 14:37:54 -0700283 return false;
Tom Sepez51da0932015-11-25 16:05:49 -0800284#ifdef PDF_ENABLE_XFA
Tom Sepezb1670b52017-02-16 17:01:00 -0800285 CPDFXFA_Context* pXFAContext = pRuntime->GetFormFillEnv()->GetXFAContext();
dsinclair521b7502016-11-02 13:02:28 -0700286 if (pXFAContext->GetDocType() == 1 || pXFAContext->GetDocType() == 2) {
Tom Sepezd6278ba2015-09-08 16:34:37 -0700287 vp << JS_NUM_VIEWERVERSION_XFA;
tsepez4cf55152016-11-02 14:37:54 -0700288 return true;
Tom Sepezbf59a072015-10-21 14:07:23 -0700289 }
Tom Sepez40e9ff32015-11-30 12:39:54 -0800290#endif // PDF_ENABLE_XFA
Tom Sepezbf59a072015-10-21 14:07:23 -0700291 vp << JS_NUM_VIEWERVERSION;
tsepez4cf55152016-11-02 14:37:54 -0700292 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700293}
294
Tom Sepezb1670b52017-02-16 17:01:00 -0800295bool app::platform(CJS_Runtime* pRuntime,
Tom Sepezd6ae2af2017-02-16 11:49:55 -0800296 CJS_PropValue& vp,
297 CFX_WideString& sError) {
Jun Fanga0217b62015-12-02 13:57:18 +0800298 if (!vp.IsGetting())
tsepez4cf55152016-11-02 14:37:54 -0700299 return false;
Tom Sepez4d6fa832015-12-08 11:31:59 -0800300#ifdef PDF_ENABLE_XFA
Tom Sepezb1670b52017-02-16 17:01:00 -0800301 CPDFSDK_FormFillEnvironment* pFormFillEnv = pRuntime->GetFormFillEnv();
dsinclair82e17672016-10-11 12:38:01 -0700302 if (!pFormFillEnv)
tsepez4cf55152016-11-02 14:37:54 -0700303 return false;
dsinclair82e17672016-10-11 12:38:01 -0700304 CFX_WideString platfrom = pFormFillEnv->GetPlatform();
Tom Sepez4d6fa832015-12-08 11:31:59 -0800305 if (!platfrom.IsEmpty()) {
Jun Fanga0217b62015-12-02 13:57:18 +0800306 vp << platfrom;
tsepez4cf55152016-11-02 14:37:54 -0700307 return true;
Tom Sepez4d6fa832015-12-08 11:31:59 -0800308 }
309#endif
310 vp << JS_STR_PLATFORM;
tsepez4cf55152016-11-02 14:37:54 -0700311 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700312}
313
Tom Sepezb1670b52017-02-16 17:01:00 -0800314bool app::language(CJS_Runtime* pRuntime,
Tom Sepezd6ae2af2017-02-16 11:49:55 -0800315 CJS_PropValue& vp,
316 CFX_WideString& sError) {
Jun Fang487d1a92015-12-02 13:20:03 +0800317 if (!vp.IsGetting())
tsepez4cf55152016-11-02 14:37:54 -0700318 return false;
Tom Sepez4d6fa832015-12-08 11:31:59 -0800319#ifdef PDF_ENABLE_XFA
Tom Sepezb1670b52017-02-16 17:01:00 -0800320 CPDFSDK_FormFillEnvironment* pFormFillEnv = pRuntime->GetFormFillEnv();
dsinclair82e17672016-10-11 12:38:01 -0700321 if (!pFormFillEnv)
tsepez4cf55152016-11-02 14:37:54 -0700322 return false;
dsinclair82e17672016-10-11 12:38:01 -0700323 CFX_WideString language = pFormFillEnv->GetLanguage();
Tom Sepez4d6fa832015-12-08 11:31:59 -0800324 if (!language.IsEmpty()) {
Jun Fang487d1a92015-12-02 13:20:03 +0800325 vp << language;
tsepez4cf55152016-11-02 14:37:54 -0700326 return true;
Tom Sepez4d6fa832015-12-08 11:31:59 -0800327 }
328#endif
dsinclairf51e4dc2016-10-13 07:43:19 -0700329 vp << JS_STR_LANGUAGE;
tsepez4cf55152016-11-02 14:37:54 -0700330 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700331}
332
333// creates a new fdf object that contains no data
334// comment: need reader support
335// note:
dsinclair735606d2016-10-05 15:47:02 -0700336// CFDF_Document * CPDFSDK_FormFillEnvironment::NewFDF();
Tom Sepezb1670b52017-02-16 17:01:00 -0800337bool app::newFDF(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700338 const std::vector<CJS_Value>& params,
339 CJS_Value& vRet,
340 CFX_WideString& sError) {
341 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700342}
343// opens a specified pdf document and returns its document object
344// comment:need reader support
345// note: as defined in js reference, the proto of this function's fourth
346// parmeters, how old an fdf document while do not show it.
dsinclair735606d2016-10-05 15:47:02 -0700347// CFDF_Document * CPDFSDK_FormFillEnvironment::OpenFDF(string strPath,bool
348// bUserConv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700349
Tom Sepezb1670b52017-02-16 17:01:00 -0800350bool app::openFDF(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700351 const std::vector<CJS_Value>& params,
352 CJS_Value& vRet,
353 CFX_WideString& sError) {
354 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700355}
356
Tom Sepezb1670b52017-02-16 17:01:00 -0800357bool app::alert(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700358 const std::vector<CJS_Value>& params,
359 CJS_Value& vRet,
360 CFX_WideString& sError) {
Tom Sepezbd932572016-01-29 09:10:41 -0800361 std::vector<CJS_Value> newParams = JS_ExpandKeywordParams(
362 pRuntime, params, 4, L"cMsg", L"nIcon", L"nType", L"cTitle");
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700363
Tom Sepezbd932572016-01-29 09:10:41 -0800364 if (newParams[0].GetType() == CJS_Value::VT_unknown) {
tsepezcd5dc852016-09-08 11:23:24 -0700365 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);
tsepez4cf55152016-11-02 14:37:54 -0700366 return false;
Tom Sepezbd932572016-01-29 09:10:41 -0800367 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700368
dsinclair82e17672016-10-11 12:38:01 -0700369 CPDFSDK_FormFillEnvironment* pFormFillEnv = pRuntime->GetFormFillEnv();
370 if (!pFormFillEnv) {
tsepezf3dc8c62016-08-10 06:29:29 -0700371 vRet = CJS_Value(pRuntime, 0);
tsepez4cf55152016-11-02 14:37:54 -0700372 return true;
tsepeze1e7bd02016-08-08 13:03:16 -0700373 }
374
Tom Sepezbd932572016-01-29 09:10:41 -0800375 CFX_WideString swMsg;
376 if (newParams[0].GetType() == CJS_Value::VT_object) {
tsepeze5aff742016-08-08 09:49:42 -0700377 CJS_Array carray;
tsepezb4694242016-08-15 16:44:55 -0700378 if (newParams[0].ConvertToArray(pRuntime, carray)) {
Tom Sepezbd932572016-01-29 09:10:41 -0800379 swMsg = L"[";
380 CJS_Value element(pRuntime);
tsepezb4694242016-08-15 16:44:55 -0700381 for (int i = 0; i < carray.GetLength(pRuntime); ++i) {
Tom Sepezbd932572016-01-29 09:10:41 -0800382 if (i)
383 swMsg += L", ";
tsepezb4694242016-08-15 16:44:55 -0700384 carray.GetElement(pRuntime, i, element);
385 swMsg += element.ToCFXWideString(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700386 }
Tom Sepezbd932572016-01-29 09:10:41 -0800387 swMsg += L"]";
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700388 } else {
tsepezb4694242016-08-15 16:44:55 -0700389 swMsg = newParams[0].ToCFXWideString(pRuntime);
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700390 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700391 } else {
tsepezb4694242016-08-15 16:44:55 -0700392 swMsg = newParams[0].ToCFXWideString(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700393 }
394
Tom Sepezbd932572016-01-29 09:10:41 -0800395 int iIcon = 0;
396 if (newParams[1].GetType() != CJS_Value::VT_unknown)
tsepezb4694242016-08-15 16:44:55 -0700397 iIcon = newParams[1].ToInt(pRuntime);
Tom Sepezbd932572016-01-29 09:10:41 -0800398
399 int iType = 0;
400 if (newParams[2].GetType() != CJS_Value::VT_unknown)
tsepezb4694242016-08-15 16:44:55 -0700401 iType = newParams[2].ToInt(pRuntime);
Tom Sepezbd932572016-01-29 09:10:41 -0800402
403 CFX_WideString swTitle;
404 if (newParams[3].GetType() != CJS_Value::VT_unknown)
tsepezb4694242016-08-15 16:44:55 -0700405 swTitle = newParams[3].ToCFXWideString(pRuntime);
Tom Sepezbd932572016-01-29 09:10:41 -0800406 else
tsepezcd5dc852016-09-08 11:23:24 -0700407 swTitle = JSGetStringFromID(IDS_STRING_JSALERT);
Tom Sepezbd932572016-01-29 09:10:41 -0800408
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700409 pRuntime->BeginBlock();
dsinclair7cbe68e2016-10-12 11:56:23 -0700410 pFormFillEnv->KillFocusAnnot(0);
tsepeze1e7bd02016-08-08 13:03:16 -0700411
dsinclair82e17672016-10-11 12:38:01 -0700412 vRet = CJS_Value(pRuntime, pFormFillEnv->JS_appAlert(
413 swMsg.c_str(), swTitle.c_str(), iType, iIcon));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700414 pRuntime->EndBlock();
tsepez4cf55152016-11-02 14:37:54 -0700415 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700416}
417
Tom Sepezb1670b52017-02-16 17:01:00 -0800418bool app::beep(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700419 const std::vector<CJS_Value>& params,
420 CJS_Value& vRet,
421 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700422 if (params.size() == 1) {
dsinclair82e17672016-10-11 12:38:01 -0700423 pRuntime->GetFormFillEnv()->JS_appBeep(params[0].ToInt(pRuntime));
tsepez4cf55152016-11-02 14:37:54 -0700424 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700425 }
426
tsepezcd5dc852016-09-08 11:23:24 -0700427 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);
tsepez4cf55152016-11-02 14:37:54 -0700428 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700429}
430
Tom Sepezb1670b52017-02-16 17:01:00 -0800431bool app::findComponent(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700432 const std::vector<CJS_Value>& params,
433 CJS_Value& vRet,
434 CFX_WideString& sError) {
435 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700436}
437
Tom Sepezb1670b52017-02-16 17:01:00 -0800438bool app::popUpMenuEx(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700439 const std::vector<CJS_Value>& params,
440 CJS_Value& vRet,
441 CFX_WideString& sError) {
442 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700443}
444
Tom Sepezb1670b52017-02-16 17:01:00 -0800445bool app::fs(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) {
tsepez4cf55152016-11-02 14:37:54 -0700446 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700447}
448
Tom Sepezb1670b52017-02-16 17:01:00 -0800449bool app::setInterval(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700450 const std::vector<CJS_Value>& params,
451 CJS_Value& vRet,
452 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700453 if (params.size() > 2 || params.size() == 0) {
tsepezcd5dc852016-09-08 11:23:24 -0700454 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);
tsepez4cf55152016-11-02 14:37:54 -0700455 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700456 }
Tom Sepezc6ab1722015-02-05 15:27:25 -0800457
tsepezf3dc8c62016-08-10 06:29:29 -0700458 CFX_WideString script =
tsepezb4694242016-08-15 16:44:55 -0700459 params.size() > 0 ? params[0].ToCFXWideString(pRuntime) : L"";
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700460 if (script.IsEmpty()) {
tsepezcd5dc852016-09-08 11:23:24 -0700461 sError = JSGetStringFromID(IDS_STRING_JSAFNUMBER_KEYSTROKE);
tsepez4cf55152016-11-02 14:37:54 -0700462 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700463 }
464
tsepezb4694242016-08-15 16:44:55 -0700465 uint32_t dwInterval = params.size() > 1 ? params[1].ToInt(pRuntime) : 1000;
dsinclair2eb7c7d2016-08-18 09:58:19 -0700466
dsinclair82e17672016-10-11 12:38:01 -0700467 GlobalTimer* timerRef = new GlobalTimer(this, pRuntime->GetFormFillEnv(),
468 pRuntime, 0, script, dwInterval, 0);
tsepeza752edf2016-08-19 14:57:42 -0700469 m_Timers.insert(std::unique_ptr<GlobalTimer>(timerRef));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700470
tsepezb4694242016-08-15 16:44:55 -0700471 v8::Local<v8::Object> pRetObj =
472 pRuntime->NewFxDynamicObj(CJS_TimerObj::g_nObjDefnID);
Tom Sepezc5a14722017-02-24 15:31:12 -0800473 if (pRetObj.IsEmpty())
474 return false;
475
tsepezb4694242016-08-15 16:44:55 -0700476 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);
Tom Sepezc5a14722017-02-24 15:31:12 -0800508 if (pRetObj.IsEmpty())
509 return false;
tsepez41a53ad2016-03-28 16:59:30 -0700510
tsepezb4694242016-08-15 16:44:55 -0700511 CJS_TimerObj* pJS_TimerObj =
512 static_cast<CJS_TimerObj*>(pRuntime->GetObjectPrivate(pRetObj));
tsepez41a53ad2016-03-28 16:59:30 -0700513 TimerObj* pTimerObj = static_cast<TimerObj*>(pJS_TimerObj->GetEmbedObject());
dsinclair2eb7c7d2016-08-18 09:58:19 -0700514 pTimerObj->SetTimer(timerRef);
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}