• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // 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.
4 
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 
7 #ifndef XFA_FXFA_PARSER_XFA_OBJECT_H_
8 #define XFA_FXFA_PARSER_XFA_OBJECT_H_
9 
10 #include <map>
11 #include <unordered_set>
12 
13 #include "fxjs/cfxjse_arguments.h"
14 #include "xfa/fde/xml/fde_xml.h"
15 #include "xfa/fxfa/parser/xfa_utils.h"
16 
17 class CXFA_Document;
18 class CXFA_Node;
19 class CXFA_NodeList;
20 
21 enum class XFA_ObjectType {
22   Object,
23   List,
24   NodeList,
25   Node,
26   NodeC,
27   NodeV,
28   ModelNode,
29   TextNode,
30   ContainerNode,
31   ContentNode,
32   VariablesThis
33 };
34 
35 enum XFA_NodeFlag {
36   XFA_NodeFlag_None = 0,
37   XFA_NodeFlag_Initialized = 1 << 0,
38   XFA_NodeFlag_HasRemovedChildren = 1 << 1,
39   XFA_NodeFlag_NeedsInitApp = 1 << 2,
40   XFA_NodeFlag_BindFormItems = 1 << 3,
41   XFA_NodeFlag_UserInteractive = 1 << 4,
42   XFA_NodeFlag_SkipDataBinding = 1 << 5,
43   XFA_NodeFlag_OwnXMLNode = 1 << 6,
44   XFA_NodeFlag_UnusedNode = 1 << 7,
45   XFA_NodeFlag_LayoutGeneratedNode = 1 << 8
46 };
47 
48 class CXFA_Object : public CFXJSE_HostObject {
49  public:
50   CXFA_Object(CXFA_Document* pDocument,
51               XFA_ObjectType objectType,
52               XFA_Element eType,
53               const CFX_WideStringC& elementName);
54   ~CXFA_Object() override;
55 
GetDocument()56   CXFA_Document* GetDocument() const { return m_pDocument; }
GetObjectType()57   XFA_ObjectType GetObjectType() const { return m_objectType; }
58 
IsNode()59   bool IsNode() const {
60     return m_objectType == XFA_ObjectType::Node ||
61            m_objectType == XFA_ObjectType::NodeC ||
62            m_objectType == XFA_ObjectType::NodeV ||
63            m_objectType == XFA_ObjectType::ModelNode ||
64            m_objectType == XFA_ObjectType::TextNode ||
65            m_objectType == XFA_ObjectType::ContainerNode ||
66            m_objectType == XFA_ObjectType::ContentNode ||
67            m_objectType == XFA_ObjectType::VariablesThis;
68   }
IsNodeList()69   bool IsNodeList() const { return m_objectType == XFA_ObjectType::NodeList; }
IsContentNode()70   bool IsContentNode() const {
71     return m_objectType == XFA_ObjectType::ContentNode;
72   }
IsContainerNode()73   bool IsContainerNode() const {
74     return m_objectType == XFA_ObjectType::ContainerNode;
75   }
IsModelNode()76   bool IsModelNode() const { return m_objectType == XFA_ObjectType::ModelNode; }
IsNodeV()77   bool IsNodeV() const { return m_objectType == XFA_ObjectType::NodeV; }
IsVariablesThis()78   bool IsVariablesThis() const {
79     return m_objectType == XFA_ObjectType::VariablesThis;
80   }
81 
82   CXFA_Node* AsNode();
83   CXFA_NodeList* AsNodeList();
84 
85   const CXFA_Node* AsNode() const;
86   const CXFA_NodeList* AsNodeList() const;
87 
88   XFA_Element GetElementType() const;
89   CFX_WideStringC GetClassName() const;
90   uint32_t GetClassHashCode() const;
91   void Script_ObjectClass_ClassName(CFXJSE_Value* pValue,
92                                     bool bSetting,
93                                     XFA_ATTRIBUTE eAttribute);
94 
95   void ThrowInvalidPropertyException() const;
96   void ThrowArgumentMismatchException() const;
97   void ThrowIndexOutOfBoundsException() const;
98   void ThrowParamCountMismatchException(const CFX_WideString& method) const;
99 
100  protected:
101   void ThrowException(const FX_WCHAR* str, ...) const;
102 
103   CXFA_Document* const m_pDocument;
104   const XFA_ObjectType m_objectType;
105   const XFA_Element m_elementType;
106 
107   const uint32_t m_elementNameHash;
108   const CFX_WideStringC m_elementName;
109 };
110 using CXFA_ObjArray = CFX_ArrayTemplate<CXFA_Object*>;
111 
112 #define XFA_NODEFILTER_Children 0x01
113 #define XFA_NODEFILTER_Properties 0x02
114 #define XFA_NODEFILTER_OneOfProperty 0x04
115 #define XFA_CLONEFLAG_Content 0x01
116 enum XFA_NODEITEM {
117   XFA_NODEITEM_Parent,
118   XFA_NODEITEM_FirstChild,
119   XFA_NODEITEM_NextSibling,
120   XFA_NODEITEM_PrevSibling,
121 };
122 enum XFA_SOM_MESSAGETYPE {
123   XFA_SOM_ValidationMessage,
124   XFA_SOM_FormatMessage,
125   XFA_SOM_MandatoryMessage
126 };
127 
128 using CXFA_NodeArray = CFX_ArrayTemplate<CXFA_Node*>;
129 using CXFA_NodeStack = CFX_StackTemplate<CXFA_Node*>;
130 using CXFA_NodeSet = std::unordered_set<CXFA_Node*>;
131 
132 typedef void (*PD_CALLBACK_FREEDATA)(void* pData);
133 typedef void (*PD_CALLBACK_DUPLICATEDATA)(void*& pData);
134 
135 struct XFA_MAPDATABLOCKCALLBACKINFO {
136   PD_CALLBACK_FREEDATA pFree;
137   PD_CALLBACK_DUPLICATEDATA pCopy;
138 };
139 
140 struct XFA_MAPDATABLOCK {
GetDataXFA_MAPDATABLOCK141   uint8_t* GetData() const { return (uint8_t*)this + sizeof(XFA_MAPDATABLOCK); }
142   XFA_MAPDATABLOCKCALLBACKINFO* pCallbackInfo;
143   int32_t iBytes;
144 };
145 
146 struct XFA_MAPMODULEDATA {
147   XFA_MAPMODULEDATA();
148   ~XFA_MAPMODULEDATA();
149 
150   std::map<void*, void*> m_ValueMap;
151   std::map<void*, XFA_MAPDATABLOCK*> m_BufferMap;
152 };
153 
154 #define XFA_CalcRefCount (void*)(uintptr_t) FXBSTR_ID('X', 'F', 'A', 'R')
155 #define XFA_CalcData (void*)(uintptr_t) FXBSTR_ID('X', 'F', 'A', 'C')
156 #define XFA_LAYOUTITEMKEY (void*)(uintptr_t) FXBSTR_ID('L', 'Y', 'I', 'M')
157 
158 class CXFA_Node : public CXFA_Object {
159  public:
GetPacketID()160   uint32_t GetPacketID() const { return m_ePacket; }
161 
162   void SetFlag(uint32_t dwFlag, bool bNotify);
163   void ClearFlag(uint32_t dwFlag);
164 
IsInitialized()165   bool IsInitialized() const { return HasFlag(XFA_NodeFlag_Initialized); }
IsOwnXMLNode()166   bool IsOwnXMLNode() const { return HasFlag(XFA_NodeFlag_OwnXMLNode); }
IsUserInteractive()167   bool IsUserInteractive() const {
168     return HasFlag(XFA_NodeFlag_UserInteractive);
169   }
IsUnusedNode()170   bool IsUnusedNode() const { return HasFlag(XFA_NodeFlag_UnusedNode); }
IsLayoutGeneratedNode()171   bool IsLayoutGeneratedNode() const {
172     return HasFlag(XFA_NodeFlag_LayoutGeneratedNode);
173   }
BindsFormItems()174   bool BindsFormItems() const { return HasFlag(XFA_NodeFlag_BindFormItems); }
HasRemovedChildren()175   bool HasRemovedChildren() const {
176     return HasFlag(XFA_NodeFlag_HasRemovedChildren);
177   }
NeedsInitApp()178   bool NeedsInitApp() const { return HasFlag(XFA_NodeFlag_NeedsInitApp); }
179 
180   bool IsAttributeInXML();
IsFormContainer()181   bool IsFormContainer() const {
182     return m_ePacket == XFA_XDPPACKET_Form && IsContainerNode();
183   }
SetXMLMappingNode(CFDE_XMLNode * pXMLNode)184   void SetXMLMappingNode(CFDE_XMLNode* pXMLNode) { m_pXMLNode = pXMLNode; }
GetXMLMappingNode()185   CFDE_XMLNode* GetXMLMappingNode() const { return m_pXMLNode; }
186   CFDE_XMLNode* CreateXMLMappingNode();
187   bool IsNeedSavingXMLNode();
GetNameHash()188   uint32_t GetNameHash() const { return m_dwNameHash; }
IsUnnamed()189   bool IsUnnamed() const { return m_dwNameHash == 0; }
190   CXFA_Node* GetModelNode();
191   void UpdateNameHash();
192   bool HasAttribute(XFA_ATTRIBUTE eAttr, bool bCanInherit = false);
193   bool SetAttribute(XFA_ATTRIBUTE eAttr,
194                     const CFX_WideStringC& wsValue,
195                     bool bNotify = false);
196   bool GetAttribute(XFA_ATTRIBUTE eAttr,
197                     CFX_WideString& wsValue,
198                     bool bUseDefault = true);
199   bool SetAttribute(const CFX_WideStringC& wsAttr,
200                     const CFX_WideStringC& wsValue,
201                     bool bNotify = false);
202   bool GetAttribute(const CFX_WideStringC& wsAttr,
203                     CFX_WideString& wsValue,
204                     bool bUseDefault = true);
205   bool RemoveAttribute(const CFX_WideStringC& wsAttr);
206   bool SetContent(const CFX_WideString& wsContent,
207                   const CFX_WideString& wsXMLValue,
208                   bool bNotify = false,
209                   bool bScriptModify = false,
210                   bool bSyncData = true);
211   bool TryContent(CFX_WideString& wsContent,
212                   bool bScriptModify = false,
213                   bool bProto = true);
214   CFX_WideString GetContent();
215 
216   bool TryNamespace(CFX_WideString& wsNamespace);
217 
218   bool SetBoolean(XFA_ATTRIBUTE eAttr, bool bValue, bool bNotify = false) {
219     return SetValue(eAttr, XFA_ATTRIBUTETYPE_Boolean, (void*)(uintptr_t)bValue,
220                     bNotify);
221   }
222   bool TryBoolean(XFA_ATTRIBUTE eAttr, bool& bValue, bool bUseDefault = true);
GetBoolean(XFA_ATTRIBUTE eAttr)223   bool GetBoolean(XFA_ATTRIBUTE eAttr) {
224     bool bValue;
225     return TryBoolean(eAttr, bValue, true) ? bValue : false;
226   }
227   bool SetInteger(XFA_ATTRIBUTE eAttr, int32_t iValue, bool bNotify = false) {
228     return SetValue(eAttr, XFA_ATTRIBUTETYPE_Integer, (void*)(uintptr_t)iValue,
229                     bNotify);
230   }
231   bool TryInteger(XFA_ATTRIBUTE eAttr,
232                   int32_t& iValue,
233                   bool bUseDefault = true);
GetInteger(XFA_ATTRIBUTE eAttr)234   int32_t GetInteger(XFA_ATTRIBUTE eAttr) {
235     int32_t iValue;
236     return TryInteger(eAttr, iValue, true) ? iValue : 0;
237   }
238   bool SetEnum(XFA_ATTRIBUTE eAttr,
239                XFA_ATTRIBUTEENUM eValue,
240                bool bNotify = false) {
241     return SetValue(eAttr, XFA_ATTRIBUTETYPE_Enum, (void*)(uintptr_t)eValue,
242                     bNotify);
243   }
244   bool TryEnum(XFA_ATTRIBUTE eAttr,
245                XFA_ATTRIBUTEENUM& eValue,
246                bool bUseDefault = true);
GetEnum(XFA_ATTRIBUTE eAttr)247   XFA_ATTRIBUTEENUM GetEnum(XFA_ATTRIBUTE eAttr) {
248     XFA_ATTRIBUTEENUM eValue;
249     return TryEnum(eAttr, eValue, true) ? eValue : XFA_ATTRIBUTEENUM_Unknown;
250   }
251   bool SetCData(XFA_ATTRIBUTE eAttr,
252                 const CFX_WideString& wsValue,
253                 bool bNotify = false,
254                 bool bScriptModify = false);
255   bool SetAttributeValue(const CFX_WideString& wsValue,
256                          const CFX_WideString& wsXMLValue,
257                          bool bNotify = false,
258                          bool bScriptModify = false);
259   bool TryCData(XFA_ATTRIBUTE eAttr,
260                 CFX_WideString& wsValue,
261                 bool bUseDefault = true,
262                 bool bProto = true);
263   bool TryCData(XFA_ATTRIBUTE eAttr,
264                 CFX_WideStringC& wsValue,
265                 bool bUseDefault = true,
266                 bool bProto = true);
GetCData(XFA_ATTRIBUTE eAttr)267   CFX_WideStringC GetCData(XFA_ATTRIBUTE eAttr) {
268     CFX_WideStringC wsValue;
269     return TryCData(eAttr, wsValue) ? wsValue : CFX_WideStringC();
270   }
271   bool SetMeasure(XFA_ATTRIBUTE eAttr,
272                   CXFA_Measurement mValue,
273                   bool bNotify = false);
274   bool TryMeasure(XFA_ATTRIBUTE eAttr,
275                   CXFA_Measurement& mValue,
276                   bool bUseDefault = true) const;
277   CXFA_Measurement GetMeasure(XFA_ATTRIBUTE eAttr) const;
278   bool SetObject(XFA_ATTRIBUTE eAttr,
279                  void* pData,
280                  XFA_MAPDATABLOCKCALLBACKINFO* pCallbackInfo = nullptr);
281   bool TryObject(XFA_ATTRIBUTE eAttr, void*& pData);
GetObject(XFA_ATTRIBUTE eAttr)282   void* GetObject(XFA_ATTRIBUTE eAttr) {
283     void* pData;
284     return TryObject(eAttr, pData) ? pData : nullptr;
285   }
286   bool SetUserData(void* pKey,
287                    void* pData,
288                    XFA_MAPDATABLOCKCALLBACKINFO* pCallbackInfo = nullptr);
289   bool TryUserData(void* pKey, void*& pData, bool bProtoAlso = false);
290   void* GetUserData(void* pKey, bool bProtoAlso = false) {
291     void* pData;
292     return TryUserData(pKey, pData, bProtoAlso) ? pData : nullptr;
293   }
294   CXFA_Node* GetProperty(int32_t index,
295                          XFA_Element eType,
296                          bool bCreateProperty = true);
297   int32_t CountChildren(XFA_Element eType, bool bOnlyChild = false);
298   CXFA_Node* GetChild(int32_t index,
299                       XFA_Element eType,
300                       bool bOnlyChild = false);
301   int32_t InsertChild(int32_t index, CXFA_Node* pNode);
302   bool InsertChild(CXFA_Node* pNode, CXFA_Node* pBeforeNode = nullptr);
303   bool RemoveChild(CXFA_Node* pNode, bool bNotify = true);
304   CXFA_Node* Clone(bool bRecursive);
305   CXFA_Node* GetNodeItem(XFA_NODEITEM eItem) const;
306   CXFA_Node* GetNodeItem(XFA_NODEITEM eItem, XFA_ObjectType eType) const;
307   int32_t GetNodeList(CXFA_NodeArray& nodes,
308                       uint32_t dwTypeFilter = XFA_NODEFILTER_Children |
309                                               XFA_NODEFILTER_Properties,
310                       XFA_Element eTypeFilter = XFA_Element::Unknown,
311                       int32_t iLevel = 1);
312   CXFA_Node* CreateSamePacketNode(XFA_Element eType,
313                                   uint32_t dwFlags = XFA_NodeFlag_Initialized);
314   CXFA_Node* CloneTemplateToForm(bool bRecursive);
315   CXFA_Node* GetTemplateNode() const;
316   void SetTemplateNode(CXFA_Node* pTemplateNode);
317   CXFA_Node* GetDataDescriptionNode();
318   void SetDataDescriptionNode(CXFA_Node* pDataDescriptionNode);
319   CXFA_Node* GetBindData();
320   int32_t GetBindItems(CXFA_NodeArray& formItems);
321   int32_t AddBindItem(CXFA_Node* pFormNode);
322   int32_t RemoveBindItem(CXFA_Node* pFormNode);
323   bool HasBindItem();
324   CXFA_WidgetData* GetWidgetData();
325   CXFA_WidgetData* GetContainerWidgetData();
326   bool GetLocaleName(CFX_WideString& wsLocaleName);
327   XFA_ATTRIBUTEENUM GetIntact();
328   CXFA_Node* GetFirstChildByName(const CFX_WideStringC& wsNodeName) const;
329   CXFA_Node* GetFirstChildByName(uint32_t dwNodeNameHash) const;
330   CXFA_Node* GetFirstChildByClass(XFA_Element eType) const;
331   CXFA_Node* GetNextSameNameSibling(uint32_t dwNodeNameHash) const;
332   CXFA_Node* GetNextSameNameSibling(const CFX_WideStringC& wsNodeName) const;
333   CXFA_Node* GetNextSameClassSibling(XFA_Element eType) const;
334   int32_t GetNodeSameNameIndex() const;
335   int32_t GetNodeSameClassIndex() const;
336   void GetSOMExpression(CFX_WideString& wsSOMExpression);
337   CXFA_Node* GetInstanceMgrOfSubform();
338 
339   CXFA_Node* GetOccurNode();
340   void Script_TreeClass_ResolveNode(CFXJSE_Arguments* pArguments);
341   void Script_TreeClass_ResolveNodes(CFXJSE_Arguments* pArguments);
342   void Script_Som_ResolveNodeList(CFXJSE_Value* pValue,
343                                   CFX_WideString wsExpression,
344                                   uint32_t dwFlag,
345                                   CXFA_Node* refNode = nullptr);
346   void Script_TreeClass_All(CFXJSE_Value* pValue,
347                             bool bSetting,
348                             XFA_ATTRIBUTE eAttribute);
349   void Script_TreeClass_Nodes(CFXJSE_Value* pValue,
350                               bool bSetting,
351                               XFA_ATTRIBUTE eAttribute);
352   void Script_TreeClass_ClassAll(CFXJSE_Value* pValue,
353                                  bool bSetting,
354                                  XFA_ATTRIBUTE eAttribute);
355   void Script_TreeClass_Parent(CFXJSE_Value* pValue,
356                                bool bSetting,
357                                XFA_ATTRIBUTE eAttribute);
358   void Script_TreeClass_Index(CFXJSE_Value* pValue,
359                               bool bSetting,
360                               XFA_ATTRIBUTE eAttribute);
361   void Script_TreeClass_ClassIndex(CFXJSE_Value* pValue,
362                                    bool bSetting,
363                                    XFA_ATTRIBUTE eAttribute);
364   void Script_TreeClass_SomExpression(CFXJSE_Value* pValue,
365                                       bool bSetting,
366                                       XFA_ATTRIBUTE eAttribute);
367   void Script_NodeClass_ApplyXSL(CFXJSE_Arguments* pArguments);
368   void Script_NodeClass_AssignNode(CFXJSE_Arguments* pArguments);
369   void Script_NodeClass_Clone(CFXJSE_Arguments* pArguments);
370   void Script_NodeClass_GetAttribute(CFXJSE_Arguments* pArguments);
371   void Script_NodeClass_GetElement(CFXJSE_Arguments* pArguments);
372   void Script_NodeClass_IsPropertySpecified(CFXJSE_Arguments* pArguments);
373   void Script_NodeClass_LoadXML(CFXJSE_Arguments* pArguments);
374   void Script_NodeClass_SaveFilteredXML(CFXJSE_Arguments* pArguments);
375   void Script_NodeClass_SaveXML(CFXJSE_Arguments* pArguments);
376   void Script_NodeClass_SetAttribute(CFXJSE_Arguments* pArguments);
377   void Script_NodeClass_SetElement(CFXJSE_Arguments* pArguments);
378   void Script_NodeClass_Ns(CFXJSE_Value* pValue,
379                            bool bSetting,
380                            XFA_ATTRIBUTE eAttribute);
381   void Script_NodeClass_Model(CFXJSE_Value* pValue,
382                               bool bSetting,
383                               XFA_ATTRIBUTE eAttribute);
384   void Script_NodeClass_IsContainer(CFXJSE_Value* pValue,
385                                     bool bSetting,
386                                     XFA_ATTRIBUTE eAttribute);
387   void Script_NodeClass_IsNull(CFXJSE_Value* pValue,
388                                bool bSetting,
389                                XFA_ATTRIBUTE eAttribute);
390   void Script_NodeClass_OneOfChild(CFXJSE_Value* pValue,
391                                    bool bSetting,
392                                    XFA_ATTRIBUTE eAttribute);
393   void Script_ContainerClass_GetDelta(CFXJSE_Arguments* pArguments);
394   void Script_ContainerClass_GetDeltas(CFXJSE_Arguments* pArguments);
395   void Script_ModelClass_ClearErrorList(CFXJSE_Arguments* pArguments);
396   void Script_ModelClass_CreateNode(CFXJSE_Arguments* pArguments);
397   void Script_ModelClass_IsCompatibleNS(CFXJSE_Arguments* pArguments);
398   void Script_ModelClass_Context(CFXJSE_Value* pValue,
399                                  bool bSetting,
400                                  XFA_ATTRIBUTE eAttribute);
401   void Script_ModelClass_AliasNode(CFXJSE_Value* pValue,
402                                    bool bSetting,
403                                    XFA_ATTRIBUTE eAttribute);
404   void Script_WsdlConnection_Execute(CFXJSE_Arguments* pArguments);
405   void Script_Delta_Restore(CFXJSE_Arguments* pArguments);
406   void Script_Delta_CurrentValue(CFXJSE_Value* pValue,
407                                  bool bSetting,
408                                  XFA_ATTRIBUTE eAttribute);
409   void Script_Delta_SavedValue(CFXJSE_Value* pValue,
410                                bool bSetting,
411                                XFA_ATTRIBUTE eAttribute);
412   void Script_Delta_Target(CFXJSE_Value* pValue,
413                            bool bSetting,
414                            XFA_ATTRIBUTE eAttribute);
415   void Script_Attribute_SendAttributeChangeMessage(XFA_ATTRIBUTE eAttribute,
416                                                    bool bScriptModify);
417   void Script_Attribute_Integer(CFXJSE_Value* pValue,
418                                 bool bSetting,
419                                 XFA_ATTRIBUTE eAttribute);
420   void Script_Attribute_IntegerRead(CFXJSE_Value* pValue,
421                                     bool bSetting,
422                                     XFA_ATTRIBUTE eAttribute);
423   void Script_Attribute_BOOL(CFXJSE_Value* pValue,
424                              bool bSetting,
425                              XFA_ATTRIBUTE eAttribute);
426   void Script_Attribute_BOOLRead(CFXJSE_Value* pValue,
427                                  bool bSetting,
428                                  XFA_ATTRIBUTE eAttribute);
429   void Script_Attribute_String(CFXJSE_Value* pValue,
430                                bool bSetting,
431                                XFA_ATTRIBUTE eAttribute);
432   void Script_Attribute_StringRead(CFXJSE_Value* pValue,
433                                    bool bSetting,
434                                    XFA_ATTRIBUTE eAttribute);
435   void Script_Som_ValidationMessage(CFXJSE_Value* pValue,
436                                     bool bSetting,
437                                     XFA_ATTRIBUTE eAttribute);
438   void Script_Field_Length(CFXJSE_Value* pValue,
439                            bool bSetting,
440                            XFA_ATTRIBUTE eAttribute);
441   void Script_Som_DefaultValue(CFXJSE_Value* pValue,
442                                bool bSetting,
443                                XFA_ATTRIBUTE eAttribute);
444   void Script_Som_DefaultValue_Read(CFXJSE_Value* pValue,
445                                     bool bSetting,
446                                     XFA_ATTRIBUTE eAttribute);
447   void Script_Boolean_Value(CFXJSE_Value* pValue,
448                             bool bSetting,
449                             XFA_ATTRIBUTE eAttribute);
450   void Script_Som_Message(CFXJSE_Value* pValue,
451                           bool bSetting,
452                           XFA_SOM_MESSAGETYPE iMessageType);
453   void Script_Som_BorderColor(CFXJSE_Value* pValue,
454                               bool bSetting,
455                               XFA_ATTRIBUTE eAttribute);
456   void Script_Som_BorderWidth(CFXJSE_Value* pValue,
457                               bool bSetting,
458                               XFA_ATTRIBUTE eAttribute);
459   void Script_Som_FillColor(CFXJSE_Value* pValue,
460                             bool bSetting,
461                             XFA_ATTRIBUTE eAttribute);
462   void Script_Som_DataNode(CFXJSE_Value* pValue,
463                            bool bSetting,
464                            XFA_ATTRIBUTE eAttribute);
465   void Script_Som_FontColor(CFXJSE_Value* pValue,
466                             bool bSetting,
467                             XFA_ATTRIBUTE eAttribute);
468   void Script_Som_Mandatory(CFXJSE_Value* pValue,
469                             bool bSetting,
470                             XFA_ATTRIBUTE eAttribute);
471   void Script_Som_MandatoryMessage(CFXJSE_Value* pValue,
472                                    bool bSetting,
473                                    XFA_ATTRIBUTE eAttribute);
474   void Script_Som_InstanceIndex(CFXJSE_Value* pValue,
475                                 bool bSetting,
476                                 XFA_ATTRIBUTE eAttribute);
477   void Script_Draw_DefaultValue(CFXJSE_Value* pValue,
478                                 bool bSetting,
479                                 XFA_ATTRIBUTE eAttribute);
480   void Script_Field_DefaultValue(CFXJSE_Value* pValue,
481                                  bool bSetting,
482                                  XFA_ATTRIBUTE eAttribute);
483   void Script_Field_EditValue(CFXJSE_Value* pValue,
484                               bool bSetting,
485                               XFA_ATTRIBUTE eAttribute);
486   void Script_Field_FormatMessage(CFXJSE_Value* pValue,
487                                   bool bSetting,
488                                   XFA_ATTRIBUTE eAttribute);
489   void Script_Field_FormattedValue(CFXJSE_Value* pValue,
490                                    bool bSetting,
491                                    XFA_ATTRIBUTE eAttribute);
492   void Script_Field_ParentSubform(CFXJSE_Value* pValue,
493                                   bool bSetting,
494                                   XFA_ATTRIBUTE eAttribute);
495   void Script_Field_SelectedIndex(CFXJSE_Value* pValue,
496                                   bool bSetting,
497                                   XFA_ATTRIBUTE eAttribute);
498   void Script_Field_ClearItems(CFXJSE_Arguments* pArguments);
499   void Script_Field_ExecEvent(CFXJSE_Arguments* pArguments);
500   void Script_Field_ExecInitialize(CFXJSE_Arguments* pArguments);
501   void Script_Field_DeleteItem(CFXJSE_Arguments* pArguments);
502   void Script_Field_GetSaveItem(CFXJSE_Arguments* pArguments);
503   void Script_Field_BoundItem(CFXJSE_Arguments* pArguments);
504   void Script_Field_GetItemState(CFXJSE_Arguments* pArguments);
505   void Script_Field_ExecCalculate(CFXJSE_Arguments* pArguments);
506   void Script_Field_SetItems(CFXJSE_Arguments* pArguments);
507   void Script_Field_GetDisplayItem(CFXJSE_Arguments* pArguments);
508   void Script_Field_SetItemState(CFXJSE_Arguments* pArguments);
509   void Script_Field_AddItem(CFXJSE_Arguments* pArguments);
510   void Script_Field_ExecValidate(CFXJSE_Arguments* pArguments);
511   void Script_ExclGroup_DefaultAndRawValue(CFXJSE_Value* pValue,
512                                            bool bSetting,
513                                            XFA_ATTRIBUTE eAttribute);
514   void Script_ExclGroup_ErrorText(CFXJSE_Value* pValue,
515                                   bool bSetting,
516                                   XFA_ATTRIBUTE eAttribute);
517   void Script_ExclGroup_Transient(CFXJSE_Value* pValue,
518                                   bool bSetting,
519                                   XFA_ATTRIBUTE eAttribute);
520   void Script_ExclGroup_ExecEvent(CFXJSE_Arguments* pArguments);
521   void Script_ExclGroup_SelectedMember(CFXJSE_Arguments* pArguments);
522   void Script_ExclGroup_ExecInitialize(CFXJSE_Arguments* pArguments);
523   void Script_ExclGroup_ExecCalculate(CFXJSE_Arguments* pArguments);
524   void Script_ExclGroup_ExecValidate(CFXJSE_Arguments* pArguments);
525   void Script_Subform_InstanceManager(CFXJSE_Value* pValue,
526                                       bool bSetting,
527                                       XFA_ATTRIBUTE eAttribute);
528   void Script_Subform_Locale(CFXJSE_Value* pValue,
529                              bool bSetting,
530                              XFA_ATTRIBUTE eAttribute);
531   void Script_Subform_ExecEvent(CFXJSE_Arguments* pArguments);
532   void Script_Subform_ExecInitialize(CFXJSE_Arguments* pArguments);
533   void Script_Subform_ExecCalculate(CFXJSE_Arguments* pArguments);
534   void Script_Subform_ExecValidate(CFXJSE_Arguments* pArguments);
535   void Script_Subform_GetInvalidObjects(CFXJSE_Arguments* pArguments);
536 
537   int32_t Subform_and_SubformSet_InstanceIndex();
538   void Script_Template_FormNodes(CFXJSE_Arguments* pArguments);
539   void Script_Template_Remerge(CFXJSE_Arguments* pArguments);
540   void Script_Template_ExecInitialize(CFXJSE_Arguments* pArguments);
541   void Script_Template_CreateNode(CFXJSE_Arguments* pArguments);
542   void Script_Template_Recalculate(CFXJSE_Arguments* pArguments);
543   void Script_Template_ExecCalculate(CFXJSE_Arguments* pArguments);
544   void Script_Template_ExecValidate(CFXJSE_Arguments* pArguments);
545   void Script_Manifest_Evaluate(CFXJSE_Arguments* pArguments);
546   void Script_InstanceManager_Count(CFXJSE_Value* pValue,
547                                     bool bSetting,
548                                     XFA_ATTRIBUTE eAttribute);
549   void Script_InstanceManager_Max(CFXJSE_Value* pValue,
550                                   bool bSetting,
551                                   XFA_ATTRIBUTE eAttribute);
552   void Script_InstanceManager_Min(CFXJSE_Value* pValue,
553                                   bool bSetting,
554                                   XFA_ATTRIBUTE eAttribute);
555   void Script_InstanceManager_MoveInstance(CFXJSE_Arguments* pArguments);
556   void Script_InstanceManager_RemoveInstance(CFXJSE_Arguments* pArguments);
557   void Script_InstanceManager_SetInstances(CFXJSE_Arguments* pArguments);
558   void Script_InstanceManager_AddInstance(CFXJSE_Arguments* pArguments);
559   void Script_InstanceManager_InsertInstance(CFXJSE_Arguments* pArguments);
560   int32_t InstanceManager_SetInstances(int32_t iCount);
561   int32_t InstanceManager_MoveInstance(int32_t iTo, int32_t iFrom);
562   void Script_Occur_Max(CFXJSE_Value* pValue,
563                         bool bSetting,
564                         XFA_ATTRIBUTE eAttribute);
565   void Script_Occur_Min(CFXJSE_Value* pValue,
566                         bool bSetting,
567                         XFA_ATTRIBUTE eAttribute);
568   void Script_Desc_Metadata(CFXJSE_Arguments* pArguments);
569   void Script_Form_FormNodes(CFXJSE_Arguments* pArguments);
570   void Script_Form_Remerge(CFXJSE_Arguments* pArguments);
571   void Script_Form_ExecInitialize(CFXJSE_Arguments* pArguments);
572   void Script_Form_Recalculate(CFXJSE_Arguments* pArguments);
573   void Script_Form_ExecCalculate(CFXJSE_Arguments* pArguments);
574   void Script_Form_ExecValidate(CFXJSE_Arguments* pArguments);
575   void Script_Form_Checksum(CFXJSE_Value* pValue,
576                             bool bSetting,
577                             XFA_ATTRIBUTE eAttribute);
578   void Script_Packet_GetAttribute(CFXJSE_Arguments* pArguments);
579   void Script_Packet_SetAttribute(CFXJSE_Arguments* pArguments);
580   void Script_Packet_RemoveAttribute(CFXJSE_Arguments* pArguments);
581   void Script_Packet_Content(CFXJSE_Value* pValue,
582                              bool bSetting,
583                              XFA_ATTRIBUTE eAttribute);
584   void Script_Source_Next(CFXJSE_Arguments* pArguments);
585   void Script_Source_CancelBatch(CFXJSE_Arguments* pArguments);
586   void Script_Source_First(CFXJSE_Arguments* pArguments);
587   void Script_Source_UpdateBatch(CFXJSE_Arguments* pArguments);
588   void Script_Source_Previous(CFXJSE_Arguments* pArguments);
589   void Script_Source_IsBOF(CFXJSE_Arguments* pArguments);
590   void Script_Source_IsEOF(CFXJSE_Arguments* pArguments);
591   void Script_Source_Cancel(CFXJSE_Arguments* pArguments);
592   void Script_Source_Update(CFXJSE_Arguments* pArguments);
593   void Script_Source_Open(CFXJSE_Arguments* pArguments);
594   void Script_Source_Delete(CFXJSE_Arguments* pArguments);
595   void Script_Source_AddNew(CFXJSE_Arguments* pArguments);
596   void Script_Source_Requery(CFXJSE_Arguments* pArguments);
597   void Script_Source_Resync(CFXJSE_Arguments* pArguments);
598   void Script_Source_Close(CFXJSE_Arguments* pArguments);
599   void Script_Source_Last(CFXJSE_Arguments* pArguments);
600   void Script_Source_HasDataChanged(CFXJSE_Arguments* pArguments);
601   void Script_Source_Db(CFXJSE_Value* pValue,
602                         bool bSetting,
603                         XFA_ATTRIBUTE eAttribute);
604   void Script_Xfa_This(CFXJSE_Value* pValue,
605                        bool bSetting,
606                        XFA_ATTRIBUTE eAttribute);
607   void Script_Handler_Version(CFXJSE_Value* pValue,
608                               bool bSetting,
609                               XFA_ATTRIBUTE eAttribute);
610   void Script_SubmitFormat_Mode(CFXJSE_Value* pValue,
611                                 bool bSetting,
612                                 XFA_ATTRIBUTE eAttribute);
613   void Script_Extras_Type(CFXJSE_Value* pValue,
614                           bool bSetting,
615                           XFA_ATTRIBUTE eAttribute);
616   void Script_Encrypt_Format(CFXJSE_Value* pValue,
617                              bool bSetting,
618                              XFA_ATTRIBUTE eAttribute);
619   void Script_Script_Stateless(CFXJSE_Value* pValue,
620                                bool bSetting,
621                                XFA_ATTRIBUTE eAttribute);
622 
623  protected:
624   friend class CXFA_Document;
625 
626   CXFA_Node(CXFA_Document* pDoc,
627             uint16_t ePacket,
628             XFA_ObjectType oType,
629             XFA_Element eType,
630             const CFX_WideStringC& elementName);
631   ~CXFA_Node() override;
632 
633   bool HasFlag(XFA_NodeFlag dwFlag) const;
634   CXFA_Node* Deprecated_GetPrevSibling();
635   bool SetValue(XFA_ATTRIBUTE eAttr,
636                 XFA_ATTRIBUTETYPE eType,
637                 void* pValue,
638                 bool bNotify);
639   bool GetValue(XFA_ATTRIBUTE eAttr,
640                 XFA_ATTRIBUTETYPE eType,
641                 bool bUseDefault,
642                 void*& pValue);
643   void OnRemoved(bool bNotify);
644   void OnChanging(XFA_ATTRIBUTE eAttr, bool bNotify);
645   void OnChanged(XFA_ATTRIBUTE eAttr, bool bNotify, bool bScriptModify);
646   int32_t execSingleEventByName(const CFX_WideStringC& wsEventName,
647                                 XFA_Element eType);
648   bool SetScriptContent(const CFX_WideString& wsContent,
649                         const CFX_WideString& wsXMLValue,
650                         bool bNotify = true,
651                         bool bScriptModify = false,
652                         bool bSyncData = true);
653   CFX_WideString GetScriptContent(bool bScriptModify = false);
654   XFA_MAPMODULEDATA* CreateMapModuleData();
655   XFA_MAPMODULEDATA* GetMapModuleData() const;
656   void SetMapModuleValue(void* pKey, void* pValue);
657   bool GetMapModuleValue(void* pKey, void*& pValue);
658   void SetMapModuleString(void* pKey, const CFX_WideStringC& wsValue);
659   bool GetMapModuleString(void* pKey, CFX_WideStringC& wsValue);
660   void SetMapModuleBuffer(
661       void* pKey,
662       void* pValue,
663       int32_t iBytes,
664       XFA_MAPDATABLOCKCALLBACKINFO* pCallbackInfo = nullptr);
665   bool GetMapModuleBuffer(void* pKey,
666                           void*& pValue,
667                           int32_t& iBytes,
668                           bool bProtoAlso = true) const;
669   bool HasMapModuleKey(void* pKey, bool bProtoAlso = false);
670   void RemoveMapModuleKey(void* pKey = nullptr);
671   void MergeAllData(void* pDstModule);
672   void MoveBufferMapData(CXFA_Node* pDstModule, void* pKey);
673   void MoveBufferMapData(CXFA_Node* pSrcModule,
674                          CXFA_Node* pDstModule,
675                          void* pKey,
676                          bool bRecursive = false);
677 
678   CXFA_Node* m_pNext;
679   CXFA_Node* m_pChild;
680   CXFA_Node* m_pLastChild;
681   CXFA_Node* m_pParent;
682   CFDE_XMLNode* m_pXMLNode;
683   uint16_t m_ePacket;
684   uint16_t m_uNodeFlags;
685   uint32_t m_dwNameHash;
686   CXFA_Node* m_pAuxNode;
687   XFA_MAPMODULEDATA* m_pMapModuleData;
688 
689  private:
690   void ThrowMissingPropertyException(const CFX_WideString& obj,
691                                      const CFX_WideString& prop) const;
692   void ThrowTooManyOccurancesException(const CFX_WideString& obj) const;
693 };
694 
695 class CXFA_ThisProxy : public CXFA_Object {
696  public:
697   CXFA_ThisProxy(CXFA_Node* pThisNode, CXFA_Node* pScriptNode);
698   ~CXFA_ThisProxy() override;
699 
700   CXFA_Node* GetThisNode() const;
701   CXFA_Node* GetScriptNode() const;
702 
703  private:
704   CXFA_Node* m_pThisNode;
705   CXFA_Node* m_pScriptNode;
706 };
707 
708 class CXFA_NodeList : public CXFA_Object {
709  public:
710   explicit CXFA_NodeList(CXFA_Document* pDocument);
711   ~CXFA_NodeList() override;
712 
713   CXFA_Node* NamedItem(const CFX_WideStringC& wsName);
714   virtual int32_t GetLength() = 0;
715   virtual bool Append(CXFA_Node* pNode) = 0;
716   virtual bool Insert(CXFA_Node* pNewNode, CXFA_Node* pBeforeNode) = 0;
717   virtual bool Remove(CXFA_Node* pNode) = 0;
718   virtual CXFA_Node* Item(int32_t iIndex) = 0;
719 
720   void Script_ListClass_Append(CFXJSE_Arguments* pArguments);
721   void Script_ListClass_Insert(CFXJSE_Arguments* pArguments);
722   void Script_ListClass_Remove(CFXJSE_Arguments* pArguments);
723   void Script_ListClass_Item(CFXJSE_Arguments* pArguments);
724 
725   void Script_TreelistClass_NamedItem(CFXJSE_Arguments* pArguments);
726   void Script_ListClass_Length(CFXJSE_Value* pValue,
727                                bool bSetting,
728                                XFA_ATTRIBUTE eAttribute);
729 };
730 
731 class CXFA_ArrayNodeList : public CXFA_NodeList {
732  public:
733   explicit CXFA_ArrayNodeList(CXFA_Document* pDocument);
734   ~CXFA_ArrayNodeList() override;
735 
736   // From CXFA_NodeList.
737   int32_t GetLength() override;
738   bool Append(CXFA_Node* pNode) override;
739   bool Insert(CXFA_Node* pNewNode, CXFA_Node* pBeforeNode) override;
740   bool Remove(CXFA_Node* pNode) override;
741   CXFA_Node* Item(int32_t iIndex) override;
742 
743   void SetArrayNodeList(const CXFA_NodeArray& srcArray);
744 
745  protected:
746   CXFA_NodeArray m_array;
747 };
748 
749 class CXFA_AttachNodeList : public CXFA_NodeList {
750  public:
751   CXFA_AttachNodeList(CXFA_Document* pDocument, CXFA_Node* pAttachNode);
752 
753   // From CXFA_NodeList.
754   int32_t GetLength() override;
755   bool Append(CXFA_Node* pNode) override;
756   bool Insert(CXFA_Node* pNewNode, CXFA_Node* pBeforeNode) override;
757   bool Remove(CXFA_Node* pNode) override;
758   CXFA_Node* Item(int32_t iIndex) override;
759 
760  protected:
761   CXFA_Node* m_pAttachNode;
762 };
763 class CXFA_TraverseStrategy_XFAContainerNode {
764  public:
765   static CXFA_Node* GetFirstChild(CXFA_Node* pTemplateNode,
766                                   void* pUserData = nullptr) {
767     return pTemplateNode->GetNodeItem(XFA_NODEITEM_FirstChild,
768                                       XFA_ObjectType::ContainerNode);
769   }
770   static CXFA_Node* GetNextSibling(CXFA_Node* pTemplateNode,
771                                    void* pUserData = nullptr) {
772     return pTemplateNode->GetNodeItem(XFA_NODEITEM_NextSibling,
773                                       XFA_ObjectType::ContainerNode);
774   }
775   static CXFA_Node* GetParent(CXFA_Node* pTemplateNode,
776                               void* pUserData = nullptr) {
777     return pTemplateNode->GetNodeItem(XFA_NODEITEM_Parent,
778                                       XFA_ObjectType::ContainerNode);
779   }
780 };
781 typedef CXFA_NodeIteratorTemplate<CXFA_Node,
782                                   CXFA_TraverseStrategy_XFAContainerNode>
783     CXFA_ContainerIterator;
784 class CXFA_TraverseStrategy_XFANode {
785  public:
GetFirstChild(CXFA_Node * pTemplateNode)786   static inline CXFA_Node* GetFirstChild(CXFA_Node* pTemplateNode) {
787     return pTemplateNode->GetNodeItem(XFA_NODEITEM_FirstChild);
788   }
GetNextSibling(CXFA_Node * pTemplateNode)789   static inline CXFA_Node* GetNextSibling(CXFA_Node* pTemplateNode) {
790     return pTemplateNode->GetNodeItem(XFA_NODEITEM_NextSibling);
791   }
GetParent(CXFA_Node * pTemplateNode)792   static inline CXFA_Node* GetParent(CXFA_Node* pTemplateNode) {
793     return pTemplateNode->GetNodeItem(XFA_NODEITEM_Parent);
794   }
795 };
796 typedef CXFA_NodeIteratorTemplate<CXFA_Node, CXFA_TraverseStrategy_XFANode>
797     CXFA_NodeIterator;
798 
AsNode()799 inline CXFA_Node* CXFA_Object::AsNode() {
800   return IsNode() ? static_cast<CXFA_Node*>(this) : nullptr;
801 }
802 
AsNodeList()803 inline CXFA_NodeList* CXFA_Object::AsNodeList() {
804   return IsNodeList() ? static_cast<CXFA_NodeList*>(this) : nullptr;
805 }
806 
AsNode()807 inline const CXFA_Node* CXFA_Object::AsNode() const {
808   return IsNode() ? static_cast<const CXFA_Node*>(this) : nullptr;
809 }
810 
AsNodeList()811 inline const CXFA_NodeList* CXFA_Object::AsNodeList() const {
812   return IsNodeList() ? static_cast<const CXFA_NodeList*>(this) : nullptr;
813 }
814 
ToNode(CXFA_Object * pObj)815 inline CXFA_Node* ToNode(CXFA_Object* pObj) {
816   return pObj ? pObj->AsNode() : nullptr;
817 }
818 
ToNode(const CXFA_Object * pObj)819 inline const CXFA_Node* ToNode(const CXFA_Object* pObj) {
820   return pObj ? pObj->AsNode() : nullptr;
821 }
822 
823 #endif  // XFA_FXFA_PARSER_XFA_OBJECT_H_
824