goldendict-ng/weburlrequestinterceptor.cpp
Xiao YiFang e6ab87ca73 fix:add ifr local scheme
due to iframe security policy and x-frame-option .
the website online dictionary can not work in qt 5.15.2+ version.
this is a workaround to pass through the restriction.
2022-05-15 22:54:26 +08:00

30 lines
865 B
C++

#include "weburlrequestinterceptor.h"
#include <QDebug>
#include "utils.hh"
#include "globalbroadcaster.h"
WebUrlRequestInterceptor::WebUrlRequestInterceptor(QObject *p)
:QWebEngineUrlRequestInterceptor(p)
{
}
void WebUrlRequestInterceptor::interceptRequest( QWebEngineUrlRequestInfo &info) {
if( Utils::isExternalLink( info.requestUrl() ) )
{
if(!GlobalBroadcaster::instance()-> existedInWhitelist(info.requestUrl().host()))
{
info.block( true );
}
}
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() );
info.block(true);
}
}