Raymond Hill 2018-10-29 09:56:51 -03:00
parent fa3eaf13c6
commit 6d9382a501
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
3 changed files with 65 additions and 25 deletions

View File

@ -50,6 +50,7 @@ var µBlock = (function() { // jshint ignore:line
manualUpdateAssetFetchPeriod: 500,
popupFontSize: 'unset',
requestJournalProcessPeriod: 1000,
strictBlockingBypassDuration: 120,
suspendTabsUntilReady: false,
userResourcesLocation: 'unset'
};

View File

@ -1261,11 +1261,11 @@ var onMessage = function(request, sender, callback) {
}
// Sync
var response;
let response;
switch ( request.what ) {
case 'temporarilyWhitelistDocument':
µBlock.webRequest.temporarilyWhitelistDocument(request.hostname);
µBlock.webRequest.strictBlockBypass(request.hostname);
break;
default:

View File

@ -196,7 +196,10 @@ var onBeforeRootFrameRequest = function(details) {
}
// Permanently unrestricted?
if ( result === 0 && µb.sessionSwitches.evaluateZ('no-strict-blocking', requestHostname) ) {
if (
result === 0 &&
µb.sessionSwitches.evaluateZ('no-strict-blocking', requestHostname)
) {
result = 2;
if ( logEnabled ) {
logData = { engine: 'u', result: 2, raw: 'no-strict-blocking: ' + µb.sessionSwitches.z + ' true' };
@ -204,10 +207,13 @@ var onBeforeRootFrameRequest = function(details) {
}
// Temporarily whitelisted?
if ( result === 0 ) {
result = isTemporarilyWhitelisted(result, requestHostname);
if ( result === 2 && logEnabled === true ) {
logData = { engine: 'u', result: 2, raw: 'no-strict-blocking true (temporary)' };
if (
result === 0 &&
strictBlockBypasser.isBypassed(requestHostname)
) {
result = 2;
if ( logEnabled ) {
logData = { engine: 'u', result: 2, raw: 'no-strict-blocking: true (temporary)' };
}
}
@ -1074,24 +1080,58 @@ var headerValueFromName = function(headerName, headers) {
/******************************************************************************/
var isTemporarilyWhitelisted = function(result, hostname) {
for (;;) {
let obsolete = documentWhitelists.get(hostname);
if ( obsolete !== undefined ) {
if ( obsolete > Date.now() ) {
if ( result === 0 ) { return 2; }
} else {
documentWhitelists.delete(hostname);
let strictBlockBypasser = {
hostnameToDeadlineMap: new Map(),
cleanupTimer: undefined,
cleanup: function() {
for ( let [ hostname, deadline ] of this.hostnameToDeadlineMap ) {
if ( deadline <= Date.now() ) {
this.hostnameToDeadlineMap.delete(hostname);
}
}
let pos = hostname.indexOf('.');
if ( pos === -1 ) { break; }
hostname = hostname.slice(pos + 1);
}
return result;
};
},
let documentWhitelists = new Map();
bypass: function(hostname) {
if ( typeof hostname !== 'string' || hostname === '' ) { return; }
this.hostnameToDeadlineMap.set(
hostname,
Date.now() + µBlock.hiddenSettings.strictBlockingBypassDuration * 1000
);
},
isBypassed: function(hostname) {
if ( this.hostnameToDeadlineMap.size === 0 ) { return false; }
let bypassDuration =
µBlock.hiddenSettings.strictBlockingBypassDuration * 1000;
if ( this.cleanupTimer === undefined ) {
this.cleanupTimer = vAPI.setTimeout(
( ) => {
this.cleanupTimer = undefined;
this.cleanup();
},
bypassDuration + 10000
);
}
for (;;) {
let deadline = this.hostnameToDeadlineMap.get(hostname);
if ( deadline !== undefined ) {
if ( deadline > Date.now() ) {
this.hostnameToDeadlineMap.set(
hostname,
Date.now() + bypassDuration
);
return true;
}
this.hostnameToDeadlineMap.delete(hostname);
}
let pos = hostname.indexOf('.');
if ( pos === -1 ) { break; }
hostname = hostname.slice(pos + 1);
}
return false;
}
};
/******************************************************************************/
@ -1156,9 +1196,8 @@ return {
};
})(),
temporarilyWhitelistDocument: function(hostname) {
if ( typeof hostname !== 'string' || hostname === '' ) { return; }
documentWhitelists.set(hostname, Date.now() + 60 * 1000);
strictBlockBypass: function(hostname) {
strictBlockBypasser.bypass(hostname);
}
};