Hi Vonuyx,
I've been working on a similar problem - not sure if you've gotten an
answer to your question yet (I'm only seeing your email today), but
below is my implementation of the OnStateChange() function to get my
hands on the current pages URI and title.  I've only tested this with
Mozilla 1.7.6 so far but plan to test on Firefox and Netscape some time
this week. 
Anyway this definitely works. One thing to be aware of is that you can
actually jump into this section of code several times when loading a
page and not all the info (URL, title) is available each time you enter
the function.

Cheers,
 Damien

NS_IMETHODIMP
MyClass::OnStateChange( nsIWebProgress *aWebProgress,
                                                   nsIRequest *aRequest,
PRUint32 aStateFlags,
                                                   nsresult aStatus )
{
        if (aStateFlags & STATE_IS_DOCUMENT) 
        {
                if (aStateFlags & STATE_STOP)
                {
                        HWND hWnd = NULL;
                        nsCOMPtr<nsIDOMWindow> window;
                        nsresult rv =
aWebProgress->GetDOMWindow(getter_AddRefs(window));

                        if (NS_FAILED(rv))
                        {
                                // TODO Log an error...
                                return rv;
                        }

                        nsIDOMDocument *domDocument;
                        window->GetDocument(&domDocument);
                        
                        nsCOMPtr<nsIDOMHTMLDocument>
                        htmlDomDocument(do_QueryInterface(domDocument));

                        if (htmlDomDocument)
                        {
                                nsEmbedString strDocText;
                                htmlDomDocument->GetTitle (strDocText);
                                const PRUnichar *strTitle =
strDocText.get(); 
                                htmlDomDocument->GetURL(strDocText);
                                const PRUnichar *strURL =
strDocText.get();
                        }
                }
        }

        return NS_OK;
}

> -----Original Message-----
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of vonuyx
> Sent: 13 April 2005 16:09
> To: [email protected]
> Subject: Re: How to obtain the URI of the currently 
> displaying document.
> 
> 
> Hello,
> Thankyou a lot for the tip.
> 
>  > and from it the location object, from which you can get 
> the href  > property which gives you the URL (as a string).
> 
> 
> Would you tell me which interface I should use for that "location 
> object"? I thought it was nsIDOMLocation, but it is not 
> included in the 
> latest gecko-sdk I have. And how to get that interface? Directly from 
> the nsIDOMWindow?
> 
> Thanks alot in advance.
> Vonuyx
> 
> 
> 
> Christian Biesinger wrote:
> 
> > vonuyx wrote:
> > 
> >> // Get the web browser
> >> nsCOMPtr<nsIWebBrowser> pWebBrowser;
> >> 
> pServman->GetServiceByContractID("@mozilla.org/embedding/browser/nsWe
> >> pServman->bBrowser;1"
> >> , NS_GET_IID(nsIWebBrowser), getter_AddRefs(pWebBrowser));
> > 
> > 
> > You can't do that. This is no service; each window would 
> have its own
> > instace of this component. Not to mention that Mozilla and 
> Firefox do 
> > not use nsWebBrowser.
> > 
> > 
> > You can get the DOM Window from aWebProgress in 
> > nsIWebProgressListener,
> > and from it the location object, from which you can get the href 
> > property which gives you the URL (as a string).
> 
> _______________________________________________
> Mozilla-xpcom mailing list
> [email protected] 
> http://mail.mozilla.org/listinfo/mozilla-xpcom
> 

_______________________________________________
Mozilla-xpcom mailing list
[email protected]
http://mail.mozilla.org/listinfo/mozilla-xpcom

Reply via email to