Commit 6129b10b authored by japhet@chromium.org's avatar japhet@chromium.org

location.replace() breaks same-document back/forward navigations.

For navigations that don't create a new entry in the back/forward list (like
location.replace), we don't create a new HistoryItem, we just update the
existing one. If the url changes, we currently update some id numbers as well:
the item sequence number (which uniquely identifies the item), and the
document sequence number (which is common among history items that can be
navigated between without creating a new document). For a location.replace()
within the same document, we still need to change the item sequence number
(so that a back navigation is guaranteed to do something), but the document
sequence number should *not* update, so that a same-document navigation is
still possible.

BUG=363724
TEST=fast/loader/back-after-same-document-location-replace.html

Review URL: https://codereview.chromium.org/267613003

git-svn-id: svn://svn.chromium.org/blink/trunk@173045 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 4e50edda
<body>
<script>
if (window.testRunner) {
testRunner.dumpAsText();
testRunner.waitUntilDone();
}
window.onload = function() {
setTimeout(function() {
location.href = "#1";
location.replace("#2");
history.back();
}, 0);
};
window.onhashchange = function() {
if (location.hash != "")
return;
document.body.appendChild(document.createTextNode("PASS"));
if (window.testRunner)
testRunner.notifyDone();
}
</script>
</body>
......@@ -257,10 +257,15 @@ void FrameLoader::setHistoryItemStateForCommit(HistoryCommitType historyCommitTy
{
if (m_provisionalItem)
m_currentItem = m_provisionalItem.release();
if (!m_currentItem || historyCommitType == StandardCommit)
if (!m_currentItem || historyCommitType == StandardCommit) {
m_currentItem = HistoryItem::create();
else if (!isPushOrReplaceState && m_documentLoader->url() != m_currentItem->url())
m_currentItem->generateNewSequenceNumbers();
} else if (!isPushOrReplaceState && m_documentLoader->url() != m_currentItem->url()) {
m_currentItem->generateNewItemSequenceNumber();
if (!equalIgnoringFragmentIdentifier(m_documentLoader->url(), m_currentItem->url()))
m_currentItem->generateNewDocumentSequenceNumber();
}
m_currentItem->setURL(m_documentLoader->urlForHistory());
m_currentItem->setDocumentState(m_frame->document()->formElementsState());
m_currentItem->setTarget(m_frame->tree().uniqueName());
......
......@@ -53,9 +53,13 @@ HistoryItem::~HistoryItem()
{
}
void HistoryItem::generateNewSequenceNumbers()
void HistoryItem::generateNewItemSequenceNumber()
{
m_itemSequenceNumber = generateSequenceNumber();
}
void HistoryItem::generateNewDocumentSequenceNumber()
{
m_documentSequenceNumber = generateSequenceNumber();
}
......
......@@ -52,7 +52,8 @@ public:
// Used when the frame this item represents was navigated to a different
// url but a new item wasn't created.
void generateNewSequenceNumbers();
void generateNewItemSequenceNumber();
void generateNewDocumentSequenceNumber();
const String& urlString() const;
KURL url() const;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment