From 6e49bf5815cade3c62591e0c7adc30d4e8509d35 Mon Sep 17 00:00:00 2001 From: Peter Van der Beken Date: Sun, 23 Aug 2020 17:41:06 +0000 Subject: [PATCH] Bug 1659991 - Generate an id if we create a new session history entry in the child process. r=smaug Differential Revision: https://phabricator.services.mozilla.com/D87742 --- docshell/shistory/SessionHistoryEntry.cpp | 5 ++--- docshell/shistory/nsSHEntryShared.cpp | 11 ++++++++--- docshell/shistory/nsSHEntryShared.h | 9 ++++++--- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/docshell/shistory/SessionHistoryEntry.cpp b/docshell/shistory/SessionHistoryEntry.cpp index 0c9fe11e80a2..390865721ac8 100644 --- a/docshell/shistory/SessionHistoryEntry.cpp +++ b/docshell/shistory/SessionHistoryEntry.cpp @@ -129,10 +129,9 @@ SessionHistoryInfo::SharedState SessionHistoryInfo::SharedState::Create( aPartitionedPrincipalToInherit, aCsp, aContentType)); } - // FIXME Pass the correct ID!!! return SharedState(MakeUnique( - 0, aTriggeringPrincipal, aPrincipalToInherit, - aPartitionedPrincipalToInherit, aCsp, aContentType)); + aTriggeringPrincipal, aPrincipalToInherit, aPartitionedPrincipalToInherit, + aCsp, aContentType)); } SessionHistoryInfo::SharedState::SharedState() { diff --git a/docshell/shistory/nsSHEntryShared.cpp b/docshell/shistory/nsSHEntryShared.cpp index f51265484086..4969cb3488cb 100644 --- a/docshell/shistory/nsSHEntryShared.cpp +++ b/docshell/shistory/nsSHEntryShared.cpp @@ -7,6 +7,7 @@ #include "nsSHEntryShared.h" #include "nsArray.h" +#include "nsContentUtils.h" #include "nsDocShellEditorData.h" #include "nsIContentViewer.h" #include "nsISHistory.h" @@ -28,13 +29,17 @@ uint64_t gSHEntrySharedID = 0; namespace mozilla { namespace dom { +/* static */ +uint64_t SHEntrySharedState::GenerateId() { + return nsContentUtils::GenerateProcessSpecificId(++gSHEntrySharedID); +} + SHEntrySharedParentState::SHEntrySharedParentState( nsIPrincipal* aTriggeringPrincipal, nsIPrincipal* aPrincipalToInherit, nsIPrincipal* aPartitionedPrincipalToInherit, nsIContentSecurityPolicy* aCsp, const nsACString& aContentType) - : SHEntrySharedState(++gSHEntrySharedID, aTriggeringPrincipal, - aPrincipalToInherit, aPartitionedPrincipalToInherit, - aCsp, aContentType) {} + : SHEntrySharedState(aTriggeringPrincipal, aPrincipalToInherit, + aPartitionedPrincipalToInherit, aCsp, aContentType) {} SHEntrySharedParentState::~SHEntrySharedParentState() {} diff --git a/docshell/shistory/nsSHEntryShared.h b/docshell/shistory/nsSHEntryShared.h index 90c9d80d3d08..e8cf83130c05 100644 --- a/docshell/shistory/nsSHEntryShared.h +++ b/docshell/shistory/nsSHEntryShared.h @@ -48,14 +48,14 @@ class Document; * parent process. */ struct SHEntrySharedState { - SHEntrySharedState() = default; + SHEntrySharedState() : mId(GenerateId()) {} SHEntrySharedState(const SHEntrySharedState& aState) = default; - SHEntrySharedState(uint64_t aId, nsIPrincipal* aTriggeringPrincipal, + SHEntrySharedState(nsIPrincipal* aTriggeringPrincipal, nsIPrincipal* aPrincipalToInherit, nsIPrincipal* aPartitionedPrincipalToInherit, nsIContentSecurityPolicy* aCsp, const nsACString& aContentType) - : mId(aId), + : mId(GenerateId()), mTriggeringPrincipal(aTriggeringPrincipal), mPrincipalToInherit(aPrincipalToInherit), mPartitionedPrincipalToInherit(aPartitionedPrincipalToInherit), @@ -77,6 +77,9 @@ struct SHEntrySharedState { // moved to bfcache. nsCOMPtr mLayoutHistoryState; uint32_t mCacheKey = 0; + + protected: + static uint64_t GenerateId(); }; /**