2021-12-11 16:34:37 +00:00
|
|
|
#include "weburlrequestinterceptor.h"
|
|
|
|
#include <QDebug>
|
2021-12-29 15:28:26 +00:00
|
|
|
#include "utils.hh"
|
2022-05-13 16:00:23 +00:00
|
|
|
#include "globalbroadcaster.h"
|
2021-12-11 16:34:37 +00:00
|
|
|
|
|
|
|
WebUrlRequestInterceptor::WebUrlRequestInterceptor(QObject *p)
|
|
|
|
:QWebEngineUrlRequestInterceptor(p)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
2021-12-31 14:11:55 +00:00
|
|
|
void WebUrlRequestInterceptor::interceptRequest( QWebEngineUrlRequestInfo &info) {
|
2022-05-17 12:44:48 +00:00
|
|
|
if( GlobalBroadcaster::instance()->getPreference()->disallowContentFromOtherSites && Utils::isExternalLink( info.requestUrl() ) )
|
2022-05-13 16:00:23 +00:00
|
|
|
{
|
2022-05-17 12:44:48 +00:00
|
|
|
//file:// link ,pass
|
|
|
|
if(info.requestUrl().scheme()=="file"){
|
|
|
|
return;
|
|
|
|
}
|
2022-10-15 05:58:24 +00:00
|
|
|
auto hostBase = Utils::Url::getHostBase( info.requestUrl().host() );
|
2022-05-16 23:55:32 +00:00
|
|
|
if( GlobalBroadcaster::instance()->existedInWhitelist( hostBase ) )
|
2022-05-13 16:00:23 +00:00
|
|
|
{
|
2022-05-16 14:10:12 +00:00
|
|
|
//whitelist url does not block
|
|
|
|
return;
|
|
|
|
}
|
2022-09-04 11:50:12 +00:00
|
|
|
if( info.resourceType() == QWebEngineUrlRequestInfo::ResourceTypeImage
|
|
|
|
|| info.resourceType() == QWebEngineUrlRequestInfo::ResourceTypeFontResource
|
|
|
|
|| info.resourceType() == QWebEngineUrlRequestInfo::ResourceTypeStylesheet
|
|
|
|
|| info.resourceType() == QWebEngineUrlRequestInfo::ResourceTypeMedia
|
|
|
|
|| Utils::isHtmlResources( info.requestUrl() ) )
|
|
|
|
{
|
2022-05-16 14:10:12 +00:00
|
|
|
//let throuth the resources file.
|
|
|
|
return;
|
2022-05-13 16:00:23 +00:00
|
|
|
}
|
2022-05-16 23:55:32 +00:00
|
|
|
|
2022-05-17 12:44:48 +00:00
|
|
|
// block external links
|
2022-05-16 23:55:32 +00:00
|
|
|
{
|
|
|
|
info.block( true );
|
2022-05-17 12:44:48 +00:00
|
|
|
return;
|
2022-05-16 23:55:32 +00:00
|
|
|
}
|
2022-05-13 16:00:23 +00:00
|
|
|
}
|
|
|
|
|
2021-12-31 14:11:55 +00:00
|
|
|
if (QWebEngineUrlRequestInfo::NavigationTypeLink == info.navigationType() && info.resourceType() == QWebEngineUrlRequestInfo::ResourceTypeMainFrame) {
|
2022-04-20 12:25:27 +00:00
|
|
|
//workaround to fix devtool "Switch devtool to chinese" interface was blocked.
|
|
|
|
if( info.requestUrl().scheme() == "devtools" )
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2022-07-10 04:55:27 +00:00
|
|
|
emit linkClicked( info.requestUrl() );
|
|
|
|
info.block(true);
|
2021-12-29 15:28:26 +00:00
|
|
|
}
|
2022-07-10 04:19:09 +00:00
|
|
|
|
|
|
|
//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 );
|
|
|
|
}
|
2021-12-11 16:34:37 +00:00
|
|
|
}
|