the foam is extremely good for filling irregular gaps between lining and wall, it also expands, sticks, and sets rigid so it holds the frame firmly in position with no rattle or shake and it will not come loose when your teenage daughter keeps slamming the door.
However it needs practice to get a neat finish (I block the gap with a batten wrapped in clingfilm, and inject through drilled holes) and I believe there is a maximum gap size it is rated for. might only be 6mm? though I have used it to fill far bigger cavities, provided there is something covering them. It blocks noise and draughts as well as smoke (so does the furry pile strip, and with a carefully trimmed door, it helps the door shut quietly).
You can trim the foam back once hardened with a breadknife, and it will accept filler or paint. The architrave will hide it anyway.
The mastic swells with heat, the foam doesn't, so is suitable for a permanent fixing like a dooor lining, but not a working gap. I reckon it is far better than mineral wool because it sticks and form a solid block.