Re: How to get currently selected tab index and its content

veeru <[email protected]> Mon, 29 Mar 2010 22:01:10 -0700 (PDT)
Newsgroups gmane.comp.mozilla.devel.dom
Organization http://groups.google.com
Message-ID <e33127ac-a3e0-4722-90e6-cd45e8f3a04b@k19g2000yqn.googlegroups.com>
On Mar 30, 2:23 am, Jens Sorensen <[email protected]> wrote:
> You are almost there.. You can get the Tab's document from the tabnode
> (your domnode i assume) like this
>
>         :
> nodeList->Item(i, getter_AddRefs(domNode));
>
> nsCOMPtr<nsIDOMXULElement> xulElement = do_QueryInterface(domNode);
>
> nsCOMPtr<nsIBoxObject> boxObject;
> xulElement->GetBoxObject( getter_AddRefs(boxObject);
>
> nsCOMPtr<nsIBrowserBoxObject> browserObj = do_QueryInterface(boxObject);
>
> nsCOMPtr<nsIDocShell> docShell;
> browserObj->GetDocShell( getter_AddRefs(docShell) );
>
> nsCOMPtr<nsIDOMWindow> domWindow = do_GetInterface(docShell)
>
> nsCOMPtr<nsIDOMDocument> doc;
> domWindow->GetDocument( getter_AddRefs((spDoc) );
>
> Remember to check return values and NULL pointers :)... Keep in mind
> that some of the interfaces are unfrozen as well.
>
> Let me know how it goes..
>
> Cheers,
> Jens
>
>
>
> On Mon, Mar 29, 2010 at 8:13 AM, Josh Matthews <[email protected]> wrote:
> > On 03/29/2010 11:18 PM, veeru wrote:
>
> >> 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;
>
> > This condition looks wrong to me, especially since you later use xbl->
>
> > Cheers,
> > Josh
> > _______________________________________________
> > dev-tech-dom mailing list
> > [email protected]
> >https://lists.mozilla.org/listinfo/dev-tech-dom

Hi Jens,

NULL pointer is returned at the following line

sCOMPtr<nsIBrowserBoxObject> browserObj =
do_QueryInterface(boxObject);

Thus I am not able to move forward.

Also I've implemented nsIWebProgressListener to listen on the tab ie.
on STATE_START and STATE_STOP in OnStateChange() method.
In this function, I want to determine for which tab STATE_START or
STATE_STOP has occured. But I am not able to do so. Here is the code
where I am listening on event

/////////////////// CODE START //////////////////////////////

NS_IMETHODIMP CTestComponent::OnStateChange(nsIWebProgress
*aWebProgress,
                                        nsIRequest *aRequest,PRUint32
aStateFlags,nsresult aStatus)
{
	nsresult rv;

	if ((aStateFlags & STATE_START | STATE_STOP) && (aStateFlags &
STATE_IS_WINDOW))
	{
		nsCOMPtr<nsIDOMWindow> domWindow;
		rv = aWebProgress->GetDOMWindow(getter_AddRefs(domWindow));
		if (FAILED(rv))
		{
			return NS_ERROR_FAILURE;
		}

		if(domWindow)
		{
                          // Here how to determine for which tab the
event has occurred. Mean either getting tab reference or its index.
		}
	}

	return NS_OK;
}

///////////////////////////////// CODE
END ////////////////////////////////////

Please help me out. I am stuck to it badly.