| 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 #ifndef CORE_FPDFAPI_FPDF_PARSER_CPDF_DATA_AVAIL_H_ | 7 #ifndef CORE_FPDFAPI_FPDF_PARSER_INCLUDE_CPDF_DATA_AVAIL_H_ |
| 8 #define CORE_FPDFAPI_FPDF_PARSER_CPDF_DATA_AVAIL_H_ | 8 #define CORE_FPDFAPI_FPDF_PARSER_INCLUDE_CPDF_DATA_AVAIL_H_ |
| 9 | 9 |
| 10 #include "core/fpdfapi/fpdf_parser/cpdf_hint_tables.h" | |
| 11 #include "core/fpdfapi/fpdf_parser/cpdf_syntax_parser.h" | 10 #include "core/fpdfapi/fpdf_parser/cpdf_syntax_parser.h" |
| 12 #include "core/fpdfapi/fpdf_parser/include/cpdf_parser.h" | 11 #include "core/fpdfapi/fpdf_parser/include/cpdf_parser.h" |
| 13 #include "core/fpdfapi/fpdf_parser/include/ipdf_data_avail.h" | |
| 14 #include "core/fxcrt/include/fx_basic.h" | 12 #include "core/fxcrt/include/fx_basic.h" |
| 15 | 13 |
| 16 class CPDF_Dictionary; | 14 class CPDF_Dictionary; |
| 15 class CPDF_HintTables; |
| 17 class CPDF_IndirectObjectHolder; | 16 class CPDF_IndirectObjectHolder; |
| 18 class CPDF_Parser; | 17 class CPDF_Parser; |
| 19 | 18 |
| 20 enum PDF_DATAAVAIL_STATUS { | 19 enum PDF_DATAAVAIL_STATUS { |
| 21 PDF_DATAAVAIL_HEADER = 0, | 20 PDF_DATAAVAIL_HEADER = 0, |
| 22 PDF_DATAAVAIL_FIRSTPAGE, | 21 PDF_DATAAVAIL_FIRSTPAGE, |
| 23 PDF_DATAAVAIL_FIRSTPAGE_PREPARE, | 22 PDF_DATAAVAIL_FIRSTPAGE_PREPARE, |
| 24 PDF_DATAAVAIL_HINTTABLE, | 23 PDF_DATAAVAIL_HINTTABLE, |
| 25 PDF_DATAAVAIL_END, | 24 PDF_DATAAVAIL_END, |
| 26 PDF_DATAAVAIL_CROSSREF, | 25 PDF_DATAAVAIL_CROSSREF, |
| (...skipping 15 matching lines...) Expand all Loading... |
| 42 PDF_DATAAVAIL_TRAILER_APPEND | 41 PDF_DATAAVAIL_TRAILER_APPEND |
| 43 }; | 42 }; |
| 44 | 43 |
| 45 enum PDF_PAGENODE_TYPE { | 44 enum PDF_PAGENODE_TYPE { |
| 46 PDF_PAGENODE_UNKNOWN = 0, | 45 PDF_PAGENODE_UNKNOWN = 0, |
| 47 PDF_PAGENODE_PAGE, | 46 PDF_PAGENODE_PAGE, |
| 48 PDF_PAGENODE_PAGES, | 47 PDF_PAGENODE_PAGES, |
| 49 PDF_PAGENODE_ARRAY, | 48 PDF_PAGENODE_ARRAY, |
| 50 }; | 49 }; |
| 51 | 50 |
| 52 class CPDF_DataAvail final : public IPDF_DataAvail { | 51 class CPDF_DataAvail final { |
| 53 public: | 52 public: |
| 53 // Must match PDF_DATA_* definitions in public/fpdf_dataavail.h, but cannot |
| 54 // #include that header. fpdfsdk/fpdf_dataavail.cpp has static_asserts |
| 55 // to make sure the two sets of values match. |
| 56 enum DocAvailStatus { |
| 57 DataError = -1, // PDF_DATA_ERROR |
| 58 DataNotAvailable = 0, // PDF_DATA_NOTAVAIL |
| 59 DataAvailable = 1, // PDF_DATA_AVAIL |
| 60 }; |
| 61 |
| 62 // Must match PDF_*LINEAR* definitions in public/fpdf_dataavail.h, but cannot |
| 63 // #include that header. fpdfsdk/fpdf_dataavail.cpp has static_asserts |
| 64 // to make sure the two sets of values match. |
| 65 enum DocLinearizationStatus { |
| 66 LinearizationUnknown = -1, // PDF_LINEARIZATION_UNKNOWN |
| 67 NotLinearized = 0, // PDF_NOT_LINEARIZED |
| 68 Linearized = 1, // PDF_LINEARIZED |
| 69 }; |
| 70 |
| 71 // Must match PDF_FORM_* definitions in public/fpdf_dataavail.h, but cannot |
| 72 // #include that header. fpdfsdk/fpdf_dataavail.cpp has static_asserts |
| 73 // to make sure the two sets of values match. |
| 74 enum DocFormStatus { |
| 75 FormError = -1, // PDF_FORM_ERROR |
| 76 FormNotAvailable = 0, // PDF_FORM_NOTAVAIL |
| 77 FormAvailable = 1, // PDF_FORM_AVAIL |
| 78 FormNotExist = 2, // PDF_FORM_NOTEXIST |
| 79 }; |
| 80 |
| 81 class FileAvail { |
| 82 public: |
| 83 virtual ~FileAvail(); |
| 84 virtual FX_BOOL IsDataAvail(FX_FILESIZE offset, uint32_t size) = 0; |
| 85 }; |
| 86 |
| 87 class DownloadHints { |
| 88 public: |
| 89 virtual ~DownloadHints(); |
| 90 virtual void AddSegment(FX_FILESIZE offset, uint32_t size) = 0; |
| 91 }; |
| 92 |
| 54 CPDF_DataAvail(FileAvail* pFileAvail, | 93 CPDF_DataAvail(FileAvail* pFileAvail, |
| 55 IFX_FileRead* pFileRead, | 94 IFX_FileRead* pFileRead, |
| 56 FX_BOOL bSupportHintTable); | 95 FX_BOOL bSupportHintTable); |
| 57 ~CPDF_DataAvail() override; | 96 ~CPDF_DataAvail(); |
| 58 | 97 |
| 59 // IPDF_DataAvail | 98 DocAvailStatus IsDocAvail(DownloadHints* pHints); |
| 60 DocAvailStatus IsDocAvail(DownloadHints* pHints) override; | 99 void SetDocument(CPDF_Document* pDoc); |
| 61 void SetDocument(CPDF_Document* pDoc) override; | 100 DocAvailStatus IsPageAvail(int iPage, DownloadHints* pHints); |
| 62 DocAvailStatus IsPageAvail(int iPage, DownloadHints* pHints) override; | 101 DocFormStatus IsFormAvail(DownloadHints* pHints); |
| 63 DocFormStatus IsFormAvail(DownloadHints* pHints) override; | 102 DocLinearizationStatus IsLinearizedPDF(); |
| 64 DocLinearizationStatus IsLinearizedPDF() override; | 103 FX_BOOL IsLinearized(); |
| 65 FX_BOOL IsLinearized() override; | 104 void GetLinearizedMainXRefInfo(FX_FILESIZE* pPos, uint32_t* pSize); |
| 66 void GetLinearizedMainXRefInfo(FX_FILESIZE* pPos, uint32_t* pSize) override; | 105 IFX_FileRead* GetFileRead() const { return m_pFileRead; } |
| 67 | |
| 68 int GetPageCount() const; | 106 int GetPageCount() const; |
| 69 CPDF_Dictionary* GetPage(int index); | 107 CPDF_Dictionary* GetPage(int index); |
| 70 | 108 |
| 71 friend class CPDF_HintTables; | 109 friend class CPDF_HintTables; |
| 72 | 110 |
| 73 protected: | 111 protected: |
| 74 class PageNode { | 112 class PageNode { |
| 75 public: | 113 public: |
| 76 PageNode(); | 114 PageNode(); |
| 77 ~PageNode(); | 115 ~PageNode(); |
| 78 | 116 |
| 79 PDF_PAGENODE_TYPE m_type; | 117 PDF_PAGENODE_TYPE m_type; |
| 80 uint32_t m_dwPageNo; | 118 uint32_t m_dwPageNo; |
| 81 CFX_ArrayTemplate<PageNode*> m_childNode; | 119 CFX_ArrayTemplate<PageNode*> m_childNode; |
| 82 }; | 120 }; |
| 83 | 121 |
| 84 static const int kMaxDataAvailRecursionDepth = 64; | 122 static const int kMaxDataAvailRecursionDepth = 64; |
| 85 static int s_CurrentDataAvailRecursionDepth; | 123 static int s_CurrentDataAvailRecursionDepth; |
| 86 static const int kMaxPageRecursionDepth = 1024; | 124 static const int kMaxPageRecursionDepth = 1024; |
| 87 | 125 |
| 88 uint32_t GetObjectSize(uint32_t objnum, FX_FILESIZE& offset); | 126 uint32_t GetObjectSize(uint32_t objnum, FX_FILESIZE& offset); |
| 89 FX_BOOL IsObjectsAvail(CFX_ArrayTemplate<CPDF_Object*>& obj_array, | 127 FX_BOOL IsObjectsAvail(CFX_ArrayTemplate<CPDF_Object*>& obj_array, |
| 90 FX_BOOL bParsePage, | 128 FX_BOOL bParsePage, |
| 91 IPDF_DataAvail::DownloadHints* pHints, | 129 DownloadHints* pHints, |
| 92 CFX_ArrayTemplate<CPDF_Object*>& ret_array); | 130 CFX_ArrayTemplate<CPDF_Object*>& ret_array); |
| 93 FX_BOOL CheckDocStatus(IPDF_DataAvail::DownloadHints* pHints); | 131 FX_BOOL CheckDocStatus(DownloadHints* pHints); |
| 94 FX_BOOL CheckHeader(IPDF_DataAvail::DownloadHints* pHints); | 132 FX_BOOL CheckHeader(DownloadHints* pHints); |
| 95 FX_BOOL CheckFirstPage(IPDF_DataAvail::DownloadHints* pHints); | 133 FX_BOOL CheckFirstPage(DownloadHints* pHints); |
| 96 FX_BOOL CheckHintTables(IPDF_DataAvail::DownloadHints* pHints); | 134 FX_BOOL CheckHintTables(DownloadHints* pHints); |
| 97 FX_BOOL CheckEnd(IPDF_DataAvail::DownloadHints* pHints); | 135 FX_BOOL CheckEnd(DownloadHints* pHints); |
| 98 FX_BOOL CheckCrossRef(IPDF_DataAvail::DownloadHints* pHints); | 136 FX_BOOL CheckCrossRef(DownloadHints* pHints); |
| 99 FX_BOOL CheckCrossRefItem(IPDF_DataAvail::DownloadHints* pHints); | 137 FX_BOOL CheckCrossRefItem(DownloadHints* pHints); |
| 100 FX_BOOL CheckTrailer(IPDF_DataAvail::DownloadHints* pHints); | 138 FX_BOOL CheckTrailer(DownloadHints* pHints); |
| 101 FX_BOOL CheckRoot(IPDF_DataAvail::DownloadHints* pHints); | 139 FX_BOOL CheckRoot(DownloadHints* pHints); |
| 102 FX_BOOL CheckInfo(IPDF_DataAvail::DownloadHints* pHints); | 140 FX_BOOL CheckInfo(DownloadHints* pHints); |
| 103 FX_BOOL CheckPages(IPDF_DataAvail::DownloadHints* pHints); | 141 FX_BOOL CheckPages(DownloadHints* pHints); |
| 104 FX_BOOL CheckPage(IPDF_DataAvail::DownloadHints* pHints); | 142 FX_BOOL CheckPage(DownloadHints* pHints); |
| 105 FX_BOOL CheckResources(IPDF_DataAvail::DownloadHints* pHints); | 143 FX_BOOL CheckResources(DownloadHints* pHints); |
| 106 FX_BOOL CheckAnnots(IPDF_DataAvail::DownloadHints* pHints); | 144 FX_BOOL CheckAnnots(DownloadHints* pHints); |
| 107 FX_BOOL CheckAcroForm(IPDF_DataAvail::DownloadHints* pHints); | 145 FX_BOOL CheckAcroForm(DownloadHints* pHints); |
| 108 FX_BOOL CheckAcroFormSubObject(IPDF_DataAvail::DownloadHints* pHints); | 146 FX_BOOL CheckAcroFormSubObject(DownloadHints* pHints); |
| 109 FX_BOOL CheckTrailerAppend(IPDF_DataAvail::DownloadHints* pHints); | 147 FX_BOOL CheckTrailerAppend(DownloadHints* pHints); |
| 110 FX_BOOL CheckPageStatus(IPDF_DataAvail::DownloadHints* pHints); | 148 FX_BOOL CheckPageStatus(DownloadHints* pHints); |
| 111 FX_BOOL CheckAllCrossRefStream(IPDF_DataAvail::DownloadHints* pHints); | 149 FX_BOOL CheckAllCrossRefStream(DownloadHints* pHints); |
| 112 | 150 |
| 113 int32_t CheckCrossRefStream(IPDF_DataAvail::DownloadHints* pHints, | 151 int32_t CheckCrossRefStream(DownloadHints* pHints, FX_FILESIZE& xref_offset); |
| 114 FX_FILESIZE& xref_offset); | |
| 115 FX_BOOL IsLinearizedFile(uint8_t* pData, uint32_t dwLen); | 152 FX_BOOL IsLinearizedFile(uint8_t* pData, uint32_t dwLen); |
| 116 void SetStartOffset(FX_FILESIZE dwOffset); | 153 void SetStartOffset(FX_FILESIZE dwOffset); |
| 117 FX_BOOL GetNextToken(CFX_ByteString& token); | 154 FX_BOOL GetNextToken(CFX_ByteString& token); |
| 118 FX_BOOL GetNextChar(uint8_t& ch); | 155 FX_BOOL GetNextChar(uint8_t& ch); |
| 119 CPDF_Object* ParseIndirectObjectAt( | 156 CPDF_Object* ParseIndirectObjectAt( |
| 120 FX_FILESIZE pos, | 157 FX_FILESIZE pos, |
| 121 uint32_t objnum, | 158 uint32_t objnum, |
| 122 CPDF_IndirectObjectHolder* pObjList = nullptr); | 159 CPDF_IndirectObjectHolder* pObjList = nullptr); |
| 123 CPDF_Object* GetObject(uint32_t objnum, | 160 CPDF_Object* GetObject(uint32_t objnum, |
| 124 IPDF_DataAvail::DownloadHints* pHints, | 161 DownloadHints* pHints, |
| 125 FX_BOOL* pExistInFile); | 162 FX_BOOL* pExistInFile); |
| 126 FX_BOOL GetPageKids(CPDF_Parser* pParser, CPDF_Object* pPages); | 163 FX_BOOL GetPageKids(CPDF_Parser* pParser, CPDF_Object* pPages); |
| 127 FX_BOOL PreparePageItem(); | 164 FX_BOOL PreparePageItem(); |
| 128 FX_BOOL LoadPages(IPDF_DataAvail::DownloadHints* pHints); | 165 FX_BOOL LoadPages(DownloadHints* pHints); |
| 129 FX_BOOL LoadAllXref(IPDF_DataAvail::DownloadHints* pHints); | 166 FX_BOOL LoadAllXref(DownloadHints* pHints); |
| 130 FX_BOOL LoadAllFile(IPDF_DataAvail::DownloadHints* pHints); | 167 FX_BOOL LoadAllFile(DownloadHints* pHints); |
| 131 DocAvailStatus CheckLinearizedData(IPDF_DataAvail::DownloadHints* pHints); | 168 DocAvailStatus CheckLinearizedData(DownloadHints* pHints); |
| 132 FX_BOOL CheckPageAnnots(int iPage, IPDF_DataAvail::DownloadHints* pHints); | 169 FX_BOOL CheckPageAnnots(int iPage, DownloadHints* pHints); |
| 133 | 170 |
| 134 DocAvailStatus CheckLinearizedFirstPage( | 171 DocAvailStatus CheckLinearizedFirstPage(int iPage, DownloadHints* pHints); |
| 135 int iPage, | |
| 136 IPDF_DataAvail::DownloadHints* pHints); | |
| 137 FX_BOOL HaveResourceAncestor(CPDF_Dictionary* pDict); | 172 FX_BOOL HaveResourceAncestor(CPDF_Dictionary* pDict); |
| 138 FX_BOOL CheckPage(int32_t iPage, IPDF_DataAvail::DownloadHints* pHints); | 173 FX_BOOL CheckPage(int32_t iPage, DownloadHints* pHints); |
| 139 FX_BOOL LoadDocPages(IPDF_DataAvail::DownloadHints* pHints); | 174 FX_BOOL LoadDocPages(DownloadHints* pHints); |
| 140 FX_BOOL LoadDocPage(int32_t iPage, IPDF_DataAvail::DownloadHints* pHints); | 175 FX_BOOL LoadDocPage(int32_t iPage, DownloadHints* pHints); |
| 141 FX_BOOL CheckPageNode(PageNode& pageNodes, | 176 FX_BOOL CheckPageNode(PageNode& pageNodes, |
| 142 int32_t iPage, | 177 int32_t iPage, |
| 143 int32_t& iCount, | 178 int32_t& iCount, |
| 144 IPDF_DataAvail::DownloadHints* pHints, | 179 DownloadHints* pHints, |
| 145 int level); | 180 int level); |
| 146 FX_BOOL CheckUnkownPageNode(uint32_t dwPageNo, | 181 FX_BOOL CheckUnkownPageNode(uint32_t dwPageNo, |
| 147 PageNode* pPageNode, | 182 PageNode* pPageNode, |
| 148 IPDF_DataAvail::DownloadHints* pHints); | 183 DownloadHints* pHints); |
| 149 FX_BOOL CheckArrayPageNode(uint32_t dwPageNo, | 184 FX_BOOL CheckArrayPageNode(uint32_t dwPageNo, |
| 150 PageNode* pPageNode, | 185 PageNode* pPageNode, |
| 151 IPDF_DataAvail::DownloadHints* pHints); | 186 DownloadHints* pHints); |
| 152 FX_BOOL CheckPageCount(IPDF_DataAvail::DownloadHints* pHints); | 187 FX_BOOL CheckPageCount(DownloadHints* pHints); |
| 153 bool IsFirstCheck(int iPage); | 188 bool IsFirstCheck(int iPage); |
| 154 void ResetFirstCheck(int iPage); | 189 void ResetFirstCheck(int iPage); |
| 155 FX_BOOL IsDataAvail(FX_FILESIZE offset, | 190 FX_BOOL IsDataAvail(FX_FILESIZE offset, uint32_t size, DownloadHints* pHints); |
| 156 uint32_t size, | |
| 157 IPDF_DataAvail::DownloadHints* pHints); | |
| 158 | 191 |
| 192 FileAvail* const m_pFileAvail; |
| 193 IFX_FileRead* const m_pFileRead; |
| 159 CPDF_Parser m_parser; | 194 CPDF_Parser m_parser; |
| 160 CPDF_SyntaxParser m_syntaxParser; | 195 CPDF_SyntaxParser m_syntaxParser; |
| 161 CPDF_Object* m_pRoot; | 196 CPDF_Object* m_pRoot; |
| 162 uint32_t m_dwRootObjNum; | 197 uint32_t m_dwRootObjNum; |
| 163 uint32_t m_dwInfoObjNum; | 198 uint32_t m_dwInfoObjNum; |
| 164 CPDF_Object* m_pLinearized; | 199 CPDF_Object* m_pLinearized; |
| 165 CPDF_Object* m_pTrailer; | 200 CPDF_Object* m_pTrailer; |
| 166 FX_BOOL m_bDocAvail; | 201 FX_BOOL m_bDocAvail; |
| 167 FX_FILESIZE m_dwHeaderOffset; | 202 FX_FILESIZE m_dwHeaderOffset; |
| 168 FX_FILESIZE m_dwLastXRefOffset; | 203 FX_FILESIZE m_dwLastXRefOffset; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 FX_FILESIZE m_dwPrevXRefOffset; | 242 FX_FILESIZE m_dwPrevXRefOffset; |
| 208 FX_BOOL m_bTotalLoadPageTree; | 243 FX_BOOL m_bTotalLoadPageTree; |
| 209 FX_BOOL m_bCurPageDictLoadOK; | 244 FX_BOOL m_bCurPageDictLoadOK; |
| 210 PageNode m_pageNodes; | 245 PageNode m_pageNodes; |
| 211 std::set<uint32_t> m_pageMapCheckState; | 246 std::set<uint32_t> m_pageMapCheckState; |
| 212 std::set<uint32_t> m_pagesLoadState; | 247 std::set<uint32_t> m_pagesLoadState; |
| 213 std::unique_ptr<CPDF_HintTables> m_pHintTables; | 248 std::unique_ptr<CPDF_HintTables> m_pHintTables; |
| 214 FX_BOOL m_bSupportHintTable; | 249 FX_BOOL m_bSupportHintTable; |
| 215 }; | 250 }; |
| 216 | 251 |
| 217 #endif // CORE_FPDFAPI_FPDF_PARSER_CPDF_DATA_AVAIL_H_ | 252 #endif // CORE_FPDFAPI_FPDF_PARSER_INCLUDE_CPDF_DATA_AVAIL_H_ |
| OLD | NEW |