blob: 325a84b1f877647b38f95e5222efe7b6e7b0b72b [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
Lei Zhangaa8bf7e2015-12-24 19:13:32 -08009#include <memory>
Dan Sinclair3ebd1212016-03-09 09:59:23 -050010#include <vector>
Lei Zhangaa8bf7e2015-12-24 19:13:32 -080011
dsinclair735606d2016-10-05 15:47:02 -070012#include "fpdfsdk/cpdfsdk_formfillenvironment.h"
dsinclair114e46a2016-09-29 17:18:21 -070013#include "fpdfsdk/cpdfsdk_interform.h"
Dan Sinclairf766ad22016-03-14 13:51:24 -040014#include "fpdfsdk/javascript/Document.h"
Dan Sinclairf766ad22016-03-14 13:51:24 -040015#include "fpdfsdk/javascript/JS_Define.h"
16#include "fpdfsdk/javascript/JS_EventHandler.h"
17#include "fpdfsdk/javascript/JS_Object.h"
Dan Sinclairf766ad22016-03-14 13:51:24 -040018#include "fpdfsdk/javascript/JS_Value.h"
dsinclair64376be2016-03-31 20:03:24 -070019#include "fpdfsdk/javascript/cjs_context.h"
20#include "fpdfsdk/javascript/cjs_runtime.h"
Dan Sinclairf766ad22016-03-14 13:51:24 -040021#include "fpdfsdk/javascript/resource.h"
tsepeza752edf2016-08-19 14:57:42 -070022#include "third_party/base/stl_util.h"
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070023
tsepez1c620542016-09-12 09:47:52 -070024class GlobalTimer {
tsepeze3ff76b2016-08-08 11:58:47 -070025 public:
26 GlobalTimer(app* pObj,
dsinclair82e17672016-10-11 12:38:01 -070027 CPDFSDK_FormFillEnvironment* pFormFillEnv,
tsepeze3ff76b2016-08-08 11:58:47 -070028 CJS_Runtime* pRuntime,
29 int nType,
30 const CFX_WideString& script,
31 uint32_t dwElapse,
32 uint32_t dwTimeOut);
tsepez8832fbf2016-09-08 10:25:55 -070033 ~GlobalTimer();
tsepeze3ff76b2016-08-08 11:58:47 -070034
35 static void Trigger(int nTimerID);
36 static void Cancel(int nTimerID);
37
38 bool IsOneShot() const { return m_nType == 1; }
39 uint32_t GetTimeOut() const { return m_dwTimeOut; }
40 int GetTimerID() const { return m_nTimerID; }
tsepez1c620542016-09-12 09:47:52 -070041 CJS_Runtime* GetRuntime() const { return m_pRuntime.Get(); }
tsepeze3ff76b2016-08-08 11:58:47 -070042 CFX_WideString GetJScript() const { return m_swJScript; }
43
44 private:
dsinclair72177da2016-09-15 12:07:23 -070045 using TimerMap = std::map<uint32_t, GlobalTimer*>;
tsepeze3ff76b2016-08-08 11:58:47 -070046 static TimerMap* GetGlobalTimerMap();
47
tsepeze3ff76b2016-08-08 11:58:47 -070048 uint32_t m_nTimerID;
49 app* const m_pEmbedObj;
50 bool m_bProcessing;
tsepeze3ff76b2016-08-08 11:58:47 -070051
52 // data
53 const int m_nType; // 0:Interval; 1:TimeOut
54 const uint32_t m_dwTimeOut;
55 const CFX_WideString m_swJScript;
tsepez1c620542016-09-12 09:47:52 -070056 CJS_Runtime::ObservedPtr m_pRuntime;
dsinclair82e17672016-10-11 12:38:01 -070057 CPDFSDK_FormFillEnvironment* const m_pFormFillEnv;
tsepeze3ff76b2016-08-08 11:58:47 -070058};
59
60GlobalTimer::GlobalTimer(app* pObj,
dsinclair82e17672016-10-11 12:38:01 -070061 CPDFSDK_FormFillEnvironment* pFormFillEnv,
tsepeze3ff76b2016-08-08 11:58:47 -070062 CJS_Runtime* pRuntime,
63 int nType,
64 const CFX_WideString& script,
65 uint32_t dwElapse,
66 uint32_t dwTimeOut)
67 : m_nTimerID(0),
68 m_pEmbedObj(pObj),
69 m_bProcessing(false),
tsepeze3ff76b2016-08-08 11:58:47 -070070 m_nType(nType),
71 m_dwTimeOut(dwTimeOut),
72 m_swJScript(script),
73 m_pRuntime(pRuntime),
dsinclair82e17672016-10-11 12:38:01 -070074 m_pFormFillEnv(pFormFillEnv) {
75 CFX_SystemHandler* pHandler = m_pFormFillEnv->GetSysHandler();
tsepeze3ff76b2016-08-08 11:58:47 -070076 m_nTimerID = pHandler->SetTimer(dwElapse, Trigger);
77 (*GetGlobalTimerMap())[m_nTimerID] = this;
tsepeze3ff76b2016-08-08 11:58:47 -070078}
79
80GlobalTimer::~GlobalTimer() {
tsepeze3ff76b2016-08-08 11:58:47 -070081 if (!m_nTimerID)
82 return;
83
tsepez8832fbf2016-09-08 10:25:55 -070084 if (GetRuntime())
dsinclair82e17672016-10-11 12:38:01 -070085 m_pFormFillEnv->GetSysHandler()->KillTimer(m_nTimerID);
tsepeze3ff76b2016-08-08 11:58:47 -070086
87 GetGlobalTimerMap()->erase(m_nTimerID);
88}
89
90// static
91void GlobalTimer::Trigger(int nTimerID) {
92 auto it = GetGlobalTimerMap()->find(nTimerID);
93 if (it == GetGlobalTimerMap()->end())
94 return;
95
96 GlobalTimer* pTimer = it->second;
97 if (pTimer->m_bProcessing)
98 return;
99
100 pTimer->m_bProcessing = true;
101 if (pTimer->m_pEmbedObj)
102 pTimer->m_pEmbedObj->TimerProc(pTimer);
103
104 // Timer proc may have destroyed timer, find it again.
105 it = GetGlobalTimerMap()->find(nTimerID);
106 if (it == GetGlobalTimerMap()->end())
107 return;
108
109 pTimer = it->second;
110 pTimer->m_bProcessing = false;
111 if (pTimer->IsOneShot())
112 pTimer->m_pEmbedObj->CancelProc(pTimer);
113}
114
115// static
116void GlobalTimer::Cancel(int nTimerID) {
117 auto it = GetGlobalTimerMap()->find(nTimerID);
118 if (it == GetGlobalTimerMap()->end())
119 return;
120
121 GlobalTimer* pTimer = it->second;
122 pTimer->m_pEmbedObj->CancelProc(pTimer);
123}
124
125// static
126GlobalTimer::TimerMap* GlobalTimer::GetGlobalTimerMap() {
127 // Leak the timer array at shutdown.
128 static auto* s_TimerMap = new TimerMap;
129 return s_TimerMap;
130}
131
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700132BEGIN_JS_STATIC_CONST(CJS_TimerObj)
133END_JS_STATIC_CONST()
134
135BEGIN_JS_STATIC_PROP(CJS_TimerObj)
136END_JS_STATIC_PROP()
137
138BEGIN_JS_STATIC_METHOD(CJS_TimerObj)
139END_JS_STATIC_METHOD()
140
141IMPLEMENT_JS_CLASS(CJS_TimerObj, TimerObj)
142
143TimerObj::TimerObj(CJS_Object* pJSObject)
tsepez8ca63de2016-08-05 17:12:27 -0700144 : CJS_EmbedObj(pJSObject), m_nTimerID(0) {}
Tom Sepezc6ab1722015-02-05 15:27:25 -0800145
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700146TimerObj::~TimerObj() {}
147
tsepeze3ff76b2016-08-08 11:58:47 -0700148void TimerObj::SetTimer(GlobalTimer* pTimer) {
tsepez8ca63de2016-08-05 17:12:27 -0700149 m_nTimerID = pTimer->GetTimerID();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700150}
151
Tom Sepezd6278ba2015-09-08 16:34:37 -0700152#define JS_STR_VIEWERTYPE L"pdfium"
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700153#define JS_STR_VIEWERVARIATION L"Full"
154#define JS_STR_PLATFORM L"WIN"
155#define JS_STR_LANGUANGE L"ENU"
Tom Sepezd6278ba2015-09-08 16:34:37 -0700156#define JS_NUM_VIEWERVERSION 8
Tom Sepez51da0932015-11-25 16:05:49 -0800157#ifdef PDF_ENABLE_XFA
Tom Sepezd6278ba2015-09-08 16:34:37 -0700158#define JS_NUM_VIEWERVERSION_XFA 11
Tom Sepez40e9ff32015-11-30 12:39:54 -0800159#endif // PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700160#define JS_NUM_FORMSVERSION 7
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700161
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700162BEGIN_JS_STATIC_CONST(CJS_App)
163END_JS_STATIC_CONST()
164
165BEGIN_JS_STATIC_PROP(CJS_App)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700166JS_STATIC_PROP_ENTRY(activeDocs)
167JS_STATIC_PROP_ENTRY(calculate)
168JS_STATIC_PROP_ENTRY(formsVersion)
169JS_STATIC_PROP_ENTRY(fs)
170JS_STATIC_PROP_ENTRY(fullscreen)
171JS_STATIC_PROP_ENTRY(language)
172JS_STATIC_PROP_ENTRY(media)
173JS_STATIC_PROP_ENTRY(platform)
174JS_STATIC_PROP_ENTRY(runtimeHighlight)
175JS_STATIC_PROP_ENTRY(viewerType)
176JS_STATIC_PROP_ENTRY(viewerVariation)
177JS_STATIC_PROP_ENTRY(viewerVersion)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700178END_JS_STATIC_PROP()
179
180BEGIN_JS_STATIC_METHOD(CJS_App)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700181JS_STATIC_METHOD_ENTRY(alert)
182JS_STATIC_METHOD_ENTRY(beep)
183JS_STATIC_METHOD_ENTRY(browseForDoc)
184JS_STATIC_METHOD_ENTRY(clearInterval)
185JS_STATIC_METHOD_ENTRY(clearTimeOut)
186JS_STATIC_METHOD_ENTRY(execDialog)
187JS_STATIC_METHOD_ENTRY(execMenuItem)
188JS_STATIC_METHOD_ENTRY(findComponent)
189JS_STATIC_METHOD_ENTRY(goBack)
190JS_STATIC_METHOD_ENTRY(goForward)
191JS_STATIC_METHOD_ENTRY(launchURL)
192JS_STATIC_METHOD_ENTRY(mailMsg)
193JS_STATIC_METHOD_ENTRY(newFDF)
194JS_STATIC_METHOD_ENTRY(newDoc)
195JS_STATIC_METHOD_ENTRY(openDoc)
196JS_STATIC_METHOD_ENTRY(openFDF)
197JS_STATIC_METHOD_ENTRY(popUpMenuEx)
198JS_STATIC_METHOD_ENTRY(popUpMenu)
199JS_STATIC_METHOD_ENTRY(response)
200JS_STATIC_METHOD_ENTRY(setInterval)
201JS_STATIC_METHOD_ENTRY(setTimeOut)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700202END_JS_STATIC_METHOD()
203
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700204IMPLEMENT_JS_CLASS(CJS_App, app)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700205
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700206app::app(CJS_Object* pJSObject)
207 : CJS_EmbedObj(pJSObject), m_bCalculate(true), m_bRuntimeHighLight(false) {}
208
Lei Zhang2b1a2d52015-08-14 22:16:22 -0700209app::~app() {
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700210}
211
Tom Sepezba038bc2015-10-08 12:03:00 -0700212FX_BOOL app::activeDocs(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700213 CJS_PropValue& vp,
214 CFX_WideString& sError) {
215 if (!vp.IsGetting())
216 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700217
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700218 CJS_Context* pContext = (CJS_Context*)cc;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700219 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
dsinclair82e17672016-10-11 12:38:01 -0700220 CJS_Document* pJSDocument = nullptr;
221 v8::Local<v8::Object> pObj = pRuntime->GetThisObj();
222 if (CFXJS_Engine::GetObjDefnID(pObj) == CJS_Document::g_nObjDefnID) {
223 pJSDocument = static_cast<CJS_Document*>(pRuntime->GetObjectPrivate(pObj));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700224 }
dsinclair82e17672016-10-11 12:38:01 -0700225
226 CJS_Array aDocs;
227 aDocs.SetElement(pRuntime, 0, CJS_Value(pRuntime, pJSDocument));
228
tsepezb4694242016-08-15 16:44:55 -0700229 if (aDocs.GetLength(pRuntime) > 0)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700230 vp << aDocs;
231 else
tsepezf3dc8c62016-08-10 06:29:29 -0700232 vp.GetJSValue()->SetNull(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700233
234 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700235}
236
Tom Sepezba038bc2015-10-08 12:03:00 -0700237FX_BOOL app::calculate(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700238 CJS_PropValue& vp,
239 CFX_WideString& sError) {
240 if (vp.IsSetting()) {
241 bool bVP;
242 vp >> bVP;
243 m_bCalculate = (FX_BOOL)bVP;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700244
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700245 CJS_Context* pContext = (CJS_Context*)cc;
dsinclair4526faf2016-10-11 10:54:49 -0700246 pContext->GetFormFillEnv()
dsinclair4526faf2016-10-11 10:54:49 -0700247 ->GetInterForm()
248 ->EnableCalculate((FX_BOOL)m_bCalculate);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700249 } else {
250 vp << (bool)m_bCalculate;
251 }
252 return TRUE;
253}
254
Tom Sepezba038bc2015-10-08 12:03:00 -0700255FX_BOOL app::formsVersion(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700256 CJS_PropValue& vp,
257 CFX_WideString& sError) {
258 if (vp.IsGetting()) {
259 vp << JS_NUM_FORMSVERSION;
260 return TRUE;
261 }
262
263 return FALSE;
264}
265
Tom Sepezba038bc2015-10-08 12:03:00 -0700266FX_BOOL app::viewerType(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700267 CJS_PropValue& vp,
268 CFX_WideString& sError) {
269 if (vp.IsGetting()) {
Tom Sepezd6278ba2015-09-08 16:34:37 -0700270 vp << JS_STR_VIEWERTYPE;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700271 return TRUE;
272 }
273
274 return FALSE;
275}
276
Tom Sepezba038bc2015-10-08 12:03:00 -0700277FX_BOOL app::viewerVariation(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700278 CJS_PropValue& vp,
279 CFX_WideString& sError) {
280 if (vp.IsGetting()) {
281 vp << JS_STR_VIEWERVARIATION;
282 return TRUE;
283 }
284
285 return FALSE;
286}
287
Tom Sepezba038bc2015-10-08 12:03:00 -0700288FX_BOOL app::viewerVersion(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700289 CJS_PropValue& vp,
290 CFX_WideString& sError) {
291 if (!vp.IsGetting())
292 return FALSE;
Tom Sepez51da0932015-11-25 16:05:49 -0800293#ifdef PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700294 CJS_Context* pContext = (CJS_Context*)cc;
dsinclair7cbe68e2016-10-12 11:56:23 -0700295 CPDFXFA_Document* pDoc = pContext->GetFormFillEnv()->GetXFADocument();
Tom Sepezbf59a072015-10-21 14:07:23 -0700296 if (pDoc->GetDocType() == 1 || pDoc->GetDocType() == 2) {
Tom Sepezd6278ba2015-09-08 16:34:37 -0700297 vp << JS_NUM_VIEWERVERSION_XFA;
Tom Sepezbf59a072015-10-21 14:07:23 -0700298 return TRUE;
299 }
Tom Sepez40e9ff32015-11-30 12:39:54 -0800300#endif // PDF_ENABLE_XFA
Tom Sepezbf59a072015-10-21 14:07:23 -0700301 vp << JS_NUM_VIEWERVERSION;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700302 return TRUE;
303}
304
Tom Sepezba038bc2015-10-08 12:03:00 -0700305FX_BOOL app::platform(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700306 CJS_PropValue& vp,
307 CFX_WideString& sError) {
Jun Fanga0217b62015-12-02 13:57:18 +0800308 if (!vp.IsGetting())
309 return FALSE;
Tom Sepez4d6fa832015-12-08 11:31:59 -0800310#ifdef PDF_ENABLE_XFA
dsinclair82e17672016-10-11 12:38:01 -0700311 CPDFSDK_FormFillEnvironment* pFormFillEnv =
312 static_cast<CJS_Context*>(cc)->GetJSRuntime()->GetFormFillEnv();
313 if (!pFormFillEnv)
Jun Fanga0217b62015-12-02 13:57:18 +0800314 return FALSE;
dsinclair82e17672016-10-11 12:38:01 -0700315 CFX_WideString platfrom = pFormFillEnv->GetPlatform();
Tom Sepez4d6fa832015-12-08 11:31:59 -0800316 if (!platfrom.IsEmpty()) {
Jun Fanga0217b62015-12-02 13:57:18 +0800317 vp << platfrom;
Tom Sepez4d6fa832015-12-08 11:31:59 -0800318 return TRUE;
319 }
320#endif
321 vp << JS_STR_PLATFORM;
Jun Fanga0217b62015-12-02 13:57:18 +0800322 return TRUE;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700323}
324
Tom Sepezba038bc2015-10-08 12:03:00 -0700325FX_BOOL app::language(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700326 CJS_PropValue& vp,
327 CFX_WideString& sError) {
Jun Fang487d1a92015-12-02 13:20:03 +0800328 if (!vp.IsGetting())
329 return FALSE;
Tom Sepez4d6fa832015-12-08 11:31:59 -0800330#ifdef PDF_ENABLE_XFA
dsinclair82e17672016-10-11 12:38:01 -0700331 CPDFSDK_FormFillEnvironment* pFormFillEnv =
332 static_cast<CJS_Context*>(cc)->GetJSRuntime()->GetFormFillEnv();
333 if (!pFormFillEnv)
Jun Fang487d1a92015-12-02 13:20:03 +0800334 return FALSE;
dsinclair82e17672016-10-11 12:38:01 -0700335 CFX_WideString language = pFormFillEnv->GetLanguage();
Tom Sepez4d6fa832015-12-08 11:31:59 -0800336 if (!language.IsEmpty()) {
Jun Fang487d1a92015-12-02 13:20:03 +0800337 vp << language;
Tom Sepez4d6fa832015-12-08 11:31:59 -0800338 return TRUE;
339 }
340#endif
341 vp << JS_STR_LANGUANGE;
Jun Fang487d1a92015-12-02 13:20:03 +0800342 return TRUE;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700343}
344
345// creates a new fdf object that contains no data
346// comment: need reader support
347// note:
dsinclair735606d2016-10-05 15:47:02 -0700348// CFDF_Document * CPDFSDK_FormFillEnvironment::NewFDF();
Tom Sepezba038bc2015-10-08 12:03:00 -0700349FX_BOOL app::newFDF(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -0800350 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700351 CJS_Value& vRet,
352 CFX_WideString& sError) {
353 return TRUE;
354}
355// opens a specified pdf document and returns its document object
356// comment:need reader support
357// note: as defined in js reference, the proto of this function's fourth
358// parmeters, how old an fdf document while do not show it.
dsinclair735606d2016-10-05 15:47:02 -0700359// CFDF_Document * CPDFSDK_FormFillEnvironment::OpenFDF(string strPath,bool
360// bUserConv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700361
Tom Sepezba038bc2015-10-08 12:03:00 -0700362FX_BOOL app::openFDF(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -0800363 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700364 CJS_Value& vRet,
365 CFX_WideString& sError) {
366 return TRUE;
367}
368
Tom Sepezba038bc2015-10-08 12:03:00 -0700369FX_BOOL app::alert(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -0800370 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700371 CJS_Value& vRet,
372 CFX_WideString& sError) {
Tom Sepez67fd5df2015-10-08 12:24:19 -0700373 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
Tom Sepezbd932572016-01-29 09:10:41 -0800374 std::vector<CJS_Value> newParams = JS_ExpandKeywordParams(
375 pRuntime, params, 4, L"cMsg", L"nIcon", L"nType", L"cTitle");
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700376
Tom Sepezbd932572016-01-29 09:10:41 -0800377 if (newParams[0].GetType() == CJS_Value::VT_unknown) {
tsepezcd5dc852016-09-08 11:23:24 -0700378 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);
Tom Sepezbd932572016-01-29 09:10:41 -0800379 return FALSE;
380 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700381
dsinclair82e17672016-10-11 12:38:01 -0700382 CPDFSDK_FormFillEnvironment* pFormFillEnv = pRuntime->GetFormFillEnv();
383 if (!pFormFillEnv) {
tsepezf3dc8c62016-08-10 06:29:29 -0700384 vRet = CJS_Value(pRuntime, 0);
tsepeze1e7bd02016-08-08 13:03:16 -0700385 return TRUE;
386 }
387
Tom Sepezbd932572016-01-29 09:10:41 -0800388 CFX_WideString swMsg;
389 if (newParams[0].GetType() == CJS_Value::VT_object) {
tsepeze5aff742016-08-08 09:49:42 -0700390 CJS_Array carray;
tsepezb4694242016-08-15 16:44:55 -0700391 if (newParams[0].ConvertToArray(pRuntime, carray)) {
Tom Sepezbd932572016-01-29 09:10:41 -0800392 swMsg = L"[";
393 CJS_Value element(pRuntime);
tsepezb4694242016-08-15 16:44:55 -0700394 for (int i = 0; i < carray.GetLength(pRuntime); ++i) {
Tom Sepezbd932572016-01-29 09:10:41 -0800395 if (i)
396 swMsg += L", ";
tsepezb4694242016-08-15 16:44:55 -0700397 carray.GetElement(pRuntime, i, element);
398 swMsg += element.ToCFXWideString(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700399 }
Tom Sepezbd932572016-01-29 09:10:41 -0800400 swMsg += L"]";
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700401 } else {
tsepezb4694242016-08-15 16:44:55 -0700402 swMsg = newParams[0].ToCFXWideString(pRuntime);
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700403 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700404 } else {
tsepezb4694242016-08-15 16:44:55 -0700405 swMsg = newParams[0].ToCFXWideString(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700406 }
407
Tom Sepezbd932572016-01-29 09:10:41 -0800408 int iIcon = 0;
409 if (newParams[1].GetType() != CJS_Value::VT_unknown)
tsepezb4694242016-08-15 16:44:55 -0700410 iIcon = newParams[1].ToInt(pRuntime);
Tom Sepezbd932572016-01-29 09:10:41 -0800411
412 int iType = 0;
413 if (newParams[2].GetType() != CJS_Value::VT_unknown)
tsepezb4694242016-08-15 16:44:55 -0700414 iType = newParams[2].ToInt(pRuntime);
Tom Sepezbd932572016-01-29 09:10:41 -0800415
416 CFX_WideString swTitle;
417 if (newParams[3].GetType() != CJS_Value::VT_unknown)
tsepezb4694242016-08-15 16:44:55 -0700418 swTitle = newParams[3].ToCFXWideString(pRuntime);
Tom Sepezbd932572016-01-29 09:10:41 -0800419 else
tsepezcd5dc852016-09-08 11:23:24 -0700420 swTitle = JSGetStringFromID(IDS_STRING_JSALERT);
Tom Sepezbd932572016-01-29 09:10:41 -0800421
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700422 pRuntime->BeginBlock();
dsinclair7cbe68e2016-10-12 11:56:23 -0700423 pFormFillEnv->KillFocusAnnot(0);
tsepeze1e7bd02016-08-08 13:03:16 -0700424
dsinclair82e17672016-10-11 12:38:01 -0700425 vRet = CJS_Value(pRuntime, pFormFillEnv->JS_appAlert(
426 swMsg.c_str(), swTitle.c_str(), iType, iIcon));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700427 pRuntime->EndBlock();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700428 return TRUE;
429}
430
Tom Sepezba038bc2015-10-08 12:03:00 -0700431FX_BOOL app::beep(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -0800432 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700433 CJS_Value& vRet,
434 CFX_WideString& sError) {
435 if (params.size() == 1) {
tsepezcd5dc852016-09-08 11:23:24 -0700436 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
dsinclair82e17672016-10-11 12:38:01 -0700437 pRuntime->GetFormFillEnv()->JS_appBeep(params[0].ToInt(pRuntime));
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700438 return TRUE;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700439 }
440
tsepezcd5dc852016-09-08 11:23:24 -0700441 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700442 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700443}
444
Tom Sepezba038bc2015-10-08 12:03:00 -0700445FX_BOOL app::findComponent(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -0800446 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700447 CJS_Value& vRet,
448 CFX_WideString& sError) {
449 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700450}
451
Tom Sepezba038bc2015-10-08 12:03:00 -0700452FX_BOOL app::popUpMenuEx(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -0800453 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700454 CJS_Value& vRet,
455 CFX_WideString& sError) {
456 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700457}
458
Tom Sepezba038bc2015-10-08 12:03:00 -0700459FX_BOOL app::fs(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700460 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700461}
462
Tom Sepezba038bc2015-10-08 12:03:00 -0700463FX_BOOL app::setInterval(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -0800464 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700465 CJS_Value& vRet,
466 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700467 if (params.size() > 2 || params.size() == 0) {
tsepezcd5dc852016-09-08 11:23:24 -0700468 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700469 return FALSE;
470 }
Tom Sepezc6ab1722015-02-05 15:27:25 -0800471
tsepezcd5dc852016-09-08 11:23:24 -0700472 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
tsepezf3dc8c62016-08-10 06:29:29 -0700473 CFX_WideString script =
tsepezb4694242016-08-15 16:44:55 -0700474 params.size() > 0 ? params[0].ToCFXWideString(pRuntime) : L"";
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700475 if (script.IsEmpty()) {
tsepezcd5dc852016-09-08 11:23:24 -0700476 sError = JSGetStringFromID(IDS_STRING_JSAFNUMBER_KEYSTROKE);
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700477 return TRUE;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700478 }
479
tsepezb4694242016-08-15 16:44:55 -0700480 uint32_t dwInterval = params.size() > 1 ? params[1].ToInt(pRuntime) : 1000;
dsinclair2eb7c7d2016-08-18 09:58:19 -0700481
dsinclair82e17672016-10-11 12:38:01 -0700482 GlobalTimer* timerRef = new GlobalTimer(this, pRuntime->GetFormFillEnv(),
483 pRuntime, 0, script, dwInterval, 0);
tsepeza752edf2016-08-19 14:57:42 -0700484 m_Timers.insert(std::unique_ptr<GlobalTimer>(timerRef));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700485
tsepezb4694242016-08-15 16:44:55 -0700486 v8::Local<v8::Object> pRetObj =
487 pRuntime->NewFxDynamicObj(CJS_TimerObj::g_nObjDefnID);
488 CJS_TimerObj* pJS_TimerObj =
489 static_cast<CJS_TimerObj*>(pRuntime->GetObjectPrivate(pRetObj));
tsepez41a53ad2016-03-28 16:59:30 -0700490 TimerObj* pTimerObj = static_cast<TimerObj*>(pJS_TimerObj->GetEmbedObject());
dsinclair2eb7c7d2016-08-18 09:58:19 -0700491 pTimerObj->SetTimer(timerRef);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700492
tsepezf3dc8c62016-08-10 06:29:29 -0700493 vRet = CJS_Value(pRuntime, pRetObj);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700494 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700495}
496
Tom Sepezba038bc2015-10-08 12:03:00 -0700497FX_BOOL app::setTimeOut(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -0800498 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700499 CJS_Value& vRet,
500 CFX_WideString& sError) {
501 if (params.size() > 2 || params.size() == 0) {
tsepezcd5dc852016-09-08 11:23:24 -0700502 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700503 return FALSE;
504 }
Tom Sepezc6ab1722015-02-05 15:27:25 -0800505
tsepezcd5dc852016-09-08 11:23:24 -0700506 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
tsepezb4694242016-08-15 16:44:55 -0700507 CFX_WideString script = params[0].ToCFXWideString(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700508 if (script.IsEmpty()) {
tsepezcd5dc852016-09-08 11:23:24 -0700509 sError = JSGetStringFromID(IDS_STRING_JSAFNUMBER_KEYSTROKE);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700510 return TRUE;
511 }
512
tsepezb4694242016-08-15 16:44:55 -0700513 uint32_t dwTimeOut = params.size() > 1 ? params[1].ToInt(pRuntime) : 1000;
tsepeza752edf2016-08-19 14:57:42 -0700514 GlobalTimer* timerRef =
dsinclair82e17672016-10-11 12:38:01 -0700515 new GlobalTimer(this, pRuntime->GetFormFillEnv(), pRuntime, 1, script,
516 dwTimeOut, dwTimeOut);
tsepeza752edf2016-08-19 14:57:42 -0700517 m_Timers.insert(std::unique_ptr<GlobalTimer>(timerRef));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700518
tsepezb4694242016-08-15 16:44:55 -0700519 v8::Local<v8::Object> pRetObj =
520 pRuntime->NewFxDynamicObj(CJS_TimerObj::g_nObjDefnID);
tsepez41a53ad2016-03-28 16:59:30 -0700521
tsepezb4694242016-08-15 16:44:55 -0700522 CJS_TimerObj* pJS_TimerObj =
523 static_cast<CJS_TimerObj*>(pRuntime->GetObjectPrivate(pRetObj));
tsepez41a53ad2016-03-28 16:59:30 -0700524
525 TimerObj* pTimerObj = static_cast<TimerObj*>(pJS_TimerObj->GetEmbedObject());
dsinclair2eb7c7d2016-08-18 09:58:19 -0700526 pTimerObj->SetTimer(timerRef);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700527
tsepezf3dc8c62016-08-10 06:29:29 -0700528 vRet = CJS_Value(pRuntime, pRetObj);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700529 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700530}
531
Tom Sepezba038bc2015-10-08 12:03:00 -0700532FX_BOOL app::clearTimeOut(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -0800533 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700534 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);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700538 return FALSE;
539 }
540
tsepezcd5dc852016-09-08 11:23:24 -0700541 app::ClearTimerCommon(CJS_Runtime::FromContext(cc), params[0]);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700542 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700543}
544
Tom Sepezba038bc2015-10-08 12:03:00 -0700545FX_BOOL app::clearInterval(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -0800546 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700547 CJS_Value& vRet,
548 CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700549 if (params.size() != 1) {
tsepezcd5dc852016-09-08 11:23:24 -0700550 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700551 return FALSE;
552 }
553
tsepezcd5dc852016-09-08 11:23:24 -0700554 app::ClearTimerCommon(CJS_Runtime::FromContext(cc), params[0]);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700555 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700556}
557
tsepezb4694242016-08-15 16:44:55 -0700558void app::ClearTimerCommon(CJS_Runtime* pRuntime, const CJS_Value& param) {
tsepez40faa792016-07-15 17:58:02 -0700559 if (param.GetType() != CJS_Value::VT_object)
tsepez41a53ad2016-03-28 16:59:30 -0700560 return;
561
tsepezb4694242016-08-15 16:44:55 -0700562 v8::Local<v8::Object> pObj = param.ToV8Object(pRuntime);
563 if (CFXJS_Engine::GetObjDefnID(pObj) != CJS_TimerObj::g_nObjDefnID)
tsepez41a53ad2016-03-28 16:59:30 -0700564 return;
565
tsepezb4694242016-08-15 16:44:55 -0700566 CJS_Object* pJSObj = param.ToCJSObject(pRuntime);
tsepez41a53ad2016-03-28 16:59:30 -0700567 if (!pJSObj)
568 return;
569
570 TimerObj* pTimerObj = static_cast<TimerObj*>(pJSObj->GetEmbedObject());
571 if (!pTimerObj)
572 return;
573
tsepeze3ff76b2016-08-08 11:58:47 -0700574 GlobalTimer::Cancel(pTimerObj->GetTimerID());
tsepez41a53ad2016-03-28 16:59:30 -0700575}
576
Tom Sepezba038bc2015-10-08 12:03:00 -0700577FX_BOOL app::execMenuItem(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -0800578 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700579 CJS_Value& vRet,
580 CFX_WideString& sError) {
581 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700582}
583
tsepeze3ff76b2016-08-08 11:58:47 -0700584void app::TimerProc(GlobalTimer* pTimer) {
Lei Zhang2d5a0e12015-10-05 17:00:03 -0700585 CJS_Runtime* pRuntime = pTimer->GetRuntime();
tsepez8ca63de2016-08-05 17:12:27 -0700586 if (pRuntime && (!pTimer->IsOneShot() || pTimer->GetTimeOut() > 0))
587 RunJsScript(pRuntime, pTimer->GetJScript());
588}
Lei Zhang2d5a0e12015-10-05 17:00:03 -0700589
tsepeze3ff76b2016-08-08 11:58:47 -0700590void app::CancelProc(GlobalTimer* pTimer) {
tsepeza752edf2016-08-19 14:57:42 -0700591 m_Timers.erase(pdfium::FakeUniquePtr<GlobalTimer>(pTimer));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700592}
593
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700594void app::RunJsScript(CJS_Runtime* pRuntime, const CFX_WideString& wsScript) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700595 if (!pRuntime->IsBlocking()) {
Tom Sepezba038bc2015-10-08 12:03:00 -0700596 IJS_Context* pContext = pRuntime->NewContext();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700597 pContext->OnExternal_Exec();
598 CFX_WideString wtInfo;
Tom Sepez33420902015-10-13 15:00:10 -0700599 pContext->RunScript(wsScript, &wtInfo);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700600 pRuntime->ReleaseContext(pContext);
601 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700602}
603
Tom Sepezba038bc2015-10-08 12:03:00 -0700604FX_BOOL app::goBack(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -0800605 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700606 CJS_Value& vRet,
607 CFX_WideString& sError) {
Tom Sepezc6ab1722015-02-05 15:27:25 -0800608 // Not supported.
609 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700610}
611
Tom Sepezba038bc2015-10-08 12:03:00 -0700612FX_BOOL app::goForward(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -0800613 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700614 CJS_Value& vRet,
615 CFX_WideString& sError) {
Tom Sepezc6ab1722015-02-05 15:27:25 -0800616 // Not supported.
617 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700618}
619
Tom Sepezba038bc2015-10-08 12:03:00 -0700620FX_BOOL app::mailMsg(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -0800621 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700622 CJS_Value& vRet,
623 CFX_WideString& sError) {
tsepezcd5dc852016-09-08 11:23:24 -0700624 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
Tom Sepeze5fbd7a2016-01-29 17:05:08 -0800625 std::vector<CJS_Value> newParams =
626 JS_ExpandKeywordParams(pRuntime, params, 6, L"bUI", L"cTo", L"cCc",
627 L"cBcc", L"cSubject", L"cMsg");
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700628
Tom Sepeze5fbd7a2016-01-29 17:05:08 -0800629 if (newParams[0].GetType() == CJS_Value::VT_unknown) {
tsepezcd5dc852016-09-08 11:23:24 -0700630 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);
Tom Sepeze5fbd7a2016-01-29 17:05:08 -0800631 return FALSE;
632 }
tsepezb4694242016-08-15 16:44:55 -0700633 bool bUI = newParams[0].ToBool(pRuntime);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700634
Tom Sepeze5fbd7a2016-01-29 17:05:08 -0800635 CFX_WideString cTo;
636 if (newParams[1].GetType() != CJS_Value::VT_unknown) {
tsepezb4694242016-08-15 16:44:55 -0700637 cTo = newParams[1].ToCFXWideString(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700638 } else {
Tom Sepeze5fbd7a2016-01-29 17:05:08 -0800639 if (!bUI) {
640 // cTo parameter required when UI not invoked.
tsepezcd5dc852016-09-08 11:23:24 -0700641 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700642 return FALSE;
Tom Sepeze5fbd7a2016-01-29 17:05:08 -0800643 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700644 }
Tom Sepezc6ab1722015-02-05 15:27:25 -0800645
Tom Sepeze5fbd7a2016-01-29 17:05:08 -0800646 CFX_WideString cCc;
647 if (newParams[2].GetType() != CJS_Value::VT_unknown)
tsepezb4694242016-08-15 16:44:55 -0700648 cCc = newParams[2].ToCFXWideString(pRuntime);
Tom Sepeze5fbd7a2016-01-29 17:05:08 -0800649
650 CFX_WideString cBcc;
651 if (newParams[3].GetType() != CJS_Value::VT_unknown)
tsepezb4694242016-08-15 16:44:55 -0700652 cBcc = newParams[3].ToCFXWideString(pRuntime);
Tom Sepeze5fbd7a2016-01-29 17:05:08 -0800653
654 CFX_WideString cSubject;
655 if (newParams[4].GetType() != CJS_Value::VT_unknown)
tsepezb4694242016-08-15 16:44:55 -0700656 cSubject = newParams[4].ToCFXWideString(pRuntime);
Tom Sepeze5fbd7a2016-01-29 17:05:08 -0800657
658 CFX_WideString cMsg;
659 if (newParams[5].GetType() != CJS_Value::VT_unknown)
tsepezb4694242016-08-15 16:44:55 -0700660 cMsg = newParams[5].ToCFXWideString(pRuntime);
Tom Sepeze5fbd7a2016-01-29 17:05:08 -0800661
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700662 pRuntime->BeginBlock();
tsepezcd5dc852016-09-08 11:23:24 -0700663 CJS_Context* pContext = static_cast<CJS_Context*>(cc);
dsinclair4526faf2016-10-11 10:54:49 -0700664 pContext->GetFormFillEnv()->JS_docmailForm(nullptr, 0, bUI, cTo.c_str(),
665 cSubject.c_str(), cCc.c_str(),
666 cBcc.c_str(), cMsg.c_str());
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700667 pRuntime->EndBlock();
Tom Sepeze5fbd7a2016-01-29 17:05:08 -0800668 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700669}
670
Tom Sepezba038bc2015-10-08 12:03:00 -0700671FX_BOOL app::launchURL(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -0800672 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700673 CJS_Value& vRet,
674 CFX_WideString& sError) {
Tom Sepezc6ab1722015-02-05 15:27:25 -0800675 // Unsafe, not supported.
676 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700677}
678
Tom Sepezba038bc2015-10-08 12:03:00 -0700679FX_BOOL app::runtimeHighlight(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700680 CJS_PropValue& vp,
681 CFX_WideString& sError) {
682 if (vp.IsSetting()) {
683 vp >> m_bRuntimeHighLight;
684 } else {
685 vp << m_bRuntimeHighLight;
686 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700687 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700688}
689
Tom Sepezba038bc2015-10-08 12:03:00 -0700690FX_BOOL app::fullscreen(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700691 CJS_PropValue& vp,
692 CFX_WideString& sError) {
693 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700694}
695
Tom Sepezba038bc2015-10-08 12:03:00 -0700696FX_BOOL app::popUpMenu(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -0800697 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700698 CJS_Value& vRet,
699 CFX_WideString& sError) {
700 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700701}
702
Tom Sepezba038bc2015-10-08 12:03:00 -0700703FX_BOOL app::browseForDoc(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -0800704 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700705 CJS_Value& vRet,
706 CFX_WideString& sError) {
Tom Sepezc6ab1722015-02-05 15:27:25 -0800707 // Unsafe, not supported.
708 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700709}
710
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700711CFX_WideString app::SysPathToPDFPath(const CFX_WideString& sOldPath) {
712 CFX_WideString sRet = L"/";
Tom Sepezc6ab1722015-02-05 15:27:25 -0800713
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700714 for (int i = 0, sz = sOldPath.GetLength(); i < sz; i++) {
715 wchar_t c = sOldPath.GetAt(i);
716 if (c == L':') {
717 } else {
718 if (c == L'\\') {
719 sRet += L"/";
720 } else {
721 sRet += c;
722 }
723 }
724 }
Tom Sepezc6ab1722015-02-05 15:27:25 -0800725
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700726 return sRet;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700727}
728
Tom Sepezba038bc2015-10-08 12:03:00 -0700729FX_BOOL app::newDoc(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -0800730 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700731 CJS_Value& vRet,
732 CFX_WideString& sError) {
733 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700734}
735
Tom Sepezba038bc2015-10-08 12:03:00 -0700736FX_BOOL app::openDoc(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -0800737 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700738 CJS_Value& vRet,
739 CFX_WideString& sError) {
740 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700741}
742
Tom Sepezba038bc2015-10-08 12:03:00 -0700743FX_BOOL app::response(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -0800744 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700745 CJS_Value& vRet,
746 CFX_WideString& sError) {
Tom Sepez67fd5df2015-10-08 12:24:19 -0700747 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
Tom Sepez58fb36a2016-02-01 10:32:14 -0800748 std::vector<CJS_Value> newParams =
749 JS_ExpandKeywordParams(pRuntime, params, 5, L"cQuestion", L"cTitle",
750 L"cDefault", L"bPassword", L"cLabel");
Tom Sepez621d4de2014-07-29 14:01:21 -0700751
Tom Sepez58fb36a2016-02-01 10:32:14 -0800752 if (newParams[0].GetType() == CJS_Value::VT_unknown) {
tsepezcd5dc852016-09-08 11:23:24 -0700753 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);
Tom Sepez58fb36a2016-02-01 10:32:14 -0800754 return FALSE;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700755 }
tsepezb4694242016-08-15 16:44:55 -0700756 CFX_WideString swQuestion = newParams[0].ToCFXWideString(pRuntime);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700757
Tom Sepez58fb36a2016-02-01 10:32:14 -0800758 CFX_WideString swTitle = L"PDF";
759 if (newParams[1].GetType() != CJS_Value::VT_unknown)
tsepezb4694242016-08-15 16:44:55 -0700760 swTitle = newParams[1].ToCFXWideString(pRuntime);
Tom Sepez58fb36a2016-02-01 10:32:14 -0800761
762 CFX_WideString swDefault;
763 if (newParams[2].GetType() != CJS_Value::VT_unknown)
tsepezb4694242016-08-15 16:44:55 -0700764 swDefault = newParams[2].ToCFXWideString(pRuntime);
Tom Sepez58fb36a2016-02-01 10:32:14 -0800765
766 bool bPassword = false;
767 if (newParams[3].GetType() != CJS_Value::VT_unknown)
tsepezb4694242016-08-15 16:44:55 -0700768 bPassword = newParams[3].ToBool(pRuntime);
Tom Sepez58fb36a2016-02-01 10:32:14 -0800769
770 CFX_WideString swLabel;
771 if (newParams[4].GetType() != CJS_Value::VT_unknown)
tsepezb4694242016-08-15 16:44:55 -0700772 swLabel = newParams[4].ToCFXWideString(pRuntime);
Tom Sepez621d4de2014-07-29 14:01:21 -0700773
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700774 const int MAX_INPUT_BYTES = 2048;
Lei Zhangaa8bf7e2015-12-24 19:13:32 -0800775 std::unique_ptr<char[]> pBuff(new char[MAX_INPUT_BYTES + 2]);
Lei Zhangdb5256f2015-10-02 10:11:43 -0700776 memset(pBuff.get(), 0, MAX_INPUT_BYTES + 2);
Tom Sepez58fb36a2016-02-01 10:32:14 -0800777
tsepezcd5dc852016-09-08 11:23:24 -0700778 CJS_Context* pContext = static_cast<CJS_Context*>(cc);
dsinclair4526faf2016-10-11 10:54:49 -0700779 int nLengthBytes = pContext->GetFormFillEnv()->JS_appResponse(
Lei Zhangdb5256f2015-10-02 10:11:43 -0700780 swQuestion.c_str(), swTitle.c_str(), swDefault.c_str(), swLabel.c_str(),
Tom Sepez58fb36a2016-02-01 10:32:14 -0800781 bPassword, pBuff.get(), MAX_INPUT_BYTES);
782
783 if (nLengthBytes < 0 || nLengthBytes > MAX_INPUT_BYTES) {
tsepezcd5dc852016-09-08 11:23:24 -0700784 sError = JSGetStringFromID(IDS_STRING_JSPARAM_TOOLONG);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700785 return FALSE;
786 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700787
tsepezf3dc8c62016-08-10 06:29:29 -0700788 vRet = CJS_Value(pRuntime, CFX_WideString::FromUTF16LE(
789 reinterpret_cast<uint16_t*>(pBuff.get()),
790 nLengthBytes / sizeof(uint16_t))
791 .c_str());
792
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700793 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700794}
795
Tom Sepezba038bc2015-10-08 12:03:00 -0700796FX_BOOL app::media(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700797 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700798}
799
Tom Sepezba038bc2015-10-08 12:03:00 -0700800FX_BOOL app::execDialog(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -0800801 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700802 CJS_Value& vRet,
803 CFX_WideString& sError) {
804 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700805}