mirror of https://github.com/gorhill/uBlock.git
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) {
|
||||
if ( !response ) {
|
||||
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);
|
||||
|
|
|
@ -38,7 +38,7 @@ if ( document instanceof HTMLDocument === false ) {
|
|||
}
|
||||
|
||||
// This can happen
|
||||
if ( !vAPI || !vAPI.messaging ) {
|
||||
if ( !vAPI ) {
|
||||
//console.debug('contentscript-end.js > vAPI not found');
|
||||
return;
|
||||
}
|
||||
|
@ -58,33 +58,12 @@ if ( vAPI.contentscriptEndInjected ) {
|
|||
vAPI.contentscriptEndInjected = true;
|
||||
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');
|
||||
|
||||
// https://github.com/gorhill/uMatrix/issues/144
|
||||
shutdownJobs.add(function() {
|
||||
vAPI.shutdown.add(function() {
|
||||
messager.close();
|
||||
});
|
||||
|
||||
|
@ -151,7 +130,7 @@ var uBlockCollapser = (function() {
|
|||
var onProcessed = function(response) {
|
||||
// https://github.com/gorhill/uMatrix/issues/144
|
||||
if ( response.shutdown ) {
|
||||
shutdownJobs.exec();
|
||||
vAPI.shutdown.exec();
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -368,7 +347,7 @@ var uBlockCollapser = (function() {
|
|||
var nextRetrieveHandler = function(response) {
|
||||
// https://github.com/gorhill/uMatrix/issues/144
|
||||
if ( response && response.shutdown ) {
|
||||
shutdownJobs.exec();
|
||||
vAPI.shutdown.exec();
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -740,7 +719,7 @@ var uBlockCollapser = (function() {
|
|||
});
|
||||
|
||||
// https://github.com/gorhill/uMatrix/issues/144
|
||||
shutdownJobs.add(function() {
|
||||
vAPI.shutdown.add(function() {
|
||||
treeObserver.disconnect();
|
||||
if ( addedNodeListsTimer !== null ) {
|
||||
clearTimeout(addedNodeListsTimer);
|
||||
|
@ -767,7 +746,7 @@ var uBlockCollapser = (function() {
|
|||
document.addEventListener('error', onResourceFailed, true);
|
||||
|
||||
// https://github.com/gorhill/uMatrix/issues/144
|
||||
shutdownJobs.add(function() {
|
||||
vAPI.shutdown.add(function() {
|
||||
document.removeEventListener('error', onResourceFailed, true);
|
||||
});
|
||||
})();
|
||||
|
@ -831,7 +810,7 @@ var uBlockCollapser = (function() {
|
|||
window.addEventListener('contextmenu', onContextMenu, true);
|
||||
|
||||
// https://github.com/gorhill/uMatrix/issues/144
|
||||
shutdownJobs.add(function() {
|
||||
vAPI.shutdown.add(function() {
|
||||
document.removeEventListener('contextmenu', onContextMenu, true);
|
||||
});
|
||||
})();
|
||||
|
|
|
@ -41,7 +41,7 @@ if ( document instanceof HTMLDocument === false ) {
|
|||
}
|
||||
|
||||
// This can happen
|
||||
if ( !vAPI || !vAPI.messaging ) {
|
||||
if ( !vAPI ) {
|
||||
//console.debug('contentscript-start.js > vAPI not found');
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -36,7 +36,7 @@ if ( document instanceof HTMLDocument === false ) {
|
|||
}
|
||||
|
||||
// This can happen
|
||||
if ( !vAPI || !vAPI.messaging ) {
|
||||
if ( !vAPI ) {
|
||||
//console.debug('cosmetic-count.js > no vAPI');
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -36,7 +36,7 @@ if ( document instanceof HTMLDocument === false ) {
|
|||
}
|
||||
|
||||
// This can happen
|
||||
if ( !vAPI || !vAPI.messaging ) {
|
||||
if ( !vAPI ) {
|
||||
//console.debug('cosmetic-off.js > no vAPI');
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -36,7 +36,7 @@ if ( document instanceof HTMLDocument === false ) {
|
|||
}
|
||||
|
||||
// This can happen
|
||||
if ( !vAPI || !vAPI.messaging ) {
|
||||
if ( !vAPI ) {
|
||||
//console.debug('cosmetic-on.js > no vAPI');
|
||||
return;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue