Friday, January 1, 2010

Regarding browser proxy settings for plugins

My UML professor, Dr. Fu, asked a question regarding Browser Plug-in use of a browser's proxy settings. It seemed like an easy enough question to answer, but before I knew it I was reading source code, so I'm not sure how obvious this info is. This may be the reason that so few plug-ins comply with a browser's proxy settings. I did a bit of research and decided to use it for my first blog post.


First I wanted to look at the Firefox proxy settings. It wasn't clear what 'Auto-detect proxy settings for this network' actually used to determine the proxy. Neither reading the Firefox help nor Googling, answered the question.
It turns out that all major browsers use a protocol called WPAD (Web Proxy Autodiscovery Protocol) that uses DHCP or DNS protocols to identify a URL that contains proxy details. More information is available here: http://en.wikipedia.org/wiki/Web_Proxy_Autodiscovery_Protocol
This file is formatted based on the Proxy Auto-Config (PAC) file standard (http://en.wikipedia.org/wiki/Proxy_auto-config). You can also specify the URL to this file directly in the 'Automatic proxy configuration URL' in the browser's proxy settings.



Now onto the real purpose of this post...

On a Window's platform it's pretty easy to get the system's proxy settings (which are also the IE proxy settings). You can use either WinHttpGetIEProxyForCurrentUser() or InternetOpen() from C/C++ - which is a good language choice for a Plugin.

An example of WinHttpGetIEProxyForCurrentUser() is located here: http://stackoverflow.com/questions/202547

An example of InternetOpen() is located here: http://support.microsoft.com/kb/226473

These are not good options for most browsers, such as those based on Mozilla. Instead other APIs are required such as NPAPI or XPCOM.

The current preference is NPAPI, with updates to this API as recently as early '09. It includes new options to remove dependency on browser specific XPCOM APIs (more on that in a second). To cut to the chase, the new API is NPN_GetValueForURL() (in npapi.h). Use this with the NPNURLVariable parameter set to NPNURLVProxy. An example of using this API for Cookies is here: http://forums.mozillazine.org/viewtopic.php?f=27&t=1233835

According to this post (http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6796470), the NPAPI enhancements are available as far back as Firefox 3.1.

As for the XPCOM API, it was provided by Firefox to provide more access than available through the initial versions of NPAPI (https://developer.mozilla.org/En/XPCOM_API_Reference). However, it was browser specific, and only available in Firefox. According to this post, it is deprecated following Firefox 3.6: https://lists.ximiam.com/pipermail/moonlight-list/2009-October/000628.html

The XPCOM API provides a set of nsIProtocolProxyService APIs (https://developer.mozilla.org/en/NsIProtocolProxyService). These provide access to a number of browser proxy settings. Here's an example of using the XPCOM API from both C++ and a script: https://developer.mozilla.org/en/Creating_XPCOM_Components/Using_XPCOM_Components#Finding_Mozilla_Components

Note that both the NPAPI and XPCOM APIs provide info about the resolved proxy settings. This means that if Automatic proxy settings are used, the values returned via these APIs are the actual proxy server, rather than a link to a PAC file.

No comments:

Post a Comment