code review: only clients of win watcher care about window type

This commit is contained in:
gorhill 2015-10-22 18:27:24 -04:00
parent afd77a3cef
commit 0eb0708a5b
1 changed files with 5 additions and 10 deletions

View File

@ -580,6 +580,7 @@ var winWatcher = (function() {
} }
addWindow(win); addWindow(win);
}, },
onCloseWindow: function(aWindow) { onCloseWindow: function(aWindow) {
var win; var win;
try { try {
@ -589,6 +590,7 @@ var winWatcher = (function() {
} }
removeWindow(win); removeWindow(win);
}, },
observe: function(aSubject, topic) { observe: function(aSubject, topic) {
// https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIWindowWatcher#registerNotification%28%29 // https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIWindowWatcher#registerNotification%28%29
// "aSubject - the window being opened or closed, sent as an // "aSubject - the window being opened or closed, sent as an
@ -613,10 +615,10 @@ var winWatcher = (function() {
}; };
(function() { (function() {
var win, winumerator, docElement; var winumerator, win;
// https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIWindowMediator#getEnumerator%28%29 // https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIWindowMediator#getEnumerator%28%29
winumerator = Services.wm.getEnumerator(chromeWindowType); winumerator = Services.wm.getEnumerator(null);
while ( winumerator.hasMoreElements() ) { while ( winumerator.hasMoreElements() ) {
win = winumerator.getNext(); win = winumerator.getNext();
if ( !win.closed ) { if ( !win.closed ) {
@ -630,14 +632,7 @@ var winWatcher = (function() {
win = winumerator.getNext() win = winumerator.getNext()
.QueryInterface(Ci.nsIInterfaceRequestor) .QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindow); .getInterface(Ci.nsIDOMWindow);
if ( win.closed ) { if ( !win.closed ) {
continue;
}
docElement = win.document && win.document.documentElement;
if ( !docElement ) {
continue;
}
if ( docElement.getAttribute('windowtype') === chromeWindowType ) {
windowToIdMap.set(win, windowIdGenerator++); windowToIdMap.set(win, windowIdGenerator++);
} }
} }