mirror of
https://invent.kde.org/network/falkon.git
synced 2024-12-20 10:46:35 +01:00
AdBlock: Show error page when the whole page was blocked
This commit is contained in:
parent
74350785b0
commit
af93ecf81e
@ -105,14 +105,26 @@ bool AdBlockManager::block(QWebEngineUrlRequestInfo &request)
|
||||
|
||||
if (blockedRule) {
|
||||
res = true;
|
||||
|
||||
if (request.resourceType() == QWebEngineUrlRequestInfo::ResourceTypeMainFrame) {
|
||||
QUrl url(QSL("qupzilla:adblock"));
|
||||
QUrlQuery query;
|
||||
query.addQueryItem(QSL("rule"), blockedRule->filter());
|
||||
query.addQueryItem(QSL("subscription"), blockedRule->subscription()->title());
|
||||
url.setQuery(query);
|
||||
request.redirect(url);
|
||||
}
|
||||
else {
|
||||
request.block(true);
|
||||
}
|
||||
|
||||
#ifdef ADBLOCK_DEBUG
|
||||
qDebug() << "BLOCKED: " << timer.elapsed() << blockedRule->filter() << request.url();
|
||||
qDebug() << "BLOCKED: " << timer.elapsed() << blockedRule->filter() << request.requestUrl();
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef ADBLOCK_DEBUG
|
||||
qDebug() << timer.elapsed() << request.url();
|
||||
qDebug() << timer.elapsed() << request.requestUrl();
|
||||
#endif
|
||||
|
||||
return res;
|
||||
|
@ -2,7 +2,7 @@
|
||||
<qresource prefix="/">
|
||||
<file>html/errorPage.html</file>
|
||||
<file>html/adblock_big.png</file>
|
||||
<file>html/adblockPage.html</file>
|
||||
<file>html/adblock.html</file>
|
||||
<file>html/about.html</file>
|
||||
<file>html/box-border.png</file>
|
||||
<file>html/copyright</file>
|
||||
|
@ -222,7 +222,7 @@ QString LocationBar::convertUrlToText(const QUrl &url)
|
||||
|
||||
QString stringUrl = QzTools::urlEncodeQueryString(url);
|
||||
|
||||
if (stringUrl == QLatin1String("qupzilla:speeddial") || stringUrl == QLatin1String("about:blank")) {
|
||||
if (stringUrl == QL1S("qupzilla:speeddial") || stringUrl.startsWith(QL1S("qupzilla:adblock")) || stringUrl == QL1S("about:blank")) {
|
||||
stringUrl.clear();
|
||||
}
|
||||
|
||||
|
@ -30,6 +30,7 @@
|
||||
|
||||
#include <QTimer>
|
||||
#include <QSettings>
|
||||
#include <QUrlQuery>
|
||||
#include <QWebEngineUrlRequestJob>
|
||||
|
||||
static QString authorString(const char* name, const QString &mail)
|
||||
@ -45,7 +46,7 @@ QupZillaSchemeHandler::QupZillaSchemeHandler(QObject *parent)
|
||||
void QupZillaSchemeHandler::requestStarted(QWebEngineUrlRequestJob *job)
|
||||
{
|
||||
QStringList knownPages;
|
||||
knownPages << "about" << "reportbug" << "start" << "speeddial" << "config" << "restore";
|
||||
knownPages << "about" << "reportbug" << "start" << "speeddial" << "config" << "restore" << "adblock";
|
||||
|
||||
if (knownPages.contains(job->requestUrl().path()))
|
||||
job->reply(QByteArrayLiteral("text/html"), new QupZillaSchemeReply(job));
|
||||
@ -91,6 +92,9 @@ void QupZillaSchemeReply::loadPage()
|
||||
else if (m_pageName == QLatin1String("restore")) {
|
||||
stream << restorePage();
|
||||
}
|
||||
else if (m_pageName == QLatin1String("adblock")) {
|
||||
stream << adblockPage();
|
||||
}
|
||||
|
||||
stream.flush();
|
||||
m_buffer.reset();
|
||||
@ -480,3 +484,27 @@ QString QupZillaSchemeReply::configPage()
|
||||
|
||||
return page;
|
||||
}
|
||||
|
||||
QString QupZillaSchemeReply::adblockPage()
|
||||
{
|
||||
static QString aPage;
|
||||
|
||||
if (aPage.isEmpty()) {
|
||||
aPage.append(QzTools::readAllFileContents(":html/adblock.html"));
|
||||
aPage.replace(QLatin1String("%FAVICON%"), QLatin1String("qrc:html/adblock_big.png"));
|
||||
aPage.replace(QLatin1String("%BOX-BORDER%"), QLatin1String("qrc:html/box-border.png"));
|
||||
aPage.replace(QLatin1String("%IMAGE%"), QLatin1String("qrc:html/adblock_big.png"));
|
||||
aPage.replace(QLatin1String("%TITLE%"), tr("Blocked content"));
|
||||
aPage = QzTools::applyDirectionToPage(aPage);
|
||||
}
|
||||
|
||||
|
||||
QString page = aPage;
|
||||
QUrlQuery query(m_job->requestUrl());
|
||||
|
||||
const QString rule = query.queryItemValue(QSL("rule"));
|
||||
const QString subscription = query.queryItemValue(QSL("subscription"));
|
||||
page.replace(QLatin1String("%RULE%"), tr("Blocked by <i>%1 (%2)</i>").arg(rule, subscription));
|
||||
|
||||
return page;
|
||||
}
|
||||
|
@ -53,6 +53,7 @@ private:
|
||||
QString speeddialPage();
|
||||
QString restorePage();
|
||||
QString configPage();
|
||||
QString adblockPage();
|
||||
|
||||
bool m_loaded;
|
||||
QBuffer m_buffer;
|
||||
|
Loading…
Reference in New Issue
Block a user