1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-11-16 23:42:39 +01:00

Fix for #1448: Raise tab close events for all the tabs of a window when that window is closed. Made getTabForBrowser robust to being called for orphaned tab browsers.

This commit is contained in:
AlexVallat 2015-06-23 18:09:32 +01:00
parent eb264c6b87
commit 204404db06

View File

@ -330,9 +330,46 @@ var windowWatcher = {
}, },
onClosed: function(win) {
win.removeEventListener('DOMContentLoaded', this.onReady);
var tabContainer;
var tabBrowser = getTabBrowser(win);
if ( !tabBrowser ) {
return;
}
if ( tabBrowser.deck ) {
// Fennec
tabContainer = tabBrowser.deck;
} else if ( tabBrowser.tabContainer ) {
tabContainer = tabBrowser.tabContainer;
}
tabContainer.removeEventListener('TabClose', tabWatcher.onTabClose);
tabContainer.removeEventListener('TabSelect', tabWatcher.onTabSelect);
for ( var tab of tabBrowser.tabs ) {
tabWatcher.onTabClose({ target: tab });
var browser = getBrowserForTab(tab);
if ( browser === null ) {
continue;
}
// Close extension tabs
var URI = browser.currentURI;
if ( URI.schemeIs('chrome') && URI.host === location.host ) {
vAPI.tabs._remove(tab, getTabBrowser(win));
}
}
},
observe: function(win, topic) { observe: function(win, topic) {
if ( topic === 'domwindowopened' ) { if ( topic === 'domwindowopened' ) {
win.addEventListener('DOMContentLoaded', this.onReady); win.addEventListener('DOMContentLoaded', this.onReady);
} else if (topic === 'domwindowclosed') {
this.onClosed(win);
} }
} }
}; };
@ -383,6 +420,9 @@ var getTabForBrowser = function(browser) {
return null; return null;
} }
var win = browser.ownerGlobal; var win = browser.ownerGlobal;
if ( !win ) {
return null;
}
if (vAPI.fennec) { if (vAPI.fennec) {
return win.BrowserApp && win.BrowserApp.getTabForBrowser(browser); return win.BrowserApp && win.BrowserApp.getTabForBrowser(browser);
} else { } else {
@ -447,35 +487,7 @@ vAPI.tabs.registerListeners = function() {
vAPI.contextMenu.remove(); vAPI.contextMenu.remove();
for ( var win of vAPI.tabs.getWindows() ) { for ( var win of vAPI.tabs.getWindows() ) {
win.removeEventListener('DOMContentLoaded', windowWatcher.onReady); windowWatcher.onClosed(win);
var tabContainer;
var tabBrowser = getTabBrowser(win);
if ( !tabBrowser ) {
continue;
}
if ( tabBrowser.deck ) {
// Fennec
tabContainer = tabBrowser.deck;
} else if ( tabBrowser.tabContainer ) {
tabContainer = tabBrowser.tabContainer;
}
tabContainer.removeEventListener('TabClose', tabWatcher.onTabClose);
tabContainer.removeEventListener('TabSelect', tabWatcher.onTabSelect);
// Close extension tabs
for ( var tab of tabBrowser.tabs ) {
var browser = getBrowserForTab(tab);
if ( browser === null ) {
continue;
}
var URI = browser.currentURI;
if ( URI.schemeIs('chrome') && URI.host === location.host ) {
vAPI.tabs._remove(tab, getTabBrowser(win));
}
}
} }
}); });
}; };