instance of nsIURIContentListener never gets called - Mozilla

This is a discussion on instance of nsIURIContentListener never gets called - Mozilla ; Hi everyone! I'm trying to hook my custom nsIURIContentListener (just to track the starts of page loads) to a particular Browser object, but my code never gets called. The code is: function custom_tab_uri_listener(parentBrowser) { this.init(parentBrowser); return this; } custom_uri_listener.prototype = ...

+ Reply to Thread
Results 1 to 2 of 2

Thread: instance of nsIURIContentListener never gets called

  1. instance of nsIURIContentListener never gets called

    Hi everyone!

    I'm trying to hook my custom nsIURIContentListener (just to track the
    starts of page loads) to a particular Browser object, but my code
    never gets called. The code is:

    function custom_tab_uri_listener(parentBrowser)
    {
    this.init(parentBrowser);
    return this;
    }

    custom_uri_listener.prototype = {

    init: function(parentBrowser)
    {
    var docShell = parentBrowser.docShell;
    oldListener =
    docShell.QueryInterface(Components.interfaces.nsII nterfaceRequestor)
    .getInterface(Components.interfaces.nsIURIContentL istener);

    oldListener.parentContentListener = this;

    /* // Also tried:
    var wnd =
    parentBrowser.contentWindow.QueryInterface(Compone nts.interfaces.nsIInterfaceRequestor)
    .getInterface(Components.interfaces.nsIWebNavigati on)
    .QueryInterface(Components.interfaces.nsIDocShell)
    .QueryInterface(Components.interfaces.nsIInterface Requestor)
    .getInterface(Components.interfaces.nsIURIContentL istener);

    wnd.parentContentListener = this;*/
    },

    QueryInterface: function(aIID)
    {
    if(aIID.equals(Components.interfaces.nsISupports) ||
    aIID.equals(Components.interfaces.nsIURIContentLis tener) ||
    aIID.equals(Components.interfaces.nsISupportsWeakR eference))
    return this;

    throw Components.results.NS_NOINTERFACE;
    },

    GetWeakReference: function()
    {
    alert("GetWeakReference");
    return this;
    },

    canHandleContent: function(/*char* */ contentType, /*function*/
    isContentPreferred, /*out char* */ desiredContentType)
    {alert(contentType);
    return (contentType.indexOf("html") != -1);
    },

    doContent: function(/*char* */ contentType, /*function*/
    isContentPreferred, /*nsIRequest*/ request, /*out nsIStreamListener*/
    contentHandler)
    {alert(contentType);
    return true;
    },

    isPreferred: function(/*char* */ contentType, /*out char* */
    desiredContentType)
    {alert(contentType);
    return (contentType.indexOf("html") != -1);
    },

    onStartURIOpen: function(/*nsIURI*/ URI)
    {
    alert(URI.spec);
    return true;
    }
    };

    (later in my code I write:

    listener = new custom_tab_uri_listener(gBrowser.selectedBrowser);
    )

    Code doesn't produce errors, but neither of functions gets invoked.
    What am I doing wrong? Thank you much in advance!

  2. Re: instance of nsIURIContentListener never gets called

    Nevermind the inconsistency in object/prototype names - my bad when
    editing the post.

    The line:

    > custom_uri_listener.prototype = {


    should read as:

    > custom_tab_uri_listener.prototype = {


+ Reply to Thread