|
|
|
|
@ -1,6 +1,6 @@ |
|
|
|
|
/* ============================================================
|
|
|
|
|
* Falkon - Qt web browser |
|
|
|
|
* Copyright (C) 2015-2017 David Rosca <nowrep@gmail.com> |
|
|
|
|
* Copyright (C) 2015-2018 David Rosca <nowrep@gmail.com> |
|
|
|
|
* |
|
|
|
|
* This program is free software: you can redistribute it and/or modify |
|
|
|
|
* it under the terms of the GNU General Public License as published by |
|
|
|
|
@ -29,10 +29,34 @@ NetworkUrlInterceptor::NetworkUrlInterceptor(QObject *parent) |
|
|
|
|
|
|
|
|
|
void NetworkUrlInterceptor::interceptRequest(QWebEngineUrlRequestInfo &info) |
|
|
|
|
{ |
|
|
|
|
if (m_sendDNT) |
|
|
|
|
m_mutex.lock(); |
|
|
|
|
|
|
|
|
|
if (m_sendDNT) { |
|
|
|
|
info.setHttpHeader(QByteArrayLiteral("DNT"), QByteArrayLiteral("1")); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const QString host = info.firstPartyUrl().host(); |
|
|
|
|
|
|
|
|
|
if (m_usePerDomainUserAgent) { |
|
|
|
|
QString userAgent; |
|
|
|
|
if (m_userAgentsList.contains(host)) { |
|
|
|
|
userAgent = m_userAgentsList.value(host); |
|
|
|
|
} else { |
|
|
|
|
QHashIterator<QString, QString> i(m_userAgentsList); |
|
|
|
|
while (i.hasNext()) { |
|
|
|
|
i.next(); |
|
|
|
|
if (host.endsWith(i.key())) { |
|
|
|
|
userAgent = i.value(); |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (!userAgent.isEmpty()) { |
|
|
|
|
info.setHttpHeader(QByteArrayLiteral("User-Agent"), userAgent.toUtf8()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
info.setHttpHeader(QByteArrayLiteral("User-Agent"), mApp->userAgentManager()->userAgentForUrl(info.firstPartyUrl()).toUtf8()); |
|
|
|
|
m_mutex.unlock(); |
|
|
|
|
|
|
|
|
|
foreach (UrlInterceptor *interceptor, m_interceptors) { |
|
|
|
|
interceptor->interceptRequest(info); |
|
|
|
|
@ -52,8 +76,15 @@ void NetworkUrlInterceptor::removeUrlInterceptor(UrlInterceptor *interceptor) |
|
|
|
|
|
|
|
|
|
void NetworkUrlInterceptor::loadSettings() |
|
|
|
|
{ |
|
|
|
|
m_mutex.lock(); |
|
|
|
|
|
|
|
|
|
Settings settings; |
|
|
|
|
settings.beginGroup("Web-Browser-Settings"); |
|
|
|
|
m_sendDNT = settings.value("DoNotTrack", false).toBool(); |
|
|
|
|
settings.endGroup(); |
|
|
|
|
|
|
|
|
|
m_usePerDomainUserAgent = mApp->userAgentManager()->usePerDomainUserAgents(); |
|
|
|
|
m_userAgentsList = mApp->userAgentManager()->perDomainUserAgentsList(); |
|
|
|
|
|
|
|
|
|
m_mutex.unlock(); |
|
|
|
|
} |
|
|
|
|
|