Hello,
I am in the beginning stage of a project where I would like to use Mozilla/XPCOM to
capture URIs with specific extension and process them with some existing C++ code.
I suspect that my URIContentListener is not getting registered with the dispatcher,
since
1- when I try to load a page with extension .foo, I get a nsURILoader error (abort ||
m_targetStreamListener)
2- some of the logging and print statements are not printed.
Here is what I am doing
(i) --------------------------
In the 'Module' part of the code, I register myself in the 'content listener'
category, and I register the content listener with the dispatcher. (There might be a
problem with the lifetime of the pointer I get there?)
static NS_METHOD nsFooRegistrationProc(nsIComponentManager *aCompMgr,
nsIFile* aPath, const char*registryLocation, const char* componentType,
const nsModuleComponentInfo *info)
{
nsresult rv;
nsCOMPtr<nsICategoryManager>
catman(do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv));
if (NS_FAILED(rv))
return rv;
char* previous = nsnull; // seen in weblock application....
catman->AddCategoryEntry(NS_CONTENT_LISTENER_CATEGORYMANAGER_ENTRY,
"text/foo",
info->mContractID,
PR_TRUE, // ?
PR_TRUE, // ?
&previous);
if (previous)
nsMemory::Free(previous);
// Do I need to register the content listener here?
nsCOMPtr<nsIURILoader> dispatcher
= do_GetService(NS_URI_LOADER_CONTRACTID, &rv);
if (NS_SUCCEEDED(rv))
{
nsCOMPtr<nsIURIContentListener> listener;
listener = do_CreateInstance(NS_FOO_CONTRACTID);
rv = dispatcher->RegisterContentListener(listener);
}
return NS_OK;
}
(ii) ------------------------
In the docontent method, I assigned a streamlistener to the pointer.
NS_IMETHODIMP nsFoo::DoContent(const char* aContentType,
PRBool aIsContentPreferred, nsIRequest* aRequest,
nsIStreamListener** aContentHandler, PRBool* retval)
{
PR_LOG(gFooXpcomLog, PR_LOG_DEBUG, ("FooXpcom DoContent\n"));
printf("Hello !!!\n");
if (!listener_)
{
listener_ = do_CreateInstance(NS_FOOLISTEN_CONTRACTID);
}
*aContentHandler = listener_;
return NS_OK;
}
where nsCOMPtr<nsFooListener> listener_;
--------------------------
At startup, XPCOM loads the module fine (or so it seems):
1079716704[8093548]: nsNativeComponentLoader: Loaded "libfoopcom.so".
1079716704[8093548]: nsComponentManager:
RegisterComponentCommon({73ab5f6a-e11c-4201-8847-407e50d0f73a},
@mozilla.org/fooxpcom;1?type=text/foo, rel:libfooxpcom.so,
application/x-mozilla-native)
1079716704[8093548]: nsNativeComponentLoader: loading "libdocshell.so"
1079716704[8093548]: nsNativeComponentLoader: Factory creation succeeded for
rel:libdocshell.so
1079716704[8093548]: nsComponentManager:
CreateInstanceByContractID(@mozilla.org/uriloader;1) succeeded
1079716704[8093548]: nsNativeComponentLoader: Factory creation succeeded for
rel:libfooxpcom.so
1079716704[8093548]: nsComponentManager:
CreateInstanceByContractID(@mozilla.org/fooxpcom;1?type=text/foo) succeeded
1079716704[8093548]: nsComponentManager:
RegisterComponentCommon({be642f9f-a5db-4e06-aecb-d3f47a0787ba},
@mozilla.org/fooxpcom/foo;1, rel:libfooxpcom.so, application/x-mozilla-native)
1079716704[8093548]: nsNativeComponentLoader: Autoregistration Passed for
"libfooxpcom.so".
but upon loading a document file:///tmp/bar.foo, I get
1079716704[8093548]: Got type from channel: 'text/foo'
1079716704[8093548]: Disposition header: ''
1079716704[8093548]: forceExternalHandling: no
1079716704[8093548]: [0x87282b8] nsDocumentOpenInfo::TryContentListener;
mIsContentPreferred = false
1079716704[8093548]: WARNING:
NS_ENSURE_TRUE(NS_SUCCEEDED(docLoaderFactory->CreateInstance("view", aOpenedChannel,
aLoadGroup, aContentType, static_cast< nsIContentViewerContainer * >(this), 0,
aContentHandler, aViewer))) failed, file nsDocShell.cpp, line 4619
1079716704[8093548]: ###!!! ASSERTION: DoContent returned no listener?: 'abort ||
m_targetStreamListener', file nsURILoader.cpp, line 728
1079716704[8093548]: ###!!! Break: at file nsURILoader.cpp, line 728
which suggest my 'DoContent' code doesn't get tried, and probably that the
TryContentListener doesn't try on my listener...
I welcome any suggestions... I've been looking at some code in the mailnews/base/src,
the security, but I can't get my story straight. Need help, thanks!
Matthieu
_______________________________________________
Mozilla-xpcom mailing list
[EMAIL PROTECTED]
http://mail.mozilla.org/listinfo/mozilla-xpcom