Commit b6d4b5e9 authored by Peter Van der Beken's avatar Peter Van der Beken
Browse files

Bug 1588491 - Associate session history entries with a session history object...

Bug 1588491 - Associate session history entries with a session history object from creation. r=smaug

Differential Revision: https://phabricator.services.mozilla.com/D49170

--HG--
extra : rebase_source : bc4c6e8cea0de7e85ae78ffb3ce09a7465e61b4a
extra : amend_source : 956bf8fa227e613b7f816dd5af9029ed24ba2c46
extra : source : 2d4b06fe1f429eec844cdeba8a7faaa63bfc25ab
extra : histedit_source : a2345826c7f94311ee57d805bf3ac9bed2e12ea7
parent 3974b1bd
......@@ -11329,7 +11329,13 @@ nsresult nsDocShell::AddToSessionHistory(
// Create a new entry if necessary.
if (!entry) {
entry = components::SHEntry::Create();
nsCOMPtr<nsIWebNavigation> webnav = do_QueryInterface(root);
NS_ENSURE_TRUE(webnav, NS_ERROR_FAILURE);
RefPtr<ChildSHistory> shistory = webnav->GetSessionHistory();
NS_ENSURE_TRUE(shistory, NS_ERROR_FAILURE);
shistory->LegacySHistory()->CreateEntry(getter_AddRefs(entry));
if (!entry) {
return NS_ERROR_OUT_OF_MEMORY;
......
......@@ -43,17 +43,6 @@ InitFunc = 'mozilla::InitDocShellModule'
UnloadFunc = 'mozilla::UnloadDocShellModule'
Classes = [
{
'name': 'SHEntry',
'cid': '{bfd1a791-ad9f-11d3-bdc7-0050040a9b44}',
'contract_ids': ['@mozilla.org/browser/session-history-entry;1'],
'type': 'nsISHEntry',
'constructor': 'mozilla::dom::CreateSHEntry',
'headers': [
'nsISHEntry.h',
'mozilla/dom/ChildSHistory.h',
],
},
{
'name': 'DocLoader',
'cid': '{057b04d0-0ccf-11d2-beba-00805f8a66dc}',
......
......@@ -125,16 +125,5 @@ nsISupports* ChildSHistory::GetParentObject() const {
return ToSupports(mm);
}
already_AddRefed<nsISHEntry> CreateSHEntry() {
uint64_t sharedID = SHEntryChildShared::CreateSharedID();
if (XRE_IsContentProcess() && StaticPrefs::fission_sessionHistoryInParent()) {
return do_AddRef(static_cast<SHEntryChild*>(
ContentChild::GetSingleton()->SendPSHEntryConstructor(sharedID)));
}
nsCOMPtr<nsISHEntry> entry = new nsLegacySHEntry(sharedID);
return entry.forget();
}
} // namespace dom
} // namespace mozilla
......@@ -108,8 +108,6 @@ class ChildSHistory : public nsISupports, public nsWrapperCache {
mozilla::LinkedList<PendingAsyncHistoryNavigation> mPendingNavigations;
};
already_AddRefed<nsISHEntry> CreateSHEntry();
} // namespace dom
} // namespace mozilla
......
......@@ -59,7 +59,11 @@ void SHEntryChildShared::EvictContentViewers(
for (auto iter = aToEvictSharedStateIDs.begin();
iter != aToEvictSharedStateIDs.end(); ++iter) {
RefPtr<SHEntryChildShared> shared = sSHEntryChildSharedTable->Get(*iter);
MOZ_ASSERT(shared, "shared entry can't be null");
if (!shared) {
// This can happen if we've created an entry in the parent, and have never
// sent it over IPC to the child.
continue;
}
nsCOMPtr<nsIContentViewer> viewer = shared->mContentViewer;
if (viewer) {
numEvictedSoFar++;
......@@ -589,7 +593,7 @@ NS_IMETHODIMP
SHEntryChild::Clone(nsISHEntry** aResult) {
NS_IF_ADDREF(*aResult = static_cast<SHEntryChild*>(
ContentChild::GetSingleton()->SendPSHEntryConstructor(
this)));
mShared->mSHistory, this)));
return NS_OK;
}
......@@ -955,19 +959,11 @@ SHEntryChild::SetLastTouched(uint32_t aLastTouched) {
}
NS_IMETHODIMP
SHEntryChild::GetSHistory(nsISHistory** aSHistory) {
SHEntryChild::GetShistory(nsISHistory** aSHistory) {
*aSHistory = do_AddRef(mShared->mSHistory).take();
return NS_OK;
}
NS_IMETHODIMP
SHEntryChild::SetSHistory(nsISHistory* aSHistory) {
// mSHistory can not be changed once it's set
MOZ_ASSERT(!mShared->mSHistory || (mShared->mSHistory == aSHistory));
mShared->mSHistory = static_cast<SHistoryChild*>(aSHistory);
return NS_OK;
}
NS_IMETHODIMP
SHEntryChild::SetLoadTypeAsHistory() {
return SendSetLoadTypeAsHistory() ? NS_OK : NS_ERROR_FAILURE;
......
......@@ -14,8 +14,10 @@ namespace mozilla {
namespace dom {
SHEntrySharedParent::SHEntrySharedParent(PContentParent* aContentParent,
LegacySHistory* aSHistory,
uint64_t aSharedID)
: SHEntrySharedParentState(aSharedID), mContentParent(aContentParent) {}
: SHEntrySharedParentState(aSHistory, aSharedID),
mContentParent(aContentParent) {}
void SHEntrySharedParent::Destroy() {
if (mContentParent &&
......@@ -25,6 +27,11 @@ void SHEntrySharedParent::Destroy() {
SHEntrySharedParentState::Destroy();
}
LegacySHEntry::LegacySHEntry(PContentParent* aContentParent,
LegacySHistory* aSHistory, uint64_t aSharedID)
: nsSHEntry(new SHEntrySharedParent(aContentParent, aSHistory, aSharedID)),
mActor(nullptr) {}
NS_IMPL_ISUPPORTS_INHERITED0(LegacySHEntry, nsSHEntry)
SHEntryParent* LegacySHEntry::CreateActor() {
......@@ -44,12 +51,8 @@ MaybeNewPSHEntryParent LegacySHEntry::GetOrCreateActor(
}
void LegacySHEntry::AbandonBFCacheEntry(uint64_t aNewSharedID) {
PContentParent* contentParent =
static_cast<SHEntrySharedParent*>(mShared.get())->GetContentParent();
RefPtr<SHEntrySharedParent> shared =
new SHEntrySharedParent(contentParent, aNewSharedID);
shared->CopyFrom(mShared);
mShared = shared.forget();
mShared =
static_cast<SHEntrySharedParent*>(mShared.get())->Duplicate(aNewSharedID);
}
NS_IMETHODIMP
......@@ -301,7 +304,7 @@ bool SHEntryParent::RecvGetStateData(ClonedMessageData* aData) {
if (container) {
static_cast<nsStructuredCloneContainer*>(container.get())
->BuildClonedMessageDataForParent(
static_cast<ContentParent*>(Manager()), *aData);
static_cast<ContentParent*>(ToplevelProtocol()), *aData);
}
return true;
}
......
......@@ -16,6 +16,7 @@
namespace mozilla {
namespace dom {
class LegacySHistory;
class PContentParent;
class SHEntryParent;
......@@ -25,12 +26,25 @@ class SHEntryParent;
*/
class SHEntrySharedParent : public SHEntrySharedParentState {
public:
SHEntrySharedParent(PContentParent* aContentParent, uint64_t aSharedID);
void Destroy() override;
SHEntrySharedParent(PContentParent* aContentParent, LegacySHistory* aSHistory,
uint64_t aSharedID);
already_AddRefed<SHEntrySharedParent> Duplicate(uint64_t aNewSharedID) {
RefPtr<SHEntrySharedParent> shared =
new SHEntrySharedParent(this, aNewSharedID);
shared->CopyFrom(this);
return shared.forget();
}
PContentParent* GetContentParent() { return mContentParent.get(); }
protected:
SHEntrySharedParent(SHEntrySharedParent* aDuplicate, uint64_t aSharedID)
: SHEntrySharedParentState(aDuplicate, aSharedID),
mContentParent(aDuplicate->mContentParent) {}
void Destroy() override;
private:
mozilla::WeakPtr<PContentParent> mContentParent;
};
......@@ -44,9 +58,8 @@ class SHEntrySharedParent : public SHEntrySharedParentState {
*/
class LegacySHEntry final : public nsSHEntry, public CrossProcessSHEntry {
public:
LegacySHEntry(PContentParent* aParent, uint64_t aSharedID)
: nsSHEntry(new SHEntrySharedParent(aParent, aSharedID)),
mActor(nullptr) {}
LegacySHEntry(PContentParent* aContentParent, LegacySHistory* aSHistory,
uint64_t aSharedID);
explicit LegacySHEntry(const LegacySHEntry& aEntry)
: nsSHEntry(aEntry), mActor(nullptr) {}
......@@ -66,7 +79,7 @@ class LegacySHEntry final : public nsSHEntry, public CrossProcessSHEntry {
private:
friend class SHEntryParent;
friend class ContentParent;
friend class SHistoryParent;
~LegacySHEntry() {}
......
......@@ -195,7 +195,6 @@ SHistoryChild::AddEntry(nsISHEntry* aEntry, bool aPersist) {
}
NS_ENSURE_SUCCESS(rv, rv);
aEntry->SetSHistory(this);
if (mRootDocShell) {
aEntry->SetDocshellID(mRootDocShell->HistoryID());
......@@ -224,7 +223,6 @@ SHistoryChild::ReplaceEntry(int32_t aIndex, nsISHEntry* aReplaceEntry) {
}
NS_ENSURE_SUCCESS(rv, rv);
aReplaceEntry->SetSHistory(this);
return NS_OK;
}
......@@ -359,6 +357,18 @@ SHistoryChild::Reload(uint32_t aReloadFlags) {
return LoadURI(loadResult);
}
NS_IMETHODIMP
SHistoryChild::CreateEntry(nsISHEntry** aEntry) {
uint64_t sharedID = SHEntryChildShared::CreateSharedID();
RefPtr<SHEntryChild> entry = static_cast<SHEntryChild*>(
Manager()->SendPSHEntryConstructor(this, sharedID));
if (!entry) {
return NS_ERROR_FAILURE;
}
entry.forget(aEntry);
return NS_OK;
}
nsresult SHistoryChild::LoadURI(LoadSHEntryData& aLoadData) {
nsCOMPtr<nsIDocShell> docShell = aLoadData.browsingContext()->GetDocShell();
NS_ENSURE_TRUE(docShell, NS_ERROR_FAILURE);
......
......@@ -36,10 +36,26 @@ static void FillInLoadResult(PContentParent* aManager, nsresult aRv,
}
SHistoryParent::SHistoryParent(CanonicalBrowsingContext* aContext)
: mContext(aContext), mHistory(new LegacySHistory(aContext, nsID())) {}
: mHistory(new LegacySHistory(aContext, nsID())) {}
SHistoryParent::~SHistoryParent() {}
SHEntryParent* SHistoryParent::CreateEntry(
PContentParent* aContentParent, PSHistoryParent* aSHistoryParent,
const PSHEntryOrSharedID& aEntryOrSharedID) {
RefPtr<LegacySHEntry> entry;
if (aEntryOrSharedID.type() == PSHEntryOrSharedID::Tuint64_t) {
entry = new LegacySHEntry(
aContentParent, static_cast<SHistoryParent*>(aSHistoryParent)->mHistory,
aEntryOrSharedID.get_uint64_t());
} else {
entry = new LegacySHEntry(*(
static_cast<const SHEntryParent*>(aEntryOrSharedID.get_PSHEntryParent())
->mEntry));
}
return entry->CreateActor();
}
void SHistoryParent::ActorDestroy(ActorDestroyReason aWhy) {}
bool SHistoryParent::RecvGetCount(int32_t* aCount) {
......@@ -140,6 +156,7 @@ bool SHistoryParent::RecvEvictAllContentViewers() {
bool SHistoryParent::RecvEvictContentViewersOrReplaceEntry(
PSHEntryParent* aNewSHEntry, bool aReplace) {
MOZ_ASSERT(Manager() == aNewSHEntry->Manager());
mHistory->EvictContentViewersOrReplaceEntry(
aNewSHEntry ? static_cast<SHEntryParent*>(aNewSHEntry)->mEntry.get()
: nullptr,
......@@ -332,5 +349,16 @@ void LegacySHistory::EvictOutOfRangeWindowContentViewers(int32_t aIndex) {
}
}
NS_IMETHODIMP
LegacySHistory::CreateEntry(nsISHEntry** aEntry) {
NS_ENSURE_TRUE(mRootBC, NS_ERROR_FAILURE);
NS_ADDREF(*aEntry = new LegacySHEntry(
static_cast<CanonicalBrowsingContext*>(mRootBC)
->GetContentParent(),
this, SHEntryChildShared::CreateSharedID()));
return NS_OK;
}
} // namespace dom
} // namespace mozilla
......@@ -7,6 +7,7 @@
#ifndef mozilla_dom_SHistoryParent_h
#define mozilla_dom_SHistoryParent_h
#include "mozilla/dom/CanonicalBrowsingContext.h"
#include "mozilla/dom/PSHistoryParent.h"
#include "mozilla/RefPtr.h"
#include "nsSHistory.h"
......@@ -14,7 +15,6 @@
namespace mozilla {
namespace dom {
class CanonicalBrowsingContext;
class SHistoryParent;
/**
......@@ -29,8 +29,9 @@ class LegacySHistory final : public nsSHistory {
void EvictOutOfRangeWindowContentViewers(int32_t aIndex) override;
public:
LegacySHistory(mozilla::dom::CanonicalBrowsingContext* aRootBC,
const nsID& aDocShellID);
LegacySHistory(CanonicalBrowsingContext* aRootBC, const nsID& aDocShellID);
NS_IMETHOD CreateEntry(nsISHEntry** aEntry) override;
};
/**
......@@ -45,6 +46,10 @@ class SHistoryParent final : public PSHistoryParent {
explicit SHistoryParent(CanonicalBrowsingContext* aContext);
virtual ~SHistoryParent();
static SHEntryParent* CreateEntry(PContentParent* aContentParent,
PSHistoryParent* aSHistoryParent,
const PSHEntryOrSharedID& aEntryOrSharedID);
protected:
void ActorDestroy(ActorDestroyReason aWhy) override;
......@@ -84,7 +89,6 @@ class SHistoryParent final : public PSHistoryParent {
bool aReplace);
bool RecvNotifyListenersContentViewerEvicted(uint32_t aNumEvicted);
RefPtr<CanonicalBrowsingContext> mContext;
RefPtr<LegacySHistory> mHistory;
};
......
......@@ -218,11 +218,9 @@ interface nsISHEntry : nsISupports
[infallible] readonly attribute boolean loadedInThisProcess;
/**
* The session history it belongs to. It's usually only set on root entries.
* SHEntry is strictly bound to the SHistory it belongs to; it should not be
* changed once set to a non-null value.
* The session history it belongs to.
*/
[noscript, infallible] attribute nsISHistory SHistory;
[infallible] readonly attribute nsISHistory shistory;
/**
* A number that is assigned by the sHistory when the entry is activated
......
......@@ -264,4 +264,6 @@ interface nsISHistory: nsISupports
[notxpcom] void EnsureCorrectEntryAtCurrIndex(in nsISHEntry aEntry);
[notxpcom] void EvictContentViewersOrReplaceEntry(in nsISHEntry aNewSHEntry, in bool aReplace);
nsISHEntry createEntry();
};
......@@ -920,21 +920,12 @@ nsSHEntry::SetLastTouched(uint32_t aLastTouched) {
}
NS_IMETHODIMP
nsSHEntry::GetSHistory(nsISHistory** aSHistory) {
nsSHEntry::GetShistory(nsISHistory** aSHistory) {
nsCOMPtr<nsISHistory> shistory(do_QueryReferent(mShared->mSHistory));
shistory.forget(aSHistory);
return NS_OK;
}
NS_IMETHODIMP
nsSHEntry::SetSHistory(nsISHistory* aSHistory) {
nsWeakPtr shistory = do_GetWeakReference(aSHistory);
// mSHistory can not be changed once it's set
MOZ_ASSERT(!mShared->mSHistory || (mShared->mSHistory == shistory));
mShared->mSHistory = shistory;
return NS_OK;
}
NS_IMETHODIMP
nsSHEntry::SetLoadTypeAsHistory() {
// Set the LoadType by default to loadHistory during creation
......@@ -1047,8 +1038,8 @@ void nsSHEntry::EvictContentViewer() {
}
}
nsLegacySHEntry::nsLegacySHEntry(uint64_t aID)
: nsSHEntry(new nsSHEntryShared(aID)) {}
nsLegacySHEntry::nsLegacySHEntry(nsSHistory* aHistory, uint64_t aID)
: nsSHEntry(new nsSHEntryShared(aHistory, aID)) {}
NS_IMETHODIMP
nsLegacySHEntry::SetContentViewer(nsIContentViewer* aViewer) {
......@@ -1205,8 +1196,8 @@ bool nsLegacySHEntry::HasBFCacheEntry(nsIBFCacheEntry* aEntry) {
NS_IMETHODIMP
nsLegacySHEntry::AbandonBFCacheEntry() {
mShared = nsSHEntryShared::Duplicate(
GetState(), mozilla::dom::SHEntryChildShared::CreateSharedID());
mShared =
GetState()->Duplicate(mozilla::dom::SHEntryChildShared::CreateSharedID());
return NS_OK;
}
......
......@@ -79,7 +79,7 @@ class nsSHEntry : public nsISHEntry {
*/
class nsLegacySHEntry final : public nsSHEntry {
public:
explicit nsLegacySHEntry(uint64_t aID);
explicit nsLegacySHEntry(nsSHistory* aHistory, uint64_t aID);
explicit nsLegacySHEntry(const nsLegacySHEntry& aOther) : nsSHEntry(aOther) {}
NS_IMETHOD GetContentViewer(nsIContentViewer** aResult) override;
......
......@@ -13,8 +13,8 @@
#include "nsIDocShellTreeItem.h"
#include "mozilla/dom/Document.h"
#include "nsILayoutHistoryState.h"
#include "nsISHistory.h"
#include "nsIWebNavigation.h"
#include "nsSHistory.h"
#include "nsThreadUtils.h"
#include "mozilla/Attributes.h"
......@@ -22,23 +22,30 @@
namespace dom = mozilla::dom;
void nsSHEntryShared::Shutdown() {}
namespace mozilla {
namespace dom {
SHEntrySharedParentState::SHEntrySharedParentState(nsSHistory* aSHistory,
uint64_t aID)
: SHEntrySharedParentState(nsWeakPtr(do_GetWeakReference(aSHistory)).get(),
aID) {}
dom::SHEntrySharedParentState::SHEntrySharedParentState(uint64_t aID)
SHEntrySharedParentState::SHEntrySharedParentState(nsIWeakReference* aSHistory,
uint64_t aID)
: mDocShellID({0}),
mViewerBounds(0, 0, 0, 0),
mCacheKey(0),
mLastTouched(0),
mID(aID),
mSHistory(aSHistory),
mIsFrameNavigation(false),
mSticky(true),
mDynamicallyCreated(false),
mExpired(false) {}
dom::SHEntrySharedParentState::~SHEntrySharedParentState() {}
SHEntrySharedParentState::~SHEntrySharedParentState() {}
void dom::SHEntrySharedParentState::CopyFrom(
dom::SHEntrySharedParentState* aEntry) {
void SHEntrySharedParentState::CopyFrom(SHEntrySharedParentState* aEntry) {
mDocShellID = aEntry->mDocShellID;
mTriggeringPrincipal = aEntry->mTriggeringPrincipal;
mPrincipalToInherit = aEntry->mPrincipalToInherit;
......@@ -62,14 +69,15 @@ void dom::SHEntrySharedParentState::NotifyListenersContentViewerEvicted() {
dom::SHEntrySharedChildState::SHEntrySharedChildState()
: mSaveLayoutState(true) {}
void dom::SHEntrySharedChildState::CopyFrom(
dom::SHEntrySharedChildState* aEntry) {
void SHEntrySharedChildState::CopyFrom(SHEntrySharedChildState* aEntry) {
mChildShells.AppendObjects(aEntry->mChildShells);
mSaveLayoutState = aEntry->mSaveLayoutState;
}
nsSHEntryShared::nsSHEntryShared(uint64_t aID)
: dom::SHEntrySharedParentState(aID) {}
} // namespace dom
} // namespace mozilla
void nsSHEntryShared::Shutdown() {}
nsSHEntryShared::~nsSHEntryShared() {
// The destruction can be caused by either the entry is removed from session
......@@ -94,11 +102,11 @@ NS_IMPL_ADDREF_INHERITED(nsSHEntryShared, dom::SHEntrySharedParentState)
NS_IMPL_RELEASE_INHERITED(nsSHEntryShared, dom::SHEntrySharedParentState)
already_AddRefed<nsSHEntryShared> nsSHEntryShared::Duplicate(
nsSHEntryShared* aEntry, uint64_t aNewSharedID) {
RefPtr<nsSHEntryShared> newEntry = new nsSHEntryShared(aNewSharedID);
uint64_t aNewSharedID) {
RefPtr<nsSHEntryShared> newEntry = new nsSHEntryShared(this, aNewSharedID);
newEntry->dom::SHEntrySharedParentState::CopyFrom(aEntry);
newEntry->dom::SHEntrySharedChildState::CopyFrom(aEntry);
newEntry->dom::SHEntrySharedParentState::CopyFrom(this);
newEntry->dom::SHEntrySharedChildState::CopyFrom(this);
return newEntry.forget();
}
......
......@@ -26,6 +26,7 @@ class nsIDocShellTreeItem;
class nsILayoutHistoryState;
class nsDocShellEditorData;
class nsIMutableArray;
class nsSHistory;
// A document may have multiple SHEntries, either due to hash navigations or
// calls to history.pushState. SHEntries corresponding to the same document
......@@ -47,15 +48,15 @@ class Document;
*/
class SHEntrySharedParentState {
public:
explicit SHEntrySharedParentState(uint64_t aID);
uint64_t GetID() const { return mID; }
void NotifyListenersContentViewerEvicted();
protected:
friend class nsSHEntry;
SHEntrySharedParentState(nsSHistory* aSHistory, uint64_t aID);
SHEntrySharedParentState(SHEntrySharedParentState* aDuplicate, uint64_t aID)
: SHEntrySharedParentState(aDuplicate->mSHistory, aID) {}
SHEntrySharedParentState(nsIWeakReference* aDuplicate, uint64_t aID);
virtual ~SHEntrySharedParentState();
NS_INLINE_DECL_VIRTUAL_REFCOUNTING_WITH_DESTROY(SHEntrySharedParentState,
Destroy())
......@@ -137,7 +138,9 @@ class nsSHEntryShared final : public nsIBFCacheEntry,
static void EnsureHistoryTracker();
static void Shutdown();
explicit nsSHEntryShared(uint64_t aID);
using SHEntrySharedParentState::SHEntrySharedParentState;
already_AddRefed<nsSHEntryShared> Duplicate(uint64_t aNewSharedID);
NS_DECL_ISUPPORTS_INHERITED
NS_DECL_NSIBFCACHEENTRY
......@@ -151,9 +154,6 @@ class nsSHEntryShared final : public nsIBFCacheEntry,
nsExpirationState* GetExpirationState() { return &mExpirationState; }
static already_AddRefed<nsSHEntryShared> Duplicate(nsSHEntryShared* aEntry,
uint64_t aNewSharedID);
private:
~nsSHEntryShared();
......
......@@ -194,10 +194,10 @@ void nsSHistory::EvictContentViewerForEntry(nsISHEntry* aEntry) {
}
nsSHistory::nsSHistory(BrowsingContext* aRootBC, const nsID& aRootDocShellID)
: mIsRemote(false),
: mRootBC(aRootBC),
mIsRemote(false),
mIndex(-1),
mRequestedIndex(-1),
mRootBC(aRootBC),
mRootDocShellID(aRootDocShellID) {
// Add this new SHistory object to the list
gSHistoryList.insertBack(this);
......@@ -553,8 +553,8 @@ nsresult nsSHistory::AddEntry(nsISHEntry* aSHEntry, bool aPersist,
int32_t* aEntriesPurged) {
NS_ENSURE_ARG(aSHEntry);
nsCOMPtr<nsISHistory> shistoryOfEntry = aSHEntry->GetSHistory();
if (shistoryOfEntry && shistoryOfEntry != this) {
nsCOMPtr<nsISHistory> shistoryOfEntry = aSHEntry->GetShistory();
if (shistoryOfEntry != this) {
NS_WARNING(
"The entry has been associated to another nsISHistory instance. "
"Try nsISHEntry.clone() and nsISHEntry.abandonBFCacheEntry() "
......@@ -562,8 +562,6 @@ nsresult nsSHistory::AddEntry(nsISHEntry* aSHEntry, bool aPersist,
return NS_ERROR_FAILURE;
}
aSHEntry->SetSHistory(this);
// If we have a root docshell, update the docshell id of the root shentry to
// match the id of that docshell
if (mRootBC) {
......@@ -770,8 +768,8 @@ nsSHistory::ReplaceEntry(int32_t aIndex, nsISHEntry* aReplaceEntry) {
return NS_ERROR_FAILURE;
}
nsCOMPtr<nsISHistory> shistoryOfEntry = aReplaceEntry->GetSHistory();
if (shistoryOfEntry && shistoryOfEntry != this) {
nsCOMPtr<nsISHistory> shistoryOfEntry = aReplaceEntry->GetShistory();
if (shistoryOfEntry != this) {
NS_WARNING(
"The entry has been associated to another nsISHistory instance. "
"Try nsISHEntry.clone() and nsISHEntry.abandonBFCacheEntry() "
......@@ -779,8 +777,6 @@ nsSHistory::ReplaceEntry(int32_t aIndex, nsISHEntry* aReplaceEntry) {
return NS_ERROR_FAILURE;
}
aReplaceEntry->SetSHistory(this);
NOTIFY_LISTENERS(OnHistoryReplaceEntry, ());
aReplaceEntry->SetPersist(true);
......@@ -1578,3 +1574,11 @@ nsresult nsSHistory::InitiateLoad(nsISHEntry* aFrameEntry,
return NS_OK;
}
NS_IMETHODIMP
nsSHistory::CreateEntry(nsISHEntry** aEntry) {
nsCOMPtr<nsISHEntry> entry =
new nsLegacySHEntry(this, SHEntryChildShared::CreateSharedID());
entry.forget(aEntry);
return NS_OK;
}