diff --git a/utils.hh b/utils.hh index a12175af..76661c6e 100644 --- a/utils.hh +++ b/utils.hh @@ -11,6 +11,7 @@ #include #include #include +#include "filetype.hh" namespace Utils { @@ -240,6 +241,15 @@ inline std::pair< bool, QString > getQueryWord( QUrl const & url ) } return std::make_pair( validScheme, word ); } + +inline bool isAudioUrl( QUrl const & url ) +{ + // Note: we check for forvo sound links explicitly, as they don't have extensions + + return ( url.scheme() == "http" || url.scheme() == "https" || url.scheme() == "gdau" ) + && ( Filetype::isNameOfSound( url.path().toUtf8().data() ) || url.host() == "apifree.forvo.com" ); +} + } } diff --git a/weburlrequestinterceptor.cpp b/weburlrequestinterceptor.cpp index 1837f939..48573288 100644 --- a/weburlrequestinterceptor.cpp +++ b/weburlrequestinterceptor.cpp @@ -42,4 +42,11 @@ void WebUrlRequestInterceptor::interceptRequest( QWebEngineUrlRequestInfo &info) // emit linkClicked( info.requestUrl() ); // info.block(true); } + + //window.location=audio link + if( Utils::Url::isAudioUrl(info.requestUrl()) && info.navigationType()==QWebEngineUrlRequestInfo::NavigationTypeRedirect ) + { + qDebug() << "blocked audio url from page redirect" << info.requestUrl().url(); + info.block( true ); + } }