I am making an XPCOM component, which implements nsIObserver and nsIWebProgressListener. The component registers for the xpcom-startup category. In the nsIObserver::Observe method, I called my AddProgressListener method, in which I got a reference to nsIWebProgress through GetServiceByContractID. But the call to progress->AddProgressListener fails. Basiclly, I am trying the code in the http://lxr.mozilla.org/mozilla/source/uriloader/prefetch/nsPrefetchService.cpp#305 (thanks Darin). I can't see the difference between my code to add the progressListener and the code of PrefetchService does the same thing. But the progress->AddProgressListener method just fails. Could anyone tell me where I am wrong? How to add the webProgressListener sucessfully? Thank you very much for your guys' help.
NS_IMETHODIMP
mybho::Observe(nsISupports *aSubject, const char *aTopic, const PRUnichar *aData)
{
if (!strcmp(aTopic, NS_XPCOM_STARTUP_OBSERVER_ID)){
AddProgressListener();
}
mybho::Observe(nsISupports *aSubject, const char *aTopic, const PRUnichar *aData)
{
if (!strcmp(aTopic, NS_XPCOM_STARTUP_OBSERVER_ID)){
AddProgressListener();
}
return NS_OK;
}
}
void mybho::AddProgressListener()
{
nsresult rv;
// Register as an observer for the document loader
nsCOMPtr<nsIServiceManager> servman;
NS_GetServiceManager(getter_AddRefs(servman));
{
nsresult rv;
// Register as an observer for the document loader
nsCOMPtr<nsIServiceManager> servman;
NS_GetServiceManager(getter_AddRefs(servman));
nsCOMPtr<nsIWebProgress> progress;
if (servman)
servman->GetServiceByContractID("@mozilla.org/docloaderservice;1",
NS_GET_IID(nsIWebProgress),
getter_AddRefs(progress));
if (servman)
servman->GetServiceByContractID("@mozilla.org/docloaderservice;1",
NS_GET_IID(nsIWebProgress),
getter_AddRefs(progress));
if (progress){
// reach here
rv = progress->AddProgressListener(this, nsIWebProgress::NOTIFY_STATE_DOCUMENT);
rv = progress->AddProgressListener(this, nsIWebProgress::NOTIFY_STATE_DOCUMENT);
}
//test
if (NS_OK == rv){
//test
if (NS_OK == rv){
//this doesn't work
fopen("c:\\temp\\ok.txt", "w");
}
fopen("c:\\temp\\ok.txt", "w");
}
if (NS_FAILED(rv)){
//reach here
fopen("c:\\temp\\bad.txt", "w");
}
//test
}
fopen("c:\\temp\\bad.txt", "w");
}
//test
}
Do you Yahoo!?
Yahoo! Finance: Get your refund fast by filing online
