opt: forbid the page to redirect to audio link url.

This commit is contained in:
Xiao YiFang 2022-07-10 12:19:09 +08:00
parent 45c2bf38bd
commit ce35085f25
2 changed files with 17 additions and 0 deletions

View file

@ -11,6 +11,7 @@
#include <QUrlQuery>
#include <QJsonObject>
#include <QJsonDocument>
#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" );
}
}
}

View file

@ -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 );
}
}