防止 xulrunner 中的浏览器位置更改
我一直在阅读和使用 https://developer.mozilla.org/en/XUL_School/ Intercepting_Page_Loads 但似乎可以做我需要的事情。
我正在研究 Chromeless,试图防止主 xulbrowser 元素被导航离开,例如链接不应该工作,window.location.href="http://www.example.com/"
也不应该工作。
我假设我可以通过 browser.webProgress.addProgressListener 来做到这一点,然后监听 onProgressChange ,但我不知道如何区分资源请求和 < code>browser 更改位置(似乎 onLocationChange
为时已晚,因为文档已经被卸载)。
browser.webProgress.addProgressListener({
onLocationChange: function(){},
onStatusChange: function(){},
onStateChange: function(){},
onSecurityChange: function(){},
onProgressChange: function(){
aRequest.QueryInterface(Components.interfaces.nsIHttpChannel)
if( /* need to check if the object triggering the event is the xulbrowser */ ){
aRequest.cancel(Components.results.NS_BINDING_ABORTED);
}
},
QueryInterface: xpcom.utils.generateQI([Ci.nsIWebProgressListener, Ci.nsISupportsWeakReference])
}, wo._browser.webProgress.NOTIFY_ALL);
另一个听起来很有希望的选项是 nsIContentPolicy.shouldLoad() 方法,但我真的不知道如何“创建一个扩展 nsIContentPolicy 的 XPCOM 组件并使用 nsICategoryManager 将其注册到“内容策略”类别”。
有什么想法吗?
I've been reading and hacking around with https://developer.mozilla.org/en/XUL_School/Intercepting_Page_Loads but can seem to do what I need.
I'm working on Chromeless, trying to prevent the main xulbrowser element from ever being navigated away from, e.g., links should not work, neither should window.location.href="http://www.example.com/"
.
I'm assuming I can do this via browser.webProgress.addProgressListener
and then listen to onProgressChange
but I can't figure out how to differentiate between a resource request and the browser
changing locations (it seems that onLocationChange
is too late as the document is already being unloaded).
browser.webProgress.addProgressListener({
onLocationChange: function(){},
onStatusChange: function(){},
onStateChange: function(){},
onSecurityChange: function(){},
onProgressChange: function(){
aRequest.QueryInterface(Components.interfaces.nsIHttpChannel)
if( /* need to check if the object triggering the event is the xulbrowser */ ){
aRequest.cancel(Components.results.NS_BINDING_ABORTED);
}
},
QueryInterface: xpcom.utils.generateQI([Ci.nsIWebProgressListener, Ci.nsISupportsWeakReference])
}, wo._browser.webProgress.NOTIFY_ALL);
Another option that sounds promising is the nsIContentPolicy.shouldLoad()
method but I really have no clue how to "create an XPCOM component that extends nsIContentPolicy and register it to the "content-policy" category using the nsICategoryManager."
Any Ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我从 mozilla 的 #xulrunner irc 频道获得了有关此问题的帮助。
结果解决方案如下。
注意:这是一个在 Mozilla Chromeless 中使用的模块,
require("chrome")
和require("xpcom")
位在正常情况下将不可用 https://github.com感兴趣的人可以在 github 上拉取请求: /mozilla/chromeless/pull/114
I got help on this from the mozilla's #xulrunner irc channel.
Resulting solution follows.
Note: this is a module for use in Mozilla Chromeless, the
require("chrome")
andrequire("xpcom")
bits will NOT be available under normal circumstances.Pull Request on github for those that are interested: https://github.com/mozilla/chromeless/pull/114