Crossposted from blog.collectik.net
If you’re a firefox user, I hope you’ve already discovered that we have a ‘Collectik This’ plugin. Once you’ve installed this plugin, wherever you are on the internet, if you find a feed you would like to collect, or an audio or video file you’d like to add to your playlist, just right click on the link, select ‘Collectik This’ from the menu, and we’ll do the rest.
When I was developing this (hat-tip to the excellent roachfiend tutorial) I found I needed one trick which was hard to find documentation on. Since it took a while to figure it out, I thought I’d share it. If you aren’t interested in developing firefox plugins, now is probably a good place to stop…
The problem: if you open a popup window in a firefox plugin (using window.open and specifying the URL), firefox doesn’t (as far as I can work out) send any cookies with the http request. This makes it a bit hard to do any sort of session management. The work around for this came in two parts. Firstly, since we use the Ruby cgi/session session management, there is no need to send a cookie if you can extract the session id and pass it as a parameter in the URL (&_session_id=xxxxx). Secondly (and this is the bit that took some finding), you have access to the firefox cookiemanager. So we have a method like this…
function getCookie() {
cookiemanager = Components.classes["@mozilla.org/cookiemanager;1"].getService();
cookiemanager = cookiemanager.QueryInterface(
Components.interfaces.nsICookieManager);
var enumerator = cookiemanager.enumerator;
while (enumerator.hasMoreElements())
{
var nextCookie = enumerator.getNext();
if (!nextCookie) break;
nextCookie = nextCookie.QueryInterface(Components.interfaces.nsICookie);
if (nextCookie.host=='collectik.net' && nextCookie.name=='_session_id')
{
return nextCookie.value;
}
}
return false;
}
Maybe that will help someone… and if there is a better way, I’d love to hear it.