summaryrefslogtreecommitdiff
path: root/xfa/fxfa/parser
diff options
context:
space:
mode:
authorDan Sinclair <dsinclair@chromium.org>2017-11-30 21:26:51 +0000
committerChromium commit bot <commit-bot@chromium.org>2017-11-30 21:26:51 +0000
commit9daec60824d085db8c2f841fd389c725df1f8b0b (patch)
tree2defab579e0d19a40932780864e1fe30cd5dbb4c /xfa/fxfa/parser
parent8b357e7504ea804293983453540ae91c9fc57922 (diff)
downloadpdfium-9daec60824d085db8c2f841fd389c725df1f8b0b.tar.xz
Cleanup XFA packet code
Remove GetPacketByID, move GetPacketByName to the xfa_utils file. Cleanup CreateNode to accept the XFA_XDPPACKET instead of the packet info. Change-Id: I0f246c84f61b6b4175ca307bdcd125d9bc24bb1e Reviewed-on: https://pdfium-review.googlesource.com/20010 Reviewed-by: Henrique Nakashima <hnakashima@chromium.org> Reviewed-by: Lei Zhang <thestig@chromium.org> Commit-Queue: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'xfa/fxfa/parser')
-rw-r--r--xfa/fxfa/parser/cxfa_document.cpp13
-rw-r--r--xfa/fxfa/parser/cxfa_document.h3
-rw-r--r--xfa/fxfa/parser/cxfa_node.cpp5
-rw-r--r--xfa/fxfa/parser/cxfa_node.h12
-rw-r--r--xfa/fxfa/parser/cxfa_simple_parser.cpp22
-rw-r--r--xfa/fxfa/parser/xfa_utils.cpp17
-rw-r--r--xfa/fxfa/parser/xfa_utils.h2
7 files changed, 27 insertions, 47 deletions
diff --git a/xfa/fxfa/parser/cxfa_document.cpp b/xfa/fxfa/parser/cxfa_document.cpp
index 3fc5c39643..4e230ee87b 100644
--- a/xfa/fxfa/parser/cxfa_document.cpp
+++ b/xfa/fxfa/parser/cxfa_document.cpp
@@ -213,17 +213,14 @@ CXFA_Object* CXFA_Document::GetXFAObject(XFA_HashCode dwNodeNameHash) {
}
}
-CXFA_Node* CXFA_Document::CreateNode(uint32_t dwPacket, XFA_Element eElement) {
- return CreateNode(XFA_GetPacketByID(dwPacket), eElement);
-}
-
-CXFA_Node* CXFA_Document::CreateNode(const XFA_PACKETINFO* pPacket,
+CXFA_Node* CXFA_Document::CreateNode(XFA_XDPPACKET packet,
XFA_Element eElement) {
- if (!pPacket || eElement == XFA_Element::Unknown)
+ if (packet == XFA_XDPPACKET_UNKNOWN || packet >= XFA_XDPPACKET_LAST ||
+ eElement == XFA_Element::Unknown) {
return nullptr;
+ }
- std::unique_ptr<CXFA_Node> pNode =
- CXFA_Node::Create(this, eElement, pPacket->eName);
+ std::unique_ptr<CXFA_Node> pNode = CXFA_Node::Create(this, eElement, packet);
if (!pNode)
return nullptr;
diff --git a/xfa/fxfa/parser/cxfa_document.h b/xfa/fxfa/parser/cxfa_document.h
index 45e9236ee8..82ef661f17 100644
--- a/xfa/fxfa/parser/cxfa_document.h
+++ b/xfa/fxfa/parser/cxfa_document.h
@@ -87,8 +87,7 @@ class CXFA_Document {
XFA_VERSION GetCurVersionMode() { return m_eCurVersionMode; }
XFA_VERSION RecognizeXFAVersionNumber(const WideString& wsTemplateNS);
- CXFA_Node* CreateNode(uint32_t dwPacket, XFA_Element eElement);
- CXFA_Node* CreateNode(const XFA_PACKETINFO* pPacket, XFA_Element eElement);
+ CXFA_Node* CreateNode(XFA_XDPPACKET packet, XFA_Element eElement);
void DoProtoMerge();
void DoDataMerge();
diff --git a/xfa/fxfa/parser/cxfa_node.cpp b/xfa/fxfa/parser/cxfa_node.cpp
index f24bddb990..c8e226633b 100644
--- a/xfa/fxfa/parser/cxfa_node.cpp
+++ b/xfa/fxfa/parser/cxfa_node.cpp
@@ -157,7 +157,7 @@ pdfium::Optional<XFA_ATTRIBUTEENUM> CXFA_Node::NameToAttributeEnum(
}
CXFA_Node::CXFA_Node(CXFA_Document* pDoc,
- uint16_t ePacket,
+ XFA_XDPPACKET ePacket,
uint32_t validPackets,
XFA_ObjectType oType,
XFA_Element eType,
@@ -429,8 +429,7 @@ std::vector<CXFA_Node*> CXFA_Node::GetNodeList(uint32_t dwTypeFilter,
if (!property)
return nodes;
- const XFA_PACKETINFO* pPacket = XFA_GetPacketByID(GetPacketID());
- CXFA_Node* pNewNode = m_pDocument->CreateNode(pPacket, *property);
+ CXFA_Node* pNewNode = m_pDocument->CreateNode(GetPacketID(), *property);
if (pNewNode) {
InsertChild(pNewNode, nullptr);
pNewNode->SetFlag(XFA_NodeFlag_Initialized, true);
diff --git a/xfa/fxfa/parser/cxfa_node.h b/xfa/fxfa/parser/cxfa_node.h
index 3e05f36fab..a2e8b3042c 100644
--- a/xfa/fxfa/parser/cxfa_node.h
+++ b/xfa/fxfa/parser/cxfa_node.h
@@ -84,7 +84,7 @@ class CXFA_Node : public CXFA_Object {
XFA_Attribute GetAttribute(size_t i) const;
XFA_AttributeType GetAttributeType(XFA_Attribute type) const;
- uint32_t GetPacketID() const { return m_ePacket; }
+ XFA_XDPPACKET GetPacketID() const { return m_ePacket; }
void SetFlag(uint32_t dwFlag, bool bNotify);
void ClearFlag(uint32_t dwFlag);
@@ -182,7 +182,7 @@ class CXFA_Node : public CXFA_Object {
protected:
CXFA_Node(CXFA_Document* pDoc,
- uint16_t ePacket,
+ XFA_XDPPACKET ePacket,
uint32_t validPackets,
XFA_ObjectType oType,
XFA_Element eType,
@@ -200,15 +200,15 @@ class CXFA_Node : public CXFA_Object {
pdfium::Optional<void*> GetDefaultValue(XFA_Attribute attr,
XFA_AttributeType eType) const;
- const PropertyData* m_Properties;
- const AttributeData* m_Attributes;
- uint32_t m_ValidPackets;
+ const PropertyData* const m_Properties;
+ const AttributeData* const m_Attributes;
+ const uint32_t m_ValidPackets;
CXFA_Node* m_pNext;
CXFA_Node* m_pChild;
CXFA_Node* m_pLastChild;
CXFA_Node* m_pParent;
CFX_XMLNode* m_pXMLNode;
- uint16_t m_ePacket;
+ const XFA_XDPPACKET m_ePacket;
uint16_t m_uNodeFlags;
uint32_t m_dwNameHash;
CXFA_Node* m_pAuxNode;
diff --git a/xfa/fxfa/parser/cxfa_simple_parser.cpp b/xfa/fxfa/parser/cxfa_simple_parser.cpp
index 453ae8d059..515240341e 100644
--- a/xfa/fxfa/parser/cxfa_simple_parser.cpp
+++ b/xfa/fxfa/parser/cxfa_simple_parser.cpp
@@ -228,26 +228,6 @@ void ConvertXMLToPlainText(CFX_XMLElement* pRootXMLNode, WideString& wsOutput) {
}
}
-const XFA_PACKETINFO* GetPacketByName(const WideStringView& wsName) {
- if (wsName.IsEmpty())
- return nullptr;
-
- uint32_t uHash = FX_HashCode_GetW(wsName, false);
- int32_t iStart = 0;
- int32_t iEnd = g_iXFAPacketCount - 1;
- do {
- int32_t iMid = (iStart + iEnd) / 2;
- const XFA_PACKETINFO* pInfo = g_XFAPacketData + iMid;
- if (uHash == pInfo->uHash)
- return pInfo;
- if (uHash < pInfo->uHash)
- iEnd = iMid - 1;
- else
- iStart = iMid + 1;
- } while (iStart <= iEnd);
- return nullptr;
-}
-
} // namespace
bool XFA_RecognizeRichText(CFX_XMLElement* pRichTextXMLNode) {
@@ -508,7 +488,7 @@ CXFA_Node* CXFA_SimpleParser::ParseAsXDPPacket_XDP(
CFX_XMLElement* pElement = reinterpret_cast<CFX_XMLElement*>(pChildItem);
WideString wsPacketName = pElement->GetLocalTagName();
const XFA_PACKETINFO* pPacketInfo =
- GetPacketByName(wsPacketName.AsStringView());
+ XFA_GetPacketByName(wsPacketName.AsStringView());
if (pPacketInfo && pPacketInfo->pURI) {
if (!MatchNodeName(pElement, pPacketInfo->pName, pPacketInfo->pURI,
pPacketInfo->eFlags)) {
diff --git a/xfa/fxfa/parser/xfa_utils.cpp b/xfa/fxfa/parser/xfa_utils.cpp
index e9315763b7..a7b31aebec 100644
--- a/xfa/fxfa/parser/xfa_utils.cpp
+++ b/xfa/fxfa/parser/xfa_utils.cpp
@@ -190,14 +190,19 @@ const XFA_PACKETINFO* XFA_GetPacketByIndex(XFA_PacketType ePacket) {
return g_XFAPacketData + static_cast<uint8_t>(ePacket);
}
-const XFA_PACKETINFO* XFA_GetPacketByID(uint32_t dwPacket) {
- int32_t iStart = 0, iEnd = g_iXFAPacketCount - 1;
+const XFA_PACKETINFO* XFA_GetPacketByName(const WideStringView& wsName) {
+ if (wsName.IsEmpty())
+ return nullptr;
+
+ uint32_t uHash = FX_HashCode_GetW(wsName, false);
+ int32_t iStart = 0;
+ int32_t iEnd = g_iXFAPacketCount - 1;
do {
int32_t iMid = (iStart + iEnd) / 2;
- uint32_t dwFind = (g_XFAPacketData + iMid)->eName;
- if (dwPacket == dwFind)
- return g_XFAPacketData + iMid;
- if (dwPacket < dwFind)
+ const XFA_PACKETINFO* pInfo = g_XFAPacketData + iMid;
+ if (uHash == pInfo->uHash)
+ return pInfo;
+ if (uHash < pInfo->uHash)
iEnd = iMid - 1;
else
iStart = iMid + 1;
diff --git a/xfa/fxfa/parser/xfa_utils.h b/xfa/fxfa/parser/xfa_utils.h
index 889dcc0f0a..5cd265e2b3 100644
--- a/xfa/fxfa/parser/xfa_utils.h
+++ b/xfa/fxfa/parser/xfa_utils.h
@@ -43,6 +43,6 @@ const XFA_SCRIPTATTRIBUTEINFO* XFA_GetScriptAttributeByName(
const WideStringView& wsAttributeName);
const XFA_PACKETINFO* XFA_GetPacketByIndex(XFA_PacketType ePacket);
-const XFA_PACKETINFO* XFA_GetPacketByID(uint32_t dwPacket);
+const XFA_PACKETINFO* XFA_GetPacketByName(const WideStringView& wsName);
#endif // XFA_FXFA_PARSER_XFA_UTILS_H_