From 7e5fdd0b1a2ce17e89723fee3e58ae472e32461f Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Mon, 23 Jan 2017 16:24:26 -0500 Subject: Track CFDE_CSSComputedStyle with retained ptrs Remove the bare new and use CFX_RetainPtr to keep track of the computed styles. Change-Id: Icf235623529797176707482c78676814b7a81b9e Reviewed-on: https://pdfium-review.googlesource.com/2292 Reviewed-by: Tom Sepez Commit-Queue: dsinclair --- xfa/fde/css/cfde_csscomputedstyle.cpp | 13 +------------ xfa/fde/css/cfde_csscomputedstyle.h | 16 +++++++--------- xfa/fde/css/cfde_cssstyleselector.cpp | 5 +++-- xfa/fde/css/cfde_cssstyleselector.h | 2 +- 4 files changed, 12 insertions(+), 24 deletions(-) (limited to 'xfa/fde') diff --git a/xfa/fde/css/cfde_csscomputedstyle.cpp b/xfa/fde/css/cfde_csscomputedstyle.cpp index 010f573c04..b563bbf445 100644 --- a/xfa/fde/css/cfde_csscomputedstyle.cpp +++ b/xfa/fde/css/cfde_csscomputedstyle.cpp @@ -10,21 +10,10 @@ #include "xfa/fde/css/cfde_cssstringvalue.h" #include "xfa/fde/css/cfde_cssvaluelist.h" -CFDE_CSSComputedStyle::CFDE_CSSComputedStyle() : m_dwRefCount(1) {} +CFDE_CSSComputedStyle::CFDE_CSSComputedStyle() {} CFDE_CSSComputedStyle::~CFDE_CSSComputedStyle() {} -uint32_t CFDE_CSSComputedStyle::Retain() { - return ++m_dwRefCount; -} - -uint32_t CFDE_CSSComputedStyle::Release() { - uint32_t dwRefCount = --m_dwRefCount; - if (dwRefCount == 0) - delete this; - return dwRefCount; -} - bool CFDE_CSSComputedStyle::GetCustomStyle(const CFX_WideStringC& wsName, CFX_WideString& wsValue) const { for (int32_t i = pdfium::CollectionSize(m_CustomProperties) - 2; diff --git a/xfa/fde/css/cfde_csscomputedstyle.h b/xfa/fde/css/cfde_csscomputedstyle.h index 73eb996f0d..1f73d87631 100644 --- a/xfa/fde/css/cfde_csscomputedstyle.h +++ b/xfa/fde/css/cfde_csscomputedstyle.h @@ -15,7 +15,7 @@ class CFDE_CSSValueList; -class CFDE_CSSComputedStyle : public IFX_Retainable { +class CFDE_CSSComputedStyle : public CFX_Retainable { public: class InheritedData { public: @@ -54,13 +54,6 @@ class CFDE_CSSComputedStyle : public IFX_Retainable { bool m_bHasPadding; }; - CFDE_CSSComputedStyle(); - ~CFDE_CSSComputedStyle() override; - - // IFX_Retainable - uint32_t Retain() override; - uint32_t Release() override; - int32_t CountFontFamilies() const; const CFX_WideString GetFontFamily(int32_t index) const; uint16_t GetFontWeight() const; @@ -105,7 +98,12 @@ class CFDE_CSSComputedStyle : public IFX_Retainable { NonInheritedData m_NonInheritedData; private: - uint32_t m_dwRefCount; + template + friend CFX_RetainPtr pdfium::MakeRetain(Args&&... args); + + CFDE_CSSComputedStyle(); + ~CFDE_CSSComputedStyle() override; + std::vector m_CustomProperties; }; diff --git a/xfa/fde/css/cfde_cssstyleselector.cpp b/xfa/fde/css/cfde_cssstyleselector.cpp index 63d8e0986b..1b4aa0e13b 100644 --- a/xfa/fde/css/cfde_cssstyleselector.cpp +++ b/xfa/fde/css/cfde_cssstyleselector.cpp @@ -55,9 +55,9 @@ CFDE_CSSAccelerator* CFDE_CSSStyleSelector::InitAccelerator() { return m_pAccelerator.get(); } -CFDE_CSSComputedStyle* CFDE_CSSStyleSelector::CreateComputedStyle( +CFX_RetainPtr CFDE_CSSStyleSelector::CreateComputedStyle( CFDE_CSSComputedStyle* pParentStyle) { - CFDE_CSSComputedStyle* pStyle = new CFDE_CSSComputedStyle(); + auto pStyle = pdfium::MakeRetain(); if (pParentStyle) pStyle->m_InheritedData = pParentStyle->m_InheritedData; return pStyle; @@ -77,6 +77,7 @@ int32_t CFDE_CSSStyleSelector::MatchDeclarations( CXFA_CSSTagProvider* pTag, CFX_ArrayTemplate& matchedDecls) { ASSERT(pTag); + CFDE_CSSTagCache* pCache = m_pAccelerator->top(); ASSERT(pCache && pCache->GetTag() == pTag); diff --git a/xfa/fde/css/cfde_cssstyleselector.h b/xfa/fde/css/cfde_cssstyleselector.h index 2b03d7e961..c2262d7aa7 100644 --- a/xfa/fde/css/cfde_cssstyleselector.h +++ b/xfa/fde/css/cfde_cssstyleselector.h @@ -37,7 +37,7 @@ class CFDE_CSSStyleSelector { void UpdateStyleIndex(); CFDE_CSSAccelerator* InitAccelerator(); - CFDE_CSSComputedStyle* CreateComputedStyle( + CFX_RetainPtr CreateComputedStyle( CFDE_CSSComputedStyle* pParentStyle); int32_t MatchDeclarations( CXFA_CSSTagProvider* pTag, -- cgit v1.2.3