mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-23 20:14:05 +00:00
opt: function refract
This commit is contained in:
parent
2619e7be97
commit
4eedefc585
|
@ -200,7 +200,7 @@ QNetworkReply * ArticleNetworkAccessManager::getArticleReply( QNetworkRequest co
|
|||
QUrl refererUrl = QUrl::fromEncoded( referer );
|
||||
|
||||
if ( !url.host().endsWith( refererUrl.host() ) &&
|
||||
getHostBaseFromUrl( url ) != getHostBaseFromUrl( refererUrl ) && !url.scheme().startsWith("data") )
|
||||
Utils::Url::getHostBaseFromUrl( url ) != Utils::Url::getHostBaseFromUrl( refererUrl ) && !url.scheme().startsWith("data") )
|
||||
{
|
||||
gdWarning( "Blocking element \"%s\" due to not same domain", url.toEncoded().data() );
|
||||
|
||||
|
|
|
@ -28,13 +28,13 @@ Config::Preferences * GlobalBroadcaster::getPreference()
|
|||
|
||||
void GlobalBroadcaster::addWhitelist( QString url )
|
||||
{
|
||||
whitelist.push_back( url );
|
||||
auto baseUrl = ::getHostBase( url );
|
||||
whitelist.push_back( baseUrl );
|
||||
whitelist.insert( url );
|
||||
auto baseUrl = Utils::Url::getHostBase( url );
|
||||
whitelist.insert( baseUrl );
|
||||
}
|
||||
|
||||
bool GlobalBroadcaster::existedInWhitelist( QString url )
|
||||
{
|
||||
return std::find( whitelist.begin(), whitelist.end(), url ) != whitelist.end();
|
||||
return whitelist.contains(url);
|
||||
}
|
||||
// namespace global
|
||||
|
|
|
@ -16,7 +16,7 @@ class GlobalBroadcaster : public QObject
|
|||
Q_OBJECT
|
||||
private:
|
||||
Config::Preferences * preference;
|
||||
std::vector<QString> whitelist;
|
||||
QSet<QString> whitelist;
|
||||
|
||||
public:
|
||||
void setPreference( Config::Preferences * _pre );
|
||||
|
|
8
utils.cc
8
utils.cc
|
@ -5,3 +5,11 @@ QString Utils::Path::combine(const QString& path1, const QString& path2)
|
|||
{
|
||||
return QDir::cleanPath(path1 + QDir::separator() + path2);
|
||||
}
|
||||
|
||||
QString Utils::Url::getSchemeAndHost( QUrl const & url )
|
||||
{
|
||||
auto _url = url.url();
|
||||
auto index = _url.indexOf("://");
|
||||
auto hostEndIndex = _url.indexOf("/",index+3);
|
||||
return _url.mid(0,hostEndIndex);
|
||||
}
|
||||
|
|
17
utils.hh
17
utils.hh
|
@ -272,16 +272,6 @@ inline bool isAudioUrl( QUrl const & url )
|
|||
&& ( Filetype::isNameOfSound( url.path().toUtf8().data() ) || url.host() == "apifree.forvo.com" );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
namespace Path{
|
||||
QString combine(const QString& path1, const QString& path2);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
/// Uses some heuristics to chop off the first domain name from the host name,
|
||||
/// but only if it's not too base. Returns the resulting host name.
|
||||
inline QString getHostBase( QString const & host )
|
||||
|
@ -315,8 +305,15 @@ inline QString getHostBaseFromUrl( QUrl const & url )
|
|||
|
||||
return getHostBase( host );
|
||||
}
|
||||
|
||||
QString getSchemeAndHost( QUrl const & url );
|
||||
|
||||
}
|
||||
|
||||
namespace Path{
|
||||
QString combine(const QString& path1, const QString& path2);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif // UTILS_HH
|
||||
|
|
|
@ -15,7 +15,7 @@ void WebUrlRequestInterceptor::interceptRequest( QWebEngineUrlRequestInfo &info)
|
|||
if(info.requestUrl().scheme()=="file"){
|
||||
return;
|
||||
}
|
||||
auto hostBase = getHostBase( info.requestUrl().host() );
|
||||
auto hostBase = Utils::Url::getHostBase( info.requestUrl().host() );
|
||||
if( GlobalBroadcaster::instance()->existedInWhitelist( hostBase ) )
|
||||
{
|
||||
//whitelist url does not block
|
||||
|
|
Loading…
Reference in a new issue