Implement document load tracking.

Improves on the state of the art for #1416. Images, XHR, stylesheets, and scripts now block the document load event from firing, and DOMContentLoaded is dispatched after parsing is complete.
Can this cause the `load` event either for the image or for the document to fire synchronously? If yes, that's bad. Events that can fire asynchronously should always fire asynchronously. Otherwise, you get weirdness/bugs like those that can be seen in Gecko around `file:` URLs (whose channels exhibit sync behavior) when code has usually been tested with `http:` URLs (whose channels exhibit async behavior).