opt: website dictionary ,add whitelist of host url.

This commit is contained in:
Xiao YiFang 2022-07-16 09:13:33 +08:00
parent 34796ce8ed
commit 6ed7fda315
2 changed files with 17 additions and 5 deletions

View file

@ -5,6 +5,12 @@
Q_GLOBAL_STATIC( GlobalBroadcaster, bdcaster )
GlobalBroadcaster::GlobalBroadcaster( QObject * parent ) : QObject( parent )
{
QStringList whiteUrlHosts = { "ajax.googleapis.com" };
for( auto host : whiteUrlHosts )
{
addWhitelist( host );
}
}
GlobalBroadcaster * GlobalBroadcaster::instance()

View file

@ -46,16 +46,22 @@ void IframeSchemeHandler::requestStarted(QWebEngineUrlRequestJob *requestJob)
while( !base.isEmpty() && !base.endsWith( "/" ) )
base.chop( 1 );
QRegularExpression tags( "<base\\s+.*?>",
QRegularExpression baseTag( "<base\\s+.*?>",
QRegularExpression::CaseInsensitiveOption | QRegularExpression::DotMatchesEverythingOption );
QString baseTagHtml = "<base href=\"" + base + "\">";
// remove existed base tag
articleString.remove( tags ) ;
qsizetype pos = articleString.indexOf( "<head>" );
if( pos > -1 )
articleString.insert( pos + 6, baseTagHtml );
articleString.remove( baseTag ) ;
QRegularExpression headTag( "<head\\s+.*?>",
QRegularExpression::CaseInsensitiveOption
| QRegularExpression::DotMatchesEverythingOption );
auto match = headTag.match( articleString, 0 );
if( match.hasMatch() )
{
articleString.insert( match.capturedEnd(), baseTagHtml );
}
buffer->setData(codec->fromUnicode(articleString));