Pretty intricate fix which detects when we are in a top frame and then
gently tries to set a cookie and switch from cookieless sessions to
cookie-based sessions.