mirror of
https://github.com/gorhill/uBlock.git
synced 2024-10-06 09:37:12 +02:00
Ensure scriptlet cache is reset when filtering profile changes
Related issue: https://github.com/uBlockOrigin/uBlock-issues/issues/2896 TODO: Eventually, distinguish between filtering profile increasing or decreasing so as to avoid flushing caches when increasing filtering, which should not affect the scriptlets cache.
This commit is contained in:
parent
d6bd14d708
commit
e5b438257f
@ -66,6 +66,10 @@ const scriptletFilteringEngine = {
|
|||||||
const contentScriptRegisterer = new (class {
|
const contentScriptRegisterer = new (class {
|
||||||
constructor() {
|
constructor() {
|
||||||
this.hostnameToDetails = new Map();
|
this.hostnameToDetails = new Map();
|
||||||
|
if ( browser.contentScripts === undefined ) { return; }
|
||||||
|
µb.onEvent('filteringBehaviorChanged', ( ) => {
|
||||||
|
this.reset();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
register(hostname, code) {
|
register(hostname, code) {
|
||||||
if ( browser.contentScripts === undefined ) { return false; }
|
if ( browser.contentScripts === undefined ) { return false; }
|
||||||
|
@ -453,7 +453,7 @@ if ( selfieIsValid !== true ) {
|
|||||||
|
|
||||||
// Flush memory cache -- unsure whether the browser does this internally
|
// Flush memory cache -- unsure whether the browser does this internally
|
||||||
// when loading a new extension.
|
// when loading a new extension.
|
||||||
vAPI.net.handlerBehaviorChanged();
|
µb.filteringBehaviorChanged();
|
||||||
|
|
||||||
// Final initialization steps after all needed assets are in memory.
|
// Final initialization steps after all needed assets are in memory.
|
||||||
|
|
||||||
|
@ -243,7 +243,7 @@ import {
|
|||||||
if ( typeof hs[key] !== typeof hsDefault[key] ) { continue; }
|
if ( typeof hs[key] !== typeof hsDefault[key] ) { continue; }
|
||||||
this.hiddenSettings[key] = hs[key];
|
this.hiddenSettings[key] = hs[key];
|
||||||
}
|
}
|
||||||
this.fireDOMEvent('hiddenSettingsChanged');
|
this.fireEvent('hiddenSettingsChanged');
|
||||||
};
|
};
|
||||||
|
|
||||||
// Note: Save only the settings which values differ from the default ones.
|
// Note: Save only the settings which values differ from the default ones.
|
||||||
@ -259,7 +259,7 @@ import {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
self.addEventListener('hiddenSettingsChanged', ( ) => {
|
µb.onEvent('hiddenSettingsChanged', ( ) => {
|
||||||
const µbhs = µb.hiddenSettings;
|
const µbhs = µb.hiddenSettings;
|
||||||
ubologSet(µbhs.consoleLogLevel === 'info');
|
ubologSet(µbhs.consoleLogLevel === 'info');
|
||||||
vAPI.net.setOptions({
|
vAPI.net.setOptions({
|
||||||
@ -364,6 +364,7 @@ self.addEventListener('hiddenSettingsChanged', ( ) => {
|
|||||||
netWhitelist: this.arrayFromWhitelist(this.netWhitelist)
|
netWhitelist: this.arrayFromWhitelist(this.netWhitelist)
|
||||||
});
|
});
|
||||||
this.netWhitelistModifyTime = Date.now();
|
this.netWhitelistModifyTime = Date.now();
|
||||||
|
µb.filteringBehaviorChanged();
|
||||||
};
|
};
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
@ -593,7 +594,7 @@ self.addEventListener('hiddenSettingsChanged', ( ) => {
|
|||||||
|
|
||||||
// https://www.reddit.com/r/uBlockOrigin/comments/cj7g7m/
|
// https://www.reddit.com/r/uBlockOrigin/comments/cj7g7m/
|
||||||
// https://www.reddit.com/r/uBlockOrigin/comments/cnq0bi/
|
// https://www.reddit.com/r/uBlockOrigin/comments/cnq0bi/
|
||||||
vAPI.net.handlerBehaviorChanged();
|
µb.filteringBehaviorChanged();
|
||||||
|
|
||||||
vAPI.messaging.broadcast({ what: 'userFiltersUpdated' });
|
vAPI.messaging.broadcast({ what: 'userFiltersUpdated' });
|
||||||
};
|
};
|
||||||
@ -830,7 +831,7 @@ self.addEventListener('hiddenSettingsChanged', ( ) => {
|
|||||||
staticExtFilteringEngine.freeze();
|
staticExtFilteringEngine.freeze();
|
||||||
redirectEngine.freeze();
|
redirectEngine.freeze();
|
||||||
vAPI.net.unsuspend();
|
vAPI.net.unsuspend();
|
||||||
vAPI.net.handlerBehaviorChanged();
|
µb.filteringBehaviorChanged();
|
||||||
|
|
||||||
vAPI.storage.set({ 'availableFilterLists': µb.availableFilterLists });
|
vAPI.storage.set({ 'availableFilterLists': µb.availableFilterLists });
|
||||||
|
|
||||||
|
@ -187,10 +187,6 @@ const matchBucket = function(url, hostname, bucket, start) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.saveWhitelist();
|
this.saveWhitelist();
|
||||||
|
|
||||||
// Flush memory cache
|
|
||||||
vAPI.net.handlerBehaviorChanged();
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -425,7 +421,7 @@ const matchBucket = function(url, hostname, bucket, start) {
|
|||||||
redirectEngine.invalidateResourcesSelfie(io);
|
redirectEngine.invalidateResourcesSelfie(io);
|
||||||
this.loadRedirectResources();
|
this.loadRedirectResources();
|
||||||
}
|
}
|
||||||
this.fireDOMEvent('hiddenSettingsChanged');
|
this.fireEvent('hiddenSettingsChanged');
|
||||||
};
|
};
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
@ -526,9 +522,7 @@ const matchBucket = function(url, hostname, bucket, start) {
|
|||||||
cosmeticFilteringEngine.removeFromSelectorCache(srcHostname, 'net');
|
cosmeticFilteringEngine.removeFromSelectorCache(srcHostname, 'net');
|
||||||
|
|
||||||
// Flush memory cache
|
// Flush memory cache
|
||||||
if ( action === 1 ) {
|
µb.filteringBehaviorChanged();
|
||||||
vAPI.net.handlerBehaviorChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( details.tabId === undefined ) { return; }
|
if ( details.tabId === undefined ) { return; }
|
||||||
|
|
||||||
@ -614,7 +608,7 @@ const matchBucket = function(url, hostname, bucket, start) {
|
|||||||
switch ( details.name ) {
|
switch ( details.name ) {
|
||||||
case 'no-scripting':
|
case 'no-scripting':
|
||||||
case 'no-remote-fonts':
|
case 'no-remote-fonts':
|
||||||
vAPI.net.handlerBehaviorChanged();
|
µb.filteringBehaviorChanged();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
@ -675,7 +669,7 @@ const matchBucket = function(url, hostname, bucket, start) {
|
|||||||
|
|
||||||
parse();
|
parse();
|
||||||
|
|
||||||
self.addEventListener('hiddenSettingsChanged', ( ) => { parse(); });
|
µb.onEvent('hiddenSettingsChanged', ( ) => { parse(); });
|
||||||
}
|
}
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
@ -134,16 +134,32 @@ import µb from './background.js';
|
|||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
µb.fireDOMEvent = function(name) {
|
µb.fireEvent = function(name) {
|
||||||
if (
|
if (
|
||||||
window instanceof Object &&
|
self instanceof Object &&
|
||||||
window.dispatchEvent instanceof Function &&
|
self.dispatchEvent instanceof Function &&
|
||||||
window.CustomEvent instanceof Function
|
self.CustomEvent instanceof Function
|
||||||
) {
|
) {
|
||||||
window.dispatchEvent(new CustomEvent(name));
|
self.dispatchEvent(new CustomEvent(name));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
µb.onEvent = function(name, fn) {
|
||||||
|
if (
|
||||||
|
self instanceof Object &&
|
||||||
|
self.addEventListener instanceof Function
|
||||||
|
) {
|
||||||
|
self.addEventListener(name, fn);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/******************************************************************************/
|
||||||
|
|
||||||
|
µb.filteringBehaviorChanged = function() {
|
||||||
|
vAPI.net.handlerBehaviorChanged();
|
||||||
|
this.fireEvent('filteringBehaviorChanged');
|
||||||
|
};
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
// TODO: properly compare arrays
|
// TODO: properly compare arrays
|
||||||
|
Loading…
Reference in New Issue
Block a user