| 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/fx_safe_types.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" |
| 17 #include "third_party/base/numerics/safe_conversions_impl.h" |
| 16 #include "third_party/base/ptr_util.h" | 18 #include "third_party/base/ptr_util.h" |
| 17 | 19 |
| 18 // These checks are here because core/ and public/ cannot depend on each other. | 20 // These checks are here because core/ and public/ cannot depend on each other. |
| 19 static_assert(CPDF_DataAvail::DataError == PDF_DATA_ERROR, | 21 static_assert(CPDF_DataAvail::DataError == PDF_DATA_ERROR, |
| 20 "CPDF_DataAvail::DataError value mismatch"); | 22 "CPDF_DataAvail::DataError value mismatch"); |
| 21 static_assert(CPDF_DataAvail::DataNotAvailable == PDF_DATA_NOTAVAIL, | 23 static_assert(CPDF_DataAvail::DataNotAvailable == PDF_DATA_NOTAVAIL, |
| 22 "CPDF_DataAvail::DataNotAvailable value mismatch"); | 24 "CPDF_DataAvail::DataNotAvailable value mismatch"); |
| 23 static_assert(CPDF_DataAvail::DataAvailable == PDF_DATA_AVAIL, | 25 static_assert(CPDF_DataAvail::DataAvailable == PDF_DATA_AVAIL, |
| 24 "CPDF_DataAvail::DataAvailable value mismatch"); | 26 "CPDF_DataAvail::DataAvailable value mismatch"); |
| 25 | 27 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 52 bool IsDataAvail(FX_FILESIZE offset, uint32_t size) override { | 54 bool IsDataAvail(FX_FILESIZE offset, uint32_t size) override { |
| 53 return !!m_pfileAvail->IsDataAvail(m_pfileAvail, offset, size); | 55 return !!m_pfileAvail->IsDataAvail(m_pfileAvail, offset, size); |
| 54 } | 56 } |
| 55 | 57 |
| 56 private: | 58 private: |
| 57 FX_FILEAVAIL* m_pfileAvail; | 59 FX_FILEAVAIL* m_pfileAvail; |
| 58 }; | 60 }; |
| 59 | 61 |
| 60 class CFPDF_FileAccessWrap : public IFX_SeekableReadStream { | 62 class CFPDF_FileAccessWrap : public IFX_SeekableReadStream { |
| 61 public: | 63 public: |
| 62 CFPDF_FileAccessWrap() { m_pFileAccess = nullptr; } | 64 CFPDF_FileAccessWrap() { |
| 65 m_pFileAccess = nullptr; |
| 66 m_nCurPos = 0; |
| 67 } |
| 63 ~CFPDF_FileAccessWrap() override {} | 68 ~CFPDF_FileAccessWrap() override {} |
| 64 | 69 |
| 65 void Set(FPDF_FILEACCESS* pFile) { m_pFileAccess = pFile; } | 70 void Set(FPDF_FILEACCESS* pFile) { m_pFileAccess = pFile; } |
| 66 | 71 |
| 67 // IFX_SeekableReadStream | 72 bool IsEOF() override { |
| 73 return m_nCurPos >= |
| 74 pdfium::base::checked_cast<FX_FILESIZE>(m_pFileAccess->m_FileLen); |
| 75 } |
| 76 |
| 77 // IFX_FileRead |
| 68 FX_FILESIZE GetSize() override { return m_pFileAccess->m_FileLen; } | 78 FX_FILESIZE GetSize() override { return m_pFileAccess->m_FileLen; } |
| 69 | 79 |
| 70 bool ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) override { | 80 size_t ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) override { |
| 71 return !!m_pFileAccess->m_GetBlock(m_pFileAccess->m_Param, offset, | 81 int blockSize = m_pFileAccess->m_GetBlock(m_pFileAccess->m_Param, offset, |
| 72 (uint8_t*)buffer, size); | 82 (uint8_t*)buffer, size); |
| 83 m_nCurPos = offset + pdfium::base::checked_cast<FX_FILESIZE>(blockSize); |
| 84 return pdfium::base::checked_cast<size_t>(blockSize); |
| 73 } | 85 } |
| 74 | 86 |
| 75 void Release() override {} | 87 void Release() override {} |
| 76 | 88 |
| 77 private: | 89 private: |
| 78 FPDF_FILEACCESS* m_pFileAccess; | 90 FPDF_FILEACCESS* m_pFileAccess; |
| 91 FX_FILESIZE m_nCurPos; |
| 79 }; | 92 }; |
| 80 | 93 |
| 81 class CFPDF_DownloadHintsWrap : public CPDF_DataAvail::DownloadHints { | 94 class CFPDF_DownloadHintsWrap : public CPDF_DataAvail::DownloadHints { |
| 82 public: | 95 public: |
| 83 explicit CFPDF_DownloadHintsWrap(FX_DOWNLOADHINTS* pDownloadHints) { | 96 explicit CFPDF_DownloadHintsWrap(FX_DOWNLOADHINTS* pDownloadHints) { |
| 84 m_pDownloadHints = pDownloadHints; | 97 m_pDownloadHints = pDownloadHints; |
| 85 } | 98 } |
| 86 ~CFPDF_DownloadHintsWrap() override {} | 99 ~CFPDF_DownloadHintsWrap() override {} |
| 87 | 100 |
| 88 public: | 101 public: |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 CFPDF_DownloadHintsWrap hints_wrap(hints); | 193 CFPDF_DownloadHintsWrap hints_wrap(hints); |
| 181 return CFPDFDataAvailFromFPDFAvail(avail)->m_pDataAvail->IsFormAvail( | 194 return CFPDFDataAvailFromFPDFAvail(avail)->m_pDataAvail->IsFormAvail( |
| 182 &hints_wrap); | 195 &hints_wrap); |
| 183 } | 196 } |
| 184 | 197 |
| 185 DLLEXPORT int STDCALL FPDFAvail_IsLinearized(FPDF_AVAIL avail) { | 198 DLLEXPORT int STDCALL FPDFAvail_IsLinearized(FPDF_AVAIL avail) { |
| 186 if (!avail) | 199 if (!avail) |
| 187 return PDF_LINEARIZATION_UNKNOWN; | 200 return PDF_LINEARIZATION_UNKNOWN; |
| 188 return CFPDFDataAvailFromFPDFAvail(avail)->m_pDataAvail->IsLinearizedPDF(); | 201 return CFPDFDataAvailFromFPDFAvail(avail)->m_pDataAvail->IsLinearizedPDF(); |
| 189 } | 202 } |
| OLD | NEW |