summaryrefslogtreecommitdiff
path: root/src/adblock
diff options
context:
space:
mode:
authorAndrea Diamantini <adjam7@gmail.com>2010-03-30 17:14:54 +0200
committerAndrea Diamantini <adjam7@gmail.com>2010-03-30 17:14:54 +0200
commitc5e684b649d5aac0424abcd573c1cb1a3e7dbb9d (patch)
tree26d69726d9ab245ee485f6c52931e8d4fa987742 /src/adblock
parentCleaning urlbar API and improving animation (diff)
downloadrekonq-c5e684b649d5aac0424abcd573c1cb1a3e7dbb9d.tar.xz
Not so stupid, after all..
Diffstat (limited to 'src/adblock')
-rw-r--r--src/adblock/adblockmanager.cpp44
-rw-r--r--src/adblock/adblockmanager.h2
2 files changed, 39 insertions, 7 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();
}
}
}
diff --git a/src/adblock/adblockmanager.h b/src/adblock/adblockmanager.h
index c0bd2b70..9b1cc915 100644
--- a/src/adblock/adblockmanager.h
+++ b/src/adblock/adblockmanager.h
@@ -131,7 +131,7 @@ public:
AdBlockManager(QObject *parent = 0);
~AdBlockManager();
- QNetworkReply *block(const QNetworkRequest &request);
+ QNetworkReply *block(const QNetworkRequest &request, WebPage *page);
void applyHidingRules(WebPage *page);
void addSubscription(const QString &title, const QString &location);