mirror of
https://invent.kde.org/network/falkon.git
synced 2024-12-20 02:36:34 +01:00
Bring back AdBlock blocking network requests
This commit is contained in:
parent
40eb1281f8
commit
e91d6482d1
@ -1,82 +0,0 @@
|
||||
/* ============================================================
|
||||
* QupZilla - WebKit based browser
|
||||
* Copyright (C) 2010-2014 David Rosca <nowrep@gmail.com>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
* ============================================================ */
|
||||
/**
|
||||
* Copyright (c) 2009, Benjamin C. Meyer <ben@meyerhome.net>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Benjamin Meyer nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "adblockblockednetworkreply.h"
|
||||
#include "adblocksubscription.h"
|
||||
#include "adblockrule.h"
|
||||
|
||||
#include <QNetworkRequest>
|
||||
#include <QTimer>
|
||||
|
||||
AdBlockBlockedNetworkReply::AdBlockBlockedNetworkReply(const AdBlockRule* rule, QObject* parent)
|
||||
: QNetworkReply(parent)
|
||||
{
|
||||
setOperation(QNetworkAccessManager::GetOperation);
|
||||
setError(QNetworkReply::ContentAccessDenied, QString("AdBlock: %1 (%2)").arg(rule->subscription()->title(), rule->filter()));
|
||||
|
||||
open(QIODevice::ReadOnly);
|
||||
|
||||
QTimer::singleShot(0, this, SLOT(delayedFinished()));
|
||||
}
|
||||
|
||||
void AdBlockBlockedNetworkReply::setRequest(const QNetworkRequest &request)
|
||||
{
|
||||
QNetworkReply::setRequest(request);
|
||||
setUrl(request.url());
|
||||
}
|
||||
|
||||
qint64 AdBlockBlockedNetworkReply::readData(char* data, qint64 maxSize)
|
||||
{
|
||||
Q_UNUSED(data);
|
||||
Q_UNUSED(maxSize);
|
||||
return -1;
|
||||
}
|
||||
|
||||
void AdBlockBlockedNetworkReply::delayedFinished()
|
||||
{
|
||||
emit error(QNetworkReply::ContentAccessDenied);
|
||||
emit finished();
|
||||
}
|
||||
|
@ -1,75 +0,0 @@
|
||||
/* ============================================================
|
||||
* QupZilla - WebKit based browser
|
||||
* Copyright (C) 2010-2014 David Rosca <nowrep@gmail.com>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
* ============================================================ */
|
||||
/**
|
||||
* Copyright (c) 2009, Benjamin C. Meyer <ben@meyerhome.net>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Benjamin Meyer nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef ADBLOCKBLOCKEDNETWORKREPLY_H
|
||||
#define ADBLOCKBLOCKEDNETWORKREPLY_H
|
||||
|
||||
#include <QNetworkReply>
|
||||
|
||||
#include "qzcommon.h"
|
||||
|
||||
class AdBlockRule;
|
||||
class AdBlockSubscription;
|
||||
|
||||
class QUPZILLA_EXPORT AdBlockBlockedNetworkReply : public QNetworkReply
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
AdBlockBlockedNetworkReply(const AdBlockRule* rule, QObject* parent = 0);
|
||||
void abort() {}
|
||||
|
||||
void setRequest(const QNetworkRequest &request);
|
||||
|
||||
protected:
|
||||
qint64 readData(char* data, qint64 maxSize);
|
||||
|
||||
private slots:
|
||||
void delayedFinished();
|
||||
|
||||
};
|
||||
|
||||
#endif // ADBLOCKBLOCKEDNETWORKREPLY_H
|
||||
|
@ -19,13 +19,14 @@
|
||||
#include "adblockdialog.h"
|
||||
#include "adblockmatcher.h"
|
||||
#include "adblocksubscription.h"
|
||||
#include "adblockblockednetworkreply.h"
|
||||
#include "adblockurlinterceptor.h"
|
||||
#include "datapaths.h"
|
||||
#include "mainapplication.h"
|
||||
#include "webpage.h"
|
||||
#include "qztools.h"
|
||||
#include "browserwindow.h"
|
||||
#include "settings.h"
|
||||
#include "networkmanager.h"
|
||||
|
||||
#include <QDateTime>
|
||||
#include <QTextStream>
|
||||
@ -46,6 +47,7 @@ AdBlockManager::AdBlockManager(QObject* parent)
|
||||
, m_enabled(true)
|
||||
, m_useLimitedEasyList(true)
|
||||
, m_matcher(new AdBlockMatcher(this))
|
||||
, m_interceptor(new AdBlockUrlInterceptor(this))
|
||||
{
|
||||
load();
|
||||
}
|
||||
@ -83,7 +85,7 @@ QList<AdBlockSubscription*> AdBlockManager::subscriptions() const
|
||||
return m_subscriptions;
|
||||
}
|
||||
|
||||
QNetworkReply* AdBlockManager::block(const QNetworkRequest &request)
|
||||
bool AdBlockManager::block(QWebEngineUrlRequestInfo &request)
|
||||
{
|
||||
#ifdef ADBLOCK_DEBUG
|
||||
QElapsedTimer timer;
|
||||
@ -96,34 +98,22 @@ QNetworkReply* AdBlockManager::block(const QNetworkRequest &request)
|
||||
if (!isEnabled() || !canRunOnScheme(urlScheme))
|
||||
return 0;
|
||||
|
||||
bool res = false;
|
||||
const AdBlockRule* blockedRule = m_matcher->match(request, urlDomain, urlString);
|
||||
|
||||
if (blockedRule) {
|
||||
QVariant v = request.attribute((QNetworkRequest::Attribute)(QNetworkRequest::User + 100));
|
||||
WebPage* webPage = static_cast<WebPage*>(v.value<void*>());
|
||||
if (webPage) {
|
||||
if (!canBeBlocked(webPage->url())) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
webPage->addAdBlockRule(blockedRule, request.url());
|
||||
}
|
||||
|
||||
AdBlockBlockedNetworkReply* reply = new AdBlockBlockedNetworkReply(blockedRule, this);
|
||||
reply->setRequest(request);
|
||||
|
||||
res = true;
|
||||
request.blockRequest(true);
|
||||
#ifdef ADBLOCK_DEBUG
|
||||
qDebug() << "BLOCKED: " << timer.elapsed() << blockedRule->filter() << request.url();
|
||||
#endif
|
||||
|
||||
return reply;
|
||||
}
|
||||
|
||||
#ifdef ADBLOCK_DEBUG
|
||||
qDebug() << timer.elapsed() << request.url();
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
return res;
|
||||
}
|
||||
|
||||
QStringList AdBlockManager::disabledRules() const
|
||||
@ -217,6 +207,7 @@ void AdBlockManager::load()
|
||||
settings.endGroup();
|
||||
|
||||
if (!m_enabled) {
|
||||
mApp->networkManager()->removeUrlInterceptor(m_interceptor);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -285,6 +276,8 @@ void AdBlockManager::load()
|
||||
|
||||
m_matcher->update();
|
||||
m_loaded = true;
|
||||
|
||||
mApp->networkManager()->installUrlInterceptor(m_interceptor);
|
||||
}
|
||||
|
||||
void AdBlockManager::updateAllSubscriptions()
|
||||
|
@ -25,14 +25,14 @@
|
||||
#include "qzcommon.h"
|
||||
|
||||
class QUrl;
|
||||
class QNetworkReply;
|
||||
class QNetworkRequest;
|
||||
class QWebEngineUrlRequestInfo;
|
||||
|
||||
class AdBlockRule;
|
||||
class AdBlockDialog;
|
||||
class AdBlockMatcher;
|
||||
class AdBlockCustomList;
|
||||
class AdBlockSubscription;
|
||||
class AdBlockUrlInterceptor;
|
||||
|
||||
class QUPZILLA_EXPORT AdBlockManager : public QObject
|
||||
{
|
||||
@ -57,7 +57,7 @@ public:
|
||||
AdBlockSubscription* subscriptionByName(const QString &name) const;
|
||||
QList<AdBlockSubscription*> subscriptions() const;
|
||||
|
||||
QNetworkReply* block(const QNetworkRequest &request);
|
||||
bool block(QWebEngineUrlRequestInfo &request);
|
||||
|
||||
QStringList disabledRules() const;
|
||||
void addDisabledRule(const QString &filter);
|
||||
@ -92,6 +92,7 @@ private:
|
||||
AdBlockMatcher* m_matcher;
|
||||
QStringList m_disabledRules;
|
||||
|
||||
AdBlockUrlInterceptor *m_interceptor;
|
||||
QPointer<AdBlockDialog> m_adBlockDialog;
|
||||
};
|
||||
|
||||
|
@ -32,7 +32,7 @@ AdBlockMatcher::~AdBlockMatcher()
|
||||
clear();
|
||||
}
|
||||
|
||||
const AdBlockRule* AdBlockMatcher::match(const QNetworkRequest &request, const QString &urlDomain, const QString &urlString) const
|
||||
const AdBlockRule* AdBlockMatcher::match(const QWebEngineUrlRequestInfo &request, const QString &urlDomain, const QString &urlString) const
|
||||
{
|
||||
// Exception rules
|
||||
if (m_networkExceptionTree.find(request, urlDomain, urlString))
|
||||
|
@ -24,6 +24,8 @@
|
||||
#include "qzcommon.h"
|
||||
#include "adblocksearchtree.h"
|
||||
|
||||
class QWebEngineUrlRequestInfo;
|
||||
|
||||
class AdBlockManager;
|
||||
|
||||
class QUPZILLA_EXPORT AdBlockMatcher : public QObject
|
||||
@ -34,7 +36,7 @@ public:
|
||||
explicit AdBlockMatcher(AdBlockManager* manager);
|
||||
~AdBlockMatcher();
|
||||
|
||||
const AdBlockRule* match(const QNetworkRequest &request, const QString &urlDomain, const QString &urlString) const;
|
||||
const AdBlockRule* match(const QWebEngineUrlRequestInfo &request, const QString &urlDomain, const QString &urlString) const;
|
||||
|
||||
bool adBlockDisabledForUrl(const QUrl &url) const;
|
||||
bool elemHideDisabledForUrl(const QUrl &url) const;
|
||||
|
@ -52,11 +52,10 @@
|
||||
#include <QUrl>
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
#include <QNetworkRequest>
|
||||
#include <QWebEnginePage>
|
||||
#include <QWebEngineUrlRequestInfo>
|
||||
|
||||
// Version for Qt < 4.8 has one issue, it will wrongly
|
||||
// count .co.uk (and others) as second-level domain
|
||||
#if QTWEBENGINE_DISABLED
|
||||
static QString toSecondLevelDomain(const QUrl &url)
|
||||
{
|
||||
const QString topLevelDomain = url.topLevelDomain();
|
||||
@ -78,6 +77,7 @@ static QString toSecondLevelDomain(const QUrl &url)
|
||||
|
||||
return domain + topLevelDomain;
|
||||
}
|
||||
#endif
|
||||
|
||||
AdBlockRule::AdBlockRule(const QString &filter, AdBlockSubscription* subscription)
|
||||
: m_subscription(subscription)
|
||||
@ -203,36 +203,20 @@ bool AdBlockRule::urlMatch(const QUrl &url) const
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
const QString encodedUrl = url.toEncoded();
|
||||
const QString domain = url.host();
|
||||
|
||||
return networkMatch(QNetworkRequest(url), domain, encodedUrl);
|
||||
return stringMatch(domain, encodedUrl);
|
||||
}
|
||||
|
||||
bool AdBlockRule::networkMatch(const QNetworkRequest &request, const QString &domain, const QString &encodedUrl) const
|
||||
bool AdBlockRule::networkMatch(const QWebEngineUrlRequestInfo &request, const QString &domain, const QString &encodedUrl) const
|
||||
{
|
||||
if (m_type == CssRule || !m_isEnabled || m_isInternalDisabled) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool matched = false;
|
||||
|
||||
if (m_type == StringContainsMatchRule) {
|
||||
matched = encodedUrl.contains(m_matchString, m_caseSensitivity);
|
||||
}
|
||||
else if (m_type == DomainMatchRule) {
|
||||
matched = isMatchingDomain(domain, m_matchString);
|
||||
}
|
||||
else if (m_type == StringEndsMatchRule) {
|
||||
matched = encodedUrl.endsWith(m_matchString, m_caseSensitivity);
|
||||
}
|
||||
else if (m_type == RegExpMatchRule) {
|
||||
if (!isMatchingRegExpStrings(encodedUrl)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
matched = (m_regExp->regExp.indexIn(encodedUrl) != -1);
|
||||
}
|
||||
bool matched = stringMatch(domain, encodedUrl);
|
||||
|
||||
if (matched) {
|
||||
// Check domain restrictions
|
||||
@ -261,7 +245,7 @@ bool AdBlockRule::networkMatch(const QNetworkRequest &request, const QString &do
|
||||
}
|
||||
|
||||
// Check image restriction
|
||||
if (hasOption(ImageOption) && !matchImage(encodedUrl)) {
|
||||
if (hasOption(ImageOption) && !matchImage(request)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -311,8 +295,9 @@ bool AdBlockRule::matchDomain(const QString &domain) const
|
||||
return false;
|
||||
}
|
||||
|
||||
bool AdBlockRule::matchThirdParty(const QNetworkRequest &request) const
|
||||
bool AdBlockRule::matchThirdParty(const QWebEngineUrlRequestInfo &request) const
|
||||
{
|
||||
#if QTWEBENGINE_DISABLED
|
||||
const QString referer = request.attribute(QNetworkRequest::Attribute(QNetworkRequest::User + 151), QString()).toString();
|
||||
|
||||
if (referer.isEmpty()) {
|
||||
@ -326,50 +311,36 @@ bool AdBlockRule::matchThirdParty(const QNetworkRequest &request) const
|
||||
bool match = refererHost != host;
|
||||
|
||||
return hasException(ThirdPartyOption) ? !match : match;
|
||||
}
|
||||
|
||||
bool AdBlockRule::matchObject(const QNetworkRequest &request) const
|
||||
{
|
||||
bool match = request.attribute(QNetworkRequest::Attribute(QNetworkRequest::User + 150)).toString() == QL1S("object");
|
||||
|
||||
return hasException(ObjectOption) ? !match : match;
|
||||
}
|
||||
|
||||
bool AdBlockRule::matchSubdocument(const QNetworkRequest &request) const
|
||||
{
|
||||
Q_UNUSED(request)
|
||||
#if QTWEBENGINE_DISABLED
|
||||
QWebEngineFrame* originatingFrame = static_cast<QWebEngineFrame*>(request.originatingObject());
|
||||
if (!originatingFrame) {
|
||||
return false;
|
||||
}
|
||||
|
||||
QWebEnginePage* page = originatingFrame->page();
|
||||
if (!page) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool match = !(originatingFrame == page->mainFrame());
|
||||
|
||||
return hasException(SubdocumentOption) ? !match : match;
|
||||
#else
|
||||
Q_UNUSED(request)
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool AdBlockRule::matchXmlHttpRequest(const QNetworkRequest &request) const
|
||||
bool AdBlockRule::matchObject(const QWebEngineUrlRequestInfo &request) const
|
||||
{
|
||||
bool match = request.rawHeader("X-Requested-With") == QByteArray("XMLHttpRequest");
|
||||
bool match = request.resourceType() == QWebEngineUrlRequestInfo::ResourceTypeObject;
|
||||
|
||||
return hasException(ObjectOption) ? !match : match;
|
||||
}
|
||||
|
||||
bool AdBlockRule::matchSubdocument(const QWebEngineUrlRequestInfo &request) const
|
||||
{
|
||||
bool match = request.resourceType() == QWebEngineUrlRequestInfo::ResourceTypeSubFrame;
|
||||
|
||||
return hasException(SubdocumentOption) ? !match : match;
|
||||
}
|
||||
|
||||
bool AdBlockRule::matchXmlHttpRequest(const QWebEngineUrlRequestInfo &request) const
|
||||
{
|
||||
bool match = request.resourceType() == QWebEngineUrlRequestInfo::ResourceTypeXhr;
|
||||
|
||||
return hasException(XMLHttpRequestOption) ? !match : match;
|
||||
}
|
||||
|
||||
bool AdBlockRule::matchImage(const QString &encodedUrl) const
|
||||
bool AdBlockRule::matchImage(const QWebEngineUrlRequestInfo &request) const
|
||||
{
|
||||
bool match = encodedUrl.endsWith(QL1S(".png")) ||
|
||||
encodedUrl.endsWith(QL1S(".jpg")) ||
|
||||
encodedUrl.endsWith(QL1S(".gif")) ||
|
||||
encodedUrl.endsWith(QL1S(".jpeg"));
|
||||
bool match = request.resourceType() == QWebEngineUrlRequestInfo::ResourceTypeImage;
|
||||
|
||||
return hasException(ImageOption) ? !match : match;
|
||||
}
|
||||
@ -660,6 +631,27 @@ QList<QStringMatcher> AdBlockRule::createStringMatchers(const QStringList &filte
|
||||
return matchers;
|
||||
}
|
||||
|
||||
bool AdBlockRule::stringMatch(const QString &domain, const QString &encodedUrl) const
|
||||
{
|
||||
if (m_type == StringContainsMatchRule) {
|
||||
return encodedUrl.contains(m_matchString, m_caseSensitivity);
|
||||
}
|
||||
else if (m_type == DomainMatchRule) {
|
||||
return isMatchingDomain(domain, m_matchString);
|
||||
}
|
||||
else if (m_type == StringEndsMatchRule) {
|
||||
return encodedUrl.endsWith(m_matchString, m_caseSensitivity);
|
||||
}
|
||||
else if (m_type == RegExpMatchRule) {
|
||||
if (!isMatchingRegExpStrings(encodedUrl)) {
|
||||
return false;
|
||||
}
|
||||
return (m_regExp->regExp.indexIn(encodedUrl) != -1);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool AdBlockRule::isMatchingDomain(const QString &domain, const QString &filter) const
|
||||
{
|
||||
return QzTools::matchDomain(filter, domain);
|
||||
|
@ -53,8 +53,8 @@
|
||||
#include "qzcommon.h"
|
||||
#include "qzregexp.h"
|
||||
|
||||
class QNetworkRequest;
|
||||
class QUrl;
|
||||
class QWebEngineUrlRequestInfo;
|
||||
|
||||
class AdBlockSubscription;
|
||||
|
||||
@ -91,16 +91,17 @@ public:
|
||||
bool isInternalDisabled() const;
|
||||
|
||||
bool urlMatch(const QUrl &url) const;
|
||||
bool networkMatch(const QNetworkRequest &request, const QString &domain, const QString &encodedUrl) const;
|
||||
bool networkMatch(const QWebEngineUrlRequestInfo &request, const QString &domain, const QString &encodedUrl) const;
|
||||
|
||||
bool matchDomain(const QString &domain) const;
|
||||
bool matchThirdParty(const QNetworkRequest &request) const;
|
||||
bool matchObject(const QNetworkRequest &request) const;
|
||||
bool matchSubdocument(const QNetworkRequest &request) const;
|
||||
bool matchXmlHttpRequest(const QNetworkRequest &request) const;
|
||||
bool matchImage(const QString &encodedUrl) const;
|
||||
bool matchThirdParty(const QWebEngineUrlRequestInfo &request) const;
|
||||
bool matchObject(const QWebEngineUrlRequestInfo &request) const;
|
||||
bool matchSubdocument(const QWebEngineUrlRequestInfo &request) const;
|
||||
bool matchXmlHttpRequest(const QWebEngineUrlRequestInfo &request) const;
|
||||
bool matchImage(const QWebEngineUrlRequestInfo &request) const;
|
||||
|
||||
protected:
|
||||
bool stringMatch(const QString &domain, const QString &encodedUrl) const;
|
||||
bool isMatchingDomain(const QString &domain, const QString &filter) const;
|
||||
bool isMatchingRegExpStrings(const QString &url) const;
|
||||
QStringList parseRegExpFilter(const QString &filter) const;
|
||||
|
@ -18,6 +18,8 @@
|
||||
#include "adblocksearchtree.h"
|
||||
#include "adblockrule.h"
|
||||
|
||||
#include <QWebEngineUrlRequestInfo>
|
||||
|
||||
AdBlockSearchTree::AdBlockSearchTree()
|
||||
: m_root(new Node)
|
||||
{
|
||||
@ -67,7 +69,7 @@ bool AdBlockSearchTree::add(const AdBlockRule* rule)
|
||||
return true;
|
||||
}
|
||||
|
||||
const AdBlockRule* AdBlockSearchTree::find(const QNetworkRequest &request, const QString &domain, const QString &urlString) const
|
||||
const AdBlockRule* AdBlockSearchTree::find(const QWebEngineUrlRequestInfo &request, const QString &domain, const QString &urlString) const
|
||||
{
|
||||
int len = urlString.size();
|
||||
|
||||
@ -87,7 +89,7 @@ const AdBlockRule* AdBlockSearchTree::find(const QNetworkRequest &request, const
|
||||
return 0;
|
||||
}
|
||||
|
||||
const AdBlockRule* AdBlockSearchTree::prefixSearch(const QNetworkRequest &request, const QString &domain, const QString &urlString, const QChar* string, int len) const
|
||||
const AdBlockRule* AdBlockSearchTree::prefixSearch(const QWebEngineUrlRequestInfo &request, const QString &domain, const QString &urlString, const QChar* string, int len) const
|
||||
{
|
||||
if (len <= 0) {
|
||||
return 0;
|
||||
|
@ -23,7 +23,7 @@
|
||||
|
||||
#include "qzcommon.h"
|
||||
|
||||
class QNetworkRequest;
|
||||
class QWebEngineUrlRequestInfo;
|
||||
|
||||
class AdBlockRule;
|
||||
|
||||
@ -36,7 +36,7 @@ public:
|
||||
void clear();
|
||||
|
||||
bool add(const AdBlockRule* rule);
|
||||
const AdBlockRule* find(const QNetworkRequest &request, const QString &domain, const QString &urlString) const;
|
||||
const AdBlockRule* find(const QWebEngineUrlRequestInfo &request, const QString &domain, const QString &urlString) const;
|
||||
|
||||
private:
|
||||
struct Node {
|
||||
@ -47,7 +47,7 @@ private:
|
||||
Node() : c(0) , rule(0) { }
|
||||
};
|
||||
|
||||
const AdBlockRule* prefixSearch(const QNetworkRequest &request, const QString &domain,
|
||||
const AdBlockRule* prefixSearch(const QWebEngineUrlRequestInfo &request, const QString &domain,
|
||||
const QString &urlString, const QChar* string, int len) const;
|
||||
|
||||
void deleteNode(Node* node);
|
||||
|
31
src/lib/adblock/adblockurlinterceptor.cpp
Normal file
31
src/lib/adblock/adblockurlinterceptor.cpp
Normal file
@ -0,0 +1,31 @@
|
||||
/* ============================================================
|
||||
* QupZilla - QtWebEngine based browser
|
||||
* Copyright (C) 2015 David Rosca <nowrep@gmail.com>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
* ============================================================ */
|
||||
|
||||
#include "adblockurlinterceptor.h"
|
||||
#include "adblockmanager.h"
|
||||
|
||||
AdBlockUrlInterceptor::AdBlockUrlInterceptor(AdBlockManager *manager)
|
||||
: UrlInterceptor(manager)
|
||||
, m_manager(manager)
|
||||
{
|
||||
}
|
||||
|
||||
bool AdBlockUrlInterceptor::interceptRequest(QWebEngineUrlRequestInfo &info)
|
||||
{
|
||||
return m_manager->block(info);
|
||||
}
|
38
src/lib/adblock/adblockurlinterceptor.h
Normal file
38
src/lib/adblock/adblockurlinterceptor.h
Normal file
@ -0,0 +1,38 @@
|
||||
/* ============================================================
|
||||
* QupZilla - QtWebEngine based browser
|
||||
* Copyright (C) 2015 David Rosca <nowrep@gmail.com>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
* ============================================================ */
|
||||
|
||||
#ifndef ADBLOCKURLINTERCEPTOR_H
|
||||
#define ADBLOCKURLINTERCEPTOR_H
|
||||
|
||||
#include "urlinterceptor.h"
|
||||
#include "qzcommon.h"
|
||||
|
||||
class AdBlockManager;
|
||||
|
||||
class QUPZILLA_EXPORT AdBlockUrlInterceptor : public UrlInterceptor
|
||||
{
|
||||
public:
|
||||
explicit AdBlockUrlInterceptor(AdBlockManager* manager);
|
||||
|
||||
bool interceptRequest(QWebEngineUrlRequestInfo &info);
|
||||
|
||||
private:
|
||||
AdBlockManager *m_manager;
|
||||
};
|
||||
|
||||
#endif // ADBLOCKURLINTERCEPTOR_H
|
@ -54,7 +54,7 @@ SOURCES += \
|
||||
3rdparty/squeezelabelv2.cpp \
|
||||
3rdparty/stylehelper.cpp \
|
||||
adblock/adblockaddsubscriptiondialog.cpp \
|
||||
adblock/adblockblockednetworkreply.cpp \
|
||||
adblock/adblockurlinterceptor.cpp \
|
||||
adblock/adblockdialog.cpp \
|
||||
adblock/adblockicon.cpp \
|
||||
adblock/adblockmanager.cpp \
|
||||
@ -248,7 +248,7 @@ HEADERS += \
|
||||
3rdparty/squeezelabelv2.h \
|
||||
3rdparty/stylehelper.h \
|
||||
adblock/adblockaddsubscriptiondialog.h \
|
||||
adblock/adblockblockednetworkreply.h \
|
||||
adblock/adblockurlinterceptor.h \
|
||||
adblock/adblockdialog.h \
|
||||
adblock/adblockicon.h \
|
||||
adblock/adblockmanager.h \
|
||||
|
Loading…
Reference in New Issue
Block a user