From 7fc1898ae5a207b8c8ca468ca9e15c1da83baeca Mon Sep 17 00:00:00 2001 From: Tim Abraldes Date: Wed, 17 Apr 2013 10:40:38 -0700 Subject: [PATCH] bug 855581. Wait until we've actually closed the last tab to create a new one. DONTBUILD. r=fryn --- browser/metro/base/content/browser-ui.js | 24 +++++----------------- browser/metro/base/content/browser.js | 26 +++++++++++------------- 2 files changed, 17 insertions(+), 33 deletions(-) diff --git a/browser/metro/base/content/browser-ui.js b/browser/metro/base/content/browser-ui.js index caa15188ae1..f8446f0d7ea 100644 --- a/browser/metro/base/content/browser-ui.js +++ b/browser/metro/base/content/browser-ui.js @@ -393,29 +393,15 @@ var BrowserUI = { }, closeTab: function closeTab(aTab) { - // If we only have one tab, open a new one - if (Browser.tabs.length === 1 && !StartUI.isStartURI()) - Browser.addTab(Browser.getHomePage()); - - // We only have the start tab - if (Browser.tabs.length === 1) - return; - // If no tab is passed in, assume the current tab let tab = aTab || Browser.selectedTab; - let tabToClose = tab instanceof XULElement ? Browser.getTabFromChrome(tab) : tab; + Browser.closeTab(tab); + }, + animateClosingTab: function animateClosingTab(tabToClose) { if (this.isTabsOnly) { - Browser.closeTab(tabToClose); + Browser.closeTab(tabToClose, { forceClose: true } ); } else { - let nextTab = Browser.getNextTab(tabToClose); - - if (!nextTab) - return; - - if (nextTab) - Browser.selectedTab = nextTab; - // Trigger closing animation tabToClose.chromeTab.setAttribute("closing", "true"); @@ -425,7 +411,7 @@ var BrowserUI = { } this.setOnTabAnimationEnd(function() { - Browser.closeTab(tabToClose); + Browser.closeTab(tabToClose, { forceClose: true } ); if (wasCollapsed) ContextUI.dismissWithDelay(kNewTabAnimationDelayMsec); }); diff --git a/browser/metro/base/content/browser.js b/browser/metro/base/content/browser.js index 1006a2d88cf..ba18b5f8756 100644 --- a/browser/metro/base/content/browser.js +++ b/browser/metro/base/content/browser.js @@ -453,11 +453,12 @@ var Browser = { closeTab: function closeTab(aTab, aOptions) { let tab = aTab instanceof XULElement ? this.getTabFromChrome(aTab) : aTab; - if (!tab || !this.getNextTab(tab)) + if (!tab) { return; + } if (aOptions && "forceClose" in aOptions && aOptions.forceClose) { - this._doCloseTab(aTab); + this._doCloseTab(tab); return; } @@ -469,9 +470,11 @@ var Browser = { }, _doCloseTab: function _doCloseTab(aTab) { + if (this._tabs.length === 1) { + Browser.addTab(this.getHomePage()); + } + let nextTab = this.getNextTab(aTab); - if (!nextTab) - return; // Tabs owned by the closed tab are now orphaned. this._tabs.forEach(function(item, index, array) { @@ -918,16 +921,11 @@ var Browser = { break; case "Browser:CanUnload:Return": { - if (!json.permit) - return; - - // Allow a little delay to not close the target tab while processing - // a message for this particular tab - setTimeout(function(self) { - let tab = self.getTabForBrowser(browser); - self._doCloseTab(tab); - }, 0, this); - break; + if (json.permit) { + let tab = this.getTabForBrowser(browser); + BrowserUI.animateClosingTab(tab); + } + break; } case "Browser:ZoomToPoint:Return": if (json.zoomTo) {