From 73c8a96c48cfc52c3db6fc54b402ba204bc11a5f Mon Sep 17 00:00:00 2001 From: gorhill Date: Wed, 16 Nov 2016 16:08:03 -0500 Subject: [PATCH] workaround for https://bugzilla.mozilla.org/show_bug.cgi?id=1317173 --- platform/firefox/vapi-background.js | 47 +++++++++++++++++------------ src/js/tab.js | 2 +- 2 files changed, 28 insertions(+), 21 deletions(-) diff --git a/platform/firefox/vapi-background.js b/platform/firefox/vapi-background.js index 4a5b32c7e..d01eb9a36 100644 --- a/platform/firefox/vapi-background.js +++ b/platform/firefox/vapi-background.js @@ -1064,36 +1064,43 @@ vAPI.tabs._remove = (function() { tabBrowser.closeTab(tab); }; } - return function(tab, tabBrowser, nuke) { - if ( !tabBrowser ) { - return; - } - if ( tabBrowser.tabs.length === 1 && nuke ) { - getOwnerWindow(tab).close(); - } else { - tabBrowser.removeTab(tab); - } + return function(tab, tabBrowser) { + if ( !tabBrowser ) { return; } + tabBrowser.removeTab(tab); }; })(); /******************************************************************************/ +// https://bugzilla.mozilla.org/show_bug.cgi?id=1317173 +// Work around FF45 (and earlier) timing issue by delaying the closing +// of tabs. The picked delay is just what seemed to work for the test case +// reported in the issue above. + vAPI.tabs.remove = (function() { - var remove = function(tabId, nuke) { - var browser = tabWatcher.browserFromTabId(tabId); - if ( !browser ) { - return; + var timer = null, + queue = []; + + var remove = function() { + timer = null; + var tabId, browser, tab; + while ( (tabId = queue.pop()) ) { + browser = tabWatcher.browserFromTabId(tabId); + if ( !browser ) { continue; } + tab = tabWatcher.tabFromBrowser(browser); + if ( !tab ) { continue; } + this._remove(tab, getTabBrowser(getOwnerWindow(browser))); } - var tab = tabWatcher.tabFromBrowser(browser); - if ( !tab ) { - return; - } - this._remove(tab, getTabBrowser(getOwnerWindow(browser)), nuke); }; // Do this asynchronously - return function(tabId, nuke) { - vAPI.setTimeout(remove.bind(this, tabId, nuke), 1); + return function(tabId, delay) { + queue.push(tabId); + if ( timer !== null ) { + if ( !delay ) { return; } + clearTimeout(timer); + } + timer = vAPI.setTimeout(remove.bind(this), delay ? 250 : 25); }; })(); diff --git a/src/js/tab.js b/src/js/tab.js index d4b311887..ffad7a4df 100644 --- a/src/js/tab.js +++ b/src/js/tab.js @@ -777,7 +777,7 @@ vAPI.tabs.onPopupUpdated = (function() { // It is a popup, block and remove the tab. if ( popupType === 'popup' ) { µb.unbindTabFromPageStats(targetTabId); - vAPI.tabs.remove(targetTabId, true); + vAPI.tabs.remove(targetTabId, false); } else { µb.unbindTabFromPageStats(openerTabId); vAPI.tabs.remove(openerTabId, true);