Christian Biesinger <[EMAIL PROTECTED]> wrote in message news:<[EMAIL PROTECTED]>...
> On Wed, Jul 14, 2004 at 03:02:24AM -0700, yueweng wrote:
> > I have implement the suggestion in the following code, but, I am still
> > not able to capture any browser signal yet. May I know if there is
> > anything I missed out in the following code in order to start
> > receiving Mozilla browser event?
>
> It seems that you never make sure that your component gets called at any
> time. See for example
> http://www.mozilla.org/projects/xpcom/book/cxc/html/weblock.html#1001977
> for how to make sure that your component gets instantiated on each app
> startup.
>
> --
Hi Christian ,
Thanks for the help again. I have made changes by inherit one more
interface from nsIObserver. Then program is able to perform
nsSampleRegistrationProc() to do AddCategoryEntry("xpcom-startup",
similar to what weblock has done.
Then I restart the mozilla again. This time my constructor
nsSampleImpl() is being called, I think it should be, during starting
of mozilla. However, mozilla crashed inside the constructor,
nsSampleImpl() at the function AddProgressListener(). I don't know
what's wrong with my implementation, I am wondering if you can help me
up again?
/
The implementation of nsSampleImpl() is as follows:
static NS_DEFINE_IID(kDocLoaderServiceCID,
NS_DOCUMENTLOADER_SERVICE_CID);
nsSampleImpl::nsSampleImpl()
{
nsCOMPtr
progress(do_GetService(kDocLoaderServiceCID));
if (progress)
progress->AddProgressListener((nsIWebProgressListener*)this,
nsIWebProgress::NOTIFY_STATE_DOCUMENT);
}
//
The following is the callstack when crashed:
nsQueryInterface::operator()() line 47 + 21 bytes
nsCOMPtr::assign_from_qi() line 1030 + 17 bytes
nsCOMPtr::nsCOMPtr() line 572
nsCOMPtr::Assert_NoQueryNeeded() line 520
nsCOMPtr::nsCOMPtr() line 590
nsDocLoaderImpl::AddProgressListener() line 891 <-MY PROGRAM
nsSampleImpl::nsSampleImpl() line 79 <-MY PROGRAM
nsSampleImplConstructor() line 89 + 27 bytes <-MY PROGRAM
nsGenericFactory::CreateInstance() line 82 + 21 bytes
nsComponentManagerImpl::CreateInstanceByContractID() line 2000 + 24
bytes
nsComponentManagerImpl::GetServiceByContractID() line 2420 + 50 bytes
nsGetServiceByContractID::operator()() line 121 + 38 bytes
nsCOMPtr_base::assign_from_helper() line 114 + 18 bytes
nsCOMPtr::nsCOMPtr() line 846
NS_CreateServicesFromCategory() line 785 + 37 bytes
NS_InitXPCOM2() line 633 + 17 bytes
NS_InitXPCOM2() line 173 + 18 bytes
GRE_Startup() line 477 + 35 bytes
main() line 1705 + 5 bytes
mainCRTStartup() line 338 + 17 bytes
//
The implementation of other parts of the program is as follows:
NS_IMETHODIMP
nsSampleImpl::QueryInterface(REFNSIID aIID, void** aInstancePtr)
{
if (NULL == aInstancePtr) {
return NS_ERROR_NULL_POINTER;
}
*aInstancePtr = NULL;
if (aIID.Equals(NS_GET_IID(nsISample))) {
*aInstancePtr = (void*) NS_STATIC_CAST(nsISample*,this);
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(NS_GET_IID(nsSupportsWeakReference))) {
*aInstancePtr = (void*) NS_STATIC_CAST(nsISample*,this);
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(NS_GET_IID(nsIObserver))) {
*aInstancePtr = (void*) NS_STATIC_CAST(nsISample*,this);
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(NS_GET_IID(nsIWebProgressListener))) {
*aInstancePtr = (void*) NS_STATIC_CAST(nsISample*,this);
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(NS_GET_IID(nsISupports))) {
*aInstancePtr = (void*) NS_STATIC_CAST(nsISupports*,
NS_STATIC_CAST(nsISample*,this));
NS_ADDREF_THIS();
return NS_OK;
}
return NS_NOINTERFACE;
}
NS_IMPL_ADDREF(nsSampleImpl)
NS_IMPL_RELEASE(nsSampleImpl)
#define NS_SAMPLE_CONTRACTID "@mozilla.org/sample;1"
class nsSampleImpl : public nsIWebProgressListener,
public nsSupportsWeakReference,
public nsIObserver,
public nsISample
{
public:
nsSampleImpl();
NS_DECL_ISUPPORTS;
NS_DECL_NSISAMPLE
NS_DECL_NSIOBSERVER;
NS_DECL_NSIWEBPROGRESSLISTENER;
private:
~nsSampleImpl();
char* mValue;
};
static NS_METHOD nsSampleRegistrationProc(nsIComponentManager
*aCompMgr,
nsIFile *aPath,
const char
*registryLocation,
const char *componentType,
const nsModuleComponentInfo
*info)
{
nsresult rv;
nsCOMPtr servman =
do_QueryInterface((nsISupports*)aCompMgr, &rv);
if (NS_FAILED(rv))
return rv;
nsCOMPtr catman;