diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/adblock/adblockmanager.cpp | 44 | ||||
-rw-r--r-- | src/adblock/adblockmanager.h | 2 | ||||
-rw-r--r-- | src/networkaccessmanager.cpp | 17 | ||||
-rw-r--r-- | src/networkaccessmanager.h | 6 |
4 files changed, 55 insertions, 14 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); diff --git a/src/networkaccessmanager.cpp b/src/networkaccessmanager.cpp index 77597cef..99337206 100644 --- a/src/networkaccessmanager.cpp +++ b/src/networkaccessmanager.cpp @@ -32,10 +32,15 @@ // Local Includes #include "application.h" #include "adblockmanager.h" +#include "webpage.h" + +// KDE Includes #include <KDebug> + NetworkAccessManager::NetworkAccessManager(QObject *parent) : AccessManager(parent) + , _parentPage( qobject_cast<WebPage *>(parent) ) { } @@ -48,16 +53,16 @@ QNetworkReply *NetworkAccessManager::createRequest(Operation op, const QNetworkR { case QNetworkAccessManager::HeadOperation: kDebug() << "HEAD OPERATION"; - if(outgoingData) - { - QByteArray outgoingDataByteArray = outgoingData->peek(1024 * 1024); - kDebug() << outgoingDataByteArray; - } +// if(outgoingData) +// { +// QByteArray outgoingDataByteArray = outgoingData->peek(1024 * 1024); +// kDebug() << outgoingDataByteArray; +// } break; case QNetworkAccessManager::GetOperation: kDebug() << "GET OPERATION"; - reply = Application::adblockManager()->block(req); + reply = Application::adblockManager()->block(req, _parentPage); if (reply) return reply; break; diff --git a/src/networkaccessmanager.h b/src/networkaccessmanager.h index 5e55c1e6..352f67d6 100644 --- a/src/networkaccessmanager.h +++ b/src/networkaccessmanager.h @@ -31,6 +31,7 @@ // Local Includes #include "rekonqprivate_export.h" +#include "webpage.h" // KDE Includes #include <kio/accessmanager.h> @@ -44,10 +45,13 @@ class REKONQ_TESTS_EXPORT NetworkAccessManager : public AccessManager Q_OBJECT public: - NetworkAccessManager(QObject *parent = 0); + NetworkAccessManager(QObject *parent); protected: virtual QNetworkReply *createRequest(Operation op, const QNetworkRequest &req, QIODevice *outgoingData = 0); + +private: + WebPage *_parentPage; }; #endif // NETWORKACCESSMANAGER_H |