1 // Copyright 2016 PDFium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 6 7 #ifndef CORE_FPDFAPI_PARSER_CPDF_STREAM_ACC_H_ 8 #define CORE_FPDFAPI_PARSER_CPDF_STREAM_ACC_H_ 9 10 #include <memory> 11 12 #include "core/fxcrt/fx_memory_wrappers.h" 13 #include "core/fxcrt/fx_string.h" 14 #include "core/fxcrt/fx_system.h" 15 #include "core/fxcrt/maybe_owned.h" 16 #include "core/fxcrt/retain_ptr.h" 17 #include "third_party/base/span.h" 18 19 class CPDF_Dictionary; 20 class CPDF_Stream; 21 22 class CPDF_StreamAcc final : public Retainable { 23 public: 24 template <typename T, typename... Args> 25 friend RetainPtr<T> pdfium::MakeRetain(Args&&... args); 26 27 CPDF_StreamAcc(const CPDF_StreamAcc&) = delete; 28 CPDF_StreamAcc& operator=(const CPDF_StreamAcc&) = delete; 29 30 void LoadAllDataFiltered(); 31 void LoadAllDataFilteredWithEstimatedSize(uint32_t estimated_size); 32 void LoadAllDataImageAcc(uint32_t estimated_size); 33 void LoadAllDataRaw(); 34 GetStream()35 const CPDF_Stream* GetStream() const { return m_pStream.Get(); } 36 const CPDF_Dictionary* GetDict() const; 37 38 uint8_t* GetData() const; 39 uint32_t GetSize() const; 40 pdfium::span<uint8_t> GetSpan(); 41 pdfium::span<const uint8_t> GetSpan() const; 42 ByteString ComputeDigest() const; GetImageDecoder()43 ByteString GetImageDecoder() const { return m_ImageDecoder; } GetImageParam()44 const CPDF_Dictionary* GetImageParam() const { return m_pImageParam.Get(); } 45 std::unique_ptr<uint8_t, FxFreeDeleter> DetachData(); 46 47 private: 48 explicit CPDF_StreamAcc(const CPDF_Stream* pStream); 49 ~CPDF_StreamAcc() override; 50 51 void LoadAllData(bool bRawAccess, uint32_t estimated_size, bool bImageAcc); 52 void ProcessRawData(); 53 void ProcessFilteredData(uint32_t estimated_size, bool bImageAcc); 54 55 // Reads the raw data from |m_pStream|, or return nullptr on failure. 56 std::unique_ptr<uint8_t, FxFreeDeleter> ReadRawStream() const; 57 58 MaybeOwned<uint8_t, FxFreeDeleter> m_pData; 59 uint32_t m_dwSize = 0; 60 ByteString m_ImageDecoder; 61 RetainPtr<const CPDF_Dictionary> m_pImageParam; 62 RetainPtr<const CPDF_Stream> const m_pStream; 63 }; 64 65 #endif // CORE_FPDFAPI_PARSER_CPDF_STREAM_ACC_H_ 66