1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-09-01 16:49:39 +02:00

code review: return asap when in shouldLoadPopupListener

This commit is contained in:
gorhill 2016-06-30 15:47:51 -04:00
parent e6c38257be
commit 8aebf060b8

View File

@ -2331,15 +2331,8 @@ vAPI.net.registerListeners = function() {
} }
var shouldLoadPopupListenerMessageName = location.host + ':shouldLoadPopup'; var shouldLoadPopupListenerMessageName = location.host + ':shouldLoadPopup';
var shouldLoadPopupListener = function(e) { var shouldLoadPopupListener = function(openerURL, popupTabId) {
if ( typeof vAPI.tabs.onPopupCreated !== 'function' ) {
return;
}
var openerURL = e.data;
var popupTabId = tabWatcher.tabIdFromTarget(e.target);
var uri, openerTabId; var uri, openerTabId;
for ( var browser of tabWatcher.browsers() ) { for ( var browser of tabWatcher.browsers() ) {
uri = browser.currentURI; uri = browser.currentURI;
@ -2362,10 +2355,20 @@ vAPI.net.registerListeners = function() {
} }
} }
}; };
var shouldLoadPopupListenerAsync = function(e) {
if ( typeof vAPI.tabs.onPopupCreated !== 'function' ) {
return;
}
// We are handling a synchronous message: do not block.
vAPI.setTimeout(
shouldLoadPopupListener.bind(null, e.data, tabWatcher.tabIdFromTarget(e.target)),
1
);
};
vAPI.messaging.globalMessageManager.addMessageListener( vAPI.messaging.globalMessageManager.addMessageListener(
shouldLoadPopupListenerMessageName, shouldLoadPopupListenerMessageName,
shouldLoadPopupListener shouldLoadPopupListenerAsync
); );
var shouldLoadListenerMessageName = location.host + ':shouldLoad'; var shouldLoadListenerMessageName = location.host + ':shouldLoad';
@ -2451,7 +2454,7 @@ vAPI.net.registerListeners = function() {
cleanupTasks.push(function() { cleanupTasks.push(function() {
vAPI.messaging.globalMessageManager.removeMessageListener( vAPI.messaging.globalMessageManager.removeMessageListener(
shouldLoadPopupListenerMessageName, shouldLoadPopupListenerMessageName,
shouldLoadPopupListener shouldLoadPopupListenerAsync
); );
vAPI.messaging.globalMessageManager.removeMessageListener( vAPI.messaging.globalMessageManager.removeMessageListener(