diff --git a/resources/docs/Documentation.md b/resources/docs/Documentation.md index c0575b3b9..180dcac8b 100644 --- a/resources/docs/Documentation.md +++ b/resources/docs/Documentation.md @@ -157,7 +157,7 @@ You can right click on any item in embedded web browser and hit `Save as` button You can download up to 6 files simultaneously. ## AdBlock -[Web-based variant](#web-based-and-lite-app-variants) of RSS Guard offers ad-blocking functionality. AdBlock uses standard AdBlock-Plus-like scripts, thus allowing you to use EasyList etc. AdBlock supports element hiding rules and site-wide blocking. +[Web-based variant](#web-based-and-lite-app-variants) of RSS Guard offers ad-blocking functionality. AdBlock uses standard AdBlock-Plus-like scripts, thus allowing you to use EasyList etc. AdBlock supports all fundamental features of AdBlock-Plus format, including element hiding rules and site-wide blocking. You can find its settings in `Web browser & tabs` section of main menu. diff --git a/src/librssguard/definitions/definitions.h b/src/librssguard/definitions/definitions.h index 8d400a58e..a8190b82a 100755 --- a/src/librssguard/definitions/definitions.h +++ b/src/librssguard/definitions/definitions.h @@ -17,7 +17,6 @@ #define ARGUMENTS_LIST_SEPARATOR "\n" -#define ADBLOCK_ADBLOCKED_PAGE "adblockedpage" #define ADBLOCK_HOWTO_FILTERS "https://help.eyeo.com/en/adblockplus/how-to-write-filters" #define ADBLOCK_UPDATE_DAYS_INTERVAL 14 #define ADBLOCK_ICON_ACTIVE "adblock" @@ -116,6 +115,7 @@ #define INTERNAL_URL_MESSAGE "http://rssguard.message" #define INTERNAL_URL_BLANK "http://rssguard.blank" +#define INTERNAL_URL_ADBLOCKED "http://rssguard.adblocked" #define INTERNAL_URL_MESSAGE_HOST "rssguard.message" #define INTERNAL_URL_BLANK_HOST "rssguard.blank" #define INTERNAL_URL_PASSATTACHMENT "http://rssguard.passattachment" diff --git a/src/librssguard/librssguard.pro b/src/librssguard/librssguard.pro index f2ec5aade..0ad5d4624 100644 --- a/src/librssguard/librssguard.pro +++ b/src/librssguard/librssguard.pro @@ -386,16 +386,14 @@ equals(USE_WEBENGINE, true) { gui/webbrowser.h \ gui/discoverfeedsbutton.h \ network-web/googlesuggest.h \ - network-web/webpage.h \ - network-web/rssguardschemehandler.h + network-web/webpage.h SOURCES += gui/locationlineedit.cpp \ gui/webviewer.cpp \ gui/webbrowser.cpp \ gui/discoverfeedsbutton.cpp \ network-web/googlesuggest.cpp \ - network-web/webpage.cpp \ - network-web/rssguardschemehandler.cpp + network-web/webpage.cpp # Add AdBlock sources. HEADERS += network-web/adblock/adblockaddsubscriptiondialog.h \ diff --git a/src/librssguard/network-web/rssguardschemehandler.cpp b/src/librssguard/network-web/rssguardschemehandler.cpp deleted file mode 100644 index f2cfd6fac..000000000 --- a/src/librssguard/network-web/rssguardschemehandler.cpp +++ /dev/null @@ -1,62 +0,0 @@ -// For license of this file, see /LICENSE.md. - -// -// Copyright (C) 2011-2017 by Martin Rotter -// Copyright (C) 2010-2014 by David Rosca -// -// RSS Guard 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. -// -// RSS Guard 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 RSS Guard. If not, see . - -#include "network-web/rssguardschemehandler.h" - -#include "definitions/definitions.h" -#include "miscellaneous/application.h" -#include "miscellaneous/skinfactory.h" - -#include -#include -#include - -RssGuardSchemeHandler::RssGuardSchemeHandler(QObject* parent) : QWebEngineUrlSchemeHandler(parent) {} - -RssGuardSchemeHandler::~RssGuardSchemeHandler() = default; - -void RssGuardSchemeHandler::requestStarted(QWebEngineUrlRequestJob* job) { - // Decide which data we want. - QByteArray data = targetData(job->requestUrl()); - - if (data.isEmpty()) { - job->fail(QWebEngineUrlRequestJob::Error::UrlNotFound); - } - else { - auto* buf = new QBuffer(job); - - buf->setData(data); - job->reply(QByteArray("text/html"), buf); - } -} - -QByteArray RssGuardSchemeHandler::targetData(const QUrl& url) { - const QString& url_string = url.toString(); - - if (url_string.contains(QSL(ADBLOCK_ADBLOCKED_PAGE))) { - QUrlQuery query(url); - const QString& subscription = query.queryItemValue(QSL("subscription")); - const QString& rule = query.queryItemValue(QSL("rule")); - - return qApp->skins()->adBlockedPage(subscription, rule).toUtf8(); - } - else { - return QByteArray(); - } -} diff --git a/src/librssguard/network-web/rssguardschemehandler.h b/src/librssguard/network-web/rssguardschemehandler.h deleted file mode 100644 index dd39c15ed..000000000 --- a/src/librssguard/network-web/rssguardschemehandler.h +++ /dev/null @@ -1,42 +0,0 @@ -// For license of this file, see /LICENSE.md. - -// -// Copyright (C) 2011-2017 by Martin Rotter -// Copyright (C) 2010-2014 by David Rosca -// -// RSS Guard 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. -// -// RSS Guard 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 RSS Guard. If not, see . - -#ifndef RSSGUARDSCHEMEHANDLER_H -#define RSSGUARDSCHEMEHANDLER_H - -#include -#include - -class QWebEngineUrlRequestJob; -class QBuffer; - -class RssGuardSchemeHandler : public QWebEngineUrlSchemeHandler { - Q_OBJECT - - public: - explicit RssGuardSchemeHandler(QObject* parent = nullptr); - virtual ~RssGuardSchemeHandler(); - - void requestStarted(QWebEngineUrlRequestJob* job); - - private: - QByteArray targetData(const QUrl& url); -}; - -#endif // RSSGUARDSCHEMEHANDLER_H diff --git a/src/librssguard/network-web/webfactory.cpp b/src/librssguard/network-web/webfactory.cpp index b266babd0..a46f80bbb 100644 --- a/src/librssguard/network-web/webfactory.cpp +++ b/src/librssguard/network-web/webfactory.cpp @@ -13,7 +13,6 @@ #include "network-web/adblock/adblockicon.h" #include "network-web/adblock/adblockmanager.h" #include "network-web/networkurlinterceptor.h" -#include "network-web/rssguardschemehandler.h" #include "network-web/urlinterceptor.h" #include @@ -32,25 +31,11 @@ WebFactory::WebFactory(QObject* parent) #endif #if defined(USE_WEBENGINE) - QWebEngineUrlScheme url_scheme(QByteArray(APP_LOW_NAME)); - - url_scheme.setDefaultPort(QWebEngineUrlScheme::SpecialPort::PortUnspecified); - url_scheme.setSyntax(QWebEngineUrlScheme::Syntax::Host); - url_scheme.setFlags(QWebEngineUrlScheme::Flag::LocalScheme | - QWebEngineUrlScheme::Flag::LocalAccessAllowed | - QWebEngineUrlScheme::Flag::ServiceWorkersAllowed | - QWebEngineUrlScheme::Flag::ContentSecurityPolicyIgnored); - - QWebEngineUrlScheme::registerScheme(url_scheme); - #if QT_VERSION >= 0x050D00 // Qt >= 5.13.0 QWebEngineProfile::defaultProfile()->setUrlRequestInterceptor(m_urlInterceptor); #else QWebEngineProfile::defaultProfile()->setRequestInterceptor(m_urlInterceptor); #endif - - QWebEngineProfile::defaultProfile()->installUrlSchemeHandler(QByteArray(APP_LOW_NAME), - new RssGuardSchemeHandler(QWebEngineProfile::defaultProfile())); #endif } diff --git a/src/librssguard/network-web/webpage.cpp b/src/librssguard/network-web/webpage.cpp index 5c73ddaf8..d2b37c17c 100644 --- a/src/librssguard/network-web/webpage.cpp +++ b/src/librssguard/network-web/webpage.cpp @@ -61,14 +61,8 @@ bool WebPage::acceptNavigationRequest(const QUrl& url, NavigationType type, bool if (adblock_rule != nullptr) { // This website is entirely blocked. - QUrlQuery query; - QUrl new_url(QSL("%1:///%2/").arg(APP_LOW_NAME, ADBLOCK_ADBLOCKED_PAGE)); - - query.addQueryItem(QSL("rule"), adblock_rule->filter()); - query.addQueryItem(QSL("subscription"), adblock_rule->subscription()->title()); - new_url.setQuery(query); - - setUrl(new_url); + setHtml(qApp->skins()->adBlockedPage(adblock_rule->subscription()->title(), adblock_rule->filter()), + QUrl::fromUserInput(INTERNAL_URL_ADBLOCKED)); return false; } }