OLD | NEW |
1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 | 6 |
7 #include "xfa/fxfa/parser/xfa_script_imp.h" | 7 #include "xfa/fxfa/parser/xfa_script_imp.h" |
8 | 8 |
9 #include "core/fxcrt/include/fx_ext.h" | 9 #include "core/fxcrt/include/fx_ext.h" |
10 #include "xfa/fxfa/app/xfa_ffnotify.h" | 10 #include "xfa/fxfa/app/xfa_ffnotify.h" |
11 #include "xfa/fxfa/fm2js/xfa_fm2jsapi.h" | |
12 #include "xfa/fxfa/parser/xfa_doclayout.h" | 11 #include "xfa/fxfa/parser/xfa_doclayout.h" |
13 #include "xfa/fxfa/parser/xfa_document.h" | 12 #include "xfa/fxfa/parser/xfa_document.h" |
14 #include "xfa/fxfa/parser/xfa_localemgr.h" | 13 #include "xfa/fxfa/parser/xfa_localemgr.h" |
15 #include "xfa/fxfa/parser/xfa_object.h" | 14 #include "xfa/fxfa/parser/xfa_object.h" |
16 #include "xfa/fxfa/parser/xfa_parser.h" | 15 #include "xfa/fxfa/parser/xfa_parser.h" |
17 #include "xfa/fxfa/parser/xfa_script.h" | 16 #include "xfa/fxfa/parser/xfa_script.h" |
18 #include "xfa/fxfa/parser/xfa_script_nodehelper.h" | 17 #include "xfa/fxfa/parser/xfa_script_nodehelper.h" |
19 #include "xfa/fxfa/parser/xfa_script_resolveprocessor.h" | 18 #include "xfa/fxfa/parser/xfa_script_resolveprocessor.h" |
20 #include "xfa/fxfa/parser/xfa_utils.h" | 19 #include "xfa/fxfa/parser/xfa_utils.h" |
21 #include "xfa/fxjse/cfxjse_arguments.h" | 20 #include "xfa/fxjse/cfxjse_arguments.h" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 nullptr, // methods | 57 nullptr, // methods |
59 0, // property count | 58 0, // property count |
60 0, // method count | 59 0, // method count |
61 CXFA_ScriptContext::NormalPropTypeGetter, | 60 CXFA_ScriptContext::NormalPropTypeGetter, |
62 CXFA_ScriptContext::GlobalPropertyGetter, | 61 CXFA_ScriptContext::GlobalPropertyGetter, |
63 CXFA_ScriptContext::GlobalPropertySetter, | 62 CXFA_ScriptContext::GlobalPropertySetter, |
64 nullptr, // property deleter | 63 nullptr, // property deleter |
65 CXFA_ScriptContext::NormalMethodCall, | 64 CXFA_ScriptContext::NormalMethodCall, |
66 }; | 65 }; |
67 | 66 |
| 67 const char kFormCalcRuntime[] = "foxit_xfa_formcalc_runtime"; |
| 68 |
68 } // namespace | 69 } // namespace |
69 | 70 |
70 CXFA_ScriptContext::CXFA_ScriptContext(CXFA_Document* pDocument) | 71 CXFA_ScriptContext::CXFA_ScriptContext(CXFA_Document* pDocument) |
71 : m_pDocument(pDocument), | 72 : m_pDocument(pDocument), |
72 m_pJsContext(nullptr), | 73 m_pJsContext(nullptr), |
73 m_pIsolate(nullptr), | 74 m_pIsolate(nullptr), |
74 m_pJsClass(nullptr), | 75 m_pJsClass(nullptr), |
75 m_eScriptType(XFA_SCRIPTLANGTYPE_Unkown), | 76 m_eScriptType(XFA_SCRIPTLANGTYPE_Unkown), |
76 m_pScriptNodeArray(nullptr), | 77 m_pScriptNodeArray(nullptr), |
77 m_pResolveProcessor(nullptr), | 78 m_pResolveProcessor(nullptr), |
78 m_hFM2JSContext(nullptr), | 79 m_hFM2JSContext(nullptr), |
79 m_pThisObject(nullptr), | 80 m_pThisObject(nullptr), |
80 m_dwBuiltInInFlags(0), | 81 m_dwBuiltInInFlags(0), |
81 m_eRunAtType(XFA_ATTRIBUTEENUM_Client) { | 82 m_eRunAtType(XFA_ATTRIBUTEENUM_Client) { |
82 } | 83 } |
| 84 |
83 CXFA_ScriptContext::~CXFA_ScriptContext() { | 85 CXFA_ScriptContext::~CXFA_ScriptContext() { |
84 FX_POSITION ps = m_mapXFAToValue.GetStartPosition(); | 86 FX_POSITION ps = m_mapXFAToValue.GetStartPosition(); |
85 while (ps) { | 87 while (ps) { |
86 CXFA_Object* pXFAObj; | 88 CXFA_Object* pXFAObj; |
87 CFXJSE_Value* pValue; | 89 CFXJSE_Value* pValue; |
88 m_mapXFAToValue.GetNextAssoc(ps, pXFAObj, pValue); | 90 m_mapXFAToValue.GetNextAssoc(ps, pXFAObj, pValue); |
89 delete pValue; | 91 delete pValue; |
90 } | 92 } |
91 m_mapXFAToValue.RemoveAll(); | 93 m_mapXFAToValue.RemoveAll(); |
92 ReleaseVariablesMap(); | 94 ReleaseVariablesMap(); |
93 if (m_hFM2JSContext) { | 95 |
94 XFA_FM2JS_ContextRelease(m_hFM2JSContext); | 96 delete m_hFM2JSContext; |
95 m_hFM2JSContext = NULL; | 97 |
96 } | |
97 if (m_pJsContext) { | 98 if (m_pJsContext) { |
98 FXJSE_Context_Release(m_pJsContext); | 99 FXJSE_Context_Release(m_pJsContext); |
99 m_pJsContext = NULL; | 100 m_pJsContext = NULL; |
100 } | 101 } |
101 delete m_pResolveProcessor; | 102 delete m_pResolveProcessor; |
102 m_upObjectArray.RemoveAll(); | 103 m_upObjectArray.RemoveAll(); |
103 for (int32_t i = 0; i < m_CacheListArray.GetSize(); i++) | 104 for (int32_t i = 0; i < m_CacheListArray.GetSize(); i++) |
104 delete m_CacheListArray[i]; | 105 delete m_CacheListArray[i]; |
105 } | 106 } |
106 void CXFA_ScriptContext::Initialize(v8::Isolate* pIsolate) { | 107 void CXFA_ScriptContext::Initialize(v8::Isolate* pIsolate) { |
107 m_pIsolate = pIsolate; | 108 m_pIsolate = pIsolate; |
108 DefineJsContext(); | 109 DefineJsContext(); |
109 DefineJsClass(); | 110 DefineJsClass(); |
110 m_pResolveProcessor = new CXFA_ResolveProcessor; | 111 m_pResolveProcessor = new CXFA_ResolveProcessor; |
111 } | 112 } |
112 FX_BOOL CXFA_ScriptContext::RunScript(XFA_SCRIPTLANGTYPE eScriptType, | 113 FX_BOOL CXFA_ScriptContext::RunScript(XFA_SCRIPTLANGTYPE eScriptType, |
113 const CFX_WideStringC& wsScript, | 114 const CFX_WideStringC& wsScript, |
114 CFXJSE_Value* hRetValue, | 115 CFXJSE_Value* hRetValue, |
115 CXFA_Object* pThisObject) { | 116 CXFA_Object* pThisObject) { |
116 CFX_ByteString btScript; | 117 CFX_ByteString btScript; |
117 XFA_SCRIPTLANGTYPE eSaveType = m_eScriptType; | 118 XFA_SCRIPTLANGTYPE eSaveType = m_eScriptType; |
118 m_eScriptType = eScriptType; | 119 m_eScriptType = eScriptType; |
119 if (eScriptType == XFA_SCRIPTLANGTYPE_Formcalc) { | 120 if (eScriptType == XFA_SCRIPTLANGTYPE_Formcalc) { |
120 if (!m_hFM2JSContext) { | 121 if (!m_hFM2JSContext) { |
121 m_hFM2JSContext = | 122 m_hFM2JSContext = |
122 XFA_FM2JS_ContextCreate(m_pIsolate, m_pJsContext, m_pDocument); | 123 new CXFA_FM2JSContext(m_pIsolate, m_pJsContext, m_pDocument); |
123 } | 124 } |
124 CFX_WideTextBuf wsJavaScript; | 125 CFX_WideTextBuf wsJavaScript; |
125 CFX_WideString wsErrorInfo; | 126 CFX_WideString wsErrorInfo; |
126 int32_t iFlags = XFA_FM2JS_Translate(wsScript, wsJavaScript, wsErrorInfo); | 127 int32_t iFlags = |
| 128 CXFA_FM2JSContext::Translate(wsScript, wsJavaScript, wsErrorInfo); |
127 if (iFlags) { | 129 if (iFlags) { |
128 FXJSE_Value_SetUndefined(hRetValue); | 130 FXJSE_Value_SetUndefined(hRetValue); |
129 return FALSE; | 131 return FALSE; |
130 } | 132 } |
131 btScript = | 133 btScript = |
132 FX_UTF8Encode(wsJavaScript.GetBuffer(), wsJavaScript.GetLength()); | 134 FX_UTF8Encode(wsJavaScript.GetBuffer(), wsJavaScript.GetLength()); |
133 } else { | 135 } else { |
134 btScript = FX_UTF8Encode(wsScript.c_str(), wsScript.GetLength()); | 136 btScript = FX_UTF8Encode(wsScript.c_str(), wsScript.GetLength()); |
135 } | 137 } |
136 CXFA_Object* pOriginalObject = m_pThisObject; | 138 CXFA_Object* pOriginalObject = m_pThisObject; |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 const CFX_ByteStringC& szPropName, | 205 const CFX_ByteStringC& szPropName, |
204 CFXJSE_Value* pValue) { | 206 CFXJSE_Value* pValue) { |
205 CXFA_Object* pOriginalObject = | 207 CXFA_Object* pOriginalObject = |
206 static_cast<CXFA_Object*>(FXJSE_Value_ToObject(pObject, nullptr)); | 208 static_cast<CXFA_Object*>(FXJSE_Value_ToObject(pObject, nullptr)); |
207 CXFA_Document* pDoc = pOriginalObject->GetDocument(); | 209 CXFA_Document* pDoc = pOriginalObject->GetDocument(); |
208 CXFA_ScriptContext* lpScriptContext = | 210 CXFA_ScriptContext* lpScriptContext = |
209 (CXFA_ScriptContext*)pDoc->GetScriptContext(); | 211 (CXFA_ScriptContext*)pDoc->GetScriptContext(); |
210 CXFA_Object* lpCurNode = lpScriptContext->GetVariablesThis(pOriginalObject); | 212 CXFA_Object* lpCurNode = lpScriptContext->GetVariablesThis(pOriginalObject); |
211 CFX_WideString wsPropName = CFX_WideString::FromUTF8(szPropName); | 213 CFX_WideString wsPropName = CFX_WideString::FromUTF8(szPropName); |
212 if (lpScriptContext->GetType() == XFA_SCRIPTLANGTYPE_Formcalc) { | 214 if (lpScriptContext->GetType() == XFA_SCRIPTLANGTYPE_Formcalc) { |
213 if (szPropName == FOXIT_XFA_FM2JS_FORMCALC_RUNTIME) { | 215 if (szPropName == kFormCalcRuntime) { |
214 XFA_FM2JS_GlobalPropertyGetter(lpScriptContext->m_hFM2JSContext, pValue); | 216 lpScriptContext->m_hFM2JSContext->GlobalPropertyGetter(pValue); |
215 return; | 217 return; |
216 } | 218 } |
217 XFA_HashCode uHashCode = static_cast<XFA_HashCode>( | 219 XFA_HashCode uHashCode = static_cast<XFA_HashCode>( |
218 FX_HashCode_GetW(wsPropName.AsStringC(), false)); | 220 FX_HashCode_GetW(wsPropName.AsStringC(), false)); |
219 if (uHashCode != XFA_HASHCODE_Layout) { | 221 if (uHashCode != XFA_HASHCODE_Layout) { |
220 CXFA_Object* pObject = | 222 CXFA_Object* pObject = |
221 lpScriptContext->GetDocument()->GetXFAObject(uHashCode); | 223 lpScriptContext->GetDocument()->GetXFAObject(uHashCode); |
222 if (pObject) { | 224 if (pObject) { |
223 FXJSE_Value_Set(pValue, lpScriptContext->GetJSValueFromMap(pObject)); | 225 FXJSE_Value_Set(pValue, lpScriptContext->GetJSValueFromMap(pObject)); |
224 return; | 226 return; |
(...skipping 537 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
762 } | 764 } |
763 } | 765 } |
764 void CXFA_ScriptContext::AddNodesOfRunScript(CXFA_Node* pNode) { | 766 void CXFA_ScriptContext::AddNodesOfRunScript(CXFA_Node* pNode) { |
765 if (!m_pScriptNodeArray) { | 767 if (!m_pScriptNodeArray) { |
766 return; | 768 return; |
767 } | 769 } |
768 if (m_pScriptNodeArray->Find(pNode) == -1) { | 770 if (m_pScriptNodeArray->Find(pNode) == -1) { |
769 m_pScriptNodeArray->Add(pNode); | 771 m_pScriptNodeArray->Add(pNode); |
770 } | 772 } |
771 } | 773 } |
OLD | NEW |