diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/webengine/webpage.cpp | 36 | ||||
-rw-r--r-- | src/webengine/webpage.h | 1 |
2 files changed, 35 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()); + }); + } +} diff --git a/src/webengine/webpage.h b/src/webengine/webpage.h index 3e5ce34..2158815 100644 --- a/src/webengine/webpage.h +++ b/src/webengine/webpage.h @@ -25,6 +25,7 @@ protected: private slots: void featurePermissionDialog(const QUrl &securityOrigin, QWebEnginePage::Feature feature); + void renderProcessCrashed(QWebEnginePage::RenderProcessTerminationStatus terminationStatus, int exitCode); }; #endif // SMOLBOTE_WEBPAGE_H |