Croker devotes a couple of pages to "elucidating" the allusions in the song.
It is all very tongue-in-cheek.
The song was a perennial favorite (Roud 13337). The Bodleian has six broadsheet printings between by 1866.
The idea that it could have been truly "impromptu," however, is obviously nonsense.