XULRunner:阻止到任意域的链接 [英] XULRunner: Prevent links to arbitrary domains

查看:175
本文介绍了XULRunner:阻止到任意域的链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设,我们有一个像XULRunner应用程序的Mozilla Prism。有一个带有< browser />元素的XUL窗口,浏览器在给定的域(例如example.com)上显示一个网页。



是example.com上的几个链接。如果用户遵循本地链接(即停留在example.com上),应该允许他们关注。如果另一方面链接到elpmaxe.moc,应该有(我不介意)这两种可能性:


  • 真正的浏览器打开(就像在Prism中),或
  • 没有任何反应。


    <任何想法都可以做到这一点?使用browser.document.onload或DOMready或这样的事件是不够的,因为即使在页面加载期间链接也必须被安全地阻止(即,当这些事件都没有被触发时)。
    <解决方案似乎你想要的功能与 BlockSite - 除了要将应用的域名加入白名单并阻止其他所有内容。 在XUL Runner中安装扩展有一些MDC文档可能有帮助。



    或者,您可以查看源代码并尝试找出它所在的位置 - 这样可以让您实现另一种行为,即阻止并避免在应用中发送扩展。我认为 BlockSite.js 是关键文件,看起来像处理程序被添加到这里(第171行):

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



    BlockSiteObserver 函数在代码中定义就在上面。


    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).

    解决方案

    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.

    这篇关于XULRunner:阻止到任意域的链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