blob: 34b51310cebce74b69c7776e6e156664b8dac51f [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
Tom Sepez37458412015-10-06 11:33:46 -07009#include "Document.h"
10#include "JS_Context.h"
11#include "JS_Define.h"
12#include "JS_EventHandler.h"
13#include "JS_Object.h"
14#include "JS_Runtime.h"
15#include "JS_Value.h"
Lei Zhangbde53d22015-11-12 22:21:30 -080016#include "fpdfsdk/include/fsdk_mgr.h" // For CPDFDoc_Environment.
17#include "fpdfsdk/include/javascript/IJavaScript.h"
Tom Sepez37458412015-10-06 11:33:46 -070018#include "resource.h"
Lei Zhang8241df72015-11-06 14:38:48 -080019#include "third_party/base/nonstd_unique_ptr.h"
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070020
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070021BEGIN_JS_STATIC_CONST(CJS_TimerObj)
22END_JS_STATIC_CONST()
23
24BEGIN_JS_STATIC_PROP(CJS_TimerObj)
25END_JS_STATIC_PROP()
26
27BEGIN_JS_STATIC_METHOD(CJS_TimerObj)
28END_JS_STATIC_METHOD()
29
30IMPLEMENT_JS_CLASS(CJS_TimerObj, TimerObj)
31
32TimerObj::TimerObj(CJS_Object* pJSObject)
Nico Weber9d8ec5a2015-08-04 13:00:21 -070033 : CJS_EmbedObj(pJSObject), m_pTimer(NULL) {}
Tom Sepezc6ab1722015-02-05 15:27:25 -080034
Nico Weber9d8ec5a2015-08-04 13:00:21 -070035TimerObj::~TimerObj() {}
36
37void TimerObj::SetTimer(CJS_Timer* pTimer) {
38 m_pTimer = pTimer;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070039}
40
Nico Weber9d8ec5a2015-08-04 13:00:21 -070041CJS_Timer* TimerObj::GetTimer() const {
42 return m_pTimer;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070043}
44
Tom Sepezd6278ba2015-09-08 16:34:37 -070045#define JS_STR_VIEWERTYPE L"pdfium"
Nico Weber9d8ec5a2015-08-04 13:00:21 -070046#define JS_STR_VIEWERVARIATION L"Full"
47#define JS_STR_PLATFORM L"WIN"
48#define JS_STR_LANGUANGE L"ENU"
Tom Sepezd6278ba2015-09-08 16:34:37 -070049#define JS_NUM_VIEWERVERSION 8
Tom Sepez51da0932015-11-25 16:05:49 -080050#ifdef PDF_ENABLE_XFA
Tom Sepezd6278ba2015-09-08 16:34:37 -070051#define JS_NUM_VIEWERVERSION_XFA 11
Tom Sepez40e9ff32015-11-30 12:39:54 -080052#endif // PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -070053#define JS_NUM_FORMSVERSION 7
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070054
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070055BEGIN_JS_STATIC_CONST(CJS_App)
56END_JS_STATIC_CONST()
57
58BEGIN_JS_STATIC_PROP(CJS_App)
Nico Weber9d8ec5a2015-08-04 13:00:21 -070059JS_STATIC_PROP_ENTRY(activeDocs)
60JS_STATIC_PROP_ENTRY(calculate)
61JS_STATIC_PROP_ENTRY(formsVersion)
62JS_STATIC_PROP_ENTRY(fs)
63JS_STATIC_PROP_ENTRY(fullscreen)
64JS_STATIC_PROP_ENTRY(language)
65JS_STATIC_PROP_ENTRY(media)
66JS_STATIC_PROP_ENTRY(platform)
67JS_STATIC_PROP_ENTRY(runtimeHighlight)
68JS_STATIC_PROP_ENTRY(viewerType)
69JS_STATIC_PROP_ENTRY(viewerVariation)
70JS_STATIC_PROP_ENTRY(viewerVersion)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070071END_JS_STATIC_PROP()
72
73BEGIN_JS_STATIC_METHOD(CJS_App)
Nico Weber9d8ec5a2015-08-04 13:00:21 -070074JS_STATIC_METHOD_ENTRY(alert)
75JS_STATIC_METHOD_ENTRY(beep)
76JS_STATIC_METHOD_ENTRY(browseForDoc)
77JS_STATIC_METHOD_ENTRY(clearInterval)
78JS_STATIC_METHOD_ENTRY(clearTimeOut)
79JS_STATIC_METHOD_ENTRY(execDialog)
80JS_STATIC_METHOD_ENTRY(execMenuItem)
81JS_STATIC_METHOD_ENTRY(findComponent)
82JS_STATIC_METHOD_ENTRY(goBack)
83JS_STATIC_METHOD_ENTRY(goForward)
84JS_STATIC_METHOD_ENTRY(launchURL)
85JS_STATIC_METHOD_ENTRY(mailMsg)
86JS_STATIC_METHOD_ENTRY(newFDF)
87JS_STATIC_METHOD_ENTRY(newDoc)
88JS_STATIC_METHOD_ENTRY(openDoc)
89JS_STATIC_METHOD_ENTRY(openFDF)
90JS_STATIC_METHOD_ENTRY(popUpMenuEx)
91JS_STATIC_METHOD_ENTRY(popUpMenu)
92JS_STATIC_METHOD_ENTRY(response)
93JS_STATIC_METHOD_ENTRY(setInterval)
94JS_STATIC_METHOD_ENTRY(setTimeOut)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070095END_JS_STATIC_METHOD()
96
Nico Weber9d8ec5a2015-08-04 13:00:21 -070097IMPLEMENT_JS_CLASS(CJS_App, app)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070098
Nico Weber9d8ec5a2015-08-04 13:00:21 -070099app::app(CJS_Object* pJSObject)
100 : CJS_EmbedObj(pJSObject), m_bCalculate(true), m_bRuntimeHighLight(false) {}
101
Lei Zhang2b1a2d52015-08-14 22:16:22 -0700102app::~app() {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700103 for (int i = 0, sz = m_aTimer.GetSize(); i < sz; i++)
104 delete m_aTimer[i];
105
106 m_aTimer.RemoveAll();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700107}
108
Tom Sepezba038bc2015-10-08 12:03:00 -0700109FX_BOOL app::activeDocs(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700110 CJS_PropValue& vp,
111 CFX_WideString& sError) {
112 if (!vp.IsGetting())
113 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700114
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700115 CJS_Context* pContext = (CJS_Context*)cc;
116 CPDFDoc_Environment* pApp = pContext->GetReaderApp();
117 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
118 CPDFSDK_Document* pCurDoc = pContext->GetReaderDocument();
Tom Sepez67fd5df2015-10-08 12:24:19 -0700119 CJS_Array aDocs(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700120 if (CPDFSDK_Document* pDoc = pApp->GetSDKDocument()) {
121 CJS_Document* pJSDocument = NULL;
122 if (pDoc == pCurDoc) {
Tom Sepez39bfe122015-09-17 15:25:23 -0700123 v8::Local<v8::Object> pObj = FXJS_GetThisObj(pRuntime->GetIsolate());
Tom Sepezcd56a7d2015-10-06 11:45:28 -0700124 if (FXJS_GetObjDefnID(pObj) == CJS_Document::g_nObjDefnID)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700125 pJSDocument =
Tom Sepez39bfe122015-09-17 15:25:23 -0700126 (CJS_Document*)FXJS_GetPrivate(pRuntime->GetIsolate(), pObj);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700127 } else {
Tom Sepez39bfe122015-09-17 15:25:23 -0700128 v8::Local<v8::Object> pObj = FXJS_NewFxDynamicObj(
Tom Sepez33420902015-10-13 15:00:10 -0700129 pRuntime->GetIsolate(), pRuntime, CJS_Document::g_nObjDefnID);
Tom Sepez39bfe122015-09-17 15:25:23 -0700130 pJSDocument =
131 (CJS_Document*)FXJS_GetPrivate(pRuntime->GetIsolate(), pObj);
Lei Zhang96660d62015-12-14 18:27:25 -0800132 ASSERT(pJSDocument);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700133 }
Tom Sepez67fd5df2015-10-08 12:24:19 -0700134 aDocs.SetElement(0, CJS_Value(pRuntime, pJSDocument));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700135 }
136 if (aDocs.GetLength() > 0)
137 vp << aDocs;
138 else
139 vp.SetNull();
140
141 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700142}
143
Tom Sepezba038bc2015-10-08 12:03:00 -0700144FX_BOOL app::calculate(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700145 CJS_PropValue& vp,
146 CFX_WideString& sError) {
147 if (vp.IsSetting()) {
148 bool bVP;
149 vp >> bVP;
150 m_bCalculate = (FX_BOOL)bVP;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700151
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700152 CJS_Context* pContext = (CJS_Context*)cc;
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700153 CPDFDoc_Environment* pApp = pContext->GetReaderApp();
154 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
Tom Sepez67fd5df2015-10-08 12:24:19 -0700155 CJS_Array aDocs(pRuntime);
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700156 if (CPDFSDK_Document* pDoc = pApp->GetSDKDocument())
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700157 pDoc->GetInterForm()->EnableCalculate((FX_BOOL)m_bCalculate);
158 } else {
159 vp << (bool)m_bCalculate;
160 }
161 return TRUE;
162}
163
Tom Sepezba038bc2015-10-08 12:03:00 -0700164FX_BOOL app::formsVersion(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700165 CJS_PropValue& vp,
166 CFX_WideString& sError) {
167 if (vp.IsGetting()) {
168 vp << JS_NUM_FORMSVERSION;
169 return TRUE;
170 }
171
172 return FALSE;
173}
174
Tom Sepezba038bc2015-10-08 12:03:00 -0700175FX_BOOL app::viewerType(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700176 CJS_PropValue& vp,
177 CFX_WideString& sError) {
178 if (vp.IsGetting()) {
Tom Sepezd6278ba2015-09-08 16:34:37 -0700179 vp << JS_STR_VIEWERTYPE;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700180 return TRUE;
181 }
182
183 return FALSE;
184}
185
Tom Sepezba038bc2015-10-08 12:03:00 -0700186FX_BOOL app::viewerVariation(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700187 CJS_PropValue& vp,
188 CFX_WideString& sError) {
189 if (vp.IsGetting()) {
190 vp << JS_STR_VIEWERVARIATION;
191 return TRUE;
192 }
193
194 return FALSE;
195}
196
Tom Sepezba038bc2015-10-08 12:03:00 -0700197FX_BOOL app::viewerVersion(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700198 CJS_PropValue& vp,
199 CFX_WideString& sError) {
200 if (!vp.IsGetting())
201 return FALSE;
Tom Sepez51da0932015-11-25 16:05:49 -0800202#ifdef PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700203 CJS_Context* pContext = (CJS_Context*)cc;
204 CPDFSDK_Document* pCurDoc = pContext->GetReaderDocument();
Tom Sepez50d12ad2015-11-24 09:50:51 -0800205 CPDFXFA_Document* pDoc = pCurDoc->GetXFADocument();
Tom Sepezbf59a072015-10-21 14:07:23 -0700206 if (pDoc->GetDocType() == 1 || pDoc->GetDocType() == 2) {
Tom Sepezd6278ba2015-09-08 16:34:37 -0700207 vp << JS_NUM_VIEWERVERSION_XFA;
Tom Sepezbf59a072015-10-21 14:07:23 -0700208 return TRUE;
209 }
Tom Sepez40e9ff32015-11-30 12:39:54 -0800210#endif // PDF_ENABLE_XFA
Tom Sepezbf59a072015-10-21 14:07:23 -0700211 vp << JS_NUM_VIEWERVERSION;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700212 return TRUE;
213}
214
Tom Sepezba038bc2015-10-08 12:03:00 -0700215FX_BOOL app::platform(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700216 CJS_PropValue& vp,
217 CFX_WideString& sError) {
Jun Fanga0217b62015-12-02 13:57:18 +0800218 if (!vp.IsGetting())
219 return FALSE;
Tom Sepez4d6fa832015-12-08 11:31:59 -0800220#ifdef PDF_ENABLE_XFA
Jun Fanga0217b62015-12-02 13:57:18 +0800221 CPDFDoc_Environment* pEnv =
222 static_cast<CJS_Context*>(cc)->GetJSRuntime()->GetReaderApp();
223 if (!pEnv)
224 return FALSE;
225 CFX_WideString platfrom = pEnv->FFI_GetPlatform();
Tom Sepez4d6fa832015-12-08 11:31:59 -0800226 if (!platfrom.IsEmpty()) {
Jun Fanga0217b62015-12-02 13:57:18 +0800227 vp << platfrom;
Tom Sepez4d6fa832015-12-08 11:31:59 -0800228 return TRUE;
229 }
230#endif
231 vp << JS_STR_PLATFORM;
Jun Fanga0217b62015-12-02 13:57:18 +0800232 return TRUE;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700233}
234
Tom Sepezba038bc2015-10-08 12:03:00 -0700235FX_BOOL app::language(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700236 CJS_PropValue& vp,
237 CFX_WideString& sError) {
Jun Fang487d1a92015-12-02 13:20:03 +0800238 if (!vp.IsGetting())
239 return FALSE;
Tom Sepez4d6fa832015-12-08 11:31:59 -0800240#ifdef PDF_ENABLE_XFA
Jun Fang487d1a92015-12-02 13:20:03 +0800241 CPDFDoc_Environment* pEnv =
242 static_cast<CJS_Context*>(cc)->GetJSRuntime()->GetReaderApp();
243 if (!pEnv)
244 return FALSE;
245 CFX_WideString language = pEnv->FFI_GetLanguage();
Tom Sepez4d6fa832015-12-08 11:31:59 -0800246 if (!language.IsEmpty()) {
Jun Fang487d1a92015-12-02 13:20:03 +0800247 vp << language;
Tom Sepez4d6fa832015-12-08 11:31:59 -0800248 return TRUE;
249 }
250#endif
251 vp << JS_STR_LANGUANGE;
Jun Fang487d1a92015-12-02 13:20:03 +0800252 return TRUE;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700253}
254
255// creates a new fdf object that contains no data
256// comment: need reader support
257// note:
258// CFDF_Document * CPDFDoc_Environment::NewFDF();
Tom Sepezba038bc2015-10-08 12:03:00 -0700259FX_BOOL app::newFDF(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -0800260 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700261 CJS_Value& vRet,
262 CFX_WideString& sError) {
263 return TRUE;
264}
265// opens a specified pdf document and returns its document object
266// comment:need reader support
267// note: as defined in js reference, the proto of this function's fourth
268// parmeters, how old an fdf document while do not show it.
269// CFDF_Document * CPDFDoc_Environment::OpenFDF(string strPath,bool bUserConv);
270
Tom Sepezba038bc2015-10-08 12:03:00 -0700271FX_BOOL app::openFDF(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -0800272 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700273 CJS_Value& vRet,
274 CFX_WideString& sError) {
275 return TRUE;
276}
277
Tom Sepezba038bc2015-10-08 12:03:00 -0700278FX_BOOL app::alert(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -0800279 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700280 CJS_Value& vRet,
281 CFX_WideString& sError) {
282 int iSize = params.size();
283 if (iSize < 1)
284 return FALSE;
285
286 CFX_WideString swMsg = L"";
287 CFX_WideString swTitle = L"";
288 int iIcon = 0;
289 int iType = 0;
290
Tom Sepez67fd5df2015-10-08 12:24:19 -0700291 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
292 v8::Isolate* isolate = pRuntime->GetIsolate();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700293
294 if (iSize == 1) {
Tom Sepez39bfe122015-09-17 15:25:23 -0700295 if (params[0].GetType() == CJS_Value::VT_object) {
Tom Sepez808a99e2015-09-10 12:28:37 -0700296 v8::Local<v8::Object> pObj = params[0].ToV8Object();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700297 {
298 v8::Local<v8::Value> pValue =
Tom Sepez39bfe122015-09-17 15:25:23 -0700299 FXJS_GetObjectElement(isolate, pObj, L"cMsg");
Tom Sepez67fd5df2015-10-08 12:24:19 -0700300 swMsg = CJS_Value(pRuntime, pValue, CJS_Value::VT_unknown)
301 .ToCFXWideString();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700302
Tom Sepez39bfe122015-09-17 15:25:23 -0700303 pValue = FXJS_GetObjectElement(isolate, pObj, L"cTitle");
Tom Sepez67fd5df2015-10-08 12:24:19 -0700304 swTitle = CJS_Value(pRuntime, pValue, CJS_Value::VT_unknown)
305 .ToCFXWideString();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700306
Tom Sepez39bfe122015-09-17 15:25:23 -0700307 pValue = FXJS_GetObjectElement(isolate, pObj, L"nIcon");
Tom Sepez67fd5df2015-10-08 12:24:19 -0700308 iIcon = CJS_Value(pRuntime, pValue, CJS_Value::VT_unknown).ToInt();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700309
Tom Sepez39bfe122015-09-17 15:25:23 -0700310 pValue = FXJS_GetObjectElement(isolate, pObj, L"nType");
Tom Sepez67fd5df2015-10-08 12:24:19 -0700311 iType = CJS_Value(pRuntime, pValue, CJS_Value::VT_unknown).ToInt();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700312 }
313
314 if (swMsg == L"") {
Tom Sepez67fd5df2015-10-08 12:24:19 -0700315 CJS_Array carray(pRuntime);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700316 if (params[0].ConvertToArray(carray)) {
Lei Zhange00660b2015-08-13 15:40:18 -0700317 int iLength = carray.GetLength();
Tom Sepez67fd5df2015-10-08 12:24:19 -0700318 CJS_Value* pValue = new CJS_Value(pRuntime);
Lei Zhange00660b2015-08-13 15:40:18 -0700319 for (int i = 0; i < iLength; ++i) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700320 carray.GetElement(i, *pValue);
321 swMsg += (*pValue).ToCFXWideString();
Lei Zhange00660b2015-08-13 15:40:18 -0700322 if (i < iLength - 1)
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700323 swMsg += L", ";
324 }
325
326 delete pValue;
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700327 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700328 }
329
330 if (swTitle == L"")
331 swTitle = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSALERT);
Tom Sepez39bfe122015-09-17 15:25:23 -0700332 } else if (params[0].GetType() == CJS_Value::VT_boolean) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700333 FX_BOOL bGet = params[0].ToBool();
334 if (bGet)
335 swMsg = L"true";
336 else
337 swMsg = L"false";
338
339 swTitle = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSALERT);
340 } else {
341 swMsg = params[0].ToCFXWideString();
342 swTitle = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSALERT);
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700343 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700344 } else {
Tom Sepez39bfe122015-09-17 15:25:23 -0700345 if (params[0].GetType() == CJS_Value::VT_boolean) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700346 FX_BOOL bGet = params[0].ToBool();
347 if (bGet)
348 swMsg = L"true";
349 else
350 swMsg = L"false";
351 } else {
352 swMsg = params[0].ToCFXWideString();
353 }
354 swTitle = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSALERT);
Tom Sepezc6ab1722015-02-05 15:27:25 -0800355
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700356 for (int i = 1; i < iSize; i++) {
357 if (i == 1)
358 iIcon = params[i].ToInt();
359 if (i == 2)
360 iType = params[i].ToInt();
361 if (i == 3)
362 swTitle = params[i].ToCFXWideString();
363 }
364 }
365
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700366 pRuntime->BeginBlock();
Lei Zhangd607f5b2015-10-05 17:06:09 -0700367 vRet = MsgBox(pRuntime->GetReaderApp(), swMsg.c_str(), swTitle.c_str(), iType,
368 iIcon);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700369 pRuntime->EndBlock();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700370 return TRUE;
371}
372
Tom Sepezba038bc2015-10-08 12:03:00 -0700373FX_BOOL app::beep(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -0800374 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700375 CJS_Value& vRet,
376 CFX_WideString& sError) {
377 if (params.size() == 1) {
378 CJS_Context* pContext = (CJS_Context*)cc;
379 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
380 CPDFDoc_Environment* pEnv = pRuntime->GetReaderApp();
381 pEnv->JS_appBeep(params[0].ToInt());
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700382 return TRUE;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700383 }
384
385 sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSPARAMERROR);
386 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700387}
388
Tom Sepezba038bc2015-10-08 12:03:00 -0700389FX_BOOL app::findComponent(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -0800390 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700391 CJS_Value& vRet,
392 CFX_WideString& sError) {
393 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700394}
395
Tom Sepezba038bc2015-10-08 12:03:00 -0700396FX_BOOL app::popUpMenuEx(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -0800397 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700398 CJS_Value& vRet,
399 CFX_WideString& sError) {
400 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700401}
402
Tom Sepezba038bc2015-10-08 12:03:00 -0700403FX_BOOL app::fs(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700404 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700405}
406
Tom Sepezba038bc2015-10-08 12:03:00 -0700407FX_BOOL app::setInterval(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -0800408 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700409 CJS_Value& vRet,
410 CFX_WideString& sError) {
411 CJS_Context* pContext = (CJS_Context*)cc;
412 if (params.size() > 2 || params.size() == 0) {
413 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
414 return FALSE;
415 }
Tom Sepezc6ab1722015-02-05 15:27:25 -0800416
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700417 CFX_WideString script = params.size() > 0 ? params[0].ToCFXWideString() : L"";
418 if (script.IsEmpty()) {
419 sError = JSGetStringFromID(pContext, IDS_STRING_JSAFNUMBER_KEYSTROKE);
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700420 return TRUE;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700421 }
422
423 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
424 FX_DWORD dwInterval = params.size() > 1 ? params[1].ToInt() : 1000;
425
426 CPDFDoc_Environment* pApp = pRuntime->GetReaderApp();
427 ASSERT(pApp);
Lei Zhang2d5a0e12015-10-05 17:00:03 -0700428 CJS_Timer* pTimer =
429 new CJS_Timer(this, pApp, pRuntime, 0, script, dwInterval, 0);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700430 m_aTimer.Add(pTimer);
431
Tom Sepez39bfe122015-09-17 15:25:23 -0700432 v8::Local<v8::Object> pRetObj = FXJS_NewFxDynamicObj(
Tom Sepez33420902015-10-13 15:00:10 -0700433 pRuntime->GetIsolate(), pRuntime, CJS_TimerObj::g_nObjDefnID);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700434 CJS_TimerObj* pJS_TimerObj =
Tom Sepez39bfe122015-09-17 15:25:23 -0700435 (CJS_TimerObj*)FXJS_GetPrivate(pRuntime->GetIsolate(), pRetObj);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700436 TimerObj* pTimerObj = (TimerObj*)pJS_TimerObj->GetEmbedObject();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700437 pTimerObj->SetTimer(pTimer);
438
439 vRet = pRetObj;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700440 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700441}
442
Tom Sepezba038bc2015-10-08 12:03:00 -0700443FX_BOOL app::setTimeOut(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -0800444 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700445 CJS_Value& vRet,
446 CFX_WideString& sError) {
447 if (params.size() > 2 || params.size() == 0) {
448 sError = JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSPARAMERROR);
449 return FALSE;
450 }
Tom Sepezc6ab1722015-02-05 15:27:25 -0800451
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700452 CJS_Context* pContext = (CJS_Context*)cc;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700453 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700454
455 CFX_WideString script = params.size() > 0 ? params[0].ToCFXWideString() : L"";
456 if (script.IsEmpty()) {
457 sError =
458 JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSAFNUMBER_KEYSTROKE);
459 return TRUE;
460 }
461
462 FX_DWORD dwTimeOut = params.size() > 1 ? params[1].ToInt() : 1000;
463
464 CPDFDoc_Environment* pApp = pRuntime->GetReaderApp();
465 ASSERT(pApp);
466
Lei Zhang2d5a0e12015-10-05 17:00:03 -0700467 CJS_Timer* pTimer =
468 new CJS_Timer(this, pApp, pRuntime, 1, script, dwTimeOut, dwTimeOut);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700469 m_aTimer.Add(pTimer);
470
Tom Sepez39bfe122015-09-17 15:25:23 -0700471 v8::Local<v8::Object> pRetObj = FXJS_NewFxDynamicObj(
Tom Sepez33420902015-10-13 15:00:10 -0700472 pRuntime->GetIsolate(), pRuntime, CJS_TimerObj::g_nObjDefnID);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700473 CJS_TimerObj* pJS_TimerObj =
Tom Sepez39bfe122015-09-17 15:25:23 -0700474 (CJS_TimerObj*)FXJS_GetPrivate(pRuntime->GetIsolate(), pRetObj);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700475 TimerObj* pTimerObj = (TimerObj*)pJS_TimerObj->GetEmbedObject();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700476 pTimerObj->SetTimer(pTimer);
477
478 vRet = pRetObj;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700479 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700480}
481
Tom Sepezba038bc2015-10-08 12:03:00 -0700482FX_BOOL app::clearTimeOut(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -0800483 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700484 CJS_Value& vRet,
485 CFX_WideString& sError) {
486 CJS_Context* pContext = (CJS_Context*)cc;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700487 if (params.size() != 1) {
Tom Sepezcd56a7d2015-10-06 11:45:28 -0700488 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700489 return FALSE;
490 }
491
Tom Sepez39bfe122015-09-17 15:25:23 -0700492 if (params[0].GetType() == CJS_Value::VT_fxobject) {
Tom Sepez808a99e2015-09-10 12:28:37 -0700493 v8::Local<v8::Object> pObj = params[0].ToV8Object();
Tom Sepezcd56a7d2015-10-06 11:45:28 -0700494 if (FXJS_GetObjDefnID(pObj) == CJS_TimerObj::g_nObjDefnID) {
495 if (CJS_Object* pJSObj = params[0].ToCJSObject()) {
496 if (TimerObj* pTimerObj = (TimerObj*)pJSObj->GetEmbedObject()) {
497 if (CJS_Timer* pTimer = pTimerObj->GetTimer()) {
498 pTimer->KillJSTimer();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700499
Tom Sepezcd56a7d2015-10-06 11:45:28 -0700500 for (int i = 0, sz = m_aTimer.GetSize(); i < sz; i++) {
501 if (m_aTimer[i] == pTimer) {
502 m_aTimer.RemoveAt(i);
503 break;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700504 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700505 }
Tom Sepezcd56a7d2015-10-06 11:45:28 -0700506
507 delete pTimer;
508 pTimerObj->SetTimer(NULL);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700509 }
510 }
511 }
512 }
513 }
514
515 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700516}
517
Tom Sepezba038bc2015-10-08 12:03:00 -0700518FX_BOOL app::clearInterval(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -0800519 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700520 CJS_Value& vRet,
521 CFX_WideString& sError) {
522 CJS_Context* pContext = (CJS_Context*)cc;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700523 if (params.size() != 1) {
Tom Sepezcd56a7d2015-10-06 11:45:28 -0700524 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700525 return FALSE;
526 }
527
Tom Sepez39bfe122015-09-17 15:25:23 -0700528 if (params[0].GetType() == CJS_Value::VT_fxobject) {
Tom Sepez808a99e2015-09-10 12:28:37 -0700529 v8::Local<v8::Object> pObj = params[0].ToV8Object();
Tom Sepezcd56a7d2015-10-06 11:45:28 -0700530 if (FXJS_GetObjDefnID(pObj) == CJS_TimerObj::g_nObjDefnID) {
531 if (CJS_Object* pJSObj = params[0].ToCJSObject()) {
532 if (TimerObj* pTimerObj = (TimerObj*)pJSObj->GetEmbedObject()) {
533 if (CJS_Timer* pTimer = pTimerObj->GetTimer()) {
534 pTimer->KillJSTimer();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700535
Tom Sepezcd56a7d2015-10-06 11:45:28 -0700536 for (int i = 0, sz = m_aTimer.GetSize(); i < sz; i++) {
537 if (m_aTimer[i] == pTimer) {
538 m_aTimer.RemoveAt(i);
539 break;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700540 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700541 }
Tom Sepezcd56a7d2015-10-06 11:45:28 -0700542
543 delete pTimer;
544 pTimerObj->SetTimer(NULL);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700545 }
546 }
547 }
548 }
549 }
550
551 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700552}
553
Tom Sepezba038bc2015-10-08 12:03:00 -0700554FX_BOOL app::execMenuItem(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -0800555 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700556 CJS_Value& vRet,
557 CFX_WideString& sError) {
558 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700559}
560
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700561void app::TimerProc(CJS_Timer* pTimer) {
Lei Zhang2d5a0e12015-10-05 17:00:03 -0700562 CJS_Runtime* pRuntime = pTimer->GetRuntime();
563
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700564 switch (pTimer->GetType()) {
565 case 0: // interval
Lei Zhang2d5a0e12015-10-05 17:00:03 -0700566 if (pRuntime)
567 RunJsScript(pRuntime, pTimer->GetJScript());
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700568 break;
569 case 1:
570 if (pTimer->GetTimeOut() > 0) {
Lei Zhang2d5a0e12015-10-05 17:00:03 -0700571 if (pRuntime)
572 RunJsScript(pRuntime, pTimer->GetJScript());
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700573 pTimer->KillJSTimer();
574 }
575 break;
576 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700577}
578
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700579void app::RunJsScript(CJS_Runtime* pRuntime, const CFX_WideString& wsScript) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700580 if (!pRuntime->IsBlocking()) {
Tom Sepezba038bc2015-10-08 12:03:00 -0700581 IJS_Context* pContext = pRuntime->NewContext();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700582 pContext->OnExternal_Exec();
583 CFX_WideString wtInfo;
Tom Sepez33420902015-10-13 15:00:10 -0700584 pContext->RunScript(wsScript, &wtInfo);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700585 pRuntime->ReleaseContext(pContext);
586 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700587}
588
Tom Sepezba038bc2015-10-08 12:03:00 -0700589FX_BOOL app::goBack(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -0800590 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700591 CJS_Value& vRet,
592 CFX_WideString& sError) {
Tom Sepezc6ab1722015-02-05 15:27:25 -0800593 // Not supported.
594 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700595}
596
Tom Sepezba038bc2015-10-08 12:03:00 -0700597FX_BOOL app::goForward(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -0800598 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700599 CJS_Value& vRet,
600 CFX_WideString& sError) {
Tom Sepezc6ab1722015-02-05 15:27:25 -0800601 // Not supported.
602 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700603}
604
Tom Sepezba038bc2015-10-08 12:03:00 -0700605FX_BOOL app::mailMsg(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -0800606 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700607 CJS_Value& vRet,
608 CFX_WideString& sError) {
Tom Sepez67fd5df2015-10-08 12:24:19 -0700609 if (params.size() < 1)
610 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700611
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700612 FX_BOOL bUI = TRUE;
613 CFX_WideString cTo = L"";
614 CFX_WideString cCc = L"";
615 CFX_WideString cBcc = L"";
616 CFX_WideString cSubject = L"";
617 CFX_WideString cMsg = L"";
Tom Sepezf4ef3f92015-04-23 11:31:31 -0700618
Tom Sepez67fd5df2015-10-08 12:24:19 -0700619 CJS_Context* pContext = static_cast<CJS_Context*>(cc);
620 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
621 v8::Isolate* isolate = pRuntime->GetIsolate();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700622
Tom Sepez39bfe122015-09-17 15:25:23 -0700623 if (params[0].GetType() == CJS_Value::VT_object) {
Tom Sepez808a99e2015-09-10 12:28:37 -0700624 v8::Local<v8::Object> pObj = params[0].ToV8Object();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700625
Tom Sepez39bfe122015-09-17 15:25:23 -0700626 v8::Local<v8::Value> pValue = FXJS_GetObjectElement(isolate, pObj, L"bUI");
Tom Sepez67fd5df2015-10-08 12:24:19 -0700627 bUI = CJS_Value(pRuntime, pValue, GET_VALUE_TYPE(pValue)).ToBool();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700628
Tom Sepez39bfe122015-09-17 15:25:23 -0700629 pValue = FXJS_GetObjectElement(isolate, pObj, L"cTo");
Tom Sepez67fd5df2015-10-08 12:24:19 -0700630 cTo = CJS_Value(pRuntime, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700631
Tom Sepez39bfe122015-09-17 15:25:23 -0700632 pValue = FXJS_GetObjectElement(isolate, pObj, L"cCc");
Tom Sepez67fd5df2015-10-08 12:24:19 -0700633 cCc = CJS_Value(pRuntime, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700634
Tom Sepez39bfe122015-09-17 15:25:23 -0700635 pValue = FXJS_GetObjectElement(isolate, pObj, L"cBcc");
Tom Sepez67fd5df2015-10-08 12:24:19 -0700636 cBcc =
637 CJS_Value(pRuntime, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700638
Tom Sepez39bfe122015-09-17 15:25:23 -0700639 pValue = FXJS_GetObjectElement(isolate, pObj, L"cSubject");
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700640 cSubject =
Tom Sepez67fd5df2015-10-08 12:24:19 -0700641 CJS_Value(pRuntime, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700642
Tom Sepez39bfe122015-09-17 15:25:23 -0700643 pValue = FXJS_GetObjectElement(isolate, pObj, L"cMsg");
Tom Sepez67fd5df2015-10-08 12:24:19 -0700644 cMsg =
645 CJS_Value(pRuntime, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700646 } else {
647 if (params.size() < 2)
648 return FALSE;
Tom Sepezf4ef3f92015-04-23 11:31:31 -0700649
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700650 bUI = params[0].ToBool();
651 cTo = params[1].ToCFXWideString();
Tom Sepezf4ef3f92015-04-23 11:31:31 -0700652
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700653 if (params.size() >= 3)
654 cCc = params[2].ToCFXWideString();
655 if (params.size() >= 4)
656 cBcc = params[3].ToCFXWideString();
657 if (params.size() >= 5)
658 cSubject = params[4].ToCFXWideString();
659 if (params.size() >= 6)
660 cMsg = params[5].ToCFXWideString();
661 }
Tom Sepezc6ab1722015-02-05 15:27:25 -0800662
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700663 pRuntime->BeginBlock();
Tom Sepez67fd5df2015-10-08 12:24:19 -0700664 pContext->GetReaderApp()->JS_docmailForm(NULL, 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();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700668
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700669 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700670}
671
Tom Sepezba038bc2015-10-08 12:03:00 -0700672FX_BOOL app::launchURL(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -0800673 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700674 CJS_Value& vRet,
675 CFX_WideString& sError) {
Tom Sepezc6ab1722015-02-05 15:27:25 -0800676 // Unsafe, not supported.
677 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700678}
679
Tom Sepezba038bc2015-10-08 12:03:00 -0700680FX_BOOL app::runtimeHighlight(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700681 CJS_PropValue& vp,
682 CFX_WideString& sError) {
683 if (vp.IsSetting()) {
684 vp >> m_bRuntimeHighLight;
685 } else {
686 vp << m_bRuntimeHighLight;
687 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700688
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700689 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700690}
691
Tom Sepezba038bc2015-10-08 12:03:00 -0700692FX_BOOL app::fullscreen(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700693 CJS_PropValue& vp,
694 CFX_WideString& sError) {
695 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700696}
697
Tom Sepezba038bc2015-10-08 12:03:00 -0700698FX_BOOL app::popUpMenu(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -0800699 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700700 CJS_Value& vRet,
701 CFX_WideString& sError) {
702 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700703}
704
Tom Sepezba038bc2015-10-08 12:03:00 -0700705FX_BOOL app::browseForDoc(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -0800706 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700707 CJS_Value& vRet,
708 CFX_WideString& sError) {
Tom Sepezc6ab1722015-02-05 15:27:25 -0800709 // Unsafe, not supported.
710 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700711}
712
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700713CFX_WideString app::SysPathToPDFPath(const CFX_WideString& sOldPath) {
714 CFX_WideString sRet = L"/";
Tom Sepezc6ab1722015-02-05 15:27:25 -0800715
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700716 for (int i = 0, sz = sOldPath.GetLength(); i < sz; i++) {
717 wchar_t c = sOldPath.GetAt(i);
718 if (c == L':') {
719 } else {
720 if (c == L'\\') {
721 sRet += L"/";
722 } else {
723 sRet += c;
724 }
725 }
726 }
Tom Sepezc6ab1722015-02-05 15:27:25 -0800727
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700728 return sRet;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700729}
730
Tom Sepezba038bc2015-10-08 12:03:00 -0700731FX_BOOL app::newDoc(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -0800732 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700733 CJS_Value& vRet,
734 CFX_WideString& sError) {
735 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700736}
737
Tom Sepezba038bc2015-10-08 12:03:00 -0700738FX_BOOL app::openDoc(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -0800739 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700740 CJS_Value& vRet,
741 CFX_WideString& sError) {
742 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700743}
744
Tom Sepezba038bc2015-10-08 12:03:00 -0700745FX_BOOL app::response(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 CFX_WideString swQuestion = L"";
750 CFX_WideString swLabel = L"";
751 CFX_WideString swTitle = L"PDF";
752 CFX_WideString swDefault = L"";
753 bool bPassWord = false;
Tom Sepez621d4de2014-07-29 14:01:21 -0700754
Tom Sepez67fd5df2015-10-08 12:24:19 -0700755 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
756 v8::Isolate* isolate = pRuntime->GetIsolate();
Tom Sepez621d4de2014-07-29 14:01:21 -0700757
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700758 int iLength = params.size();
Tom Sepez39bfe122015-09-17 15:25:23 -0700759 if (iLength > 0 && params[0].GetType() == CJS_Value::VT_object) {
Tom Sepez808a99e2015-09-10 12:28:37 -0700760 v8::Local<v8::Object> pObj = params[0].ToV8Object();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700761 v8::Local<v8::Value> pValue =
Tom Sepez39bfe122015-09-17 15:25:23 -0700762 FXJS_GetObjectElement(isolate, pObj, L"cQuestion");
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700763 swQuestion =
Tom Sepez67fd5df2015-10-08 12:24:19 -0700764 CJS_Value(pRuntime, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700765
Tom Sepez39bfe122015-09-17 15:25:23 -0700766 pValue = FXJS_GetObjectElement(isolate, pObj, L"cTitle");
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700767 swTitle =
Tom Sepez67fd5df2015-10-08 12:24:19 -0700768 CJS_Value(pRuntime, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700769
Tom Sepez39bfe122015-09-17 15:25:23 -0700770 pValue = FXJS_GetObjectElement(isolate, pObj, L"cDefault");
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700771 swDefault =
Tom Sepez67fd5df2015-10-08 12:24:19 -0700772 CJS_Value(pRuntime, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700773
Tom Sepez39bfe122015-09-17 15:25:23 -0700774 pValue = FXJS_GetObjectElement(isolate, pObj, L"cLabel");
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700775 swLabel =
Tom Sepez67fd5df2015-10-08 12:24:19 -0700776 CJS_Value(pRuntime, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700777
Tom Sepez39bfe122015-09-17 15:25:23 -0700778 pValue = FXJS_GetObjectElement(isolate, pObj, L"bPassword");
Tom Sepez67fd5df2015-10-08 12:24:19 -0700779 bPassWord = CJS_Value(pRuntime, pValue, GET_VALUE_TYPE(pValue)).ToBool();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700780 } else {
781 switch (iLength) {
782 case 5:
783 swLabel = params[4].ToCFXWideString();
784 // FALLTHROUGH
785 case 4:
786 bPassWord = params[3].ToBool();
787 // FALLTHROUGH
788 case 3:
789 swDefault = params[2].ToCFXWideString();
790 // FALLTHROUGH
791 case 2:
792 swTitle = params[1].ToCFXWideString();
793 // FALLTHROUGH
794 case 1:
795 swQuestion = params[0].ToCFXWideString();
796 // FALLTHROUGH
797 default:
798 break;
799 }
800 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700801
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700802 CJS_Context* pContext = (CJS_Context*)cc;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700803 CPDFDoc_Environment* pApp = pContext->GetReaderApp();
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
Tom Sepezba038bc2015-10-08 12:03:00 -0700823FX_BOOL app::media(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700824 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700825}
826
Tom Sepezba038bc2015-10-08 12:03:00 -0700827FX_BOOL app::execDialog(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -0800828 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700829 CJS_Value& vRet,
830 CFX_WideString& sError) {
831 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700832}