[Project_owners] Getting Source Tab When Listening to http-on-modify-request

Kyle Wilgus wigginz at gmail.com
Thu Mar 1 05:07:22 PST 2007


I've made a lot of progress this morning and I'm able to get the
_actual_ tab. Here is the function I've ended up with at the moment to
get the tab.linkedPanel from the subject. I'm using the value of
linkedPanel as the unique identifier of the tab, so far this has
proven to work.

function cookiestore_getTabIdForHttpChannel(httpChannel)
{
    var oHttp =
httpChannel.QueryInterface(Components.interfaces.nsIHttpChannel);
    if ( oHttp.notificationCallbacks )
    {
        var interfaceRequestor =
oHttp.notificationCallbacks.QueryInterface(Components.interfaces.nsIInterfaceRequestor);
        var targetDoc =
interfaceRequestor.getInterface(Components.interfaces.nsIDOMWindow).document;
        var tab = null;
        var targetBrowserIndex = gBrowser.getBrowserIndexForDocument(targetDoc);
        // handle the case where there was no tab associated with the
request (rss, etc)
        if (targetBrowserIndex != -1)
            tab = gBrowser.tabContainer.childNodes[targetBrowserIndex];
        else
            return(null);
        return(tab.linkedPanel);
    }
    else
        return(null);
}

I'll need to add the check for loadGroup case now that Eric has
pointed it out. I'm also trying to figure out why AJAX requests aren't
triggering the topic.

Thanks a bunch everyone, this has been a major pain for a long time
for me, it's great to finally have a solution!

Kyle



On 3/1/07, eric.jung at yahoo.com <eric.jung at yahoo.com> wrote:
>
> I got a little further with this. notificationCallbacks is sometimes null.
> When it's null, you need to use the loadGroup. However, the loadGroup can
> also be empty (rare but seems to happen). When this occurs, I cannot get any
> document at all. Also, sometimes the loadGroup has more than one element in
> it. In those case, I don't know which one to choose -- perhaps it doesn't
> matter.
>
> Don't forget that some requests won't be associated with a tab at all; e.g.
> rss feeds that have been bookmarked.
>
> I'll post some code tonight, but it's not much. I hope someone can give
> Neil's suggestion a try in the meantime to get the actual tab.
>
>
> ----- Original Message ----
> From: Neil <neil at parkwaycc.co.uk>
> To: project_owners at mozdev.org
> Sent: Thursday, March 1, 2007 4:47:49 AM
> Subject: Re: [Project_owners] Getting Source Tab When Listening to
> http-on-modify-request
>
>
> Kyle Wilgus wrote:
>
> > var oHttp =
> >
> aSubject.QueryInterface(Components.interfaces.nsIHttpChannel);
> > var interfaceRequestor =
> >
> oHttp.notificationCallbacks.QueryInterface(Components.interfaces.nsIInterfaceRequestor);
> >
> > var DOMWindow =
> >
> interfaceRequestor.getInterface(Components.interfaces.nsIDOMWindow);
> > var loadedDoc = DOMWindow.document;
> >
> > Does anyone know where I can go from here? Is it possible to get the
> > tab object from the window or document?
>
> If you can get hold of the nsIDocShell object (hopefully by getInterface
> on the callbacks but if not then getInterface on the window) then I
> think you can QI it to an nsIDocShellTreeItem, get its rootTreeItem,
> then getInterface on that to an nsIDOMWindow, then call
> getBrowser().getBrowserIndexForDocument(DOMWindow.top.document).
> _______________________________________________
> Project_owners mailing list
> Project_owners at mozdev.org
> http://mozdev.org/mailman/listinfo/project_owners
>
>
> _______________________________________________
> Project_owners mailing list
> Project_owners at mozdev.org
> http://mozdev.org/mailman/listinfo/project_owners
>
>


-- 
Kyle
http://wigginz.com


More information about the Project_owners mailing list