problem with title in a WebProgressListener - Mozilla

This is a discussion on problem with title in a WebProgressListener - Mozilla ; Hi, I'm having trouble when creating a simple address bar listener. When I QueryInterface aRequest to nsIHttpChannel in the onLocationChange method, the title of the browser stops changing when I change in firefox between different tabs, and the title is ...

+ Reply to Thread
Results 1 to 3 of 3

Thread: problem with title in a WebProgressListener

  1. problem with title in a WebProgressListener

    Hi,
    I'm having trouble when creating a simple address bar listener. When
    I QueryInterface aRequest to nsIHttpChannel in the onLocationChange
    method, the title of the browser stops changing when I change in
    firefox between different tabs, and the title is left as the one of the
    newest tab. Here is the code:

    var urlListener = {
    QueryInterface: function(IID) {
    if (IID.equals(Components.interfaces.nsIWebProgressLi stener) ||
    IID.equals(Components.interfaces.nsISupportsWeakRe ference) ||
    IID.equals(Components.interfaces.nsISupports))
    return this;

    throw Components.results.NS_NOINTERFACE;
    },

    onLocationChange: function(aWebProgress, aRequest, location) {
    var httpChannel =
    aRequest.QueryInterface(Components.interfaces.nsIH ttpChannel);
    },

    onStateChange: function(aWebProgress, aRequest, aStateFlags, aStatus)
    {
    return 0;
    },

    onProgressChange: function() {},
    onStatusChange: function() {},
    onSecurityChange: function() {},
    onLinkIconAvailable: function() {}
    };

    var myExtension = {

    init: function() {
    gBrowser.addProgressListener(urlListener,
    Components.interfaces.nsIWebProgress.NOTIFY_LOCATI ON);
    },

    uninit: function() {
    gBrowser.removeProgressListener(urlListener);
    },
    };


    window.addEventListener("load", function() {myExtension.init()},
    false);
    window.addEventListener("unload", function() {myExtension.uninit()},
    false);

    Any help would be appreciated.


  2. Re: problem with title in a WebProgressListener

    Cosmin.ro wrote:

    >When I QueryInterface aRequest to nsIHttpChannel in the onLocationChange method, the title of the browser stops changing when I change in firefox between different tabs, and the title is left as the one of the newest tab.
    >

    If the channel isn't an instance of nsIHttpChannel the QueryInterface
    will throw an error, which isn't caught by the tabbed browser so it
    stops working too.

    Instead, you should test the channel like this:
    onLocationChange: function(aWebProgress, aRequest, aLocation) {
    if (aRequest instanceof Components.interfaces.nsIHttpChannel) {
    /* do nsIHttpChannel-like things with aRequest */
    }
    },

    --
    Warning: May contain traces of nuts.

  3. Re: problem with title in a WebProgressListener

    I forgot to say thanks, that worked.


+ Reply to Thread