From 0bcac1882a6f86f7127fd7ee091c06a40e2c9048 Mon Sep 17 00:00:00 2001 From: Michael Schuster Date: Mon, 23 Dec 2019 05:14:21 +0100 Subject: [PATCH] Make WebFlowCredentialsDialog cancellation- and deletion-safe - Add new signal to let WebFlowCredentials know and emit asked() to also tell AccountState that the user won't authenticate, and triggering log-out state in the settings window. - Use deleteLater() to safely delete WebFlowCredentialsDialog, so that Qt can free it at the right time and without crashes. Do the same with it's _webView and _flow2AuthWidget on closeEvent(). Signed-off-by: Michael Schuster --- src/gui/creds/webflowcredentials.cpp | 11 ++++++++++- src/gui/creds/webflowcredentials.h | 1 + src/gui/creds/webflowcredentialsdialog.cpp | 11 ++++++++--- src/gui/creds/webflowcredentialsdialog.h | 1 + 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/gui/creds/webflowcredentials.cpp b/src/gui/creds/webflowcredentials.cpp index 008e119f37..c82798abf6 100644 --- a/src/gui/creds/webflowcredentials.cpp +++ b/src/gui/creds/webflowcredentials.cpp @@ -170,6 +170,7 @@ void WebFlowCredentials::askFromUser() { _askDialog->show(); connect(_askDialog, &WebFlowCredentialsDialog::urlCatched, this, &WebFlowCredentials::slotAskFromUserCredentialsProvided); + connect(_askDialog, &WebFlowCredentialsDialog::onClose, this, &WebFlowCredentials::slotAskFromUserCancelled); }); job->start(); @@ -205,10 +206,18 @@ void WebFlowCredentials::slotAskFromUserCredentialsProvided(const QString &user, emit asked(); _askDialog->close(); - delete _askDialog; + _askDialog->deleteLater(); _askDialog = nullptr; } +void WebFlowCredentials::slotAskFromUserCancelled() { + qCDebug(lcWebFlowCredentials()) << "User cancelled reauth!"; + + emit asked(); + + _askDialog->deleteLater(); + _askDialog = nullptr; +} bool WebFlowCredentials::stillValid(QNetworkReply *reply) { if (reply->error() != QNetworkReply::NoError) { diff --git a/src/gui/creds/webflowcredentials.h b/src/gui/creds/webflowcredentials.h index bb09bf57cc..50c392ae68 100644 --- a/src/gui/creds/webflowcredentials.h +++ b/src/gui/creds/webflowcredentials.h @@ -61,6 +61,7 @@ private slots: void slotFinished(QNetworkReply *reply); void slotAskFromUserCredentialsProvided(const QString &user, const QString &pass, const QString &host); + void slotAskFromUserCancelled(); void slotReadClientCertPEMJobDone(QKeychain::Job *incomingJob); void slotReadClientKeyPEMJobDone(QKeychain::Job *incomingJob); diff --git a/src/gui/creds/webflowcredentialsdialog.cpp b/src/gui/creds/webflowcredentialsdialog.cpp index bb27f86b74..d85b9eb042 100644 --- a/src/gui/creds/webflowcredentialsdialog.cpp +++ b/src/gui/creds/webflowcredentialsdialog.cpp @@ -65,11 +65,16 @@ void WebFlowCredentialsDialog::closeEvent(QCloseEvent* e) { if (_webView) { // Force calling WebView::~WebView() earlier so that _profile and _page are // deleted in the correct order. - delete _webView; + _webView->deleteLater(); + _webView = nullptr; } - if (_flow2AuthWidget) - delete _flow2AuthWidget; + if (_flow2AuthWidget) { + _flow2AuthWidget->deleteLater(); + _flow2AuthWidget = nullptr; + } + + emit onClose(); } void WebFlowCredentialsDialog::setUrl(const QUrl &url) { diff --git a/src/gui/creds/webflowcredentialsdialog.h b/src/gui/creds/webflowcredentialsdialog.h index ba252714a6..93755c160f 100644 --- a/src/gui/creds/webflowcredentialsdialog.h +++ b/src/gui/creds/webflowcredentialsdialog.h @@ -39,6 +39,7 @@ signals: void urlCatched(const QString user, const QString pass, const QString host); void styleChanged(); void onActivate(); + void onClose(); private: void customizeStyle();