diff options
author | Aqua-sama <aqua@iserlohn-fortress.net> | 2019-01-09 19:38:58 +0100 |
---|---|---|
committer | Aqua-sama <aqua@iserlohn-fortress.net> | 2019-01-09 19:38:58 +0100 |
commit | 3d2ae07c455c0e423c64f19e445518427a5684fa (patch) | |
tree | 58f6b47c3db33658a6f2e605fd021f08d1fa9964 /src/browser.cpp | |
parent | Add assorted unfished doc files to repo (diff) | |
download | smolbote-3d2ae07c455c0e423c64f19e445518427a5684fa.tar.xz |
Rewrite lib/urlfilter
- Make HostList and AdBlockList implementations independent from each
other
- Move urlfilter tests to lib/urlfilter
Diffstat (limited to 'src/browser.cpp')
-rw-r--r-- | src/browser.cpp | 30 |
1 files changed, 27 insertions, 3 deletions
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 <QAction> @@ -35,6 +34,9 @@ #include <version.h> #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<QString, Profile *> 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<QStringList>("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<QString, WebProfile *>(m_profileManager->id(profile), profile); @@ -164,7 +175,20 @@ void Browser::setup(QVector<QPluginLoader *> plugins) // downloads m_downloads = std::make_unique<DownloadsWidget>(m_config->value<QString>("downloads.path").value()); // url request filter - m_urlFilter = std::make_unique<Filter>(m_config); + for(const QString &hostlist : Util::files(m_config->value<QString>("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<QString>("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 |