Search code examples
firefoxpluginsxpcomnpapinpruntime

How to get browser proxy from NPAPI plugin, without using xpcomglue?


I am developing a plugin, and I need to get browser proxy for a given host.

Right now it works using nsIProtocolProxyService. However, the NewURI function (needed to construct an URI object, used by nsIProtocolProxyService::resolve()) takes a const reference to nsACString. And it looks like, for any concrete implementation of it I need to link with xpcomglue, which I cannot do (If I understand it right, I shouldn't link dynamically for techincal reasons; and I cannot link statically with xpcomglue_s for legal reasons).

So, how can I get browser proxy without linking with xpcomglue?


Solution

  • This is definitely a tricky question. Really, the best way (when possible) is to use the NPN_GetURL/NPN_PostURL style NPAPI functions when possible. If that's not possible, you're more or less up a creek unless you can rely on a recent browser version.

    If you can assume a recent version of Firefox / gecko API (I'm pretty sure Firefox 3.6 supports this, but not certain which started; docs say gecko SDK 1.9, but I don't think it was there at that point) then you can use NPN_GetValueForURL with NPNURLVProxy to get the proxy information for a given URL.

    Again, keep in mind that this will only work on newer browsers, and I haven't had a chance to compile a compatibility matrix on what supports it yet; I have plans to add this to FireBreath, but it didn't make it into 1.4 so it may be another month before I get to it.

    As a failover option, the most common solution if this isn't available is to simply get the proxy configuration for WinInet (internet explorer) and trust that it will be the same.

    This is (IMO) a significant issue without a really good fix. This is the reason that Flash is notoriously fickle with network access across proxies as well.