The idea is to fire the visibilitychange event synchronously during pageshow and pagehide, since we're
already running script there for the pageshow/pagehide events. For docshell active state changes, we
fire the event asynchronously. In all cases, the actual state changes just before the event fires.