Bug 992309

Mike has reviewed a3eda77 (the largest part) here https://bugzilla.mozilla.org/show_bug.cgi?id=992309#c3
The other 2 parts still need review