Improve handling of preferences in Firefox

This PR attempts to fix #4005.

*Note that while this works as it should in the addon, I haven't tested the `mozcentral` version of the patch.*

@brendandahl What is your opinion about this?