Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(57)

Side by Side Diff: xfa/fxfa/parser/xfa_object_imp.cpp

Issue 1919563002: Pass CFX_*StringCs to FX_HashCode_GETA and _GETW hash functions. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: fix issue from c4 Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « xfa/fxfa/parser/xfa_document_imp.cpp ('k') | xfa/fxfa/parser/xfa_script_imp.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #include "xfa/fxfa/parser/xfa_object.h" 7 #include "xfa/fxfa/parser/xfa_object.h"
8 8
9 #include "core/fxcrt/include/fx_ext.h" 9 #include "core/fxcrt/include/fx_ext.h"
10 #include "xfa/fde/xml/fde_xml_imp.h" 10 #include "xfa/fde/xml/fde_xml_imp.h"
(...skipping 1751 matching lines...) Expand 10 before | Expand all | Expand 10 after
1762 {0xd576d08e, L"mouseUp", XFA_EVENT_MouseUp, 5}, 1762 {0xd576d08e, L"mouseUp", XFA_EVENT_MouseUp, 5},
1763 {0xd95657a6, L"click", XFA_EVENT_Click, 4}, 1763 {0xd95657a6, L"click", XFA_EVENT_Click, 4},
1764 {0xdbfbe02e, L"calculate", XFA_EVENT_Calculate, 1}, 1764 {0xdbfbe02e, L"calculate", XFA_EVENT_Calculate, 1},
1765 {0xe25fa7b8, L"postOpen", XFA_EVENT_PostOpen, 7}, 1765 {0xe25fa7b8, L"postOpen", XFA_EVENT_PostOpen, 7},
1766 {0xe28dce7e, L"enter", XFA_EVENT_Enter, 2}, 1766 {0xe28dce7e, L"enter", XFA_EVENT_Enter, 2},
1767 {0xfc82d695, L"postSave", XFA_EVENT_PostSave, 0}, 1767 {0xfc82d695, L"postSave", XFA_EVENT_PostSave, 0},
1768 {0xfd54fbb7, L"postSign", XFA_EVENT_PostSign, 6}, 1768 {0xfd54fbb7, L"postSign", XFA_EVENT_PostSign, 6},
1769 }; 1769 };
1770 const XFA_ExecEventParaInfo* GetEventParaInfoByName( 1770 const XFA_ExecEventParaInfo* GetEventParaInfoByName(
1771 const CFX_WideStringC& wsEventName) { 1771 const CFX_WideStringC& wsEventName) {
1772 int32_t iLength = wsEventName.GetLength(); 1772 uint32_t uHash = FX_HashCode_GetW(wsEventName, false);
1773 uint32_t uHash = FX_HashCode_String_GetW(wsEventName.c_str(), iLength); 1773 int32_t iStart = 0;
1774 const XFA_ExecEventParaInfo* eventParaInfo = NULL; 1774 int32_t iEnd = (sizeof(gs_eventParaInfos) / sizeof(gs_eventParaInfos[0])) - 1;
1775 int32_t iStart = 0,
1776 iEnd = (sizeof(gs_eventParaInfos) / sizeof(gs_eventParaInfos[0])) - 1;
1777 int32_t iMid = (iStart + iEnd) / 2;
1778 do { 1775 do {
1779 iMid = (iStart + iEnd) / 2; 1776 int32_t iMid = (iStart + iEnd) / 2;
1780 eventParaInfo = &gs_eventParaInfos[iMid]; 1777 const XFA_ExecEventParaInfo* eventParaInfo = &gs_eventParaInfos[iMid];
1781 if (uHash == eventParaInfo->m_uHash) { 1778 if (uHash == eventParaInfo->m_uHash) {
1782 return eventParaInfo; 1779 return eventParaInfo;
1783 } else if (uHash < eventParaInfo->m_uHash) { 1780 }
1781 if (uHash < eventParaInfo->m_uHash) {
1784 iEnd = iMid - 1; 1782 iEnd = iMid - 1;
1785 } else { 1783 } else {
1786 iStart = iMid + 1; 1784 iStart = iMid + 1;
1787 } 1785 }
1788 } while (iStart <= iEnd); 1786 } while (iStart <= iEnd);
1789 return NULL; 1787 return nullptr;
1790 } 1788 }
1791 void XFA_STRING_TO_RGB(CFX_WideString& strRGB, 1789 void XFA_STRING_TO_RGB(CFX_WideString& strRGB,
1792 int32_t& r, 1790 int32_t& r,
1793 int32_t& g, 1791 int32_t& g,
1794 int32_t& b) { 1792 int32_t& b) {
1795 r = 0; 1793 r = 0;
1796 g = 0; 1794 g = 0;
1797 b = 0; 1795 b = 0;
1798 FX_WCHAR zero = '0'; 1796 FX_WCHAR zero = '0';
1799 int32_t iIndex = 0; 1797 int32_t iIndex = 0;
(...skipping 1480 matching lines...) Expand 10 before | Expand all | Expand 10 after
3280 int32_t iCount = XFA_ScriptInstanceManager_GetCount(this); 3278 int32_t iCount = XFA_ScriptInstanceManager_GetCount(this);
3281 if (iDesired == iCount) { 3279 if (iDesired == iCount) {
3282 return 0; 3280 return 0;
3283 } 3281 }
3284 if (iDesired < iCount) { 3282 if (iDesired < iCount) {
3285 CFX_WideStringC wsInstManagerName = GetCData(XFA_ATTRIBUTE_Name); 3283 CFX_WideStringC wsInstManagerName = GetCData(XFA_ATTRIBUTE_Name);
3286 CFX_WideString wsInstanceName = wsInstManagerName.IsEmpty() 3284 CFX_WideString wsInstanceName = wsInstManagerName.IsEmpty()
3287 ? wsInstManagerName 3285 ? wsInstManagerName
3288 : wsInstManagerName.Mid(1); 3286 : wsInstManagerName.Mid(1);
3289 uint32_t dInstanceNameHash = 3287 uint32_t dInstanceNameHash =
3290 wsInstanceName.IsEmpty() ? 0 : FX_HashCode_String_GetW( 3288 FX_HashCode_GetW(wsInstanceName.AsStringC(), false);
3291 wsInstanceName.c_str(),
3292 wsInstanceName.GetLength());
3293 CXFA_Node* pPrevSibling = 3289 CXFA_Node* pPrevSibling =
3294 (iDesired == 0) ? this 3290 (iDesired == 0) ? this
3295 : XFA_ScriptInstanceManager_GetItem(this, iDesired - 1); 3291 : XFA_ScriptInstanceManager_GetItem(this, iDesired - 1);
3296 while (iCount > iDesired) { 3292 while (iCount > iDesired) {
3297 CXFA_Node* pRemoveInstance = 3293 CXFA_Node* pRemoveInstance =
3298 pPrevSibling->GetNodeItem(XFA_NODEITEM_NextSibling); 3294 pPrevSibling->GetNodeItem(XFA_NODEITEM_NextSibling);
3299 if (pRemoveInstance->GetClassID() != XFA_ELEMENT_Subform && 3295 if (pRemoveInstance->GetClassID() != XFA_ELEMENT_Subform &&
3300 pRemoveInstance->GetClassID() != XFA_ELEMENT_SubformSet) { 3296 pRemoveInstance->GetClassID() != XFA_ELEMENT_SubformSet) {
3301 continue; 3297 continue;
3302 } 3298 }
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after
3719 FXJSE_Value_SetUTF8String(hValue, FX_UTF8Encode(FX_WSTRC(L"0")).AsStringC()); 3715 FXJSE_Value_SetUTF8String(hValue, FX_UTF8Encode(FX_WSTRC(L"0")).AsStringC());
3720 } 3716 }
3721 void CXFA_Node::Script_Encrypt_Format(FXJSE_HVALUE hValue, 3717 void CXFA_Node::Script_Encrypt_Format(FXJSE_HVALUE hValue,
3722 FX_BOOL bSetting, 3718 FX_BOOL bSetting,
3723 XFA_ATTRIBUTE eAttribute) {} 3719 XFA_ATTRIBUTE eAttribute) {}
3724 enum XFA_KEYTYPE { 3720 enum XFA_KEYTYPE {
3725 XFA_KEYTYPE_Custom, 3721 XFA_KEYTYPE_Custom,
3726 XFA_KEYTYPE_Element, 3722 XFA_KEYTYPE_Element,
3727 }; 3723 };
3728 void* XFA_GetMapKey_Custom(const CFX_WideStringC& wsKey) { 3724 void* XFA_GetMapKey_Custom(const CFX_WideStringC& wsKey) {
3729 uint32_t dwKey = FX_HashCode_String_GetW(wsKey.c_str(), wsKey.GetLength()); 3725 uint32_t dwKey = FX_HashCode_GetW(wsKey, false);
3730 return (void*)(uintptr_t)((dwKey << 1) | XFA_KEYTYPE_Custom); 3726 return (void*)(uintptr_t)((dwKey << 1) | XFA_KEYTYPE_Custom);
3731 } 3727 }
3732 void* XFA_GetMapKey_Element(XFA_ELEMENT eElement, XFA_ATTRIBUTE eAttribute) { 3728 void* XFA_GetMapKey_Element(XFA_ELEMENT eElement, XFA_ATTRIBUTE eAttribute) {
3733 return (void*)(uintptr_t)((eElement << 16) | (eAttribute << 8) | 3729 return (void*)(uintptr_t)((eElement << 16) | (eAttribute << 8) |
3734 XFA_KEYTYPE_Element); 3730 XFA_KEYTYPE_Element);
3735 } 3731 }
3736 FX_BOOL CXFA_Node::HasAttribute(XFA_ATTRIBUTE eAttr, FX_BOOL bCanInherit) { 3732 FX_BOOL CXFA_Node::HasAttribute(XFA_ATTRIBUTE eAttr, FX_BOOL bCanInherit) {
3737 void* pKey = XFA_GetMapKey_Element(GetClassID(), eAttr); 3733 void* pKey = XFA_GetMapKey_Element(GetClassID(), eAttr);
3738 return HasMapModuleKey(pKey, bCanInherit); 3734 return HasMapModuleKey(pKey, bCanInherit);
3739 } 3735 }
(...skipping 985 matching lines...) Expand 10 before | Expand all | Expand 10 after
4725 pNode->m_pXMLNode = pNewXMLElement; 4721 pNode->m_pXMLNode = pNewXMLElement;
4726 pNode->SetEnum(XFA_ATTRIBUTE_Contains, XFA_ATTRIBUTEENUM_Unknown); 4722 pNode->SetEnum(XFA_ATTRIBUTE_Contains, XFA_ATTRIBUTEENUM_Unknown);
4727 } else { 4723 } else {
4728 m_pXMLNode->RemoveChildNode(pNode->m_pXMLNode); 4724 m_pXMLNode->RemoveChildNode(pNode->m_pXMLNode);
4729 } 4725 }
4730 pNode->SetFlag(XFA_NODEFLAG_OwnXMLNode, false); 4726 pNode->SetFlag(XFA_NODEFLAG_OwnXMLNode, false);
4731 } 4727 }
4732 return TRUE; 4728 return TRUE;
4733 } 4729 }
4734 CXFA_Node* CXFA_Node::GetFirstChildByName(const CFX_WideStringC& wsName) const { 4730 CXFA_Node* CXFA_Node::GetFirstChildByName(const CFX_WideStringC& wsName) const {
4735 return GetFirstChildByName( 4731 return GetFirstChildByName(FX_HashCode_GetW(wsName, false));
4736 wsName.IsEmpty() ? 0 : FX_HashCode_String_GetW(wsName.c_str(),
4737 wsName.GetLength()));
4738 } 4732 }
4739 CXFA_Node* CXFA_Node::GetFirstChildByName(uint32_t dwNameHash) const { 4733 CXFA_Node* CXFA_Node::GetFirstChildByName(uint32_t dwNameHash) const {
4740 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_FirstChild); pNode; 4734 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_FirstChild); pNode;
4741 pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { 4735 pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
4742 if (pNode->GetNameHash() == dwNameHash) { 4736 if (pNode->GetNameHash() == dwNameHash) {
4743 return pNode; 4737 return pNode;
4744 } 4738 }
4745 } 4739 }
4746 return NULL; 4740 return NULL;
4747 } 4741 }
(...skipping 10 matching lines...) Expand all
4758 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_NextSibling); pNode; 4752 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_NextSibling); pNode;
4759 pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { 4753 pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
4760 if (pNode->GetNameHash() == dwNameHash) { 4754 if (pNode->GetNameHash() == dwNameHash) {
4761 return pNode; 4755 return pNode;
4762 } 4756 }
4763 } 4757 }
4764 return NULL; 4758 return NULL;
4765 } 4759 }
4766 CXFA_Node* CXFA_Node::GetNextSameNameSibling( 4760 CXFA_Node* CXFA_Node::GetNextSameNameSibling(
4767 const CFX_WideStringC& wsNodeName) const { 4761 const CFX_WideStringC& wsNodeName) const {
4768 return GetNextSameNameSibling( 4762 return GetNextSameNameSibling(FX_HashCode_GetW(wsNodeName, false));
4769 wsNodeName.IsEmpty() ? 0
4770 : FX_HashCode_String_GetW(wsNodeName.c_str(),
4771 wsNodeName.GetLength()));
4772 } 4763 }
4773 CXFA_Node* CXFA_Node::GetNextSameClassSibling(XFA_ELEMENT eElement) const { 4764 CXFA_Node* CXFA_Node::GetNextSameClassSibling(XFA_ELEMENT eElement) const {
4774 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_NextSibling); pNode; 4765 for (CXFA_Node* pNode = GetNodeItem(XFA_NODEITEM_NextSibling); pNode;
4775 pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) { 4766 pNode = pNode->GetNodeItem(XFA_NODEITEM_NextSibling)) {
4776 if (pNode->GetClassID() == eElement) { 4767 if (pNode->GetClassID() == eElement) {
4777 return pNode; 4768 return pNode;
4778 } 4769 }
4779 } 4770 }
4780 return NULL; 4771 return NULL;
4781 } 4772 }
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
4944 FALSE, FALSE); 4935 FALSE, FALSE);
4945 } 4936 }
4946 } 4937 }
4947 } 4938 }
4948 } 4939 }
4949 return iRet; 4940 return iRet;
4950 } 4941 }
4951 void CXFA_Node::UpdateNameHash() { 4942 void CXFA_Node::UpdateNameHash() {
4952 const XFA_NOTSUREATTRIBUTE* pNotsure = 4943 const XFA_NOTSUREATTRIBUTE* pNotsure =
4953 XFA_GetNotsureAttribute(GetClassID(), XFA_ATTRIBUTE_Name); 4944 XFA_GetNotsureAttribute(GetClassID(), XFA_ATTRIBUTE_Name);
4945 CFX_WideStringC wsName;
4954 if (!pNotsure || pNotsure->eType == XFA_ATTRIBUTETYPE_Cdata) { 4946 if (!pNotsure || pNotsure->eType == XFA_ATTRIBUTETYPE_Cdata) {
4955 CFX_WideStringC wsName = GetCData(XFA_ATTRIBUTE_Name); 4947 wsName = GetCData(XFA_ATTRIBUTE_Name);
4956 m_dwNameHash = 4948 m_dwNameHash = FX_HashCode_GetW(wsName, false);
4957 wsName.IsEmpty() ? 0 : FX_HashCode_String_GetW(wsName.c_str(),
4958 wsName.GetLength());
4959 } else if (pNotsure->eType == XFA_ATTRIBUTETYPE_Enum) { 4949 } else if (pNotsure->eType == XFA_ATTRIBUTETYPE_Enum) {
4960 CFX_WideStringC wsName = 4950 wsName = XFA_GetAttributeEnumByID(GetEnum(XFA_ATTRIBUTE_Name))->pName;
4961 XFA_GetAttributeEnumByID(GetEnum(XFA_ATTRIBUTE_Name))->pName; 4951 m_dwNameHash = FX_HashCode_GetW(wsName, false);
4962 m_dwNameHash =
4963 wsName.IsEmpty() ? 0 : FX_HashCode_String_GetW(wsName.c_str(),
4964 wsName.GetLength());
4965 } 4952 }
4966 } 4953 }
4967 CFDE_XMLNode* CXFA_Node::CreateXMLMappingNode() { 4954 CFDE_XMLNode* CXFA_Node::CreateXMLMappingNode() {
4968 if (!m_pXMLNode) { 4955 if (!m_pXMLNode) {
4969 CFX_WideStringC wsTag = GetCData(XFA_ATTRIBUTE_Name); 4956 CFX_WideStringC wsTag = GetCData(XFA_ATTRIBUTE_Name);
4970 m_pXMLNode = new CFDE_XMLElement(wsTag); 4957 m_pXMLNode = new CFDE_XMLElement(wsTag);
4971 SetFlag(XFA_NODEFLAG_OwnXMLNode, false); 4958 SetFlag(XFA_NODEFLAG_OwnXMLNode, false);
4972 } 4959 }
4973 return m_pXMLNode; 4960 return m_pXMLNode;
4974 } 4961 }
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
5226 MoveBufferMapData(pSrcChild, pDstChild, pKey, TRUE); 5213 MoveBufferMapData(pSrcChild, pDstChild, pKey, TRUE);
5227 } 5214 }
5228 } 5215 }
5229 pSrcModule->MoveBufferMapData(pDstModule, pKey); 5216 pSrcModule->MoveBufferMapData(pDstModule, pKey);
5230 } 5217 }
5231 CXFA_NodeList::CXFA_NodeList(CXFA_Document* pDocument) 5218 CXFA_NodeList::CXFA_NodeList(CXFA_Document* pDocument)
5232 : CXFA_Object(pDocument, XFA_OBJECTTYPE_NodeList) { 5219 : CXFA_Object(pDocument, XFA_OBJECTTYPE_NodeList) {
5233 m_pDocument->GetScriptContext()->CacheList(this); 5220 m_pDocument->GetScriptContext()->CacheList(this);
5234 } 5221 }
5235 CXFA_Node* CXFA_NodeList::NamedItem(const CFX_WideStringC& wsName) { 5222 CXFA_Node* CXFA_NodeList::NamedItem(const CFX_WideStringC& wsName) {
5223 uint32_t dwHashCode = FX_HashCode_GetW(wsName, false);
5236 int32_t iCount = GetLength(); 5224 int32_t iCount = GetLength();
5237 uint32_t dwHashCode =
5238 FX_HashCode_String_GetW(wsName.c_str(), wsName.GetLength());
5239 for (int32_t i = 0; i < iCount; i++) { 5225 for (int32_t i = 0; i < iCount; i++) {
5240 CXFA_Node* ret = Item(i); 5226 CXFA_Node* ret = Item(i);
5241 if (dwHashCode == ret->GetNameHash()) { 5227 if (dwHashCode == ret->GetNameHash())
5242 return ret; 5228 return ret;
5243 }
5244 } 5229 }
5245 return NULL; 5230 return NULL;
5246 } 5231 }
5247 void CXFA_NodeList::Script_ListClass_Append(CFXJSE_Arguments* pArguments) { 5232 void CXFA_NodeList::Script_ListClass_Append(CFXJSE_Arguments* pArguments) {
5248 int32_t argc = pArguments->GetLength(); 5233 int32_t argc = pArguments->GetLength();
5249 if (argc == 1) { 5234 if (argc == 1) {
5250 CXFA_Node* pNode = static_cast<CXFA_Node*>(pArguments->GetObject(0)); 5235 CXFA_Node* pNode = static_cast<CXFA_Node*>(pArguments->GetObject(0));
5251 if (pNode) { 5236 if (pNode) {
5252 Append(pNode); 5237 Append(pNode);
5253 } else { 5238 } else {
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
5395 return m_pAttachNode->InsertChild(pNewNode, pBeforeNode); 5380 return m_pAttachNode->InsertChild(pNewNode, pBeforeNode);
5396 } 5381 }
5397 FX_BOOL CXFA_AttachNodeList::Remove(CXFA_Node* pNode) { 5382 FX_BOOL CXFA_AttachNodeList::Remove(CXFA_Node* pNode) {
5398 return m_pAttachNode->RemoveChild(pNode); 5383 return m_pAttachNode->RemoveChild(pNode);
5399 } 5384 }
5400 CXFA_Node* CXFA_AttachNodeList::Item(int32_t iIndex) { 5385 CXFA_Node* CXFA_AttachNodeList::Item(int32_t iIndex) {
5401 return m_pAttachNode->GetChild( 5386 return m_pAttachNode->GetChild(
5402 iIndex, XFA_ELEMENT_UNKNOWN, 5387 iIndex, XFA_ELEMENT_UNKNOWN,
5403 m_pAttachNode->GetClassID() == XFA_ELEMENT_Subform); 5388 m_pAttachNode->GetClassID() == XFA_ELEMENT_Subform);
5404 } 5389 }
OLDNEW
« no previous file with comments | « xfa/fxfa/parser/xfa_document_imp.cpp ('k') | xfa/fxfa/parser/xfa_script_imp.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698