From 31f8740fe51ceca8e973a2efe40d4d440d7a5cb7 Mon Sep 17 00:00:00 2001 From: dsinclair Date: Wed, 20 Jul 2016 06:34:45 -0700 Subject: Rename remaining xfa_script_* files. This Cl renames the remaining xfa_script_* files to match the class names contained within the files. Review-Url: https://codereview.chromium.org/2160343002 --- xfa/fxfa/app/xfa_ffdochandler.cpp | 4 +- xfa/fxfa/app/xfa_ffdocview.cpp | 4 +- xfa/fxfa/app/xfa_ffwidgetacc.cpp | 4 +- xfa/fxfa/fm2js/xfa_fm2jscontext.cpp | 2 +- xfa/fxfa/fm2js/xfa_fm2jscontext.h | 2 +- xfa/fxfa/parser/cscript_datawindow.cpp | 1 - xfa/fxfa/parser/cscript_eventpseudomodel.cpp | 3 +- xfa/fxfa/parser/cscript_hostpseudomodel.cpp | 4 +- xfa/fxfa/parser/cscript_layoutpseudomodel.cpp | 3 +- xfa/fxfa/parser/cscript_logpseudomodel.cpp | 1 - xfa/fxfa/parser/cscript_signaturepseudomodel.cpp | 3 +- xfa/fxfa/parser/cxfa_node.cpp | 2 +- xfa/fxfa/parser/cxfa_nodehelper.cpp | 429 +++++++++++ xfa/fxfa/parser/cxfa_nodehelper.h | 72 ++ xfa/fxfa/parser/cxfa_nodelist.cpp | 2 +- xfa/fxfa/parser/cxfa_resolveprocessor.cpp | 826 ++++++++++++++++++++++ xfa/fxfa/parser/cxfa_resolveprocessor.h | 78 ++ xfa/fxfa/parser/cxfa_scriptcontext.cpp | 739 +++++++++++++++++++ xfa/fxfa/parser/cxfa_scriptcontext.h | 126 ++++ xfa/fxfa/parser/cxfa_valuearray.cpp | 2 +- xfa/fxfa/parser/xfa_basic_data_element_script.cpp | 1 - xfa/fxfa/parser/xfa_basic_imp.cpp | 1 - xfa/fxfa/parser/xfa_document_datamerger_imp.cpp | 4 +- xfa/fxfa/parser/xfa_document_imp.cpp | 4 +- xfa/fxfa/parser/xfa_document_layout_imp.cpp | 1 - xfa/fxfa/parser/xfa_document_serialize.cpp | 1 - xfa/fxfa/parser/xfa_layout_appadapter.cpp | 1 - xfa/fxfa/parser/xfa_layout_itemlayout.cpp | 1 - xfa/fxfa/parser/xfa_layout_pagemgr_new.cpp | 4 +- xfa/fxfa/parser/xfa_locale.cpp | 1 - xfa/fxfa/parser/xfa_localemgr.cpp | 1 - xfa/fxfa/parser/xfa_localevalue.cpp | 1 - xfa/fxfa/parser/xfa_resolvenode_rs.h | 68 ++ xfa/fxfa/parser/xfa_script.h | 68 -- xfa/fxfa/parser/xfa_script_imp.cpp | 739 ------------------- xfa/fxfa/parser/xfa_script_imp.h | 126 ---- xfa/fxfa/parser/xfa_script_nodehelper.cpp | 429 ----------- xfa/fxfa/parser/xfa_script_nodehelper.h | 72 -- xfa/fxfa/parser/xfa_script_resolveprocessor.cpp | 826 ---------------------- xfa/fxfa/parser/xfa_script_resolveprocessor.h | 78 -- xfa/fxfa/parser/xfa_utils_imp.cpp | 1 - 41 files changed, 2360 insertions(+), 2375 deletions(-) create mode 100644 xfa/fxfa/parser/cxfa_nodehelper.cpp create mode 100644 xfa/fxfa/parser/cxfa_nodehelper.h create mode 100644 xfa/fxfa/parser/cxfa_resolveprocessor.cpp create mode 100644 xfa/fxfa/parser/cxfa_resolveprocessor.h create mode 100644 xfa/fxfa/parser/cxfa_scriptcontext.cpp create mode 100644 xfa/fxfa/parser/cxfa_scriptcontext.h create mode 100644 xfa/fxfa/parser/xfa_resolvenode_rs.h delete mode 100644 xfa/fxfa/parser/xfa_script.h delete mode 100644 xfa/fxfa/parser/xfa_script_imp.cpp delete mode 100644 xfa/fxfa/parser/xfa_script_imp.h delete mode 100644 xfa/fxfa/parser/xfa_script_nodehelper.cpp delete mode 100644 xfa/fxfa/parser/xfa_script_nodehelper.h delete mode 100644 xfa/fxfa/parser/xfa_script_resolveprocessor.cpp delete mode 100644 xfa/fxfa/parser/xfa_script_resolveprocessor.h (limited to 'xfa/fxfa') diff --git a/xfa/fxfa/app/xfa_ffdochandler.cpp b/xfa/fxfa/app/xfa_ffdochandler.cpp index e0a28337ca..fdaba40b4b 100644 --- a/xfa/fxfa/app/xfa_ffdochandler.cpp +++ b/xfa/fxfa/app/xfa_ffdochandler.cpp @@ -8,8 +8,8 @@ #include "xfa/fxfa/include/xfa_checksum.h" #include "xfa/fxfa/include/xfa_ffdoc.h" -#include "xfa/fxfa/parser/xfa_script.h" -#include "xfa/fxfa/parser/xfa_script_imp.h" +#include "xfa/fxfa/parser/cxfa_scriptcontext.h" +#include "xfa/fxfa/parser/xfa_resolvenode_rs.h" CXFA_FFDocHandler::CXFA_FFDocHandler() {} diff --git a/xfa/fxfa/app/xfa_ffdocview.cpp b/xfa/fxfa/app/xfa_ffdocview.cpp index 7c7136b1ca..bbed31be25 100644 --- a/xfa/fxfa/app/xfa_ffdocview.cpp +++ b/xfa/fxfa/app/xfa_ffdocview.cpp @@ -30,9 +30,9 @@ #include "xfa/fxfa/include/xfa_ffwidget.h" #include "xfa/fxfa/include/xfa_ffwidgethandler.h" #include "xfa/fxfa/parser/cxfa_binditems.h" +#include "xfa/fxfa/parser/cxfa_scriptcontext.h" #include "xfa/fxfa/parser/xfa_document_layout_imp.h" -#include "xfa/fxfa/parser/xfa_script.h" -#include "xfa/fxfa/parser/xfa_script_imp.h" +#include "xfa/fxfa/parser/xfa_resolvenode_rs.h" extern const XFA_ATTRIBUTEENUM gs_EventActivity[] = { XFA_ATTRIBUTEENUM_Click, XFA_ATTRIBUTEENUM_Change, diff --git a/xfa/fxfa/app/xfa_ffwidgetacc.cpp b/xfa/fxfa/app/xfa_ffwidgetacc.cpp index fec0c20c58..57bd7bf80d 100644 --- a/xfa/fxfa/app/xfa_ffwidgetacc.cpp +++ b/xfa/fxfa/app/xfa_ffwidgetacc.cpp @@ -24,10 +24,10 @@ #include "xfa/fxfa/include/xfa_ffpageview.h" #include "xfa/fxfa/include/xfa_ffwidget.h" #include "xfa/fxfa/include/xfa_fontmgr.h" +#include "xfa/fxfa/parser/cxfa_scriptcontext.h" #include "xfa/fxfa/parser/xfa_document_layout_imp.h" #include "xfa/fxfa/parser/xfa_localevalue.h" -#include "xfa/fxfa/parser/xfa_script.h" -#include "xfa/fxfa/parser/xfa_script_imp.h" +#include "xfa/fxfa/parser/xfa_resolvenode_rs.h" static void XFA_FFDeleteCalcData(void* pData) { if (pData) { diff --git a/xfa/fxfa/fm2js/xfa_fm2jscontext.cpp b/xfa/fxfa/fm2js/xfa_fm2jscontext.cpp index b5bc6757c4..357fd7e3fe 100644 --- a/xfa/fxfa/fm2js/xfa_fm2jscontext.cpp +++ b/xfa/fxfa/fm2js/xfa_fm2jscontext.cpp @@ -15,9 +15,9 @@ #include "xfa/fgas/localization/fgas_locale.h" #include "xfa/fxfa/app/xfa_ffnotify.h" #include "xfa/fxfa/fm2js/xfa_program.h" +#include "xfa/fxfa/parser/cxfa_scriptcontext.h" #include "xfa/fxfa/parser/xfa_document.h" #include "xfa/fxfa/parser/xfa_localevalue.h" -#include "xfa/fxfa/parser/xfa_script_imp.h" namespace { diff --git a/xfa/fxfa/fm2js/xfa_fm2jscontext.h b/xfa/fxfa/fm2js/xfa_fm2jscontext.h index fc98dbbd4a..1483cbc707 100644 --- a/xfa/fxfa/fm2js/xfa_fm2jscontext.h +++ b/xfa/fxfa/fm2js/xfa_fm2jscontext.h @@ -9,7 +9,7 @@ #include "fxjs/include/cfxjse_arguments.h" #include "fxjs/include/cfxjse_context.h" -#include "xfa/fxfa/parser/xfa_script.h" +#include "xfa/fxfa/parser/xfa_resolvenode_rs.h" class CXFA_FM2JSContext : public CFXJSE_HostObject { public: diff --git a/xfa/fxfa/parser/cscript_datawindow.cpp b/xfa/fxfa/parser/cscript_datawindow.cpp index a5b0587d4d..43f22446e3 100644 --- a/xfa/fxfa/parser/cscript_datawindow.cpp +++ b/xfa/fxfa/parser/cscript_datawindow.cpp @@ -11,7 +11,6 @@ #include "xfa/fxfa/parser/xfa_document.h" #include "xfa/fxfa/parser/xfa_localemgr.h" #include "xfa/fxfa/parser/xfa_object.h" -#include "xfa/fxfa/parser/xfa_script.h" #include "xfa/fxfa/parser/xfa_utils.h" CScript_DataWindow::CScript_DataWindow(CXFA_Document* pDocument) diff --git a/xfa/fxfa/parser/cscript_eventpseudomodel.cpp b/xfa/fxfa/parser/cscript_eventpseudomodel.cpp index d1d1aeaaa9..6b08cdc92b 100644 --- a/xfa/fxfa/parser/cscript_eventpseudomodel.cpp +++ b/xfa/fxfa/parser/cscript_eventpseudomodel.cpp @@ -10,12 +10,11 @@ #include "xfa/fxfa/app/xfa_ffnotify.h" #include "xfa/fxfa/include/cxfa_eventparam.h" #include "xfa/fxfa/include/xfa_ffwidgethandler.h" +#include "xfa/fxfa/parser/cxfa_scriptcontext.h" #include "xfa/fxfa/parser/xfa_doclayout.h" #include "xfa/fxfa/parser/xfa_document.h" #include "xfa/fxfa/parser/xfa_localemgr.h" #include "xfa/fxfa/parser/xfa_object.h" -#include "xfa/fxfa/parser/xfa_script.h" -#include "xfa/fxfa/parser/xfa_script_imp.h" #include "xfa/fxfa/parser/xfa_utils.h" namespace { diff --git a/xfa/fxfa/parser/cscript_hostpseudomodel.cpp b/xfa/fxfa/parser/cscript_hostpseudomodel.cpp index 365d268b0e..eb4fcd9a29 100644 --- a/xfa/fxfa/parser/cscript_hostpseudomodel.cpp +++ b/xfa/fxfa/parser/cscript_hostpseudomodel.cpp @@ -8,13 +8,13 @@ #include "fxjs/include/cfxjse_arguments.h" #include "xfa/fxfa/app/xfa_ffnotify.h" +#include "xfa/fxfa/parser/cxfa_scriptcontext.h" #include "xfa/fxfa/parser/xfa_doclayout.h" #include "xfa/fxfa/parser/xfa_document.h" #include "xfa/fxfa/parser/xfa_document_layout_imp.h" #include "xfa/fxfa/parser/xfa_localemgr.h" #include "xfa/fxfa/parser/xfa_object.h" -#include "xfa/fxfa/parser/xfa_script.h" -#include "xfa/fxfa/parser/xfa_script_imp.h" +#include "xfa/fxfa/parser/xfa_resolvenode_rs.h" #include "xfa/fxfa/parser/xfa_utils.h" namespace { diff --git a/xfa/fxfa/parser/cscript_layoutpseudomodel.cpp b/xfa/fxfa/parser/cscript_layoutpseudomodel.cpp index d50f1b77d6..10bfd6defa 100644 --- a/xfa/fxfa/parser/cscript_layoutpseudomodel.cpp +++ b/xfa/fxfa/parser/cscript_layoutpseudomodel.cpp @@ -11,14 +11,13 @@ #include "fxjs/include/cfxjse_arguments.h" #include "third_party/base/stl_util.h" #include "xfa/fxfa/app/xfa_ffnotify.h" +#include "xfa/fxfa/parser/cxfa_scriptcontext.h" #include "xfa/fxfa/parser/xfa_doclayout.h" #include "xfa/fxfa/parser/xfa_document.h" #include "xfa/fxfa/parser/xfa_document_layout_imp.h" #include "xfa/fxfa/parser/xfa_layout_appadapter.h" #include "xfa/fxfa/parser/xfa_localemgr.h" #include "xfa/fxfa/parser/xfa_object.h" -#include "xfa/fxfa/parser/xfa_script.h" -#include "xfa/fxfa/parser/xfa_script_imp.h" #include "xfa/fxfa/parser/xfa_utils.h" CScript_LayoutPseudoModel::CScript_LayoutPseudoModel(CXFA_Document* pDocument) diff --git a/xfa/fxfa/parser/cscript_logpseudomodel.cpp b/xfa/fxfa/parser/cscript_logpseudomodel.cpp index ae3629d5a5..fbb13af035 100644 --- a/xfa/fxfa/parser/cscript_logpseudomodel.cpp +++ b/xfa/fxfa/parser/cscript_logpseudomodel.cpp @@ -11,7 +11,6 @@ #include "xfa/fxfa/parser/xfa_document.h" #include "xfa/fxfa/parser/xfa_localemgr.h" #include "xfa/fxfa/parser/xfa_object.h" -#include "xfa/fxfa/parser/xfa_script.h" #include "xfa/fxfa/parser/xfa_utils.h" CScript_LogPseudoModel::CScript_LogPseudoModel(CXFA_Document* pDocument) diff --git a/xfa/fxfa/parser/cscript_signaturepseudomodel.cpp b/xfa/fxfa/parser/cscript_signaturepseudomodel.cpp index ed5891eb3a..2a23110ad3 100644 --- a/xfa/fxfa/parser/cscript_signaturepseudomodel.cpp +++ b/xfa/fxfa/parser/cscript_signaturepseudomodel.cpp @@ -8,12 +8,11 @@ #include "fxjs/include/cfxjse_arguments.h" #include "xfa/fxfa/app/xfa_ffnotify.h" +#include "xfa/fxfa/parser/cxfa_scriptcontext.h" #include "xfa/fxfa/parser/xfa_doclayout.h" #include "xfa/fxfa/parser/xfa_document.h" #include "xfa/fxfa/parser/xfa_localemgr.h" #include "xfa/fxfa/parser/xfa_object.h" -#include "xfa/fxfa/parser/xfa_script.h" -#include "xfa/fxfa/parser/xfa_script_imp.h" #include "xfa/fxfa/parser/xfa_utils.h" CScript_SignaturePseudoModel::CScript_SignaturePseudoModel( diff --git a/xfa/fxfa/parser/cxfa_node.cpp b/xfa/fxfa/parser/cxfa_node.cpp index fffd24e1d5..8f352d35ac 100644 --- a/xfa/fxfa/parser/cxfa_node.cpp +++ b/xfa/fxfa/parser/cxfa_node.cpp @@ -18,11 +18,11 @@ #include "xfa/fxfa/app/xfa_ffnotify.h" #include "xfa/fxfa/include/cxfa_eventparam.h" #include "xfa/fxfa/parser/cxfa_occur.h" +#include "xfa/fxfa/parser/cxfa_scriptcontext.h" #include "xfa/fxfa/parser/cxfa_simple_parser.h" #include "xfa/fxfa/parser/xfa_basic_data.h" #include "xfa/fxfa/parser/xfa_document.h" #include "xfa/fxfa/parser/xfa_document_layout_imp.h" -#include "xfa/fxfa/parser/xfa_script_imp.h" namespace { diff --git a/xfa/fxfa/parser/cxfa_nodehelper.cpp b/xfa/fxfa/parser/cxfa_nodehelper.cpp new file mode 100644 index 0000000000..038a5a55ab --- /dev/null +++ b/xfa/fxfa/parser/cxfa_nodehelper.cpp @@ -0,0 +1,429 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "xfa/fxfa/parser/cxfa_nodehelper.h" + +#include "core/fxcrt/include/fx_ext.h" +#include "xfa/fxfa/parser/cxfa_scriptcontext.h" +#include "xfa/fxfa/parser/xfa_doclayout.h" +#include "xfa/fxfa/parser/xfa_document.h" +#include "xfa/fxfa/parser/xfa_localemgr.h" +#include "xfa/fxfa/parser/xfa_object.h" +#include "xfa/fxfa/parser/xfa_resolvenode_rs.h" +#include "xfa/fxfa/parser/xfa_utils.h" + +CXFA_NodeHelper::CXFA_NodeHelper() + : m_eLastCreateType(XFA_Element::DataValue), + m_pCreateParent(nullptr), + m_iCreateCount(0), + m_iCreateFlag(XFA_RESOLVENODE_RSTYPE_CreateNodeOne), + m_iCurAllStart(-1), + m_pAllStartParent(nullptr) {} + +CXFA_NodeHelper::~CXFA_NodeHelper() {} + +CXFA_Node* CXFA_NodeHelper::ResolveNodes_GetOneChild(CXFA_Node* parent, + const FX_WCHAR* pwsName, + FX_BOOL bIsClassName) { + if (!parent) { + return nullptr; + } + CXFA_NodeArray siblings; + uint32_t uNameHash = FX_HashCode_GetW(CFX_WideStringC(pwsName), false); + NodeAcc_TraverseAnySiblings(parent, uNameHash, &siblings, bIsClassName); + if (siblings.GetSize() == 0) { + return nullptr; + } + return siblings[0]; +} + +int32_t CXFA_NodeHelper::CountSiblings(CXFA_Node* pNode, + XFA_LOGIC_TYPE eLogicType, + CXFA_NodeArray* pSiblings, + FX_BOOL bIsClassName) { + if (!pNode) + return 0; + CXFA_Node* parent = ResolveNodes_GetParent(pNode, XFA_LOGIC_NoTransparent); + if (!parent) + return 0; + const XFA_PROPERTY* pProperty = XFA_GetPropertyOfElement( + parent->GetElementType(), pNode->GetElementType(), XFA_XDPPACKET_UNKNOWN); + if (!pProperty && eLogicType == XFA_LOGIC_Transparent) { + parent = ResolveNodes_GetParent(pNode, XFA_LOGIC_Transparent); + if (!parent) { + return 0; + } + } + if (bIsClassName) { + return NodeAcc_TraverseSiblings(parent, pNode->GetClassHashCode(), + pSiblings, eLogicType, bIsClassName); + } else { + return NodeAcc_TraverseSiblings(parent, pNode->GetNameHash(), pSiblings, + eLogicType, bIsClassName); + } +} + +int32_t CXFA_NodeHelper::NodeAcc_TraverseAnySiblings(CXFA_Node* parent, + uint32_t dNameHash, + CXFA_NodeArray* pSiblings, + FX_BOOL bIsClassName) { + if (!parent || !pSiblings) { + return 0; + } + int32_t nCount = 0; + int32_t i = 0; + CXFA_NodeArray properties; + parent->GetNodeList(properties, XFA_NODEFILTER_Properties); + int32_t nProperties = properties.GetSize(); + for (i = 0; i < nProperties; ++i) { + CXFA_Node* child = properties[i]; + if (bIsClassName) { + if (child->GetClassHashCode() == dNameHash) { + pSiblings->Add(child); + nCount++; + } + } else { + if (child->GetNameHash() == dNameHash) { + pSiblings->Add(child); + nCount++; + } + } + if (nCount > 0) { + return nCount; + } + nCount += + NodeAcc_TraverseAnySiblings(child, dNameHash, pSiblings, bIsClassName); + } + CXFA_NodeArray children; + parent->GetNodeList(children, XFA_NODEFILTER_Children); + int32_t nChildren = children.GetSize(); + for (i = 0; i < nChildren; i++) { + CXFA_Node* child = children[i]; + if (bIsClassName) { + if (child->GetClassHashCode() == dNameHash) { + if (pSiblings) { + pSiblings->Add(child); + } + nCount++; + } + } else { + if (child->GetNameHash() == dNameHash) { + if (pSiblings) { + pSiblings->Add(child); + } + nCount++; + } + } + if (nCount > 0) { + return nCount; + } + nCount += + NodeAcc_TraverseAnySiblings(child, dNameHash, pSiblings, bIsClassName); + } + return nCount; +} + +int32_t CXFA_NodeHelper::NodeAcc_TraverseSiblings(CXFA_Node* parent, + uint32_t dNameHash, + CXFA_NodeArray* pSiblings, + XFA_LOGIC_TYPE eLogicType, + FX_BOOL bIsClassName, + FX_BOOL bIsFindProperty) { + if (!parent || !pSiblings) { + return 0; + } + int32_t nCount = 0; + int32_t i = 0; + if (bIsFindProperty) { + CXFA_NodeArray properties; + parent->GetNodeList(properties, XFA_NODEFILTER_Properties); + int32_t nProperties = properties.GetSize(); + for (i = 0; i < nProperties; ++i) { + CXFA_Node* child = properties[i]; + if (bIsClassName) { + if (child->GetClassHashCode() == dNameHash) { + pSiblings->Add(child); + nCount++; + } + } else { + if (child->GetNameHash() == dNameHash) { + if (child->GetElementType() != XFA_Element::PageSet && + child->GetElementType() != XFA_Element::Extras && + child->GetElementType() != XFA_Element::Items) { + pSiblings->Add(child); + nCount++; + } + } + } + if (child->IsUnnamed() && + child->GetElementType() == XFA_Element::PageSet) { + nCount += NodeAcc_TraverseSiblings(child, dNameHash, pSiblings, + eLogicType, bIsClassName, FALSE); + } + } + if (nCount > 0) { + return nCount; + } + } + CXFA_NodeArray children; + parent->GetNodeList(children, XFA_NODEFILTER_Children); + int32_t nChildren = children.GetSize(); + for (i = 0; i < nChildren; i++) { + CXFA_Node* child = children[i]; + if (child->GetElementType() == XFA_Element::Variables) { + continue; + } + if (bIsClassName) { + if (child->GetClassHashCode() == dNameHash) { + if (pSiblings) { + pSiblings->Add(child); + } + nCount++; + } + } else { + if (child->GetNameHash() == dNameHash) { + if (pSiblings) { + pSiblings->Add(child); + } + nCount++; + } + } + if (eLogicType == XFA_LOGIC_NoTransparent) { + continue; + } + if (NodeIsTransparent(child) && + child->GetElementType() != XFA_Element::PageSet) { + nCount += NodeAcc_TraverseSiblings(child, dNameHash, pSiblings, + eLogicType, bIsClassName, FALSE); + } + } + return nCount; +} + +CXFA_Node* CXFA_NodeHelper::ResolveNodes_GetParent(CXFA_Node* pNode, + XFA_LOGIC_TYPE eLogicType) { + if (!pNode) { + return nullptr; + } + if (eLogicType == XFA_LOGIC_NoTransparent) { + return pNode->GetNodeItem(XFA_NODEITEM_Parent); + } + CXFA_Node* parent; + CXFA_Node* node = pNode; + while (TRUE) { + parent = ResolveNodes_GetParent(node); + if (!parent) { + break; + } + XFA_Element parentType = parent->GetElementType(); + if ((!parent->IsUnnamed() && parentType != XFA_Element::SubformSet) || + parentType == XFA_Element::Variables) { + break; + } + node = parent; + } + return parent; +} + +int32_t CXFA_NodeHelper::GetIndex(CXFA_Node* pNode, + XFA_LOGIC_TYPE eLogicType, + FX_BOOL bIsProperty, + FX_BOOL bIsClassIndex) { + CXFA_Node* parent = ResolveNodes_GetParent(pNode, XFA_LOGIC_NoTransparent); + if (!parent) { + return 0; + } + if (!bIsProperty && eLogicType == XFA_LOGIC_Transparent) { + parent = ResolveNodes_GetParent(pNode, XFA_LOGIC_Transparent); + if (!parent) { + return 0; + } + } + uint32_t dwHashName = pNode->GetNameHash(); + if (bIsClassIndex) { + dwHashName = pNode->GetClassHashCode(); + } + CXFA_NodeArray siblings; + int32_t iSize = NodeAcc_TraverseSiblings(parent, dwHashName, &siblings, + eLogicType, bIsClassIndex); + for (int32_t i = 0; i < iSize; ++i) { + CXFA_Node* child = siblings[i]; + if (child == pNode) { + return i; + } + } + return 0; +} + +void CXFA_NodeHelper::GetNameExpression(CXFA_Node* refNode, + CFX_WideString& wsName, + FX_BOOL bIsAllPath, + XFA_LOGIC_TYPE eLogicType) { + wsName.clear(); + if (bIsAllPath) { + GetNameExpression(refNode, wsName, FALSE, eLogicType); + CFX_WideString wsParent; + CXFA_Node* parent = + ResolveNodes_GetParent(refNode, XFA_LOGIC_NoTransparent); + while (parent) { + GetNameExpression(parent, wsParent, FALSE, eLogicType); + wsParent += L"."; + wsParent += wsName; + wsName = wsParent; + parent = ResolveNodes_GetParent(parent, XFA_LOGIC_NoTransparent); + } + return; + } + + CFX_WideString ws; + FX_BOOL bIsProperty = NodeIsProperty(refNode); + if (refNode->IsUnnamed() || + (bIsProperty && refNode->GetElementType() != XFA_Element::PageSet)) { + ws = refNode->GetClassName(); + wsName.Format(L"#%s[%d]", ws.c_str(), + GetIndex(refNode, eLogicType, bIsProperty, TRUE)); + return; + } + ws = refNode->GetCData(XFA_ATTRIBUTE_Name); + ws.Replace(L".", L"\\."); + wsName.Format(L"%s[%d]", ws.c_str(), + GetIndex(refNode, eLogicType, bIsProperty, FALSE)); +} + +FX_BOOL CXFA_NodeHelper::NodeIsTransparent(CXFA_Node* refNode) { + if (!refNode) { + return FALSE; + } + XFA_Element refNodeType = refNode->GetElementType(); + if ((refNode->IsUnnamed() && refNode->IsContainerNode()) || + refNodeType == XFA_Element::SubformSet || + refNodeType == XFA_Element::Area || refNodeType == XFA_Element::Proto) { + return TRUE; + } + return FALSE; +} + +FX_BOOL CXFA_NodeHelper::CreateNode_ForCondition(CFX_WideString& wsCondition) { + int32_t iLen = wsCondition.GetLength(); + CFX_WideString wsIndex(L"0"); + FX_BOOL bAll = FALSE; + if (iLen == 0) { + m_iCreateFlag = XFA_RESOLVENODE_RSTYPE_CreateNodeOne; + return FALSE; + } + if (wsCondition.GetAt(0) == '[') { + int32_t i = 1; + for (; i < iLen; ++i) { + FX_WCHAR ch = wsCondition[i]; + if (ch == ' ') { + continue; + } + if (ch == '+' || ch == '-') { + break; + } else if (ch == '*') { + bAll = TRUE; + break; + } else { + break; + } + } + if (bAll) { + wsIndex = FX_WSTRC(L"1"); + m_iCreateFlag = XFA_RESOLVENODE_RSTYPE_CreateNodeAll; + } else { + m_iCreateFlag = XFA_RESOLVENODE_RSTYPE_CreateNodeOne; + wsIndex = wsCondition.Mid(i, iLen - 1 - i); + } + int32_t iIndex = wsIndex.GetInteger(); + m_iCreateCount = iIndex; + return TRUE; + } + return FALSE; +} + +FX_BOOL CXFA_NodeHelper::ResolveNodes_CreateNode( + CFX_WideString wsName, + CFX_WideString wsCondition, + FX_BOOL bLastNode, + CXFA_ScriptContext* pScriptContext) { + if (!m_pCreateParent) { + return FALSE; + } + FX_BOOL bIsClassName = FALSE; + FX_BOOL bResult = FALSE; + if (wsName.GetAt(0) == '!') { + wsName = wsName.Right(wsName.GetLength() - 1); + m_pCreateParent = ToNode( + pScriptContext->GetDocument()->GetXFAObject(XFA_HASHCODE_Datasets)); + } + if (wsName.GetAt(0) == '#') { + bIsClassName = TRUE; + wsName = wsName.Right(wsName.GetLength() - 1); + } + if (m_iCreateCount == 0) { + CreateNode_ForCondition(wsCondition); + } + if (bIsClassName) { + XFA_Element eType = XFA_GetElementTypeForName(wsName.AsStringC()); + if (eType == XFA_Element::Unknown) + return FALSE; + + for (int32_t iIndex = 0; iIndex < m_iCreateCount; iIndex++) { + CXFA_Node* pNewNode = m_pCreateParent->CreateSamePacketNode(eType); + if (pNewNode) { + m_pCreateParent->InsertChild(pNewNode); + if (iIndex == m_iCreateCount - 1) { + m_pCreateParent = pNewNode; + } + bResult = TRUE; + } + } + } else { + XFA_Element eClassType = XFA_Element::DataGroup; + if (bLastNode) { + eClassType = m_eLastCreateType; + } + for (int32_t iIndex = 0; iIndex < m_iCreateCount; iIndex++) { + CXFA_Node* pNewNode = m_pCreateParent->CreateSamePacketNode(eClassType); + if (pNewNode) { + pNewNode->SetAttribute(XFA_ATTRIBUTE_Name, wsName.AsStringC()); + pNewNode->CreateXMLMappingNode(); + m_pCreateParent->InsertChild(pNewNode); + if (iIndex == m_iCreateCount - 1) { + m_pCreateParent = pNewNode; + } + bResult = TRUE; + } + } + } + if (!bResult) { + m_pCreateParent = nullptr; + } + return bResult; +} + +void CXFA_NodeHelper::SetCreateNodeType(CXFA_Node* refNode) { + if (!refNode) { + return; + } + if (refNode->GetElementType() == XFA_Element::Subform) { + m_eLastCreateType = XFA_Element::DataGroup; + } else if (refNode->GetElementType() == XFA_Element::Field) { + m_eLastCreateType = XFA_FieldIsMultiListBox(refNode) + ? XFA_Element::DataGroup + : XFA_Element::DataValue; + } else if (refNode->GetElementType() == XFA_Element::ExclGroup) { + m_eLastCreateType = XFA_Element::DataValue; + } +} + +FX_BOOL CXFA_NodeHelper::NodeIsProperty(CXFA_Node* refNode) { + CXFA_Node* parent = ResolveNodes_GetParent(refNode, XFA_LOGIC_NoTransparent); + return parent && refNode && + XFA_GetPropertyOfElement(parent->GetElementType(), + refNode->GetElementType(), + XFA_XDPPACKET_UNKNOWN); +} diff --git a/xfa/fxfa/parser/cxfa_nodehelper.h b/xfa/fxfa/parser/cxfa_nodehelper.h new file mode 100644 index 0000000000..a913d5de04 --- /dev/null +++ b/xfa/fxfa/parser/cxfa_nodehelper.h @@ -0,0 +1,72 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef XFA_FXFA_PARSER_CXFA_NODEHELPER_H_ +#define XFA_FXFA_PARSER_CXFA_NODEHELPER_H_ + +#include "xfa/fxfa/parser/xfa_object.h" +#include "xfa/fxfa/parser/xfa_resolvenode_rs.h" + +class CXFA_ScriptContext; + +enum XFA_LOGIC_TYPE { + XFA_LOGIC_NoTransparent, + XFA_LOGIC_Transparent, +}; + +class CXFA_NodeHelper { + public: + CXFA_NodeHelper(); + ~CXFA_NodeHelper(); + + CXFA_Node* ResolveNodes_GetOneChild(CXFA_Node* parent, + const FX_WCHAR* pwsName, + FX_BOOL bIsClassName = FALSE); + CXFA_Node* ResolveNodes_GetParent( + CXFA_Node* pNode, + XFA_LOGIC_TYPE eLogicType = XFA_LOGIC_NoTransparent); + + int32_t NodeAcc_TraverseSiblings(CXFA_Node* parent, + uint32_t dNameHash, + CXFA_NodeArray* pSiblings, + XFA_LOGIC_TYPE eLogicType, + FX_BOOL bIsClassName = FALSE, + FX_BOOL bIsFindProperty = TRUE); + int32_t NodeAcc_TraverseAnySiblings(CXFA_Node* parent, + uint32_t dNameHash, + CXFA_NodeArray* pSiblings, + FX_BOOL bIsClassName = FALSE); + int32_t CountSiblings(CXFA_Node* pNode, + XFA_LOGIC_TYPE eLogicType, + CXFA_NodeArray* pSiblings, + FX_BOOL bIsClassName = FALSE); + int32_t GetIndex(CXFA_Node* pNode, + XFA_LOGIC_TYPE eLogicType = XFA_LOGIC_NoTransparent, + FX_BOOL bIsProperty = FALSE, + FX_BOOL bIsClassIndex = FALSE); + void GetNameExpression(CXFA_Node* refNode, + CFX_WideString& wsName, + FX_BOOL bIsAllPath, + XFA_LOGIC_TYPE eLogicType = XFA_LOGIC_NoTransparent); + FX_BOOL NodeIsTransparent(CXFA_Node* refNode); + FX_BOOL ResolveNodes_CreateNode(CFX_WideString wsName, + CFX_WideString wsCondition, + FX_BOOL bLastNode, + CXFA_ScriptContext* pScriptContext); + FX_BOOL CreateNode_ForCondition(CFX_WideString& wsCondition); + void SetCreateNodeType(CXFA_Node* refNode); + FX_BOOL NodeIsProperty(CXFA_Node* refNode); + + public: + XFA_Element m_eLastCreateType; + CXFA_Node* m_pCreateParent; + int32_t m_iCreateCount; + XFA_RESOVENODE_RSTYPE m_iCreateFlag; + int32_t m_iCurAllStart; + CXFA_Node* m_pAllStartParent; +}; + +#endif // XFA_FXFA_PARSER_CXFA_NODEHELPER_H_ diff --git a/xfa/fxfa/parser/cxfa_nodelist.cpp b/xfa/fxfa/parser/cxfa_nodelist.cpp index e95c2f61ca..61e5091c56 100644 --- a/xfa/fxfa/parser/cxfa_nodelist.cpp +++ b/xfa/fxfa/parser/cxfa_nodelist.cpp @@ -7,8 +7,8 @@ #include "xfa/fxfa/parser/xfa_object.h" #include "core/fxcrt/include/fx_ext.h" +#include "xfa/fxfa/parser/cxfa_scriptcontext.h" #include "xfa/fxfa/parser/xfa_document.h" -#include "xfa/fxfa/parser/xfa_script_imp.h" CXFA_NodeList::CXFA_NodeList(CXFA_Document* pDocument) : CXFA_Object(pDocument, diff --git a/xfa/fxfa/parser/cxfa_resolveprocessor.cpp b/xfa/fxfa/parser/cxfa_resolveprocessor.cpp new file mode 100644 index 0000000000..b6894c483a --- /dev/null +++ b/xfa/fxfa/parser/cxfa_resolveprocessor.cpp @@ -0,0 +1,826 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "xfa/fxfa/parser/cxfa_resolveprocessor.h" + +#include "core/fxcrt/include/fx_ext.h" +#include "xfa/fxfa/parser/cxfa_nodehelper.h" +#include "xfa/fxfa/parser/cxfa_scriptcontext.h" +#include "xfa/fxfa/parser/xfa_doclayout.h" +#include "xfa/fxfa/parser/xfa_document.h" +#include "xfa/fxfa/parser/xfa_localemgr.h" +#include "xfa/fxfa/parser/xfa_object.h" +#include "xfa/fxfa/parser/xfa_resolvenode_rs.h" +#include "xfa/fxfa/parser/xfa_utils.h" + +CXFA_ResolveProcessor::CXFA_ResolveProcessor() + : m_iCurStart(0), m_pNodeHelper(new CXFA_NodeHelper) {} + +CXFA_ResolveProcessor::~CXFA_ResolveProcessor() { + delete m_pNodeHelper; +} + +int32_t CXFA_ResolveProcessor::Resolve(CXFA_ResolveNodesData& rnd) { + if (!rnd.m_CurNode) { + return -1; + } + if (!rnd.m_CurNode->IsNode()) { + if (rnd.m_dwStyles & XFA_RESOLVENODE_Attributes) { + return ResolveForAttributeRs(rnd.m_CurNode, rnd, + rnd.m_wsName.AsStringC()); + } + return 0; + } + if (rnd.m_dwStyles & XFA_RESOLVENODE_AnyChild) { + return ResolveAnyChild(rnd); + } + FX_WCHAR wch = rnd.m_wsName.GetAt(0); + switch (wch) { + case '$': + return ResolveDollar(rnd); + case '!': + return ResolveExcalmatory(rnd); + case '#': + return ResolveNumberSign(rnd); + case '*': + return ResolveAsterisk(rnd); + // TODO(dsinclair): We could probably remove this. + case '.': + return ResolveAnyChild(rnd); + default: + break; + } + if (rnd.m_uHashName == XFA_HASHCODE_This && rnd.m_nLevel == 0) { + rnd.m_Nodes.Add(rnd.m_pSC->GetThisObject()); + return 1; + } else if (rnd.m_CurNode->GetElementType() == XFA_Element::Xfa) { + CXFA_Object* pObjNode = + rnd.m_pSC->GetDocument()->GetXFAObject(rnd.m_uHashName); + if (pObjNode) { + rnd.m_Nodes.Add(pObjNode); + } else if (rnd.m_uHashName == XFA_HASHCODE_Xfa) { + rnd.m_Nodes.Add(rnd.m_CurNode); + } else if ((rnd.m_dwStyles & XFA_RESOLVENODE_Attributes) && + ResolveForAttributeRs(rnd.m_CurNode, rnd, + rnd.m_wsName.AsStringC())) { + return 1; + } + if (rnd.m_Nodes.GetSize() > 0) { + FilterCondition(rnd, rnd.m_wsCondition); + } + return rnd.m_Nodes.GetSize(); + } + int32_t nRet = ResolveNormal(rnd); + if (nRet < 1 && rnd.m_uHashName == XFA_HASHCODE_Xfa) { + rnd.m_Nodes.Add(rnd.m_pSC->GetDocument()->GetRoot()); + } + return rnd.m_Nodes.GetSize(); +} +int32_t CXFA_ResolveProcessor::ResolveAnyChild(CXFA_ResolveNodesData& rnd) { + CFX_WideString wsName = rnd.m_wsName; + CFX_WideString wsCondition = rnd.m_wsCondition; + CXFA_Node* findNode = nullptr; + CXFA_NodeArray siblings; + FX_BOOL bClassName = FALSE; + if (wsName.GetAt(0) == '#') { + bClassName = TRUE; + wsName = wsName.Right(wsName.GetLength() - 1); + } + findNode = m_pNodeHelper->ResolveNodes_GetOneChild( + ToNode(rnd.m_CurNode), wsName.c_str(), bClassName); + if (!findNode) { + return 0; + } + if (wsCondition.IsEmpty()) { + rnd.m_Nodes.Add(findNode); + return rnd.m_Nodes.GetSize(); + } + m_pNodeHelper->CountSiblings(findNode, XFA_LOGIC_Transparent, + (CXFA_NodeArray*)&rnd.m_Nodes, bClassName); + FilterCondition(rnd, wsCondition); + return rnd.m_Nodes.GetSize(); +} +int32_t CXFA_ResolveProcessor::ResolveDollar(CXFA_ResolveNodesData& rnd) { + CXFA_ObjArray& nodes = rnd.m_Nodes; + CFX_WideString wsName = rnd.m_wsName; + CFX_WideString wsCondition = rnd.m_wsCondition; + int32_t iNameLen = wsName.GetLength(); + if (iNameLen == 1) { + nodes.Add(rnd.m_CurNode); + return 1; + } + if (rnd.m_nLevel > 0) { + return -1; + } + XFA_HashCode dwNameHash = static_cast(FX_HashCode_GetW( + CFX_WideStringC(wsName.c_str() + 1, iNameLen - 1), false)); + if (dwNameHash == XFA_HASHCODE_Xfa) { + nodes.Add(rnd.m_pSC->GetDocument()->GetRoot()); + } else { + CXFA_Object* pObjNode = rnd.m_pSC->GetDocument()->GetXFAObject(dwNameHash); + if (pObjNode) { + rnd.m_Nodes.Add(pObjNode); + } + } + if (rnd.m_Nodes.GetSize() > 0) { + FilterCondition(rnd, wsCondition); + } + return rnd.m_Nodes.GetSize(); +} +int32_t CXFA_ResolveProcessor::ResolveExcalmatory(CXFA_ResolveNodesData& rnd) { + if (rnd.m_nLevel > 0) { + return 0; + } + CXFA_Node* datasets = + ToNode(rnd.m_pSC->GetDocument()->GetXFAObject(XFA_HASHCODE_Datasets)); + if (!datasets) { + return 0; + } + CXFA_ResolveNodesData rndFind; + rndFind.m_pSC = rnd.m_pSC; + rndFind.m_CurNode = datasets; + rndFind.m_wsName = rnd.m_wsName.Right(rnd.m_wsName.GetLength() - 1); + rndFind.m_uHashName = static_cast( + FX_HashCode_GetW(rndFind.m_wsName.AsStringC(), false)); + rndFind.m_nLevel = rnd.m_nLevel + 1; + rndFind.m_dwStyles = XFA_RESOLVENODE_Children; + rndFind.m_wsCondition = rnd.m_wsCondition; + Resolve(rndFind); + if (rndFind.m_Nodes.GetSize() > 0) { + rnd.m_Nodes.Append(rndFind.m_Nodes); + rndFind.m_Nodes.RemoveAll(); + } + return rnd.m_Nodes.GetSize(); +} +int32_t CXFA_ResolveProcessor::ResolveNumberSign(CXFA_ResolveNodesData& rnd) { + CFX_WideString wsName = rnd.m_wsName.Right(rnd.m_wsName.GetLength() - 1); + CFX_WideString wsCondition = rnd.m_wsCondition; + CXFA_Node* curNode = ToNode(rnd.m_CurNode); + if (ResolveForAttributeRs(curNode, rnd, wsName.AsStringC())) { + return 1; + } + CXFA_ResolveNodesData rndFind; + rndFind.m_pSC = rnd.m_pSC; + rndFind.m_nLevel = rnd.m_nLevel + 1; + rndFind.m_dwStyles = rnd.m_dwStyles; + rndFind.m_dwStyles |= XFA_RESOLVENODE_TagName; + rndFind.m_dwStyles &= ~XFA_RESOLVENODE_Attributes; + rndFind.m_wsName = wsName; + rndFind.m_uHashName = static_cast( + FX_HashCode_GetW(rndFind.m_wsName.AsStringC(), false)); + rndFind.m_wsCondition = wsCondition; + rndFind.m_CurNode = curNode; + ResolveNormal(rndFind); + if (rndFind.m_Nodes.GetSize() > 0) { + if (wsCondition.GetLength() == 0 && rndFind.m_Nodes.Find(curNode) >= 0) { + rnd.m_Nodes.Add(curNode); + } else { + rnd.m_Nodes.Append(rndFind.m_Nodes); + rndFind.m_Nodes.RemoveAll(); + } + } + return rnd.m_Nodes.GetSize(); +} +int32_t CXFA_ResolveProcessor::ResolveForAttributeRs( + CXFA_Object* curNode, + CXFA_ResolveNodesData& rnd, + const CFX_WideStringC& strAttr) { + const XFA_SCRIPTATTRIBUTEINFO* lpScriptAttribute = + XFA_GetScriptAttributeByName(curNode->GetElementType(), strAttr); + if (lpScriptAttribute) { + rnd.m_pScriptAttribute = lpScriptAttribute; + rnd.m_Nodes.Add(curNode); + rnd.m_dwFlag = XFA_RESOVENODE_RSTYPE_Attribute; + return 1; + } + return 0; +} +int32_t CXFA_ResolveProcessor::ResolveNormal(CXFA_ResolveNodesData& rnd) { + if (rnd.m_nLevel > 32) { + return 0; + } + if (!rnd.m_CurNode->IsNode()) { + return 0; + } + CXFA_Node* curNode = ToNode(rnd.m_CurNode); + CXFA_ObjArray& nodes = rnd.m_Nodes; + int32_t nNum = nodes.GetSize(); + uint32_t dwStyles = rnd.m_dwStyles; + CFX_WideString& wsName = rnd.m_wsName; + XFA_HashCode uNameHash = rnd.m_uHashName; + CFX_WideString& wsCondition = rnd.m_wsCondition; + CXFA_ResolveNodesData rndFind; + rndFind.m_wsName = rnd.m_wsName; + rndFind.m_wsCondition = rnd.m_wsCondition; + rndFind.m_pSC = rnd.m_pSC; + rndFind.m_nLevel = rnd.m_nLevel + 1; + rndFind.m_uHashName = uNameHash; + CXFA_NodeArray children; + CXFA_NodeArray properties; + CXFA_Node* pVariablesNode = nullptr; + CXFA_Node* pPageSetNode = nullptr; + CXFA_Node* pChild = curNode->GetNodeItem(XFA_NODEITEM_FirstChild); + while (pChild) { + if (pChild->GetElementType() == XFA_Element::Variables) { + pVariablesNode = pChild; + pChild = pChild->GetNodeItem(XFA_NODEITEM_NextSibling); + continue; + } else if (pChild->GetElementType() == XFA_Element::PageSet) { + pPageSetNode = pChild; + pChild = pChild->GetNodeItem(XFA_NODEITEM_NextSibling); + continue; + } else { + const XFA_PROPERTY* pPropert = XFA_GetPropertyOfElement( + curNode->GetElementType(), pChild->GetElementType(), + XFA_XDPPACKET_UNKNOWN); + if (pPropert) { + properties.Add(pChild); + } else { + children.Add(pChild); + } + } + pChild = pChild->GetNodeItem(XFA_NODEITEM_NextSibling); + } + if ((dwStyles & XFA_RESOLVENODE_Properties) && pVariablesNode) { + uint32_t uPropHash = pVariablesNode->GetClassHashCode(); + if (uPropHash == uNameHash) { + nodes.Add(pVariablesNode); + } else { + rndFind.m_CurNode = pVariablesNode; + SetStylesForChild(dwStyles, rndFind); + CFX_WideString wsSaveCondition = rndFind.m_wsCondition; + rndFind.m_wsCondition.clear(); + ResolveNormal(rndFind); + rndFind.m_wsCondition = wsSaveCondition; + if (rndFind.m_Nodes.GetSize() > 0) { + nodes.Append(rndFind.m_Nodes); + rndFind.m_Nodes.RemoveAll(); + } + } + if (nodes.GetSize() > nNum) { + FilterCondition(rnd, wsCondition); + if (nodes.GetSize() > 0) { + return 1; + } + return 0; + } + } + if (dwStyles & XFA_RESOLVENODE_Children) { + FX_BOOL bSetFlag = FALSE; + if (pPageSetNode && (dwStyles & XFA_RESOLVENODE_Properties)) { + children.Add(pPageSetNode); + } + for (int32_t i = 0; i < children.GetSize(); i++) { + CXFA_Node* child = children[i]; + if (dwStyles & XFA_RESOLVENODE_TagName) { + if (child->GetClassHashCode() == uNameHash) { + nodes.Add(child); + } + } else if (child->GetNameHash() == uNameHash) { + nodes.Add(child); + } + if (m_pNodeHelper->NodeIsTransparent(child) && + child->GetElementType() != XFA_Element::PageSet) { + if (!bSetFlag) { + SetStylesForChild(dwStyles, rndFind); + bSetFlag = TRUE; + } + rndFind.m_CurNode = child; + CFX_WideString wsSaveCondition = rndFind.m_wsCondition; + rndFind.m_wsCondition.clear(); + ResolveNormal(rndFind); + rndFind.m_wsCondition = wsSaveCondition; + if (rndFind.m_Nodes.GetSize() > 0) { + nodes.Append(rndFind.m_Nodes); + rndFind.m_Nodes.RemoveAll(); + } + } + } + if (nodes.GetSize() > nNum) { + if (!(dwStyles & XFA_RESOLVENODE_ALL)) { + CXFA_NodeArray upArrayNodes; + if (m_pNodeHelper->NodeIsTransparent(ToNode(curNode))) { + m_pNodeHelper->CountSiblings(ToNode(nodes[0]), XFA_LOGIC_Transparent, + &upArrayNodes, + !!(dwStyles & XFA_RESOLVENODE_TagName)); + } + if (upArrayNodes.GetSize() > nodes.GetSize()) { + upArrayNodes[0] = ToNode(nodes[0]); + nodes.RemoveAll(); + nodes.Append((CXFA_ObjArray&)upArrayNodes); + upArrayNodes.RemoveAll(); + } + } + FilterCondition(rnd, wsCondition); + if (nodes.GetSize() > 0) { + return 1; + } + return 0; + } + } + if (dwStyles & XFA_RESOLVENODE_Attributes) { + if (ResolveForAttributeRs(curNode, rnd, wsName.AsStringC())) { + return 1; + } + } + if (dwStyles & XFA_RESOLVENODE_Properties) { + for (int32_t i = 0; i < properties.GetSize(); i++) { + CXFA_Node* childProperty = properties[i]; + if (childProperty->IsUnnamed()) { + uint32_t uPropHash = childProperty->GetClassHashCode(); + if (uPropHash == uNameHash) { + nodes.Add(childProperty); + } + } else if (childProperty->GetNameHash() == uNameHash && + childProperty->GetElementType() != XFA_Element::Extras && + childProperty->GetElementType() != XFA_Element::Items) { + nodes.Add(childProperty); + } + } + if (nodes.GetSize() > nNum) { + FilterCondition(rnd, wsCondition); + if (nodes.GetSize() > 0) { + return 1; + } + return 0; + } + CXFA_Node* pProp = nullptr; + if (XFA_Element::Subform == curNode->GetElementType() && + XFA_HASHCODE_Occur == uNameHash) { + CXFA_Node* pInstanceManager = + curNode->AsNode()->GetInstanceMgrOfSubform(); + if (pInstanceManager) { + pProp = pInstanceManager->GetProperty(0, XFA_Element::Occur, TRUE); + } + } else { + XFA_Element eType = XFA_GetElementTypeForName(wsName.AsStringC()); + if (eType != XFA_Element::Unknown) { + pProp = curNode->AsNode()->GetProperty(0, eType, + eType != XFA_Element::PageSet); + } + } + if (pProp) { + nodes.Add(pProp); + return nodes.GetSize(); + } + } + CXFA_Node* parentNode = m_pNodeHelper->ResolveNodes_GetParent( + curNode->AsNode(), XFA_LOGIC_NoTransparent); + uint32_t uCurClassHash = curNode->GetClassHashCode(); + if (!parentNode) { + if (uCurClassHash == uNameHash) { + nodes.Add(curNode->AsNode()); + FilterCondition(rnd, wsCondition); + if (nodes.GetSize() > 0) { + return 1; + } + } + return 0; + } + if (dwStyles & XFA_RESOLVENODE_Siblings) { + CXFA_Node* child = parentNode->GetNodeItem(XFA_NODEITEM_FirstChild); + uint32_t dwSubStyles = + XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Properties; + if (dwStyles & XFA_RESOLVENODE_TagName) { + dwSubStyles |= XFA_RESOLVENODE_TagName; + } + if (dwStyles & XFA_RESOLVENODE_ALL) { + dwSubStyles |= XFA_RESOLVENODE_ALL; + } + rndFind.m_dwStyles = dwSubStyles; + while (child) { + if (child == curNode) { + if (dwStyles & XFA_RESOLVENODE_TagName) { + if (uCurClassHash == uNameHash) { + nodes.Add(curNode); + } + } else { + if (child->GetNameHash() == uNameHash) { + nodes.Add(curNode); + if (rnd.m_nLevel == 0 && wsCondition.GetLength() == 0) { + nodes.RemoveAll(); + nodes.Add(curNode); + return 1; + } + } + } + child = child->GetNodeItem(XFA_NODEITEM_NextSibling); + continue; + } + if (dwStyles & XFA_RESOLVENODE_TagName) { + if (child->GetClassHashCode() == uNameHash) { + nodes.Add(child); + } + } else if (child->GetNameHash() == uNameHash) { + nodes.Add(child); + } + const XFA_PROPERTY* pPropert = XFA_GetPropertyOfElement( + parentNode->GetElementType(), child->GetElementType(), + XFA_XDPPACKET_UNKNOWN); + FX_BOOL bInnerSearch = FALSE; + if (pPropert) { + if ((child->GetElementType() == XFA_Element::Variables || + child->GetElementType() == XFA_Element::PageSet)) { + bInnerSearch = TRUE; + } + } else { + if (m_pNodeHelper->NodeIsTransparent(child)) { + bInnerSearch = TRUE; + } + } + if (bInnerSearch) { + rndFind.m_CurNode = child; + CFX_WideString wsOriginCondition = rndFind.m_wsCondition; + rndFind.m_wsCondition.clear(); + uint32_t dwOriginStyle = rndFind.m_dwStyles; + rndFind.m_dwStyles = dwOriginStyle | XFA_RESOLVENODE_ALL; + ResolveNormal(rndFind); + rndFind.m_dwStyles = dwOriginStyle; + rndFind.m_wsCondition = wsOriginCondition; + if (rndFind.m_Nodes.GetSize() > 0) { + nodes.Append(rndFind.m_Nodes); + rndFind.m_Nodes.RemoveAll(); + } + } + child = child->GetNodeItem(XFA_NODEITEM_NextSibling); + } + if (nodes.GetSize() > nNum) { + if (m_pNodeHelper->NodeIsTransparent(parentNode)) { + CXFA_NodeArray upArrayNodes; + m_pNodeHelper->CountSiblings(ToNode(nodes[0]), XFA_LOGIC_Transparent, + &upArrayNodes, + !!(dwStyles & XFA_RESOLVENODE_TagName)); + if (upArrayNodes.GetSize() > nodes.GetSize()) { + upArrayNodes[0] = ToNode(nodes[0]); + nodes.RemoveAll(); + nodes.Append((CXFA_ObjArray&)upArrayNodes); + upArrayNodes.RemoveAll(); + } + } + FilterCondition(rnd, wsCondition); + if (nodes.GetSize() > 0) { + return 1; + } + return 0; + } + } + if (dwStyles & XFA_RESOLVENODE_Parent) { + uint32_t dwSubStyles = XFA_RESOLVENODE_Siblings | XFA_RESOLVENODE_Parent | + XFA_RESOLVENODE_Properties; + if (dwStyles & XFA_RESOLVENODE_TagName) { + dwSubStyles |= XFA_RESOLVENODE_TagName; + } + if (dwStyles & XFA_RESOLVENODE_ALL) { + dwSubStyles |= XFA_RESOLVENODE_ALL; + } + rndFind.m_dwStyles = dwSubStyles; + rndFind.m_CurNode = parentNode; + CXFA_NodeArray& array = rnd.m_pSC->GetUpObjectArray(); + array.Add(parentNode); + ResolveNormal(rndFind); + if (rndFind.m_Nodes.GetSize() > 0) { + nodes.Append(rndFind.m_Nodes); + rndFind.m_Nodes.RemoveAll(); + } + if (nodes.GetSize() > nNum) { + return 1; + } + } + return 0; +} +int32_t CXFA_ResolveProcessor::ResolveAsterisk(CXFA_ResolveNodesData& rnd) { + CXFA_Node* curNode = ToNode(rnd.m_CurNode); + CXFA_ObjArray& nodes = rnd.m_Nodes; + CXFA_NodeArray array; + curNode->GetNodeList(array, + XFA_NODEFILTER_Children | XFA_NODEFILTER_Properties); + nodes.Append((CXFA_ObjArray&)array); + return nodes.GetSize(); +} +int32_t CXFA_ResolveProcessor::ResolvePopStack(CFX_Int32Array& stack) { + int32_t nType = -1; + int32_t iSize = stack.GetSize() - 1; + if (iSize > -1) { + nType = stack[iSize]; + stack.RemoveAt(iSize, 1); + } + return nType; +} +int32_t CXFA_ResolveProcessor::GetFilter(const CFX_WideStringC& wsExpression, + int32_t nStart, + CXFA_ResolveNodesData& rnd) { + ASSERT(nStart > -1); + int32_t iLength = wsExpression.GetLength(); + if (nStart >= iLength) { + return 0; + } + CFX_WideString& wsName = rnd.m_wsName; + CFX_WideString& wsCondition = rnd.m_wsCondition; + FX_WCHAR* pNameBuf = wsName.GetBuffer(iLength - nStart); + FX_WCHAR* pConditionBuf = wsCondition.GetBuffer(iLength - nStart); + int32_t nNameCount = 0; + int32_t nConditionCount = 0; + CFX_Int32Array stack; + int32_t nType = -1; + const FX_WCHAR* pSrc = wsExpression.c_str(); + FX_WCHAR wPrev = 0, wCur; + FX_BOOL bIsCondition = FALSE; + while (nStart < iLength) { + wCur = pSrc[nStart++]; + if (wCur == '.') { + if (wPrev == '\\') { + pNameBuf[nNameCount - 1] = wPrev = '.'; + continue; + } + if (nNameCount == 0) { + rnd.m_dwStyles |= XFA_RESOLVENODE_AnyChild; + continue; + } + FX_WCHAR wLookahead = nStart < iLength ? pSrc[nStart] : 0; + if (wLookahead != '[' && wLookahead != '(') { + if (nType < 0) { + break; + } + } + } + if (wCur == '[' || wCur == '(') { + bIsCondition = TRUE; + } else if (wCur == '.' && nStart < iLength && + (pSrc[nStart] == '[' || pSrc[nStart] == '(')) { + bIsCondition = TRUE; + } + if (bIsCondition) { + pConditionBuf[nConditionCount++] = wCur; + } else { + pNameBuf[nNameCount++] = wCur; + } + FX_BOOL bRecursive = TRUE; + switch (nType) { + case 0: + if (wCur == ']') { + nType = ResolvePopStack(stack); + bRecursive = FALSE; + } + break; + case 1: + if (wCur == ')') { + nType = ResolvePopStack(stack); + bRecursive = FALSE; + } + break; + case 2: + if (wCur == '"') { + nType = ResolvePopStack(stack); + bRecursive = FALSE; + } + break; + } + if (bRecursive) { + switch (wCur) { + case '[': + stack.Add(nType); + nType = 0; + break; + case '(': + stack.Add(nType); + nType = 1; + break; + case '"': + stack.Add(nType); + nType = 2; + break; + } + } + wPrev = wCur; + } + if (stack.GetSize() > 0) { + return -1; + } + wsName.ReleaseBuffer(nNameCount); + wsName.TrimLeft(); + wsName.TrimRight(); + wsCondition.ReleaseBuffer(nConditionCount); + wsCondition.TrimLeft(); + wsCondition.TrimRight(); + rnd.m_uHashName = + static_cast(FX_HashCode_GetW(wsName.AsStringC(), false)); + return nStart; +} +void CXFA_ResolveProcessor::ConditionArray(int32_t iCurIndex, + CFX_WideString wsCondition, + int32_t iFoundCount, + CXFA_ResolveNodesData& rnd) { + CXFA_NodeArray& findNodes = (CXFA_NodeArray&)rnd.m_Nodes; + int32_t iLen = wsCondition.GetLength(); + FX_BOOL bRelative = FALSE; + FX_BOOL bAll = FALSE; + int32_t i = 1; + for (; i < iLen; ++i) { + FX_WCHAR ch = wsCondition[i]; + if (ch == ' ') { + continue; + } + if (ch == '+' || ch == '-') { + bRelative = TRUE; + break; + } else if (ch == '*') { + bAll = TRUE; + break; + } else { + break; + } + } + if (bAll) { + if (rnd.m_dwStyles & XFA_RESOLVENODE_CreateNode) { + if (rnd.m_dwStyles & XFA_RESOLVENODE_Bind) { + m_pNodeHelper->m_pCreateParent = ToNode(rnd.m_CurNode); + m_pNodeHelper->m_iCreateCount = 1; + findNodes.RemoveAll(); + m_pNodeHelper->m_iCurAllStart = -1; + m_pNodeHelper->m_pAllStartParent = nullptr; + } else { + if (m_pNodeHelper->m_iCurAllStart == -1) { + m_pNodeHelper->m_iCurAllStart = m_iCurStart; + m_pNodeHelper->m_pAllStartParent = ToNode(rnd.m_CurNode); + } + } + } else if (rnd.m_dwStyles & XFA_RESOLVENODE_BindNew) { + if (m_pNodeHelper->m_iCurAllStart == -1) { + m_pNodeHelper->m_iCurAllStart = m_iCurStart; + } + } + return; + } + if (iFoundCount == 1 && !iLen) { + return; + } + CFX_WideString wsIndex; + wsIndex = wsCondition.Mid(i, iLen - 1 - i); + int32_t iIndex = wsIndex.GetInteger(); + if (bRelative) { + iIndex += iCurIndex; + } + if (iFoundCount <= iIndex || iIndex < 0) { + if (rnd.m_dwStyles & XFA_RESOLVENODE_CreateNode) { + m_pNodeHelper->m_pCreateParent = ToNode(rnd.m_CurNode); + m_pNodeHelper->m_iCreateCount = iIndex - iFoundCount + 1; + } + findNodes.RemoveAll(); + } else { + CXFA_Node* ret = findNodes[iIndex]; + findNodes.RemoveAll(); + findNodes.Add(ret); + } +} +void CXFA_ResolveProcessor::DoPredicateFilter(int32_t iCurIndex, + CFX_WideString wsCondition, + int32_t iFoundCount, + CXFA_ResolveNodesData& rnd) { + CXFA_NodeArray& findNodes = (CXFA_NodeArray&)rnd.m_Nodes; + ASSERT(iFoundCount == findNodes.GetSize()); + CFX_WideString wsExpression; + XFA_SCRIPTLANGTYPE eLangType = XFA_SCRIPTLANGTYPE_Unkown; + if (wsCondition.Left(2) == FX_WSTRC(L".[") && + wsCondition.Right(1) == FX_WSTRC(L"]")) { + eLangType = XFA_SCRIPTLANGTYPE_Formcalc; + } else if (wsCondition.Left(2) == FX_WSTRC(L".(") && + wsCondition.Right(1) == FX_WSTRC(L")")) { + eLangType = XFA_SCRIPTLANGTYPE_Javascript; + } else { + return; + } + + CXFA_ScriptContext* pContext = rnd.m_pSC; + wsExpression = wsCondition.Mid(2, wsCondition.GetLength() - 3); + for (int32_t i = iFoundCount - 1; i >= 0; i--) { + CXFA_Object* node = findNodes[i]; + FX_BOOL bRet = FALSE; + std::unique_ptr pRetValue( + new CFXJSE_Value(rnd.m_pSC->GetRuntime())); + bRet = pContext->RunScript(eLangType, wsExpression.AsStringC(), + pRetValue.get(), node); + if (!bRet || !pRetValue->ToBoolean()) + findNodes.RemoveAt(i); + } +} + +void CXFA_ResolveProcessor::FilterCondition(CXFA_ResolveNodesData& rnd, + CFX_WideString wsCondition) { + CXFA_NodeArray& findNodes = (CXFA_NodeArray&)rnd.m_Nodes; + int32_t iCurrIndex = 0; + const CXFA_NodeArray& array = rnd.m_pSC->GetUpObjectArray(); + int32_t iSize = array.GetSize(); + if (iSize) { + CXFA_Node* curNode = array[iSize - 1]; + FX_BOOL bIsProperty = m_pNodeHelper->NodeIsProperty(curNode); + if (curNode->IsUnnamed() || + (bIsProperty && curNode->GetElementType() != XFA_Element::PageSet)) { + iCurrIndex = m_pNodeHelper->GetIndex(curNode, XFA_LOGIC_Transparent, + bIsProperty, TRUE); + } else { + iCurrIndex = m_pNodeHelper->GetIndex(curNode, XFA_LOGIC_Transparent, + bIsProperty, FALSE); + } + } + int32_t iFoundCount = findNodes.GetSize(); + wsCondition.TrimLeft(); + wsCondition.TrimRight(); + int32_t iLen = wsCondition.GetLength(); + if (!iLen) { + if (rnd.m_dwStyles & XFA_RESOLVENODE_ALL) { + return; + } + if (iFoundCount == 1) { + return; + } + if (iFoundCount <= iCurrIndex) { + if (rnd.m_dwStyles & XFA_RESOLVENODE_CreateNode) { + m_pNodeHelper->m_pCreateParent = ToNode(rnd.m_CurNode); + m_pNodeHelper->m_iCreateCount = iCurrIndex - iFoundCount + 1; + } + findNodes.RemoveAll(); + return; + } else { + CXFA_Node* ret = findNodes[iCurrIndex]; + findNodes.RemoveAll(); + findNodes.Add(ret); + return; + } + } + FX_WCHAR wTypeChar = wsCondition[0]; + switch (wTypeChar) { + case '[': + ConditionArray(iCurrIndex, wsCondition, iFoundCount, rnd); + return; + case '(': + return; + case '"': + return; + case '.': + if (iLen > 1 && (wsCondition[1] == '[' || wsCondition[1] == '(')) { + DoPredicateFilter(iCurrIndex, wsCondition, iFoundCount, rnd); + } + default: + return; + } +} +void CXFA_ResolveProcessor::SetStylesForChild(uint32_t dwParentStyles, + CXFA_ResolveNodesData& rnd) { + uint32_t dwSubStyles = XFA_RESOLVENODE_Children; + if (dwParentStyles & XFA_RESOLVENODE_TagName) { + dwSubStyles |= XFA_RESOLVENODE_TagName; + } + dwSubStyles &= ~XFA_RESOLVENODE_Parent; + dwSubStyles &= ~XFA_RESOLVENODE_Siblings; + dwSubStyles &= ~XFA_RESOLVENODE_Properties; + dwSubStyles |= XFA_RESOLVENODE_ALL; + rnd.m_dwStyles = dwSubStyles; +} +int32_t CXFA_ResolveProcessor::SetResultCreateNode( + XFA_RESOLVENODE_RS& resolveNodeRS, + CFX_WideString& wsLastCondition) { + if (m_pNodeHelper->m_pCreateParent) { + resolveNodeRS.nodes.Add(m_pNodeHelper->m_pCreateParent); + } else { + m_pNodeHelper->CreateNode_ForCondition(wsLastCondition); + } + resolveNodeRS.dwFlags = m_pNodeHelper->m_iCreateFlag; + if (resolveNodeRS.dwFlags == XFA_RESOLVENODE_RSTYPE_CreateNodeOne) { + if (m_pNodeHelper->m_iCurAllStart != -1) { + resolveNodeRS.dwFlags = XFA_RESOLVENODE_RSTYPE_CreateNodeMidAll; + } + } + return resolveNodeRS.nodes.GetSize(); +} +void CXFA_ResolveProcessor::SetIndexDataBind(CFX_WideString& wsNextCondition, + int32_t& iIndex, + int32_t iCount) { + if (m_pNodeHelper->CreateNode_ForCondition(wsNextCondition)) { + if (m_pNodeHelper->m_eLastCreateType == XFA_Element::DataGroup) { + iIndex = 0; + } else { + iIndex = iCount - 1; + } + } else { + iIndex = iCount - 1; + } +} + +CXFA_ResolveNodesData::CXFA_ResolveNodesData(CXFA_ScriptContext* pSC) + : m_pSC(pSC), + m_CurNode(nullptr), + m_wsName(), + m_uHashName(XFA_HASHCODE_None), + m_wsCondition(), + m_nLevel(0), + m_Nodes(), + m_dwStyles(XFA_RESOLVENODE_Children), + m_pScriptAttribute(nullptr), + m_dwFlag(XFA_RESOVENODE_RSTYPE_Nodes) {} + +CXFA_ResolveNodesData::~CXFA_ResolveNodesData() { + m_Nodes.RemoveAll(); +} diff --git a/xfa/fxfa/parser/cxfa_resolveprocessor.h b/xfa/fxfa/parser/cxfa_resolveprocessor.h new file mode 100644 index 0000000000..4db0ea2270 --- /dev/null +++ b/xfa/fxfa/parser/cxfa_resolveprocessor.h @@ -0,0 +1,78 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef XFA_FXFA_PARSER_CXFA_RESOLVEPROCESSOR_H_ +#define XFA_FXFA_PARSER_CXFA_RESOLVEPROCESSOR_H_ + +#include "xfa/fxfa/parser/xfa_object.h" +#include "xfa/fxfa/parser/xfa_resolvenode_rs.h" + +class CXFA_NodeHelper; +class CXFA_ScriptContext; + +class CXFA_ResolveNodesData { + public: + CXFA_ResolveNodesData(CXFA_ScriptContext* pSC = nullptr); + ~CXFA_ResolveNodesData(); + + CXFA_ScriptContext* m_pSC; + CXFA_Object* m_CurNode; + CFX_WideString m_wsName; + XFA_HashCode m_uHashName; + CFX_WideString m_wsCondition; + int32_t m_nLevel; + CXFA_ObjArray m_Nodes; + uint32_t m_dwStyles; + const XFA_SCRIPTATTRIBUTEINFO* m_pScriptAttribute; + XFA_RESOVENODE_RSTYPE m_dwFlag; +}; + +class CXFA_ResolveProcessor { + public: + CXFA_ResolveProcessor(); + ~CXFA_ResolveProcessor(); + + int32_t Resolve(CXFA_ResolveNodesData& rnd); + int32_t GetFilter(const CFX_WideStringC& wsExpression, + int32_t nStart, + CXFA_ResolveNodesData& rnd); + int32_t SetResultCreateNode(XFA_RESOLVENODE_RS& resolveNodeRS, + CFX_WideString& wsLastCondition); + void SetIndexDataBind(CFX_WideString& wsNextCondition, + int32_t& iIndex, + int32_t iCount); + void SetCurStart(int32_t start) { m_iCurStart = start; } + + CXFA_NodeHelper* GetNodeHelper() { return m_pNodeHelper; } + + private: + int32_t ResolveForAttributeRs(CXFA_Object* curNode, + CXFA_ResolveNodesData& rnd, + const CFX_WideStringC& strAttr); + int32_t ResolveAnyChild(CXFA_ResolveNodesData& rnd); + int32_t ResolveDollar(CXFA_ResolveNodesData& rnd); + int32_t ResolveExcalmatory(CXFA_ResolveNodesData& rnd); + int32_t ResolveNumberSign(CXFA_ResolveNodesData& rnd); + int32_t ResolveAsterisk(CXFA_ResolveNodesData& rnd); + int32_t ResolveNormal(CXFA_ResolveNodesData& rnd); + int32_t ResolvePopStack(CFX_Int32Array& stack); + void SetStylesForChild(uint32_t dwParentStyles, CXFA_ResolveNodesData& rnd); + + void ConditionArray(int32_t iCurIndex, + CFX_WideString wsCondition, + int32_t iFoundCount, + CXFA_ResolveNodesData& rnd); + void DoPredicateFilter(int32_t iCurIndex, + CFX_WideString wsCondition, + int32_t iFoundCount, + CXFA_ResolveNodesData& rnd); + void FilterCondition(CXFA_ResolveNodesData& rnd, CFX_WideString wsCondition); + + int32_t m_iCurStart; + CXFA_NodeHelper* m_pNodeHelper; +}; + +#endif // XFA_FXFA_PARSER_CXFA_RESOLVEPROCESSOR_H_ diff --git a/xfa/fxfa/parser/cxfa_scriptcontext.cpp b/xfa/fxfa/parser/cxfa_scriptcontext.cpp new file mode 100644 index 0000000000..16c46964f4 --- /dev/null +++ b/xfa/fxfa/parser/cxfa_scriptcontext.cpp @@ -0,0 +1,739 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "xfa/fxfa/parser/cxfa_scriptcontext.h" + +#include "core/fxcrt/include/fx_ext.h" +#include "fxjs/include/cfxjse_arguments.h" +#include "fxjs/include/cfxjse_class.h" +#include "fxjs/include/cfxjse_value.h" +#include "xfa/fxfa/app/xfa_ffnotify.h" +#include "xfa/fxfa/include/cxfa_eventparam.h" +#include "xfa/fxfa/parser/cxfa_nodehelper.h" +#include "xfa/fxfa/parser/cxfa_resolveprocessor.h" +#include "xfa/fxfa/parser/xfa_doclayout.h" +#include "xfa/fxfa/parser/xfa_document.h" +#include "xfa/fxfa/parser/xfa_localemgr.h" +#include "xfa/fxfa/parser/xfa_object.h" +#include "xfa/fxfa/parser/xfa_resolvenode_rs.h" +#include "xfa/fxfa/parser/xfa_utils.h" + +namespace { + +const FXJSE_CLASS_DESCRIPTOR GlobalClassDescriptor = { + "Root", // name + nullptr, // constructor + nullptr, // properties + nullptr, // methods + 0, // property count + 0, // method count + CXFA_ScriptContext::GlobalPropTypeGetter, + CXFA_ScriptContext::GlobalPropertyGetter, + CXFA_ScriptContext::GlobalPropertySetter, + nullptr, // property deleter + CXFA_ScriptContext::NormalMethodCall, +}; + +const FXJSE_CLASS_DESCRIPTOR NormalClassDescriptor = { + "XFAObject", // name + nullptr, // constructor + nullptr, // properties + nullptr, // methods + 0, // property count + 0, // method count + CXFA_ScriptContext::NormalPropTypeGetter, + CXFA_ScriptContext::NormalPropertyGetter, + CXFA_ScriptContext::NormalPropertySetter, + nullptr, // property deleter + CXFA_ScriptContext::NormalMethodCall, +}; + +const FXJSE_CLASS_DESCRIPTOR VariablesClassDescriptor = { + "XFAScriptObject", // name + nullptr, // constructor + nullptr, // properties + nullptr, // methods + 0, // property count + 0, // method count + CXFA_ScriptContext::NormalPropTypeGetter, + CXFA_ScriptContext::GlobalPropertyGetter, + CXFA_ScriptContext::GlobalPropertySetter, + nullptr, // property deleter + CXFA_ScriptContext::NormalMethodCall, +}; + +const char kFormCalcRuntime[] = "foxit_xfa_formcalc_runtime"; + +CXFA_ThisProxy* ToThisProxy(CFXJSE_Value* pValue, CFXJSE_Class* pClass) { + return static_cast(pValue->ToHostObject(pClass)); +} + +} // namespace + +// static. +CXFA_Object* CXFA_ScriptContext::ToObject(CFXJSE_Value* pValue, + CFXJSE_Class* pClass) { + return static_cast(pValue->ToHostObject(pClass)); +} + +CXFA_ScriptContext::CXFA_ScriptContext(CXFA_Document* pDocument) + : m_pDocument(pDocument), + m_pIsolate(nullptr), + m_pJsClass(nullptr), + m_eScriptType(XFA_SCRIPTLANGTYPE_Unkown), + m_pScriptNodeArray(nullptr), + m_pThisObject(nullptr), + m_dwBuiltInInFlags(0), + m_eRunAtType(XFA_ATTRIBUTEENUM_Client) {} + +CXFA_ScriptContext::~CXFA_ScriptContext() { + FX_POSITION ps = m_mapVariableToContext.GetStartPosition(); + while (ps) { + CXFA_Object* pScriptNode; + CFXJSE_Context* pVariableContext = nullptr; + m_mapVariableToContext.GetNextAssoc(ps, pScriptNode, pVariableContext); + + delete ToThisProxy(pVariableContext->GetGlobalObject().get(), nullptr); + delete pVariableContext; + } + m_mapVariableToContext.RemoveAll(); + + m_upObjectArray.RemoveAll(); +} +void CXFA_ScriptContext::Initialize(v8::Isolate* pIsolate) { + m_pIsolate = pIsolate; + DefineJsContext(); + DefineJsClass(); + m_ResolveProcessor.reset(new CXFA_ResolveProcessor); +} +FX_BOOL CXFA_ScriptContext::RunScript(XFA_SCRIPTLANGTYPE eScriptType, + const CFX_WideStringC& wsScript, + CFXJSE_Value* hRetValue, + CXFA_Object* pThisObject) { + CFX_ByteString btScript; + XFA_SCRIPTLANGTYPE eSaveType = m_eScriptType; + m_eScriptType = eScriptType; + if (eScriptType == XFA_SCRIPTLANGTYPE_Formcalc) { + if (!m_FM2JSContext) { + m_FM2JSContext.reset( + new CXFA_FM2JSContext(m_pIsolate, m_JsContext.get(), m_pDocument)); + } + CFX_WideTextBuf wsJavaScript; + CFX_WideString wsErrorInfo; + int32_t iFlags = + CXFA_FM2JSContext::Translate(wsScript, wsJavaScript, wsErrorInfo); + if (iFlags) { + hRetValue->SetUndefined(); + return FALSE; + } + btScript = + FX_UTF8Encode(wsJavaScript.GetBuffer(), wsJavaScript.GetLength()); + } else { + btScript = FX_UTF8Encode(wsScript.c_str(), wsScript.GetLength()); + } + CXFA_Object* pOriginalObject = m_pThisObject; + m_pThisObject = pThisObject; + CFXJSE_Value* pValue = pThisObject ? GetJSValueFromMap(pThisObject) : nullptr; + FX_BOOL bRet = + m_JsContext->ExecuteScript(btScript.c_str(), hRetValue, pValue); + m_pThisObject = pOriginalObject; + m_eScriptType = eSaveType; + return bRet; +} +void CXFA_ScriptContext::GlobalPropertySetter(CFXJSE_Value* pObject, + const CFX_ByteStringC& szPropName, + CFXJSE_Value* pValue) { + CXFA_Object* lpOrginalNode = ToObject(pObject, nullptr); + CXFA_Document* pDoc = lpOrginalNode->GetDocument(); + CXFA_ScriptContext* lpScriptContext = pDoc->GetScriptContext(); + CXFA_Object* lpCurNode = lpScriptContext->GetVariablesThis(lpOrginalNode); + CFX_WideString wsPropName = CFX_WideString::FromUTF8(szPropName); + uint32_t dwFlag = XFA_RESOLVENODE_Parent | XFA_RESOLVENODE_Siblings | + XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Properties | + XFA_RESOLVENODE_Attributes; + CXFA_Node* pRefNode = ToNode(lpScriptContext->GetThisObject()); + if (lpOrginalNode->IsVariablesThis()) + pRefNode = ToNode(lpCurNode); + if (lpScriptContext->QueryNodeByFlag(pRefNode, wsPropName.AsStringC(), pValue, + dwFlag, TRUE)) { + return; + } + if (lpOrginalNode->IsVariablesThis()) { + if (pValue && pValue->IsUndefined()) { + pObject->SetObjectOwnProperty(szPropName, pValue); + return; + } + } + CXFA_FFNotify* pNotify = pDoc->GetNotify(); + if (!pNotify) { + return; + } + pNotify->GetDocProvider()->SetGlobalProperty(pNotify->GetHDOC(), szPropName, + pValue); +} +FX_BOOL CXFA_ScriptContext::QueryNodeByFlag(CXFA_Node* refNode, + const CFX_WideStringC& propname, + CFXJSE_Value* pValue, + uint32_t dwFlag, + FX_BOOL bSetting) { + if (!refNode) + return false; + XFA_RESOLVENODE_RS resolveRs; + if (ResolveObjects(refNode, propname, resolveRs, dwFlag) <= 0) + return false; + if (resolveRs.dwFlags == XFA_RESOVENODE_RSTYPE_Nodes) { + pValue->Assign(GetJSValueFromMap(resolveRs.nodes[0])); + return true; + } + if (resolveRs.dwFlags == XFA_RESOVENODE_RSTYPE_Attribute) { + const XFA_SCRIPTATTRIBUTEINFO* lpAttributeInfo = resolveRs.pScriptAttribute; + if (lpAttributeInfo) { + (resolveRs.nodes[0]->*(lpAttributeInfo->lpfnCallback))( + pValue, bSetting, (XFA_ATTRIBUTE)lpAttributeInfo->eAttribute); + } + } + return true; +} +void CXFA_ScriptContext::GlobalPropertyGetter(CFXJSE_Value* pObject, + const CFX_ByteStringC& szPropName, + CFXJSE_Value* pValue) { + CXFA_Object* pOriginalObject = ToObject(pObject, nullptr); + CXFA_Document* pDoc = pOriginalObject->GetDocument(); + CXFA_ScriptContext* lpScriptContext = pDoc->GetScriptContext(); + CXFA_Object* lpCurNode = lpScriptContext->GetVariablesThis(pOriginalObject); + CFX_WideString wsPropName = CFX_WideString::FromUTF8(szPropName); + if (lpScriptContext->GetType() == XFA_SCRIPTLANGTYPE_Formcalc) { + if (szPropName == kFormCalcRuntime) { + lpScriptContext->m_FM2JSContext->GlobalPropertyGetter(pValue); + return; + } + XFA_HashCode uHashCode = static_cast( + FX_HashCode_GetW(wsPropName.AsStringC(), false)); + if (uHashCode != XFA_HASHCODE_Layout) { + CXFA_Object* pObj = + lpScriptContext->GetDocument()->GetXFAObject(uHashCode); + if (pObj) { + pValue->Assign(lpScriptContext->GetJSValueFromMap(pObj)); + return; + } + } + } + uint32_t dwFlag = XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Properties | + XFA_RESOLVENODE_Attributes; + CXFA_Node* pRefNode = ToNode(lpScriptContext->GetThisObject()); + if (pOriginalObject->IsVariablesThis()) { + pRefNode = ToNode(lpCurNode); + } + if (lpScriptContext->QueryNodeByFlag(pRefNode, wsPropName.AsStringC(), pValue, + dwFlag, FALSE)) { + return; + } + dwFlag = XFA_RESOLVENODE_Parent | XFA_RESOLVENODE_Siblings; + if (lpScriptContext->QueryNodeByFlag(pRefNode, wsPropName.AsStringC(), pValue, + dwFlag, FALSE)) { + return; + } + CXFA_Object* pScriptObject = + lpScriptContext->GetVariablesThis(pOriginalObject, TRUE); + if (pScriptObject && + lpScriptContext->QueryVariableValue(pScriptObject->AsNode(), szPropName, + pValue, TRUE)) { + return; + } + CXFA_FFNotify* pNotify = pDoc->GetNotify(); + if (!pNotify) { + return; + } + pNotify->GetDocProvider()->GetGlobalProperty(pNotify->GetHDOC(), szPropName, + pValue); +} +void CXFA_ScriptContext::NormalPropertyGetter(CFXJSE_Value* pOriginalValue, + const CFX_ByteStringC& szPropName, + CFXJSE_Value* pReturnValue) { + CXFA_Object* pOriginalObject = ToObject(pOriginalValue, nullptr); + if (!pOriginalObject) { + pReturnValue->SetUndefined(); + return; + } + CFX_WideString wsPropName = CFX_WideString::FromUTF8(szPropName); + CXFA_ScriptContext* lpScriptContext = + pOriginalObject->GetDocument()->GetScriptContext(); + CXFA_Object* pObject = lpScriptContext->GetVariablesThis(pOriginalObject); + if (wsPropName == FX_WSTRC(L"xfa")) { + CFXJSE_Value* pValue = lpScriptContext->GetJSValueFromMap( + lpScriptContext->GetDocument()->GetRoot()); + pReturnValue->Assign(pValue); + return; + } + uint32_t dwFlag = XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Properties | + XFA_RESOLVENODE_Attributes; + FX_BOOL bRet = lpScriptContext->QueryNodeByFlag( + ToNode(pObject), wsPropName.AsStringC(), pReturnValue, dwFlag, FALSE); + if (bRet) { + return; + } + if (pObject == lpScriptContext->GetThisObject() || + (lpScriptContext->GetType() == XFA_SCRIPTLANGTYPE_Javascript && + !lpScriptContext->IsStrictScopeInJavaScript())) { + dwFlag = XFA_RESOLVENODE_Parent | XFA_RESOLVENODE_Siblings; + bRet = lpScriptContext->QueryNodeByFlag( + ToNode(pObject), wsPropName.AsStringC(), pReturnValue, dwFlag, FALSE); + } + if (bRet) { + return; + } + CXFA_Object* pScriptObject = + lpScriptContext->GetVariablesThis(pOriginalObject, TRUE); + if (pScriptObject) { + bRet = lpScriptContext->QueryVariableValue(ToNode(pScriptObject), + szPropName, pReturnValue, TRUE); + } + if (!bRet) { + pReturnValue->SetUndefined(); + } +} +void CXFA_ScriptContext::NormalPropertySetter(CFXJSE_Value* pOriginalValue, + const CFX_ByteStringC& szPropName, + CFXJSE_Value* pReturnValue) { + CXFA_Object* pOriginalObject = ToObject(pOriginalValue, nullptr); + if (!pOriginalObject) + return; + + CXFA_ScriptContext* lpScriptContext = + pOriginalObject->GetDocument()->GetScriptContext(); + CXFA_Object* pObject = lpScriptContext->GetVariablesThis(pOriginalObject); + CFX_WideString wsPropName = CFX_WideString::FromUTF8(szPropName); + const XFA_SCRIPTATTRIBUTEINFO* lpAttributeInfo = XFA_GetScriptAttributeByName( + pObject->GetElementType(), wsPropName.AsStringC()); + if (lpAttributeInfo) { + (pObject->*(lpAttributeInfo->lpfnCallback))( + pReturnValue, TRUE, (XFA_ATTRIBUTE)lpAttributeInfo->eAttribute); + } else { + if (pObject->IsNode()) { + if (wsPropName.GetAt(0) == '#') { + wsPropName = wsPropName.Right(wsPropName.GetLength() - 1); + } + CXFA_Node* pNode = ToNode(pObject); + CXFA_Node* pPropOrChild = nullptr; + XFA_Element eType = XFA_GetElementTypeForName(wsPropName.AsStringC()); + if (eType != XFA_Element::Unknown) + pPropOrChild = pNode->GetProperty(0, eType); + else + pPropOrChild = pNode->GetFirstChildByName(wsPropName.AsStringC()); + + if (pPropOrChild) { + CFX_WideString wsDefaultName(L"{default}"); + const XFA_SCRIPTATTRIBUTEINFO* lpAttrInfo = + XFA_GetScriptAttributeByName(pPropOrChild->GetElementType(), + wsDefaultName.AsStringC()); + if (lpAttrInfo) { + (pPropOrChild->*(lpAttrInfo->lpfnCallback))( + pReturnValue, TRUE, (XFA_ATTRIBUTE)lpAttrInfo->eAttribute); + return; + } + } + } + CXFA_Object* pScriptObject = + lpScriptContext->GetVariablesThis(pOriginalObject, TRUE); + if (pScriptObject) { + lpScriptContext->QueryVariableValue(ToNode(pScriptObject), szPropName, + pReturnValue, FALSE); + } + } +} +int32_t CXFA_ScriptContext::NormalPropTypeGetter( + CFXJSE_Value* pOriginalValue, + const CFX_ByteStringC& szPropName, + FX_BOOL bQueryIn) { + CXFA_Object* pObject = ToObject(pOriginalValue, nullptr); + if (!pObject) + return FXJSE_ClassPropType_None; + + CXFA_ScriptContext* lpScriptContext = + pObject->GetDocument()->GetScriptContext(); + pObject = lpScriptContext->GetVariablesThis(pObject); + XFA_Element eType = pObject->GetElementType(); + CFX_WideString wsPropName = CFX_WideString::FromUTF8(szPropName); + if (XFA_GetMethodByName(eType, wsPropName.AsStringC())) { + return FXJSE_ClassPropType_Method; + } + if (bQueryIn && + !XFA_GetScriptAttributeByName(eType, wsPropName.AsStringC())) { + return FXJSE_ClassPropType_None; + } + return FXJSE_ClassPropType_Property; +} +int32_t CXFA_ScriptContext::GlobalPropTypeGetter( + CFXJSE_Value* pOriginalValue, + const CFX_ByteStringC& szPropName, + FX_BOOL bQueryIn) { + CXFA_Object* pObject = ToObject(pOriginalValue, nullptr); + if (!pObject) + return FXJSE_ClassPropType_None; + + CXFA_ScriptContext* lpScriptContext = + pObject->GetDocument()->GetScriptContext(); + pObject = lpScriptContext->GetVariablesThis(pObject); + XFA_Element eType = pObject->GetElementType(); + CFX_WideString wsPropName = CFX_WideString::FromUTF8(szPropName); + if (XFA_GetMethodByName(eType, wsPropName.AsStringC())) { + return FXJSE_ClassPropType_Method; + } + return FXJSE_ClassPropType_Property; +} +void CXFA_ScriptContext::NormalMethodCall(CFXJSE_Value* pThis, + const CFX_ByteStringC& szFuncName, + CFXJSE_Arguments& args) { + CXFA_Object* pObject = ToObject(pThis, nullptr); + if (!pObject) + return; + + CXFA_ScriptContext* lpScriptContext = + pObject->GetDocument()->GetScriptContext(); + pObject = lpScriptContext->GetVariablesThis(pObject); + CFX_WideString wsFunName = CFX_WideString::FromUTF8(szFuncName); + const XFA_METHODINFO* lpMethodInfo = + XFA_GetMethodByName(pObject->GetElementType(), wsFunName.AsStringC()); + if (!lpMethodInfo) + return; + + (pObject->*(lpMethodInfo->lpfnCallback))(&args); +} +FX_BOOL CXFA_ScriptContext::IsStrictScopeInJavaScript() { + return m_pDocument->HasFlag(XFA_DOCFLAG_StrictScoping); +} +XFA_SCRIPTLANGTYPE CXFA_ScriptContext::GetType() { + return m_eScriptType; +} +void CXFA_ScriptContext::DefineJsContext() { + m_JsContext.reset(CFXJSE_Context::Create(m_pIsolate, &GlobalClassDescriptor, + m_pDocument->GetRoot())); + RemoveBuiltInObjs(m_JsContext.get()); + m_JsContext->EnableCompatibleMode(); +} +CFXJSE_Context* CXFA_ScriptContext::CreateVariablesContext( + CXFA_Node* pScriptNode, + CXFA_Node* pSubform) { + if (!pScriptNode || !pSubform) + return nullptr; + + CFXJSE_Context* pVariablesContext = + CFXJSE_Context::Create(m_pIsolate, &VariablesClassDescriptor, + new CXFA_ThisProxy(pSubform, pScriptNode)); + RemoveBuiltInObjs(pVariablesContext); + pVariablesContext->EnableCompatibleMode(); + m_mapVariableToContext.SetAt(pScriptNode, pVariablesContext); + return pVariablesContext; +} +CXFA_Object* CXFA_ScriptContext::GetVariablesThis(CXFA_Object* pObject, + FX_BOOL bScriptNode) { + if (!pObject->IsVariablesThis()) + return pObject; + + CXFA_ThisProxy* pProxy = static_cast(pObject); + return bScriptNode ? pProxy->GetScriptNode() : pProxy->GetThisNode(); +} + +FX_BOOL CXFA_ScriptContext::RunVariablesScript(CXFA_Node* pScriptNode) { + if (!pScriptNode) + return FALSE; + + if (pScriptNode->GetElementType() != XFA_Element::Script) + return TRUE; + + CXFA_Node* pParent = pScriptNode->GetNodeItem(XFA_NODEITEM_Parent); + if (!pParent || pParent->GetElementType() != XFA_Element::Variables) + return FALSE; + + if (m_mapVariableToContext.GetValueAt(pScriptNode)) + return TRUE; + + CXFA_Node* pTextNode = pScriptNode->GetNodeItem(XFA_NODEITEM_FirstChild); + if (!pTextNode) + return FALSE; + + CFX_WideStringC wsScript; + if (!pTextNode->TryCData(XFA_ATTRIBUTE_Value, wsScript)) + return FALSE; + + CFX_ByteString btScript = + FX_UTF8Encode(wsScript.c_str(), wsScript.GetLength()); + std::unique_ptr hRetValue(new CFXJSE_Value(m_pIsolate)); + CXFA_Node* pThisObject = pParent->GetNodeItem(XFA_NODEITEM_Parent); + CFXJSE_Context* pVariablesContext = + CreateVariablesContext(pScriptNode, pThisObject); + CXFA_Object* pOriginalObject = m_pThisObject; + m_pThisObject = pThisObject; + FX_BOOL bRet = + pVariablesContext->ExecuteScript(btScript.c_str(), hRetValue.get()); + m_pThisObject = pOriginalObject; + return bRet; +} + +FX_BOOL CXFA_ScriptContext::QueryVariableValue( + CXFA_Node* pScriptNode, + const CFX_ByteStringC& szPropName, + CFXJSE_Value* pValue, + FX_BOOL bGetter) { + if (!pScriptNode || pScriptNode->GetElementType() != XFA_Element::Script) + return FALSE; + + CXFA_Node* variablesNode = pScriptNode->GetNodeItem(XFA_NODEITEM_Parent); + if (!variablesNode || + variablesNode->GetElementType() != XFA_Element::Variables) + return FALSE; + + void* lpVariables = m_mapVariableToContext.GetValueAt(pScriptNode); + if (!lpVariables) + return FALSE; + + FX_BOOL bRes = FALSE; + CFXJSE_Context* pVariableContext = static_cast(lpVariables); + std::unique_ptr pObject = pVariableContext->GetGlobalObject(); + std::unique_ptr hVariableValue(new CFXJSE_Value(m_pIsolate)); + if (!bGetter) { + pObject->SetObjectOwnProperty(szPropName, pValue); + bRes = TRUE; + } else if (pObject->HasObjectOwnProperty(szPropName, FALSE)) { + pObject->GetObjectProperty(szPropName, hVariableValue.get()); + if (hVariableValue->IsFunction()) + pValue->SetFunctionBind(hVariableValue.get(), pObject.get()); + else if (bGetter) + pValue->Assign(hVariableValue.get()); + else + hVariableValue.get()->Assign(pValue); + bRes = TRUE; + } + return bRes; +} + +void CXFA_ScriptContext::DefineJsClass() { + m_pJsClass = CFXJSE_Class::Create(m_JsContext.get(), &NormalClassDescriptor); +} + +void CXFA_ScriptContext::RemoveBuiltInObjs(CFXJSE_Context* pContext) const { + static const CFX_ByteStringC OBJ_NAME[2] = {"Number", "Date"}; + std::unique_ptr pObject = pContext->GetGlobalObject(); + std::unique_ptr hProp(new CFXJSE_Value(m_pIsolate)); + for (int i = 0; i < 2; ++i) { + if (pObject->GetObjectProperty(OBJ_NAME[i], hProp.get())) + pObject->DeleteObjectProperty(OBJ_NAME[i]); + } +} +CFXJSE_Class* CXFA_ScriptContext::GetJseNormalClass() { + return m_pJsClass; +} +int32_t CXFA_ScriptContext::ResolveObjects(CXFA_Object* refNode, + const CFX_WideStringC& wsExpression, + XFA_RESOLVENODE_RS& resolveNodeRS, + uint32_t dwStyles, + CXFA_Node* bindNode) { + if (wsExpression.IsEmpty()) { + return 0; + } + if (m_eScriptType != XFA_SCRIPTLANGTYPE_Formcalc || + (dwStyles & (XFA_RESOLVENODE_Parent | XFA_RESOLVENODE_Siblings))) { + m_upObjectArray.RemoveAll(); + } + if (refNode && refNode->IsNode() && + (dwStyles & (XFA_RESOLVENODE_Parent | XFA_RESOLVENODE_Siblings))) { + m_upObjectArray.Add(refNode->AsNode()); + } + FX_BOOL bNextCreate = FALSE; + if (dwStyles & XFA_RESOLVENODE_CreateNode) { + m_ResolveProcessor->GetNodeHelper()->SetCreateNodeType(bindNode); + } + m_ResolveProcessor->GetNodeHelper()->m_pCreateParent = nullptr; + m_ResolveProcessor->GetNodeHelper()->m_iCurAllStart = -1; + CXFA_ResolveNodesData rndFind; + int32_t nStart = 0; + int32_t nLevel = 0; + int32_t nRet = -1; + rndFind.m_pSC = this; + CXFA_ObjArray findNodes; + findNodes.Add(refNode ? refNode : m_pDocument->GetRoot()); + int32_t nNodes = 0; + while (TRUE) { + nNodes = findNodes.GetSize(); + int32_t i = 0; + rndFind.m_dwStyles = dwStyles; + m_ResolveProcessor->SetCurStart(nStart); + nStart = m_ResolveProcessor->GetFilter(wsExpression, nStart, rndFind); + if (nStart < 1) { + if ((dwStyles & XFA_RESOLVENODE_CreateNode) && !bNextCreate) { + CXFA_Node* pDataNode = nullptr; + nStart = m_ResolveProcessor->GetNodeHelper()->m_iCurAllStart; + if (nStart != -1) { + pDataNode = m_pDocument->GetNotBindNode(findNodes); + if (pDataNode) { + findNodes.RemoveAll(); + findNodes.Add(pDataNode); + break; + } + } else { + pDataNode = findNodes[0]->AsNode(); + findNodes.RemoveAll(); + findNodes.Add(pDataNode); + break; + } + dwStyles |= XFA_RESOLVENODE_Bind; + findNodes.RemoveAll(); + findNodes.Add(m_ResolveProcessor->GetNodeHelper()->m_pAllStartParent); + continue; + } else { + break; + } + } + if (bNextCreate) { + FX_BOOL bCreate = + m_ResolveProcessor->GetNodeHelper()->ResolveNodes_CreateNode( + rndFind.m_wsName, rndFind.m_wsCondition, + nStart == wsExpression.GetLength(), this); + if (bCreate) { + continue; + } else { + break; + } + } + CXFA_ObjArray retNodes; + while (i < nNodes) { + FX_BOOL bDataBind = FALSE; + if (((dwStyles & XFA_RESOLVENODE_Bind) || + (dwStyles & XFA_RESOLVENODE_CreateNode)) && + nNodes > 1) { + CXFA_ResolveNodesData rndBind; + m_ResolveProcessor->GetFilter(wsExpression, nStart, rndBind); + m_ResolveProcessor->SetIndexDataBind(rndBind.m_wsCondition, i, nNodes); + bDataBind = TRUE; + } + rndFind.m_CurNode = findNodes[i++]; + rndFind.m_nLevel = nLevel; + rndFind.m_dwFlag = XFA_RESOVENODE_RSTYPE_Nodes; + nRet = m_ResolveProcessor->Resolve(rndFind); + if (nRet < 1) { + continue; + } + if (rndFind.m_dwFlag == XFA_RESOVENODE_RSTYPE_Attribute && + rndFind.m_pScriptAttribute && nStart < wsExpression.GetLength()) { + std::unique_ptr pValue(new CFXJSE_Value(m_pIsolate)); + (rndFind.m_Nodes[0]->*(rndFind.m_pScriptAttribute->lpfnCallback))( + pValue.get(), FALSE, + (XFA_ATTRIBUTE)rndFind.m_pScriptAttribute->eAttribute); + rndFind.m_Nodes.SetAt(0, ToObject(pValue.get(), nullptr)); + } + int32_t iSize = m_upObjectArray.GetSize(); + if (iSize) { + m_upObjectArray.RemoveAt(iSize - 1); + } + retNodes.Append(rndFind.m_Nodes); + rndFind.m_Nodes.RemoveAll(); + if (bDataBind) { + break; + } + } + findNodes.RemoveAll(); + nNodes = retNodes.GetSize(); + if (nNodes < 1) { + if (dwStyles & XFA_RESOLVENODE_CreateNode) { + bNextCreate = TRUE; + if (!m_ResolveProcessor->GetNodeHelper()->m_pCreateParent) { + m_ResolveProcessor->GetNodeHelper()->m_pCreateParent = + ToNode(rndFind.m_CurNode); + m_ResolveProcessor->GetNodeHelper()->m_iCreateCount = 1; + } + FX_BOOL bCreate = + m_ResolveProcessor->GetNodeHelper()->ResolveNodes_CreateNode( + rndFind.m_wsName, rndFind.m_wsCondition, + nStart == wsExpression.GetLength(), this); + if (bCreate) { + continue; + } else { + break; + } + } else { + break; + } + } + findNodes.Copy(retNodes); + rndFind.m_Nodes.RemoveAll(); + if (nLevel == 0) { + dwStyles &= ~(XFA_RESOLVENODE_Parent | XFA_RESOLVENODE_Siblings); + } + nLevel++; + } + if (!bNextCreate) { + resolveNodeRS.dwFlags = rndFind.m_dwFlag; + if (nNodes > 0) { + resolveNodeRS.nodes.Append(findNodes); + } + if (rndFind.m_dwFlag == XFA_RESOVENODE_RSTYPE_Attribute) { + resolveNodeRS.pScriptAttribute = rndFind.m_pScriptAttribute; + return 1; + } + } + if (dwStyles & (XFA_RESOLVENODE_CreateNode | XFA_RESOLVENODE_Bind | + XFA_RESOLVENODE_BindNew)) { + m_ResolveProcessor->SetResultCreateNode(resolveNodeRS, + rndFind.m_wsCondition); + if (!bNextCreate && (dwStyles & XFA_RESOLVENODE_CreateNode)) { + resolveNodeRS.dwFlags = XFA_RESOVENODE_RSTYPE_ExistNodes; + } + return resolveNodeRS.nodes.GetSize(); + } + return nNodes; +} + +void CXFA_ScriptContext::AddToCacheList(std::unique_ptr pList) { + m_CacheList.push_back(std::move(pList)); +} + +CFXJSE_Value* CXFA_ScriptContext::GetJSValueFromMap(CXFA_Object* pObject) { + if (!pObject) + return nullptr; + if (pObject->IsNode()) + RunVariablesScript(pObject->AsNode()); + + auto iter = m_mapObjectToValue.find(pObject); + if (iter != m_mapObjectToValue.end()) + return iter->second.get(); + + std::unique_ptr jsValue(new CFXJSE_Value(m_pIsolate)); + jsValue->SetObject(pObject, m_pJsClass); + CFXJSE_Value* pValue = jsValue.get(); + m_mapObjectToValue.insert(std::make_pair(pObject, std::move(jsValue))); + return pValue; +} +int32_t CXFA_ScriptContext::GetIndexByName(CXFA_Node* refNode) { + CXFA_NodeHelper* lpNodeHelper = m_ResolveProcessor->GetNodeHelper(); + return lpNodeHelper->GetIndex(refNode, XFA_LOGIC_Transparent, + lpNodeHelper->NodeIsProperty(refNode), FALSE); +} +int32_t CXFA_ScriptContext::GetIndexByClassName(CXFA_Node* refNode) { + CXFA_NodeHelper* lpNodeHelper = m_ResolveProcessor->GetNodeHelper(); + return lpNodeHelper->GetIndex(refNode, XFA_LOGIC_Transparent, + lpNodeHelper->NodeIsProperty(refNode), TRUE); +} +void CXFA_ScriptContext::GetSomExpression(CXFA_Node* refNode, + CFX_WideString& wsExpression) { + CXFA_NodeHelper* lpNodeHelper = m_ResolveProcessor->GetNodeHelper(); + lpNodeHelper->GetNameExpression(refNode, wsExpression, TRUE, + XFA_LOGIC_Transparent); +} +void CXFA_ScriptContext::SetNodesOfRunScript(CXFA_NodeArray* pArray) { + m_pScriptNodeArray = pArray; +} +void CXFA_ScriptContext::AddNodesOfRunScript(const CXFA_NodeArray& nodes) { + if (!m_pScriptNodeArray) + return; + if (nodes.GetSize() > 0) + m_pScriptNodeArray->Copy(nodes); +} +void CXFA_ScriptContext::AddNodesOfRunScript(CXFA_Node* pNode) { + if (!m_pScriptNodeArray) + return; + if (m_pScriptNodeArray->Find(pNode) == -1) + m_pScriptNodeArray->Add(pNode); +} diff --git a/xfa/fxfa/parser/cxfa_scriptcontext.h b/xfa/fxfa/parser/cxfa_scriptcontext.h new file mode 100644 index 0000000000..f06279024c --- /dev/null +++ b/xfa/fxfa/parser/cxfa_scriptcontext.h @@ -0,0 +1,126 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef XFA_FXFA_PARSER_CXFA_SCRIPTCONTEXT_H_ +#define XFA_FXFA_PARSER_CXFA_SCRIPTCONTEXT_H_ + +#include +#include +#include + +#include "fxjs/include/cfxjse_arguments.h" +#include "xfa/fxfa/fm2js/xfa_fm2jscontext.h" +#include "xfa/fxfa/include/cxfa_eventparam.h" +#include "xfa/fxfa/parser/xfa_document.h" +#include "xfa/fxfa/parser/xfa_resolvenode_rs.h" + +#define XFA_RESOLVENODE_TagName 0x0002 + +class CXFA_ResolveProcessor; + +class CXFA_ScriptContext { + public: + explicit CXFA_ScriptContext(CXFA_Document* pDocument); + ~CXFA_ScriptContext(); + + void Initialize(v8::Isolate* pIsolate); + void SetEventParam(CXFA_EventParam param) { m_eventParam = param; } + CXFA_EventParam* GetEventParam() { return &m_eventParam; } + FX_BOOL RunScript(XFA_SCRIPTLANGTYPE eScriptType, + const CFX_WideStringC& wsScript, + CFXJSE_Value* pRetValue, + CXFA_Object* pThisObject = nullptr); + + int32_t ResolveObjects(CXFA_Object* refNode, + const CFX_WideStringC& wsExpression, + XFA_RESOLVENODE_RS& resolveNodeRS, + uint32_t dwStyles = XFA_RESOLVENODE_Children, + CXFA_Node* bindNode = nullptr); + CFXJSE_Value* GetJSValueFromMap(CXFA_Object* pObject); + void AddToCacheList(std::unique_ptr pList); + CXFA_Object* GetThisObject() const { return m_pThisObject; } + v8::Isolate* GetRuntime() const { return m_pIsolate; } + + int32_t GetIndexByName(CXFA_Node* refNode); + int32_t GetIndexByClassName(CXFA_Node* refNode); + void GetSomExpression(CXFA_Node* refNode, CFX_WideString& wsExpression); + + void SetNodesOfRunScript(CXFA_NodeArray* pArray); + void AddNodesOfRunScript(const CXFA_NodeArray& nodes); + void AddNodesOfRunScript(CXFA_Node* pNode); + CFXJSE_Class* GetJseNormalClass(); + + void SetRunAtType(XFA_ATTRIBUTEENUM eRunAt) { m_eRunAtType = eRunAt; } + FX_BOOL IsRunAtClient() { return m_eRunAtType != XFA_ATTRIBUTEENUM_Server; } + FX_BOOL QueryNodeByFlag(CXFA_Node* refNode, + const CFX_WideStringC& propname, + CFXJSE_Value* pValue, + uint32_t dwFlag, + FX_BOOL bSetting); + FX_BOOL QueryVariableValue(CXFA_Node* pScriptNode, + const CFX_ByteStringC& szPropName, + CFXJSE_Value* pValue, + FX_BOOL bGetter); + FX_BOOL QueryBuiltinValue(const CFX_ByteStringC& szPropName, + CFXJSE_Value* pValue); + static void GlobalPropertyGetter(CFXJSE_Value* pObject, + const CFX_ByteStringC& szPropName, + CFXJSE_Value* pValue); + static void GlobalPropertySetter(CFXJSE_Value* pObject, + const CFX_ByteStringC& szPropName, + CFXJSE_Value* pValue); + static void NormalPropertyGetter(CFXJSE_Value* pObject, + const CFX_ByteStringC& szPropName, + CFXJSE_Value* pValue); + static void NormalPropertySetter(CFXJSE_Value* pObject, + const CFX_ByteStringC& szPropName, + CFXJSE_Value* pValue); + static void NormalMethodCall(CFXJSE_Value* hThis, + const CFX_ByteStringC& szFuncName, + CFXJSE_Arguments& args); + static int32_t NormalPropTypeGetter(CFXJSE_Value* pObject, + const CFX_ByteStringC& szPropName, + FX_BOOL bQueryIn); + static int32_t GlobalPropTypeGetter(CFXJSE_Value* pObject, + const CFX_ByteStringC& szPropName, + FX_BOOL bQueryIn); + FX_BOOL RunVariablesScript(CXFA_Node* pScriptNode); + CXFA_Object* GetVariablesThis(CXFA_Object* pObject, + FX_BOOL bScriptNode = FALSE); + FX_BOOL IsStrictScopeInJavaScript(); + XFA_SCRIPTLANGTYPE GetType(); + CXFA_NodeArray& GetUpObjectArray() { return m_upObjectArray; } + CXFA_Document* GetDocument() const { return m_pDocument; } + + static CXFA_Object* ToObject(CFXJSE_Value* pValue, CFXJSE_Class* pClass); + + private: + void DefineJsContext(); + CFXJSE_Context* CreateVariablesContext(CXFA_Node* pScriptNode, + CXFA_Node* pSubform); + void DefineJsClass(); + void RemoveBuiltInObjs(CFXJSE_Context* pContext) const; + + CXFA_Document* m_pDocument; + std::unique_ptr m_JsContext; + v8::Isolate* m_pIsolate; + CFXJSE_Class* m_pJsClass; + XFA_SCRIPTLANGTYPE m_eScriptType; + std::map> m_mapObjectToValue; + CFX_MapPtrTemplate m_mapVariableToContext; + CXFA_EventParam m_eventParam; + CXFA_NodeArray m_upObjectArray; + // CacheList holds the NodeList items so we can clean them up when we're done. + std::vector> m_CacheList; + CXFA_NodeArray* m_pScriptNodeArray; + std::unique_ptr m_ResolveProcessor; + std::unique_ptr m_FM2JSContext; + CXFA_Object* m_pThisObject; + uint32_t m_dwBuiltInInFlags; + XFA_ATTRIBUTEENUM m_eRunAtType; +}; + +#endif // XFA_FXFA_PARSER_CXFA_SCRIPTCONTEXT_H_ diff --git a/xfa/fxfa/parser/cxfa_valuearray.cpp b/xfa/fxfa/parser/cxfa_valuearray.cpp index face1b4cb4..04afc40b0e 100644 --- a/xfa/fxfa/parser/cxfa_valuearray.cpp +++ b/xfa/fxfa/parser/cxfa_valuearray.cpp @@ -6,7 +6,7 @@ #include "xfa/fxfa/parser/cxfa_valuearray.h" -#include "xfa/fxfa/parser/xfa_script_imp.h" +#include "xfa/fxfa/parser/cxfa_scriptcontext.h" CXFA_ValueArray::CXFA_ValueArray(v8::Isolate* pIsolate) : m_pIsolate(pIsolate) {} diff --git a/xfa/fxfa/parser/xfa_basic_data_element_script.cpp b/xfa/fxfa/parser/xfa_basic_data_element_script.cpp index 7ea1679dcb..f4be53b679 100644 --- a/xfa/fxfa/parser/xfa_basic_data_element_script.cpp +++ b/xfa/fxfa/parser/xfa_basic_data_element_script.cpp @@ -13,7 +13,6 @@ #include "xfa/fxfa/parser/cscript_layoutpseudomodel.h" #include "xfa/fxfa/parser/cscript_logpseudomodel.h" #include "xfa/fxfa/parser/cscript_signaturepseudomodel.h" -#include "xfa/fxfa/parser/xfa_script.h" const XFA_SCRIPTHIERARCHY g_XFAScriptIndex[] = { {0, 0, 0, 2, 316}, {0, 0, 2, 2, 316}, {0, 0, 4, 2, 316}, diff --git a/xfa/fxfa/parser/xfa_basic_imp.cpp b/xfa/fxfa/parser/xfa_basic_imp.cpp index 4d3b128bdb..46328607dc 100644 --- a/xfa/fxfa/parser/xfa_basic_imp.cpp +++ b/xfa/fxfa/parser/xfa_basic_imp.cpp @@ -14,7 +14,6 @@ #include "xfa/fxfa/parser/xfa_document.h" #include "xfa/fxfa/parser/xfa_localemgr.h" #include "xfa/fxfa/parser/xfa_object.h" -#include "xfa/fxfa/parser/xfa_script.h" #include "xfa/fxfa/parser/xfa_utils.h" const XFA_PACKETINFO* XFA_GetPacketByName(const CFX_WideStringC& wsName) { diff --git a/xfa/fxfa/parser/xfa_document_datamerger_imp.cpp b/xfa/fxfa/parser/xfa_document_datamerger_imp.cpp index 06bd0dc557..dad843c29b 100644 --- a/xfa/fxfa/parser/xfa_document_datamerger_imp.cpp +++ b/xfa/fxfa/parser/xfa_document_datamerger_imp.cpp @@ -9,14 +9,14 @@ #include "core/fxcrt/include/fx_ext.h" #include "xfa/fde/xml/fde_xml_imp.h" #include "xfa/fxfa/parser/cxfa_occur.h" +#include "xfa/fxfa/parser/cxfa_scriptcontext.h" #include "xfa/fxfa/parser/xfa_basic_imp.h" #include "xfa/fxfa/parser/xfa_doclayout.h" #include "xfa/fxfa/parser/xfa_document.h" #include "xfa/fxfa/parser/xfa_document_layout_imp.h" #include "xfa/fxfa/parser/xfa_localemgr.h" #include "xfa/fxfa/parser/xfa_object.h" -#include "xfa/fxfa/parser/xfa_script.h" -#include "xfa/fxfa/parser/xfa_script_imp.h" +#include "xfa/fxfa/parser/xfa_resolvenode_rs.h" #include "xfa/fxfa/parser/xfa_utils.h" namespace { diff --git a/xfa/fxfa/parser/xfa_document_imp.cpp b/xfa/fxfa/parser/xfa_document_imp.cpp index b862b59ecd..dcd98df250 100644 --- a/xfa/fxfa/parser/xfa_document_imp.cpp +++ b/xfa/fxfa/parser/xfa_document_imp.cpp @@ -13,14 +13,14 @@ #include "xfa/fxfa/parser/cscript_logpseudomodel.h" #include "xfa/fxfa/parser/cscript_signaturepseudomodel.h" #include "xfa/fxfa/parser/cxfa_document_parser.h" +#include "xfa/fxfa/parser/cxfa_scriptcontext.h" #include "xfa/fxfa/parser/xfa_basic_imp.h" #include "xfa/fxfa/parser/xfa_doclayout.h" #include "xfa/fxfa/parser/xfa_document.h" #include "xfa/fxfa/parser/xfa_document_layout_imp.h" #include "xfa/fxfa/parser/xfa_localemgr.h" #include "xfa/fxfa/parser/xfa_object.h" -#include "xfa/fxfa/parser/xfa_script.h" -#include "xfa/fxfa/parser/xfa_script_imp.h" +#include "xfa/fxfa/parser/xfa_resolvenode_rs.h" #include "xfa/fxfa/parser/xfa_utils.h" CXFA_Document::CXFA_Document(CXFA_DocumentParser* pParser) diff --git a/xfa/fxfa/parser/xfa_document_layout_imp.cpp b/xfa/fxfa/parser/xfa_document_layout_imp.cpp index 5bcc4493d5..dc3565735c 100644 --- a/xfa/fxfa/parser/xfa_document_layout_imp.cpp +++ b/xfa/fxfa/parser/xfa_document_layout_imp.cpp @@ -15,7 +15,6 @@ #include "xfa/fxfa/parser/xfa_layout_pagemgr_new.h" #include "xfa/fxfa/parser/xfa_localemgr.h" #include "xfa/fxfa/parser/xfa_object.h" -#include "xfa/fxfa/parser/xfa_script.h" #include "xfa/fxfa/parser/xfa_utils.h" CXFA_LayoutProcessor* CXFA_Document::GetLayoutProcessor() { diff --git a/xfa/fxfa/parser/xfa_document_serialize.cpp b/xfa/fxfa/parser/xfa_document_serialize.cpp index a8c4cde4ac..e6cd3e8ef7 100644 --- a/xfa/fxfa/parser/xfa_document_serialize.cpp +++ b/xfa/fxfa/parser/xfa_document_serialize.cpp @@ -13,7 +13,6 @@ #include "xfa/fxfa/parser/xfa_document.h" #include "xfa/fxfa/parser/xfa_localemgr.h" #include "xfa/fxfa/parser/xfa_object.h" -#include "xfa/fxfa/parser/xfa_script.h" #include "xfa/fxfa/parser/xfa_utils.h" CXFA_DataImporter::CXFA_DataImporter(CXFA_Document* pDocument) diff --git a/xfa/fxfa/parser/xfa_layout_appadapter.cpp b/xfa/fxfa/parser/xfa_layout_appadapter.cpp index a28987cfb8..ad6c560c1e 100644 --- a/xfa/fxfa/parser/xfa_layout_appadapter.cpp +++ b/xfa/fxfa/parser/xfa_layout_appadapter.cpp @@ -14,7 +14,6 @@ #include "xfa/fxfa/parser/xfa_layout_pagemgr_new.h" #include "xfa/fxfa/parser/xfa_localemgr.h" #include "xfa/fxfa/parser/xfa_object.h" -#include "xfa/fxfa/parser/xfa_script.h" #include "xfa/fxfa/parser/xfa_utils.h" void XFA_ReleaseLayoutItem(CXFA_LayoutItem* pLayoutItem) { diff --git a/xfa/fxfa/parser/xfa_layout_itemlayout.cpp b/xfa/fxfa/parser/xfa_layout_itemlayout.cpp index b834267f09..d56eac96fa 100644 --- a/xfa/fxfa/parser/xfa_layout_itemlayout.cpp +++ b/xfa/fxfa/parser/xfa_layout_itemlayout.cpp @@ -18,7 +18,6 @@ #include "xfa/fxfa/parser/xfa_layout_pagemgr_new.h" #include "xfa/fxfa/parser/xfa_localemgr.h" #include "xfa/fxfa/parser/xfa_object.h" -#include "xfa/fxfa/parser/xfa_script.h" #include "xfa/fxfa/parser/xfa_utils.h" namespace { diff --git a/xfa/fxfa/parser/xfa_layout_pagemgr_new.cpp b/xfa/fxfa/parser/xfa_layout_pagemgr_new.cpp index 7ddb759363..f69c832d10 100644 --- a/xfa/fxfa/parser/xfa_layout_pagemgr_new.cpp +++ b/xfa/fxfa/parser/xfa_layout_pagemgr_new.cpp @@ -7,6 +7,7 @@ #include "xfa/fxfa/parser/xfa_layout_pagemgr_new.h" #include "xfa/fxfa/app/xfa_ffnotify.h" +#include "xfa/fxfa/parser/cxfa_scriptcontext.h" #include "xfa/fxfa/parser/xfa_doclayout.h" #include "xfa/fxfa/parser/xfa_document.h" #include "xfa/fxfa/parser/xfa_document_datamerger_imp.h" @@ -15,8 +16,7 @@ #include "xfa/fxfa/parser/xfa_layout_itemlayout.h" #include "xfa/fxfa/parser/xfa_localemgr.h" #include "xfa/fxfa/parser/xfa_object.h" -#include "xfa/fxfa/parser/xfa_script.h" -#include "xfa/fxfa/parser/xfa_script_imp.h" +#include "xfa/fxfa/parser/xfa_resolvenode_rs.h" #include "xfa/fxfa/parser/xfa_utils.h" namespace { diff --git a/xfa/fxfa/parser/xfa_locale.cpp b/xfa/fxfa/parser/xfa_locale.cpp index e0e42a8d74..48492a9776 100644 --- a/xfa/fxfa/parser/xfa_locale.cpp +++ b/xfa/fxfa/parser/xfa_locale.cpp @@ -11,7 +11,6 @@ #include "xfa/fxfa/parser/xfa_document.h" #include "xfa/fxfa/parser/xfa_localemgr.h" #include "xfa/fxfa/parser/xfa_object.h" -#include "xfa/fxfa/parser/xfa_script.h" #include "xfa/fxfa/parser/xfa_utils.h" static const FX_WCHAR g_FX_Percent[] = L"z,zzz,zzz,zzz,zzz,zzz%"; diff --git a/xfa/fxfa/parser/xfa_localemgr.cpp b/xfa/fxfa/parser/xfa_localemgr.cpp index fbc3f15bc1..f19b1324d4 100644 --- a/xfa/fxfa/parser/xfa_localemgr.cpp +++ b/xfa/fxfa/parser/xfa_localemgr.cpp @@ -13,7 +13,6 @@ #include "xfa/fxfa/parser/xfa_document.h" #include "xfa/fxfa/parser/xfa_locale.h" #include "xfa/fxfa/parser/xfa_object.h" -#include "xfa/fxfa/parser/xfa_script.h" #include "xfa/fxfa/parser/xfa_utils.h" const uint8_t g_enUS_Locale[] = { diff --git a/xfa/fxfa/parser/xfa_localevalue.cpp b/xfa/fxfa/parser/xfa_localevalue.cpp index 995d021726..f5d95ad48f 100644 --- a/xfa/fxfa/parser/xfa_localevalue.cpp +++ b/xfa/fxfa/parser/xfa_localevalue.cpp @@ -12,7 +12,6 @@ #include "xfa/fxfa/parser/xfa_document.h" #include "xfa/fxfa/parser/xfa_localemgr.h" #include "xfa/fxfa/parser/xfa_object.h" -#include "xfa/fxfa/parser/xfa_script.h" #include "xfa/fxfa/parser/xfa_utils.h" static const FX_DOUBLE fraction_scales[] = {0.1, diff --git a/xfa/fxfa/parser/xfa_resolvenode_rs.h b/xfa/fxfa/parser/xfa_resolvenode_rs.h new file mode 100644 index 0000000000..809ba95ff6 --- /dev/null +++ b/xfa/fxfa/parser/xfa_resolvenode_rs.h @@ -0,0 +1,68 @@ +// Copyright 2014 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef XFA_FXFA_PARSER_XFA_RESOLVENODE_RS_H_ +#define XFA_FXFA_PARSER_XFA_RESOLVENODE_RS_H_ + +#include "fxjs/include/cfxjse_value.h" +#include "xfa/fxfa/include/fxfa.h" +#include "xfa/fxfa/parser/cxfa_valuearray.h" + +#define XFA_RESOLVENODE_Children 0x0001 +#define XFA_RESOLVENODE_Attributes 0x0004 +#define XFA_RESOLVENODE_Properties 0x0008 +#define XFA_RESOLVENODE_Siblings 0x0020 +#define XFA_RESOLVENODE_Parent 0x0040 +#define XFA_RESOLVENODE_AnyChild 0x0080 +#define XFA_RESOLVENODE_ALL 0x0100 +#define XFA_RESOLVENODE_CreateNode 0x0400 +#define XFA_RESOLVENODE_Bind 0x0800 +#define XFA_RESOLVENODE_BindNew 0x1000 + +enum XFA_SCRIPTLANGTYPE { + XFA_SCRIPTLANGTYPE_Formcalc = XFA_SCRIPTTYPE_Formcalc, + XFA_SCRIPTLANGTYPE_Javascript = XFA_SCRIPTTYPE_Javascript, + XFA_SCRIPTLANGTYPE_Unkown = XFA_SCRIPTTYPE_Unkown, +}; + +enum XFA_RESOVENODE_RSTYPE { + XFA_RESOVENODE_RSTYPE_Nodes, + XFA_RESOVENODE_RSTYPE_Attribute, + XFA_RESOLVENODE_RSTYPE_CreateNodeOne, + XFA_RESOLVENODE_RSTYPE_CreateNodeAll, + XFA_RESOLVENODE_RSTYPE_CreateNodeMidAll, + XFA_RESOVENODE_RSTYPE_ExistNodes, +}; + +struct XFA_RESOLVENODE_RS { + XFA_RESOLVENODE_RS(); + ~XFA_RESOLVENODE_RS(); + + int32_t GetAttributeResult(CXFA_ValueArray& valueArray) const { + if (pScriptAttribute && pScriptAttribute->eValueType == XFA_SCRIPT_Object) { + v8::Isolate* pIsolate = valueArray.m_pIsolate; + for (int32_t i = 0; i < nodes.GetSize(); i++) { + std::unique_ptr pValue(new CFXJSE_Value(pIsolate)); + (nodes[i]->*(pScriptAttribute->lpfnCallback))( + pValue.get(), FALSE, (XFA_ATTRIBUTE)pScriptAttribute->eAttribute); + valueArray.Add(pValue.release()); + } + } + return valueArray.GetSize(); + } + + CXFA_ObjArray nodes; + XFA_RESOVENODE_RSTYPE dwFlags; + const XFA_SCRIPTATTRIBUTEINFO* pScriptAttribute; +}; + +inline XFA_RESOLVENODE_RS::XFA_RESOLVENODE_RS() + : dwFlags(XFA_RESOVENODE_RSTYPE_Nodes), pScriptAttribute(nullptr) {} + +inline XFA_RESOLVENODE_RS::~XFA_RESOLVENODE_RS() { + nodes.RemoveAll(); +} +#endif // XFA_FXFA_PARSER_XFA_RESOLVENODE_RS_H_ diff --git a/xfa/fxfa/parser/xfa_script.h b/xfa/fxfa/parser/xfa_script.h deleted file mode 100644 index 038d2dbdd3..0000000000 --- a/xfa/fxfa/parser/xfa_script.h +++ /dev/null @@ -1,68 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef XFA_FXFA_PARSER_XFA_SCRIPT_H_ -#define XFA_FXFA_PARSER_XFA_SCRIPT_H_ - -#include "fxjs/include/cfxjse_value.h" -#include "xfa/fxfa/include/fxfa.h" -#include "xfa/fxfa/parser/cxfa_valuearray.h" - -#define XFA_RESOLVENODE_Children 0x0001 -#define XFA_RESOLVENODE_Attributes 0x0004 -#define XFA_RESOLVENODE_Properties 0x0008 -#define XFA_RESOLVENODE_Siblings 0x0020 -#define XFA_RESOLVENODE_Parent 0x0040 -#define XFA_RESOLVENODE_AnyChild 0x0080 -#define XFA_RESOLVENODE_ALL 0x0100 -#define XFA_RESOLVENODE_CreateNode 0x0400 -#define XFA_RESOLVENODE_Bind 0x0800 -#define XFA_RESOLVENODE_BindNew 0x1000 - -enum XFA_SCRIPTLANGTYPE { - XFA_SCRIPTLANGTYPE_Formcalc = XFA_SCRIPTTYPE_Formcalc, - XFA_SCRIPTLANGTYPE_Javascript = XFA_SCRIPTTYPE_Javascript, - XFA_SCRIPTLANGTYPE_Unkown = XFA_SCRIPTTYPE_Unkown, -}; - -enum XFA_RESOVENODE_RSTYPE { - XFA_RESOVENODE_RSTYPE_Nodes, - XFA_RESOVENODE_RSTYPE_Attribute, - XFA_RESOLVENODE_RSTYPE_CreateNodeOne, - XFA_RESOLVENODE_RSTYPE_CreateNodeAll, - XFA_RESOLVENODE_RSTYPE_CreateNodeMidAll, - XFA_RESOVENODE_RSTYPE_ExistNodes, -}; - -struct XFA_RESOLVENODE_RS { - XFA_RESOLVENODE_RS(); - ~XFA_RESOLVENODE_RS(); - - int32_t GetAttributeResult(CXFA_ValueArray& valueArray) const { - if (pScriptAttribute && pScriptAttribute->eValueType == XFA_SCRIPT_Object) { - v8::Isolate* pIsolate = valueArray.m_pIsolate; - for (int32_t i = 0; i < nodes.GetSize(); i++) { - std::unique_ptr pValue(new CFXJSE_Value(pIsolate)); - (nodes[i]->*(pScriptAttribute->lpfnCallback))( - pValue.get(), FALSE, (XFA_ATTRIBUTE)pScriptAttribute->eAttribute); - valueArray.Add(pValue.release()); - } - } - return valueArray.GetSize(); - } - - CXFA_ObjArray nodes; - XFA_RESOVENODE_RSTYPE dwFlags; - const XFA_SCRIPTATTRIBUTEINFO* pScriptAttribute; -}; - -inline XFA_RESOLVENODE_RS::XFA_RESOLVENODE_RS() - : dwFlags(XFA_RESOVENODE_RSTYPE_Nodes), pScriptAttribute(nullptr) {} - -inline XFA_RESOLVENODE_RS::~XFA_RESOLVENODE_RS() { - nodes.RemoveAll(); -} -#endif // XFA_FXFA_PARSER_XFA_SCRIPT_H_ diff --git a/xfa/fxfa/parser/xfa_script_imp.cpp b/xfa/fxfa/parser/xfa_script_imp.cpp deleted file mode 100644 index e426c1ecf7..0000000000 --- a/xfa/fxfa/parser/xfa_script_imp.cpp +++ /dev/null @@ -1,739 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "xfa/fxfa/parser/xfa_script_imp.h" - -#include "core/fxcrt/include/fx_ext.h" -#include "fxjs/include/cfxjse_arguments.h" -#include "fxjs/include/cfxjse_class.h" -#include "fxjs/include/cfxjse_value.h" -#include "xfa/fxfa/app/xfa_ffnotify.h" -#include "xfa/fxfa/include/cxfa_eventparam.h" -#include "xfa/fxfa/parser/xfa_doclayout.h" -#include "xfa/fxfa/parser/xfa_document.h" -#include "xfa/fxfa/parser/xfa_localemgr.h" -#include "xfa/fxfa/parser/xfa_object.h" -#include "xfa/fxfa/parser/xfa_script.h" -#include "xfa/fxfa/parser/xfa_script_nodehelper.h" -#include "xfa/fxfa/parser/xfa_script_resolveprocessor.h" -#include "xfa/fxfa/parser/xfa_utils.h" - -namespace { - -const FXJSE_CLASS_DESCRIPTOR GlobalClassDescriptor = { - "Root", // name - nullptr, // constructor - nullptr, // properties - nullptr, // methods - 0, // property count - 0, // method count - CXFA_ScriptContext::GlobalPropTypeGetter, - CXFA_ScriptContext::GlobalPropertyGetter, - CXFA_ScriptContext::GlobalPropertySetter, - nullptr, // property deleter - CXFA_ScriptContext::NormalMethodCall, -}; - -const FXJSE_CLASS_DESCRIPTOR NormalClassDescriptor = { - "XFAObject", // name - nullptr, // constructor - nullptr, // properties - nullptr, // methods - 0, // property count - 0, // method count - CXFA_ScriptContext::NormalPropTypeGetter, - CXFA_ScriptContext::NormalPropertyGetter, - CXFA_ScriptContext::NormalPropertySetter, - nullptr, // property deleter - CXFA_ScriptContext::NormalMethodCall, -}; - -const FXJSE_CLASS_DESCRIPTOR VariablesClassDescriptor = { - "XFAScriptObject", // name - nullptr, // constructor - nullptr, // properties - nullptr, // methods - 0, // property count - 0, // method count - CXFA_ScriptContext::NormalPropTypeGetter, - CXFA_ScriptContext::GlobalPropertyGetter, - CXFA_ScriptContext::GlobalPropertySetter, - nullptr, // property deleter - CXFA_ScriptContext::NormalMethodCall, -}; - -const char kFormCalcRuntime[] = "foxit_xfa_formcalc_runtime"; - -CXFA_ThisProxy* ToThisProxy(CFXJSE_Value* pValue, CFXJSE_Class* pClass) { - return static_cast(pValue->ToHostObject(pClass)); -} - -} // namespace - -// static. -CXFA_Object* CXFA_ScriptContext::ToObject(CFXJSE_Value* pValue, - CFXJSE_Class* pClass) { - return static_cast(pValue->ToHostObject(pClass)); -} - -CXFA_ScriptContext::CXFA_ScriptContext(CXFA_Document* pDocument) - : m_pDocument(pDocument), - m_pIsolate(nullptr), - m_pJsClass(nullptr), - m_eScriptType(XFA_SCRIPTLANGTYPE_Unkown), - m_pScriptNodeArray(nullptr), - m_pThisObject(nullptr), - m_dwBuiltInInFlags(0), - m_eRunAtType(XFA_ATTRIBUTEENUM_Client) {} - -CXFA_ScriptContext::~CXFA_ScriptContext() { - FX_POSITION ps = m_mapVariableToContext.GetStartPosition(); - while (ps) { - CXFA_Object* pScriptNode; - CFXJSE_Context* pVariableContext = nullptr; - m_mapVariableToContext.GetNextAssoc(ps, pScriptNode, pVariableContext); - - delete ToThisProxy(pVariableContext->GetGlobalObject().get(), nullptr); - delete pVariableContext; - } - m_mapVariableToContext.RemoveAll(); - - m_upObjectArray.RemoveAll(); -} -void CXFA_ScriptContext::Initialize(v8::Isolate* pIsolate) { - m_pIsolate = pIsolate; - DefineJsContext(); - DefineJsClass(); - m_ResolveProcessor.reset(new CXFA_ResolveProcessor); -} -FX_BOOL CXFA_ScriptContext::RunScript(XFA_SCRIPTLANGTYPE eScriptType, - const CFX_WideStringC& wsScript, - CFXJSE_Value* hRetValue, - CXFA_Object* pThisObject) { - CFX_ByteString btScript; - XFA_SCRIPTLANGTYPE eSaveType = m_eScriptType; - m_eScriptType = eScriptType; - if (eScriptType == XFA_SCRIPTLANGTYPE_Formcalc) { - if (!m_FM2JSContext) { - m_FM2JSContext.reset( - new CXFA_FM2JSContext(m_pIsolate, m_JsContext.get(), m_pDocument)); - } - CFX_WideTextBuf wsJavaScript; - CFX_WideString wsErrorInfo; - int32_t iFlags = - CXFA_FM2JSContext::Translate(wsScript, wsJavaScript, wsErrorInfo); - if (iFlags) { - hRetValue->SetUndefined(); - return FALSE; - } - btScript = - FX_UTF8Encode(wsJavaScript.GetBuffer(), wsJavaScript.GetLength()); - } else { - btScript = FX_UTF8Encode(wsScript.c_str(), wsScript.GetLength()); - } - CXFA_Object* pOriginalObject = m_pThisObject; - m_pThisObject = pThisObject; - CFXJSE_Value* pValue = pThisObject ? GetJSValueFromMap(pThisObject) : nullptr; - FX_BOOL bRet = - m_JsContext->ExecuteScript(btScript.c_str(), hRetValue, pValue); - m_pThisObject = pOriginalObject; - m_eScriptType = eSaveType; - return bRet; -} -void CXFA_ScriptContext::GlobalPropertySetter(CFXJSE_Value* pObject, - const CFX_ByteStringC& szPropName, - CFXJSE_Value* pValue) { - CXFA_Object* lpOrginalNode = ToObject(pObject, nullptr); - CXFA_Document* pDoc = lpOrginalNode->GetDocument(); - CXFA_ScriptContext* lpScriptContext = pDoc->GetScriptContext(); - CXFA_Object* lpCurNode = lpScriptContext->GetVariablesThis(lpOrginalNode); - CFX_WideString wsPropName = CFX_WideString::FromUTF8(szPropName); - uint32_t dwFlag = XFA_RESOLVENODE_Parent | XFA_RESOLVENODE_Siblings | - XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Properties | - XFA_RESOLVENODE_Attributes; - CXFA_Node* pRefNode = ToNode(lpScriptContext->GetThisObject()); - if (lpOrginalNode->IsVariablesThis()) - pRefNode = ToNode(lpCurNode); - if (lpScriptContext->QueryNodeByFlag(pRefNode, wsPropName.AsStringC(), pValue, - dwFlag, TRUE)) { - return; - } - if (lpOrginalNode->IsVariablesThis()) { - if (pValue && pValue->IsUndefined()) { - pObject->SetObjectOwnProperty(szPropName, pValue); - return; - } - } - CXFA_FFNotify* pNotify = pDoc->GetNotify(); - if (!pNotify) { - return; - } - pNotify->GetDocProvider()->SetGlobalProperty(pNotify->GetHDOC(), szPropName, - pValue); -} -FX_BOOL CXFA_ScriptContext::QueryNodeByFlag(CXFA_Node* refNode, - const CFX_WideStringC& propname, - CFXJSE_Value* pValue, - uint32_t dwFlag, - FX_BOOL bSetting) { - if (!refNode) - return false; - XFA_RESOLVENODE_RS resolveRs; - if (ResolveObjects(refNode, propname, resolveRs, dwFlag) <= 0) - return false; - if (resolveRs.dwFlags == XFA_RESOVENODE_RSTYPE_Nodes) { - pValue->Assign(GetJSValueFromMap(resolveRs.nodes[0])); - return true; - } - if (resolveRs.dwFlags == XFA_RESOVENODE_RSTYPE_Attribute) { - const XFA_SCRIPTATTRIBUTEINFO* lpAttributeInfo = resolveRs.pScriptAttribute; - if (lpAttributeInfo) { - (resolveRs.nodes[0]->*(lpAttributeInfo->lpfnCallback))( - pValue, bSetting, (XFA_ATTRIBUTE)lpAttributeInfo->eAttribute); - } - } - return true; -} -void CXFA_ScriptContext::GlobalPropertyGetter(CFXJSE_Value* pObject, - const CFX_ByteStringC& szPropName, - CFXJSE_Value* pValue) { - CXFA_Object* pOriginalObject = ToObject(pObject, nullptr); - CXFA_Document* pDoc = pOriginalObject->GetDocument(); - CXFA_ScriptContext* lpScriptContext = pDoc->GetScriptContext(); - CXFA_Object* lpCurNode = lpScriptContext->GetVariablesThis(pOriginalObject); - CFX_WideString wsPropName = CFX_WideString::FromUTF8(szPropName); - if (lpScriptContext->GetType() == XFA_SCRIPTLANGTYPE_Formcalc) { - if (szPropName == kFormCalcRuntime) { - lpScriptContext->m_FM2JSContext->GlobalPropertyGetter(pValue); - return; - } - XFA_HashCode uHashCode = static_cast( - FX_HashCode_GetW(wsPropName.AsStringC(), false)); - if (uHashCode != XFA_HASHCODE_Layout) { - CXFA_Object* pObj = - lpScriptContext->GetDocument()->GetXFAObject(uHashCode); - if (pObj) { - pValue->Assign(lpScriptContext->GetJSValueFromMap(pObj)); - return; - } - } - } - uint32_t dwFlag = XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Properties | - XFA_RESOLVENODE_Attributes; - CXFA_Node* pRefNode = ToNode(lpScriptContext->GetThisObject()); - if (pOriginalObject->IsVariablesThis()) { - pRefNode = ToNode(lpCurNode); - } - if (lpScriptContext->QueryNodeByFlag(pRefNode, wsPropName.AsStringC(), pValue, - dwFlag, FALSE)) { - return; - } - dwFlag = XFA_RESOLVENODE_Parent | XFA_RESOLVENODE_Siblings; - if (lpScriptContext->QueryNodeByFlag(pRefNode, wsPropName.AsStringC(), pValue, - dwFlag, FALSE)) { - return; - } - CXFA_Object* pScriptObject = - lpScriptContext->GetVariablesThis(pOriginalObject, TRUE); - if (pScriptObject && - lpScriptContext->QueryVariableValue(pScriptObject->AsNode(), szPropName, - pValue, TRUE)) { - return; - } - CXFA_FFNotify* pNotify = pDoc->GetNotify(); - if (!pNotify) { - return; - } - pNotify->GetDocProvider()->GetGlobalProperty(pNotify->GetHDOC(), szPropName, - pValue); -} -void CXFA_ScriptContext::NormalPropertyGetter(CFXJSE_Value* pOriginalValue, - const CFX_ByteStringC& szPropName, - CFXJSE_Value* pReturnValue) { - CXFA_Object* pOriginalObject = ToObject(pOriginalValue, nullptr); - if (!pOriginalObject) { - pReturnValue->SetUndefined(); - return; - } - CFX_WideString wsPropName = CFX_WideString::FromUTF8(szPropName); - CXFA_ScriptContext* lpScriptContext = - pOriginalObject->GetDocument()->GetScriptContext(); - CXFA_Object* pObject = lpScriptContext->GetVariablesThis(pOriginalObject); - if (wsPropName == FX_WSTRC(L"xfa")) { - CFXJSE_Value* pValue = lpScriptContext->GetJSValueFromMap( - lpScriptContext->GetDocument()->GetRoot()); - pReturnValue->Assign(pValue); - return; - } - uint32_t dwFlag = XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Properties | - XFA_RESOLVENODE_Attributes; - FX_BOOL bRet = lpScriptContext->QueryNodeByFlag( - ToNode(pObject), wsPropName.AsStringC(), pReturnValue, dwFlag, FALSE); - if (bRet) { - return; - } - if (pObject == lpScriptContext->GetThisObject() || - (lpScriptContext->GetType() == XFA_SCRIPTLANGTYPE_Javascript && - !lpScriptContext->IsStrictScopeInJavaScript())) { - dwFlag = XFA_RESOLVENODE_Parent | XFA_RESOLVENODE_Siblings; - bRet = lpScriptContext->QueryNodeByFlag( - ToNode(pObject), wsPropName.AsStringC(), pReturnValue, dwFlag, FALSE); - } - if (bRet) { - return; - } - CXFA_Object* pScriptObject = - lpScriptContext->GetVariablesThis(pOriginalObject, TRUE); - if (pScriptObject) { - bRet = lpScriptContext->QueryVariableValue(ToNode(pScriptObject), - szPropName, pReturnValue, TRUE); - } - if (!bRet) { - pReturnValue->SetUndefined(); - } -} -void CXFA_ScriptContext::NormalPropertySetter(CFXJSE_Value* pOriginalValue, - const CFX_ByteStringC& szPropName, - CFXJSE_Value* pReturnValue) { - CXFA_Object* pOriginalObject = ToObject(pOriginalValue, nullptr); - if (!pOriginalObject) - return; - - CXFA_ScriptContext* lpScriptContext = - pOriginalObject->GetDocument()->GetScriptContext(); - CXFA_Object* pObject = lpScriptContext->GetVariablesThis(pOriginalObject); - CFX_WideString wsPropName = CFX_WideString::FromUTF8(szPropName); - const XFA_SCRIPTATTRIBUTEINFO* lpAttributeInfo = XFA_GetScriptAttributeByName( - pObject->GetElementType(), wsPropName.AsStringC()); - if (lpAttributeInfo) { - (pObject->*(lpAttributeInfo->lpfnCallback))( - pReturnValue, TRUE, (XFA_ATTRIBUTE)lpAttributeInfo->eAttribute); - } else { - if (pObject->IsNode()) { - if (wsPropName.GetAt(0) == '#') { - wsPropName = wsPropName.Right(wsPropName.GetLength() - 1); - } - CXFA_Node* pNode = ToNode(pObject); - CXFA_Node* pPropOrChild = nullptr; - XFA_Element eType = XFA_GetElementTypeForName(wsPropName.AsStringC()); - if (eType != XFA_Element::Unknown) - pPropOrChild = pNode->GetProperty(0, eType); - else - pPropOrChild = pNode->GetFirstChildByName(wsPropName.AsStringC()); - - if (pPropOrChild) { - CFX_WideString wsDefaultName(L"{default}"); - const XFA_SCRIPTATTRIBUTEINFO* lpAttrInfo = - XFA_GetScriptAttributeByName(pPropOrChild->GetElementType(), - wsDefaultName.AsStringC()); - if (lpAttrInfo) { - (pPropOrChild->*(lpAttrInfo->lpfnCallback))( - pReturnValue, TRUE, (XFA_ATTRIBUTE)lpAttrInfo->eAttribute); - return; - } - } - } - CXFA_Object* pScriptObject = - lpScriptContext->GetVariablesThis(pOriginalObject, TRUE); - if (pScriptObject) { - lpScriptContext->QueryVariableValue(ToNode(pScriptObject), szPropName, - pReturnValue, FALSE); - } - } -} -int32_t CXFA_ScriptContext::NormalPropTypeGetter( - CFXJSE_Value* pOriginalValue, - const CFX_ByteStringC& szPropName, - FX_BOOL bQueryIn) { - CXFA_Object* pObject = ToObject(pOriginalValue, nullptr); - if (!pObject) - return FXJSE_ClassPropType_None; - - CXFA_ScriptContext* lpScriptContext = - pObject->GetDocument()->GetScriptContext(); - pObject = lpScriptContext->GetVariablesThis(pObject); - XFA_Element eType = pObject->GetElementType(); - CFX_WideString wsPropName = CFX_WideString::FromUTF8(szPropName); - if (XFA_GetMethodByName(eType, wsPropName.AsStringC())) { - return FXJSE_ClassPropType_Method; - } - if (bQueryIn && - !XFA_GetScriptAttributeByName(eType, wsPropName.AsStringC())) { - return FXJSE_ClassPropType_None; - } - return FXJSE_ClassPropType_Property; -} -int32_t CXFA_ScriptContext::GlobalPropTypeGetter( - CFXJSE_Value* pOriginalValue, - const CFX_ByteStringC& szPropName, - FX_BOOL bQueryIn) { - CXFA_Object* pObject = ToObject(pOriginalValue, nullptr); - if (!pObject) - return FXJSE_ClassPropType_None; - - CXFA_ScriptContext* lpScriptContext = - pObject->GetDocument()->GetScriptContext(); - pObject = lpScriptContext->GetVariablesThis(pObject); - XFA_Element eType = pObject->GetElementType(); - CFX_WideString wsPropName = CFX_WideString::FromUTF8(szPropName); - if (XFA_GetMethodByName(eType, wsPropName.AsStringC())) { - return FXJSE_ClassPropType_Method; - } - return FXJSE_ClassPropType_Property; -} -void CXFA_ScriptContext::NormalMethodCall(CFXJSE_Value* pThis, - const CFX_ByteStringC& szFuncName, - CFXJSE_Arguments& args) { - CXFA_Object* pObject = ToObject(pThis, nullptr); - if (!pObject) - return; - - CXFA_ScriptContext* lpScriptContext = - pObject->GetDocument()->GetScriptContext(); - pObject = lpScriptContext->GetVariablesThis(pObject); - CFX_WideString wsFunName = CFX_WideString::FromUTF8(szFuncName); - const XFA_METHODINFO* lpMethodInfo = - XFA_GetMethodByName(pObject->GetElementType(), wsFunName.AsStringC()); - if (!lpMethodInfo) - return; - - (pObject->*(lpMethodInfo->lpfnCallback))(&args); -} -FX_BOOL CXFA_ScriptContext::IsStrictScopeInJavaScript() { - return m_pDocument->HasFlag(XFA_DOCFLAG_StrictScoping); -} -XFA_SCRIPTLANGTYPE CXFA_ScriptContext::GetType() { - return m_eScriptType; -} -void CXFA_ScriptContext::DefineJsContext() { - m_JsContext.reset(CFXJSE_Context::Create(m_pIsolate, &GlobalClassDescriptor, - m_pDocument->GetRoot())); - RemoveBuiltInObjs(m_JsContext.get()); - m_JsContext->EnableCompatibleMode(); -} -CFXJSE_Context* CXFA_ScriptContext::CreateVariablesContext( - CXFA_Node* pScriptNode, - CXFA_Node* pSubform) { - if (!pScriptNode || !pSubform) - return nullptr; - - CFXJSE_Context* pVariablesContext = - CFXJSE_Context::Create(m_pIsolate, &VariablesClassDescriptor, - new CXFA_ThisProxy(pSubform, pScriptNode)); - RemoveBuiltInObjs(pVariablesContext); - pVariablesContext->EnableCompatibleMode(); - m_mapVariableToContext.SetAt(pScriptNode, pVariablesContext); - return pVariablesContext; -} -CXFA_Object* CXFA_ScriptContext::GetVariablesThis(CXFA_Object* pObject, - FX_BOOL bScriptNode) { - if (!pObject->IsVariablesThis()) - return pObject; - - CXFA_ThisProxy* pProxy = static_cast(pObject); - return bScriptNode ? pProxy->GetScriptNode() : pProxy->GetThisNode(); -} - -FX_BOOL CXFA_ScriptContext::RunVariablesScript(CXFA_Node* pScriptNode) { - if (!pScriptNode) - return FALSE; - - if (pScriptNode->GetElementType() != XFA_Element::Script) - return TRUE; - - CXFA_Node* pParent = pScriptNode->GetNodeItem(XFA_NODEITEM_Parent); - if (!pParent || pParent->GetElementType() != XFA_Element::Variables) - return FALSE; - - if (m_mapVariableToContext.GetValueAt(pScriptNode)) - return TRUE; - - CXFA_Node* pTextNode = pScriptNode->GetNodeItem(XFA_NODEITEM_FirstChild); - if (!pTextNode) - return FALSE; - - CFX_WideStringC wsScript; - if (!pTextNode->TryCData(XFA_ATTRIBUTE_Value, wsScript)) - return FALSE; - - CFX_ByteString btScript = - FX_UTF8Encode(wsScript.c_str(), wsScript.GetLength()); - std::unique_ptr hRetValue(new CFXJSE_Value(m_pIsolate)); - CXFA_Node* pThisObject = pParent->GetNodeItem(XFA_NODEITEM_Parent); - CFXJSE_Context* pVariablesContext = - CreateVariablesContext(pScriptNode, pThisObject); - CXFA_Object* pOriginalObject = m_pThisObject; - m_pThisObject = pThisObject; - FX_BOOL bRet = - pVariablesContext->ExecuteScript(btScript.c_str(), hRetValue.get()); - m_pThisObject = pOriginalObject; - return bRet; -} - -FX_BOOL CXFA_ScriptContext::QueryVariableValue( - CXFA_Node* pScriptNode, - const CFX_ByteStringC& szPropName, - CFXJSE_Value* pValue, - FX_BOOL bGetter) { - if (!pScriptNode || pScriptNode->GetElementType() != XFA_Element::Script) - return FALSE; - - CXFA_Node* variablesNode = pScriptNode->GetNodeItem(XFA_NODEITEM_Parent); - if (!variablesNode || - variablesNode->GetElementType() != XFA_Element::Variables) - return FALSE; - - void* lpVariables = m_mapVariableToContext.GetValueAt(pScriptNode); - if (!lpVariables) - return FALSE; - - FX_BOOL bRes = FALSE; - CFXJSE_Context* pVariableContext = static_cast(lpVariables); - std::unique_ptr pObject = pVariableContext->GetGlobalObject(); - std::unique_ptr hVariableValue(new CFXJSE_Value(m_pIsolate)); - if (!bGetter) { - pObject->SetObjectOwnProperty(szPropName, pValue); - bRes = TRUE; - } else if (pObject->HasObjectOwnProperty(szPropName, FALSE)) { - pObject->GetObjectProperty(szPropName, hVariableValue.get()); - if (hVariableValue->IsFunction()) - pValue->SetFunctionBind(hVariableValue.get(), pObject.get()); - else if (bGetter) - pValue->Assign(hVariableValue.get()); - else - hVariableValue.get()->Assign(pValue); - bRes = TRUE; - } - return bRes; -} - -void CXFA_ScriptContext::DefineJsClass() { - m_pJsClass = CFXJSE_Class::Create(m_JsContext.get(), &NormalClassDescriptor); -} - -void CXFA_ScriptContext::RemoveBuiltInObjs(CFXJSE_Context* pContext) const { - static const CFX_ByteStringC OBJ_NAME[2] = {"Number", "Date"}; - std::unique_ptr pObject = pContext->GetGlobalObject(); - std::unique_ptr hProp(new CFXJSE_Value(m_pIsolate)); - for (int i = 0; i < 2; ++i) { - if (pObject->GetObjectProperty(OBJ_NAME[i], hProp.get())) - pObject->DeleteObjectProperty(OBJ_NAME[i]); - } -} -CFXJSE_Class* CXFA_ScriptContext::GetJseNormalClass() { - return m_pJsClass; -} -int32_t CXFA_ScriptContext::ResolveObjects(CXFA_Object* refNode, - const CFX_WideStringC& wsExpression, - XFA_RESOLVENODE_RS& resolveNodeRS, - uint32_t dwStyles, - CXFA_Node* bindNode) { - if (wsExpression.IsEmpty()) { - return 0; - } - if (m_eScriptType != XFA_SCRIPTLANGTYPE_Formcalc || - (dwStyles & (XFA_RESOLVENODE_Parent | XFA_RESOLVENODE_Siblings))) { - m_upObjectArray.RemoveAll(); - } - if (refNode && refNode->IsNode() && - (dwStyles & (XFA_RESOLVENODE_Parent | XFA_RESOLVENODE_Siblings))) { - m_upObjectArray.Add(refNode->AsNode()); - } - FX_BOOL bNextCreate = FALSE; - if (dwStyles & XFA_RESOLVENODE_CreateNode) { - m_ResolveProcessor->GetNodeHelper()->SetCreateNodeType(bindNode); - } - m_ResolveProcessor->GetNodeHelper()->m_pCreateParent = nullptr; - m_ResolveProcessor->GetNodeHelper()->m_iCurAllStart = -1; - CXFA_ResolveNodesData rndFind; - int32_t nStart = 0; - int32_t nLevel = 0; - int32_t nRet = -1; - rndFind.m_pSC = this; - CXFA_ObjArray findNodes; - findNodes.Add(refNode ? refNode : m_pDocument->GetRoot()); - int32_t nNodes = 0; - while (TRUE) { - nNodes = findNodes.GetSize(); - int32_t i = 0; - rndFind.m_dwStyles = dwStyles; - m_ResolveProcessor->SetCurStart(nStart); - nStart = m_ResolveProcessor->GetFilter(wsExpression, nStart, rndFind); - if (nStart < 1) { - if ((dwStyles & XFA_RESOLVENODE_CreateNode) && !bNextCreate) { - CXFA_Node* pDataNode = nullptr; - nStart = m_ResolveProcessor->GetNodeHelper()->m_iCurAllStart; - if (nStart != -1) { - pDataNode = m_pDocument->GetNotBindNode(findNodes); - if (pDataNode) { - findNodes.RemoveAll(); - findNodes.Add(pDataNode); - break; - } - } else { - pDataNode = findNodes[0]->AsNode(); - findNodes.RemoveAll(); - findNodes.Add(pDataNode); - break; - } - dwStyles |= XFA_RESOLVENODE_Bind; - findNodes.RemoveAll(); - findNodes.Add(m_ResolveProcessor->GetNodeHelper()->m_pAllStartParent); - continue; - } else { - break; - } - } - if (bNextCreate) { - FX_BOOL bCreate = - m_ResolveProcessor->GetNodeHelper()->ResolveNodes_CreateNode( - rndFind.m_wsName, rndFind.m_wsCondition, - nStart == wsExpression.GetLength(), this); - if (bCreate) { - continue; - } else { - break; - } - } - CXFA_ObjArray retNodes; - while (i < nNodes) { - FX_BOOL bDataBind = FALSE; - if (((dwStyles & XFA_RESOLVENODE_Bind) || - (dwStyles & XFA_RESOLVENODE_CreateNode)) && - nNodes > 1) { - CXFA_ResolveNodesData rndBind; - m_ResolveProcessor->GetFilter(wsExpression, nStart, rndBind); - m_ResolveProcessor->SetIndexDataBind(rndBind.m_wsCondition, i, nNodes); - bDataBind = TRUE; - } - rndFind.m_CurNode = findNodes[i++]; - rndFind.m_nLevel = nLevel; - rndFind.m_dwFlag = XFA_RESOVENODE_RSTYPE_Nodes; - nRet = m_ResolveProcessor->Resolve(rndFind); - if (nRet < 1) { - continue; - } - if (rndFind.m_dwFlag == XFA_RESOVENODE_RSTYPE_Attribute && - rndFind.m_pScriptAttribute && nStart < wsExpression.GetLength()) { - std::unique_ptr pValue(new CFXJSE_Value(m_pIsolate)); - (rndFind.m_Nodes[0]->*(rndFind.m_pScriptAttribute->lpfnCallback))( - pValue.get(), FALSE, - (XFA_ATTRIBUTE)rndFind.m_pScriptAttribute->eAttribute); - rndFind.m_Nodes.SetAt(0, ToObject(pValue.get(), nullptr)); - } - int32_t iSize = m_upObjectArray.GetSize(); - if (iSize) { - m_upObjectArray.RemoveAt(iSize - 1); - } - retNodes.Append(rndFind.m_Nodes); - rndFind.m_Nodes.RemoveAll(); - if (bDataBind) { - break; - } - } - findNodes.RemoveAll(); - nNodes = retNodes.GetSize(); - if (nNodes < 1) { - if (dwStyles & XFA_RESOLVENODE_CreateNode) { - bNextCreate = TRUE; - if (!m_ResolveProcessor->GetNodeHelper()->m_pCreateParent) { - m_ResolveProcessor->GetNodeHelper()->m_pCreateParent = - ToNode(rndFind.m_CurNode); - m_ResolveProcessor->GetNodeHelper()->m_iCreateCount = 1; - } - FX_BOOL bCreate = - m_ResolveProcessor->GetNodeHelper()->ResolveNodes_CreateNode( - rndFind.m_wsName, rndFind.m_wsCondition, - nStart == wsExpression.GetLength(), this); - if (bCreate) { - continue; - } else { - break; - } - } else { - break; - } - } - findNodes.Copy(retNodes); - rndFind.m_Nodes.RemoveAll(); - if (nLevel == 0) { - dwStyles &= ~(XFA_RESOLVENODE_Parent | XFA_RESOLVENODE_Siblings); - } - nLevel++; - } - if (!bNextCreate) { - resolveNodeRS.dwFlags = rndFind.m_dwFlag; - if (nNodes > 0) { - resolveNodeRS.nodes.Append(findNodes); - } - if (rndFind.m_dwFlag == XFA_RESOVENODE_RSTYPE_Attribute) { - resolveNodeRS.pScriptAttribute = rndFind.m_pScriptAttribute; - return 1; - } - } - if (dwStyles & (XFA_RESOLVENODE_CreateNode | XFA_RESOLVENODE_Bind | - XFA_RESOLVENODE_BindNew)) { - m_ResolveProcessor->SetResultCreateNode(resolveNodeRS, - rndFind.m_wsCondition); - if (!bNextCreate && (dwStyles & XFA_RESOLVENODE_CreateNode)) { - resolveNodeRS.dwFlags = XFA_RESOVENODE_RSTYPE_ExistNodes; - } - return resolveNodeRS.nodes.GetSize(); - } - return nNodes; -} - -void CXFA_ScriptContext::AddToCacheList(std::unique_ptr pList) { - m_CacheList.push_back(std::move(pList)); -} - -CFXJSE_Value* CXFA_ScriptContext::GetJSValueFromMap(CXFA_Object* pObject) { - if (!pObject) - return nullptr; - if (pObject->IsNode()) - RunVariablesScript(pObject->AsNode()); - - auto iter = m_mapObjectToValue.find(pObject); - if (iter != m_mapObjectToValue.end()) - return iter->second.get(); - - std::unique_ptr jsValue(new CFXJSE_Value(m_pIsolate)); - jsValue->SetObject(pObject, m_pJsClass); - CFXJSE_Value* pValue = jsValue.get(); - m_mapObjectToValue.insert(std::make_pair(pObject, std::move(jsValue))); - return pValue; -} -int32_t CXFA_ScriptContext::GetIndexByName(CXFA_Node* refNode) { - CXFA_NodeHelper* lpNodeHelper = m_ResolveProcessor->GetNodeHelper(); - return lpNodeHelper->GetIndex(refNode, XFA_LOGIC_Transparent, - lpNodeHelper->NodeIsProperty(refNode), FALSE); -} -int32_t CXFA_ScriptContext::GetIndexByClassName(CXFA_Node* refNode) { - CXFA_NodeHelper* lpNodeHelper = m_ResolveProcessor->GetNodeHelper(); - return lpNodeHelper->GetIndex(refNode, XFA_LOGIC_Transparent, - lpNodeHelper->NodeIsProperty(refNode), TRUE); -} -void CXFA_ScriptContext::GetSomExpression(CXFA_Node* refNode, - CFX_WideString& wsExpression) { - CXFA_NodeHelper* lpNodeHelper = m_ResolveProcessor->GetNodeHelper(); - lpNodeHelper->GetNameExpression(refNode, wsExpression, TRUE, - XFA_LOGIC_Transparent); -} -void CXFA_ScriptContext::SetNodesOfRunScript(CXFA_NodeArray* pArray) { - m_pScriptNodeArray = pArray; -} -void CXFA_ScriptContext::AddNodesOfRunScript(const CXFA_NodeArray& nodes) { - if (!m_pScriptNodeArray) - return; - if (nodes.GetSize() > 0) - m_pScriptNodeArray->Copy(nodes); -} -void CXFA_ScriptContext::AddNodesOfRunScript(CXFA_Node* pNode) { - if (!m_pScriptNodeArray) - return; - if (m_pScriptNodeArray->Find(pNode) == -1) - m_pScriptNodeArray->Add(pNode); -} diff --git a/xfa/fxfa/parser/xfa_script_imp.h b/xfa/fxfa/parser/xfa_script_imp.h deleted file mode 100644 index 5356679636..0000000000 --- a/xfa/fxfa/parser/xfa_script_imp.h +++ /dev/null @@ -1,126 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef XFA_FXFA_PARSER_XFA_SCRIPT_IMP_H_ -#define XFA_FXFA_PARSER_XFA_SCRIPT_IMP_H_ - -#include -#include -#include - -#include "fxjs/include/cfxjse_arguments.h" -#include "xfa/fxfa/fm2js/xfa_fm2jscontext.h" -#include "xfa/fxfa/include/cxfa_eventparam.h" -#include "xfa/fxfa/parser/xfa_document.h" -#include "xfa/fxfa/parser/xfa_script.h" - -#define XFA_RESOLVENODE_TagName 0x0002 - -class CXFA_ResolveProcessor; - -class CXFA_ScriptContext { - public: - explicit CXFA_ScriptContext(CXFA_Document* pDocument); - ~CXFA_ScriptContext(); - - void Initialize(v8::Isolate* pIsolate); - void SetEventParam(CXFA_EventParam param) { m_eventParam = param; } - CXFA_EventParam* GetEventParam() { return &m_eventParam; } - FX_BOOL RunScript(XFA_SCRIPTLANGTYPE eScriptType, - const CFX_WideStringC& wsScript, - CFXJSE_Value* pRetValue, - CXFA_Object* pThisObject = nullptr); - - int32_t ResolveObjects(CXFA_Object* refNode, - const CFX_WideStringC& wsExpression, - XFA_RESOLVENODE_RS& resolveNodeRS, - uint32_t dwStyles = XFA_RESOLVENODE_Children, - CXFA_Node* bindNode = nullptr); - CFXJSE_Value* GetJSValueFromMap(CXFA_Object* pObject); - void AddToCacheList(std::unique_ptr pList); - CXFA_Object* GetThisObject() const { return m_pThisObject; } - v8::Isolate* GetRuntime() const { return m_pIsolate; } - - int32_t GetIndexByName(CXFA_Node* refNode); - int32_t GetIndexByClassName(CXFA_Node* refNode); - void GetSomExpression(CXFA_Node* refNode, CFX_WideString& wsExpression); - - void SetNodesOfRunScript(CXFA_NodeArray* pArray); - void AddNodesOfRunScript(const CXFA_NodeArray& nodes); - void AddNodesOfRunScript(CXFA_Node* pNode); - CFXJSE_Class* GetJseNormalClass(); - - void SetRunAtType(XFA_ATTRIBUTEENUM eRunAt) { m_eRunAtType = eRunAt; } - FX_BOOL IsRunAtClient() { return m_eRunAtType != XFA_ATTRIBUTEENUM_Server; } - FX_BOOL QueryNodeByFlag(CXFA_Node* refNode, - const CFX_WideStringC& propname, - CFXJSE_Value* pValue, - uint32_t dwFlag, - FX_BOOL bSetting); - FX_BOOL QueryVariableValue(CXFA_Node* pScriptNode, - const CFX_ByteStringC& szPropName, - CFXJSE_Value* pValue, - FX_BOOL bGetter); - FX_BOOL QueryBuiltinValue(const CFX_ByteStringC& szPropName, - CFXJSE_Value* pValue); - static void GlobalPropertyGetter(CFXJSE_Value* pObject, - const CFX_ByteStringC& szPropName, - CFXJSE_Value* pValue); - static void GlobalPropertySetter(CFXJSE_Value* pObject, - const CFX_ByteStringC& szPropName, - CFXJSE_Value* pValue); - static void NormalPropertyGetter(CFXJSE_Value* pObject, - const CFX_ByteStringC& szPropName, - CFXJSE_Value* pValue); - static void NormalPropertySetter(CFXJSE_Value* pObject, - const CFX_ByteStringC& szPropName, - CFXJSE_Value* pValue); - static void NormalMethodCall(CFXJSE_Value* hThis, - const CFX_ByteStringC& szFuncName, - CFXJSE_Arguments& args); - static int32_t NormalPropTypeGetter(CFXJSE_Value* pObject, - const CFX_ByteStringC& szPropName, - FX_BOOL bQueryIn); - static int32_t GlobalPropTypeGetter(CFXJSE_Value* pObject, - const CFX_ByteStringC& szPropName, - FX_BOOL bQueryIn); - FX_BOOL RunVariablesScript(CXFA_Node* pScriptNode); - CXFA_Object* GetVariablesThis(CXFA_Object* pObject, - FX_BOOL bScriptNode = FALSE); - FX_BOOL IsStrictScopeInJavaScript(); - XFA_SCRIPTLANGTYPE GetType(); - CXFA_NodeArray& GetUpObjectArray() { return m_upObjectArray; } - CXFA_Document* GetDocument() const { return m_pDocument; } - - static CXFA_Object* ToObject(CFXJSE_Value* pValue, CFXJSE_Class* pClass); - - private: - void DefineJsContext(); - CFXJSE_Context* CreateVariablesContext(CXFA_Node* pScriptNode, - CXFA_Node* pSubform); - void DefineJsClass(); - void RemoveBuiltInObjs(CFXJSE_Context* pContext) const; - - CXFA_Document* m_pDocument; - std::unique_ptr m_JsContext; - v8::Isolate* m_pIsolate; - CFXJSE_Class* m_pJsClass; - XFA_SCRIPTLANGTYPE m_eScriptType; - std::map> m_mapObjectToValue; - CFX_MapPtrTemplate m_mapVariableToContext; - CXFA_EventParam m_eventParam; - CXFA_NodeArray m_upObjectArray; - // CacheList holds the NodeList items so we can clean them up when we're done. - std::vector> m_CacheList; - CXFA_NodeArray* m_pScriptNodeArray; - std::unique_ptr m_ResolveProcessor; - std::unique_ptr m_FM2JSContext; - CXFA_Object* m_pThisObject; - uint32_t m_dwBuiltInInFlags; - XFA_ATTRIBUTEENUM m_eRunAtType; -}; - -#endif // XFA_FXFA_PARSER_XFA_SCRIPT_IMP_H_ diff --git a/xfa/fxfa/parser/xfa_script_nodehelper.cpp b/xfa/fxfa/parser/xfa_script_nodehelper.cpp deleted file mode 100644 index dd0f3eacd8..0000000000 --- a/xfa/fxfa/parser/xfa_script_nodehelper.cpp +++ /dev/null @@ -1,429 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "xfa/fxfa/parser/xfa_script_nodehelper.h" - -#include "core/fxcrt/include/fx_ext.h" -#include "xfa/fxfa/parser/xfa_doclayout.h" -#include "xfa/fxfa/parser/xfa_document.h" -#include "xfa/fxfa/parser/xfa_localemgr.h" -#include "xfa/fxfa/parser/xfa_object.h" -#include "xfa/fxfa/parser/xfa_script.h" -#include "xfa/fxfa/parser/xfa_script_imp.h" -#include "xfa/fxfa/parser/xfa_utils.h" - -CXFA_NodeHelper::CXFA_NodeHelper() - : m_eLastCreateType(XFA_Element::DataValue), - m_pCreateParent(nullptr), - m_iCreateCount(0), - m_iCreateFlag(XFA_RESOLVENODE_RSTYPE_CreateNodeOne), - m_iCurAllStart(-1), - m_pAllStartParent(nullptr) {} - -CXFA_NodeHelper::~CXFA_NodeHelper() {} - -CXFA_Node* CXFA_NodeHelper::ResolveNodes_GetOneChild(CXFA_Node* parent, - const FX_WCHAR* pwsName, - FX_BOOL bIsClassName) { - if (!parent) { - return nullptr; - } - CXFA_NodeArray siblings; - uint32_t uNameHash = FX_HashCode_GetW(CFX_WideStringC(pwsName), false); - NodeAcc_TraverseAnySiblings(parent, uNameHash, &siblings, bIsClassName); - if (siblings.GetSize() == 0) { - return nullptr; - } - return siblings[0]; -} - -int32_t CXFA_NodeHelper::CountSiblings(CXFA_Node* pNode, - XFA_LOGIC_TYPE eLogicType, - CXFA_NodeArray* pSiblings, - FX_BOOL bIsClassName) { - if (!pNode) - return 0; - CXFA_Node* parent = ResolveNodes_GetParent(pNode, XFA_LOGIC_NoTransparent); - if (!parent) - return 0; - const XFA_PROPERTY* pProperty = XFA_GetPropertyOfElement( - parent->GetElementType(), pNode->GetElementType(), XFA_XDPPACKET_UNKNOWN); - if (!pProperty && eLogicType == XFA_LOGIC_Transparent) { - parent = ResolveNodes_GetParent(pNode, XFA_LOGIC_Transparent); - if (!parent) { - return 0; - } - } - if (bIsClassName) { - return NodeAcc_TraverseSiblings(parent, pNode->GetClassHashCode(), - pSiblings, eLogicType, bIsClassName); - } else { - return NodeAcc_TraverseSiblings(parent, pNode->GetNameHash(), pSiblings, - eLogicType, bIsClassName); - } -} - -int32_t CXFA_NodeHelper::NodeAcc_TraverseAnySiblings(CXFA_Node* parent, - uint32_t dNameHash, - CXFA_NodeArray* pSiblings, - FX_BOOL bIsClassName) { - if (!parent || !pSiblings) { - return 0; - } - int32_t nCount = 0; - int32_t i = 0; - CXFA_NodeArray properties; - parent->GetNodeList(properties, XFA_NODEFILTER_Properties); - int32_t nProperties = properties.GetSize(); - for (i = 0; i < nProperties; ++i) { - CXFA_Node* child = properties[i]; - if (bIsClassName) { - if (child->GetClassHashCode() == dNameHash) { - pSiblings->Add(child); - nCount++; - } - } else { - if (child->GetNameHash() == dNameHash) { - pSiblings->Add(child); - nCount++; - } - } - if (nCount > 0) { - return nCount; - } - nCount += - NodeAcc_TraverseAnySiblings(child, dNameHash, pSiblings, bIsClassName); - } - CXFA_NodeArray children; - parent->GetNodeList(children, XFA_NODEFILTER_Children); - int32_t nChildren = children.GetSize(); - for (i = 0; i < nChildren; i++) { - CXFA_Node* child = children[i]; - if (bIsClassName) { - if (child->GetClassHashCode() == dNameHash) { - if (pSiblings) { - pSiblings->Add(child); - } - nCount++; - } - } else { - if (child->GetNameHash() == dNameHash) { - if (pSiblings) { - pSiblings->Add(child); - } - nCount++; - } - } - if (nCount > 0) { - return nCount; - } - nCount += - NodeAcc_TraverseAnySiblings(child, dNameHash, pSiblings, bIsClassName); - } - return nCount; -} - -int32_t CXFA_NodeHelper::NodeAcc_TraverseSiblings(CXFA_Node* parent, - uint32_t dNameHash, - CXFA_NodeArray* pSiblings, - XFA_LOGIC_TYPE eLogicType, - FX_BOOL bIsClassName, - FX_BOOL bIsFindProperty) { - if (!parent || !pSiblings) { - return 0; - } - int32_t nCount = 0; - int32_t i = 0; - if (bIsFindProperty) { - CXFA_NodeArray properties; - parent->GetNodeList(properties, XFA_NODEFILTER_Properties); - int32_t nProperties = properties.GetSize(); - for (i = 0; i < nProperties; ++i) { - CXFA_Node* child = properties[i]; - if (bIsClassName) { - if (child->GetClassHashCode() == dNameHash) { - pSiblings->Add(child); - nCount++; - } - } else { - if (child->GetNameHash() == dNameHash) { - if (child->GetElementType() != XFA_Element::PageSet && - child->GetElementType() != XFA_Element::Extras && - child->GetElementType() != XFA_Element::Items) { - pSiblings->Add(child); - nCount++; - } - } - } - if (child->IsUnnamed() && - child->GetElementType() == XFA_Element::PageSet) { - nCount += NodeAcc_TraverseSiblings(child, dNameHash, pSiblings, - eLogicType, bIsClassName, FALSE); - } - } - if (nCount > 0) { - return nCount; - } - } - CXFA_NodeArray children; - parent->GetNodeList(children, XFA_NODEFILTER_Children); - int32_t nChildren = children.GetSize(); - for (i = 0; i < nChildren; i++) { - CXFA_Node* child = children[i]; - if (child->GetElementType() == XFA_Element::Variables) { - continue; - } - if (bIsClassName) { - if (child->GetClassHashCode() == dNameHash) { - if (pSiblings) { - pSiblings->Add(child); - } - nCount++; - } - } else { - if (child->GetNameHash() == dNameHash) { - if (pSiblings) { - pSiblings->Add(child); - } - nCount++; - } - } - if (eLogicType == XFA_LOGIC_NoTransparent) { - continue; - } - if (NodeIsTransparent(child) && - child->GetElementType() != XFA_Element::PageSet) { - nCount += NodeAcc_TraverseSiblings(child, dNameHash, pSiblings, - eLogicType, bIsClassName, FALSE); - } - } - return nCount; -} - -CXFA_Node* CXFA_NodeHelper::ResolveNodes_GetParent(CXFA_Node* pNode, - XFA_LOGIC_TYPE eLogicType) { - if (!pNode) { - return nullptr; - } - if (eLogicType == XFA_LOGIC_NoTransparent) { - return pNode->GetNodeItem(XFA_NODEITEM_Parent); - } - CXFA_Node* parent; - CXFA_Node* node = pNode; - while (TRUE) { - parent = ResolveNodes_GetParent(node); - if (!parent) { - break; - } - XFA_Element parentType = parent->GetElementType(); - if ((!parent->IsUnnamed() && parentType != XFA_Element::SubformSet) || - parentType == XFA_Element::Variables) { - break; - } - node = parent; - } - return parent; -} - -int32_t CXFA_NodeHelper::GetIndex(CXFA_Node* pNode, - XFA_LOGIC_TYPE eLogicType, - FX_BOOL bIsProperty, - FX_BOOL bIsClassIndex) { - CXFA_Node* parent = ResolveNodes_GetParent(pNode, XFA_LOGIC_NoTransparent); - if (!parent) { - return 0; - } - if (!bIsProperty && eLogicType == XFA_LOGIC_Transparent) { - parent = ResolveNodes_GetParent(pNode, XFA_LOGIC_Transparent); - if (!parent) { - return 0; - } - } - uint32_t dwHashName = pNode->GetNameHash(); - if (bIsClassIndex) { - dwHashName = pNode->GetClassHashCode(); - } - CXFA_NodeArray siblings; - int32_t iSize = NodeAcc_TraverseSiblings(parent, dwHashName, &siblings, - eLogicType, bIsClassIndex); - for (int32_t i = 0; i < iSize; ++i) { - CXFA_Node* child = siblings[i]; - if (child == pNode) { - return i; - } - } - return 0; -} - -void CXFA_NodeHelper::GetNameExpression(CXFA_Node* refNode, - CFX_WideString& wsName, - FX_BOOL bIsAllPath, - XFA_LOGIC_TYPE eLogicType) { - wsName.clear(); - if (bIsAllPath) { - GetNameExpression(refNode, wsName, FALSE, eLogicType); - CFX_WideString wsParent; - CXFA_Node* parent = - ResolveNodes_GetParent(refNode, XFA_LOGIC_NoTransparent); - while (parent) { - GetNameExpression(parent, wsParent, FALSE, eLogicType); - wsParent += L"."; - wsParent += wsName; - wsName = wsParent; - parent = ResolveNodes_GetParent(parent, XFA_LOGIC_NoTransparent); - } - return; - } - - CFX_WideString ws; - FX_BOOL bIsProperty = NodeIsProperty(refNode); - if (refNode->IsUnnamed() || - (bIsProperty && refNode->GetElementType() != XFA_Element::PageSet)) { - ws = refNode->GetClassName(); - wsName.Format(L"#%s[%d]", ws.c_str(), - GetIndex(refNode, eLogicType, bIsProperty, TRUE)); - return; - } - ws = refNode->GetCData(XFA_ATTRIBUTE_Name); - ws.Replace(L".", L"\\."); - wsName.Format(L"%s[%d]", ws.c_str(), - GetIndex(refNode, eLogicType, bIsProperty, FALSE)); -} - -FX_BOOL CXFA_NodeHelper::NodeIsTransparent(CXFA_Node* refNode) { - if (!refNode) { - return FALSE; - } - XFA_Element refNodeType = refNode->GetElementType(); - if ((refNode->IsUnnamed() && refNode->IsContainerNode()) || - refNodeType == XFA_Element::SubformSet || - refNodeType == XFA_Element::Area || refNodeType == XFA_Element::Proto) { - return TRUE; - } - return FALSE; -} - -FX_BOOL CXFA_NodeHelper::CreateNode_ForCondition(CFX_WideString& wsCondition) { - int32_t iLen = wsCondition.GetLength(); - CFX_WideString wsIndex(L"0"); - FX_BOOL bAll = FALSE; - if (iLen == 0) { - m_iCreateFlag = XFA_RESOLVENODE_RSTYPE_CreateNodeOne; - return FALSE; - } - if (wsCondition.GetAt(0) == '[') { - int32_t i = 1; - for (; i < iLen; ++i) { - FX_WCHAR ch = wsCondition[i]; - if (ch == ' ') { - continue; - } - if (ch == '+' || ch == '-') { - break; - } else if (ch == '*') { - bAll = TRUE; - break; - } else { - break; - } - } - if (bAll) { - wsIndex = FX_WSTRC(L"1"); - m_iCreateFlag = XFA_RESOLVENODE_RSTYPE_CreateNodeAll; - } else { - m_iCreateFlag = XFA_RESOLVENODE_RSTYPE_CreateNodeOne; - wsIndex = wsCondition.Mid(i, iLen - 1 - i); - } - int32_t iIndex = wsIndex.GetInteger(); - m_iCreateCount = iIndex; - return TRUE; - } - return FALSE; -} - -FX_BOOL CXFA_NodeHelper::ResolveNodes_CreateNode( - CFX_WideString wsName, - CFX_WideString wsCondition, - FX_BOOL bLastNode, - CXFA_ScriptContext* pScriptContext) { - if (!m_pCreateParent) { - return FALSE; - } - FX_BOOL bIsClassName = FALSE; - FX_BOOL bResult = FALSE; - if (wsName.GetAt(0) == '!') { - wsName = wsName.Right(wsName.GetLength() - 1); - m_pCreateParent = ToNode( - pScriptContext->GetDocument()->GetXFAObject(XFA_HASHCODE_Datasets)); - } - if (wsName.GetAt(0) == '#') { - bIsClassName = TRUE; - wsName = wsName.Right(wsName.GetLength() - 1); - } - if (m_iCreateCount == 0) { - CreateNode_ForCondition(wsCondition); - } - if (bIsClassName) { - XFA_Element eType = XFA_GetElementTypeForName(wsName.AsStringC()); - if (eType == XFA_Element::Unknown) - return FALSE; - - for (int32_t iIndex = 0; iIndex < m_iCreateCount; iIndex++) { - CXFA_Node* pNewNode = m_pCreateParent->CreateSamePacketNode(eType); - if (pNewNode) { - m_pCreateParent->InsertChild(pNewNode); - if (iIndex == m_iCreateCount - 1) { - m_pCreateParent = pNewNode; - } - bResult = TRUE; - } - } - } else { - XFA_Element eClassType = XFA_Element::DataGroup; - if (bLastNode) { - eClassType = m_eLastCreateType; - } - for (int32_t iIndex = 0; iIndex < m_iCreateCount; iIndex++) { - CXFA_Node* pNewNode = m_pCreateParent->CreateSamePacketNode(eClassType); - if (pNewNode) { - pNewNode->SetAttribute(XFA_ATTRIBUTE_Name, wsName.AsStringC()); - pNewNode->CreateXMLMappingNode(); - m_pCreateParent->InsertChild(pNewNode); - if (iIndex == m_iCreateCount - 1) { - m_pCreateParent = pNewNode; - } - bResult = TRUE; - } - } - } - if (!bResult) { - m_pCreateParent = nullptr; - } - return bResult; -} - -void CXFA_NodeHelper::SetCreateNodeType(CXFA_Node* refNode) { - if (!refNode) { - return; - } - if (refNode->GetElementType() == XFA_Element::Subform) { - m_eLastCreateType = XFA_Element::DataGroup; - } else if (refNode->GetElementType() == XFA_Element::Field) { - m_eLastCreateType = XFA_FieldIsMultiListBox(refNode) - ? XFA_Element::DataGroup - : XFA_Element::DataValue; - } else if (refNode->GetElementType() == XFA_Element::ExclGroup) { - m_eLastCreateType = XFA_Element::DataValue; - } -} - -FX_BOOL CXFA_NodeHelper::NodeIsProperty(CXFA_Node* refNode) { - CXFA_Node* parent = ResolveNodes_GetParent(refNode, XFA_LOGIC_NoTransparent); - return parent && refNode && - XFA_GetPropertyOfElement(parent->GetElementType(), - refNode->GetElementType(), - XFA_XDPPACKET_UNKNOWN); -} diff --git a/xfa/fxfa/parser/xfa_script_nodehelper.h b/xfa/fxfa/parser/xfa_script_nodehelper.h deleted file mode 100644 index 2c9dd8d831..0000000000 --- a/xfa/fxfa/parser/xfa_script_nodehelper.h +++ /dev/null @@ -1,72 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef XFA_FXFA_PARSER_XFA_SCRIPT_NODEHELPER_H_ -#define XFA_FXFA_PARSER_XFA_SCRIPT_NODEHELPER_H_ - -#include "xfa/fxfa/parser/xfa_object.h" -#include "xfa/fxfa/parser/xfa_script.h" - -class CXFA_ScriptContext; - -enum XFA_LOGIC_TYPE { - XFA_LOGIC_NoTransparent, - XFA_LOGIC_Transparent, -}; - -class CXFA_NodeHelper { - public: - CXFA_NodeHelper(); - ~CXFA_NodeHelper(); - - CXFA_Node* ResolveNodes_GetOneChild(CXFA_Node* parent, - const FX_WCHAR* pwsName, - FX_BOOL bIsClassName = FALSE); - CXFA_Node* ResolveNodes_GetParent( - CXFA_Node* pNode, - XFA_LOGIC_TYPE eLogicType = XFA_LOGIC_NoTransparent); - - int32_t NodeAcc_TraverseSiblings(CXFA_Node* parent, - uint32_t dNameHash, - CXFA_NodeArray* pSiblings, - XFA_LOGIC_TYPE eLogicType, - FX_BOOL bIsClassName = FALSE, - FX_BOOL bIsFindProperty = TRUE); - int32_t NodeAcc_TraverseAnySiblings(CXFA_Node* parent, - uint32_t dNameHash, - CXFA_NodeArray* pSiblings, - FX_BOOL bIsClassName = FALSE); - int32_t CountSiblings(CXFA_Node* pNode, - XFA_LOGIC_TYPE eLogicType, - CXFA_NodeArray* pSiblings, - FX_BOOL bIsClassName = FALSE); - int32_t GetIndex(CXFA_Node* pNode, - XFA_LOGIC_TYPE eLogicType = XFA_LOGIC_NoTransparent, - FX_BOOL bIsProperty = FALSE, - FX_BOOL bIsClassIndex = FALSE); - void GetNameExpression(CXFA_Node* refNode, - CFX_WideString& wsName, - FX_BOOL bIsAllPath, - XFA_LOGIC_TYPE eLogicType = XFA_LOGIC_NoTransparent); - FX_BOOL NodeIsTransparent(CXFA_Node* refNode); - FX_BOOL ResolveNodes_CreateNode(CFX_WideString wsName, - CFX_WideString wsCondition, - FX_BOOL bLastNode, - CXFA_ScriptContext* pScriptContext); - FX_BOOL CreateNode_ForCondition(CFX_WideString& wsCondition); - void SetCreateNodeType(CXFA_Node* refNode); - FX_BOOL NodeIsProperty(CXFA_Node* refNode); - - public: - XFA_Element m_eLastCreateType; - CXFA_Node* m_pCreateParent; - int32_t m_iCreateCount; - XFA_RESOVENODE_RSTYPE m_iCreateFlag; - int32_t m_iCurAllStart; - CXFA_Node* m_pAllStartParent; -}; - -#endif // XFA_FXFA_PARSER_XFA_SCRIPT_NODEHELPER_H_ diff --git a/xfa/fxfa/parser/xfa_script_resolveprocessor.cpp b/xfa/fxfa/parser/xfa_script_resolveprocessor.cpp deleted file mode 100644 index 2025cf246b..0000000000 --- a/xfa/fxfa/parser/xfa_script_resolveprocessor.cpp +++ /dev/null @@ -1,826 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include "xfa/fxfa/parser/xfa_script_resolveprocessor.h" - -#include "core/fxcrt/include/fx_ext.h" -#include "xfa/fxfa/parser/xfa_doclayout.h" -#include "xfa/fxfa/parser/xfa_document.h" -#include "xfa/fxfa/parser/xfa_localemgr.h" -#include "xfa/fxfa/parser/xfa_object.h" -#include "xfa/fxfa/parser/xfa_script.h" -#include "xfa/fxfa/parser/xfa_script_imp.h" -#include "xfa/fxfa/parser/xfa_script_nodehelper.h" -#include "xfa/fxfa/parser/xfa_utils.h" - -CXFA_ResolveProcessor::CXFA_ResolveProcessor() - : m_iCurStart(0), m_pNodeHelper(new CXFA_NodeHelper) {} - -CXFA_ResolveProcessor::~CXFA_ResolveProcessor() { - delete m_pNodeHelper; -} - -int32_t CXFA_ResolveProcessor::Resolve(CXFA_ResolveNodesData& rnd) { - if (!rnd.m_CurNode) { - return -1; - } - if (!rnd.m_CurNode->IsNode()) { - if (rnd.m_dwStyles & XFA_RESOLVENODE_Attributes) { - return ResolveForAttributeRs(rnd.m_CurNode, rnd, - rnd.m_wsName.AsStringC()); - } - return 0; - } - if (rnd.m_dwStyles & XFA_RESOLVENODE_AnyChild) { - return ResolveAnyChild(rnd); - } - FX_WCHAR wch = rnd.m_wsName.GetAt(0); - switch (wch) { - case '$': - return ResolveDollar(rnd); - case '!': - return ResolveExcalmatory(rnd); - case '#': - return ResolveNumberSign(rnd); - case '*': - return ResolveAsterisk(rnd); - // TODO(dsinclair): We could probably remove this. - case '.': - return ResolveAnyChild(rnd); - default: - break; - } - if (rnd.m_uHashName == XFA_HASHCODE_This && rnd.m_nLevel == 0) { - rnd.m_Nodes.Add(rnd.m_pSC->GetThisObject()); - return 1; - } else if (rnd.m_CurNode->GetElementType() == XFA_Element::Xfa) { - CXFA_Object* pObjNode = - rnd.m_pSC->GetDocument()->GetXFAObject(rnd.m_uHashName); - if (pObjNode) { - rnd.m_Nodes.Add(pObjNode); - } else if (rnd.m_uHashName == XFA_HASHCODE_Xfa) { - rnd.m_Nodes.Add(rnd.m_CurNode); - } else if ((rnd.m_dwStyles & XFA_RESOLVENODE_Attributes) && - ResolveForAttributeRs(rnd.m_CurNode, rnd, - rnd.m_wsName.AsStringC())) { - return 1; - } - if (rnd.m_Nodes.GetSize() > 0) { - FilterCondition(rnd, rnd.m_wsCondition); - } - return rnd.m_Nodes.GetSize(); - } - int32_t nRet = ResolveNormal(rnd); - if (nRet < 1 && rnd.m_uHashName == XFA_HASHCODE_Xfa) { - rnd.m_Nodes.Add(rnd.m_pSC->GetDocument()->GetRoot()); - } - return rnd.m_Nodes.GetSize(); -} -int32_t CXFA_ResolveProcessor::ResolveAnyChild(CXFA_ResolveNodesData& rnd) { - CFX_WideString wsName = rnd.m_wsName; - CFX_WideString wsCondition = rnd.m_wsCondition; - CXFA_Node* findNode = nullptr; - CXFA_NodeArray siblings; - FX_BOOL bClassName = FALSE; - if (wsName.GetAt(0) == '#') { - bClassName = TRUE; - wsName = wsName.Right(wsName.GetLength() - 1); - } - findNode = m_pNodeHelper->ResolveNodes_GetOneChild( - ToNode(rnd.m_CurNode), wsName.c_str(), bClassName); - if (!findNode) { - return 0; - } - if (wsCondition.IsEmpty()) { - rnd.m_Nodes.Add(findNode); - return rnd.m_Nodes.GetSize(); - } - m_pNodeHelper->CountSiblings(findNode, XFA_LOGIC_Transparent, - (CXFA_NodeArray*)&rnd.m_Nodes, bClassName); - FilterCondition(rnd, wsCondition); - return rnd.m_Nodes.GetSize(); -} -int32_t CXFA_ResolveProcessor::ResolveDollar(CXFA_ResolveNodesData& rnd) { - CXFA_ObjArray& nodes = rnd.m_Nodes; - CFX_WideString wsName = rnd.m_wsName; - CFX_WideString wsCondition = rnd.m_wsCondition; - int32_t iNameLen = wsName.GetLength(); - if (iNameLen == 1) { - nodes.Add(rnd.m_CurNode); - return 1; - } - if (rnd.m_nLevel > 0) { - return -1; - } - XFA_HashCode dwNameHash = static_cast(FX_HashCode_GetW( - CFX_WideStringC(wsName.c_str() + 1, iNameLen - 1), false)); - if (dwNameHash == XFA_HASHCODE_Xfa) { - nodes.Add(rnd.m_pSC->GetDocument()->GetRoot()); - } else { - CXFA_Object* pObjNode = rnd.m_pSC->GetDocument()->GetXFAObject(dwNameHash); - if (pObjNode) { - rnd.m_Nodes.Add(pObjNode); - } - } - if (rnd.m_Nodes.GetSize() > 0) { - FilterCondition(rnd, wsCondition); - } - return rnd.m_Nodes.GetSize(); -} -int32_t CXFA_ResolveProcessor::ResolveExcalmatory(CXFA_ResolveNodesData& rnd) { - if (rnd.m_nLevel > 0) { - return 0; - } - CXFA_Node* datasets = - ToNode(rnd.m_pSC->GetDocument()->GetXFAObject(XFA_HASHCODE_Datasets)); - if (!datasets) { - return 0; - } - CXFA_ResolveNodesData rndFind; - rndFind.m_pSC = rnd.m_pSC; - rndFind.m_CurNode = datasets; - rndFind.m_wsName = rnd.m_wsName.Right(rnd.m_wsName.GetLength() - 1); - rndFind.m_uHashName = static_cast( - FX_HashCode_GetW(rndFind.m_wsName.AsStringC(), false)); - rndFind.m_nLevel = rnd.m_nLevel + 1; - rndFind.m_dwStyles = XFA_RESOLVENODE_Children; - rndFind.m_wsCondition = rnd.m_wsCondition; - Resolve(rndFind); - if (rndFind.m_Nodes.GetSize() > 0) { - rnd.m_Nodes.Append(rndFind.m_Nodes); - rndFind.m_Nodes.RemoveAll(); - } - return rnd.m_Nodes.GetSize(); -} -int32_t CXFA_ResolveProcessor::ResolveNumberSign(CXFA_ResolveNodesData& rnd) { - CFX_WideString wsName = rnd.m_wsName.Right(rnd.m_wsName.GetLength() - 1); - CFX_WideString wsCondition = rnd.m_wsCondition; - CXFA_Node* curNode = ToNode(rnd.m_CurNode); - if (ResolveForAttributeRs(curNode, rnd, wsName.AsStringC())) { - return 1; - } - CXFA_ResolveNodesData rndFind; - rndFind.m_pSC = rnd.m_pSC; - rndFind.m_nLevel = rnd.m_nLevel + 1; - rndFind.m_dwStyles = rnd.m_dwStyles; - rndFind.m_dwStyles |= XFA_RESOLVENODE_TagName; - rndFind.m_dwStyles &= ~XFA_RESOLVENODE_Attributes; - rndFind.m_wsName = wsName; - rndFind.m_uHashName = static_cast( - FX_HashCode_GetW(rndFind.m_wsName.AsStringC(), false)); - rndFind.m_wsCondition = wsCondition; - rndFind.m_CurNode = curNode; - ResolveNormal(rndFind); - if (rndFind.m_Nodes.GetSize() > 0) { - if (wsCondition.GetLength() == 0 && rndFind.m_Nodes.Find(curNode) >= 0) { - rnd.m_Nodes.Add(curNode); - } else { - rnd.m_Nodes.Append(rndFind.m_Nodes); - rndFind.m_Nodes.RemoveAll(); - } - } - return rnd.m_Nodes.GetSize(); -} -int32_t CXFA_ResolveProcessor::ResolveForAttributeRs( - CXFA_Object* curNode, - CXFA_ResolveNodesData& rnd, - const CFX_WideStringC& strAttr) { - const XFA_SCRIPTATTRIBUTEINFO* lpScriptAttribute = - XFA_GetScriptAttributeByName(curNode->GetElementType(), strAttr); - if (lpScriptAttribute) { - rnd.m_pScriptAttribute = lpScriptAttribute; - rnd.m_Nodes.Add(curNode); - rnd.m_dwFlag = XFA_RESOVENODE_RSTYPE_Attribute; - return 1; - } - return 0; -} -int32_t CXFA_ResolveProcessor::ResolveNormal(CXFA_ResolveNodesData& rnd) { - if (rnd.m_nLevel > 32) { - return 0; - } - if (!rnd.m_CurNode->IsNode()) { - return 0; - } - CXFA_Node* curNode = ToNode(rnd.m_CurNode); - CXFA_ObjArray& nodes = rnd.m_Nodes; - int32_t nNum = nodes.GetSize(); - uint32_t dwStyles = rnd.m_dwStyles; - CFX_WideString& wsName = rnd.m_wsName; - XFA_HashCode uNameHash = rnd.m_uHashName; - CFX_WideString& wsCondition = rnd.m_wsCondition; - CXFA_ResolveNodesData rndFind; - rndFind.m_wsName = rnd.m_wsName; - rndFind.m_wsCondition = rnd.m_wsCondition; - rndFind.m_pSC = rnd.m_pSC; - rndFind.m_nLevel = rnd.m_nLevel + 1; - rndFind.m_uHashName = uNameHash; - CXFA_NodeArray children; - CXFA_NodeArray properties; - CXFA_Node* pVariablesNode = nullptr; - CXFA_Node* pPageSetNode = nullptr; - CXFA_Node* pChild = curNode->GetNodeItem(XFA_NODEITEM_FirstChild); - while (pChild) { - if (pChild->GetElementType() == XFA_Element::Variables) { - pVariablesNode = pChild; - pChild = pChild->GetNodeItem(XFA_NODEITEM_NextSibling); - continue; - } else if (pChild->GetElementType() == XFA_Element::PageSet) { - pPageSetNode = pChild; - pChild = pChild->GetNodeItem(XFA_NODEITEM_NextSibling); - continue; - } else { - const XFA_PROPERTY* pPropert = XFA_GetPropertyOfElement( - curNode->GetElementType(), pChild->GetElementType(), - XFA_XDPPACKET_UNKNOWN); - if (pPropert) { - properties.Add(pChild); - } else { - children.Add(pChild); - } - } - pChild = pChild->GetNodeItem(XFA_NODEITEM_NextSibling); - } - if ((dwStyles & XFA_RESOLVENODE_Properties) && pVariablesNode) { - uint32_t uPropHash = pVariablesNode->GetClassHashCode(); - if (uPropHash == uNameHash) { - nodes.Add(pVariablesNode); - } else { - rndFind.m_CurNode = pVariablesNode; - SetStylesForChild(dwStyles, rndFind); - CFX_WideString wsSaveCondition = rndFind.m_wsCondition; - rndFind.m_wsCondition.clear(); - ResolveNormal(rndFind); - rndFind.m_wsCondition = wsSaveCondition; - if (rndFind.m_Nodes.GetSize() > 0) { - nodes.Append(rndFind.m_Nodes); - rndFind.m_Nodes.RemoveAll(); - } - } - if (nodes.GetSize() > nNum) { - FilterCondition(rnd, wsCondition); - if (nodes.GetSize() > 0) { - return 1; - } - return 0; - } - } - if (dwStyles & XFA_RESOLVENODE_Children) { - FX_BOOL bSetFlag = FALSE; - if (pPageSetNode && (dwStyles & XFA_RESOLVENODE_Properties)) { - children.Add(pPageSetNode); - } - for (int32_t i = 0; i < children.GetSize(); i++) { - CXFA_Node* child = children[i]; - if (dwStyles & XFA_RESOLVENODE_TagName) { - if (child->GetClassHashCode() == uNameHash) { - nodes.Add(child); - } - } else if (child->GetNameHash() == uNameHash) { - nodes.Add(child); - } - if (m_pNodeHelper->NodeIsTransparent(child) && - child->GetElementType() != XFA_Element::PageSet) { - if (!bSetFlag) { - SetStylesForChild(dwStyles, rndFind); - bSetFlag = TRUE; - } - rndFind.m_CurNode = child; - CFX_WideString wsSaveCondition = rndFind.m_wsCondition; - rndFind.m_wsCondition.clear(); - ResolveNormal(rndFind); - rndFind.m_wsCondition = wsSaveCondition; - if (rndFind.m_Nodes.GetSize() > 0) { - nodes.Append(rndFind.m_Nodes); - rndFind.m_Nodes.RemoveAll(); - } - } - } - if (nodes.GetSize() > nNum) { - if (!(dwStyles & XFA_RESOLVENODE_ALL)) { - CXFA_NodeArray upArrayNodes; - if (m_pNodeHelper->NodeIsTransparent(ToNode(curNode))) { - m_pNodeHelper->CountSiblings(ToNode(nodes[0]), XFA_LOGIC_Transparent, - &upArrayNodes, - !!(dwStyles & XFA_RESOLVENODE_TagName)); - } - if (upArrayNodes.GetSize() > nodes.GetSize()) { - upArrayNodes[0] = ToNode(nodes[0]); - nodes.RemoveAll(); - nodes.Append((CXFA_ObjArray&)upArrayNodes); - upArrayNodes.RemoveAll(); - } - } - FilterCondition(rnd, wsCondition); - if (nodes.GetSize() > 0) { - return 1; - } - return 0; - } - } - if (dwStyles & XFA_RESOLVENODE_Attributes) { - if (ResolveForAttributeRs(curNode, rnd, wsName.AsStringC())) { - return 1; - } - } - if (dwStyles & XFA_RESOLVENODE_Properties) { - for (int32_t i = 0; i < properties.GetSize(); i++) { - CXFA_Node* childProperty = properties[i]; - if (childProperty->IsUnnamed()) { - uint32_t uPropHash = childProperty->GetClassHashCode(); - if (uPropHash == uNameHash) { - nodes.Add(childProperty); - } - } else if (childProperty->GetNameHash() == uNameHash && - childProperty->GetElementType() != XFA_Element::Extras && - childProperty->GetElementType() != XFA_Element::Items) { - nodes.Add(childProperty); - } - } - if (nodes.GetSize() > nNum) { - FilterCondition(rnd, wsCondition); - if (nodes.GetSize() > 0) { - return 1; - } - return 0; - } - CXFA_Node* pProp = nullptr; - if (XFA_Element::Subform == curNode->GetElementType() && - XFA_HASHCODE_Occur == uNameHash) { - CXFA_Node* pInstanceManager = - curNode->AsNode()->GetInstanceMgrOfSubform(); - if (pInstanceManager) { - pProp = pInstanceManager->GetProperty(0, XFA_Element::Occur, TRUE); - } - } else { - XFA_Element eType = XFA_GetElementTypeForName(wsName.AsStringC()); - if (eType != XFA_Element::Unknown) { - pProp = curNode->AsNode()->GetProperty(0, eType, - eType != XFA_Element::PageSet); - } - } - if (pProp) { - nodes.Add(pProp); - return nodes.GetSize(); - } - } - CXFA_Node* parentNode = m_pNodeHelper->ResolveNodes_GetParent( - curNode->AsNode(), XFA_LOGIC_NoTransparent); - uint32_t uCurClassHash = curNode->GetClassHashCode(); - if (!parentNode) { - if (uCurClassHash == uNameHash) { - nodes.Add(curNode->AsNode()); - FilterCondition(rnd, wsCondition); - if (nodes.GetSize() > 0) { - return 1; - } - } - return 0; - } - if (dwStyles & XFA_RESOLVENODE_Siblings) { - CXFA_Node* child = parentNode->GetNodeItem(XFA_NODEITEM_FirstChild); - uint32_t dwSubStyles = - XFA_RESOLVENODE_Children | XFA_RESOLVENODE_Properties; - if (dwStyles & XFA_RESOLVENODE_TagName) { - dwSubStyles |= XFA_RESOLVENODE_TagName; - } - if (dwStyles & XFA_RESOLVENODE_ALL) { - dwSubStyles |= XFA_RESOLVENODE_ALL; - } - rndFind.m_dwStyles = dwSubStyles; - while (child) { - if (child == curNode) { - if (dwStyles & XFA_RESOLVENODE_TagName) { - if (uCurClassHash == uNameHash) { - nodes.Add(curNode); - } - } else { - if (child->GetNameHash() == uNameHash) { - nodes.Add(curNode); - if (rnd.m_nLevel == 0 && wsCondition.GetLength() == 0) { - nodes.RemoveAll(); - nodes.Add(curNode); - return 1; - } - } - } - child = child->GetNodeItem(XFA_NODEITEM_NextSibling); - continue; - } - if (dwStyles & XFA_RESOLVENODE_TagName) { - if (child->GetClassHashCode() == uNameHash) { - nodes.Add(child); - } - } else if (child->GetNameHash() == uNameHash) { - nodes.Add(child); - } - const XFA_PROPERTY* pPropert = XFA_GetPropertyOfElement( - parentNode->GetElementType(), child->GetElementType(), - XFA_XDPPACKET_UNKNOWN); - FX_BOOL bInnerSearch = FALSE; - if (pPropert) { - if ((child->GetElementType() == XFA_Element::Variables || - child->GetElementType() == XFA_Element::PageSet)) { - bInnerSearch = TRUE; - } - } else { - if (m_pNodeHelper->NodeIsTransparent(child)) { - bInnerSearch = TRUE; - } - } - if (bInnerSearch) { - rndFind.m_CurNode = child; - CFX_WideString wsOriginCondition = rndFind.m_wsCondition; - rndFind.m_wsCondition.clear(); - uint32_t dwOriginStyle = rndFind.m_dwStyles; - rndFind.m_dwStyles = dwOriginStyle | XFA_RESOLVENODE_ALL; - ResolveNormal(rndFind); - rndFind.m_dwStyles = dwOriginStyle; - rndFind.m_wsCondition = wsOriginCondition; - if (rndFind.m_Nodes.GetSize() > 0) { - nodes.Append(rndFind.m_Nodes); - rndFind.m_Nodes.RemoveAll(); - } - } - child = child->GetNodeItem(XFA_NODEITEM_NextSibling); - } - if (nodes.GetSize() > nNum) { - if (m_pNodeHelper->NodeIsTransparent(parentNode)) { - CXFA_NodeArray upArrayNodes; - m_pNodeHelper->CountSiblings(ToNode(nodes[0]), XFA_LOGIC_Transparent, - &upArrayNodes, - !!(dwStyles & XFA_RESOLVENODE_TagName)); - if (upArrayNodes.GetSize() > nodes.GetSize()) { - upArrayNodes[0] = ToNode(nodes[0]); - nodes.RemoveAll(); - nodes.Append((CXFA_ObjArray&)upArrayNodes); - upArrayNodes.RemoveAll(); - } - } - FilterCondition(rnd, wsCondition); - if (nodes.GetSize() > 0) { - return 1; - } - return 0; - } - } - if (dwStyles & XFA_RESOLVENODE_Parent) { - uint32_t dwSubStyles = XFA_RESOLVENODE_Siblings | XFA_RESOLVENODE_Parent | - XFA_RESOLVENODE_Properties; - if (dwStyles & XFA_RESOLVENODE_TagName) { - dwSubStyles |= XFA_RESOLVENODE_TagName; - } - if (dwStyles & XFA_RESOLVENODE_ALL) { - dwSubStyles |= XFA_RESOLVENODE_ALL; - } - rndFind.m_dwStyles = dwSubStyles; - rndFind.m_CurNode = parentNode; - CXFA_NodeArray& array = rnd.m_pSC->GetUpObjectArray(); - array.Add(parentNode); - ResolveNormal(rndFind); - if (rndFind.m_Nodes.GetSize() > 0) { - nodes.Append(rndFind.m_Nodes); - rndFind.m_Nodes.RemoveAll(); - } - if (nodes.GetSize() > nNum) { - return 1; - } - } - return 0; -} -int32_t CXFA_ResolveProcessor::ResolveAsterisk(CXFA_ResolveNodesData& rnd) { - CXFA_Node* curNode = ToNode(rnd.m_CurNode); - CXFA_ObjArray& nodes = rnd.m_Nodes; - CXFA_NodeArray array; - curNode->GetNodeList(array, - XFA_NODEFILTER_Children | XFA_NODEFILTER_Properties); - nodes.Append((CXFA_ObjArray&)array); - return nodes.GetSize(); -} -int32_t CXFA_ResolveProcessor::ResolvePopStack(CFX_Int32Array& stack) { - int32_t nType = -1; - int32_t iSize = stack.GetSize() - 1; - if (iSize > -1) { - nType = stack[iSize]; - stack.RemoveAt(iSize, 1); - } - return nType; -} -int32_t CXFA_ResolveProcessor::GetFilter(const CFX_WideStringC& wsExpression, - int32_t nStart, - CXFA_ResolveNodesData& rnd) { - ASSERT(nStart > -1); - int32_t iLength = wsExpression.GetLength(); - if (nStart >= iLength) { - return 0; - } - CFX_WideString& wsName = rnd.m_wsName; - CFX_WideString& wsCondition = rnd.m_wsCondition; - FX_WCHAR* pNameBuf = wsName.GetBuffer(iLength - nStart); - FX_WCHAR* pConditionBuf = wsCondition.GetBuffer(iLength - nStart); - int32_t nNameCount = 0; - int32_t nConditionCount = 0; - CFX_Int32Array stack; - int32_t nType = -1; - const FX_WCHAR* pSrc = wsExpression.c_str(); - FX_WCHAR wPrev = 0, wCur; - FX_BOOL bIsCondition = FALSE; - while (nStart < iLength) { - wCur = pSrc[nStart++]; - if (wCur == '.') { - if (wPrev == '\\') { - pNameBuf[nNameCount - 1] = wPrev = '.'; - continue; - } - if (nNameCount == 0) { - rnd.m_dwStyles |= XFA_RESOLVENODE_AnyChild; - continue; - } - FX_WCHAR wLookahead = nStart < iLength ? pSrc[nStart] : 0; - if (wLookahead != '[' && wLookahead != '(') { - if (nType < 0) { - break; - } - } - } - if (wCur == '[' || wCur == '(') { - bIsCondition = TRUE; - } else if (wCur == '.' && nStart < iLength && - (pSrc[nStart] == '[' || pSrc[nStart] == '(')) { - bIsCondition = TRUE; - } - if (bIsCondition) { - pConditionBuf[nConditionCount++] = wCur; - } else { - pNameBuf[nNameCount++] = wCur; - } - FX_BOOL bRecursive = TRUE; - switch (nType) { - case 0: - if (wCur == ']') { - nType = ResolvePopStack(stack); - bRecursive = FALSE; - } - break; - case 1: - if (wCur == ')') { - nType = ResolvePopStack(stack); - bRecursive = FALSE; - } - break; - case 2: - if (wCur == '"') { - nType = ResolvePopStack(stack); - bRecursive = FALSE; - } - break; - } - if (bRecursive) { - switch (wCur) { - case '[': - stack.Add(nType); - nType = 0; - break; - case '(': - stack.Add(nType); - nType = 1; - break; - case '"': - stack.Add(nType); - nType = 2; - break; - } - } - wPrev = wCur; - } - if (stack.GetSize() > 0) { - return -1; - } - wsName.ReleaseBuffer(nNameCount); - wsName.TrimLeft(); - wsName.TrimRight(); - wsCondition.ReleaseBuffer(nConditionCount); - wsCondition.TrimLeft(); - wsCondition.TrimRight(); - rnd.m_uHashName = - static_cast(FX_HashCode_GetW(wsName.AsStringC(), false)); - return nStart; -} -void CXFA_ResolveProcessor::ConditionArray(int32_t iCurIndex, - CFX_WideString wsCondition, - int32_t iFoundCount, - CXFA_ResolveNodesData& rnd) { - CXFA_NodeArray& findNodes = (CXFA_NodeArray&)rnd.m_Nodes; - int32_t iLen = wsCondition.GetLength(); - FX_BOOL bRelative = FALSE; - FX_BOOL bAll = FALSE; - int32_t i = 1; - for (; i < iLen; ++i) { - FX_WCHAR ch = wsCondition[i]; - if (ch == ' ') { - continue; - } - if (ch == '+' || ch == '-') { - bRelative = TRUE; - break; - } else if (ch == '*') { - bAll = TRUE; - break; - } else { - break; - } - } - if (bAll) { - if (rnd.m_dwStyles & XFA_RESOLVENODE_CreateNode) { - if (rnd.m_dwStyles & XFA_RESOLVENODE_Bind) { - m_pNodeHelper->m_pCreateParent = ToNode(rnd.m_CurNode); - m_pNodeHelper->m_iCreateCount = 1; - findNodes.RemoveAll(); - m_pNodeHelper->m_iCurAllStart = -1; - m_pNodeHelper->m_pAllStartParent = nullptr; - } else { - if (m_pNodeHelper->m_iCurAllStart == -1) { - m_pNodeHelper->m_iCurAllStart = m_iCurStart; - m_pNodeHelper->m_pAllStartParent = ToNode(rnd.m_CurNode); - } - } - } else if (rnd.m_dwStyles & XFA_RESOLVENODE_BindNew) { - if (m_pNodeHelper->m_iCurAllStart == -1) { - m_pNodeHelper->m_iCurAllStart = m_iCurStart; - } - } - return; - } - if (iFoundCount == 1 && !iLen) { - return; - } - CFX_WideString wsIndex; - wsIndex = wsCondition.Mid(i, iLen - 1 - i); - int32_t iIndex = wsIndex.GetInteger(); - if (bRelative) { - iIndex += iCurIndex; - } - if (iFoundCount <= iIndex || iIndex < 0) { - if (rnd.m_dwStyles & XFA_RESOLVENODE_CreateNode) { - m_pNodeHelper->m_pCreateParent = ToNode(rnd.m_CurNode); - m_pNodeHelper->m_iCreateCount = iIndex - iFoundCount + 1; - } - findNodes.RemoveAll(); - } else { - CXFA_Node* ret = findNodes[iIndex]; - findNodes.RemoveAll(); - findNodes.Add(ret); - } -} -void CXFA_ResolveProcessor::DoPredicateFilter(int32_t iCurIndex, - CFX_WideString wsCondition, - int32_t iFoundCount, - CXFA_ResolveNodesData& rnd) { - CXFA_NodeArray& findNodes = (CXFA_NodeArray&)rnd.m_Nodes; - ASSERT(iFoundCount == findNodes.GetSize()); - CFX_WideString wsExpression; - XFA_SCRIPTLANGTYPE eLangType = XFA_SCRIPTLANGTYPE_Unkown; - if (wsCondition.Left(2) == FX_WSTRC(L".[") && - wsCondition.Right(1) == FX_WSTRC(L"]")) { - eLangType = XFA_SCRIPTLANGTYPE_Formcalc; - } else if (wsCondition.Left(2) == FX_WSTRC(L".(") && - wsCondition.Right(1) == FX_WSTRC(L")")) { - eLangType = XFA_SCRIPTLANGTYPE_Javascript; - } else { - return; - } - - CXFA_ScriptContext* pContext = rnd.m_pSC; - wsExpression = wsCondition.Mid(2, wsCondition.GetLength() - 3); - for (int32_t i = iFoundCount - 1; i >= 0; i--) { - CXFA_Object* node = findNodes[i]; - FX_BOOL bRet = FALSE; - std::unique_ptr pRetValue( - new CFXJSE_Value(rnd.m_pSC->GetRuntime())); - bRet = pContext->RunScript(eLangType, wsExpression.AsStringC(), - pRetValue.get(), node); - if (!bRet || !pRetValue->ToBoolean()) - findNodes.RemoveAt(i); - } -} - -void CXFA_ResolveProcessor::FilterCondition(CXFA_ResolveNodesData& rnd, - CFX_WideString wsCondition) { - CXFA_NodeArray& findNodes = (CXFA_NodeArray&)rnd.m_Nodes; - int32_t iCurrIndex = 0; - const CXFA_NodeArray& array = rnd.m_pSC->GetUpObjectArray(); - int32_t iSize = array.GetSize(); - if (iSize) { - CXFA_Node* curNode = array[iSize - 1]; - FX_BOOL bIsProperty = m_pNodeHelper->NodeIsProperty(curNode); - if (curNode->IsUnnamed() || - (bIsProperty && curNode->GetElementType() != XFA_Element::PageSet)) { - iCurrIndex = m_pNodeHelper->GetIndex(curNode, XFA_LOGIC_Transparent, - bIsProperty, TRUE); - } else { - iCurrIndex = m_pNodeHelper->GetIndex(curNode, XFA_LOGIC_Transparent, - bIsProperty, FALSE); - } - } - int32_t iFoundCount = findNodes.GetSize(); - wsCondition.TrimLeft(); - wsCondition.TrimRight(); - int32_t iLen = wsCondition.GetLength(); - if (!iLen) { - if (rnd.m_dwStyles & XFA_RESOLVENODE_ALL) { - return; - } - if (iFoundCount == 1) { - return; - } - if (iFoundCount <= iCurrIndex) { - if (rnd.m_dwStyles & XFA_RESOLVENODE_CreateNode) { - m_pNodeHelper->m_pCreateParent = ToNode(rnd.m_CurNode); - m_pNodeHelper->m_iCreateCount = iCurrIndex - iFoundCount + 1; - } - findNodes.RemoveAll(); - return; - } else { - CXFA_Node* ret = findNodes[iCurrIndex]; - findNodes.RemoveAll(); - findNodes.Add(ret); - return; - } - } - FX_WCHAR wTypeChar = wsCondition[0]; - switch (wTypeChar) { - case '[': - ConditionArray(iCurrIndex, wsCondition, iFoundCount, rnd); - return; - case '(': - return; - case '"': - return; - case '.': - if (iLen > 1 && (wsCondition[1] == '[' || wsCondition[1] == '(')) { - DoPredicateFilter(iCurrIndex, wsCondition, iFoundCount, rnd); - } - default: - return; - } -} -void CXFA_ResolveProcessor::SetStylesForChild(uint32_t dwParentStyles, - CXFA_ResolveNodesData& rnd) { - uint32_t dwSubStyles = XFA_RESOLVENODE_Children; - if (dwParentStyles & XFA_RESOLVENODE_TagName) { - dwSubStyles |= XFA_RESOLVENODE_TagName; - } - dwSubStyles &= ~XFA_RESOLVENODE_Parent; - dwSubStyles &= ~XFA_RESOLVENODE_Siblings; - dwSubStyles &= ~XFA_RESOLVENODE_Properties; - dwSubStyles |= XFA_RESOLVENODE_ALL; - rnd.m_dwStyles = dwSubStyles; -} -int32_t CXFA_ResolveProcessor::SetResultCreateNode( - XFA_RESOLVENODE_RS& resolveNodeRS, - CFX_WideString& wsLastCondition) { - if (m_pNodeHelper->m_pCreateParent) { - resolveNodeRS.nodes.Add(m_pNodeHelper->m_pCreateParent); - } else { - m_pNodeHelper->CreateNode_ForCondition(wsLastCondition); - } - resolveNodeRS.dwFlags = m_pNodeHelper->m_iCreateFlag; - if (resolveNodeRS.dwFlags == XFA_RESOLVENODE_RSTYPE_CreateNodeOne) { - if (m_pNodeHelper->m_iCurAllStart != -1) { - resolveNodeRS.dwFlags = XFA_RESOLVENODE_RSTYPE_CreateNodeMidAll; - } - } - return resolveNodeRS.nodes.GetSize(); -} -void CXFA_ResolveProcessor::SetIndexDataBind(CFX_WideString& wsNextCondition, - int32_t& iIndex, - int32_t iCount) { - if (m_pNodeHelper->CreateNode_ForCondition(wsNextCondition)) { - if (m_pNodeHelper->m_eLastCreateType == XFA_Element::DataGroup) { - iIndex = 0; - } else { - iIndex = iCount - 1; - } - } else { - iIndex = iCount - 1; - } -} - -CXFA_ResolveNodesData::CXFA_ResolveNodesData(CXFA_ScriptContext* pSC) - : m_pSC(pSC), - m_CurNode(nullptr), - m_wsName(), - m_uHashName(XFA_HASHCODE_None), - m_wsCondition(), - m_nLevel(0), - m_Nodes(), - m_dwStyles(XFA_RESOLVENODE_Children), - m_pScriptAttribute(nullptr), - m_dwFlag(XFA_RESOVENODE_RSTYPE_Nodes) {} - -CXFA_ResolveNodesData::~CXFA_ResolveNodesData() { - m_Nodes.RemoveAll(); -} diff --git a/xfa/fxfa/parser/xfa_script_resolveprocessor.h b/xfa/fxfa/parser/xfa_script_resolveprocessor.h deleted file mode 100644 index d8f16b1e50..0000000000 --- a/xfa/fxfa/parser/xfa_script_resolveprocessor.h +++ /dev/null @@ -1,78 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef XFA_FXFA_PARSER_XFA_SCRIPT_RESOLVEPROCESSOR_H_ -#define XFA_FXFA_PARSER_XFA_SCRIPT_RESOLVEPROCESSOR_H_ - -#include "xfa/fxfa/parser/xfa_object.h" -#include "xfa/fxfa/parser/xfa_script.h" - -class CXFA_NodeHelper; -class CXFA_ScriptContext; - -class CXFA_ResolveNodesData { - public: - CXFA_ResolveNodesData(CXFA_ScriptContext* pSC = nullptr); - ~CXFA_ResolveNodesData(); - - CXFA_ScriptContext* m_pSC; - CXFA_Object* m_CurNode; - CFX_WideString m_wsName; - XFA_HashCode m_uHashName; - CFX_WideString m_wsCondition; - int32_t m_nLevel; - CXFA_ObjArray m_Nodes; - uint32_t m_dwStyles; - const XFA_SCRIPTATTRIBUTEINFO* m_pScriptAttribute; - XFA_RESOVENODE_RSTYPE m_dwFlag; -}; - -class CXFA_ResolveProcessor { - public: - CXFA_ResolveProcessor(); - ~CXFA_ResolveProcessor(); - - int32_t Resolve(CXFA_ResolveNodesData& rnd); - int32_t GetFilter(const CFX_WideStringC& wsExpression, - int32_t nStart, - CXFA_ResolveNodesData& rnd); - int32_t SetResultCreateNode(XFA_RESOLVENODE_RS& resolveNodeRS, - CFX_WideString& wsLastCondition); - void SetIndexDataBind(CFX_WideString& wsNextCondition, - int32_t& iIndex, - int32_t iCount); - void SetCurStart(int32_t start) { m_iCurStart = start; } - - CXFA_NodeHelper* GetNodeHelper() { return m_pNodeHelper; } - - private: - int32_t ResolveForAttributeRs(CXFA_Object* curNode, - CXFA_ResolveNodesData& rnd, - const CFX_WideStringC& strAttr); - int32_t ResolveAnyChild(CXFA_ResolveNodesData& rnd); - int32_t ResolveDollar(CXFA_ResolveNodesData& rnd); - int32_t ResolveExcalmatory(CXFA_ResolveNodesData& rnd); - int32_t ResolveNumberSign(CXFA_ResolveNodesData& rnd); - int32_t ResolveAsterisk(CXFA_ResolveNodesData& rnd); - int32_t ResolveNormal(CXFA_ResolveNodesData& rnd); - int32_t ResolvePopStack(CFX_Int32Array& stack); - void SetStylesForChild(uint32_t dwParentStyles, CXFA_ResolveNodesData& rnd); - - void ConditionArray(int32_t iCurIndex, - CFX_WideString wsCondition, - int32_t iFoundCount, - CXFA_ResolveNodesData& rnd); - void DoPredicateFilter(int32_t iCurIndex, - CFX_WideString wsCondition, - int32_t iFoundCount, - CXFA_ResolveNodesData& rnd); - void FilterCondition(CXFA_ResolveNodesData& rnd, CFX_WideString wsCondition); - - int32_t m_iCurStart; - CXFA_NodeHelper* m_pNodeHelper; -}; - -#endif // XFA_FXFA_PARSER_XFA_SCRIPT_RESOLVEPROCESSOR_H_ diff --git a/xfa/fxfa/parser/xfa_utils_imp.cpp b/xfa/fxfa/parser/xfa_utils_imp.cpp index 3e0db4836b..2f9c3e0d8c 100644 --- a/xfa/fxfa/parser/xfa_utils_imp.cpp +++ b/xfa/fxfa/parser/xfa_utils_imp.cpp @@ -13,7 +13,6 @@ #include "xfa/fxfa/parser/xfa_localemgr.h" #include "xfa/fxfa/parser/xfa_localevalue.h" #include "xfa/fxfa/parser/xfa_object.h" -#include "xfa/fxfa/parser/xfa_script.h" namespace { -- cgit v1.2.3