mirror of https://github.com/gorhill/uBlock.git
This commit is contained in:
parent
cf94ca5576
commit
741c145e90
|
@ -150,6 +150,9 @@ vAPI.messaging = {
|
||||||
},
|
},
|
||||||
close: function() {
|
close: function() {
|
||||||
delete vAPI.messaging.channels[this.channelName];
|
delete vAPI.messaging.channels[this.channelName];
|
||||||
|
if ( Object.keys(vAPI.messaging.channels).length === 0 ) {
|
||||||
|
vAPI.messaging.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -56,10 +56,36 @@ if ( vAPI.contentscriptEndInjected ) {
|
||||||
}
|
}
|
||||||
vAPI.contentscriptEndInjected = true;
|
vAPI.contentscriptEndInjected = true;
|
||||||
|
|
||||||
|
/******************************************************************************/
|
||||||
|
/******************************************************************************/
|
||||||
|
|
||||||
|
var shutdownJobs = (function() {
|
||||||
|
var jobs = [];
|
||||||
|
|
||||||
|
return {
|
||||||
|
add: function(job) {
|
||||||
|
jobs.push(job);
|
||||||
|
},
|
||||||
|
exec: function() {
|
||||||
|
//console.debug('Shutting down...');
|
||||||
|
var job;
|
||||||
|
while ( job = jobs.pop() ) {
|
||||||
|
job();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
})();
|
||||||
|
|
||||||
|
/******************************************************************************/
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
var messager = vAPI.messaging.channel('contentscript-end.js');
|
var messager = vAPI.messaging.channel('contentscript-end.js');
|
||||||
|
|
||||||
|
// https://github.com/gorhill/uMatrix/issues/144
|
||||||
|
shutdownJobs.add(function() {
|
||||||
|
messager.close();
|
||||||
|
});
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
// https://github.com/chrisaljoudi/uBlock/issues/789
|
// https://github.com/chrisaljoudi/uBlock/issues/789
|
||||||
|
@ -119,7 +145,14 @@ var uBlockCollapser = (function() {
|
||||||
this.collapse = false;
|
this.collapse = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
var onProcessed = function(requests) {
|
var onProcessed = function(response) {
|
||||||
|
// https://github.com/gorhill/uMatrix/issues/144
|
||||||
|
if ( response.shutdown ) {
|
||||||
|
shutdownJobs.exec();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var requests = response.result;
|
||||||
if ( requests === null || Array.isArray(requests) === false ) {
|
if ( requests === null || Array.isArray(requests) === false ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -314,24 +347,32 @@ var uBlockCollapser = (function() {
|
||||||
firstRetrieveHandler = null;
|
firstRetrieveHandler = null;
|
||||||
|
|
||||||
// These are sent only once
|
// These are sent only once
|
||||||
if ( response ) {
|
var result = response && response.result;
|
||||||
if ( response.highGenerics ) {
|
if ( result ) {
|
||||||
highGenerics = response.highGenerics;
|
if ( result.highGenerics ) {
|
||||||
|
highGenerics = result.highGenerics;
|
||||||
}
|
}
|
||||||
if ( response.donthide ) {
|
if ( result.donthide ) {
|
||||||
processLowGenerics(response.donthide, nullArray);
|
processLowGenerics(result.donthide, nullArray);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
nextRetrieveHandler(response);
|
nextRetrieveHandler(response);
|
||||||
};
|
};
|
||||||
|
|
||||||
var nextRetrieveHandler = function(selectors) {
|
var nextRetrieveHandler = function(response) {
|
||||||
|
// https://github.com/gorhill/uMatrix/issues/144
|
||||||
|
if ( response && response.shutdown ) {
|
||||||
|
shutdownJobs.exec();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
//var tStart = timer.now();
|
//var tStart = timer.now();
|
||||||
//console.debug('µBlock> contextNodes = %o', contextNodes);
|
//console.debug('µBlock> contextNodes = %o', contextNodes);
|
||||||
|
var result = response && response.result;
|
||||||
var hideSelectors = [];
|
var hideSelectors = [];
|
||||||
if ( selectors && selectors.hide.length ) {
|
if ( result && result.hide.length ) {
|
||||||
processLowGenerics(selectors.hide, hideSelectors);
|
processLowGenerics(result.hide, hideSelectors);
|
||||||
}
|
}
|
||||||
if ( highGenerics ) {
|
if ( highGenerics ) {
|
||||||
if ( highGenerics.hideLowCount ) {
|
if ( highGenerics.hideLowCount ) {
|
||||||
|
@ -688,6 +729,14 @@ var uBlockCollapser = (function() {
|
||||||
childList: true,
|
childList: true,
|
||||||
subtree: true
|
subtree: true
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// https://github.com/gorhill/uMatrix/issues/144
|
||||||
|
shutdownJobs.add(function() {
|
||||||
|
treeObserver.disconnect();
|
||||||
|
if ( addedNodeListsTimer !== null ) {
|
||||||
|
clearTimeout(addedNodeListsTimer);
|
||||||
|
}
|
||||||
|
});
|
||||||
})();
|
})();
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
@ -700,6 +749,7 @@ var uBlockCollapser = (function() {
|
||||||
// - Elements dynamically added to the page
|
// - Elements dynamically added to the page
|
||||||
// - Elements which resource URL changes
|
// - Elements which resource URL changes
|
||||||
|
|
||||||
|
(function() {
|
||||||
var onResourceFailed = function(ev) {
|
var onResourceFailed = function(ev) {
|
||||||
//console.debug('onResourceFailed(%o)', ev);
|
//console.debug('onResourceFailed(%o)', ev);
|
||||||
uBlockCollapser.add(ev.target);
|
uBlockCollapser.add(ev.target);
|
||||||
|
@ -707,6 +757,12 @@ var onResourceFailed = function(ev) {
|
||||||
};
|
};
|
||||||
document.addEventListener('error', onResourceFailed, true);
|
document.addEventListener('error', onResourceFailed, true);
|
||||||
|
|
||||||
|
// https://github.com/gorhill/uMatrix/issues/144
|
||||||
|
shutdownJobs.add(function() {
|
||||||
|
document.removeEventListener('error', onResourceFailed, true);
|
||||||
|
});
|
||||||
|
})();
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
|
@ -764,6 +820,11 @@ document.addEventListener('error', onResourceFailed, true);
|
||||||
};
|
};
|
||||||
|
|
||||||
window.addEventListener('contextmenu', onContextMenu, true);
|
window.addEventListener('contextmenu', onContextMenu, true);
|
||||||
|
|
||||||
|
// https://github.com/gorhill/uMatrix/issues/144
|
||||||
|
shutdownJobs.add(function() {
|
||||||
|
document.removeEventListener('contextmenu', onContextMenu, true);
|
||||||
|
});
|
||||||
})();
|
})();
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
|
@ -496,9 +496,12 @@ var onMessage = function(details, sender, callback) {
|
||||||
|
|
||||||
switch ( details.what ) {
|
switch ( details.what ) {
|
||||||
case 'retrieveGenericCosmeticSelectors':
|
case 'retrieveGenericCosmeticSelectors':
|
||||||
if ( pageStore && pageStore.getGenericCosmeticFilteringSwitch()
|
response = {
|
||||||
&& (!frameStore || frameStore.getNetFilteringSwitch()) ) {
|
shutdown: !pageStore || !pageStore.getNetFilteringSwitch() || (frameStore && !frameStore.getNetFilteringSwitch()),
|
||||||
response = µb.cosmeticFilteringEngine.retrieveGenericSelectors(details);
|
result: null
|
||||||
|
};
|
||||||
|
if(pageStore && pageStore.getGenericCosmeticFilteringSwitch()) {
|
||||||
|
response.result = µb.cosmeticFilteringEngine.retrieveGenericSelectors(details);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -508,7 +511,13 @@ var onMessage = function(details, sender, callback) {
|
||||||
|
|
||||||
// Evaluate many requests
|
// Evaluate many requests
|
||||||
case 'filterRequests':
|
case 'filterRequests':
|
||||||
response = filterRequests(pageStore, details);
|
response = {
|
||||||
|
shutdown: !pageStore || !pageStore.getNetFilteringSwitch(),
|
||||||
|
result: null
|
||||||
|
};
|
||||||
|
if(pageStore) {
|
||||||
|
response.result = filterRequests(pageStore, details);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|
Loading…
Reference in New Issue