In an XULRunner application, I want to check all URLs before their open
so that I can redirect some URLs to a specified server. I am not sure
if the "onStartURIOpen" method of nsIURIContentListener can be used to
do that. And, seems I can't register the nsIURIContentListener
correctly. Who knows how to do that? Thanks. The code is attached
below:

//mybrowser.xul

<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>

<window id="mybrowser" width="800" height="600"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";>
<script src="mybrowser.js"/>
<browser flex="1" id="browser" src="" type="content-primary"/>
</window>

//mybrowser.js
function URIContentListener() {
}

URIContentListener.prototype = {

QueryInterface: function(aIID) {
if (aIID.equals(Components.interfaces.nsISupports)
|| aIID.equals(Components.interfaces.nsIURIContentListener)
|| aIID.equals(Components.interfaces.nsISupportsWeakReference))
return this;
throw Components.results.NS_ERROR_NO_INTERFACE;
},

canHandleContent: function (contentType , isContentPreferred ,
desiredContentType ) {
return true;
},

doContent: function (contentType ,isContentPreferred ,request ,
contentHandler ) {
return true;
},

isPreferred: function (contentType ,desiredContentType ) {
return true;
},

onStartURIOpen: function (URI ) {
alert("onStartURIOpen");
return false;
}
};

function onload() {

var browser = document.getElementById("browser");

uriListener = new URIContentListener();

var uriLoader =
Components.classes["@mozilla.org/uriloader;1"].getService(Components.interfaces.nsIURILoader);
uriLoader.registerContentListener(uriListener);
}

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

Reply via email to