I am creating application which gets URL from Firefox on every pageload(every url entered by user…).Without using javascript………
Uptil I have created component which is starting up automatically . I registered for AddProgressListener (NOTIFY_STATE_ALL | NOTIFY_ALL)….
But I am unable to get OnStateChange() event. I tried a lot but am still having problems. I searched codes on the i-net but it confuses me.
I am sending code below. I promise it is short code(not big stuff..). it is Build and running program….
Will you please take look by your experienced eyes? You can do changes in code.
And one one other question…..
OnState change is called for every request?
For getting url I have to navigate through all the tabs which are opened?(is there any way to get url directly without doing this stuff…).
I hope you will help me…………………
Waiting for your reply…………..
Sachin Khutwad.
I implemented
class MyComponent : public IMyComponent, public nsIWebProgressListener, public nsIObserver
{
}
in my observe() method following is code ::
NS_IMETHODIMP MyComponent::Observe(nsISupports *aSubject, const char *aTopic, const PRUnichar *aData)
{
nsresult rv;
WCHAR wszURL[MAX_PATH] = L"";
nsCOMPtr<nsIObserverService> os;
nsCOMPtr<nsIServiceManager> servMan;
rv = NS_GetServiceManager(getter_AddRefs(servMan));
if (NS_SUCCEEDED(rv))
{
servMan->GetServiceByContractID("@mozilla.org/observer-service;1",NS_GET_IID(nsIObserverService),getter_AddRefs(os));
if (_stricmp(aTopic, "xpcom-startup") == 0)
{
nsCOMPtr<nsIWebProgress> progress;
servMan->GetServiceByContractID("@mozilla.org/docloaderservice;1", NS_GET_IID(nsIWebProgress), getter_AddRefs(progress));
progress->AddProgressListener(this, nsIWebProgress::NOTIFY_STATE_ALL | nsIWebProgress::NOTIFY_ALL);
MessageBox(NULL,L"prgresslistner added",L"Success",MB_OK);
}
}
return NS_OK;
}
And in OnSteateChange() Method following is code ::
NS_IMETHODIMP MyComponent::OnStateChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, PRUint32 aStateFlags, nsresult aStatus)
{
MessageBox(NULL,L"inside OnStateChange ()",L"Success",MB_OK);
if ((aStateFlags & STATE_STOP) && (aStateFlags & STATE_IS_DOCUMENT))
{
MessageBox(NULL,L"inside OnStateChange ()",L"Success",MB_OK);
}
return NS_OK;
}
Can anyone please tell me why OnstateChange() method is not getting called?
Please give any code sample if you have.