The code to restore inspector view state on page reload (in https://webkit.org/b/122125/) saves view state on the Frame.Event.ProvisionalLoadCommitted event, and then tries to restore it on Frame.Event.MainResourceDidChange. However, these events are not one-to-one for things that do not generate provisional loads. Instead, we should add a symmetric MainResourceWillChange event that is 1:1 with MainResourceDidChange. It needs to be called from Frame.commitProvisionalLoad() and Frame.initialize() when Frame._mainResource is being set. The order should be: MainResourceWillChange -> (maybe) ProvisionalLoadCommitted -> MainResourceDidChange. Then, the view state serialization should happen on the first event. NB. Code in FrameResourceManager.frameDidNavigate is responsible for deciding whether there is a provisional load or not.
<rdar://problem/16070884>