nsIContentPolicy problem. ShouldLoad not called
I've almost copyed all the necessary code from the tutorial:Creating
XPCOM Components([url]https://developer.mozilla.org/en/[/url]
Creating_XPCOM_Components) and [url]https://developer.mozilla.org/en/nsIContentPolicy[/url]
All works fine except for one thing: the ShouldLoad() and ShouldProcess
() function have never been called at all. I've checked the return
value of AddCategoryEntry(), nothing was wrong. Of course I did search
a lot, but only to find lots of guys asking the same question with
mine and no one replies. So I did'nt even change the subject. hope
it's not a stupid question.
Re: nsIContentPolicy problem. ShouldLoad not called
On 6 sep, 14:46, Justin Z <june.ue...@gmail.com> wrote:[color=blue]
> I've almost copyed all the necessary code from the tutorial:Creating
> XPCOM Components([url]https://developer.mozilla.org/en/[/url]
> Creating_XPCOM_Components) andhttps://developer.mozilla.org/en/nsIContentPolicy
> All works fine except for one thing: the ShouldLoad() and ShouldProcess
> () function have never been called at all. I've checked the return
> value of AddCategoryEntry(), nothing was wrong. Of course I did search
> a lot, but only to find lots of guys asking the same question with
> mine and no one replies. So I did'nt even change the subject. hope
> it's not a stupid question.[/color]
You don't show any code. How i can say whats wrong?
Here is my code for my nsIContentPolicy implementation. It works
perfect:
//...
const CONTENT_POLICY_LISTENER_CLASS_ID = Components.ID("your id");
const CONTENT_POLICY_LISTENER_CLASS_NAME = "your class name";
const CONTENT_POLICY_LISTENER_CONTRACT_ID = "@yoursite.com/content-
policy-listener;1";
const Cc = Components.classes;
const Ci = Components.interfaces;
const Cr = Components.results;
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
//...
var gPolicyListener = null;
/**
* Service for adding custom handling of HTTP requests.
*/
function ContentPolicyListener() {
this.pref = Cc["@mozilla.org/preferences-service;1"].getService
(Ci.nsIPrefService).getBranch("netlistener_ext.");
}
ContentPolicyListener.prototype =
{
// properties required for XPCOM registration:
classDescription: CONTENT_POLICY_LISTENER_CLASS_NAME,
classID: CONTENT_POLICY_LISTENER_CLASS_ID,
contractID: CONTENT_POLICY_LISTENER_CONTRACT_ID,
_xpcom_factory: {
createInstance: function(outer, iid)
{
if (outer)
throw Cr.NS_ERROR_NO_AGGREGATION;
if (gPolicyListener == null) {
gPolicyListener = new ContentPolicyListener();
}
return gPolicyListener;
}
},
_xpcom_categories: [{category: "content-policy"}],
QueryInterface: XPCOMUtils.generateQI([Ci.nsIContentPolicy,
Ci.nsIObserverService]),
//... implementaion here
}
function NSGetModule(compMgr, fileSpec) {
return XPCOMUtils.generateModule([ContentPolicyListener]);
}
Re: nsIContentPolicy problem. ShouldLoad not called
Hi ant_katcin, thanks for your reply. I forgot to say my extension was
developed with VC++. One more thing is, my extension can be viewed by
the XPCOMViewer tool, with all the interfaces showed correctly.
Here is my code:
NS_IMPL_ISUPPORTS3(CSpecialThing, ISpecialThing, nsIObserver,
nsIContentPolicy);
NS_IMETHODIMP CSpecialThing::ShouldLoad(PRUint32 aContentType,
nsIURI *aContentLocation,
nsIURI *aRequestOrigin,
nsISupports *aContext,
const nsACString &aMimeTypeGuess,
nsISupports *aExtra,
PRInt16 *_retval)
{
::MessageBox(0,_T("should load "),NULL,0);
*_retval = REJECT_SERVER;
return NS_OK;
}
NS_IMETHODIMP CSpecialThing::ShouldProcess(PRUint32 aContentType,
nsIURI *aContentLocation, nsIURI *aRequestOrigin, nsISupports
*aContext, const nsACString &aMimeType, nsISupports *aExtra, PRInt16
*_retval)
{
return NS_OK;
}
NS_METHOD WebLockRegistration(nsIComponentManager *aCompMgr,
nsIFile *aPath,
const char *registryLocation,
const char *componentType,
const nsModuleComponentInfo *info)
{
::MessageBox(0,_T("WebLockRegistration"),_T(""),MB_OK);
nsresult rv;
nsCOMPtr<nsIServiceManager> servman =
do_QueryInterface((nsISupports*)aCompMgr, &rv);
if (NS_FAILED(rv))
return rv;
nsCOMPtr<nsICategoryManager> catman;
servman->GetServiceByContractID(NS_CATEGORYMANAGER_CONTRACTID,
NS_GET_IID(nsICategoryManager),
getter_AddRefs(catman));
if (NS_FAILED(rv))
return rv;
char* previous=nsnull;
rv = catman->AddCategoryEntry("content-policy",
SPECIALTHING_CLASSNAME,
SPECIALTHING_CONTRACTID_SRV,
PR_TRUE,
PR_TRUE,
&previous);
if (previous)
nsMemory::Free(previous);
rv = catman->AddCategoryEntry("app-startup",
SPECIALTHING_CLASSNAME,
SPECIALTHING_CONTRACTID_SRV,
PR_TRUE,
PR_TRUE,
&previous);
if (previous)
nsMemory::Free(previous);
return rv;
}
NS_METHOD WebLockUnregistration(nsIComponentManager *aCompMgr,
nsIFile *aPath,
const char *registryLocation,
const nsModuleComponentInfo *info)
{
nsresult rv;
nsCOMPtr<nsIServiceManager> servman =
do_QueryInterface((nsISupports*)aCompMgr, &rv);
if (NS_FAILED(rv))
return rv;
nsCOMPtr<nsICategoryManager> catman; servman->GetServiceByContractID
(NS_CATEGORYMANAGER_CONTRACTID,NS_GET_IID(nsICategoryManager),
getter_AddRefs(catman));
if (NS_FAILED(rv))
return rv;
rv = catman->DeleteCategoryEntry("content-policy",
SPECIALTHING_CLASSNAME, PR_TRUE);
rv = catman->DeleteCategoryEntry("app-startup",
SPECIALTHING_CLASSNAME,
PR_TRUE);
return rv;
}
NS_IMETHODIMP CSpecialThing::Observe(nsISupports *aSubject, const char
*aTopic, const PRUnichar *aData)
{
return NS_OK;
}
Re: nsIContentPolicy problem. ShouldLoad not called
Hi,
I have same problem you are facing.i am using firefox 3.0 and xulrunner-1.9.0.17.en-US.win32.sdk .
in nsContentPolicy.h return type was not mathcing with Weblock's example's ShouldLoad(..) method. So i change return type in nsContentPolicy.h. is it right thing?
My shouldLoad method is not called.
My codde is same as your code.
Will you please giude me?