如何在 Firefox 中为所有页面元素实现内容转换器?

发布于 2024-07-25 21:52:44 字数 392 浏览 5 评论 0原文

我正在尝试将 Internet Explorer 插件移植到 Firefox,但我不确定在哪里可以找到我需要的内容。

基本上,我需要能够使用特定的 Content-Type 标头过滤浏览器接收到的所有内容。 我尝试实现一个流转换器,这有效,但仅适用于页面、框架或 iframe 中的顶级文档。 我在 IE 上也遇到了同样的问题,解决它确实很麻烦,而且由于我理想地希望这是跨平台的,所以我真的希望能够在 Firefox 中做到这一点,而无需诉诸 vtable hacks。

内容以专有压缩格式压缩。 所以我需要接收数据,解压缩它,并将 Content-Type 更改回原始未压缩文件应有的内容。

如果有一种方法可以过滤收到的所有数据,这可能是可以接受的,我可以自己解析标头。

谢谢

I'm attempting to port over an Internet Explorer plugin to Firefox, but I'm not sure where to look for what I need.

Basically I need to be able to filter all content that is received by the browser with a certain Content-Type header. I tried implementing a stream converter, and this works, but only for the top-level document in the page, frame, or iframe. I had the same problem with IE, and getting around it was really hacky, and since I would ideally like this to be cross platform I would really like to be able to do this in Firefox without resorting to vtable hacks.

The content is served compressed with a proprietary compression format. So I need to receive the data, decompress it, and change the Content-Type back to what the original uncompressed file should have.

If there is a way to just filter all data received, that would probably be acceptable, I could handle parsing the header myself.

Thanks

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

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

发布评论

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

评论(1

沧桑㈠ 2024-08-01 21:52:44

我想我可能已经找到了我需要的东西。 我发现了这个用于跟踪 HTTP 调用的链接: http://blues.ath .cx/firekeeper/resources/http_tracer.html

由于某种原因,JavaScript 实现似乎存在一些问题,我不是 JavaScript 专家,无法解决这个问题,但我已经用 C++ 实现了它,并且初步结果表明我应该能够根据我的需要对其进行修改。

基本上,我们用我们自己的实现替换 nsIHttpProtocolHandler 服务,它保留了对初始实现的引用。 当调用服务时,我们只是将其代理到保存的原始实现。 然后我们提供我们自己的 nsIHttpChannel 和 nsIStreamListener 实现,我们也将它们用作代理。

我们再次将大部分调用代理回原始处理程序。 但在 OnDataAvailable 中,我们没有将数据传递给底层 nsIStreamListener,而是使用 nsIStorageStream 保存数据。 然后在 OnStopRequest 中,获取所有数据后,我们可以将其解压缩,然后在原始处理程序上调用 OnDataAvailable,然后调用 OnStopRequest。

到目前为止,它已经进行了一些小型的简单测试,但我必须对其进行一些更严格的测试……我还必须弄清楚是否可以使用 HTTPS 做同样的事情。

目前我看到的最大问题是它依赖于一些未冻结的接口,例如nsIHttpChannelInternal。 但据我所知,我没办法,而且我的版本兼容性要求非常小,所以如果有必要的话我可以忍受。

与此同时,如果有人有任何其他建议,我会洗耳恭听:D

I think I may have found what I needed. I came across this link which is used for tracing HTTP calls: http://blues.ath.cx/firekeeper/resources/http_tracer.html

There seems to be some problems with the JavaScript implementation for some reason, and I'm not a JavaScript guru to figure it out, but I've implemented it in C++ and initial results suggest that I should be able to modify it for my needs.

Basically we're replacing the nsIHttpProtocolHandler service with our own implementation, which keeps a reference to the initial implementation. When a call is made to the service, we just proxy it over to the saved original implementation. Then we provide our own implementation of nsIHttpChannel and nsIStreamListener which we use as proxies too.

Again we proxy most of the calls back off to the original handlers. But in OnDataAvailable, instead of passing the data on to the underlying nsIStreamListener, we save it using nsIStorageStream. Then in OnStopRequest, after we've gotten all of the data, we can decompress it and then call OnDataAvailable on the original handler, followed by OnStopRequest.

It has worked on some small simple tests so far, but I'll have to put it through some more rigorous tests... I'll also have to figure out if I can do the same thing with HTTPS.

The biggest problem I see at the moment is that it relies on some unfrozen interfaces such as nsIHttpChannelInternal. Can't be helped though as far as I can tell, and my version compatibility requirements are pretty small, so I can live with it if I have to.

In the meantime, if anybody has any other suggestions, I'm all ears :D

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