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 "public/fpdf_dataavail.h" | 7 #include "public/fpdf_dataavail.h" |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 #include <utility> | 10 #include <utility> |
11 | 11 |
12 #include "core/fpdfapi/parser/cpdf_data_avail.h" | 12 #include "core/fpdfapi/parser/cpdf_data_avail.h" |
13 #include "core/fpdfapi/parser/cpdf_document.h" | 13 #include "core/fpdfapi/parser/cpdf_document.h" |
| 14 #include "core/fxcrt/cfx_retain_ptr.h" |
14 #include "fpdfsdk/fsdk_define.h" | 15 #include "fpdfsdk/fsdk_define.h" |
15 #include "public/fpdf_formfill.h" | 16 #include "public/fpdf_formfill.h" |
16 #include "third_party/base/ptr_util.h" | 17 #include "third_party/base/ptr_util.h" |
17 | 18 |
18 // These checks are here because core/ and public/ cannot depend on each other. | 19 // These checks are here because core/ and public/ cannot depend on each other. |
19 static_assert(CPDF_DataAvail::DataError == PDF_DATA_ERROR, | 20 static_assert(CPDF_DataAvail::DataError == PDF_DATA_ERROR, |
20 "CPDF_DataAvail::DataError value mismatch"); | 21 "CPDF_DataAvail::DataError value mismatch"); |
21 static_assert(CPDF_DataAvail::DataNotAvailable == PDF_DATA_NOTAVAIL, | 22 static_assert(CPDF_DataAvail::DataNotAvailable == PDF_DATA_NOTAVAIL, |
22 "CPDF_DataAvail::DataNotAvailable value mismatch"); | 23 "CPDF_DataAvail::DataNotAvailable value mismatch"); |
23 static_assert(CPDF_DataAvail::DataAvailable == PDF_DATA_AVAIL, | 24 static_assert(CPDF_DataAvail::DataAvailable == PDF_DATA_AVAIL, |
(...skipping 12 matching lines...) Expand all Loading... |
36 "CPDF_DataAvail::FormNotAvailable value mismatch"); | 37 "CPDF_DataAvail::FormNotAvailable value mismatch"); |
37 static_assert(CPDF_DataAvail::FormAvailable == PDF_FORM_AVAIL, | 38 static_assert(CPDF_DataAvail::FormAvailable == PDF_FORM_AVAIL, |
38 "CPDF_DataAvail::FormAvailable value mismatch"); | 39 "CPDF_DataAvail::FormAvailable value mismatch"); |
39 static_assert(CPDF_DataAvail::FormNotExist == PDF_FORM_NOTEXIST, | 40 static_assert(CPDF_DataAvail::FormNotExist == PDF_FORM_NOTEXIST, |
40 "CPDF_DataAvail::FormNotExist value mismatch"); | 41 "CPDF_DataAvail::FormNotExist value mismatch"); |
41 | 42 |
42 namespace { | 43 namespace { |
43 | 44 |
44 class CFPDF_FileAvailWrap : public CPDF_DataAvail::FileAvail { | 45 class CFPDF_FileAvailWrap : public CPDF_DataAvail::FileAvail { |
45 public: | 46 public: |
46 CFPDF_FileAvailWrap() { m_pfileAvail = nullptr; } | 47 CFPDF_FileAvailWrap() : m_pfileAvail(nullptr) {} |
47 ~CFPDF_FileAvailWrap() override {} | 48 ~CFPDF_FileAvailWrap() override {} |
48 | 49 |
49 void Set(FX_FILEAVAIL* pfileAvail) { m_pfileAvail = pfileAvail; } | 50 void Set(FX_FILEAVAIL* pfileAvail) { m_pfileAvail = pfileAvail; } |
50 | 51 |
51 // CPDF_DataAvail::FileAvail: | 52 // CPDF_DataAvail::FileAvail: |
52 bool IsDataAvail(FX_FILESIZE offset, uint32_t size) override { | 53 bool IsDataAvail(FX_FILESIZE offset, uint32_t size) override { |
53 return !!m_pfileAvail->IsDataAvail(m_pfileAvail, offset, size); | 54 return !!m_pfileAvail->IsDataAvail(m_pfileAvail, offset, size); |
54 } | 55 } |
55 | 56 |
56 private: | 57 private: |
57 FX_FILEAVAIL* m_pfileAvail; | 58 FX_FILEAVAIL* m_pfileAvail; |
58 }; | 59 }; |
59 | 60 |
60 class CFPDF_FileAccessWrap : public IFX_SeekableReadStream { | 61 class CFPDF_FileAccessWrap : public IFX_SeekableReadStream { |
61 public: | 62 public: |
62 CFPDF_FileAccessWrap() { m_pFileAccess = nullptr; } | 63 static CFX_RetainPtr<CFPDF_FileAccessWrap> Create() { |
| 64 return CFX_RetainPtr<CFPDF_FileAccessWrap>(new CFPDF_FileAccessWrap()); |
| 65 } |
63 ~CFPDF_FileAccessWrap() override {} | 66 ~CFPDF_FileAccessWrap() override {} |
64 | 67 |
65 void Set(FPDF_FILEACCESS* pFile) { m_pFileAccess = pFile; } | 68 void Set(FPDF_FILEACCESS* pFile) { m_pFileAccess = pFile; } |
66 | 69 |
67 // IFX_SeekableReadStream | 70 // IFX_SeekableReadStream |
68 FX_FILESIZE GetSize() override { return m_pFileAccess->m_FileLen; } | 71 FX_FILESIZE GetSize() override { return m_pFileAccess->m_FileLen; } |
69 | 72 |
70 bool ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) override { | 73 bool ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) override { |
71 return !!m_pFileAccess->m_GetBlock(m_pFileAccess->m_Param, offset, | 74 return !!m_pFileAccess->m_GetBlock(m_pFileAccess->m_Param, offset, |
72 (uint8_t*)buffer, size); | 75 (uint8_t*)buffer, size); |
73 } | 76 } |
74 | 77 |
75 void Release() override {} | 78 private: |
| 79 CFPDF_FileAccessWrap() : m_pFileAccess(nullptr) {} |
76 | 80 |
77 private: | |
78 FPDF_FILEACCESS* m_pFileAccess; | 81 FPDF_FILEACCESS* m_pFileAccess; |
79 }; | 82 }; |
80 | 83 |
81 class CFPDF_DownloadHintsWrap : public CPDF_DataAvail::DownloadHints { | 84 class CFPDF_DownloadHintsWrap : public CPDF_DataAvail::DownloadHints { |
82 public: | 85 public: |
83 explicit CFPDF_DownloadHintsWrap(FX_DOWNLOADHINTS* pDownloadHints) { | 86 explicit CFPDF_DownloadHintsWrap(FX_DOWNLOADHINTS* pDownloadHints) { |
84 m_pDownloadHints = pDownloadHints; | 87 m_pDownloadHints = pDownloadHints; |
85 } | 88 } |
86 ~CFPDF_DownloadHintsWrap() override {} | 89 ~CFPDF_DownloadHintsWrap() override {} |
87 | 90 |
88 public: | 91 public: |
89 // IFX_DownloadHints | 92 // IFX_DownloadHints |
90 void AddSegment(FX_FILESIZE offset, uint32_t size) override { | 93 void AddSegment(FX_FILESIZE offset, uint32_t size) override { |
91 m_pDownloadHints->AddSegment(m_pDownloadHints, offset, size); | 94 m_pDownloadHints->AddSegment(m_pDownloadHints, offset, size); |
92 } | 95 } |
93 | 96 |
94 private: | 97 private: |
95 FX_DOWNLOADHINTS* m_pDownloadHints; | 98 FX_DOWNLOADHINTS* m_pDownloadHints; |
96 }; | 99 }; |
97 | 100 |
98 class CFPDF_DataAvail { | 101 class CFPDF_DataAvail { |
99 public: | 102 public: |
100 CFPDF_DataAvail() {} | 103 CFPDF_DataAvail() |
| 104 : m_FileAvail(new CFPDF_FileAvailWrap), |
| 105 m_FileRead(CFPDF_FileAccessWrap::Create()) {} |
101 ~CFPDF_DataAvail() {} | 106 ~CFPDF_DataAvail() {} |
102 | 107 |
103 std::unique_ptr<CPDF_DataAvail> m_pDataAvail; | 108 std::unique_ptr<CPDF_DataAvail> m_pDataAvail; |
104 CFPDF_FileAvailWrap m_FileAvail; | 109 std::unique_ptr<CFPDF_FileAvailWrap> m_FileAvail; |
105 CFPDF_FileAccessWrap m_FileRead; | 110 CFX_RetainPtr<CFPDF_FileAccessWrap> m_FileRead; |
106 }; | 111 }; |
107 | 112 |
108 CFPDF_DataAvail* CFPDFDataAvailFromFPDFAvail(FPDF_AVAIL avail) { | 113 CFPDF_DataAvail* CFPDFDataAvailFromFPDFAvail(FPDF_AVAIL avail) { |
109 return static_cast<CFPDF_DataAvail*>(avail); | 114 return static_cast<CFPDF_DataAvail*>(avail); |
110 } | 115 } |
111 | 116 |
112 } // namespace | 117 } // namespace |
113 | 118 |
114 DLLEXPORT FPDF_AVAIL STDCALL FPDFAvail_Create(FX_FILEAVAIL* file_avail, | 119 DLLEXPORT FPDF_AVAIL STDCALL FPDFAvail_Create(FX_FILEAVAIL* file_avail, |
115 FPDF_FILEACCESS* file) { | 120 FPDF_FILEACCESS* file) { |
116 CFPDF_DataAvail* pAvail = new CFPDF_DataAvail; | 121 CFPDF_DataAvail* pAvail = new CFPDF_DataAvail; |
117 pAvail->m_FileAvail.Set(file_avail); | 122 pAvail->m_FileAvail->Set(file_avail); |
118 pAvail->m_FileRead.Set(file); | 123 pAvail->m_FileRead->Set(file); |
119 pAvail->m_pDataAvail = pdfium::MakeUnique<CPDF_DataAvail>( | 124 pAvail->m_pDataAvail = pdfium::MakeUnique<CPDF_DataAvail>( |
120 &pAvail->m_FileAvail, &pAvail->m_FileRead, true); | 125 pAvail->m_FileAvail.get(), pAvail->m_FileRead, true); |
121 return pAvail; | 126 return pAvail; |
122 } | 127 } |
123 | 128 |
124 DLLEXPORT void STDCALL FPDFAvail_Destroy(FPDF_AVAIL avail) { | 129 DLLEXPORT void STDCALL FPDFAvail_Destroy(FPDF_AVAIL avail) { |
125 delete (CFPDF_DataAvail*)avail; | 130 delete (CFPDF_DataAvail*)avail; |
126 } | 131 } |
127 | 132 |
128 DLLEXPORT int STDCALL FPDFAvail_IsDocAvail(FPDF_AVAIL avail, | 133 DLLEXPORT int STDCALL FPDFAvail_IsDocAvail(FPDF_AVAIL avail, |
129 FX_DOWNLOADHINTS* hints) { | 134 FX_DOWNLOADHINTS* hints) { |
130 if (!avail || !hints) | 135 if (!avail || !hints) |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 CFPDF_DownloadHintsWrap hints_wrap(hints); | 185 CFPDF_DownloadHintsWrap hints_wrap(hints); |
181 return CFPDFDataAvailFromFPDFAvail(avail)->m_pDataAvail->IsFormAvail( | 186 return CFPDFDataAvailFromFPDFAvail(avail)->m_pDataAvail->IsFormAvail( |
182 &hints_wrap); | 187 &hints_wrap); |
183 } | 188 } |
184 | 189 |
185 DLLEXPORT int STDCALL FPDFAvail_IsLinearized(FPDF_AVAIL avail) { | 190 DLLEXPORT int STDCALL FPDFAvail_IsLinearized(FPDF_AVAIL avail) { |
186 if (!avail) | 191 if (!avail) |
187 return PDF_LINEARIZATION_UNKNOWN; | 192 return PDF_LINEARIZATION_UNKNOWN; |
188 return CFPDFDataAvailFromFPDFAvail(avail)->m_pDataAvail->IsLinearizedPDF(); | 193 return CFPDFDataAvailFromFPDFAvail(avail)->m_pDataAvail->IsLinearizedPDF(); |
189 } | 194 } |
OLD | NEW |