Click here to Skip to main content
15,881,815 members
Please Sign up or sign in to vote.
4.00/5 (2 votes)
See more:
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);
               //nsCString url;
               //aRequest->GetName(url);

           }

       return NS_OK;
    }


Can anyone please tell me why OnstateChange() method is not getting called?
Please give any code sample if you have.
Posted
Updated 22-Nov-10 20:42pm
v2

You need to inherit your class MyComponent also from nsSupportsWeakReference and have following in implementation NS_IMPL_ISUPPORTSX(CProgressListener, ... , nsISupportsWeakReference) where X is replaced with correct number of classes you inherit from. This will add weak reference implementation to your class. Remember that your object needs to have at least one strong reference (call AddRef on it) in order not to be destroyed by runtime.
 
Share this answer
 
if AddProgressListener fails it might be due to the class not inherited from nsSupportsWeakReference.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900