diff --git a/src/lib/adblock/adblockaddsubscriptiondialog.cpp b/src/lib/adblock/adblockaddsubscriptiondialog.cpp index db89ce10..c010b0f9 100644 --- a/src/lib/adblock/adblockaddsubscriptiondialog.cpp +++ b/src/lib/adblock/adblockaddsubscriptiondialog.cpp @@ -1,91 +1,92 @@ /* ============================================================ * Falkon - Qt web browser * Copyright (C) 2010-2017 David Rosca * * 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 * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * ============================================================ */ #include "adblockaddsubscriptiondialog.h" #include "ui_adblockaddsubscriptiondialog.h" +#include "adblockmanager.h" AdBlockAddSubscriptionDialog::AdBlockAddSubscriptionDialog(QWidget* parent) : QDialog(parent) , ui(new Ui::AdBlockAddSubscriptionDialog) { ui->setupUi(this); m_knownSubscriptions << Subscription("EasyList (English)", ADBLOCK_EASYLIST_URL) << Subscription("BSI Lista Polska (Polish)", "http://www.bsi.info.pl/filtrABP.txt") << Subscription("Czech List (Czech)", "http://adblock.dajbych.net/adblock.txt") << Subscription("dutchblock (Dutch)", "http://groenewoudt.net/dutchblock/list.txt") << Subscription("Filtros Nauscopicos (Spanish)", "http://abp.mozilla-hispano.org/nauscopio/filtros.txt") << Subscription("IsraelList (Hebrew)", "http://secure.fanboy.co.nz/israelilist/IsraelList.txt") << Subscription("NLBlock (Dutch)", "http://www.verzijlbergh.com/adblock/nlblock.txt") << Subscription("Peter Lowe's list (English)", "http://pgl.yoyo.org/adservers/serverlist.php?hostformat=adblockplus&mimetype=plaintext") << Subscription("PLgeneral (Polish)", "http://www.niecko.pl/adblock/adblock.txt") << Subscription("Schacks Adblock Plus liste (Danish)", "http://adblock.schack.dk/block.txt") << Subscription("Xfiles (Italian)", "http://mozilla.gfsolone.com/filtri.txt") << Subscription("EasyPrivacy (English)", "http://easylist-downloads.adblockplus.org/easyprivacy.txt") << Subscription("RU Adlist (Russian)", "https://easylist-downloads.adblockplus.org/advblock.txt") << Subscription("ABPindo (Indonesian)", "https://raw.githubusercontent.com/heradhis/indonesianadblockrules/master/subscriptions/abpindo.txt") << Subscription("Easylist China (Chinese)", "https://easylist-downloads.adblockplus.org/easylistchina.txt") << Subscription("Anti-Adblock Killer", "https://raw.githubusercontent.com/reek/anti-adblock-killer/master/anti-adblock-killer-filters.txt") << Subscription(tr("Other..."), QString()); foreach (const Subscription &subscription, m_knownSubscriptions) { ui->comboBox->addItem(subscription.title); } connect(ui->comboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(indexChanged(int))); indexChanged(0); } QString AdBlockAddSubscriptionDialog::title() const { return ui->title->text(); } QString AdBlockAddSubscriptionDialog::url() const { return ui->url->text(); } void AdBlockAddSubscriptionDialog::indexChanged(int index) { const Subscription subscription = m_knownSubscriptions.at(index); // "Other..." entry if (subscription.url.isEmpty()) { ui->title->clear(); ui->url->clear(); } else { int pos = subscription.title.indexOf(QLatin1Char('(')); QString title = subscription.title; if (pos > 0) { title = title.left(pos).trimmed(); } ui->title->setText(title); ui->title->setCursorPosition(0); ui->url->setText(subscription.url); ui->url->setCursorPosition(0); } } AdBlockAddSubscriptionDialog::~AdBlockAddSubscriptionDialog() { delete ui; } diff --git a/src/lib/adblock/adblockmanager.h b/src/lib/adblock/adblockmanager.h index b9795645..7f2b17ec 100644 --- a/src/lib/adblock/adblockmanager.h +++ b/src/lib/adblock/adblockmanager.h @@ -1,115 +1,117 @@ /* ============================================================ * Falkon - Qt web browser * Copyright (C) 2010-2018 David Rosca * * 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 * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * ============================================================ */ #ifndef ADBLOCKMANAGER_H #define ADBLOCKMANAGER_H #include #include #include #include #include #include #include "qzcommon.h" +#define ADBLOCK_EASYLIST_URL "https://easylist-downloads.adblockplus.org/easylist.txt" + class AdBlockRule; class AdBlockDialog; class AdBlockMatcher; class AdBlockCustomList; class AdBlockSubscription; class AdBlockUrlInterceptor; struct AdBlockedRequest { QUrl requestUrl; QUrl firstPartyUrl; QByteArray requestMethod; QWebEngineUrlRequestInfo::ResourceType resourceType; QWebEngineUrlRequestInfo::NavigationType navigationType; QString rule; }; Q_DECLARE_METATYPE(AdBlockedRequest) class FALKON_EXPORT AdBlockManager : public QObject { Q_OBJECT public: AdBlockManager(QObject* parent = 0); ~AdBlockManager(); void load(); void save(); bool isEnabled() const; bool canRunOnScheme(const QString &scheme) const; bool canBeBlocked(const QUrl &url) const; QString elementHidingRules(const QUrl &url) const; QString elementHidingRulesForDomain(const QUrl &url) const; AdBlockSubscription* subscriptionByName(const QString &name) const; QList subscriptions() const; bool block(QWebEngineUrlRequestInfo &request, QString &ruleFilter, QString &ruleSubscription); QVector blockedRequestsForUrl(const QUrl &url) const; void clearBlockedRequestsForUrl(const QUrl &url); QStringList disabledRules() const; void addDisabledRule(const QString &filter); void removeDisabledRule(const QString &filter); bool addSubscriptionFromUrl(const QUrl &url); AdBlockSubscription* addSubscription(const QString &title, const QString &url); bool removeSubscription(AdBlockSubscription* subscription); AdBlockCustomList* customList() const; static AdBlockManager* instance(); signals: void enabledChanged(bool enabled); void blockedRequestsChanged(const QUrl &url); public slots: void setEnabled(bool enabled); void showRule(); void updateMatcher(); void updateAllSubscriptions(); AdBlockDialog* showDialog(); private: bool m_loaded; bool m_enabled; QList m_subscriptions; AdBlockMatcher* m_matcher; QStringList m_disabledRules; AdBlockUrlInterceptor *m_interceptor; QPointer m_adBlockDialog; QMutex m_mutex; QHash> m_blockedRequests; }; #endif // ADBLOCKMANAGER_H diff --git a/src/lib/app/qzcommon.h b/src/lib/app/qzcommon.h index 11445c54..406c838c 100644 --- a/src/lib/app/qzcommon.h +++ b/src/lib/app/qzcommon.h @@ -1,141 +1,139 @@ /* ============================================================ * Falkon - Qt web browser * Copyright (C) 2010-2018 David Rosca * * 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 * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * ============================================================ */ #ifndef QZCOMMON_H #define QZCOMMON_H #include #include #ifdef FALKON_SHAREDLIBRARY #define FALKON_EXPORT Q_DECL_EXPORT #else #define FALKON_EXPORT Q_DECL_IMPORT #endif #ifndef Q_UNLIKELY #define Q_UNLIKELY(x) x #endif #ifndef Q_LIKELY #define Q_LIKELY(x) x #endif #ifndef QSL #define QSL(x) QStringLiteral(x) #endif #ifndef QL1S #define QL1S(x) QLatin1String(x) #endif #ifndef QL1C #define QL1C(x) QLatin1Char(x) #endif namespace Qz { // Version of session.dat file extern const int sessionVersion; // Version of bookmarks.json file extern const int bookmarksVersion; FALKON_EXPORT extern const char* APPNAME; FALKON_EXPORT extern const char* VERSION; FALKON_EXPORT extern const char* AUTHOR; FALKON_EXPORT extern const char* COPYRIGHT; FALKON_EXPORT extern const char* WWWADDRESS; FALKON_EXPORT extern const char* WIKIADDRESS; enum BrowserWindowType { BW_FirstAppWindow, BW_OtherRestoredWindow, BW_NewWindow, BW_MacFirstWindow }; enum CommandLineAction { CL_NoAction, CL_OpenUrl, CL_OpenUrlInCurrentTab, CL_OpenUrlInNewWindow, CL_StartWithProfile, CL_StartWithoutAddons, CL_NewTab, CL_NewWindow, CL_ShowDownloadManager, CL_ToggleFullScreen, CL_StartPrivateBrowsing, CL_StartNewInstance, CL_StartPortable, CL_ExitAction }; enum ObjectName { ON_WebView, ON_TabBar, ON_BrowserWindow }; enum NewTabPositionFlag { NT_SelectedTab = 1, NT_NotSelectedTab = 2, NT_CleanTab = 4, NT_TabAtTheEnd = 8, NT_NewEmptyTab = 16, NT_SelectedNewEmptyTab = NT_SelectedTab | NT_TabAtTheEnd | NT_NewEmptyTab, NT_SelectedTabAtTheEnd = NT_SelectedTab | NT_TabAtTheEnd, NT_NotSelectedTabAtTheEnd = NT_NotSelectedTab | NT_TabAtTheEnd, NT_CleanSelectedTabAtTheEnd = NT_SelectedTab | NT_TabAtTheEnd | NT_CleanTab, NT_CleanSelectedTab = NT_CleanTab | NT_SelectedTab, NT_CleanNotSelectedTab = NT_CleanTab | NT_NotSelectedTab }; Q_DECLARE_FLAGS(NewTabPositionFlags, NewTabPositionFlag) Q_DECLARE_OPERATORS_FOR_FLAGS(Qz::NewTabPositionFlags) } -#define ADBLOCK_EASYLIST_URL "https://easylist-downloads.adblockplus.org/easylist.txt" - #if defined(Q_OS_WIN) || defined(Q_OS_OS2) #define DEFAULT_THEME_NAME "windows" #elif defined(Q_OS_MACOS) #define DEFAULT_THEME_NAME "mac" #elif defined(Q_OS_UNIX) #define DEFAULT_THEME_NAME "linux" #else #define DEFAULT_THEME_NAME "default" #endif #ifdef Q_OS_WIN #define DISABLE_CHECK_UPDATES false #else #define DISABLE_CHECK_UPDATES true #endif #define DEFAULT_CHECK_DEFAULTBROWSER false #ifdef Q_OS_WIN #define DEFAULT_DOWNLOAD_USE_NATIVE_DIALOG false #else #define DEFAULT_DOWNLOAD_USE_NATIVE_DIALOG true #endif #endif // QZCOMMON_H