diff --git a/src/lib/adblock/adblockmanager.cpp b/src/lib/adblock/adblockmanager.cpp index 8f8f68640..6edc878fc 100644 --- a/src/lib/adblock/adblockmanager.cpp +++ b/src/lib/adblock/adblockmanager.cpp @@ -1,6 +1,6 @@ /* ============================================================ * QupZilla - WebKit based browser -* Copyright (C) 2010-2014 David Rosca +* Copyright (C) 2010-2016 David Rosca * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -390,8 +390,11 @@ bool AdBlockManager::canBeBlocked(const QUrl &url) const return !m_matcher->adBlockDisabledForUrl(url); } -QString AdBlockManager::elementHidingRules() const +QString AdBlockManager::elementHidingRules(const QUrl &url) const { + if (!isEnabled() || !canRunOnScheme(url.scheme()) || !canBeBlocked(url)) + return QString(); + return m_matcher->elementHidingRules(); } @@ -400,10 +403,6 @@ QString AdBlockManager::elementHidingRulesForDomain(const QUrl &url) const if (!isEnabled() || !canRunOnScheme(url.scheme()) || !canBeBlocked(url)) return QString(); - // Acid3 doesn't like the way element hiding rules are embedded into page - if (url.host() == QLatin1String("acid3.acidtests.org")) - return QString(); - return m_matcher->elementHidingRulesForDomain(url.host()); } diff --git a/src/lib/adblock/adblockmanager.h b/src/lib/adblock/adblockmanager.h index 2722295d0..3c627eaa8 100644 --- a/src/lib/adblock/adblockmanager.h +++ b/src/lib/adblock/adblockmanager.h @@ -1,6 +1,6 @@ /* ============================================================ * QupZilla - WebKit based browser -* Copyright (C) 2010-2014 David Rosca +* Copyright (C) 2010-2016 David Rosca * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -51,7 +51,7 @@ public: bool useLimitedEasyList() const; void setUseLimitedEasyList(bool useLimited); - QString elementHidingRules() const; + QString elementHidingRules(const QUrl &url) const; QString elementHidingRulesForDomain(const QUrl &url) const; AdBlockSubscription* subscriptionByName(const QString &name) const; diff --git a/src/lib/app/mainapplication.cpp b/src/lib/app/mainapplication.cpp index 0f549db7c..cdec4bc89 100644 --- a/src/lib/app/mainapplication.cpp +++ b/src/lib/app/mainapplication.cpp @@ -1079,7 +1079,6 @@ void MainApplication::setUserStyleSheet(const QString &filePath) userCss += QString("::selection {background: %1; color: %2;} ").arg(highlightColor, highlightedTextColor); #endif - userCss += AdBlockManager::instance()->elementHidingRules().replace(QL1S("\""), QL1S("\\\"")); userCss += QzTools::readAllFileContents(filePath).remove(QLatin1Char('\n')); const QString name = QStringLiteral("_qupzilla_userstylesheet"); diff --git a/src/lib/webengine/webpage.cpp b/src/lib/webengine/webpage.cpp index acfc7879a..741bbbd42 100644 --- a/src/lib/webengine/webpage.cpp +++ b/src/lib/webengine/webpage.cpp @@ -467,13 +467,15 @@ void WebPage::cleanBlockedObjects() return; } - // Apply domain-specific element hiding rules - const QString elementHiding = manager->elementHidingRulesForDomain(url()); - if (elementHiding.isEmpty()) { - return; - } + // Apply global element hiding rules + const QString elementHiding = manager->elementHidingRules(url()); + if (!elementHiding.isEmpty()) + runJavaScript(Scripts::setCss(elementHiding), WebPage::SafeJsWorld); - runJavaScript(Scripts::setCss(elementHiding), WebPage::SafeJsWorld); + // Apply domain-specific element hiding rules + const QString siteElementHiding = manager->elementHidingRulesForDomain(url()); + if (!siteElementHiding.isEmpty()) + runJavaScript(Scripts::setCss(siteElementHiding), WebPage::SafeJsWorld); } bool WebPage::javaScriptPrompt(const QUrl &securityOrigin, const QString &msg, const QString &defaultValue, QString* result)