aboutsummaryrefslogtreecommitdiff
path: root/src/webengine/webpage.cpp
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2018-08-23 14:50:58 +0200
committerAqua-sama <aqua@iserlohn-fortress.net>2018-08-23 14:51:19 +0200
commit1b6885608c09d8788daafb4e171ce781f885e021 (patch)
treeb69ae8cf1f4b3069f5ec3ffd55cd76089b1c2a9f /src/webengine/webpage.cpp
parentAdd mute button to WebView context menu (diff)
downloadsmolbote-1b6885608c09d8788daafb4e171ce781f885e021.tar.xz
WebPage: add render process crash recovery page
Diffstat (limited to 'src/webengine/webpage.cpp')
-rw-r--r--src/webengine/webpage.cpp36
1 files changed, 34 insertions, 2 deletions
diff --git a/src/webengine/webpage.cpp b/src/webengine/webpage.cpp
index b075fa1..ff57ac5 100644
--- a/src/webengine/webpage.cpp
+++ b/src/webengine/webpage.cpp
@@ -9,9 +9,23 @@
#include "webpage.h"
#include <QMessageBox>
#include <QWebEngineFullScreenRequest>
-
+#include <QTimer>
#include <QLayout>
+QString tr_terminationStatus(QWebEnginePage::RenderProcessTerminationStatus status)
+{
+ switch (status) {
+ case QWebEnginePage::NormalTerminationStatus:
+ return QObject::tr("The render process terminated normally.");
+ case QWebEnginePage::AbnormalTerminationStatus:
+ return QObject::tr("The render process terminated with with a non-zero exit status.");
+ case QWebEnginePage::CrashedTerminationStatus:
+ return QObject::tr("The render process crashed, for example because of a segmentation fault.");
+ case QWebEnginePage::KilledTerminationStatus:
+ return QObject::tr("The render process was killed, for example by SIGKILL or task manager kill.");
+ }
+}
+
QString feature_toString(QWebEnginePage::Feature feature)
{
switch(feature) {
@@ -32,7 +46,6 @@ QString feature_toString(QWebEnginePage::Feature feature)
case QWebEnginePage::DesktopAudioVideoCapture:
return QObject::tr("Desktop Audio and Video Capture");
}
- return QString();
}
WebPage::WebPage(QWebEngineProfile *profile, QObject *parent)
@@ -43,6 +56,7 @@ WebPage::WebPage(QWebEngineProfile *profile, QObject *parent)
});
connect(this, &QWebEnginePage::featurePermissionRequested, this, &WebPage::featurePermissionDialog);
+ connect(this, &QWebEnginePage::renderProcessTerminated, this, &WebPage::renderProcessCrashed);
}
bool WebPage::certificateError(const QWebEngineCertificateError &certificateError)
@@ -118,3 +132,21 @@ void WebPage::featurePermissionDialog(const QUrl &securityOrigin, QWebEnginePage
else
setFeaturePermission(securityOrigin, feature, QWebEnginePage::PermissionDeniedByUser);
}
+
+void WebPage::renderProcessCrashed(QWebEnginePage::RenderProcessTerminationStatus terminationStatus, int exitCode)
+{
+ if(terminationStatus != QWebEnginePage::NormalTerminationStatus) {
+#ifdef QT_DEBUG
+ qDebug("render process terminated: [%i] %i", terminationStatus, exitCode);
+#endif
+
+ QString page = "<html><body><h1>This tab has crashed!</h1>%message%</body></html>";
+ page.replace(QLatin1String("%message%"), QString("<p>%1<br>Exit code is %2.</p>"
+ "<p>Press <a href='%3'>here</a> to reload this tab.</p>").arg(tr_terminationStatus(terminationStatus), QString::number(exitCode),
+ this->url().toEncoded()));
+
+ QTimer::singleShot(0, this, [=]() {
+ setHtml(page.toUtf8(), url());
+ });
+ }
+}