goldendict-ng/weburlrequestinterceptor.cpp

30 lines
865 B
C++
Raw Normal View History

2021-12-11 16:34:37 +00:00
#include "weburlrequestinterceptor.h"
#include <QDebug>
#include "utils.hh"
#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) {
if( Utils::isExternalLink( info.requestUrl() ) )
{
if(!GlobalBroadcaster::instance()-> existedInWhitelist(info.requestUrl().host()))
{
info.block( true );
}
}
2021-12-31 14:11:55 +00:00
if (QWebEngineUrlRequestInfo::NavigationTypeLink == info.navigationType() && info.resourceType() == QWebEngineUrlRequestInfo::ResourceTypeMainFrame) {
//workaround to fix devtool "Switch devtool to chinese" interface was blocked.
if( info.requestUrl().scheme() == "devtools" )
{
return;
}
emit linkClicked( info.requestUrl() );
2021-12-31 14:11:55 +00:00
info.block(true);
}
2021-12-11 16:34:37 +00:00
}