Flush memory cache at key filtering profile changes

To reduce the need for hard reload after changes in filters,
rules.
This commit is contained in:
Raymond Hill 2023-04-03 10:19:06 -04:00
parent daee72b982
commit 6e8aeae283
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
4 changed files with 50 additions and 21 deletions

View File

@ -1298,6 +1298,9 @@ vAPI.Net = class {
this.listenerMap.set(clientListener, actualListener);
return actualListener;
}
handlerBehaviorChanged() {
browser.webRequest.handlerBehaviorChanged();
}
onUnprocessedRequest(details) {
const { tabId } = details;
if ( tabId === -1 ) { return; }

View File

@ -459,6 +459,10 @@ if ( selfieIsValid !== true ) {
}
}
// Flush memory cache -- unsure whether the browser does this internally
// when loading a new extension.
vAPI.net.handlerBehaviorChanged();
// Final initialization steps after all needed assets are in memory.
// https://github.com/uBlockOrigin/uBlock-issues/issues/974

View File

@ -19,7 +19,7 @@
Home: https://github.com/gorhill/uBlock
*/
/* globals browser, WebAssembly */
/* globals WebAssembly */
'use strict';
@ -581,9 +581,7 @@ self.addEventListener('hiddenSettingsChanged', ( ) => {
// https://www.reddit.com/r/uBlockOrigin/comments/cj7g7m/
// https://www.reddit.com/r/uBlockOrigin/comments/cnq0bi/
if ( options.killCache ) {
browser.webRequest.handlerBehaviorChanged();
}
vAPI.net.handlerBehaviorChanged();
vAPI.messaging.broadcast({ what: 'userFiltersUpdated' });
};
@ -818,6 +816,7 @@ self.addEventListener('hiddenSettingsChanged', ( ) => {
staticExtFilteringEngine.freeze();
redirectEngine.freeze();
vAPI.net.unsuspend();
vAPI.net.handlerBehaviorChanged();
vAPI.storage.set({ 'availableFilterLists': µb.availableFilterLists });

View File

@ -187,6 +187,10 @@ const matchBucket = function(url, hostname, bucket, start) {
}
}
this.saveWhitelist();
// Flush memory cache
vAPI.net.handlerBehaviorChanged();
return true;
};
@ -521,6 +525,11 @@ const matchBucket = function(url, hostname, bucket, start) {
// https://github.com/chrisaljoudi/uBlock/issues/420
cosmeticFilteringEngine.removeFromSelectorCache(srcHostname, 'net');
// Flush memory cache
if ( action === 1 ) {
vAPI.net.handlerBehaviorChanged();
}
if ( details.tabId === undefined ) { return; }
if ( requestType.startsWith('3p') ) {
@ -577,25 +586,39 @@ const matchBucket = function(url, hostname, bucket, start) {
);
if ( changed === false ) { return; }
// Take action if needed
// Take per-switch action if needed
switch ( details.name ) {
case 'no-scripting':
this.updateToolbarIcon(details.tabId, 0b100);
break;
case 'no-cosmetic-filtering': {
const scriptlet = newState ? 'cosmetic-off' : 'cosmetic-on';
vAPI.tabs.executeScript(details.tabId, {
file: `/js/scriptlets/${scriptlet}.js`,
allFrames: true,
});
break;
}
case 'no-large-media':
const pageStore = this.pageStoreFromTabId(details.tabId);
if ( pageStore !== null ) {
pageStore.temporarilyAllowLargeMediaElements(!newState);
case 'no-scripting':
this.updateToolbarIcon(details.tabId, 0b100);
break;
case 'no-cosmetic-filtering': {
const scriptlet = newState ? 'cosmetic-off' : 'cosmetic-on';
vAPI.tabs.executeScript(details.tabId, {
file: `/js/scriptlets/${scriptlet}.js`,
allFrames: true,
});
break;
}
case 'no-large-media':
const pageStore = this.pageStoreFromTabId(details.tabId);
if ( pageStore !== null ) {
pageStore.temporarilyAllowLargeMediaElements(!newState);
}
break;
default:
break;
}
// Flush memory cache if needed
if ( newState ) {
switch ( details.name ) {
case 'no-scripting':
case 'no-remote-fonts':
vAPI.net.handlerBehaviorChanged();
break;
default:
break;
}
break;
}
if ( details.persist !== true ) { return; }