Hi,
It seems to me that everytime when a whole page is loaded (within a single window), OnStateChange is called twice with some speciale values of aStateFlags.
In your example (http://www.cnn.com/), you should have:


1. First, OnStateChange is called with aStateFlags contains STATE_STOP |STATE_IS_DOCUMENT and in aRequest you have aRequest::GetName() == http://www.cnn.com/
2. Next, OnStateChange is called again with aStateFlags contains STATE_STOP | STATE_IS_NETWORK | STATE_IS_WINDOW and the same URI in aRequest.


I think you can depent on this to determine whether the whole page was loaded or not.

It works for Firefox 1.x

Vonuyx



Damien O'Brien wrote:

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;
}


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

Reply via email to