Use map of unique_ptr in cxfa_textparser.

Change-Id: I005f9da5ab64558689204f23d3444cdc68f3c59b
Reviewed-on: https://pdfium-review.googlesource.com/3064
Reviewed-by: dsinclair <dsinclair@chromium.org>
Commit-Queue: dsinclair <dsinclair@chromium.org>
diff --git a/xfa/fxfa/app/cxfa_textparser.cpp b/xfa/fxfa/app/cxfa_textparser.cpp
index 6a9aeb0..5463480 100644
--- a/xfa/fxfa/app/cxfa_textparser.cpp
+++ b/xfa/fxfa/app/cxfa_textparser.cpp
@@ -43,21 +43,13 @@
 CXFA_TextParser::CXFA_TextParser()
     : m_bParsed(false), m_cssInitialized(false) {}
 
-CXFA_TextParser::~CXFA_TextParser() {
-  for (auto& pair : m_mapXMLNodeToParseContext) {
-    if (pair.second)
-      delete pair.second;
-  }
-}
+CXFA_TextParser::~CXFA_TextParser() {}
 
 void CXFA_TextParser::Reset() {
-  for (auto& pair : m_mapXMLNodeToParseContext) {
-    if (pair.second)
-      delete pair.second;
-  }
   m_mapXMLNodeToParseContext.clear();
   m_bParsed = false;
 }
+
 void CXFA_TextParser::InitCSSData(CXFA_TextProvider* pTextProvider) {
   if (!pTextProvider)
     return;
@@ -67,12 +59,8 @@
     CFGAS_FontMgr* pFontMgr = pDoc->GetApp()->GetFDEFontMgr();
     ASSERT(pFontMgr);
     m_pSelector = pdfium::MakeUnique<CFDE_CSSStyleSelector>(pFontMgr);
-    float fFontSize = 10;
     CXFA_Font font = pTextProvider->GetFontNode();
-    if (font) {
-      fFontSize = font.GetFontSize();
-    }
-    m_pSelector->SetDefFontSize(fFontSize);
+    m_pSelector->SetDefFontSize(font ? font.GetFontSize() : 10.0f);
   }
 
   if (m_cssInitialized)
@@ -191,7 +179,7 @@
   if (it == m_mapXMLNodeToParseContext.end())
     return nullptr;
 
-  CXFA_TextParseContext* pContext = it->second;
+  CXFA_TextParseContext* pContext = it->second.get();
   if (!pContext)
     return nullptr;
 
@@ -231,7 +219,7 @@
   CFX_RetainPtr<CFDE_CSSComputedStyle> pNewStyle;
   if ((tagProvider->GetTagName() != L"body") ||
       (tagProvider->GetTagName() != L"html")) {
-    CXFA_TextParseContext* pTextContext = new CXFA_TextParseContext;
+    auto pTextContext = pdfium::MakeUnique<CXFA_TextParseContext>();
     FDE_CSSDisplay eDisplay = FDE_CSSDisplay::Inline;
     if (!tagProvider->m_bContent) {
       auto declArray =
@@ -247,7 +235,7 @@
       eDisplay = pNewStyle->GetDisplay();
     }
     pTextContext->SetDisplay(eDisplay);
-    m_mapXMLNodeToParseContext[pXMLNode] = pTextContext;
+    m_mapXMLNodeToParseContext[pXMLNode] = std::move(pTextContext);
   }
 
   for (CFDE_XMLNode* pXMLChild =
@@ -383,7 +371,7 @@
     while (pXMLNode) {
       auto it = m_mapXMLNodeToParseContext.find(pXMLNode);
       if (it != m_mapXMLNodeToParseContext.end()) {
-        CXFA_TextParseContext* pContext = it->second;
+        CXFA_TextParseContext* pContext = it->second.get();
         if (pContext && pContext->m_pParentStyle &&
             pContext->m_pParentStyle->GetCustomStyle(
                 L"xfa-font-horizontal-scale", wsValue)) {
@@ -547,7 +535,7 @@
 CXFA_TextParseContext* CXFA_TextParser::GetParseContextFromMap(
     CFDE_XMLNode* pXMLNode) {
   auto it = m_mapXMLNodeToParseContext.find(pXMLNode);
-  return it != m_mapXMLNodeToParseContext.end() ? it->second : nullptr;
+  return it != m_mapXMLNodeToParseContext.end() ? it->second.get() : nullptr;
 }
 
 bool CXFA_TextParser::GetTabstops(CFDE_CSSComputedStyle* pStyle,
diff --git a/xfa/fxfa/app/cxfa_textparser.h b/xfa/fxfa/app/cxfa_textparser.h
index 524f125..29f03a8 100644
--- a/xfa/fxfa/app/cxfa_textparser.h
+++ b/xfa/fxfa/app/cxfa_textparser.h
@@ -94,10 +94,11 @@
   CFX_RetainPtr<CFDE_CSSComputedStyle> CreateStyle(
       CFDE_CSSComputedStyle* pParentStyle);
 
-  std::unique_ptr<CFDE_CSSStyleSelector> m_pSelector;
-  std::map<CFDE_XMLNode*, CXFA_TextParseContext*> m_mapXMLNodeToParseContext;
   bool m_bParsed;
   bool m_cssInitialized;
+  std::unique_ptr<CFDE_CSSStyleSelector> m_pSelector;
+  std::map<CFDE_XMLNode*, std::unique_ptr<CXFA_TextParseContext>>
+      m_mapXMLNodeToParseContext;
 };
 
 #endif  // XFA_FXFA_APP_CXFA_TEXTPARSER_H_