1

Is there any way from an nsIChannel/nsIStreamListener to get the HTML element that caused the request to be sent in the first place?

I subscribed to http-on-examine-response and I am using nsITraceableChannel.setNewListener to read and modify incoming content. I want to only modify javascript content loaded from script tags, but I haven't found a reliable way to identify which responses are suitable. The MIME header cannot be trusted. Can I access information about what FF is planning to use this request for?

Perhaps something to do with the callbacks or the observers in the loadgroup?

Edit: is the aContentType argument of nsIContentPolicy.shouldLoad trustworthy? If I was able to pass information through the channel, I'd be set...

4

1 回答 1

0

nsIContentPolicy.shouldLoad 的 aContentType 参数是否可信?

AFAIK,是的,就涉及核心代码而言,但期望附加组件行为不端。

nsScriptLoader实现将在加载外部脚本之前对其进行检查其他核心代码不(ab)使用相同的类型。但请记住,您不会收到询问内联脚本的通知。此外,在脚本的情况下, aContexttoshouldLoad应该是nsIScriptElement(不可编写脚本的),这也是 nsIScriptLoaderObserver (可编写脚本的)并且可能是 a nsIDOMHTMLScriptElement,所以我想你可以确定QI/instanceof一下aContext

至于nsIChannel通过 http-observers 获取元素:我认为不可能这样做。我上面提到的 script 元素将被填充到 non-scriptablensScriptLoadRequest中,而后者又作为上下文提供给nsIChannel.asyncOpen(),因此即使它是可编写脚本的,它也不可用。

于 2013-08-09T16:57:04.830 回答