Hi Damien,
here is my code to test if a page is completely loaded (it works fine with
multiple framesets included in webpages):
".....
// 1) we count requests each time the listener is called during loading:
// ---------------------------------------------------------------------
if (progressStateFlags & STATE_START) {
if (progressStateFlags & STATE_IS_NETWORK) {
mTotalRequests = 0;
mFinishedRequests = 0;
}
if (progressStateFlags & STATE_IS_REQUEST) {
++mTotalRequests;
}
}else {
if (progressStateFlags & STATE_STOP) {
if (progressStateFlags & STATE_IS_REQUEST) {
++mFinishedRequests;
}
}
}
// 2) while the page is loading, we ignore the page and return:
// -----------------------------------------------------------
if ((progressStateFlags & nsIWebProgressListener::STATE_START) &&
(progressStateFlags
& nsIWebProgressListener::STATE_IS_DOCUMENT)) {
return NS_OK;
}
if (!progress) {
return NS_OK;
}else {
progress->GetIsLoadingDocument(&docLoading);
if (docLoading == PR_TRUE) {
fprintf(outputFile, "\nonStateChange : our document is still
loading -> ignored...\n");
fflush(outputFile);
return NS_OK;
}
}
//3) at this step, we hope that the document is completely loaded but we
must verify it by testing the number of requests and the flags :
//
-----------------------------------------------------------------------------------------------------------------------------------
if ((mFinishedRequests == mTotalRequests) && ((progressStateFlags &
nsIWebProgressListener::STATE_STOP)
| (progressStateFlags & nsIWebProgressListener::STATE_IS_NETWORK))
&& (status == NS_OK)){
// loading is finished:
...... insert your code to begin your work .....
}
Kind regards.
B�atrice Philippe.
"Damien O'Brien" <[EMAIL PROTECTED]> a �crit dans le message de
news: [EMAIL PROTECTED]
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