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 _FXFA_SCRIPT_IMP_H 8 #define _FXFA_SCRIPT_IMP_H 9 #define XFA_RESOLVENODE_TagName 0x0002 10 #define XFA_JSBUILTIN_Initialized 0x0001 11 #define XFA_JSBUILTIN_HasCount 0x0002 12 class CXFA_ResolveProcessor; 13 class CXFA_ScriptContext : public IXFA_ScriptContext { 14 public: 15 CXFA_ScriptContext(CXFA_Document* pDocument); 16 ~CXFA_ScriptContext(); 17 virtual void Release(); 18 virtual void Initialize(FXJSE_HRUNTIME hRuntime); SetEventParam(CXFA_EventParam * pEventParam)19 virtual void SetEventParam(CXFA_EventParam* pEventParam) { 20 m_pEventParam = pEventParam; 21 } GetEventParam()22 virtual CXFA_EventParam* GetEventParam() { return m_pEventParam; } 23 virtual FX_BOOL RunScript(XFA_SCRIPTLANGTYPE eScriptType, 24 const CFX_WideStringC& wsScript, 25 FXJSE_HVALUE hRetValue, 26 CXFA_Object* pThisObject = NULL); 27 28 virtual int32_t ResolveObjects(CXFA_Object* refNode, 29 const CFX_WideStringC& wsExpression, 30 XFA_RESOLVENODE_RS& resolveNodeRS, 31 FX_DWORD dwStyles = XFA_RESOLVENODE_Children, 32 CXFA_Node* bindNode = NULL); 33 virtual FXJSE_HVALUE GetJSValueFromMap(CXFA_Object* pObject); CacheList(CXFA_NodeList * pList)34 virtual void CacheList(CXFA_NodeList* pList) { m_CacheListArray.Add(pList); } GetThisObject()35 virtual CXFA_Object* GetThisObject() const { return m_pThisObject; } GetRuntime()36 virtual FXJSE_HRUNTIME GetRuntime() const { return m_hJsRuntime; } 37 38 virtual int32_t GetIndexByName(CXFA_Node* refNode); 39 virtual int32_t GetIndexByClassName(CXFA_Node* refNode); 40 virtual void GetSomExpression(CXFA_Node* refNode, 41 CFX_WideString& wsExpression); 42 43 virtual void SetNodesOfRunScript(CXFA_NodeArray* pArray); 44 virtual void AddNodesOfRunScript(const CXFA_NodeArray& nodes); 45 virtual void AddNodesOfRunScript(CXFA_Node* pNode); 46 virtual FXJSE_HCLASS GetJseNormalClass(); 47 48 virtual void AddJSBuiltinObject(XFA_LPCJSBUILTININFO pBuitinObject); SetRunAtType(XFA_ATTRIBUTEENUM eRunAt)49 virtual void SetRunAtType(XFA_ATTRIBUTEENUM eRunAt) { m_eRunAtType = eRunAt; } IsRunAtClient()50 virtual FX_BOOL IsRunAtClient() { 51 return m_eRunAtType != XFA_ATTRIBUTEENUM_Server; 52 } 53 FX_BOOL QueryNodeByFlag(CXFA_Node* refNode, 54 const CFX_WideStringC& propname, 55 FXJSE_HVALUE hValue, 56 FX_DWORD dwFlag, 57 FX_BOOL bSetting); 58 FX_BOOL QueryVariableHValue(CXFA_Node* pScriptNode, 59 const CFX_ByteStringC& szPropName, 60 FXJSE_HVALUE hValue, 61 FX_BOOL bGetter); 62 FX_BOOL QueryBuiltinHValue(const CFX_ByteStringC& szPropName, 63 FXJSE_HVALUE hValue); 64 static void GlobalPropertyGetter(FXJSE_HOBJECT hObject, 65 const CFX_ByteStringC& szPropName, 66 FXJSE_HVALUE hValue); 67 static void GlobalPropertySetter(FXJSE_HOBJECT hObject, 68 const CFX_ByteStringC& szPropName, 69 FXJSE_HVALUE hValue); 70 static void NormalPropertyGetter(FXJSE_HOBJECT hObject, 71 const CFX_ByteStringC& szPropName, 72 FXJSE_HVALUE hValue); 73 static void NormalPropertySetter(FXJSE_HOBJECT hObject, 74 const CFX_ByteStringC& szPropName, 75 FXJSE_HVALUE hValue); 76 static void NormalMethodCall(FXJSE_HOBJECT hThis, 77 const CFX_ByteStringC& szFuncName, 78 CFXJSE_Arguments& args); 79 static int32_t NormalPropTypeGetter(FXJSE_HOBJECT hObject, 80 const CFX_ByteStringC& szPropName, 81 FX_BOOL bQueryIn); 82 static int32_t GlobalPropTypeGetter(FXJSE_HOBJECT hObject, 83 const CFX_ByteStringC& szPropName, 84 FX_BOOL bQueryIn); 85 FX_BOOL RunVariablesScript(CXFA_Node* pScriptNode); 86 CXFA_Object* GetVariablesThis(CXFA_Object* pObject, 87 FX_BOOL bScriptNode = FALSE); 88 void ReleaseVariablesMap(); 89 FX_BOOL IsStrictScopeInJavaScript(); 90 XFA_SCRIPTLANGTYPE GetType(); GetUpObjectArray()91 CXFA_NodeArray& GetUpObjectArray() { return m_upObjectArray; } GetDocument()92 CXFA_Document* GetDocument() const { return m_pDocument; } 93 94 protected: 95 void DefineJsContext(); 96 FXJSE_HCONTEXT CreateVariablesContext(CXFA_Node* pScriptNode, 97 CXFA_Node* pSubform); 98 void DefineJsClass(); 99 100 CXFA_Document* m_pDocument; 101 FXJSE_HCONTEXT m_hJsContext; 102 FXJSE_HRUNTIME m_hJsRuntime; 103 FXJSE_HCLASS m_hJsClass; 104 XFA_SCRIPTLANGTYPE m_eScriptType; 105 FXJSE_CLASS m_JsGlobalClass; 106 FXJSE_CLASS m_JsNormalClass; 107 CFX_MapPtrTemplate<CXFA_Object*, FXJSE_HVALUE> m_mapXFAToHValue; 108 FXJSE_CLASS m_JsGlobalVariablesClass; 109 CFX_MapPtrTemplate<CXFA_Object*, FXJSE_HCONTEXT> m_mapVariableToHValue; 110 CXFA_EventParam* m_pEventParam; 111 CXFA_NodeArray m_upObjectArray; 112 CFX_PtrArray m_CacheListArray; 113 CXFA_NodeArray* m_pScriptNodeArray; 114 CXFA_ResolveProcessor* m_pResolveProcessor; 115 XFA_HFM2JSCONTEXT m_hFM2JSContext; 116 CXFA_Object* m_pThisObject; 117 CFX_CMapByteStringToPtr m_JSBuiltInObjects; 118 FX_DWORD m_dwBuiltInInFlags; 119 XFA_ATTRIBUTEENUM m_eRunAtType; 120 }; 121 #endif 122