Quantcast

Getting tab URL in C++

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Getting tab URL in C++

Vaibhav-9
Hi,

I am writing Firefox extension using C++.

I am enumerating the tabs to get their respective URLs.

Following is pseudocode:

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

nsCOMPtr<nsIWindowMediator> windowMediator =
do_GetService(NS_WINDOWMEDIATOR_CONTRACTID, &rv);
windowMediator->GetMostRecentWindow(L"navigator:browser",
getter_AddRefs(dwi));
dwi->GetDocument(getter_AddRefs(doc));
nsCOMPtr<nsIDOMDocumentXBL> xbl(do_QueryInterface(doc));
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)
                                                                );
nsString retval;
PRBool bRet = 0;
nsCOMPtr<nsIDOMNodeList> nodeList;
pAnoEl->GetChildNodes(getter_AddRefs(nodeList));
nsCOMPtr<nsIDOMNode> domNode;
rv = nodeList->GetLength(&len);
for (PRUint32 i = 0; i < len; i++)
{
        nodeList->Item(i, getter_AddRefs(domNode));
        nsCOMPtr<nsIDOMXULElement> xulElement = do_QueryInterface(domNode);
        nsCOMPtr<nsIBoxObject> boxObject;
        xulElement->GetBoxObject(getter_AddRefs(boxObject));
        nsCOMPtr<nsIBrowserBoxObject> browserboxObject =
do_QueryInterface(boxObject);
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

In the above code QueryInterface for getting nsIBrowserBoxObject fails
with error code: NS_ERROR_NO_INTERFACE.

Please suggest me the ways to get tab URL.

Help Me !!!

Thanks,
Vaibhav.
_______________________________________________
dev-tech-dom mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-dom
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Getting tab URL in C++

Jens Sorensen
You are almost there..

If you bring up DOM inspector then you will notice that the
'browsers/tabs' are actually located under the 'xul:panels' node which
has the anonid value of "panelcontainer" and not "tabcontainer".  You
passed "tabcontainer" in to "GetAnonymousElementByAttribute" which is
not correct. You will also notice that this element contains multiple
'xul:notificationbox' elements (one for each tab) and that the
'xul:browser' node is the last child of the 'xul:notificationbox'.

The 'xul:browser" node is what you are looking for.

Here is the updated code.

        nsresult rv;
        nsCOMPtr<nsIWindowMediator> windowMediator =
do_GetService(NS_WINDOWMEDIATOR_CONTRACTID, &rv);

        nsCOMPtr<nsIDOMWindowInternal> dwi;
        windowMediator->GetMostRecentWindow(L"navigator:browser", getter_AddRefs(dwi));
        nsCOMPtr<nsIDOMDocument> doc;
        dwi->GetDocument(getter_AddRefs(doc));

        nsCOMPtr<nsIDOMDocumentXBL> xbl(do_QueryInterface(doc));

        nsCOMPtr<nsIDOMElement> domEl;
        doc->GetElementById(NS_LITERAL_STRING("content"), getter_AddRefs(domEl));
        nsCOMPtr<nsIDOMElement> pAnoEl;

        // getting xul:tabpanels
        xbl->GetAnonymousElementByAttribute(domEl,
NS_LITERAL_STRING("anonid"), NS_LITERAL_STRING("panelcontainer"),
getter_AddRefs(pAnoEl)  );
        nsString retval;
        PRBool bRet = 0;
        nsCOMPtr<nsIDOMNodeList> nodeList;
        pAnoEl->GetChildNodes(getter_AddRefs(nodeList));
        nsCOMPtr<nsIDOMNode> domNode;

        PRUint32 len = 0;
        rv = nodeList->GetLength(&len);

        for( PRUint32 i=0; i<len; i++ )
        {
                // getting the xul::notificationbox
                nsCOMPtr<nsIDOMNode> domNode;
                nodeList->Item(i, getter_AddRefs(domNode));

                // get the last child of the 'xul::notificationbox' which is the 'xul:browser'
                nsCOMPtr<nsIDOMNode> domXULBrowser;
                domNode->GetLastChild(getter_AddRefs(domXULBrowser));

                nsCOMPtr<nsIDOMXULElement> xulElement = do_QueryInterface(domXULBrowser);
                nsCOMPtr<nsIBoxObject> boxObject;
                xulElement->GetBoxObject(getter_AddRefs(boxObject));
                nsCOMPtr<nsIBrowserBoxObject> browserboxObject = do_QueryInterface(boxObject);

                nsCOMPtr<nsIDocShell> docShell;
                browserboxObject->GetDocShell(getter_AddRefs(docShell));

                nsCOMPtr<nsIWebNavigation> webNav = do_QueryInterface(docShell);

                nsCOMPtr<nsIURI> uri;
                webNav->GetCurrentURI(getter_AddRefs(uri));
               
                nsCString path;
                uri->GetAsciiSpec(path);
        }

If you do this early in the stage then the uri might be NULL or the
URL will most likely be about:blank.

I suggest that you add "TabOpen", "TabSelect" "TabXXXX" event
listeners if you need to track tab creation, destruction etc.

nsCOMPtr<nsIDOMEventTarget> eventTarget = do_QueryInterface(dwi);
eventTarget->AddEventListener(.....)

Remember to check for null pointers etc..
Cheers,
Jens Sorensen







        nsresult rv;
        nsCOMPtr<nsIWindowMediator> windowMediator =
do_GetService(NS_WINDOWMEDIATOR_CONTRACTID, &rv);

        nsCOMPtr<nsIDOMWindowInternal> dwi;
        windowMediator->GetMostRecentWindow(L"navigator:browser", getter_AddRefs(dwi));
        nsCOMPtr<nsIDOMDocument> doc;
        dwi->GetDocument(getter_AddRefs(doc));

        nsCOMPtr<nsIDOMDocumentXBL> xbl(do_QueryInterface(doc));

        nsCOMPtr<nsIDOMElement> domEl;
        doc->GetElementById(NS_LITERAL_STRING("content"), getter_AddRefs(domEl));
        nsCOMPtr<nsIDOMElement> pAnoEl;

        // getting xul:tabpanels
        xbl->GetAnonymousElementByAttribute(domEl,
NS_LITERAL_STRING("anonid"), NS_LITERAL_STRING("panelcontainer"),
getter_AddRefs(pAnoEl)  );
        nsString retval;
        PRBool bRet = 0;
        nsCOMPtr<nsIDOMNodeList> nodeList;
        pAnoEl->GetChildNodes(getter_AddRefs(nodeList));
        nsCOMPtr<nsIDOMNode> domNode;

        PRUint32 len = 0;
        rv = nodeList->GetLength(&len);

        for( PRUint32 i=0; i<len; i++ )
        {
                // getting the xul::notificationbox
                nsCOMPtr<nsIDOMNode> domNode;
                nodeList->Item(i, getter_AddRefs(domNode));

                // get the last child of the 'xul::notificationbox' which is the 'xul:browser'
                nsCOMPtr<nsIDOMNode> domXULBrowser;
                domNode->GetLastChild(getter_AddRefs(domXULBrowser));

                nsCOMPtr<nsIDOMXULElement> xulElement = do_QueryInterface(domXULBrowser);
                nsCOMPtr<nsIBoxObject> boxObject;
                xulElement->GetBoxObject(getter_AddRefs(boxObject));
                nsCOMPtr<nsIBrowserBoxObject> browserboxObject = do_QueryInterface(boxObject);

                nsCOMPtr<nsIDocShell> docShell;
                browserboxObject->GetDocShell(getter_AddRefs(docShell));

                nsCOMPtr<nsIWebNavigation> webNav = do_QueryInterface(docShell);

                nsCOMPtr<nsIURI> uri;
                webNav->GetCurrentURI(getter_AddRefs(uri));
               
                nsCString path;
                uri->GetAsciiSpec(path);
        }


On Thu, Apr 8, 2010 at 6:04 AM, Vaibhav <[hidden email]> wrote:

> Hi,
>
> I am writing Firefox extension using C++.
>
> I am enumerating the tabs to get their respective URLs.
>
> Following is pseudocode:
>
> /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
>
> nsCOMPtr<nsIWindowMediator> windowMediator =
> do_GetService(NS_WINDOWMEDIATOR_CONTRACTID, &rv);
> windowMediator->GetMostRecentWindow(L"navigator:browser",
> getter_AddRefs(dwi));
> dwi->GetDocument(getter_AddRefs(doc));
> nsCOMPtr<nsIDOMDocumentXBL> xbl(do_QueryInterface(doc));
> 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)
>                                                                );
> nsString retval;
> PRBool bRet = 0;
> nsCOMPtr<nsIDOMNodeList> nodeList;
> pAnoEl->GetChildNodes(getter_AddRefs(nodeList));
> nsCOMPtr<nsIDOMNode> domNode;
> rv = nodeList->GetLength(&len);
> for (PRUint32 i = 0; i < len; i++)
> {
>        nodeList->Item(i, getter_AddRefs(domNode));
>        nsCOMPtr<nsIDOMXULElement> xulElement = do_QueryInterface(domNode);
>        nsCOMPtr<nsIBoxObject> boxObject;
>        xulElement->GetBoxObject(getter_AddRefs(boxObject));
>        nsCOMPtr<nsIBrowserBoxObject> browserboxObject =
> do_QueryInterface(boxObject);
> }
>
> /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
>
> In the above code QueryInterface for getting nsIBrowserBoxObject fails
> with error code: NS_ERROR_NO_INTERFACE.
>
> Please suggest me the ways to get tab URL.
>
> Help Me !!!
>
> Thanks,
> Vaibhav.
> _______________________________________________
> dev-tech-dom mailing list
> [hidden email]
> https://lists.mozilla.org/listinfo/dev-tech-dom
>
_______________________________________________
dev-tech-dom mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-dom
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Getting tab URL in C++

