blob: 26f28f5b48bfa96947b0eb5d0e92885be4369b1a [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
Dan Sinclair85c8e7f2016-11-21 13:50:32 -05009#include <map>
Lei Zhangaa8bf7e2015-12-24 19:13:32 -080010#include <memory>
Dan Sinclair3ebd1212016-03-09 09:59:23 -050011#include <vector>
Lei Zhangaa8bf7e2015-12-24 19:13:32 -080012
dsinclair735606d2016-10-05 15:47:02 -070013#include "fpdfsdk/cpdfsdk_formfillenvironment.h"
dsinclair114e46a2016-09-29 17:18:21 -070014#include "fpdfsdk/cpdfsdk_interform.h"
Dan Sinclairf766ad22016-03-14 13:51:24 -040015#include "fpdfsdk/javascript/Document.h"
Dan Sinclairf766ad22016-03-14 13:51:24 -040016#include "fpdfsdk/javascript/JS_Define.h"
17#include "fpdfsdk/javascript/JS_EventHandler.h"
18#include "fpdfsdk/javascript/JS_Object.h"
Dan Sinclairf766ad22016-03-14 13:51:24 -040019#include "fpdfsdk/javascript/JS_Value.h"
Tom Sepezd6ae2af2017-02-16 11:49:55 -080020#include "fpdfsdk/javascript/cjs_event_context.h"
dsinclair64376be2016-03-31 20:03:24 -070021#include "fpdfsdk/javascript/cjs_runtime.h"
Dan Sinclairf766ad22016-03-14 13:51:24 -040022#include "fpdfsdk/javascript/resource.h"
tsepeza752edf2016-08-19 14:57:42 -070023#include "third_party/base/stl_util.h"
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070024
Dan Sinclair3cac3602017-10-24 15:15:27 -040025namespace {
26
27bool IsTypeKnown(v8::Local<v8::Value> value) {
28 return !value.IsEmpty() &&
29 (value->IsString() || value->IsNumber() || value->IsBoolean() ||
30 value->IsDate() || value->IsObject() || value->IsNull() ||
31 value->IsUndefined());
32}
33
34} // namespace
35
tsepez1c620542016-09-12 09:47:52 -070036class GlobalTimer {
tsepeze3ff76b2016-08-08 11:58:47 -070037 public:
38 GlobalTimer(app* pObj,
dsinclair82e17672016-10-11 12:38:01 -070039 CPDFSDK_FormFillEnvironment* pFormFillEnv,
tsepeze3ff76b2016-08-08 11:58:47 -070040 CJS_Runtime* pRuntime,
41 int nType,
Ryan Harrison275e2602017-09-18 14:23:18 -040042 const WideString& script,
tsepeze3ff76b2016-08-08 11:58:47 -070043 uint32_t dwElapse,
44 uint32_t dwTimeOut);
tsepez8832fbf2016-09-08 10:25:55 -070045 ~GlobalTimer();
tsepeze3ff76b2016-08-08 11:58:47 -070046
47 static void Trigger(int nTimerID);
48 static void Cancel(int nTimerID);
49
50 bool IsOneShot() const { return m_nType == 1; }
51 uint32_t GetTimeOut() const { return m_dwTimeOut; }
52 int GetTimerID() const { return m_nTimerID; }
tsepez1c620542016-09-12 09:47:52 -070053 CJS_Runtime* GetRuntime() const { return m_pRuntime.Get(); }
Ryan Harrison275e2602017-09-18 14:23:18 -040054 WideString GetJScript() const { return m_swJScript; }
tsepeze3ff76b2016-08-08 11:58:47 -070055
56 private:
dsinclair72177da2016-09-15 12:07:23 -070057 using TimerMap = std::map<uint32_t, GlobalTimer*>;
tsepeze3ff76b2016-08-08 11:58:47 -070058 static TimerMap* GetGlobalTimerMap();
59
tsepeze3ff76b2016-08-08 11:58:47 -070060 uint32_t m_nTimerID;
61 app* const m_pEmbedObj;
62 bool m_bProcessing;
tsepeze3ff76b2016-08-08 11:58:47 -070063
64 // data
65 const int m_nType; // 0:Interval; 1:TimeOut
66 const uint32_t m_dwTimeOut;
Ryan Harrison275e2602017-09-18 14:23:18 -040067 const WideString m_swJScript;
tsepez1c620542016-09-12 09:47:52 -070068 CJS_Runtime::ObservedPtr m_pRuntime;
Tom Sepez77f6d0f2017-02-23 12:14:10 -080069 CPDFSDK_FormFillEnvironment::ObservedPtr m_pFormFillEnv;
tsepeze3ff76b2016-08-08 11:58:47 -070070};
71
72GlobalTimer::GlobalTimer(app* pObj,
dsinclair82e17672016-10-11 12:38:01 -070073 CPDFSDK_FormFillEnvironment* pFormFillEnv,
tsepeze3ff76b2016-08-08 11:58:47 -070074 CJS_Runtime* pRuntime,
75 int nType,
Ryan Harrison275e2602017-09-18 14:23:18 -040076 const WideString& script,
tsepeze3ff76b2016-08-08 11:58:47 -070077 uint32_t dwElapse,
78 uint32_t dwTimeOut)
79 : m_nTimerID(0),
80 m_pEmbedObj(pObj),
81 m_bProcessing(false),
tsepeze3ff76b2016-08-08 11:58:47 -070082 m_nType(nType),
83 m_dwTimeOut(dwTimeOut),
84 m_swJScript(script),
85 m_pRuntime(pRuntime),
dsinclair82e17672016-10-11 12:38:01 -070086 m_pFormFillEnv(pFormFillEnv) {
87 CFX_SystemHandler* pHandler = m_pFormFillEnv->GetSysHandler();
tsepeze3ff76b2016-08-08 11:58:47 -070088 m_nTimerID = pHandler->SetTimer(dwElapse, Trigger);
tsepez6cf5eca2017-01-12 11:21:12 -080089 if (m_nTimerID)
90 (*GetGlobalTimerMap())[m_nTimerID] = this;
tsepeze3ff76b2016-08-08 11:58:47 -070091}
92
93GlobalTimer::~GlobalTimer() {
tsepeze3ff76b2016-08-08 11:58:47 -070094 if (!m_nTimerID)
95 return;
96
tsepez8832fbf2016-09-08 10:25:55 -070097 if (GetRuntime())
dsinclair82e17672016-10-11 12:38:01 -070098 m_pFormFillEnv->GetSysHandler()->KillTimer(m_nTimerID);
tsepeze3ff76b2016-08-08 11:58:47 -070099
100 GetGlobalTimerMap()->erase(m_nTimerID);
101}
102
103// static
104void GlobalTimer::Trigger(int nTimerID) {
105 auto it = GetGlobalTimerMap()->find(nTimerID);
106 if (it == GetGlobalTimerMap()->end())
107 return;
108
109 GlobalTimer* pTimer = it->second;
110 if (pTimer->m_bProcessing)
111 return;
112
113 pTimer->m_bProcessing = true;
114 if (pTimer->m_pEmbedObj)
115 pTimer->m_pEmbedObj->TimerProc(pTimer);
116
117 // Timer proc may have destroyed timer, find it again.
118 it = GetGlobalTimerMap()->find(nTimerID);
119 if (it == GetGlobalTimerMap()->end())
120 return;
121
122 pTimer = it->second;
123 pTimer->m_bProcessing = false;
124 if (pTimer->IsOneShot())
125 pTimer->m_pEmbedObj->CancelProc(pTimer);
126}
127
128// static
129void GlobalTimer::Cancel(int nTimerID) {
130 auto it = GetGlobalTimerMap()->find(nTimerID);
131 if (it == GetGlobalTimerMap()->end())
132 return;
133
134 GlobalTimer* pTimer = it->second;
135 pTimer->m_pEmbedObj->CancelProc(pTimer);
136}
137
138// static
139GlobalTimer::TimerMap* GlobalTimer::GetGlobalTimerMap() {
140 // Leak the timer array at shutdown.
141 static auto* s_TimerMap = new TimerMap;
142 return s_TimerMap;
143}
144
Tom Sepez04557b82017-02-16 09:43:10 -0800145JSConstSpec CJS_TimerObj::ConstSpecs[] = {{0, JSConstSpec::Number, 0, 0}};
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700146
Tom Sepez04557b82017-02-16 09:43:10 -0800147JSPropertySpec CJS_TimerObj::PropertySpecs[] = {{0, 0, 0}};
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700148
Tom Sepez04557b82017-02-16 09:43:10 -0800149JSMethodSpec CJS_TimerObj::MethodSpecs[] = {{0, 0}};
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700150
Dan Sinclair4b172c42017-10-23 11:22:31 -0400151IMPLEMENT_JS_CLASS(CJS_TimerObj, TimerObj, TimerObj)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700152
153TimerObj::TimerObj(CJS_Object* pJSObject)
tsepez8ca63de2016-08-05 17:12:27 -0700154 : CJS_EmbedObj(pJSObject), m_nTimerID(0) {}
Tom Sepezc6ab1722015-02-05 15:27:25 -0800155
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700156TimerObj::~TimerObj() {}
157
tsepeze3ff76b2016-08-08 11:58:47 -0700158void TimerObj::SetTimer(GlobalTimer* pTimer) {
tsepez8ca63de2016-08-05 17:12:27 -0700159 m_nTimerID = pTimer->GetTimerID();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700160}
161
Tom Sepezd6278ba2015-09-08 16:34:37 -0700162#define JS_STR_VIEWERTYPE L"pdfium"
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700163#define JS_STR_VIEWERVARIATION L"Full"
164#define JS_STR_PLATFORM L"WIN"
dsinclairf51e4dc2016-10-13 07:43:19 -0700165#define JS_STR_LANGUAGE L"ENU"
Tom Sepezd6278ba2015-09-08 16:34:37 -0700166#define JS_NUM_VIEWERVERSION 8
Tom Sepez51da0932015-11-25 16:05:49 -0800167#ifdef PDF_ENABLE_XFA
Tom Sepezd6278ba2015-09-08 16:34:37 -0700168#define JS_NUM_VIEWERVERSION_XFA 11
Tom Sepez40e9ff32015-11-30 12:39:54 -0800169#endif // PDF_ENABLE_XFA
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700170#define JS_NUM_FORMSVERSION 7
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700171
Tom Sepez04557b82017-02-16 09:43:10 -0800172JSConstSpec CJS_App::ConstSpecs[] = {{0, JSConstSpec::Number, 0, 0}};
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700173
Tom Sepez04557b82017-02-16 09:43:10 -0800174JSPropertySpec CJS_App::PropertySpecs[] = {
dan sinclaircbe23db2017-10-19 14:29:33 -0400175 {"activeDocs", get_active_docs_static, set_active_docs_static},
Tom Sepez4d5b8c52017-02-21 15:17:07 -0800176 {"calculate", get_calculate_static, set_calculate_static},
dan sinclaircbe23db2017-10-19 14:29:33 -0400177 {"formsVersion", get_forms_version_static, set_forms_version_static},
Tom Sepez4d5b8c52017-02-21 15:17:07 -0800178 {"fs", get_fs_static, set_fs_static},
179 {"fullscreen", get_fullscreen_static, set_fullscreen_static},
180 {"language", get_language_static, set_language_static},
181 {"media", get_media_static, set_media_static},
182 {"platform", get_platform_static, set_platform_static},
dan sinclaircbe23db2017-10-19 14:29:33 -0400183 {"runtimeHighlight", get_runtime_highlight_static,
184 set_runtime_highlight_static},
185 {"viewerType", get_viewer_type_static, set_viewer_type_static},
186 {"viewerVariation", get_viewer_variation_static,
187 set_viewer_variation_static},
188 {"viewerVersion", get_viewer_version_static, set_viewer_version_static},
Tom Sepez04557b82017-02-16 09:43:10 -0800189 {0, 0, 0}};
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700190
Tom Sepez9b99b632017-02-21 15:05:57 -0800191JSMethodSpec CJS_App::MethodSpecs[] = {{"alert", alert_static},
192 {"beep", beep_static},
193 {"browseForDoc", browseForDoc_static},
194 {"clearInterval", clearInterval_static},
195 {"clearTimeOut", clearTimeOut_static},
196 {"execDialog", execDialog_static},
197 {"execMenuItem", execMenuItem_static},
198 {"findComponent", findComponent_static},
199 {"goBack", goBack_static},
200 {"goForward", goForward_static},
201 {"launchURL", launchURL_static},
202 {"mailMsg", mailMsg_static},
203 {"newFDF", newFDF_static},
204 {"newDoc", newDoc_static},
205 {"openDoc", openDoc_static},
206 {"openFDF", openFDF_static},
207 {"popUpMenuEx", popUpMenuEx_static},
208 {"popUpMenu", popUpMenu_static},
209 {"response", response_static},
210 {"setInterval", setInterval_static},
211 {"setTimeOut", setTimeOut_static},
Tom Sepez04557b82017-02-16 09:43:10 -0800212 {0, 0}};
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700213
Dan Sinclair4b172c42017-10-23 11:22:31 -0400214IMPLEMENT_JS_CLASS(CJS_App, app, app)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700215
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700216app::app(CJS_Object* pJSObject)
217 : CJS_EmbedObj(pJSObject), m_bCalculate(true), m_bRuntimeHighLight(false) {}
218
Lei Zhang2b1a2d52015-08-14 22:16:22 -0700219app::~app() {
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700220}
221
dan sinclaircbe23db2017-10-19 14:29:33 -0400222bool app::get_active_docs(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400223 CJS_Value* vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400224 WideString* sError) {
dsinclair82e17672016-10-11 12:38:01 -0700225 CJS_Document* pJSDocument = nullptr;
226 v8::Local<v8::Object> pObj = pRuntime->GetThisObj();
Tom Sepezc5a14722017-02-24 15:31:12 -0800227 if (CFXJS_Engine::GetObjDefnID(pObj) == CJS_Document::g_nObjDefnID)
dsinclair82e17672016-10-11 12:38:01 -0700228 pJSDocument = static_cast<CJS_Document*>(pRuntime->GetObjectPrivate(pObj));
dsinclair82e17672016-10-11 12:38:01 -0700229
230 CJS_Array aDocs;
Dan Sinclair1d8d9ac2017-10-24 11:23:25 -0400231 aDocs.SetElement(
232 pRuntime, 0,
233 pJSDocument ? CJS_Value(pJSDocument->ToV8Object()) : CJS_Value());
Dan Sinclair1b2a18e2017-10-24 13:56:29 -0400234 if (aDocs.GetLength(pRuntime) > 0) {
235 if (aDocs.ToV8Value().IsEmpty())
236 vp->Set(pRuntime->NewArray());
237 else
238 vp->Set(aDocs.ToV8Value());
239 } else {
Dan Sinclaire4974922017-10-24 09:36:16 -0400240 vp->Set(pRuntime->NewNull());
Dan Sinclair1b2a18e2017-10-24 13:56:29 -0400241 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700242
tsepez4cf55152016-11-02 14:37:54 -0700243 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700244}
245
dan sinclaircbe23db2017-10-19 14:29:33 -0400246bool app::set_active_docs(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400247 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400248 WideString* sError) {
249 return false;
250}
251
252bool app::get_calculate(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400253 CJS_Value* vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400254 WideString* sError) {
Dan Sinclaire4974922017-10-24 09:36:16 -0400255 vp->Set(pRuntime->NewBoolean(m_bCalculate));
tsepez4cf55152016-11-02 14:37:54 -0700256 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700257}
258
dan sinclaircbe23db2017-10-19 14:29:33 -0400259bool app::set_calculate(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400260 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400261 WideString* sError) {
Dan Sinclair1b2a18e2017-10-24 13:56:29 -0400262 m_bCalculate = pRuntime->ToBoolean(vp.ToV8Value());
dan sinclaircbe23db2017-10-19 14:29:33 -0400263 pRuntime->GetFormFillEnv()->GetInterForm()->EnableCalculate(m_bCalculate);
264 return true;
265}
tsepez4cf55152016-11-02 14:37:54 -0700266
dan sinclaircbe23db2017-10-19 14:29:33 -0400267bool app::get_forms_version(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400268 CJS_Value* vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400269 WideString* sError) {
Dan Sinclaire4974922017-10-24 09:36:16 -0400270 vp->Set(pRuntime->NewNumber(JS_NUM_FORMSVERSION));
dan sinclaircbe23db2017-10-19 14:29:33 -0400271 return true;
272}
273
274bool app::set_forms_version(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400275 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400276 WideString* sError) {
tsepez4cf55152016-11-02 14:37:54 -0700277 return false;
278}
279
dan sinclaircbe23db2017-10-19 14:29:33 -0400280bool app::get_viewer_type(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400281 CJS_Value* vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400282 WideString* sError) {
Dan Sinclaire4974922017-10-24 09:36:16 -0400283 vp->Set(pRuntime->NewString(JS_STR_VIEWERTYPE));
dan sinclaircbe23db2017-10-19 14:29:33 -0400284 return true;
285}
tsepez4cf55152016-11-02 14:37:54 -0700286
dan sinclaircbe23db2017-10-19 14:29:33 -0400287bool app::set_viewer_type(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400288 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400289 WideString* sError) {
tsepez4cf55152016-11-02 14:37:54 -0700290 return false;
291}
292
dan sinclaircbe23db2017-10-19 14:29:33 -0400293bool app::get_viewer_variation(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400294 CJS_Value* vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400295 WideString* sError) {
Dan Sinclaire4974922017-10-24 09:36:16 -0400296 vp->Set(pRuntime->NewString(JS_STR_VIEWERVARIATION));
dan sinclaircbe23db2017-10-19 14:29:33 -0400297 return true;
298}
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700299
dan sinclaircbe23db2017-10-19 14:29:33 -0400300bool app::set_viewer_variation(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400301 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400302 WideString* sError) {
tsepez4cf55152016-11-02 14:37:54 -0700303 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700304}
305
dan sinclaircbe23db2017-10-19 14:29:33 -0400306bool app::get_viewer_version(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400307 CJS_Value* vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400308 WideString* sError) {
Tom Sepez51da0932015-11-25 16:05:49 -0800309#ifdef PDF_ENABLE_XFA
Tom Sepezb1670b52017-02-16 17:01:00 -0800310 CPDFXFA_Context* pXFAContext = pRuntime->GetFormFillEnv()->GetXFAContext();
Ryan Harrison854d71c2017-10-18 12:28:14 -0400311 if (pXFAContext->ContainsXFAForm()) {
Dan Sinclaire4974922017-10-24 09:36:16 -0400312 vp->Set(pRuntime->NewNumber(JS_NUM_VIEWERVERSION_XFA));
tsepez4cf55152016-11-02 14:37:54 -0700313 return true;
Tom Sepezbf59a072015-10-21 14:07:23 -0700314 }
Tom Sepez40e9ff32015-11-30 12:39:54 -0800315#endif // PDF_ENABLE_XFA
Dan Sinclaire4974922017-10-24 09:36:16 -0400316 vp->Set(pRuntime->NewNumber(JS_NUM_VIEWERVERSION));
tsepez4cf55152016-11-02 14:37:54 -0700317 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700318}
319
dan sinclaircbe23db2017-10-19 14:29:33 -0400320bool app::set_viewer_version(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400321 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400322 WideString* sError) {
323 return false;
324}
325
326bool app::get_platform(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400327 CJS_Value* vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400328 WideString* sError) {
Tom Sepez4d6fa832015-12-08 11:31:59 -0800329#ifdef PDF_ENABLE_XFA
Tom Sepezb1670b52017-02-16 17:01:00 -0800330 CPDFSDK_FormFillEnvironment* pFormFillEnv = pRuntime->GetFormFillEnv();
dsinclair82e17672016-10-11 12:38:01 -0700331 if (!pFormFillEnv)
tsepez4cf55152016-11-02 14:37:54 -0700332 return false;
dan sinclaircbe23db2017-10-19 14:29:33 -0400333
Ryan Harrison275e2602017-09-18 14:23:18 -0400334 WideString platfrom = pFormFillEnv->GetPlatform();
Tom Sepez4d6fa832015-12-08 11:31:59 -0800335 if (!platfrom.IsEmpty()) {
Dan Sinclaire4974922017-10-24 09:36:16 -0400336 vp->Set(pRuntime->NewString(platfrom.c_str()));
tsepez4cf55152016-11-02 14:37:54 -0700337 return true;
Tom Sepez4d6fa832015-12-08 11:31:59 -0800338 }
339#endif
Dan Sinclaire4974922017-10-24 09:36:16 -0400340 vp->Set(pRuntime->NewString(JS_STR_PLATFORM));
tsepez4cf55152016-11-02 14:37:54 -0700341 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700342}
343
dan sinclaircbe23db2017-10-19 14:29:33 -0400344bool app::set_platform(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400345 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400346 WideString* sError) {
347 return false;
348}
349
350bool app::get_language(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400351 CJS_Value* vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400352 WideString* sError) {
Tom Sepez4d6fa832015-12-08 11:31:59 -0800353#ifdef PDF_ENABLE_XFA
Tom Sepezb1670b52017-02-16 17:01:00 -0800354 CPDFSDK_FormFillEnvironment* pFormFillEnv = pRuntime->GetFormFillEnv();
dsinclair82e17672016-10-11 12:38:01 -0700355 if (!pFormFillEnv)
tsepez4cf55152016-11-02 14:37:54 -0700356 return false;
dan sinclaircbe23db2017-10-19 14:29:33 -0400357
Ryan Harrison275e2602017-09-18 14:23:18 -0400358 WideString language = pFormFillEnv->GetLanguage();
Tom Sepez4d6fa832015-12-08 11:31:59 -0800359 if (!language.IsEmpty()) {
Dan Sinclaire4974922017-10-24 09:36:16 -0400360 vp->Set(pRuntime->NewString(language.c_str()));
tsepez4cf55152016-11-02 14:37:54 -0700361 return true;
Tom Sepez4d6fa832015-12-08 11:31:59 -0800362 }
363#endif
Dan Sinclaire4974922017-10-24 09:36:16 -0400364 vp->Set(pRuntime->NewString(JS_STR_LANGUAGE));
tsepez4cf55152016-11-02 14:37:54 -0700365 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700366}
367
dan sinclaircbe23db2017-10-19 14:29:33 -0400368bool app::set_language(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400369 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400370 WideString* sError) {
371 return false;
372}
373
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700374// creates a new fdf object that contains no data
375// comment: need reader support
376// note:
dsinclair735606d2016-10-05 15:47:02 -0700377// CFDF_Document * CPDFSDK_FormFillEnvironment::NewFDF();
Tom Sepezb1670b52017-02-16 17:01:00 -0800378bool app::newFDF(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700379 const std::vector<CJS_Value>& params,
380 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -0400381 WideString& sError) {
tsepez4cf55152016-11-02 14:37:54 -0700382 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700383}
384// opens a specified pdf document and returns its document object
385// comment:need reader support
386// note: as defined in js reference, the proto of this function's fourth
387// parmeters, how old an fdf document while do not show it.
dsinclair735606d2016-10-05 15:47:02 -0700388// CFDF_Document * CPDFSDK_FormFillEnvironment::OpenFDF(string strPath,bool
389// bUserConv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700390
Tom Sepezb1670b52017-02-16 17:01:00 -0800391bool app::openFDF(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700392 const std::vector<CJS_Value>& params,
393 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -0400394 WideString& sError) {
tsepez4cf55152016-11-02 14:37:54 -0700395 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700396}
397
Tom Sepezb1670b52017-02-16 17:01:00 -0800398bool app::alert(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700399 const std::vector<CJS_Value>& params,
400 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -0400401 WideString& sError) {
Dan Sinclairc9708952017-10-23 09:40:59 -0400402 std::vector<CJS_Value> newParams = ExpandKeywordParams(
Tom Sepezbd932572016-01-29 09:10:41 -0800403 pRuntime, params, 4, L"cMsg", L"nIcon", L"nType", L"cTitle");
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700404
Dan Sinclair3cac3602017-10-24 15:15:27 -0400405 if (!IsTypeKnown(newParams[0].ToV8Value())) {
tsepezcd5dc852016-09-08 11:23:24 -0700406 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);
tsepez4cf55152016-11-02 14:37:54 -0700407 return false;
Tom Sepezbd932572016-01-29 09:10:41 -0800408 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700409
dsinclair82e17672016-10-11 12:38:01 -0700410 CPDFSDK_FormFillEnvironment* pFormFillEnv = pRuntime->GetFormFillEnv();
411 if (!pFormFillEnv) {
Dan Sinclair1d8d9ac2017-10-24 11:23:25 -0400412 vRet = CJS_Value(pRuntime->NewNumber(0));
tsepez4cf55152016-11-02 14:37:54 -0700413 return true;
tsepeze1e7bd02016-08-08 13:03:16 -0700414 }
415
Ryan Harrison275e2602017-09-18 14:23:18 -0400416 WideString swMsg;
Dan Sinclair3cac3602017-10-24 15:15:27 -0400417 if (newParams[0].ToV8Value()->IsObject()) {
Dan Sinclairc9708952017-10-23 09:40:59 -0400418 if (newParams[0].IsArrayObject()) {
Dan Sinclair1b2a18e2017-10-24 13:56:29 -0400419 CJS_Array carray(pRuntime->ToArray(newParams[0].ToV8Value()));
Tom Sepezbd932572016-01-29 09:10:41 -0800420 swMsg = L"[";
tsepezb4694242016-08-15 16:44:55 -0700421 for (int i = 0; i < carray.GetLength(pRuntime); ++i) {
Tom Sepezbd932572016-01-29 09:10:41 -0800422 if (i)
423 swMsg += L", ";
Dan Sinclairc9708952017-10-23 09:40:59 -0400424
425 CJS_Value element(carray.GetElement(pRuntime, i));
Dan Sinclair1b2a18e2017-10-24 13:56:29 -0400426 swMsg += pRuntime->ToWideString(element.ToV8Value());
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700427 }
Tom Sepezbd932572016-01-29 09:10:41 -0800428 swMsg += L"]";
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700429 } else {
Dan Sinclair1b2a18e2017-10-24 13:56:29 -0400430 swMsg = pRuntime->ToWideString(newParams[0].ToV8Value());
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700431 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700432 } else {
Dan Sinclair1b2a18e2017-10-24 13:56:29 -0400433 swMsg = pRuntime->ToWideString(newParams[0].ToV8Value());
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700434 }
435
Tom Sepezbd932572016-01-29 09:10:41 -0800436 int iIcon = 0;
Dan Sinclair3cac3602017-10-24 15:15:27 -0400437 if (IsTypeKnown(newParams[1].ToV8Value()))
Dan Sinclair1b2a18e2017-10-24 13:56:29 -0400438 iIcon = pRuntime->ToInt32(newParams[1].ToV8Value());
Tom Sepezbd932572016-01-29 09:10:41 -0800439
440 int iType = 0;
Dan Sinclair3cac3602017-10-24 15:15:27 -0400441 if (IsTypeKnown(newParams[2].ToV8Value()))
Dan Sinclair1b2a18e2017-10-24 13:56:29 -0400442 iType = pRuntime->ToInt32(newParams[2].ToV8Value());
Tom Sepezbd932572016-01-29 09:10:41 -0800443
Ryan Harrison275e2602017-09-18 14:23:18 -0400444 WideString swTitle;
Dan Sinclair3cac3602017-10-24 15:15:27 -0400445 if (IsTypeKnown(newParams[3].ToV8Value()))
Dan Sinclair1b2a18e2017-10-24 13:56:29 -0400446 swTitle = pRuntime->ToWideString(newParams[3].ToV8Value());
Tom Sepezbd932572016-01-29 09:10:41 -0800447 else
tsepezcd5dc852016-09-08 11:23:24 -0700448 swTitle = JSGetStringFromID(IDS_STRING_JSALERT);
Tom Sepezbd932572016-01-29 09:10:41 -0800449
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700450 pRuntime->BeginBlock();
dsinclair7cbe68e2016-10-12 11:56:23 -0700451 pFormFillEnv->KillFocusAnnot(0);
tsepeze1e7bd02016-08-08 13:03:16 -0700452
Dan Sinclair1d8d9ac2017-10-24 11:23:25 -0400453 vRet = CJS_Value(pRuntime->NewNumber(
454 pFormFillEnv->JS_appAlert(swMsg.c_str(), swTitle.c_str(), iType, iIcon)));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700455 pRuntime->EndBlock();
tsepez4cf55152016-11-02 14:37:54 -0700456 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700457}
458
Tom Sepezb1670b52017-02-16 17:01:00 -0800459bool app::beep(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700460 const std::vector<CJS_Value>& params,
461 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -0400462 WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700463 if (params.size() == 1) {
Dan Sinclair1b2a18e2017-10-24 13:56:29 -0400464 pRuntime->GetFormFillEnv()->JS_appBeep(
465 pRuntime->ToInt32(params[0].ToV8Value()));
tsepez4cf55152016-11-02 14:37:54 -0700466 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700467 }
468
tsepezcd5dc852016-09-08 11:23:24 -0700469 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);
tsepez4cf55152016-11-02 14:37:54 -0700470 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700471}
472
Tom Sepezb1670b52017-02-16 17:01:00 -0800473bool app::findComponent(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700474 const std::vector<CJS_Value>& params,
475 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -0400476 WideString& sError) {
tsepez4cf55152016-11-02 14:37:54 -0700477 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700478}
479
Tom Sepezb1670b52017-02-16 17:01:00 -0800480bool app::popUpMenuEx(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700481 const std::vector<CJS_Value>& params,
482 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -0400483 WideString& sError) {
tsepez4cf55152016-11-02 14:37:54 -0700484 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700485}
486
Dan Sinclair33d13f22017-10-23 09:44:30 -0400487bool app::get_fs(CJS_Runtime* pRuntime, CJS_Value* vp, WideString* sError) {
dan sinclaircbe23db2017-10-19 14:29:33 -0400488 return false;
489}
490
491bool app::set_fs(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400492 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400493 WideString* sError) {
tsepez4cf55152016-11-02 14:37:54 -0700494 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700495}
496
Tom Sepezb1670b52017-02-16 17:01:00 -0800497bool app::setInterval(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700498 const std::vector<CJS_Value>& params,
499 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -0400500 WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700501 if (params.size() > 2 || params.size() == 0) {
tsepezcd5dc852016-09-08 11:23:24 -0700502 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);
tsepez4cf55152016-11-02 14:37:54 -0700503 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700504 }
Tom Sepezc6ab1722015-02-05 15:27:25 -0800505
Ryan Harrison275e2602017-09-18 14:23:18 -0400506 WideString script =
Dan Sinclair1b2a18e2017-10-24 13:56:29 -0400507 params.size() > 0 ? pRuntime->ToWideString(params[0].ToV8Value()) : L"";
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700508 if (script.IsEmpty()) {
tsepezcd5dc852016-09-08 11:23:24 -0700509 sError = JSGetStringFromID(IDS_STRING_JSAFNUMBER_KEYSTROKE);
tsepez4cf55152016-11-02 14:37:54 -0700510 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700511 }
512
Dan Sinclair1b2a18e2017-10-24 13:56:29 -0400513 uint32_t dwInterval =
514 params.size() > 1 ? pRuntime->ToInt32(params[1].ToV8Value()) : 1000;
dsinclair2eb7c7d2016-08-18 09:58:19 -0700515
dsinclair82e17672016-10-11 12:38:01 -0700516 GlobalTimer* timerRef = new GlobalTimer(this, pRuntime->GetFormFillEnv(),
517 pRuntime, 0, script, dwInterval, 0);
tsepeza752edf2016-08-19 14:57:42 -0700518 m_Timers.insert(std::unique_ptr<GlobalTimer>(timerRef));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700519
tsepezb4694242016-08-15 16:44:55 -0700520 v8::Local<v8::Object> pRetObj =
521 pRuntime->NewFxDynamicObj(CJS_TimerObj::g_nObjDefnID);
Tom Sepezc5a14722017-02-24 15:31:12 -0800522 if (pRetObj.IsEmpty())
523 return false;
524
tsepezb4694242016-08-15 16:44:55 -0700525 CJS_TimerObj* pJS_TimerObj =
526 static_cast<CJS_TimerObj*>(pRuntime->GetObjectPrivate(pRetObj));
tsepez41a53ad2016-03-28 16:59:30 -0700527 TimerObj* pTimerObj = static_cast<TimerObj*>(pJS_TimerObj->GetEmbedObject());
dsinclair2eb7c7d2016-08-18 09:58:19 -0700528 pTimerObj->SetTimer(timerRef);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700529
Dan Sinclaire4974922017-10-24 09:36:16 -0400530 vRet = CJS_Value(pRetObj);
tsepez4cf55152016-11-02 14:37:54 -0700531 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700532}
533
Tom Sepezb1670b52017-02-16 17:01:00 -0800534bool app::setTimeOut(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700535 const std::vector<CJS_Value>& params,
536 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -0400537 WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700538 if (params.size() > 2 || params.size() == 0) {
tsepezcd5dc852016-09-08 11:23:24 -0700539 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);
tsepez4cf55152016-11-02 14:37:54 -0700540 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700541 }
Tom Sepezc6ab1722015-02-05 15:27:25 -0800542
Dan Sinclair1b2a18e2017-10-24 13:56:29 -0400543 WideString script = pRuntime->ToWideString(params[0].ToV8Value());
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700544 if (script.IsEmpty()) {
tsepezcd5dc852016-09-08 11:23:24 -0700545 sError = JSGetStringFromID(IDS_STRING_JSAFNUMBER_KEYSTROKE);
tsepez4cf55152016-11-02 14:37:54 -0700546 return true;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700547 }
548
Dan Sinclair1b2a18e2017-10-24 13:56:29 -0400549 uint32_t dwTimeOut =
550 params.size() > 1 ? pRuntime->ToInt32(params[1].ToV8Value()) : 1000;
tsepeza752edf2016-08-19 14:57:42 -0700551 GlobalTimer* timerRef =
dsinclair82e17672016-10-11 12:38:01 -0700552 new GlobalTimer(this, pRuntime->GetFormFillEnv(), pRuntime, 1, script,
553 dwTimeOut, dwTimeOut);
tsepeza752edf2016-08-19 14:57:42 -0700554 m_Timers.insert(std::unique_ptr<GlobalTimer>(timerRef));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700555
tsepezb4694242016-08-15 16:44:55 -0700556 v8::Local<v8::Object> pRetObj =
557 pRuntime->NewFxDynamicObj(CJS_TimerObj::g_nObjDefnID);
Tom Sepezc5a14722017-02-24 15:31:12 -0800558 if (pRetObj.IsEmpty())
559 return false;
tsepez41a53ad2016-03-28 16:59:30 -0700560
tsepezb4694242016-08-15 16:44:55 -0700561 CJS_TimerObj* pJS_TimerObj =
562 static_cast<CJS_TimerObj*>(pRuntime->GetObjectPrivate(pRetObj));
tsepez41a53ad2016-03-28 16:59:30 -0700563 TimerObj* pTimerObj = static_cast<TimerObj*>(pJS_TimerObj->GetEmbedObject());
dsinclair2eb7c7d2016-08-18 09:58:19 -0700564 pTimerObj->SetTimer(timerRef);
Dan Sinclaire4974922017-10-24 09:36:16 -0400565 vRet = CJS_Value(pRetObj);
tsepez4cf55152016-11-02 14:37:54 -0700566 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700567}
568
Tom Sepezb1670b52017-02-16 17:01:00 -0800569bool app::clearTimeOut(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700570 const std::vector<CJS_Value>& params,
571 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -0400572 WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700573 if (params.size() != 1) {
tsepezcd5dc852016-09-08 11:23:24 -0700574 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);
tsepez4cf55152016-11-02 14:37:54 -0700575 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700576 }
577
Tom Sepezb1670b52017-02-16 17:01:00 -0800578 app::ClearTimerCommon(pRuntime, params[0]);
tsepez4cf55152016-11-02 14:37:54 -0700579 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700580}
581
Tom Sepezb1670b52017-02-16 17:01:00 -0800582bool app::clearInterval(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700583 const std::vector<CJS_Value>& params,
584 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -0400585 WideString& sError) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700586 if (params.size() != 1) {
tsepezcd5dc852016-09-08 11:23:24 -0700587 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);
tsepez4cf55152016-11-02 14:37:54 -0700588 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700589 }
590
Tom Sepezb1670b52017-02-16 17:01:00 -0800591 app::ClearTimerCommon(pRuntime, params[0]);
tsepez4cf55152016-11-02 14:37:54 -0700592 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700593}
594
tsepezb4694242016-08-15 16:44:55 -0700595void app::ClearTimerCommon(CJS_Runtime* pRuntime, const CJS_Value& param) {
Dan Sinclair3cac3602017-10-24 15:15:27 -0400596 if (!param.ToV8Value()->IsObject())
tsepez41a53ad2016-03-28 16:59:30 -0700597 return;
598
Dan Sinclair1b2a18e2017-10-24 13:56:29 -0400599 v8::Local<v8::Object> pObj = pRuntime->ToObject(param.ToV8Value());
tsepezb4694242016-08-15 16:44:55 -0700600 if (CFXJS_Engine::GetObjDefnID(pObj) != CJS_TimerObj::g_nObjDefnID)
tsepez41a53ad2016-03-28 16:59:30 -0700601 return;
602
Dan Sinclair1b2a18e2017-10-24 13:56:29 -0400603 CJS_Object* pJSObj =
604 static_cast<CJS_Object*>(pRuntime->GetObjectPrivate(pObj));
tsepez41a53ad2016-03-28 16:59:30 -0700605 if (!pJSObj)
606 return;
607
608 TimerObj* pTimerObj = static_cast<TimerObj*>(pJSObj->GetEmbedObject());
609 if (!pTimerObj)
610 return;
611
tsepeze3ff76b2016-08-08 11:58:47 -0700612 GlobalTimer::Cancel(pTimerObj->GetTimerID());
tsepez41a53ad2016-03-28 16:59:30 -0700613}
614
Tom Sepezb1670b52017-02-16 17:01:00 -0800615bool app::execMenuItem(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700616 const std::vector<CJS_Value>& params,
617 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -0400618 WideString& sError) {
tsepez4cf55152016-11-02 14:37:54 -0700619 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700620}
621
tsepeze3ff76b2016-08-08 11:58:47 -0700622void app::TimerProc(GlobalTimer* pTimer) {
Lei Zhang2d5a0e12015-10-05 17:00:03 -0700623 CJS_Runtime* pRuntime = pTimer->GetRuntime();
tsepez8ca63de2016-08-05 17:12:27 -0700624 if (pRuntime && (!pTimer->IsOneShot() || pTimer->GetTimeOut() > 0))
625 RunJsScript(pRuntime, pTimer->GetJScript());
626}
Lei Zhang2d5a0e12015-10-05 17:00:03 -0700627
tsepeze3ff76b2016-08-08 11:58:47 -0700628void app::CancelProc(GlobalTimer* pTimer) {
tsepeza752edf2016-08-19 14:57:42 -0700629 m_Timers.erase(pdfium::FakeUniquePtr<GlobalTimer>(pTimer));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700630}
631
Ryan Harrison275e2602017-09-18 14:23:18 -0400632void app::RunJsScript(CJS_Runtime* pRuntime, const WideString& wsScript) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700633 if (!pRuntime->IsBlocking()) {
Tom Sepezd6ae2af2017-02-16 11:49:55 -0800634 IJS_EventContext* pContext = pRuntime->NewEventContext();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700635 pContext->OnExternal_Exec();
Ryan Harrison275e2602017-09-18 14:23:18 -0400636 WideString wtInfo;
Tom Sepez33420902015-10-13 15:00:10 -0700637 pContext->RunScript(wsScript, &wtInfo);
Tom Sepezd6ae2af2017-02-16 11:49:55 -0800638 pRuntime->ReleaseEventContext(pContext);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700639 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700640}
641
Tom Sepezb1670b52017-02-16 17:01:00 -0800642bool app::goBack(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700643 const std::vector<CJS_Value>& params,
644 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -0400645 WideString& sError) {
tsepez4cf55152016-11-02 14:37:54 -0700646 // Not supported.
647 return true;
648}
649
Tom Sepezb1670b52017-02-16 17:01:00 -0800650bool app::goForward(CJS_Runtime* pRuntime,
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,
Ryan Harrison275e2602017-09-18 14:23:18 -0400653 WideString& sError) {
Tom Sepezc6ab1722015-02-05 15:27:25 -0800654 // Not supported.
tsepez4cf55152016-11-02 14:37:54 -0700655 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700656}
657
Tom Sepezb1670b52017-02-16 17:01:00 -0800658bool app::mailMsg(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700659 const std::vector<CJS_Value>& params,
660 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -0400661 WideString& sError) {
Tom Sepeze5fbd7a2016-01-29 17:05:08 -0800662 std::vector<CJS_Value> newParams =
Dan Sinclairc9708952017-10-23 09:40:59 -0400663 ExpandKeywordParams(pRuntime, params, 6, L"bUI", L"cTo", L"cCc", L"cBcc",
664 L"cSubject", L"cMsg");
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700665
Dan Sinclair3cac3602017-10-24 15:15:27 -0400666 if (!IsTypeKnown(newParams[0].ToV8Value())) {
tsepezcd5dc852016-09-08 11:23:24 -0700667 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);
tsepez4cf55152016-11-02 14:37:54 -0700668 return false;
Tom Sepeze5fbd7a2016-01-29 17:05:08 -0800669 }
Dan Sinclair1b2a18e2017-10-24 13:56:29 -0400670 bool bUI = pRuntime->ToBoolean(newParams[0].ToV8Value());
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700671
Ryan Harrison275e2602017-09-18 14:23:18 -0400672 WideString cTo;
Dan Sinclair3cac3602017-10-24 15:15:27 -0400673 if (IsTypeKnown(newParams[1].ToV8Value())) {
Dan Sinclair1b2a18e2017-10-24 13:56:29 -0400674 cTo = pRuntime->ToWideString(newParams[1].ToV8Value());
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700675 } else {
Tom Sepeze5fbd7a2016-01-29 17:05:08 -0800676 if (!bUI) {
677 // cTo parameter required when UI not invoked.
tsepezcd5dc852016-09-08 11:23:24 -0700678 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);
tsepez4cf55152016-11-02 14:37:54 -0700679 return false;
Tom Sepeze5fbd7a2016-01-29 17:05:08 -0800680 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700681 }
Tom Sepezc6ab1722015-02-05 15:27:25 -0800682
Ryan Harrison275e2602017-09-18 14:23:18 -0400683 WideString cCc;
Dan Sinclair3cac3602017-10-24 15:15:27 -0400684 if (IsTypeKnown(newParams[2].ToV8Value()))
Dan Sinclair1b2a18e2017-10-24 13:56:29 -0400685 cCc = pRuntime->ToWideString(newParams[2].ToV8Value());
Tom Sepeze5fbd7a2016-01-29 17:05:08 -0800686
Ryan Harrison275e2602017-09-18 14:23:18 -0400687 WideString cBcc;
Dan Sinclair3cac3602017-10-24 15:15:27 -0400688 if (IsTypeKnown(newParams[3].ToV8Value()))
Dan Sinclair1b2a18e2017-10-24 13:56:29 -0400689 cBcc = pRuntime->ToWideString(newParams[3].ToV8Value());
Tom Sepeze5fbd7a2016-01-29 17:05:08 -0800690
Ryan Harrison275e2602017-09-18 14:23:18 -0400691 WideString cSubject;
Dan Sinclair3cac3602017-10-24 15:15:27 -0400692 if (IsTypeKnown(newParams[4].ToV8Value()))
Dan Sinclair1b2a18e2017-10-24 13:56:29 -0400693 cSubject = pRuntime->ToWideString(newParams[4].ToV8Value());
Tom Sepeze5fbd7a2016-01-29 17:05:08 -0800694
Ryan Harrison275e2602017-09-18 14:23:18 -0400695 WideString cMsg;
Dan Sinclair3cac3602017-10-24 15:15:27 -0400696 if (IsTypeKnown(newParams[5].ToV8Value()))
Dan Sinclair1b2a18e2017-10-24 13:56:29 -0400697 cMsg = pRuntime->ToWideString(newParams[5].ToV8Value());
Tom Sepeze5fbd7a2016-01-29 17:05:08 -0800698
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700699 pRuntime->BeginBlock();
Tom Sepezb1670b52017-02-16 17:01:00 -0800700 pRuntime->GetFormFillEnv()->JS_docmailForm(nullptr, 0, bUI, cTo.c_str(),
dsinclair4526faf2016-10-11 10:54:49 -0700701 cSubject.c_str(), cCc.c_str(),
702 cBcc.c_str(), cMsg.c_str());
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700703 pRuntime->EndBlock();
tsepez4cf55152016-11-02 14:37:54 -0700704 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700705}
706
Tom Sepezb1670b52017-02-16 17:01:00 -0800707bool app::launchURL(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700708 const std::vector<CJS_Value>& params,
709 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -0400710 WideString& sError) {
Tom Sepezc6ab1722015-02-05 15:27:25 -0800711 // Unsafe, not supported.
tsepez4cf55152016-11-02 14:37:54 -0700712 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700713}
714
dan sinclaircbe23db2017-10-19 14:29:33 -0400715bool app::get_runtime_highlight(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400716 CJS_Value* vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400717 WideString* sError) {
Dan Sinclaire4974922017-10-24 09:36:16 -0400718 vp->Set(pRuntime->NewBoolean(m_bRuntimeHighLight));
tsepez4cf55152016-11-02 14:37:54 -0700719 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700720}
721
dan sinclaircbe23db2017-10-19 14:29:33 -0400722bool app::set_runtime_highlight(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400723 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400724 WideString* sError) {
Dan Sinclair1b2a18e2017-10-24 13:56:29 -0400725 m_bRuntimeHighLight = pRuntime->ToBoolean(vp.ToV8Value());
dan sinclaircbe23db2017-10-19 14:29:33 -0400726 return true;
727}
728
729bool app::get_fullscreen(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400730 CJS_Value* vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400731 WideString* sError) {
732 return false;
733}
734
735bool app::set_fullscreen(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400736 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400737 WideString* sError) {
tsepez4cf55152016-11-02 14:37:54 -0700738 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700739}
740
Tom Sepezb1670b52017-02-16 17:01:00 -0800741bool app::popUpMenu(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700742 const std::vector<CJS_Value>& params,
743 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -0400744 WideString& sError) {
tsepez4cf55152016-11-02 14:37:54 -0700745 return false;
746}
747
Tom Sepezb1670b52017-02-16 17:01:00 -0800748bool app::browseForDoc(CJS_Runtime* pRuntime,
Lei Zhang945fdb72015-11-11 10:18:16 -0800749 const std::vector<CJS_Value>& params,
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700750 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -0400751 WideString& sError) {
Tom Sepezc6ab1722015-02-05 15:27:25 -0800752 // Unsafe, not supported.
tsepez4cf55152016-11-02 14:37:54 -0700753 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700754}
755
Ryan Harrison275e2602017-09-18 14:23:18 -0400756WideString app::SysPathToPDFPath(const WideString& sOldPath) {
757 WideString sRet = L"/";
Tom Sepez3c3e2712017-04-17 15:38:19 -0700758 for (const wchar_t& c : sOldPath) {
759 if (c != L':')
760 sRet += (c == L'\\') ? L'/' : c;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700761 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700762 return sRet;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700763}
764
Tom Sepezb1670b52017-02-16 17:01:00 -0800765bool app::newDoc(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700766 const std::vector<CJS_Value>& params,
767 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -0400768 WideString& sError) {
tsepez4cf55152016-11-02 14:37:54 -0700769 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700770}
771
Tom Sepezb1670b52017-02-16 17:01:00 -0800772bool app::openDoc(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700773 const std::vector<CJS_Value>& params,
774 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -0400775 WideString& sError) {
tsepez4cf55152016-11-02 14:37:54 -0700776 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700777}
778
Tom Sepezb1670b52017-02-16 17:01:00 -0800779bool app::response(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700780 const std::vector<CJS_Value>& params,
781 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -0400782 WideString& sError) {
Tom Sepez58fb36a2016-02-01 10:32:14 -0800783 std::vector<CJS_Value> newParams =
Dan Sinclairc9708952017-10-23 09:40:59 -0400784 ExpandKeywordParams(pRuntime, params, 5, L"cQuestion", L"cTitle",
785 L"cDefault", L"bPassword", L"cLabel");
Tom Sepez621d4de2014-07-29 14:01:21 -0700786
Dan Sinclair3cac3602017-10-24 15:15:27 -0400787 if (!IsTypeKnown(newParams[0].ToV8Value())) {
tsepezcd5dc852016-09-08 11:23:24 -0700788 sError = JSGetStringFromID(IDS_STRING_JSPARAMERROR);
tsepez4cf55152016-11-02 14:37:54 -0700789 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700790 }
Dan Sinclair1b2a18e2017-10-24 13:56:29 -0400791 WideString swQuestion = pRuntime->ToWideString(newParams[0].ToV8Value());
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700792
Ryan Harrison275e2602017-09-18 14:23:18 -0400793 WideString swTitle = L"PDF";
Dan Sinclair3cac3602017-10-24 15:15:27 -0400794 if (IsTypeKnown(newParams[1].ToV8Value()))
Dan Sinclair1b2a18e2017-10-24 13:56:29 -0400795 swTitle = pRuntime->ToWideString(newParams[1].ToV8Value());
Tom Sepez58fb36a2016-02-01 10:32:14 -0800796
Ryan Harrison275e2602017-09-18 14:23:18 -0400797 WideString swDefault;
Dan Sinclair3cac3602017-10-24 15:15:27 -0400798 if (IsTypeKnown(newParams[2].ToV8Value()))
Dan Sinclair1b2a18e2017-10-24 13:56:29 -0400799 swDefault = pRuntime->ToWideString(newParams[2].ToV8Value());
Tom Sepez58fb36a2016-02-01 10:32:14 -0800800
801 bool bPassword = false;
Dan Sinclair3cac3602017-10-24 15:15:27 -0400802 if (IsTypeKnown(newParams[3].ToV8Value()))
Dan Sinclair1b2a18e2017-10-24 13:56:29 -0400803 bPassword = pRuntime->ToBoolean(newParams[3].ToV8Value());
Tom Sepez58fb36a2016-02-01 10:32:14 -0800804
Ryan Harrison275e2602017-09-18 14:23:18 -0400805 WideString swLabel;
Dan Sinclair3cac3602017-10-24 15:15:27 -0400806 if (IsTypeKnown(newParams[4].ToV8Value()))
Dan Sinclair1b2a18e2017-10-24 13:56:29 -0400807 swLabel = pRuntime->ToWideString(newParams[4].ToV8Value());
Tom Sepez621d4de2014-07-29 14:01:21 -0700808
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700809 const int MAX_INPUT_BYTES = 2048;
Tom Sepezd7188f72017-05-02 15:10:58 -0700810 std::vector<uint8_t> pBuff(MAX_INPUT_BYTES + 2);
Tom Sepezb1670b52017-02-16 17:01:00 -0800811 int nLengthBytes = pRuntime->GetFormFillEnv()->JS_appResponse(
Lei Zhangdb5256f2015-10-02 10:11:43 -0700812 swQuestion.c_str(), swTitle.c_str(), swDefault.c_str(), swLabel.c_str(),
Tom Sepezd7188f72017-05-02 15:10:58 -0700813 bPassword, pBuff.data(), MAX_INPUT_BYTES);
Tom Sepez58fb36a2016-02-01 10:32:14 -0800814
815 if (nLengthBytes < 0 || nLengthBytes > MAX_INPUT_BYTES) {
tsepezcd5dc852016-09-08 11:23:24 -0700816 sError = JSGetStringFromID(IDS_STRING_JSPARAM_TOOLONG);
tsepez4cf55152016-11-02 14:37:54 -0700817 return false;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700818 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700819
Dan Sinclair1d8d9ac2017-10-24 11:23:25 -0400820 vRet = CJS_Value(pRuntime->NewString(
821 WideString::FromUTF16LE(reinterpret_cast<uint16_t*>(pBuff.data()),
822 nLengthBytes / sizeof(uint16_t))
823 .c_str()));
tsepezf3dc8c62016-08-10 06:29:29 -0700824
tsepez4cf55152016-11-02 14:37:54 -0700825 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700826}
827
Dan Sinclair33d13f22017-10-23 09:44:30 -0400828bool app::get_media(CJS_Runtime* pRuntime, CJS_Value* vp, WideString* sError) {
dan sinclaircbe23db2017-10-19 14:29:33 -0400829 return false;
830}
831
832bool app::set_media(CJS_Runtime* pRuntime,
Dan Sinclair33d13f22017-10-23 09:44:30 -0400833 const CJS_Value& vp,
dan sinclaircbe23db2017-10-19 14:29:33 -0400834 WideString* sError) {
tsepez4cf55152016-11-02 14:37:54 -0700835 return false;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700836}
837
Tom Sepezb1670b52017-02-16 17:01:00 -0800838bool app::execDialog(CJS_Runtime* pRuntime,
tsepez4cf55152016-11-02 14:37:54 -0700839 const std::vector<CJS_Value>& params,
840 CJS_Value& vRet,
Ryan Harrison275e2602017-09-18 14:23:18 -0400841 WideString& sError) {
tsepez4cf55152016-11-02 14:37:54 -0700842 return true;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700843}