From d0f81f5e3baf209b56d7a99f0d39fbd3e51d6439 Mon Sep 17 00:00:00 2001 From: gorhill Date: Thu, 5 Feb 2015 23:14:12 -0500 Subject: [PATCH] this fixes #689 --- src/js/dynamic-net-filtering.js | 19 ++++++++++++------- src/js/messaging.js | 4 ++-- src/js/pagestore.js | 19 ++++++++++++++----- src/js/ublock.js | 8 -------- 4 files changed, 28 insertions(+), 22 deletions(-) diff --git a/src/js/dynamic-net-filtering.js b/src/js/dynamic-net-filtering.js index 4ed0b45d0..7a7c411be 100644 --- a/src/js/dynamic-net-filtering.js +++ b/src/js/dynamic-net-filtering.js @@ -295,12 +295,24 @@ Matrix.prototype.evaluateCellZY = function(srcHostname, desHostname, type) { /******************************************************************************/ +Matrix.prototype.mustAllowCellZY = function(srcHostname, desHostname, type) { + return this.evaluateCellZY(srcHostname, desHostname, type).r === 2; +}; + +/******************************************************************************/ + Matrix.prototype.mustBlockOrAllow = function() { return this.r === 1 || this.r === 2; }; /******************************************************************************/ +Matrix.prototype.mustBlock = function() { + return this.r === 1; +}; + +/******************************************************************************/ + Matrix.prototype.mustAbort = function() { return this.r === 3; }; @@ -325,13 +337,6 @@ Matrix.prototype.toFilterString = function() { /******************************************************************************/ -Matrix.prototype.mustBlock = function(srcHostname, desHostname, type) { - this.evaluateCellZY(srcHostname, desHostname, type); - return this.r === 1; -}; - -/******************************************************************************/ - Matrix.prototype.srcHostnameFromRule = function(rule) { return rule.slice(0, rule.indexOf(' ')); }; diff --git a/src/js/messaging.js b/src/js/messaging.js index 0dd46cf25..f3baa58cc 100644 --- a/src/js/messaging.js +++ b/src/js/messaging.js @@ -333,7 +333,7 @@ var onMessage = function(request, sender, callback) { switch ( request.what ) { case 'retrieveDomainCosmeticSelectors': - if ( pageStore && pageStore.getNetFilteringSwitch() ) { + if ( pageStore && pageStore.getSpecificCosmeticFilteringSwitch() ) { response = µb.cosmeticFilteringEngine.retrieveDomainSelectors(request); } break; @@ -453,7 +453,7 @@ var onMessage = function(details, sender, callback) { switch ( details.what ) { case 'retrieveGenericCosmeticSelectors': - if ( pageStore && pageStore.getCosmeticFilteringSwitch() ) { + if ( pageStore && pageStore.getGenericCosmeticFilteringSwitch() ) { response = µb.cosmeticFilteringEngine.retrieveGenericSelectors(details); } break; diff --git a/src/js/pagestore.js b/src/js/pagestore.js index e9ffc89dd..2aefdcf38 100644 --- a/src/js/pagestore.js +++ b/src/js/pagestore.js @@ -601,9 +601,19 @@ PageStore.prototype.getNetFilteringSwitch = function() { /******************************************************************************/ -PageStore.prototype.getCosmeticFilteringSwitch = function() { - return this.getNetFilteringSwitch() !== false && - this.skipCosmeticFiltering === false; +PageStore.prototype.getSpecificCosmeticFilteringSwitch = function() { + return this.getNetFilteringSwitch() && + (µb.userSettings.advancedUserEnabled && + µb.dynamicNetFilteringEngine.mustAllowCellZY(this.rootHostname, this.rootHostname, '*')) === false; +}; + +/******************************************************************************/ + +PageStore.prototype.getGenericCosmeticFilteringSwitch = function() { + return this.getNetFilteringSwitch() && + this.skipCosmeticFiltering === false && + (µb.userSettings.advancedUserEnabled && + µb.dynamicNetFilteringEngine.mustAllowCellZY(this.rootHostname, this.rootHostname, '*')) === false; }; /******************************************************************************/ @@ -638,8 +648,7 @@ PageStore.prototype.filterRequest = function(context) { // We evaluate dynamic filtering first, and hopefully we can skip // evaluation of static filtering. if ( µb.userSettings.advancedUserEnabled ) { - var df = µb.dynamicNetFilteringEngine.clearRegisters(); - df.evaluateCellZY(context.rootHostname, context.requestHostname, context.requestType); + var df = µb.dynamicNetFilteringEngine.evaluateCellZY(context.rootHostname, context.requestHostname, context.requestType); if ( df.mustBlockOrAllow() ) { result = df.toFilterString(); } diff --git a/src/js/ublock.js b/src/js/ublock.js index e595cf787..c2753649a 100644 --- a/src/js/ublock.js +++ b/src/js/ublock.js @@ -154,14 +154,6 @@ var matchWhitelistDirective = function(url, hostname, directive) { /******************************************************************************/ -// For now we will use the net whitelist - -µBlock.getCosmeticFilteringSwitch = function(url) { - return this.getNetFilteringSwitch(url); -}; - -/******************************************************************************/ - µBlock.stringFromWhitelist = function(whitelist) { var r = {}; var i, bucket;