From 9f825c30595a2689c48353860461a5dc9049a351 Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Sat, 21 Sep 2019 16:42:15 -0400 Subject: [PATCH] Do not flush blocked-elements cache at webNavigation time While testing for the new `elemhide` option using ABP's test page[1], I found out that the placeholder of the blocked image on that page was not properly collapsed by uBO. The reason was because the page is very simple and flushing the blocked-elements cache at webNavigation.onCommitted time was causing the loss of information collected between webRequest.onBeforeRequest and webNavigation.onCommitted, preventing uBO from properly collapsing the placeholders. The blocked-elements cache is now flushed ONLY at webRequest.onBeforeRequest time. [1] https://testpages.adblockplus.org/en/exceptions/elemhide --- src/js/pagestore.js | 22 +++------------------- src/js/tab.js | 1 + 2 files changed, 4 insertions(+), 19 deletions(-) diff --git a/src/js/pagestore.js b/src/js/pagestore.js index 4ddc73b60..615515a72 100644 --- a/src/js/pagestore.js +++ b/src/js/pagestore.js @@ -41,10 +41,6 @@ const µb = µBlock; /******************************************************************************/ -// To mitigate memory churning -const netFilteringCacheJunkyard = []; -const netFilteringCacheJunkyardMax = 10; - const NetFilteringResultCache = class { constructor() { this.init(); @@ -58,14 +54,6 @@ const NetFilteringResultCache = class { return this; } - dispose() { - this.empty(); - if ( netFilteringCacheJunkyard.length < netFilteringCacheJunkyardMax ) { - netFilteringCacheJunkyard.push(this); - } - return null; - } - rememberResult(fctxt, result) { if ( fctxt.tabId <= 0 ) { return; } if ( this.results.size === 0 ) { @@ -155,10 +143,7 @@ const NetFilteringResultCache = class { } static factory() { - const entry = netFilteringCacheJunkyard.pop(); - return entry !== undefined - ? entry.init() - : new NetFilteringResultCache(); + return new NetFilteringResultCache(); } }; @@ -218,6 +203,7 @@ const PageStore = class { this.journalTimer = null; this.journalLastCommitted = this.journalLastUncommitted = undefined; this.journalLastUncommittedURL = undefined; + this.netFilteringCache = NetFilteringResultCache.factory(); this.init(tabId, context); } @@ -261,7 +247,6 @@ const PageStore = class { this.popupBlockedCount = 0; this.largeMediaCount = 0; this.largeMediaTimer = null; - this.netFilteringCache = NetFilteringResultCache.factory(); this.internalRedirectionCount = 0; this.extraData.clear(); @@ -327,7 +312,6 @@ const PageStore = class { this.largeMediaTimer = null; } this.disposeFrameStores(); - this.netFilteringCache = this.netFilteringCache.dispose(); this.init(this.tabId, context); return this; } @@ -337,13 +321,13 @@ const PageStore = class { this.title = ''; this.rawURL = ''; this.hostnameToCountMap = null; + this.netFilteringCache.empty(); this.allowLargeMediaElementsUntil = 0; if ( this.largeMediaTimer !== null ) { clearTimeout(this.largeMediaTimer); this.largeMediaTimer = null; } this.disposeFrameStores(); - this.netFilteringCache = this.netFilteringCache.dispose(); if ( this.journalTimer !== null ) { clearTimeout(this.journalTimer); this.journalTimer = null; diff --git a/src/js/tab.js b/src/js/tab.js index d0e64bcb3..ea7286251 100644 --- a/src/js/tab.js +++ b/src/js/tab.js @@ -887,6 +887,7 @@ vAPI.tabs = new vAPI.Tabs(); // https://github.com/chrisaljoudi/uBlock/issues/516 // If context is 'beforeRequest', do not rebind, wait for confirmation. if ( context === 'beforeRequest' ) { + pageStore.netFilteringCache.empty(); return pageStore; }