diff --git a/addon-sdk/source/lib/sdk/window/utils.js b/addon-sdk/source/lib/sdk/window/utils.js index 155d6842b3267d..78de9cb3f05e5a 100644 --- a/addon-sdk/source/lib/sdk/window/utils.js +++ b/addon-sdk/source/lib/sdk/window/utils.js @@ -297,6 +297,7 @@ function windows(type, options) { let window = winEnum.getNext().QueryInterface(Ci.nsIDOMWindow); // Only add non-private windows when pb permission isn't set, // unless an option forces the addition of them. + // XXXbz should this be checking window.closed? if (options.includePrivate || !isWindowPrivate(window)) { list.push(window); } diff --git a/browser/base/content/browser.js b/browser/base/content/browser.js index e30b1f90e3bdfa..80d5b93b070389 100644 --- a/browser/base/content/browser.js +++ b/browser/base/content/browser.js @@ -2177,6 +2177,9 @@ function BrowserPageInfo(doc, initialTab, imageElement) { // Check for windows matching the url while (windows.hasMoreElements()) { var currentWindow = windows.getNext(); + if (currentWindow.closed) { + continue; + } if (currentWindow.document.documentElement.getAttribute("relatedUrl") == documentURL) { currentWindow.focus(); currentWindow.resetPageInfo(args); @@ -6040,7 +6043,7 @@ function warnAboutClosingWindow() { let nonPopupPresent = false; while (e.hasMoreElements()) { let win = e.getNext(); - if (win != window) { + if (!win.closed && win != window) { if (isPBWindow && PrivateBrowsingUtils.isWindowPrivate(win)) otherPBWindowExists = true; if (win.toolbar.visible) diff --git a/browser/base/content/utilityOverlay.js b/browser/base/content/utilityOverlay.js index 0aecd6dd4242e3..ffc116e9013a2c 100644 --- a/browser/base/content/utilityOverlay.js +++ b/browser/base/content/utilityOverlay.js @@ -454,6 +454,9 @@ function openAboutDialog() { while (enumerator.hasMoreElements()) { // Only open one about window (Bug 599573) let win = enumerator.getNext(); + if (win.closed) { + continue; + } win.focus(); return; } diff --git a/browser/components/nsBrowserGlue.js b/browser/components/nsBrowserGlue.js index f9a7fe13a505ce..2423b0cfc08319 100644 --- a/browser/components/nsBrowserGlue.js +++ b/browser/components/nsBrowserGlue.js @@ -769,6 +769,7 @@ BrowserGlue.prototype = { var browserEnum = Services.wm.getEnumerator("navigator:browser"); let allWindowsPrivate = true; while (browserEnum.hasMoreElements()) { + // XXXbz should we skip closed windows here? windowcount++; var browser = browserEnum.getNext(); diff --git a/browser/devtools/webconsole/webconsole.js b/browser/devtools/webconsole/webconsole.js index bc0424520ea588..38b7b5959bfb5b 100644 --- a/browser/devtools/webconsole/webconsole.js +++ b/browser/devtools/webconsole/webconsole.js @@ -2608,7 +2608,7 @@ WebConsoleFrame.prototype = { while (wins.hasMoreElements()) { let win = wins.getNext(); - if (win.Scratchpad.uniqueName === aSourceURL) { + if (!win.closed && win.Scratchpad.uniqueName === aSourceURL) { win.focus(); return; } diff --git a/browser/modules/webappsUI.jsm b/browser/modules/webappsUI.jsm index 3a4c8aea150669..a915733190c901 100644 --- a/browser/modules/webappsUI.jsm +++ b/browser/modules/webappsUI.jsm @@ -81,6 +81,9 @@ this.webappsUI = { let found = false; while (!found && browserEnumerator.hasMoreElements()) { let browserWin = browserEnumerator.getNext(); + if (browserWin.closed) { + continue; + } let tabbrowser = browserWin.gBrowser; // Check each tab of this browser instance diff --git a/mobile/android/chrome/content/browser.js b/mobile/android/chrome/content/browser.js index e673cb1fbbbd3b..0f505e9336c8b2 100644 --- a/mobile/android/chrome/content/browser.js +++ b/mobile/android/chrome/content/browser.js @@ -919,7 +919,7 @@ var BrowserApp = { let e = Services.wm.getEnumerator("navigator:browser"); while (e.hasMoreElements() && lastBrowser) { let win = e.getNext(); - if (win != window) + if (!win.closed && win != window) lastBrowser = false; } diff --git a/toolkit/components/help/content/contextHelp.js b/toolkit/components/help/content/contextHelp.js index cd66615c90e3a9..9c8b6d4a13893a 100644 --- a/toolkit/components/help/content/contextHelp.js +++ b/toolkit/components/help/content/contextHelp.js @@ -61,7 +61,7 @@ function locateHelpWindow(contentPack) { # pack. while (iterator.hasMoreElements()) { aWindow = iterator.getNext(); - if (aWindow.getHelpFileURI() == contentPack) { + if (!aWindow.closed && aWindow.getHelpFileURI() == contentPack) { topWindow = aWindow; } } diff --git a/toolkit/components/social/MozSocialAPI.jsm b/toolkit/components/social/MozSocialAPI.jsm index 65e7b9b1eb460b..599bb4b38d4f9f 100644 --- a/toolkit/components/social/MozSocialAPI.jsm +++ b/toolkit/components/social/MozSocialAPI.jsm @@ -302,7 +302,7 @@ function findChromeWindowForChats(preferredWindow) { } while (enumerator.hasMoreElements()) { let win = enumerator.getNext(); - if (win && isWindowGoodForChats(win)) + if (!win.closed && isWindowGoodForChats(win)) topMost = win; } return topMost; diff --git a/toolkit/content/globalOverlay.js b/toolkit/content/globalOverlay.js index 2665df12e8996f..0c964a2811cf0a 100644 --- a/toolkit/content/globalOverlay.js +++ b/toolkit/content/globalOverlay.js @@ -13,6 +13,9 @@ function closeWindow(aClose, aPromptFunction) while (e.hasMoreElements()) { var w = e.getNext(); + if (w.closed) { + continue; + } if (++windowCount == 2) break; } diff --git a/toolkit/mozapps/extensions/content/extensions.js b/toolkit/mozapps/extensions/content/extensions.js index 6860e5183d54d5..7161bb009ca0de 100644 --- a/toolkit/mozapps/extensions/content/extensions.js +++ b/toolkit/mozapps/extensions/content/extensions.js @@ -927,6 +927,9 @@ var gViewController = { var windows = Services.wm.getEnumerator(null); while (windows.hasMoreElements()) { var win = windows.getNext(); + if (win.closed) { + continue; + } if (win.document.documentURI == optionsURL) { win.focus(); return; diff --git a/xpfe/appshell/public/nsIWindowMediator.idl b/xpfe/appshell/public/nsIWindowMediator.idl index 1114bec9122639..d5c1946b6503d9 100644 --- a/xpfe/appshell/public/nsIWindowMediator.idl +++ b/xpfe/appshell/public/nsIWindowMediator.idl @@ -29,7 +29,9 @@ interface nsIWindowMediator: nsISupports * windows of this type. ("type" is the * |windowtype| attribute of the XML element.) * If null, all windows will be enumerated. - * @return an enumerator of nsIDOMWindows + * @return an enumerator of nsIDOMWindows. Note that windows close + * asynchronously in many cases, so windows returned from this + * enumerator can have .closed set to true. Caveat enumerator! */ nsISimpleEnumerator getEnumerator(in wstring aWindowType);