7#include "fxjs/xfa/cjx_hostpseudomodel.h"
12#include "fxjs/js_resources.h"
13#include "fxjs/xfa/cfxjse_engine.h"
14#include "third_party/base/check.h"
15#include "third_party/base/containers/span.h"
16#include "v8/include/v8-object.h"
17#include "xfa/fxfa/cxfa_ffdoc.h"
18#include "xfa/fxfa/cxfa_ffnotify.h"
19#include "xfa/fxfa/parser/cscript_hostpseudomodel.h"
20#include "xfa/fxfa/parser/cxfa_node.h"
24size_t FilterName(WideStringView wsExpression,
26 WideString& wsFilter) {
27 const size_t nLength = wsExpression.GetLength();
28 if (nStart >= nLength)
34 pdfium::span<
wchar_t> pBuf = wsFilter.GetBuffer(nLength - nStart);
35 const wchar_t* pSrc = wsExpression.unterminated_c_str();
36 while (nStart < nLength) {
37 wchar_t wCur = pSrc[nStart++];
41 pBuf[nCount++] = wCur;
44 wsFilter.ReleaseBuffer(nCount);
52 {
"beep", beep_static},
53 {
"documentCountInBatch", documentCountInBatch_static},
54 {
"documentInBatch", documentInBatch_static},
55 {
"exportData", exportData_static},
56 {
"getFocus", getFocus_static},
57 {
"gotoURL", gotoURL_static},
58 {
"importData", importData_static},
59 {
"messageBox", messageBox_static},
60 {
"openList", openList_static},
61 {
"pageDown", pageDown_static},
62 {
"pageUp", pageUp_static},
63 {
"print", print_static},
64 {
"resetData", resetData_static},
65 {
"response", response_static},
66 {
"setFocus", setFocus_static}};
68CJX_HostPseudoModel::CJX_HostPseudoModel(CScript_HostPseudoModel* model)
79void CJX_HostPseudoModel::appType(
v8::Isolate* pIsolate,
80 v8::Local<v8::Value>* pValue,
91 *pValue = fxv8::NewStringHelper(pIsolate,
"Exchange");
94void CJX_HostPseudoModel::calculationsEnabled(
v8::Isolate* pIsolate,
95 v8::Local<v8::Value>* pValue,
105 fxv8::ReentrantToBooleanHelper(pIsolate, *pValue)
);
111void CJX_HostPseudoModel::currentPage(
v8::Isolate* pIsolate,
112 v8::Local<v8::Value>* pValue,
127void CJX_HostPseudoModel::language(
v8::Isolate* pIsolate,
128 v8::Local<v8::Value>* pValue,
137 WideString
::FromASCII(
"Unable to set language value.")
);
141 *pValue = fxv8::NewStringHelper(pIsolate, lang.AsStringView());
144void CJX_HostPseudoModel::numPages(
v8::Isolate* pIsolate,
145 v8::Local<v8::Value>* pValue,
155 WideString
::FromASCII(
"Unable to set numPages value.")
);
161void CJX_HostPseudoModel::platform(
v8::Isolate* pIsolate,
162 v8::Local<v8::Value>* pValue,
171 WideString
::FromASCII(
"Unable to set platform value.")
);
175 *pValue = fxv8::NewStringHelper(pIsolate, plat.AsStringView());
178void CJX_HostPseudoModel::title(
v8::Isolate* pIsolate,
179 v8::Local<v8::Value>* pValue,
182 if (!
GetDocument()->GetScriptContext()->IsRunAtClient())
196 *pValue = fxv8::NewStringHelper(pIsolate, bsTitle.AsStringView());
199void CJX_HostPseudoModel::validationsEnabled(
v8::Isolate* pIsolate,
200 v8::Local<v8::Value>* pValue,
210 fxv8::ReentrantToBooleanHelper(pIsolate, *pValue)
);
217void CJX_HostPseudoModel::variation(
v8::Isolate* pIsolate,
218 v8::Local<v8::Value>* pValue,
221 if (!
GetDocument()->GetScriptContext()->IsRunAtClient())
226 WideString
::FromASCII(
"Unable to set variation value.")
);
229 *pValue = fxv8::NewStringHelper(pIsolate,
"Full");
232void CJX_HostPseudoModel::version(
v8::Isolate* pIsolate,
233 v8::Local<v8::Value>* pValue,
241 *pValue = fxv8::NewStringHelper(pIsolate,
"11");
244void CJX_HostPseudoModel::name(
v8::Isolate* pIsolate,
245 v8::Local<v8::Value>* pValue,
257 *pValue = fxv8::NewStringHelper(pIsolate, bsName.AsStringView());
262 pdfium::span<v8::Local<v8::Value>> params) {
267 if (params.size() != 1)
274 pNotify->GetFFDoc()->GotoURL(runtime->ToWideString(params[0]));
280 pdfium::span<v8::Local<v8::Value>> params) {
285 if (params.size() != 1)
293 if (params[0]->IsObject()) {
294 pNode = ToNode(runtime->ToXFAObject(params[0]));
295 }
else if (params[0]->IsString()) {
301 XFA_ResolveFlag::kParent,
302 XFA_ResolveFlag::kSiblings};
303 absl::optional<CFXJSE_Engine::ResolveResult> maybeResult =
304 runtime->ResolveObjects(
305 pObject, runtime->ToWideString(params[0]).AsStringView(), kFlags);
306 if (!maybeResult.has_value() ||
307 !maybeResult.value().objects.front()->IsNode()) {
310 pNode = maybeResult.value().objects.front()->AsNode();
320 pdfium::span<v8::Local<v8::Value>> params) {
321 if (params.empty() || params.size() > 4)
329 if (params.size() >= 1)
330 question = runtime->ToWideString(params[0]);
333 if (params.size() >= 2)
334 title = runtime->ToWideString(params[1]);
336 WideString defaultAnswer;
337 if (params.size() >= 3)
338 defaultAnswer = runtime->ToWideString(params[2]);
341 if (params.size() >= 4)
342 mark = runtime->ToInt32(params[3]) != 0;
347 runtime->NewString(answer
.ToUTF8().AsStringView())
);
350CJS_Result CJX_HostPseudoModel::documentInBatch(
352 pdfium::span<v8::Local<v8::Value>> params) {
358 pdfium::span<v8::Local<v8::Value>> params) {
359 if (params.size() > 1)
366 WideString expression;
367 if (params.size() >= 1)
368 expression = runtime->ToWideString(params[0]);
378 const size_t nExpLength = expression.GetLength();
379 while (nStart < nExpLength) {
380 nStart = FilterName(expression.AsStringView(), nStart, wsName);
386 XFA_ResolveFlag::kParent,
387 XFA_ResolveFlag::kSiblings};
388 absl::optional<CFXJSE_Engine::ResolveResult> maybeResult =
389 runtime->ResolveObjects(pObject, wsName.AsStringView(), kFlags);
390 if (!maybeResult.has_value() ||
391 !maybeResult.value().objects.front()->IsNode())
394 pNode = maybeResult.value().objects.front()->AsNode();
405 pdfium::span<v8::Local<v8::Value>> params) {
410 if (params.size() > 1)
418 if (params.size() >= 1)
419 dwType = runtime->ToInt32(params[0]);
427 pdfium::span<v8::Local<v8::Value>> params) {
432 if (params.size() != 1)
440 if (params.size() >= 1) {
441 if (params[0]->IsObject()) {
442 pNode = ToNode(runtime->ToXFAObject(params[0]));
443 }
else if (params[0]->IsString()) {
449 XFA_ResolveFlag::kParent,
450 XFA_ResolveFlag::kSiblings};
451 absl::optional<CFXJSE_Engine::ResolveResult> maybeResult =
452 runtime->ResolveObjects(
453 pObject, runtime->ToWideString(params[0]).AsStringView(), kFlags);
454 if (!maybeResult.has_value() ||
455 !maybeResult.value().objects.front()->IsNode()) {
458 pNode = maybeResult.value().objects.front()->AsNode();
467 pdfium::span<v8::Local<v8::Value>> params) {
481 pdfium::span<v8::Local<v8::Value>> params) {
486 if (params.empty() || params.size() > 4)
494 if (params.size() >= 1)
495 message = runtime->ToWideString(params[0]);
498 if (params.size() >= 2)
499 title = runtime->ToWideString(params[1]);
502 if (params.size() >= 3) {
503 messageType = runtime->ToInt32(params[2]);
509 if (params.size() >= 4) {
510 buttonType = runtime->ToInt32(params[3]);
516 messageType
, buttonType
);
520CJS_Result CJX_HostPseudoModel::documentCountInBatch(
522 pdfium::span<v8::Local<v8::Value>> params) {
528 pdfium::span<v8::Local<v8::Value>> params) {
533 if (params.size() != 8)
541 if (runtime->ToBoolean(params[0]))
543 if (runtime->ToBoolean(params[3]))
545 if (runtime->ToBoolean(params[4]))
547 if (runtime->ToBoolean(params[5]))
549 if (runtime->ToBoolean(params[6]))
551 if (runtime->ToBoolean(params[7]))
554 int32_t nStartPage = runtime->ToInt32(params[1]);
555 int32_t nEndPage = runtime->ToInt32(params[2]);
562 pdfium::span<v8::Local<v8::Value>> params) {
563 if (params.empty() || params.size() > 1)
571 pdfium::span<v8::Local<v8::Value>> params) {
572 if (params.empty() || params.size() > 2)
580 if (params.size() >= 1)
581 filePath = runtime->ToWideString(params[0]);
584 if (params.size() >= 2)
585 XDP = runtime->ToBoolean(params[1]);
593 pdfium::span<v8::Local<v8::Value>> params) {
609 pdfium::span<v8::Local<v8::Value>> params) {
617 if (!nPageCount || nCurPage == nPageCount)
620 int32_t nNewPage = 0;
621 if (nCurPage >= nPageCount)
622 nNewPage = nPageCount - 1;
624 nNewPage = nCurPage + 1;
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 DefineMethods(pdfium::span< const CJX_MethodSpec > methods)
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)