1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-10-06 09:37:12 +02:00

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
This commit is contained in:
Raymond Hill 2019-09-21 16:42:15 -04:00
parent 350e436c08
commit 9f825c3059
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
2 changed files with 4 additions and 19 deletions

View File

@ -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;

View File

@ -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;
}