blob: 6d31d7e2e4a7ca83be5cb43c5fa1486c67ca530d [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();
Dan Sinclaircdba7472017-03-23 09:17:10 -0400286 if (pXFAContext->GetDocType() == XFA_DocType::Dynamic ||
287 pXFAContext->GetDocType() == XFA_DocType::Static) {
Tom Sepezd6278ba2015-09-08 16:34:37 -0700288 vp << JS_NUM_VIEWERVERSION_XFA;
tsepez4cf55152016-11-02 14:37:54 -0700289 return true;
Tom Sepezbf59a072015-10-21 14:07:23 -0700290 }
Tom Sepez40e9ff32015-11-30 12:39:54 -0800291#endif // PDF_ENABLE_XFA
Tom Sepezbf59a072015-10-21 14:07:23 -0700292 vp << JS_NUM_VIEWERVERSION;
tsepez4cf55152016-11-02 14:37:54 -0700293 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700294}
295
Tom Sepezb1670b52017-02-16 17:01:00 -0800296bool app::platform(CJS_Runtime* pRuntime,
Tom Sepezd6ae2af2017-02-16 11:49:55 -0800297 CJS_PropValue& vp,
298 CFX_WideString& sError) {
Jun Fanga0217b62015-12-02 13:57:18 +0800299 if (!vp.IsGetting())
tsepez4cf55152016-11-02 14:37:54 -0700300 return false;
Tom Sepez4d6fa832015-12-08 11:31:59 -0800301#ifdef PDF_ENABLE_XFA
Tom Sepezb1670b52017-02-16 17:01:00 -0800302 CPDFSDK_FormFillEnvironment* pFormFillEnv = pRuntime->GetFormFillEnv();
dsinclair82e17672016-10-11 12:38:01 -0700303 if (!pFormFillEnv)
tsepez4cf55152016-11-02 14:37:54 -0700304 return false;
dsinclair82e17672016-10-11 12:38:01 -0700305 CFX_WideString platfrom = pFormFillEnv->GetPlatform();
Tom Sepez4d6fa832015-12-08 11:31:59 -0800306 if (!platfrom.IsEmpty()) {
Jun Fanga0217b62015-12-02 13:57:18 +0800307 vp << platfrom;
tsepez4cf55152016-11-02 14:37:54 -0700308 return true;
Tom Sepez4d6fa832015-12-08 11:31:59 -0800309 }
310#endif
311 vp << JS_STR_PLATFORM;
tsepez4cf55152016-11-02 14:37:54 -0700312 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700313}
314
Tom Sepezb1670b52017-02-16 17:01:00 -0800315bool app::language(CJS_Runtime* pRuntime,
Tom Sepezd6ae2af2017-02-16 11:49:55 -0800316 CJS_PropValue& vp,
317 CFX_WideString& sError) {
Jun Fang487d1a92015-12-02 13:20:03 +0800318 if (!vp.IsGetting())
tsepez4cf55152016-11-02 14:37:54 -0700319 return false;
Tom Sepez4d6fa832015-12-08 11:31:59 -0800320#ifdef PDF_ENABLE_XFA
Tom Sepezb1670b52017-02-16 17:01:00 -0800321 CPDFSDK_FormFillEnvironment* pFormFillEnv = pRuntime->GetFormFillEnv();
dsinclair82e17672016-10-11 12:38:01 -0700322 if (!pFormFillEnv)
tsepez4cf55152016-11-02 14:37:54 -0700323 return false;
dsinclair82e17672016-10-11 12:38:01 -0700324 CFX_WideString language = pFormFillEnv->GetLanguage();
Tom Sepez4d6fa832015-12-08 11:31:59 -0800325 if (!language.IsEmpty()) {
Jun Fang487d1a92015-12-02 13:20:03 +0800326 vp << language;
tsepez4cf55152016-11-02 14:37:54 -0700327 return true;
Tom Sepez4d6fa832015-12-08 11:31:59 -0800328 }
329#endif
dsinclairf51e4dc2016-10-13 07:43:19 -0700330 vp << JS_STR_LANGUAGE;
tsepez4cf55152016-11-02 14:37:54 -0700331 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700332}
333
334// creates a new fdf object that contains no data
335// comment: need reader support
336// note:
dsinclair735606d2016-10-05 15:47:02 -0700337// CFDF_Document * CPDFSDK_FormFillEnvironment::NewFDF();
Tom Sepezb1670b52017-02-16 17:01:00 -0800338bool app::newFDF(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700339 const std::vector<CJS_Value>& params,
340 CJS_Value& vRet,
341 CFX_WideString& sError) {
342 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700343}
344// opens a specified pdf document and returns its document object
345// comment:need reader support
346// note: as defined in js reference, the proto of this function's fourth
347// parmeters, how old an fdf document while do not show it.
dsinclair735606d2016-10-05 15:47:02 -0700348// CFDF_Document * CPDFSDK_FormFillEnvironment::OpenFDF(string strPath,bool
349// bUserConv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700350
Tom Sepezb1670b52017-02-16 17:01:00 -0800351bool app::openFDF(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700352 const std::vector<CJS_Value>& params,
353 CJS_Value& vRet,
354 CFX_WideString& sError) {
355 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700356}
357
Tom Sepezb1670b52017-02-16 17:01:00 -0800358bool app::alert(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700359 const std::vector<CJS_Value>& params,
360 CJS_Value& vRet,
361 CFX_WideString& sError) {
Tom Sepezbd932572016-01-29 09:10:41 -0800362 std::vector<CJS_Value> newParams = JS_ExpandKeywordParams(
363 pRuntime, params, 4, L"cMsg", L"nIcon", L"nType", L"cTitle");
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700364
Tom Sepezbd932572016-01-29 09:10:41 -0800365 if (newParams[0].GetType() == CJS_Value::VT_unknown) {
tsepezcd5dc852016-09-08 11:23:24 -0700366 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);
tsepez4cf55152016-11-02 14:37:54 -0700367 return false;
Tom Sepezbd932572016-01-29 09:10:41 -0800368 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700369
dsinclair82e17672016-10-11 12:38:01 -0700370 CPDFSDK_FormFillEnvironment* pFormFillEnv = pRuntime->GetFormFillEnv();
371 if (!pFormFillEnv) {
tsepezf3dc8c62016-08-10 06:29:29 -0700372 vRet = CJS_Value(pRuntime, 0);
tsepez4cf55152016-11-02 14:37:54 -0700373 return true;
tsepeze1e7bd02016-08-08 13:03:16 -0700374 }
375
Tom Sepezbd932572016-01-29 09:10:41 -0800376 CFX_WideString swMsg;
377 if (newParams[0].GetType() == CJS_Value::VT_object) {
tsepeze5aff742016-08-08 09:49:42 -0700378 CJS_Array carray;
tsepezb4694242016-08-15 16:44:55 -0700379 if (newParams[0].ConvertToArray(pRuntime, carray)) {
Tom Sepezbd932572016-01-29 09:10:41 -0800380 swMsg = L"[";
381 CJS_Value element(pRuntime);
tsepezb4694242016-08-15 16:44:55 -0700382 for (int i = 0; i < carray.GetLength(pRuntime); ++i) {
Tom Sepezbd932572016-01-29 09:10:41 -0800383 if (i)
384 swMsg += L", ";
tsepezb4694242016-08-15 16:44:55 -0700385 carray.GetElement(pRuntime, i, element);
386 swMsg += element.ToCFXWideString(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700387 }
Tom Sepezbd932572016-01-29 09:10:41 -0800388 swMsg += L"]";
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700389 } else {
tsepezb4694242016-08-15 16:44:55 -0700390 swMsg = newParams[0].ToCFXWideString(pRuntime);
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700391 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700392 } else {
tsepezb4694242016-08-15 16:44:55 -0700393 swMsg = newParams[0].ToCFXWideString(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700394 }
395
Tom Sepezbd932572016-01-29 09:10:41 -0800396 int iIcon = 0;
397 if (newParams[1].GetType() != CJS_Value::VT_unknown)
tsepezb4694242016-08-15 16:44:55 -0700398 iIcon = newParams[1].ToInt(pRuntime);
Tom Sepezbd932572016-01-29 09:10:41 -0800399
400 int iType = 0;
401 if (newParams[2].GetType() != CJS_Value::VT_unknown)
tsepezb4694242016-08-15 16:44:55 -0700402 iType = newParams[2].ToInt(pRuntime);
Tom Sepezbd932572016-01-29 09:10:41 -0800403
404 CFX_WideString swTitle;
405 if (newParams[3].GetType() != CJS_Value::VT_unknown)
tsepezb4694242016-08-15 16:44:55 -0700406 swTitle = newParams[3].ToCFXWideString(pRuntime);
Tom Sepezbd932572016-01-29 09:10:41 -0800407 else
tsepezcd5dc852016-09-08 11:23:24 -0700408 swTitle = JSGetStringFromID(IDS_STRING_JSALERT);
Tom Sepezbd932572016-01-29 09:10:41 -0800409
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700410 pRuntime->BeginBlock();
dsinclair7cbe68e2016-10-12 11:56:23 -0700411 pFormFillEnv->KillFocusAnnot(0);
tsepeze1e7bd02016-08-08 13:03:16 -0700412
dsinclair82e17672016-10-11 12:38:01 -0700413 vRet = CJS_Value(pRuntime, pFormFillEnv->JS_appAlert(
414 swMsg.c_str(), swTitle.c_str(), iType, iIcon));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700415 pRuntime->EndBlock();
tsepez4cf55152016-11-02 14:37:54 -0700416 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700417}
418
Tom Sepezb1670b52017-02-16 17:01:00 -0800419bool app::beep(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700420 const std::vector<CJS_Value>& params,
421 CJS_Value& vRet,
422 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700423 if (params.size() == 1) {
dsinclair82e17672016-10-11 12:38:01 -0700424 pRuntime->GetFormFillEnv()->JS_appBeep(params[0].ToInt(pRuntime));
tsepez4cf55152016-11-02 14:37:54 -0700425 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700426 }
427
tsepezcd5dc852016-09-08 11:23:24 -0700428 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);
tsepez4cf55152016-11-02 14:37:54 -0700429 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700430}
431
Tom Sepezb1670b52017-02-16 17:01:00 -0800432bool app::findComponent(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700433 const std::vector<CJS_Value>& params,
434 CJS_Value& vRet,
435 CFX_WideString& sError) {
436 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700437}
438
Tom Sepezb1670b52017-02-16 17:01:00 -0800439bool app::popUpMenuEx(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700440 const std::vector<CJS_Value>& params,
441 CJS_Value& vRet,
442 CFX_WideString& sError) {
443 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700444}
445
Tom Sepezb1670b52017-02-16 17:01:00 -0800446bool app::fs(CJS_Runtime* pRuntime, CJS_PropValue& vp, CFX_WideString& sError) {
tsepez4cf55152016-11-02 14:37:54 -0700447 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700448}
449
Tom Sepezb1670b52017-02-16 17:01:00 -0800450bool app::setInterval(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700451 const std::vector<CJS_Value>& params,
452 CJS_Value& vRet,
453 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700454 if (params.size() > 2 || params.size() == 0) {
tsepezcd5dc852016-09-08 11:23:24 -0700455 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);
tsepez4cf55152016-11-02 14:37:54 -0700456 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700457 }
Tom Sepezc6ab1722015-02-05 15:27:25 -0800458
tsepezf3dc8c62016-08-10 06:29:29 -0700459 CFX_WideString script =
tsepezb4694242016-08-15 16:44:55 -0700460 params.size() > 0 ? params[0].ToCFXWideString(pRuntime) : L"";
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700461 if (script.IsEmpty()) {
tsepezcd5dc852016-09-08 11:23:24 -0700462 sError = JSGetStringFromID(IDS_STRING_JSAFNUMBER_KEYSTROKE);
tsepez4cf55152016-11-02 14:37:54 -0700463 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700464 }
465
tsepezb4694242016-08-15 16:44:55 -0700466 uint32_t dwInterval = params.size() > 1 ? params[1].ToInt(pRuntime) : 1000;
dsinclair2eb7c7d2016-08-18 09:58:19 -0700467
dsinclair82e17672016-10-11 12:38:01 -0700468 GlobalTimer* timerRef = new GlobalTimer(this, pRuntime->GetFormFillEnv(),
469 pRuntime, 0, script, dwInterval, 0);
tsepeza752edf2016-08-19 14:57:42 -0700470 m_Timers.insert(std::unique_ptr<GlobalTimer>(timerRef));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700471
tsepezb4694242016-08-15 16:44:55 -0700472 v8::Local<v8::Object> pRetObj =
473 pRuntime->NewFxDynamicObj(CJS_TimerObj::g_nObjDefnID);
Tom Sepezc5a14722017-02-24 15:31:12 -0800474 if (pRetObj.IsEmpty())
475 return false;
476
tsepezb4694242016-08-15 16:44:55 -0700477 CJS_TimerObj* pJS_TimerObj =
478 static_cast<CJS_TimerObj*>(pRuntime->GetObjectPrivate(pRetObj));
tsepez41a53ad2016-03-28 16:59:30 -0700479 TimerObj* pTimerObj = static_cast<TimerObj*>(pJS_TimerObj->GetEmbedObject());
dsinclair2eb7c7d2016-08-18 09:58:19 -0700480 pTimerObj->SetTimer(timerRef);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700481
tsepezf3dc8c62016-08-10 06:29:29 -0700482 vRet = CJS_Value(pRuntime, pRetObj);
tsepez4cf55152016-11-02 14:37:54 -0700483 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700484}
485
Tom Sepezb1670b52017-02-16 17:01:00 -0800486bool app::setTimeOut(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700487 const std::vector<CJS_Value>& params,
488 CJS_Value& vRet,
489 CFX_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
tsepezb4694242016-08-15 16:44:55 -0700495 CFX_WideString script = params[0].ToCFXWideString(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700496 if (script.IsEmpty()) {
tsepezcd5dc852016-09-08 11:23:24 -0700497 sError = JSGetStringFromID(IDS_STRING_JSAFNUMBER_KEYSTROKE);
tsepez4cf55152016-11-02 14:37:54 -0700498 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700499 }
500
tsepezb4694242016-08-15 16:44:55 -0700501 uint32_t dwTimeOut = params.size() > 1 ? params[1].ToInt(pRuntime) : 1000;
tsepeza752edf2016-08-19 14:57:42 -0700502 GlobalTimer* timerRef =
dsinclair82e17672016-10-11 12:38:01 -0700503 new GlobalTimer(this, pRuntime->GetFormFillEnv(), pRuntime, 1, script,
504 dwTimeOut, dwTimeOut);
tsepeza752edf2016-08-19 14:57:42 -0700505 m_Timers.insert(std::unique_ptr<GlobalTimer>(timerRef));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700506
tsepezb4694242016-08-15 16:44:55 -0700507 v8::Local<v8::Object> pRetObj =
508 pRuntime->NewFxDynamicObj(CJS_TimerObj::g_nObjDefnID);
Tom Sepezc5a14722017-02-24 15:31:12 -0800509 if (pRetObj.IsEmpty())
510 return false;
tsepez41a53ad2016-03-28 16:59:30 -0700511
tsepezb4694242016-08-15 16:44:55 -0700512 CJS_TimerObj* pJS_TimerObj =
513 static_cast<CJS_TimerObj*>(pRuntime->GetObjectPrivate(pRetObj));
tsepez41a53ad2016-03-28 16:59:30 -0700514 TimerObj* pTimerObj = static_cast<TimerObj*>(pJS_TimerObj->GetEmbedObject());
dsinclair2eb7c7d2016-08-18 09:58:19 -0700515 pTimerObj->SetTimer(timerRef);
tsepezf3dc8c62016-08-10 06:29:29 -0700516 vRet = CJS_Value(pRuntime, pRetObj);
tsepez4cf55152016-11-02 14:37:54 -0700517 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700518}
519
Tom Sepezb1670b52017-02-16 17:01:00 -0800520bool app::clearTimeOut(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700521 const std::vector<CJS_Value>& params,
522 CJS_Value& vRet,
523 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700524 if (params.size() != 1) {
tsepezcd5dc852016-09-08 11:23:24 -0700525 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);
tsepez4cf55152016-11-02 14:37:54 -0700526 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700527 }
528
Tom Sepezb1670b52017-02-16 17:01:00 -0800529 app::ClearTimerCommon(pRuntime, params[0]);
tsepez4cf55152016-11-02 14:37:54 -0700530 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700531}
532
Tom Sepezb1670b52017-02-16 17:01:00 -0800533bool app::clearInterval(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700534 const std::vector<CJS_Value>& params,
535 CJS_Value& vRet,
536 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700537 if (params.size() != 1) {
tsepezcd5dc852016-09-08 11:23:24 -0700538 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);
tsepez4cf55152016-11-02 14:37:54 -0700539 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700540 }
541
Tom Sepezb1670b52017-02-16 17:01:00 -0800542 app::ClearTimerCommon(pRuntime, params[0]);
tsepez4cf55152016-11-02 14:37:54 -0700543 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700544}
545
tsepezb4694242016-08-15 16:44:55 -0700546void app::ClearTimerCommon(CJS_Runtime* pRuntime, const CJS_Value& param) {
tsepez40faa792016-07-15 17:58:02 -0700547 if (param.GetType() != CJS_Value::VT_object)
tsepez41a53ad2016-03-28 16:59:30 -0700548 return;
549
tsepezb4694242016-08-15 16:44:55 -0700550 v8::Local<v8::Object> pObj = param.ToV8Object(pRuntime);
551 if (CFXJS_Engine::GetObjDefnID(pObj) != CJS_TimerObj::g_nObjDefnID)
tsepez41a53ad2016-03-28 16:59:30 -0700552 return;
553
tsepezb4694242016-08-15 16:44:55 -0700554 CJS_Object* pJSObj = param.ToCJSObject(pRuntime);
tsepez41a53ad2016-03-28 16:59:30 -0700555 if (!pJSObj)
556 return;
557
558 TimerObj* pTimerObj = static_cast<TimerObj*>(pJSObj->GetEmbedObject());
559 if (!pTimerObj)
560 return;
561
tsepeze3ff76b2016-08-08 11:58:47 -0700562 GlobalTimer::Cancel(pTimerObj->GetTimerID());
tsepez41a53ad2016-03-28 16:59:30 -0700563}
564
Tom Sepezb1670b52017-02-16 17:01:00 -0800565bool app::execMenuItem(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700566 const std::vector<CJS_Value>& params,
567 CJS_Value& vRet,
568 CFX_WideString& sError) {
569 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700570}
571
tsepeze3ff76b2016-08-08 11:58:47 -0700572void app::TimerProc(GlobalTimer* pTimer) {
Lei Zhang2d5a0e12015-10-05 17:00:03 -0700573 CJS_Runtime* pRuntime = pTimer->GetRuntime();
tsepez8ca63de2016-08-05 17:12:27 -0700574 if (pRuntime && (!pTimer->IsOneShot() || pTimer->GetTimeOut() > 0))
575 RunJsScript(pRuntime, pTimer->GetJScript());
576}
Lei Zhang2d5a0e12015-10-05 17:00:03 -0700577
tsepeze3ff76b2016-08-08 11:58:47 -0700578void app::CancelProc(GlobalTimer* pTimer) {
tsepeza752edf2016-08-19 14:57:42 -0700579 m_Timers.erase(pdfium::FakeUniquePtr<GlobalTimer>(pTimer));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700580}
581
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700582void app::RunJsScript(CJS_Runtime* pRuntime, const CFX_WideString& wsScript) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700583 if (!pRuntime->IsBlocking()) {
Tom Sepezd6ae2af2017-02-16 11:49:55 -0800584 IJS_EventContext* pContext = pRuntime->NewEventContext();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700585 pContext->OnExternal_Exec();
586 CFX_WideString wtInfo;
Tom Sepez33420902015-10-13 15:00:10 -0700587 pContext->RunScript(wsScript, &wtInfo);
Tom Sepezd6ae2af2017-02-16 11:49:55 -0800588 pRuntime->ReleaseEventContext(pContext);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700589 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700590}
591
Tom Sepezb1670b52017-02-16 17:01:00 -0800592bool app::goBack(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700593 const std::vector<CJS_Value>& params,
594 CJS_Value& vRet,
595 CFX_WideString& sError) {
596 // Not supported.
597 return true;
598}
599
Tom Sepezb1670b52017-02-16 17:01:00 -0800600bool app::goForward(CJS_Runtime* pRuntime,
Lei Zhang945fdb72015-11-11 10:18:16 -0800601 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700602 CJS_Value& vRet,
603 CFX_WideString& sError) {
Tom Sepezc6ab1722015-02-05 15:27:25 -0800604 // Not supported.
tsepez4cf55152016-11-02 14:37:54 -0700605 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700606}
607
Tom Sepezb1670b52017-02-16 17:01:00 -0800608bool app::mailMsg(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700609 const std::vector<CJS_Value>& params,
610 CJS_Value& vRet,
611 CFX_WideString& sError) {
Tom Sepeze5fbd7a2016-01-29 17:05:08 -0800612 std::vector<CJS_Value> newParams =
613 JS_ExpandKeywordParams(pRuntime, params, 6, L"bUI", L"cTo", L"cCc",
614 L"cBcc", L"cSubject", L"cMsg");
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700615
Tom Sepeze5fbd7a2016-01-29 17:05:08 -0800616 if (newParams[0].GetType() == CJS_Value::VT_unknown) {
tsepezcd5dc852016-09-08 11:23:24 -0700617 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);
tsepez4cf55152016-11-02 14:37:54 -0700618 return false;
Tom Sepeze5fbd7a2016-01-29 17:05:08 -0800619 }
tsepezb4694242016-08-15 16:44:55 -0700620 bool bUI = newParams[0].ToBool(pRuntime);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700621
Tom Sepeze5fbd7a2016-01-29 17:05:08 -0800622 CFX_WideString cTo;
623 if (newParams[1].GetType() != CJS_Value::VT_unknown) {
tsepezb4694242016-08-15 16:44:55 -0700624 cTo = newParams[1].ToCFXWideString(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700625 } else {
Tom Sepeze5fbd7a2016-01-29 17:05:08 -0800626 if (!bUI) {
627 // cTo parameter required when UI not invoked.
tsepezcd5dc852016-09-08 11:23:24 -0700628 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);
tsepez4cf55152016-11-02 14:37:54 -0700629 return false;
Tom Sepeze5fbd7a2016-01-29 17:05:08 -0800630 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700631 }
Tom Sepezc6ab1722015-02-05 15:27:25 -0800632
Tom Sepeze5fbd7a2016-01-29 17:05:08 -0800633 CFX_WideString cCc;
634 if (newParams[2].GetType() != CJS_Value::VT_unknown)
tsepezb4694242016-08-15 16:44:55 -0700635 cCc = newParams[2].ToCFXWideString(pRuntime);
Tom Sepeze5fbd7a2016-01-29 17:05:08 -0800636
637 CFX_WideString cBcc;
638 if (newParams[3].GetType() != CJS_Value::VT_unknown)
tsepezb4694242016-08-15 16:44:55 -0700639 cBcc = newParams[3].ToCFXWideString(pRuntime);
Tom Sepeze5fbd7a2016-01-29 17:05:08 -0800640
641 CFX_WideString cSubject;
642 if (newParams[4].GetType() != CJS_Value::VT_unknown)
tsepezb4694242016-08-15 16:44:55 -0700643 cSubject = newParams[4].ToCFXWideString(pRuntime);
Tom Sepeze5fbd7a2016-01-29 17:05:08 -0800644
645 CFX_WideString cMsg;
646 if (newParams[5].GetType() != CJS_Value::VT_unknown)
tsepezb4694242016-08-15 16:44:55 -0700647 cMsg = newParams[5].ToCFXWideString(pRuntime);
Tom Sepeze5fbd7a2016-01-29 17:05:08 -0800648
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700649 pRuntime->BeginBlock();
Tom Sepezb1670b52017-02-16 17:01:00 -0800650 pRuntime->GetFormFillEnv()->JS_docmailForm(nullptr, 0, bUI, cTo.c_str(),
dsinclair4526faf2016-10-11 10:54:49 -0700651 cSubject.c_str(), cCc.c_str(),
652 cBcc.c_str(), cMsg.c_str());
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700653 pRuntime->EndBlock();
tsepez4cf55152016-11-02 14:37:54 -0700654 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700655}
656
Tom Sepezb1670b52017-02-16 17:01:00 -0800657bool app::launchURL(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700658 const std::vector<CJS_Value>& params,
659 CJS_Value& vRet,
660 CFX_WideString& sError) {
Tom Sepezc6ab1722015-02-05 15:27:25 -0800661 // Unsafe, not supported.
tsepez4cf55152016-11-02 14:37:54 -0700662 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700663}
664
Tom Sepezb1670b52017-02-16 17:01:00 -0800665bool app::runtimeHighlight(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700666 CJS_PropValue& vp,
667 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700668 if (vp.IsSetting()) {
669 vp >> m_bRuntimeHighLight;
670 } else {
671 vp << m_bRuntimeHighLight;
672 }
tsepez4cf55152016-11-02 14:37:54 -0700673 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700674}
675
Tom Sepezb1670b52017-02-16 17:01:00 -0800676bool app::fullscreen(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700677 CJS_PropValue& vp,
678 CFX_WideString& sError) {
679 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700680}
681
Tom Sepezb1670b52017-02-16 17:01:00 -0800682bool app::popUpMenu(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700683 const std::vector<CJS_Value>& params,
684 CJS_Value& vRet,
685 CFX_WideString& sError) {
686 return false;
687}
688
Tom Sepezb1670b52017-02-16 17:01:00 -0800689bool app::browseForDoc(CJS_Runtime* pRuntime,
Lei Zhang945fdb72015-11-11 10:18:16 -0800690 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700691 CJS_Value& vRet,
692 CFX_WideString& sError) {
Tom Sepezc6ab1722015-02-05 15:27:25 -0800693 // Unsafe, not supported.
tsepez4cf55152016-11-02 14:37:54 -0700694 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700695}
696
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700697CFX_WideString app::SysPathToPDFPath(const CFX_WideString& sOldPath) {
698 CFX_WideString sRet = L"/";
Tom Sepez3c3e2712017-04-17 15:38:19 -0700699 for (const wchar_t& c : sOldPath) {
700 if (c != L':')
701 sRet += (c == L'\\') ? L'/' : c;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700702 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700703 return sRet;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700704}
705
Tom Sepezb1670b52017-02-16 17:01:00 -0800706bool app::newDoc(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700707 const std::vector<CJS_Value>& params,
708 CJS_Value& vRet,
709 CFX_WideString& sError) {
710 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700711}
712
Tom Sepezb1670b52017-02-16 17:01:00 -0800713bool app::openDoc(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700714 const std::vector<CJS_Value>& params,
715 CJS_Value& vRet,
716 CFX_WideString& sError) {
717 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700718}
719
Tom Sepezb1670b52017-02-16 17:01:00 -0800720bool app::response(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700721 const std::vector<CJS_Value>& params,
722 CJS_Value& vRet,
723 CFX_WideString& sError) {
Tom Sepez58fb36a2016-02-01 10:32:14 -0800724 std::vector<CJS_Value> newParams =
725 JS_ExpandKeywordParams(pRuntime, params, 5, L"cQuestion", L"cTitle",
726 L"cDefault", L"bPassword", L"cLabel");
Tom Sepez621d4de2014-07-29 14:01:21 -0700727
Tom Sepez58fb36a2016-02-01 10:32:14 -0800728 if (newParams[0].GetType() == CJS_Value::VT_unknown) {
tsepezcd5dc852016-09-08 11:23:24 -0700729 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);
tsepez4cf55152016-11-02 14:37:54 -0700730 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700731 }
tsepezb4694242016-08-15 16:44:55 -0700732 CFX_WideString swQuestion = newParams[0].ToCFXWideString(pRuntime);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700733
Tom Sepez58fb36a2016-02-01 10:32:14 -0800734 CFX_WideString swTitle = L"PDF";
735 if (newParams[1].GetType() != CJS_Value::VT_unknown)
tsepezb4694242016-08-15 16:44:55 -0700736 swTitle = newParams[1].ToCFXWideString(pRuntime);
Tom Sepez58fb36a2016-02-01 10:32:14 -0800737
738 CFX_WideString swDefault;
739 if (newParams[2].GetType() != CJS_Value::VT_unknown)
tsepezb4694242016-08-15 16:44:55 -0700740 swDefault = newParams[2].ToCFXWideString(pRuntime);
Tom Sepez58fb36a2016-02-01 10:32:14 -0800741
742 bool bPassword = false;
743 if (newParams[3].GetType() != CJS_Value::VT_unknown)
tsepezb4694242016-08-15 16:44:55 -0700744 bPassword = newParams[3].ToBool(pRuntime);
Tom Sepez58fb36a2016-02-01 10:32:14 -0800745
746 CFX_WideString swLabel;
747 if (newParams[4].GetType() != CJS_Value::VT_unknown)
tsepezb4694242016-08-15 16:44:55 -0700748 swLabel = newParams[4].ToCFXWideString(pRuntime);
Tom Sepez621d4de2014-07-29 14:01:21 -0700749
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700750 const int MAX_INPUT_BYTES = 2048;
Lei Zhangaa8bf7e2015-12-24 19:13:32 -0800751 std::unique_ptr<char[]> pBuff(new char[MAX_INPUT_BYTES + 2]);
Lei Zhangdb5256f2015-10-02 10:11:43 -0700752 memset(pBuff.get(), 0, MAX_INPUT_BYTES + 2);
Tom Sepez58fb36a2016-02-01 10:32:14 -0800753
Tom Sepezb1670b52017-02-16 17:01:00 -0800754 int nLengthBytes = pRuntime->GetFormFillEnv()->JS_appResponse(
Lei Zhangdb5256f2015-10-02 10:11:43 -0700755 swQuestion.c_str(), swTitle.c_str(), swDefault.c_str(), swLabel.c_str(),
Tom Sepez58fb36a2016-02-01 10:32:14 -0800756 bPassword, pBuff.get(), MAX_INPUT_BYTES);
757
758 if (nLengthBytes < 0 || nLengthBytes > MAX_INPUT_BYTES) {
tsepezcd5dc852016-09-08 11:23:24 -0700759 sError = JSGetStringFromID(IDS_STRING_JSPARAM_TOOLONG);
tsepez4cf55152016-11-02 14:37:54 -0700760 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700761 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700762
tsepezf3dc8c62016-08-10 06:29:29 -0700763 vRet = CJS_Value(pRuntime, CFX_WideString::FromUTF16LE(
764 reinterpret_cast<uint16_t*>(pBuff.get()),
765 nLengthBytes / sizeof(uint16_t))
766 .c_str());
767
tsepez4cf55152016-11-02 14:37:54 -0700768 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700769}
770
Tom Sepezb1670b52017-02-16 17:01:00 -0800771bool app::media(CJS_Runtime* pRuntime,
Tom Sepezd6ae2af2017-02-16 11:49:55 -0800772 CJS_PropValue& vp,
773 CFX_WideString& sError) {
tsepez4cf55152016-11-02 14:37:54 -0700774 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700775}
776
Tom Sepezb1670b52017-02-16 17:01:00 -0800777bool app::execDialog(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700778 const std::vector<CJS_Value>& params,
779 CJS_Value& vRet,
780 CFX_WideString& sError) {
781 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700782}