diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/slxbrowser.cpp | 36 | ||||
-rw-r--r-- | src/slxbrowser.h | 1 |
2 files changed, 27 insertions, 10 deletions
diff --git a/src/slxbrowser.cpp b/src/slxbrowser.cpp index 9c7eb03..c4c2067 100644 --- a/src/slxbrowser.cpp +++ b/src/slxbrowser.cpp @@ -85,10 +85,28 @@ void SlxBrowser::loadStarted() _progress->show(); } +void SlxBrowser::maybeTriggerBack() +{ + auto elems = _browser->page()->mainFrame()->documentElement().findAll("*"); + if (elems.count() > 10) + return; + QStringList want{{ "HEAD", "TITLE", "H1", "HR", "A", "PRE" }}; + for (auto x : elems) { + if (x.tagName() != want.first()) + continue; + want.pop_front(); + if (want.isEmpty()) + break; + } + if (want.isEmpty()) { + // Was probably a JS redirect, go back before displaying the error + _browser->page()->triggerAction(QWebPage::Back); + } +} + void SlxBrowser::loadFinished(bool ok) { _progress->hide(); - qint64 now = QDateTime::currentMSecsSinceEpoch(); bool abortedDl = _browser->wasAbortedDownload(); if (!abortedDl && !ok) { if (_unsupportedUri) { @@ -97,20 +115,18 @@ void SlxBrowser::loadFinished(bool ok) "Diese Art Link wird nicht unterstützt.\n\n" "(z.B. Mail)")); } else if (_blockedSite) { - int numElems = _browser->page()->mainFrame()->documentElement().findAll("*").count(); - if (now - _lastPageLoad < 500 && numElems < 15) { - // Was probably a JS redirect, go back before displaying the error - _browser->page()->triggerAction(QWebPage::Back); - } - QTimer::singleShot(5, [=]() { + maybeTriggerBack(); + QTimer::singleShot(10, [=]() { + maybeTriggerBack(); QMessageBox::warning(this, QString::fromUtf8("Denied"), QString::fromUtf8("Target URL not allowed.\n\n" "Dieser Link führt auf eine nicht erlaubte Seite.")); }); } else { _browser->page()->mainFrame()->setHtml("<html><body style='background:blue;color:white'><br><br>" - "<center><h1>Page Load Error</h1><pre id='content'></pre></center>" - "</body></html>"); + "<center><h1>Page Load Error</h1><pre id='content'></pre><br>" + "<p><a href='#' onclick='javascript:window.history.back()'>Back</a></p>" + "</center></body></html>"); QWebElement el = _browser->page()->mainFrame()->documentElement().findFirst("#content"); QString str; if (!_sslErrors.empty()) { @@ -145,7 +161,7 @@ void SlxBrowser::loadFinished(bool ok) _unsupportedUri = false; _blockedSite = false; - _lastPageLoad = now; + _lastPageLoad = QDateTime::currentMSecsSinceEpoch();; } void SlxBrowser::loadProgress(int progress) diff --git a/src/slxbrowser.h b/src/slxbrowser.h index 1192b7c..ae1356c 100644 --- a/src/slxbrowser.h +++ b/src/slxbrowser.h @@ -37,6 +37,7 @@ private slots: void sslErrors(QNetworkReply * reply, const QList<QSslError> & errors); void requestFinished(QNetworkReply *reply); void reloadInitial(); + void maybeTriggerBack(); private: BrowserSettings _settings; |