OLD | NEW |
1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 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_FXCRT_EXTENSION_H_ | 7 #ifndef CORE_FXCRT_EXTENSION_H_ |
8 #define CORE_FXCRT_EXTENSION_H_ | 8 #define CORE_FXCRT_EXTENSION_H_ |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
| 11 #include <memory> |
11 | 12 |
12 #include "core/fxcrt/include/fx_basic.h" | 13 #include "core/fxcrt/include/fx_basic.h" |
13 #include "core/fxcrt/include/fx_safe_types.h" | 14 #include "core/fxcrt/include/fx_safe_types.h" |
14 | 15 |
15 class IFXCRT_FileAccess { | 16 class IFXCRT_FileAccess { |
16 public: | 17 public: |
| 18 static IFXCRT_FileAccess* Create(); |
17 virtual ~IFXCRT_FileAccess() {} | 19 virtual ~IFXCRT_FileAccess() {} |
| 20 |
18 virtual FX_BOOL Open(const CFX_ByteStringC& fileName, uint32_t dwMode) = 0; | 21 virtual FX_BOOL Open(const CFX_ByteStringC& fileName, uint32_t dwMode) = 0; |
19 virtual FX_BOOL Open(const CFX_WideStringC& fileName, uint32_t dwMode) = 0; | 22 virtual FX_BOOL Open(const CFX_WideStringC& fileName, uint32_t dwMode) = 0; |
20 virtual void Close() = 0; | 23 virtual void Close() = 0; |
21 virtual void Release() = 0; | |
22 virtual FX_FILESIZE GetSize() const = 0; | 24 virtual FX_FILESIZE GetSize() const = 0; |
23 virtual FX_FILESIZE GetPosition() const = 0; | 25 virtual FX_FILESIZE GetPosition() const = 0; |
24 virtual FX_FILESIZE SetPosition(FX_FILESIZE pos) = 0; | 26 virtual FX_FILESIZE SetPosition(FX_FILESIZE pos) = 0; |
25 virtual size_t Read(void* pBuffer, size_t szBuffer) = 0; | 27 virtual size_t Read(void* pBuffer, size_t szBuffer) = 0; |
26 virtual size_t Write(const void* pBuffer, size_t szBuffer) = 0; | 28 virtual size_t Write(const void* pBuffer, size_t szBuffer) = 0; |
27 virtual size_t ReadPos(void* pBuffer, size_t szBuffer, FX_FILESIZE pos) = 0; | 29 virtual size_t ReadPos(void* pBuffer, size_t szBuffer, FX_FILESIZE pos) = 0; |
28 virtual size_t WritePos(const void* pBuffer, | 30 virtual size_t WritePos(const void* pBuffer, |
29 size_t szBuffer, | 31 size_t szBuffer, |
30 FX_FILESIZE pos) = 0; | 32 FX_FILESIZE pos) = 0; |
31 virtual FX_BOOL Flush() = 0; | 33 virtual FX_BOOL Flush() = 0; |
32 virtual FX_BOOL Truncate(FX_FILESIZE szFile) = 0; | 34 virtual FX_BOOL Truncate(FX_FILESIZE szFile) = 0; |
33 }; | 35 }; |
34 IFXCRT_FileAccess* FXCRT_FileAccess_Create(); | |
35 | 36 |
36 #ifdef PDF_ENABLE_XFA | 37 #ifdef PDF_ENABLE_XFA |
37 class CFX_CRTFileAccess : public IFX_FileAccess { | 38 class CFX_CRTFileAccess : public IFX_FileAccess { |
38 public: | 39 public: |
39 CFX_CRTFileAccess() : m_RefCount(0) {} | 40 CFX_CRTFileAccess() : m_RefCount(0) {} |
40 | 41 |
41 // IFX_FileAccess | 42 // IFX_FileAccess |
42 void Release() override { | 43 void Release() override { |
43 if (--m_RefCount == 0) | 44 if (--m_RefCount == 0) |
44 delete this; | 45 delete this; |
(...skipping 17 matching lines...) Expand all Loading... |
62 } | 63 } |
63 | 64 |
64 protected: | 65 protected: |
65 CFX_WideString m_path; | 66 CFX_WideString m_path; |
66 uint32_t m_RefCount; | 67 uint32_t m_RefCount; |
67 }; | 68 }; |
68 #endif // PDF_ENABLE_XFA | 69 #endif // PDF_ENABLE_XFA |
69 | 70 |
70 class CFX_CRTFileStream final : public IFX_FileStream { | 71 class CFX_CRTFileStream final : public IFX_FileStream { |
71 public: | 72 public: |
72 explicit CFX_CRTFileStream(IFXCRT_FileAccess* pFA); | 73 explicit CFX_CRTFileStream(std::unique_ptr<IFXCRT_FileAccess> pFA); |
73 ~CFX_CRTFileStream() override; | 74 ~CFX_CRTFileStream() override; |
74 | 75 |
75 // IFX_FileStream: | 76 // IFX_FileStream: |
76 IFX_FileStream* Retain() override; | 77 IFX_FileStream* Retain() override; |
77 void Release() override; | 78 void Release() override; |
78 FX_FILESIZE GetSize() override; | 79 FX_FILESIZE GetSize() override; |
79 FX_BOOL IsEOF() override; | 80 FX_BOOL IsEOF() override; |
80 FX_FILESIZE GetPosition() override; | 81 FX_FILESIZE GetPosition() override; |
81 FX_BOOL ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) override; | 82 FX_BOOL ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) override; |
82 size_t ReadBlock(void* buffer, size_t size) override; | 83 size_t ReadBlock(void* buffer, size_t size) override; |
83 FX_BOOL WriteBlock(const void* buffer, | 84 FX_BOOL WriteBlock(const void* buffer, |
84 FX_FILESIZE offset, | 85 FX_FILESIZE offset, |
85 size_t size) override; | 86 size_t size) override; |
86 FX_BOOL Flush() override; | 87 FX_BOOL Flush() override; |
87 | 88 |
88 protected: | 89 protected: |
89 IFXCRT_FileAccess* m_pFile; | 90 std::unique_ptr<IFXCRT_FileAccess> m_pFile; |
90 uint32_t m_dwCount; | 91 uint32_t m_dwCount; |
91 }; | 92 }; |
92 | 93 |
93 #define FX_MEMSTREAM_BlockSize (64 * 1024) | 94 #define FX_MEMSTREAM_BlockSize (64 * 1024) |
94 #define FX_MEMSTREAM_Consecutive 0x01 | 95 #define FX_MEMSTREAM_Consecutive 0x01 |
95 #define FX_MEMSTREAM_TakeOver 0x02 | 96 #define FX_MEMSTREAM_TakeOver 0x02 |
96 class CFX_MemoryStream final : public IFX_MemoryStream { | 97 class CFX_MemoryStream final : public IFX_MemoryStream { |
97 public: | 98 public: |
98 explicit CFX_MemoryStream(FX_BOOL bConsecutive) | 99 explicit CFX_MemoryStream(FX_BOOL bConsecutive) |
99 : m_dwCount(1), | 100 : m_dwCount(1), |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
325 uint32_t mt[MT_N]; | 326 uint32_t mt[MT_N]; |
326 }; | 327 }; |
327 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ | 328 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ |
328 FX_BOOL FX_GenerateCryptoRandom(uint32_t* pBuffer, int32_t iCount); | 329 FX_BOOL FX_GenerateCryptoRandom(uint32_t* pBuffer, int32_t iCount); |
329 #endif | 330 #endif |
330 #ifdef __cplusplus | 331 #ifdef __cplusplus |
331 } | 332 } |
332 #endif | 333 #endif |
333 | 334 |
334 #endif // CORE_FXCRT_EXTENSION_H_ | 335 #endif // CORE_FXCRT_EXTENSION_H_ |
OLD | NEW |