From 219e462c2a0bb9a5462c0ee43ec93ac86c9cda40 Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Thu, 22 Jan 2015 16:57:58 -0800 Subject: Use IPDF_DataAvail interface to hide CPDF_DataAvail. Currently, no callers go through the Interface, which makes having a separate interface class kind of pointless. After converting callers away from using the CPDF_DataAvail concrete class, it can be moved from the header to the .cpp file. R=bo_xu@foxitsoftware.com Review URL: https://codereview.chromium.org/873523002 --- core/include/fpdfapi/fpdf_parser.h | 215 +-------------------- .../src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp | 202 ++++++++++++++++++- fpdfsdk/src/fpdf_dataavail.cpp | 4 +- 3 files changed, 212 insertions(+), 209 deletions(-) diff --git a/core/include/fpdfapi/fpdf_parser.h b/core/include/fpdfapi/fpdf_parser.h index d2fdad4cfb..3f9bda5ad8 100644 --- a/core/include/fpdfapi/fpdf_parser.h +++ b/core/include/fpdfapi/fpdf_parser.h @@ -869,21 +869,25 @@ public: class IPDF_DataAvail { public: + static IPDF_DataAvail* Create(IFX_FileAvail* pFileAvail, IFX_FileRead* pFileRead); virtual ~IPDF_DataAvail() { } - virtual FX_BOOL IsDocAvail(IFX_DownloadHints* pHints) = 0; + IFX_FileAvail* GetFileAvail() const { return m_pFileAvail; } + IFX_FileRead* GetFileRead() const { return m_pFileRead; } + virtual FX_BOOL IsDocAvail(IFX_DownloadHints* pHints) = 0; virtual void SetDocument(CPDF_Document* pDoc) = 0; - virtual FX_BOOL IsPageAvail(int iPage, IFX_DownloadHints* pHints) = 0; - virtual FX_BOOL IsLinearized() = 0; - virtual FX_INT32 IsFormAvail(IFX_DownloadHints *pHints) = 0; - virtual FX_INT32 IsLinearizedPDF() = 0; - virtual void GetLinearizedMainXRefInfo(FX_FILESIZE *pPos, FX_DWORD *pSize) = 0; + +protected: + IPDF_DataAvail(IFX_FileAvail* pFileAvail, IFX_FileRead* pFileRead); + + IFX_FileAvail* m_pFileAvail; + IFX_FileRead* m_pFileRead; }; class CPDF_SortObjNumArray : public CFX_Object { @@ -942,203 +946,4 @@ enum PDF_DATAAVAIL_STATUS { PDF_DATAAVAIL_LOADALLFILE, PDF_DATAAVAIL_TRAILER_APPEND }; -class CPDF_DataAvail FX_FINAL : public CFX_Object, public IPDF_DataAvail -{ -public: - - CPDF_DataAvail(IFX_FileAvail* pFileAvail, IFX_FileRead* pFileRead); - ~CPDF_DataAvail(); - - virtual FX_BOOL IsDocAvail(IFX_DownloadHints* pHints) FX_OVERRIDE; - - virtual void SetDocument(CPDF_Document* pDoc) FX_OVERRIDE; - - virtual FX_BOOL IsPageAvail(int iPage, IFX_DownloadHints* pHints) FX_OVERRIDE; - - virtual FX_INT32 IsFormAvail(IFX_DownloadHints *pHints) FX_OVERRIDE; - - virtual FX_INT32 IsLinearizedPDF() FX_OVERRIDE; - - virtual FX_BOOL IsLinearized() FX_OVERRIDE - { - return m_bLinearized; - } - - virtual void GetLinearizedMainXRefInfo(FX_FILESIZE *pPos, FX_DWORD *pSize) FX_OVERRIDE; - IFX_FileRead* GetFileRead() const - { - return m_pFileRead; - } - IFX_FileAvail* GetFileAvail() const - { - return m_pFileAvail; - } -protected: - FX_DWORD GetObjectSize(FX_DWORD objnum, FX_FILESIZE& offset); - FX_BOOL IsObjectsAvail(CFX_PtrArray& obj_array, FX_BOOL bParsePage, IFX_DownloadHints* pHints, CFX_PtrArray &ret_array); - FX_BOOL CheckDocStatus(IFX_DownloadHints *pHints); - FX_BOOL CheckHeader(IFX_DownloadHints* pHints); - FX_BOOL CheckFirstPage(IFX_DownloadHints *pHints); - FX_BOOL CheckEnd(IFX_DownloadHints *pHints); - FX_BOOL CheckCrossRef(IFX_DownloadHints* pHints); - FX_BOOL CheckCrossRefItem(IFX_DownloadHints *pHints); - FX_BOOL CheckTrailer(IFX_DownloadHints* pHints); - FX_BOOL CheckRoot(IFX_DownloadHints* pHints); - FX_BOOL CheckInfo(IFX_DownloadHints* pHints); - FX_BOOL CheckPages(IFX_DownloadHints* pHints); - FX_BOOL CheckPage(IFX_DownloadHints* pHints); - FX_BOOL CheckResources(IFX_DownloadHints* pHints); - FX_BOOL CheckAnnots(IFX_DownloadHints* pHints); - FX_BOOL CheckAcroForm(IFX_DownloadHints* pHints); - FX_BOOL CheckAcroFormSubObject(IFX_DownloadHints* pHints); - FX_BOOL CheckTrailerAppend(IFX_DownloadHints* pHints); - FX_BOOL CheckPageStatus(IFX_DownloadHints* pHints); - FX_BOOL CheckAllCrossRefStream(IFX_DownloadHints *pHints); - - FX_DWORD CheckCrossRefStream(IFX_DownloadHints *pHints, FX_FILESIZE &xref_offset); - FX_BOOL IsLinearizedFile(FX_LPBYTE pData, FX_DWORD dwLen); - void SetStartOffset(FX_FILESIZE dwOffset); - FX_BOOL GetNextToken(CFX_ByteString &token); - FX_BOOL GetNextChar(FX_BYTE &ch); - CPDF_Object * ParseIndirectObjectAt(FX_FILESIZE pos, FX_DWORD objnum); - CPDF_Object * GetObject(FX_DWORD objnum, IFX_DownloadHints* pHints, FX_BOOL *pExistInFile); - FX_BOOL GetPageKids(CPDF_Parser *pParser, CPDF_Object *pPages); - FX_BOOL PreparePageItem(); - FX_BOOL LoadPages(IFX_DownloadHints* pHints); - FX_BOOL LoadAllXref(IFX_DownloadHints* pHints); - FX_BOOL LoadAllFile(IFX_DownloadHints* pHints); - FX_BOOL CheckLinearizedData(IFX_DownloadHints* pHints); - FX_BOOL CheckFileResources(IFX_DownloadHints* pHints); - FX_BOOL CheckPageAnnots(int iPage, IFX_DownloadHints* pHints); - - FX_BOOL CheckLinearizedFirstPage(int iPage, IFX_DownloadHints* pHints); - FX_BOOL HaveResourceAncestor(CPDF_Dictionary *pDict); - FX_BOOL CheckPage(FX_INT32 iPage, IFX_DownloadHints* pHints); - FX_BOOL LoadDocPages(IFX_DownloadHints* pHints); - FX_BOOL LoadDocPage(FX_INT32 iPage, IFX_DownloadHints* pHints); - FX_BOOL CheckPageNode(CPDF_PageNode &pageNodes, FX_INT32 iPage, FX_INT32 &iCount, IFX_DownloadHints* pHints); - FX_BOOL CheckUnkownPageNode(FX_DWORD dwPageNo, CPDF_PageNode *pPageNode, IFX_DownloadHints* pHints); - FX_BOOL CheckArrayPageNode(FX_DWORD dwPageNo, CPDF_PageNode *pPageNode, IFX_DownloadHints* pHints); - FX_BOOL CheckPageCount(IFX_DownloadHints* pHints); - FX_BOOL IsFirstCheck(int iPage); - void ResetFirstCheck(int iPage); - - CPDF_Parser m_parser; - - CPDF_SyntaxParser m_syntaxParser; - - CPDF_Object *m_pRoot; - - FX_DWORD m_dwRootObjNum; - - FX_DWORD m_dwInfoObjNum; - - CPDF_Object *m_pLinearized; - - CPDF_Object *m_pTrailer; - - FX_BOOL m_bDocAvail; - - FX_FILESIZE m_dwHeaderOffset; - - FX_FILESIZE m_dwLastXRefOffset; - - FX_FILESIZE m_dwXRefOffset; - - FX_FILESIZE m_dwTrailerOffset; - - FX_FILESIZE m_dwCurrentOffset; - - PDF_DATAAVAIL_STATUS m_docStatus; - - IFX_FileAvail* m_pFileAvail; - - IFX_FileRead* m_pFileRead; - - FX_FILESIZE m_dwFileLen; - - CPDF_Document* m_pDocument; - - CPDF_SortObjNumArray m_objnum_array; - - CFX_PtrArray m_objs_array; - - FX_FILESIZE m_Pos; - - FX_FILESIZE m_bufferOffset; - - FX_DWORD m_bufferSize; - - CFX_ByteString m_WordBuf; - - FX_BYTE m_WordBuffer[257]; - - FX_DWORD m_WordSize; - - FX_BYTE m_bufferData[512]; - - CFX_FileSizeArray m_CrossOffset; - - CFX_DWordArray m_XRefStreamList; - - CFX_DWordArray m_PageObjList; - - FX_DWORD m_PagesObjNum; - - FX_BOOL m_bLinearized; - - FX_DWORD m_dwFirstPageNo; - - FX_BOOL m_bLinearedDataOK; - - FX_BOOL m_bMainXRefLoadTried; - - FX_BOOL m_bMainXRefLoadedOK; - - FX_BOOL m_bPagesTreeLoad; - - FX_BOOL m_bPagesLoad; - - CPDF_Parser * m_pCurrentParser; - - FX_FILESIZE m_dwCurrentXRefSteam; - - FX_BOOL m_bAnnotsLoad; - - FX_BOOL m_bHaveAcroForm; - - FX_DWORD m_dwAcroFormObjNum; - - FX_BOOL m_bAcroFormLoad; - - CPDF_Object * m_pAcroForm; - - CFX_PtrArray m_arrayAcroforms; - - CPDF_Dictionary * m_pPageDict; - - CPDF_Object * m_pPageResource; - - FX_BOOL m_bNeedDownLoadResource; - - FX_BOOL m_bPageLoadedOK; - - FX_BOOL m_bLinearizedFormParamLoad; - - CFX_PtrArray m_PagesArray; - - FX_DWORD m_dwEncryptObjNum; - - FX_FILESIZE m_dwPrevXRefOffset; - - FX_BOOL m_bTotalLoadPageTree; - - FX_BOOL m_bCurPageDictLoadOK; - - CPDF_PageNode m_pageNodes; - - CFX_CMapDWordToDWord * m_pageMapCheckState; - - CFX_CMapDWordToDWord * m_pagesLoadState; -}; #endif diff --git a/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp b/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp index 08cc9e5b51..f6253757b6 100644 --- a/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp +++ b/core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp @@ -2716,10 +2716,208 @@ void CPDF_SyntaxParser::GetBinary(FX_BYTE* buffer, FX_DWORD size) } } } + +class CPDF_DataAvail FX_FINAL : public CFX_Object, public IPDF_DataAvail +{ +public: + CPDF_DataAvail(IFX_FileAvail* pFileAvail, IFX_FileRead* pFileRead); + ~CPDF_DataAvail(); + + virtual FX_BOOL IsDocAvail(IFX_DownloadHints* pHints) FX_OVERRIDE; + + virtual void SetDocument(CPDF_Document* pDoc) FX_OVERRIDE; + + virtual FX_BOOL IsPageAvail(int iPage, IFX_DownloadHints* pHints) FX_OVERRIDE; + + virtual FX_INT32 IsFormAvail(IFX_DownloadHints *pHints) FX_OVERRIDE; + + virtual FX_INT32 IsLinearizedPDF() FX_OVERRIDE; + + virtual FX_BOOL IsLinearized() FX_OVERRIDE + { + return m_bLinearized; + } + + virtual void GetLinearizedMainXRefInfo(FX_FILESIZE *pPos, FX_DWORD *pSize) FX_OVERRIDE; +protected: + FX_DWORD GetObjectSize(FX_DWORD objnum, FX_FILESIZE& offset); + FX_BOOL IsObjectsAvail(CFX_PtrArray& obj_array, FX_BOOL bParsePage, IFX_DownloadHints* pHints, CFX_PtrArray &ret_array); + FX_BOOL CheckDocStatus(IFX_DownloadHints *pHints); + FX_BOOL CheckHeader(IFX_DownloadHints* pHints); + FX_BOOL CheckFirstPage(IFX_DownloadHints *pHints); + FX_BOOL CheckEnd(IFX_DownloadHints *pHints); + FX_BOOL CheckCrossRef(IFX_DownloadHints* pHints); + FX_BOOL CheckCrossRefItem(IFX_DownloadHints *pHints); + FX_BOOL CheckTrailer(IFX_DownloadHints* pHints); + FX_BOOL CheckRoot(IFX_DownloadHints* pHints); + FX_BOOL CheckInfo(IFX_DownloadHints* pHints); + FX_BOOL CheckPages(IFX_DownloadHints* pHints); + FX_BOOL CheckPage(IFX_DownloadHints* pHints); + FX_BOOL CheckResources(IFX_DownloadHints* pHints); + FX_BOOL CheckAnnots(IFX_DownloadHints* pHints); + FX_BOOL CheckAcroForm(IFX_DownloadHints* pHints); + FX_BOOL CheckAcroFormSubObject(IFX_DownloadHints* pHints); + FX_BOOL CheckTrailerAppend(IFX_DownloadHints* pHints); + FX_BOOL CheckPageStatus(IFX_DownloadHints* pHints); + FX_BOOL CheckAllCrossRefStream(IFX_DownloadHints *pHints); + + FX_DWORD CheckCrossRefStream(IFX_DownloadHints *pHints, FX_FILESIZE &xref_offset); + FX_BOOL IsLinearizedFile(FX_LPBYTE pData, FX_DWORD dwLen); + void SetStartOffset(FX_FILESIZE dwOffset); + FX_BOOL GetNextToken(CFX_ByteString &token); + FX_BOOL GetNextChar(FX_BYTE &ch); + CPDF_Object * ParseIndirectObjectAt(FX_FILESIZE pos, FX_DWORD objnum); + CPDF_Object * GetObject(FX_DWORD objnum, IFX_DownloadHints* pHints, FX_BOOL *pExistInFile); + FX_BOOL GetPageKids(CPDF_Parser *pParser, CPDF_Object *pPages); + FX_BOOL PreparePageItem(); + FX_BOOL LoadPages(IFX_DownloadHints* pHints); + FX_BOOL LoadAllXref(IFX_DownloadHints* pHints); + FX_BOOL LoadAllFile(IFX_DownloadHints* pHints); + FX_BOOL CheckLinearizedData(IFX_DownloadHints* pHints); + FX_BOOL CheckFileResources(IFX_DownloadHints* pHints); + FX_BOOL CheckPageAnnots(int iPage, IFX_DownloadHints* pHints); + + FX_BOOL CheckLinearizedFirstPage(int iPage, IFX_DownloadHints* pHints); + FX_BOOL HaveResourceAncestor(CPDF_Dictionary *pDict); + FX_BOOL CheckPage(FX_INT32 iPage, IFX_DownloadHints* pHints); + FX_BOOL LoadDocPages(IFX_DownloadHints* pHints); + FX_BOOL LoadDocPage(FX_INT32 iPage, IFX_DownloadHints* pHints); + FX_BOOL CheckPageNode(CPDF_PageNode &pageNodes, FX_INT32 iPage, FX_INT32 &iCount, IFX_DownloadHints* pHints); + FX_BOOL CheckUnkownPageNode(FX_DWORD dwPageNo, CPDF_PageNode *pPageNode, IFX_DownloadHints* pHints); + FX_BOOL CheckArrayPageNode(FX_DWORD dwPageNo, CPDF_PageNode *pPageNode, IFX_DownloadHints* pHints); + FX_BOOL CheckPageCount(IFX_DownloadHints* pHints); + FX_BOOL IsFirstCheck(int iPage); + void ResetFirstCheck(int iPage); + + CPDF_Parser m_parser; + + CPDF_SyntaxParser m_syntaxParser; + + CPDF_Object *m_pRoot; + + FX_DWORD m_dwRootObjNum; + + FX_DWORD m_dwInfoObjNum; + + CPDF_Object *m_pLinearized; + + CPDF_Object *m_pTrailer; + + FX_BOOL m_bDocAvail; + + FX_FILESIZE m_dwHeaderOffset; + + FX_FILESIZE m_dwLastXRefOffset; + + FX_FILESIZE m_dwXRefOffset; + + FX_FILESIZE m_dwTrailerOffset; + + FX_FILESIZE m_dwCurrentOffset; + + PDF_DATAAVAIL_STATUS m_docStatus; + + FX_FILESIZE m_dwFileLen; + + CPDF_Document* m_pDocument; + + CPDF_SortObjNumArray m_objnum_array; + + CFX_PtrArray m_objs_array; + + FX_FILESIZE m_Pos; + + FX_FILESIZE m_bufferOffset; + + FX_DWORD m_bufferSize; + + CFX_ByteString m_WordBuf; + + FX_BYTE m_WordBuffer[257]; + + FX_DWORD m_WordSize; + + FX_BYTE m_bufferData[512]; + + CFX_FileSizeArray m_CrossOffset; + + CFX_DWordArray m_XRefStreamList; + + CFX_DWordArray m_PageObjList; + + FX_DWORD m_PagesObjNum; + + FX_BOOL m_bLinearized; + + FX_DWORD m_dwFirstPageNo; + + FX_BOOL m_bLinearedDataOK; + + FX_BOOL m_bMainXRefLoadTried; + + FX_BOOL m_bMainXRefLoadedOK; + + FX_BOOL m_bPagesTreeLoad; + + FX_BOOL m_bPagesLoad; + + CPDF_Parser * m_pCurrentParser; + + FX_FILESIZE m_dwCurrentXRefSteam; + + FX_BOOL m_bAnnotsLoad; + + FX_BOOL m_bHaveAcroForm; + + FX_DWORD m_dwAcroFormObjNum; + + FX_BOOL m_bAcroFormLoad; + + CPDF_Object * m_pAcroForm; + + CFX_PtrArray m_arrayAcroforms; + + CPDF_Dictionary * m_pPageDict; + + CPDF_Object * m_pPageResource; + + FX_BOOL m_bNeedDownLoadResource; + + FX_BOOL m_bPageLoadedOK; + + FX_BOOL m_bLinearizedFormParamLoad; + + CFX_PtrArray m_PagesArray; + + FX_DWORD m_dwEncryptObjNum; + + FX_FILESIZE m_dwPrevXRefOffset; + + FX_BOOL m_bTotalLoadPageTree; + + FX_BOOL m_bCurPageDictLoadOK; + + CPDF_PageNode m_pageNodes; + + CFX_CMapDWordToDWord * m_pageMapCheckState; + + CFX_CMapDWordToDWord * m_pagesLoadState; +}; + +IPDF_DataAvail::IPDF_DataAvail(IFX_FileAvail* pFileAvail, IFX_FileRead* pFileRead) : + m_pFileAvail(pFileAvail), + m_pFileRead(pFileRead) { +} + +// static +IPDF_DataAvail* IPDF_DataAvail::Create(IFX_FileAvail* pFileAvail, IFX_FileRead* pFileRead) +{ + return FX_NEW CPDF_DataAvail(pFileAvail, pFileRead); +} + CPDF_DataAvail::CPDF_DataAvail(IFX_FileAvail* pFileAvail, IFX_FileRead* pFileRead) + : IPDF_DataAvail(pFileAvail, pFileRead) { - m_pFileAvail = pFileAvail; - m_pFileRead = pFileRead; m_Pos = 0; m_dwFileLen = 0; if (m_pFileRead) { diff --git a/fpdfsdk/src/fpdf_dataavail.cpp b/fpdfsdk/src/fpdf_dataavail.cpp index b5483f9c39..910221a5de 100644 --- a/fpdfsdk/src/fpdf_dataavail.cpp +++ b/fpdfsdk/src/fpdf_dataavail.cpp @@ -90,7 +90,7 @@ public: if (m_pDataAvail) delete m_pDataAvail; } - CPDF_DataAvail* m_pDataAvail; + IPDF_DataAvail* m_pDataAvail; CFPDF_FileAvailWrap m_FileAvail; CFPDF_FileAccessWrap m_FileRead; }; @@ -100,7 +100,7 @@ DLLEXPORT FPDF_AVAIL STDCALL FPDFAvail_Create(FX_FILEAVAIL* file_avail, FPDF_FIL CFPDF_DataAvail* pAvail = FX_NEW CFPDF_DataAvail; pAvail->m_FileAvail.Set(file_avail); pAvail->m_FileRead.Set(file); - pAvail->m_pDataAvail = FX_NEW CPDF_DataAvail(&pAvail->m_FileAvail, &pAvail->m_FileRead); + pAvail->m_pDataAvail = IPDF_DataAvail::Create(&pAvail->m_FileAvail, &pAvail->m_FileRead); return pAvail; } -- cgit v1.2.3