From cbfef5772c52fbd3378905a61fc9432da1515433 Mon Sep 17 00:00:00 2001 From: dsinclair Date: Wed, 18 May 2016 13:16:12 -0700 Subject: Cleanup XFA_HASHCODE usage. This CL cleans up several uses of XFA_HASHCODE. The defines have been converted into an enum. For the SavePackage call the type is now used as the param instead of a string. The callers pass in the correct type instead of doing an internal conversion. The GetXFAObject accepting a string was removed as it was unused. The other variant was changed to accept the XFA_HashCode type instead of uint32_t. GetPackageData was removed as it is unused. Review-Url: https://codereview.chromium.org/1989313002 --- fpdfsdk/fpdfsave.cpp | 8 +-- fpdfsdk/fpdfxfa/fpdfxfa_doc.cpp | 26 ++++------ xfa/fxfa/app/xfa_ffdoc.cpp | 29 +++-------- xfa/fxfa/include/fxfa_basic.h | 60 ++++++++++++---------- xfa/fxfa/include/xfa_ffdoc.h | 8 +-- xfa/fxfa/parser/xfa_document.h | 3 +- .../parser/xfa_document_datadescription_imp.cpp | 2 - xfa/fxfa/parser/xfa_document_imp.cpp | 7 ++- xfa/fxfa/parser/xfa_document_serialize.cpp | 2 +- xfa/fxfa/parser/xfa_script_imp.cpp | 3 +- xfa/fxfa/parser/xfa_script_resolveprocessor.cpp | 17 +++--- xfa/fxfa/parser/xfa_script_resolveprocessor.h | 4 +- 12 files changed, 78 insertions(+), 91 deletions(-) diff --git a/fpdfsdk/fpdfsave.cpp b/fpdfsdk/fpdfsave.cpp index 84de668dde..7b08194bf4 100644 --- a/fpdfsdk/fpdfsave.cpp +++ b/fpdfsdk/fpdfsave.cpp @@ -174,8 +174,8 @@ bool SaveXFADocumentData(CPDFXFA_Document* pDocument, // L"datasets" { ScopedFileStream pDsfileWrite(FX_CreateMemoryStream()); - if (pXFADocView->GetDoc()->SavePackage(CFX_WideStringC(L"datasets"), - pDsfileWrite.get()) && + if (pXFADocView->GetDoc()->SavePackage(XFA_HASHCODE_Datasets, + pDsfileWrite.get(), nullptr) && pDsfileWrite->GetSize() > 0) { // Datasets pContext->UpdateChecksum(pDsfileWrite.get()); @@ -198,8 +198,8 @@ bool SaveXFADocumentData(CPDFXFA_Document* pDocument, // L"form" { ScopedFileStream pfileWrite(FX_CreateMemoryStream()); - if (pXFADocView->GetDoc()->SavePackage(CFX_WideStringC(L"form"), - pfileWrite.get(), pContext.get()) && + if (pXFADocView->GetDoc()->SavePackage(XFA_HASHCODE_Form, pfileWrite.get(), + pContext.get()) && pfileWrite->GetSize() > 0) { CPDF_Dictionary* pDataDict = new CPDF_Dictionary; if (iFormIndex != -1) { diff --git a/fpdfsdk/fpdfxfa/fpdfxfa_doc.cpp b/fpdfsdk/fpdfxfa/fpdfxfa_doc.cpp index 29d3d5fc0a..85a1f16f5d 100644 --- a/fpdfsdk/fpdfxfa/fpdfxfa_doc.cpp +++ b/fpdfsdk/fpdfxfa/fpdfxfa_doc.cpp @@ -660,10 +660,8 @@ void CPDFXFA_Document::ExportData(CXFA_FFDoc* hDoc, content = "\r\n"; fileWrite.WriteBlock(content.c_str(), fileWrite.GetSize(), content.GetLength()); - CFX_WideStringC data(L"data"); - if (m_pXFADocView->GetDoc()->SavePackage(data, &fileWrite)) { - // Ignoring error. - } + m_pXFADocView->GetDoc()->SavePackage(XFA_HASHCODE_Data, &fileWrite, + nullptr); } else if (fileType == FXFA_SAVEAS_XDP) { if (m_pPDFDoc == NULL) return; @@ -693,11 +691,11 @@ void CPDFXFA_Document::ExportData(CXFA_FFDoc* hDoc, if (!pDirectObj->IsStream()) continue; if (pPrePDFObj->GetString() == "form") { - CFX_WideStringC form(L"form"); - m_pXFADocView->GetDoc()->SavePackage(form, &fileWrite); + m_pXFADocView->GetDoc()->SavePackage(XFA_HASHCODE_Form, &fileWrite, + nullptr); } else if (pPrePDFObj->GetString() == "datasets") { - CFX_WideStringC datasets(L"datasets"); - m_pXFADocView->GetDoc()->SavePackage(datasets, &fileWrite); + m_pXFADocView->GetDoc()->SavePackage(XFA_HASHCODE_Datasets, &fileWrite, + nullptr); } else { if (i == size - 1) { CFX_WideString wPath = CFX_WideString::FromUTF16LE( @@ -954,11 +952,9 @@ FX_BOOL CPDFXFA_Document::_ExportSubmitFile(FPDF_FILEHANDLER* pFileHandler, CFPDF_FileStream fileStream(pFileHandler); if (fileType == FXFA_SAVEAS_XML) { - CFX_WideString ws; - ws.FromLocal("data"); const char* content = "\r\n"; fileStream.WriteBlock(content, 0, strlen(content)); - m_pXFADoc->SavePackage(ws.AsStringC(), &fileStream); + m_pXFADoc->SavePackage(XFA_HASHCODE_Data, &fileStream, nullptr); } else if (fileType == FXFA_SAVEAS_XDP) { if (flag == 0) flag = FXFA_CONFIG | FXFA_TEMPLATE | FXFA_LOCALESET | FXFA_DATASETS | @@ -1017,13 +1013,9 @@ FX_BOOL CPDFXFA_Document::_ExportSubmitFile(FPDF_FILEHANDLER* pFileHandler, if (pPrePDFObj->GetString() == "form" && !(flag & FXFA_FORM)) continue; if (pPrePDFObj->GetString() == "form") { - CFX_WideString ws; - ws.FromLocal("form"); - m_pXFADoc->SavePackage(ws.AsStringC(), &fileStream); + m_pXFADoc->SavePackage(XFA_HASHCODE_Form, &fileStream, nullptr); } else if (pPrePDFObj->GetString() == "datasets") { - CFX_WideString ws; - ws.FromLocal("datasets"); - m_pXFADoc->SavePackage(ws.AsStringC(), &fileStream); + m_pXFADoc->SavePackage(XFA_HASHCODE_Datasets, &fileStream, nullptr); } else { // PDF,creator. } diff --git a/xfa/fxfa/app/xfa_ffdoc.cpp b/xfa/fxfa/app/xfa_ffdoc.cpp index 8621430d3f..f93881564d 100644 --- a/xfa/fxfa/app/xfa_ffdoc.cpp +++ b/xfa/fxfa/app/xfa_ffdoc.cpp @@ -351,36 +351,23 @@ CFX_DIBitmap* CXFA_FFDoc::GetPDFNamedImage(const CFX_WideStringC& wsName, return pDibSource; } -CFDE_XMLElement* CXFA_FFDoc::GetPackageData(const CFX_WideStringC& wsPackage) { - uint32_t packetHash = FX_HashCode_GetW(wsPackage, false); - CXFA_Node* pNode = ToNode(m_pDocument->GetXFAObject(packetHash)); - if (!pNode) { - return NULL; - } - CFDE_XMLNode* pXMLNode = pNode->GetXMLMappingNode(); - return (pXMLNode && pXMLNode->GetType() == FDE_XMLNODE_Element) - ? static_cast(pXMLNode) - : NULL; -} - -FX_BOOL CXFA_FFDoc::SavePackage(const CFX_WideStringC& wsPackage, - IFX_FileWrite* pFile, - CXFA_ChecksumContext* pCSContext) { +bool CXFA_FFDoc::SavePackage(XFA_HashCode code, + IFX_FileWrite* pFile, + CXFA_ChecksumContext* pCSContext) { std::unique_ptr pExport( new CXFA_DataExporter(m_pDocument)); - uint32_t packetHash = FX_HashCode_GetW(wsPackage, false); - CXFA_Node* pNode = packetHash == XFA_HASHCODE_Xfa + CXFA_Node* pNode = code == XFA_HASHCODE_Xfa ? m_pDocument->GetRoot() - : ToNode(m_pDocument->GetXFAObject(packetHash)); + : ToNode(m_pDocument->GetXFAObject(code)); if (!pNode) - return pExport->Export(pFile); + return !!pExport->Export(pFile); CFX_ByteString bsChecksum; if (pCSContext) bsChecksum = pCSContext->GetChecksum(); - return pExport->Export(pFile, pNode, 0, - bsChecksum.GetLength() ? bsChecksum.c_str() : nullptr); + return !!pExport->Export( + pFile, pNode, 0, bsChecksum.GetLength() ? bsChecksum.c_str() : nullptr); } FX_BOOL CXFA_FFDoc::ImportData(IFX_FileRead* pStream, FX_BOOL bXDP) { diff --git a/xfa/fxfa/include/fxfa_basic.h b/xfa/fxfa/include/fxfa_basic.h index 30b7b6bdfe..f5f52c7a7f 100644 --- a/xfa/fxfa/include/fxfa_basic.h +++ b/xfa/fxfa/include/fxfa_basic.h @@ -11,32 +11,39 @@ #include "xfa/fxjse/include/fxjse.h" class CXFA_Measurement; -#define XFA_HASHCODE_Xfa 0xc56b9ff -#define XFA_HASHCODE_Config 0x4e1e39b6 -#define XFA_HASHCODE_Template 0x803550fc -#define XFA_HASHCODE_Datasets 0x99b95079 -#define XFA_HASHCODE_Data 0xbde9abda -#define XFA_HASHCODE_Form 0xcd309ff4 -#define XFA_HASHCODE_LocaleSet 0x5473b6dc -#define XFA_HASHCODE_ConnectionSet 0xe14c801c -#define XFA_HASHCODE_SourceSet 0x811929d -#define XFA_HASHCODE_Xdc 0xc56afbf -#define XFA_HASHCODE_Pdf 0xb843dba -#define XFA_HASHCODE_Xfdf 0x48d004a8 -#define XFA_HASHCODE_Xmpmeta 0x132a8fbc -#define XFA_HASHCODE_Signature 0x8b036f32 -#define XFA_HASHCODE_Stylesheet 0x6038580a -#define XFA_HASHCODE_XDP 0xc56afcc -#define XFA_HASHCODE_Record 0x5779d65f -#define XFA_HASHCODE_DataWindow 0x83a550d2 -#define XFA_HASHCODE_Host 0xdb075bde -#define XFA_HASHCODE_Log 0x0b1b3d22 -#define XFA_HASHCODE_Event 0x185e41e2 -#define XFA_HASHCODE_Layout 0x7e7e845e -#define XFA_HASHCODE_Occur 0xf7eebe1c -#define XFA_HASHCODE_This 0x2d574d58 -#define XFA_HASHCODE_DataDescription 0x2b5df51e -#define XFA_HASHCODE_Name 0x31b19c1 + +enum XFA_HashCode : uint32_t { + XFA_HASHCODE_None = 0, + + XFA_HASHCODE_Config = 0x4e1e39b6, + XFA_HASHCODE_ConnectionSet = 0xe14c801c, + XFA_HASHCODE_Data = 0xbde9abda, + XFA_HASHCODE_DataDescription = 0x2b5df51e, + XFA_HASHCODE_Datasets = 0x99b95079, + XFA_HASHCODE_DataWindow = 0x83a550d2, + XFA_HASHCODE_Event = 0x185e41e2, + XFA_HASHCODE_Form = 0xcd309ff4, + XFA_HASHCODE_Group = 0xf7f75fcd, + XFA_HASHCODE_Host = 0xdb075bde, + XFA_HASHCODE_Layout = 0x7e7e845e, + XFA_HASHCODE_LocaleSet = 0x5473b6dc, + XFA_HASHCODE_Log = 0x0b1b3d22, + XFA_HASHCODE_Name = 0x31b19c1, + XFA_HASHCODE_Occur = 0xf7eebe1c, + XFA_HASHCODE_Pdf = 0xb843dba, + XFA_HASHCODE_Record = 0x5779d65f, + XFA_HASHCODE_Signature = 0x8b036f32, + XFA_HASHCODE_SourceSet = 0x811929d, + XFA_HASHCODE_Stylesheet = 0x6038580a, + XFA_HASHCODE_Template = 0x803550fc, + XFA_HASHCODE_This = 0x2d574d58, + XFA_HASHCODE_Xdc = 0xc56afbf, + XFA_HASHCODE_XDP = 0xc56afcc, + XFA_HASHCODE_Xfa = 0xc56b9ff, + XFA_HASHCODE_Xfdf = 0x48d004a8, + XFA_HASHCODE_Xmpmeta = 0x132a8fbc +}; + enum XFA_PACKET { XFA_PACKET_USER, XFA_PACKET_SourceSet, @@ -54,6 +61,7 @@ enum XFA_PACKET { XFA_PACKET_Form, XFA_PACKET_ConnectionSet, }; + enum XFA_XDPPACKET { XFA_XDPPACKET_UNKNOWN = 0, XFA_XDPPACKET_Config = 1 << XFA_PACKET_Config, diff --git a/xfa/fxfa/include/xfa_ffdoc.h b/xfa/fxfa/include/xfa_ffdoc.h index 2569b505ff..af1f8d79cf 100644 --- a/xfa/fxfa/include/xfa_ffdoc.h +++ b/xfa/fxfa/include/xfa_ffdoc.h @@ -46,10 +46,10 @@ class CXFA_FFDoc { CFX_DIBitmap* GetPDFNamedImage(const CFX_WideStringC& wsName, int32_t& iImageXDpi, int32_t& iImageYDpi); - CFDE_XMLElement* GetPackageData(const CFX_WideStringC& wsPackage); - FX_BOOL SavePackage(const CFX_WideStringC& wsPackage, - IFX_FileWrite* pFile, - CXFA_ChecksumContext* pCSContext = NULL); + + bool SavePackage(XFA_HashCode code, + IFX_FileWrite* pFile, + CXFA_ChecksumContext* pCSContext); FX_BOOL ImportData(IFX_FileRead* pStream, FX_BOOL bXDP = TRUE); protected: diff --git a/xfa/fxfa/parser/xfa_document.h b/xfa/fxfa/parser/xfa_document.h index 86b2a6f62c..5279d3a995 100644 --- a/xfa/fxfa/parser/xfa_document.h +++ b/xfa/fxfa/parser/xfa_document.h @@ -65,8 +65,7 @@ class CXFA_Document { CXFA_DocumentParser* GetParser() const { return m_pParser; } CXFA_FFNotify* GetNotify() const; void SetRoot(CXFA_Node* pNewRoot); - CXFA_Object* GetXFAObject(const CFX_WideStringC& wsNodeName); - CXFA_Object* GetXFAObject(uint32_t wsNodeNameHash); + CXFA_Object* GetXFAObject(XFA_HashCode wsNodeNameHash); void AddPurgeNode(CXFA_Node* pNode); FX_BOOL RemovePurgeNode(CXFA_Node* pNode); void PurgeNodes(); diff --git a/xfa/fxfa/parser/xfa_document_datadescription_imp.cpp b/xfa/fxfa/parser/xfa_document_datadescription_imp.cpp index 31cf4119ad..27d89b4146 100644 --- a/xfa/fxfa/parser/xfa_document_datadescription_imp.cpp +++ b/xfa/fxfa/parser/xfa_document_datadescription_imp.cpp @@ -13,8 +13,6 @@ #include "xfa/fxfa/parser/xfa_script.h" #include "xfa/fxfa/parser/xfa_utils.h" -#define XFA_HASHCODE_Group 0xf7f75fcd - class CXFA_TraverseStrategy_DDGroup { public: static inline CXFA_Node* GetFirstChild(CXFA_Node* pDDGroupNode) { diff --git a/xfa/fxfa/parser/xfa_document_imp.cpp b/xfa/fxfa/parser/xfa_document_imp.cpp index 0421683e07..c6f9295dcc 100644 --- a/xfa/fxfa/parser/xfa_document_imp.cpp +++ b/xfa/fxfa/parser/xfa_document_imp.cpp @@ -77,13 +77,12 @@ void CXFA_Document::SetRoot(CXFA_Node* pNewRoot) { m_pRootNode = pNewRoot; RemovePurgeNode(pNewRoot); } + CXFA_FFNotify* CXFA_Document::GetNotify() const { return m_pParser->GetNotify(); } -CXFA_Object* CXFA_Document::GetXFAObject(const CFX_WideStringC& wsNodeName) { - return GetXFAObject(FX_HashCode_GetW(wsNodeName, false)); -} -CXFA_Object* CXFA_Document::GetXFAObject(uint32_t dwNodeNameHash) { + +CXFA_Object* CXFA_Document::GetXFAObject(XFA_HashCode dwNodeNameHash) { switch (dwNodeNameHash) { case XFA_HASHCODE_Data: { CXFA_Node* pDatasetsNode = ToNode(GetXFAObject(XFA_HASHCODE_Datasets)); diff --git a/xfa/fxfa/parser/xfa_document_serialize.cpp b/xfa/fxfa/parser/xfa_document_serialize.cpp index ef85d0e266..96c70cb3fc 100644 --- a/xfa/fxfa/parser/xfa_document_serialize.cpp +++ b/xfa/fxfa/parser/xfa_document_serialize.cpp @@ -443,7 +443,7 @@ void XFA_DataExporter_RegenerateFormFile(CXFA_Node* pNode, pStream->WriteString(pURI, FXSYS_wcslen(pURI)); CFX_WideString wsVersionNumber; XFA_DataExporter_RecognizeXFAVersionNumber( - ToNode(pNode->GetDocument()->GetXFAObject(XFA_XDPPACKET_Template)), + ToNode(pNode->GetDocument()->GetXFAObject(XFA_HASHCODE_Template)), wsVersionNumber); if (wsVersionNumber.IsEmpty()) { wsVersionNumber = FX_WSTRC(L"2.8"); diff --git a/xfa/fxfa/parser/xfa_script_imp.cpp b/xfa/fxfa/parser/xfa_script_imp.cpp index 893c5b79ea..b218121165 100644 --- a/xfa/fxfa/parser/xfa_script_imp.cpp +++ b/xfa/fxfa/parser/xfa_script_imp.cpp @@ -174,7 +174,8 @@ void CXFA_ScriptContext::GlobalPropertyGetter(FXJSE_HOBJECT hObject, XFA_FM2JS_GlobalPropertyGetter(lpScriptContext->m_hFM2JSContext, hValue); return; } - uint32_t uHashCode = FX_HashCode_GetW(wsPropName.AsStringC(), false); + XFA_HashCode uHashCode = static_cast( + FX_HashCode_GetW(wsPropName.AsStringC(), false)); if (uHashCode != XFA_HASHCODE_Layout) { CXFA_Object* pObject = lpScriptContext->GetDocument()->GetXFAObject(uHashCode); diff --git a/xfa/fxfa/parser/xfa_script_resolveprocessor.cpp b/xfa/fxfa/parser/xfa_script_resolveprocessor.cpp index fa21a50b3e..138ac66165 100644 --- a/xfa/fxfa/parser/xfa_script_resolveprocessor.cpp +++ b/xfa/fxfa/parser/xfa_script_resolveprocessor.cpp @@ -49,7 +49,7 @@ int32_t CXFA_ResolveProcessor::XFA_ResolveNodes(CXFA_ResolveNodesData& rnd) { return XFA_ResolveNodes_NumberSign(rnd); case '*': return XFA_ResolveNodes_Asterisk(rnd); - // TODO(dsinclair@chromium.org): We could probably remove this. + // TODO(dsinclair): We could probably remove this. case '.': return XFA_ResolveNodes_AnyChild(rnd); default: @@ -119,8 +119,8 @@ int32_t CXFA_ResolveProcessor::XFA_ResolveNodes_Dollar( if (rnd.m_nLevel > 0) { return -1; } - uint32_t dwNameHash = FX_HashCode_GetW( - CFX_WideStringC(wsName.c_str() + 1, iNameLen - 1), false); + 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 { @@ -148,7 +148,8 @@ int32_t CXFA_ResolveProcessor::XFA_ResolveNodes_Excalmatory( 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 = FX_HashCode_GetW(rndFind.m_wsName.AsStringC(), false); + 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; @@ -174,7 +175,8 @@ int32_t CXFA_ResolveProcessor::XFA_ResolveNodes_NumberSign( rndFind.m_dwStyles |= XFA_RESOLVENODE_TagName; rndFind.m_dwStyles &= ~XFA_RESOLVENODE_Attributes; rndFind.m_wsName = wsName; - rndFind.m_uHashName = FX_HashCode_GetW(rndFind.m_wsName.AsStringC(), false); + rndFind.m_uHashName = static_cast( + FX_HashCode_GetW(rndFind.m_wsName.AsStringC(), false)); rndFind.m_wsCondition = wsCondition; rndFind.m_CurNode = curNode; XFA_ResolveNodes_Normal(rndFind); @@ -215,7 +217,7 @@ int32_t CXFA_ResolveProcessor::XFA_ResolveNodes_Normal( int32_t nNum = nodes.GetSize(); uint32_t dwStyles = rnd.m_dwStyles; CFX_WideString& wsName = rnd.m_wsName; - uint32_t uNameHash = rnd.m_uHashName; + XFA_HashCode uNameHash = rnd.m_uHashName; CFX_WideString& wsCondition = rnd.m_wsCondition; CXFA_ResolveNodesData rndFind; rndFind.m_wsName = rnd.m_wsName; @@ -612,7 +614,8 @@ int32_t CXFA_ResolveProcessor::XFA_ResolveNodes_GetFilter( wsCondition.ReleaseBuffer(nConditionCount); wsCondition.TrimLeft(); wsCondition.TrimRight(); - rnd.m_uHashName = FX_HashCode_GetW(wsName.AsStringC(), false); + rnd.m_uHashName = + static_cast(FX_HashCode_GetW(wsName.AsStringC(), false)); return nStart; } void CXFA_ResolveProcessor::XFA_ResolveNode_ConditionArray( diff --git a/xfa/fxfa/parser/xfa_script_resolveprocessor.h b/xfa/fxfa/parser/xfa_script_resolveprocessor.h index b63cced721..9789ffd7b8 100644 --- a/xfa/fxfa/parser/xfa_script_resolveprocessor.h +++ b/xfa/fxfa/parser/xfa_script_resolveprocessor.h @@ -19,7 +19,7 @@ class CXFA_ResolveNodesData { : m_pSC(pSC), m_CurNode(NULL), m_wsName(), - m_uHashName(0), + m_uHashName(XFA_HASHCODE_None), m_wsCondition(), m_nLevel(0), m_Nodes(), @@ -30,7 +30,7 @@ class CXFA_ResolveNodesData { CXFA_ScriptContext* m_pSC; CXFA_Object* m_CurNode; CFX_WideString m_wsName; - uint32_t m_uHashName; + XFA_HashCode m_uHashName; CFX_WideString m_wsCondition; int32_t m_nLevel; CXFA_ObjArray m_Nodes; -- cgit v1.2.3