diff --git a/articleview.cc b/articleview.cc index 442213f1..51291112 100644 --- a/articleview.cc +++ b/articleview.cc @@ -340,6 +340,7 @@ ArticleView::ArticleView( QWidget * parent, ArticleNetworkAccessManager & nm, QWebEngineSettings * settings = ui.definition->page()->settings(); settings->defaultSettings()->setAttribute( QWebEngineSettings::WebAttribute::LocalContentCanAccessRemoteUrls, true ); settings->defaultSettings()->setAttribute( QWebEngineSettings::WebAttribute::LocalContentCanAccessFileUrls, true ); + settings->defaultSettings()->setAttribute( QWebEngineSettings::WebAttribute::ErrorPageEnabled, false); // Load the default blank page instantly, so there would be no flicker. QString contentType; @@ -1123,7 +1124,7 @@ void ArticleView::openLink( QUrl const & url, QUrl const & ref, QString const & scrollTo, Contexts const & contexts_ ) { - qDebug() << "clicked url:" << url; + qDebug() << "open link url:" << url; Contexts contexts( contexts_ ); diff --git a/mainwindow.cc b/mainwindow.cc index cfef39e5..9fe67dfe 100644 --- a/mainwindow.cc +++ b/mainwindow.cc @@ -1298,6 +1298,7 @@ void MainWindow::applyWebSettings() defaultSettings->setAttribute(QWebEngineSettings::PlaybackRequiresUserGesture, false); defaultSettings->setAttribute( QWebEngineSettings::WebAttribute::LocalContentCanAccessRemoteUrls, true ); defaultSettings->setAttribute( QWebEngineSettings::WebAttribute::LocalContentCanAccessFileUrls, true ); + defaultSettings->setAttribute( QWebEngineSettings::WebAttribute::ErrorPageEnabled, false); } void MainWindow::setupNetworkCache( int maxSize ) diff --git a/utils.hh b/utils.hh index c8b57596..a8370104 100644 --- a/utils.hh +++ b/utils.hh @@ -26,6 +26,13 @@ inline QString rstrip(const QString& str) { return ""; } + inline bool isExternalLink( QUrl const & url ) + { + return url.scheme() == "http" || url.scheme() == "https" || + url.scheme() == "ftp" || url.scheme() == "mailto" || + url.scheme() == "file"; + } + inline QString escape( QString const & plain ) { return plain.toHtmlEscaped(); diff --git a/weburlrequestinterceptor.cpp b/weburlrequestinterceptor.cpp index 6afec740..346cfe30 100644 --- a/weburlrequestinterceptor.cpp +++ b/weburlrequestinterceptor.cpp @@ -1,13 +1,19 @@ #include "weburlrequestinterceptor.h" #include +#include "utils.hh" WebUrlRequestInterceptor::WebUrlRequestInterceptor(QObject *p) :QWebEngineUrlRequestInterceptor(p) { } -void WebUrlRequestInterceptor::interceptRequest(QWebEngineUrlRequestInfo &info) { - if(QWebEngineUrlRequestInfo::NavigationTypeLink==info.navigationType ()&&info.resourceType ()==QWebEngineUrlRequestInfo::ResourceTypeMainFrame) - emit linkClicked(info.requestUrl ()); - +void WebUrlRequestInterceptor::interceptRequest( + QWebEngineUrlRequestInfo &info) { + if (QWebEngineUrlRequestInfo::NavigationTypeLink == info.navigationType() && + info.resourceType() == QWebEngineUrlRequestInfo::ResourceTypeMainFrame) { + emit linkClicked(info.requestUrl()); + if (Utils::isExternalLink(info.requestUrl())) { + info.block(true); + } + } }