OLD | NEW |
| (Empty) |
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_SCRIPT_IMP_H_ | |
8 #define XFA_FXFA_PARSER_XFA_SCRIPT_IMP_H_ | |
9 | |
10 #include <map> | |
11 #include <memory> | |
12 #include <vector> | |
13 | |
14 #include "fxjs/include/cfxjse_arguments.h" | |
15 #include "xfa/fxfa/fm2js/xfa_fm2jscontext.h" | |
16 #include "xfa/fxfa/include/cxfa_eventparam.h" | |
17 #include "xfa/fxfa/parser/xfa_document.h" | |
18 #include "xfa/fxfa/parser/xfa_script.h" | |
19 | |
20 #define XFA_RESOLVENODE_TagName 0x0002 | |
21 | |
22 class CXFA_ResolveProcessor; | |
23 | |
24 class CXFA_ScriptContext { | |
25 public: | |
26 explicit CXFA_ScriptContext(CXFA_Document* pDocument); | |
27 ~CXFA_ScriptContext(); | |
28 | |
29 void Initialize(v8::Isolate* pIsolate); | |
30 void SetEventParam(CXFA_EventParam param) { m_eventParam = param; } | |
31 CXFA_EventParam* GetEventParam() { return &m_eventParam; } | |
32 FX_BOOL RunScript(XFA_SCRIPTLANGTYPE eScriptType, | |
33 const CFX_WideStringC& wsScript, | |
34 CFXJSE_Value* pRetValue, | |
35 CXFA_Object* pThisObject = nullptr); | |
36 | |
37 int32_t ResolveObjects(CXFA_Object* refNode, | |
38 const CFX_WideStringC& wsExpression, | |
39 XFA_RESOLVENODE_RS& resolveNodeRS, | |
40 uint32_t dwStyles = XFA_RESOLVENODE_Children, | |
41 CXFA_Node* bindNode = nullptr); | |
42 CFXJSE_Value* GetJSValueFromMap(CXFA_Object* pObject); | |
43 void AddToCacheList(std::unique_ptr<CXFA_NodeList> pList); | |
44 CXFA_Object* GetThisObject() const { return m_pThisObject; } | |
45 v8::Isolate* GetRuntime() const { return m_pIsolate; } | |
46 | |
47 int32_t GetIndexByName(CXFA_Node* refNode); | |
48 int32_t GetIndexByClassName(CXFA_Node* refNode); | |
49 void GetSomExpression(CXFA_Node* refNode, CFX_WideString& wsExpression); | |
50 | |
51 void SetNodesOfRunScript(CXFA_NodeArray* pArray); | |
52 void AddNodesOfRunScript(const CXFA_NodeArray& nodes); | |
53 void AddNodesOfRunScript(CXFA_Node* pNode); | |
54 CFXJSE_Class* GetJseNormalClass(); | |
55 | |
56 void SetRunAtType(XFA_ATTRIBUTEENUM eRunAt) { m_eRunAtType = eRunAt; } | |
57 FX_BOOL IsRunAtClient() { return m_eRunAtType != XFA_ATTRIBUTEENUM_Server; } | |
58 FX_BOOL QueryNodeByFlag(CXFA_Node* refNode, | |
59 const CFX_WideStringC& propname, | |
60 CFXJSE_Value* pValue, | |
61 uint32_t dwFlag, | |
62 FX_BOOL bSetting); | |
63 FX_BOOL QueryVariableValue(CXFA_Node* pScriptNode, | |
64 const CFX_ByteStringC& szPropName, | |
65 CFXJSE_Value* pValue, | |
66 FX_BOOL bGetter); | |
67 FX_BOOL QueryBuiltinValue(const CFX_ByteStringC& szPropName, | |
68 CFXJSE_Value* pValue); | |
69 static void GlobalPropertyGetter(CFXJSE_Value* pObject, | |
70 const CFX_ByteStringC& szPropName, | |
71 CFXJSE_Value* pValue); | |
72 static void GlobalPropertySetter(CFXJSE_Value* pObject, | |
73 const CFX_ByteStringC& szPropName, | |
74 CFXJSE_Value* pValue); | |
75 static void NormalPropertyGetter(CFXJSE_Value* pObject, | |
76 const CFX_ByteStringC& szPropName, | |
77 CFXJSE_Value* pValue); | |
78 static void NormalPropertySetter(CFXJSE_Value* pObject, | |
79 const CFX_ByteStringC& szPropName, | |
80 CFXJSE_Value* pValue); | |
81 static void NormalMethodCall(CFXJSE_Value* hThis, | |
82 const CFX_ByteStringC& szFuncName, | |
83 CFXJSE_Arguments& args); | |
84 static int32_t NormalPropTypeGetter(CFXJSE_Value* pObject, | |
85 const CFX_ByteStringC& szPropName, | |
86 FX_BOOL bQueryIn); | |
87 static int32_t GlobalPropTypeGetter(CFXJSE_Value* pObject, | |
88 const CFX_ByteStringC& szPropName, | |
89 FX_BOOL bQueryIn); | |
90 FX_BOOL RunVariablesScript(CXFA_Node* pScriptNode); | |
91 CXFA_Object* GetVariablesThis(CXFA_Object* pObject, | |
92 FX_BOOL bScriptNode = FALSE); | |
93 FX_BOOL IsStrictScopeInJavaScript(); | |
94 XFA_SCRIPTLANGTYPE GetType(); | |
95 CXFA_NodeArray& GetUpObjectArray() { return m_upObjectArray; } | |
96 CXFA_Document* GetDocument() const { return m_pDocument; } | |
97 | |
98 static CXFA_Object* ToObject(CFXJSE_Value* pValue, CFXJSE_Class* pClass); | |
99 | |
100 private: | |
101 void DefineJsContext(); | |
102 CFXJSE_Context* CreateVariablesContext(CXFA_Node* pScriptNode, | |
103 CXFA_Node* pSubform); | |
104 void DefineJsClass(); | |
105 void RemoveBuiltInObjs(CFXJSE_Context* pContext) const; | |
106 | |
107 CXFA_Document* m_pDocument; | |
108 std::unique_ptr<CFXJSE_Context> m_JsContext; | |
109 v8::Isolate* m_pIsolate; | |
110 CFXJSE_Class* m_pJsClass; | |
111 XFA_SCRIPTLANGTYPE m_eScriptType; | |
112 std::map<CXFA_Object*, std::unique_ptr<CFXJSE_Value>> m_mapObjectToValue; | |
113 CFX_MapPtrTemplate<CXFA_Object*, CFXJSE_Context*> m_mapVariableToContext; | |
114 CXFA_EventParam m_eventParam; | |
115 CXFA_NodeArray m_upObjectArray; | |
116 // CacheList holds the NodeList items so we can clean them up when we're done. | |
117 std::vector<std::unique_ptr<CXFA_NodeList>> m_CacheList; | |
118 CXFA_NodeArray* m_pScriptNodeArray; | |
119 std::unique_ptr<CXFA_ResolveProcessor> m_ResolveProcessor; | |
120 std::unique_ptr<CXFA_FM2JSContext> m_FM2JSContext; | |
121 CXFA_Object* m_pThisObject; | |
122 uint32_t m_dwBuiltInInFlags; | |
123 XFA_ATTRIBUTEENUM m_eRunAtType; | |
124 }; | |
125 | |
126 #endif // XFA_FXFA_PARSER_XFA_SCRIPT_IMP_H_ | |
OLD | NEW |