summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--BUILD.gn2
-rw-r--r--core/fpdfapi/page/cpdf_contentmarkitem.cpp2
-rw-r--r--core/fpdfapi/page/cpdf_contentmarkitem.h3
-rw-r--r--core/fpdfapi/parser/cpdf_parser.cpp15
-rw-r--r--core/fpdfapi/parser/cpdf_parser.h3
-rw-r--r--core/fpdfapi/render/cpdf_docrenderdata.cpp2
-rw-r--r--core/fpdfapi/render/cpdf_docrenderdata.h4
-rw-r--r--core/fpdfdoc/cpdf_filespec.h5
-rw-r--r--core/fxcrt/cfx_unowned_ptr.h64
-rw-r--r--core/fxcrt/cfx_unowned_ptr_unittest.cpp86
-rw-r--r--core/fxge/fx_font.h3
-rw-r--r--core/fxge/ge/cfx_font.cpp5
-rw-r--r--fpdfsdk/cpdfsdk_interform.cpp8
-rw-r--r--fpdfsdk/cpdfsdk_interform.h7
-rw-r--r--fpdfsdk/cpdfsdk_pageview.h8
-rw-r--r--fpdfsdk/fpdfxfa/cpdfxfa_context.cpp2
-rw-r--r--fpdfsdk/fpdfxfa/cpdfxfa_context.h12
-rw-r--r--fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp2
-rw-r--r--fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.h5
-rw-r--r--fpdfsdk/javascript/JS_EventHandler.h3
-rw-r--r--fpdfsdk/pdfwindow/PWL_ComboBox.cpp4
-rw-r--r--fpdfsdk/pdfwindow/PWL_ComboBox.h3
-rw-r--r--fpdfsdk/pdfwindow/PWL_Edit.cpp2
-rw-r--r--fpdfsdk/pdfwindow/PWL_Edit.h3
-rw-r--r--fpdfsdk/pdfwindow/PWL_ListBox.cpp6
-rw-r--r--fpdfsdk/pdfwindow/PWL_ListBox.h3
-rw-r--r--xfa/fgas/font/cfgas_gefont.h3
-rw-r--r--xfa/fgas/layout/cfx_breakpiece.h3
-rw-r--r--xfa/fwl/cfwl_caret.cpp2
-rw-r--r--xfa/fwl/cfwl_caret.h2
-rw-r--r--xfa/fwl/cfwl_scrollbar.cpp3
-rw-r--r--xfa/fwl/cfwl_spinbutton.cpp4
-rw-r--r--xfa/fwl/cfwl_timer.cpp4
-rw-r--r--xfa/fwl/cfwl_timer.h7
-rw-r--r--xfa/fwl/cfwl_timerinfo.cpp6
-rw-r--r--xfa/fwl/cfwl_timerinfo.h9
-rw-r--r--xfa/fwl/cfwl_widget.h8
-rw-r--r--xfa/fxfa/cxfa_ffapp.cpp8
-rw-r--r--xfa/fxfa/cxfa_ffapp.h8
-rw-r--r--xfa/fxfa/cxfa_ffdoc.cpp11
-rw-r--r--xfa/fxfa/cxfa_ffdoc.h2
-rw-r--r--xfa/fxfa/cxfa_ffdocview.cpp46
-rw-r--r--xfa/fxfa/cxfa_ffdocview.h11
-rw-r--r--xfa/fxfa/cxfa_widgetacciterator.cpp2
-rw-r--r--xfa/fxfa/cxfa_widgetacciterator.h3
-rw-r--r--xfa/fxfa/parser/cxfa_resolveprocessor.cpp2
46 files changed, 298 insertions, 108 deletions
diff --git a/BUILD.gn b/BUILD.gn
index 25ff2c6fd3..3a26007a17 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -764,6 +764,7 @@ static_library("fxcrt") {
"core/fxcrt/cfx_string_c_template.h",
"core/fxcrt/cfx_string_data_template.h",
"core/fxcrt/cfx_string_pool_template.h",
+ "core/fxcrt/cfx_unowned_ptr.h",
"core/fxcrt/cfx_weak_ptr.h",
"core/fxcrt/cfx_widestring.cpp",
"core/fxcrt/cfx_widestring.h",
@@ -1871,6 +1872,7 @@ test("pdfium_unittests") {
"core/fxcrt/cfx_retain_ptr_unittest.cpp",
"core/fxcrt/cfx_shared_copy_on_write_unittest.cpp",
"core/fxcrt/cfx_string_pool_template_unittest.cpp",
+ "core/fxcrt/cfx_unowned_ptr_unittest.cpp",
"core/fxcrt/cfx_weak_ptr_unittest.cpp",
"core/fxcrt/cfx_widestring_unittest.cpp",
"core/fxcrt/fx_basic_gcc_unittest.cpp",
diff --git a/core/fpdfapi/page/cpdf_contentmarkitem.cpp b/core/fpdfapi/page/cpdf_contentmarkitem.cpp
index 2c370141e2..de720b39fc 100644
--- a/core/fpdfapi/page/cpdf_contentmarkitem.cpp
+++ b/core/fpdfapi/page/cpdf_contentmarkitem.cpp
@@ -26,7 +26,7 @@ CPDF_ContentMarkItem::~CPDF_ContentMarkItem() {}
CPDF_Dictionary* CPDF_ContentMarkItem::GetParam() const {
switch (m_ParamType) {
case PropertiesDict:
- return m_pPropertiesDict;
+ return m_pPropertiesDict.Get();
case DirectDict:
return m_pDirectDict.get();
case None:
diff --git a/core/fpdfapi/page/cpdf_contentmarkitem.h b/core/fpdfapi/page/cpdf_contentmarkitem.h
index ed2737111b..afd2833691 100644
--- a/core/fpdfapi/page/cpdf_contentmarkitem.h
+++ b/core/fpdfapi/page/cpdf_contentmarkitem.h
@@ -9,6 +9,7 @@
#include <memory>
+#include "core/fxcrt/cfx_unowned_ptr.h"
#include "core/fxcrt/fx_memory.h"
#include "core/fxcrt/fx_string.h"
#include "core/fxcrt/fx_system.h"
@@ -37,7 +38,7 @@ class CPDF_ContentMarkItem {
private:
CFX_ByteString m_MarkName;
ParamType m_ParamType;
- CPDF_Dictionary* m_pPropertiesDict; // not owned.
+ CFX_UnownedPtr<CPDF_Dictionary> m_pPropertiesDict;
std::unique_ptr<CPDF_Dictionary> m_pDirectDict;
};
diff --git a/core/fpdfapi/parser/cpdf_parser.cpp b/core/fpdfapi/parser/cpdf_parser.cpp
index a3e5dba40a..54b8ea0aa3 100644
--- a/core/fpdfapi/parser/cpdf_parser.cpp
+++ b/core/fpdfapi/parser/cpdf_parser.cpp
@@ -52,8 +52,7 @@ int32_t GetStreamFirst(const CFX_RetainPtr<CPDF_StreamAcc>& pObjStream) {
} // namespace
CPDF_Parser::CPDF_Parser()
- : m_pDocument(nullptr),
- m_bHasParsed(false),
+ : m_bHasParsed(false),
m_bXRefStream(false),
m_bVersionUpdated(false),
m_FileVersion(0),
@@ -719,8 +718,8 @@ bool CPDF_Parser::RebuildCrossRef() {
last_obj = start_pos;
FX_FILESIZE obj_end = 0;
std::unique_ptr<CPDF_Object> pObject =
- ParseIndirectObjectAtByStrict(m_pDocument, obj_pos, objnum,
- &obj_end);
+ ParseIndirectObjectAtByStrict(m_pDocument.Get(), obj_pos,
+ objnum, &obj_end);
if (CPDF_Stream* pStream = ToStream(pObject.get())) {
if (CPDF_Dictionary* pDict = pStream->GetDict()) {
if ((pDict->KeyExist("Type")) &&
@@ -779,7 +778,7 @@ bool CPDF_Parser::RebuildCrossRef() {
m_pSyntax->SetPos(pos + i - m_pSyntax->m_HeaderOffset);
std::unique_ptr<CPDF_Object> pObj =
- m_pSyntax->GetObject(m_pDocument, 0, 0, true);
+ m_pSyntax->GetObject(m_pDocument.Get(), 0, 0, true);
if (pObj) {
if (pObj->IsDictionary() || pObj->AsStream()) {
CPDF_Stream* pStream = pObj->AsStream();
@@ -800,7 +799,7 @@ bool CPDF_Parser::RebuildCrossRef() {
pElement ? pElement->GetObjNum() : 0;
if (dwObjNum) {
m_pTrailer->SetNewFor<CPDF_Reference>(
- key, m_pDocument, dwObjNum);
+ key, m_pDocument.Get(), dwObjNum);
} else {
m_pTrailer->SetFor(key, pElement->Clone());
}
@@ -920,7 +919,7 @@ bool CPDF_Parser::RebuildCrossRef() {
bool CPDF_Parser::LoadCrossRefV5(FX_FILESIZE* pos, bool bMainXRef) {
std::unique_ptr<CPDF_Object> pObject(
- ParseIndirectObjectAt(m_pDocument, *pos, 0));
+ ParseIndirectObjectAt(m_pDocument.Get(), *pos, 0));
if (!pObject)
return false;
@@ -1397,7 +1396,7 @@ std::unique_ptr<CPDF_Dictionary> CPDF_Parser::LoadTrailerV4() {
if (m_pSyntax->GetKeyword() != "trailer")
return nullptr;
- return ToDictionary(m_pSyntax->GetObject(m_pDocument, 0, 0, true));
+ return ToDictionary(m_pSyntax->GetObject(m_pDocument.Get(), 0, 0, true));
}
uint32_t CPDF_Parser::GetPermissions() const {
diff --git a/core/fpdfapi/parser/cpdf_parser.h b/core/fpdfapi/parser/cpdf_parser.h
index 7ae2d4627e..c444c99f28 100644
--- a/core/fpdfapi/parser/cpdf_parser.h
+++ b/core/fpdfapi/parser/cpdf_parser.h
@@ -12,6 +12,7 @@
#include <set>
#include <vector>
+#include "core/fxcrt/cfx_unowned_ptr.h"
#include "core/fxcrt/fx_basic.h"
class CPDF_Array;
@@ -150,7 +151,7 @@ class CPDF_Parser {
// the objects.
bool VerifyCrossRefV4();
- CPDF_Document* m_pDocument; // not owned
+ CFX_UnownedPtr<CPDF_Document> m_pDocument;
bool m_bHasParsed;
bool m_bXRefStream;
bool m_bVersionUpdated;
diff --git a/core/fpdfapi/render/cpdf_docrenderdata.cpp b/core/fpdfapi/render/cpdf_docrenderdata.cpp
index 2d0bca4497..d03824b59e 100644
--- a/core/fpdfapi/render/cpdf_docrenderdata.cpp
+++ b/core/fpdfapi/render/cpdf_docrenderdata.cpp
@@ -88,7 +88,7 @@ CFX_RetainPtr<CPDF_TransferFunc> CPDF_DocRenderData::GetTransferFunc(
if (!pFuncs[0])
return nullptr;
}
- auto pTransfer = pdfium::MakeRetain<CPDF_TransferFunc>(m_pPDFDoc);
+ auto pTransfer = pdfium::MakeRetain<CPDF_TransferFunc>(m_pPDFDoc.Get());
m_TransferFuncMap[pObj] = pTransfer;
float input;
diff --git a/core/fpdfapi/render/cpdf_docrenderdata.h b/core/fpdfapi/render/cpdf_docrenderdata.h
index 7952f95991..949a079126 100644
--- a/core/fpdfapi/render/cpdf_docrenderdata.h
+++ b/core/fpdfapi/render/cpdf_docrenderdata.h
@@ -11,6 +11,8 @@
#include "core/fpdfapi/page/cpdf_countedobject.h"
#include "core/fpdfapi/render/cpdf_transferfunc.h"
+#include "core/fxcrt/cfx_unowned_ptr.h"
+#include "core/fxcrt/fx_system.h"
class CPDF_Document;
class CPDF_Font;
@@ -32,7 +34,7 @@ class CPDF_DocRenderData {
void Clear(bool bRelease);
private:
- CPDF_Document* m_pPDFDoc; // Not Owned
+ CFX_UnownedPtr<CPDF_Document> m_pPDFDoc;
std::map<CPDF_Font*, CFX_RetainPtr<CPDF_Type3Cache>> m_Type3FaceMap;
std::map<CPDF_Object*, CFX_RetainPtr<CPDF_TransferFunc>> m_TransferFuncMap;
};
diff --git a/core/fpdfdoc/cpdf_filespec.h b/core/fpdfdoc/cpdf_filespec.h
index ea002f0e22..fb71b57186 100644
--- a/core/fpdfdoc/cpdf_filespec.h
+++ b/core/fpdfdoc/cpdf_filespec.h
@@ -8,6 +8,7 @@
#define CORE_FPDFDOC_CPDF_FILESPEC_H_
#include "core/fxcrt/cfx_string_pool_template.h"
+#include "core/fxcrt/cfx_unowned_ptr.h"
#include "core/fxcrt/cfx_weak_ptr.h"
#include "core/fxcrt/fx_string.h"
@@ -24,14 +25,14 @@ class CPDF_FileSpec {
// Convert a pdf file name into platform dependent format.
static CFX_WideString DecodeFileName(const CFX_WideStringC& filepath);
- CPDF_Object* GetObj() const { return m_pObj; }
+ CPDF_Object* GetObj() const { return m_pObj.Get(); }
bool GetFileName(CFX_WideString* wsFileName) const;
// Set this file spec to refer to a file name (not a url).
void SetFileName(const CFX_WideStringC& wsFileName);
private:
- CPDF_Object* const m_pObj; // not owned.
+ CFX_UnownedPtr<CPDF_Object> const m_pObj;
};
#endif // CORE_FPDFDOC_CPDF_FILESPEC_H_
diff --git a/core/fxcrt/cfx_unowned_ptr.h b/core/fxcrt/cfx_unowned_ptr.h
new file mode 100644
index 0000000000..11f4e8e38b
--- /dev/null
+++ b/core/fxcrt/cfx_unowned_ptr.h
@@ -0,0 +1,64 @@
+// Copyright 2017 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CORE_FXCRT_CFX_UNOWNED_PTR_H_
+#define CORE_FXCRT_CFX_UNOWNED_PTR_H_
+
+#include <functional>
+#include <memory>
+#include <type_traits>
+#include <utility>
+
+#include "core/fxcrt/fx_memory.h"
+
+template <class T>
+class CFX_UnownedPtr {
+ public:
+ CFX_UnownedPtr() {}
+ CFX_UnownedPtr(const CFX_UnownedPtr& that) : CFX_UnownedPtr(that.Get()) {}
+
+ template <typename U>
+ explicit CFX_UnownedPtr(U* pObj) : m_pObj(pObj) {}
+
+ // Deliberately implicit to allow returning nullptrs.
+ // NOLINTNEXTLINE(runtime/explicit)
+ CFX_UnownedPtr(std::nullptr_t ptr) {}
+
+#if defined(MEMORY_TOOL_REPLACES_ALLOCATOR)
+ ~CFX_UnownedPtr() {
+ if (m_pObj)
+ reinterpret_cast<volatile uint8_t*>(m_pObj)[0];
+ }
+#endif
+
+ CFX_UnownedPtr& operator=(T* that) {
+ m_pObj = that;
+ return *this;
+ }
+ CFX_UnownedPtr& operator=(const CFX_UnownedPtr& that) {
+ if (*this != that)
+ m_pObj = that.Get();
+ return *this;
+ }
+
+ bool operator==(const CFX_UnownedPtr& that) const {
+ return Get() == that.Get();
+ }
+ bool operator==(const T* that) const { return Get() == that; }
+ bool operator!=(const CFX_UnownedPtr& that) const { return !(*this == that); }
+ bool operator!=(const T* that) const { return !(*this == that); }
+ bool operator<(const CFX_UnownedPtr& that) const {
+ return std::less<T*>()(Get(), that.Get());
+ }
+
+ T* Get() const { return m_pObj; }
+ explicit operator bool() const { return !!m_pObj; }
+ T& operator*() const { return *m_pObj; }
+ T* operator->() const { return m_pObj; }
+
+ private:
+ T* m_pObj = nullptr;
+};
+
+#endif // CORE_FXCRT_CFX_UNOWNED_PTR_H_
diff --git a/core/fxcrt/cfx_unowned_ptr_unittest.cpp b/core/fxcrt/cfx_unowned_ptr_unittest.cpp
new file mode 100644
index 0000000000..7d29faedf5
--- /dev/null
+++ b/core/fxcrt/cfx_unowned_ptr_unittest.cpp
@@ -0,0 +1,86 @@
+// Copyright 2017 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "core/fxcrt/cfx_unowned_ptr.h"
+
+#include <utility>
+#include <vector>
+
+#include "testing/fx_string_testhelpers.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace {
+
+class Clink {
+ public:
+ CFX_UnownedPtr<Clink> next_ = nullptr;
+};
+
+void DeleteDangling() {
+ Clink* ptr1 = new Clink();
+ Clink* ptr2 = new Clink();
+ ptr2->next_ = ptr1;
+ delete ptr1;
+ delete ptr2;
+}
+
+} // namespace
+
+TEST(fxcrt, UnownedPtrOk) {
+ Clink* ptr1 = new Clink();
+ Clink* ptr2 = new Clink();
+ ptr2->next_ = ptr1;
+ delete ptr2;
+ delete ptr1;
+}
+
+TEST(fxcrt, UnownedPtrNotOk) {
+#if defined(MEMORY_TOOL_REPLACES_ALLOCATOR)
+ EXPECT_DEATH(DeleteDangling(), "");
+#else
+ DeleteDangling();
+#endif
+}
+
+TEST(fxcrt, OperatorEQ) {
+ int foo;
+ CFX_UnownedPtr<int> ptr1;
+ EXPECT_TRUE(ptr1 == ptr1);
+
+ CFX_UnownedPtr<int> ptr2;
+ EXPECT_TRUE(ptr1 == ptr2);
+
+ CFX_UnownedPtr<int> ptr3(&foo);
+ EXPECT_TRUE(ptr3 == &foo);
+ EXPECT_FALSE(ptr1 == ptr3);
+
+ ptr1 = &foo;
+ EXPECT_TRUE(ptr1 == ptr3);
+}
+
+TEST(fxcrt, OperatorNE) {
+ int foo;
+ CFX_UnownedPtr<int> ptr1;
+ EXPECT_FALSE(ptr1 != ptr1);
+
+ CFX_UnownedPtr<int> ptr2;
+ EXPECT_FALSE(ptr1 != ptr2);
+
+ CFX_UnownedPtr<int> ptr3(&foo);
+ EXPECT_FALSE(ptr3 != &foo);
+ EXPECT_TRUE(ptr1 != ptr3);
+
+ ptr1 = &foo;
+ EXPECT_FALSE(ptr1 != ptr3);
+}
+
+TEST(fxcrt, OperatorLT) {
+ int foos[2];
+ CFX_UnownedPtr<int> ptr1(&foos[0]);
+ CFX_UnownedPtr<int> ptr2(&foos[1]);
+
+ EXPECT_FALSE(ptr1 < ptr1);
+ EXPECT_TRUE(ptr1 < ptr2);
+ EXPECT_FALSE(ptr2 < ptr1);
+}
diff --git a/core/fxge/fx_font.h b/core/fxge/fx_font.h
index ce91e27c42..946c713418 100644
--- a/core/fxge/fx_font.h
+++ b/core/fxge/fx_font.h
@@ -11,6 +11,7 @@
#include <utility>
#include <vector>
+#include "core/fxcrt/cfx_unowned_ptr.h"
#include "core/fxcrt/fx_system.h"
#include "core/fxge/cfx_substfont.h"
#include "core/fxge/dib/cfx_dibitmap.h"
@@ -172,7 +173,7 @@ class CFX_Font {
void ClearFaceCache();
FXFT_Face m_Face;
- mutable CFX_FaceCache* m_FaceCache; // not owned.
+ mutable CFX_UnownedPtr<CFX_FaceCache> m_FaceCache;
std::unique_ptr<CFX_SubstFont> m_pSubstFont;
std::vector<uint8_t> m_pFontDataAllocation;
uint8_t* m_pFontData;
diff --git a/core/fxge/ge/cfx_font.cpp b/core/fxge/ge/cfx_font.cpp
index 2ae34f11b9..18baed9d09 100644
--- a/core/fxge/ge/cfx_font.cpp
+++ b/core/fxge/ge/cfx_font.cpp
@@ -537,10 +537,9 @@ int CFX_Font::GetMaxAdvanceWidth() const {
}
CFX_FaceCache* CFX_Font::GetFaceCache() const {
- if (!m_FaceCache) {
+ if (!m_FaceCache)
m_FaceCache = CFX_GEModule::Get()->GetFontCache()->GetCachedFace(this);
- }
- return m_FaceCache;
+ return m_FaceCache.Get();
}
void CFX_Font::ClearFaceCache() {
diff --git a/fpdfsdk/cpdfsdk_interform.cpp b/fpdfsdk/cpdfsdk_interform.cpp
index b44002cef8..2d02a7ab93 100644
--- a/fpdfsdk/cpdfsdk_interform.cpp
+++ b/fpdfsdk/cpdfsdk_interform.cpp
@@ -351,8 +351,8 @@ bool CPDFSDK_InterForm::OnKeyStrokeCommit(CPDF_FormField* pFormField,
fa.bModifier = m_pFormFillEnv->IsCTRLKeyDown(0);
fa.bShift = m_pFormFillEnv->IsSHIFTKeyDown(0);
fa.sValue = csValue;
- pActionHandler->DoAction_FieldJavaScript(action, CPDF_AAction::KeyStroke,
- m_pFormFillEnv, pFormField, fa);
+ pActionHandler->DoAction_FieldJavaScript(
+ action, CPDF_AAction::KeyStroke, m_pFormFillEnv.Get(), pFormField, fa);
return fa.bRC;
}
@@ -371,8 +371,8 @@ bool CPDFSDK_InterForm::OnValidate(CPDF_FormField* pFormField,
fa.bModifier = m_pFormFillEnv->IsCTRLKeyDown(0);
fa.bShift = m_pFormFillEnv->IsSHIFTKeyDown(0);
fa.sValue = csValue;
- pActionHandler->DoAction_FieldJavaScript(action, CPDF_AAction::Validate,
- m_pFormFillEnv, pFormField, fa);
+ pActionHandler->DoAction_FieldJavaScript(
+ action, CPDF_AAction::Validate, m_pFormFillEnv.Get(), pFormField, fa);
return fa.bRC;
}
diff --git a/fpdfsdk/cpdfsdk_interform.h b/fpdfsdk/cpdfsdk_interform.h
index 032399c84e..b613c731ba 100644
--- a/fpdfsdk/cpdfsdk_interform.h
+++ b/fpdfsdk/cpdfsdk_interform.h
@@ -13,6 +13,7 @@
#include "core/fpdfdoc/cpdf_action.h"
#include "core/fpdfdoc/ipdf_formnotify.h"
+#include "core/fxcrt/cfx_unowned_ptr.h"
#include "core/fxcrt/fx_basic.h"
#include "core/fxge/fx_dib.h"
#include "fpdfsdk/cpdfsdk_widget.h"
@@ -35,7 +36,9 @@ class CPDFSDK_InterForm : public IPDF_FormNotify {
~CPDFSDK_InterForm() override;
CPDF_InterForm* GetInterForm() const { return m_pInterForm.get(); }
- CPDFSDK_FormFillEnvironment* GetFormFillEnv() const { return m_pFormFillEnv; }
+ CPDFSDK_FormFillEnvironment* GetFormFillEnv() const {
+ return m_pFormFillEnv.Get();
+ }
bool HighlightWidgets();
@@ -121,7 +124,7 @@ class CPDFSDK_InterForm : public IPDF_FormNotify {
using CPDFSDK_WidgetMap = std::map<CPDF_FormControl*, CPDFSDK_Widget*>;
- CPDFSDK_FormFillEnvironment* m_pFormFillEnv; // Not owned.
+ CFX_UnownedPtr<CPDFSDK_FormFillEnvironment> m_pFormFillEnv;
std::unique_ptr<CPDF_InterForm> m_pInterForm;
CPDFSDK_WidgetMap m_Map;
#ifdef PDF_ENABLE_XFA
diff --git a/fpdfsdk/cpdfsdk_pageview.h b/fpdfsdk/cpdfsdk_pageview.h
index bcd5177c1a..8bede08a5d 100644
--- a/fpdfsdk/cpdfsdk_pageview.h
+++ b/fpdfsdk/cpdfsdk_pageview.h
@@ -11,6 +11,7 @@
#include <vector>
#include "core/fpdfapi/page/cpdf_page.h"
+#include "core/fxcrt/cfx_unowned_ptr.h"
#include "core/fxcrt/fx_system.h"
#include "fpdfsdk/cpdfsdk_annot.h"
@@ -55,7 +56,10 @@ class CPDFSDK_PageView final : public CPDF_Page::View {
CPDF_Page* GetPDFPage() const;
CPDF_Document* GetPDFDocument();
- CPDFSDK_FormFillEnvironment* GetFormFillEnv() const { return m_pFormFillEnv; }
+ CPDFSDK_FormFillEnvironment* GetFormFillEnv() const {
+ return m_pFormFillEnv.Get();
+ }
+
bool OnLButtonDown(const CFX_PointF& point, uint32_t nFlag);
bool OnLButtonUp(const CFX_PointF& point, uint32_t nFlag);
#ifdef PDF_ENABLE_XFA
@@ -102,7 +106,7 @@ class CPDFSDK_PageView final : public CPDF_Page::View {
UnderlyingPageType* const m_page;
std::unique_ptr<CPDF_AnnotList> m_pAnnotList;
std::vector<CPDFSDK_Annot*> m_SDKAnnotArray;
- CPDFSDK_FormFillEnvironment* const m_pFormFillEnv; // Not owned.
+ CFX_UnownedPtr<CPDFSDK_FormFillEnvironment> const m_pFormFillEnv;
CPDFSDK_Annot::ObservedPtr m_pCaptureWidget;
#ifndef PDF_ENABLE_XFA
bool m_bOwnsPage;
diff --git a/fpdfsdk/fpdfxfa/cpdfxfa_context.cpp b/fpdfsdk/fpdfxfa/cpdfxfa_context.cpp
index 454e2187a3..93ecab0d08 100644
--- a/fpdfsdk/fpdfxfa/cpdfxfa_context.cpp
+++ b/fpdfsdk/fpdfxfa/cpdfxfa_context.cpp
@@ -358,6 +358,6 @@ bool CPDFXFA_Context::PutRequestURL(const CFX_WideString& wsURL,
IFWL_AdapterTimerMgr* CPDFXFA_Context::GetTimerMgr() {
CXFA_FWLAdapterTimerMgr* pAdapter = nullptr;
if (m_pFormFillEnv)
- pAdapter = new CXFA_FWLAdapterTimerMgr(m_pFormFillEnv);
+ pAdapter = new CXFA_FWLAdapterTimerMgr(m_pFormFillEnv.Get());
return pAdapter;
}
diff --git a/fpdfsdk/fpdfxfa/cpdfxfa_context.h b/fpdfsdk/fpdfxfa/cpdfxfa_context.h
index 8e6b2198af..690e1855e3 100644
--- a/fpdfsdk/fpdfxfa/cpdfxfa_context.h
+++ b/fpdfsdk/fpdfxfa/cpdfxfa_context.h
@@ -10,6 +10,8 @@
#include <memory>
#include <vector>
+#include "core/fxcrt/cfx_unowned_ptr.h"
+#include "core/fxcrt/fx_system.h"
#include "fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.h"
#include "xfa/fxfa/cxfa_ffdoc.h"
@@ -36,12 +38,14 @@ class CPDFXFA_Context : public IXFA_AppProvider {
bool LoadXFADoc();
CPDF_Document* GetPDFDoc() { return m_pPDFDoc.get(); }
CXFA_FFDoc* GetXFADoc() { return m_pXFADoc.get(); }
- CXFA_FFDocView* GetXFADocView() { return m_pXFADocView; }
+ CXFA_FFDocView* GetXFADocView() { return m_pXFADocView.Get(); }
XFA_DocType GetDocType() const { return m_iDocType; }
v8::Isolate* GetJSERuntime() const;
CXFA_FFApp* GetXFAApp() { return m_pXFAApp.get(); }
- CPDFSDK_FormFillEnvironment* GetFormFillEnv() const { return m_pFormFillEnv; }
+ CPDFSDK_FormFillEnvironment* GetFormFillEnv() const {
+ return m_pFormFillEnv.Get();
+ }
void SetFormFillEnv(CPDFSDK_FormFillEnvironment* pFormFillEnv);
void DeletePage(int page_index);
@@ -102,8 +106,8 @@ class CPDFXFA_Context : public IXFA_AppProvider {
std::unique_ptr<CPDF_Document> m_pPDFDoc;
std::unique_ptr<CXFA_FFDoc> m_pXFADoc;
- CPDFSDK_FormFillEnvironment* m_pFormFillEnv; // not owned.
- CXFA_FFDocView* m_pXFADocView; // not owned.
+ CFX_UnownedPtr<CPDFSDK_FormFillEnvironment> m_pFormFillEnv;
+ CFX_UnownedPtr<CXFA_FFDocView> m_pXFADocView;
std::unique_ptr<CXFA_FFApp> m_pXFAApp;
std::unique_ptr<CJS_Runtime> m_pRuntime;
std::vector<CPDFXFA_Page*> m_XFAPageList;
diff --git a/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp b/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp
index 4464f1c43a..1a27d9b015 100644
--- a/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp
+++ b/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.cpp
@@ -46,7 +46,7 @@ CPDFXFA_DocEnvironment::CPDFXFA_DocEnvironment(CPDFXFA_Context* pContext)
CPDFXFA_DocEnvironment::~CPDFXFA_DocEnvironment() {
if (m_pJSEventContext && m_pContext->GetFormFillEnv()) {
m_pContext->GetFormFillEnv()->GetJSRuntime()->ReleaseEventContext(
- m_pJSEventContext);
+ m_pJSEventContext.Get());
}
}
diff --git a/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.h b/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.h
index 8f1d238103..ec04e78db9 100644
--- a/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.h
+++ b/fpdfsdk/fpdfxfa/cpdfxfa_docenvironment.h
@@ -8,6 +8,7 @@
#define FPDFSDK_FPDFXFA_CPDFXFA_DOCENVIRONMENT_H_
#include "core/fxcrt/cfx_retain_ptr.h"
+#include "core/fxcrt/cfx_unowned_ptr.h"
#include "public/fpdfview.h"
#include "xfa/fxfa/fxfa.h"
@@ -105,8 +106,8 @@ class CPDFXFA_DocEnvironment : public IXFA_DocEnvironment {
FPDF_DWORD flag);
void ToXFAContentFlags(CFX_WideString csSrcContent, FPDF_DWORD& flag);
- CPDFXFA_Context* const m_pContext; // Not owned.
- IJS_EventContext* m_pJSEventContext; // Not owned.
+ CFX_UnownedPtr<CPDFXFA_Context> const m_pContext;
+ CFX_UnownedPtr<IJS_EventContext> m_pJSEventContext;
};
#endif // FPDFSDK_FPDFXFA_CPDFXFA_DOCENVIRONMENT_H_
diff --git a/fpdfsdk/javascript/JS_EventHandler.h b/fpdfsdk/javascript/JS_EventHandler.h
index 1e70a358bc..5dcb70b4c8 100644
--- a/fpdfsdk/javascript/JS_EventHandler.h
+++ b/fpdfsdk/javascript/JS_EventHandler.h
@@ -7,6 +7,7 @@
#ifndef FPDFSDK_JAVASCRIPT_JS_EVENTHANDLER_H_
#define FPDFSDK_JAVASCRIPT_JS_EVENTHANDLER_H_
+#include "core/fxcrt/cfx_unowned_ptr.h"
#include "core/fxcrt/fx_string.h"
#include "core/fxcrt/fx_system.h"
#include "fpdfsdk/cpdfsdk_formfillenvironment.h"
@@ -165,7 +166,7 @@ class CJS_EventHandler {
JS_EVENT_T EventType() { return m_eEventType; }
public:
- CJS_EventContext* const m_pJSEventContext; // Not Owned.
+ CFX_UnownedPtr<CJS_EventContext> const m_pJSEventContext;
JS_EVENT_T m_eEventType;
bool m_bValid;
diff --git a/fpdfsdk/pdfwindow/PWL_ComboBox.cpp b/fpdfsdk/pdfwindow/PWL_ComboBox.cpp
index 9321e0f606..9f5ab97858 100644
--- a/fpdfsdk/pdfwindow/PWL_ComboBox.cpp
+++ b/fpdfsdk/pdfwindow/PWL_ComboBox.cpp
@@ -265,7 +265,7 @@ void CPWL_ComboBox::CreateEdit(const PWL_CREATEPARAM& cp) {
return;
m_pEdit = pdfium::MakeUnique<CPWL_CBEdit>();
- m_pEdit->AttachFFLData(m_pFormFiller);
+ m_pEdit->AttachFFLData(m_pFormFiller.Get());
PWL_CREATEPARAM ecp = cp;
ecp.pParentWnd = this;
@@ -306,7 +306,7 @@ void CPWL_ComboBox::CreateListBox(const PWL_CREATEPARAM& cp) {
return;
m_pList = pdfium::MakeUnique<CPWL_CBListBox>();
- m_pList->AttachFFLData(m_pFormFiller);
+ m_pList->AttachFFLData(m_pFormFiller.Get());
PWL_CREATEPARAM lcp = cp;
lcp.pParentWnd = this;
diff --git a/fpdfsdk/pdfwindow/PWL_ComboBox.h b/fpdfsdk/pdfwindow/PWL_ComboBox.h
index a687eb8e94..19d9ab2a04 100644
--- a/fpdfsdk/pdfwindow/PWL_ComboBox.h
+++ b/fpdfsdk/pdfwindow/PWL_ComboBox.h
@@ -9,6 +9,7 @@
#include <memory>
+#include "core/fxcrt/cfx_unowned_ptr.h"
#include "fpdfsdk/pdfwindow/PWL_Edit.h"
#include "fpdfsdk/pdfwindow/PWL_ListBox.h"
#include "fpdfsdk/pdfwindow/PWL_Wnd.h"
@@ -100,7 +101,7 @@ class CPWL_ComboBox : public CPWL_Wnd {
int32_t m_nPopupWhere;
int32_t m_nSelectItem;
IPWL_Filler_Notify* m_pFillerNotify;
- CFFL_FormFiller* m_pFormFiller; // Not owned.
+ CFX_UnownedPtr<CFFL_FormFiller> m_pFormFiller;
};
#endif // FPDFSDK_PDFWINDOW_PWL_COMBOBOX_H_
diff --git a/fpdfsdk/pdfwindow/PWL_Edit.cpp b/fpdfsdk/pdfwindow/PWL_Edit.cpp
index 90572746da..4e37e9bde4 100644
--- a/fpdfsdk/pdfwindow/PWL_Edit.cpp
+++ b/fpdfsdk/pdfwindow/PWL_Edit.cpp
@@ -398,7 +398,7 @@ void CPWL_Edit::DrawThisAppearance(CFX_RenderDevice* pDevice,
CFX_SystemHandler* pSysHandler = GetSystemHandler();
CFX_Edit::DrawEdit(pDevice, pUser2Device, m_pEdit.get(),
GetTextColor().ToFXColor(GetTransparency()), rcClip,
- CFX_PointF(), pRange, pSysHandler, m_pFormFiller);
+ CFX_PointF(), pRange, pSysHandler, m_pFormFiller.Get());
}
bool CPWL_Edit::OnLButtonDown(const CFX_PointF& point, uint32_t nFlag) {
diff --git a/fpdfsdk/pdfwindow/PWL_Edit.h b/fpdfsdk/pdfwindow/PWL_Edit.h
index 5e1a36610d..bd3799141a 100644
--- a/fpdfsdk/pdfwindow/PWL_Edit.h
+++ b/fpdfsdk/pdfwindow/PWL_Edit.h
@@ -9,6 +9,7 @@
#include <vector>
+#include "core/fxcrt/cfx_unowned_ptr.h"
#include "core/fxcrt/fx_basic.h"
#include "fpdfsdk/fxedit/fx_edit.h"
#include "fpdfsdk/pdfwindow/PWL_EditCtrl.h"
@@ -136,7 +137,7 @@ class CPWL_Edit : public CPWL_EditCtrl {
IPWL_Filler_Notify* m_pFillerNotify;
bool m_bFocus;
CFX_FloatRect m_rcOldWindow;
- CFFL_FormFiller* m_pFormFiller; // Not owned.
+ CFX_UnownedPtr<CFFL_FormFiller> m_pFormFiller;
};
#endif // FPDFSDK_PDFWINDOW_PWL_EDIT_H_
diff --git a/fpdfsdk/pdfwindow/PWL_ListBox.cpp b/fpdfsdk/pdfwindow/PWL_ListBox.cpp
index 8448204a74..b682959426 100644
--- a/fpdfsdk/pdfwindow/PWL_ListBox.cpp
+++ b/fpdfsdk/pdfwindow/PWL_ListBox.cpp
@@ -172,14 +172,14 @@ void CPWL_ListBox::DrawThisAppearance(CFX_RenderDevice* pDevice,
if (pSysHandler && pSysHandler->IsSelectionImplemented()) {
CFX_Edit::DrawEdit(pDevice, pUser2Device, m_pList->GetItemEdit(i),
GetTextColor().ToFXColor(255), rcList, ptOffset,
- nullptr, pSysHandler, m_pFormFiller);
- pSysHandler->OutputSelectedRect(m_pFormFiller, rcItem);
+ nullptr, pSysHandler, m_pFormFiller.Get());
+ pSysHandler->OutputSelectedRect(m_pFormFiller.Get(), rcItem);
} else {
CPWL_Utils::DrawFillRect(pDevice, pUser2Device, rcItem,
ArgbEncode(255, 0, 51, 113));
CFX_Edit::DrawEdit(pDevice, pUser2Device, m_pList->GetItemEdit(i),
ArgbEncode(255, 255, 255, 255), rcList, ptOffset,
- nullptr, pSysHandler, m_pFormFiller);
+ nullptr, pSysHandler, m_pFormFiller.Get());
}
} else {
CFX_SystemHandler* pSysHandler = GetSystemHandler();
diff --git a/fpdfsdk/pdfwindow/PWL_ListBox.h b/fpdfsdk/pdfwindow/PWL_ListBox.h
index 9f8f464efb..0de9c91195 100644
--- a/fpdfsdk/pdfwindow/PWL_ListBox.h
+++ b/fpdfsdk/pdfwindow/PWL_ListBox.h
@@ -9,6 +9,7 @@
#include <memory>
+#include "core/fxcrt/cfx_unowned_ptr.h"
#include "fpdfsdk/fxedit/fx_edit.h"
#include "fpdfsdk/pdfwindow/PWL_Wnd.h"
@@ -111,7 +112,7 @@ class CPWL_ListBox : public CPWL_Wnd {
IPWL_Filler_Notify* m_pFillerNotify;
private:
- CFFL_FormFiller* m_pFormFiller; // Not owned.
+ CFX_UnownedPtr<CFFL_FormFiller> m_pFormFiller;
};
#endif // FPDFSDK_PDFWINDOW_PWL_LISTBOX_H_
diff --git a/xfa/fgas/font/cfgas_gefont.h b/xfa/fgas/font/cfgas_gefont.h
index ba2e6e69a5..5fe73bbb40 100644
--- a/xfa/fgas/font/cfgas_gefont.h
+++ b/xfa/fgas/font/cfgas_gefont.h
@@ -12,6 +12,7 @@
#include <vector>
#include "core/fxcrt/cfx_retain_ptr.h"
+#include "core/fxcrt/cfx_unowned_ptr.h"
#include "core/fxcrt/fx_memory.h"
#include "xfa/fgas/font/cfgas_fontmgr.h"
@@ -101,7 +102,7 @@ class CFGAS_GEFont : public CFX_Retainable {
std::unique_ptr<CFX_UnicodeEncoding> m_pFontEncoding;
std::map<wchar_t, int32_t> m_CharWidthMap;
std::map<wchar_t, CFX_Rect> m_BBoxMap;
- CXFA_PDFFontMgr* m_pProvider; // not owned.
+ CFX_UnownedPtr<CXFA_PDFFontMgr> m_pProvider;
std::vector<CFX_RetainPtr<CFGAS_GEFont>> m_SubstFonts;
std::map<wchar_t, CFX_RetainPtr<CFGAS_GEFont>> m_FontMapper;
};
diff --git a/xfa/fgas/layout/cfx_breakpiece.h b/xfa/fgas/layout/cfx_breakpiece.h
index 1c51b1e42a..807b5f769f 100644
--- a/xfa/fgas/layout/cfx_breakpiece.h
+++ b/xfa/fgas/layout/cfx_breakpiece.h
@@ -11,6 +11,7 @@
#include "core/fxcrt/cfx_char.h"
#include "core/fxcrt/cfx_retain_ptr.h"
+#include "core/fxcrt/cfx_unowned_ptr.h"
#include "core/fxcrt/fx_string.h"
#include "xfa/fxfa/app/cxfa_textuserdata.h"
@@ -39,7 +40,7 @@ class CFX_BreakPiece {
int32_t m_iVerticalScale;
uint32_t m_dwIdentity;
uint32_t m_dwCharStyles;
- std::vector<CFX_Char>* m_pChars; // not owned.
+ CFX_UnownedPtr<std::vector<CFX_Char>> m_pChars;
CFX_RetainPtr<CXFA_TextUserData> m_pUserData;
};
diff --git a/xfa/fwl/cfwl_caret.cpp b/xfa/fwl/cfwl_caret.cpp
index a6ea9ddb56..21387a47f9 100644
--- a/xfa/fwl/cfwl_caret.cpp
+++ b/xfa/fwl/cfwl_caret.cpp
@@ -97,7 +97,7 @@ void CFWL_Caret::OnDrawWidget(CFX_Graphics* pGraphics,
CFWL_Caret::Timer::Timer(CFWL_Caret* pCaret) : CFWL_Timer(pCaret) {}
void CFWL_Caret::Timer::Run(CFWL_TimerInfo* pTimerInfo) {
- CFWL_Caret* pCaret = static_cast<CFWL_Caret*>(m_pWidget);
+ CFWL_Caret* pCaret = static_cast<CFWL_Caret*>(m_pWidget.Get());
if (!(pCaret->GetStates() & FWL_STATE_CAT_HightLight))
pCaret->SetStates(FWL_STATE_CAT_HightLight);
else
diff --git a/xfa/fwl/cfwl_caret.h b/xfa/fwl/cfwl_caret.h
index e0c07d301a..da0548c2bf 100644
--- a/xfa/fwl/cfwl_caret.h
+++ b/xfa/fwl/cfwl_caret.h
@@ -51,7 +51,7 @@ class CFWL_Caret : public CFWL_Widget {
const CFX_Matrix* pMatrix);
std::unique_ptr<CFWL_Caret::Timer> m_pTimer;
- CFWL_TimerInfo* m_pTimerInfo; // not owned.
+ CFX_UnownedPtr<CFWL_TimerInfo> m_pTimerInfo;
};
#endif // XFA_FWL_CFWL_CARET_H_
diff --git a/xfa/fwl/cfwl_scrollbar.cpp b/xfa/fwl/cfwl_scrollbar.cpp
index 72797ed315..79e8b48115 100644
--- a/xfa/fwl/cfwl_scrollbar.cpp
+++ b/xfa/fwl/cfwl_scrollbar.cpp
@@ -485,8 +485,7 @@ void CFWL_ScrollBar::DoMouseHover(int32_t iItem,
CFWL_ScrollBar::Timer::Timer(CFWL_ScrollBar* pToolTip) : CFWL_Timer(pToolTip) {}
void CFWL_ScrollBar::Timer::Run(CFWL_TimerInfo* pTimerInfo) {
- CFWL_ScrollBar* pButton = static_cast<CFWL_ScrollBar*>(m_pWidget);
-
+ CFWL_ScrollBar* pButton = static_cast<CFWL_ScrollBar*>(m_pWidget.Get());
if (pButton->m_pTimerInfo)
pButton->m_pTimerInfo->StopTimer();
diff --git a/xfa/fwl/cfwl_spinbutton.cpp b/xfa/fwl/cfwl_spinbutton.cpp
index 6e58b69baf..65bd6cdd3a 100644
--- a/xfa/fwl/cfwl_spinbutton.cpp
+++ b/xfa/fwl/cfwl_spinbutton.cpp
@@ -336,7 +336,6 @@ void CFWL_SpinButton::OnKeyDown(CFWL_MessageKey* pMsg) {
CFWL_Event wmPosChanged(CFWL_Event::Type::Click, this);
DispatchEvent(&wmPosChanged);
-
RepaintRect(bUpEnable ? m_rtUpButton : m_rtDnButton);
}
@@ -344,8 +343,7 @@ CFWL_SpinButton::Timer::Timer(CFWL_SpinButton* pToolTip)
: CFWL_Timer(pToolTip) {}
void CFWL_SpinButton::Timer::Run(CFWL_TimerInfo* pTimerInfo) {
- CFWL_SpinButton* pButton = static_cast<CFWL_SpinButton*>(m_pWidget);
-
+ CFWL_SpinButton* pButton = static_cast<CFWL_SpinButton*>(m_pWidget.Get());
if (!pButton->m_pTimerInfo)
return;
diff --git a/xfa/fwl/cfwl_timer.cpp b/xfa/fwl/cfwl_timer.cpp
index 0cd3b2b768..2734e49d78 100644
--- a/xfa/fwl/cfwl_timer.cpp
+++ b/xfa/fwl/cfwl_timer.cpp
@@ -12,6 +12,10 @@
#include "xfa/fwl/ifwl_adaptertimermgr.h"
#include "xfa/fxfa/cxfa_ffapp.h"
+CFWL_Timer::CFWL_Timer(CFWL_Widget* parent) : m_pWidget(parent) {}
+
+CFWL_Timer::~CFWL_Timer() {}
+
CFWL_TimerInfo* CFWL_Timer::StartTimer(uint32_t dwElapse, bool bImmediately) {
const CFWL_App* pApp = m_pWidget->GetOwnerApp();
if (!pApp)
diff --git a/xfa/fwl/cfwl_timer.h b/xfa/fwl/cfwl_timer.h
index 6c9079acfe..93de009ed1 100644
--- a/xfa/fwl/cfwl_timer.h
+++ b/xfa/fwl/cfwl_timer.h
@@ -7,6 +7,7 @@
#ifndef XFA_FWL_CFWL_TIMER_H_
#define XFA_FWL_CFWL_TIMER_H_
+#include "core/fxcrt/cfx_unowned_ptr.h"
#include "core/fxcrt/fx_system.h"
class CFWL_TimerInfo;
@@ -14,14 +15,14 @@ class CFWL_Widget;
class CFWL_Timer {
public:
- explicit CFWL_Timer(CFWL_Widget* parent) : m_pWidget(parent) {}
- virtual ~CFWL_Timer() {}
+ explicit CFWL_Timer(CFWL_Widget* parent);
+ virtual ~CFWL_Timer();
virtual void Run(CFWL_TimerInfo* hTimer) = 0;
CFWL_TimerInfo* StartTimer(uint32_t dwElapse, bool bImmediately);
protected:
- CFWL_Widget* m_pWidget; // Not owned.
+ CFX_UnownedPtr<CFWL_Widget> m_pWidget;
};
#endif // XFA_FWL_CFWL_TIMER_H_
diff --git a/xfa/fwl/cfwl_timerinfo.cpp b/xfa/fwl/cfwl_timerinfo.cpp
index 8c7aaebbbb..ee4746af3f 100644
--- a/xfa/fwl/cfwl_timerinfo.cpp
+++ b/xfa/fwl/cfwl_timerinfo.cpp
@@ -8,6 +8,12 @@
#include "xfa/fwl/ifwl_adaptertimermgr.h"
+CFWL_TimerInfo::CFWL_TimerInfo(IFWL_AdapterTimerMgr* mgr) : m_pMgr(mgr) {
+ ASSERT(mgr);
+}
+
+CFWL_TimerInfo::~CFWL_TimerInfo() {}
+
void CFWL_TimerInfo::StopTimer() {
m_pMgr->Stop(this);
}
diff --git a/xfa/fwl/cfwl_timerinfo.h b/xfa/fwl/cfwl_timerinfo.h
index a47fede60f..ae77ef5d59 100644
--- a/xfa/fwl/cfwl_timerinfo.h
+++ b/xfa/fwl/cfwl_timerinfo.h
@@ -7,21 +7,20 @@
#ifndef XFA_FWL_CFWL_TIMERINFO_H_
#define XFA_FWL_CFWL_TIMERINFO_H_
+#include "core/fxcrt/cfx_unowned_ptr.h"
#include "core/fxcrt/fx_system.h"
class IFWL_AdapterTimerMgr;
class CFWL_TimerInfo {
public:
- explicit CFWL_TimerInfo(IFWL_AdapterTimerMgr* mgr) : m_pMgr(mgr) {
- ASSERT(mgr);
- }
- virtual ~CFWL_TimerInfo() {}
+ explicit CFWL_TimerInfo(IFWL_AdapterTimerMgr* mgr);
+ virtual ~CFWL_TimerInfo();
void StopTimer();
private:
- IFWL_AdapterTimerMgr* m_pMgr; // Not owned.
+ CFX_UnownedPtr<IFWL_AdapterTimerMgr> m_pMgr;
};
#endif // XFA_FWL_CFWL_TIMERINFO_H_
diff --git a/xfa/fwl/cfwl_widget.h b/xfa/fwl/cfwl_widget.h
index b556e7a424..dd8fb5654b 100644
--- a/xfa/fwl/cfwl_widget.h
+++ b/xfa/fwl/cfwl_widget.h
@@ -6,8 +6,10 @@
#ifndef XFA_FWL_CFWL_WIDGET_H_
#define XFA_FWL_CFWL_WIDGET_H_
+
#include <memory>
+#include "core/fxcrt/cfx_unowned_ptr.h"
#include "core/fxcrt/fx_coordinates.h"
#include "core/fxcrt/fx_system.h"
#include "xfa/fwl/cfwl_event.h"
@@ -96,10 +98,10 @@ class CFWL_Widget : public IFWL_WidgetDelegate {
void SetDelegate(IFWL_WidgetDelegate* delegate) { m_pDelegate = delegate; }
IFWL_WidgetDelegate* GetDelegate() {
- return m_pDelegate ? m_pDelegate : this;
+ return m_pDelegate ? m_pDelegate.Get() : this;
}
const IFWL_WidgetDelegate* GetDelegate() const {
- return m_pDelegate ? m_pDelegate : this;
+ return m_pDelegate ? m_pDelegate.Get() : this;
}
const CFWL_App* GetOwnerApp() const { return m_pOwnerApp; }
@@ -182,7 +184,7 @@ class CFWL_Widget : public IFWL_WidgetDelegate {
CXFA_FFWidget* m_pLayoutItem;
uint32_t m_nEventKey;
- IFWL_WidgetDelegate* m_pDelegate; // Not owned.
+ CFX_UnownedPtr<IFWL_WidgetDelegate> m_pDelegate;
};
#endif // XFA_FWL_CFWL_WIDGET_H_
diff --git a/xfa/fxfa/cxfa_ffapp.cpp b/xfa/fxfa/cxfa_ffapp.cpp
index 742cd14c30..7b97116c7a 100644
--- a/xfa/fxfa/cxfa_ffapp.cpp
+++ b/xfa/fxfa/cxfa_ffapp.cpp
@@ -23,10 +23,10 @@
#include "xfa/fxfa/cxfa_ffwidgethandler.h"
#include "xfa/fxfa/cxfa_fontmgr.h"
-CXFA_FFApp::CXFA_FFApp(IXFA_AppProvider* pProvider)
- : m_pProvider(pProvider),
- m_pWidgetMgrDelegate(nullptr),
- m_pFWLApp(pdfium::MakeUnique<CFWL_App>(this)) {}
+CXFA_FFApp::CXFA_FFApp(IXFA_AppProvider* pProvider) : m_pProvider(pProvider) {
+ // Ensure fully initialized before making an app based on |this|.
+ m_pFWLApp = pdfium::MakeUnique<CFWL_App>(this);
+}
CXFA_FFApp::~CXFA_FFApp() {}
diff --git a/xfa/fxfa/cxfa_ffapp.h b/xfa/fxfa/cxfa_ffapp.h
index 0a6409d3d1..1ae2073d82 100644
--- a/xfa/fxfa/cxfa_ffapp.h
+++ b/xfa/fxfa/cxfa_ffapp.h
@@ -13,6 +13,7 @@
#include "core/fpdfapi/parser/cpdf_stream.h"
#include "core/fpdfapi/parser/cpdf_stream_acc.h"
#include "core/fxcrt/cfx_retain_ptr.h"
+#include "core/fxcrt/cfx_unowned_ptr.h"
#include "xfa/fgas/font/cfgas_fontmgr.h"
#include "xfa/fwl/cfwl_app.h"
#include "xfa/fxfa/fxfa.h"
@@ -44,7 +45,7 @@ class CXFA_FFApp {
IFWL_AdapterTimerMgr* GetTimerMgr() const;
CXFA_FontMgr* GetXFAFontMgr() const;
CFWL_WidgetMgrDelegate* GetWidgetMgrDelegate() const {
- return m_pWidgetMgrDelegate;
+ return m_pWidgetMgrDelegate.Get();
}
void ClearEventTargets();
@@ -70,12 +71,15 @@ class CXFA_FFApp {
std::unique_ptr<CFX_FontSourceEnum_File> m_pFontSource;
#endif
std::unique_ptr<CXFA_FWLAdapterWidgetMgr> m_pAdapterWidgetMgr;
- CFWL_WidgetMgrDelegate* m_pWidgetMgrDelegate; // not owned.
// |m_pFWLApp| has to be released first, then |m_pFWLTheme| since the former
// may refers to theme manager and the latter refers to font manager.
std::unique_ptr<CXFA_FWLTheme> m_pFWLTheme;
std::unique_ptr<CFWL_App> m_pFWLApp;
+
+ // |m_pWidgetMgrDelegate| has to be released before |m_pFWLApp|, since
+ // |m_pFWLApp| is its owner.
+ CFX_UnownedPtr<CFWL_WidgetMgrDelegate> m_pWidgetMgrDelegate;
};
#endif // XFA_FXFA_CXFA_FFAPP_H_
diff --git a/xfa/fxfa/cxfa_ffdoc.cpp b/xfa/fxfa/cxfa_ffdoc.cpp
index bddc02a9ce..f7bad38934 100644
--- a/xfa/fxfa/cxfa_ffdoc.cpp
+++ b/xfa/fxfa/cxfa_ffdoc.cpp
@@ -321,21 +321,20 @@ bool CXFA_FFDoc::OpenDoc(CPDF_Document* pPDFDoc) {
return true;
}
-bool CXFA_FFDoc::CloseDoc() {
- if (m_DocView)
+void CXFA_FFDoc::CloseDoc() {
+ if (m_DocView) {
m_DocView->RunDocClose();
-
+ m_DocView.reset();
+ }
CXFA_Document* doc =
m_pDocumentParser ? m_pDocumentParser->GetDocument() : nullptr;
if (doc)
doc->ClearLayoutData();
- m_DocView.reset();
- m_pNotify.reset(nullptr);
+ m_pNotify.reset();
m_pApp->GetXFAFontMgr()->ReleaseDocFonts(this);
m_HashToDibDpiMap.clear();
m_pApp->ClearEventTargets();
- return true;
}
CPDF_Document* CXFA_FFDoc::GetPDFDoc() {
diff --git a/xfa/fxfa/cxfa_ffdoc.h b/xfa/fxfa/cxfa_ffdoc.h
index 1cfbb50a2c..d40e7ba0c8 100644
--- a/xfa/fxfa/cxfa_ffdoc.h
+++ b/xfa/fxfa/cxfa_ffdoc.h
@@ -60,7 +60,7 @@ class CXFA_FFDoc {
bool OpenDoc(const CFX_RetainPtr<IFX_SeekableStream>& pStream);
bool OpenDoc(CPDF_Document* pPDFDoc);
- bool CloseDoc();
+ void CloseDoc();
CXFA_Document* GetXFADoc() { return m_pDocumentParser->GetDocument(); }
CXFA_FFApp* GetApp() { return m_pApp; }
diff --git a/xfa/fxfa/cxfa_ffdocview.cpp b/xfa/fxfa/cxfa_ffdocview.cpp
index 058116be72..c1a8a67336 100644
--- a/xfa/fxfa/cxfa_ffdocview.cpp
+++ b/xfa/fxfa/cxfa_ffdocview.cpp
@@ -61,9 +61,6 @@ CXFA_FFDocView::CXFA_FFDocView(CXFA_FFDoc* pDoc)
m_bInLayoutStatus(false),
m_pDoc(pDoc),
m_pXFADocLayout(nullptr),
- m_pFocusAcc(nullptr),
- m_pFocusWidget(nullptr),
- m_pOldFocusWidget(nullptr),
m_iStatus(XFA_DOCVIEW_LAYOUTSTATUS_None),
m_iLock(0) {}
@@ -143,14 +140,16 @@ void CXFA_FFDocView::StopLayout() {
nullptr);
}
m_CalculateAccs.clear();
- if (m_pFocusAcc && !m_pFocusWidget) {
- SetFocusWidgetAcc(m_pFocusAcc);
- }
+ if (m_pFocusAcc && !m_pFocusWidget)
+ SetFocusWidgetAcc(m_pFocusAcc.Get());
+
m_iStatus = XFA_DOCVIEW_LAYOUTSTATUS_End;
}
+
int32_t CXFA_FFDocView::GetLayoutStatus() {
return m_iStatus;
}
+
void CXFA_FFDocView::ShowNullTestMsg() {
int32_t iCount = pdfium::CollectionSize<int32_t>(m_arrNullTestMsg);
CXFA_FFApp* pApp = m_pDoc->GetApp();
@@ -316,8 +315,8 @@ CXFA_FFDocView::CreateWidgetAccIterator() {
return pdfium::MakeUnique<CXFA_WidgetAccIterator>(pFormRoot);
}
-CXFA_FFWidget* CXFA_FFDocView::GetFocusWidget() {
- return m_pFocusWidget;
+CXFA_FFWidget* CXFA_FFDocView::GetFocusWidget() const {
+ return m_pFocusWidget.Get();
}
void CXFA_FFDocView::KillFocus() {
@@ -329,12 +328,13 @@ void CXFA_FFDocView::KillFocus() {
m_pFocusWidget = nullptr;
m_pOldFocusWidget = nullptr;
}
+
bool CXFA_FFDocView::SetFocus(CXFA_FFWidget* hWidget) {
CXFA_FFWidget* pNewFocus = hWidget;
- if (m_pOldFocusWidget == pNewFocus) {
+ if (m_pOldFocusWidget == pNewFocus)
return false;
- }
- CXFA_FFWidget* pOldFocus = m_pOldFocusWidget;
+
+ CXFA_FFWidget* pOldFocus = m_pOldFocusWidget.Get();
m_pOldFocusWidget = pNewFocus;
if (pOldFocus) {
if (m_pFocusWidget != m_pOldFocusWidget &&
@@ -345,15 +345,15 @@ bool CXFA_FFDocView::SetFocus(CXFA_FFWidget* hWidget) {
if (!pOldFocus->IsLoaded()) {
pOldFocus->LoadWidget();
}
- pOldFocus->OnSetFocus(m_pFocusWidget);
+ pOldFocus->OnSetFocus(m_pFocusWidget.Get());
m_pFocusWidget = pOldFocus;
pOldFocus->OnKillFocus(pNewFocus);
}
}
- if (m_pFocusWidget == m_pOldFocusWidget) {
+ if (m_pFocusWidget == m_pOldFocusWidget)
return false;
- }
- pNewFocus = m_pOldFocusWidget;
+
+ pNewFocus = m_pOldFocusWidget.Get();
if (m_pListFocusWidget && pNewFocus == m_pListFocusWidget) {
m_pFocusAcc = nullptr;
m_pFocusWidget = nullptr;
@@ -362,29 +362,30 @@ bool CXFA_FFDocView::SetFocus(CXFA_FFWidget* hWidget) {
return false;
}
if (pNewFocus && (pNewFocus->GetStatus() & XFA_WidgetStatus_Visible)) {
- if (!pNewFocus->IsLoaded()) {
+ if (!pNewFocus->IsLoaded())
pNewFocus->LoadWidget();
- }
- pNewFocus->OnSetFocus(m_pFocusWidget);
+ pNewFocus->OnSetFocus(m_pFocusWidget.Get());
}
m_pFocusAcc = pNewFocus ? pNewFocus->GetDataAcc() : nullptr;
m_pFocusWidget = pNewFocus;
m_pOldFocusWidget = m_pFocusWidget;
return true;
}
+
CXFA_WidgetAcc* CXFA_FFDocView::GetFocusWidgetAcc() {
- return m_pFocusAcc;
+ return m_pFocusAcc.Get();
}
+
void CXFA_FFDocView::SetFocusWidgetAcc(CXFA_WidgetAcc* pWidgetAcc) {
CXFA_FFWidget* pNewFocus =
pWidgetAcc ? pWidgetAcc->GetNextWidget(nullptr) : nullptr;
if (SetFocus(pNewFocus)) {
m_pFocusAcc = pWidgetAcc;
- if (m_iStatus == XFA_DOCVIEW_LAYOUTSTATUS_End) {
- m_pDoc->GetDocEnvironment()->SetFocusWidget(m_pDoc, m_pFocusWidget);
- }
+ if (m_iStatus == XFA_DOCVIEW_LAYOUTSTATUS_End)
+ m_pDoc->GetDocEnvironment()->SetFocusWidget(m_pDoc, m_pFocusWidget.Get());
}
}
+
void CXFA_FFDocView::DeleteLayoutItem(CXFA_FFWidget* pWidget) {
if (m_pFocusAcc == pWidget->GetDataAcc()) {
m_pFocusAcc = nullptr;
@@ -392,6 +393,7 @@ void CXFA_FFDocView::DeleteLayoutItem(CXFA_FFWidget* pWidget) {
m_pOldFocusWidget = nullptr;
}
}
+
static int32_t XFA_ProcessEvent(CXFA_FFDocView* pDocView,
CXFA_WidgetAcc* pWidgetAcc,
CXFA_EventParam* pParam) {
diff --git a/xfa/fxfa/cxfa_ffdocview.h b/xfa/fxfa/cxfa_ffdocview.h
index 761397c4b0..83d077b548 100644
--- a/xfa/fxfa/cxfa_ffdocview.h
+++ b/xfa/fxfa/cxfa_ffdocview.h
@@ -11,6 +11,7 @@
#include <memory>
#include <vector>
+#include "core/fxcrt/cfx_unowned_ptr.h"
#include "xfa/fxfa/cxfa_eventparam.h"
#include "xfa/fxfa/cxfa_ffdoc.h"
@@ -56,7 +57,7 @@ class CXFA_FFDocView {
CXFA_WidgetAcc* pWidgetAcc);
CXFA_FFWidgetHandler* GetWidgetHandler();
std::unique_ptr<CXFA_WidgetAccIterator> CreateWidgetAccIterator();
- CXFA_FFWidget* GetFocusWidget();
+ CXFA_FFWidget* GetFocusWidget() const;
void KillFocus();
bool SetFocus(CXFA_FFWidget* hWidget);
CXFA_FFWidget* GetWidgetByName(const CFX_WideString& wsName,
@@ -117,10 +118,10 @@ class CXFA_FFDocView {
CXFA_FFDoc* const m_pDoc;
std::unique_ptr<CXFA_FFWidgetHandler> m_pWidgetHandler;
- CXFA_LayoutProcessor* m_pXFADocLayout; // not owned.
- CXFA_WidgetAcc* m_pFocusAcc; // not owned.
- CXFA_FFWidget* m_pFocusWidget; // not owned.
- CXFA_FFWidget* m_pOldFocusWidget; // not owned.
+ CXFA_LayoutProcessor* m_pXFADocLayout; // Not owned.
+ CFX_UnownedPtr<CXFA_WidgetAcc> m_pFocusAcc;
+ CFX_UnownedPtr<CXFA_FFWidget> m_pFocusWidget;
+ CFX_UnownedPtr<CXFA_FFWidget> m_pOldFocusWidget;
std::map<CXFA_FFPageView*, std::unique_ptr<CFX_RectF>> m_mapPageInvalidate;
std::vector<CXFA_WidgetAcc*> m_ValidateAccs;
std::vector<CXFA_WidgetAcc*> m_CalculateAccs;
diff --git a/xfa/fxfa/cxfa_widgetacciterator.cpp b/xfa/fxfa/cxfa_widgetacciterator.cpp
index 373fba99dc..ed780853df 100644
--- a/xfa/fxfa/cxfa_widgetacciterator.cpp
+++ b/xfa/fxfa/cxfa_widgetacciterator.cpp
@@ -19,7 +19,7 @@ CXFA_WidgetAcc* CXFA_WidgetAccIterator::MoveToNext() {
while (pItem) {
m_pCurWidgetAcc = static_cast<CXFA_WidgetAcc*>(pItem->GetWidgetData());
if (m_pCurWidgetAcc)
- return m_pCurWidgetAcc;
+ return m_pCurWidgetAcc.Get();
pItem = m_ContentIterator.MoveToNext();
}
return nullptr;
diff --git a/xfa/fxfa/cxfa_widgetacciterator.h b/xfa/fxfa/cxfa_widgetacciterator.h
index ab18e833c2..0ad94260f3 100644
--- a/xfa/fxfa/cxfa_widgetacciterator.h
+++ b/xfa/fxfa/cxfa_widgetacciterator.h
@@ -7,6 +7,7 @@
#ifndef XFA_FXFA_CXFA_WIDGETACCITERATOR_H_
#define XFA_FXFA_CXFA_WIDGETACCITERATOR_H_
+#include "core/fxcrt/cfx_unowned_ptr.h"
#include "xfa/fxfa/parser/cxfa_traversestrategy_xfacontainernode.h"
class CXFA_Node;
@@ -22,7 +23,7 @@ class CXFA_WidgetAccIterator {
private:
CXFA_ContainerIterator m_ContentIterator;
- CXFA_WidgetAcc* m_pCurWidgetAcc; // not owned.
+ CFX_UnownedPtr<CXFA_WidgetAcc> m_pCurWidgetAcc;
};
#endif // XFA_FXFA_CXFA_WIDGETACCITERATOR_H_
diff --git a/xfa/fxfa/parser/cxfa_resolveprocessor.cpp b/xfa/fxfa/parser/cxfa_resolveprocessor.cpp
index d17a1bab50..add8cb8fcb 100644
--- a/xfa/fxfa/parser/cxfa_resolveprocessor.cpp
+++ b/xfa/fxfa/parser/cxfa_resolveprocessor.cpp
@@ -103,7 +103,7 @@ int32_t CXFA_ResolveProcessor::ResolveAnyChild(CXFA_ResolveNodesData& rnd) {
return pdfium::CollectionSize<int32_t>(rnd.m_Objects);
}
std::vector<CXFA_Node*> tempNodes;
- for (CXFA_Object* pObject : rnd.m_Objects)
+ for (auto* pObject : rnd.m_Objects)
tempNodes.push_back(pObject->AsNode());
m_pNodeHelper->CountSiblings(findNode, XFA_LOGIC_Transparent, &tempNodes,
bClassName);