Skip to content

Commit

Permalink
Bug 913855. Fix consumers of window mediator to be more consistent in…
Browse files Browse the repository at this point in the history
… their checking for closed windows. r=dolske

Note that we can't just stop returning closed windows from the window
mediator, because some consumers (e.g. session restore) rely on seeing
closed windows in the list so they can remove them from their internal
data structures expeditiouly.
  • Loading branch information
bzbarsky committed Sep 13, 2013
1 parent 17009bf commit 0c4e2cc
Show file tree
Hide file tree
Showing 12 changed files with 25 additions and 6 deletions.
1 change: 1 addition & 0 deletions addon-sdk/source/lib/sdk/window/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
5 changes: 4 additions & 1 deletion browser/base/content/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions browser/base/content/utilityOverlay.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
1 change: 1 addition & 0 deletions browser/components/nsBrowserGlue.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion browser/devtools/webconsole/webconsole.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
3 changes: 3 additions & 0 deletions browser/modules/webappsUI.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion mobile/android/chrome/content/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion toolkit/components/help/content/contextHelp.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
2 changes: 1 addition & 1 deletion toolkit/components/social/MozSocialAPI.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions toolkit/content/globalOverlay.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ function closeWindow(aClose, aPromptFunction)

while (e.hasMoreElements()) {
var w = e.getNext();
if (w.closed) {
continue;
}
if (++windowCount == 2)
break;
}
Expand Down
3 changes: 3 additions & 0 deletions toolkit/mozapps/extensions/content/extensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion xpfe/appshell/public/nsIWindowMediator.idl
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ interface nsIWindowMediator: nsISupports
* windows of this type. ("type" is the
* |windowtype| attribute of the XML <window> 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);

Expand Down

0 comments on commit 0c4e2cc

Please sign in to comment.