Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Accessing Firefox tab element in nsIWebProgressListener::OnStateChange using C++

76 views
Skip to first unread message

Vaibhav

unread,
Mar 19, 2010, 4:43:47 AM3/19/10
to
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.

Boris Zbarsky

unread,
Mar 21, 2010, 1:39:05 PM3/21/10
to
On 3/19/10 4:43 AM, Vaibhav wrote:
> I want to set attribute to a tab once the document load request
> completes within that tab window.
....

> I want to determine which tab window has been associated with
> particular document request.

Those aren't the same thing when subframes are present in web pages.

In any case, you can get the document, then get its parent document,
then look for the right tab in that (too bad there are no sane
tabbrowser APIs for C++ use). Or if you already have a reference to the
browser UI you can just look for the relevant tab directly in it (again,
see above about APIs).

In general, though, you want to do this from chrome JS if at all possible.

> 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.

Odd. Should work! Not that nsIDOMDocumentXBL would get you anywhere
toward your "find the tab" goal.

-Boris

Vaibhav

unread,
Mar 22, 2010, 1:52:06 AM3/22/10
to

Thnx for ur response.

My requirement is:

In OnStateChange method, I want to find the tab from which document
request is initiated & set that tab attributes.
How can I do it?

Very thnx for ur response.
-Vaibhav.

Vaibhav

unread,
Mar 22, 2010, 3:20:49 AM3/22/10
to

Hi All,

I want to find the tab index in the OnStateChange method.

-Vaibhav.

Vaibhav

unread,
Apr 19, 2010, 12:38:00 AM4/19/10
to


I got solution as Follows:

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.

Compare document pointers to get currenly navigated tab.
Get value of selected attribute to check for currenly navigated tab.

Wherever possible get help of DOM Inspector.

Vaibhav.

0 new messages