mirror of
https://github.com/gorhill/uBlock.git
synced 2024-11-10 09:07:54 +01:00
Flush the registered scriptlet cache as needed only
Related commit:
e5b438257f
This commit is contained in:
parent
f1ce3b2191
commit
8c283d4d38
5 changed files with 38 additions and 14 deletions
|
@ -345,6 +345,7 @@ const onMessage = function(request, sender, callback) {
|
|||
case 'setWhitelist':
|
||||
µb.netWhitelist = µb.whitelistFromString(request.whitelist);
|
||||
µb.saveWhitelist();
|
||||
µb.filteringBehaviorChanged();
|
||||
break;
|
||||
|
||||
case 'toggleHostnameSwitch':
|
||||
|
|
|
@ -67,7 +67,12 @@ const contentScriptRegisterer = new (class {
|
|||
constructor() {
|
||||
this.hostnameToDetails = new Map();
|
||||
if ( browser.contentScripts === undefined ) { return; }
|
||||
µb.onEvent('filteringBehaviorChanged', ( ) => {
|
||||
µb.onEvent('filteringBehaviorChanged', ev => {
|
||||
const details = ev.detail;
|
||||
if ( details instanceof Object ) {
|
||||
if ( details.direction > 0 ) { return; }
|
||||
if ( details.hostname ) { return this.flush(details.hostname); }
|
||||
}
|
||||
this.reset();
|
||||
});
|
||||
}
|
||||
|
@ -100,6 +105,15 @@ const contentScriptRegisterer = new (class {
|
|||
this.hostnameToDetails.delete(hostname);
|
||||
this.unregisterHandle(details.handle);
|
||||
}
|
||||
flush(hostname) {
|
||||
if ( hostname === '*' ) { return this.reset(); }
|
||||
for ( const hn of this.hostnameToDetails.keys() ) {
|
||||
if ( hn.endsWith(hostname) === false ) { continue; }
|
||||
const pos = hn.length - hostname.length;
|
||||
if ( pos !== 0 && hn.charCodeAt(pos-1) !== 0x2E /* . */ ) { continue; }
|
||||
this.unregister(hn);
|
||||
}
|
||||
}
|
||||
reset() {
|
||||
if ( this.hostnameToDetails.size === 0 ) { return; }
|
||||
for ( const details of this.hostnameToDetails.values() ) {
|
||||
|
|
|
@ -364,7 +364,6 @@ import {
|
|||
netWhitelist: this.arrayFromWhitelist(this.netWhitelist)
|
||||
});
|
||||
this.netWhitelistModifyTime = Date.now();
|
||||
µb.filteringBehaviorChanged();
|
||||
};
|
||||
|
||||
/******************************************************************************/
|
||||
|
|
|
@ -147,6 +147,7 @@ const matchBucket = function(url, hostname, bucket, start) {
|
|||
}
|
||||
bucket.push(directive);
|
||||
this.saveWhitelist();
|
||||
µb.filteringBehaviorChanged({ hostname: targetHostname });
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -187,6 +188,7 @@ const matchBucket = function(url, hostname, bucket, start) {
|
|||
}
|
||||
}
|
||||
this.saveWhitelist();
|
||||
µb.filteringBehaviorChanged({ direction: 1 });
|
||||
return true;
|
||||
};
|
||||
|
||||
|
@ -465,7 +467,8 @@ const matchBucket = function(url, hostname, bucket, start) {
|
|||
// (but not really) redundant rules led to this issue.
|
||||
|
||||
µb.toggleFirewallRule = function(details) {
|
||||
let { srcHostname, desHostname, requestType, action } = details;
|
||||
const { desHostname, requestType, action } = details;
|
||||
let { srcHostname } = details;
|
||||
|
||||
if ( action !== 0 ) {
|
||||
sessionFirewall.setCell(
|
||||
|
@ -495,8 +498,7 @@ const matchBucket = function(url, hostname, bucket, start) {
|
|||
permanentFirewall.unsetCell(
|
||||
srcHostname,
|
||||
desHostname,
|
||||
requestType,
|
||||
action
|
||||
requestType
|
||||
);
|
||||
}
|
||||
this.savePermanentFirewallRules();
|
||||
|
@ -521,8 +523,11 @@ const matchBucket = function(url, hostname, bucket, start) {
|
|||
// https://github.com/chrisaljoudi/uBlock/issues/420
|
||||
cosmeticFilteringEngine.removeFromSelectorCache(srcHostname, 'net');
|
||||
|
||||
// Flush memory cache
|
||||
µb.filteringBehaviorChanged();
|
||||
// Flush caches
|
||||
µb.filteringBehaviorChanged({
|
||||
direction: action === 1 ? 1 : 0,
|
||||
hostname: srcHostname,
|
||||
});
|
||||
|
||||
if ( details.tabId === undefined ) { return; }
|
||||
|
||||
|
@ -603,12 +608,15 @@ const matchBucket = function(url, hostname, bucket, start) {
|
|||
break;
|
||||
}
|
||||
|
||||
// Flush memory cache if needed
|
||||
// Flush caches if needed
|
||||
if ( newState ) {
|
||||
switch ( details.name ) {
|
||||
case 'no-scripting':
|
||||
case 'no-remote-fonts':
|
||||
µb.filteringBehaviorChanged();
|
||||
µb.filteringBehaviorChanged({
|
||||
direction: details.state ? 1 : 0,
|
||||
hostname: details.hostname,
|
||||
});
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
|
|
@ -134,13 +134,13 @@ import µb from './background.js';
|
|||
|
||||
/******************************************************************************/
|
||||
|
||||
µb.fireEvent = function(name) {
|
||||
µb.fireEvent = function(name, details = undefined) {
|
||||
if (
|
||||
self instanceof Object &&
|
||||
self.dispatchEvent instanceof Function &&
|
||||
self.CustomEvent instanceof Function
|
||||
) {
|
||||
self.dispatchEvent(new CustomEvent(name));
|
||||
self.dispatchEvent(new CustomEvent(name, { detail: details }));
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -155,9 +155,11 @@ import µb from './background.js';
|
|||
|
||||
/******************************************************************************/
|
||||
|
||||
µb.filteringBehaviorChanged = function() {
|
||||
µb.filteringBehaviorChanged = function(details = {}) {
|
||||
if ( typeof details.direction !== 'number' || details.direction >= 0 ) {
|
||||
vAPI.net.handlerBehaviorChanged();
|
||||
this.fireEvent('filteringBehaviorChanged');
|
||||
}
|
||||
this.fireEvent('filteringBehaviorChanged', details);
|
||||
};
|
||||
|
||||
/******************************************************************************/
|
||||
|
|
Loading…
Reference in a new issue