2011-03-27 21:59:40 +02:00
|
|
|
/* ============================================================
|
|
|
|
* QupZilla - WebKit based browser
|
2014-01-11 16:11:42 +01:00
|
|
|
* Copyright (C) 2010-2014 David Rosca <nowrep@gmail.com>
|
2011-03-27 21:59:40 +02:00
|
|
|
*
|
|
|
|
* 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, Zsombor Gegesy <gzsombor@gmail.com>
|
|
|
|
* 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 "adblockrule.h"
|
|
|
|
#include "adblocksubscription.h"
|
2013-02-26 15:48:47 +01:00
|
|
|
#include "qztools.h"
|
2013-11-02 17:41:51 +01:00
|
|
|
#include "qzregexp.h"
|
2011-03-27 21:59:40 +02:00
|
|
|
|
2012-02-29 18:33:50 +01:00
|
|
|
#include <QUrl>
|
|
|
|
#include <QString>
|
|
|
|
#include <QStringList>
|
2015-01-27 11:01:52 +01:00
|
|
|
#include <QWebEnginePage>
|
2015-10-05 20:16:51 +02:00
|
|
|
#include <QWebEngineUrlRequestInfo>
|
2011-03-27 21:59:40 +02:00
|
|
|
|
2013-01-22 18:12:21 +01:00
|
|
|
static QString toSecondLevelDomain(const QUrl &url)
|
2012-06-28 01:41:01 +02:00
|
|
|
{
|
2013-12-30 13:43:48 +01:00
|
|
|
const QString topLevelDomain = url.topLevelDomain();
|
|
|
|
const QString urlHost = url.host();
|
2012-06-28 01:41:01 +02:00
|
|
|
|
|
|
|
if (topLevelDomain.isEmpty() || urlHost.isEmpty()) {
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
|
|
|
|
QString domain = urlHost.left(urlHost.size() - topLevelDomain.size());
|
|
|
|
|
[AdBlock] Improved performance of loading rules
Don't use regexps for parsing rules.
Added benchmark for loading subscriptions
Before:
********* Start testing of AdBlockParseRule *********
Config: Using QTest library 4.8.6, Qt 4.8.6
PASS : AdBlockParseRule::initTestCase()
RESULT : AdBlockParseRule::parseEasyList():
596.3 msecs per iteration (total: 2,982, iterations: 5)
PASS : AdBlockParseRule::parseEasyList()
PASS : AdBlockParseRule::cleanupTestCase()
Totals: 3 passed, 0 failed, 0 skipped
********* Finished testing of AdBlockParseRule *********
After:
********* Start testing of AdBlockParseRule *********
Config: Using QTest library 4.8.6, Qt 4.8.6
PASS : AdBlockParseRule::initTestCase()
RESULT : AdBlockParseRule::parseEasyList():
481.8 msecs per iteration (total: 2,409, iterations: 5)
PASS : AdBlockParseRule::parseEasyList()
PASS : AdBlockParseRule::cleanupTestCase()
Totals: 3 passed, 0 failed, 0 skipped
********* Finished testing of AdBlockParseRule *********
2014-04-06 13:34:01 +02:00
|
|
|
if (domain.count(QL1C('.')) == 0) {
|
2012-06-28 01:41:01 +02:00
|
|
|
return urlHost;
|
|
|
|
}
|
|
|
|
|
[AdBlock] Improved performance of loading rules
Don't use regexps for parsing rules.
Added benchmark for loading subscriptions
Before:
********* Start testing of AdBlockParseRule *********
Config: Using QTest library 4.8.6, Qt 4.8.6
PASS : AdBlockParseRule::initTestCase()
RESULT : AdBlockParseRule::parseEasyList():
596.3 msecs per iteration (total: 2,982, iterations: 5)
PASS : AdBlockParseRule::parseEasyList()
PASS : AdBlockParseRule::cleanupTestCase()
Totals: 3 passed, 0 failed, 0 skipped
********* Finished testing of AdBlockParseRule *********
After:
********* Start testing of AdBlockParseRule *********
Config: Using QTest library 4.8.6, Qt 4.8.6
PASS : AdBlockParseRule::initTestCase()
RESULT : AdBlockParseRule::parseEasyList():
481.8 msecs per iteration (total: 2,409, iterations: 5)
PASS : AdBlockParseRule::parseEasyList()
PASS : AdBlockParseRule::cleanupTestCase()
Totals: 3 passed, 0 failed, 0 skipped
********* Finished testing of AdBlockParseRule *********
2014-04-06 13:34:01 +02:00
|
|
|
while (domain.count(QL1C('.')) != 0) {
|
|
|
|
domain = domain.mid(domain.indexOf(QL1C('.')) + 1);
|
2012-06-28 01:41:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return domain + topLevelDomain;
|
|
|
|
}
|
2011-03-27 21:59:40 +02:00
|
|
|
|
2012-07-01 18:11:43 +02:00
|
|
|
AdBlockRule::AdBlockRule(const QString &filter, AdBlockSubscription* subscription)
|
|
|
|
: m_subscription(subscription)
|
2013-02-27 21:26:41 +01:00
|
|
|
, m_type(StringContainsMatchRule)
|
2012-06-25 16:07:25 +02:00
|
|
|
, m_caseSensitivity(Qt::CaseInsensitive)
|
2013-02-27 21:26:41 +01:00
|
|
|
, m_isEnabled(true)
|
|
|
|
, m_isException(false)
|
|
|
|
, m_isInternalDisabled(false)
|
|
|
|
, m_regExp(0)
|
2011-03-27 21:59:40 +02:00
|
|
|
{
|
|
|
|
setFilter(filter);
|
|
|
|
}
|
|
|
|
|
[AdBlock] Improved performance of loading rules
Don't use regexps for parsing rules.
Added benchmark for loading subscriptions
Before:
********* Start testing of AdBlockParseRule *********
Config: Using QTest library 4.8.6, Qt 4.8.6
PASS : AdBlockParseRule::initTestCase()
RESULT : AdBlockParseRule::parseEasyList():
596.3 msecs per iteration (total: 2,982, iterations: 5)
PASS : AdBlockParseRule::parseEasyList()
PASS : AdBlockParseRule::cleanupTestCase()
Totals: 3 passed, 0 failed, 0 skipped
********* Finished testing of AdBlockParseRule *********
After:
********* Start testing of AdBlockParseRule *********
Config: Using QTest library 4.8.6, Qt 4.8.6
PASS : AdBlockParseRule::initTestCase()
RESULT : AdBlockParseRule::parseEasyList():
481.8 msecs per iteration (total: 2,409, iterations: 5)
PASS : AdBlockParseRule::parseEasyList()
PASS : AdBlockParseRule::cleanupTestCase()
Totals: 3 passed, 0 failed, 0 skipped
********* Finished testing of AdBlockParseRule *********
2014-04-06 13:34:01 +02:00
|
|
|
AdBlockRule::~AdBlockRule()
|
|
|
|
{
|
|
|
|
delete m_regExp;
|
|
|
|
}
|
|
|
|
|
2014-09-16 10:38:28 +02:00
|
|
|
AdBlockRule* AdBlockRule::copy() const
|
|
|
|
{
|
|
|
|
AdBlockRule* rule = new AdBlockRule();
|
|
|
|
rule->m_subscription = m_subscription;
|
|
|
|
rule->m_type = m_type;
|
|
|
|
rule->m_options = m_options;
|
|
|
|
rule->m_exceptions = m_exceptions;
|
|
|
|
rule->m_filter = m_filter;
|
|
|
|
rule->m_matchString = m_matchString;
|
|
|
|
rule->m_caseSensitivity = m_caseSensitivity;
|
|
|
|
rule->m_isEnabled = m_isEnabled;
|
|
|
|
rule->m_isException = m_isException;
|
|
|
|
rule->m_isInternalDisabled = m_isInternalDisabled;
|
|
|
|
rule->m_allowedDomains = m_allowedDomains;
|
|
|
|
rule->m_blockedDomains = m_blockedDomains;
|
|
|
|
|
|
|
|
if (m_regExp) {
|
|
|
|
rule->m_regExp = new RegExp;
|
|
|
|
rule->m_regExp->regExp = m_regExp->regExp;
|
|
|
|
rule->m_regExp->matchers = m_regExp->matchers;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rule;
|
|
|
|
}
|
|
|
|
|
2012-07-01 18:11:43 +02:00
|
|
|
AdBlockSubscription* AdBlockRule::subscription() const
|
|
|
|
{
|
|
|
|
return m_subscription;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AdBlockRule::setSubscription(AdBlockSubscription* subscription)
|
|
|
|
{
|
|
|
|
m_subscription = subscription;
|
|
|
|
}
|
|
|
|
|
2011-03-27 21:59:40 +02:00
|
|
|
QString AdBlockRule::filter() const
|
|
|
|
{
|
|
|
|
return m_filter;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AdBlockRule::setFilter(const QString &filter)
|
|
|
|
{
|
|
|
|
m_filter = filter;
|
2012-06-25 16:07:25 +02:00
|
|
|
parseFilter();
|
2011-03-27 21:59:40 +02:00
|
|
|
}
|
|
|
|
|
2012-06-25 16:07:25 +02:00
|
|
|
bool AdBlockRule::isCssRule() const
|
2011-03-27 21:59:40 +02:00
|
|
|
{
|
2013-02-27 21:26:41 +01:00
|
|
|
return m_type == CssRule;
|
2012-06-25 16:07:25 +02:00
|
|
|
}
|
2011-03-27 21:59:40 +02:00
|
|
|
|
2012-06-25 16:07:25 +02:00
|
|
|
QString AdBlockRule::cssSelector() const
|
|
|
|
{
|
2014-03-12 13:25:12 +01:00
|
|
|
return m_matchString;
|
2011-03-27 21:59:40 +02:00
|
|
|
}
|
|
|
|
|
2012-07-04 16:00:53 +02:00
|
|
|
bool AdBlockRule::isDocument() const
|
|
|
|
{
|
2013-02-27 21:26:41 +01:00
|
|
|
return hasOption(DocumentOption);
|
2012-07-04 16:00:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool AdBlockRule::isElemhide() const
|
|
|
|
{
|
2013-02-27 21:26:41 +01:00
|
|
|
return hasOption(ElementHideOption);
|
2012-07-04 16:00:53 +02:00
|
|
|
}
|
|
|
|
|
2012-06-25 16:07:25 +02:00
|
|
|
bool AdBlockRule::isDomainRestricted() const
|
2011-03-27 21:59:40 +02:00
|
|
|
{
|
2013-02-27 21:26:41 +01:00
|
|
|
return hasOption(DomainRestrictedOption);
|
2011-03-27 21:59:40 +02:00
|
|
|
}
|
|
|
|
|
2012-06-25 16:07:25 +02:00
|
|
|
bool AdBlockRule::isException() const
|
2011-03-27 21:59:40 +02:00
|
|
|
{
|
2013-02-27 21:26:41 +01:00
|
|
|
return m_isException;
|
2011-03-27 21:59:40 +02:00
|
|
|
}
|
|
|
|
|
2012-07-01 20:11:37 +02:00
|
|
|
bool AdBlockRule::isComment() const
|
|
|
|
{
|
[AdBlock] Improved performance of loading rules
Don't use regexps for parsing rules.
Added benchmark for loading subscriptions
Before:
********* Start testing of AdBlockParseRule *********
Config: Using QTest library 4.8.6, Qt 4.8.6
PASS : AdBlockParseRule::initTestCase()
RESULT : AdBlockParseRule::parseEasyList():
596.3 msecs per iteration (total: 2,982, iterations: 5)
PASS : AdBlockParseRule::parseEasyList()
PASS : AdBlockParseRule::cleanupTestCase()
Totals: 3 passed, 0 failed, 0 skipped
********* Finished testing of AdBlockParseRule *********
After:
********* Start testing of AdBlockParseRule *********
Config: Using QTest library 4.8.6, Qt 4.8.6
PASS : AdBlockParseRule::initTestCase()
RESULT : AdBlockParseRule::parseEasyList():
481.8 msecs per iteration (total: 2,409, iterations: 5)
PASS : AdBlockParseRule::parseEasyList()
PASS : AdBlockParseRule::cleanupTestCase()
Totals: 3 passed, 0 failed, 0 skipped
********* Finished testing of AdBlockParseRule *********
2014-04-06 13:34:01 +02:00
|
|
|
return m_filter.startsWith(QL1C('!'));
|
2012-07-01 20:11:37 +02:00
|
|
|
}
|
|
|
|
|
2011-03-27 21:59:40 +02:00
|
|
|
bool AdBlockRule::isEnabled() const
|
|
|
|
{
|
2013-02-27 21:26:41 +01:00
|
|
|
return m_isEnabled;
|
2011-03-27 21:59:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void AdBlockRule::setEnabled(bool enabled)
|
|
|
|
{
|
2013-02-27 21:26:41 +01:00
|
|
|
m_isEnabled = enabled;
|
2011-03-27 21:59:40 +02:00
|
|
|
}
|
|
|
|
|
2012-07-01 14:44:01 +02:00
|
|
|
bool AdBlockRule::isSlow() const
|
|
|
|
{
|
2013-02-26 10:42:48 +01:00
|
|
|
return m_regExp != 0;
|
2012-07-01 14:44:01 +02:00
|
|
|
}
|
|
|
|
|
2012-06-25 16:07:25 +02:00
|
|
|
bool AdBlockRule::isInternalDisabled() const
|
2011-03-27 21:59:40 +02:00
|
|
|
{
|
2013-02-27 21:26:41 +01:00
|
|
|
return m_isInternalDisabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AdBlockRule::urlMatch(const QUrl &url) const
|
|
|
|
{
|
|
|
|
if (!hasOption(DocumentOption) && !hasOption(ElementHideOption)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-10-05 20:16:51 +02:00
|
|
|
|
2013-12-30 13:43:48 +01:00
|
|
|
const QString encodedUrl = url.toEncoded();
|
|
|
|
const QString domain = url.host();
|
2013-02-27 21:26:41 +01:00
|
|
|
|
2015-10-05 20:16:51 +02:00
|
|
|
return stringMatch(domain, encodedUrl);
|
2012-06-25 16:07:25 +02:00
|
|
|
}
|
|
|
|
|
2015-10-05 20:16:51 +02:00
|
|
|
bool AdBlockRule::networkMatch(const QWebEngineUrlRequestInfo &request, const QString &domain, const QString &encodedUrl) const
|
2012-06-25 16:07:25 +02:00
|
|
|
{
|
2013-02-27 21:26:41 +01:00
|
|
|
if (m_type == CssRule || !m_isEnabled || m_isInternalDisabled) {
|
2012-06-25 16:07:25 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-10-05 20:16:51 +02:00
|
|
|
bool matched = stringMatch(domain, encodedUrl);
|
2012-06-28 01:41:01 +02:00
|
|
|
|
|
|
|
if (matched) {
|
|
|
|
// Check domain restrictions
|
2015-10-09 13:16:24 +02:00
|
|
|
if (hasOption(DomainRestrictedOption) && !matchDomain(request.firstPartyUrl().host())) {
|
2012-06-28 01:41:01 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check third-party restriction
|
2013-02-27 21:26:41 +01:00
|
|
|
if (hasOption(ThirdPartyOption) && !matchThirdParty(request)) {
|
2012-06-28 01:41:01 +02:00
|
|
|
return false;
|
|
|
|
}
|
2012-07-01 12:07:00 +02:00
|
|
|
|
|
|
|
// Check object restrictions
|
2013-02-27 21:26:41 +01:00
|
|
|
if (hasOption(ObjectOption) && !matchObject(request)) {
|
2012-07-01 12:07:00 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check subdocument restriction
|
2013-02-27 21:26:41 +01:00
|
|
|
if (hasOption(SubdocumentOption) && !matchSubdocument(request)) {
|
2012-07-01 12:07:00 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check xmlhttprequest restriction
|
2013-02-27 21:26:41 +01:00
|
|
|
if (hasOption(XMLHttpRequestOption) && !matchXmlHttpRequest(request)) {
|
2012-07-01 12:07:00 +02:00
|
|
|
return false;
|
|
|
|
}
|
2013-02-07 11:04:09 +01:00
|
|
|
|
|
|
|
// Check image restriction
|
2015-10-05 20:16:51 +02:00
|
|
|
if (hasOption(ImageOption) && !matchImage(request)) {
|
2013-02-07 11:04:09 +01:00
|
|
|
return false;
|
|
|
|
}
|
2015-10-05 20:43:05 +02:00
|
|
|
|
|
|
|
// Check script restriction
|
|
|
|
if (hasOption(ScriptOption) && !matchScript(request)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check stylesheet restriction
|
|
|
|
if (hasOption(StyleSheetOption) && !matchStyleSheet(request)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check object-subrequest restriction
|
|
|
|
if (hasOption(ObjectSubrequestOption) && !matchObjectSubrequest(request)) {
|
|
|
|
return false;
|
|
|
|
}
|
2012-06-25 16:07:25 +02:00
|
|
|
}
|
|
|
|
|
2012-06-28 01:41:01 +02:00
|
|
|
return matched;
|
2011-03-27 21:59:40 +02:00
|
|
|
}
|
|
|
|
|
2012-06-25 16:07:25 +02:00
|
|
|
bool AdBlockRule::matchDomain(const QString &domain) const
|
2011-11-06 17:01:23 +01:00
|
|
|
{
|
2013-02-27 21:26:41 +01:00
|
|
|
if (!m_isEnabled) {
|
2012-07-04 17:53:49 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-02-27 21:26:41 +01:00
|
|
|
if (!hasOption(DomainRestrictedOption)) {
|
2012-06-25 16:07:25 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_blockedDomains.isEmpty()) {
|
2013-03-06 09:05:41 +01:00
|
|
|
foreach (const QString &d, m_allowedDomains) {
|
2013-02-26 15:48:47 +01:00
|
|
|
if (isMatchingDomain(domain, d)) {
|
2012-06-25 16:07:25 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (m_allowedDomains.isEmpty()) {
|
2013-03-06 09:05:41 +01:00
|
|
|
foreach (const QString &d, m_blockedDomains) {
|
2013-02-26 15:48:47 +01:00
|
|
|
if (isMatchingDomain(domain, d)) {
|
2012-06-25 16:07:25 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else {
|
2013-03-06 09:05:41 +01:00
|
|
|
foreach (const QString &d, m_blockedDomains) {
|
2013-02-26 15:48:47 +01:00
|
|
|
if (isMatchingDomain(domain, d)) {
|
2012-06-25 16:07:25 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-06 09:05:41 +01:00
|
|
|
foreach (const QString &d, m_allowedDomains) {
|
2013-02-26 15:48:47 +01:00
|
|
|
if (isMatchingDomain(domain, d)) {
|
2012-06-25 16:07:25 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2011-03-27 21:59:40 +02:00
|
|
|
}
|
|
|
|
|
2015-10-05 20:16:51 +02:00
|
|
|
bool AdBlockRule::matchThirdParty(const QWebEngineUrlRequestInfo &request) const
|
2012-06-28 01:41:01 +02:00
|
|
|
{
|
|
|
|
// Third-party matching should be performed on second-level domains
|
2015-10-09 13:16:24 +02:00
|
|
|
const QString firstPartyHost = toSecondLevelDomain(request.firstPartyUrl());
|
|
|
|
const QString host = toSecondLevelDomain(request.requestUrl());
|
2012-06-28 01:41:01 +02:00
|
|
|
|
2015-10-09 13:16:24 +02:00
|
|
|
bool match = firstPartyHost != host;
|
2012-07-01 12:07:00 +02:00
|
|
|
|
2013-02-27 21:26:41 +01:00
|
|
|
return hasException(ThirdPartyOption) ? !match : match;
|
2012-07-01 12:07:00 +02:00
|
|
|
}
|
|
|
|
|
2015-10-05 20:16:51 +02:00
|
|
|
bool AdBlockRule::matchObject(const QWebEngineUrlRequestInfo &request) const
|
2012-07-01 12:07:00 +02:00
|
|
|
{
|
2015-10-05 20:16:51 +02:00
|
|
|
bool match = request.resourceType() == QWebEngineUrlRequestInfo::ResourceTypeObject;
|
2012-07-01 12:07:00 +02:00
|
|
|
|
2013-02-27 21:26:41 +01:00
|
|
|
return hasException(ObjectOption) ? !match : match;
|
2012-07-01 12:07:00 +02:00
|
|
|
}
|
|
|
|
|
2015-10-05 20:16:51 +02:00
|
|
|
bool AdBlockRule::matchSubdocument(const QWebEngineUrlRequestInfo &request) const
|
2012-07-01 12:07:00 +02:00
|
|
|
{
|
2015-10-05 20:16:51 +02:00
|
|
|
bool match = request.resourceType() == QWebEngineUrlRequestInfo::ResourceTypeSubFrame;
|
2012-07-01 12:07:00 +02:00
|
|
|
|
2013-02-27 21:26:41 +01:00
|
|
|
return hasException(SubdocumentOption) ? !match : match;
|
2012-07-01 12:07:00 +02:00
|
|
|
}
|
|
|
|
|
2015-10-05 20:16:51 +02:00
|
|
|
bool AdBlockRule::matchXmlHttpRequest(const QWebEngineUrlRequestInfo &request) const
|
2012-07-01 12:07:00 +02:00
|
|
|
{
|
2015-10-05 20:16:51 +02:00
|
|
|
bool match = request.resourceType() == QWebEngineUrlRequestInfo::ResourceTypeXhr;
|
2012-07-01 12:07:00 +02:00
|
|
|
|
2013-02-27 21:26:41 +01:00
|
|
|
return hasException(XMLHttpRequestOption) ? !match : match;
|
2012-06-28 01:41:01 +02:00
|
|
|
}
|
|
|
|
|
2015-10-05 20:16:51 +02:00
|
|
|
bool AdBlockRule::matchImage(const QWebEngineUrlRequestInfo &request) const
|
2013-02-07 11:04:09 +01:00
|
|
|
{
|
2015-10-05 20:16:51 +02:00
|
|
|
bool match = request.resourceType() == QWebEngineUrlRequestInfo::ResourceTypeImage;
|
2013-02-07 11:04:09 +01:00
|
|
|
|
2013-02-27 21:26:41 +01:00
|
|
|
return hasException(ImageOption) ? !match : match;
|
2013-02-07 11:04:09 +01:00
|
|
|
}
|
|
|
|
|
2015-10-05 20:43:05 +02:00
|
|
|
bool AdBlockRule::matchScript(const QWebEngineUrlRequestInfo &request) const
|
|
|
|
{
|
|
|
|
bool match = request.resourceType() == QWebEngineUrlRequestInfo::ResourceTypeScript;
|
|
|
|
|
|
|
|
return hasException(ScriptOption) ? !match : match;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AdBlockRule::matchStyleSheet(const QWebEngineUrlRequestInfo &request) const
|
|
|
|
{
|
|
|
|
bool match = request.resourceType() == QWebEngineUrlRequestInfo::ResourceTypeStylesheet;
|
|
|
|
|
|
|
|
return hasException(StyleSheetOption) ? !match : match;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AdBlockRule::matchObjectSubrequest(const QWebEngineUrlRequestInfo &request) const
|
|
|
|
{
|
|
|
|
bool match = request.resourceType() == QWebEngineUrlRequestInfo::ResourceTypeSubResource;
|
|
|
|
|
|
|
|
return hasException(ObjectSubrequestOption) ? !match : match;
|
|
|
|
}
|
|
|
|
|
2012-06-25 16:07:25 +02:00
|
|
|
void AdBlockRule::parseFilter()
|
2011-03-27 21:59:40 +02:00
|
|
|
{
|
2012-06-25 16:07:25 +02:00
|
|
|
QString parsedLine = m_filter;
|
|
|
|
|
2012-07-01 20:11:37 +02:00
|
|
|
// Empty rule or just comment
|
[AdBlock] Improved performance of loading rules
Don't use regexps for parsing rules.
Added benchmark for loading subscriptions
Before:
********* Start testing of AdBlockParseRule *********
Config: Using QTest library 4.8.6, Qt 4.8.6
PASS : AdBlockParseRule::initTestCase()
RESULT : AdBlockParseRule::parseEasyList():
596.3 msecs per iteration (total: 2,982, iterations: 5)
PASS : AdBlockParseRule::parseEasyList()
PASS : AdBlockParseRule::cleanupTestCase()
Totals: 3 passed, 0 failed, 0 skipped
********* Finished testing of AdBlockParseRule *********
After:
********* Start testing of AdBlockParseRule *********
Config: Using QTest library 4.8.6, Qt 4.8.6
PASS : AdBlockParseRule::initTestCase()
RESULT : AdBlockParseRule::parseEasyList():
481.8 msecs per iteration (total: 2,409, iterations: 5)
PASS : AdBlockParseRule::parseEasyList()
PASS : AdBlockParseRule::cleanupTestCase()
Totals: 3 passed, 0 failed, 0 skipped
********* Finished testing of AdBlockParseRule *********
2014-04-06 13:34:01 +02:00
|
|
|
if (m_filter.trimmed().isEmpty() || m_filter.startsWith(QL1C('!'))) {
|
2013-11-04 16:03:11 +01:00
|
|
|
// We want to differentiate rule disabled by user and rule disabled in subscription file
|
|
|
|
// m_isInternalDisabled is also used when rule is disabled due to all options not being supported
|
2013-02-27 21:26:41 +01:00
|
|
|
m_isEnabled = false;
|
2013-11-04 16:03:11 +01:00
|
|
|
m_isInternalDisabled = true;
|
2013-11-02 17:41:51 +01:00
|
|
|
m_type = Invalid;
|
2012-06-25 16:07:25 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// CSS Element hiding rule
|
2014-09-16 00:35:32 +02:00
|
|
|
if (parsedLine.contains(QL1S("##")) || parsedLine.contains(QL1S("#@#"))) {
|
2013-02-27 21:26:41 +01:00
|
|
|
m_type = CssRule;
|
2014-09-16 00:35:32 +02:00
|
|
|
int pos = parsedLine.indexOf(QL1C('#'));
|
2012-06-25 16:07:25 +02:00
|
|
|
|
|
|
|
// Domain restricted rule
|
[AdBlock] Improved performance of loading rules
Don't use regexps for parsing rules.
Added benchmark for loading subscriptions
Before:
********* Start testing of AdBlockParseRule *********
Config: Using QTest library 4.8.6, Qt 4.8.6
PASS : AdBlockParseRule::initTestCase()
RESULT : AdBlockParseRule::parseEasyList():
596.3 msecs per iteration (total: 2,982, iterations: 5)
PASS : AdBlockParseRule::parseEasyList()
PASS : AdBlockParseRule::cleanupTestCase()
Totals: 3 passed, 0 failed, 0 skipped
********* Finished testing of AdBlockParseRule *********
After:
********* Start testing of AdBlockParseRule *********
Config: Using QTest library 4.8.6, Qt 4.8.6
PASS : AdBlockParseRule::initTestCase()
RESULT : AdBlockParseRule::parseEasyList():
481.8 msecs per iteration (total: 2,409, iterations: 5)
PASS : AdBlockParseRule::parseEasyList()
PASS : AdBlockParseRule::cleanupTestCase()
Totals: 3 passed, 0 failed, 0 skipped
********* Finished testing of AdBlockParseRule *********
2014-04-06 13:34:01 +02:00
|
|
|
if (!parsedLine.startsWith(QL1S("##"))) {
|
2012-07-01 18:11:43 +02:00
|
|
|
QString domains = parsedLine.left(pos);
|
[AdBlock] Improved performance of loading rules
Don't use regexps for parsing rules.
Added benchmark for loading subscriptions
Before:
********* Start testing of AdBlockParseRule *********
Config: Using QTest library 4.8.6, Qt 4.8.6
PASS : AdBlockParseRule::initTestCase()
RESULT : AdBlockParseRule::parseEasyList():
596.3 msecs per iteration (total: 2,982, iterations: 5)
PASS : AdBlockParseRule::parseEasyList()
PASS : AdBlockParseRule::cleanupTestCase()
Totals: 3 passed, 0 failed, 0 skipped
********* Finished testing of AdBlockParseRule *********
After:
********* Start testing of AdBlockParseRule *********
Config: Using QTest library 4.8.6, Qt 4.8.6
PASS : AdBlockParseRule::initTestCase()
RESULT : AdBlockParseRule::parseEasyList():
481.8 msecs per iteration (total: 2,409, iterations: 5)
PASS : AdBlockParseRule::parseEasyList()
PASS : AdBlockParseRule::cleanupTestCase()
Totals: 3 passed, 0 failed, 0 skipped
********* Finished testing of AdBlockParseRule *********
2014-04-06 13:34:01 +02:00
|
|
|
parseDomains(domains, QL1C(','));
|
2012-06-25 16:07:25 +02:00
|
|
|
}
|
|
|
|
|
2014-09-16 00:35:32 +02:00
|
|
|
m_isException = parsedLine.at(pos + 1) == QL1C('@');
|
|
|
|
m_matchString = parsedLine.mid(m_isException ? pos + 3 : pos + 2);
|
|
|
|
|
2012-06-25 16:07:25 +02:00
|
|
|
// CSS rule cannot have more options -> stop parsing
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Exception always starts with @@
|
[AdBlock] Improved performance of loading rules
Don't use regexps for parsing rules.
Added benchmark for loading subscriptions
Before:
********* Start testing of AdBlockParseRule *********
Config: Using QTest library 4.8.6, Qt 4.8.6
PASS : AdBlockParseRule::initTestCase()
RESULT : AdBlockParseRule::parseEasyList():
596.3 msecs per iteration (total: 2,982, iterations: 5)
PASS : AdBlockParseRule::parseEasyList()
PASS : AdBlockParseRule::cleanupTestCase()
Totals: 3 passed, 0 failed, 0 skipped
********* Finished testing of AdBlockParseRule *********
After:
********* Start testing of AdBlockParseRule *********
Config: Using QTest library 4.8.6, Qt 4.8.6
PASS : AdBlockParseRule::initTestCase()
RESULT : AdBlockParseRule::parseEasyList():
481.8 msecs per iteration (total: 2,409, iterations: 5)
PASS : AdBlockParseRule::parseEasyList()
PASS : AdBlockParseRule::cleanupTestCase()
Totals: 3 passed, 0 failed, 0 skipped
********* Finished testing of AdBlockParseRule *********
2014-04-06 13:34:01 +02:00
|
|
|
if (parsedLine.startsWith(QL1S("@@"))) {
|
2013-02-27 21:26:41 +01:00
|
|
|
m_isException = true;
|
2012-06-25 16:07:25 +02:00
|
|
|
parsedLine = parsedLine.mid(2);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Parse all options following $ char
|
[AdBlock] Improved performance of loading rules
Don't use regexps for parsing rules.
Added benchmark for loading subscriptions
Before:
********* Start testing of AdBlockParseRule *********
Config: Using QTest library 4.8.6, Qt 4.8.6
PASS : AdBlockParseRule::initTestCase()
RESULT : AdBlockParseRule::parseEasyList():
596.3 msecs per iteration (total: 2,982, iterations: 5)
PASS : AdBlockParseRule::parseEasyList()
PASS : AdBlockParseRule::cleanupTestCase()
Totals: 3 passed, 0 failed, 0 skipped
********* Finished testing of AdBlockParseRule *********
After:
********* Start testing of AdBlockParseRule *********
Config: Using QTest library 4.8.6, Qt 4.8.6
PASS : AdBlockParseRule::initTestCase()
RESULT : AdBlockParseRule::parseEasyList():
481.8 msecs per iteration (total: 2,409, iterations: 5)
PASS : AdBlockParseRule::parseEasyList()
PASS : AdBlockParseRule::cleanupTestCase()
Totals: 3 passed, 0 failed, 0 skipped
********* Finished testing of AdBlockParseRule *********
2014-04-06 13:34:01 +02:00
|
|
|
int optionsIndex = parsedLine.indexOf(QL1C('$'));
|
2012-06-25 16:07:25 +02:00
|
|
|
if (optionsIndex >= 0) {
|
[AdBlock] Improved performance of loading rules
Don't use regexps for parsing rules.
Added benchmark for loading subscriptions
Before:
********* Start testing of AdBlockParseRule *********
Config: Using QTest library 4.8.6, Qt 4.8.6
PASS : AdBlockParseRule::initTestCase()
RESULT : AdBlockParseRule::parseEasyList():
596.3 msecs per iteration (total: 2,982, iterations: 5)
PASS : AdBlockParseRule::parseEasyList()
PASS : AdBlockParseRule::cleanupTestCase()
Totals: 3 passed, 0 failed, 0 skipped
********* Finished testing of AdBlockParseRule *********
After:
********* Start testing of AdBlockParseRule *********
Config: Using QTest library 4.8.6, Qt 4.8.6
PASS : AdBlockParseRule::initTestCase()
RESULT : AdBlockParseRule::parseEasyList():
481.8 msecs per iteration (total: 2,409, iterations: 5)
PASS : AdBlockParseRule::parseEasyList()
PASS : AdBlockParseRule::cleanupTestCase()
Totals: 3 passed, 0 failed, 0 skipped
********* Finished testing of AdBlockParseRule *********
2014-04-06 13:34:01 +02:00
|
|
|
const QStringList options = parsedLine.mid(optionsIndex + 1).split(QL1C(','), QString::SkipEmptyParts);
|
2012-06-25 16:07:25 +02:00
|
|
|
|
|
|
|
int handledOptions = 0;
|
2013-03-06 09:05:41 +01:00
|
|
|
foreach (const QString &option, options) {
|
[AdBlock] Improved performance of loading rules
Don't use regexps for parsing rules.
Added benchmark for loading subscriptions
Before:
********* Start testing of AdBlockParseRule *********
Config: Using QTest library 4.8.6, Qt 4.8.6
PASS : AdBlockParseRule::initTestCase()
RESULT : AdBlockParseRule::parseEasyList():
596.3 msecs per iteration (total: 2,982, iterations: 5)
PASS : AdBlockParseRule::parseEasyList()
PASS : AdBlockParseRule::cleanupTestCase()
Totals: 3 passed, 0 failed, 0 skipped
********* Finished testing of AdBlockParseRule *********
After:
********* Start testing of AdBlockParseRule *********
Config: Using QTest library 4.8.6, Qt 4.8.6
PASS : AdBlockParseRule::initTestCase()
RESULT : AdBlockParseRule::parseEasyList():
481.8 msecs per iteration (total: 2,409, iterations: 5)
PASS : AdBlockParseRule::parseEasyList()
PASS : AdBlockParseRule::cleanupTestCase()
Totals: 3 passed, 0 failed, 0 skipped
********* Finished testing of AdBlockParseRule *********
2014-04-06 13:34:01 +02:00
|
|
|
if (option.startsWith(QL1S("domain="))) {
|
|
|
|
parseDomains(option.mid(7), QL1C('|'));
|
2012-06-25 16:07:25 +02:00
|
|
|
++handledOptions;
|
|
|
|
}
|
[AdBlock] Improved performance of loading rules
Don't use regexps for parsing rules.
Added benchmark for loading subscriptions
Before:
********* Start testing of AdBlockParseRule *********
Config: Using QTest library 4.8.6, Qt 4.8.6
PASS : AdBlockParseRule::initTestCase()
RESULT : AdBlockParseRule::parseEasyList():
596.3 msecs per iteration (total: 2,982, iterations: 5)
PASS : AdBlockParseRule::parseEasyList()
PASS : AdBlockParseRule::cleanupTestCase()
Totals: 3 passed, 0 failed, 0 skipped
********* Finished testing of AdBlockParseRule *********
After:
********* Start testing of AdBlockParseRule *********
Config: Using QTest library 4.8.6, Qt 4.8.6
PASS : AdBlockParseRule::initTestCase()
RESULT : AdBlockParseRule::parseEasyList():
481.8 msecs per iteration (total: 2,409, iterations: 5)
PASS : AdBlockParseRule::parseEasyList()
PASS : AdBlockParseRule::cleanupTestCase()
Totals: 3 passed, 0 failed, 0 skipped
********* Finished testing of AdBlockParseRule *********
2014-04-06 13:34:01 +02:00
|
|
|
else if (option == QL1S("match-case")) {
|
2012-06-25 16:07:25 +02:00
|
|
|
m_caseSensitivity = Qt::CaseSensitive;
|
|
|
|
++handledOptions;
|
|
|
|
}
|
[AdBlock] Improved performance of loading rules
Don't use regexps for parsing rules.
Added benchmark for loading subscriptions
Before:
********* Start testing of AdBlockParseRule *********
Config: Using QTest library 4.8.6, Qt 4.8.6
PASS : AdBlockParseRule::initTestCase()
RESULT : AdBlockParseRule::parseEasyList():
596.3 msecs per iteration (total: 2,982, iterations: 5)
PASS : AdBlockParseRule::parseEasyList()
PASS : AdBlockParseRule::cleanupTestCase()
Totals: 3 passed, 0 failed, 0 skipped
********* Finished testing of AdBlockParseRule *********
After:
********* Start testing of AdBlockParseRule *********
Config: Using QTest library 4.8.6, Qt 4.8.6
PASS : AdBlockParseRule::initTestCase()
RESULT : AdBlockParseRule::parseEasyList():
481.8 msecs per iteration (total: 2,409, iterations: 5)
PASS : AdBlockParseRule::parseEasyList()
PASS : AdBlockParseRule::cleanupTestCase()
Totals: 3 passed, 0 failed, 0 skipped
********* Finished testing of AdBlockParseRule *********
2014-04-06 13:34:01 +02:00
|
|
|
else if (option.endsWith(QL1S("third-party"))) {
|
2013-02-27 21:26:41 +01:00
|
|
|
setOption(ThirdPartyOption);
|
[AdBlock] Improved performance of loading rules
Don't use regexps for parsing rules.
Added benchmark for loading subscriptions
Before:
********* Start testing of AdBlockParseRule *********
Config: Using QTest library 4.8.6, Qt 4.8.6
PASS : AdBlockParseRule::initTestCase()
RESULT : AdBlockParseRule::parseEasyList():
596.3 msecs per iteration (total: 2,982, iterations: 5)
PASS : AdBlockParseRule::parseEasyList()
PASS : AdBlockParseRule::cleanupTestCase()
Totals: 3 passed, 0 failed, 0 skipped
********* Finished testing of AdBlockParseRule *********
After:
********* Start testing of AdBlockParseRule *********
Config: Using QTest library 4.8.6, Qt 4.8.6
PASS : AdBlockParseRule::initTestCase()
RESULT : AdBlockParseRule::parseEasyList():
481.8 msecs per iteration (total: 2,409, iterations: 5)
PASS : AdBlockParseRule::parseEasyList()
PASS : AdBlockParseRule::cleanupTestCase()
Totals: 3 passed, 0 failed, 0 skipped
********* Finished testing of AdBlockParseRule *********
2014-04-06 13:34:01 +02:00
|
|
|
setException(ThirdPartyOption, option.startsWith(QL1C('~')));
|
2012-06-25 16:07:25 +02:00
|
|
|
++handledOptions;
|
|
|
|
}
|
[AdBlock] Improved performance of loading rules
Don't use regexps for parsing rules.
Added benchmark for loading subscriptions
Before:
********* Start testing of AdBlockParseRule *********
Config: Using QTest library 4.8.6, Qt 4.8.6
PASS : AdBlockParseRule::initTestCase()
RESULT : AdBlockParseRule::parseEasyList():
596.3 msecs per iteration (total: 2,982, iterations: 5)
PASS : AdBlockParseRule::parseEasyList()
PASS : AdBlockParseRule::cleanupTestCase()
Totals: 3 passed, 0 failed, 0 skipped
********* Finished testing of AdBlockParseRule *********
After:
********* Start testing of AdBlockParseRule *********
Config: Using QTest library 4.8.6, Qt 4.8.6
PASS : AdBlockParseRule::initTestCase()
RESULT : AdBlockParseRule::parseEasyList():
481.8 msecs per iteration (total: 2,409, iterations: 5)
PASS : AdBlockParseRule::parseEasyList()
PASS : AdBlockParseRule::cleanupTestCase()
Totals: 3 passed, 0 failed, 0 skipped
********* Finished testing of AdBlockParseRule *********
2014-04-06 13:34:01 +02:00
|
|
|
else if (option.endsWith(QL1S("object"))) {
|
2013-02-27 21:26:41 +01:00
|
|
|
setOption(ObjectOption);
|
[AdBlock] Improved performance of loading rules
Don't use regexps for parsing rules.
Added benchmark for loading subscriptions
Before:
********* Start testing of AdBlockParseRule *********
Config: Using QTest library 4.8.6, Qt 4.8.6
PASS : AdBlockParseRule::initTestCase()
RESULT : AdBlockParseRule::parseEasyList():
596.3 msecs per iteration (total: 2,982, iterations: 5)
PASS : AdBlockParseRule::parseEasyList()
PASS : AdBlockParseRule::cleanupTestCase()
Totals: 3 passed, 0 failed, 0 skipped
********* Finished testing of AdBlockParseRule *********
After:
********* Start testing of AdBlockParseRule *********
Config: Using QTest library 4.8.6, Qt 4.8.6
PASS : AdBlockParseRule::initTestCase()
RESULT : AdBlockParseRule::parseEasyList():
481.8 msecs per iteration (total: 2,409, iterations: 5)
PASS : AdBlockParseRule::parseEasyList()
PASS : AdBlockParseRule::cleanupTestCase()
Totals: 3 passed, 0 failed, 0 skipped
********* Finished testing of AdBlockParseRule *********
2014-04-06 13:34:01 +02:00
|
|
|
setException(ObjectOption, option.startsWith(QL1C('~')));
|
2012-07-01 12:07:00 +02:00
|
|
|
++handledOptions;
|
|
|
|
}
|
[AdBlock] Improved performance of loading rules
Don't use regexps for parsing rules.
Added benchmark for loading subscriptions
Before:
********* Start testing of AdBlockParseRule *********
Config: Using QTest library 4.8.6, Qt 4.8.6
PASS : AdBlockParseRule::initTestCase()
RESULT : AdBlockParseRule::parseEasyList():
596.3 msecs per iteration (total: 2,982, iterations: 5)
PASS : AdBlockParseRule::parseEasyList()
PASS : AdBlockParseRule::cleanupTestCase()
Totals: 3 passed, 0 failed, 0 skipped
********* Finished testing of AdBlockParseRule *********
After:
********* Start testing of AdBlockParseRule *********
Config: Using QTest library 4.8.6, Qt 4.8.6
PASS : AdBlockParseRule::initTestCase()
RESULT : AdBlockParseRule::parseEasyList():
481.8 msecs per iteration (total: 2,409, iterations: 5)
PASS : AdBlockParseRule::parseEasyList()
PASS : AdBlockParseRule::cleanupTestCase()
Totals: 3 passed, 0 failed, 0 skipped
********* Finished testing of AdBlockParseRule *********
2014-04-06 13:34:01 +02:00
|
|
|
else if (option.endsWith(QL1S("subdocument"))) {
|
2013-02-27 21:26:41 +01:00
|
|
|
setOption(SubdocumentOption);
|
[AdBlock] Improved performance of loading rules
Don't use regexps for parsing rules.
Added benchmark for loading subscriptions
Before:
********* Start testing of AdBlockParseRule *********
Config: Using QTest library 4.8.6, Qt 4.8.6
PASS : AdBlockParseRule::initTestCase()
RESULT : AdBlockParseRule::parseEasyList():
596.3 msecs per iteration (total: 2,982, iterations: 5)
PASS : AdBlockParseRule::parseEasyList()
PASS : AdBlockParseRule::cleanupTestCase()
Totals: 3 passed, 0 failed, 0 skipped
********* Finished testing of AdBlockParseRule *********
After:
********* Start testing of AdBlockParseRule *********
Config: Using QTest library 4.8.6, Qt 4.8.6
PASS : AdBlockParseRule::initTestCase()
RESULT : AdBlockParseRule::parseEasyList():
481.8 msecs per iteration (total: 2,409, iterations: 5)
PASS : AdBlockParseRule::parseEasyList()
PASS : AdBlockParseRule::cleanupTestCase()
Totals: 3 passed, 0 failed, 0 skipped
********* Finished testing of AdBlockParseRule *********
2014-04-06 13:34:01 +02:00
|
|
|
setException(SubdocumentOption, option.startsWith(QL1C('~')));
|
2012-07-01 12:07:00 +02:00
|
|
|
++handledOptions;
|
|
|
|
}
|
[AdBlock] Improved performance of loading rules
Don't use regexps for parsing rules.
Added benchmark for loading subscriptions
Before:
********* Start testing of AdBlockParseRule *********
Config: Using QTest library 4.8.6, Qt 4.8.6
PASS : AdBlockParseRule::initTestCase()
RESULT : AdBlockParseRule::parseEasyList():
596.3 msecs per iteration (total: 2,982, iterations: 5)
PASS : AdBlockParseRule::parseEasyList()
PASS : AdBlockParseRule::cleanupTestCase()
Totals: 3 passed, 0 failed, 0 skipped
********* Finished testing of AdBlockParseRule *********
After:
********* Start testing of AdBlockParseRule *********
Config: Using QTest library 4.8.6, Qt 4.8.6
PASS : AdBlockParseRule::initTestCase()
RESULT : AdBlockParseRule::parseEasyList():
481.8 msecs per iteration (total: 2,409, iterations: 5)
PASS : AdBlockParseRule::parseEasyList()
PASS : AdBlockParseRule::cleanupTestCase()
Totals: 3 passed, 0 failed, 0 skipped
********* Finished testing of AdBlockParseRule *********
2014-04-06 13:34:01 +02:00
|
|
|
else if (option.endsWith(QL1S("xmlhttprequest"))) {
|
2013-02-27 21:26:41 +01:00
|
|
|
setOption(XMLHttpRequestOption);
|
[AdBlock] Improved performance of loading rules
Don't use regexps for parsing rules.
Added benchmark for loading subscriptions
Before:
********* Start testing of AdBlockParseRule *********
Config: Using QTest library 4.8.6, Qt 4.8.6
PASS : AdBlockParseRule::initTestCase()
RESULT : AdBlockParseRule::parseEasyList():
596.3 msecs per iteration (total: 2,982, iterations: 5)
PASS : AdBlockParseRule::parseEasyList()
PASS : AdBlockParseRule::cleanupTestCase()
Totals: 3 passed, 0 failed, 0 skipped
********* Finished testing of AdBlockParseRule *********
After:
********* Start testing of AdBlockParseRule *********
Config: Using QTest library 4.8.6, Qt 4.8.6
PASS : AdBlockParseRule::initTestCase()
RESULT : AdBlockParseRule::parseEasyList():
481.8 msecs per iteration (total: 2,409, iterations: 5)
PASS : AdBlockParseRule::parseEasyList()
PASS : AdBlockParseRule::cleanupTestCase()
Totals: 3 passed, 0 failed, 0 skipped
********* Finished testing of AdBlockParseRule *********
2014-04-06 13:34:01 +02:00
|
|
|
setException(XMLHttpRequestOption, option.startsWith(QL1C('~')));
|
2012-07-01 12:07:00 +02:00
|
|
|
++handledOptions;
|
|
|
|
}
|
[AdBlock] Improved performance of loading rules
Don't use regexps for parsing rules.
Added benchmark for loading subscriptions
Before:
********* Start testing of AdBlockParseRule *********
Config: Using QTest library 4.8.6, Qt 4.8.6
PASS : AdBlockParseRule::initTestCase()
RESULT : AdBlockParseRule::parseEasyList():
596.3 msecs per iteration (total: 2,982, iterations: 5)
PASS : AdBlockParseRule::parseEasyList()
PASS : AdBlockParseRule::cleanupTestCase()
Totals: 3 passed, 0 failed, 0 skipped
********* Finished testing of AdBlockParseRule *********
After:
********* Start testing of AdBlockParseRule *********
Config: Using QTest library 4.8.6, Qt 4.8.6
PASS : AdBlockParseRule::initTestCase()
RESULT : AdBlockParseRule::parseEasyList():
481.8 msecs per iteration (total: 2,409, iterations: 5)
PASS : AdBlockParseRule::parseEasyList()
PASS : AdBlockParseRule::cleanupTestCase()
Totals: 3 passed, 0 failed, 0 skipped
********* Finished testing of AdBlockParseRule *********
2014-04-06 13:34:01 +02:00
|
|
|
else if (option.endsWith(QL1S("image"))) {
|
2013-02-27 21:26:41 +01:00
|
|
|
setOption(ImageOption);
|
[AdBlock] Improved performance of loading rules
Don't use regexps for parsing rules.
Added benchmark for loading subscriptions
Before:
********* Start testing of AdBlockParseRule *********
Config: Using QTest library 4.8.6, Qt 4.8.6
PASS : AdBlockParseRule::initTestCase()
RESULT : AdBlockParseRule::parseEasyList():
596.3 msecs per iteration (total: 2,982, iterations: 5)
PASS : AdBlockParseRule::parseEasyList()
PASS : AdBlockParseRule::cleanupTestCase()
Totals: 3 passed, 0 failed, 0 skipped
********* Finished testing of AdBlockParseRule *********
After:
********* Start testing of AdBlockParseRule *********
Config: Using QTest library 4.8.6, Qt 4.8.6
PASS : AdBlockParseRule::initTestCase()
RESULT : AdBlockParseRule::parseEasyList():
481.8 msecs per iteration (total: 2,409, iterations: 5)
PASS : AdBlockParseRule::parseEasyList()
PASS : AdBlockParseRule::cleanupTestCase()
Totals: 3 passed, 0 failed, 0 skipped
********* Finished testing of AdBlockParseRule *********
2014-04-06 13:34:01 +02:00
|
|
|
setException(ImageOption, option.startsWith(QL1C('~')));
|
2013-02-07 11:04:09 +01:00
|
|
|
++handledOptions;
|
|
|
|
}
|
2015-10-05 20:43:05 +02:00
|
|
|
else if (option.endsWith(QL1S("script"))) {
|
|
|
|
setOption(ScriptOption);
|
|
|
|
setException(ScriptOption, option.startsWith(QL1C('~')));
|
|
|
|
++handledOptions;
|
|
|
|
}
|
|
|
|
else if (option.endsWith(QL1S("stylesheet"))) {
|
|
|
|
setOption(StyleSheetOption);
|
|
|
|
setException(StyleSheetOption, option.startsWith(QL1C('~')));
|
|
|
|
++handledOptions;
|
|
|
|
}
|
|
|
|
else if (option.endsWith(QL1S("object-subrequest"))) {
|
|
|
|
setOption(ObjectSubrequestOption);
|
|
|
|
setException(ObjectSubrequestOption, option.startsWith(QL1C('~')));
|
|
|
|
++handledOptions;
|
|
|
|
}
|
[AdBlock] Improved performance of loading rules
Don't use regexps for parsing rules.
Added benchmark for loading subscriptions
Before:
********* Start testing of AdBlockParseRule *********
Config: Using QTest library 4.8.6, Qt 4.8.6
PASS : AdBlockParseRule::initTestCase()
RESULT : AdBlockParseRule::parseEasyList():
596.3 msecs per iteration (total: 2,982, iterations: 5)
PASS : AdBlockParseRule::parseEasyList()
PASS : AdBlockParseRule::cleanupTestCase()
Totals: 3 passed, 0 failed, 0 skipped
********* Finished testing of AdBlockParseRule *********
After:
********* Start testing of AdBlockParseRule *********
Config: Using QTest library 4.8.6, Qt 4.8.6
PASS : AdBlockParseRule::initTestCase()
RESULT : AdBlockParseRule::parseEasyList():
481.8 msecs per iteration (total: 2,409, iterations: 5)
PASS : AdBlockParseRule::parseEasyList()
PASS : AdBlockParseRule::cleanupTestCase()
Totals: 3 passed, 0 failed, 0 skipped
********* Finished testing of AdBlockParseRule *********
2014-04-06 13:34:01 +02:00
|
|
|
else if (option == QL1S("document") && m_isException) {
|
2013-02-27 21:26:41 +01:00
|
|
|
setOption(DocumentOption);
|
2012-07-04 16:00:53 +02:00
|
|
|
++handledOptions;
|
|
|
|
}
|
[AdBlock] Improved performance of loading rules
Don't use regexps for parsing rules.
Added benchmark for loading subscriptions
Before:
********* Start testing of AdBlockParseRule *********
Config: Using QTest library 4.8.6, Qt 4.8.6
PASS : AdBlockParseRule::initTestCase()
RESULT : AdBlockParseRule::parseEasyList():
596.3 msecs per iteration (total: 2,982, iterations: 5)
PASS : AdBlockParseRule::parseEasyList()
PASS : AdBlockParseRule::cleanupTestCase()
Totals: 3 passed, 0 failed, 0 skipped
********* Finished testing of AdBlockParseRule *********
After:
********* Start testing of AdBlockParseRule *********
Config: Using QTest library 4.8.6, Qt 4.8.6
PASS : AdBlockParseRule::initTestCase()
RESULT : AdBlockParseRule::parseEasyList():
481.8 msecs per iteration (total: 2,409, iterations: 5)
PASS : AdBlockParseRule::parseEasyList()
PASS : AdBlockParseRule::cleanupTestCase()
Totals: 3 passed, 0 failed, 0 skipped
********* Finished testing of AdBlockParseRule *********
2014-04-06 13:34:01 +02:00
|
|
|
else if (option == QL1S("elemhide") && m_isException) {
|
2013-02-27 21:26:41 +01:00
|
|
|
setOption(ElementHideOption);
|
2012-07-04 16:00:53 +02:00
|
|
|
++handledOptions;
|
|
|
|
}
|
[AdBlock] Improved performance of loading rules
Don't use regexps for parsing rules.
Added benchmark for loading subscriptions
Before:
********* Start testing of AdBlockParseRule *********
Config: Using QTest library 4.8.6, Qt 4.8.6
PASS : AdBlockParseRule::initTestCase()
RESULT : AdBlockParseRule::parseEasyList():
596.3 msecs per iteration (total: 2,982, iterations: 5)
PASS : AdBlockParseRule::parseEasyList()
PASS : AdBlockParseRule::cleanupTestCase()
Totals: 3 passed, 0 failed, 0 skipped
********* Finished testing of AdBlockParseRule *********
After:
********* Start testing of AdBlockParseRule *********
Config: Using QTest library 4.8.6, Qt 4.8.6
PASS : AdBlockParseRule::initTestCase()
RESULT : AdBlockParseRule::parseEasyList():
481.8 msecs per iteration (total: 2,409, iterations: 5)
PASS : AdBlockParseRule::parseEasyList()
PASS : AdBlockParseRule::cleanupTestCase()
Totals: 3 passed, 0 failed, 0 skipped
********* Finished testing of AdBlockParseRule *********
2014-04-06 13:34:01 +02:00
|
|
|
else if (option == QL1S("collapse")) {
|
2013-02-27 21:26:41 +01:00
|
|
|
// Hiding placeholders of blocked elements is enabled by default
|
2012-07-04 10:08:55 +02:00
|
|
|
++handledOptions;
|
|
|
|
}
|
2012-06-25 16:07:25 +02:00
|
|
|
}
|
|
|
|
|
2012-07-01 12:07:00 +02:00
|
|
|
// If we don't handle all options, it's safer to just disable this rule
|
2012-06-25 16:07:25 +02:00
|
|
|
if (handledOptions != options.count()) {
|
2013-02-27 21:26:41 +01:00
|
|
|
m_isInternalDisabled = true;
|
2013-11-02 17:41:51 +01:00
|
|
|
m_type = Invalid;
|
2012-06-25 16:07:25 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
parsedLine = parsedLine.left(optionsIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Rule is classic regexp
|
[AdBlock] Improved performance of loading rules
Don't use regexps for parsing rules.
Added benchmark for loading subscriptions
Before:
********* Start testing of AdBlockParseRule *********
Config: Using QTest library 4.8.6, Qt 4.8.6
PASS : AdBlockParseRule::initTestCase()
RESULT : AdBlockParseRule::parseEasyList():
596.3 msecs per iteration (total: 2,982, iterations: 5)
PASS : AdBlockParseRule::parseEasyList()
PASS : AdBlockParseRule::cleanupTestCase()
Totals: 3 passed, 0 failed, 0 skipped
********* Finished testing of AdBlockParseRule *********
After:
********* Start testing of AdBlockParseRule *********
Config: Using QTest library 4.8.6, Qt 4.8.6
PASS : AdBlockParseRule::initTestCase()
RESULT : AdBlockParseRule::parseEasyList():
481.8 msecs per iteration (total: 2,409, iterations: 5)
PASS : AdBlockParseRule::parseEasyList()
PASS : AdBlockParseRule::cleanupTestCase()
Totals: 3 passed, 0 failed, 0 skipped
********* Finished testing of AdBlockParseRule *********
2014-04-06 13:34:01 +02:00
|
|
|
if (parsedLine.startsWith(QL1C('/')) && parsedLine.endsWith(QL1C('/'))) {
|
2012-06-25 16:07:25 +02:00
|
|
|
parsedLine = parsedLine.mid(1);
|
|
|
|
parsedLine = parsedLine.left(parsedLine.size() - 1);
|
|
|
|
|
2013-02-27 21:26:41 +01:00
|
|
|
m_type = RegExpMatchRule;
|
2014-03-12 13:25:12 +01:00
|
|
|
m_regExp = new RegExp;
|
|
|
|
m_regExp->regExp = QzRegExp(parsedLine, m_caseSensitivity);
|
2014-04-13 11:49:39 +02:00
|
|
|
m_regExp->matchers = createStringMatchers(parseRegExpFilter(parsedLine));
|
2012-06-25 16:07:25 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove starting and ending wildcards (*)
|
[AdBlock] Improved performance of loading rules
Don't use regexps for parsing rules.
Added benchmark for loading subscriptions
Before:
********* Start testing of AdBlockParseRule *********
Config: Using QTest library 4.8.6, Qt 4.8.6
PASS : AdBlockParseRule::initTestCase()
RESULT : AdBlockParseRule::parseEasyList():
596.3 msecs per iteration (total: 2,982, iterations: 5)
PASS : AdBlockParseRule::parseEasyList()
PASS : AdBlockParseRule::cleanupTestCase()
Totals: 3 passed, 0 failed, 0 skipped
********* Finished testing of AdBlockParseRule *********
After:
********* Start testing of AdBlockParseRule *********
Config: Using QTest library 4.8.6, Qt 4.8.6
PASS : AdBlockParseRule::initTestCase()
RESULT : AdBlockParseRule::parseEasyList():
481.8 msecs per iteration (total: 2,409, iterations: 5)
PASS : AdBlockParseRule::parseEasyList()
PASS : AdBlockParseRule::cleanupTestCase()
Totals: 3 passed, 0 failed, 0 skipped
********* Finished testing of AdBlockParseRule *********
2014-04-06 13:34:01 +02:00
|
|
|
if (parsedLine.startsWith(QL1C('*'))) {
|
2012-06-25 16:07:25 +02:00
|
|
|
parsedLine = parsedLine.mid(1);
|
|
|
|
}
|
|
|
|
|
[AdBlock] Improved performance of loading rules
Don't use regexps for parsing rules.
Added benchmark for loading subscriptions
Before:
********* Start testing of AdBlockParseRule *********
Config: Using QTest library 4.8.6, Qt 4.8.6
PASS : AdBlockParseRule::initTestCase()
RESULT : AdBlockParseRule::parseEasyList():
596.3 msecs per iteration (total: 2,982, iterations: 5)
PASS : AdBlockParseRule::parseEasyList()
PASS : AdBlockParseRule::cleanupTestCase()
Totals: 3 passed, 0 failed, 0 skipped
********* Finished testing of AdBlockParseRule *********
After:
********* Start testing of AdBlockParseRule *********
Config: Using QTest library 4.8.6, Qt 4.8.6
PASS : AdBlockParseRule::initTestCase()
RESULT : AdBlockParseRule::parseEasyList():
481.8 msecs per iteration (total: 2,409, iterations: 5)
PASS : AdBlockParseRule::parseEasyList()
PASS : AdBlockParseRule::cleanupTestCase()
Totals: 3 passed, 0 failed, 0 skipped
********* Finished testing of AdBlockParseRule *********
2014-04-06 13:34:01 +02:00
|
|
|
if (parsedLine.endsWith(QL1C('*'))) {
|
2012-06-25 16:07:25 +02:00
|
|
|
parsedLine = parsedLine.left(parsedLine.size() - 1);
|
|
|
|
}
|
|
|
|
|
2012-07-01 14:44:01 +02:00
|
|
|
// We can use fast string matching for domain here
|
[AdBlock] Improved performance of loading rules
Don't use regexps for parsing rules.
Added benchmark for loading subscriptions
Before:
********* Start testing of AdBlockParseRule *********
Config: Using QTest library 4.8.6, Qt 4.8.6
PASS : AdBlockParseRule::initTestCase()
RESULT : AdBlockParseRule::parseEasyList():
596.3 msecs per iteration (total: 2,982, iterations: 5)
PASS : AdBlockParseRule::parseEasyList()
PASS : AdBlockParseRule::cleanupTestCase()
Totals: 3 passed, 0 failed, 0 skipped
********* Finished testing of AdBlockParseRule *********
After:
********* Start testing of AdBlockParseRule *********
Config: Using QTest library 4.8.6, Qt 4.8.6
PASS : AdBlockParseRule::initTestCase()
RESULT : AdBlockParseRule::parseEasyList():
481.8 msecs per iteration (total: 2,409, iterations: 5)
PASS : AdBlockParseRule::parseEasyList()
PASS : AdBlockParseRule::cleanupTestCase()
Totals: 3 passed, 0 failed, 0 skipped
********* Finished testing of AdBlockParseRule *********
2014-04-06 13:34:01 +02:00
|
|
|
if (filterIsOnlyDomain(parsedLine)) {
|
2012-07-01 14:44:01 +02:00
|
|
|
parsedLine = parsedLine.mid(2);
|
|
|
|
parsedLine = parsedLine.left(parsedLine.size() - 1);
|
|
|
|
|
2013-02-27 21:26:41 +01:00
|
|
|
m_type = DomainMatchRule;
|
2012-07-01 14:44:01 +02:00
|
|
|
m_matchString = parsedLine;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If rule contains only | at end, we can also use string matching
|
[AdBlock] Improved performance of loading rules
Don't use regexps for parsing rules.
Added benchmark for loading subscriptions
Before:
********* Start testing of AdBlockParseRule *********
Config: Using QTest library 4.8.6, Qt 4.8.6
PASS : AdBlockParseRule::initTestCase()
RESULT : AdBlockParseRule::parseEasyList():
596.3 msecs per iteration (total: 2,982, iterations: 5)
PASS : AdBlockParseRule::parseEasyList()
PASS : AdBlockParseRule::cleanupTestCase()
Totals: 3 passed, 0 failed, 0 skipped
********* Finished testing of AdBlockParseRule *********
After:
********* Start testing of AdBlockParseRule *********
Config: Using QTest library 4.8.6, Qt 4.8.6
PASS : AdBlockParseRule::initTestCase()
RESULT : AdBlockParseRule::parseEasyList():
481.8 msecs per iteration (total: 2,409, iterations: 5)
PASS : AdBlockParseRule::parseEasyList()
PASS : AdBlockParseRule::cleanupTestCase()
Totals: 3 passed, 0 failed, 0 skipped
********* Finished testing of AdBlockParseRule *********
2014-04-06 13:34:01 +02:00
|
|
|
if (filterIsOnlyEndsMatch(parsedLine)) {
|
2012-07-01 14:44:01 +02:00
|
|
|
parsedLine = parsedLine.left(parsedLine.size() - 1);
|
|
|
|
|
2013-02-27 21:26:41 +01:00
|
|
|
m_type = StringEndsMatchRule;
|
2012-07-01 14:44:01 +02:00
|
|
|
m_matchString = parsedLine;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-06-28 01:41:01 +02:00
|
|
|
// If we still find a wildcard (*) or separator (^) or (|)
|
2013-02-24 10:57:58 +01:00
|
|
|
// we must modify parsedLine to comply with QzRegExp
|
[AdBlock] Improved performance of loading rules
Don't use regexps for parsing rules.
Added benchmark for loading subscriptions
Before:
********* Start testing of AdBlockParseRule *********
Config: Using QTest library 4.8.6, Qt 4.8.6
PASS : AdBlockParseRule::initTestCase()
RESULT : AdBlockParseRule::parseEasyList():
596.3 msecs per iteration (total: 2,982, iterations: 5)
PASS : AdBlockParseRule::parseEasyList()
PASS : AdBlockParseRule::cleanupTestCase()
Totals: 3 passed, 0 failed, 0 skipped
********* Finished testing of AdBlockParseRule *********
After:
********* Start testing of AdBlockParseRule *********
Config: Using QTest library 4.8.6, Qt 4.8.6
PASS : AdBlockParseRule::initTestCase()
RESULT : AdBlockParseRule::parseEasyList():
481.8 msecs per iteration (total: 2,409, iterations: 5)
PASS : AdBlockParseRule::parseEasyList()
PASS : AdBlockParseRule::cleanupTestCase()
Totals: 3 passed, 0 failed, 0 skipped
********* Finished testing of AdBlockParseRule *********
2014-04-06 13:34:01 +02:00
|
|
|
if (parsedLine.contains(QL1C('*')) ||
|
|
|
|
parsedLine.contains(QL1C('^')) ||
|
|
|
|
parsedLine.contains(QL1C('|'))
|
2014-04-05 14:42:19 +02:00
|
|
|
) {
|
2013-02-27 21:26:41 +01:00
|
|
|
m_type = RegExpMatchRule;
|
2014-03-12 13:25:12 +01:00
|
|
|
m_regExp = new RegExp;
|
[AdBlock] Improved performance of loading rules
Don't use regexps for parsing rules.
Added benchmark for loading subscriptions
Before:
********* Start testing of AdBlockParseRule *********
Config: Using QTest library 4.8.6, Qt 4.8.6
PASS : AdBlockParseRule::initTestCase()
RESULT : AdBlockParseRule::parseEasyList():
596.3 msecs per iteration (total: 2,982, iterations: 5)
PASS : AdBlockParseRule::parseEasyList()
PASS : AdBlockParseRule::cleanupTestCase()
Totals: 3 passed, 0 failed, 0 skipped
********* Finished testing of AdBlockParseRule *********
After:
********* Start testing of AdBlockParseRule *********
Config: Using QTest library 4.8.6, Qt 4.8.6
PASS : AdBlockParseRule::initTestCase()
RESULT : AdBlockParseRule::parseEasyList():
481.8 msecs per iteration (total: 2,409, iterations: 5)
PASS : AdBlockParseRule::parseEasyList()
PASS : AdBlockParseRule::cleanupTestCase()
Totals: 3 passed, 0 failed, 0 skipped
********* Finished testing of AdBlockParseRule *********
2014-04-06 13:34:01 +02:00
|
|
|
m_regExp->regExp = QzRegExp(createRegExpFromFilter(parsedLine), m_caseSensitivity);
|
2014-04-13 11:49:39 +02:00
|
|
|
m_regExp->matchers = createStringMatchers(parseRegExpFilter(parsedLine));
|
2012-06-25 16:07:25 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We haven't found anything that needs use of regexp, yay!
|
2013-02-27 21:26:41 +01:00
|
|
|
m_type = StringContainsMatchRule;
|
2012-06-25 16:07:25 +02:00
|
|
|
m_matchString = parsedLine;
|
2011-03-27 21:59:40 +02:00
|
|
|
}
|
|
|
|
|
2012-06-25 16:07:25 +02:00
|
|
|
void AdBlockRule::parseDomains(const QString &domains, const QChar &separator)
|
|
|
|
{
|
2013-02-15 12:36:25 +01:00
|
|
|
QStringList domainsList = domains.split(separator, QString::SkipEmptyParts);
|
2012-06-25 16:07:25 +02:00
|
|
|
|
2013-03-06 09:05:41 +01:00
|
|
|
foreach (const QString domain, domainsList) {
|
2012-06-25 16:07:25 +02:00
|
|
|
if (domain.isEmpty()) {
|
|
|
|
continue;
|
|
|
|
}
|
[AdBlock] Improved performance of loading rules
Don't use regexps for parsing rules.
Added benchmark for loading subscriptions
Before:
********* Start testing of AdBlockParseRule *********
Config: Using QTest library 4.8.6, Qt 4.8.6
PASS : AdBlockParseRule::initTestCase()
RESULT : AdBlockParseRule::parseEasyList():
596.3 msecs per iteration (total: 2,982, iterations: 5)
PASS : AdBlockParseRule::parseEasyList()
PASS : AdBlockParseRule::cleanupTestCase()
Totals: 3 passed, 0 failed, 0 skipped
********* Finished testing of AdBlockParseRule *********
After:
********* Start testing of AdBlockParseRule *********
Config: Using QTest library 4.8.6, Qt 4.8.6
PASS : AdBlockParseRule::initTestCase()
RESULT : AdBlockParseRule::parseEasyList():
481.8 msecs per iteration (total: 2,409, iterations: 5)
PASS : AdBlockParseRule::parseEasyList()
PASS : AdBlockParseRule::cleanupTestCase()
Totals: 3 passed, 0 failed, 0 skipped
********* Finished testing of AdBlockParseRule *********
2014-04-06 13:34:01 +02:00
|
|
|
if (domain.startsWith(QL1C('~'))) {
|
2012-06-25 16:07:25 +02:00
|
|
|
m_blockedDomains.append(domain.mid(1));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
m_allowedDomains.append(domain);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-27 21:26:41 +01:00
|
|
|
if (!m_blockedDomains.isEmpty() || !m_allowedDomains.isEmpty()) {
|
|
|
|
setOption(DomainRestrictedOption);
|
|
|
|
}
|
2012-06-25 16:07:25 +02:00
|
|
|
}
|
2012-09-01 11:41:12 +02:00
|
|
|
|
[AdBlock] Improved performance of loading rules
Don't use regexps for parsing rules.
Added benchmark for loading subscriptions
Before:
********* Start testing of AdBlockParseRule *********
Config: Using QTest library 4.8.6, Qt 4.8.6
PASS : AdBlockParseRule::initTestCase()
RESULT : AdBlockParseRule::parseEasyList():
596.3 msecs per iteration (total: 2,982, iterations: 5)
PASS : AdBlockParseRule::parseEasyList()
PASS : AdBlockParseRule::cleanupTestCase()
Totals: 3 passed, 0 failed, 0 skipped
********* Finished testing of AdBlockParseRule *********
After:
********* Start testing of AdBlockParseRule *********
Config: Using QTest library 4.8.6, Qt 4.8.6
PASS : AdBlockParseRule::initTestCase()
RESULT : AdBlockParseRule::parseEasyList():
481.8 msecs per iteration (total: 2,409, iterations: 5)
PASS : AdBlockParseRule::parseEasyList()
PASS : AdBlockParseRule::cleanupTestCase()
Totals: 3 passed, 0 failed, 0 skipped
********* Finished testing of AdBlockParseRule *********
2014-04-06 13:34:01 +02:00
|
|
|
bool AdBlockRule::filterIsOnlyDomain(const QString &filter) const
|
|
|
|
{
|
|
|
|
if (!filter.endsWith(QL1C('^')) || !filter.startsWith(QL1S("||")))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
for (int i = 0; i < filter.size(); ++i) {
|
2014-04-06 13:50:09 +02:00
|
|
|
switch (filter.at(i).toLatin1()) {
|
[AdBlock] Improved performance of loading rules
Don't use regexps for parsing rules.
Added benchmark for loading subscriptions
Before:
********* Start testing of AdBlockParseRule *********
Config: Using QTest library 4.8.6, Qt 4.8.6
PASS : AdBlockParseRule::initTestCase()
RESULT : AdBlockParseRule::parseEasyList():
596.3 msecs per iteration (total: 2,982, iterations: 5)
PASS : AdBlockParseRule::parseEasyList()
PASS : AdBlockParseRule::cleanupTestCase()
Totals: 3 passed, 0 failed, 0 skipped
********* Finished testing of AdBlockParseRule *********
After:
********* Start testing of AdBlockParseRule *********
Config: Using QTest library 4.8.6, Qt 4.8.6
PASS : AdBlockParseRule::initTestCase()
RESULT : AdBlockParseRule::parseEasyList():
481.8 msecs per iteration (total: 2,409, iterations: 5)
PASS : AdBlockParseRule::parseEasyList()
PASS : AdBlockParseRule::cleanupTestCase()
Totals: 3 passed, 0 failed, 0 skipped
********* Finished testing of AdBlockParseRule *********
2014-04-06 13:34:01 +02:00
|
|
|
case '/':
|
|
|
|
case ':':
|
|
|
|
case '?':
|
|
|
|
case '=':
|
|
|
|
case '&':
|
|
|
|
case '*':
|
|
|
|
return false;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AdBlockRule::filterIsOnlyEndsMatch(const QString &filter) const
|
|
|
|
{
|
|
|
|
for (int i = 0; i < filter.size(); ++i) {
|
2014-04-06 13:50:09 +02:00
|
|
|
switch (filter.at(i).toLatin1()) {
|
[AdBlock] Improved performance of loading rules
Don't use regexps for parsing rules.
Added benchmark for loading subscriptions
Before:
********* Start testing of AdBlockParseRule *********
Config: Using QTest library 4.8.6, Qt 4.8.6
PASS : AdBlockParseRule::initTestCase()
RESULT : AdBlockParseRule::parseEasyList():
596.3 msecs per iteration (total: 2,982, iterations: 5)
PASS : AdBlockParseRule::parseEasyList()
PASS : AdBlockParseRule::cleanupTestCase()
Totals: 3 passed, 0 failed, 0 skipped
********* Finished testing of AdBlockParseRule *********
After:
********* Start testing of AdBlockParseRule *********
Config: Using QTest library 4.8.6, Qt 4.8.6
PASS : AdBlockParseRule::initTestCase()
RESULT : AdBlockParseRule::parseEasyList():
481.8 msecs per iteration (total: 2,409, iterations: 5)
PASS : AdBlockParseRule::parseEasyList()
PASS : AdBlockParseRule::cleanupTestCase()
Totals: 3 passed, 0 failed, 0 skipped
********* Finished testing of AdBlockParseRule *********
2014-04-06 13:34:01 +02:00
|
|
|
case '^':
|
|
|
|
case '*':
|
|
|
|
return false;
|
|
|
|
case '|':
|
|
|
|
return i == filter.size() - 1;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool wordCharacter(const QChar &c)
|
|
|
|
{
|
|
|
|
return c.isLetterOrNumber() || c.isMark() || c == QL1C('_');
|
|
|
|
}
|
|
|
|
|
|
|
|
QString AdBlockRule::createRegExpFromFilter(const QString &filter) const
|
|
|
|
{
|
|
|
|
QString parsed;
|
|
|
|
parsed.reserve(filter.size());
|
|
|
|
|
|
|
|
bool hadWildcard = false; // Filter multiple wildcards
|
|
|
|
|
|
|
|
for (int i = 0; i < filter.size(); ++i) {
|
|
|
|
const QChar c = filter.at(i);
|
2014-04-06 13:50:09 +02:00
|
|
|
switch (c.toLatin1()) {
|
[AdBlock] Improved performance of loading rules
Don't use regexps for parsing rules.
Added benchmark for loading subscriptions
Before:
********* Start testing of AdBlockParseRule *********
Config: Using QTest library 4.8.6, Qt 4.8.6
PASS : AdBlockParseRule::initTestCase()
RESULT : AdBlockParseRule::parseEasyList():
596.3 msecs per iteration (total: 2,982, iterations: 5)
PASS : AdBlockParseRule::parseEasyList()
PASS : AdBlockParseRule::cleanupTestCase()
Totals: 3 passed, 0 failed, 0 skipped
********* Finished testing of AdBlockParseRule *********
After:
********* Start testing of AdBlockParseRule *********
Config: Using QTest library 4.8.6, Qt 4.8.6
PASS : AdBlockParseRule::initTestCase()
RESULT : AdBlockParseRule::parseEasyList():
481.8 msecs per iteration (total: 2,409, iterations: 5)
PASS : AdBlockParseRule::parseEasyList()
PASS : AdBlockParseRule::cleanupTestCase()
Totals: 3 passed, 0 failed, 0 skipped
********* Finished testing of AdBlockParseRule *********
2014-04-06 13:34:01 +02:00
|
|
|
case '^':
|
|
|
|
parsed.append(QL1S("(?:[^\\w\\d\\-.%]|$)"));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case '*':
|
|
|
|
if (!hadWildcard)
|
|
|
|
parsed.append(QL1S(".*"));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case '|':
|
|
|
|
if (i == 0) {
|
|
|
|
if (filter.size() > 1 && filter.at(1) == QL1C('|')) {
|
|
|
|
parsed.append(QL1S("^[\\w\\-]+:\\/+(?!\\/)(?:[^\\/]+\\.)?"));
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
parsed.append('^');
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if (i == filter.size() - 1) {
|
|
|
|
parsed.append(QL1C('$'));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// fallthrough
|
|
|
|
|
|
|
|
default:
|
|
|
|
if (!wordCharacter(c))
|
|
|
|
parsed.append(QL1C('\\') + c);
|
|
|
|
else
|
|
|
|
parsed.append(c);
|
|
|
|
}
|
|
|
|
|
|
|
|
hadWildcard = c == QL1C('*');
|
|
|
|
}
|
|
|
|
|
|
|
|
return parsed;
|
|
|
|
}
|
|
|
|
|
2014-04-13 11:49:39 +02:00
|
|
|
QList<QStringMatcher> AdBlockRule::createStringMatchers(const QStringList &filters) const
|
|
|
|
{
|
|
|
|
QList<QStringMatcher> matchers;
|
|
|
|
matchers.reserve(filters.size());
|
|
|
|
|
|
|
|
foreach (const QString &filter, filters) {
|
|
|
|
matchers.append(QStringMatcher(filter, m_caseSensitivity));
|
|
|
|
}
|
|
|
|
|
|
|
|
return matchers;
|
|
|
|
}
|
|
|
|
|
2015-10-05 20:16:51 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2013-02-26 15:48:47 +01:00
|
|
|
bool AdBlockRule::isMatchingDomain(const QString &domain, const QString &filter) const
|
2012-09-01 11:41:12 +02:00
|
|
|
{
|
2013-02-26 15:48:47 +01:00
|
|
|
return QzTools::matchDomain(filter, domain);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AdBlockRule::isMatchingRegExpStrings(const QString &url) const
|
|
|
|
{
|
2014-03-12 13:25:12 +01:00
|
|
|
Q_ASSERT(m_regExp);
|
|
|
|
|
2014-04-13 11:49:39 +02:00
|
|
|
foreach (const QStringMatcher &matcher, m_regExp->matchers) {
|
|
|
|
if (matcher.indexIn(url) == -1)
|
2013-02-26 15:48:47 +01:00
|
|
|
return false;
|
2012-09-01 11:41:12 +02:00
|
|
|
}
|
|
|
|
|
2013-02-26 15:48:47 +01:00
|
|
|
return true;
|
|
|
|
}
|
2012-09-01 11:41:12 +02:00
|
|
|
|
2013-02-26 15:48:47 +01:00
|
|
|
// Split regexp filter into strings that can be used with QString::contains
|
|
|
|
// Don't use parts that contains only 1 char and duplicated parts
|
[AdBlock] Improved performance of loading rules
Don't use regexps for parsing rules.
Added benchmark for loading subscriptions
Before:
********* Start testing of AdBlockParseRule *********
Config: Using QTest library 4.8.6, Qt 4.8.6
PASS : AdBlockParseRule::initTestCase()
RESULT : AdBlockParseRule::parseEasyList():
596.3 msecs per iteration (total: 2,982, iterations: 5)
PASS : AdBlockParseRule::parseEasyList()
PASS : AdBlockParseRule::cleanupTestCase()
Totals: 3 passed, 0 failed, 0 skipped
********* Finished testing of AdBlockParseRule *********
After:
********* Start testing of AdBlockParseRule *********
Config: Using QTest library 4.8.6, Qt 4.8.6
PASS : AdBlockParseRule::initTestCase()
RESULT : AdBlockParseRule::parseEasyList():
481.8 msecs per iteration (total: 2,409, iterations: 5)
PASS : AdBlockParseRule::parseEasyList()
PASS : AdBlockParseRule::cleanupTestCase()
Totals: 3 passed, 0 failed, 0 skipped
********* Finished testing of AdBlockParseRule *********
2014-04-06 13:34:01 +02:00
|
|
|
QStringList AdBlockRule::parseRegExpFilter(const QString &filter) const
|
|
|
|
{
|
|
|
|
QStringList list;
|
|
|
|
int startPos = -1;
|
|
|
|
|
|
|
|
for (int i = 0; i < filter.size(); ++i) {
|
|
|
|
const QChar c = filter.at(i);
|
|
|
|
// Meta characters in AdBlock rules are | * ^
|
|
|
|
if (c == QL1C('|') || c == QL1C('*') || c == QL1C('^')) {
|
|
|
|
const QString sub = filter.mid(startPos, i - startPos);
|
|
|
|
if (sub.size() > 1)
|
|
|
|
list.append(sub);
|
|
|
|
startPos = i + 1;
|
2013-02-26 15:48:47 +01:00
|
|
|
}
|
2012-09-01 11:41:12 +02:00
|
|
|
}
|
|
|
|
|
[AdBlock] Improved performance of loading rules
Don't use regexps for parsing rules.
Added benchmark for loading subscriptions
Before:
********* Start testing of AdBlockParseRule *********
Config: Using QTest library 4.8.6, Qt 4.8.6
PASS : AdBlockParseRule::initTestCase()
RESULT : AdBlockParseRule::parseEasyList():
596.3 msecs per iteration (total: 2,982, iterations: 5)
PASS : AdBlockParseRule::parseEasyList()
PASS : AdBlockParseRule::cleanupTestCase()
Totals: 3 passed, 0 failed, 0 skipped
********* Finished testing of AdBlockParseRule *********
After:
********* Start testing of AdBlockParseRule *********
Config: Using QTest library 4.8.6, Qt 4.8.6
PASS : AdBlockParseRule::initTestCase()
RESULT : AdBlockParseRule::parseEasyList():
481.8 msecs per iteration (total: 2,409, iterations: 5)
PASS : AdBlockParseRule::parseEasyList()
PASS : AdBlockParseRule::cleanupTestCase()
Totals: 3 passed, 0 failed, 0 skipped
********* Finished testing of AdBlockParseRule *********
2014-04-06 13:34:01 +02:00
|
|
|
const QString sub = filter.mid(startPos);
|
|
|
|
if (sub.size() > 1)
|
|
|
|
list.append(sub);
|
|
|
|
|
|
|
|
list.removeDuplicates();
|
|
|
|
|
2013-02-26 15:48:47 +01:00
|
|
|
return list;
|
2012-09-01 11:41:12 +02:00
|
|
|
}
|
2013-02-26 10:42:48 +01:00
|
|
|
|
2013-02-27 21:26:41 +01:00
|
|
|
bool AdBlockRule::hasOption(const AdBlockRule::RuleOption &opt) const
|
|
|
|
{
|
|
|
|
return (m_options & opt);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AdBlockRule::hasException(const AdBlockRule::RuleOption &opt) const
|
|
|
|
{
|
|
|
|
return (m_exceptions & opt);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AdBlockRule::setOption(const AdBlockRule::RuleOption &opt)
|
|
|
|
{
|
|
|
|
m_options |= opt;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AdBlockRule::setException(const AdBlockRule::RuleOption &opt, bool on)
|
|
|
|
{
|
|
|
|
if (on) {
|
|
|
|
m_exceptions |= opt;
|
|
|
|
}
|
|
|
|
}
|