mirror of
https://github.com/gorhill/uBlock.git
synced 2024-10-06 09:37:12 +02:00
code review
This commit is contained in:
parent
b10e018846
commit
31bea1d08b
@ -46,6 +46,29 @@ vAPI.chrome = true;
|
|||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
|
vAPI.shutdown = (function() {
|
||||||
|
var jobs = [];
|
||||||
|
|
||||||
|
var add = function(job) {
|
||||||
|
jobs.push(job);
|
||||||
|
};
|
||||||
|
|
||||||
|
var exec = function() {
|
||||||
|
//console.debug('Shutting down...');
|
||||||
|
var job;
|
||||||
|
while ( job = jobs.pop() ) {
|
||||||
|
job();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return {
|
||||||
|
add: add,
|
||||||
|
exec: exec
|
||||||
|
};
|
||||||
|
})();
|
||||||
|
|
||||||
|
/******************************************************************************/
|
||||||
|
|
||||||
var messagingConnector = function(response) {
|
var messagingConnector = function(response) {
|
||||||
if ( !response ) {
|
if ( !response ) {
|
||||||
return;
|
return;
|
||||||
@ -144,6 +167,15 @@ vAPI.messaging = {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// No need to have vAPI client linger around after shutdown if
|
||||||
|
// we are not a top window (because element picker can still
|
||||||
|
// be injected in top window).
|
||||||
|
if ( window !== window.top ) {
|
||||||
|
vAPI.shutdown.add(function() {
|
||||||
|
vAPI = null;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
})(this);
|
})(this);
|
||||||
|
@ -38,7 +38,7 @@ if ( document instanceof HTMLDocument === false ) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// This can happen
|
// This can happen
|
||||||
if ( !vAPI || !vAPI.messaging ) {
|
if ( !vAPI ) {
|
||||||
//console.debug('contentscript-end.js > vAPI not found');
|
//console.debug('contentscript-end.js > vAPI not found');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -58,33 +58,12 @@ if ( vAPI.contentscriptEndInjected ) {
|
|||||||
vAPI.contentscriptEndInjected = true;
|
vAPI.contentscriptEndInjected = true;
|
||||||
vAPI.styles = vAPI.styles || [];
|
vAPI.styles = vAPI.styles || [];
|
||||||
|
|
||||||
/******************************************************************************/
|
|
||||||
/******************************************************************************/
|
|
||||||
|
|
||||||
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
|
// https://github.com/gorhill/uMatrix/issues/144
|
||||||
shutdownJobs.add(function() {
|
vAPI.shutdown.add(function() {
|
||||||
messager.close();
|
messager.close();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -151,7 +130,7 @@ var uBlockCollapser = (function() {
|
|||||||
var onProcessed = function(response) {
|
var onProcessed = function(response) {
|
||||||
// https://github.com/gorhill/uMatrix/issues/144
|
// https://github.com/gorhill/uMatrix/issues/144
|
||||||
if ( response.shutdown ) {
|
if ( response.shutdown ) {
|
||||||
shutdownJobs.exec();
|
vAPI.shutdown.exec();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -368,7 +347,7 @@ var uBlockCollapser = (function() {
|
|||||||
var nextRetrieveHandler = function(response) {
|
var nextRetrieveHandler = function(response) {
|
||||||
// https://github.com/gorhill/uMatrix/issues/144
|
// https://github.com/gorhill/uMatrix/issues/144
|
||||||
if ( response && response.shutdown ) {
|
if ( response && response.shutdown ) {
|
||||||
shutdownJobs.exec();
|
vAPI.shutdown.exec();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -740,7 +719,7 @@ var uBlockCollapser = (function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// https://github.com/gorhill/uMatrix/issues/144
|
// https://github.com/gorhill/uMatrix/issues/144
|
||||||
shutdownJobs.add(function() {
|
vAPI.shutdown.add(function() {
|
||||||
treeObserver.disconnect();
|
treeObserver.disconnect();
|
||||||
if ( addedNodeListsTimer !== null ) {
|
if ( addedNodeListsTimer !== null ) {
|
||||||
clearTimeout(addedNodeListsTimer);
|
clearTimeout(addedNodeListsTimer);
|
||||||
@ -767,7 +746,7 @@ var uBlockCollapser = (function() {
|
|||||||
document.addEventListener('error', onResourceFailed, true);
|
document.addEventListener('error', onResourceFailed, true);
|
||||||
|
|
||||||
// https://github.com/gorhill/uMatrix/issues/144
|
// https://github.com/gorhill/uMatrix/issues/144
|
||||||
shutdownJobs.add(function() {
|
vAPI.shutdown.add(function() {
|
||||||
document.removeEventListener('error', onResourceFailed, true);
|
document.removeEventListener('error', onResourceFailed, true);
|
||||||
});
|
});
|
||||||
})();
|
})();
|
||||||
@ -831,7 +810,7 @@ var uBlockCollapser = (function() {
|
|||||||
window.addEventListener('contextmenu', onContextMenu, true);
|
window.addEventListener('contextmenu', onContextMenu, true);
|
||||||
|
|
||||||
// https://github.com/gorhill/uMatrix/issues/144
|
// https://github.com/gorhill/uMatrix/issues/144
|
||||||
shutdownJobs.add(function() {
|
vAPI.shutdown.add(function() {
|
||||||
document.removeEventListener('contextmenu', onContextMenu, true);
|
document.removeEventListener('contextmenu', onContextMenu, true);
|
||||||
});
|
});
|
||||||
})();
|
})();
|
||||||
|
@ -41,7 +41,7 @@ if ( document instanceof HTMLDocument === false ) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// This can happen
|
// This can happen
|
||||||
if ( !vAPI || !vAPI.messaging ) {
|
if ( !vAPI ) {
|
||||||
//console.debug('contentscript-start.js > vAPI not found');
|
//console.debug('contentscript-start.js > vAPI not found');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,7 @@ if ( document instanceof HTMLDocument === false ) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// This can happen
|
// This can happen
|
||||||
if ( !vAPI || !vAPI.messaging ) {
|
if ( !vAPI ) {
|
||||||
//console.debug('cosmetic-count.js > no vAPI');
|
//console.debug('cosmetic-count.js > no vAPI');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,7 @@ if ( document instanceof HTMLDocument === false ) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// This can happen
|
// This can happen
|
||||||
if ( !vAPI || !vAPI.messaging ) {
|
if ( !vAPI ) {
|
||||||
//console.debug('cosmetic-off.js > no vAPI');
|
//console.debug('cosmetic-off.js > no vAPI');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,7 @@ if ( document instanceof HTMLDocument === false ) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// This can happen
|
// This can happen
|
||||||
if ( !vAPI || !vAPI.messaging ) {
|
if ( !vAPI ) {
|
||||||
//console.debug('cosmetic-on.js > no vAPI');
|
//console.debug('cosmetic-on.js > no vAPI');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user