My question is about the ShouldLoad method of interface nsIContentPolicy
My component registered in the content-policy category successfully and It's already called ShouldLoad when a page's loaded.
But when it executed these lines, firefox just crashed:
nsEmbedCString scheme;
contentLocation->GetScheme(scheme);
Here my complete ShoudLoad method:
NS_IMETHODIMP WebLock::ShouldLoad(PRUint32 contentType,
nsIURI *contentLocation,
nsIURI *aRequestOrigin,
nsISupports *aContext,
const nsACString & aMimeTypeGuess,
nsISupports *aExtra,
PRInt16 * _retval)
{
if (!contentLocation)
return NS_ERROR_FAILURE;
nsEmbedCString scheme;
contentLocation->GetScheme(scheme);
if (strcmp("http", scheme.get()) != 0 &&
strcmp("https", scheme.get()) != 0 &&
strcmp("ftp", scheme.get()) != 0 ) {
// this isn't a type of URI that we deal with.
*_retval = PR_TRUE;
return NS_OK;
}
nsEmbedCString hostToLoad;
contentLocation->GetHost(hostToLoad);
// Assume failure. Do not allow this nsIURI to load.
*_retval = PR_FALSE;
nsresult rv;
urlNode* node = mRootURLNode;
PRBool match = PR_FALSE;
while (node)
{
nsCOMPtr<nsIURI> uri;
nsEmbedCString urlString(node->urlString);
rv = mIOService->NewURI(urlString, nsnull, nsnull, getter_AddRefs(uri));
// if anything bad happens, just abort.
if (NS_FAILED(rv))
return rv;
nsEmbedCString host;
uri->GetHost(host);
if (strcmp(hostToLoad.get(), host.get()) == 0) {
// match found. Allow this nsIURI to load.
*_retval = PR_TRUE;
return NS_OK;
}
node = node->next;
}
return NS_OK;
}
So what's wrong ? do have I fogotten something ?
Thanks in advance for your help.
ps: Please excuse my bad English.