Bug 1321706: Fix race in closed window handling. r?mikedeboer
MozReview-Commit-ID: KszEE0I7w7e
--- a/browser/components/sessionstore/SessionStore.jsm
+++ b/browser/components/sessionstore/SessionStore.jsm
@@ -2940,17 +2940,19 @@ var SessionStoreInternal = {
/**
* gather session data as object
* @param aUpdateAll
* Bool update all windows
* @returns object
*/
getCurrentState: function (aUpdateAll) {
- this._handleClosedWindows();
+ this._handleClosedWindows().then(() => {
+ this._notifyOfClosedObjectsChange();
+ });
var activeWindow = this._getMostRecentBrowserWindow();
TelemetryStopwatch.start("FX_SESSION_RESTORE_COLLECT_ALL_WINDOWS_DATA_MS");
if (RunState.isRunning) {
// update the data for all windows with activities since the last save operation
this._forEachBrowserWindow(function(aWindow) {
if (!this._isWindowLoaded(aWindow)) // window data is still in _statesToRestore
@@ -4001,22 +4003,24 @@ var SessionStoreInternal = {
/**
* Calls onClose for windows that are determined to be closed but aren't
* destroyed yet, which would otherwise cause getBrowserState and
* setBrowserState to treat them as open windows.
*/
_handleClosedWindows: function ssi_handleClosedWindows() {
var windowsEnum = Services.wm.getEnumerator("navigator:browser");
+ let promises = [];
while (windowsEnum.hasMoreElements()) {
var window = windowsEnum.getNext();
if (window.closed) {
- this.onClose(window);
+ promises.push(this.onClose(window));
}
}
+ return Promise.all(promises);
},
/**
* open a new browser window for a given session state
* called when restoring a multi-window session
* @param aState
* Object containing session data
*/