Falkon Develop
Cross-platform Qt-based web browser
adblockurlinterceptor.cpp
Go to the documentation of this file.
1/* ============================================================
2* Falkon - Qt web browser
3* Copyright (C) 2015-2018 David Rosca <nowrep@gmail.com>
4*
5* This program is free software: you can redistribute it and/or modify
6* it under the terms of the GNU General Public License as published by
7* the Free Software Foundation, either version 3 of the License, or
8* (at your option) any later version.
9*
10* This program is distributed in the hope that it will be useful,
11* but WITHOUT ANY WARRANTY; without even the implied warranty of
12* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13* GNU General Public License for more details.
14*
15* You should have received a copy of the GNU General Public License
16* along with this program. If not, see <http://www.gnu.org/licenses/>.
17* ============================================================ */
18
20#include "adblockrule.h"
21#include "qztools.h"
22
23#include <QUrlQuery>
24
26 : UrlInterceptor(manager)
27 , m_manager(manager)
28{
29}
30
31void AdBlockUrlInterceptor::interceptRequest(QWebEngineUrlRequestInfo &request)
32{
33 QString ruleFilter;
34 QString ruleSubscription;
35 if (!m_manager->block(request, ruleFilter, ruleSubscription)) {
36 return;
37 }
38
39 if (request.resourceType() == QWebEngineUrlRequestInfo::ResourceTypeMainFrame) {
40 QString url = QSL("qrc:adblock/data/adblock.html?direction=%DIRECTION%&title=%1&rule=%3").arg(
41 tr("Blocked content"),
42 tr("Blocked by <i>%1 (%2)</i>").arg(ruleFilter, ruleSubscription)
43 );
45
46 request.redirect(QUrl(url));
47 } else {
48 request.block(true);
49 }
50
52 r.requestUrl = request.requestUrl();
53 r.firstPartyUrl = request.firstPartyUrl();
54 r.requestMethod = request.requestMethod();
55 r.resourceType = request.resourceType();
56 r.navigationType = request.navigationType();
57 r.rule = ruleFilter;
58 Q_EMIT requestBlocked(r);
59}
bool block(QWebEngineUrlRequestInfo &request, QString &ruleFilter, QString &ruleSubscription)
AdBlockUrlInterceptor(AdBlockManager *manager)
void interceptRequest(QWebEngineUrlRequestInfo &request) override
void requestBlocked(const AdBlockedRequest &request)
static QString applyDirectionToPage(QString &pageContents)
Definition: qztools.cpp:439
#define QSL(x)
Definition: qzcommon.h:40
QByteArray requestMethod
QWebEngineUrlRequestInfo::ResourceType resourceType
QWebEngineUrlRequestInfo::NavigationType navigationType