From f5c848aa9b73ccaebd42dacaccfe7f2568ede343 Mon Sep 17 00:00:00 2001 From: wolfbeast Date: Tue, 6 Aug 2019 08:41:51 +0000 Subject: Issue #1118 Part 2: Allow UpdateURLAndHistory to work even if mOSHE is null, if we're doing a replace. We're going to end up hitting this if someone does a document.open() before mOSHE has been set. We shouldn't need to worry about mLSHE, because the document.open() will cancel the corresponding load. --- docshell/base/nsDocShell.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'docshell/base') diff --git a/docshell/base/nsDocShell.cpp b/docshell/base/nsDocShell.cpp index d4d86b83a..2aea69847 100644 --- a/docshell/base/nsDocShell.cpp +++ b/docshell/base/nsDocShell.cpp @@ -12054,7 +12054,7 @@ nsDocShell::UpdateURLAndHistory(nsIDocument* aDocument, nsIURI* aNewURI, // history. This will erase all SHEntries after the new entry and make this // entry the current one. This operation may modify mOSHE, which we need // later, so we keep a reference here. - NS_ENSURE_TRUE(mOSHE, NS_ERROR_FAILURE); + NS_ENSURE_TRUE(mOSHE || aReplace, NS_ERROR_FAILURE); nsCOMPtr oldOSHE = mOSHE; mLoadType = LOAD_PUSHSTATE; @@ -12101,6 +12101,16 @@ nsDocShell::UpdateURLAndHistory(nsIDocument* aDocument, nsIURI* aNewURI, } else { // Step 3. newSHEntry = mOSHE; + + // Since we're not changing which page we have loaded, pass + if (!newSHEntry) { + nsresult rv = AddToSessionHistory( + aNewURI, nullptr, + aDocument->NodePrincipal(), // triggeringPrincipal + nullptr, true, getter_AddRefs(newSHEntry)); + NS_ENSURE_SUCCESS(rv, rv); + mOSHE = newSHEntry; + } newSHEntry->SetURI(aNewURI); newSHEntry->SetOriginalURI(aNewURI); newSHEntry->SetLoadReplace(false); @@ -12117,7 +12127,10 @@ nsDocShell::UpdateURLAndHistory(nsIDocument* aDocument, nsIURI* aNewURI, // set URIWasModified to true for the current SHEntry (bug 669671). bool sameExceptHashes = true, oldURIWasModified = false; aNewURI->EqualsExceptRef(aCurrentURI, &sameExceptHashes); - oldOSHE->GetURIWasModified(&oldURIWasModified); + // mOSHE might be null on replace. Only check if we're not replacing. + if (oldOSHE) { + oldOSHE->GetURIWasModified(&oldURIWasModified); + } newSHEntry->SetURIWasModified(!sameExceptHashes || oldURIWasModified); // Step E as described at the top of AddState: If aReplace is false, -- cgit v1.2.3