Area de-PHPizzata  —  This area is free from PHP crapware

17 giugno 2009

How-to use "addProgressListener" in XULRunner…

I originally posted this in mozilla.dev.tech.xul newsgroup, server news.mozilla.org, on Nov, 23rd 2006.

/*
First, we’ll associate the progress listener for a "browser"
to a listener object:
*/

browserObject.addProgressListener( listObj,
Components.interfaces.nsIWebProgress.NOTIFY_STATE_WINDOW );

// Remember to define the object, something like this:

listObj = new Object();

listObj.wpl = Components.interfaces.nsIWebProgressListener;

listObj.QueryInterface = function( aIID ) {
if (aIID.equals(listObj.wpl) ||
aIID.equals(Components.interfaces.nsISupportsWeakReference) ||
aIID.equals(Components.interfaces.nsISupports)) return this;
throw Components.results.NS_NOINTERFACE;
}

listObj.onStateChange = function(aProgress, aRequest, aFlag, aStatus) {
if (aFlag & listObj.wpl.STATE_START) {
// This fires when the load event is initiated
} else {
if (aFlag & listObj.wpl.STATE_STOP) {
if ( aFlag & listObj.wpl.STATE_IS_WINDOW ) {
// This fires when ALL load finish
}
if ( aFlag & listObj.wpl.STATE_IS_NETWORK ) {
// Fires when ALL load are REALLY over,
// do something "final" here
} else {
// This fires when a load finishes
}
}
}
return 0;
}

// This fires when the location bar changes i.e load event is confirmed
// or when the user switches tabs
listObj.onLocationChange = function(aProgress, aRequest, aURI) {
// do whatever you want to do
return 0;
}

// For definitions of the remaining functions see XulPlanet.com
listObj.onProgressChange    = function() { return 0 };
listObj.onStatusChange      = function() { return 0 };
listObj.onSecurityChange    = function() { return 0 };
listObj.onLinkIconAvailable = function() { return 0 };

/*
I use the progress listener to trap the end of a local HTML
"template" file loading, and run XSLT transormations.
In addition I need to evaluate the browser contentDocument DOM
in order to clean "target" attributes on links, and so on.

HTH
*/

Etichette:

0 Commenti:

Posta un commento

Link a questo post:

Crea un link

<< Home page