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> |
(...skipping 4883 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4894 m_pMapModuleData = new XFA_MAPMODULEDATA; | 4894 m_pMapModuleData = new XFA_MAPMODULEDATA; |
4895 return m_pMapModuleData; | 4895 return m_pMapModuleData; |
4896 } | 4896 } |
4897 | 4897 |
4898 XFA_MAPMODULEDATA* CXFA_Node::GetMapModuleData() const { | 4898 XFA_MAPMODULEDATA* CXFA_Node::GetMapModuleData() const { |
4899 return m_pMapModuleData; | 4899 return m_pMapModuleData; |
4900 } | 4900 } |
4901 | 4901 |
4902 void CXFA_Node::SetMapModuleValue(void* pKey, void* pValue) { | 4902 void CXFA_Node::SetMapModuleValue(void* pKey, void* pValue) { |
4903 XFA_MAPMODULEDATA* pModule = CreateMapModuleData(); | 4903 XFA_MAPMODULEDATA* pModule = CreateMapModuleData(); |
4904 pModule->m_ValueMap.SetAt(pKey, pValue); | 4904 pModule->m_ValueMap[pKey] = pValue; |
4905 } | 4905 } |
4906 | 4906 |
4907 bool CXFA_Node::GetMapModuleValue(void* pKey, void*& pValue) { | 4907 bool CXFA_Node::GetMapModuleValue(void* pKey, void*& pValue) { |
4908 CXFA_Node* pNode = this; | 4908 for (CXFA_Node* pNode = this; pNode; pNode = pNode->GetTemplateNode()) { |
4909 while (pNode) { | |
4910 XFA_MAPMODULEDATA* pModule = pNode->GetMapModuleData(); | 4909 XFA_MAPMODULEDATA* pModule = pNode->GetMapModuleData(); |
4911 if (pModule && pModule->m_ValueMap.Lookup(pKey, pValue)) { | 4910 if (pModule) { |
4912 return true; | 4911 auto it = pModule->m_ValueMap.find(pKey); |
4912 if (it != pModule->m_ValueMap.end()) { | |
4913 pValue = it->second; | |
4914 return true; | |
4915 } | |
4913 } | 4916 } |
4914 pNode = pNode->GetPacketID() != XFA_XDPPACKET_Datasets | 4917 if (pNode->GetPacketID() == XFA_XDPPACKET_Datasets) |
4915 ? pNode->GetTemplateNode() | 4918 break; |
4916 : nullptr; | |
4917 } | 4919 } |
4918 return false; | 4920 return false; |
4919 } | 4921 } |
4920 | 4922 |
4921 void CXFA_Node::SetMapModuleString(void* pKey, const CFX_WideStringC& wsValue) { | 4923 void CXFA_Node::SetMapModuleString(void* pKey, const CFX_WideStringC& wsValue) { |
4922 SetMapModuleBuffer(pKey, (void*)wsValue.c_str(), | 4924 SetMapModuleBuffer(pKey, (void*)wsValue.c_str(), |
4923 wsValue.GetLength() * sizeof(FX_WCHAR)); | 4925 wsValue.GetLength() * sizeof(FX_WCHAR)); |
4924 } | 4926 } |
4925 | 4927 |
4926 bool CXFA_Node::GetMapModuleString(void* pKey, CFX_WideStringC& wsValue) { | 4928 bool CXFA_Node::GetMapModuleString(void* pKey, CFX_WideStringC& wsValue) { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4958 pBuffer->pCallbackInfo = pCallbackInfo; | 4960 pBuffer->pCallbackInfo = pCallbackInfo; |
4959 pBuffer->iBytes = iBytes; | 4961 pBuffer->iBytes = iBytes; |
4960 FXSYS_memcpy(pBuffer->GetData(), pValue, iBytes); | 4962 FXSYS_memcpy(pBuffer->GetData(), pValue, iBytes); |
4961 } | 4963 } |
4962 | 4964 |
4963 bool CXFA_Node::GetMapModuleBuffer(void* pKey, | 4965 bool CXFA_Node::GetMapModuleBuffer(void* pKey, |
4964 void*& pValue, | 4966 void*& pValue, |
4965 int32_t& iBytes, | 4967 int32_t& iBytes, |
4966 bool bProtoAlso) const { | 4968 bool bProtoAlso) const { |
4967 XFA_MAPDATABLOCK* pBuffer = nullptr; | 4969 XFA_MAPDATABLOCK* pBuffer = nullptr; |
4968 const CXFA_Node* pNode = this; | 4970 for (const CXFA_Node* pNode = this; pNode; pNode->GetTemplateNode()) { |
4969 while (pNode) { | |
4970 XFA_MAPMODULEDATA* pModule = pNode->GetMapModuleData(); | 4971 XFA_MAPMODULEDATA* pModule = pNode->GetMapModuleData(); |
4971 if (pModule && pModule->m_BufferMap.Lookup(pKey, pBuffer)) { | 4972 if (pModule) { |
4973 auto it = pModule->m_BufferMap.find(pKey); | |
4974 if (it != pModule->m_BufferMap.end()) { | |
4975 pBuffer = it->second; | |
4976 break; | |
4977 } | |
4978 } | |
4979 if (!bProtoAlso || pNode->GetPacketID() == XFA_XDPPACKET_Datasets) | |
4972 break; | 4980 break; |
4973 } | |
4974 pNode = (bProtoAlso && pNode->GetPacketID() != XFA_XDPPACKET_Datasets) | |
4975 ? pNode->GetTemplateNode() | |
4976 : nullptr; | |
4977 } | 4981 } |
4978 if (!pBuffer) { | 4982 if (!pBuffer) |
4979 return false; | 4983 return false; |
4980 } | 4984 |
4981 pValue = pBuffer->GetData(); | 4985 pValue = pBuffer->GetData(); |
4982 iBytes = pBuffer->iBytes; | 4986 iBytes = pBuffer->iBytes; |
4983 return true; | 4987 return true; |
4984 } | 4988 } |
4985 | 4989 |
4986 bool CXFA_Node::HasMapModuleKey(void* pKey, bool bProtoAlso) { | 4990 bool CXFA_Node::HasMapModuleKey(void* pKey, bool bProtoAlso) { |
4987 CXFA_Node* pNode = this; | 4991 for (CXFA_Node* pNode = this; pNode; pNode = pNode->GetTemplateNode()) { |
4988 while (pNode) { | |
4989 void* pVal; | |
4990 XFA_MAPMODULEDATA* pModule = pNode->GetMapModuleData(); | 4992 XFA_MAPMODULEDATA* pModule = pNode->GetMapModuleData(); |
4991 if (pModule && | 4993 if (pModule) { |
4992 (pModule->m_ValueMap.Lookup(pKey, pVal) || | 4994 auto it1 = pModule->m_ValueMap.find(pKey); |
4993 pModule->m_BufferMap.Lookup(pKey, (XFA_MAPDATABLOCK*&)pVal))) { | 4995 if (it1 != pModule->m_ValueMap.end()) |
4994 return true; | 4996 return true; |
4997 | |
4998 auto it2 = pModule->m_BufferMap.find(pKey); | |
4999 if (it2 != pModule->m_BufferMap.end()) | |
5000 return true; | |
4995 } | 5001 } |
4996 pNode = (bProtoAlso && pNode->GetPacketID() != XFA_XDPPACKET_Datasets) | 5002 if (!bProtoAlso || pNode->GetPacketID() == XFA_XDPPACKET_Datasets) |
4997 ? pNode->GetTemplateNode() | 5003 break; |
4998 : nullptr; | |
4999 } | 5004 } |
5000 return false; | 5005 return false; |
5001 } | 5006 } |
5002 | 5007 |
5003 void CXFA_Node::RemoveMapModuleKey(void* pKey) { | 5008 void CXFA_Node::RemoveMapModuleKey(void* pKey) { |
5004 XFA_MAPMODULEDATA* pModule = GetMapModuleData(); | 5009 XFA_MAPMODULEDATA* pModule = GetMapModuleData(); |
5005 if (!pModule) | 5010 if (!pModule) |
5006 return; | 5011 return; |
5007 | 5012 |
5008 if (pKey) { | 5013 if (pKey) { |
5009 XFA_MAPDATABLOCK* pBuffer = nullptr; | 5014 auto it = pModule->m_BufferMap.find(pKey); |
5010 pModule->m_BufferMap.Lookup(pKey, pBuffer); | 5015 if (it != pModule->m_BufferMap.end()) { |
5016 XFA_MAPDATABLOCK* pBuffer = it->second; | |
5017 if (pBuffer) { | |
5018 if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pFree) | |
5019 pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData()); | |
5020 FX_Free(pBuffer); | |
5021 } | |
5022 pModule->m_BufferMap.erase(it); | |
5023 } | |
5024 pModule->m_ValueMap.erase(pKey); | |
5025 return; | |
5026 } | |
5027 | |
5028 for (auto& pair : pModule->m_BufferMap) { | |
5029 XFA_MAPDATABLOCK* pBuffer = pair.second; | |
5011 if (pBuffer) { | 5030 if (pBuffer) { |
5012 if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pFree) { | 5031 if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pFree) |
5013 pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData()); | 5032 pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData()); |
5014 } | |
5015 FX_Free(pBuffer); | 5033 FX_Free(pBuffer); |
5016 } | 5034 } |
5017 pModule->m_BufferMap.RemoveKey(pKey); | |
5018 pModule->m_ValueMap.RemoveKey(pKey); | |
5019 } else { | |
5020 XFA_MAPDATABLOCK* pBuffer; | |
5021 FX_POSITION posBuffer = pModule->m_BufferMap.GetStartPosition(); | |
5022 while (posBuffer) { | |
5023 pModule->m_BufferMap.GetNextAssoc(posBuffer, pKey, pBuffer); | |
5024 if (pBuffer) { | |
5025 if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pFree) { | |
5026 pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData()); | |
5027 } | |
5028 FX_Free(pBuffer); | |
5029 } | |
5030 } | |
5031 pModule->m_BufferMap.RemoveAll(); | |
5032 pModule->m_ValueMap.RemoveAll(); | |
5033 delete pModule; | |
5034 } | 5035 } |
5036 pModule->m_BufferMap.clear(); | |
5037 pModule->m_ValueMap.clear(); | |
5038 delete pModule; | |
5035 } | 5039 } |
5036 | 5040 |
5037 void CXFA_Node::MergeAllData(void* pDstModule, bool bUseSrcAttr) { | 5041 void CXFA_Node::MergeAllData(void* pDstModule) { |
Tom Sepez
2017/01/05 00:45:55
note: bUseSrcData always passed as true.
| |
5038 XFA_MAPMODULEDATA* pDstModuleData = | 5042 XFA_MAPMODULEDATA* pDstModuleData = |
5039 static_cast<CXFA_Node*>(pDstModule)->CreateMapModuleData(); | 5043 static_cast<CXFA_Node*>(pDstModule)->CreateMapModuleData(); |
5040 XFA_MAPMODULEDATA* pSrcModuleData = GetMapModuleData(); | 5044 XFA_MAPMODULEDATA* pSrcModuleData = GetMapModuleData(); |
5041 if (!pSrcModuleData) { | 5045 if (!pSrcModuleData) |
5042 return; | 5046 return; |
5043 } | 5047 |
5044 FX_POSITION psValue = pSrcModuleData->m_ValueMap.GetStartPosition(); | 5048 for (const auto& pair : pSrcModuleData->m_ValueMap) |
5045 while (psValue) { | 5049 pDstModuleData->m_ValueMap[pair.first] = pair.second; |
5046 void* pKey; | 5050 |
5047 void* pValue; | 5051 for (const auto& pair : pSrcModuleData->m_BufferMap) { |
5048 pSrcModuleData->m_ValueMap.GetNextAssoc(psValue, pKey, pValue); | 5052 XFA_MAPDATABLOCK* pSrcBuffer = pair.second; |
5049 if (bUseSrcAttr || !pDstModuleData->m_ValueMap.GetValueAt(pKey)) { | 5053 XFA_MAPDATABLOCK*& pDstBuffer = pDstModuleData->m_BufferMap[pair.first]; |
5050 pDstModuleData->m_ValueMap.SetAt(pKey, pValue); | |
5051 } | |
5052 } | |
5053 FX_POSITION psBuffer = pSrcModuleData->m_BufferMap.GetStartPosition(); | |
5054 while (psBuffer) { | |
5055 void* pKey; | |
5056 XFA_MAPDATABLOCK* pSrcBuffer; | |
5057 pSrcModuleData->m_BufferMap.GetNextAssoc(psBuffer, pKey, pSrcBuffer); | |
5058 XFA_MAPDATABLOCK*& pBuffer = pDstModuleData->m_BufferMap[pKey]; | |
Tom Sepez
2017/01/05 00:45:55
note: renamed to pDstBuffer which results in some
| |
5059 if (pBuffer && !bUseSrcAttr) { | |
5060 continue; | |
5061 } | |
5062 if (pSrcBuffer->pCallbackInfo && pSrcBuffer->pCallbackInfo->pFree && | 5054 if (pSrcBuffer->pCallbackInfo && pSrcBuffer->pCallbackInfo->pFree && |
5063 !pSrcBuffer->pCallbackInfo->pCopy) { | 5055 !pSrcBuffer->pCallbackInfo->pCopy) { |
5064 if (pBuffer) { | 5056 if (pDstBuffer) { |
5065 pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData()); | 5057 pDstBuffer->pCallbackInfo->pFree(*(void**)pDstBuffer->GetData()); |
5066 pDstModuleData->m_BufferMap.RemoveKey(pKey); | 5058 pDstModuleData->m_BufferMap.erase(pair.first); |
5067 } | 5059 } |
5068 continue; | 5060 continue; |
5069 } | 5061 } |
5070 if (!pBuffer) { | 5062 if (!pDstBuffer) { |
5071 pBuffer = (XFA_MAPDATABLOCK*)FX_Alloc( | 5063 pDstBuffer = (XFA_MAPDATABLOCK*)FX_Alloc( |
5072 uint8_t, sizeof(XFA_MAPDATABLOCK) + pSrcBuffer->iBytes); | 5064 uint8_t, sizeof(XFA_MAPDATABLOCK) + pSrcBuffer->iBytes); |
5073 } else if (pBuffer->iBytes != pSrcBuffer->iBytes) { | 5065 } else if (pDstBuffer->iBytes != pSrcBuffer->iBytes) { |
5074 if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pFree) { | 5066 if (pDstBuffer->pCallbackInfo && pDstBuffer->pCallbackInfo->pFree) { |
5075 pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData()); | 5067 pDstBuffer->pCallbackInfo->pFree(*(void**)pDstBuffer->GetData()); |
5076 } | 5068 } |
5077 pBuffer = (XFA_MAPDATABLOCK*)FX_Realloc( | 5069 pDstBuffer = (XFA_MAPDATABLOCK*)FX_Realloc( |
5078 uint8_t, pBuffer, sizeof(XFA_MAPDATABLOCK) + pSrcBuffer->iBytes); | 5070 uint8_t, pDstBuffer, sizeof(XFA_MAPDATABLOCK) + pSrcBuffer->iBytes); |
5079 } else if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pFree) { | 5071 } else if (pDstBuffer->pCallbackInfo && pDstBuffer->pCallbackInfo->pFree) { |
5080 pBuffer->pCallbackInfo->pFree(*(void**)pBuffer->GetData()); | 5072 pDstBuffer->pCallbackInfo->pFree(*(void**)pDstBuffer->GetData()); |
5081 } | 5073 } |
5082 if (!pBuffer) { | 5074 if (!pDstBuffer) { |
5083 continue; | 5075 continue; |
5084 } | 5076 } |
5085 pBuffer->pCallbackInfo = pSrcBuffer->pCallbackInfo; | 5077 pDstBuffer->pCallbackInfo = pSrcBuffer->pCallbackInfo; |
5086 pBuffer->iBytes = pSrcBuffer->iBytes; | 5078 pDstBuffer->iBytes = pSrcBuffer->iBytes; |
5087 FXSYS_memcpy(pBuffer->GetData(), pSrcBuffer->GetData(), pSrcBuffer->iBytes); | 5079 FXSYS_memcpy(pDstBuffer->GetData(), pSrcBuffer->GetData(), |
5088 if (pBuffer->pCallbackInfo && pBuffer->pCallbackInfo->pCopy) { | 5080 pSrcBuffer->iBytes); |
5089 pBuffer->pCallbackInfo->pCopy(*(void**)pBuffer->GetData()); | 5081 if (pDstBuffer->pCallbackInfo && pDstBuffer->pCallbackInfo->pCopy) { |
5082 pDstBuffer->pCallbackInfo->pCopy(*(void**)pDstBuffer->GetData()); | |
5090 } | 5083 } |
5091 } | 5084 } |
5092 } | 5085 } |
5093 | 5086 |
5094 void CXFA_Node::MoveBufferMapData(CXFA_Node* pDstModule, void* pKey) { | 5087 void CXFA_Node::MoveBufferMapData(CXFA_Node* pDstModule, void* pKey) { |
5095 if (!pDstModule) { | 5088 if (!pDstModule) { |
5096 return; | 5089 return; |
5097 } | 5090 } |
5098 bool bNeedMove = true; | 5091 bool bNeedMove = true; |
5099 if (!pKey) { | 5092 if (!pKey) { |
5100 bNeedMove = false; | 5093 bNeedMove = false; |
5101 } | 5094 } |
5102 if (pDstModule->GetElementType() != GetElementType()) { | 5095 if (pDstModule->GetElementType() != GetElementType()) { |
5103 bNeedMove = false; | 5096 bNeedMove = false; |
5104 } | 5097 } |
5105 XFA_MAPMODULEDATA* pSrcModuleData = nullptr; | 5098 XFA_MAPMODULEDATA* pSrcModuleData = nullptr; |
5106 XFA_MAPMODULEDATA* pDstModuleData = nullptr; | 5099 XFA_MAPMODULEDATA* pDstModuleData = nullptr; |
5107 if (bNeedMove) { | 5100 if (bNeedMove) { |
5108 pSrcModuleData = GetMapModuleData(); | 5101 pSrcModuleData = GetMapModuleData(); |
5109 if (!pSrcModuleData) { | 5102 if (!pSrcModuleData) { |
5110 bNeedMove = false; | 5103 bNeedMove = false; |
5111 } | 5104 } |
5112 pDstModuleData = pDstModule->CreateMapModuleData(); | 5105 pDstModuleData = pDstModule->CreateMapModuleData(); |
5113 } | 5106 } |
5114 if (bNeedMove) { | 5107 if (bNeedMove) { |
5115 void* pBufferBlockData = pSrcModuleData->m_BufferMap.GetValueAt(pKey); | 5108 auto it = pSrcModuleData->m_BufferMap.find(pKey); |
5116 if (pBufferBlockData) { | 5109 if (it != pSrcModuleData->m_BufferMap.end()) { |
5117 pSrcModuleData->m_BufferMap.RemoveKey(pKey); | 5110 void* pBufferBlockData = it->second; |
5118 pDstModuleData->m_BufferMap.RemoveKey(pKey); | 5111 if (pBufferBlockData) { |
5119 pDstModuleData->m_BufferMap.SetAt(pKey, | 5112 pSrcModuleData->m_BufferMap.erase(pKey); |
5120 (XFA_MAPDATABLOCK*)pBufferBlockData); | 5113 pDstModuleData->m_BufferMap[pKey] = (XFA_MAPDATABLOCK*)pBufferBlockData; |
5114 } | |
5121 } | 5115 } |
5122 } | 5116 } |
5123 if (pDstModule->IsNodeV()) { | 5117 if (pDstModule->IsNodeV()) { |
5124 CFX_WideString wsValue = pDstModule->GetScriptContent(false); | 5118 CFX_WideString wsValue = pDstModule->GetScriptContent(false); |
5125 CFX_WideString wsFormatValue(wsValue); | 5119 CFX_WideString wsFormatValue(wsValue); |
5126 CXFA_WidgetData* pWidgetData = pDstModule->GetContainerWidgetData(); | 5120 CXFA_WidgetData* pWidgetData = pDstModule->GetContainerWidgetData(); |
5127 if (pWidgetData) { | 5121 if (pWidgetData) { |
5128 pWidgetData->GetFormatDataValue(wsValue, wsFormatValue); | 5122 pWidgetData->GetFormatDataValue(wsValue, wsFormatValue); |
5129 } | 5123 } |
5130 pDstModule->SetScriptContent(wsValue, wsFormatValue, true, true); | 5124 pDstModule->SetScriptContent(wsValue, wsFormatValue, true, true); |
(...skipping 25 matching lines...) Expand all Loading... | |
5156 ThrowException(L"'%s' doesn't have property '%s'.", obj.c_str(), | 5150 ThrowException(L"'%s' doesn't have property '%s'.", obj.c_str(), |
5157 prop.c_str()); | 5151 prop.c_str()); |
5158 } | 5152 } |
5159 | 5153 |
5160 void CXFA_Node::ThrowTooManyOccurancesException( | 5154 void CXFA_Node::ThrowTooManyOccurancesException( |
5161 const CFX_WideString& obj) const { | 5155 const CFX_WideString& obj) const { |
5162 ThrowException( | 5156 ThrowException( |
5163 L"The element [%s] has violated its allowable number of occurrences.", | 5157 L"The element [%s] has violated its allowable number of occurrences.", |
5164 obj.c_str()); | 5158 obj.c_str()); |
5165 } | 5159 } |
OLD | NEW |