How to get currently selected tab index and its content
veeru <[email protected]> Mon, 29 Mar 2010 03:18:12 -0700 (PDT)
| Newsgroups | gmane.comp.mozilla.devel.dom |
|---|---|
| Organization | http://groups.google.com |
| Message-ID | <9e632fbc-3651-4e30-bc4b-ffabf27e3eff@g28g2000yqh.googlegroups.com> |
Hi,
I am developing an XPCOM component in c++. I am able to get number of
tabs currently opened using XBL. Please see the code below:
////////////////////////////////////////////C O D
E//////////////////////////////////////////
nsresult rv;
nsCOMPtr<nsIWindowMediator> windowMediator
= do_GetService(NS_WINDOWMEDIATOR_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv,rv);
PRUint32 len;
nsString temp;
nsCOMPtr<nsIDOMDocument> curDoc;
nsCOMPtr<nsIDOMElement> domEl;
nsCOMPtr<nsIDOMNodeList> tabbrowser;
nsCOMPtr<nsIDOMDocument> doc;
nsCOMPtr<nsIDOMWindowInternal> dwi;
windowMediator->GetMostRecentWindow(L"navigator:browser",
getter_AddRefs(dwi));
if (dwi)
{
dwi->GetDocument(getter_AddRefs(doc));
if (doc)
{
nsCOMPtr<nsIDOMDocumentXBL> xbl(do_QueryInterface(doc));
if (xbl)
return NS_ERROR_FAILURE;
doc->GetElementById(NS_LITERAL_STRING("content"),
getter_AddRefs(domEl));
if (domEl)
{
nsCOMPtr<nsIDOMElement> pAnoEl;
xbl->GetAnonymousElementByAttribute(domEl,
NS_LITERAL_STRING("anonid"), NS_LITERAL_STRING("tabcontainer"),
getter_AddRefs(pAnoEl));
if (pAnoEl)
{
nsCOMPtr<nsIDOMNodeList> nodeList;
pAnoEl->GetChildNodes(getter_AddRefs(nodeList));
if (nodeList)
{
nsCOMPtr<nsIDOMNode> domNode;
nodeList->GetLength(&len);
for (PRUint32 i = 0; i < len; i++)
{
nodeList->Item(i, getter_AddRefs(domNode));
curDoc =
do_QueryInterface(domNode); // fails here.
}
}
}
}
}
}
///////////////////////////////////END OF
CODE////////////////////////////////////////
Here I am getting number of tab, even I am able to set/get attributes.
But I am able to decide which is the currently selected tab. I tried
to use property and method from tabbrowser.xml, but failed.
Also I want to get the content of currently selected tab. But I tried
to QI nsIDOMNode for nsIDOMDocument, it failed. But in dependency
diagram on mozilla site, it is given that nsIDOMNode is derived form
nsIDOMDocument.
How can I get the current tab content, DOM pointer and its index?
Please help me, I am stuck to it.
Thank you in advance.