Firefox - enumerating tabs in C++
I can't figure out how to enumerate and retrieve the current URL of
each tab in Firefox. I'm registered for and receiving the tab events
- "TabOpen", "TabClose", and "TabSelect" - but I have no idea what to
do after that. QI'ing the target and currentTarget either fails or
gives the same nsIDOMWindow pointer.
Currently, I'm attempting to enumerate by walking the DOM. I can
drill down all the way to the "browser" nsIDOMNodes, but I can't
figure out how to get to the #document node underneath - the browser
nodes report 0 children. I've tried QI'ing the node to various
objects, and have only been successful with nsIDOM[XUL]Element. That
doesn't seem to do much for me.
Inside OnStateChange, I've noticed that the nsIDOMWindow pointer for
each request is unique to its corresponding tab, so I'm thinking
there's got to be a way to map the DOM node back to a window like
that.
Surely I'm trying to approach this from the wrong direction. Can
anyone please show me the light?
Thanks,
Dave
Re: Firefox - enumerating tabs in C++
[email]test1033@gmail.com[/email] wrote:
[color=blue]
>Surely I'm trying to approach this from the wrong direction.
>[/color]
Unfortunately your main problem is that the tabbrowser doesn't have a
C++ API.
--
Warning: May contain traces of nuts.
Re: Firefox - enumerating tabs in C++
> Unfortunately your main problem is that the tabbrowser doesn't have a[color=blue]
> C++ API.[/color]
Well that certainly makes me feel less stupid. That being said, it
seems like I should have two options:
1. Somehow back out to the nsIDOMWindow that corresponds to each
xul:browser node, which themselves are anonymous nodes of the
tabbrowser. When I call nsIDOMNode::GetOwnerDocument on each, I get
the same pointer, which doesn't seem to make much sense.
2. Somehow get to the #document node directly underneath the browser
node. DOM Inspector displays this node in some purple color and I
don't really understand the whole hierarchy. However, if DOMi knows
the relationship between the two, surely there's a way to figure it
out programmatically, no?
Thanks for the help. If it isn't obvious, Mozilla is pretty foreign
to me.
Dave
Re: Firefox - enumerating tabs in C++
[email]test1033@gmail.com[/email] wrote:
[color=blue][color=green]
>>Unfortunately your main problem is that the tabbrowser doesn't have a C++ API.
>>
>>[/color]
>Somehow get to the #document node directly underneath the browser node. DOM Inspector displays this node in some purple color and I don't really understand the whole hierarchy. However, if DOMi knows the relationship between the two, surely there's a way to figure it out programmatically, no?
>
>[/color]
You can do it using unfrozen API, for which you would have to build your
own SDK from the source. You can use
nsIDOMDocumentXBL::GetAnonymousNodes and normal DOM APIs to enumerate
the subtree underneath the tabbrowser node. You can then use
nsIXULElement::GetBoxObject, nsIContainerBoxObject::GetDocShell and
nsIWebNavigation::GetDocument to get each subdocument.
--
Warning: May contain traces of nuts.
Re: Firefox - enumerating tabs in C++
> You can then use nsIXULElement::GetBoxObject, nsIContainerBoxObject::GetDocShell and[color=blue]
> nsIWebNavigation::GetDocument to get each subdocument.[/color]
Sounds promising. In testing, I've already got the browser node QI'd
to an nsIXULElement, so it should be straightforward to give this
avenue a try come Monday. Thanks a ton!
Dave
Re: Firefox - enumerating tabs in C++
Worked perfectly. Not the most elegant solution for monitoring tabs
but good enough for now. Thanks again!
Dave
Re: Firefox - enumerating tabs in C++
Hi All,
I am developing extension for Firefox 3.0 to 3.5 versions using VS2008.
I want to set attribute to a tab once the document load request completes within that tab window.
So in OnStateChange method, I am checking for document load.
I have used STATE_STOP & STATE_IS_DOCUMENT for it.
I want to determine which tab window has been associated with particular document request.
I have valid DOM Document pointer got from nsIWebProgress *aWebProgress which is 1st input
parameter of OnStateChange.
if ((aStateFlags & STATE_STOP) && (aStateFlags & STATE_IS_DOCUMENT))
{
nsCOMPtr<nsIDOMWindow> domwin;
nsCOMPtr<nsIDOMDocument> domDoc;
aWebProgress->GetDOMWindow(getter_AddRefs(domwin));
domwin->GetDocument(getter_AddRefs(domDoc));
}
I have tried to get nsIDOMDocumentXBL pointer by QIing nsIDOMDocument pointer(domDoc in my example) but it fails with Error code 0x80004002 (2147500034) i.e.NS_ERROR_NO_INTERFACE.
How do I get the tab element corresponding to document load request.
Could any one please help me?
Thanks in Advance,
Vaibhav D. Gade.
Solution to enumerating tabs in C++
nsCOMPtr<nsIDOMDocument> pDoc;
nsCOMPtr<nsIWindowMediator> windowMediator = do_GetService(NS_WINDOWMEDIATOR_CONTRACTID, &rv);
windowMediator->GetMostRecentWindow(L"navigator:browser", getter_AddRefs(dwi));
dwi->GetDocument(getter_AddRefs(pDoc));
nsCOMPtr<nsIDOMDocumentXBL> xbl = do_QueryInterface(pDoc, &rv);
doc->GetElementById(NS_LITERAL_STRING("content"), getter_AddRefs(domEl));
nsCOMPtr<nsIDOMElement> pAnoEl;
xbl->GetAnonymousElementByAttribute(
domEl,
NS_LITERAL_STRING("anonid"),
NS_LITERAL_STRING("tabcontainer"),
getter_AddRefs(pAnoEl)
);
nsCOMPtr<nsIDOMNodeList> nodeTabsList;
pAnoEl->GetChildNodes(getter_AddRefs(nodeTabsList));
nodeTabsList->GetLength(&tabnodelength);
nsCOMPtr<nsIDOMElement> domImgElem;
for (PRUint32 i = 0; i < tabnodelength; i++)
{
nsCOMPtr<nsIDOMNode> domTabNode;
nodeTabsList->Item(i, getter_AddRefs(domTabNode)); // This is XUL:Tab Element
}
panelcontainer - Attribute value used to get 'xul:notification' element.
tabcontainer - Attribute value used to get 'xul:tabs' element.
Wherever possible get help of DOM Inspector.
Vaibhav.