DocShell/Fastback: Difference between revisions

no edit summary
No edit summary
Line 1: Line 1:
Fastback, or back-forward cache, is a mechanism to save nsIContentViewer objects (which include the DOM and PresShell/frame tree) in a session history entry, and restore it if the page is reloaded from session history.  It can be broken down into saving to history, restoring from history, and evicting from history.
== Saving to history ==
== Saving to history ==
The <code>[[nsIContentViewer]]</code> saves itself to the SH Entry. It gets an SH Entry in its <code>Close</code> function as an argument, and saves itself there in <code>Destroy</code>.
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.
 
These functions are called from <code>nsDocShell::RestoreFromHistory</code> or <code>nsDocShell::SetupNewViewer</code> (that latter one doesn't call Destroy?). Things are only saved if <code>mSavingOldViewer</code> is true (otherwise, <code>null</code> is passed to Close).
 
What's the role of <code>CaptureState</code>?


Saving will always save to <code>mOSHE</code>
If we determine that the content viewer can safely be cached, then we need to capture some extra state and "freeze" the documentation.  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.


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.
 
== Restoration from history ==
== Restoration from history ==
<code>nsDocShell::InternalLoad</code> checks whether the load is a history load and if so, whether it has a cached presentation.
<code>nsDocShell::InternalLoad</code> checks whether the load is a history load and if so, whether it has a cached presentation.
53

edits