diff options
author | Andrea Diamantini <adjam7@gmail.com> | 2010-03-30 17:14:54 +0200 |
---|---|---|
committer | Andrea Diamantini <adjam7@gmail.com> | 2010-03-30 17:14:54 +0200 |
commit | c5e684b649d5aac0424abcd573c1cb1a3e7dbb9d (patch) | |
tree | 26d69726d9ab245ee485f6c52931e8d4fa987742 /src/adblock/adblockmanager.cpp | |
parent | Cleaning urlbar API and improving animation (diff) | |
download | rekonq-c5e684b649d5aac0424abcd573c1cb1a3e7dbb9d.tar.xz |
Not so stupid, after all..
Diffstat (limited to 'src/adblock/adblockmanager.cpp')
-rw-r--r-- | src/adblock/adblockmanager.cpp | 44 |
1 files changed, 38 insertions, 6 deletions
diff --git a/src/adblock/adblockmanager.cpp b/src/adblock/adblockmanager.cpp index 71412d5d..e4986264 100644 --- a/src/adblock/adblockmanager.cpp +++ b/src/adblock/adblockmanager.cpp @@ -148,7 +148,7 @@ void AdBlockManager::loadRules(const QStringList &rules) } -QNetworkReply *AdBlockManager::block(const QNetworkRequest &request) +QNetworkReply *AdBlockManager::block(const QNetworkRequest &request, WebPage *page) { if (!_isAdblockEnabled) return 0; @@ -179,6 +179,19 @@ QNetworkReply *AdBlockManager::block(const QNetworkRequest &request) kDebug() << "****ADBLOCK: BLACK RULE Matched: ***********"; kDebug() << "Filter exp: " << filter.pattern(); kDebug() << "UrlString: " << urlString; + + QWebElement document = page->mainFrame()->documentElement(); + QWebElementCollection elements = document.findAll("*"); + foreach (QWebElement el, elements) + { + if(filter.match( el.attribute("src") ) ) + { + kDebug() << "MATCHES ATTRIBUTE!!!!!"; + el.setStyleProperty(QLatin1String("visibility"), QLatin1String("hidden")); + el.removeFromDocument(); + } + } + AdBlockNetworkReply *reply = new AdBlockNetworkReply(request, urlString, this); return reply; } @@ -197,19 +210,38 @@ void AdBlockManager::applyHidingRules(WebPage *page) if (!_isAdblockEnabled) return; +// // BLACK RULES +// foreach(const AdBlockRule &filter, _blackList) +// { +// QWebElementCollection elements = document.findAll("*"); +// foreach (QWebElement el, elements) +// { +// if(filter.match( el.attribute("src") ) ) +// { +// kDebug() << "MATCHES!!!!!"; +// el.setStyleProperty(QLatin1String("visibility"), QLatin1String("hidden")); +// el.removeFromDocument(); +// } +// } +// } + if (!_isHideAdsEnabled) return; + + QWebElement document = page->mainFrame()->documentElement(); + // HIDE RULES foreach(const QString &filter, _hideList) { - QWebElement document = page->mainFrame()->documentElement(); QWebElementCollection elements = document.findAll(filter); - foreach (QWebElement element, elements) + foreach (QWebElement el, elements) { - kDebug() << "Hide element: " << element.localName(); - element.setStyleProperty(QLatin1String("visibility"), QLatin1String("hidden")); - element.removeFromDocument(); + if(el.isNull()) + continue; + kDebug() << "Hide element: " << el.localName(); + el.setStyleProperty(QLatin1String("visibility"), QLatin1String("hidden")); + el.removeFromDocument(); } } } |