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 #include "core/fxcrt/extension.h" | 7 #include "core/fxcrt/extension.h" |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <memory> | 10 #include <memory> |
| 11 #include <utility> | 11 #include <utility> |
| 12 | 12 |
| 13 #include "core/fxcrt/fx_basic.h" | 13 #include "core/fxcrt/fx_basic.h" |
| 14 #include "core/fxcrt/fx_ext.h" | 14 #include "core/fxcrt/fx_ext.h" |
| 15 | 15 |
| 16 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ | 16 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ |
| 17 #include <wincrypt.h> | 17 #include <wincrypt.h> |
| 18 #else | 18 #else |
| 19 #include <ctime> | 19 #include <ctime> |
| 20 #endif | 20 #endif |
| 21 | 21 |
| 22 #ifdef PDF_ENABLE_XFA | 22 #ifdef PDF_ENABLE_XFA |
| 23 | 23 |
| 24 class CFX_CRTFileAccess : public IFX_FileAccess { | |
| 25 public: | |
| 26 CFX_CRTFileAccess(); | |
| 27 ~CFX_CRTFileAccess() override; | |
| 28 | |
| 29 // IFX_FileAccess | |
| 30 void Release() override; | |
| 31 IFX_FileAccess* Retain() override; | |
| 32 void GetPath(CFX_WideString& wsPath) override; | |
| 33 IFX_SeekableStream* CreateFileStream(uint32_t dwModes) override; | |
| 34 | |
| 35 bool Init(const CFX_WideStringC& wsPath); | |
| 36 | |
| 37 protected: | |
|
npm
2016/12/01 21:21:49
Can this be private?
Tom Sepez
2016/12/01 21:33:45
Done.
| |
| 38 CFX_WideString m_path; | |
| 39 uint32_t m_RefCount; | |
| 40 }; | |
| 41 | |
| 24 CFX_CRTFileAccess::CFX_CRTFileAccess() : m_RefCount(0) {} | 42 CFX_CRTFileAccess::CFX_CRTFileAccess() : m_RefCount(0) {} |
| 25 | 43 |
| 26 CFX_CRTFileAccess::~CFX_CRTFileAccess() {} | 44 CFX_CRTFileAccess::~CFX_CRTFileAccess() {} |
| 27 | 45 |
| 28 void CFX_CRTFileAccess::Release() { | 46 void CFX_CRTFileAccess::Release() { |
| 29 if (--m_RefCount == 0) | 47 if (--m_RefCount == 0) |
| 30 delete this; | 48 delete this; |
| 31 } | 49 } |
| 32 | 50 |
| 33 IFX_FileAccess* CFX_CRTFileAccess::Retain() { | 51 IFX_FileAccess* CFX_CRTFileAccess::Retain() { |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 44 } | 62 } |
| 45 | 63 |
| 46 bool CFX_CRTFileAccess::Init(const CFX_WideStringC& wsPath) { | 64 bool CFX_CRTFileAccess::Init(const CFX_WideStringC& wsPath) { |
| 47 m_path = wsPath; | 65 m_path = wsPath; |
| 48 m_RefCount = 1; | 66 m_RefCount = 1; |
| 49 return true; | 67 return true; |
| 50 } | 68 } |
| 51 | 69 |
| 52 #endif // PDF_ENABLE_XFA | 70 #endif // PDF_ENABLE_XFA |
| 53 | 71 |
| 72 class CFX_CRTFileStream final : public IFX_SeekableStream { | |
| 73 public: | |
| 74 explicit CFX_CRTFileStream(std::unique_ptr<IFXCRT_FileAccess> pFA); | |
| 75 ~CFX_CRTFileStream() override; | |
| 76 | |
| 77 // IFX_SeekableStream: | |
| 78 IFX_SeekableStream* Retain() override; | |
| 79 void Release() override; | |
| 80 FX_FILESIZE GetSize() override; | |
| 81 bool IsEOF() override; | |
| 82 FX_FILESIZE GetPosition() override; | |
| 83 bool ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) override; | |
| 84 size_t ReadBlock(void* buffer, size_t size) override; | |
| 85 bool WriteBlock(const void* buffer, FX_FILESIZE offset, size_t size) override; | |
| 86 bool Flush() override; | |
| 87 | |
| 88 protected: | |
|
npm
2016/12/01 21:21:49
Ditto
Tom Sepez
2016/12/01 21:33:45
Done.
| |
| 89 std::unique_ptr<IFXCRT_FileAccess> m_pFile; | |
| 90 uint32_t m_dwCount; | |
| 91 }; | |
| 92 | |
| 54 CFX_CRTFileStream::CFX_CRTFileStream(std::unique_ptr<IFXCRT_FileAccess> pFA) | 93 CFX_CRTFileStream::CFX_CRTFileStream(std::unique_ptr<IFXCRT_FileAccess> pFA) |
| 55 : m_pFile(std::move(pFA)), m_dwCount(1) {} | 94 : m_pFile(std::move(pFA)), m_dwCount(1) {} |
| 56 | 95 |
| 57 CFX_CRTFileStream::~CFX_CRTFileStream() {} | 96 CFX_CRTFileStream::~CFX_CRTFileStream() {} |
|
npm
2016/12/01 21:21:49
Can you place the other methods in CFX_CRTFileStre
Tom Sepez
2016/12/01 21:33:45
Ooops. Pasted in wrong place. fixed.
| |
| 58 | 97 |
| 98 #define FX_MEMSTREAM_BlockSize (64 * 1024) | |
| 99 #define FX_MEMSTREAM_Consecutive 0x01 | |
| 100 #define FX_MEMSTREAM_TakeOver 0x02 | |
| 101 | |
| 102 class CFX_MemoryStream final : public IFX_MemoryStream { | |
| 103 public: | |
| 104 explicit CFX_MemoryStream(bool bConsecutive); | |
| 105 CFX_MemoryStream(uint8_t* pBuffer, size_t nSize, bool bTakeOver); | |
| 106 ~CFX_MemoryStream() override; | |
| 107 | |
| 108 // IFX_MemoryStream | |
| 109 IFX_SeekableStream* Retain() override; | |
| 110 void Release() override; | |
| 111 FX_FILESIZE GetSize() override; | |
| 112 bool IsEOF() override; | |
| 113 FX_FILESIZE GetPosition() override; | |
| 114 bool ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) override; | |
| 115 size_t ReadBlock(void* buffer, size_t size) override; | |
| 116 bool WriteBlock(const void* buffer, FX_FILESIZE offset, size_t size) override; | |
| 117 bool Flush() override; | |
| 118 bool IsConsecutive() const override; | |
| 119 void EstimateSize(size_t nInitSize, size_t nGrowSize) override; | |
| 120 uint8_t* GetBuffer() const override; | |
| 121 void AttachBuffer(uint8_t* pBuffer, | |
| 122 size_t nSize, | |
| 123 bool bTakeOver = false) override; | |
| 124 void DetachBuffer() override; | |
| 125 | |
| 126 protected: | |
|
npm
2016/12/01 21:21:49
Ditto private?
Tom Sepez
2016/12/01 21:33:45
Done. Protected on a final class is always wrong.
| |
| 127 CFX_ArrayTemplate<uint8_t*> m_Blocks; | |
| 128 uint32_t m_dwCount; | |
| 129 size_t m_nTotalSize; | |
| 130 size_t m_nCurSize; | |
| 131 size_t m_nCurPos; | |
| 132 size_t m_nGrowSize; | |
| 133 uint32_t m_dwFlags; | |
| 134 bool ExpandBlocks(size_t size); | |
| 135 }; | |
| 136 | |
| 59 CFX_MemoryStream::CFX_MemoryStream(bool bConsecutive) | 137 CFX_MemoryStream::CFX_MemoryStream(bool bConsecutive) |
| 60 : m_dwCount(1), | 138 : m_dwCount(1), |
| 61 m_nTotalSize(0), | 139 m_nTotalSize(0), |
| 62 m_nCurSize(0), | 140 m_nCurSize(0), |
| 63 m_nCurPos(0), | 141 m_nCurPos(0), |
| 64 m_nGrowSize(FX_MEMSTREAM_BlockSize) { | 142 m_nGrowSize(FX_MEMSTREAM_BlockSize) { |
| 65 m_dwFlags = | 143 m_dwFlags = |
| 66 FX_MEMSTREAM_TakeOver | (bConsecutive ? FX_MEMSTREAM_Consecutive : 0); | 144 FX_MEMSTREAM_TakeOver | (bConsecutive ? FX_MEMSTREAM_Consecutive : 0); |
| 67 } | 145 } |
| 68 | 146 |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 318 } | 396 } |
| 319 | 397 |
| 320 bool CFX_CRTFileStream::WriteBlock(const void* buffer, | 398 bool CFX_CRTFileStream::WriteBlock(const void* buffer, |
| 321 FX_FILESIZE offset, | 399 FX_FILESIZE offset, |
| 322 size_t size) { | 400 size_t size) { |
| 323 return !!m_pFile->WritePos(buffer, size, offset); | 401 return !!m_pFile->WritePos(buffer, size, offset); |
| 324 } | 402 } |
| 325 | 403 |
| 326 bool CFX_CRTFileStream::Flush() { | 404 bool CFX_CRTFileStream::Flush() { |
| 327 return m_pFile->Flush(); | 405 return m_pFile->Flush(); |
| 328 } | 406 } |
|
npm
2016/12/01 21:21:49
So now everything above this can go inside namespa
Tom Sepez
2016/12/01 21:33:45
Probably. Done.
| |
| 329 | 407 |
| 330 #ifdef PDF_ENABLE_XFA | 408 #ifdef PDF_ENABLE_XFA |
| 331 IFX_FileAccess* FX_CreateDefaultFileAccess(const CFX_WideStringC& wsPath) { | 409 IFX_FileAccess* FX_CreateDefaultFileAccess(const CFX_WideStringC& wsPath) { |
| 332 if (wsPath.GetLength() == 0) | 410 if (wsPath.GetLength() == 0) |
| 333 return nullptr; | 411 return nullptr; |
| 334 | 412 |
| 335 CFX_CRTFileAccess* pFA = new CFX_CRTFileAccess; | 413 CFX_CRTFileAccess* pFA = new CFX_CRTFileAccess; |
| 336 pFA->Init(wsPath); | 414 pFA->Init(wsPath); |
| 337 return pFA; | 415 return pFA; |
| 338 } | 416 } |
| (...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 620 b = ((const uint8_t*)pGUID)[i]; | 698 b = ((const uint8_t*)pGUID)[i]; |
| 621 *pBuf++ = gs_FX_pHexChars[b >> 4]; | 699 *pBuf++ = gs_FX_pHexChars[b >> 4]; |
| 622 *pBuf++ = gs_FX_pHexChars[b & 0x0F]; | 700 *pBuf++ = gs_FX_pHexChars[b & 0x0F]; |
| 623 if (bSeparator && (i == 3 || i == 5 || i == 7 || i == 9)) { | 701 if (bSeparator && (i == 3 || i == 5 || i == 7 || i == 9)) { |
| 624 *pBuf++ = L'-'; | 702 *pBuf++ = L'-'; |
| 625 } | 703 } |
| 626 } | 704 } |
| 627 bsStr.ReleaseBuffer(bSeparator ? 36 : 32); | 705 bsStr.ReleaseBuffer(bSeparator ? 36 : 32); |
| 628 } | 706 } |
| 629 #endif // PDF_ENABLE_XFA | 707 #endif // PDF_ENABLE_XFA |
| OLD | NEW |