diff --git a/browser/components/sessionstore/SessionStore.jsm b/browser/components/sessionstore/SessionStore.jsm index 69fafba31885..d22ee8c38936 100644 --- a/browser/components/sessionstore/SessionStore.jsm +++ b/browser/components/sessionstore/SessionStore.jsm @@ -1488,22 +1488,33 @@ var SessionStoreInternal = { * @return Promise */ flushAllWindowsAsync: Task.async(function*(progress={}) { - let windowPromises = []; + let windowPromises = new Map(); // We collect flush promises and close each window immediately so that // the user can't start changing any window state while we're waiting // for the flushes to finish. this._forEachBrowserWindow((win) => { - windowPromises.push(TabStateFlusher.flushWindow(win)); - win.close(); + windowPromises.set(win, TabStateFlusher.flushWindow(win)); + + // We have to wait for these messages to come up from + // each window and each browser. In the meantime, hide + // the windows to improve perceived shutdown speed. + let baseWin = win.QueryInterface(Ci.nsIInterfaceRequestor) + .getInterface(Ci.nsIDocShell) + .QueryInterface(Ci.nsIDocShellTreeItem) + .treeOwner + .QueryInterface(Ci.nsIBaseWindow); + baseWin.visibility = false; }); - progress.total = windowPromises.length; + progress.total = windowPromises.size; + progress.current = 0; // We'll iterate through the Promise array, yielding each one, so as to // provide useful progress information to AsyncShutdown. - for (let i = 0; i < windowPromises.length; ++i) { - progress.current = i; - yield windowPromises[i]; + for (let [win, promise] of windowPromises) { + yield promise; + this._collectWindowData(win); + progress.current++; }; // We must cache this because _getMostRecentBrowserWindow will always