blob: ae9001f04c2c50460903b5224579249d04447631 [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
Tom Sepez37458412015-10-06 11:33:46 -07007#include "app.h"
8
Lei Zhangdb5256f2015-10-02 10:11:43 -07009#include "../../../third_party/base/nonstd_unique_ptr.h"
Tom Sepez37458412015-10-06 11:33:46 -070010#include "../../include/fsdk_mgr.h" // For CPDFDoc_Environment.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070011#include "../../include/javascript/IJavaScript.h"
Tom Sepez37458412015-10-06 11:33:46 -070012#include "Document.h"
13#include "JS_Context.h"
14#include "JS_Define.h"
15#include "JS_EventHandler.h"
16#include "JS_Object.h"
17#include "JS_Runtime.h"
18#include "JS_Value.h"
19#include "resource.h"
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070020
Nico Weber9d8ec5a2015-08-04 13:00:21 -070021static v8::Isolate* GetIsolate(IFXJS_Context* cc) {
22 CJS_Context* pContext = (CJS_Context*)cc;
Nico Weber9d8ec5a2015-08-04 13:00:21 -070023 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
Nico Weber9d8ec5a2015-08-04 13:00:21 -070024 return pRuntime->GetIsolate();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070025}
26
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070027BEGIN_JS_STATIC_CONST(CJS_TimerObj)
28END_JS_STATIC_CONST()
29
30BEGIN_JS_STATIC_PROP(CJS_TimerObj)
31END_JS_STATIC_PROP()
32
33BEGIN_JS_STATIC_METHOD(CJS_TimerObj)
34END_JS_STATIC_METHOD()
35
36IMPLEMENT_JS_CLASS(CJS_TimerObj, TimerObj)
37
38TimerObj::TimerObj(CJS_Object* pJSObject)
Nico Weber9d8ec5a2015-08-04 13:00:21 -070039 : CJS_EmbedObj(pJSObject), m_pTimer(NULL) {}
Tom Sepezc6ab1722015-02-05 15:27:25 -080040
Nico Weber9d8ec5a2015-08-04 13:00:21 -070041TimerObj::~TimerObj() {}
42
43void TimerObj::SetTimer(CJS_Timer* pTimer) {
44 m_pTimer = pTimer;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070045}
46
Nico Weber9d8ec5a2015-08-04 13:00:21 -070047CJS_Timer* TimerObj::GetTimer() const {
48 return m_pTimer;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070049}
50
Tom Sepezd6278ba2015-09-08 16:34:37 -070051#define JS_STR_VIEWERTYPE L"pdfium"
Nico Weber9d8ec5a2015-08-04 13:00:21 -070052#define JS_STR_VIEWERVARIATION L"Full"
53#define JS_STR_PLATFORM L"WIN"
54#define JS_STR_LANGUANGE L"ENU"
Tom Sepezd6278ba2015-09-08 16:34:37 -070055#define JS_NUM_VIEWERVERSION 8
56#define JS_NUM_VIEWERVERSION_XFA 11
Nico Weber9d8ec5a2015-08-04 13:00:21 -070057#define JS_NUM_FORMSVERSION 7
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070058
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070059BEGIN_JS_STATIC_CONST(CJS_App)
60END_JS_STATIC_CONST()
61
62BEGIN_JS_STATIC_PROP(CJS_App)
Nico Weber9d8ec5a2015-08-04 13:00:21 -070063JS_STATIC_PROP_ENTRY(activeDocs)
64JS_STATIC_PROP_ENTRY(calculate)
65JS_STATIC_PROP_ENTRY(formsVersion)
66JS_STATIC_PROP_ENTRY(fs)
67JS_STATIC_PROP_ENTRY(fullscreen)
68JS_STATIC_PROP_ENTRY(language)
69JS_STATIC_PROP_ENTRY(media)
70JS_STATIC_PROP_ENTRY(platform)
71JS_STATIC_PROP_ENTRY(runtimeHighlight)
72JS_STATIC_PROP_ENTRY(viewerType)
73JS_STATIC_PROP_ENTRY(viewerVariation)
74JS_STATIC_PROP_ENTRY(viewerVersion)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070075END_JS_STATIC_PROP()
76
77BEGIN_JS_STATIC_METHOD(CJS_App)
Nico Weber9d8ec5a2015-08-04 13:00:21 -070078JS_STATIC_METHOD_ENTRY(alert)
79JS_STATIC_METHOD_ENTRY(beep)
80JS_STATIC_METHOD_ENTRY(browseForDoc)
81JS_STATIC_METHOD_ENTRY(clearInterval)
82JS_STATIC_METHOD_ENTRY(clearTimeOut)
83JS_STATIC_METHOD_ENTRY(execDialog)
84JS_STATIC_METHOD_ENTRY(execMenuItem)
85JS_STATIC_METHOD_ENTRY(findComponent)
86JS_STATIC_METHOD_ENTRY(goBack)
87JS_STATIC_METHOD_ENTRY(goForward)
88JS_STATIC_METHOD_ENTRY(launchURL)
89JS_STATIC_METHOD_ENTRY(mailMsg)
90JS_STATIC_METHOD_ENTRY(newFDF)
91JS_STATIC_METHOD_ENTRY(newDoc)
92JS_STATIC_METHOD_ENTRY(openDoc)
93JS_STATIC_METHOD_ENTRY(openFDF)
94JS_STATIC_METHOD_ENTRY(popUpMenuEx)
95JS_STATIC_METHOD_ENTRY(popUpMenu)
96JS_STATIC_METHOD_ENTRY(response)
97JS_STATIC_METHOD_ENTRY(setInterval)
98JS_STATIC_METHOD_ENTRY(setTimeOut)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070099END_JS_STATIC_METHOD()
100
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700101IMPLEMENT_JS_CLASS(CJS_App, app)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700102
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700103app::app(CJS_Object* pJSObject)
104 : CJS_EmbedObj(pJSObject), m_bCalculate(true), m_bRuntimeHighLight(false) {}
105
Lei Zhang2b1a2d52015-08-14 22:16:22 -0700106app::~app() {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700107 for (int i = 0, sz = m_aTimer.GetSize(); i < sz; i++)
108 delete m_aTimer[i];
109
110 m_aTimer.RemoveAll();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700111}
112
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700113FX_BOOL app::activeDocs(IFXJS_Context* cc,
114 CJS_PropValue& vp,
115 CFX_WideString& sError) {
116 if (!vp.IsGetting())
117 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700118
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700119 CJS_Context* pContext = (CJS_Context*)cc;
120 CPDFDoc_Environment* pApp = pContext->GetReaderApp();
121 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
122 CPDFSDK_Document* pCurDoc = pContext->GetReaderDocument();
123 CJS_Array aDocs(pRuntime->GetIsolate());
124 if (CPDFSDK_Document* pDoc = pApp->GetSDKDocument()) {
125 CJS_Document* pJSDocument = NULL;
126 if (pDoc == pCurDoc) {
Tom Sepez39bfe122015-09-17 15:25:23 -0700127 v8::Local<v8::Object> pObj = FXJS_GetThisObj(pRuntime->GetIsolate());
Tom Sepezcd56a7d2015-10-06 11:45:28 -0700128 if (FXJS_GetObjDefnID(pObj) == CJS_Document::g_nObjDefnID)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700129 pJSDocument =
Tom Sepez39bfe122015-09-17 15:25:23 -0700130 (CJS_Document*)FXJS_GetPrivate(pRuntime->GetIsolate(), pObj);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700131 } else {
Tom Sepez39bfe122015-09-17 15:25:23 -0700132 v8::Local<v8::Object> pObj = FXJS_NewFxDynamicObj(
Tom Sepezcd56a7d2015-10-06 11:45:28 -0700133 pRuntime->GetIsolate(), pContext, CJS_Document::g_nObjDefnID);
Tom Sepez39bfe122015-09-17 15:25:23 -0700134 pJSDocument =
135 (CJS_Document*)FXJS_GetPrivate(pRuntime->GetIsolate(), pObj);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700136 ASSERT(pJSDocument != NULL);
137 }
138 aDocs.SetElement(0, CJS_Value(pRuntime->GetIsolate(), pJSDocument));
139 }
140 if (aDocs.GetLength() > 0)
141 vp << aDocs;
142 else
143 vp.SetNull();
144
145 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700146}
147
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700148FX_BOOL app::calculate(IFXJS_Context* cc,
149 CJS_PropValue& vp,
150 CFX_WideString& sError) {
151 if (vp.IsSetting()) {
152 bool bVP;
153 vp >> bVP;
154 m_bCalculate = (FX_BOOL)bVP;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700155
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700156 CJS_Context* pContext = (CJS_Context*)cc;
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700157 CPDFDoc_Environment* pApp = pContext->GetReaderApp();
158 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700159 CJS_Array aDocs(pRuntime->GetIsolate());
160 if (CPDFSDK_Document* pDoc = pApp->GetSDKDocument())
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700161 pDoc->GetInterForm()->EnableCalculate((FX_BOOL)m_bCalculate);
162 } else {
163 vp << (bool)m_bCalculate;
164 }
165 return TRUE;
166}
167
168FX_BOOL app::formsVersion(IFXJS_Context* cc,
169 CJS_PropValue& vp,
170 CFX_WideString& sError) {
171 if (vp.IsGetting()) {
172 vp << JS_NUM_FORMSVERSION;
173 return TRUE;
174 }
175
176 return FALSE;
177}
178
179FX_BOOL app::viewerType(IFXJS_Context* cc,
180 CJS_PropValue& vp,
181 CFX_WideString& sError) {
182 if (vp.IsGetting()) {
Tom Sepezd6278ba2015-09-08 16:34:37 -0700183 vp << JS_STR_VIEWERTYPE;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700184 return TRUE;
185 }
186
187 return FALSE;
188}
189
190FX_BOOL app::viewerVariation(IFXJS_Context* cc,
191 CJS_PropValue& vp,
192 CFX_WideString& sError) {
193 if (vp.IsGetting()) {
194 vp << JS_STR_VIEWERVARIATION;
195 return TRUE;
196 }
197
198 return FALSE;
199}
200
201FX_BOOL app::viewerVersion(IFXJS_Context* cc,
202 CJS_PropValue& vp,
203 CFX_WideString& sError) {
204 if (!vp.IsGetting())
205 return FALSE;
206
207 CJS_Context* pContext = (CJS_Context*)cc;
208 CPDFSDK_Document* pCurDoc = pContext->GetReaderDocument();
209 CPDFXFA_Document* pDoc = pCurDoc->GetDocument();
210 if (pDoc->GetDocType() == 1 || pDoc->GetDocType() == 2)
Tom Sepezd6278ba2015-09-08 16:34:37 -0700211 vp << JS_NUM_VIEWERVERSION_XFA;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700212 else
Tom Sepezd6278ba2015-09-08 16:34:37 -0700213 vp << JS_NUM_VIEWERVERSION;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700214
215 return TRUE;
216}
217
218FX_BOOL app::platform(IFXJS_Context* cc,
219 CJS_PropValue& vp,
220 CFX_WideString& sError) {
221 if (vp.IsGetting()) {
222 vp << JS_STR_PLATFORM;
223 return TRUE;
224 }
225
226 return FALSE;
227}
228
229FX_BOOL app::language(IFXJS_Context* cc,
230 CJS_PropValue& vp,
231 CFX_WideString& sError) {
232 if (vp.IsGetting()) {
233 vp << JS_STR_LANGUANGE;
234 return TRUE;
235 }
236
237 return FALSE;
238}
239
240// creates a new fdf object that contains no data
241// comment: need reader support
242// note:
243// CFDF_Document * CPDFDoc_Environment::NewFDF();
244FX_BOOL app::newFDF(IFXJS_Context* cc,
245 const CJS_Parameters& params,
246 CJS_Value& vRet,
247 CFX_WideString& sError) {
248 return TRUE;
249}
250// opens a specified pdf document and returns its document object
251// comment:need reader support
252// note: as defined in js reference, the proto of this function's fourth
253// parmeters, how old an fdf document while do not show it.
254// CFDF_Document * CPDFDoc_Environment::OpenFDF(string strPath,bool bUserConv);
255
256FX_BOOL app::openFDF(IFXJS_Context* cc,
257 const CJS_Parameters& params,
258 CJS_Value& vRet,
259 CFX_WideString& sError) {
260 return TRUE;
261}
262
263FX_BOOL app::alert(IFXJS_Context* cc,
264 const CJS_Parameters& params,
265 CJS_Value& vRet,
266 CFX_WideString& sError) {
267 int iSize = params.size();
268 if (iSize < 1)
269 return FALSE;
270
271 CFX_WideString swMsg = L"";
272 CFX_WideString swTitle = L"";
273 int iIcon = 0;
274 int iType = 0;
275
276 v8::Isolate* isolate = GetIsolate(cc);
277
278 if (iSize == 1) {
Tom Sepez39bfe122015-09-17 15:25:23 -0700279 if (params[0].GetType() == CJS_Value::VT_object) {
Tom Sepez808a99e2015-09-10 12:28:37 -0700280 v8::Local<v8::Object> pObj = params[0].ToV8Object();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700281 {
282 v8::Local<v8::Value> pValue =
Tom Sepez39bfe122015-09-17 15:25:23 -0700283 FXJS_GetObjectElement(isolate, pObj, L"cMsg");
284 swMsg =
285 CJS_Value(isolate, pValue, CJS_Value::VT_unknown).ToCFXWideString();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700286
Tom Sepez39bfe122015-09-17 15:25:23 -0700287 pValue = FXJS_GetObjectElement(isolate, pObj, L"cTitle");
288 swTitle =
289 CJS_Value(isolate, pValue, CJS_Value::VT_unknown).ToCFXWideString();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700290
Tom Sepez39bfe122015-09-17 15:25:23 -0700291 pValue = FXJS_GetObjectElement(isolate, pObj, L"nIcon");
292 iIcon = CJS_Value(isolate, pValue, CJS_Value::VT_unknown).ToInt();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700293
Tom Sepez39bfe122015-09-17 15:25:23 -0700294 pValue = FXJS_GetObjectElement(isolate, pObj, L"nType");
295 iType = CJS_Value(isolate, pValue, CJS_Value::VT_unknown).ToInt();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700296 }
297
298 if (swMsg == L"") {
299 CJS_Array carray(isolate);
300 if (params[0].ConvertToArray(carray)) {
Lei Zhange00660b2015-08-13 15:40:18 -0700301 int iLength = carray.GetLength();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700302 CJS_Value* pValue = new CJS_Value(isolate);
Lei Zhange00660b2015-08-13 15:40:18 -0700303 for (int i = 0; i < iLength; ++i) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700304 carray.GetElement(i, *pValue);
305 swMsg += (*pValue).ToCFXWideString();
Lei Zhange00660b2015-08-13 15:40:18 -0700306 if (i < iLength - 1)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700307 swMsg += L", ";
308 }
309
310 delete pValue;
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700311 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700312 }
313
314 if (swTitle == L"")
315 swTitle = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSALERT);
Tom Sepez39bfe122015-09-17 15:25:23 -0700316 } else if (params[0].GetType() == CJS_Value::VT_boolean) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700317 FX_BOOL bGet = params[0].ToBool();
318 if (bGet)
319 swMsg = L"true";
320 else
321 swMsg = L"false";
322
323 swTitle = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSALERT);
324 } else {
325 swMsg = params[0].ToCFXWideString();
326 swTitle = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSALERT);
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700327 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700328 } else {
Tom Sepez39bfe122015-09-17 15:25:23 -0700329 if (params[0].GetType() == CJS_Value::VT_boolean) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700330 FX_BOOL bGet = params[0].ToBool();
331 if (bGet)
332 swMsg = L"true";
333 else
334 swMsg = L"false";
335 } else {
336 swMsg = params[0].ToCFXWideString();
337 }
338 swTitle = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSALERT);
Tom Sepezc6ab1722015-02-05 15:27:25 -0800339
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700340 for (int i = 1; i < iSize; i++) {
341 if (i == 1)
342 iIcon = params[i].ToInt();
343 if (i == 2)
344 iType = params[i].ToInt();
345 if (i == 3)
346 swTitle = params[i].ToCFXWideString();
347 }
348 }
349
350 CJS_Context* pContext = (CJS_Context*)cc;
351 ASSERT(pContext != NULL);
352 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
353 ASSERT(pRuntime != NULL);
354 pRuntime->BeginBlock();
Lei Zhangd607f5b2015-10-05 17:06:09 -0700355 vRet = MsgBox(pRuntime->GetReaderApp(), swMsg.c_str(), swTitle.c_str(), iType,
356 iIcon);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700357 pRuntime->EndBlock();
358
359 return TRUE;
360}
361
362FX_BOOL app::beep(IFXJS_Context* cc,
363 const CJS_Parameters& params,
364 CJS_Value& vRet,
365 CFX_WideString& sError) {
366 if (params.size() == 1) {
367 CJS_Context* pContext = (CJS_Context*)cc;
368 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
369 CPDFDoc_Environment* pEnv = pRuntime->GetReaderApp();
370 pEnv->JS_appBeep(params[0].ToInt());
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700371 return TRUE;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700372 }
373
374 sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSPARAMERROR);
375 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700376}
377
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700378FX_BOOL app::findComponent(IFXJS_Context* cc,
379 const CJS_Parameters& params,
380 CJS_Value& vRet,
381 CFX_WideString& sError) {
382 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700383}
384
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700385FX_BOOL app::popUpMenuEx(IFXJS_Context* cc,
386 const CJS_Parameters& params,
387 CJS_Value& vRet,
388 CFX_WideString& sError) {
389 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700390}
391
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700392FX_BOOL app::fs(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) {
393 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700394}
395
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700396FX_BOOL app::setInterval(IFXJS_Context* cc,
397 const CJS_Parameters& params,
398 CJS_Value& vRet,
399 CFX_WideString& sError) {
400 CJS_Context* pContext = (CJS_Context*)cc;
401 if (params.size() > 2 || params.size() == 0) {
402 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
403 return FALSE;
404 }
Tom Sepezc6ab1722015-02-05 15:27:25 -0800405
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700406 CFX_WideString script = params.size() > 0 ? params[0].ToCFXWideString() : L"";
407 if (script.IsEmpty()) {
408 sError = JSGetStringFromID(pContext, IDS_STRING_JSAFNUMBER_KEYSTROKE);
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700409 return TRUE;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700410 }
411
412 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
413 FX_DWORD dwInterval = params.size() > 1 ? params[1].ToInt() : 1000;
414
415 CPDFDoc_Environment* pApp = pRuntime->GetReaderApp();
416 ASSERT(pApp);
Lei Zhang2d5a0e12015-10-05 17:00:03 -0700417 CJS_Timer* pTimer =
418 new CJS_Timer(this, pApp, pRuntime, 0, script, dwInterval, 0);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700419 m_aTimer.Add(pTimer);
420
Tom Sepez39bfe122015-09-17 15:25:23 -0700421 v8::Local<v8::Object> pRetObj = FXJS_NewFxDynamicObj(
Tom Sepezcd56a7d2015-10-06 11:45:28 -0700422 pRuntime->GetIsolate(), pContext, CJS_TimerObj::g_nObjDefnID);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700423 CJS_TimerObj* pJS_TimerObj =
Tom Sepez39bfe122015-09-17 15:25:23 -0700424 (CJS_TimerObj*)FXJS_GetPrivate(pRuntime->GetIsolate(), pRetObj);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700425 TimerObj* pTimerObj = (TimerObj*)pJS_TimerObj->GetEmbedObject();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700426 pTimerObj->SetTimer(pTimer);
427
428 vRet = pRetObj;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700429 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700430}
431
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700432FX_BOOL app::setTimeOut(IFXJS_Context* cc,
433 const CJS_Parameters& params,
434 CJS_Value& vRet,
435 CFX_WideString& sError) {
436 if (params.size() > 2 || params.size() == 0) {
437 sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSPARAMERROR);
438 return FALSE;
439 }
Tom Sepezc6ab1722015-02-05 15:27:25 -0800440
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700441 CJS_Context* pContext = (CJS_Context*)cc;
442 ASSERT(pContext != NULL);
443 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
444 ASSERT(pRuntime != NULL);
445
446 CFX_WideString script = params.size() > 0 ? params[0].ToCFXWideString() : L"";
447 if (script.IsEmpty()) {
448 sError =
449 JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSAFNUMBER_KEYSTROKE);
450 return TRUE;
451 }
452
453 FX_DWORD dwTimeOut = params.size() > 1 ? params[1].ToInt() : 1000;
454
455 CPDFDoc_Environment* pApp = pRuntime->GetReaderApp();
456 ASSERT(pApp);
457
Lei Zhang2d5a0e12015-10-05 17:00:03 -0700458 CJS_Timer* pTimer =
459 new CJS_Timer(this, pApp, pRuntime, 1, script, dwTimeOut, dwTimeOut);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700460 m_aTimer.Add(pTimer);
461
Tom Sepez39bfe122015-09-17 15:25:23 -0700462 v8::Local<v8::Object> pRetObj = FXJS_NewFxDynamicObj(
Tom Sepezcd56a7d2015-10-06 11:45:28 -0700463 pRuntime->GetIsolate(), pContext, CJS_TimerObj::g_nObjDefnID);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700464 CJS_TimerObj* pJS_TimerObj =
Tom Sepez39bfe122015-09-17 15:25:23 -0700465 (CJS_TimerObj*)FXJS_GetPrivate(pRuntime->GetIsolate(), pRetObj);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700466 TimerObj* pTimerObj = (TimerObj*)pJS_TimerObj->GetEmbedObject();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700467 pTimerObj->SetTimer(pTimer);
468
469 vRet = pRetObj;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700470 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700471}
472
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700473FX_BOOL app::clearTimeOut(IFXJS_Context* cc,
474 const CJS_Parameters& params,
475 CJS_Value& vRet,
476 CFX_WideString& sError) {
477 CJS_Context* pContext = (CJS_Context*)cc;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700478 if (params.size() != 1) {
Tom Sepezcd56a7d2015-10-06 11:45:28 -0700479 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700480 return FALSE;
481 }
482
Tom Sepez39bfe122015-09-17 15:25:23 -0700483 if (params[0].GetType() == CJS_Value::VT_fxobject) {
Tom Sepez808a99e2015-09-10 12:28:37 -0700484 v8::Local<v8::Object> pObj = params[0].ToV8Object();
Tom Sepezcd56a7d2015-10-06 11:45:28 -0700485 if (FXJS_GetObjDefnID(pObj) == CJS_TimerObj::g_nObjDefnID) {
486 if (CJS_Object* pJSObj = params[0].ToCJSObject()) {
487 if (TimerObj* pTimerObj = (TimerObj*)pJSObj->GetEmbedObject()) {
488 if (CJS_Timer* pTimer = pTimerObj->GetTimer()) {
489 pTimer->KillJSTimer();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700490
Tom Sepezcd56a7d2015-10-06 11:45:28 -0700491 for (int i = 0, sz = m_aTimer.GetSize(); i < sz; i++) {
492 if (m_aTimer[i] == pTimer) {
493 m_aTimer.RemoveAt(i);
494 break;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700495 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700496 }
Tom Sepezcd56a7d2015-10-06 11:45:28 -0700497
498 delete pTimer;
499 pTimerObj->SetTimer(NULL);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700500 }
501 }
502 }
503 }
504 }
505
506 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700507}
508
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700509FX_BOOL app::clearInterval(IFXJS_Context* cc,
510 const CJS_Parameters& params,
511 CJS_Value& vRet,
512 CFX_WideString& sError) {
513 CJS_Context* pContext = (CJS_Context*)cc;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700514 if (params.size() != 1) {
Tom Sepezcd56a7d2015-10-06 11:45:28 -0700515 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700516 return FALSE;
517 }
518
Tom Sepez39bfe122015-09-17 15:25:23 -0700519 if (params[0].GetType() == CJS_Value::VT_fxobject) {
Tom Sepez808a99e2015-09-10 12:28:37 -0700520 v8::Local<v8::Object> pObj = params[0].ToV8Object();
Tom Sepezcd56a7d2015-10-06 11:45:28 -0700521 if (FXJS_GetObjDefnID(pObj) == CJS_TimerObj::g_nObjDefnID) {
522 if (CJS_Object* pJSObj = params[0].ToCJSObject()) {
523 if (TimerObj* pTimerObj = (TimerObj*)pJSObj->GetEmbedObject()) {
524 if (CJS_Timer* pTimer = pTimerObj->GetTimer()) {
525 pTimer->KillJSTimer();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700526
Tom Sepezcd56a7d2015-10-06 11:45:28 -0700527 for (int i = 0, sz = m_aTimer.GetSize(); i < sz; i++) {
528 if (m_aTimer[i] == pTimer) {
529 m_aTimer.RemoveAt(i);
530 break;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700531 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700532 }
Tom Sepezcd56a7d2015-10-06 11:45:28 -0700533
534 delete pTimer;
535 pTimerObj->SetTimer(NULL);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700536 }
537 }
538 }
539 }
540 }
541
542 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700543}
544
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700545FX_BOOL app::execMenuItem(IFXJS_Context* cc,
546 const CJS_Parameters& params,
547 CJS_Value& vRet,
548 CFX_WideString& sError) {
549 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700550}
551
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700552void app::TimerProc(CJS_Timer* pTimer) {
553 ASSERT(pTimer != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700554
Lei Zhang2d5a0e12015-10-05 17:00:03 -0700555 CJS_Runtime* pRuntime = pTimer->GetRuntime();
556
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700557 switch (pTimer->GetType()) {
558 case 0: // interval
Lei Zhang2d5a0e12015-10-05 17:00:03 -0700559 if (pRuntime)
560 RunJsScript(pRuntime, pTimer->GetJScript());
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700561 break;
562 case 1:
563 if (pTimer->GetTimeOut() > 0) {
Lei Zhang2d5a0e12015-10-05 17:00:03 -0700564 if (pRuntime)
565 RunJsScript(pRuntime, pTimer->GetJScript());
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700566 pTimer->KillJSTimer();
567 }
568 break;
569 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700570}
571
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700572void app::RunJsScript(CJS_Runtime* pRuntime, const CFX_WideString& wsScript) {
573 ASSERT(pRuntime != NULL);
574
575 if (!pRuntime->IsBlocking()) {
576 IFXJS_Context* pContext = pRuntime->NewContext();
577 ASSERT(pContext != NULL);
578 pContext->OnExternal_Exec();
579 CFX_WideString wtInfo;
580 pContext->RunScript(wsScript, wtInfo);
581 pRuntime->ReleaseContext(pContext);
582 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700583}
584
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700585FX_BOOL app::goBack(IFXJS_Context* cc,
586 const CJS_Parameters& params,
587 CJS_Value& vRet,
588 CFX_WideString& sError) {
Tom Sepezc6ab1722015-02-05 15:27:25 -0800589 // Not supported.
590 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700591}
592
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700593FX_BOOL app::goForward(IFXJS_Context* cc,
594 const CJS_Parameters& params,
595 CJS_Value& vRet,
596 CFX_WideString& sError) {
Tom Sepezc6ab1722015-02-05 15:27:25 -0800597 // Not supported.
598 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700599}
600
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700601FX_BOOL app::mailMsg(IFXJS_Context* cc,
602 const CJS_Parameters& params,
603 CJS_Value& vRet,
604 CFX_WideString& sError) {
605 CJS_Context* pContext = (CJS_Context*)cc;
606 v8::Isolate* isolate = GetIsolate(cc);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700607
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700608 FX_BOOL bUI = TRUE;
609 CFX_WideString cTo = L"";
610 CFX_WideString cCc = L"";
611 CFX_WideString cBcc = L"";
612 CFX_WideString cSubject = L"";
613 CFX_WideString cMsg = L"";
Tom Sepezf4ef3f92015-04-23 11:31:31 -0700614
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700615 if (params.size() < 1)
616 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700617
Tom Sepez39bfe122015-09-17 15:25:23 -0700618 if (params[0].GetType() == CJS_Value::VT_object) {
Tom Sepez808a99e2015-09-10 12:28:37 -0700619 v8::Local<v8::Object> pObj = params[0].ToV8Object();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700620
Tom Sepez39bfe122015-09-17 15:25:23 -0700621 v8::Local<v8::Value> pValue = FXJS_GetObjectElement(isolate, pObj, L"bUI");
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700622 bUI = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToBool();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700623
Tom Sepez39bfe122015-09-17 15:25:23 -0700624 pValue = FXJS_GetObjectElement(isolate, pObj, L"cTo");
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700625 cTo = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700626
Tom Sepez39bfe122015-09-17 15:25:23 -0700627 pValue = FXJS_GetObjectElement(isolate, pObj, L"cCc");
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700628 cCc = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700629
Tom Sepez39bfe122015-09-17 15:25:23 -0700630 pValue = FXJS_GetObjectElement(isolate, pObj, L"cBcc");
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700631 cBcc = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700632
Tom Sepez39bfe122015-09-17 15:25:23 -0700633 pValue = FXJS_GetObjectElement(isolate, pObj, L"cSubject");
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700634 cSubject =
635 CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700636
Tom Sepez39bfe122015-09-17 15:25:23 -0700637 pValue = FXJS_GetObjectElement(isolate, pObj, L"cMsg");
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700638 cMsg = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString();
639 } else {
640 if (params.size() < 2)
641 return FALSE;
Tom Sepezf4ef3f92015-04-23 11:31:31 -0700642
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700643 bUI = params[0].ToBool();
644 cTo = params[1].ToCFXWideString();
Tom Sepezf4ef3f92015-04-23 11:31:31 -0700645
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700646 if (params.size() >= 3)
647 cCc = params[2].ToCFXWideString();
648 if (params.size() >= 4)
649 cBcc = params[3].ToCFXWideString();
650 if (params.size() >= 5)
651 cSubject = params[4].ToCFXWideString();
652 if (params.size() >= 6)
653 cMsg = params[5].ToCFXWideString();
654 }
Tom Sepezc6ab1722015-02-05 15:27:25 -0800655
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700656 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
657 ASSERT(pRuntime != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700658
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700659 CPDFDoc_Environment* pApp = pContext->GetReaderApp();
660 ASSERT(pApp != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700661
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700662 pRuntime->BeginBlock();
663 pApp->JS_docmailForm(NULL, 0, bUI, cTo.c_str(), cSubject.c_str(), cCc.c_str(),
664 cBcc.c_str(), cMsg.c_str());
665 pRuntime->EndBlock();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700666
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700667 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700668}
669
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700670FX_BOOL app::launchURL(IFXJS_Context* cc,
671 const CJS_Parameters& params,
672 CJS_Value& vRet,
673 CFX_WideString& sError) {
Tom Sepezc6ab1722015-02-05 15:27:25 -0800674 // Unsafe, not supported.
675 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700676}
677
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700678FX_BOOL app::runtimeHighlight(IFXJS_Context* cc,
679 CJS_PropValue& vp,
680 CFX_WideString& sError) {
681 if (vp.IsSetting()) {
682 vp >> m_bRuntimeHighLight;
683 } else {
684 vp << m_bRuntimeHighLight;
685 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700686
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700687 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700688}
689
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700690FX_BOOL app::fullscreen(IFXJS_Context* cc,
691 CJS_PropValue& vp,
692 CFX_WideString& sError) {
693 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700694}
695
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700696FX_BOOL app::popUpMenu(IFXJS_Context* cc,
697 const CJS_Parameters& params,
698 CJS_Value& vRet,
699 CFX_WideString& sError) {
700 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700701}
702
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700703FX_BOOL app::browseForDoc(IFXJS_Context* cc,
704 const CJS_Parameters& params,
705 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
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700729FX_BOOL app::newDoc(IFXJS_Context* cc,
730 const CJS_Parameters& params,
731 CJS_Value& vRet,
732 CFX_WideString& sError) {
733 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700734}
735
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700736FX_BOOL app::openDoc(IFXJS_Context* cc,
737 const CJS_Parameters& params,
738 CJS_Value& vRet,
739 CFX_WideString& sError) {
740 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700741}
742
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700743FX_BOOL app::response(IFXJS_Context* cc,
744 const CJS_Parameters& params,
745 CJS_Value& vRet,
746 CFX_WideString& sError) {
747 CFX_WideString swQuestion = L"";
748 CFX_WideString swLabel = L"";
749 CFX_WideString swTitle = L"PDF";
750 CFX_WideString swDefault = L"";
751 bool bPassWord = false;
Tom Sepez621d4de2014-07-29 14:01:21 -0700752
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700753 v8::Isolate* isolate = GetIsolate(cc);
Tom Sepez621d4de2014-07-29 14:01:21 -0700754
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700755 int iLength = params.size();
Tom Sepez39bfe122015-09-17 15:25:23 -0700756 if (iLength > 0 && params[0].GetType() == CJS_Value::VT_object) {
Tom Sepez808a99e2015-09-10 12:28:37 -0700757 v8::Local<v8::Object> pObj = params[0].ToV8Object();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700758 v8::Local<v8::Value> pValue =
Tom Sepez39bfe122015-09-17 15:25:23 -0700759 FXJS_GetObjectElement(isolate, pObj, L"cQuestion");
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700760 swQuestion =
761 CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700762
Tom Sepez39bfe122015-09-17 15:25:23 -0700763 pValue = FXJS_GetObjectElement(isolate, pObj, L"cTitle");
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700764 swTitle =
765 CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700766
Tom Sepez39bfe122015-09-17 15:25:23 -0700767 pValue = FXJS_GetObjectElement(isolate, pObj, L"cDefault");
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700768 swDefault =
769 CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700770
Tom Sepez39bfe122015-09-17 15:25:23 -0700771 pValue = FXJS_GetObjectElement(isolate, pObj, L"cLabel");
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700772 swLabel =
773 CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700774
Tom Sepez39bfe122015-09-17 15:25:23 -0700775 pValue = FXJS_GetObjectElement(isolate, pObj, L"bPassword");
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700776 bPassWord = CJS_Value(isolate, pValue, GET_VALUE_TYPE(pValue)).ToBool();
777 } else {
778 switch (iLength) {
779 case 5:
780 swLabel = params[4].ToCFXWideString();
781 // FALLTHROUGH
782 case 4:
783 bPassWord = params[3].ToBool();
784 // FALLTHROUGH
785 case 3:
786 swDefault = params[2].ToCFXWideString();
787 // FALLTHROUGH
788 case 2:
789 swTitle = params[1].ToCFXWideString();
790 // FALLTHROUGH
791 case 1:
792 swQuestion = params[0].ToCFXWideString();
793 // FALLTHROUGH
794 default:
795 break;
796 }
797 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700798
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700799 CJS_Context* pContext = (CJS_Context*)cc;
800 ASSERT(pContext != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700801
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700802 CPDFDoc_Environment* pApp = pContext->GetReaderApp();
803 ASSERT(pApp != NULL);
Tom Sepez621d4de2014-07-29 14:01:21 -0700804
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700805 const int MAX_INPUT_BYTES = 2048;
Lei Zhangdb5256f2015-10-02 10:11:43 -0700806 nonstd::unique_ptr<char[]> pBuff(new char[MAX_INPUT_BYTES + 2]);
807 memset(pBuff.get(), 0, MAX_INPUT_BYTES + 2);
808 int nLengthBytes = pApp->JS_appResponse(
809 swQuestion.c_str(), swTitle.c_str(), swDefault.c_str(), swLabel.c_str(),
810 bPassWord, pBuff.get(), MAX_INPUT_BYTES);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700811 if (nLengthBytes <= 0) {
812 vRet.SetNull();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700813 return FALSE;
814 }
Lei Zhangdb5256f2015-10-02 10:11:43 -0700815 nLengthBytes = std::min(nLengthBytes, MAX_INPUT_BYTES);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700816
Lei Zhangdb5256f2015-10-02 10:11:43 -0700817 CFX_WideString ret_string = CFX_WideString::FromUTF16LE(
818 (unsigned short*)pBuff.get(), nLengthBytes / sizeof(unsigned short));
819 vRet = ret_string.c_str();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700820 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700821}
822
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700823FX_BOOL app::media(IFXJS_Context* cc,
824 CJS_PropValue& vp,
825 CFX_WideString& sError) {
826 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700827}
828
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700829FX_BOOL app::execDialog(IFXJS_Context* cc,
830 const CJS_Parameters& params,
831 CJS_Value& vRet,
832 CFX_WideString& sError) {
833 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700834}