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

时间:2023-01-23 21:14:27

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

我正在尝试将Internet Explorer插件移植到Firefox,但我不确定在哪里寻找我需要的东西。

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.

基本上我需要能够使用某个Content-Type标头过滤浏览器收到的所有内容。我尝试实现流转换器,这是有效的,但仅适用于页面,框架或iframe中的*文档。我遇到了与IE相同的问题,并且绕过它真的很hacky,因为我理想这样做是跨平台的,我真的希望能够在Firefox中做到这一点而不诉诸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.

内容以专有压缩格式压缩。因此,我需要接收数据,对其进行解压缩,然后将Content-Type更改回原始未压缩文件应具有的内容。

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

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

Thanks

1 个解决方案

#1


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

我想我可能找到了我需要的东西。我遇到了这个用于跟踪HTTP调用的链接: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.

由于某种原因,JavaScript实现似乎存在一些问题,我不是一个JavaScript大师,但我已经用C ++实现了它,初步结果表明我应该能够根据我的需要修改它。

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.

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

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.

我们再次将大部分调用代理回原始处理程序。但是在OnDataAvailable中,我们不是将数据传递给底层的nsIStreamListener,而是使用nsIStorageStream保存它。然后在OnStopRequest中,在我们获得所有数据之后,我们可以解压缩它,然后在原始处理程序上调用OnDataAvailable,然后调用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.

到目前为止,它已经进行了一些小的简单测试,但我必须通过一些更严格的测试...我还必须弄清楚我是否可以用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.

我目前看到的最大问题是它依赖于一些未冻结的接口,如nsIHttpChannelInternal。据我所知,无法帮助,我的版本兼容性要求非常小,所以如果必须,我可以忍受它。

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

与此同时,如果有人有任何其他建议,我全都听见了:D

#1


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

我想我可能找到了我需要的东西。我遇到了这个用于跟踪HTTP调用的链接: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.

由于某种原因,JavaScript实现似乎存在一些问题,我不是一个JavaScript大师,但我已经用C ++实现了它,初步结果表明我应该能够根据我的需要修改它。

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.

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

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.

我们再次将大部分调用代理回原始处理程序。但是在OnDataAvailable中,我们不是将数据传递给底层的nsIStreamListener,而是使用nsIStorageStream保存它。然后在OnStopRequest中,在我们获得所有数据之后,我们可以解压缩它,然后在原始处理程序上调用OnDataAvailable,然后调用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.

到目前为止,它已经进行了一些小的简单测试,但我必须通过一些更严格的测试...我还必须弄清楚我是否可以用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.

我目前看到的最大问题是它依赖于一些未冻结的接口,如nsIHttpChannelInternal。据我所知,无法帮助,我的版本兼容性要求非常小,所以如果必须,我可以忍受它。

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

与此同时,如果有人有任何其他建议,我全都听见了:D