| 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 "fxjse/include/cfxjse_arguments.h" | 10 #include "fxjse/include/cfxjse_arguments.h" |
| (...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 301 CFXJSE_Value* pReturnValue) { | 301 CFXJSE_Value* pReturnValue) { |
| 302 CXFA_Object* pOriginalObject = ToObject(pOriginalValue, nullptr); | 302 CXFA_Object* pOriginalObject = ToObject(pOriginalValue, nullptr); |
| 303 if (!pOriginalObject) | 303 if (!pOriginalObject) |
| 304 return; | 304 return; |
| 305 | 305 |
| 306 CXFA_ScriptContext* lpScriptContext = | 306 CXFA_ScriptContext* lpScriptContext = |
| 307 pOriginalObject->GetDocument()->GetScriptContext(); | 307 pOriginalObject->GetDocument()->GetScriptContext(); |
| 308 CXFA_Object* pObject = lpScriptContext->GetVariablesThis(pOriginalObject); | 308 CXFA_Object* pObject = lpScriptContext->GetVariablesThis(pOriginalObject); |
| 309 CFX_WideString wsPropName = CFX_WideString::FromUTF8(szPropName); | 309 CFX_WideString wsPropName = CFX_WideString::FromUTF8(szPropName); |
| 310 const XFA_SCRIPTATTRIBUTEINFO* lpAttributeInfo = XFA_GetScriptAttributeByName( | 310 const XFA_SCRIPTATTRIBUTEINFO* lpAttributeInfo = XFA_GetScriptAttributeByName( |
| 311 pObject->GetClassID(), wsPropName.AsStringC()); | 311 pObject->GetElementType(), wsPropName.AsStringC()); |
| 312 if (lpAttributeInfo) { | 312 if (lpAttributeInfo) { |
| 313 (pObject->*(lpAttributeInfo->lpfnCallback))( | 313 (pObject->*(lpAttributeInfo->lpfnCallback))( |
| 314 pReturnValue, TRUE, (XFA_ATTRIBUTE)lpAttributeInfo->eAttribute); | 314 pReturnValue, TRUE, (XFA_ATTRIBUTE)lpAttributeInfo->eAttribute); |
| 315 } else { | 315 } else { |
| 316 if (pObject->IsNode()) { | 316 if (pObject->IsNode()) { |
| 317 if (wsPropName.GetAt(0) == '#') { | 317 if (wsPropName.GetAt(0) == '#') { |
| 318 wsPropName = wsPropName.Right(wsPropName.GetLength() - 1); | 318 wsPropName = wsPropName.Right(wsPropName.GetLength() - 1); |
| 319 } | 319 } |
| 320 CXFA_Node* pNode = ToNode(pObject); | 320 CXFA_Node* pNode = ToNode(pObject); |
| 321 CXFA_Node* pPropOrChild = nullptr; | 321 CXFA_Node* pPropOrChild = nullptr; |
| 322 const XFA_ELEMENTINFO* lpElementInfo = | 322 const XFA_ELEMENTINFO* lpElementInfo = |
| 323 XFA_GetElementByName(wsPropName.AsStringC()); | 323 XFA_GetElementByName(wsPropName.AsStringC()); |
| 324 if (lpElementInfo) { | 324 if (lpElementInfo) { |
| 325 pPropOrChild = pNode->GetProperty(0, lpElementInfo->eName); | 325 pPropOrChild = pNode->GetProperty(0, lpElementInfo->eName); |
| 326 } else { | 326 } else { |
| 327 pPropOrChild = pNode->GetFirstChildByName(wsPropName.AsStringC()); | 327 pPropOrChild = pNode->GetFirstChildByName(wsPropName.AsStringC()); |
| 328 } | 328 } |
| 329 if (pPropOrChild) { | 329 if (pPropOrChild) { |
| 330 CFX_WideString wsDefaultName(L"{default}"); | 330 CFX_WideString wsDefaultName(L"{default}"); |
| 331 const XFA_SCRIPTATTRIBUTEINFO* lpAttrInfo = | 331 const XFA_SCRIPTATTRIBUTEINFO* lpAttrInfo = |
| 332 XFA_GetScriptAttributeByName(pPropOrChild->GetClassID(), | 332 XFA_GetScriptAttributeByName(pPropOrChild->GetElementType(), |
| 333 wsDefaultName.AsStringC()); | 333 wsDefaultName.AsStringC()); |
| 334 if (lpAttrInfo) { | 334 if (lpAttrInfo) { |
| 335 (pPropOrChild->*(lpAttrInfo->lpfnCallback))( | 335 (pPropOrChild->*(lpAttrInfo->lpfnCallback))( |
| 336 pReturnValue, TRUE, (XFA_ATTRIBUTE)lpAttrInfo->eAttribute); | 336 pReturnValue, TRUE, (XFA_ATTRIBUTE)lpAttrInfo->eAttribute); |
| 337 return; | 337 return; |
| 338 } | 338 } |
| 339 } | 339 } |
| 340 } | 340 } |
| 341 CXFA_Object* pScriptObject = | 341 CXFA_Object* pScriptObject = |
| 342 lpScriptContext->GetVariablesThis(pOriginalObject, TRUE); | 342 lpScriptContext->GetVariablesThis(pOriginalObject, TRUE); |
| 343 if (pScriptObject) { | 343 if (pScriptObject) { |
| 344 lpScriptContext->QueryVariableValue(ToNode(pScriptObject), szPropName, | 344 lpScriptContext->QueryVariableValue(ToNode(pScriptObject), szPropName, |
| 345 pReturnValue, FALSE); | 345 pReturnValue, FALSE); |
| 346 } | 346 } |
| 347 } | 347 } |
| 348 } | 348 } |
| 349 int32_t CXFA_ScriptContext::NormalPropTypeGetter( | 349 int32_t CXFA_ScriptContext::NormalPropTypeGetter( |
| 350 CFXJSE_Value* pOriginalValue, | 350 CFXJSE_Value* pOriginalValue, |
| 351 const CFX_ByteStringC& szPropName, | 351 const CFX_ByteStringC& szPropName, |
| 352 FX_BOOL bQueryIn) { | 352 FX_BOOL bQueryIn) { |
| 353 CXFA_Object* pObject = ToObject(pOriginalValue, nullptr); | 353 CXFA_Object* pObject = ToObject(pOriginalValue, nullptr); |
| 354 if (!pObject) | 354 if (!pObject) |
| 355 return FXJSE_ClassPropType_None; | 355 return FXJSE_ClassPropType_None; |
| 356 | 356 |
| 357 CXFA_ScriptContext* lpScriptContext = | 357 CXFA_ScriptContext* lpScriptContext = |
| 358 pObject->GetDocument()->GetScriptContext(); | 358 pObject->GetDocument()->GetScriptContext(); |
| 359 pObject = lpScriptContext->GetVariablesThis(pObject); | 359 pObject = lpScriptContext->GetVariablesThis(pObject); |
| 360 XFA_Element objElement = pObject->GetClassID(); | 360 XFA_Element objElement = pObject->GetElementType(); |
| 361 CFX_WideString wsPropName = CFX_WideString::FromUTF8(szPropName); | 361 CFX_WideString wsPropName = CFX_WideString::FromUTF8(szPropName); |
| 362 if (XFA_GetMethodByName(objElement, wsPropName.AsStringC())) { | 362 if (XFA_GetMethodByName(objElement, wsPropName.AsStringC())) { |
| 363 return FXJSE_ClassPropType_Method; | 363 return FXJSE_ClassPropType_Method; |
| 364 } | 364 } |
| 365 if (bQueryIn && | 365 if (bQueryIn && |
| 366 !XFA_GetScriptAttributeByName(objElement, wsPropName.AsStringC())) { | 366 !XFA_GetScriptAttributeByName(objElement, wsPropName.AsStringC())) { |
| 367 return FXJSE_ClassPropType_None; | 367 return FXJSE_ClassPropType_None; |
| 368 } | 368 } |
| 369 return FXJSE_ClassPropType_Property; | 369 return FXJSE_ClassPropType_Property; |
| 370 } | 370 } |
| 371 int32_t CXFA_ScriptContext::GlobalPropTypeGetter( | 371 int32_t CXFA_ScriptContext::GlobalPropTypeGetter( |
| 372 CFXJSE_Value* pOriginalValue, | 372 CFXJSE_Value* pOriginalValue, |
| 373 const CFX_ByteStringC& szPropName, | 373 const CFX_ByteStringC& szPropName, |
| 374 FX_BOOL bQueryIn) { | 374 FX_BOOL bQueryIn) { |
| 375 CXFA_Object* pObject = ToObject(pOriginalValue, nullptr); | 375 CXFA_Object* pObject = ToObject(pOriginalValue, nullptr); |
| 376 if (!pObject) | 376 if (!pObject) |
| 377 return FXJSE_ClassPropType_None; | 377 return FXJSE_ClassPropType_None; |
| 378 | 378 |
| 379 CXFA_ScriptContext* lpScriptContext = | 379 CXFA_ScriptContext* lpScriptContext = |
| 380 pObject->GetDocument()->GetScriptContext(); | 380 pObject->GetDocument()->GetScriptContext(); |
| 381 pObject = lpScriptContext->GetVariablesThis(pObject); | 381 pObject = lpScriptContext->GetVariablesThis(pObject); |
| 382 XFA_Element objElement = pObject->GetClassID(); | 382 XFA_Element objElement = pObject->GetElementType(); |
| 383 CFX_WideString wsPropName = CFX_WideString::FromUTF8(szPropName); | 383 CFX_WideString wsPropName = CFX_WideString::FromUTF8(szPropName); |
| 384 if (XFA_GetMethodByName(objElement, wsPropName.AsStringC())) { | 384 if (XFA_GetMethodByName(objElement, wsPropName.AsStringC())) { |
| 385 return FXJSE_ClassPropType_Method; | 385 return FXJSE_ClassPropType_Method; |
| 386 } | 386 } |
| 387 return FXJSE_ClassPropType_Property; | 387 return FXJSE_ClassPropType_Property; |
| 388 } | 388 } |
| 389 void CXFA_ScriptContext::NormalMethodCall(CFXJSE_Value* pThis, | 389 void CXFA_ScriptContext::NormalMethodCall(CFXJSE_Value* pThis, |
| 390 const CFX_ByteStringC& szFuncName, | 390 const CFX_ByteStringC& szFuncName, |
| 391 CFXJSE_Arguments& args) { | 391 CFXJSE_Arguments& args) { |
| 392 CXFA_Object* pObject = ToObject(pThis, nullptr); | 392 CXFA_Object* pObject = ToObject(pThis, nullptr); |
| 393 if (!pObject) | 393 if (!pObject) |
| 394 return; | 394 return; |
| 395 | 395 |
| 396 CXFA_ScriptContext* lpScriptContext = | 396 CXFA_ScriptContext* lpScriptContext = |
| 397 pObject->GetDocument()->GetScriptContext(); | 397 pObject->GetDocument()->GetScriptContext(); |
| 398 pObject = lpScriptContext->GetVariablesThis(pObject); | 398 pObject = lpScriptContext->GetVariablesThis(pObject); |
| 399 CFX_WideString wsFunName = CFX_WideString::FromUTF8(szFuncName); | 399 CFX_WideString wsFunName = CFX_WideString::FromUTF8(szFuncName); |
| 400 const XFA_METHODINFO* lpMethodInfo = | 400 const XFA_METHODINFO* lpMethodInfo = |
| 401 XFA_GetMethodByName(pObject->GetClassID(), wsFunName.AsStringC()); | 401 XFA_GetMethodByName(pObject->GetElementType(), wsFunName.AsStringC()); |
| 402 if (!lpMethodInfo) | 402 if (!lpMethodInfo) |
| 403 return; | 403 return; |
| 404 | 404 |
| 405 (pObject->*(lpMethodInfo->lpfnCallback))(&args); | 405 (pObject->*(lpMethodInfo->lpfnCallback))(&args); |
| 406 } | 406 } |
| 407 FX_BOOL CXFA_ScriptContext::IsStrictScopeInJavaScript() { | 407 FX_BOOL CXFA_ScriptContext::IsStrictScopeInJavaScript() { |
| 408 return m_pDocument->HasFlag(XFA_DOCFLAG_StrictScoping); | 408 return m_pDocument->HasFlag(XFA_DOCFLAG_StrictScoping); |
| 409 } | 409 } |
| 410 XFA_SCRIPTLANGTYPE CXFA_ScriptContext::GetType() { | 410 XFA_SCRIPTLANGTYPE CXFA_ScriptContext::GetType() { |
| 411 return m_eScriptType; | 411 return m_eScriptType; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 436 return pObject; | 436 return pObject; |
| 437 | 437 |
| 438 CXFA_ThisProxy* pProxy = static_cast<CXFA_ThisProxy*>(pObject); | 438 CXFA_ThisProxy* pProxy = static_cast<CXFA_ThisProxy*>(pObject); |
| 439 return bScriptNode ? pProxy->GetScriptNode() : pProxy->GetThisNode(); | 439 return bScriptNode ? pProxy->GetScriptNode() : pProxy->GetThisNode(); |
| 440 } | 440 } |
| 441 | 441 |
| 442 FX_BOOL CXFA_ScriptContext::RunVariablesScript(CXFA_Node* pScriptNode) { | 442 FX_BOOL CXFA_ScriptContext::RunVariablesScript(CXFA_Node* pScriptNode) { |
| 443 if (!pScriptNode) | 443 if (!pScriptNode) |
| 444 return FALSE; | 444 return FALSE; |
| 445 | 445 |
| 446 if (pScriptNode->GetClassID() != XFA_Element::Script) | 446 if (pScriptNode->GetElementType() != XFA_Element::Script) |
| 447 return TRUE; | 447 return TRUE; |
| 448 | 448 |
| 449 CXFA_Node* pParent = pScriptNode->GetNodeItem(XFA_NODEITEM_Parent); | 449 CXFA_Node* pParent = pScriptNode->GetNodeItem(XFA_NODEITEM_Parent); |
| 450 if (!pParent || pParent->GetClassID() != XFA_Element::Variables) | 450 if (!pParent || pParent->GetElementType() != XFA_Element::Variables) |
| 451 return FALSE; | 451 return FALSE; |
| 452 | 452 |
| 453 if (m_mapVariableToContext.GetValueAt(pScriptNode)) | 453 if (m_mapVariableToContext.GetValueAt(pScriptNode)) |
| 454 return TRUE; | 454 return TRUE; |
| 455 | 455 |
| 456 CXFA_Node* pTextNode = pScriptNode->GetNodeItem(XFA_NODEITEM_FirstChild); | 456 CXFA_Node* pTextNode = pScriptNode->GetNodeItem(XFA_NODEITEM_FirstChild); |
| 457 if (!pTextNode) | 457 if (!pTextNode) |
| 458 return FALSE; | 458 return FALSE; |
| 459 | 459 |
| 460 CFX_WideStringC wsScript; | 460 CFX_WideStringC wsScript; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 473 pVariablesContext->ExecuteScript(btScript.c_str(), hRetValue.get()); | 473 pVariablesContext->ExecuteScript(btScript.c_str(), hRetValue.get()); |
| 474 m_pThisObject = pOriginalObject; | 474 m_pThisObject = pOriginalObject; |
| 475 return bRet; | 475 return bRet; |
| 476 } | 476 } |
| 477 | 477 |
| 478 FX_BOOL CXFA_ScriptContext::QueryVariableValue( | 478 FX_BOOL CXFA_ScriptContext::QueryVariableValue( |
| 479 CXFA_Node* pScriptNode, | 479 CXFA_Node* pScriptNode, |
| 480 const CFX_ByteStringC& szPropName, | 480 const CFX_ByteStringC& szPropName, |
| 481 CFXJSE_Value* pValue, | 481 CFXJSE_Value* pValue, |
| 482 FX_BOOL bGetter) { | 482 FX_BOOL bGetter) { |
| 483 if (!pScriptNode || pScriptNode->GetClassID() != XFA_Element::Script) | 483 if (!pScriptNode || pScriptNode->GetElementType() != XFA_Element::Script) |
| 484 return FALSE; | 484 return FALSE; |
| 485 | 485 |
| 486 CXFA_Node* variablesNode = pScriptNode->GetNodeItem(XFA_NODEITEM_Parent); | 486 CXFA_Node* variablesNode = pScriptNode->GetNodeItem(XFA_NODEITEM_Parent); |
| 487 if (!variablesNode || variablesNode->GetClassID() != XFA_Element::Variables) | 487 if (!variablesNode || |
| 488 variablesNode->GetElementType() != XFA_Element::Variables) |
| 488 return FALSE; | 489 return FALSE; |
| 489 | 490 |
| 490 void* lpVariables = m_mapVariableToContext.GetValueAt(pScriptNode); | 491 void* lpVariables = m_mapVariableToContext.GetValueAt(pScriptNode); |
| 491 if (!lpVariables) | 492 if (!lpVariables) |
| 492 return FALSE; | 493 return FALSE; |
| 493 | 494 |
| 494 FX_BOOL bRes = FALSE; | 495 FX_BOOL bRes = FALSE; |
| 495 CFXJSE_Context* pVariableContext = static_cast<CFXJSE_Context*>(lpVariables); | 496 CFXJSE_Context* pVariableContext = static_cast<CFXJSE_Context*>(lpVariables); |
| 496 std::unique_ptr<CFXJSE_Value> pObject = pVariableContext->GetGlobalObject(); | 497 std::unique_ptr<CFXJSE_Value> pObject = pVariableContext->GetGlobalObject(); |
| 497 std::unique_ptr<CFXJSE_Value> hVariableValue(new CFXJSE_Value(m_pIsolate)); | 498 std::unique_ptr<CFXJSE_Value> hVariableValue(new CFXJSE_Value(m_pIsolate)); |
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 736 return; | 737 return; |
| 737 if (nodes.GetSize() > 0) | 738 if (nodes.GetSize() > 0) |
| 738 m_pScriptNodeArray->Copy(nodes); | 739 m_pScriptNodeArray->Copy(nodes); |
| 739 } | 740 } |
| 740 void CXFA_ScriptContext::AddNodesOfRunScript(CXFA_Node* pNode) { | 741 void CXFA_ScriptContext::AddNodesOfRunScript(CXFA_Node* pNode) { |
| 741 if (!m_pScriptNodeArray) | 742 if (!m_pScriptNodeArray) |
| 742 return; | 743 return; |
| 743 if (m_pScriptNodeArray->Find(pNode) == -1) | 744 if (m_pScriptNodeArray->Find(pNode) == -1) |
| 744 m_pScriptNodeArray->Add(pNode); | 745 m_pScriptNodeArray->Add(pNode); |
| 745 } | 746 } |
| OLD | NEW |