From b9c1f2e39718236641c503e25a82df0126c5a67f Mon Sep 17 00:00:00 2001 From: gorhill Date: Wed, 17 Dec 2014 10:32:50 -0500 Subject: [PATCH] this fixes #420 --- src/js/cosmetic-filtering.js | 21 +++++++++++++++++++++ src/js/ublock.js | 13 ++++++++++--- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/src/js/cosmetic-filtering.js b/src/js/cosmetic-filtering.js index 35324c9c8..9e86b1f7c 100644 --- a/src/js/cosmetic-filtering.js +++ b/src/js/cosmetic-filtering.js @@ -363,6 +363,17 @@ SelectorCacheEntry.prototype.add = function(selectors, type) { } }; +// https://github.com/gorhill/uBlock/issues/420 +SelectorCacheEntry.prototype.remove = function(type) { + this.lastAccessTime = Date.now(); + if ( type === 'cosmetic' ) { + this.cosmetic = {}; + } else { + this.net = {}; + this.netCount = 0; + } +}; + SelectorCacheEntry.prototype.retrieve = function(type, out) { this.lastAccessTime = Date.now(); var dict = type === 'cosmetic' ? this.cosmetic : this.net; @@ -918,6 +929,16 @@ FilterContainer.prototype.addToSelectorCache = function(details) { /******************************************************************************/ +FilterContainer.prototype.removeFromSelectorCache = function(hostname, type) { + var entry = this.selectorCache[hostname]; + if ( entry === undefined ) { + return; + } + entry.remove(type); +}; + +/******************************************************************************/ + FilterContainer.prototype.retrieveFromSelectorCache = function(hostname, type, out) { var entry = this.selectorCache[hostname]; if ( entry === undefined ) { diff --git a/src/js/ublock.js b/src/js/ublock.js index 3e48a7f5b..2b926a672 100644 --- a/src/js/ublock.js +++ b/src/js/ublock.js @@ -314,9 +314,16 @@ var matchWhitelistDirective = function(url, hostname, directive) { } else { changed = this.netFilteringEngine.dynamicFilterUnblock(details.hostname, details.requestType, details.firstParty); } - if ( changed ) { - this.userSettings.dynamicFilteringSelfie = this.netFilteringEngine.selfieFromDynamicFilters(); - this.XAL.keyvalSetOne('dynamicFilteringSelfie', this.userSettings.dynamicFilteringSelfie); + if ( !changed ) { + return; + } + + this.userSettings.dynamicFilteringSelfie = this.netFilteringEngine.selfieFromDynamicFilters(); + this.XAL.keyvalSetOne('dynamicFilteringSelfie', this.userSettings.dynamicFilteringSelfie); + + // https://github.com/gorhill/uBlock/issues/420 + if ( details.requestType === 'sub_frame' && !details.block ) { + this.cosmeticFilteringEngine.removeFromSelectorCache(details.pageHostname, 'net'); } };