Issue #1118 Part 4: Allow UpdateURLAndHistory to work even if there's no

root session history.

This can happen when someone does a document.open() on a document that
has no session history.
This commit is contained in:
wolfbeast 2019-08-06 09:58:35 +00:00 • committed by Roy Tam
commit ab6131d1e6

View file

@ -12137,7 +12137,9 @@ nsDocShell::UpdateURLAndHistory(nsIDocument* aDocument, nsIURI* aNewURI,
// indicating that we're doing a pushState rather than a replaceState, notify // indicating that we're doing a pushState rather than a replaceState, notify
// bfcache that we've added a page to the history so it can evict content // bfcache that we've added a page to the history so it can evict content
// viewers if appropriate. Otherwise call ReplaceEntry so that we notify // viewers if appropriate. Otherwise call ReplaceEntry so that we notify
// nsIHistoryListeners that an entry was replaced. // nsIHistoryListeners that an entry was replaced. We may not have a root
// session history if this call is coming from a document.open() in a docshell
// subtree that disables session history.
nsCOMPtr<nsISHistory> rootSH; nsCOMPtr<nsISHistory> rootSH;
GetRootSessionHistory(getter_AddRefs(rootSH)); GetRootSessionHistory(getter_AddRefs(rootSH));
NS_ENSURE_TRUE(rootSH, NS_ERROR_UNEXPECTED); NS_ENSURE_TRUE(rootSH, NS_ERROR_UNEXPECTED);
@ -12147,6 +12149,7 @@ nsDocShell::UpdateURLAndHistory(nsIDocument* aDocument, nsIURI* aNewURI,
nsresult rv; nsresult rv;
if (rootSH) {
if (!aReplace) { if (!aReplace) {
int32_t curIndex = -1; int32_t curIndex = -1;
rv = rootSH->GetIndex(&curIndex); rv = rootSH->GetIndex(&curIndex);
@ -12162,6 +12165,7 @@ nsDocShell::UpdateURLAndHistory(nsIDocument* aDocument, nsIURI* aNewURI,
internalSH->ReplaceEntry(index, rootSHEntry); internalSH->ReplaceEntry(index, rootSHEntry);
} }
} }
}
// Step 4: If the document's URI changed, update document's URI and update // Step 4: If the document's URI changed, update document's URI and update
// global history. // global history.