aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/webengine/urlinterceptor.cpp40
-rw-r--r--src/webengine/urlinterceptor.h4
2 files changed, 38 insertions, 6 deletions
diff --git a/src/webengine/urlinterceptor.cpp b/src/webengine/urlinterceptor.cpp
index 4e1b2f1..1b44c47 100644
--- a/src/webengine/urlinterceptor.cpp
+++ b/src/webengine/urlinterceptor.cpp
@@ -11,6 +11,8 @@
#include <QTextStream>
#include <configuration/configuration.h>
#include <boost/algorithm/string.hpp>
+#include <QJsonDocument>
+#include <QJsonArray>
UrlRequestInterceptor::UrlRequestInterceptor(const std::unique_ptr<Configuration> &config, QObject *parent)
: QWebEngineUrlRequestInterceptor(parent)
@@ -36,8 +38,29 @@ UrlRequestInterceptor::UrlRequestInterceptor(const std::unique_ptr<Configuration
m_headers.emplace_back(pair);
}
}
+
+ QFile rules(config->value<QString>("filter.json-path").value());
+ if(rules.open(QIODevice::ReadOnly | QIODevice::Text)) {
+ auto doc = QJsonDocument::fromJson(rules.readAll()).object();
+
+ Q_ASSERT(doc.value("domains").isArray());
+ for(QJsonValue d : doc.value("domains").toArray()) {
+ domain.addDomain(d.toString());
+ }
+
+ Q_ASSERT(doc.value("rules").isArray());
+ for(QJsonValue rule : doc.value("rules").toArray()) {
+ auto p = std::make_unique<FilterRule>(rule.toObject());
+ parseJson(p, rule.toObject());
+ domain.addRule(p);
+ }
+
+ rules.close();
+ }
+
}
+// test DNT on https://browserleaks.com/donottrack
void UrlRequestInterceptor::interceptRequest(QWebEngineUrlRequestInfo &info)
{
for(const Header &header : m_headers) {
@@ -46,15 +69,20 @@ void UrlRequestInterceptor::interceptRequest(QWebEngineUrlRequestInfo &info)
if(rules.contains(info.requestUrl().host())) {
info.block(rules.value(info.requestUrl().host()).isBlocking);
+ return;
+ }
+
+ if(domain.hasMatch(info.requestUrl().host())) {
+ domain.process(info);
}
#ifdef QT_DEBUG
- qDebug("request>>>");
- qDebug("firstParty url=%s", qUtf8Printable(info.firstPartyUrl().toString()));
- qDebug("firstParty host=%s", qUtf8Printable(info.firstPartyUrl().host()));
- qDebug("request url=%s", qUtf8Printable(info.requestUrl().toString()));
- qDebug("request host=%s", qUtf8Printable(info.requestUrl().host()));
- qDebug("<<<");
+// qDebug("request>>>");
+// qDebug("firstParty url=%s", qUtf8Printable(info.firstPartyUrl().toString()));
+// qDebug("firstParty host=%s", qUtf8Printable(info.firstPartyUrl().host()));
+// qDebug("request url=%s", qUtf8Printable(info.requestUrl().toString()));
+// qDebug("request host=%s", qUtf8Printable(info.requestUrl().host()));
+// qDebug("<<<");
#endif
}
diff --git a/src/webengine/urlinterceptor.h b/src/webengine/urlinterceptor.h
index 2f91e30..06a4b97 100644
--- a/src/webengine/urlinterceptor.h
+++ b/src/webengine/urlinterceptor.h
@@ -14,6 +14,8 @@
#include <QVector>
#include <QByteArray>
+#include "web/urlfilter/filterdomain.h"
+
typedef std::pair<std::string, std::string> Header;
class Configuration;
@@ -33,6 +35,8 @@ public:
private:
QHash<QString, HostRule> rules;
std::vector<Header> m_headers;
+
+ FilterDomain domain;
};
QHash<QString, UrlRequestInterceptor::HostRule> parse(const QString &filename);