Hi,
I'm working on a C++ XPCOM component on WinXP. I want to get the title and
URL of pages viewed in a browser. To do this I using the function
OnStateChange() from nsIWebProgressListener.  This all seems to be working
fine, however I've discovered a problem when visiting certain web pages
(e.g. www.cnn.com).
There are several references to other pages that need to be downloded within
this page. So the browser needs to download each of these "embedded" pages
in turn. The problem with this is my plugin thinks each of these is a new
page and so OnStateChange() gets called for each embedded page. I am testing
aStateFlags to determine the download state but this can't tell me if a page
is an "embedded" page. So instead of me seeing just one page being loaded
when I go to www.cnn.com - I see several pages e.g 

http://ar.atwola.com/html/93182780/547029716/aol?SNM=HI&width=120&height=90&;
target=_blank&TZ=-60&TVAR=class%3Dintl&CT=I
http://cnn.dyn.cnn.com/weatherBox.html?domId=weatherBox&time=1114017300788
And finally the page that I'm really only interested in;
http://www.cnn.com/

What I need is a way for me to determine when the page is finished loading.
Does anyone have any idea how I can do this?

I've included a cutdown version of my OnStateChange() implementation in case
this helps.
Thanks
 Damien

NS_IMETHODIMP
MyMozilla::OnStateChange( nsIWebProgress *aWebProgress,
                           nsIRequest *aRequest, PRUint32 aStateFlags,
                           nsresult aStatus )
{
        // First check that this is a document load that's occuring.
        if (aStateFlags & STATE_IS_DOCUMENT) 
        {
                // Now check if we've finished loading the document
                if (aStateFlags & STATE_STOP)
                {
                        HWND hWnd = NULL;
                        nsCOMPtr<nsIDOMWindow> window;
                        nsresult rv =
aWebProgress->GetDOMWindow(getter_AddRefs(window));

                        if (NS_FAILED(rv))
                        {
                                return rv;
                        }

                        nsIDOMDocument *domDocument;
                        rv = window->GetDocument(&domDocument);
                                 
                        if (NS_FAILED(rv))
                        {
                                return rv;
                        }
                                
                        nsCOMPtr<nsIDOMHTMLDocument>
                        htmlDomDocument(do_QueryInterface(domDocument));

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

                                // DO STUFF HERE.....
                        }
                }
        }

        return NS_OK;
}

<<attachment: winmail.dat>>

Reply via email to