2

I'm creating a Firefox extension, in which I want to iterate through the Application.windows array and check if one of its elements is the same as Application.activeWindow.
The mentioned excerpt from my code looks like this:

for (var i in Application.windows) {
    if (Application.windows[i]==Application.activeWindow) alert('debug');
    // there was some more complex code than alert('debug'),
    // but since it didn't work, I decided to try with an alert
}

Unfortunately, the 'debug' alert is never viewed. Thus I decided to try this code (with only one window opened):

// the following code runs in an event listener for window.onload
alert(Application.windows[0]);
alert(Application.activeWindow);
alert(Application.windows[0]==Application.activeWindow);

Firefox displayed 3 alerts: the first one was [object Object], the second one - [xpconnect wrapped fuelIWindow], and the last one (which didn't surprise me) said false. So it seems the objects I'm trying to compare have different types. How can I deal with this? Thanks in advance.

rhino
  • 13,543
  • 9
  • 37
  • 39

1 Answers1

1

You have two problems.

The first is that XPConnect doesn't support array-valued properties, so when FUEL (or STEEL or SMILE) return an array, they're actually returning an nsIVariant of internal objects! On the other hand, single-valued objects return an XPConnect wrapper which hides the internal object.

The second is that each time you access windows or activeWindow, new internal objects are created, so even two calls to activeWindow return different objects.

The way around this is to avoid FUEL and enumerate the windows directly using the window mediator.

Neil
  • 54,642
  • 8
  • 60
  • 72
  • Thank you for the solution and for valuable information. I've managed to achieve the desired result using the window mediator. – rhino Apr 10 '11 at 22:15