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 ) Q_GLOBAL_STATIC( GlobalBroadcaster, bdcaster )
GlobalBroadcaster::GlobalBroadcaster( QObject * parent ) : QObject( parent ) GlobalBroadcaster::GlobalBroadcaster( QObject * parent ) : QObject( parent )
{ {
QStringList whiteUrlHosts = { "ajax.googleapis.com" };
for( auto host : whiteUrlHosts )
{
addWhitelist( host );
}
} }
GlobalBroadcaster * GlobalBroadcaster::instance() GlobalBroadcaster * GlobalBroadcaster::instance()

View file

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