XULRunner:防止链接到任意域

发布于 2024-07-25 03:34:48 字数 430 浏览 2 评论 0原文

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

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

  • “真正的”浏览器打开(就像在 Prism 中一样),或者
  • 什么也没有发生。

有什么想法可以做到这一点吗? 使用 browser.document.onload 或 DOMready 或此类事件是不够的,因为即使在页面加载期间(即,当这些事件尚未触发时)也必须安全地阻止链接。

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

仲春光 2024-08-01 03:34:48

看来您想要类似于 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 函数在上面的代码中定义。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文