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 namespace { | 22 namespace { |
23 | 23 |
24 #ifdef PDF_ENABLE_XFA | 24 #ifdef PDF_ENABLE_XFA |
25 | 25 |
26 class CFX_CRTFileAccess : public IFX_FileAccess { | 26 class CFX_CRTFileAccess : public IFX_FileAccess { |
27 public: | 27 public: |
28 CFX_CRTFileAccess(); | 28 template <typename T, typename... Args> |
29 ~CFX_CRTFileAccess() override; | 29 friend CFX_RetainPtr<T> pdfium::MakeRetain(Args&&... args); |
dsinclair
2016/12/07 23:05:03
Does this need to be public?
Tom Sepez
2016/12/07 23:26:55
In C++, the placement of the friend statement does
| |
30 | 30 |
31 // IFX_FileAccess | 31 // IFX_FileAccess |
32 void Release() override; | |
33 IFX_FileAccess* Retain() override; | |
34 void GetPath(CFX_WideString& wsPath) override; | 32 void GetPath(CFX_WideString& wsPath) override; |
35 CFX_RetainPtr<IFX_SeekableStream> CreateFileStream(uint32_t dwModes) override; | 33 CFX_RetainPtr<IFX_SeekableStream> CreateFileStream(uint32_t dwModes) override; |
36 | 34 |
37 bool Init(const CFX_WideStringC& wsPath); | 35 bool Init(const CFX_WideStringC& wsPath); |
38 | 36 |
39 private: | 37 private: |
38 CFX_CRTFileAccess(); | |
39 ~CFX_CRTFileAccess() override; | |
40 | |
40 CFX_WideString m_path; | 41 CFX_WideString m_path; |
41 uint32_t m_RefCount; | |
42 }; | 42 }; |
43 | 43 |
44 CFX_CRTFileAccess::CFX_CRTFileAccess() : m_RefCount(0) {} | 44 CFX_CRTFileAccess::CFX_CRTFileAccess() {} |
45 | 45 |
46 CFX_CRTFileAccess::~CFX_CRTFileAccess() {} | 46 CFX_CRTFileAccess::~CFX_CRTFileAccess() {} |
47 | 47 |
48 void CFX_CRTFileAccess::Release() { | |
49 if (--m_RefCount == 0) | |
50 delete this; | |
51 } | |
52 | |
53 IFX_FileAccess* CFX_CRTFileAccess::Retain() { | |
54 m_RefCount++; | |
55 return (IFX_FileAccess*)this; | |
56 } | |
57 | |
58 void CFX_CRTFileAccess::GetPath(CFX_WideString& wsPath) { | 48 void CFX_CRTFileAccess::GetPath(CFX_WideString& wsPath) { |
59 wsPath = m_path; | 49 wsPath = m_path; |
60 } | 50 } |
61 | 51 |
62 CFX_RetainPtr<IFX_SeekableStream> CFX_CRTFileAccess::CreateFileStream( | 52 CFX_RetainPtr<IFX_SeekableStream> CFX_CRTFileAccess::CreateFileStream( |
63 uint32_t dwModes) { | 53 uint32_t dwModes) { |
64 return IFX_SeekableStream::CreateFromFilename(m_path.c_str(), dwModes); | 54 return IFX_SeekableStream::CreateFromFilename(m_path.c_str(), dwModes); |
65 } | 55 } |
66 | 56 |
67 bool CFX_CRTFileAccess::Init(const CFX_WideStringC& wsPath) { | 57 bool CFX_CRTFileAccess::Init(const CFX_WideStringC& wsPath) { |
68 m_path = wsPath; | 58 m_path = wsPath; |
69 m_RefCount = 1; | |
70 return true; | 59 return true; |
71 } | 60 } |
72 | 61 |
73 #endif // PDF_ENABLE_XFA | 62 #endif // PDF_ENABLE_XFA |
74 | 63 |
75 class CFX_CRTFileStream final : public IFX_SeekableStream { | 64 class CFX_CRTFileStream final : public IFX_SeekableStream { |
76 public: | 65 public: |
77 template <typename T, typename... Args> | 66 template <typename T, typename... Args> |
78 friend CFX_RetainPtr<T> pdfium::MakeRetain(Args&&... args); | 67 friend CFX_RetainPtr<T> pdfium::MakeRetain(Args&&... args); |
79 | 68 |
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
378 uint8_t* pBlock = FX_Alloc(uint8_t, m_nGrowSize); | 367 uint8_t* pBlock = FX_Alloc(uint8_t, m_nGrowSize); |
379 m_Blocks.SetAt(iCount++, pBlock); | 368 m_Blocks.SetAt(iCount++, pBlock); |
380 m_nTotalSize += m_nGrowSize; | 369 m_nTotalSize += m_nGrowSize; |
381 } | 370 } |
382 return true; | 371 return true; |
383 } | 372 } |
384 | 373 |
385 } // namespace | 374 } // namespace |
386 | 375 |
387 #ifdef PDF_ENABLE_XFA | 376 #ifdef PDF_ENABLE_XFA |
388 IFX_FileAccess* IFX_FileAccess::CreateDefault(const CFX_WideStringC& wsPath) { | 377 CFX_RetainPtr<IFX_FileAccess> IFX_FileAccess::CreateDefault( |
378 const CFX_WideStringC& wsPath) { | |
389 if (wsPath.GetLength() == 0) | 379 if (wsPath.GetLength() == 0) |
390 return nullptr; | 380 return nullptr; |
391 | 381 |
392 CFX_CRTFileAccess* pFA = new CFX_CRTFileAccess; | 382 auto pFA = pdfium::MakeRetain<CFX_CRTFileAccess>(); |
393 pFA->Init(wsPath); | 383 pFA->Init(wsPath); |
394 return pFA; | 384 return pFA; |
395 } | 385 } |
396 #endif // PDF_ENABLE_XFA | 386 #endif // PDF_ENABLE_XFA |
397 | 387 |
398 // static | 388 // static |
399 CFX_RetainPtr<IFX_SeekableStream> IFX_SeekableStream::CreateFromFilename( | 389 CFX_RetainPtr<IFX_SeekableStream> IFX_SeekableStream::CreateFromFilename( |
400 const FX_CHAR* filename, | 390 const FX_CHAR* filename, |
401 uint32_t dwModes) { | 391 uint32_t dwModes) { |
402 std::unique_ptr<IFXCRT_FileAccess> pFA(IFXCRT_FileAccess::Create()); | 392 std::unique_ptr<IFXCRT_FileAccess> pFA(IFXCRT_FileAccess::Create()); |
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
677 b = ((const uint8_t*)pGUID)[i]; | 667 b = ((const uint8_t*)pGUID)[i]; |
678 *pBuf++ = gs_FX_pHexChars[b >> 4]; | 668 *pBuf++ = gs_FX_pHexChars[b >> 4]; |
679 *pBuf++ = gs_FX_pHexChars[b & 0x0F]; | 669 *pBuf++ = gs_FX_pHexChars[b & 0x0F]; |
680 if (bSeparator && (i == 3 || i == 5 || i == 7 || i == 9)) { | 670 if (bSeparator && (i == 3 || i == 5 || i == 7 || i == 9)) { |
681 *pBuf++ = L'-'; | 671 *pBuf++ = L'-'; |
682 } | 672 } |
683 } | 673 } |
684 bsStr.ReleaseBuffer(bSeparator ? 36 : 32); | 674 bsStr.ReleaseBuffer(bSeparator ? 36 : 32); |
685 } | 675 } |
686 #endif // PDF_ENABLE_XFA | 676 #endif // PDF_ENABLE_XFA |
OLD | NEW |