Chromium Code Reviews| 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_SRC_FXCRT_EXTENSION_H_ | 7 #ifndef CORE_SRC_FXCRT_EXTENSION_H_ |
| 8 #define CORE_SRC_FXCRT_EXTENSION_H_ | 8 #define CORE_SRC_FXCRT_EXTENSION_H_ |
| 9 | 9 |
| 10 #include "../../include/fxcrt/fx_basic.h" | 10 #include "../../include/fxcrt/fx_basic.h" |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 23 virtual size_t Read(void* pBuffer, size_t szBuffer) = 0; | 23 virtual size_t Read(void* pBuffer, size_t szBuffer) = 0; |
| 24 virtual size_t Write(const void* pBuffer, size_t szBuffer) = 0; | 24 virtual size_t Write(const void* pBuffer, size_t szBuffer) = 0; |
| 25 virtual size_t ReadPos(void* pBuffer, size_t szBuffer, FX_FILESIZE pos) = 0; | 25 virtual size_t ReadPos(void* pBuffer, size_t szBuffer, FX_FILESIZE pos) = 0; |
| 26 virtual size_t WritePos(const void* pBuffer, | 26 virtual size_t WritePos(const void* pBuffer, |
| 27 size_t szBuffer, | 27 size_t szBuffer, |
| 28 FX_FILESIZE pos) = 0; | 28 FX_FILESIZE pos) = 0; |
| 29 virtual FX_BOOL Flush() = 0; | 29 virtual FX_BOOL Flush() = 0; |
| 30 virtual FX_BOOL Truncate(FX_FILESIZE szFile) = 0; | 30 virtual FX_BOOL Truncate(FX_FILESIZE szFile) = 0; |
| 31 }; | 31 }; |
| 32 IFXCRT_FileAccess* FXCRT_FileAccess_Create(); | 32 IFXCRT_FileAccess* FXCRT_FileAccess_Create(); |
| 33 | |
| 33 class CFX_CRTFileAccess : public IFX_FileAccess { | 34 class CFX_CRTFileAccess : public IFX_FileAccess { |
|
Lei Zhang
2015/08/15 04:49:07
This is new in XFA.
| |
| 34 public: | 35 public: |
| 35 CFX_CRTFileAccess() : m_RefCount(0) {} | 36 CFX_CRTFileAccess() : m_RefCount(0) {} |
| 36 | 37 |
| 37 virtual void Release() { | 38 // IFX_FileAccess |
| 39 void Release() override { | |
| 38 if (--m_RefCount == 0) | 40 if (--m_RefCount == 0) |
| 39 delete this; | 41 delete this; |
| 40 } | 42 } |
| 41 | 43 |
| 42 IFX_FileAccess* Retain() { | 44 IFX_FileAccess* Retain() override { |
| 43 m_RefCount++; | 45 m_RefCount++; |
| 44 return (IFX_FileAccess*)this; | 46 return (IFX_FileAccess*)this; |
| 45 } | 47 } |
| 46 | 48 |
| 47 virtual FX_BOOL Init(const CFX_WideStringC& wsPath) { | 49 void GetPath(CFX_WideString& wsPath) override { wsPath = m_path; } |
| 50 | |
| 51 IFX_FileStream* CreateFileStream(FX_DWORD dwModes) override { | |
| 52 return FX_CreateFileStream(m_path, dwModes); | |
| 53 } | |
| 54 | |
| 55 FX_BOOL Init(const CFX_WideStringC& wsPath) { | |
| 48 m_path = wsPath; | 56 m_path = wsPath; |
| 49 m_RefCount = 1; | 57 m_RefCount = 1; |
| 50 return TRUE; | 58 return TRUE; |
| 51 } | 59 } |
| 52 | 60 |
| 53 virtual void GetPath(CFX_WideString& wsPath) { wsPath = m_path; } | |
| 54 | |
| 55 virtual IFX_FileStream* CreateFileStream(FX_DWORD dwModes) { | |
| 56 return FX_CreateFileStream(m_path, dwModes); | |
| 57 } | |
| 58 | |
| 59 protected: | 61 protected: |
| 60 CFX_WideString m_path; | 62 CFX_WideString m_path; |
| 61 FX_DWORD m_RefCount; | 63 FX_DWORD m_RefCount; |
| 62 }; | 64 }; |
| 65 | |
| 63 class CFX_CRTFileStream final : public IFX_FileStream { | 66 class CFX_CRTFileStream final : public IFX_FileStream { |
| 64 public: | 67 public: |
| 65 CFX_CRTFileStream(IFXCRT_FileAccess* pFA) : m_pFile(pFA), m_dwCount(1) {} | 68 CFX_CRTFileStream(IFXCRT_FileAccess* pFA) : m_pFile(pFA), m_dwCount(1) {} |
| 66 ~CFX_CRTFileStream() { | 69 ~CFX_CRTFileStream() override { |
| 67 if (m_pFile) { | 70 if (m_pFile) { |
| 68 m_pFile->Release(); | 71 m_pFile->Release(); |
| 69 } | 72 } |
| 70 } | 73 } |
| 71 virtual IFX_FileStream* Retain() override { | 74 virtual IFX_FileStream* Retain() override { |
| 72 m_dwCount++; | 75 m_dwCount++; |
| 73 return this; | 76 return this; |
| 74 } | 77 } |
| 75 virtual void Release() override { | 78 virtual void Release() override { |
| 76 FX_DWORD nCount = --m_dwCount; | 79 FX_DWORD nCount = --m_dwCount; |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 93 FX_FILESIZE offset, | 96 FX_FILESIZE offset, |
| 94 size_t size) override { | 97 size_t size) override { |
| 95 return (FX_BOOL)m_pFile->WritePos(buffer, size, offset); | 98 return (FX_BOOL)m_pFile->WritePos(buffer, size, offset); |
| 96 } | 99 } |
| 97 virtual FX_BOOL Flush() override { return m_pFile->Flush(); } | 100 virtual FX_BOOL Flush() override { return m_pFile->Flush(); } |
| 98 | 101 |
| 99 protected: | 102 protected: |
| 100 IFXCRT_FileAccess* m_pFile; | 103 IFXCRT_FileAccess* m_pFile; |
| 101 FX_DWORD m_dwCount; | 104 FX_DWORD m_dwCount; |
| 102 }; | 105 }; |
| 106 | |
| 103 #define FX_MEMSTREAM_BlockSize (64 * 1024) | 107 #define FX_MEMSTREAM_BlockSize (64 * 1024) |
| 104 #define FX_MEMSTREAM_Consecutive 0x01 | 108 #define FX_MEMSTREAM_Consecutive 0x01 |
| 105 #define FX_MEMSTREAM_TakeOver 0x02 | 109 #define FX_MEMSTREAM_TakeOver 0x02 |
| 106 class CFX_MemoryStream final : public IFX_MemoryStream { | 110 class CFX_MemoryStream final : public IFX_MemoryStream { |
| 107 public: | 111 public: |
| 108 CFX_MemoryStream(FX_BOOL bConsecutive) | 112 CFX_MemoryStream(FX_BOOL bConsecutive) |
| 109 : m_dwCount(1), | 113 : m_dwCount(1), |
| 110 m_nTotalSize(0), | 114 m_nTotalSize(0), |
| 111 m_nCurSize(0), | 115 m_nCurSize(0), |
| 112 m_nCurPos(0), | 116 m_nCurPos(0), |
| 113 m_nGrowSize(FX_MEMSTREAM_BlockSize) { | 117 m_nGrowSize(FX_MEMSTREAM_BlockSize) { |
| 114 m_dwFlags = | 118 m_dwFlags = |
| 115 FX_MEMSTREAM_TakeOver | (bConsecutive ? FX_MEMSTREAM_Consecutive : 0); | 119 FX_MEMSTREAM_TakeOver | (bConsecutive ? FX_MEMSTREAM_Consecutive : 0); |
| 116 } | 120 } |
| 117 CFX_MemoryStream(uint8_t* pBuffer, size_t nSize, FX_BOOL bTakeOver) | 121 CFX_MemoryStream(uint8_t* pBuffer, size_t nSize, FX_BOOL bTakeOver) |
| 118 : m_dwCount(1), | 122 : m_dwCount(1), |
| 119 m_nTotalSize(nSize), | 123 m_nTotalSize(nSize), |
| 120 m_nCurSize(nSize), | 124 m_nCurSize(nSize), |
| 121 m_nCurPos(0), | 125 m_nCurPos(0), |
| 122 m_nGrowSize(FX_MEMSTREAM_BlockSize) { | 126 m_nGrowSize(FX_MEMSTREAM_BlockSize) { |
| 123 m_Blocks.Add(pBuffer); | 127 m_Blocks.Add(pBuffer); |
| 124 m_dwFlags = | 128 m_dwFlags = |
| 125 FX_MEMSTREAM_Consecutive | (bTakeOver ? FX_MEMSTREAM_TakeOver : 0); | 129 FX_MEMSTREAM_Consecutive | (bTakeOver ? FX_MEMSTREAM_TakeOver : 0); |
| 126 } | 130 } |
| 127 ~CFX_MemoryStream() { | 131 ~CFX_MemoryStream() override { |
| 128 if (m_dwFlags & FX_MEMSTREAM_TakeOver) { | 132 if (m_dwFlags & FX_MEMSTREAM_TakeOver) { |
| 129 for (int32_t i = 0; i < m_Blocks.GetSize(); i++) { | 133 for (int32_t i = 0; i < m_Blocks.GetSize(); i++) { |
| 130 FX_Free((uint8_t*)m_Blocks[i]); | 134 FX_Free((uint8_t*)m_Blocks[i]); |
| 131 } | 135 } |
| 132 } | 136 } |
| 133 m_Blocks.RemoveAll(); | 137 m_Blocks.RemoveAll(); |
| 134 } | 138 } |
| 135 virtual IFX_FileStream* Retain() override { | 139 virtual IFX_FileStream* Retain() override { |
| 136 m_dwCount++; | 140 m_dwCount++; |
| 137 return this; | 141 return this; |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 310 size = (size - m_nTotalSize + m_nGrowSize - 1) / m_nGrowSize; | 314 size = (size - m_nTotalSize + m_nGrowSize - 1) / m_nGrowSize; |
| 311 m_Blocks.SetSize(m_Blocks.GetSize() + (int32_t)size); | 315 m_Blocks.SetSize(m_Blocks.GetSize() + (int32_t)size); |
| 312 while (size--) { | 316 while (size--) { |
| 313 uint8_t* pBlock = FX_Alloc(uint8_t, m_nGrowSize); | 317 uint8_t* pBlock = FX_Alloc(uint8_t, m_nGrowSize); |
| 314 m_Blocks.SetAt(iCount++, pBlock); | 318 m_Blocks.SetAt(iCount++, pBlock); |
| 315 m_nTotalSize += m_nGrowSize; | 319 m_nTotalSize += m_nGrowSize; |
| 316 } | 320 } |
| 317 return TRUE; | 321 return TRUE; |
| 318 } | 322 } |
| 319 }; | 323 }; |
| 324 | |
| 320 #ifdef __cplusplus | 325 #ifdef __cplusplus |
| 321 extern "C" { | 326 extern "C" { |
| 322 #endif | 327 #endif |
| 323 #define MT_N 848 | 328 #define MT_N 848 |
| 324 #define MT_M 456 | 329 #define MT_M 456 |
| 325 #define MT_Matrix_A 0x9908b0df | 330 #define MT_Matrix_A 0x9908b0df |
| 326 #define MT_Upper_Mask 0x80000000 | 331 #define MT_Upper_Mask 0x80000000 |
| 327 #define MT_Lower_Mask 0x7fffffff | 332 #define MT_Lower_Mask 0x7fffffff |
| 328 typedef struct _FX_MTRANDOMCONTEXT { | 333 typedef struct _FX_MTRANDOMCONTEXT { |
| 329 _FX_MTRANDOMCONTEXT() { | 334 _FX_MTRANDOMCONTEXT() { |
| 330 mti = MT_N + 1; | 335 mti = MT_N + 1; |
| 331 bHaveSeed = FALSE; | 336 bHaveSeed = FALSE; |
| 332 } | 337 } |
| 333 FX_DWORD mti; | 338 FX_DWORD mti; |
| 334 FX_BOOL bHaveSeed; | 339 FX_BOOL bHaveSeed; |
| 335 FX_DWORD mt[MT_N]; | 340 FX_DWORD mt[MT_N]; |
| 336 } FX_MTRANDOMCONTEXT, *FX_LPMTRANDOMCONTEXT; | 341 } FX_MTRANDOMCONTEXT, *FX_LPMTRANDOMCONTEXT; |
| 337 typedef FX_MTRANDOMCONTEXT const* FX_LPCMTRANDOMCONTEXT; | 342 typedef FX_MTRANDOMCONTEXT const* FX_LPCMTRANDOMCONTEXT; |
| 338 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ | 343 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ |
| 339 FX_BOOL FX_GenerateCryptoRandom(FX_DWORD* pBuffer, int32_t iCount); | 344 FX_BOOL FX_GenerateCryptoRandom(FX_DWORD* pBuffer, int32_t iCount); |
| 340 #endif | 345 #endif |
| 341 #ifdef __cplusplus | 346 #ifdef __cplusplus |
| 342 } | 347 } |
| 343 #endif | 348 #endif |
| 344 | 349 |
| 345 #endif // CORE_SRC_FXCRT_EXTENSION_H_ | 350 #endif // CORE_SRC_FXCRT_EXTENSION_H_ |
| OLD | NEW |