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

Side by Side Diff: core/include/fpdfapi/cpdf_parser.h

Issue 1805603002: core/include/fdpfapi cleanup Part I. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Rebase to master Created 4 years, 9 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 | « core/include/fpdfapi/cpdf_object.h ('k') | core/include/fpdfapi/cpdf_reference.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2016 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
7 #ifndef CORE_INCLUDE_FPDFAPI_CPDF_PARSER_H_
8 #define CORE_INCLUDE_FPDFAPI_CPDF_PARSER_H_
9
10 #include <map>
11 #include <memory>
12 #include <set>
13
14 #include "core/include/fxcrt/fx_basic.h"
15
16 class CPDF_Array;
17 class CPDF_Dictionary;
18 class CPDF_Document;
19 class CPDF_IndirectObjectHolder;
20 class CPDF_Object;
21 class CPDF_StreamAcc;
22 class CPDF_SyntaxParser;
23 class IFX_FileRead;
24 class IPDF_CryptoHandler;
25 class IPDF_SecurityHandler;
26
27 class CPDF_Parser {
28 public:
29 enum Error {
30 SUCCESS = 0,
31 FILE_ERROR,
32 FORMAT_ERROR,
33 PASSWORD_ERROR,
34 HANDLER_ERROR
35 };
36
37 CPDF_Parser();
38 ~CPDF_Parser();
39
40 Error StartParse(IFX_FileRead* pFile);
41 FX_DWORD GetPermissions(FX_BOOL bCheckRevision = FALSE);
42
43 void SetPassword(const FX_CHAR* password) { m_Password = password; }
44 CFX_ByteString GetPassword() { return m_Password; }
45 CPDF_Dictionary* GetTrailer() const { return m_pTrailer; }
46 FX_FILESIZE GetLastXRefOffset() const { return m_LastXRefOffset; }
47 CPDF_Document* GetDocument() const { return m_pDocument; }
48
49 FX_DWORD GetRootObjNum();
50 FX_DWORD GetInfoObjNum();
51 CPDF_Array* GetIDArray();
52
53 CPDF_Dictionary* GetEncryptDict() const { return m_pEncryptDict; }
54
55 CPDF_Object* ParseIndirectObject(CPDF_IndirectObjectHolder* pObjList,
56 FX_DWORD objnum);
57
58 FX_DWORD GetLastObjNum() const;
59 bool IsValidObjectNumber(FX_DWORD objnum) const;
60 FX_FILESIZE GetObjectPositionOrZero(FX_DWORD objnum) const;
61 uint8_t GetObjectType(FX_DWORD objnum) const;
62 uint16_t GetObjectGenNum(FX_DWORD objnum) const;
63 bool IsVersionUpdated() const { return m_bVersionUpdated; }
64 bool IsObjectFreeOrNull(FX_DWORD objnum) const;
65 FX_BOOL IsFormStream(FX_DWORD objnum, FX_BOOL& bForm);
66 IPDF_CryptoHandler* GetCryptoHandler();
67 IFX_FileRead* GetFileAccess() const;
68
69 FX_FILESIZE GetObjectOffset(FX_DWORD objnum) const;
70 FX_FILESIZE GetObjectSize(FX_DWORD objnum) const;
71
72 void GetIndirectBinary(FX_DWORD objnum, uint8_t*& pBuffer, FX_DWORD& size);
73 int GetFileVersion() const { return m_FileVersion; }
74 FX_BOOL IsXRefStream() const { return m_bXRefStream; }
75
76 CPDF_Object* ParseIndirectObjectAt(CPDF_IndirectObjectHolder* pObjList,
77 FX_FILESIZE pos,
78 FX_DWORD objnum);
79
80 CPDF_Object* ParseIndirectObjectAtByStrict(
81 CPDF_IndirectObjectHolder* pObjList,
82 FX_FILESIZE pos,
83 FX_DWORD objnum,
84 FX_FILESIZE* pResultPos);
85
86 Error StartAsyncParse(IFX_FileRead* pFile);
87
88 FX_DWORD GetFirstPageNo() const { return m_dwFirstPageNo; }
89
90 protected:
91 struct ObjectInfo {
92 ObjectInfo() : pos(0), type(0), gennum(0) {}
93
94 FX_FILESIZE pos;
95 uint8_t type;
96 uint16_t gennum;
97 };
98
99 void CloseParser();
100 CPDF_Object* ParseDirect(CPDF_Object* pObj);
101 FX_BOOL LoadAllCrossRefV4(FX_FILESIZE pos);
102 FX_BOOL LoadAllCrossRefV5(FX_FILESIZE pos);
103 bool LoadCrossRefV4(FX_FILESIZE pos, FX_FILESIZE streampos, FX_BOOL bSkip);
104 FX_BOOL LoadCrossRefV5(FX_FILESIZE* pos, FX_BOOL bMainXRef);
105 CPDF_Dictionary* LoadTrailerV4();
106 FX_BOOL RebuildCrossRef();
107 Error SetEncryptHandler();
108 void ReleaseEncryptHandler();
109 FX_BOOL LoadLinearizedAllCrossRefV4(FX_FILESIZE pos, FX_DWORD dwObjCount);
110 FX_BOOL LoadLinearizedCrossRefV4(FX_FILESIZE pos, FX_DWORD dwObjCount);
111 FX_BOOL LoadLinearizedAllCrossRefV5(FX_FILESIZE pos);
112 Error LoadLinearizedMainXRefTable();
113 CPDF_StreamAcc* GetObjectStream(FX_DWORD number);
114 FX_BOOL IsLinearizedFile(IFX_FileRead* pFileAccess, FX_DWORD offset);
115 void SetEncryptDictionary(CPDF_Dictionary* pDict);
116 void ShrinkObjectMap(FX_DWORD size);
117
118 CPDF_Document* m_pDocument;
119 std::unique_ptr<CPDF_SyntaxParser> m_pSyntax;
120 bool m_bOwnFileRead;
121 int m_FileVersion;
122 CPDF_Dictionary* m_pTrailer;
123 CPDF_Dictionary* m_pEncryptDict;
124 FX_FILESIZE m_LastXRefOffset;
125 FX_BOOL m_bXRefStream;
126 std::unique_ptr<IPDF_SecurityHandler> m_pSecurityHandler;
127 CFX_ByteString m_bsRecipient;
128 CFX_ByteString m_FilePath;
129 CFX_ByteString m_Password;
130 std::map<FX_DWORD, ObjectInfo> m_ObjectInfo;
131 std::set<FX_FILESIZE> m_SortedOffset;
132 CFX_ArrayTemplate<CPDF_Dictionary*> m_Trailers;
133 bool m_bVersionUpdated;
134 CPDF_Object* m_pLinearized;
135 FX_DWORD m_dwFirstPageNo;
136 FX_DWORD m_dwXrefStartObjNum;
137
138 // A map of object numbers to indirect streams. Map owns the streams.
139 std::map<FX_DWORD, std::unique_ptr<CPDF_StreamAcc>> m_ObjectStreamMap;
140
141 // Mapping of object numbers to offsets. The offsets are relative to the first
142 // object in the stream.
143 using StreamObjectCache = std::map<FX_DWORD, FX_DWORD>;
144
145 // Mapping of streams to their object caches. This is valid as long as the
146 // streams in |m_ObjectStreamMap| are valid.
147 std::map<CPDF_StreamAcc*, StreamObjectCache> m_ObjCache;
148
149 // All indirect object numbers that are being parsed.
150 std::set<FX_DWORD> m_ParsingObjNums;
151
152 friend class CPDF_DataAvail;
153
154 private:
155 enum class ParserState {
156 kDefault,
157 kComment,
158 kWhitespace,
159 kString,
160 kHexString,
161 kEscapedString,
162 kXref,
163 kObjNum,
164 kPostObjNum,
165 kGenNum,
166 kPostGenNum,
167 kTrailer,
168 kBeginObj,
169 kEndObj
170 };
171 };
172
173 #endif // CORE_INCLUDE_FPDFAPI_CPDF_PARSER_H_
OLDNEW
« no previous file with comments | « core/include/fpdfapi/cpdf_object.h ('k') | core/include/fpdfapi/cpdf_reference.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698