7#include "fxjs/xfa/cjx_hostpseudomodel.h"
9#include "core/fxcrt/check.h"
10#include "core/fxcrt/span.h"
12#include "fxjs/js_resources.h"
13#include "fxjs/xfa/cfxjse_engine.h"
14#include "v8/include/v8-object.h"
15#include "xfa/fxfa/cxfa_ffdoc.h"
16#include "xfa/fxfa/cxfa_ffnotify.h"
17#include "xfa/fxfa/parser/cscript_hostpseudomodel.h"
18#include "xfa/fxfa/parser/cxfa_node.h"
25 const size_t nLength = wsExpression.GetLength();
26 if (nStart >= nLength)
30 pdfium::span<
const wchar_t> pSrc = wsExpression.span();
33 pdfium::span<
wchar_t> pBuf = wsFilter.GetBuffer(nLength - nStart);
34 while (nStart < nLength) {
35 wchar_t wCur = pSrc[nStart++];
39 pBuf[nCount++] = wCur;
42 wsFilter.ReleaseBuffer(nCount);
50 {
"beep", beep_static},
51 {
"documentCountInBatch", documentCountInBatch_static},
52 {
"documentInBatch", documentInBatch_static},
53 {
"exportData", exportData_static},
54 {
"getFocus", getFocus_static},
55 {
"gotoURL", gotoURL_static},
56 {
"importData", importData_static},
57 {
"messageBox", messageBox_static},
58 {
"openList", openList_static},
59 {
"pageDown", pageDown_static},
60 {
"pageUp", pageUp_static},
61 {
"print", print_static},
62 {
"resetData", resetData_static},
63 {
"response", response_static},
64 {
"setFocus", setFocus_static}};
66CJX_HostPseudoModel::CJX_HostPseudoModel(CScript_HostPseudoModel* model)
68 DefineMethods(MethodSpecs);
77void CJX_HostPseudoModel::appType(
v8::Isolate* pIsolate,
78 v8::Local<v8::Value>* pValue,
89 *pValue = fxv8::NewStringHelper(pIsolate,
"Exchange");
92void CJX_HostPseudoModel::calculationsEnabled(
v8::Isolate* pIsolate,
93 v8::Local<v8::Value>* pValue,
103 fxv8::ReentrantToBooleanHelper(pIsolate, *pValue)
);
109void CJX_HostPseudoModel::currentPage(
v8::Isolate* pIsolate,
110 v8::Local<v8::Value>* pValue,
125void CJX_HostPseudoModel::language(
v8::Isolate* pIsolate,
126 v8::Local<v8::Value>* pValue,
139 *pValue = fxv8::NewStringHelper(pIsolate, lang.AsStringView());
142void CJX_HostPseudoModel::numPages(
v8::Isolate* pIsolate,
143 v8::Local<v8::Value>* pValue,
159void CJX_HostPseudoModel::platform(
v8::Isolate* pIsolate,
160 v8::Local<v8::Value>* pValue,
173 *pValue = fxv8::NewStringHelper(pIsolate, plat.AsStringView());
176void CJX_HostPseudoModel::title(
v8::Isolate* pIsolate,
177 v8::Local<v8::Value>* pValue,
180 if (!
GetDocument()->GetScriptContext()->IsRunAtClient())
194 *pValue = fxv8::NewStringHelper(pIsolate, bsTitle.AsStringView());
197void CJX_HostPseudoModel::validationsEnabled(
v8::Isolate* pIsolate,
198 v8::Local<v8::Value>* pValue,
208 fxv8::ReentrantToBooleanHelper(pIsolate, *pValue)
);
215void CJX_HostPseudoModel::variation(
v8::Isolate* pIsolate,
216 v8::Local<v8::Value>* pValue,
219 if (!
GetDocument()->GetScriptContext()->IsRunAtClient())
227 *pValue = fxv8::NewStringHelper(pIsolate,
"Full");
230void CJX_HostPseudoModel::version(
v8::Isolate* pIsolate,
231 v8::Local<v8::Value>* pValue,
239 *pValue = fxv8::NewStringHelper(pIsolate,
"11");
242void CJX_HostPseudoModel::name(
v8::Isolate* pIsolate,
243 v8::Local<v8::Value>* pValue,
255 *pValue = fxv8::NewStringHelper(pIsolate, bsName.AsStringView());
260 pdfium::span<v8::Local<v8::Value>> params) {
265 if (params.size() != 1)
272 pNotify->GetFFDoc()->GotoURL(runtime->ToWideString(params[0]));
278 pdfium::span<v8::Local<v8::Value>> params) {
283 if (params.size() != 1)
291 if (params[0]->IsObject()) {
292 pNode = ToNode(runtime->ToXFAObject(params[0]));
293 }
else if (params[0]->IsString()) {
302 runtime->ResolveObjects(
303 pObject, runtime->ToWideString(params[0]).AsStringView(), kFlags);
304 if (!maybeResult.has_value() ||
305 !maybeResult.value().objects.front()->IsNode()) {
308 pNode = maybeResult.value().objects.front()->AsNode();
318 pdfium::span<v8::Local<v8::Value>> params) {
319 if (params.empty() || params.size() > 4)
327 if (params.size() >= 1)
328 question = runtime->ToWideString(params[0]);
331 if (params.size() >= 2)
332 title = runtime->ToWideString(params[1]);
335 if (params.size() >= 3)
336 defaultAnswer = runtime->ToWideString(params[2]);
339 if (params.size() >= 4)
340 mark = runtime->ToInt32(params[3]) != 0;
345 runtime->NewString(answer
.ToUTF8().AsStringView())
);
348CJS_Result CJX_HostPseudoModel::documentInBatch(
350 pdfium::span<v8::Local<v8::Value>> params) {
356 pdfium::span<v8::Local<v8::Value>> params) {
357 if (params.size() > 1)
365 if (params.size() >= 1)
366 expression = runtime->ToWideString(params[0]);
368 if (expression.IsEmpty()) {
376 const size_t nExpLength = expression.GetLength();
377 while (nStart < nExpLength) {
378 nStart = FilterName(expression.AsStringView(), nStart, wsName);
387 runtime->ResolveObjects(pObject, wsName.AsStringView(), kFlags);
388 if (!maybeResult.has_value() ||
389 !maybeResult.value().objects.front()->IsNode())
392 pNode = maybeResult.value().objects.front()->AsNode();
403 pdfium::span<v8::Local<v8::Value>> params) {
408 if (params.size() > 1)
416 if (params.size() >= 1)
417 dwType = runtime->ToInt32(params[0]);
425 pdfium::span<v8::Local<v8::Value>> params) {
430 if (params.size() != 1)
438 if (params.size() >= 1) {
439 if (params[0]->IsObject()) {
440 pNode = ToNode(runtime->ToXFAObject(params[0]));
441 }
else if (params[0]->IsString()) {
450 runtime->ResolveObjects(
451 pObject, runtime->ToWideString(params[0]).AsStringView(), kFlags);
452 if (!maybeResult.has_value() ||
453 !maybeResult.value().objects.front()->IsNode()) {
456 pNode = maybeResult.value().objects.front()->AsNode();
465 pdfium::span<v8::Local<v8::Value>> params) {
479 pdfium::span<v8::Local<v8::Value>> params) {
484 if (params.empty() || params.size() > 4)
492 if (params.size() >= 1)
493 message = runtime->ToWideString(params[0]);
496 if (params.size() >= 2)
497 title = runtime->ToWideString(params[1]);
500 if (params.size() >= 3) {
501 messageType = runtime->ToInt32(params[2]);
507 if (params.size() >= 4) {
508 buttonType = runtime->ToInt32(params[3]);
514 messageType
, buttonType
);
518CJS_Result CJX_HostPseudoModel::documentCountInBatch(
520 pdfium::span<v8::Local<v8::Value>> params) {
526 pdfium::span<v8::Local<v8::Value>> params) {
531 if (params.size() != 8)
539 if (runtime->ToBoolean(params[0]))
541 if (runtime->ToBoolean(params[3]))
543 if (runtime->ToBoolean(params[4]))
545 if (runtime->ToBoolean(params[5]))
547 if (runtime->ToBoolean(params[6]))
549 if (runtime->ToBoolean(params[7]))
552 int32_t nStartPage = runtime->ToInt32(params[1]);
553 int32_t nEndPage = runtime->ToInt32(params[2]);
560 pdfium::span<v8::Local<v8::Value>> params) {
561 if (params.empty() || params.size() > 1)
569 pdfium::span<v8::Local<v8::Value>> params) {
570 if (params.empty() || params.size() > 2)
578 if (params.size() >= 1)
579 filePath = runtime->ToWideString(params[0]);
582 if (params.size() >= 2)
583 XDP = runtime->ToBoolean(params[1]);
591 pdfium::span<v8::Local<v8::Value>> params) {
607 pdfium::span<v8::Local<v8::Value>> params) {
615 if (!nPageCount || nCurPage == nPageCount)
618 int32_t nNewPage = 0;
619 if (nCurPage >= nPageCount)
620 nNewPage = nPageCount - 1;
622 nNewPage = nCurPage + 1;
fxcrt::ByteString ByteString
CXFA_Object * GetThisObject() const
friend class EventParamScope
static CJS_Result Success()
static CJS_Result Failure(JSMessage id)
~CJX_HostPseudoModel() override
bool DynamicTypeIs(TypeTag eType) const override
void ThrowInvalidPropertyException(v8::Isolate *pIsolate) const
CXFA_Document * GetDocument() const
virtual bool DynamicTypeIs(TypeTag eType) const
void ThrowException(v8::Isolate *pIsolate, const WideString &str) const
virtual WideString GetAppName()=0
virtual WideString GetPlatform()=0
virtual void Beep(uint32_t dwType)=0
virtual int32_t MsgBox(const WideString &wsMessage, const WideString &wsTitle, uint32_t dwIconType, uint32_t dwButtonType)=0
virtual WideString Response(const WideString &wsQuestion, const WideString &wsTitle, const WideString &wsDefaultAnswer, bool bMask)=0
virtual WideString GetLanguage()=0
void Print(int32_t nStartPage, int32_t nEndPage, Mask< XFA_PrintOpt > dwOptions)
void SetCurrentPage(int32_t iCurPage)
void SetCalculationsEnabled(bool bEnabled)
bool IsCalculationsEnabled() const
void SetValidationsEnabled(bool bEnabled)
WideString GetTitle() const
int32_t GetCurrentPage() const
bool IsValidationsEnabled() const
void ExportData(const WideString &wsFilePath, bool bXDP)
void SetTitle(const WideString &wsTitle)
int32_t CountPages() const
void ResetData(CXFA_Node *pNode)
void SetFocusWidgetNode(CXFA_Node *pNode)
CXFA_FFDoc * GetFFDoc() const
CXFA_FFApp::CallbackIface * GetAppProvider()
CXFA_Node * GetFocusWidgetNode()
void OpenDropDownList(CXFA_Node *pNode)
bool IsWidgetReady() const
ByteString ToUTF8() const
static WideString FromASCII(ByteStringView str)
fxcrt::WideStringView WideStringView
fxcrt::WideString WideString