In the first case, it loads fine and works fine, but when I turn my
extension OFF and call the unload function, the event still triggers
the function I loaded into the listener.
In the second case, If my homepage is google.com for example, and I
load the listener, then switch to another URL, the event will not
fire. Clicking on another link will fire the event, and it works from
here on out. The problem arises, I believe, because the init function
sets the old URL to null, and I check for this and ignore it because
when a new tab is opened, it will try to fire the function twice
because it changes from the old tab URL to NULL, then changes from
NULL to the new tab's URL.
Here is my code:
var EXTEN_urlBarListener = {
QueryInterface: function(aIID)
{
if (aIID.equals(Components.interfaces.nsIWebProgressListener) ||
aIID.equals(Components.interfaces.nsISupportsWeakReference) ||
aIID.equals(Components.interfaces.nsISupports))
return this;
throw Components.results.NS_NOINTERFACE;
},
onLocationChange: function(aProgress, aRequest, aURI)
{
domWindow = aProgress.DOMWindow;
EXTEN.processNewURL(aURI, domWindow);
},
onStateChange: function() {},
onProgressChange: function() {},
onStatusChange: function() {},
onSecurityChange: function() {},
onLinkIconAvailable: function() {}
};
var EXTEN = {
oldURL: null,
init: function() {
gBrowser.addProgressListener(EXTEN_urlBarListener,
Components.interfaces.nsIWebProgress.NOTIFY_STATE_DOCUMENT);
},
uninit: function() {
gBrowser.removeProgressListener(EXTEN_urlBarListener);
},
processNewURL: function(aURI, domWindow) {
if (aURI.spec == this.oldURL || !aURI.spec)
return;
if(domWindow == domWindow.top)
{
this.oldURL = aURI.spec;
EXTEN_Reset(); //MY FUNCTION TO FIRE
}
}
};
I then use the following to load/unload:
gBrowser.addEventListener("load", function() {fixShip.init()},
true); // LOAD
gBrowser.addEventListener("unload", function() {fixShip.uninit()},
true); //UNLOAD
Phew that's a mouthful. I derived the majority of the code from the
moz mdc website ( http://developer.mozilla.org/en/docs/Code_snippets:Progress_Listeners
). Any help at all would be greatly appreciated. Thanks again!
Bryan