Friday, 17 June 2011

How to make your old plugins work with Firefox 4?

I had a old plugin, which was working fine with Firefox 3.6. When I upgraded to Firefox 4.0.1, it suddenly stopped working. Firefox was listing it in the list of plugins installed and pointing to the right dll to load. Googling for this issue did not help. Also, tried replicating the registry entries similar to the ones in the machine which had Firefox 3.6 installed. No, it also did not work out.

From Process Explorer, came to know that Firefox 4.0.1 was not at all loading the dll. Then I looked into the Firefox logs to see what exactly is going on with this plugin dll.
[ Use the following commands to get the Firefox browser logs in file c:\plugins.log.
C:\> set NSPR_LOG_MODULES=all:5
C:\> set NSPR_LOG_FILE=c:\plugins.log
C:\> cd C:\Program Files\Mozilla Firefox
C:\> firefox.exe ]

To my surprise, Firefox was actually loading the plugin dll. But immediately it was unloading it. Then I put debug logs in all the plugin implemented APIs, to see what was going wrong. Finally found out that in NPP_Initialize(), I was calling NS_GetServiceManager(), an XPCOM API to get a reference to the XPCOM service manager. It was failing to get the reference and NPP_Initialize() was returning NPERR_GENERIC_ERROR to the browser. Cause of the issue is thus found out. Looking for solutions in Google again, I hit on the code project link, which explained two ways of getting the reference for XPCOM service manager. One, I was using in my plugin using the XPCOM API, NS_GetServiceManager(). The other one used the XPCOM API NS_InitXPCOM2(). Tried this one. Wow, it worked!

You can surely try this solution, if you are looking for solutions as to why your old plugin is not working in Firefox 4.0.1. See you then. Happy debugging!

No comments:


Related Posts with Thumbnails