Make WebFlowCredentialsDialog cancellation- and deletion-safe
authorMichael Schuster <michael@schuster.ms>
Mon, 23 Dec 2019 04:14:21 +0000 (05:14 +0100)
committerMichael Schuster <48932272+misch7@users.noreply.github.com>
Tue, 24 Dec 2019 06:46:57 +0000 (07:46 +0100)
- 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 <michael@schuster.ms>
src/gui/creds/webflowcredentials.cpp
src/gui/creds/webflowcredentials.h
src/gui/creds/webflowcredentialsdialog.cpp
src/gui/creds/webflowcredentialsdialog.h

index 008e119f376dec473fa6f1bcbaf90ecc1501c6e4..c82798abf673583a5fd96c9d93f6a3ef832584ec 100644 (file)
@@ -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) {
index bb09bf57ccc2a9efe708b609efcfc0a4fa580a51..50c392ae681434f5c8b9f8000897313d39626c15 100644 (file)
@@ -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);
index bb27f86b741d6f1d22a412fb988fba972c50ad52..d85b9eb042a2dceac38a6dc91376bd65e7891e6b 100644 (file)
@@ -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) {
index ba252714a6eef8c6189f8e977291dbd14f73aaf8..93755c160f969a7ffa7924b66b0dc306e2a11601 100644 (file)
@@ -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();