1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
|
// Copyright 2017 PDFium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
#ifndef FXJS_XFA_CJX_OBJECT_H_
#define FXJS_XFA_CJX_OBJECT_H_
#include <map>
#include <memory>
#include <utility>
#include <vector>
#include "core/fxcrt/unowned_ptr.h"
#include "core/fxcrt/widestring.h"
#include "core/fxcrt/xml/cfx_xmlelement.h"
#include "third_party/base/optional.h"
#include "xfa/fxfa/fxfa_basic.h"
#include "xfa/fxfa/parser/cxfa_widgetdata.h"
class CFXJSE_Value;
class CJS_V8;
class CXFA_CalcData;
class CXFA_Document;
class CXFA_LayoutItem;
class CXFA_Object;
struct XFA_MAPMODULEDATA;
typedef CJS_Return (*CJX_MethodCall)(
CJX_Object* obj,
CJS_V8* runtime,
const std::vector<v8::Local<v8::Value>>& params);
struct CJX_MethodSpec {
const char* pName;
CJX_MethodCall pMethodCall;
};
typedef void (*PD_CALLBACK_FREEDATA)(void* pData);
typedef void (*PD_CALLBACK_DUPLICATEDATA)(void*& pData);
struct XFA_MAPDATABLOCKCALLBACKINFO {
PD_CALLBACK_FREEDATA pFree;
PD_CALLBACK_DUPLICATEDATA pCopy;
};
class CJX_Object {
public:
explicit CJX_Object(CXFA_Object* obj);
virtual ~CJX_Object();
CXFA_Object* GetXFAObject() { return object_.Get(); }
const CXFA_Object* GetXFAObject() const { return object_.Get(); }
CXFA_Document* GetDocument() const;
void SetWidgetData(std::unique_ptr<CXFA_WidgetData> data) {
widget_data_ = std::move(data);
}
CXFA_WidgetData* GetWidgetData() const { return widget_data_.get(); }
void SetCalcRecursionCount(size_t count) { calc_recursion_count_ = count; }
size_t GetCalcRecursionCount() const { return calc_recursion_count_; }
void SetLayoutItem(CXFA_LayoutItem* item) { layout_item_ = item; }
CXFA_LayoutItem* GetLayoutItem() const { return layout_item_.Get(); }
bool HasMethod(const WideString& func) const;
CJS_Return RunMethod(const WideString& func,
const std::vector<v8::Local<v8::Value>>& params);
bool HasAttribute(XFA_Attribute eAttr);
bool SetAttribute(XFA_Attribute eAttr,
const WideStringView& wsValue,
bool bNotify);
bool SetAttribute(const WideStringView& wsAttr,
const WideStringView& wsValue,
bool bNotify);
void RemoveAttribute(const WideStringView& wsAttr);
WideString GetAttribute(const WideStringView& attr);
WideString GetAttribute(XFA_Attribute attr);
pdfium::Optional<WideString> TryAttribute(const WideStringView& wsAttr,
bool bUseDefault);
pdfium::Optional<WideString> TryAttribute(XFA_Attribute eAttr,
bool bUseDefault);
pdfium::Optional<WideString> TryContent(bool bScriptModify, bool bProto);
bool SetContent(const WideString& wsContent,
const WideString& wsXMLValue,
bool bNotify,
bool bScriptModify,
bool bSyncData);
WideString GetContent(bool bScriptModify);
CXFA_Node* GetProperty(int32_t index,
XFA_Element eType,
bool bCreateProperty);
void SetAttributeValue(const WideString& wsValue,
const WideString& wsXMLValue,
bool bNotify,
bool bScriptModify);
void Script_Attribute_String(CFXJSE_Value* pValue,
bool bSetting,
XFA_Attribute eAttribute);
void Script_Attribute_BOOL(CFXJSE_Value* pValue,
bool bSetting,
XFA_Attribute eAttribute);
void Script_Attribute_Integer(CFXJSE_Value* pValue,
bool bSetting,
XFA_Attribute eAttribute);
void Script_Som_FontColor(CFXJSE_Value* pValue,
bool bSetting,
XFA_Attribute eAttribute);
void Script_Som_FillColor(CFXJSE_Value* pValue,
bool bSetting,
XFA_Attribute eAttribute);
void Script_Som_BorderColor(CFXJSE_Value* pValue,
bool bSetting,
XFA_Attribute eAttribute);
void Script_Som_BorderWidth(CFXJSE_Value* pValue,
bool bSetting,
XFA_Attribute eAttribute);
void Script_Som_ValidationMessage(CFXJSE_Value* pValue,
bool bSetting,
XFA_Attribute eAttribute);
void Script_Som_MandatoryMessage(CFXJSE_Value* pValue,
bool bSetting,
XFA_Attribute eAttribute);
void Script_Field_FormatMessage(CFXJSE_Value* pValue,
bool bSetting,
XFA_Attribute eAttribute);
void Script_Som_DefaultValue(CFXJSE_Value* pValue,
bool bSetting,
XFA_Attribute eAttribute);
void Script_Som_DefaultValue_Read(CFXJSE_Value* pValue,
bool bSetting,
XFA_Attribute eAttribute);
void Script_Som_DataNode(CFXJSE_Value* pValue,
bool bSetting,
XFA_Attribute eAttribute);
void Script_Som_Mandatory(CFXJSE_Value* pValue,
bool bSetting,
XFA_Attribute eAttribute);
void Script_Som_InstanceIndex(CFXJSE_Value* pValue,
bool bSetting,
XFA_Attribute eAttribute);
void Script_NodeClass_Ns(CFXJSE_Value* pValue,
bool bSetting,
XFA_Attribute eAttribute);
void Script_NodeClass_Model(CFXJSE_Value* pValue,
bool bSetting,
XFA_Attribute eAttribute);
void Script_NodeClass_IsContainer(CFXJSE_Value* pValue,
bool bSetting,
XFA_Attribute eAttribute);
void Script_NodeClass_IsNull(CFXJSE_Value* pValue,
bool bSetting,
XFA_Attribute eAttribute);
void Script_NodeClass_OneOfChild(CFXJSE_Value* pValue,
bool bSetting,
XFA_Attribute eAttribute);
void Script_ModelClass_Context(CFXJSE_Value* pValue,
bool bSetting,
XFA_Attribute eAttribute);
void Script_ModelClass_AliasNode(CFXJSE_Value* pValue,
bool bSetting,
XFA_Attribute eAttribute);
void Script_Delta_CurrentValue(CFXJSE_Value* pValue,
bool bSetting,
XFA_Attribute eAttribute);
void Script_Delta_SavedValue(CFXJSE_Value* pValue,
bool bSetting,
XFA_Attribute eAttribute);
void Script_Delta_Target(CFXJSE_Value* pValue,
bool bSetting,
XFA_Attribute eAttribute);
void Script_Field_Length(CFXJSE_Value* pValue,
bool bSetting,
XFA_Attribute eAttribute);
void Script_Field_EditValue(CFXJSE_Value* pValue,
bool bSetting,
XFA_Attribute eAttribute);
void Script_Field_FormattedValue(CFXJSE_Value* pValue,
bool bSetting,
XFA_Attribute eAttribute);
void Script_Field_ParentSubform(CFXJSE_Value* pValue,
bool bSetting,
XFA_Attribute eAttribute);
void Script_Field_SelectedIndex(CFXJSE_Value* pValue,
bool bSetting,
XFA_Attribute eAttribute);
void Script_ExclGroup_DefaultAndRawValue(CFXJSE_Value* pValue,
bool bSetting,
XFA_Attribute eAttribute);
void Script_ExclGroup_ErrorText(CFXJSE_Value* pValue,
bool bSetting,
XFA_Attribute eAttribute);
void Script_ExclGroup_Transient(CFXJSE_Value* pValue,
bool bSetting,
XFA_Attribute eAttribute);
void Script_Subform_InstanceManager(CFXJSE_Value* pValue,
bool bSetting,
XFA_Attribute eAttribute);
void Script_Subform_Locale(CFXJSE_Value* pValue,
bool bSetting,
XFA_Attribute eAttribute);
void Script_InstanceManager_Count(CFXJSE_Value* pValue,
bool bSetting,
XFA_Attribute eAttribute);
void Script_InstanceManager_Max(CFXJSE_Value* pValue,
bool bSetting,
XFA_Attribute eAttribute);
void Script_InstanceManager_Min(CFXJSE_Value* pValue,
bool bSetting,
XFA_Attribute eAttribute);
void Script_Occur_Max(CFXJSE_Value* pValue,
bool bSetting,
XFA_Attribute eAttribute);
void Script_Occur_Min(CFXJSE_Value* pValue,
bool bSetting,
XFA_Attribute eAttribute);
void Script_Form_Checksum(CFXJSE_Value* pValue,
bool bSetting,
XFA_Attribute eAttribute);
void Script_Packet_Content(CFXJSE_Value* pValue,
bool bSetting,
XFA_Attribute eAttribute);
void Script_Source_Db(CFXJSE_Value* pValue,
bool bSetting,
XFA_Attribute eAttribute);
void Script_Xfa_This(CFXJSE_Value* pValue,
bool bSetting,
XFA_Attribute eAttribute);
void Script_Handler_Version(CFXJSE_Value* pValue,
bool bSetting,
XFA_Attribute eAttribute);
void Script_SubmitFormat_Mode(CFXJSE_Value* pValue,
bool bSetting,
XFA_Attribute eAttribute);
void Script_Extras_Type(CFXJSE_Value* pValue,
bool bSetting,
XFA_Attribute eAttribute);
void Script_Encrypt_Format(CFXJSE_Value* pValue,
bool bSetting,
XFA_Attribute eAttribute);
void Script_Script_Stateless(CFXJSE_Value* pValue,
bool bSetting,
XFA_Attribute eAttribute);
pdfium::Optional<WideString> TryNamespace();
pdfium::Optional<int32_t> TryInteger(XFA_Attribute eAttr, bool bUseDefault);
bool SetInteger(XFA_Attribute eAttr, int32_t iValue, bool bNotify);
int32_t GetInteger(XFA_Attribute eAttr);
pdfium::Optional<WideString> TryCData(XFA_Attribute eAttr, bool bUseDefault);
bool SetCData(XFA_Attribute eAttr,
const WideString& wsValue,
bool bNotify,
bool bScriptModify);
WideString GetCData(XFA_Attribute eAttr);
pdfium::Optional<XFA_AttributeEnum> TryEnum(XFA_Attribute eAttr,
bool bUseDefault);
bool SetEnum(XFA_Attribute eAttr, XFA_AttributeEnum eValue, bool bNotify);
XFA_AttributeEnum GetEnum(XFA_Attribute eAttr);
pdfium::Optional<bool> TryBoolean(XFA_Attribute eAttr, bool bUseDefault);
bool SetBoolean(XFA_Attribute eAttr, bool bValue, bool bNotify);
bool GetBoolean(XFA_Attribute eAttr);
pdfium::Optional<CXFA_Measurement> TryMeasure(XFA_Attribute eAttr,
bool bUseDefault) const;
bool SetMeasure(XFA_Attribute eAttr, CXFA_Measurement mValue, bool bNotify);
CXFA_Measurement GetMeasure(XFA_Attribute eAttr) const;
void Script_ObjectClass_ClassName(CFXJSE_Value* pValue,
bool bSetting,
XFA_Attribute eAttribute);
void MergeAllData(CXFA_Object* pDstModule);
void SetCalcData(std::unique_ptr<CXFA_CalcData> data);
CXFA_CalcData* GetCalcData() const { return calc_data_.get(); }
std::unique_ptr<CXFA_CalcData> ReleaseCalcData();
int32_t InstanceManager_SetInstances(int32_t iDesired);
int32_t InstanceManager_MoveInstance(int32_t iTo, int32_t iFrom);
void ThrowInvalidPropertyException() const;
void ThrowArgumentMismatchException() const;
void ThrowIndexOutOfBoundsException() const;
void ThrowParamCountMismatchException(const WideString& method) const;
void ThrowTooManyOccurancesException(const WideString& obj) const;
protected:
void DefineMethods(const CJX_MethodSpec method_specs[], size_t count);
void MoveBufferMapData(CXFA_Object* pSrcModule, CXFA_Object* pDstModule);
void SetMapModuleString(void* pKey, const WideStringView& wsValue);
void ThrowException(const wchar_t* str, ...) const;
private:
enum XFA_SOM_MESSAGETYPE {
XFA_SOM_ValidationMessage,
XFA_SOM_FormatMessage,
XFA_SOM_MandatoryMessage
};
void Script_Som_Message(CFXJSE_Value* pValue,
bool bSetting,
XFA_SOM_MESSAGETYPE iMessageType);
void Script_Boolean_DefaultValue(CFXJSE_Value* pValue,
bool bSetting,
XFA_Attribute eAttribute);
void Script_Draw_DefaultValue(CFXJSE_Value* pValue,
bool bSetting,
XFA_Attribute eAttribute);
void Script_Field_DefaultValue(CFXJSE_Value* pValue,
bool bSetting,
XFA_Attribute eAttribute);
int32_t Subform_and_SubformSet_InstanceIndex();
void OnChanged(XFA_Attribute eAttr, bool bNotify, bool bScriptModify);
void OnChanging(XFA_Attribute eAttr, bool bNotify);
bool SetUserData(void* pKey,
void* pData,
XFA_MAPDATABLOCKCALLBACKINFO* pCallbackInfo);
// Returns a pointer to the XML node that needs to be updated with the new
// attribute value. |nullptr| if no update is needed.
CFX_XMLElement* SetValue(XFA_Attribute eAttr,
XFA_AttributeType eType,
void* pValue,
bool bNotify);
XFA_MAPMODULEDATA* CreateMapModuleData();
XFA_MAPMODULEDATA* GetMapModuleData() const;
void SetMapModuleValue(void* pKey, void* pValue);
bool GetMapModuleValue(void* pKey, void*& pValue);
bool GetMapModuleString(void* pKey, WideStringView& wsValue);
void SetMapModuleBuffer(void* pKey,
void* pValue,
int32_t iBytes,
XFA_MAPDATABLOCKCALLBACKINFO* pCallbackInfo);
bool GetMapModuleBuffer(void* pKey,
void*& pValue,
int32_t& iBytes,
bool bProtoAlso) const;
bool HasMapModuleKey(void* pKey);
void ClearMapModuleBuffer();
void RemoveMapModuleKey(void* pKey);
void MoveBufferMapData(CXFA_Object* pDstModule);
UnownedPtr<CXFA_Object> object_;
UnownedPtr<CXFA_LayoutItem> layout_item_;
std::unique_ptr<CXFA_WidgetData> widget_data_;
std::unique_ptr<XFA_MAPMODULEDATA> map_module_data_;
std::unique_ptr<CXFA_CalcData> calc_data_;
std::map<ByteString, CJX_MethodCall> method_specs_;
size_t calc_recursion_count_ = 0;
};
#endif // FXJS_XFA_CJX_OBJECT_H_
|