Vaibhav-9
In reply to this post by Vaibhav-9
On Apr 10, 7:15 am, Jens Sorensen <[hidden email]> wrote:

> You are almost there..
>
> If you bring up DOM inspector then you will notice that the
> 'browsers/tabs' are actually located under the 'xul:panels' node which
> has the anonid value of "panelcontainer" and not "tabcontainer".  You
> passed "tabcontainer" in to "GetAnonymousElementByAttribute" which is
> not correct. You will also notice that this element contains multiple
> 'xul:notificationbox' elements (one for each tab) and that the
> 'xul:browser' node is the last child of the 'xul:notificationbox'.
>
> The 'xul:browser" node is what you are looking for.
>
> Here is the updated code.
>
>         nsresult rv;
>         nsCOMPtr<nsIWindowMediator> windowMediator =
> do_GetService(NS_WINDOWMEDIATOR_CONTRACTID, &rv);
>
>         nsCOMPtr<nsIDOMWindowInternal> dwi;
>         windowMediator->GetMostRecentWindow(L"navigator:browser", getter_AddRefs(dwi));
>         nsCOMPtr<nsIDOMDocument> doc;
>         dwi->GetDocument(getter_AddRefs(doc));
>
>         nsCOMPtr<nsIDOMDocumentXBL> xbl(do_QueryInterface(doc));
>
>         nsCOMPtr<nsIDOMElement> domEl;
>         doc->GetElementById(NS_LITERAL_STRING("content"), getter_AddRefs(domEl));
>         nsCOMPtr<nsIDOMElement> pAnoEl;
>
>         // getting xul:tabpanels
>         xbl->GetAnonymousElementByAttribute(domEl,
> NS_LITERAL_STRING("anonid"), NS_LITERAL_STRING("panelcontainer"),
> getter_AddRefs(pAnoEl)  );
>         nsString retval;
>         PRBool bRet = 0;
>         nsCOMPtr<nsIDOMNodeList> nodeList;
>         pAnoEl->GetChildNodes(getter_AddRefs(nodeList));
>         nsCOMPtr<nsIDOMNode> domNode;
>
>         PRUint32 len = 0;
>         rv = nodeList->GetLength(&len);
>
>         for( PRUint32 i=0; i<len; i++ )
>         {
>                 // getting the xul::notificationbox
>                 nsCOMPtr<nsIDOMNode> domNode;
>                 nodeList->Item(i, getter_AddRefs(domNode));
>
>                 // get the last child of the 'xul::notificationbox' which is the 'xul:browser'
>                 nsCOMPtr<nsIDOMNode> domXULBrowser;
>                 domNode->GetLastChild(getter_AddRefs(domXULBrowser));
>
>                 nsCOMPtr<nsIDOMXULElement> xulElement = do_QueryInterface(domXULBrowser);
>                 nsCOMPtr<nsIBoxObject> boxObject;
>                 xulElement->GetBoxObject(getter_AddRefs(boxObject));
>                 nsCOMPtr<nsIBrowserBoxObject> browserboxObject = do_QueryInterface(boxObject);
>
>                 nsCOMPtr<nsIDocShell> docShell;
>                 browserboxObject->GetDocShell(getter_AddRefs(docShell));
>
>                 nsCOMPtr<nsIWebNavigation> webNav = do_QueryInterface(docShell);
>
>                 nsCOMPtr<nsIURI> uri;
>                 webNav->GetCurrentURI(getter_AddRefs(uri));
>
>                 nsCString path;
>                 uri->GetAsciiSpec(path);
>         }
>
> If you do this early in the stage then the uri might be NULL or the
> URL will most likely be about:blank.
>
> I suggest that you add "TabOpen", "TabSelect" "TabXXXX" event
> listeners if you need to track tab creation, destruction etc.
>
> nsCOMPtr<nsIDOMEventTarget> eventTarget = do_QueryInterface(dwi);
> eventTarget->AddEventListener(.....)
>
> Remember to check for null pointers etc..
> Cheers,
> Jens Sorensen
>
>         nsresult rv;
>         nsCOMPtr<nsIWindowMediator> windowMediator =
> do_GetService(NS_WINDOWMEDIATOR_CONTRACTID, &rv);
>
>         nsCOMPtr<nsIDOMWindowInternal> dwi;
>         windowMediator->GetMostRecentWindow(L"navigator:browser", getter_AddRefs(dwi));
>         nsCOMPtr<nsIDOMDocument> doc;
>         dwi->GetDocument(getter_AddRefs(doc));
>
>         nsCOMPtr<nsIDOMDocumentXBL> xbl(do_QueryInterface(doc));
>
>         nsCOMPtr<nsIDOMElement> domEl;
>         doc->GetElementById(NS_LITERAL_STRING("content"), getter_AddRefs(domEl));
>         nsCOMPtr<nsIDOMElement> pAnoEl;
>
>         // getting xul:tabpanels
>         xbl->GetAnonymousElementByAttribute(domEl,
> NS_LITERAL_STRING("anonid"), NS_LITERAL_STRING("panelcontainer"),
> getter_AddRefs(pAnoEl)  );
>         nsString retval;
>         PRBool bRet = 0;
>         nsCOMPtr<nsIDOMNodeList> nodeList;
>         pAnoEl->GetChildNodes(getter_AddRefs(nodeList));
>         nsCOMPtr<nsIDOMNode> domNode;
>
>         PRUint32 len = 0;
>         rv = nodeList->GetLength(&len);
>
>         for( PRUint32 i=0; i<len; i++ )
>         {
>                 // getting the xul::notificationbox
>                 nsCOMPtr<nsIDOMNode> domNode;
>                 nodeList->Item(i, getter_AddRefs(domNode));
>
>                 // get the last child of the 'xul::notificationbox' which is the 'xul:browser'
>                 nsCOMPtr<nsIDOMNode> domXULBrowser;
>                 domNode->GetLastChild(getter_AddRefs(domXULBrowser));
>
>                 nsCOMPtr<nsIDOMXULElement> xulElement = do_QueryInterface(domXULBrowser);
>                 nsCOMPtr<nsIBoxObject> boxObject;
>                 xulElement->GetBoxObject(getter_AddRefs(boxObject));
>                 nsCOMPtr<nsIBrowserBoxObject> browserboxObject = do_QueryInterface(boxObject);
>
>                 nsCOMPtr<nsIDocShell> docShell;
>                 browserboxObject->GetDocShell(getter_AddRefs(docShell));
>
>                 nsCOMPtr<nsIWebNavigation> webNav = do_QueryInterface(docShell);
>
>                 nsCOMPtr<nsIURI> uri;
>                 webNav->GetCurrentURI(getter_AddRefs(uri));
>
>                 nsCString path;
>                 uri->GetAsciiSpec(path);
>         }
>
>
>
> On Thu, Apr 8, 2010 at 6:04 AM, Vaibhav <[hidden email]> wrote:
> > Hi,
>
> > I am writing Firefox extension using C++.
>
> > I am enumerating the tabs to get their respective URLs.
>
> > Following is pseudocode:
>
> > /////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////// ///
>
> > nsCOMPtr<nsIWindowMediator> windowMediator =
> > do_GetService(NS_WINDOWMEDIATOR_CONTRACTID, &rv);
> > windowMediator->GetMostRecentWindow(L"navigator:browser",
> > getter_AddRefs(dwi));
> > dwi->GetDocument(getter_AddRefs(doc));
> > nsCOMPtr<nsIDOMDocumentXBL> xbl(do_QueryInterface(doc));
> > 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)
> >                                                                );
> > nsString retval;
> > PRBool bRet = 0;
> > nsCOMPtr<nsIDOMNodeList> nodeList;
> > pAnoEl->GetChildNodes(getter_AddRefs(nodeList));
> > nsCOMPtr<nsIDOMNode> domNode;
> > rv = nodeList->GetLength(&len);
> > for (PRUint32 i = 0; i < len; i++)
> > {
> >        nodeList->Item(i, getter_AddRefs(domNode));
> >        nsCOMPtr<nsIDOMXULElement> xulElement = do_QueryInterface(domNode);
> >        nsCOMPtr<nsIBoxObject> boxObject;
> >        xulElement->GetBoxObject(getter_AddRefs(boxObject));
> >        nsCOMPtr<nsIBrowserBoxObject> browserboxObject =
> > do_QueryInterface(boxObject);
> > }
>
> > /////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////// ///
>
> > In the above code QueryInterface for getting nsIBrowserBoxObject fails
> > with error code: NS_ERROR_NO_INTERFACE.
>
> > Please suggest me the ways to get tab URL.
>
> > Help Me !!!
>
> > Thanks,
> > Vaibhav.
> > _______________________________________________
> > dev-tech-dom mailing list
> > [hidden email]
> >https://lists.mozilla.org/listinfo/dev-tech-dom

