blob: 4aab9afb1446921a1c3d9faee684e93e7e05d630 [file] [log] [blame]
K. Moon832a6942022-10-31 20:11:31 +00001// Copyright 2014 The PDFium Authors
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07002// 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 Sinclaire0345a42017-10-30 20:20:42 +00007#include "fxjs/cjs_app.h"
Tom Sepez37458412015-10-06 11:33:46 -07008
Lei Zhang2810c832022-08-16 18:45:22 +00009#include <stdint.h>
10
Lei Zhangcd3d3792022-09-28 17:22:04 +000011#include <algorithm>
Lei Zhang96c95172018-05-22 21:59:00 +000012#include <utility>
13
Tom Sepezcc81d112024-01-19 22:35:28 +000014#include "core/fxcrt/fixed_size_data_vector.h"
Lei Zhang37935952024-02-16 04:39:56 +000015#include "core/fxcrt/span.h"
Lei Zhang549fe5d2021-06-18 23:46:09 +000016#include "core/fxcrt/stl_util.h"
Tom Sepeze2acc372021-08-17 22:32:53 +000017#include "fpdfsdk/cpdfsdk_formfillenvironment.h"
Lei Zhangc3450652018-10-11 16:54:42 +000018#include "fpdfsdk/cpdfsdk_interactiveform.h"
Dan Sinclaire0345a42017-10-30 20:20:42 +000019#include "fxjs/cjs_document.h"
20#include "fxjs/cjs_timerobj.h"
21#include "fxjs/global_timer.h"
22#include "fxjs/ijs_event_context.h"
23#include "fxjs/js_resources.h"
Dan Elphick05673a32021-09-09 15:42:55 +000024#include "v8/include/v8-container.h"
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070025
Tom Sepez40d12fb2021-07-28 17:45:00 +000026namespace {
27
28constexpr wchar_t kStrViewerType[] = L"pdfium";
29constexpr wchar_t kStrViewerVariation[] = L"Full";
30constexpr wchar_t kStrPlatform[] = L"WIN";
31constexpr wchar_t kStrLanguage[] = L"ENU";
32constexpr int kNumViewerVersion = 8;
33constexpr int kNumViewerVersionXfa = 11;
34constexpr int kNumFormsVersion = 7;
35
36} // namespace
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070037
Dan Sinclairc94a7932017-10-26 16:48:57 -040038const JSPropertySpec CJS_App::PropertySpecs[] = {
dan sinclaircbe23db2017-10-19 14:29:33 -040039 {"activeDocs", get_active_docs_static, set_active_docs_static},
Tom Sepez4d5b8c52017-02-21 15:17:07 -080040 {"calculate", get_calculate_static, set_calculate_static},
dan sinclaircbe23db2017-10-19 14:29:33 -040041 {"formsVersion", get_forms_version_static, set_forms_version_static},
Tom Sepez4d5b8c52017-02-21 15:17:07 -080042 {"fs", get_fs_static, set_fs_static},
43 {"fullscreen", get_fullscreen_static, set_fullscreen_static},
44 {"language", get_language_static, set_language_static},
45 {"media", get_media_static, set_media_static},
46 {"platform", get_platform_static, set_platform_static},
dan sinclaircbe23db2017-10-19 14:29:33 -040047 {"runtimeHighlight", get_runtime_highlight_static,
48 set_runtime_highlight_static},
49 {"viewerType", get_viewer_type_static, set_viewer_type_static},
50 {"viewerVariation", get_viewer_variation_static,
51 set_viewer_variation_static},
Dan Sinclair909fa2d2017-12-12 01:53:28 +000052 {"viewerVersion", get_viewer_version_static, set_viewer_version_static}};
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070053
Dan Sinclairc94a7932017-10-26 16:48:57 -040054const JSMethodSpec CJS_App::MethodSpecs[] = {
55 {"alert", alert_static},
56 {"beep", beep_static},
57 {"browseForDoc", browseForDoc_static},
58 {"clearInterval", clearInterval_static},
59 {"clearTimeOut", clearTimeOut_static},
60 {"execDialog", execDialog_static},
61 {"execMenuItem", execMenuItem_static},
62 {"findComponent", findComponent_static},
63 {"goBack", goBack_static},
64 {"goForward", goForward_static},
65 {"launchURL", launchURL_static},
66 {"mailMsg", mailMsg_static},
67 {"newFDF", newFDF_static},
68 {"newDoc", newDoc_static},
69 {"openDoc", openDoc_static},
70 {"openFDF", openFDF_static},
71 {"popUpMenuEx", popUpMenuEx_static},
72 {"popUpMenu", popUpMenu_static},
73 {"response", response_static},
74 {"setInterval", setInterval_static},
Dan Sinclair909fa2d2017-12-12 01:53:28 +000075 {"setTimeOut", setTimeOut_static}};
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070076
Tom Sepezb4958712020-10-13 20:30:43 +000077uint32_t CJS_App::ObjDefnID = 0;
Dan Sinclair89d26c82017-10-26 12:21:28 -040078
Dan Sinclairf7435522018-02-05 22:27:22 +000079const char CJS_App::kName[] = "app";
80
Dan Sinclairef299532017-10-26 16:48:30 -040081// static
Tom Sepezb4958712020-10-13 20:30:43 +000082uint32_t CJS_App::GetObjDefnID() {
Lei Zhangad1f7b42018-07-11 13:04:43 +000083 return ObjDefnID;
84}
85
86// static
Dan Sinclairbef4d3e2017-10-26 16:49:38 -040087void CJS_App::DefineJSObjects(CFXJS_Engine* pEngine) {
Dan Sinclairf7435522018-02-05 22:27:22 +000088 ObjDefnID = pEngine->DefineObj(CJS_App::kName, FXJSOBJTYPE_STATIC,
Dan Sinclair998fee32018-02-05 21:43:19 +000089 JSConstructor<CJS_App>, JSDestructor);
Tom Sepez8b4ddeb2018-06-11 15:55:17 +000090 DefineProps(pEngine, ObjDefnID, PropertySpecs);
91 DefineMethods(pEngine, ObjDefnID, MethodSpecs);
Dan Sinclair89d26c82017-10-26 12:21:28 -040092}
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070093
Tom Sepez36aae4f2018-06-04 19:44:37 +000094CJS_App::CJS_App(v8::Local<v8::Object> pObject, CJS_Runtime* pRuntime)
95 : CJS_Object(pObject, pRuntime) {}
Dan Sinclair998fee32018-02-05 21:43:19 +000096
Dan Sinclairf7435522018-02-05 22:27:22 +000097CJS_App::~CJS_App() = default;
Nico Weber9d8ec5a2015-08-04 13:00:21 -070098
Tom Sepez3a6d0582018-08-17 19:28:52 +000099CJS_Result CJS_App::get_active_docs(CJS_Runtime* pRuntime) {
dsinclair82e17672016-10-11 12:38:01 -0700100 v8::Local<v8::Object> pObj = pRuntime->GetThisObj();
Daniel Hosseinianb6a909b2021-10-22 18:21:53 +0000101 auto pJSDocument = JSGetObject<CJS_Document>(pRuntime->GetIsolate(), pObj);
Lei Zhang15c0b1e2019-03-05 19:54:16 +0000102 if (!pJSDocument)
103 return CJS_Result::Failure(JSMessage::kObjectTypeError);
Dan Sinclair3a1ba8e2017-10-26 09:28:59 -0400104 v8::Local<v8::Array> aDocs = pRuntime->NewArray();
Lei Zhang15c0b1e2019-03-05 19:54:16 +0000105 pRuntime->PutArrayElement(aDocs, 0, pJSDocument->ToV8Object());
Dan Sinclair3a1ba8e2017-10-26 09:28:59 -0400106 if (pRuntime->GetArrayLength(aDocs) > 0)
Tom Sepez3a6d0582018-08-17 19:28:52 +0000107 return CJS_Result::Success(aDocs);
Tom Sepez20736f72018-08-17 16:44:50 +0000108
Tom Sepez3a6d0582018-08-17 19:28:52 +0000109 return CJS_Result::Success(pRuntime->NewUndefined());
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700110}
111
Tom Sepez3a6d0582018-08-17 19:28:52 +0000112CJS_Result CJS_App::set_active_docs(CJS_Runtime* pRuntime,
Dan Sinclairf7435522018-02-05 22:27:22 +0000113 v8::Local<v8::Value> vp) {
Tom Sepez3a6d0582018-08-17 19:28:52 +0000114 return CJS_Result::Failure(JSMessage::kNotSupportedError);
dan sinclaircbe23db2017-10-19 14:29:33 -0400115}
116
Tom Sepez3a6d0582018-08-17 19:28:52 +0000117CJS_Result CJS_App::get_calculate(CJS_Runtime* pRuntime) {
118 return CJS_Result::Success(pRuntime->NewBoolean(m_bCalculate));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700119}
120
Tom Sepez3a6d0582018-08-17 19:28:52 +0000121CJS_Result CJS_App::set_calculate(CJS_Runtime* pRuntime,
Dan Sinclairf7435522018-02-05 22:27:22 +0000122 v8::Local<v8::Value> vp) {
dan sinclair80435cb2017-10-24 21:40:24 -0400123 m_bCalculate = pRuntime->ToBoolean(vp);
Lei Zhang073ecf42018-10-11 16:56:00 +0000124 pRuntime->GetFormFillEnv()->GetInteractiveForm()->EnableCalculate(
125 m_bCalculate);
Tom Sepez3a6d0582018-08-17 19:28:52 +0000126 return CJS_Result::Success();
dan sinclaircbe23db2017-10-19 14:29:33 -0400127}
tsepez4cf55152016-11-02 14:37:54 -0700128
Tom Sepez3a6d0582018-08-17 19:28:52 +0000129CJS_Result CJS_App::get_forms_version(CJS_Runtime* pRuntime) {
Tom Sepez40d12fb2021-07-28 17:45:00 +0000130 return CJS_Result::Success(pRuntime->NewNumber(kNumFormsVersion));
dan sinclaircbe23db2017-10-19 14:29:33 -0400131}
132
Tom Sepez3a6d0582018-08-17 19:28:52 +0000133CJS_Result CJS_App::set_forms_version(CJS_Runtime* pRuntime,
Dan Sinclairf7435522018-02-05 22:27:22 +0000134 v8::Local<v8::Value> vp) {
Tom Sepez3a6d0582018-08-17 19:28:52 +0000135 return CJS_Result::Failure(JSMessage::kNotSupportedError);
tsepez4cf55152016-11-02 14:37:54 -0700136}
137
Tom Sepez3a6d0582018-08-17 19:28:52 +0000138CJS_Result CJS_App::get_viewer_type(CJS_Runtime* pRuntime) {
Tom Sepez40d12fb2021-07-28 17:45:00 +0000139 return CJS_Result::Success(pRuntime->NewString(kStrViewerType));
dan sinclaircbe23db2017-10-19 14:29:33 -0400140}
tsepez4cf55152016-11-02 14:37:54 -0700141
Tom Sepez3a6d0582018-08-17 19:28:52 +0000142CJS_Result CJS_App::set_viewer_type(CJS_Runtime* pRuntime,
Dan Sinclairf7435522018-02-05 22:27:22 +0000143 v8::Local<v8::Value> vp) {
Tom Sepez3a6d0582018-08-17 19:28:52 +0000144 return CJS_Result::Failure(JSMessage::kNotSupportedError);
tsepez4cf55152016-11-02 14:37:54 -0700145}
146
Tom Sepez3a6d0582018-08-17 19:28:52 +0000147CJS_Result CJS_App::get_viewer_variation(CJS_Runtime* pRuntime) {
Tom Sepez40d12fb2021-07-28 17:45:00 +0000148 return CJS_Result::Success(pRuntime->NewString(kStrViewerVariation));
dan sinclaircbe23db2017-10-19 14:29:33 -0400149}
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700150
Tom Sepez3a6d0582018-08-17 19:28:52 +0000151CJS_Result CJS_App::set_viewer_variation(CJS_Runtime* pRuntime,
Dan Sinclairf7435522018-02-05 22:27:22 +0000152 v8::Local<v8::Value> vp) {
Tom Sepez3a6d0582018-08-17 19:28:52 +0000153 return CJS_Result::Failure(JSMessage::kNotSupportedError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700154}
155
Tom Sepez3a6d0582018-08-17 19:28:52 +0000156CJS_Result CJS_App::get_viewer_version(CJS_Runtime* pRuntime) {
Tom Sepezd48bd292019-08-14 19:48:55 +0000157 CPDF_Document::Extension* pContext =
158 pRuntime->GetFormFillEnv()->GetDocExtension();
159 int version = pContext && pContext->ContainsExtensionForm()
Tom Sepez40d12fb2021-07-28 17:45:00 +0000160 ? kNumViewerVersionXfa
161 : kNumViewerVersion;
Tom Sepezd48bd292019-08-14 19:48:55 +0000162 return CJS_Result::Success(pRuntime->NewNumber(version));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700163}
164
Tom Sepez3a6d0582018-08-17 19:28:52 +0000165CJS_Result CJS_App::set_viewer_version(CJS_Runtime* pRuntime,
Dan Sinclairf7435522018-02-05 22:27:22 +0000166 v8::Local<v8::Value> vp) {
Tom Sepez3a6d0582018-08-17 19:28:52 +0000167 return CJS_Result::Failure(JSMessage::kNotSupportedError);
dan sinclaircbe23db2017-10-19 14:29:33 -0400168}
169
Tom Sepez3a6d0582018-08-17 19:28:52 +0000170CJS_Result CJS_App::get_platform(CJS_Runtime* pRuntime) {
Tom Sepezb1670b52017-02-16 17:01:00 -0800171 CPDFSDK_FormFillEnvironment* pFormFillEnv = pRuntime->GetFormFillEnv();
Tom Sepezd48bd292019-08-14 19:48:55 +0000172 if (pFormFillEnv) {
173 WideString platform = pFormFillEnv->GetPlatform();
174 if (!platform.IsEmpty())
175 return CJS_Result::Success(pRuntime->NewString(platform.AsStringView()));
176 }
Tom Sepez40d12fb2021-07-28 17:45:00 +0000177 return CJS_Result::Success(pRuntime->NewString(kStrPlatform));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700178}
179
Tom Sepez3a6d0582018-08-17 19:28:52 +0000180CJS_Result CJS_App::set_platform(CJS_Runtime* pRuntime,
Dan Sinclairf7435522018-02-05 22:27:22 +0000181 v8::Local<v8::Value> vp) {
Tom Sepez3a6d0582018-08-17 19:28:52 +0000182 return CJS_Result::Failure(JSMessage::kNotSupportedError);
dan sinclaircbe23db2017-10-19 14:29:33 -0400183}
184
Tom Sepez3a6d0582018-08-17 19:28:52 +0000185CJS_Result CJS_App::get_language(CJS_Runtime* pRuntime) {
Tom Sepezb1670b52017-02-16 17:01:00 -0800186 CPDFSDK_FormFillEnvironment* pFormFillEnv = pRuntime->GetFormFillEnv();
Tom Sepezd48bd292019-08-14 19:48:55 +0000187 if (pFormFillEnv) {
188 WideString language = pFormFillEnv->GetLanguage();
189 if (!language.IsEmpty())
190 return CJS_Result::Success(pRuntime->NewString(language.AsStringView()));
191 }
Tom Sepez40d12fb2021-07-28 17:45:00 +0000192 return CJS_Result::Success(pRuntime->NewString(kStrLanguage));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700193}
194
Tom Sepez3a6d0582018-08-17 19:28:52 +0000195CJS_Result CJS_App::set_language(CJS_Runtime* pRuntime,
Dan Sinclairf7435522018-02-05 22:27:22 +0000196 v8::Local<v8::Value> vp) {
Tom Sepez3a6d0582018-08-17 19:28:52 +0000197 return CJS_Result::Failure(JSMessage::kNotSupportedError);
dan sinclaircbe23db2017-10-19 14:29:33 -0400198}
199
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700200// creates a new fdf object that contains no data
201// comment: need reader support
202// note:
dsinclair735606d2016-10-05 15:47:02 -0700203// CFDF_Document * CPDFSDK_FormFillEnvironment::NewFDF();
Tom Sepez3a6d0582018-08-17 19:28:52 +0000204CJS_Result CJS_App::newFDF(CJS_Runtime* pRuntime,
Tom Sepez90589d42023-11-01 18:24:30 +0000205 pdfium::span<v8::Local<v8::Value>> params) {
Tom Sepez3a6d0582018-08-17 19:28:52 +0000206 return CJS_Result::Success();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700207}
Dan Sinclair8f524d62017-10-25 13:30:31 -0400208
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700209// opens a specified pdf document and returns its document object
210// comment:need reader support
211// note: as defined in js reference, the proto of this function's fourth
212// parmeters, how old an fdf document while do not show it.
dsinclair735606d2016-10-05 15:47:02 -0700213// CFDF_Document * CPDFSDK_FormFillEnvironment::OpenFDF(string strPath,bool
214// bUserConv);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700215
Tom Sepez3a6d0582018-08-17 19:28:52 +0000216CJS_Result CJS_App::openFDF(CJS_Runtime* pRuntime,
Tom Sepez90589d42023-11-01 18:24:30 +0000217 pdfium::span<v8::Local<v8::Value>> params) {
Tom Sepez3a6d0582018-08-17 19:28:52 +0000218 return CJS_Result::Success();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700219}
220
Tom Sepez3a6d0582018-08-17 19:28:52 +0000221CJS_Result CJS_App::alert(CJS_Runtime* pRuntime,
Tom Sepez90589d42023-11-01 18:24:30 +0000222 pdfium::span<v8::Local<v8::Value>> params) {
Tom Sepez0a34b6b2023-11-01 20:16:25 +0000223 v8::LocalVector<v8::Value> newParams = ExpandKeywordParams(
Tom Sepezca610782018-12-13 18:01:04 +0000224 pRuntime, params, 4, "cMsg", "nIcon", "nType", "cTitle");
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700225
Tom Sepez0e5bab12018-10-18 21:39:40 +0000226 if (!IsExpandedParamKnown(newParams[0]))
Tom Sepez3a6d0582018-08-17 19:28:52 +0000227 return CJS_Result::Failure(JSMessage::kParamError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700228
dsinclair82e17672016-10-11 12:38:01 -0700229 CPDFSDK_FormFillEnvironment* pFormFillEnv = pRuntime->GetFormFillEnv();
Dan Sinclair8f524d62017-10-25 13:30:31 -0400230 if (!pFormFillEnv)
Tom Sepez3a6d0582018-08-17 19:28:52 +0000231 return CJS_Result::Success(pRuntime->NewNumber(0));
tsepeze1e7bd02016-08-08 13:03:16 -0700232
Ryan Harrison275e2602017-09-18 14:23:18 -0400233 WideString swMsg;
dan sinclair80435cb2017-10-24 21:40:24 -0400234 if (newParams[0]->IsArray()) {
Dan Sinclair3a1ba8e2017-10-26 09:28:59 -0400235 v8::Local<v8::Array> carray = pRuntime->ToArray(newParams[0]);
Dan Sinclair037eae62017-10-24 15:29:01 -0400236 swMsg = L"[";
Dan Sinclair3a1ba8e2017-10-26 09:28:59 -0400237 for (size_t i = 0; i < pRuntime->GetArrayLength(carray); ++i) {
Dan Sinclair037eae62017-10-24 15:29:01 -0400238 if (i)
239 swMsg += L", ";
Dan Sinclairc9708952017-10-23 09:40:59 -0400240
Dan Sinclair3a1ba8e2017-10-26 09:28:59 -0400241 swMsg += pRuntime->ToWideString(pRuntime->GetArrayElement(carray, i));
Tom Sepezdcbc02f2015-07-17 09:16:17 -0700242 }
Dan Sinclair037eae62017-10-24 15:29:01 -0400243 swMsg += L"]";
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700244 } else {
dan sinclair80435cb2017-10-24 21:40:24 -0400245 swMsg = pRuntime->ToWideString(newParams[0]);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700246 }
247
Ryan Harrisonc3cc2ab2018-06-21 21:09:54 +0000248 int iIcon = JSPLATFORM_ALERT_ICON_DEFAULT;
Tom Sepez0e5bab12018-10-18 21:39:40 +0000249 if (IsExpandedParamKnown(newParams[1]))
dan sinclair80435cb2017-10-24 21:40:24 -0400250 iIcon = pRuntime->ToInt32(newParams[1]);
Tom Sepezbd932572016-01-29 09:10:41 -0800251
Ryan Harrisonc3cc2ab2018-06-21 21:09:54 +0000252 int iType = JSPLATFORM_ALERT_BUTTON_DEFAULT;
Tom Sepez0e5bab12018-10-18 21:39:40 +0000253 if (IsExpandedParamKnown(newParams[2]))
dan sinclair80435cb2017-10-24 21:40:24 -0400254 iType = pRuntime->ToInt32(newParams[2]);
Tom Sepezbd932572016-01-29 09:10:41 -0800255
Ryan Harrison275e2602017-09-18 14:23:18 -0400256 WideString swTitle;
Tom Sepez0e5bab12018-10-18 21:39:40 +0000257 if (IsExpandedParamKnown(newParams[3]))
dan sinclair80435cb2017-10-24 21:40:24 -0400258 swTitle = pRuntime->ToWideString(newParams[3]);
Tom Sepezbd932572016-01-29 09:10:41 -0800259 else
Dan Sinclaird6e9cfa2017-10-30 21:19:42 +0000260 swTitle = JSGetStringFromID(JSMessage::kAlert);
Tom Sepezbd932572016-01-29 09:10:41 -0800261
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700262 pRuntime->BeginBlock();
Tom Sepez6f9e9f62021-08-11 17:01:53 +0000263 pFormFillEnv->KillFocusAnnot({});
Dan Sinclair8f524d62017-10-25 13:30:31 -0400264 v8::Local<v8::Value> ret = pRuntime->NewNumber(
Tom Sepez35939f82018-04-17 21:23:58 +0000265 pFormFillEnv->JS_appAlert(swMsg, swTitle, iType, iIcon));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700266 pRuntime->EndBlock();
Dan Sinclair8f524d62017-10-25 13:30:31 -0400267
Tom Sepez3a6d0582018-08-17 19:28:52 +0000268 return CJS_Result::Success(ret);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700269}
270
Tom Sepez3a6d0582018-08-17 19:28:52 +0000271CJS_Result CJS_App::beep(CJS_Runtime* pRuntime,
Tom Sepez90589d42023-11-01 18:24:30 +0000272 pdfium::span<v8::Local<v8::Value>> params) {
Lei Zhang96c95172018-05-22 21:59:00 +0000273 if (params.size() != 1)
Tom Sepez3a6d0582018-08-17 19:28:52 +0000274 return CJS_Result::Failure(JSMessage::kParamError);
Lei Zhang96c95172018-05-22 21:59:00 +0000275
Ryan Harrisonc3cc2ab2018-06-21 21:09:54 +0000276 int type = JSPLATFORM_BEEP_DEFAULT;
Tom Sepez0e5bab12018-10-18 21:39:40 +0000277 if (IsExpandedParamKnown(params[0]))
Ryan Harrisonc3cc2ab2018-06-21 21:09:54 +0000278 type = pRuntime->ToInt32(params[0]);
279
280 pRuntime->GetFormFillEnv()->JS_appBeep(type);
Tom Sepez3a6d0582018-08-17 19:28:52 +0000281 return CJS_Result::Success();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700282}
283
Tom Sepez90589d42023-11-01 18:24:30 +0000284CJS_Result CJS_App::findComponent(CJS_Runtime* pRuntime,
285 pdfium::span<v8::Local<v8::Value>> params) {
Tom Sepez3a6d0582018-08-17 19:28:52 +0000286 return CJS_Result::Success();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700287}
288
Tom Sepez90589d42023-11-01 18:24:30 +0000289CJS_Result CJS_App::popUpMenuEx(CJS_Runtime* pRuntime,
290 pdfium::span<v8::Local<v8::Value>> params) {
Tom Sepez3a6d0582018-08-17 19:28:52 +0000291 return CJS_Result::Failure(JSMessage::kNotSupportedError);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700292}
293
Tom Sepez3a6d0582018-08-17 19:28:52 +0000294CJS_Result CJS_App::get_fs(CJS_Runtime* pRuntime) {
295 return CJS_Result::Failure(JSMessage::kNotSupportedError);
dan sinclaircbe23db2017-10-19 14:29:33 -0400296}
297
Tom Sepez3a6d0582018-08-17 19:28:52 +0000298CJS_Result CJS_App::set_fs(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp) {
299 return CJS_Result::Failure(JSMessage::kNotSupportedError);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700300}
301
Tom Sepez90589d42023-11-01 18:24:30 +0000302CJS_Result CJS_App::setInterval(CJS_Runtime* pRuntime,
303 pdfium::span<v8::Local<v8::Value>> params) {
Lei Zhang96c95172018-05-22 21:59:00 +0000304 if (params.size() == 0 || params.size() > 2)
Tom Sepez3a6d0582018-08-17 19:28:52 +0000305 return CJS_Result::Failure(JSMessage::kParamError);
Tom Sepezc6ab1722015-02-05 15:27:25 -0800306
Lei Zhang96c95172018-05-22 21:59:00 +0000307 WideString script = pRuntime->ToWideString(params[0]);
Dan Sinclair8f524d62017-10-25 13:30:31 -0400308 if (script.IsEmpty())
Tom Sepez3a6d0582018-08-17 19:28:52 +0000309 return CJS_Result::Failure(JSMessage::kInvalidInputError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700310
dan sinclair80435cb2017-10-24 21:40:24 -0400311 uint32_t dwInterval = params.size() > 1 ? pRuntime->ToInt32(params[1]) : 1000;
Tom Sepez31d722d2020-05-15 22:03:46 +0000312 auto timerRef = std::make_unique<GlobalTimer>(
Tom Sepez24374a62019-08-07 21:26:02 +0000313 this, pRuntime, GlobalTimer::Type::kRepeating, script, dwInterval, 0);
Lei Zhang96c95172018-05-22 21:59:00 +0000314 GlobalTimer* pTimerRef = timerRef.get();
315 m_Timers.insert(std::move(timerRef));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700316
Tom Sepez55ccb522018-08-14 23:40:10 +0000317 v8::Local<v8::Object> pRetObj = pRuntime->NewFXJSBoundObject(
318 CJS_TimerObj::GetObjDefnID(), FXJSOBJTYPE_DYNAMIC);
Tom Sepezc5a14722017-02-24 15:31:12 -0800319 if (pRetObj.IsEmpty())
Tom Sepez3a6d0582018-08-17 19:28:52 +0000320 return CJS_Result::Failure(JSMessage::kBadObjectError);
Tom Sepezc5a14722017-02-24 15:31:12 -0800321
Daniel Hosseinianb6a909b2021-10-22 18:21:53 +0000322 auto* pJS_TimerObj = static_cast<CJS_TimerObj*>(
Tom Sepez07c784b2024-06-06 22:44:54 +0000323 CFXJS_Engine::GetBinding(pRuntime->GetIsolate(), pRetObj));
Tom Sepezddaa40f2018-06-06 18:30:15 +0000324
Lei Zhang96c95172018-05-22 21:59:00 +0000325 pJS_TimerObj->SetTimer(pTimerRef);
Tom Sepez3a6d0582018-08-17 19:28:52 +0000326 return CJS_Result::Success(pRetObj);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700327}
328
Tom Sepez90589d42023-11-01 18:24:30 +0000329CJS_Result CJS_App::setTimeOut(CJS_Runtime* pRuntime,
330 pdfium::span<v8::Local<v8::Value>> params) {
Lei Zhang96c95172018-05-22 21:59:00 +0000331 if (params.size() == 0 || params.size() > 2)
Tom Sepez3a6d0582018-08-17 19:28:52 +0000332 return CJS_Result::Failure(JSMessage::kParamError);
Tom Sepezc6ab1722015-02-05 15:27:25 -0800333
dan sinclair80435cb2017-10-24 21:40:24 -0400334 WideString script = pRuntime->ToWideString(params[0]);
Dan Sinclair8f524d62017-10-25 13:30:31 -0400335 if (script.IsEmpty())
Tom Sepez3a6d0582018-08-17 19:28:52 +0000336 return CJS_Result::Failure(JSMessage::kInvalidInputError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700337
dan sinclair80435cb2017-10-24 21:40:24 -0400338 uint32_t dwTimeOut = params.size() > 1 ? pRuntime->ToInt32(params[1]) : 1000;
Tom Sepez31d722d2020-05-15 22:03:46 +0000339 auto timerRef =
340 std::make_unique<GlobalTimer>(this, pRuntime, GlobalTimer::Type::kOneShot,
341 script, dwTimeOut, dwTimeOut);
Lei Zhang96c95172018-05-22 21:59:00 +0000342 GlobalTimer* pTimerRef = timerRef.get();
343 m_Timers.insert(std::move(timerRef));
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700344
Tom Sepez55ccb522018-08-14 23:40:10 +0000345 v8::Local<v8::Object> pRetObj = pRuntime->NewFXJSBoundObject(
346 CJS_TimerObj::GetObjDefnID(), FXJSOBJTYPE_DYNAMIC);
Tom Sepezc5a14722017-02-24 15:31:12 -0800347 if (pRetObj.IsEmpty())
Tom Sepez3a6d0582018-08-17 19:28:52 +0000348 return CJS_Result::Failure(JSMessage::kBadObjectError);
tsepez41a53ad2016-03-28 16:59:30 -0700349
Daniel Hosseinianb6a909b2021-10-22 18:21:53 +0000350 auto* pJS_TimerObj = static_cast<CJS_TimerObj*>(
Tom Sepez07c784b2024-06-06 22:44:54 +0000351 CFXJS_Engine::GetBinding(pRuntime->GetIsolate(), pRetObj));
Tom Sepezddaa40f2018-06-06 18:30:15 +0000352
Lei Zhang96c95172018-05-22 21:59:00 +0000353 pJS_TimerObj->SetTimer(pTimerRef);
Tom Sepez3a6d0582018-08-17 19:28:52 +0000354 return CJS_Result::Success(pRetObj);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700355}
356
Tom Sepez90589d42023-11-01 18:24:30 +0000357CJS_Result CJS_App::clearTimeOut(CJS_Runtime* pRuntime,
358 pdfium::span<v8::Local<v8::Value>> params) {
Dan Sinclair8f524d62017-10-25 13:30:31 -0400359 if (params.size() != 1)
Tom Sepez3a6d0582018-08-17 19:28:52 +0000360 return CJS_Result::Failure(JSMessage::kParamError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700361
Dan Sinclairf7435522018-02-05 22:27:22 +0000362 CJS_App::ClearTimerCommon(pRuntime, params[0]);
Tom Sepez3a6d0582018-08-17 19:28:52 +0000363 return CJS_Result::Success();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700364}
365
Tom Sepez90589d42023-11-01 18:24:30 +0000366CJS_Result CJS_App::clearInterval(CJS_Runtime* pRuntime,
367 pdfium::span<v8::Local<v8::Value>> params) {
Dan Sinclair8f524d62017-10-25 13:30:31 -0400368 if (params.size() != 1)
Tom Sepez3a6d0582018-08-17 19:28:52 +0000369 return CJS_Result::Failure(JSMessage::kParamError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700370
Dan Sinclairf7435522018-02-05 22:27:22 +0000371 CJS_App::ClearTimerCommon(pRuntime, params[0]);
Tom Sepez3a6d0582018-08-17 19:28:52 +0000372 return CJS_Result::Success();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700373}
374
Dan Sinclairf7435522018-02-05 22:27:22 +0000375void CJS_App::ClearTimerCommon(CJS_Runtime* pRuntime,
376 v8::Local<v8::Value> param) {
dan sinclair80435cb2017-10-24 21:40:24 -0400377 if (!param->IsObject())
tsepez41a53ad2016-03-28 16:59:30 -0700378 return;
379
dan sinclair80435cb2017-10-24 21:40:24 -0400380 v8::Local<v8::Object> pObj = pRuntime->ToObject(param);
Daniel Hosseinianb6a909b2021-10-22 18:21:53 +0000381 auto pTimer = JSGetObject<CJS_TimerObj>(pRuntime->GetIsolate(), pObj);
Lei Zhangb165ffb2018-07-11 17:23:53 +0000382 if (!pTimer)
tsepez41a53ad2016-03-28 16:59:30 -0700383 return;
384
Lei Zhangb165ffb2018-07-11 17:23:53 +0000385 GlobalTimer::Cancel(pTimer->GetTimerID());
tsepez41a53ad2016-03-28 16:59:30 -0700386}
387
Tom Sepez90589d42023-11-01 18:24:30 +0000388CJS_Result CJS_App::execMenuItem(CJS_Runtime* pRuntime,
389 pdfium::span<v8::Local<v8::Value>> params) {
Tom Sepez3a6d0582018-08-17 19:28:52 +0000390 return CJS_Result::Failure(JSMessage::kNotSupportedError);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700391}
392
Dan Sinclairf7435522018-02-05 22:27:22 +0000393void CJS_App::TimerProc(GlobalTimer* pTimer) {
Lei Zhang2d5a0e12015-10-05 17:00:03 -0700394 CJS_Runtime* pRuntime = pTimer->GetRuntime();
tsepez8ca63de2016-08-05 17:12:27 -0700395 if (pRuntime && (!pTimer->IsOneShot() || pTimer->GetTimeOut() > 0))
396 RunJsScript(pRuntime, pTimer->GetJScript());
397}
Lei Zhang2d5a0e12015-10-05 17:00:03 -0700398
Dan Sinclairf7435522018-02-05 22:27:22 +0000399void CJS_App::CancelProc(GlobalTimer* pTimer) {
Tom Sepezfdbd4bb2022-10-14 23:18:00 +0000400 m_Timers.erase(fxcrt::MakeFakeUniquePtr(pTimer));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700401}
402
Dan Sinclairf7435522018-02-05 22:27:22 +0000403void CJS_App::RunJsScript(CJS_Runtime* pRuntime, const WideString& wsScript) {
Tom Sepezc22d6712018-06-05 22:33:31 +0000404 if (pRuntime->IsBlocking())
405 return;
406
407 IJS_Runtime::ScopedEventContext pContext(pRuntime);
408 pContext->OnExternal_Exec();
409 pContext->RunScript(wsScript);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700410}
411
Tom Sepez3a6d0582018-08-17 19:28:52 +0000412CJS_Result CJS_App::goBack(CJS_Runtime* pRuntime,
Tom Sepez90589d42023-11-01 18:24:30 +0000413 pdfium::span<v8::Local<v8::Value>> params) {
Tom Sepez20736f72018-08-17 16:44:50 +0000414 // Not supported, but do not return error.
Tom Sepez3a6d0582018-08-17 19:28:52 +0000415 return CJS_Result::Success();
tsepez4cf55152016-11-02 14:37:54 -0700416}
417
Tom Sepez3a6d0582018-08-17 19:28:52 +0000418CJS_Result CJS_App::goForward(CJS_Runtime* pRuntime,
Tom Sepez90589d42023-11-01 18:24:30 +0000419 pdfium::span<v8::Local<v8::Value>> params) {
Tom Sepez20736f72018-08-17 16:44:50 +0000420 // Not supported, but do not return error.
Tom Sepez3a6d0582018-08-17 19:28:52 +0000421 return CJS_Result::Success();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700422}
423
Tom Sepez3a6d0582018-08-17 19:28:52 +0000424CJS_Result CJS_App::mailMsg(CJS_Runtime* pRuntime,
Tom Sepez90589d42023-11-01 18:24:30 +0000425 pdfium::span<v8::Local<v8::Value>> params) {
Tom Sepez0a34b6b2023-11-01 20:16:25 +0000426 v8::LocalVector<v8::Value> newParams = ExpandKeywordParams(
Tom Sepezca610782018-12-13 18:01:04 +0000427 pRuntime, params, 6, "bUI", "cTo", "cCc", "cBcc", "cSubject", "cMsg");
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700428
Tom Sepez0e5bab12018-10-18 21:39:40 +0000429 if (!IsExpandedParamKnown(newParams[0]))
Tom Sepez3a6d0582018-08-17 19:28:52 +0000430 return CJS_Result::Failure(JSMessage::kParamError);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700431
Dan Sinclair8f524d62017-10-25 13:30:31 -0400432 bool bUI = pRuntime->ToBoolean(newParams[0]);
Ryan Harrison275e2602017-09-18 14:23:18 -0400433 WideString cTo;
Tom Sepez0e5bab12018-10-18 21:39:40 +0000434 if (IsExpandedParamKnown(newParams[1])) {
dan sinclair80435cb2017-10-24 21:40:24 -0400435 cTo = pRuntime->ToWideString(newParams[1]);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700436 } else {
Dan Sinclair8f524d62017-10-25 13:30:31 -0400437 // cTo parameter required when UI not invoked.
438 if (!bUI)
Tom Sepez3a6d0582018-08-17 19:28:52 +0000439 return CJS_Result::Failure(JSMessage::kParamError);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700440 }
Tom Sepezc6ab1722015-02-05 15:27:25 -0800441
Ryan Harrison275e2602017-09-18 14:23:18 -0400442 WideString cCc;
Tom Sepez0e5bab12018-10-18 21:39:40 +0000443 if (IsExpandedParamKnown(newParams[2]))
dan sinclair80435cb2017-10-24 21:40:24 -0400444 cCc = pRuntime->ToWideString(newParams[2]);
Tom Sepeze5fbd7a2016-01-29 17:05:08 -0800445
Ryan Harrison275e2602017-09-18 14:23:18 -0400446 WideString cBcc;
Tom Sepez0e5bab12018-10-18 21:39:40 +0000447 if (IsExpandedParamKnown(newParams[3]))
dan sinclair80435cb2017-10-24 21:40:24 -0400448 cBcc = pRuntime->ToWideString(newParams[3]);
Tom Sepeze5fbd7a2016-01-29 17:05:08 -0800449
Ryan Harrison275e2602017-09-18 14:23:18 -0400450 WideString cSubject;
Tom Sepez0e5bab12018-10-18 21:39:40 +0000451 if (IsExpandedParamKnown(newParams[4]))
dan sinclair80435cb2017-10-24 21:40:24 -0400452 cSubject = pRuntime->ToWideString(newParams[4]);
Tom Sepeze5fbd7a2016-01-29 17:05:08 -0800453
Ryan Harrison275e2602017-09-18 14:23:18 -0400454 WideString cMsg;
Tom Sepez0e5bab12018-10-18 21:39:40 +0000455 if (IsExpandedParamKnown(newParams[5]))
dan sinclair80435cb2017-10-24 21:40:24 -0400456 cMsg = pRuntime->ToWideString(newParams[5]);
Tom Sepeze5fbd7a2016-01-29 17:05:08 -0800457
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700458 pRuntime->BeginBlock();
Lei Zhang80524632022-08-16 20:31:46 +0000459 pRuntime->GetFormFillEnv()->JS_docmailForm(pdfium::span<const uint8_t>(), bUI,
460 cTo, cSubject, cCc, cBcc, cMsg);
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700461 pRuntime->EndBlock();
Tom Sepez3a6d0582018-08-17 19:28:52 +0000462 return CJS_Result::Success();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700463}
464
Tom Sepez3a6d0582018-08-17 19:28:52 +0000465CJS_Result CJS_App::launchURL(CJS_Runtime* pRuntime,
Tom Sepez90589d42023-11-01 18:24:30 +0000466 pdfium::span<v8::Local<v8::Value>> params) {
Tom Sepez20736f72018-08-17 16:44:50 +0000467 // Unsafe, not supported, but do not return error.
Tom Sepez3a6d0582018-08-17 19:28:52 +0000468 return CJS_Result::Success();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700469}
470
Tom Sepez3a6d0582018-08-17 19:28:52 +0000471CJS_Result CJS_App::get_runtime_highlight(CJS_Runtime* pRuntime) {
472 return CJS_Result::Success(pRuntime->NewBoolean(m_bRuntimeHighLight));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700473}
474
Tom Sepez3a6d0582018-08-17 19:28:52 +0000475CJS_Result CJS_App::set_runtime_highlight(CJS_Runtime* pRuntime,
Dan Sinclairf7435522018-02-05 22:27:22 +0000476 v8::Local<v8::Value> vp) {
dan sinclair80435cb2017-10-24 21:40:24 -0400477 m_bRuntimeHighLight = pRuntime->ToBoolean(vp);
Tom Sepez3a6d0582018-08-17 19:28:52 +0000478 return CJS_Result::Success();
dan sinclaircbe23db2017-10-19 14:29:33 -0400479}
480
Tom Sepez3a6d0582018-08-17 19:28:52 +0000481CJS_Result CJS_App::get_fullscreen(CJS_Runtime* pRuntime) {
482 return CJS_Result::Failure(JSMessage::kNotSupportedError);
dan sinclaircbe23db2017-10-19 14:29:33 -0400483}
484
Tom Sepez3a6d0582018-08-17 19:28:52 +0000485CJS_Result CJS_App::set_fullscreen(CJS_Runtime* pRuntime,
Dan Sinclairf7435522018-02-05 22:27:22 +0000486 v8::Local<v8::Value> vp) {
Tom Sepez3a6d0582018-08-17 19:28:52 +0000487 return CJS_Result::Failure(JSMessage::kNotSupportedError);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700488}
489
Tom Sepez3a6d0582018-08-17 19:28:52 +0000490CJS_Result CJS_App::popUpMenu(CJS_Runtime* pRuntime,
Tom Sepez90589d42023-11-01 18:24:30 +0000491 pdfium::span<v8::Local<v8::Value>> params) {
Tom Sepez3a6d0582018-08-17 19:28:52 +0000492 return CJS_Result::Failure(JSMessage::kNotSupportedError);
tsepez4cf55152016-11-02 14:37:54 -0700493}
494
Tom Sepez90589d42023-11-01 18:24:30 +0000495CJS_Result CJS_App::browseForDoc(CJS_Runtime* pRuntime,
496 pdfium::span<v8::Local<v8::Value>> params) {
Tom Sepez20736f72018-08-17 16:44:50 +0000497 // Unsafe, not supported, but do not return an error.
Tom Sepez3a6d0582018-08-17 19:28:52 +0000498 return CJS_Result::Success();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700499}
500
Dan Sinclairf7435522018-02-05 22:27:22 +0000501WideString CJS_App::SysPathToPDFPath(const WideString& sOldPath) {
Tom Sepez27062af2024-03-19 20:38:06 +0000502 auto sRet = WideString::FromASCII("/");
Tom Sepez3c3e2712017-04-17 15:38:19 -0700503 for (const wchar_t& c : sOldPath) {
Tom Sepez27062af2024-03-19 20:38:06 +0000504 if (c != L':') {
Tom Sepez3c3e2712017-04-17 15:38:19 -0700505 sRet += (c == L'\\') ? L'/' : c;
Tom Sepez27062af2024-03-19 20:38:06 +0000506 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700507 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700508 return sRet;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700509}
510
Tom Sepez3a6d0582018-08-17 19:28:52 +0000511CJS_Result CJS_App::newDoc(CJS_Runtime* pRuntime,
Tom Sepez90589d42023-11-01 18:24:30 +0000512 pdfium::span<v8::Local<v8::Value>> params) {
Tom Sepez3a6d0582018-08-17 19:28:52 +0000513 return CJS_Result::Failure(JSMessage::kNotSupportedError);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700514}
515
Tom Sepez3a6d0582018-08-17 19:28:52 +0000516CJS_Result CJS_App::openDoc(CJS_Runtime* pRuntime,
Tom Sepez90589d42023-11-01 18:24:30 +0000517 pdfium::span<v8::Local<v8::Value>> params) {
Tom Sepez3a6d0582018-08-17 19:28:52 +0000518 return CJS_Result::Failure(JSMessage::kNotSupportedError);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700519}
520
Tom Sepez3a6d0582018-08-17 19:28:52 +0000521CJS_Result CJS_App::response(CJS_Runtime* pRuntime,
Tom Sepez90589d42023-11-01 18:24:30 +0000522 pdfium::span<v8::Local<v8::Value>> params) {
Tom Sepez0a34b6b2023-11-01 20:16:25 +0000523 v8::LocalVector<v8::Value> newParams =
Tom Sepezca610782018-12-13 18:01:04 +0000524 ExpandKeywordParams(pRuntime, params, 5, "cQuestion", "cTitle",
525 "cDefault", "bPassword", "cLabel");
Tom Sepez621d4de2014-07-29 14:01:21 -0700526
Tom Sepez0e5bab12018-10-18 21:39:40 +0000527 if (!IsExpandedParamKnown(newParams[0]))
Tom Sepez3a6d0582018-08-17 19:28:52 +0000528 return CJS_Result::Failure(JSMessage::kParamError);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700529
Dan Sinclair8f524d62017-10-25 13:30:31 -0400530 WideString swQuestion = pRuntime->ToWideString(newParams[0]);
Tom Sepez27062af2024-03-19 20:38:06 +0000531 auto swTitle = WideString::FromASCII("PDF");
Tom Sepez0e5bab12018-10-18 21:39:40 +0000532 if (IsExpandedParamKnown(newParams[1]))
dan sinclair80435cb2017-10-24 21:40:24 -0400533 swTitle = pRuntime->ToWideString(newParams[1]);
Tom Sepez58fb36a2016-02-01 10:32:14 -0800534
Ryan Harrison275e2602017-09-18 14:23:18 -0400535 WideString swDefault;
Tom Sepez0e5bab12018-10-18 21:39:40 +0000536 if (IsExpandedParamKnown(newParams[2]))
dan sinclair80435cb2017-10-24 21:40:24 -0400537 swDefault = pRuntime->ToWideString(newParams[2]);
Tom Sepez58fb36a2016-02-01 10:32:14 -0800538
539 bool bPassword = false;
Tom Sepez0e5bab12018-10-18 21:39:40 +0000540 if (IsExpandedParamKnown(newParams[3]))
dan sinclair80435cb2017-10-24 21:40:24 -0400541 bPassword = pRuntime->ToBoolean(newParams[3]);
Tom Sepez58fb36a2016-02-01 10:32:14 -0800542
Ryan Harrison275e2602017-09-18 14:23:18 -0400543 WideString swLabel;
Tom Sepez0e5bab12018-10-18 21:39:40 +0000544 if (IsExpandedParamKnown(newParams[4]))
dan sinclair80435cb2017-10-24 21:40:24 -0400545 swLabel = pRuntime->ToWideString(newParams[4]);
Tom Sepez621d4de2014-07-29 14:01:21 -0700546
Lei Zhangcd3d3792022-09-28 17:22:04 +0000547 constexpr int kMaxWideChars = 1024;
548 constexpr int kMaxBytes = kMaxWideChars * sizeof(uint16_t);
Tom Sepezcc81d112024-01-19 22:35:28 +0000549 auto buffer = FixedSizeDataVector<uint8_t>::Zeroed(kMaxBytes);
Lei Zhang82b558c2022-09-27 17:52:16 +0000550 int byte_length = pRuntime->GetFormFillEnv()->JS_appResponse(
Tom Sepez06b95132024-01-04 01:44:19 +0000551 swQuestion, swTitle, swDefault, swLabel, bPassword, buffer.span());
552
Lei Zhang82b558c2022-09-27 17:52:16 +0000553 if (byte_length < 0 || byte_length > kMaxBytes)
Tom Sepez3a6d0582018-08-17 19:28:52 +0000554 return CJS_Result::Failure(JSMessage::kParamTooLongError);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700555
Tom Sepez06b95132024-01-04 01:44:19 +0000556 auto wstr = WideString::FromUTF16LE(buffer.first(byte_length));
557 return CJS_Result::Success(pRuntime->NewString(wstr.AsStringView()));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700558}
559
Tom Sepez3a6d0582018-08-17 19:28:52 +0000560CJS_Result CJS_App::get_media(CJS_Runtime* pRuntime) {
561 return CJS_Result::Failure(JSMessage::kNotSupportedError);
dan sinclaircbe23db2017-10-19 14:29:33 -0400562}
563
Tom Sepez3a6d0582018-08-17 19:28:52 +0000564CJS_Result CJS_App::set_media(CJS_Runtime* pRuntime, v8::Local<v8::Value> vp) {
565 return CJS_Result::Failure(JSMessage::kNotSupportedError);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700566}
567
Tom Sepez90589d42023-11-01 18:24:30 +0000568CJS_Result CJS_App::execDialog(CJS_Runtime* pRuntime,
569 pdfium::span<v8::Local<v8::Value>> params) {
Tom Sepez3a6d0582018-08-17 19:28:52 +0000570 return CJS_Result::Success();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700571}