How do I reliably find a request's referrer in a firefox addon?
I've found the referrer attribute on nsIHttpChannel
and this works most of the time but this is only set subject to certain security checks (e.g. it won't be set if you're navigating from an HTTPS to an HTTP URL).
I can see that it's possible to get the load context (nsILoadContext
) and, through that, things like the associated window but I can't find a way of finding the referrer information through these.
So my question is this; for those requests which have a referring URL but which don't pass the security checks present on the nsI开发者_如何学JAVAHttpChannel
referrer attribute, is there a way of obtaining the referrer information?
Gecko saves the referrer in the docshell.internalReferrer
property even in the cases where the Referer
header isn't sent. In most cases you should be able to read out referrer information like this:
if (channel instanceof nsIPropertyBag)
{
try
{
referrer = channel.getProperty("docshell.internalReferrer");
}
catch (e)
{
// Internal referrer not set, fall back to the Referer header
referrer = channel.referrer;
}
}
精彩评论