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

more deferring code re. toolbar icon on legacy Firefox (#833)

This commit is contained in:
gorhill 2015-10-17 16:07:53 -04:00
parent cfdbacd0ad
commit 308dd4bb30

View File

@ -1084,11 +1084,28 @@ var tabWatcher = (function() {
vAPI.setIcon(tabIdFromTarget(target), getOwnerWindow(target)); vAPI.setIcon(tabIdFromTarget(target), getOwnerWindow(target));
}; };
var attachToTabBrowser = function(window) { var attachToTabBrowserLater = function(details) {
var tabBrowser = getTabBrowser(window); details.tryCount = details.tryCount ? details.tryCount + 1 : 1;
if ( !tabBrowser ) { if ( details.tryCount > 5 ) {
return false; return false;
} }
vAPI.setTimeout(function(details) {
attachToTabBrowser(details.window, details.tryCount);
},
200,
details
);
return true;
};
var attachToTabBrowser = function(window, tryCount) {
// On some platforms, the tab browser isn't immediately available,
// try waiting a bit if this happens.
var tabBrowser = getTabBrowser(window);
if ( tabBrowser === null ) {
attachToTabBrowserLater({ window: window, tryCount: tryCount });
return;
}
if ( typeof vAPI.toolbarButton.attachToNewWindow === 'function' ) { if ( typeof vAPI.toolbarButton.attachToNewWindow === 'function' ) {
vAPI.toolbarButton.attachToNewWindow(window); vAPI.toolbarButton.attachToNewWindow(window);
@ -1113,8 +1130,6 @@ var tabWatcher = (function() {
// when new window is opened TabSelect doesn't run on the selected tab? // when new window is opened TabSelect doesn't run on the selected tab?
tabContainer.addEventListener('TabSelect', onSelect); tabContainer.addEventListener('TabSelect', onSelect);
} }
return true;
}; };
var onWindowLoad = function(ev) { var onWindowLoad = function(ev) {
@ -1127,12 +1142,7 @@ var tabWatcher = (function() {
return; return;
} }
// On some platforms, the tab browser isn't immediately available, attachToTabBrowser(this);
// try waiting a bit if this happens.
var win = this;
if ( attachToTabBrowser(win) === false ) {
vAPI.setTimeout(attachToTabBrowser.bind(null, win), 250);
}
}; };
var onWindowUnload = function() { var onWindowUnload = function() {
@ -2352,12 +2362,12 @@ vAPI.toolbarButton = {
var styleSheetUri = null; var styleSheetUri = null;
var addLegacyToolbarButtonLater = function(details) { var addLegacyToolbarButtonLater = function(details) {
var tryCount = details.tryCount ? details.tryCount + 1 : 1; details.tryCount = details.tryCount ? details.tryCount + 1 : 1;
if ( tryCount > 5 ) { if ( details.tryCount > 5 ) {
return false; return false;
} }
vAPI.setTimeout(function(details) { vAPI.setTimeout(function(details) {
addLegacyToolbarButton(details.window, tryCount); addLegacyToolbarButton(details.window, details.tryCount);
}, },
200, 200,
details details