blob: cb1cc9b59258fc61630f20e5a4d2149cee34875f [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);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700132 ASSERT(pJSDocument != NULL);
133 }
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;
453 ASSERT(pContext != NULL);
454 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
455 ASSERT(pRuntime != NULL);
456
457 CFX_WideString script = params.size() > 0 ? params[0].ToCFXWideString() : L"";
458 if (script.IsEmpty()) {
459 sError =
460 JSGetStringFromID((CJS_Context*)cc, IDS_STRING_JSAFNUMBER_KEYSTROKE);
461 return TRUE;
462 }
463
464 FX_DWORD dwTimeOut = params.size() > 1 ? params[1].ToInt() : 1000;
465
466 CPDFDoc_Environment* pApp = pRuntime->GetReaderApp();
467 ASSERT(pApp);
468
Lei Zhang2d5a0e12015-10-05 17:00:03 -0700469 CJS_Timer* pTimer =
470 new CJS_Timer(this, pApp, pRuntime, 1, script, dwTimeOut, dwTimeOut);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700471 m_aTimer.Add(pTimer);
472
Tom Sepez39bfe122015-09-17 15:25:23 -0700473 v8::Local<v8::Object> pRetObj = FXJS_NewFxDynamicObj(
Tom Sepez33420902015-10-13 15:00:10 -0700474 pRuntime->GetIsolate(), pRuntime, CJS_TimerObj::g_nObjDefnID);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700475 CJS_TimerObj* pJS_TimerObj =
Tom Sepez39bfe122015-09-17 15:25:23 -0700476 (CJS_TimerObj*)FXJS_GetPrivate(pRuntime->GetIsolate(), pRetObj);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700477 TimerObj* pTimerObj = (TimerObj*)pJS_TimerObj->GetEmbedObject();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700478 pTimerObj->SetTimer(pTimer);
479
480 vRet = pRetObj;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700481 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700482}
483
Tom Sepezba038bc2015-10-08 12:03:00 -0700484FX_BOOL app::clearTimeOut(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -0800485 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700486 CJS_Value& vRet,
487 CFX_WideString& sError) {
488 CJS_Context* pContext = (CJS_Context*)cc;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700489 if (params.size() != 1) {
Tom Sepezcd56a7d2015-10-06 11:45:28 -0700490 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700491 return FALSE;
492 }
493
Tom Sepez39bfe122015-09-17 15:25:23 -0700494 if (params[0].GetType() == CJS_Value::VT_fxobject) {
Tom Sepez808a99e2015-09-10 12:28:37 -0700495 v8::Local<v8::Object> pObj = params[0].ToV8Object();
Tom Sepezcd56a7d2015-10-06 11:45:28 -0700496 if (FXJS_GetObjDefnID(pObj) == CJS_TimerObj::g_nObjDefnID) {
497 if (CJS_Object* pJSObj = params[0].ToCJSObject()) {
498 if (TimerObj* pTimerObj = (TimerObj*)pJSObj->GetEmbedObject()) {
499 if (CJS_Timer* pTimer = pTimerObj->GetTimer()) {
500 pTimer->KillJSTimer();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700501
Tom Sepezcd56a7d2015-10-06 11:45:28 -0700502 for (int i = 0, sz = m_aTimer.GetSize(); i < sz; i++) {
503 if (m_aTimer[i] == pTimer) {
504 m_aTimer.RemoveAt(i);
505 break;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700506 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700507 }
Tom Sepezcd56a7d2015-10-06 11:45:28 -0700508
509 delete pTimer;
510 pTimerObj->SetTimer(NULL);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700511 }
512 }
513 }
514 }
515 }
516
517 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700518}
519
Tom Sepezba038bc2015-10-08 12:03:00 -0700520FX_BOOL app::clearInterval(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -0800521 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700522 CJS_Value& vRet,
523 CFX_WideString& sError) {
524 CJS_Context* pContext = (CJS_Context*)cc;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700525 if (params.size() != 1) {
Tom Sepezcd56a7d2015-10-06 11:45:28 -0700526 sError = JSGetStringFromID(pContext, IDS_STRING_JSPARAMERROR);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700527 return FALSE;
528 }
529
Tom Sepez39bfe122015-09-17 15:25:23 -0700530 if (params[0].GetType() == CJS_Value::VT_fxobject) {
Tom Sepez808a99e2015-09-10 12:28:37 -0700531 v8::Local<v8::Object> pObj = params[0].ToV8Object();
Tom Sepezcd56a7d2015-10-06 11:45:28 -0700532 if (FXJS_GetObjDefnID(pObj) == CJS_TimerObj::g_nObjDefnID) {
533 if (CJS_Object* pJSObj = params[0].ToCJSObject()) {
534 if (TimerObj* pTimerObj = (TimerObj*)pJSObj->GetEmbedObject()) {
535 if (CJS_Timer* pTimer = pTimerObj->GetTimer()) {
536 pTimer->KillJSTimer();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700537
Tom Sepezcd56a7d2015-10-06 11:45:28 -0700538 for (int i = 0, sz = m_aTimer.GetSize(); i < sz; i++) {
539 if (m_aTimer[i] == pTimer) {
540 m_aTimer.RemoveAt(i);
541 break;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700542 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700543 }
Tom Sepezcd56a7d2015-10-06 11:45:28 -0700544
545 delete pTimer;
546 pTimerObj->SetTimer(NULL);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700547 }
548 }
549 }
550 }
551 }
552
553 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700554}
555
Tom Sepezba038bc2015-10-08 12:03:00 -0700556FX_BOOL app::execMenuItem(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -0800557 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700558 CJS_Value& vRet,
559 CFX_WideString& sError) {
560 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700561}
562
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700563void app::TimerProc(CJS_Timer* pTimer) {
564 ASSERT(pTimer != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700565
Lei Zhang2d5a0e12015-10-05 17:00:03 -0700566 CJS_Runtime* pRuntime = pTimer->GetRuntime();
567
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700568 switch (pTimer->GetType()) {
569 case 0: // interval
Lei Zhang2d5a0e12015-10-05 17:00:03 -0700570 if (pRuntime)
571 RunJsScript(pRuntime, pTimer->GetJScript());
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700572 break;
573 case 1:
574 if (pTimer->GetTimeOut() > 0) {
Lei Zhang2d5a0e12015-10-05 17:00:03 -0700575 if (pRuntime)
576 RunJsScript(pRuntime, pTimer->GetJScript());
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700577 pTimer->KillJSTimer();
578 }
579 break;
580 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700581}
582
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700583void app::RunJsScript(CJS_Runtime* pRuntime, const CFX_WideString& wsScript) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700584 if (!pRuntime->IsBlocking()) {
Tom Sepezba038bc2015-10-08 12:03:00 -0700585 IJS_Context* pContext = pRuntime->NewContext();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700586 pContext->OnExternal_Exec();
587 CFX_WideString wtInfo;
Tom Sepez33420902015-10-13 15:00:10 -0700588 pContext->RunScript(wsScript, &wtInfo);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700589 pRuntime->ReleaseContext(pContext);
590 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700591}
592
Tom Sepezba038bc2015-10-08 12:03:00 -0700593FX_BOOL app::goBack(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -0800594 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700595 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
Tom Sepezba038bc2015-10-08 12:03:00 -0700601FX_BOOL app::goForward(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -0800602 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700603 CJS_Value& vRet,
604 CFX_WideString& sError) {
Tom Sepezc6ab1722015-02-05 15:27:25 -0800605 // Not supported.
606 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700607}
608
Tom Sepezba038bc2015-10-08 12:03:00 -0700609FX_BOOL app::mailMsg(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -0800610 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700611 CJS_Value& vRet,
612 CFX_WideString& sError) {
Tom Sepez67fd5df2015-10-08 12:24:19 -0700613 if (params.size() < 1)
614 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700615
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700616 FX_BOOL bUI = TRUE;
617 CFX_WideString cTo = L"";
618 CFX_WideString cCc = L"";
619 CFX_WideString cBcc = L"";
620 CFX_WideString cSubject = L"";
621 CFX_WideString cMsg = L"";
Tom Sepezf4ef3f92015-04-23 11:31:31 -0700622
Tom Sepez67fd5df2015-10-08 12:24:19 -0700623 CJS_Context* pContext = static_cast<CJS_Context*>(cc);
624 CJS_Runtime* pRuntime = pContext->GetJSRuntime();
625 v8::Isolate* isolate = pRuntime->GetIsolate();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700626
Tom Sepez39bfe122015-09-17 15:25:23 -0700627 if (params[0].GetType() == CJS_Value::VT_object) {
Tom Sepez808a99e2015-09-10 12:28:37 -0700628 v8::Local<v8::Object> pObj = params[0].ToV8Object();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700629
Tom Sepez39bfe122015-09-17 15:25:23 -0700630 v8::Local<v8::Value> pValue = FXJS_GetObjectElement(isolate, pObj, L"bUI");
Tom Sepez67fd5df2015-10-08 12:24:19 -0700631 bUI = CJS_Value(pRuntime, pValue, GET_VALUE_TYPE(pValue)).ToBool();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700632
Tom Sepez39bfe122015-09-17 15:25:23 -0700633 pValue = FXJS_GetObjectElement(isolate, pObj, L"cTo");
Tom Sepez67fd5df2015-10-08 12:24:19 -0700634 cTo = CJS_Value(pRuntime, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700635
Tom Sepez39bfe122015-09-17 15:25:23 -0700636 pValue = FXJS_GetObjectElement(isolate, pObj, L"cCc");
Tom Sepez67fd5df2015-10-08 12:24:19 -0700637 cCc = 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"cBcc");
Tom Sepez67fd5df2015-10-08 12:24:19 -0700640 cBcc =
641 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"cSubject");
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700644 cSubject =
Tom Sepez67fd5df2015-10-08 12:24:19 -0700645 CJS_Value(pRuntime, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700646
Tom Sepez39bfe122015-09-17 15:25:23 -0700647 pValue = FXJS_GetObjectElement(isolate, pObj, L"cMsg");
Tom Sepez67fd5df2015-10-08 12:24:19 -0700648 cMsg =
649 CJS_Value(pRuntime, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700650 } else {
651 if (params.size() < 2)
652 return FALSE;
Tom Sepezf4ef3f92015-04-23 11:31:31 -0700653
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700654 bUI = params[0].ToBool();
655 cTo = params[1].ToCFXWideString();
Tom Sepezf4ef3f92015-04-23 11:31:31 -0700656
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700657 if (params.size() >= 3)
658 cCc = params[2].ToCFXWideString();
659 if (params.size() >= 4)
660 cBcc = params[3].ToCFXWideString();
661 if (params.size() >= 5)
662 cSubject = params[4].ToCFXWideString();
663 if (params.size() >= 6)
664 cMsg = params[5].ToCFXWideString();
665 }
Tom Sepezc6ab1722015-02-05 15:27:25 -0800666
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700667 pRuntime->BeginBlock();
Tom Sepez67fd5df2015-10-08 12:24:19 -0700668 pContext->GetReaderApp()->JS_docmailForm(NULL, 0, bUI, cTo.c_str(),
669 cSubject.c_str(), cCc.c_str(),
670 cBcc.c_str(), cMsg.c_str());
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700671 pRuntime->EndBlock();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700672
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700673 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700674}
675
Tom Sepezba038bc2015-10-08 12:03:00 -0700676FX_BOOL app::launchURL(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) {
Tom Sepezc6ab1722015-02-05 15:27:25 -0800680 // Unsafe, not supported.
681 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700682}
683
Tom Sepezba038bc2015-10-08 12:03:00 -0700684FX_BOOL app::runtimeHighlight(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700685 CJS_PropValue& vp,
686 CFX_WideString& sError) {
687 if (vp.IsSetting()) {
688 vp >> m_bRuntimeHighLight;
689 } else {
690 vp << m_bRuntimeHighLight;
691 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700692
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700693 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700694}
695
Tom Sepezba038bc2015-10-08 12:03:00 -0700696FX_BOOL app::fullscreen(IJS_Context* cc,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700697 CJS_PropValue& vp,
698 CFX_WideString& sError) {
699 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700700}
701
Tom Sepezba038bc2015-10-08 12:03:00 -0700702FX_BOOL app::popUpMenu(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -0800703 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700704 CJS_Value& vRet,
705 CFX_WideString& sError) {
706 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700707}
708
Tom Sepezba038bc2015-10-08 12:03:00 -0700709FX_BOOL app::browseForDoc(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -0800710 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700711 CJS_Value& vRet,
712 CFX_WideString& sError) {
Tom Sepezc6ab1722015-02-05 15:27:25 -0800713 // Unsafe, not supported.
714 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700715}
716
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700717CFX_WideString app::SysPathToPDFPath(const CFX_WideString& sOldPath) {
718 CFX_WideString sRet = L"/";
Tom Sepezc6ab1722015-02-05 15:27:25 -0800719
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700720 for (int i = 0, sz = sOldPath.GetLength(); i < sz; i++) {
721 wchar_t c = sOldPath.GetAt(i);
722 if (c == L':') {
723 } else {
724 if (c == L'\\') {
725 sRet += L"/";
726 } else {
727 sRet += c;
728 }
729 }
730 }
Tom Sepezc6ab1722015-02-05 15:27:25 -0800731
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700732 return sRet;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700733}
734
Tom Sepezba038bc2015-10-08 12:03:00 -0700735FX_BOOL app::newDoc(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -0800736 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700737 CJS_Value& vRet,
738 CFX_WideString& sError) {
739 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700740}
741
Tom Sepezba038bc2015-10-08 12:03:00 -0700742FX_BOOL app::openDoc(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -0800743 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700744 CJS_Value& vRet,
745 CFX_WideString& sError) {
746 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700747}
748
Tom Sepezba038bc2015-10-08 12:03:00 -0700749FX_BOOL app::response(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -0800750 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700751 CJS_Value& vRet,
752 CFX_WideString& sError) {
753 CFX_WideString swQuestion = L"";
754 CFX_WideString swLabel = L"";
755 CFX_WideString swTitle = L"PDF";
756 CFX_WideString swDefault = L"";
757 bool bPassWord = false;
Tom Sepez621d4de2014-07-29 14:01:21 -0700758
Tom Sepez67fd5df2015-10-08 12:24:19 -0700759 CJS_Runtime* pRuntime = CJS_Runtime::FromContext(cc);
760 v8::Isolate* isolate = pRuntime->GetIsolate();
Tom Sepez621d4de2014-07-29 14:01:21 -0700761
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700762 int iLength = params.size();
Tom Sepez39bfe122015-09-17 15:25:23 -0700763 if (iLength > 0 && params[0].GetType() == CJS_Value::VT_object) {
Tom Sepez808a99e2015-09-10 12:28:37 -0700764 v8::Local<v8::Object> pObj = params[0].ToV8Object();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700765 v8::Local<v8::Value> pValue =
Tom Sepez39bfe122015-09-17 15:25:23 -0700766 FXJS_GetObjectElement(isolate, pObj, L"cQuestion");
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700767 swQuestion =
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"cTitle");
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700771 swTitle =
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"cDefault");
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700775 swDefault =
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"cLabel");
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700779 swLabel =
Tom Sepez67fd5df2015-10-08 12:24:19 -0700780 CJS_Value(pRuntime, pValue, GET_VALUE_TYPE(pValue)).ToCFXWideString();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700781
Tom Sepez39bfe122015-09-17 15:25:23 -0700782 pValue = FXJS_GetObjectElement(isolate, pObj, L"bPassword");
Tom Sepez67fd5df2015-10-08 12:24:19 -0700783 bPassWord = CJS_Value(pRuntime, pValue, GET_VALUE_TYPE(pValue)).ToBool();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700784 } else {
785 switch (iLength) {
786 case 5:
787 swLabel = params[4].ToCFXWideString();
788 // FALLTHROUGH
789 case 4:
790 bPassWord = params[3].ToBool();
791 // FALLTHROUGH
792 case 3:
793 swDefault = params[2].ToCFXWideString();
794 // FALLTHROUGH
795 case 2:
796 swTitle = params[1].ToCFXWideString();
797 // FALLTHROUGH
798 case 1:
799 swQuestion = params[0].ToCFXWideString();
800 // FALLTHROUGH
801 default:
802 break;
803 }
804 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700805
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700806 CJS_Context* pContext = (CJS_Context*)cc;
807 ASSERT(pContext != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700808
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700809 CPDFDoc_Environment* pApp = pContext->GetReaderApp();
810 ASSERT(pApp != NULL);
Tom Sepez621d4de2014-07-29 14:01:21 -0700811
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700812 const int MAX_INPUT_BYTES = 2048;
Lei Zhangdb5256f2015-10-02 10:11:43 -0700813 nonstd::unique_ptr<char[]> pBuff(new char[MAX_INPUT_BYTES + 2]);
814 memset(pBuff.get(), 0, MAX_INPUT_BYTES + 2);
815 int nLengthBytes = pApp->JS_appResponse(
816 swQuestion.c_str(), swTitle.c_str(), swDefault.c_str(), swLabel.c_str(),
817 bPassWord, pBuff.get(), MAX_INPUT_BYTES);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700818 if (nLengthBytes <= 0) {
819 vRet.SetNull();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700820 return FALSE;
821 }
Lei Zhangdb5256f2015-10-02 10:11:43 -0700822 nLengthBytes = std::min(nLengthBytes, MAX_INPUT_BYTES);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700823
Lei Zhangdb5256f2015-10-02 10:11:43 -0700824 CFX_WideString ret_string = CFX_WideString::FromUTF16LE(
825 (unsigned short*)pBuff.get(), nLengthBytes / sizeof(unsigned short));
826 vRet = ret_string.c_str();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700827 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700828}
829
Tom Sepezba038bc2015-10-08 12:03:00 -0700830FX_BOOL app::media(IJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700831 return FALSE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700832}
833
Tom Sepezba038bc2015-10-08 12:03:00 -0700834FX_BOOL app::execDialog(IJS_Context* cc,
Lei Zhang945fdb72015-11-11 10:18:16 -0800835 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700836 CJS_Value& vRet,
837 CFX_WideString& sError) {
838 return TRUE;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700839}