Chromium Code Reviews| 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/cxfa_scriptcontext.h" | 7 #include "xfa/fxfa/parser/cxfa_scriptcontext.h" |
| 8 | 8 |
| 9 #include "core/fxcrt/include/fx_ext.h" | 9 #include "core/fxcrt/include/fx_ext.h" |
| 10 #include "fxjs/include/cfxjse_arguments.h" | 10 #include "fxjs/include/cfxjse_arguments.h" |
| 11 #include "fxjs/include/cfxjse_class.h" | 11 #include "fxjs/include/cfxjse_class.h" |
| 12 #include "fxjs/include/cfxjse_value.h" | 12 #include "fxjs/include/cfxjse_value.h" |
| 13 #include "xfa/fxfa/app/xfa_ffnotify.h" | 13 #include "xfa/fxfa/app/xfa_ffnotify.h" |
| 14 #include "xfa/fxfa/include/cxfa_eventparam.h" | 14 #include "xfa/fxfa/include/cxfa_eventparam.h" |
| 15 #include "xfa/fxfa/parser/cxfa_nodehelper.h" | 15 #include "xfa/fxfa/parser/cxfa_nodehelper.h" |
| 16 #include "xfa/fxfa/parser/cxfa_resolveprocessor.h" | 16 #include "xfa/fxfa/parser/cxfa_resolveprocessor.h" |
| 17 #include "xfa/fxfa/parser/xfa_basic_data.h" | |
| 17 #include "xfa/fxfa/parser/xfa_doclayout.h" | 18 #include "xfa/fxfa/parser/xfa_doclayout.h" |
| 18 #include "xfa/fxfa/parser/xfa_document.h" | 19 #include "xfa/fxfa/parser/xfa_document.h" |
| 19 #include "xfa/fxfa/parser/xfa_localemgr.h" | 20 #include "xfa/fxfa/parser/xfa_localemgr.h" |
| 20 #include "xfa/fxfa/parser/xfa_object.h" | 21 #include "xfa/fxfa/parser/xfa_object.h" |
| 21 #include "xfa/fxfa/parser/xfa_resolvenode_rs.h" | 22 #include "xfa/fxfa/parser/xfa_resolvenode_rs.h" |
| 22 #include "xfa/fxfa/parser/xfa_utils.h" | 23 #include "xfa/fxfa/parser/xfa_utils.h" |
| 23 | 24 |
| 24 namespace { | 25 namespace { |
| 25 | 26 |
| 26 const FXJSE_CLASS_DESCRIPTOR GlobalClassDescriptor = { | 27 const FXJSE_CLASS_DESCRIPTOR GlobalClassDescriptor = { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 64 nullptr, // property deleter | 65 nullptr, // property deleter |
| 65 CXFA_ScriptContext::NormalMethodCall, | 66 CXFA_ScriptContext::NormalMethodCall, |
| 66 }; | 67 }; |
| 67 | 68 |
| 68 const char kFormCalcRuntime[] = "foxit_xfa_formcalc_runtime"; | 69 const char kFormCalcRuntime[] = "foxit_xfa_formcalc_runtime"; |
| 69 | 70 |
| 70 CXFA_ThisProxy* ToThisProxy(CFXJSE_Value* pValue, CFXJSE_Class* pClass) { | 71 CXFA_ThisProxy* ToThisProxy(CFXJSE_Value* pValue, CFXJSE_Class* pClass) { |
| 71 return static_cast<CXFA_ThisProxy*>(pValue->ToHostObject(pClass)); | 72 return static_cast<CXFA_ThisProxy*>(pValue->ToHostObject(pClass)); |
| 72 } | 73 } |
| 73 | 74 |
| 75 const XFA_METHODINFO* GetMethodByName(XFA_Element eElement, | |
| 76 const CFX_WideStringC& wsMethodName) { | |
| 77 if (wsMethodName.IsEmpty()) | |
| 78 return nullptr; | |
| 79 | |
| 80 int32_t iElementIndex = static_cast<int32_t>(eElement); | |
| 81 while (iElementIndex != -1) { | |
|
Lei Zhang
2016/07/20 20:54:33
Should we check we never go out of bound w.r.t. g_
dsinclair
2016/07/21 13:34:24
Done.
| |
| 82 const XFA_SCRIPTHIERARCHY* scriptIndex = g_XFAScriptIndex + iElementIndex; | |
| 83 int32_t icount = scriptIndex->wMethodCount; | |
| 84 if (icount == 0) { | |
| 85 iElementIndex = scriptIndex->wParentIndex; | |
| 86 continue; | |
| 87 } | |
| 88 uint32_t uHash = FX_HashCode_GetW(wsMethodName, false); | |
| 89 int32_t iStart = scriptIndex->wMethodStart; | |
| 90 int32_t iEnd = iStart + icount - 1; | |
| 91 do { | |
| 92 int32_t iMid = (iStart + iEnd) / 2; | |
|
Lei Zhang
2016/07/20 20:54:33
std::lower_bound() later?
dsinclair
2016/07/21 13:34:24
Acknowledged.
| |
| 93 const XFA_METHODINFO* pInfo = g_SomMethodData + iMid; | |
| 94 if (uHash == pInfo->uHash) | |
| 95 return pInfo; | |
| 96 if (uHash < pInfo->uHash) | |
| 97 iEnd = iMid - 1; | |
| 98 else | |
| 99 iStart = iMid + 1; | |
| 100 } while (iStart <= iEnd); | |
| 101 iElementIndex = scriptIndex->wParentIndex; | |
| 102 } | |
| 103 return nullptr; | |
| 104 } | |
| 105 | |
| 74 } // namespace | 106 } // namespace |
| 75 | 107 |
| 76 // static. | 108 // static. |
| 77 CXFA_Object* CXFA_ScriptContext::ToObject(CFXJSE_Value* pValue, | 109 CXFA_Object* CXFA_ScriptContext::ToObject(CFXJSE_Value* pValue, |
| 78 CFXJSE_Class* pClass) { | 110 CFXJSE_Class* pClass) { |
| 79 return static_cast<CXFA_Object*>(pValue->ToHostObject(pClass)); | 111 return static_cast<CXFA_Object*>(pValue->ToHostObject(pClass)); |
| 80 } | 112 } |
| 81 | 113 |
| 82 CXFA_ScriptContext::CXFA_ScriptContext(CXFA_Document* pDocument) | 114 CXFA_ScriptContext::CXFA_ScriptContext(CXFA_Document* pDocument) |
| 83 : m_pDocument(pDocument), | 115 : m_pDocument(pDocument), |
| (...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 350 FX_BOOL bQueryIn) { | 382 FX_BOOL bQueryIn) { |
| 351 CXFA_Object* pObject = ToObject(pOriginalValue, nullptr); | 383 CXFA_Object* pObject = ToObject(pOriginalValue, nullptr); |
| 352 if (!pObject) | 384 if (!pObject) |
| 353 return FXJSE_ClassPropType_None; | 385 return FXJSE_ClassPropType_None; |
| 354 | 386 |
| 355 CXFA_ScriptContext* lpScriptContext = | 387 CXFA_ScriptContext* lpScriptContext = |
| 356 pObject->GetDocument()->GetScriptContext(); | 388 pObject->GetDocument()->GetScriptContext(); |
| 357 pObject = lpScriptContext->GetVariablesThis(pObject); | 389 pObject = lpScriptContext->GetVariablesThis(pObject); |
| 358 XFA_Element eType = pObject->GetElementType(); | 390 XFA_Element eType = pObject->GetElementType(); |
| 359 CFX_WideString wsPropName = CFX_WideString::FromUTF8(szPropName); | 391 CFX_WideString wsPropName = CFX_WideString::FromUTF8(szPropName); |
| 360 if (XFA_GetMethodByName(eType, wsPropName.AsStringC())) { | 392 if (GetMethodByName(eType, wsPropName.AsStringC())) { |
| 361 return FXJSE_ClassPropType_Method; | 393 return FXJSE_ClassPropType_Method; |
| 362 } | 394 } |
| 363 if (bQueryIn && | 395 if (bQueryIn && |
| 364 !XFA_GetScriptAttributeByName(eType, wsPropName.AsStringC())) { | 396 !XFA_GetScriptAttributeByName(eType, wsPropName.AsStringC())) { |
| 365 return FXJSE_ClassPropType_None; | 397 return FXJSE_ClassPropType_None; |
| 366 } | 398 } |
| 367 return FXJSE_ClassPropType_Property; | 399 return FXJSE_ClassPropType_Property; |
| 368 } | 400 } |
| 369 int32_t CXFA_ScriptContext::GlobalPropTypeGetter( | 401 int32_t CXFA_ScriptContext::GlobalPropTypeGetter( |
| 370 CFXJSE_Value* pOriginalValue, | 402 CFXJSE_Value* pOriginalValue, |
| 371 const CFX_ByteStringC& szPropName, | 403 const CFX_ByteStringC& szPropName, |
| 372 FX_BOOL bQueryIn) { | 404 FX_BOOL bQueryIn) { |
| 373 CXFA_Object* pObject = ToObject(pOriginalValue, nullptr); | 405 CXFA_Object* pObject = ToObject(pOriginalValue, nullptr); |
| 374 if (!pObject) | 406 if (!pObject) |
| 375 return FXJSE_ClassPropType_None; | 407 return FXJSE_ClassPropType_None; |
| 376 | 408 |
| 377 CXFA_ScriptContext* lpScriptContext = | 409 CXFA_ScriptContext* lpScriptContext = |
| 378 pObject->GetDocument()->GetScriptContext(); | 410 pObject->GetDocument()->GetScriptContext(); |
| 379 pObject = lpScriptContext->GetVariablesThis(pObject); | 411 pObject = lpScriptContext->GetVariablesThis(pObject); |
| 380 XFA_Element eType = pObject->GetElementType(); | 412 XFA_Element eType = pObject->GetElementType(); |
| 381 CFX_WideString wsPropName = CFX_WideString::FromUTF8(szPropName); | 413 CFX_WideString wsPropName = CFX_WideString::FromUTF8(szPropName); |
| 382 if (XFA_GetMethodByName(eType, wsPropName.AsStringC())) { | 414 if (GetMethodByName(eType, wsPropName.AsStringC())) { |
| 383 return FXJSE_ClassPropType_Method; | 415 return FXJSE_ClassPropType_Method; |
| 384 } | 416 } |
| 385 return FXJSE_ClassPropType_Property; | 417 return FXJSE_ClassPropType_Property; |
| 386 } | 418 } |
| 387 void CXFA_ScriptContext::NormalMethodCall(CFXJSE_Value* pThis, | 419 void CXFA_ScriptContext::NormalMethodCall(CFXJSE_Value* pThis, |
| 388 const CFX_ByteStringC& szFuncName, | 420 const CFX_ByteStringC& szFuncName, |
| 389 CFXJSE_Arguments& args) { | 421 CFXJSE_Arguments& args) { |
| 390 CXFA_Object* pObject = ToObject(pThis, nullptr); | 422 CXFA_Object* pObject = ToObject(pThis, nullptr); |
| 391 if (!pObject) | 423 if (!pObject) |
| 392 return; | 424 return; |
| 393 | 425 |
| 394 CXFA_ScriptContext* lpScriptContext = | 426 CXFA_ScriptContext* lpScriptContext = |
| 395 pObject->GetDocument()->GetScriptContext(); | 427 pObject->GetDocument()->GetScriptContext(); |
| 396 pObject = lpScriptContext->GetVariablesThis(pObject); | 428 pObject = lpScriptContext->GetVariablesThis(pObject); |
| 397 CFX_WideString wsFunName = CFX_WideString::FromUTF8(szFuncName); | 429 CFX_WideString wsFunName = CFX_WideString::FromUTF8(szFuncName); |
| 398 const XFA_METHODINFO* lpMethodInfo = | 430 const XFA_METHODINFO* lpMethodInfo = |
| 399 XFA_GetMethodByName(pObject->GetElementType(), wsFunName.AsStringC()); | 431 GetMethodByName(pObject->GetElementType(), wsFunName.AsStringC()); |
| 400 if (!lpMethodInfo) | 432 if (!lpMethodInfo) |
| 401 return; | 433 return; |
| 402 | 434 |
| 403 (pObject->*(lpMethodInfo->lpfnCallback))(&args); | 435 (pObject->*(lpMethodInfo->lpfnCallback))(&args); |
| 404 } | 436 } |
| 405 FX_BOOL CXFA_ScriptContext::IsStrictScopeInJavaScript() { | 437 FX_BOOL CXFA_ScriptContext::IsStrictScopeInJavaScript() { |
| 406 return m_pDocument->HasFlag(XFA_DOCFLAG_StrictScoping); | 438 return m_pDocument->HasFlag(XFA_DOCFLAG_StrictScoping); |
| 407 } | 439 } |
| 408 XFA_SCRIPTLANGTYPE CXFA_ScriptContext::GetType() { | 440 XFA_SCRIPTLANGTYPE CXFA_ScriptContext::GetType() { |
| 409 return m_eScriptType; | 441 return m_eScriptType; |
| (...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 730 return; | 762 return; |
| 731 if (nodes.GetSize() > 0) | 763 if (nodes.GetSize() > 0) |
| 732 m_pScriptNodeArray->Copy(nodes); | 764 m_pScriptNodeArray->Copy(nodes); |
| 733 } | 765 } |
| 734 void CXFA_ScriptContext::AddNodesOfRunScript(CXFA_Node* pNode) { | 766 void CXFA_ScriptContext::AddNodesOfRunScript(CXFA_Node* pNode) { |
| 735 if (!m_pScriptNodeArray) | 767 if (!m_pScriptNodeArray) |
| 736 return; | 768 return; |
| 737 if (m_pScriptNodeArray->Find(pNode) == -1) | 769 if (m_pScriptNodeArray->Find(pNode) == -1) |
| 738 m_pScriptNodeArray->Add(pNode); | 770 m_pScriptNodeArray->Add(pNode); |
| 739 } | 771 } |
| OLD | NEW |