From 3d2ae07c455c0e423c64f19e445518427a5684fa Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Wed, 9 Jan 2019 19:38:58 +0100 Subject: Rewrite lib/urlfilter - Make HostList and AdBlockList implementations independent from each other - Move urlfilter tests to lib/urlfilter --- src/browser.cpp | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) (limited to 'src/browser.cpp') diff --git a/src/browser.cpp b/src/browser.cpp index 42bbc5d..3a23eeb 100644 --- a/src/browser.cpp +++ b/src/browser.cpp @@ -18,7 +18,6 @@ #include "profilemanager.h" #include "subwindow/subwindow.h" #include "util.h" -#include "webengine/filter.h" #include "webengine/urlinterceptor.h" #include "webprofile.h" #include @@ -35,6 +34,9 @@ #include #include "mainwindow/menubar.h" #include "webengine/webview.h" +#include "urlfilter.h" +#include "adblock/adblocklist.h" +#include "hostlist/hostlist.h" Browser::Browser(int &argc, char *argv[], bool allowSecondary) : SingleApplication(argc, argv, allowSecondary, SingleApplication::User | SingleApplication::SecondaryNotification | SingleApplication::ExcludeAppVersion) @@ -99,7 +101,16 @@ QPair Browser::loadProfile(const QString &id, bool isOffTheR profile = m_profileManager->createProfile(id, isOffTheRecord); } connect(profile, &WebProfile::downloadRequested, m_downloads.get(), &DownloadsWidget::addDownload); - auto *interceptor = new UrlRequestInterceptor(m_urlFilter.get(), profile, profile); + auto *interceptor = new UrlRequestInterceptor(profile, profile); + for(UrlFilter *filter : m_filters) { + interceptor->addFilter(filter); + } + const auto headers = m_config->value("filter.header").value_or(QStringList()); + for(const QString &header : headers) { + const auto h = header.split(QLatin1Literal(":")); + if(h.length() == 2) + interceptor->addHttpHeader(h.at(0).toLatin1(), h.at(1).toLatin1()); + } profile->setRequestInterceptor(interceptor); return QPair(m_profileManager->id(profile), profile); @@ -164,7 +175,20 @@ void Browser::setup(QVector plugins) // downloads m_downloads = std::make_unique(m_config->value("downloads.path").value()); // url request filter - m_urlFilter = std::make_unique(m_config); + for(const QString &hostlist : Util::files(m_config->value("filter.hosts").value_or(QString()))) { + QFile f(hostlist); + if(f.open(QIODevice::ReadOnly | QIODevice::Text)) { + m_filters.append(new HostList(&f)); + f.close(); + } + } + for(const QString &adblock : Util::files(m_config->value("filter.adblock").value_or(QString()))) { + QFile f(adblock); + if(f.open(QIODevice::ReadOnly | QIODevice::Text)) { + m_filters.append(new AdBlockList(&f)); + f.close(); + } + } // cookie request filter // load profiles -- cgit v1.2.1