Bugfix for the Clear Cache Button Firefox extension

Chris Holtz created a very useful little extension called "Clear Cache Button". Its mere purpose is to provide a button/icon that you can put in your Firefox toolbar and clear both memory and disk caches with a single click of the icon. Unfortunately with the 0.9 versions the extension broke for the MacOSX users that have not installed the Growl notification framework.

Clicking the Clear Cache button in Firefox in MacOSX logs the following to the Error Console:

uncaught exception:
[Exception... "Component returned failure code: 0x80570016 (NS_ERROR_XPC_GS_RETURNED_FAILURE) [nsIJSCID.getService]"
nsresult: "0x80570016 (NS_ERROR_XPC_GS_RETURNED_FAILURE)"
location: "JS frame :: chrome://clearcache/content/overlay.js :: clearcachebutton_clearCache :: line 7"
data: no]

Looking into the code I've found that the exception is thrown in this line:
var alertService = Components.classes["@mozilla.org/alerts-service;1"].getService(Components.interfaces.nsIAlertsService);

I've looked up the documentation of the nsIAlertsService interface. From the docs I got that the initial call to getService() should complete without error and the call to the showAlertNotification() function should throw a NS_ERROR_NOT_AVAILABLE exception (they explicitly mention MacOSX here) in case the service cannot display the notification (eg. if Growl is not installed, which is true in my case).

Unfortunately it seems that the Mac implementation of this interface is a bit buggy and already the initialization of nsIAlertsService triggers an exception.

So I've surrounded both the getService() and the showAlertNotification() calls with a try-catch block and now the extension works on MacOSX too. I've not tested it with the Growl framework installed, but I assume that it should display the notifications successfully.

Furthermore I've added the last (optional) parameter to the showAlertNotification() call so MacOSX users can block these notifications in their Growl configuration.

I've attached the modded overlay.js file, a patch/diff file (changes made to the overlay.js found in v0.9b) and the complete packaged extension with the fix incorporated which I've named v0.9b2. You can install it by downloading it to your machine (right-click, Save as) and opening the extension in Firefox via "Open file". Probably you should uninstall previous versions of the extension before you try to install this one (I haven't tried whether installing from a local file could upgrade an existing version or not).

PS: I've already sent the fix to Chris (the developer of the extension) so probably it'll be incorporated in the next official version too.

AttachmentSize
overlay-0.9b2.js2.77 KB
overlay-0.9b.diff1.55 KB
clear_cache_button-0.9b2-fx.xpi17.4 KB
overlay-0.9f2.js3.59 KB
overlay-0.9f.diff1.33 KB
clear_cache_button-0.9f2-fx.xpi11.39 KB

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Clear Cache Button v0.9f still broken on Mac OS X

Not much happened in the last two years. Apparently Chris did not add my patch to the extension. Sad
So I've taken the current version and patched it again and attached the sources and the patched XPI too.