Did you try implementing these interfaces?

class MyComponent : public nsIObserver,
              public IMyComponent,
              public nsIWebProgressListener,
              public nsSupportsWeakReference,
              public nsIUnicharStreamListener
{
public:
MyComponent();
virtual ~MyComponent();

NS_DECL_ISUPPORTS
NS_DECL_NSIOBSERVER
NS_DECL_NSIWEBPROGRESSLISTENER
NS_DECL_NSIUNICHARSTREAMLISTENER
NS_DECL_IMYCOMPONENT
}

also, you need to add this in the Component Registration routine:

  rv = catman->AddCategoryEntry("Parser data listener",
                          MY_COMPONENT_CLASSNAME,
                          MY_COMPONENT_CONTRACTID,
                          PR_TRUE,
                          PR_TRUE,
                          &previous);


To get post data, you do these in the progresslistene OnStateChange

nsCOMPtr<nsIChannel> channel(do_QueryInterface((nsISupports*)aRequest, &rv));
nsCOMPtr<nsIHttpChannel> httpChannel(do_QueryInterface(channel));
nsCOMPtr<nsIUploadChannel> uc(do_QueryInterface(channel));
nsCOMPtr<nsIInputStream> inputStream;
uc->GetUploadStream(getter_AddRefs(inputStream));

// and rewind after you are done reading

nsCOMPtr<nsISeekableStream> postDataSeekable(do_QueryInterface(inputStream)); if (postDataSeekable) postDataSeekable->Seek(nsISeekableStream::NS_SEEK_SET, 0);

Steve




lav wrote:
Hi,

I am trying to build an XPCOM that monitors the http request and
response headers and data.
I have a working version of a sample, that implements nsIObserver. I
would like to be notified on http-on-modify-request topic, to get hold
of the nsIhttpChannel interface.

My question is, is is okay to do the above in the Observe method
implementation of my XPCOM. FOr eg in "xpcom-startup" or "app-startup"
event. Well, i tried adding them, using AddObserver method, but it
keeps failing.

Dont know where i am goign wrong.

Any help is greatly appreciated.

here is the code snippet

MyComponent::Observe(nsISupports *aSubject, const char *aTopic, const
PRUnichar *aData)
{
        nsresult rv;
        nsCOMPtr<nsIServiceManager> servMan;
        if (strcmp(aTopic,"app-startup")==0)
        {
        rv = NS_GetServiceManager(getter_AddRefs(servMan));
        if (NS_FAILED(rv))
                return rv;
                nsCOMPtr<nsIObserverService> observerService;
                
servMan->GetServiceByContractID("@mozilla.org/observer-service;1",
                        NS_GET_IID(nsIObserverService),
                        getter_AddRefs(observerService));
                if (!observerService)
                        return NS_ERROR_FAILURE;
                rv = observerService->AddObserver(
                        this,
                        "http-on-modify-request", PR_TRUE);
        }
return NS_OK;
}
Thanks,
lav

_______________________________________________
dev-tech-xpcom mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-xpcom




_______________________________________________
dev-tech-xpcom mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-xpcom

Reply via email to