Use UnownedPtr<> inside STL containers

-- better names for these members.
-- rework one routine for simplicity.
-- add some missing {}.

Change-Id: I97acceb7e615f795cea23843b3673651729a3e3d
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/78891
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/core/fpdfapi/render/cpdf_renderstatus.cpp b/core/fpdfapi/render/cpdf_renderstatus.cpp
index 273b335..54e48de 100644
--- a/core/fpdfapi/render/cpdf_renderstatus.cpp
+++ b/core/fpdfapi/render/cpdf_renderstatus.cpp
@@ -971,7 +971,7 @@
         status.SetFormResource(pFormResource);
         status.Initialize(this, pStates.get());
         status.m_Type3FontCache = m_Type3FontCache;
-        status.m_Type3FontCache.push_back(pType3Font);
+        status.m_Type3FontCache.emplace_back(pType3Font);
 
         CFX_RenderDevice::StateRestorer restorer(m_pDevice);
         status.RenderObjectList(pForm, matrix);
@@ -996,7 +996,7 @@
         status.SetFormResource(pFormResource);
         status.Initialize(this, pStates.get());
         status.m_Type3FontCache = m_Type3FontCache;
-        status.m_Type3FontCache.push_back(pType3Font);
+        status.m_Type3FontCache.emplace_back(pType3Font);
         matrix.Translate(-rect.left, -rect.top);
         status.RenderObjectList(pForm, matrix);
         m_pDevice->SetDIBits(bitmap_device.GetBitmap(), rect.left, rect.top);
diff --git a/core/fpdfapi/render/cpdf_renderstatus.h b/core/fpdfapi/render/cpdf_renderstatus.h
index c299272..4d94e7a 100644
--- a/core/fpdfapi/render/cpdf_renderstatus.h
+++ b/core/fpdfapi/render/cpdf_renderstatus.h
@@ -187,7 +187,7 @@
   CPDF_RenderOptions m_Options;
   RetainPtr<const CPDF_Dictionary> m_pFormResource;
   RetainPtr<CPDF_Dictionary> m_pPageResource;
-  std::vector<CPDF_Type3Font*> m_Type3FontCache;
+  std::vector<UnownedPtr<CPDF_Type3Font>> m_Type3FontCache;
   UnownedPtr<CPDF_RenderContext> const m_pContext;
   UnownedPtr<CFX_RenderDevice> const m_pDevice;
   CFX_Matrix m_DeviceMatrix;
diff --git a/fpdfsdk/pwl/cpwl_wnd.cpp b/fpdfsdk/pwl/cpwl_wnd.cpp
index 5fbc24d..4658813 100644
--- a/fpdfsdk/pwl/cpwl_wnd.cpp
+++ b/fpdfsdk/pwl/cpwl_wnd.cpp
@@ -39,7 +39,7 @@
   }
 
   bool IsWndCaptureMouse(const CPWL_Wnd* pWnd) const {
-    return pWnd && pdfium::Contains(m_aMousePath, pWnd);
+    return pWnd && pdfium::Contains(m_MousePaths, pWnd);
   }
 
   bool IsMainCaptureKeyboard(const CPWL_Wnd* pWnd) const {
@@ -47,18 +47,18 @@
   }
 
   bool IsWndCaptureKeyboard(const CPWL_Wnd* pWnd) const {
-    return pWnd && pdfium::Contains(m_aKeyboardPath, pWnd);
+    return pWnd && pdfium::Contains(m_KeyboardPaths, pWnd);
   }
 
   void SetFocus(CPWL_Wnd* pWnd) {
-    m_aKeyboardPath.clear();
+    m_KeyboardPaths.clear();
     if (!pWnd)
       return;
 
     m_pMainKeyboardWnd = pWnd;
     CPWL_Wnd* pParent = pWnd;
     while (pParent) {
-      m_aKeyboardPath.push_back(pParent);
+      m_KeyboardPaths.emplace_back(pParent);
       pParent = pParent->GetParentWindow();
     }
     // Note, pWnd may get destroyed in the OnSetFocus call.
@@ -67,34 +67,33 @@
 
   void KillFocus() {
     ObservedPtr<CPWL_MsgControl> observed_ptr(this);
-    if (!m_aKeyboardPath.empty())
-      if (CPWL_Wnd* pWnd = m_aKeyboardPath[0])
+    if (!m_KeyboardPaths.empty()) {
+      CPWL_Wnd* pWnd = m_KeyboardPaths.front().Get();
+      if (pWnd)
         pWnd->OnKillFocus();
+    }
     if (!observed_ptr)
       return;
 
     m_pMainKeyboardWnd = nullptr;
-    m_aKeyboardPath.clear();
+    m_KeyboardPaths.clear();
   }
 
   void SetCapture(CPWL_Wnd* pWnd) {
-    m_aMousePath.clear();
-    if (pWnd) {
-      CPWL_Wnd* pParent = pWnd;
-      while (pParent) {
-        m_aMousePath.push_back(pParent);
-        pParent = pParent->GetParentWindow();
-      }
+    m_MousePaths.clear();
+    while (pWnd) {
+      m_MousePaths.emplace_back(pWnd);
+      pWnd = pWnd->GetParentWindow();
     }
   }
 
-  void ReleaseCapture() { m_aMousePath.clear(); }
+  void ReleaseCapture() { m_MousePaths.clear(); }
 
   CPWL_Wnd* GetFocusedWindow() const { return m_pMainKeyboardWnd.Get(); }
 
  private:
-  std::vector<CPWL_Wnd*> m_aMousePath;
-  std::vector<CPWL_Wnd*> m_aKeyboardPath;
+  std::vector<UnownedPtr<CPWL_Wnd>> m_MousePaths;
+  std::vector<UnownedPtr<CPWL_Wnd>> m_KeyboardPaths;
   UnownedPtr<CPWL_Wnd> m_pCreatedWnd;
   UnownedPtr<CPWL_Wnd> m_pMainKeyboardWnd;
 };