From 3ba098595ae56b64eacc0c25ab76b89a4d78d920 Mon Sep 17 00:00:00 2001 From: tsepez Date: Fri, 14 Oct 2016 16:59:10 -0700 Subject: Update CPDF_IndirectObjectHolder APIs for unique objects. Doing so highlights a few places where ownership is dubious. Add convenience functions to return an unowned reference to a newly-created indirect object. Review-Url: https://codereview.chromium.org/2419173002 --- core/fpdfapi/parser/cpdf_indirect_object_holder.h | 28 +++++++++++++++++++---- 1 file changed, 23 insertions(+), 5 deletions(-) (limited to 'core/fpdfapi/parser/cpdf_indirect_object_holder.h') diff --git a/core/fpdfapi/parser/cpdf_indirect_object_holder.h b/core/fpdfapi/parser/cpdf_indirect_object_holder.h index da4e942b5d..074e428d43 100644 --- a/core/fpdfapi/parser/cpdf_indirect_object_holder.h +++ b/core/fpdfapi/parser/cpdf_indirect_object_holder.h @@ -10,9 +10,14 @@ #include #include +#include "core/fpdfapi/parser/cpdf_object.h" +#include "core/fxcrt/cfx_string_pool_template.h" +#include "core/fxcrt/cfx_weak_ptr.h" #include "core/fxcrt/fx_system.h" -class CPDF_Object; +class CPDF_Array; +class CPDF_Dictionary; +class CPDF_Stream; class CPDF_IndirectObjectHolder { public: @@ -24,12 +29,23 @@ class CPDF_IndirectObjectHolder { CPDF_Object* GetIndirectObject(uint32_t objnum) const; CPDF_Object* GetOrParseIndirectObject(uint32_t objnum); - void ReleaseIndirectObject(uint32_t objnum); + void DeleteIndirectObject(uint32_t objnum); + + // Take ownership of |pObj|, returns unowned pointer to it. + CPDF_Object* AddIndirectObject(UniqueObject pObj); + + // Adds and owns a new object, returns unowned pointer to it. + CPDF_Array* AddIndirectArray(); + CPDF_Dictionary* AddIndirectDictionary(); + CPDF_Dictionary* AddIndirectDictionary( + const CFX_WeakPtr& pPool); + CPDF_Stream* AddIndirectStream(); + CPDF_Stream* AddIndirectStream(uint8_t* pData, + uint32_t size, + CPDF_Dictionary* pDict); - // Take ownership of |pObj|. - uint32_t AddIndirectObject(CPDF_Object* pObj); bool ReplaceIndirectObjectIfHigherGeneration(uint32_t objnum, - CPDF_Object* pObj); + UniqueObject pObj); uint32_t GetLastObjNum() const { return m_LastObjNum; } void SetLastObjNum(uint32_t objnum) { m_LastObjNum = objnum; } @@ -42,6 +58,8 @@ class CPDF_IndirectObjectHolder { private: uint32_t m_LastObjNum; + + // Ordinary deleter, not Release(). std::map> m_IndirectObjs; }; -- cgit v1.2.3