diff --git a/doc/help/settings.asciidoc b/doc/help/settings.asciidoc index 796199a19..499c9c88b 100644 --- a/doc/help/settings.asciidoc +++ b/doc/help/settings.asciidoc @@ -159,6 +159,7 @@ |<>|Whether to store cookies. |<>|List of URLs of lists which contain hosts to block. |<>|Whether host blocking is enabled. +|<>|List of domains that should always be loaded, despite being ad-blocked. |============== .Quick reference for section ``hints'' @@ -1433,6 +1434,16 @@ Valid values: Default: +pass:[true]+ +[[content-host-blocking-whitelist]] +=== host-blocking-whitelist +List of domains that should always be loaded, despite being ad-blocked. + +Domains may contain * and ? wildcards and are otherwise required to exactly match the requested domain. + +Local domains are always exempt from hostblocking. + +Default: empty + == hints Hinting settings. diff --git a/qutebrowser/browser/network/networkmanager.py b/qutebrowser/browser/network/networkmanager.py index e433b5e66..c2eee80e9 100644 --- a/qutebrowser/browser/network/networkmanager.py +++ b/qutebrowser/browser/network/networkmanager.py @@ -20,6 +20,7 @@ """Our own QNetworkAccessManager.""" import collections +import fnmatch from PyQt5.QtCore import (pyqtSlot, pyqtSignal, PYQT_VERSION, QCoreApplication, QUrl, QByteArray) @@ -49,6 +50,22 @@ def init(): QSslSocket.setDefaultCiphers(good_ciphers) +def is_whitelisted_domain(host): + """Check if the given host is on the adblock whitelist. + + Args: + host: The host of the request as string. + """ + whitelist = config.get('content', 'host-blocking-whitelist') + if whitelist is None: + return False + + for pattern in whitelist: + if fnmatch.fnmatch(host, pattern.lower()): + return True + return False + + class SslError(QSslError): """A QSslError subclass which provides __hash__ on Qt < 5.4.""" @@ -347,7 +364,8 @@ class NetworkManager(QNetworkAccessManager): host_blocker = objreg.get('host-blocker') if (op == QNetworkAccessManager.GetOperation and req.url().host() in host_blocker.blocked_hosts and - config.get('content', 'host-blocking-enabled')): + config.get('content', 'host-blocking-enabled') and + not is_whitelisted_domain(req.url().host())): log.webview.info("Request to {} blocked by host blocker.".format( req.url().host())) return networkreply.ErrorNetworkReply( diff --git a/qutebrowser/config/configdata.py b/qutebrowser/config/configdata.py index c9d82838d..cbede4a00 100644 --- a/qutebrowser/config/configdata.py +++ b/qutebrowser/config/configdata.py @@ -735,6 +735,14 @@ def data(readonly=False): SettingValue(typ.Bool(), 'true'), "Whether host blocking is enabled."), + ('host-blocking-whitelist', + SettingValue(typ.List(none_ok=True), ''), + "List of domains that should always be loaded, despite being " + "ad-blocked.\n\n" + "Domains may contain * and ? wildcards and are otherwise " + "required to exactly match the requested domain.\n\n" + "Local domains are always exempt from hostblocking."), + readonly=readonly )),