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 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 } | 108 } |
109 void CXFA_ScriptContext::GlobalPropertySetter(FXJSE_HOBJECT hObject, | 109 void CXFA_ScriptContext::GlobalPropertySetter(FXJSE_HOBJECT hObject, |
110 const CFX_ByteStringC& szPropName, | 110 const CFX_ByteStringC& szPropName, |
111 FXJSE_HVALUE hValue) { | 111 FXJSE_HVALUE hValue) { |
112 CXFA_Object* lpOrginalNode = | 112 CXFA_Object* lpOrginalNode = |
113 (CXFA_Object*)FXJSE_Value_ToObject(hObject, NULL); | 113 (CXFA_Object*)FXJSE_Value_ToObject(hObject, NULL); |
114 CXFA_Document* pDoc = lpOrginalNode->GetDocument(); | 114 CXFA_Document* pDoc = lpOrginalNode->GetDocument(); |
115 CXFA_ScriptContext* lpScriptContext = | 115 CXFA_ScriptContext* lpScriptContext = |
116 (CXFA_ScriptContext*)pDoc->GetScriptContext(); | 116 (CXFA_ScriptContext*)pDoc->GetScriptContext(); |
117 CXFA_Object* lpCurNode = lpScriptContext->GetVariablesThis(lpOrginalNode); | 117 CXFA_Object* lpCurNode = lpScriptContext->GetVariablesThis(lpOrginalNode); |
118 CFX_WideString wsPropName = CFX_WideString::FromUTF8( | 118 CFX_WideString wsPropName = CFX_WideString::FromUTF8(szPropName); |
119 (const FX_CHAR*)szPropName.raw_str(), szPropName.GetLength()); | |
120 uint32_t dwFlag = XFA_RESOLVENODE_Parent | XFA_RESOLVENODE_Siblings | | 119 uint32_t dwFlag = XFA_RESOLVENODE_Parent | XFA_RESOLVENODE_Siblings | |
121 XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Properties | | 120 XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Properties | |
122 XFA_RESOLVENODE_Attributes; | 121 XFA_RESOLVENODE_Attributes; |
123 CXFA_Node* pRefNode = ToNode(lpScriptContext->GetThisObject()); | 122 CXFA_Node* pRefNode = ToNode(lpScriptContext->GetThisObject()); |
124 if (lpOrginalNode->GetObjectType() == XFA_OBJECTTYPE_VariablesThis) { | 123 if (lpOrginalNode->GetObjectType() == XFA_OBJECTTYPE_VariablesThis) { |
125 pRefNode = ToNode(lpCurNode); | 124 pRefNode = ToNode(lpCurNode); |
126 } | 125 } |
127 if (lpScriptContext->QueryNodeByFlag(pRefNode, wsPropName.AsWideStringC(), | 126 if (lpScriptContext->QueryNodeByFlag(pRefNode, wsPropName.AsWideStringC(), |
128 hValue, dwFlag, TRUE)) { | 127 hValue, dwFlag, TRUE)) { |
129 return; | 128 return; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 } | 166 } |
168 void CXFA_ScriptContext::GlobalPropertyGetter(FXJSE_HOBJECT hObject, | 167 void CXFA_ScriptContext::GlobalPropertyGetter(FXJSE_HOBJECT hObject, |
169 const CFX_ByteStringC& szPropName, | 168 const CFX_ByteStringC& szPropName, |
170 FXJSE_HVALUE hValue) { | 169 FXJSE_HVALUE hValue) { |
171 CXFA_Object* pOrginalObject = | 170 CXFA_Object* pOrginalObject = |
172 (CXFA_Object*)FXJSE_Value_ToObject(hObject, NULL); | 171 (CXFA_Object*)FXJSE_Value_ToObject(hObject, NULL); |
173 CXFA_Document* pDoc = pOrginalObject->GetDocument(); | 172 CXFA_Document* pDoc = pOrginalObject->GetDocument(); |
174 CXFA_ScriptContext* lpScriptContext = | 173 CXFA_ScriptContext* lpScriptContext = |
175 (CXFA_ScriptContext*)pDoc->GetScriptContext(); | 174 (CXFA_ScriptContext*)pDoc->GetScriptContext(); |
176 CXFA_Object* lpCurNode = lpScriptContext->GetVariablesThis(pOrginalObject); | 175 CXFA_Object* lpCurNode = lpScriptContext->GetVariablesThis(pOrginalObject); |
177 CFX_WideString wsPropName = CFX_WideString::FromUTF8( | 176 CFX_WideString wsPropName = CFX_WideString::FromUTF8(szPropName); |
178 (const FX_CHAR*)szPropName.raw_str(), szPropName.GetLength()); | |
179 if (lpScriptContext->GetType() == XFA_SCRIPTLANGTYPE_Formcalc) { | 177 if (lpScriptContext->GetType() == XFA_SCRIPTLANGTYPE_Formcalc) { |
180 if (szPropName == FOXIT_XFA_FM2JS_FORMCALC_RUNTIME) { | 178 if (szPropName == FOXIT_XFA_FM2JS_FORMCALC_RUNTIME) { |
181 XFA_FM2JS_GlobalPropertyGetter(lpScriptContext->m_hFM2JSContext, hValue); | 179 XFA_FM2JS_GlobalPropertyGetter(lpScriptContext->m_hFM2JSContext, hValue); |
182 return; | 180 return; |
183 } | 181 } |
184 uint32_t uHashCode = | 182 uint32_t uHashCode = |
185 FX_HashCode_String_GetW(wsPropName, wsPropName.GetLength()); | 183 FX_HashCode_String_GetW(wsPropName, wsPropName.GetLength()); |
186 if (uHashCode != XFA_HASHCODE_Layout) { | 184 if (uHashCode != XFA_HASHCODE_Layout) { |
187 CXFA_Object* pObject = | 185 CXFA_Object* pObject = |
188 lpScriptContext->GetDocument()->GetXFAObject(uHashCode); | 186 lpScriptContext->GetDocument()->GetXFAObject(uHashCode); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 } | 221 } |
224 void CXFA_ScriptContext::NormalPropertyGetter(FXJSE_HOBJECT hObject, | 222 void CXFA_ScriptContext::NormalPropertyGetter(FXJSE_HOBJECT hObject, |
225 const CFX_ByteStringC& szPropName, | 223 const CFX_ByteStringC& szPropName, |
226 FXJSE_HVALUE hValue) { | 224 FXJSE_HVALUE hValue) { |
227 CXFA_Object* pOrginalObject = | 225 CXFA_Object* pOrginalObject = |
228 (CXFA_Object*)FXJSE_Value_ToObject(hObject, NULL); | 226 (CXFA_Object*)FXJSE_Value_ToObject(hObject, NULL); |
229 if (pOrginalObject == NULL) { | 227 if (pOrginalObject == NULL) { |
230 FXJSE_Value_SetUndefined(hValue); | 228 FXJSE_Value_SetUndefined(hValue); |
231 return; | 229 return; |
232 } | 230 } |
233 CFX_WideString wsPropName = CFX_WideString::FromUTF8( | 231 CFX_WideString wsPropName = CFX_WideString::FromUTF8(szPropName); |
234 (const FX_CHAR*)szPropName.raw_str(), szPropName.GetLength()); | |
235 CXFA_ScriptContext* lpScriptContext = | 232 CXFA_ScriptContext* lpScriptContext = |
236 (CXFA_ScriptContext*)pOrginalObject->GetDocument()->GetScriptContext(); | 233 (CXFA_ScriptContext*)pOrginalObject->GetDocument()->GetScriptContext(); |
237 CXFA_Object* pObject = lpScriptContext->GetVariablesThis(pOrginalObject); | 234 CXFA_Object* pObject = lpScriptContext->GetVariablesThis(pOrginalObject); |
238 if (wsPropName == FX_WSTRC(L"xfa")) { | 235 if (wsPropName == FX_WSTRC(L"xfa")) { |
239 FXJSE_HVALUE pValue = lpScriptContext->GetJSValueFromMap( | 236 FXJSE_HVALUE pValue = lpScriptContext->GetJSValueFromMap( |
240 lpScriptContext->GetDocument()->GetRoot()); | 237 lpScriptContext->GetDocument()->GetRoot()); |
241 FXJSE_Value_Set(hValue, pValue); | 238 FXJSE_Value_Set(hValue, pValue); |
242 return; | 239 return; |
243 } | 240 } |
244 uint32_t dwFlag = XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Properties | | 241 uint32_t dwFlag = XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Properties | |
(...skipping 27 matching lines...) Expand all Loading... |
272 const CFX_ByteStringC& szPropName, | 269 const CFX_ByteStringC& szPropName, |
273 FXJSE_HVALUE hValue) { | 270 FXJSE_HVALUE hValue) { |
274 CXFA_Object* pOrginalObject = | 271 CXFA_Object* pOrginalObject = |
275 (CXFA_Object*)FXJSE_Value_ToObject(hObject, NULL); | 272 (CXFA_Object*)FXJSE_Value_ToObject(hObject, NULL); |
276 if (pOrginalObject == NULL) { | 273 if (pOrginalObject == NULL) { |
277 return; | 274 return; |
278 } | 275 } |
279 CXFA_ScriptContext* lpScriptContext = | 276 CXFA_ScriptContext* lpScriptContext = |
280 (CXFA_ScriptContext*)pOrginalObject->GetDocument()->GetScriptContext(); | 277 (CXFA_ScriptContext*)pOrginalObject->GetDocument()->GetScriptContext(); |
281 CXFA_Object* pObject = lpScriptContext->GetVariablesThis(pOrginalObject); | 278 CXFA_Object* pObject = lpScriptContext->GetVariablesThis(pOrginalObject); |
282 CFX_WideString wsPropName = CFX_WideString::FromUTF8( | 279 CFX_WideString wsPropName = CFX_WideString::FromUTF8(szPropName); |
283 (const FX_CHAR*)szPropName.raw_str(), szPropName.GetLength()); | |
284 const XFA_SCRIPTATTRIBUTEINFO* lpAttributeInfo = XFA_GetScriptAttributeByName( | 280 const XFA_SCRIPTATTRIBUTEINFO* lpAttributeInfo = XFA_GetScriptAttributeByName( |
285 pObject->GetClassID(), wsPropName.AsWideStringC()); | 281 pObject->GetClassID(), wsPropName.AsWideStringC()); |
286 if (lpAttributeInfo) { | 282 if (lpAttributeInfo) { |
287 (pObject->*(lpAttributeInfo->lpfnCallback))( | 283 (pObject->*(lpAttributeInfo->lpfnCallback))( |
288 hValue, TRUE, (XFA_ATTRIBUTE)lpAttributeInfo->eAttribute); | 284 hValue, TRUE, (XFA_ATTRIBUTE)lpAttributeInfo->eAttribute); |
289 } else { | 285 } else { |
290 if (pObject->IsNode()) { | 286 if (pObject->IsNode()) { |
291 if (wsPropName.GetAt(0) == '#') { | 287 if (wsPropName.GetAt(0) == '#') { |
292 wsPropName = wsPropName.Right(wsPropName.GetLength() - 1); | 288 wsPropName = wsPropName.Right(wsPropName.GetLength() - 1); |
293 } | 289 } |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
325 const CFX_ByteStringC& szPropName, | 321 const CFX_ByteStringC& szPropName, |
326 FX_BOOL bQueryIn) { | 322 FX_BOOL bQueryIn) { |
327 CXFA_Object* pObject = (CXFA_Object*)FXJSE_Value_ToObject(hObject, NULL); | 323 CXFA_Object* pObject = (CXFA_Object*)FXJSE_Value_ToObject(hObject, NULL); |
328 if (pObject == NULL) { | 324 if (pObject == NULL) { |
329 return FXJSE_ClassPropType_None; | 325 return FXJSE_ClassPropType_None; |
330 } | 326 } |
331 CXFA_ScriptContext* lpScriptContext = | 327 CXFA_ScriptContext* lpScriptContext = |
332 (CXFA_ScriptContext*)pObject->GetDocument()->GetScriptContext(); | 328 (CXFA_ScriptContext*)pObject->GetDocument()->GetScriptContext(); |
333 pObject = lpScriptContext->GetVariablesThis(pObject); | 329 pObject = lpScriptContext->GetVariablesThis(pObject); |
334 XFA_ELEMENT objElement = pObject->GetClassID(); | 330 XFA_ELEMENT objElement = pObject->GetClassID(); |
335 CFX_WideString wsPropName = CFX_WideString::FromUTF8( | 331 CFX_WideString wsPropName = CFX_WideString::FromUTF8(szPropName); |
336 (const FX_CHAR*)szPropName.raw_str(), szPropName.GetLength()); | |
337 if (XFA_GetMethodByName(objElement, wsPropName.AsWideStringC())) { | 332 if (XFA_GetMethodByName(objElement, wsPropName.AsWideStringC())) { |
338 return FXJSE_ClassPropType_Method; | 333 return FXJSE_ClassPropType_Method; |
339 } | 334 } |
340 if (bQueryIn && | 335 if (bQueryIn && |
341 !XFA_GetScriptAttributeByName(objElement, wsPropName.AsWideStringC())) { | 336 !XFA_GetScriptAttributeByName(objElement, wsPropName.AsWideStringC())) { |
342 return FXJSE_ClassPropType_None; | 337 return FXJSE_ClassPropType_None; |
343 } | 338 } |
344 return FXJSE_ClassPropType_Property; | 339 return FXJSE_ClassPropType_Property; |
345 } | 340 } |
346 int32_t CXFA_ScriptContext::GlobalPropTypeGetter( | 341 int32_t CXFA_ScriptContext::GlobalPropTypeGetter( |
347 FXJSE_HOBJECT hObject, | 342 FXJSE_HOBJECT hObject, |
348 const CFX_ByteStringC& szPropName, | 343 const CFX_ByteStringC& szPropName, |
349 FX_BOOL bQueryIn) { | 344 FX_BOOL bQueryIn) { |
350 CXFA_Object* pObject = (CXFA_Object*)FXJSE_Value_ToObject(hObject, NULL); | 345 CXFA_Object* pObject = (CXFA_Object*)FXJSE_Value_ToObject(hObject, NULL); |
351 if (pObject == NULL) { | 346 if (pObject == NULL) { |
352 return FXJSE_ClassPropType_None; | 347 return FXJSE_ClassPropType_None; |
353 } | 348 } |
354 CXFA_ScriptContext* lpScriptContext = | 349 CXFA_ScriptContext* lpScriptContext = |
355 (CXFA_ScriptContext*)pObject->GetDocument()->GetScriptContext(); | 350 (CXFA_ScriptContext*)pObject->GetDocument()->GetScriptContext(); |
356 pObject = lpScriptContext->GetVariablesThis(pObject); | 351 pObject = lpScriptContext->GetVariablesThis(pObject); |
357 XFA_ELEMENT objElement = pObject->GetClassID(); | 352 XFA_ELEMENT objElement = pObject->GetClassID(); |
358 CFX_WideString wsPropName = CFX_WideString::FromUTF8( | 353 CFX_WideString wsPropName = CFX_WideString::FromUTF8(szPropName); |
359 (const FX_CHAR*)szPropName.raw_str(), szPropName.GetLength()); | |
360 if (XFA_GetMethodByName(objElement, wsPropName.AsWideStringC())) { | 354 if (XFA_GetMethodByName(objElement, wsPropName.AsWideStringC())) { |
361 return FXJSE_ClassPropType_Method; | 355 return FXJSE_ClassPropType_Method; |
362 } | 356 } |
363 return FXJSE_ClassPropType_Property; | 357 return FXJSE_ClassPropType_Property; |
364 } | 358 } |
365 void CXFA_ScriptContext::NormalMethodCall(FXJSE_HOBJECT hThis, | 359 void CXFA_ScriptContext::NormalMethodCall(FXJSE_HOBJECT hThis, |
366 const CFX_ByteStringC& szFuncName, | 360 const CFX_ByteStringC& szFuncName, |
367 CFXJSE_Arguments& args) { | 361 CFXJSE_Arguments& args) { |
368 CXFA_Object* pObject = (CXFA_Object*)FXJSE_Value_ToObject(hThis, NULL); | 362 CXFA_Object* pObject = (CXFA_Object*)FXJSE_Value_ToObject(hThis, NULL); |
369 if (pObject == NULL) { | 363 if (pObject == NULL) { |
370 return; | 364 return; |
371 } | 365 } |
372 CXFA_ScriptContext* lpScriptContext = | 366 CXFA_ScriptContext* lpScriptContext = |
373 (CXFA_ScriptContext*)pObject->GetDocument()->GetScriptContext(); | 367 (CXFA_ScriptContext*)pObject->GetDocument()->GetScriptContext(); |
374 pObject = lpScriptContext->GetVariablesThis(pObject); | 368 pObject = lpScriptContext->GetVariablesThis(pObject); |
375 CFX_WideString wsFunName = CFX_WideString::FromUTF8( | 369 CFX_WideString wsFunName = CFX_WideString::FromUTF8(szFuncName); |
376 (const FX_CHAR*)szFuncName.raw_str(), szFuncName.GetLength()); | |
377 const XFA_METHODINFO* lpMethodInfo = | 370 const XFA_METHODINFO* lpMethodInfo = |
378 XFA_GetMethodByName(pObject->GetClassID(), wsFunName.AsWideStringC()); | 371 XFA_GetMethodByName(pObject->GetClassID(), wsFunName.AsWideStringC()); |
379 if (NULL == lpMethodInfo) { | 372 if (NULL == lpMethodInfo) { |
380 return; | 373 return; |
381 } | 374 } |
382 (pObject->*(lpMethodInfo->lpfnCallback))(&args); | 375 (pObject->*(lpMethodInfo->lpfnCallback))(&args); |
383 } | 376 } |
384 FX_BOOL CXFA_ScriptContext::IsStrictScopeInJavaScript() { | 377 FX_BOOL CXFA_ScriptContext::IsStrictScopeInJavaScript() { |
385 return m_pDocument->HasFlag(XFA_DOCFLAG_StrictScoping); | 378 return m_pDocument->HasFlag(XFA_DOCFLAG_StrictScoping); |
386 } | 379 } |
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
773 } | 766 } |
774 } | 767 } |
775 void CXFA_ScriptContext::AddNodesOfRunScript(CXFA_Node* pNode) { | 768 void CXFA_ScriptContext::AddNodesOfRunScript(CXFA_Node* pNode) { |
776 if (!m_pScriptNodeArray) { | 769 if (!m_pScriptNodeArray) { |
777 return; | 770 return; |
778 } | 771 } |
779 if (m_pScriptNodeArray->Find(pNode) == -1) { | 772 if (m_pScriptNodeArray->Find(pNode) == -1) { |
780 m_pScriptNodeArray->Add(pNode); | 773 m_pScriptNodeArray->Add(pNode); |
781 } | 774 } |
782 } | 775 } |
OLD | NEW |