commit abc933ccee0af644bc642dc7551651d1ce0ca29a Author: Andrea Iacovitti 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 entryMap = cgFilter.entryMap(); - QMap::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 entryMap = cgFilter.entryMap(); + QMap::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" );