1
mirror of https://invent.kde.org/network/falkon.git synced 2024-11-11 01:22:10 +01:00

AdBlock: Fixed $subdocument matching.

- also improved a little blocked element's placoholders hiding
This commit is contained in:
nowrep 2012-07-13 14:12:48 +02:00
parent 14e0040a9f
commit 435ab60e79
3 changed files with 31 additions and 9 deletions

View File

@ -336,7 +336,7 @@ bool AdBlockRule::matchSubdocument(const QNetworkRequest &request) const
return false; return false;
} }
bool match = originatingFrame == page->mainFrame(); bool match = !(originatingFrame == page->mainFrame());
return m_subdocumentException ? !match : match; return m_subdocumentException ? !match : match;
} }

View File

@ -516,9 +516,7 @@ void WebPage::addAdBlockRule(const AdBlockRule* rule, const QUrl &url)
void WebPage::cleanBlockedObjects() void WebPage::cleanBlockedObjects()
{ {
AdBlockManager* manager = AdBlockManager::instance(); AdBlockManager* manager = AdBlockManager::instance();
const QString &urlScheme = url().scheme(); if (!manager->isEnabled()) {
if (!manager->isEnabled() || !manager->canRunOnScheme(urlScheme)) {
return; return;
} }
@ -530,12 +528,17 @@ void WebPage::cleanBlockedObjects()
continue; continue;
} }
QString urlEnd;
int pos = urlString.lastIndexOf('/'); int pos = urlString.lastIndexOf('/');
if (pos < 0 || urlString.endsWith('/')) { if (pos > 8) {
continue; urlEnd = urlString.mid(pos + 1);
}
if (urlString.endsWith('/')) {
urlEnd = urlString.left(urlString.size() - 1);
} }
QString urlEnd = urlString.mid(pos + 1);
QString selector("img[src$=\"" + urlEnd + "\"], iframe[src$=\"" + urlEnd + "\"]," QString selector("img[src$=\"" + urlEnd + "\"], iframe[src$=\"" + urlEnd + "\"],"
"embed[src$=\"" + urlEnd + "\"]"); "embed[src$=\"" + urlEnd + "\"]");
QWebElementCollection elements = docElement.findAll(selector); QWebElementCollection elements = docElement.findAll(selector);
@ -544,8 +547,8 @@ void WebPage::cleanBlockedObjects()
QString src = element.attribute("src"); QString src = element.attribute("src");
src.remove("../"); src.remove("../");
if (urlString.endsWith(src)) { if (urlString.contains(src)) {
element.setStyleProperty("visibility", "hidden"); element.setStyleProperty("display", "none");
} }
} }
} }

View File

@ -1,6 +1,7 @@
<html> <html>
<head> <head>
<title>AdBlock Tests &A</title> <title>AdBlock Tests &A</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
</head> </head>
<body> <body>
<h2>AdBlock Tests</h2> <h2>AdBlock Tests</h2>
@ -15,5 +16,23 @@ Blocking element with <b>##div.test-qz-ad</b> rule.
If you see this text, the rule does not works! If you see this text, the rule does not works!
</div> </div>
<h3>Subdocument rules</h3>
Blocking iframe with <b>||linux.org.ru^$subdocument</b> rule.
<iframe src="http://www.linux.org.ru" width="100" height="100"></iframe>
<h3>XMLHttpRequest rules</h3>
Blocking ajax with <b>adblock.html$xmlhttprequest</b> rule.
<div id="ajax-status">Blocked</div>
<script>
$.get("adblock.html", function(data) {
$("#ajax-status").html("Loaded!");
});
if (location.protocol == "file:") {
document.write("<h3 style='color:red'>Protocol file:// cannot be blocked!</h3>");
document.write("Please move this file to localhost");
}
</script>
</body> </body>
</html> </html>