DocShell/Fastback: Difference between revisions

Line 2: Line 2:


== Saving to history ==
== Saving to history ==
When the docshell is about to replace a ContentViewer with a new ContentViewer, it first determines whether the old content viewer is a candidate for saving in session history.  This work happens in nsDocShell::CanSavePresentation().  There are a number of factors which might disqualify a particular viewer from being saved, for example, the type of load being performed, whether the page was finished loading, or an unload event handler being installed.  We check this state once before initiating the new document load, and again once we're ready to actually swap out the content viewers.  The presentation is only cached if both checks pass.
When the docshell is about to replace a ContentViewer with a new ContentViewer, it first determines whether the old content viewer is a candidate for saving in session history.  This work happens in <code>nsDocShell::CanSavePresentation()</code>.  There are a number of factors which might disqualify a particular viewer from being saved, for example, the type of load being performed, whether the page was finished loading, or an unload event handler being installed.  We check this state once before initiating the new document load, and again once we're ready to actually swap out the content viewers.  The presentation is only cached if both checks pass.


If we determine that the content viewer can safely be cached, then we need to capture some extra state and "freeze" the presentation.  Both of these happen through nsDocShell::CaptureState.  SaveWindowState() is called on the window object, which saves the focus state and suspends timeouts.  CaptureState also suspends refresh URIs, captures the size at which the presentation was laid out, and saves off the list of child docshells.  The latter is important since the parent docshell will clear its child list when it is switched over to the new document.
If we determine that the content viewer can safely be cached, then we need to capture some extra state and "freeze" the presentation.  Both of these happen through <code>nsDocShell::CaptureState()</code><code>SaveWindowState()</code> is called on the window object, which saves the focus state and suspends timeouts.  <code>CaptureState</code> also suspends refresh URIs, captures the size at which the presentation was laid out, and saves off the list of child docshells.  The latter is important since the parent docshell will clear its child list when it is switched over to the new document.


The final part of saving to history happens when DocumentViewerImpl::Close is called on the old content viewer, and Show() is called on the new one.  Close() stores a reference to the session history entry which will contain the DocumentViewer (this comes from the DocShell's mOSHE).  When the new viewer is actually ready to paint, Show() is called and this calls Destroy() on the previous viewer.  At this time, rather than tearing down the presentation, the document viewer removes itself from the view hierarchy to suppress painting, and saves a reference to itself into the history entry.  The history entry now has sole ownership of the DocumentViewer.  Also at this point, the document's link to its docshell/window is broken, so that the document is completely detached and cannot affect the window which is now showing a different document.  Plugins in the document are destroyed, since there's no reliable way to suspend a plugin.  This is the end of the save-to-history.
The final part of saving to history happens when <code>DocumentViewerImpl::Close()</code> is called on the old content viewer, and <code>Show()</code> is called on the new one.  <code>Close</code> stores a reference to the session history entry which will contain the DocumentViewer (this comes from the DocShell's mOSHE).  When the new viewer is actually ready to paint, <code>Show</code> is called and this calls <code>Destroy</code> on the previous viewer.  At this time, rather than tearing down the presentation, the document viewer removes itself from the view hierarchy to suppress painting, and saves a reference to itself into the history entry.  The history entry now has sole ownership of the DocumentViewer.  Also at this point, the document's link to its docshell/window is broken, so that the document is completely detached and cannot affect the window which is now showing a different document.  Plugins in the document are destroyed, since there's no reliable way to suspend a plugin.  This is the end of the save-to-history.


== Restoration from history ==
== Restoration from history ==
53

edits