Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1186)

Unified Diff: Source/core/loader/FrameLoader.cpp

Issue 927213004: Accept options in history APIs to allow scroll restoration to be disabled (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: minor Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Source/core/loader/FrameLoader.cpp
diff --git a/Source/core/loader/FrameLoader.cpp b/Source/core/loader/FrameLoader.cpp
index 5d17ba671aa3458daf719ad25a587e7f1377e09b..4712a4f6e397f43e301d6a17d280a83c0c5035b7 100644
--- a/Source/core/loader/FrameLoader.cpp
+++ b/Source/core/loader/FrameLoader.cpp
@@ -290,7 +290,7 @@ void FrameLoader::replaceDocumentWhileExecutingJavaScriptURL(const String& sourc
documentLoader->replaceDocumentWhileExecutingJavaScriptURL(init, source, ownerDocument);
}
-void FrameLoader::setHistoryItemStateForCommit(HistoryCommitType historyCommitType, bool isPushOrReplaceState, PassRefPtr<SerializedScriptValue> stateObject)
+void FrameLoader::setHistoryItemStateForCommit(HistoryCommitType historyCommitType, bool isPushOrReplaceState, bool shouldRestoreScroll, PassRefPtr<SerializedScriptValue> stateObject)
{
if (m_provisionalItem)
m_currentItem = m_provisionalItem.release();
@@ -306,8 +306,10 @@ void FrameLoader::setHistoryItemStateForCommit(HistoryCommitType historyCommitTy
m_currentItem->setURL(m_documentLoader->urlForHistory());
m_currentItem->setDocumentState(m_frame->document()->formElementsState());
m_currentItem->setTarget(m_frame->tree().uniqueName());
- if (isPushOrReplaceState)
+ if (isPushOrReplaceState) {
m_currentItem->setStateObject(stateObject);
+ m_currentItem->setShouldRestoreScroll(shouldRestoreScroll);
+ }
m_currentItem->setReferrer(SecurityPolicy::generateReferrer(m_documentLoader->request().referrerPolicy(), m_currentItem->url(), m_documentLoader->request().httpReferrer()));
m_currentItem->setFormInfoFromRequest(m_documentLoader->request());
}
@@ -556,7 +558,7 @@ bool FrameLoader::allowPlugins(ReasonForCallingAllowPlugins reason)
return allowed;
}
-void FrameLoader::updateForSameDocumentNavigation(const KURL& newURL, SameDocumentNavigationSource sameDocumentNavigationSource, PassRefPtr<SerializedScriptValue> data, FrameLoadType type)
+void FrameLoader::updateForSameDocumentNavigation(const KURL& newURL, SameDocumentNavigationSource sameDocumentNavigationSource, PassRefPtr<SerializedScriptValue> data, bool shouldRestoreScroll, FrameLoadType type)
{
saveScrollState();
@@ -575,7 +577,7 @@ void FrameLoader::updateForSameDocumentNavigation(const KURL& newURL, SameDocume
if (!m_currentItem)
historyCommitType = HistoryInertCommit;
- setHistoryItemStateForCommit(historyCommitType, sameDocumentNavigationSource == SameDocumentNavigationHistoryApi, data);
+ setHistoryItemStateForCommit(historyCommitType, sameDocumentNavigationSource == SameDocumentNavigationHistoryApi, shouldRestoreScroll, data);
client()->dispatchDidNavigateWithinPage(m_currentItem.get(), historyCommitType);
client()->dispatchDidReceiveTitle(m_frame->document()->title());
if (m_frame->document()->loadEventFinished())
@@ -606,7 +608,7 @@ void FrameLoader::loadInSameDocument(const KURL& url, PassRefPtr<SerializedScrip
m_frame->localDOMWindow()->enqueueHashchangeEvent(oldURL, url);
}
m_documentLoader->setIsClientRedirect(clientRedirect == ClientRedirect);
- updateForSameDocumentNavigation(url, SameDocumentNavigationDefault, nullptr, type);
+ updateForSameDocumentNavigation(url, SameDocumentNavigationDefault, nullptr, true, type);
m_frame->view()->setWasScrolledByUser(false);
@@ -1023,6 +1025,9 @@ void FrameLoader::restoreScrollPositionAndViewState()
if (!needsHistoryItemRestore(m_loadType))
return;
+ if (!m_currentItem->shouldRestoreScroll())
+ return;
+
// This tries to balance 1. restoring as soon as possible, 2. detecting
// clamping to avoid repeatedly popping the scroll position down as the
// page height increases, 3. ignore clamp detection after load completes

Powered by Google App Engine
This is Rietveld 408576698