blob: 41fa15259a218d6f6ef2b91006b3d2fe1493c89b [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
Dan Sinclair3ebd1212016-03-09 09:59:23 -050012#include "fpdfsdk/include/fsdk_mgr.h"
Lei Zhangbde53d22015-11-12 22:21:30 -080013#include "fpdfsdk/include/javascript/IJavaScript.h"
Dan Sinclairf766ad22016-03-14 13:51:24 -040014#include "fpdfsdk/javascript/Document.h"
15#include "fpdfsdk/javascript/JS_Context.h"
16#include "fpdfsdk/javascript/JS_Define.h"
17#include "fpdfsdk/javascript/JS_EventHandler.h"
18#include "fpdfsdk/javascript/JS_Object.h"
19#include "fpdfsdk/javascript/JS_Runtime.h"
20#include "fpdfsdk/javascript/JS_Value.h"
21#include "fpdfsdk/javascript/resource.h"
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070022
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070023BEGIN_JS_STATIC_CONST(CJS_TimerObj)
24END_JS_STATIC_CONST()
25
26BEGIN_JS_STATIC_PROP(CJS_TimerObj)
27END_JS_STATIC_PROP()
28
29BEGIN_JS_STATIC_METHOD(CJS_TimerObj)
30END_JS_STATIC_METHOD()
31
32IMPLEMENT_JS_CLASS(CJS_TimerObj, TimerObj)
33
34TimerObj::TimerObj(CJS_Object* pJSObject)
Nico Weber9d8ec5a2015-08-04 13:00:21 -070035 : CJS_EmbedObj(pJSObject), m_pTimer(NULL) {}
Tom Sepezc6ab1722015-02-05 15:27:25 -080036
Nico Weber9d8ec5a2015-08-04 13:00:21 -070037TimerObj::~TimerObj() {}
38
39void TimerObj::SetTimer(CJS_Timer* pTimer) {
40 m_pTimer = pTimer;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070041}
42
Nico Weber9d8ec5a2015-08-04 13:00:21 -070043CJS_Timer* TimerObj::GetTimer() const {
44 return m_pTimer;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070045}
46
Tom Sepezd6278ba2015-09-08 16:34:37 -070047#define JS_STR_VIEWERTYPE L"pdfium"
Nico Weber9d8ec5a2015-08-04 13:00:21 -070048#define JS_STR_VIEWERVARIATION L"Full"
49#define JS_STR_PLATFORM L"WIN"
50#define JS_STR_LANGUANGE L"ENU"
Tom Sepezd6278ba2015-09-08 16:34:37 -070051#define JS_NUM_VIEWERVERSION 8
Tom Sepez51da0932015-11-25 16:05:49 -080052#ifdef PDF_ENABLE_XFA
Tom Sepezd6278ba2015-09-08 16:34:37 -070053#define JS_NUM_VIEWERVERSION_XFA 11
Tom Sepez40e9ff32015-11-30 12:39:54 -080054#endif // PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -070055#define JS_NUM_FORMSVERSION 7
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070056
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070057BEGIN_JS_STATIC_CONST(CJS_App)
58END_JS_STATIC_CONST()
59
60BEGIN_JS_STATIC_PROP(CJS_App)
Nico Weber9d8ec5a2015-08-04 13:00:21 -070061JS_STATIC_PROP_ENTRY(activeDocs)
62JS_STATIC_PROP_ENTRY(calculate)
63JS_STATIC_PROP_ENTRY(formsVersion)
64JS_STATIC_PROP_ENTRY(fs)
65JS_STATIC_PROP_ENTRY(fullscreen)
66JS_STATIC_PROP_ENTRY(language)
67JS_STATIC_PROP_ENTRY(media)
68JS_STATIC_PROP_ENTRY(platform)
69JS_STATIC_PROP_ENTRY(runtimeHighlight)
70JS_STATIC_PROP_ENTRY(viewerType)
71JS_STATIC_PROP_ENTRY(viewerVariation)
72JS_STATIC_PROP_ENTRY(viewerVersion)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070073END_JS_STATIC_PROP()
74
75BEGIN_JS_STATIC_METHOD(CJS_App)
Nico Weber9d8ec5a2015-08-04 13:00:21 -070076JS_STATIC_METHOD_ENTRY(alert)
77JS_STATIC_METHOD_ENTRY(beep)
78JS_STATIC_METHOD_ENTRY(browseForDoc)
79JS_STATIC_METHOD_ENTRY(clearInterval)
80JS_STATIC_METHOD_ENTRY(clearTimeOut)
81JS_STATIC_METHOD_ENTRY(execDialog)
82JS_STATIC_METHOD_ENTRY(execMenuItem)
83JS_STATIC_METHOD_ENTRY(findComponent)
84JS_STATIC_METHOD_ENTRY(goBack)
85JS_STATIC_METHOD_ENTRY(goForward)
86JS_STATIC_METHOD_ENTRY(launchURL)
87JS_STATIC_METHOD_ENTRY(mailMsg)
88JS_STATIC_METHOD_ENTRY(newFDF)
89JS_STATIC_METHOD_ENTRY(newDoc)
90JS_STATIC_METHOD_ENTRY(openDoc)
91JS_STATIC_METHOD_ENTRY(openFDF)
92JS_STATIC_METHOD_ENTRY(popUpMenuEx)
93JS_STATIC_METHOD_ENTRY(popUpMenu)
94JS_STATIC_METHOD_ENTRY(response)
95JS_STATIC_METHOD_ENTRY(setInterval)
96JS_STATIC_METHOD_ENTRY(setTimeOut)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070097END_JS_STATIC_METHOD()
98
Nico Weber9d8ec5a2015-08-04 13:00:21 -070099IMPLEMENT_JS_CLASS(CJS_App, app)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700100
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700101app::app(CJS_Object* pJSObject)
102 : CJS_EmbedObj(pJSObject), m_bCalculate(true), m_bRuntimeHighLight(false) {}
103
Lei Zhang2b1a2d52015-08-14 22:16:22 -0700104app::~app() {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700105 for (int i = 0, sz = m_aTimer.GetSize(); i < sz; i++)
106 delete m_aTimer[i];
107
108 m_aTimer.RemoveAll();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700109}
110
Tom Sepezba038bc2015-10-08 12:03:00 -0700111FX_BOOL app::activeDocs(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700112 CJS_PropValue& vp,
113 CFX_WideString& sError) {
114 if (!vp.IsGetting())
115 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700116
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700117 CJS_Context* pContext = (CJS_Context*)cc;
118 CPDFDoc_Environment* pApp = pContext->GetReaderApp();
119 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
120 CPDFSDK_Document* pCurDoc = pContext->GetReaderDocument();
Tom Sepez67fd5df2015-10-08 12:24:19 -0700121 CJS_Array aDocs(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700122 if (CPDFSDK_Document* pDoc = pApp->GetSDKDocument()) {
123 CJS_Document* pJSDocument = NULL;
124 if (pDoc == pCurDoc) {
Tom Sepez39bfe122015-09-17 15:25:23 -0700125 v8::Local<v8::Object> pObj = FXJS_GetThisObj(pRuntime->GetIsolate());
Tom Sepezcd56a7d2015-10-06 11:45:28 -0700126 if (FXJS_GetObjDefnID(pObj) == CJS_Document::g_nObjDefnID)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700127 pJSDocument =
Tom Sepez39bfe122015-09-17 15:25:23 -0700128 (CJS_Document*)FXJS_GetPrivate(pRuntime->GetIsolate(), pObj);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700129 } else {
Tom Sepez39bfe122015-09-17 15:25:23 -0700130 v8::Local<v8::Object> pObj = FXJS_NewFxDynamicObj(
Tom Sepez33420902015-10-13 15:00:10 -0700131 pRuntime->GetIsolate(), pRuntime, CJS_Document::g_nObjDefnID);
Tom Sepez39bfe122015-09-17 15:25:23 -0700132 pJSDocument =
133 (CJS_Document*)FXJS_GetPrivate(pRuntime->GetIsolate(), pObj);
Lei Zhang96660d62015-12-14 18:27:25 -0800134 ASSERT(pJSDocument);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700135 }
Tom Sepez67fd5df2015-10-08 12:24:19 -0700136 aDocs.SetElement(0, CJS_Value(pRuntime, pJSDocument));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700137 }
138 if (aDocs.GetLength() > 0)
139 vp << aDocs;
140 else
141 vp.SetNull();
142
143 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700144}
145
Tom Sepezba038bc2015-10-08 12:03:00 -0700146FX_BOOL app::calculate(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700147 CJS_PropValue& vp,
148 CFX_WideString& sError) {
149 if (vp.IsSetting()) {
150 bool bVP;
151 vp >> bVP;
152 m_bCalculate = (FX_BOOL)bVP;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700153
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700154 CJS_Context* pContext = (CJS_Context*)cc;
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700155 CPDFDoc_Environment* pApp = pContext->GetReaderApp();
156 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
Tom Sepez67fd5df2015-10-08 12:24:19 -0700157 CJS_Array aDocs(pRuntime);
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700158 if (CPDFSDK_Document* pDoc = pApp->GetSDKDocument())
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700159 pDoc->GetInterForm()->EnableCalculate((FX_BOOL)m_bCalculate);
160 } else {
161 vp << (bool)m_bCalculate;
162 }
163 return TRUE;
164}
165
Tom Sepezba038bc2015-10-08 12:03:00 -0700166FX_BOOL app::formsVersion(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700167 CJS_PropValue& vp,
168 CFX_WideString& sError) {
169 if (vp.IsGetting()) {
170 vp << JS_NUM_FORMSVERSION;
171 return TRUE;
172 }
173
174 return FALSE;
175}
176
Tom Sepezba038bc2015-10-08 12:03:00 -0700177FX_BOOL app::viewerType(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700178 CJS_PropValue& vp,
179 CFX_WideString& sError) {
180 if (vp.IsGetting()) {
Tom Sepezd6278ba2015-09-08 16:34:37 -0700181 vp << JS_STR_VIEWERTYPE;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700182 return TRUE;
183 }
184
185 return FALSE;
186}
187
Tom Sepezba038bc2015-10-08 12:03:00 -0700188FX_BOOL app::viewerVariation(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700189 CJS_PropValue& vp,
190 CFX_WideString& sError) {
191 if (vp.IsGetting()) {
192 vp << JS_STR_VIEWERVARIATION;
193 return TRUE;
194 }
195
196 return FALSE;
197}
198
Tom Sepezba038bc2015-10-08 12:03:00 -0700199FX_BOOL app::viewerVersion(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700200 CJS_PropValue& vp,
201 CFX_WideString& sError) {
202 if (!vp.IsGetting())
203 return FALSE;
Tom Sepez51da0932015-11-25 16:05:49 -0800204#ifdef PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700205 CJS_Context* pContext = (CJS_Context*)cc;
206 CPDFSDK_Document* pCurDoc = pContext->GetReaderDocument();
Tom Sepez50d12ad2015-11-24 09:50:51 -0800207 CPDFXFA_Document* pDoc = pCurDoc->GetXFADocument();
Tom Sepezbf59a072015-10-21 14:07:23 -0700208 if (pDoc->GetDocType() == 1 || pDoc->GetDocType() == 2) {
Tom Sepezd6278ba2015-09-08 16:34:37 -0700209 vp << JS_NUM_VIEWERVERSION_XFA;
Tom Sepezbf59a072015-10-21 14:07:23 -0700210 return TRUE;
211 }
Tom Sepez40e9ff32015-11-30 12:39:54 -0800212#endif // PDF_ENABLE_XFA
Tom Sepezbf59a072015-10-21 14:07:23 -0700213 vp << JS_NUM_VIEWERVERSION;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700214 return TRUE;
215}
216
Tom Sepezba038bc2015-10-08 12:03:00 -0700217FX_BOOL app::platform(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700218 CJS_PropValue& vp,
219 CFX_WideString& sError) {
Jun Fanga0217b62015-12-02 13:57:18 +0800220 if (!vp.IsGetting())
221 return FALSE;
Tom Sepez4d6fa832015-12-08 11:31:59 -0800222#ifdef PDF_ENABLE_XFA
Jun Fanga0217b62015-12-02 13:57:18 +0800223 CPDFDoc_Environment* pEnv =
224 static_cast<CJS_Context*>(cc)->GetJSRuntime()->GetReaderApp();
225 if (!pEnv)
226 return FALSE;
227 CFX_WideString platfrom = pEnv->FFI_GetPlatform();
Tom Sepez4d6fa832015-12-08 11:31:59 -0800228 if (!platfrom.IsEmpty()) {
Jun Fanga0217b62015-12-02 13:57:18 +0800229 vp << platfrom;
Tom Sepez4d6fa832015-12-08 11:31:59 -0800230 return TRUE;
231 }
232#endif
233 vp << JS_STR_PLATFORM;
Jun Fanga0217b62015-12-02 13:57:18 +0800234 return TRUE;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700235}
236
Tom Sepezba038bc2015-10-08 12:03:00 -0700237FX_BOOL app::language(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700238 CJS_PropValue& vp,
239 CFX_WideString& sError) {
Jun Fang487d1a92015-12-02 13:20:03 +0800240 if (!vp.IsGetting())
241 return FALSE;
Tom Sepez4d6fa832015-12-08 11:31:59 -0800242#ifdef PDF_ENABLE_XFA
Jun Fang487d1a92015-12-02 13:20:03 +0800243 CPDFDoc_Environment* pEnv =
244 static_cast<CJS_Context*>(cc)->GetJSRuntime()->GetReaderApp();
245 if (!pEnv)
246 return FALSE;
247 CFX_WideString language = pEnv->FFI_GetLanguage();
Tom Sepez4d6fa832015-12-08 11:31:59 -0800248 if (!language.IsEmpty()) {
Jun Fang487d1a92015-12-02 13:20:03 +0800249 vp << language;
Tom Sepez4d6fa832015-12-08 11:31:59 -0800250 return TRUE;
251 }
252#endif
253 vp << JS_STR_LANGUANGE;
Jun Fang487d1a92015-12-02 13:20:03 +0800254 return TRUE;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700255}
256
257// creates a new fdf object that contains no data
258// comment: need reader support
259// note:
260// CFDF_Document * CPDFDoc_Environment::NewFDF();
Tom Sepezba038bc2015-10-08 12:03:00 -0700261FX_BOOL app::newFDF(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -0800262 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700263 CJS_Value& vRet,
264 CFX_WideString& sError) {
265 return TRUE;
266}
267// opens a specified pdf document and returns its document object
268// comment:need reader support
269// note: as defined in js reference, the proto of this function's fourth
270// parmeters, how old an fdf document while do not show it.
271// CFDF_Document * CPDFDoc_Environment::OpenFDF(string strPath,bool bUserConv);
272
Tom Sepezba038bc2015-10-08 12:03:00 -0700273FX_BOOL app::openFDF(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -0800274 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700275 CJS_Value& vRet,
276 CFX_WideString& sError) {
277 return TRUE;
278}
279
Tom Sepezba038bc2015-10-08 12:03:00 -0700280FX_BOOL app::alert(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -0800281 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700282 CJS_Value& vRet,
283 CFX_WideString& sError) {
Tom Sepezbd932572016-01-29 09:10:41 -0800284 CJS_Context* pContext = static_cast<CJS_Context*>(cc);
Tom Sepez67fd5df2015-10-08 12:24:19 -0700285 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
Tom Sepezbd932572016-01-29 09:10:41 -0800286 std::vector<CJS_Value> newParams = JS_ExpandKeywordParams(
287 pRuntime, params, 4, L"cMsg", L"nIcon", L"nType", L"cTitle");
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700288
Tom Sepezbd932572016-01-29 09:10:41 -0800289 if (newParams[0].GetType() == CJS_Value::VT_unknown) {
290 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
291 return FALSE;
292 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700293
Tom Sepezbd932572016-01-29 09:10:41 -0800294 CFX_WideString swMsg;
295 if (newParams[0].GetType() == CJS_Value::VT_object) {
296 CJS_Array carray(pRuntime);
297 if (newParams[0].ConvertToArray(carray)) {
298 swMsg = L"[";
299 CJS_Value element(pRuntime);
300 for (int i = 0; i < carray.GetLength(); ++i) {
301 if (i)
302 swMsg += L", ";
303 carray.GetElement(i, element);
304 swMsg += element.ToCFXWideString();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700305 }
Tom Sepezbd932572016-01-29 09:10:41 -0800306 swMsg += L"]";
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700307 } else {
Tom Sepezbd932572016-01-29 09:10:41 -0800308 swMsg = newParams[0].ToCFXWideString();
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700309 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700310 } else {
Tom Sepezbd932572016-01-29 09:10:41 -0800311 swMsg = newParams[0].ToCFXWideString();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700312 }
313
Tom Sepezbd932572016-01-29 09:10:41 -0800314 int iIcon = 0;
315 if (newParams[1].GetType() != CJS_Value::VT_unknown)
316 iIcon = newParams[1].ToInt();
317
318 int iType = 0;
319 if (newParams[2].GetType() != CJS_Value::VT_unknown)
320 iType = newParams[2].ToInt();
321
322 CFX_WideString swTitle;
323 if (newParams[3].GetType() != CJS_Value::VT_unknown)
324 swTitle = newParams[3].ToCFXWideString();
325 else
326 swTitle = JSGetStringFromID(pContext, IDS_STRING_JSALERT);
327
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700328 pRuntime->BeginBlock();
Lei Zhangd607f5b2015-10-05 17:06:09 -0700329 vRet = MsgBox(pRuntime->GetReaderApp(), swMsg.c_str(), swTitle.c_str(), iType,
330 iIcon);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700331 pRuntime->EndBlock();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700332 return TRUE;
333}
334
Tom Sepezba038bc2015-10-08 12:03:00 -0700335FX_BOOL app::beep(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -0800336 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700337 CJS_Value& vRet,
338 CFX_WideString& sError) {
339 if (params.size() == 1) {
340 CJS_Context* pContext = (CJS_Context*)cc;
341 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
342 CPDFDoc_Environment* pEnv = pRuntime->GetReaderApp();
343 pEnv->JS_appBeep(params[0].ToInt());
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700344 return TRUE;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700345 }
346
347 sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSPARAMERROR);
348 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700349}
350
Tom Sepezba038bc2015-10-08 12:03:00 -0700351FX_BOOL app::findComponent(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -0800352 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700353 CJS_Value& vRet,
354 CFX_WideString& sError) {
355 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700356}
357
Tom Sepezba038bc2015-10-08 12:03:00 -0700358FX_BOOL app::popUpMenuEx(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -0800359 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700360 CJS_Value& vRet,
361 CFX_WideString& sError) {
362 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700363}
364
Tom Sepezba038bc2015-10-08 12:03:00 -0700365FX_BOOL app::fs(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700366 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700367}
368
Tom Sepezba038bc2015-10-08 12:03:00 -0700369FX_BOOL app::setInterval(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) {
373 CJS_Context* pContext = (CJS_Context*)cc;
374 if (params.size() > 2 || params.size() == 0) {
375 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
376 return FALSE;
377 }
Tom Sepezc6ab1722015-02-05 15:27:25 -0800378
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700379 CFX_WideString script = params.size() > 0 ? params[0].ToCFXWideString() : L"";
380 if (script.IsEmpty()) {
381 sError = JSGetStringFromID(pContext, IDS_STRING_JSAFNUMBER_KEYSTROKE);
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700382 return TRUE;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700383 }
384
385 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
tsepezc3255f52016-03-25 14:52:27 -0700386 uint32_t dwInterval = params.size() > 1 ? params[1].ToInt() : 1000;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700387
388 CPDFDoc_Environment* pApp = pRuntime->GetReaderApp();
389 ASSERT(pApp);
Lei Zhang2d5a0e12015-10-05 17:00:03 -0700390 CJS_Timer* pTimer =
391 new CJS_Timer(this, pApp, pRuntime, 0, script, dwInterval, 0);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700392 m_aTimer.Add(pTimer);
393
Tom Sepez39bfe122015-09-17 15:25:23 -0700394 v8::Local<v8::Object> pRetObj = FXJS_NewFxDynamicObj(
Tom Sepez33420902015-10-13 15:00:10 -0700395 pRuntime->GetIsolate(), pRuntime, CJS_TimerObj::g_nObjDefnID);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700396 CJS_TimerObj* pJS_TimerObj =
Tom Sepez39bfe122015-09-17 15:25:23 -0700397 (CJS_TimerObj*)FXJS_GetPrivate(pRuntime->GetIsolate(), pRetObj);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700398 TimerObj* pTimerObj = (TimerObj*)pJS_TimerObj->GetEmbedObject();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700399 pTimerObj->SetTimer(pTimer);
400
401 vRet = pRetObj;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700402 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700403}
404
Tom Sepezba038bc2015-10-08 12:03:00 -0700405FX_BOOL app::setTimeOut(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -0800406 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700407 CJS_Value& vRet,
408 CFX_WideString& sError) {
409 if (params.size() > 2 || params.size() == 0) {
410 sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSPARAMERROR);
411 return FALSE;
412 }
Tom Sepezc6ab1722015-02-05 15:27:25 -0800413
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700414 CJS_Context* pContext = (CJS_Context*)cc;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700415 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700416
417 CFX_WideString script = params.size() > 0 ? params[0].ToCFXWideString() : L"";
418 if (script.IsEmpty()) {
419 sError =
420 JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSAFNUMBER_KEYSTROKE);
421 return TRUE;
422 }
423
tsepezc3255f52016-03-25 14:52:27 -0700424 uint32_t dwTimeOut = params.size() > 1 ? params[1].ToInt() : 1000;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700425
426 CPDFDoc_Environment* pApp = pRuntime->GetReaderApp();
427 ASSERT(pApp);
428
Lei Zhang2d5a0e12015-10-05 17:00:03 -0700429 CJS_Timer* pTimer =
430 new CJS_Timer(this, pApp, pRuntime, 1, script, dwTimeOut, dwTimeOut);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700431 m_aTimer.Add(pTimer);
432
Tom Sepez39bfe122015-09-17 15:25:23 -0700433 v8::Local<v8::Object> pRetObj = FXJS_NewFxDynamicObj(
Tom Sepez33420902015-10-13 15:00:10 -0700434 pRuntime->GetIsolate(), pRuntime, CJS_TimerObj::g_nObjDefnID);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700435 CJS_TimerObj* pJS_TimerObj =
Tom Sepez39bfe122015-09-17 15:25:23 -0700436 (CJS_TimerObj*)FXJS_GetPrivate(pRuntime->GetIsolate(), pRetObj);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700437 TimerObj* pTimerObj = (TimerObj*)pJS_TimerObj->GetEmbedObject();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700438 pTimerObj->SetTimer(pTimer);
439
440 vRet = pRetObj;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700441 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700442}
443
Tom Sepezba038bc2015-10-08 12:03:00 -0700444FX_BOOL app::clearTimeOut(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -0800445 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700446 CJS_Value& vRet,
447 CFX_WideString& sError) {
448 CJS_Context* pContext = (CJS_Context*)cc;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700449 if (params.size() != 1) {
Tom Sepezcd56a7d2015-10-06 11:45:28 -0700450 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700451 return FALSE;
452 }
453
Tom Sepez39bfe122015-09-17 15:25:23 -0700454 if (params[0].GetType() == CJS_Value::VT_fxobject) {
Tom Sepez808a99e2015-09-10 12:28:37 -0700455 v8::Local<v8::Object> pObj = params[0].ToV8Object();
Tom Sepezcd56a7d2015-10-06 11:45:28 -0700456 if (FXJS_GetObjDefnID(pObj) == CJS_TimerObj::g_nObjDefnID) {
457 if (CJS_Object* pJSObj = params[0].ToCJSObject()) {
458 if (TimerObj* pTimerObj = (TimerObj*)pJSObj->GetEmbedObject()) {
459 if (CJS_Timer* pTimer = pTimerObj->GetTimer()) {
460 pTimer->KillJSTimer();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700461
Tom Sepezcd56a7d2015-10-06 11:45:28 -0700462 for (int i = 0, sz = m_aTimer.GetSize(); i < sz; i++) {
463 if (m_aTimer[i] == pTimer) {
464 m_aTimer.RemoveAt(i);
465 break;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700466 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700467 }
Tom Sepezcd56a7d2015-10-06 11:45:28 -0700468
469 delete pTimer;
470 pTimerObj->SetTimer(NULL);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700471 }
472 }
473 }
474 }
475 }
476
477 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700478}
479
Tom Sepezba038bc2015-10-08 12:03:00 -0700480FX_BOOL app::clearInterval(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -0800481 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700482 CJS_Value& vRet,
483 CFX_WideString& sError) {
484 CJS_Context* pContext = (CJS_Context*)cc;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700485 if (params.size() != 1) {
Tom Sepezcd56a7d2015-10-06 11:45:28 -0700486 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700487 return FALSE;
488 }
489
Tom Sepez39bfe122015-09-17 15:25:23 -0700490 if (params[0].GetType() == CJS_Value::VT_fxobject) {
Tom Sepez808a99e2015-09-10 12:28:37 -0700491 v8::Local<v8::Object> pObj = params[0].ToV8Object();
Tom Sepezcd56a7d2015-10-06 11:45:28 -0700492 if (FXJS_GetObjDefnID(pObj) == CJS_TimerObj::g_nObjDefnID) {
493 if (CJS_Object* pJSObj = params[0].ToCJSObject()) {
494 if (TimerObj* pTimerObj = (TimerObj*)pJSObj->GetEmbedObject()) {
495 if (CJS_Timer* pTimer = pTimerObj->GetTimer()) {
496 pTimer->KillJSTimer();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700497
Tom Sepezcd56a7d2015-10-06 11:45:28 -0700498 for (int i = 0, sz = m_aTimer.GetSize(); i < sz; i++) {
499 if (m_aTimer[i] == pTimer) {
500 m_aTimer.RemoveAt(i);
501 break;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700502 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700503 }
Tom Sepezcd56a7d2015-10-06 11:45:28 -0700504
505 delete pTimer;
506 pTimerObj->SetTimer(NULL);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700507 }
508 }
509 }
510 }
511 }
512
513 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700514}
515
Tom Sepezba038bc2015-10-08 12:03:00 -0700516FX_BOOL app::execMenuItem(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -0800517 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700518 CJS_Value& vRet,
519 CFX_WideString& sError) {
520 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700521}
522
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700523void app::TimerProc(CJS_Timer* pTimer) {
Lei Zhang2d5a0e12015-10-05 17:00:03 -0700524 CJS_Runtime* pRuntime = pTimer->GetRuntime();
525
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700526 switch (pTimer->GetType()) {
527 case 0: // interval
Lei Zhang2d5a0e12015-10-05 17:00:03 -0700528 if (pRuntime)
529 RunJsScript(pRuntime, pTimer->GetJScript());
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700530 break;
531 case 1:
532 if (pTimer->GetTimeOut() > 0) {
Lei Zhang2d5a0e12015-10-05 17:00:03 -0700533 if (pRuntime)
534 RunJsScript(pRuntime, pTimer->GetJScript());
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700535 pTimer->KillJSTimer();
536 }
537 break;
538 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700539}
540
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700541void app::RunJsScript(CJS_Runtime* pRuntime, const CFX_WideString& wsScript) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700542 if (!pRuntime->IsBlocking()) {
Tom Sepezba038bc2015-10-08 12:03:00 -0700543 IJS_Context* pContext = pRuntime->NewContext();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700544 pContext->OnExternal_Exec();
545 CFX_WideString wtInfo;
Tom Sepez33420902015-10-13 15:00:10 -0700546 pContext->RunScript(wsScript, &wtInfo);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700547 pRuntime->ReleaseContext(pContext);
548 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700549}
550
Tom Sepezba038bc2015-10-08 12:03:00 -0700551FX_BOOL app::goBack(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -0800552 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700553 CJS_Value& vRet,
554 CFX_WideString& sError) {
Tom Sepezc6ab1722015-02-05 15:27:25 -0800555 // Not supported.
556 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700557}
558
Tom Sepezba038bc2015-10-08 12:03:00 -0700559FX_BOOL app::goForward(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -0800560 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700561 CJS_Value& vRet,
562 CFX_WideString& sError) {
Tom Sepezc6ab1722015-02-05 15:27:25 -0800563 // Not supported.
564 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700565}
566
Tom Sepezba038bc2015-10-08 12:03:00 -0700567FX_BOOL app::mailMsg(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -0800568 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700569 CJS_Value& vRet,
570 CFX_WideString& sError) {
Tom Sepez67fd5df2015-10-08 12:24:19 -0700571 CJS_Context* pContext = static_cast<CJS_Context*>(cc);
572 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
Tom Sepeze5fbd7a2016-01-29 17:05:08 -0800573 std::vector<CJS_Value> newParams =
574 JS_ExpandKeywordParams(pRuntime, params, 6, L"bUI", L"cTo", L"cCc",
575 L"cBcc", L"cSubject", L"cMsg");
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700576
Tom Sepeze5fbd7a2016-01-29 17:05:08 -0800577 if (newParams[0].GetType() == CJS_Value::VT_unknown) {
578 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
579 return FALSE;
580 }
581 bool bUI = newParams[0].ToBool();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700582
Tom Sepeze5fbd7a2016-01-29 17:05:08 -0800583 CFX_WideString cTo;
584 if (newParams[1].GetType() != CJS_Value::VT_unknown) {
585 cTo = newParams[1].ToCFXWideString();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700586 } else {
Tom Sepeze5fbd7a2016-01-29 17:05:08 -0800587 if (!bUI) {
588 // cTo parameter required when UI not invoked.
589 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700590 return FALSE;
Tom Sepeze5fbd7a2016-01-29 17:05:08 -0800591 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700592 }
Tom Sepezc6ab1722015-02-05 15:27:25 -0800593
Tom Sepeze5fbd7a2016-01-29 17:05:08 -0800594 CFX_WideString cCc;
595 if (newParams[2].GetType() != CJS_Value::VT_unknown)
596 cCc = newParams[2].ToCFXWideString();
597
598 CFX_WideString cBcc;
599 if (newParams[3].GetType() != CJS_Value::VT_unknown)
600 cBcc = newParams[3].ToCFXWideString();
601
602 CFX_WideString cSubject;
603 if (newParams[4].GetType() != CJS_Value::VT_unknown)
604 cSubject = newParams[4].ToCFXWideString();
605
606 CFX_WideString cMsg;
607 if (newParams[5].GetType() != CJS_Value::VT_unknown)
608 cMsg = newParams[5].ToCFXWideString();
609
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700610 pRuntime->BeginBlock();
Tom Sepeze5fbd7a2016-01-29 17:05:08 -0800611 pContext->GetReaderApp()->JS_docmailForm(nullptr, 0, bUI, cTo.c_str(),
Tom Sepez67fd5df2015-10-08 12:24:19 -0700612 cSubject.c_str(), cCc.c_str(),
613 cBcc.c_str(), cMsg.c_str());
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700614 pRuntime->EndBlock();
Tom Sepeze5fbd7a2016-01-29 17:05:08 -0800615 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700616}
617
Tom Sepezba038bc2015-10-08 12:03:00 -0700618FX_BOOL app::launchURL(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -0800619 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700620 CJS_Value& vRet,
621 CFX_WideString& sError) {
Tom Sepezc6ab1722015-02-05 15:27:25 -0800622 // Unsafe, not supported.
623 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700624}
625
Tom Sepezba038bc2015-10-08 12:03:00 -0700626FX_BOOL app::runtimeHighlight(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700627 CJS_PropValue& vp,
628 CFX_WideString& sError) {
629 if (vp.IsSetting()) {
630 vp >> m_bRuntimeHighLight;
631 } else {
632 vp << m_bRuntimeHighLight;
633 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700634 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700635}
636
Tom Sepezba038bc2015-10-08 12:03:00 -0700637FX_BOOL app::fullscreen(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700638 CJS_PropValue& vp,
639 CFX_WideString& sError) {
640 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700641}
642
Tom Sepezba038bc2015-10-08 12:03:00 -0700643FX_BOOL app::popUpMenu(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -0800644 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700645 CJS_Value& vRet,
646 CFX_WideString& sError) {
647 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700648}
649
Tom Sepezba038bc2015-10-08 12:03:00 -0700650FX_BOOL app::browseForDoc(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -0800651 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700652 CJS_Value& vRet,
653 CFX_WideString& sError) {
Tom Sepezc6ab1722015-02-05 15:27:25 -0800654 // Unsafe, not supported.
655 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700656}
657
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700658CFX_WideString app::SysPathToPDFPath(const CFX_WideString& sOldPath) {
659 CFX_WideString sRet = L"/";
Tom Sepezc6ab1722015-02-05 15:27:25 -0800660
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700661 for (int i = 0, sz = sOldPath.GetLength(); i < sz; i++) {
662 wchar_t c = sOldPath.GetAt(i);
663 if (c == L':') {
664 } else {
665 if (c == L'\\') {
666 sRet += L"/";
667 } else {
668 sRet += c;
669 }
670 }
671 }
Tom Sepezc6ab1722015-02-05 15:27:25 -0800672
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700673 return sRet;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700674}
675
Tom Sepezba038bc2015-10-08 12:03:00 -0700676FX_BOOL app::newDoc(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -0800677 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700678 CJS_Value& vRet,
679 CFX_WideString& sError) {
680 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700681}
682
Tom Sepezba038bc2015-10-08 12:03:00 -0700683FX_BOOL app::openDoc(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -0800684 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700685 CJS_Value& vRet,
686 CFX_WideString& sError) {
687 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700688}
689
Tom Sepezba038bc2015-10-08 12:03:00 -0700690FX_BOOL app::response(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -0800691 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700692 CJS_Value& vRet,
693 CFX_WideString& sError) {
Tom Sepez58fb36a2016-02-01 10:32:14 -0800694 CJS_Context* pContext = static_cast<CJS_Context*>(cc);
Tom Sepez67fd5df2015-10-08 12:24:19 -0700695 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
Tom Sepez58fb36a2016-02-01 10:32:14 -0800696 std::vector<CJS_Value> newParams =
697 JS_ExpandKeywordParams(pRuntime, params, 5, L"cQuestion", L"cTitle",
698 L"cDefault", L"bPassword", L"cLabel");
Tom Sepez621d4de2014-07-29 14:01:21 -0700699
Tom Sepez58fb36a2016-02-01 10:32:14 -0800700 if (newParams[0].GetType() == CJS_Value::VT_unknown) {
701 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
702 return FALSE;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700703 }
Tom Sepez58fb36a2016-02-01 10:32:14 -0800704 CFX_WideString swQuestion = newParams[0].ToCFXWideString();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700705
Tom Sepez58fb36a2016-02-01 10:32:14 -0800706 CFX_WideString swTitle = L"PDF";
707 if (newParams[1].GetType() != CJS_Value::VT_unknown)
708 swTitle = newParams[1].ToCFXWideString();
709
710 CFX_WideString swDefault;
711 if (newParams[2].GetType() != CJS_Value::VT_unknown)
712 swDefault = newParams[2].ToCFXWideString();
713
714 bool bPassword = false;
715 if (newParams[3].GetType() != CJS_Value::VT_unknown)
716 bPassword = newParams[3].ToBool();
717
718 CFX_WideString swLabel;
719 if (newParams[4].GetType() != CJS_Value::VT_unknown)
720 swLabel = newParams[4].ToCFXWideString();
Tom Sepez621d4de2014-07-29 14:01:21 -0700721
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700722 const int MAX_INPUT_BYTES = 2048;
Lei Zhangaa8bf7e2015-12-24 19:13:32 -0800723 std::unique_ptr<char[]> pBuff(new char[MAX_INPUT_BYTES + 2]);
Lei Zhangdb5256f2015-10-02 10:11:43 -0700724 memset(pBuff.get(), 0, MAX_INPUT_BYTES + 2);
Tom Sepez58fb36a2016-02-01 10:32:14 -0800725
726 int nLengthBytes = pContext->GetReaderApp()->JS_appResponse(
Lei Zhangdb5256f2015-10-02 10:11:43 -0700727 swQuestion.c_str(), swTitle.c_str(), swDefault.c_str(), swLabel.c_str(),
Tom Sepez58fb36a2016-02-01 10:32:14 -0800728 bPassword, pBuff.get(), MAX_INPUT_BYTES);
729
730 if (nLengthBytes < 0 || nLengthBytes > MAX_INPUT_BYTES) {
731 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAM_TOOLONG);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700732 return FALSE;
733 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700734
Tom Sepez58fb36a2016-02-01 10:32:14 -0800735 vRet = CFX_WideString::FromUTF16LE(reinterpret_cast<uint16_t*>(pBuff.get()),
736 nLengthBytes / sizeof(uint16_t))
737 .c_str();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700738 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700739}
740
Tom Sepezba038bc2015-10-08 12:03:00 -0700741FX_BOOL app::media(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700742 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700743}
744
Tom Sepezba038bc2015-10-08 12:03:00 -0700745FX_BOOL app::execDialog(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -0800746 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700747 CJS_Value& vRet,
748 CFX_WideString& sError) {
749 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700750}