E10S - getting window IDs

My addon (sixornot) relies on storing information about http requests in a cache which is indexed by the window IDs (eg. nsidomwindowutils currentInnerWindowID and outerWindowID). I pull these out of the HTTP requests via http-on-examine-response etc., for example:

domWindow = nC.getInterface(Components.interfaces.nsIDOMWindow).top;
domWindowUtils = domWindow.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
.getInterface(Components.interfaces.nsIDOMWindowUtils);
domWindowInner = domWindowUtils.currentInnerWindowID;
domWindowOuter = domWindowUtils.outerWindowID;

This continues to work fine and pulls out the correct IDs for the requests.

In the UI side, I need to determine what the currently active tab is - so the UI button can display information relavent to the selected tab. Previously I was using this simple method to do this:

        var domWindow, domWindowUtils;
        domWindow  = win.gBrowser.mCurrentBrowser.contentWindow;
        domWindowUtils = domWindow.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
                            .getInterface(Components.interfaces.nsIDOMWindowUtils);

        this.inner = domWindowUtils.currentInnerWindowID;
        this.outer = domWindowUtils.outerWindowID;

It seems with the advent of E10S however that we can’t easily query the IDs of a window, needing to go via an async call to a messageManager. Fine, ok, so I tried this:

var mm = win.messageManager;
var currentBrowser = win.gBrowser.selectedBrowser;
    currentBrowser.messageManager.sendAsyncMessage("sixornot@baldock.me:update-id", {
    callback_id: id
});

mm.loadFrameScript("resource://sixornot/includes/content.js", true);

content.js:

addMessageListener("sixornot@baldock.me:update-id", function (message) {

var windowUtils = content.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
                             .getInterface(Components.interfaces.nsIDOMWindowUtils);

    var inner_id = windowUtils.currentInnerWindowID;
    var outer_id = windowUtils.outerWindowID;
    var hostname = content.document.location.hostname;

    sendAsyncMessage("sixornot@baldock.me:update-id", {
        callback_id: message.data.callback_id,
        inner_id: inner_id,
        outer_id: outer_id,
        hostname: hostname
    });
});

This kind of works, but it gives entirely the wrong IDs, sometimes it gives fairly sane looking IDs (e.g. outerID 10 instead of the expected 9 etc.) but sometimes it gives completely insane ones like inner: 2147483651, outer: 2147483649.

I have no idea if this is a bug, or I am just doing something wrong.

Some example logging output, here I am calling win.messageManager.broadcastAsyncMessage to get a response from every child window - and I can see the window I want (in this case outer id 29). The only way to match up the “active” tab with its’ window ID is to go via win.gBrowser.selectedBrowser though which doesn’t seem to work.

called, inner: 10, outer: 6, hostname: 
called, inner: 25, outer: 7, hostname: 
called, inner: 14, outer: 12, hostname: 
called, inner: 30, outer: 29, hostname: 
Sixornot - widget:on_page_change - evt.outer_id: 29, evt.inner_id: 30, current outer_id: 2147483649, current inner_id: 2147483651
called, inner: 2147483651, outer: 2147483649, hostname: www.google.co.uk

Been pulling my hair out over this one - this seems to be the main/only breaking change for my addon with E10S and it feels like it should be such a simple thing to be able to do.

Why are you trying to get the window IDs from the frame script instead of the main script? Seems to me like those window IDs should be tracked in the main process and not each individual one. It’s possible that you’re just getting junk results.