backport: Load/Update filter lists only when AdBlock is enabled

This commit is contained in:
Than Ngo 2012-04-12 10:30:26 +02:00
parent 278467117c
commit 1d67fe3668
2 changed files with 130 additions and 1 deletions

123
kdelibs-4.8.2-filter.patch Normal file
View File

@ -0,0 +1,123 @@
commit abc933ccee0af644bc642dc7551651d1ce0ca29a
Author: Andrea Iacovitti <aiacovitti@libero.it>
Date: Wed Apr 11 22:38:35 2012 +0200
Load/Update filter lists only when AdBlock is enabled.
FIXED-IN: 4.8.3
diff --git a/khtml/khtml_settings.cpp b/khtml/khtml_settings.cpp
index 118f388..bbe1bb4 100644
--- a/khtml/khtml_settings.cpp
+++ b/khtml/khtml_settings.cpp
@@ -410,59 +410,63 @@ void KHTMLSettings::init( KConfig * config, bool reset )
d->adBlackList.clear();
d->adWhiteList.clear();
- /** read maximum age for filter list files, minimum is one day */
- int htmlFilterListMaxAgeDays = cgFilter.readEntry(QString("HTMLFilterListMaxAgeDays")).toInt();
- if (htmlFilterListMaxAgeDays < 1)
- htmlFilterListMaxAgeDays = 1;
-
- QMap<QString,QString> entryMap = cgFilter.entryMap();
- QMap<QString,QString>::ConstIterator it;
- for( it = entryMap.constBegin(); it != entryMap.constEnd(); ++it )
- {
- int id = -1;
- QString name = it.key();
- QString url = it.value();
+ if (d->m_adFilterEnabled) {
- if (name.startsWith("Filter"))
- {
- if (url.startsWith(QLatin1String("@@")))
- d->adWhiteList.addFilter(url);
- else
- d->adBlackList.addFilter(url);
- } else if (name.startsWith("HTMLFilterListName-") && (id = name.mid(19).toInt()) > 0)
+ /** read maximum age for filter list files, minimum is one day */
+ int htmlFilterListMaxAgeDays = cgFilter.readEntry(QString("HTMLFilterListMaxAgeDays")).toInt();
+ if (htmlFilterListMaxAgeDays < 1)
+ htmlFilterListMaxAgeDays = 1;
+
+ QMap<QString,QString> entryMap = cgFilter.entryMap();
+ QMap<QString,QString>::ConstIterator it;
+ for( it = entryMap.constBegin(); it != entryMap.constEnd(); ++it )
{
- /** check if entry is enabled */
- bool filterEnabled = cgFilter.readEntry(QString("HTMLFilterListEnabled-").append(QString::number(id))) != QLatin1String("false");
-
- /** get url for HTMLFilterList */
- KUrl url(cgFilter.readEntry(QString("HTMLFilterListURL-").append(QString::number(id))));
-
- if (filterEnabled && url.isValid()) {
- /** determine where to cache HTMLFilterList file */
- QString localFile = cgFilter.readEntry(QString("HTMLFilterListLocalFilename-").append(QString::number(id)));
- localFile = KStandardDirs::locateLocal("data", "khtml/" + localFile);
-
- /** determine existence and age of cache file */
- QFileInfo fileInfo(localFile);
-
- /** load cached file if it exists, irrespective of age */
- if (fileInfo.exists())
- d->adblockFilterLoadList( localFile );
-
- /** if no cache list file exists or if it is too old ... */
- if (!fileInfo.exists() || fileInfo.lastModified().daysTo(QDateTime::currentDateTime()) > htmlFilterListMaxAgeDays)
- {
- /** ... in this case, refetch list asynchronously */
- kDebug(6000) << "Asynchronously fetching filter list from" << url << "to" << localFile;
-
- KIO::StoredTransferJob *job = KIO::storedGet( url, KIO::Reload, KIO::HideProgressInfo );
- QObject::connect( job, SIGNAL(result(KJob*)), d, SLOT(adblockFilterResult(KJob*)) );
- /** for later reference, store name of cache file */
- job->setProperty("khtmlsettings_adBlock_filename", localFile);
+ int id = -1;
+ QString name = it.key();
+ QString url = it.value();
+
+ if (name.startsWith("Filter"))
+ {
+ if (url.startsWith(QLatin1String("@@")))
+ d->adWhiteList.addFilter(url);
+ else
+ d->adBlackList.addFilter(url);
+ } else if (name.startsWith("HTMLFilterListName-") && (id = name.mid(19).toInt()) > 0)
+ {
+ /** check if entry is enabled */
+ bool filterEnabled = cgFilter.readEntry(QString("HTMLFilterListEnabled-").append(QString::number(id))) != QLatin1String("false");
+
+ /** get url for HTMLFilterList */
+ KUrl url(cgFilter.readEntry(QString("HTMLFilterListURL-").append(QString::number(id))));
+
+ if (filterEnabled && url.isValid()) {
+ /** determine where to cache HTMLFilterList file */
+ QString localFile = cgFilter.readEntry(QString("HTMLFilterListLocalFilename-").append(QString::number(id)));
+ localFile = KStandardDirs::locateLocal("data", "khtml/" + localFile);
+
+ /** determine existence and age of cache file */
+ QFileInfo fileInfo(localFile);
+
+ /** load cached file if it exists, irrespective of age */
+ if (fileInfo.exists())
+ d->adblockFilterLoadList( localFile );
+
+ /** if no cache list file exists or if it is too old ... */
+ if (!fileInfo.exists() || fileInfo.lastModified().daysTo(QDateTime::currentDateTime()) > htmlFilterListMaxAgeDays)
+ {
+ /** ... in this case, refetch list asynchronously */
+ kDebug(6000) << "Asynchronously fetching filter list from" << url << "to" << localFile;
+
+ KIO::StoredTransferJob *job = KIO::storedGet( url, KIO::Reload, KIO::HideProgressInfo );
+ QObject::connect( job, SIGNAL(result(KJob*)), d, SLOT(adblockFilterResult(KJob*)) );
+ /** for later reference, store name of cache file */
+ job->setProperty("khtmlsettings_adBlock_filename", localFile);
+ }
}
}
}
}
+
}
KConfigGroup cgHtml( config, "HTML Settings" );

View File

@ -20,7 +20,7 @@
Summary: KDE Libraries
Version: 4.8.2
Release: 1%{?dist}
Release: 2%{?dist}
Name: kdelibs
Epoch: 6
@ -132,6 +132,8 @@ Patch53: kdelibs-4.7.2-kjs-s390.patch
## upstream
# don't set rpath on multiarch dirs, https://git.reviewboard.kde.org/r/103422
Patch101: kdelibs-4.8.0-cmake_cxx_implicit_link_directories.patch
# Load/Update filter lists only when AdBlock is enabled
Patch102: kdelibs-4.8.2-filter.patch
## security fix
# Not Upstreamed? why not ? -- Rex
@ -322,6 +324,7 @@ sed -i -e "s|@@VERSION_RELEASE@@|%{version}-%{release}|" kio/kio/kprotocolmanage
# upstream patches
%patch101 -p1 -b .cmake_cxx_implicit_link_directories
%patch102 -p1 -b .filter
# security fixes
%patch200 -p1 -b .CVE-2009-2702
@ -575,6 +578,9 @@ rm -rf %{buildroot}
%changelog
* Thu Apr 12 2012 Than Ngo <than@redhat.com> - 6:4.8.2-2
- Load/Update filter lists only when AdBlock is enabled
* Fri Mar 30 2012 Jaroslav Reznik <jreznik@redhat.com> - 6:4.8.2-1
- 4.8.2