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