Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(136)

Unified Diff: fpdfsdk/fsdk_baseform.cpp

Issue 2197793002: Watch for destruction of widget during callback (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | fpdfsdk/include/fsdk_baseform.h » ('j') | fpdfsdk/include/fsdk_baseform.h » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: fpdfsdk/fsdk_baseform.cpp
diff --git a/fpdfsdk/fsdk_baseform.cpp b/fpdfsdk/fsdk_baseform.cpp
index afbd95870d3f62b5ed0842ca6e7a99abda1fc4fa..f7f052a30a455a80cb77ca3f1fb285d3b716f49d 100644
--- a/fpdfsdk/fsdk_baseform.cpp
+++ b/fpdfsdk/fsdk_baseform.cpp
@@ -26,6 +26,7 @@
#include "fpdfsdk/javascript/ijs_context.h"
#include "fpdfsdk/javascript/ijs_runtime.h"
#include "fpdfsdk/pdfwindow/PWL_Utils.h"
+#include "third_party/base/stl_util.h"
#ifdef PDF_ENABLE_XFA
#include "fpdfsdk/fpdfxfa/include/fpdfxfa_doc.h"
@@ -47,6 +48,23 @@ PDFSDK_FieldAction::PDFSDK_FieldAction()
bFieldFull(FALSE),
bRC(TRUE) {}
+CPDFSDK_Widget::Observer::Observer(CPDFSDK_Widget** pWatchedPtr)
+ : m_pWatchedPtr(pWatchedPtr) {
+ (*m_pWatchedPtr)->AddObserver(this);
+}
+
+CPDFSDK_Widget::Observer::~Observer() {
+ if (m_pWatchedPtr)
+ (*m_pWatchedPtr)->RemoveObserver(this);
+}
+
+void CPDFSDK_Widget::Observer::OnWidgetDestroyed() {
+ if (m_pWatchedPtr) {
Lei Zhang 2016/07/29 22:30:06 Is this always true, or can OnWidgetDestroyed() ge
Tom Sepez 2016/08/01 16:24:54 Shouldn't happen. Will change to assert.
+ *m_pWatchedPtr = nullptr;
+ m_pWatchedPtr = nullptr;
+ }
+}
+
CPDFSDK_Widget::CPDFSDK_Widget(CPDF_Annot* pAnnot,
CPDFSDK_PageView* pPageView,
CPDFSDK_InterForm* pInterForm)
@@ -62,7 +80,20 @@ CPDFSDK_Widget::CPDFSDK_Widget(CPDF_Annot* pAnnot,
{
}
-CPDFSDK_Widget::~CPDFSDK_Widget() {}
+CPDFSDK_Widget::~CPDFSDK_Widget() {
+ for (auto* pObserver : m_Observers)
+ pObserver->OnWidgetDestroyed();
+}
+
+void CPDFSDK_Widget::AddObserver(Observer* pObserver) {
+ ASSERT(!pdfium::ContainsKey(m_Observers, pObserver));
Lei Zhang 2016/07/29 22:30:05 You can also just try inserting, and then ASSERT t
Tom Sepez 2016/08/01 16:24:54 Probably leads to unused variable warnings when as
+ m_Observers.insert(pObserver);
+}
+
+void CPDFSDK_Widget::RemoveObserver(Observer* pObserver) {
+ ASSERT(pdfium::ContainsKey(m_Observers, pObserver));
+ m_Observers.erase(pObserver);
+}
#ifdef PDF_ENABLE_XFA
CXFA_FFWidget* CPDFSDK_Widget::GetMixXFAWidget() const {
« no previous file with comments | « no previous file | fpdfsdk/include/fsdk_baseform.h » ('j') | fpdfsdk/include/fsdk_baseform.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698