Re: how to implement nsIWepProgressListener in C++

Christian Sell <[email protected]> Mon, 24 Feb 2014 03:15:14 -0800 (PST)
Newsgroups gmane.comp.mozilla.devel.embedding
Message-ID <[email protected]>
ok, I have finally managed. Heres the code:

//class decl
class LocationListener: public nsIWebProgressListener, public nsSupportsWeakReference
{
public:
  LocationListener();
  virtual ~LocationListenerW();
  NS_DECL_ISUPPORTS
  NS_DECL_NSIWEBPROGRESSLISTENER
};

//class impl
NS_IMPL_ISUPPORTS2(LocationListener, nsIWebProgressListener, nsISupportsWeakReference)

NS_IMETHODIMP LocationListener::OnXXChange(...)
{
	return NS_OK;
}

//and class usage. plistener must be created non-locally
LocationListener * listener = new LocationListener();
nsCOMPtr<nsISupports> plistener = static_cast<nsIWebProgressListener *>(listener);

nsCOMPtr<nsIWeakReference> weakref = do_GetWeakReference(plistener, &retval);
retval = browser->AddWebBrowserListener(weakref, NS_GET_IID(nsIWebProgressListener));