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.
I am implementing the machinery that will enable asynchronous network responses in #4057. Until then we live in a world where everything except XHR is synchronous.