- Revision
- 197244
- Author
- [email protected]
- Date
- 2016-02-26 23:44:07 -0800 (Fri, 26 Feb 2016)
Log Message
Network cache: old pages returned by disk cache on history navigation after session is restored
https://bugs.webkit.org/show_bug.cgi?id=153230
Reviewed by Chris Dumez.
Source/WebCore:
Add a flag to HistoryItem to mark them as restored from session
and use it from the FrameLoader to not change the policy request
when navigating to a history item that was restored from session,
except for iOS port.
* history/HistoryItem.h:
(WebCore::HistoryItem::setWasRestoredFromSession):
(WebCore::HistoryItem::wasRestoredFromSession):
* loader/FrameLoader.cpp:
(WebCore::FrameLoader::loadDifferentDocumentItem):
Source/WebKit2:
Since r181734, the network cache never revalidates resources for
history navigation. This is good for the memory cache, but in the
case of disk cache, we might end up with outdated pages when
restoring the session. When restoring the session happens because
of an API request (we also restore the session when recovering
from a web process crash), we should revalidate back forward list
requests in the disk cache if needed. This will only happen the
first time they are loaded after a session restore. After a web process
crash, resources will be used uncondionally from the disk cache.
* WebProcess/WebPage/WebBackForwardListProxy.cpp:
(WebKit::WebBackForwardListProxy::addItemFromUIProcess): Use Ref&&
instead of PassRefPtr.
* WebProcess/WebPage/WebBackForwardListProxy.h:
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WePage::WebPage): Call restoreSessionInternal passing
No as restoredByAPIRequest parameter.
(WebKit::WebPage::restoreSessionInternal): Set restoredFromSession
flag to the created HistoryItem if the item was restored from
session by an API request.
(WebKit::WebPage::restoreSession): Call restoreSessionInternal
passing Yes as restoredByAPIRequest parameter.
* WebProcess/WebPage/WebPage.h:
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (197243 => 197244)
--- trunk/Source/WebCore/ChangeLog 2016-02-27 07:26:09 UTC (rev 197243)
+++ trunk/Source/WebCore/ChangeLog 2016-02-27 07:44:07 UTC (rev 197244)
@@ -1,3 +1,21 @@
+2016-02-26 Carlos Garcia Campos <[email protected]>
+
+ Network cache: old pages returned by disk cache on history navigation after session is restored
+ https://bugs.webkit.org/show_bug.cgi?id=153230
+
+ Reviewed by Chris Dumez.
+
+ Add a flag to HistoryItem to mark them as restored from session
+ and use it from the FrameLoader to not change the policy request
+ when navigating to a history item that was restored from session,
+ except for iOS port.
+
+ * history/HistoryItem.h:
+ (WebCore::HistoryItem::setWasRestoredFromSession):
+ (WebCore::HistoryItem::wasRestoredFromSession):
+ * loader/FrameLoader.cpp:
+ (WebCore::FrameLoader::loadDifferentDocumentItem):
+
2016-02-26 Michael Catanzaro <[email protected]>
Remove unused private field from WEBPImageDecoder
Modified: trunk/Source/WebCore/history/HistoryItem.h (197243 => 197244)
--- trunk/Source/WebCore/history/HistoryItem.h 2016-02-27 07:26:09 UTC (rev 197243)
+++ trunk/Source/WebCore/history/HistoryItem.h 2016-02-27 07:44:07 UTC (rev 197244)
@@ -205,6 +205,9 @@
void notifyChanged();
+ void setWasRestoredFromSession(bool wasRestoredFromSession) { m_wasRestoredFromSession = wasRestoredFromSession; }
+ bool wasRestoredFromSession() const { return m_wasRestoredFromSession; }
+
private:
WEBCORE_EXPORT HistoryItem();
WEBCORE_EXPORT HistoryItem(const String& urlString, const String& title);
@@ -231,6 +234,7 @@
bool m_lastVisitWasFailure;
bool m_isTargetItem;
+ bool m_wasRestoredFromSession { false };
std::unique_ptr<Vector<String>> m_redirectURLs;
Modified: trunk/Source/WebCore/loader/FrameLoader.cpp (197243 => 197244)
--- trunk/Source/WebCore/loader/FrameLoader.cpp 2016-02-27 07:26:09 UTC (rev 197243)
+++ trunk/Source/WebCore/loader/FrameLoader.cpp 2016-02-27 07:44:07 UTC (rev 197244)
@@ -3336,9 +3336,17 @@
break;
case FrameLoadType::Back:
case FrameLoadType::Forward:
- case FrameLoadType::IndexedBackForward:
- request.setCachePolicy(ReturnCacheDataElseLoad);
+ case FrameLoadType::IndexedBackForward: {
+#if PLATFORM(IOS)
+ bool allowStaleData = true;
+#else
+ bool allowStaleData = !item.wasRestoredFromSession();
+#endif
+ if (allowStaleData)
+ request.setCachePolicy(ReturnCacheDataElseLoad);
+ item.setWasRestoredFromSession(false);
break;
+ }
case FrameLoadType::Standard:
case FrameLoadType::RedirectWithLockedBackForwardList:
break;
Modified: trunk/Source/WebKit2/ChangeLog (197243 => 197244)
--- trunk/Source/WebKit2/ChangeLog 2016-02-27 07:26:09 UTC (rev 197243)
+++ trunk/Source/WebKit2/ChangeLog 2016-02-27 07:44:07 UTC (rev 197244)
@@ -1,3 +1,34 @@
+2016-02-26 Carlos Garcia Campos <[email protected]>
+
+ Network cache: old pages returned by disk cache on history navigation after session is restored
+ https://bugs.webkit.org/show_bug.cgi?id=153230
+
+ Reviewed by Chris Dumez.
+
+ Since r181734, the network cache never revalidates resources for
+ history navigation. This is good for the memory cache, but in the
+ case of disk cache, we might end up with outdated pages when
+ restoring the session. When restoring the session happens because
+ of an API request (we also restore the session when recovering
+ from a web process crash), we should revalidate back forward list
+ requests in the disk cache if needed. This will only happen the
+ first time they are loaded after a session restore. After a web process
+ crash, resources will be used uncondionally from the disk cache.
+
+ * WebProcess/WebPage/WebBackForwardListProxy.cpp:
+ (WebKit::WebBackForwardListProxy::addItemFromUIProcess): Use Ref&&
+ instead of PassRefPtr.
+ * WebProcess/WebPage/WebBackForwardListProxy.h:
+ * WebProcess/WebPage/WebPage.cpp:
+ (WebKit::WePage::WebPage): Call restoreSessionInternal passing
+ No as restoredByAPIRequest parameter.
+ (WebKit::WebPage::restoreSessionInternal): Set restoredFromSession
+ flag to the created HistoryItem if the item was restored from
+ session by an API request.
+ (WebKit::WebPage::restoreSession): Call restoreSessionInternal
+ passing Yes as restoredByAPIRequest parameter.
+ * WebProcess/WebPage/WebPage.h:
+
2016-02-26 Michael Catanzaro <[email protected]>
Fix a typo.
Modified: trunk/Source/WebKit2/WebProcess/WebPage/WebBackForwardListProxy.cpp (197243 => 197244)
--- trunk/Source/WebKit2/WebProcess/WebPage/WebBackForwardListProxy.cpp 2016-02-27 07:26:09 UTC (rev 197243)
+++ trunk/Source/WebKit2/WebProcess/WebPage/WebBackForwardListProxy.cpp 2016-02-27 07:44:07 UTC (rev 197244)
@@ -94,16 +94,14 @@
WebProcess::singleton().parentProcessConnection()->send(Messages::WebProcessProxy::AddBackForwardItem(itemID, pageID, toPageState(*item)), 0);
}
-void WebBackForwardListProxy::addItemFromUIProcess(uint64_t itemID, PassRefPtr<WebCore::HistoryItem> prpItem, uint64_t pageID)
+void WebBackForwardListProxy::addItemFromUIProcess(uint64_t itemID, Ref<HistoryItem>&& item, uint64_t pageID)
{
- RefPtr<HistoryItem> item = prpItem;
-
// This item/itemID pair should not already exist in our maps.
- ASSERT(!historyItemToIDMap().contains(item.get()));
+ ASSERT(!historyItemToIDMap().contains(item.ptr()));
ASSERT(!idToHistoryItemMap().contains(itemID));
- historyItemToIDMap().set<ItemAndPageID>(item, { .itemID = itemID, .pageID = pageID });
- idToHistoryItemMap().set(itemID, item);
+ historyItemToIDMap().set<ItemAndPageID>(item.ptr(), { .itemID = itemID, .pageID = pageID });
+ idToHistoryItemMap().set(itemID, item.ptr());
}
static void WK2NotifyHistoryItemChanged(HistoryItem* item)
Modified: trunk/Source/WebKit2/WebProcess/WebPage/WebBackForwardListProxy.h (197243 => 197244)
--- trunk/Source/WebKit2/WebProcess/WebPage/WebBackForwardListProxy.h 2016-02-27 07:26:09 UTC (rev 197243)
+++ trunk/Source/WebKit2/WebProcess/WebPage/WebBackForwardListProxy.h 2016-02-27 07:44:07 UTC (rev 197244)
@@ -42,7 +42,7 @@
static uint64_t idForItem(WebCore::HistoryItem*);
static void removeItem(uint64_t itemID);
- static void addItemFromUIProcess(uint64_t itemID, PassRefPtr<WebCore::HistoryItem>, uint64_t pageID);
+ static void addItemFromUIProcess(uint64_t itemID, Ref<WebCore::HistoryItem>&&, uint64_t pageID);
static void setHighestItemIDFromUIProcess(uint64_t itemID);
void clear();
Modified: trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp (197243 => 197244)
--- trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp 2016-02-27 07:26:09 UTC (rev 197243)
+++ trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp 2016-02-27 07:44:07 UTC (rev 197244)
@@ -490,7 +490,7 @@
WebBackForwardListProxy::setHighestItemIDFromUIProcess(parameters.highestUsedBackForwardItemID);
if (!parameters.itemStates.isEmpty())
- restoreSession(parameters.itemStates);
+ restoreSessionInternal(parameters.itemStates, WasRestoredByAPIRequest::No);
if (parameters.sessionID.isValid())
setSessionID(parameters.sessionID);
@@ -2231,10 +2231,18 @@
executeEditingCommand(commandName, argument);
}
+void WebPage::restoreSessionInternal(const Vector<BackForwardListItemState>& itemStates, WasRestoredByAPIRequest restoredByAPIRequest)
+{
+ for (const auto& itemState : itemStates) {
+ auto historyItem = toHistoryItem(itemState.pageState);
+ historyItem->setWasRestoredFromSession(restoredByAPIRequest == WasRestoredByAPIRequest::Yes);
+ WebBackForwardListProxy::addItemFromUIProcess(itemState.identifier, WTFMove(historyItem), m_pageID);
+ }
+}
+
void WebPage::restoreSession(const Vector<BackForwardListItemState>& itemStates)
{
- for (const auto& itemState : itemStates)
- WebBackForwardListProxy::addItemFromUIProcess(itemState.identifier, toHistoryItem(itemState.pageState), m_pageID);
+ restoreSessionInternal(itemStates, WasRestoredByAPIRequest::Yes);
}
#if ENABLE(TOUCH_EVENTS)
Modified: trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h (197243 => 197244)
--- trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h 2016-02-27 07:26:09 UTC (rev 197243)
+++ trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h 2016-02-27 07:44:07 UTC (rev 197244)
@@ -1020,6 +1020,8 @@
void loadURLInFrame(const String&, uint64_t frameID);
+ enum class WasRestoredByAPIRequest { No, Yes };
+ void restoreSessionInternal(const Vector<BackForwardListItemState>&, WasRestoredByAPIRequest);
void restoreSession(const Vector<BackForwardListItemState>&);
void didRemoveBackForwardItem(uint64_t);