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" |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 FXJSE_HVALUE pValue = pThisObject ? GetJSValueFromMap(pThisObject) : NULL; | 94 FXJSE_HVALUE pValue = pThisObject ? GetJSValueFromMap(pThisObject) : NULL; |
95 FX_BOOL bRet = | 95 FX_BOOL bRet = |
96 FXJSE_ExecuteScript(m_hJsContext, btScript.c_str(), hRetValue, pValue); | 96 FXJSE_ExecuteScript(m_hJsContext, btScript.c_str(), hRetValue, pValue); |
97 m_pThisObject = pOriginalObject; | 97 m_pThisObject = pOriginalObject; |
98 m_eScriptType = eSaveType; | 98 m_eScriptType = eSaveType; |
99 return bRet; | 99 return bRet; |
100 } | 100 } |
101 void CXFA_ScriptContext::GlobalPropertySetter(FXJSE_HOBJECT hObject, | 101 void CXFA_ScriptContext::GlobalPropertySetter(FXJSE_HOBJECT hObject, |
102 const CFX_ByteStringC& szPropName, | 102 const CFX_ByteStringC& szPropName, |
103 FXJSE_HVALUE hValue) { | 103 FXJSE_HVALUE hValue) { |
104 CXFA_Object* lpOrginalNode = | 104 CXFA_Object* lpOrginalNode = (CXFA_Object*)FXJSE_Value_ToObject(hObject); |
105 (CXFA_Object*)FXJSE_Value_ToObject(hObject, NULL); | |
106 CXFA_Document* pDoc = lpOrginalNode->GetDocument(); | 105 CXFA_Document* pDoc = lpOrginalNode->GetDocument(); |
107 CXFA_ScriptContext* lpScriptContext = | 106 CXFA_ScriptContext* lpScriptContext = |
108 (CXFA_ScriptContext*)pDoc->GetScriptContext(); | 107 (CXFA_ScriptContext*)pDoc->GetScriptContext(); |
109 CXFA_Object* lpCurNode = lpScriptContext->GetVariablesThis(lpOrginalNode); | 108 CXFA_Object* lpCurNode = lpScriptContext->GetVariablesThis(lpOrginalNode); |
110 CFX_WideString wsPropName = CFX_WideString::FromUTF8(szPropName); | 109 CFX_WideString wsPropName = CFX_WideString::FromUTF8(szPropName); |
111 uint32_t dwFlag = XFA_RESOLVENODE_Parent | XFA_RESOLVENODE_Siblings | | 110 uint32_t dwFlag = XFA_RESOLVENODE_Parent | XFA_RESOLVENODE_Siblings | |
112 XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Properties | | 111 XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Properties | |
113 XFA_RESOLVENODE_Attributes; | 112 XFA_RESOLVENODE_Attributes; |
114 CXFA_Node* pRefNode = ToNode(lpScriptContext->GetThisObject()); | 113 CXFA_Node* pRefNode = ToNode(lpScriptContext->GetThisObject()); |
115 if (lpOrginalNode->GetObjectType() == XFA_OBJECTTYPE_VariablesThis) { | 114 if (lpOrginalNode->GetObjectType() == XFA_OBJECTTYPE_VariablesThis) { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 if (lpAttributeInfo) { | 151 if (lpAttributeInfo) { |
153 (resolveRs.nodes[0]->*(lpAttributeInfo->lpfnCallback))( | 152 (resolveRs.nodes[0]->*(lpAttributeInfo->lpfnCallback))( |
154 hValue, bSetting, (XFA_ATTRIBUTE)lpAttributeInfo->eAttribute); | 153 hValue, bSetting, (XFA_ATTRIBUTE)lpAttributeInfo->eAttribute); |
155 } | 154 } |
156 } | 155 } |
157 return true; | 156 return true; |
158 } | 157 } |
159 void CXFA_ScriptContext::GlobalPropertyGetter(FXJSE_HOBJECT hObject, | 158 void CXFA_ScriptContext::GlobalPropertyGetter(FXJSE_HOBJECT hObject, |
160 const CFX_ByteStringC& szPropName, | 159 const CFX_ByteStringC& szPropName, |
161 FXJSE_HVALUE hValue) { | 160 FXJSE_HVALUE hValue) { |
162 CXFA_Object* pOrginalObject = | 161 CXFA_Object* pOrginalObject = (CXFA_Object*)FXJSE_Value_ToObject(hObject); |
163 (CXFA_Object*)FXJSE_Value_ToObject(hObject, NULL); | |
164 CXFA_Document* pDoc = pOrginalObject->GetDocument(); | 162 CXFA_Document* pDoc = pOrginalObject->GetDocument(); |
165 CXFA_ScriptContext* lpScriptContext = | 163 CXFA_ScriptContext* lpScriptContext = |
166 (CXFA_ScriptContext*)pDoc->GetScriptContext(); | 164 (CXFA_ScriptContext*)pDoc->GetScriptContext(); |
167 CXFA_Object* lpCurNode = lpScriptContext->GetVariablesThis(pOrginalObject); | 165 CXFA_Object* lpCurNode = lpScriptContext->GetVariablesThis(pOrginalObject); |
168 CFX_WideString wsPropName = CFX_WideString::FromUTF8(szPropName); | 166 CFX_WideString wsPropName = CFX_WideString::FromUTF8(szPropName); |
169 if (lpScriptContext->GetType() == XFA_SCRIPTLANGTYPE_Formcalc) { | 167 if (lpScriptContext->GetType() == XFA_SCRIPTLANGTYPE_Formcalc) { |
170 if (szPropName == FOXIT_XFA_FM2JS_FORMCALC_RUNTIME) { | 168 if (szPropName == FOXIT_XFA_FM2JS_FORMCALC_RUNTIME) { |
171 XFA_FM2JS_GlobalPropertyGetter(lpScriptContext->m_hFM2JSContext, hValue); | 169 XFA_FM2JS_GlobalPropertyGetter(lpScriptContext->m_hFM2JSContext, hValue); |
172 return; | 170 return; |
173 } | 171 } |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 CXFA_FFNotify* pNotify = pDoc->GetNotify(); | 205 CXFA_FFNotify* pNotify = pDoc->GetNotify(); |
208 if (!pNotify) { | 206 if (!pNotify) { |
209 return; | 207 return; |
210 } | 208 } |
211 pNotify->GetDocProvider()->GetGlobalProperty(pNotify->GetHDOC(), szPropName, | 209 pNotify->GetDocProvider()->GetGlobalProperty(pNotify->GetHDOC(), szPropName, |
212 hValue); | 210 hValue); |
213 } | 211 } |
214 void CXFA_ScriptContext::NormalPropertyGetter(FXJSE_HOBJECT hObject, | 212 void CXFA_ScriptContext::NormalPropertyGetter(FXJSE_HOBJECT hObject, |
215 const CFX_ByteStringC& szPropName, | 213 const CFX_ByteStringC& szPropName, |
216 FXJSE_HVALUE hValue) { | 214 FXJSE_HVALUE hValue) { |
217 CXFA_Object* pOrginalObject = | 215 CXFA_Object* pOrginalObject = (CXFA_Object*)FXJSE_Value_ToObject(hObject); |
218 (CXFA_Object*)FXJSE_Value_ToObject(hObject, NULL); | |
219 if (pOrginalObject == NULL) { | 216 if (pOrginalObject == NULL) { |
220 FXJSE_Value_SetUndefined(hValue); | 217 FXJSE_Value_SetUndefined(hValue); |
221 return; | 218 return; |
222 } | 219 } |
223 CFX_WideString wsPropName = CFX_WideString::FromUTF8(szPropName); | 220 CFX_WideString wsPropName = CFX_WideString::FromUTF8(szPropName); |
224 CXFA_ScriptContext* lpScriptContext = | 221 CXFA_ScriptContext* lpScriptContext = |
225 (CXFA_ScriptContext*)pOrginalObject->GetDocument()->GetScriptContext(); | 222 (CXFA_ScriptContext*)pOrginalObject->GetDocument()->GetScriptContext(); |
226 CXFA_Object* pObject = lpScriptContext->GetVariablesThis(pOrginalObject); | 223 CXFA_Object* pObject = lpScriptContext->GetVariablesThis(pOrginalObject); |
227 if (wsPropName == FX_WSTRC(L"xfa")) { | 224 if (wsPropName == FX_WSTRC(L"xfa")) { |
228 FXJSE_HVALUE pValue = lpScriptContext->GetJSValueFromMap( | 225 FXJSE_HVALUE pValue = lpScriptContext->GetJSValueFromMap( |
(...skipping 24 matching lines...) Expand all Loading... |
253 bRet = lpScriptContext->QueryVariableHValue(ToNode(pScriptObject), | 250 bRet = lpScriptContext->QueryVariableHValue(ToNode(pScriptObject), |
254 szPropName, hValue, TRUE); | 251 szPropName, hValue, TRUE); |
255 } | 252 } |
256 if (!bRet) { | 253 if (!bRet) { |
257 FXJSE_Value_SetUndefined(hValue); | 254 FXJSE_Value_SetUndefined(hValue); |
258 } | 255 } |
259 } | 256 } |
260 void CXFA_ScriptContext::NormalPropertySetter(FXJSE_HOBJECT hObject, | 257 void CXFA_ScriptContext::NormalPropertySetter(FXJSE_HOBJECT hObject, |
261 const CFX_ByteStringC& szPropName, | 258 const CFX_ByteStringC& szPropName, |
262 FXJSE_HVALUE hValue) { | 259 FXJSE_HVALUE hValue) { |
263 CXFA_Object* pOrginalObject = | 260 CXFA_Object* pOrginalObject = (CXFA_Object*)FXJSE_Value_ToObject(hObject); |
264 (CXFA_Object*)FXJSE_Value_ToObject(hObject, NULL); | |
265 if (pOrginalObject == NULL) { | 261 if (pOrginalObject == NULL) { |
266 return; | 262 return; |
267 } | 263 } |
268 CXFA_ScriptContext* lpScriptContext = | 264 CXFA_ScriptContext* lpScriptContext = |
269 (CXFA_ScriptContext*)pOrginalObject->GetDocument()->GetScriptContext(); | 265 (CXFA_ScriptContext*)pOrginalObject->GetDocument()->GetScriptContext(); |
270 CXFA_Object* pObject = lpScriptContext->GetVariablesThis(pOrginalObject); | 266 CXFA_Object* pObject = lpScriptContext->GetVariablesThis(pOrginalObject); |
271 CFX_WideString wsPropName = CFX_WideString::FromUTF8(szPropName); | 267 CFX_WideString wsPropName = CFX_WideString::FromUTF8(szPropName); |
272 const XFA_SCRIPTATTRIBUTEINFO* lpAttributeInfo = XFA_GetScriptAttributeByName( | 268 const XFA_SCRIPTATTRIBUTEINFO* lpAttributeInfo = XFA_GetScriptAttributeByName( |
273 pObject->GetClassID(), wsPropName.AsStringC()); | 269 pObject->GetClassID(), wsPropName.AsStringC()); |
274 if (lpAttributeInfo) { | 270 if (lpAttributeInfo) { |
(...skipping 30 matching lines...) Expand all Loading... |
305 if (pScriptObject) { | 301 if (pScriptObject) { |
306 lpScriptContext->QueryVariableHValue(ToNode(pScriptObject), szPropName, | 302 lpScriptContext->QueryVariableHValue(ToNode(pScriptObject), szPropName, |
307 hValue, FALSE); | 303 hValue, FALSE); |
308 } | 304 } |
309 } | 305 } |
310 } | 306 } |
311 int32_t CXFA_ScriptContext::NormalPropTypeGetter( | 307 int32_t CXFA_ScriptContext::NormalPropTypeGetter( |
312 FXJSE_HOBJECT hObject, | 308 FXJSE_HOBJECT hObject, |
313 const CFX_ByteStringC& szPropName, | 309 const CFX_ByteStringC& szPropName, |
314 FX_BOOL bQueryIn) { | 310 FX_BOOL bQueryIn) { |
315 CXFA_Object* pObject = (CXFA_Object*)FXJSE_Value_ToObject(hObject, NULL); | 311 CXFA_Object* pObject = (CXFA_Object*)FXJSE_Value_ToObject(hObject); |
316 if (pObject == NULL) { | 312 if (pObject == NULL) { |
317 return FXJSE_ClassPropType_None; | 313 return FXJSE_ClassPropType_None; |
318 } | 314 } |
319 CXFA_ScriptContext* lpScriptContext = | 315 CXFA_ScriptContext* lpScriptContext = |
320 (CXFA_ScriptContext*)pObject->GetDocument()->GetScriptContext(); | 316 (CXFA_ScriptContext*)pObject->GetDocument()->GetScriptContext(); |
321 pObject = lpScriptContext->GetVariablesThis(pObject); | 317 pObject = lpScriptContext->GetVariablesThis(pObject); |
322 XFA_ELEMENT objElement = pObject->GetClassID(); | 318 XFA_ELEMENT objElement = pObject->GetClassID(); |
323 CFX_WideString wsPropName = CFX_WideString::FromUTF8(szPropName); | 319 CFX_WideString wsPropName = CFX_WideString::FromUTF8(szPropName); |
324 if (XFA_GetMethodByName(objElement, wsPropName.AsStringC())) { | 320 if (XFA_GetMethodByName(objElement, wsPropName.AsStringC())) { |
325 return FXJSE_ClassPropType_Method; | 321 return FXJSE_ClassPropType_Method; |
326 } | 322 } |
327 if (bQueryIn && | 323 if (bQueryIn && |
328 !XFA_GetScriptAttributeByName(objElement, wsPropName.AsStringC())) { | 324 !XFA_GetScriptAttributeByName(objElement, wsPropName.AsStringC())) { |
329 return FXJSE_ClassPropType_None; | 325 return FXJSE_ClassPropType_None; |
330 } | 326 } |
331 return FXJSE_ClassPropType_Property; | 327 return FXJSE_ClassPropType_Property; |
332 } | 328 } |
333 int32_t CXFA_ScriptContext::GlobalPropTypeGetter( | 329 int32_t CXFA_ScriptContext::GlobalPropTypeGetter( |
334 FXJSE_HOBJECT hObject, | 330 FXJSE_HOBJECT hObject, |
335 const CFX_ByteStringC& szPropName, | 331 const CFX_ByteStringC& szPropName, |
336 FX_BOOL bQueryIn) { | 332 FX_BOOL bQueryIn) { |
337 CXFA_Object* pObject = (CXFA_Object*)FXJSE_Value_ToObject(hObject, NULL); | 333 CXFA_Object* pObject = (CXFA_Object*)FXJSE_Value_ToObject(hObject); |
338 if (pObject == NULL) { | 334 if (pObject == NULL) { |
339 return FXJSE_ClassPropType_None; | 335 return FXJSE_ClassPropType_None; |
340 } | 336 } |
341 CXFA_ScriptContext* lpScriptContext = | 337 CXFA_ScriptContext* lpScriptContext = |
342 (CXFA_ScriptContext*)pObject->GetDocument()->GetScriptContext(); | 338 (CXFA_ScriptContext*)pObject->GetDocument()->GetScriptContext(); |
343 pObject = lpScriptContext->GetVariablesThis(pObject); | 339 pObject = lpScriptContext->GetVariablesThis(pObject); |
344 XFA_ELEMENT objElement = pObject->GetClassID(); | 340 XFA_ELEMENT objElement = pObject->GetClassID(); |
345 CFX_WideString wsPropName = CFX_WideString::FromUTF8(szPropName); | 341 CFX_WideString wsPropName = CFX_WideString::FromUTF8(szPropName); |
346 if (XFA_GetMethodByName(objElement, wsPropName.AsStringC())) { | 342 if (XFA_GetMethodByName(objElement, wsPropName.AsStringC())) { |
347 return FXJSE_ClassPropType_Method; | 343 return FXJSE_ClassPropType_Method; |
348 } | 344 } |
349 return FXJSE_ClassPropType_Property; | 345 return FXJSE_ClassPropType_Property; |
350 } | 346 } |
351 void CXFA_ScriptContext::NormalMethodCall(FXJSE_HOBJECT hThis, | 347 void CXFA_ScriptContext::NormalMethodCall(FXJSE_HOBJECT hThis, |
352 const CFX_ByteStringC& szFuncName, | 348 const CFX_ByteStringC& szFuncName, |
353 CFXJSE_Arguments& args) { | 349 CFXJSE_Arguments& args) { |
354 CXFA_Object* pObject = (CXFA_Object*)FXJSE_Value_ToObject(hThis, NULL); | 350 CXFA_Object* pObject = (CXFA_Object*)FXJSE_Value_ToObject(hThis); |
355 if (pObject == NULL) { | 351 if (pObject == NULL) { |
356 return; | 352 return; |
357 } | 353 } |
358 CXFA_ScriptContext* lpScriptContext = | 354 CXFA_ScriptContext* lpScriptContext = |
359 (CXFA_ScriptContext*)pObject->GetDocument()->GetScriptContext(); | 355 (CXFA_ScriptContext*)pObject->GetDocument()->GetScriptContext(); |
360 pObject = lpScriptContext->GetVariablesThis(pObject); | 356 pObject = lpScriptContext->GetVariablesThis(pObject); |
361 CFX_WideString wsFunName = CFX_WideString::FromUTF8(szFuncName); | 357 CFX_WideString wsFunName = CFX_WideString::FromUTF8(szFuncName); |
362 const XFA_METHODINFO* lpMethodInfo = | 358 const XFA_METHODINFO* lpMethodInfo = |
363 XFA_GetMethodByName(pObject->GetClassID(), wsFunName.AsStringC()); | 359 XFA_GetMethodByName(pObject->GetClassID(), wsFunName.AsStringC()); |
364 if (NULL == lpMethodInfo) { | 360 if (NULL == lpMethodInfo) { |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
506 return bRes; | 502 return bRes; |
507 } | 503 } |
508 | 504 |
509 void CXFA_ScriptContext::ReleaseVariablesMap() { | 505 void CXFA_ScriptContext::ReleaseVariablesMap() { |
510 FX_POSITION ps = m_mapVariableToHValue.GetStartPosition(); | 506 FX_POSITION ps = m_mapVariableToHValue.GetStartPosition(); |
511 while (ps) { | 507 while (ps) { |
512 CXFA_Object* pScriptNode; | 508 CXFA_Object* pScriptNode; |
513 FXJSE_HCONTEXT hVariableContext = nullptr; | 509 FXJSE_HCONTEXT hVariableContext = nullptr; |
514 m_mapVariableToHValue.GetNextAssoc(ps, pScriptNode, hVariableContext); | 510 m_mapVariableToHValue.GetNextAssoc(ps, pScriptNode, hVariableContext); |
515 FXJSE_HVALUE hObject = FXJSE_Context_GetGlobalObject(hVariableContext); | 511 FXJSE_HVALUE hObject = FXJSE_Context_GetGlobalObject(hVariableContext); |
516 delete static_cast<CXFA_ThisProxy*>(FXJSE_Value_ToObject(hObject, nullptr)); | 512 delete static_cast<CXFA_ThisProxy*>(FXJSE_Value_ToObject(hObject)); |
517 FXJSE_Value_Release(hObject); | 513 FXJSE_Value_Release(hObject); |
518 FXJSE_Context_Release(hVariableContext); | 514 FXJSE_Context_Release(hVariableContext); |
519 } | 515 } |
520 m_mapVariableToHValue.RemoveAll(); | 516 m_mapVariableToHValue.RemoveAll(); |
521 } | 517 } |
522 | 518 |
523 void CXFA_ScriptContext::DefineJsClass() { | 519 void CXFA_ScriptContext::DefineJsClass() { |
524 m_JsNormalClass.constructor = NULL; | 520 m_JsNormalClass.constructor = NULL; |
525 m_JsNormalClass.name = "XFAObject"; | 521 m_JsNormalClass.name = "XFAObject"; |
526 m_JsNormalClass.propNum = 0; | 522 m_JsNormalClass.propNum = 0; |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
640 nRet = m_pResolveProcessor->XFA_ResolveNodes(rndFind); | 636 nRet = m_pResolveProcessor->XFA_ResolveNodes(rndFind); |
641 if (nRet < 1) { | 637 if (nRet < 1) { |
642 continue; | 638 continue; |
643 } | 639 } |
644 if (rndFind.m_dwFlag == XFA_RESOVENODE_RSTYPE_Attribute && | 640 if (rndFind.m_dwFlag == XFA_RESOVENODE_RSTYPE_Attribute && |
645 rndFind.m_pScriptAttribute && nStart < wsExpression.GetLength()) { | 641 rndFind.m_pScriptAttribute && nStart < wsExpression.GetLength()) { |
646 FXJSE_HVALUE hValue = FXJSE_Value_Create(m_pIsolate); | 642 FXJSE_HVALUE hValue = FXJSE_Value_Create(m_pIsolate); |
647 (rndFind.m_Nodes[0]->*(rndFind.m_pScriptAttribute->lpfnCallback))( | 643 (rndFind.m_Nodes[0]->*(rndFind.m_pScriptAttribute->lpfnCallback))( |
648 hValue, FALSE, | 644 hValue, FALSE, |
649 (XFA_ATTRIBUTE)rndFind.m_pScriptAttribute->eAttribute); | 645 (XFA_ATTRIBUTE)rndFind.m_pScriptAttribute->eAttribute); |
650 rndFind.m_Nodes.SetAt(0, | 646 rndFind.m_Nodes.SetAt(0, (CXFA_Object*)FXJSE_Value_ToObject(hValue)); |
651 (CXFA_Object*)FXJSE_Value_ToObject(hValue, NULL)); | |
652 FXJSE_Value_Release(hValue); | 647 FXJSE_Value_Release(hValue); |
653 } | 648 } |
654 int32_t iSize = m_upObjectArray.GetSize(); | 649 int32_t iSize = m_upObjectArray.GetSize(); |
655 if (iSize) { | 650 if (iSize) { |
656 m_upObjectArray.RemoveAt(iSize - 1); | 651 m_upObjectArray.RemoveAt(iSize - 1); |
657 } | 652 } |
658 retNodes.Append(rndFind.m_Nodes); | 653 retNodes.Append(rndFind.m_Nodes); |
659 rndFind.m_Nodes.RemoveAll(); | 654 rndFind.m_Nodes.RemoveAll(); |
660 if (bDataBind) { | 655 if (bDataBind) { |
661 break; | 656 break; |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
758 } | 753 } |
759 } | 754 } |
760 void CXFA_ScriptContext::AddNodesOfRunScript(CXFA_Node* pNode) { | 755 void CXFA_ScriptContext::AddNodesOfRunScript(CXFA_Node* pNode) { |
761 if (!m_pScriptNodeArray) { | 756 if (!m_pScriptNodeArray) { |
762 return; | 757 return; |
763 } | 758 } |
764 if (m_pScriptNodeArray->Find(pNode) == -1) { | 759 if (m_pScriptNodeArray->Find(pNode) == -1) { |
765 m_pScriptNodeArray->Add(pNode); | 760 m_pScriptNodeArray->Add(pNode); |
766 } | 761 } |
767 } | 762 } |
OLD | NEW |