[WK2] We should allow stale content when restoring a killed / crashed WebProcess
https://bugs.webkit.org/show_bug.cgi?id=142893
<rdar://problem/19633737>
<rdar://problem/19869257>

Reviewed by Antti Koivisto.

Source/WebCore:

Always use ReturnCacheDataElseLoad cache policy for history navigations.
Previously, we would use the default protocol cache policy for history
navigations if m_stateMachine.committedFirstRealDocumentLoad() returned
false so that we do not display stale content when restoring the session
state of Safari statup (rdar://problem/8131355). This is now handled
before reaching this method by no longer using "IndexedBackForward"
FrameLoadType when restoring session tabs, and using "Standard" load
type instead.

* loader/FrameLoader.cpp:
(WebCore::FrameLoader::loadDifferentDocumentItem):

Source/WebKit2:

Allow stale content when restoring a killed / crashed WebProcess
(similarly to a history navigation). This is actually what was intended
as we call WebPage::goToBackForwardItem() in this case, which uses
IndexedBackForward load type. However, this value was then ignored in
FrameLoader::loadDifferentDocumentItem().

This patch gets rid of the special casing in
FrameLoader::loadDifferentDocumentItem() and makes it clear at call
sites when calling goToBackForwardItem() if we should allow stale
content or not. If goToBackForwardItem() is called with the
allowStaleContent flag off, we'll keep using the IndexedBackForward
frame load type. However, if the flag is on, we'll use the Standard
frame load type and do a fresh load.

* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::reattachToWebProcessForReload):
Set allowStaleContent flag to true as we want to allow stale content
when reloading a WebProcess after it crashed or was killed (behavior
change).

(WebKit::WebPageProxy::reattachToWebProcessWithItem):
Add allowStaleContent parameter so that call sites can decide which
policy to use.

(WebKit::WebPageProxy::goForward):
(WebKit::WebPageProxy::goBack):
Set allowStaleContent flag to true as this is our policy for history
navigations.

(WebKit::WebPageProxy::goToBackForwardItem):
Add allowStaleContent parameter so that the call site can let us know
what to do. This is useful as this is called not only for indexed
back / forward navigations (allowing stale content) but also for
restoring session state (forbidding state content:
<rdar://problem/8131355>).

(WebKit::WebPageProxy::restoreFromSessionState):
Call goToBackForwardItem() with allowStaleContent flag set to false
as users expect fresh contents in this case. This method is called
when:
- Tabs are restored on Safari / MobileSafari startup
- Tabs are restored via "History > Reopen All windows from last session"

* UIProcess/WebPageProxy.h:
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::goToBackForwardItem):
Add allowStaleContent parameter and use "Standard" frame load type
instead of "IndexedBackForward" if it is false. This is needed as
"IndexedBackForward" frame load type allows using stale content.

* WebProcess/WebPage/WebPage.h:
* WebProcess/WebPage/WebPage.messages.in:
Add allowStaleContent flag to GoToBackForwardItem message.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@181782 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/WebCore/loader/FrameLoader.cpp b/Source/WebCore/loader/FrameLoader.cpp
index ae927da..8c34459 100644
--- a/Source/WebCore/loader/FrameLoader.cpp
+++ b/Source/WebCore/loader/FrameLoader.cpp
@@ -3216,10 +3216,7 @@
         case FrameLoadType::Back:
         case FrameLoadType::Forward:
         case FrameLoadType::IndexedBackForward:
-            // If the first load within a frame is a navigation within a back/forward list that was attached 
-            // without any of the items being loaded then we should use the default caching policy (<rdar://problem/8131355>).
-            if (m_stateMachine.committedFirstRealDocumentLoad())
-                request.setCachePolicy(ReturnCacheDataElseLoad);
+            request.setCachePolicy(ReturnCacheDataElseLoad);
             break;
         case FrameLoadType::Standard:
         case FrameLoadType::RedirectWithLockedBackForwardList: