| OLD | NEW |
| 1 // Copyright 2016 PDFium Authors. All rights reserved. | 1 // Copyright 2016 PDFium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | 6 |
| 7 #include "xfa/fxfa/parser/xfa_object.h" | 7 #include "xfa/fxfa/parser/xfa_object.h" |
| 8 | 8 |
| 9 #include <map> | 9 #include <map> |
| 10 #include <memory> | 10 #include <memory> |
| 11 | 11 |
| 12 #include "core/fxcrt/include/fx_ext.h" | 12 #include "core/fxcrt/include/fx_ext.h" |
| 13 #include "fxjs/include/cfxjse_value.h" | 13 #include "fxjs/include/cfxjse_value.h" |
| 14 #include "third_party/base/stl_util.h" | 14 #include "third_party/base/stl_util.h" |
| 15 #include "xfa/fde/xml/fde_xml_imp.h" | 15 #include "xfa/fde/xml/fde_xml_imp.h" |
| 16 #include "xfa/fgas/crt/fgas_codepage.h" | 16 #include "xfa/fgas/crt/fgas_codepage.h" |
| 17 #include "xfa/fgas/crt/fgas_system.h" | 17 #include "xfa/fgas/crt/fgas_system.h" |
| 18 #include "xfa/fxfa/app/xfa_ffnotify.h" | 18 #include "xfa/fxfa/app/xfa_ffnotify.h" |
| 19 #include "xfa/fxfa/include/cxfa_eventparam.h" | 19 #include "xfa/fxfa/include/cxfa_eventparam.h" |
| 20 #include "xfa/fxfa/parser/cxfa_measurement.h" |
| 20 #include "xfa/fxfa/parser/cxfa_occur.h" | 21 #include "xfa/fxfa/parser/cxfa_occur.h" |
| 21 #include "xfa/fxfa/parser/cxfa_scriptcontext.h" | 22 #include "xfa/fxfa/parser/cxfa_scriptcontext.h" |
| 22 #include "xfa/fxfa/parser/cxfa_simple_parser.h" | 23 #include "xfa/fxfa/parser/cxfa_simple_parser.h" |
| 23 #include "xfa/fxfa/parser/xfa_basic_data.h" | 24 #include "xfa/fxfa/parser/xfa_basic_data.h" |
| 24 #include "xfa/fxfa/parser/xfa_document.h" | 25 #include "xfa/fxfa/parser/xfa_document.h" |
| 25 #include "xfa/fxfa/parser/xfa_document_layout_imp.h" | 26 #include "xfa/fxfa/parser/xfa_document_layout_imp.h" |
| 26 | 27 |
| 27 namespace { | 28 namespace { |
| 28 | 29 |
| 29 void XFA_DeleteWideString(void* pData) { | 30 void XFA_DeleteWideString(void* pData) { |
| (...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 438 void* GetMapKey_Custom(const CFX_WideStringC& wsKey) { | 439 void* GetMapKey_Custom(const CFX_WideStringC& wsKey) { |
| 439 uint32_t dwKey = FX_HashCode_GetW(wsKey, false); | 440 uint32_t dwKey = FX_HashCode_GetW(wsKey, false); |
| 440 return (void*)(uintptr_t)((dwKey << 1) | XFA_KEYTYPE_Custom); | 441 return (void*)(uintptr_t)((dwKey << 1) | XFA_KEYTYPE_Custom); |
| 441 } | 442 } |
| 442 | 443 |
| 443 void* GetMapKey_Element(XFA_Element eType, XFA_ATTRIBUTE eAttribute) { | 444 void* GetMapKey_Element(XFA_Element eType, XFA_ATTRIBUTE eAttribute) { |
| 444 return (void*)(uintptr_t)((static_cast<int32_t>(eType) << 16) | | 445 return (void*)(uintptr_t)((static_cast<int32_t>(eType) << 16) | |
| 445 (eAttribute << 8) | XFA_KEYTYPE_Element); | 446 (eAttribute << 8) | XFA_KEYTYPE_Element); |
| 446 } | 447 } |
| 447 | 448 |
| 449 const XFA_ATTRIBUTEINFO* GetAttributeOfElement(XFA_Element eElement, |
| 450 XFA_ATTRIBUTE eAttribute, |
| 451 uint32_t dwPacket) { |
| 452 int32_t iCount = 0; |
| 453 const uint8_t* pAttr = XFA_GetElementAttributes(eElement, iCount); |
| 454 if (!pAttr || iCount < 1) |
| 455 return nullptr; |
| 456 |
| 457 if (!std::binary_search(pAttr, pAttr + iCount, eAttribute)) |
| 458 return nullptr; |
| 459 |
| 460 const XFA_ATTRIBUTEINFO* pInfo = XFA_GetAttributeByID(eAttribute); |
| 461 ASSERT(pInfo); |
| 462 if (dwPacket == XFA_XDPPACKET_UNKNOWN) |
| 463 return pInfo; |
| 464 return (dwPacket & pInfo->dwPackets) ? pInfo : nullptr; |
| 465 } |
| 466 |
| 467 const XFA_ATTRIBUTEENUMINFO* GetAttributeEnumByID(XFA_ATTRIBUTEENUM eName) { |
| 468 return g_XFAEnumData + eName; |
| 469 } |
| 470 |
| 448 } // namespace | 471 } // namespace |
| 449 | 472 |
| 450 static void XFA_DefaultFreeData(void* pData) {} | 473 static void XFA_DefaultFreeData(void* pData) {} |
| 451 | 474 |
| 452 static XFA_MAPDATABLOCKCALLBACKINFO gs_XFADefaultFreeData = { | 475 static XFA_MAPDATABLOCKCALLBACKINFO gs_XFADefaultFreeData = { |
| 453 XFA_DefaultFreeData, nullptr}; | 476 XFA_DefaultFreeData, nullptr}; |
| 454 | 477 |
| 455 XFA_MAPMODULEDATA::XFA_MAPMODULEDATA() {} | 478 XFA_MAPMODULEDATA::XFA_MAPMODULEDATA() {} |
| 456 | 479 |
| 457 XFA_MAPMODULEDATA::~XFA_MAPMODULEDATA() {} | 480 XFA_MAPMODULEDATA::~XFA_MAPMODULEDATA() {} |
| (...skipping 1870 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2328 CXFA_WidgetData* pWidgetData = GetWidgetData(); | 2351 CXFA_WidgetData* pWidgetData = GetWidgetData(); |
| 2329 if (!pWidgetData) { | 2352 if (!pWidgetData) { |
| 2330 return; | 2353 return; |
| 2331 } | 2354 } |
| 2332 CXFA_Validate validate = pWidgetData->GetValidate(TRUE); | 2355 CXFA_Validate validate = pWidgetData->GetValidate(TRUE); |
| 2333 if (bSetting) { | 2356 if (bSetting) { |
| 2334 validate.SetNullTest(pValue->ToWideString()); | 2357 validate.SetNullTest(pValue->ToWideString()); |
| 2335 } else { | 2358 } else { |
| 2336 int32_t iValue = validate.GetNullTest(); | 2359 int32_t iValue = validate.GetNullTest(); |
| 2337 const XFA_ATTRIBUTEENUMINFO* pInfo = | 2360 const XFA_ATTRIBUTEENUMINFO* pInfo = |
| 2338 XFA_GetAttributeEnumByID((XFA_ATTRIBUTEENUM)iValue); | 2361 GetAttributeEnumByID((XFA_ATTRIBUTEENUM)iValue); |
| 2339 CFX_WideString wsValue; | 2362 CFX_WideString wsValue; |
| 2340 if (pInfo) | 2363 if (pInfo) |
| 2341 wsValue = pInfo->pName; | 2364 wsValue = pInfo->pName; |
| 2342 pValue->SetString(FX_UTF8Encode(wsValue).AsStringC()); | 2365 pValue->SetString(FX_UTF8Encode(wsValue).AsStringC()); |
| 2343 } | 2366 } |
| 2344 } | 2367 } |
| 2345 | 2368 |
| 2346 void CXFA_Node::Script_Som_MandatoryMessage(CFXJSE_Value* pValue, | 2369 void CXFA_Node::Script_Som_MandatoryMessage(CFXJSE_Value* pValue, |
| 2347 FX_BOOL bSetting, | 2370 FX_BOOL bSetting, |
| 2348 XFA_ATTRIBUTE eAttribute) { | 2371 XFA_ATTRIBUTE eAttribute) { |
| (...skipping 564 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2913 CFX_ByteString bsNameSpace = pArguments->GetUTF8String(2); | 2936 CFX_ByteString bsNameSpace = pArguments->GetUTF8String(2); |
| 2914 strNameSpace = CFX_WideString::FromUTF8(bsNameSpace.AsStringC()); | 2937 strNameSpace = CFX_WideString::FromUTF8(bsNameSpace.AsStringC()); |
| 2915 } | 2938 } |
| 2916 } | 2939 } |
| 2917 XFA_Element eType = XFA_GetElementTypeForName(strTagName.AsStringC()); | 2940 XFA_Element eType = XFA_GetElementTypeForName(strTagName.AsStringC()); |
| 2918 CXFA_Node* pNewNode = CreateSamePacketNode(eType); | 2941 CXFA_Node* pNewNode = CreateSamePacketNode(eType); |
| 2919 if (!pNewNode) { | 2942 if (!pNewNode) { |
| 2920 pArguments->GetReturnValue()->SetNull(); | 2943 pArguments->GetReturnValue()->SetNull(); |
| 2921 } else { | 2944 } else { |
| 2922 if (!strName.IsEmpty()) { | 2945 if (!strName.IsEmpty()) { |
| 2923 if (XFA_GetAttributeOfElement(eType, XFA_ATTRIBUTE_Name, | 2946 if (GetAttributeOfElement(eType, XFA_ATTRIBUTE_Name, |
| 2924 XFA_XDPPACKET_UNKNOWN)) { | 2947 XFA_XDPPACKET_UNKNOWN)) { |
| 2925 pNewNode->SetAttribute(XFA_ATTRIBUTE_Name, strName.AsStringC(), true); | 2948 pNewNode->SetAttribute(XFA_ATTRIBUTE_Name, strName.AsStringC(), true); |
| 2926 if (pNewNode->GetPacketID() == XFA_XDPPACKET_Datasets) { | 2949 if (pNewNode->GetPacketID() == XFA_XDPPACKET_Datasets) { |
| 2927 pNewNode->CreateXMLMappingNode(); | 2950 pNewNode->CreateXMLMappingNode(); |
| 2928 } | 2951 } |
| 2929 pArguments->GetReturnValue()->Assign( | 2952 pArguments->GetReturnValue()->Assign( |
| 2930 m_pDocument->GetScriptContext()->GetJSValueFromMap(pNewNode)); | 2953 m_pDocument->GetScriptContext()->GetJSValueFromMap(pNewNode)); |
| 2931 } else { | 2954 } else { |
| 2932 ThrowException(XFA_IDS_NOT_HAVE_PROPERTY, strTagName.c_str(), | 2955 ThrowException(XFA_IDS_NOT_HAVE_PROPERTY, strTagName.c_str(), |
| 2933 L"name"); | 2956 L"name"); |
| 2934 } | 2957 } |
| (...skipping 767 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3702 const XFA_NOTSUREATTRIBUTE* pNotsure = | 3725 const XFA_NOTSUREATTRIBUTE* pNotsure = |
| 3703 XFA_GetNotsureAttribute(GetElementType(), pAttr->eName); | 3726 XFA_GetNotsureAttribute(GetElementType(), pAttr->eName); |
| 3704 eType = pNotsure ? pNotsure->eType : XFA_ATTRIBUTETYPE_Cdata; | 3727 eType = pNotsure ? pNotsure->eType : XFA_ATTRIBUTETYPE_Cdata; |
| 3705 } | 3728 } |
| 3706 switch (eType) { | 3729 switch (eType) { |
| 3707 case XFA_ATTRIBUTETYPE_Enum: { | 3730 case XFA_ATTRIBUTETYPE_Enum: { |
| 3708 XFA_ATTRIBUTEENUM eValue; | 3731 XFA_ATTRIBUTEENUM eValue; |
| 3709 if (!TryEnum(pAttr->eName, eValue, bUseDefault)) { | 3732 if (!TryEnum(pAttr->eName, eValue, bUseDefault)) { |
| 3710 return FALSE; | 3733 return FALSE; |
| 3711 } | 3734 } |
| 3712 wsValue = XFA_GetAttributeEnumByID(eValue)->pName; | 3735 wsValue = GetAttributeEnumByID(eValue)->pName; |
| 3713 return TRUE; | 3736 return TRUE; |
| 3714 } break; | 3737 } break; |
| 3715 case XFA_ATTRIBUTETYPE_Cdata: { | 3738 case XFA_ATTRIBUTETYPE_Cdata: { |
| 3716 CFX_WideStringC wsValueC; | 3739 CFX_WideStringC wsValueC; |
| 3717 if (!TryCData(pAttr->eName, wsValueC, bUseDefault)) { | 3740 if (!TryCData(pAttr->eName, wsValueC, bUseDefault)) { |
| 3718 return FALSE; | 3741 return FALSE; |
| 3719 } | 3742 } |
| 3720 wsValue = wsValueC; | 3743 wsValue = wsValueC; |
| 3721 return TRUE; | 3744 return TRUE; |
| 3722 } break; | 3745 } break; |
| (...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4051 OnChanged(eAttr, bNotify, FALSE); | 4074 OnChanged(eAttr, bNotify, FALSE); |
| 4052 if (IsNeedSavingXMLNode()) { | 4075 if (IsNeedSavingXMLNode()) { |
| 4053 ASSERT(m_pXMLNode->GetType() == FDE_XMLNODE_Element); | 4076 ASSERT(m_pXMLNode->GetType() == FDE_XMLNODE_Element); |
| 4054 const XFA_ATTRIBUTEINFO* pInfo = XFA_GetAttributeByID(eAttr); | 4077 const XFA_ATTRIBUTEINFO* pInfo = XFA_GetAttributeByID(eAttr); |
| 4055 if (pInfo) { | 4078 if (pInfo) { |
| 4056 switch (eType) { | 4079 switch (eType) { |
| 4057 case XFA_ATTRIBUTETYPE_Enum: | 4080 case XFA_ATTRIBUTETYPE_Enum: |
| 4058 static_cast<CFDE_XMLElement*>(m_pXMLNode) | 4081 static_cast<CFDE_XMLElement*>(m_pXMLNode) |
| 4059 ->SetString( | 4082 ->SetString( |
| 4060 pInfo->pName, | 4083 pInfo->pName, |
| 4061 XFA_GetAttributeEnumByID((XFA_ATTRIBUTEENUM)(uintptr_t)pValue) | 4084 GetAttributeEnumByID((XFA_ATTRIBUTEENUM)(uintptr_t)pValue) |
| 4062 ->pName); | 4085 ->pName); |
| 4063 break; | 4086 break; |
| 4064 case XFA_ATTRIBUTETYPE_Boolean: | 4087 case XFA_ATTRIBUTETYPE_Boolean: |
| 4065 static_cast<CFDE_XMLElement*>(m_pXMLNode) | 4088 static_cast<CFDE_XMLElement*>(m_pXMLNode) |
| 4066 ->SetString(pInfo->pName, pValue ? L"1" : L"0"); | 4089 ->SetString(pInfo->pName, pValue ? L"1" : L"0"); |
| 4067 break; | 4090 break; |
| 4068 case XFA_ATTRIBUTETYPE_Integer: | 4091 case XFA_ATTRIBUTETYPE_Integer: |
| 4069 static_cast<CFDE_XMLElement*>(m_pXMLNode) | 4092 static_cast<CFDE_XMLElement*>(m_pXMLNode) |
| 4070 ->SetInteger(pInfo->pName, (int32_t)(uintptr_t)pValue); | 4093 ->SetInteger(pInfo->pName, (int32_t)(uintptr_t)pValue); |
| 4071 break; | 4094 break; |
| (...skipping 812 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4884 } | 4907 } |
| 4885 | 4908 |
| 4886 void CXFA_Node::UpdateNameHash() { | 4909 void CXFA_Node::UpdateNameHash() { |
| 4887 const XFA_NOTSUREATTRIBUTE* pNotsure = | 4910 const XFA_NOTSUREATTRIBUTE* pNotsure = |
| 4888 XFA_GetNotsureAttribute(GetElementType(), XFA_ATTRIBUTE_Name); | 4911 XFA_GetNotsureAttribute(GetElementType(), XFA_ATTRIBUTE_Name); |
| 4889 CFX_WideStringC wsName; | 4912 CFX_WideStringC wsName; |
| 4890 if (!pNotsure || pNotsure->eType == XFA_ATTRIBUTETYPE_Cdata) { | 4913 if (!pNotsure || pNotsure->eType == XFA_ATTRIBUTETYPE_Cdata) { |
| 4891 wsName = GetCData(XFA_ATTRIBUTE_Name); | 4914 wsName = GetCData(XFA_ATTRIBUTE_Name); |
| 4892 m_dwNameHash = FX_HashCode_GetW(wsName, false); | 4915 m_dwNameHash = FX_HashCode_GetW(wsName, false); |
| 4893 } else if (pNotsure->eType == XFA_ATTRIBUTETYPE_Enum) { | 4916 } else if (pNotsure->eType == XFA_ATTRIBUTETYPE_Enum) { |
| 4894 wsName = XFA_GetAttributeEnumByID(GetEnum(XFA_ATTRIBUTE_Name))->pName; | 4917 wsName = GetAttributeEnumByID(GetEnum(XFA_ATTRIBUTE_Name))->pName; |
| 4895 m_dwNameHash = FX_HashCode_GetW(wsName, false); | 4918 m_dwNameHash = FX_HashCode_GetW(wsName, false); |
| 4896 } | 4919 } |
| 4897 } | 4920 } |
| 4898 | 4921 |
| 4899 CFDE_XMLNode* CXFA_Node::CreateXMLMappingNode() { | 4922 CFDE_XMLNode* CXFA_Node::CreateXMLMappingNode() { |
| 4900 if (!m_pXMLNode) { | 4923 if (!m_pXMLNode) { |
| 4901 CFX_WideString wsTag(GetCData(XFA_ATTRIBUTE_Name)); | 4924 CFX_WideString wsTag(GetCData(XFA_ATTRIBUTE_Name)); |
| 4902 m_pXMLNode = new CFDE_XMLElement(wsTag); | 4925 m_pXMLNode = new CFDE_XMLElement(wsTag); |
| 4903 SetFlag(XFA_NodeFlag_OwnXMLNode, false); | 4926 SetFlag(XFA_NodeFlag_OwnXMLNode, false); |
| 4904 } | 4927 } |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5163 CXFA_Node* pSrcChild = pSrcModule->GetNodeItem(XFA_NODEITEM_FirstChild); | 5186 CXFA_Node* pSrcChild = pSrcModule->GetNodeItem(XFA_NODEITEM_FirstChild); |
| 5164 CXFA_Node* pDstChild = pDstModule->GetNodeItem(XFA_NODEITEM_FirstChild); | 5187 CXFA_Node* pDstChild = pDstModule->GetNodeItem(XFA_NODEITEM_FirstChild); |
| 5165 for (; pSrcChild && pDstChild; | 5188 for (; pSrcChild && pDstChild; |
| 5166 pSrcChild = pSrcChild->GetNodeItem(XFA_NODEITEM_NextSibling), | 5189 pSrcChild = pSrcChild->GetNodeItem(XFA_NODEITEM_NextSibling), |
| 5167 pDstChild = pDstChild->GetNodeItem(XFA_NODEITEM_NextSibling)) { | 5190 pDstChild = pDstChild->GetNodeItem(XFA_NODEITEM_NextSibling)) { |
| 5168 MoveBufferMapData(pSrcChild, pDstChild, pKey, TRUE); | 5191 MoveBufferMapData(pSrcChild, pDstChild, pKey, TRUE); |
| 5169 } | 5192 } |
| 5170 } | 5193 } |
| 5171 pSrcModule->MoveBufferMapData(pDstModule, pKey); | 5194 pSrcModule->MoveBufferMapData(pDstModule, pKey); |
| 5172 } | 5195 } |
| OLD | NEW |