Hi Jens,

Thanks a lot.
It is a solution.

Vaibhav.

_______________________________________________
dev-tech-dom mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-dom
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Getting tab URL in C++

spushpendra2000
Hi Vaibhav,

I am also implementing the c++ code to get all opened firefox url.

Could you please send me your code.

regards
Pushpendra

On Monday, April 12, 2010 3:33:22 PM UTC+5:30, Vaibhav wrote:

> On Apr 10, 7:15 am, Jens Sorensen <[hidden email]> wrote:
> > You are almost there..
> >
> > If you bring up DOM inspector then you will notice that the
> > 'browsers/tabs' are actually located under the 'xul:panels' node which
> > has the anonid value of "panelcontainer" and not "tabcontainer".  You
> > passed "tabcontainer" in to "GetAnonymousElementByAttribute" which is
> > not correct. You will also notice that this element contains multiple
> > 'xul:notificationbox' elements (one for each tab) and that the
> > 'xul:browser' node is the last child of the 'xul:notificationbox'.
> >
> > The 'xul:browser" node is what you are looking for.
> >
> > Here is the updated code.
> >
> >         nsresult rv;
> >         nsCOMPtr<nsIWindowMediator> windowMediator =
> > do_GetService(NS_WINDOWMEDIATOR_CONTRACTID, &rv);
> >
> >         nsCOMPtr<nsIDOMWindowInternal> dwi;
> >         windowMediator->GetMostRecentWindow(L"navigator:browser", getter_AddRefs(dwi));
> >         nsCOMPtr<nsIDOMDocument> doc;
> >         dwi->GetDocument(getter_AddRefs(doc));
> >
> >         nsCOMPtr<nsIDOMDocumentXBL> xbl(do_QueryInterface(doc));
> >
> >         nsCOMPtr<nsIDOMElement> domEl;
> >         doc->GetElementById(NS_LITERAL_STRING("content"), getter_AddRefs(domEl));
> >         nsCOMPtr<nsIDOMElement> pAnoEl;
> >
> >         // getting xul:tabpanels
> >         xbl->GetAnonymousElementByAttribute(domEl,
> > NS_LITERAL_STRING("anonid"), NS_LITERAL_STRING("panelcontainer"),
> > getter_AddRefs(pAnoEl)  );
> >         nsString retval;
> >         PRBool bRet = 0;
> >         nsCOMPtr<nsIDOMNodeList> nodeList;
> >         pAnoEl->GetChildNodes(getter_AddRefs(nodeList));
> >         nsCOMPtr<nsIDOMNode> domNode;
> >
> >         PRUint32 len = 0;
> >         rv = nodeList->GetLength(&len);
> >
> >         for( PRUint32 i=0; i<len; i++ )
> >         {
> >                 // getting the xul::notificationbox
> >                 nsCOMPtr<nsIDOMNode> domNode;
> >                 nodeList->Item(i, getter_AddRefs(domNode));
> >
> >                 // get the last child of the 'xul::notificationbox' which is the 'xul:browser'
> >                 nsCOMPtr<nsIDOMNode> domXULBrowser;
> >                 domNode->GetLastChild(getter_AddRefs(domXULBrowser));
> >
> >                 nsCOMPtr<nsIDOMXULElement> xulElement = do_QueryInterface(domXULBrowser);
> >                 nsCOMPtr<nsIBoxObject> boxObject;
> >                 xulElement->GetBoxObject(getter_AddRefs(boxObject));
> >                 nsCOMPtr<nsIBrowserBoxObject> browserboxObject = do_QueryInterface(boxObject);
> >
> >                 nsCOMPtr<nsIDocShell> docShell;
> >                 browserboxObject->GetDocShell(getter_AddRefs(docShell));
> >
> >                 nsCOMPtr<nsIWebNavigation> webNav = do_QueryInterface(docShell);
> >
> >                 nsCOMPtr<nsIURI> uri;
> >                 webNav->GetCurrentURI(getter_AddRefs(uri));
> >
> >                 nsCString path;
> >                 uri->GetAsciiSpec(path);
> >         }
> >
> > If you do this early in the stage then the uri might be NULL or the
> > URL will most likely be about:blank.
> >
> > I suggest that you add "TabOpen", "TabSelect" "TabXXXX" event
> > listeners if you need to track tab creation, destruction etc.
> >
> > nsCOMPtr<nsIDOMEventTarget> eventTarget = do_QueryInterface(dwi);
> > eventTarget->AddEventListener(.....)
> >
> > Remember to check for null pointers etc..
> > Cheers,
> > Jens Sorensen
> >
> >         nsresult rv;
> >         nsCOMPtr<nsIWindowMediator> windowMediator =
> > do_GetService(NS_WINDOWMEDIATOR_CONTRACTID, &rv);
> >
> >         nsCOMPtr<nsIDOMWindowInternal> dwi;
> >         windowMediator->GetMostRecentWindow(L"navigator:browser", getter_AddRefs(dwi));
> >         nsCOMPtr<nsIDOMDocument> doc;
> >         dwi->GetDocument(getter_AddRefs(doc));
> >
> >         nsCOMPtr<nsIDOMDocumentXBL> xbl(do_QueryInterface(doc));
> >
> >         nsCOMPtr<nsIDOMElement> domEl;
> >         doc->GetElementById(NS_LITERAL_STRING("content"), getter_AddRefs(domEl));
> >         nsCOMPtr<nsIDOMElement> pAnoEl;
> >
> >         // getting xul:tabpanels
> >         xbl->GetAnonymousElementByAttribute(domEl,
> > NS_LITERAL_STRING("anonid"), NS_LITERAL_STRING("panelcontainer"),
> > getter_AddRefs(pAnoEl)  );
> >         nsString retval;
> >         PRBool bRet = 0;
> >         nsCOMPtr<nsIDOMNodeList> nodeList;
> >         pAnoEl->GetChildNodes(getter_AddRefs(nodeList));
> >         nsCOMPtr<nsIDOMNode> domNode;
> >
> >         PRUint32 len = 0;
> >         rv = nodeList->GetLength(&len);
> >
> >         for( PRUint32 i=0; i<len; i++ )
> >         {
> >                 // getting the xul::notificationbox
> >                 nsCOMPtr<nsIDOMNode> domNode;
> >                 nodeList->Item(i, getter_AddRefs(domNode));
> >
> >                 // get the last child of the 'xul::notificationbox' which is the 'xul:browser'
> >                 nsCOMPtr<nsIDOMNode> domXULBrowser;
> >                 domNode->GetLastChild(getter_AddRefs(domXULBrowser));
> >
> >                 nsCOMPtr<nsIDOMXULElement> xulElement = do_QueryInterface(domXULBrowser);
> >                 nsCOMPtr<nsIBoxObject> boxObject;
> >                 xulElement->GetBoxObject(getter_AddRefs(boxObject));
> >                 nsCOMPtr<nsIBrowserBoxObject> browserboxObject = do_QueryInterface(boxObject);
> >
> >                 nsCOMPtr<nsIDocShell> docShell;
> >                 browserboxObject->GetDocShell(getter_AddRefs(docShell));
> >
> >                 nsCOMPtr<nsIWebNavigation> webNav = do_QueryInterface(docShell);
> >
> >                 nsCOMPtr<nsIURI> uri;
> >                 webNav->GetCurrentURI(getter_AddRefs(uri));
> >
> >                 nsCString path;
> >                 uri->GetAsciiSpec(path);
> >         }
> >
> >
> >
> > On Thu, Apr 8, 2010 at 6:04 AM, Vaibhav <[hidden email]> wrote:
> > > Hi,
> >
> > > I am writing Firefox extension using C++.
> >
> > > I am enumerating the tabs to get their respective URLs.
> >
> > > Following is pseudocode:
> >
> > > /////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////// ///
> >
> > > nsCOMPtr<nsIWindowMediator> windowMediator =
> > > do_GetService(NS_WINDOWMEDIATOR_CONTRACTID, &rv);
> > > windowMediator->GetMostRecentWindow(L"navigator:browser",
> > > getter_AddRefs(dwi));
> > > dwi->GetDocument(getter_AddRefs(doc));
> > > nsCOMPtr<nsIDOMDocumentXBL> xbl(do_QueryInterface(doc));
> > > 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)
> > >                                                                );
> > > nsString retval;
> > > PRBool bRet = 0;
> > > nsCOMPtr<nsIDOMNodeList> nodeList;
> > > pAnoEl->GetChildNodes(getter_AddRefs(nodeList));
> > > nsCOMPtr<nsIDOMNode> domNode;
> > > rv = nodeList->GetLength(&len);
> > > for (PRUint32 i = 0; i < len; i++)
> > > {
> > >        nodeList->Item(i, getter_AddRefs(domNode));
> > >        nsCOMPtr<nsIDOMXULElement> xulElement = do_QueryInterface(domNode);
> > >        nsCOMPtr<nsIBoxObject> boxObject;
> > >        xulElement->GetBoxObject(getter_AddRefs(boxObject));
> > >        nsCOMPtr<nsIBrowserBoxObject> browserboxObject =
> > > do_QueryInterface(boxObject);
> > > }
> >
> > > /////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////// ///
> >
> > > In the above code QueryInterface for getting nsIBrowserBoxObject fails
> > > with error code: NS_ERROR_NO_INTERFACE.
> >
> > > Please suggest me the ways to get tab URL.
> >
> > > Help Me !!!
> >
> > > Thanks,
> > > Vaibhav.
> > > _______________________________________________
> > > dev-tech-dom mailing list
> > > [hidden email]
> > >https://lists.mozilla.org/listinfo/dev-tech-dom
>
> Hi Jens,
>
> Thanks a lot.
> It is a solution.
>
> Vaibhav.

_______________________________________________
dev-tech-dom mailing list
[hidden email]
https://lists.mozilla.org/listinfo/dev-tech-dom
Loading...