Hi,

I am having a hard time with figuring out why my custom content listener is no longer called after some time.

Basically, i want my extension to get triggered when a document with a specific content type is loaded. So i implement a content listener as a javascript component and i register it through "@mozilla.org/uriloader;1". It works just fine, but one minute or 2 after the launch of Firefox, the component is not called anymore, regardless of whether it has been called before.

I narrowed my code to this:

function DummyHandler() {
    dump("[DummyHandler] constructor\n");
var uriLoader = Components.classes["@mozilla.org/uriloader;1"].getService(Components.interfaces.nsIURILoader);
    uriLoader.registerContentListener(this);
}

DummyHandler.prototype = {
get loadCookie() { dump("[DummyHandler] get loadCookie\n"); return this.mLoadCookie; }, set loadCookie(newval) { dump("[DummyHandler] set loadCookie\n"); return this.mLoadCookie=newval; }, get parentContentListener() { dump("[DummyHandler] get parentContentListener\n"); return this.mParentContentListener; }, set parentContentListener(newval) { dump("[DummyHandler] set parentContentListener\n"); return this.mParentContentListener=newval; }
}

DummyHandler.prototype.canHandleContent = function(
        contentType,
        isContentPreferred,
        desiredContentType )  {
        dump("[DummyHandler] canHandleContent contentType: "+contentType+"\n");
        return false;
}

DummyHandler.prototype.doContent = function(
        contentType ,
        isContentPreferred ,
        request ,
        contentHandler ) {
        dump("[DummyHandler] doContent contentType: "+contentType+"\n");
        return false;
}

DummyHandler.prototype.isPreferred = function(
        contentType ,
        desiredContentType ) {
dump("[DummyHandler] isPreferred contentType: "+contentType+" "+desiredContentType+"\n");
        return false;
}

DummyHandler.prototype.onStartURIOpen = function( URI ) {
        dump("[DummyHandler] onStartURIOpen: "+URI.spec+"\n");
        return false;
}

DummyHandler.prototype.GetWeakReference = function( ) {
        dump("[DummyHandler] GetWeakReference\n");
        return this;
}

DummyHandler.prototype.QueryInterface = function(iid) {
        dump("[DummyHandler] QueryInterface("+iid+")\n");
    if(
        iid.equals(Components.interfaces.nsISupport) ||
        iid.equals(Components.interfaces.nsIURIContentListener) ||
        iid.equals(Components.interfaces.nsISupportsWeakReference)
        ) {
        return this;
        }
    throw Components.results.NS_ERROR_NO_INTERFACE;
}

[... + usual javascript component registering stuff ...]

I instantiate my component from my overlay file.

After some time, the isPreferred stopped being called.

I also notice that onStartURIOpen, canHandleContent, GetWeakReference and the accessor functions never get called, even at the beginning and when isPreferred returns true. This is not a problem in my case as i normally do all my stuff with isPreferred and doContent, but this might be a clue.

Can the "@mozilla.org/uriloader;1" component forget about my listener ?

Any idea anyone ?

Thanks.
_______________________________________________
dev-tech-network mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-network

Reply via email to