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 "core/fpdfapi/fpdf_parser/include/cpdf_data_avail.h" |
9 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" | 10 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" |
10 #include "core/fpdfapi/fpdf_parser/include/ipdf_data_avail.h" | |
11 #include "fpdfsdk/include/fsdk_define.h" | 11 #include "fpdfsdk/include/fsdk_define.h" |
12 #include "public/fpdf_formfill.h" | 12 #include "public/fpdf_formfill.h" |
13 | 13 |
14 // These checks are here because core/ and public/ cannot depend on each other. | 14 // These checks are here because core/ and public/ cannot depend on each other. |
15 static_assert(IPDF_DataAvail::DataError == PDF_DATA_ERROR, | 15 static_assert(CPDF_DataAvail::DataError == PDF_DATA_ERROR, |
16 "IPDF_DataAvail::DataError value mismatch"); | 16 "CPDF_DataAvail::DataError value mismatch"); |
17 static_assert(IPDF_DataAvail::DataNotAvailable == PDF_DATA_NOTAVAIL, | 17 static_assert(CPDF_DataAvail::DataNotAvailable == PDF_DATA_NOTAVAIL, |
18 "IPDF_DataAvail::DataNotAvailable value mismatch"); | 18 "CPDF_DataAvail::DataNotAvailable value mismatch"); |
19 static_assert(IPDF_DataAvail::DataAvailable == PDF_DATA_AVAIL, | 19 static_assert(CPDF_DataAvail::DataAvailable == PDF_DATA_AVAIL, |
20 "IPDF_DataAvail::DataAvailable value mismatch"); | 20 "CPDF_DataAvail::DataAvailable value mismatch"); |
21 | 21 |
22 static_assert(IPDF_DataAvail::LinearizationUnknown == PDF_LINEARIZATION_UNKNOWN, | 22 static_assert(CPDF_DataAvail::LinearizationUnknown == PDF_LINEARIZATION_UNKNOWN, |
23 "IPDF_DataAvail::LinearizationUnknown value mismatch"); | 23 "CPDF_DataAvail::LinearizationUnknown value mismatch"); |
24 static_assert(IPDF_DataAvail::NotLinearized == PDF_NOT_LINEARIZED, | 24 static_assert(CPDF_DataAvail::NotLinearized == PDF_NOT_LINEARIZED, |
25 "IPDF_DataAvail::NotLinearized value mismatch"); | 25 "CPDF_DataAvail::NotLinearized value mismatch"); |
26 static_assert(IPDF_DataAvail::Linearized == PDF_LINEARIZED, | 26 static_assert(CPDF_DataAvail::Linearized == PDF_LINEARIZED, |
27 "IPDF_DataAvail::Linearized value mismatch"); | 27 "CPDF_DataAvail::Linearized value mismatch"); |
28 | 28 |
29 static_assert(IPDF_DataAvail::FormError == PDF_FORM_ERROR, | 29 static_assert(CPDF_DataAvail::FormError == PDF_FORM_ERROR, |
30 "IPDF_DataAvail::FormError value mismatch"); | 30 "CPDF_DataAvail::FormError value mismatch"); |
31 static_assert(IPDF_DataAvail::FormNotAvailable == PDF_FORM_NOTAVAIL, | 31 static_assert(CPDF_DataAvail::FormNotAvailable == PDF_FORM_NOTAVAIL, |
32 "IPDF_DataAvail::FormNotAvailable value mismatch"); | 32 "CPDF_DataAvail::FormNotAvailable value mismatch"); |
33 static_assert(IPDF_DataAvail::FormAvailable == PDF_FORM_AVAIL, | 33 static_assert(CPDF_DataAvail::FormAvailable == PDF_FORM_AVAIL, |
34 "IPDF_DataAvail::FormAvailable value mismatch"); | 34 "CPDF_DataAvail::FormAvailable value mismatch"); |
35 static_assert(IPDF_DataAvail::FormNotExist == PDF_FORM_NOTEXIST, | 35 static_assert(CPDF_DataAvail::FormNotExist == PDF_FORM_NOTEXIST, |
36 "IPDF_DataAvail::FormNotExist value mismatch"); | 36 "CPDF_DataAvail::FormNotExist value mismatch"); |
37 | 37 |
38 class CFPDF_FileAvailWrap : public IPDF_DataAvail::FileAvail { | 38 namespace { |
| 39 |
| 40 class CFPDF_FileAvailWrap : public CPDF_DataAvail::FileAvail { |
39 public: | 41 public: |
40 CFPDF_FileAvailWrap() { m_pfileAvail = nullptr; } | 42 CFPDF_FileAvailWrap() { m_pfileAvail = nullptr; } |
41 ~CFPDF_FileAvailWrap() override {} | 43 ~CFPDF_FileAvailWrap() override {} |
42 | 44 |
43 void Set(FX_FILEAVAIL* pfileAvail) { m_pfileAvail = pfileAvail; } | 45 void Set(FX_FILEAVAIL* pfileAvail) { m_pfileAvail = pfileAvail; } |
44 | 46 |
45 // IPDF_DataAvail::FileAvail: | 47 // CPDF_DataAvail::FileAvail: |
46 FX_BOOL IsDataAvail(FX_FILESIZE offset, uint32_t size) override { | 48 FX_BOOL IsDataAvail(FX_FILESIZE offset, uint32_t size) override { |
47 return m_pfileAvail->IsDataAvail(m_pfileAvail, offset, size); | 49 return m_pfileAvail->IsDataAvail(m_pfileAvail, offset, size); |
48 } | 50 } |
49 | 51 |
50 private: | 52 private: |
51 FX_FILEAVAIL* m_pfileAvail; | 53 FX_FILEAVAIL* m_pfileAvail; |
52 }; | 54 }; |
53 | 55 |
54 class CFPDF_FileAccessWrap : public IFX_FileRead { | 56 class CFPDF_FileAccessWrap : public IFX_FileRead { |
55 public: | 57 public: |
56 CFPDF_FileAccessWrap() { m_pFileAccess = nullptr; } | 58 CFPDF_FileAccessWrap() { m_pFileAccess = nullptr; } |
57 ~CFPDF_FileAccessWrap() override {} | 59 ~CFPDF_FileAccessWrap() override {} |
58 | 60 |
59 void Set(FPDF_FILEACCESS* pFile) { m_pFileAccess = pFile; } | 61 void Set(FPDF_FILEACCESS* pFile) { m_pFileAccess = pFile; } |
60 | 62 |
61 // IFX_FileRead | 63 // IFX_FileRead |
62 FX_FILESIZE GetSize() override { return m_pFileAccess->m_FileLen; } | 64 FX_FILESIZE GetSize() override { return m_pFileAccess->m_FileLen; } |
63 | 65 |
64 FX_BOOL ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) override { | 66 FX_BOOL ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) override { |
65 return m_pFileAccess->m_GetBlock(m_pFileAccess->m_Param, offset, | 67 return m_pFileAccess->m_GetBlock(m_pFileAccess->m_Param, offset, |
66 (uint8_t*)buffer, size); | 68 (uint8_t*)buffer, size); |
67 } | 69 } |
68 | 70 |
69 void Release() override {} | 71 void Release() override {} |
70 | 72 |
71 private: | 73 private: |
72 FPDF_FILEACCESS* m_pFileAccess; | 74 FPDF_FILEACCESS* m_pFileAccess; |
73 }; | 75 }; |
74 | 76 |
75 class CFPDF_DownloadHintsWrap : public IPDF_DataAvail::DownloadHints { | 77 class CFPDF_DownloadHintsWrap : public CPDF_DataAvail::DownloadHints { |
76 public: | 78 public: |
77 explicit CFPDF_DownloadHintsWrap(FX_DOWNLOADHINTS* pDownloadHints) { | 79 explicit CFPDF_DownloadHintsWrap(FX_DOWNLOADHINTS* pDownloadHints) { |
78 m_pDownloadHints = pDownloadHints; | 80 m_pDownloadHints = pDownloadHints; |
79 } | 81 } |
80 ~CFPDF_DownloadHintsWrap() override {} | 82 ~CFPDF_DownloadHintsWrap() override {} |
81 | 83 |
82 public: | 84 public: |
83 // IFX_DownloadHints | 85 // IFX_DownloadHints |
84 void AddSegment(FX_FILESIZE offset, uint32_t size) override { | 86 void AddSegment(FX_FILESIZE offset, uint32_t size) override { |
85 m_pDownloadHints->AddSegment(m_pDownloadHints, offset, size); | 87 m_pDownloadHints->AddSegment(m_pDownloadHints, offset, size); |
86 } | 88 } |
87 | 89 |
88 private: | 90 private: |
89 FX_DOWNLOADHINTS* m_pDownloadHints; | 91 FX_DOWNLOADHINTS* m_pDownloadHints; |
90 }; | 92 }; |
91 | 93 |
92 class CFPDF_DataAvail { | 94 class CFPDF_DataAvail { |
93 public: | 95 public: |
94 CFPDF_DataAvail() { m_pDataAvail = nullptr; } | 96 CFPDF_DataAvail() {} |
| 97 ~CFPDF_DataAvail() {} |
95 | 98 |
96 ~CFPDF_DataAvail() { delete m_pDataAvail; } | 99 std::unique_ptr<CPDF_DataAvail> m_pDataAvail; |
97 | |
98 IPDF_DataAvail* m_pDataAvail; | |
99 CFPDF_FileAvailWrap m_FileAvail; | 100 CFPDF_FileAvailWrap m_FileAvail; |
100 CFPDF_FileAccessWrap m_FileRead; | 101 CFPDF_FileAccessWrap m_FileRead; |
101 }; | 102 }; |
102 | 103 |
| 104 CFPDF_DataAvail* CFPDFDataAvailFromFPDFAvail(FPDF_AVAIL avail) { |
| 105 return static_cast<CFPDF_DataAvail*>(avail); |
| 106 } |
| 107 |
| 108 } // namespace |
| 109 |
103 DLLEXPORT FPDF_AVAIL STDCALL FPDFAvail_Create(FX_FILEAVAIL* file_avail, | 110 DLLEXPORT FPDF_AVAIL STDCALL FPDFAvail_Create(FX_FILEAVAIL* file_avail, |
104 FPDF_FILEACCESS* file) { | 111 FPDF_FILEACCESS* file) { |
105 CFPDF_DataAvail* pAvail = new CFPDF_DataAvail; | 112 CFPDF_DataAvail* pAvail = new CFPDF_DataAvail; |
106 pAvail->m_FileAvail.Set(file_avail); | 113 pAvail->m_FileAvail.Set(file_avail); |
107 pAvail->m_FileRead.Set(file); | 114 pAvail->m_FileRead.Set(file); |
108 pAvail->m_pDataAvail = | 115 pAvail->m_pDataAvail.reset( |
109 IPDF_DataAvail::Create(&pAvail->m_FileAvail, &pAvail->m_FileRead); | 116 new CPDF_DataAvail(&pAvail->m_FileAvail, &pAvail->m_FileRead, TRUE)); |
110 return pAvail; | 117 return pAvail; |
111 } | 118 } |
112 | 119 |
113 DLLEXPORT void STDCALL FPDFAvail_Destroy(FPDF_AVAIL avail) { | 120 DLLEXPORT void STDCALL FPDFAvail_Destroy(FPDF_AVAIL avail) { |
114 delete (CFPDF_DataAvail*)avail; | 121 delete (CFPDF_DataAvail*)avail; |
115 } | 122 } |
116 | 123 |
117 DLLEXPORT int STDCALL FPDFAvail_IsDocAvail(FPDF_AVAIL avail, | 124 DLLEXPORT int STDCALL FPDFAvail_IsDocAvail(FPDF_AVAIL avail, |
118 FX_DOWNLOADHINTS* hints) { | 125 FX_DOWNLOADHINTS* hints) { |
119 if (!avail || !hints) | 126 if (!avail || !hints) |
120 return PDF_DATA_ERROR; | 127 return PDF_DATA_ERROR; |
121 CFPDF_DownloadHintsWrap hints_wrap(hints); | 128 CFPDF_DownloadHintsWrap hints_wrap(hints); |
122 return ((CFPDF_DataAvail*)avail)->m_pDataAvail->IsDocAvail(&hints_wrap); | 129 return CFPDFDataAvailFromFPDFAvail(avail)->m_pDataAvail->IsDocAvail( |
| 130 &hints_wrap); |
123 } | 131 } |
124 | 132 |
125 DLLEXPORT FPDF_DOCUMENT STDCALL | 133 DLLEXPORT FPDF_DOCUMENT STDCALL |
126 FPDFAvail_GetDocument(FPDF_AVAIL avail, FPDF_BYTESTRING password) { | 134 FPDFAvail_GetDocument(FPDF_AVAIL avail, FPDF_BYTESTRING password) { |
127 CFPDF_DataAvail* pDataAvail = static_cast<CFPDF_DataAvail*>(avail); | 135 CFPDF_DataAvail* pDataAvail = static_cast<CFPDF_DataAvail*>(avail); |
128 if (!pDataAvail) | 136 if (!pDataAvail) |
129 return nullptr; | 137 return nullptr; |
130 | 138 |
131 CPDF_Parser* pParser = new CPDF_Parser; | 139 CPDF_Parser* pParser = new CPDF_Parser; |
132 pParser->SetPassword(password); | 140 pParser->SetPassword(password); |
(...skipping 13 matching lines...) Expand all Loading... |
146 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(doc); | 154 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(doc); |
147 return pDoc ? pDoc->GetParser()->GetFirstPageNo() : 0; | 155 return pDoc ? pDoc->GetParser()->GetFirstPageNo() : 0; |
148 } | 156 } |
149 | 157 |
150 DLLEXPORT int STDCALL FPDFAvail_IsPageAvail(FPDF_AVAIL avail, | 158 DLLEXPORT int STDCALL FPDFAvail_IsPageAvail(FPDF_AVAIL avail, |
151 int page_index, | 159 int page_index, |
152 FX_DOWNLOADHINTS* hints) { | 160 FX_DOWNLOADHINTS* hints) { |
153 if (!avail || !hints) | 161 if (!avail || !hints) |
154 return PDF_DATA_ERROR; | 162 return PDF_DATA_ERROR; |
155 CFPDF_DownloadHintsWrap hints_wrap(hints); | 163 CFPDF_DownloadHintsWrap hints_wrap(hints); |
156 return ((CFPDF_DataAvail*)avail) | 164 return CFPDFDataAvailFromFPDFAvail(avail)->m_pDataAvail->IsPageAvail( |
157 ->m_pDataAvail->IsPageAvail(page_index, &hints_wrap); | 165 page_index, &hints_wrap); |
158 } | 166 } |
159 | 167 |
160 DLLEXPORT int STDCALL FPDFAvail_IsFormAvail(FPDF_AVAIL avail, | 168 DLLEXPORT int STDCALL FPDFAvail_IsFormAvail(FPDF_AVAIL avail, |
161 FX_DOWNLOADHINTS* hints) { | 169 FX_DOWNLOADHINTS* hints) { |
162 if (!avail || !hints) | 170 if (!avail || !hints) |
163 return PDF_FORM_ERROR; | 171 return PDF_FORM_ERROR; |
164 CFPDF_DownloadHintsWrap hints_wrap(hints); | 172 CFPDF_DownloadHintsWrap hints_wrap(hints); |
165 return ((CFPDF_DataAvail*)avail)->m_pDataAvail->IsFormAvail(&hints_wrap); | 173 return CFPDFDataAvailFromFPDFAvail(avail)->m_pDataAvail->IsFormAvail( |
| 174 &hints_wrap); |
166 } | 175 } |
167 | 176 |
168 DLLEXPORT int STDCALL FPDFAvail_IsLinearized(FPDF_AVAIL avail) { | 177 DLLEXPORT int STDCALL FPDFAvail_IsLinearized(FPDF_AVAIL avail) { |
169 if (!avail) | 178 if (!avail) |
170 return PDF_LINEARIZATION_UNKNOWN; | 179 return PDF_LINEARIZATION_UNKNOWN; |
171 return ((CFPDF_DataAvail*)avail)->m_pDataAvail->IsLinearizedPDF(); | 180 return CFPDFDataAvailFromFPDFAvail(avail)->m_pDataAvail->IsLinearizedPDF(); |
172 } | 181 } |
OLD | NEW |