views:

137

answers:

1

Hi,

suppose, we have a Mozilla Prism like XULRunner app. There is a XUL window with a <browser/> element, where the browser shows a web page on a given domain (say, example.com).

Now there are several links on example.com. If a user follows a local link (i.e., stays on example.com) she should be allowed to follow. If on the other hand the link goes to elpmaxe.moc, there should be (I don't mind) any of those two possibilities:

  • The "real" browser opens (just like in Prism), or
  • nothing happens.

Any ideas hwo to do this? It is not sufficient to use browser.document.onload or DOMready or such events, because the link has to be blocked safely even during page load (i.e., when none of these events fired yet).

Cheers,

+1  A: 

It seems you want functionality similar to that provided by BlockSite - except you want to whitelist the app's domain and block everything else. There's some MDC documentation on installing extensions within XUL Runner which may help.

Alternatively you could have a look through the source code and try and work out where it hooks in - this would let you implement an alternative behaviour to just blocking and avoid shipping an extension with your app. I think BlockSite.js is the key file, looks like the handler gets added here (line 171):

var observerService = Components.classes["@mozilla.org/observer-service;1"].getService(Components.interfaces.nsIObserverService);
observerService.addObserver(BlockSiteObserver, "http-on-modify-request", false);

The BlockSiteObserver function is defined in the code just above.

robertc
Cool! Thank you for pointing me to this. It looks very promising. As soon as I can test it (should be done this week), I'll accept the answer.
Boldewyn
Yep, the observer is exactly what I searched for. Thank you!
Boldewyn