Bug 1488321 - Remove all traces of the "transaction" terminology in SHistory. r=nika.

This patch:

- removes GetTransactionAtIndex(), because getTransactionAtIndex() can be used
  instead;

- renames a lot of things;

- updates some comments.

--HG--
extra : rebase_source : 845a1c1d5fe7f84eaa03db39a344d98fd5784afd
This commit is contained in:
Nicholas Nethercote 2018-09-05 09:03:22 +10:00
Родитель 13643f64e8
Коммит f5d9c8867c
12 изменённых файлов: 148 добавлений и 165 удалений

Просмотреть файл

@ -322,8 +322,8 @@ nsDocShell::nsDocShell()
, mMarginWidth(-1) , mMarginWidth(-1)
, mMarginHeight(-1) , mMarginHeight(-1)
, mItemType(typeContent) , mItemType(typeContent)
, mPreviousTransIndex(-1) , mPreviousEntryIndex(-1)
, mLoadedTransIndex(-1) , mLoadedEntryIndex(-1)
, mChildOffset(0) , mChildOffset(0)
, mSandboxFlags(0) , mSandboxFlags(0)
, mBusyFlags(BUSY_FLAGS_NONE) , mBusyFlags(BUSY_FLAGS_NONE)
@ -2286,16 +2286,16 @@ nsDocShell::SetUseErrorPages(bool aUseErrorPages)
} }
NS_IMETHODIMP NS_IMETHODIMP
nsDocShell::GetPreviousTransIndex(int32_t* aPreviousTransIndex) nsDocShell::GetPreviousEntryIndex(int32_t* aPreviousEntryIndex)
{ {
*aPreviousTransIndex = mPreviousTransIndex; *aPreviousEntryIndex = mPreviousEntryIndex;
return NS_OK; return NS_OK;
} }
NS_IMETHODIMP NS_IMETHODIMP
nsDocShell::GetLoadedTransIndex(int32_t* aLoadedTransIndex) nsDocShell::GetLoadedEntryIndex(int32_t* aLoadedEntryIndex)
{ {
*aLoadedTransIndex = mLoadedTransIndex; *aLoadedEntryIndex = mLoadedEntryIndex;
return NS_OK; return NS_OK;
} }
@ -2307,8 +2307,8 @@ nsDocShell::HistoryPurged(int32_t aNumEntries)
// eviction. We need to adjust by the number of entries that we // eviction. We need to adjust by the number of entries that we
// just purged from history, so that we look at the right session history // just purged from history, so that we look at the right session history
// entries during eviction. // entries during eviction.
mPreviousTransIndex = std::max(-1, mPreviousTransIndex - aNumEntries); mPreviousEntryIndex = std::max(-1, mPreviousEntryIndex - aNumEntries);
mLoadedTransIndex = std::max(0, mLoadedTransIndex - aNumEntries); mLoadedEntryIndex = std::max(0, mLoadedEntryIndex - aNumEntries);
nsTObserverArray<nsDocLoader*>::ForwardIterator iter(mChildList); nsTObserverArray<nsDocLoader*>::ForwardIterator iter(mChildList);
while (iter.HasMore()) { while (iter.HasMore()) {
@ -2322,29 +2322,29 @@ nsDocShell::HistoryPurged(int32_t aNumEntries)
} }
nsresult nsresult
nsDocShell::HistoryTransactionRemoved(int32_t aIndex) nsDocShell::HistoryEntryRemoved(int32_t aIndex)
{ {
// These indices are used for fastback cache eviction, to determine // These indices are used for fastback cache eviction, to determine
// which session history entries are candidates for content viewer // which session history entries are candidates for content viewer
// eviction. We need to adjust by the number of entries that we // eviction. We need to adjust by the number of entries that we
// just purged from history, so that we look at the right session history // just purged from history, so that we look at the right session history
// entries during eviction. // entries during eviction.
if (aIndex == mPreviousTransIndex) { if (aIndex == mPreviousEntryIndex) {
mPreviousTransIndex = -1; mPreviousEntryIndex = -1;
} else if (aIndex < mPreviousTransIndex) { } else if (aIndex < mPreviousEntryIndex) {
--mPreviousTransIndex; --mPreviousEntryIndex;
} }
if (mLoadedTransIndex == aIndex) { if (mLoadedEntryIndex == aIndex) {
mLoadedTransIndex = 0; mLoadedEntryIndex = 0;
} else if (aIndex < mLoadedTransIndex) { } else if (aIndex < mLoadedEntryIndex) {
--mLoadedTransIndex; --mLoadedEntryIndex;
} }
nsTObserverArray<nsDocLoader*>::ForwardIterator iter(mChildList); nsTObserverArray<nsDocLoader*>::ForwardIterator iter(mChildList);
while (iter.HasMore()) { while (iter.HasMore()) {
nsCOMPtr<nsIDocShell> shell = do_QueryObject(iter.GetNext()); nsCOMPtr<nsIDocShell> shell = do_QueryObject(iter.GetNext());
if (shell) { if (shell) {
static_cast<nsDocShell*>(shell.get())->HistoryTransactionRemoved(aIndex); static_cast<nsDocShell*>(shell.get())->HistoryEntryRemoved(aIndex);
} }
} }
@ -3866,7 +3866,7 @@ nsDocShell::AddChildSHEntryToParent(nsISHEntry* aNewEntry, int32_t aChildOffset,
// current index by 1 // current index by 1
RefPtr<ChildSHistory> rootSH = GetRootSessionHistory(); RefPtr<ChildSHistory> rootSH = GetRootSessionHistory();
if (rootSH) { if (rootSH) {
mPreviousTransIndex = rootSH->Index(); mPreviousEntryIndex = rootSH->Index();
} }
nsresult rv; nsresult rv;
@ -3877,10 +3877,10 @@ nsDocShell::AddChildSHEntryToParent(nsISHEntry* aNewEntry, int32_t aChildOffset,
} }
if (rootSH) { if (rootSH) {
mLoadedTransIndex = rootSH->Index(); mLoadedEntryIndex = rootSH->Index();
#ifdef DEBUG_PAGE_CACHE #ifdef DEBUG_PAGE_CACHE
printf("Previous index: %d, Loaded index: %d\n\n", mPreviousTransIndex, printf("Previous index: %d, Loaded index: %d\n\n", mPreviousEntryIndex,
mLoadedTransIndex); mLoadedEntryIndex);
#endif #endif
} }
@ -8120,12 +8120,12 @@ nsDocShell::RestoreFromHistory()
mURIResultedInDocument = true; mURIResultedInDocument = true;
RefPtr<ChildSHistory> rootSH = GetRootSessionHistory(); RefPtr<ChildSHistory> rootSH = GetRootSessionHistory();
if (rootSH) { if (rootSH) {
mPreviousTransIndex = rootSH->Index(); mPreviousEntryIndex = rootSH->Index();
rootSH->LegacySHistory()->UpdateIndex(); rootSH->LegacySHistory()->UpdateIndex();
mLoadedTransIndex = rootSH->Index(); mLoadedEntryIndex = rootSH->Index();
#ifdef DEBUG_PAGE_CACHE #ifdef DEBUG_PAGE_CACHE
printf("Previous index: %d, Loaded index: %d\n\n", mPreviousTransIndex, printf("Previous index: %d, Loaded index: %d\n\n", mPreviousEntryIndex,
mLoadedTransIndex); mLoadedEntryIndex);
#endif #endif
} }
@ -11607,12 +11607,12 @@ nsDocShell::OnNewURI(nsIURI* aURI, nsIChannel* aChannel,
if (rootSH && if (rootSH &&
((mLoadType & (LOAD_CMD_HISTORY | LOAD_CMD_RELOAD)) || ((mLoadType & (LOAD_CMD_HISTORY | LOAD_CMD_RELOAD)) ||
mLoadType == LOAD_NORMAL_REPLACE)) { mLoadType == LOAD_NORMAL_REPLACE)) {
mPreviousTransIndex = rootSH->Index(); mPreviousEntryIndex = rootSH->Index();
rootSH->LegacySHistory()->UpdateIndex(); rootSH->LegacySHistory()->UpdateIndex();
mLoadedTransIndex = rootSH->Index(); mLoadedEntryIndex = rootSH->Index();
#ifdef DEBUG_PAGE_CACHE #ifdef DEBUG_PAGE_CACHE
printf("Previous index: %d, Loaded index: %d\n\n", printf("Previous index: %d, Loaded index: %d\n\n",
mPreviousTransIndex, mLoadedTransIndex); mPreviousEntryIndex, mLoadedEntryIndex);
#endif #endif
} }
@ -12254,14 +12254,14 @@ nsDocShell::AddToSessionHistory(nsIURI* aURI, nsIChannel* aChannel,
if (addToSHistory) { if (addToSHistory) {
// Add to session history // Add to session history
mPreviousTransIndex = mSessionHistory->Index(); mPreviousEntryIndex = mSessionHistory->Index();
bool shouldPersist = ShouldAddToSessionHistory(aURI, aChannel); bool shouldPersist = ShouldAddToSessionHistory(aURI, aChannel);
rv = mSessionHistory->LegacySHistory()->AddEntry(entry, shouldPersist); rv = mSessionHistory->LegacySHistory()->AddEntry(entry, shouldPersist);
mLoadedTransIndex = mSessionHistory->Index(); mLoadedEntryIndex = mSessionHistory->Index();
#ifdef DEBUG_PAGE_CACHE #ifdef DEBUG_PAGE_CACHE
printf("Previous index: %d, Loaded index: %d\n\n", printf("Previous index: %d, Loaded index: %d\n\n",
mPreviousTransIndex, mLoadedTransIndex); mPreviousEntryIndex, mLoadedEntryIndex);
#endif #endif
} }
} else { } else {

Просмотреть файл

@ -254,7 +254,7 @@ public:
LOCATION_CHANGE_SAME_DOCUMENT); LOCATION_CHANGE_SAME_DOCUMENT);
} }
nsresult HistoryTransactionRemoved(int32_t aIndex); nsresult HistoryEntryRemoved(int32_t aIndex);
// Notify Scroll observers when an async panning/zooming transform // Notify Scroll observers when an async panning/zooming transform
// has started being applied // has started being applied
@ -1031,11 +1031,11 @@ private: // data members
// Create() is called, the type is not expected to change. // Create() is called, the type is not expected to change.
int32_t mItemType; int32_t mItemType;
// Index into the SHTransaction list, indicating the previous and current // Index into the nsISHEntry array, indicating the previous and current
// transaction at the time that this DocShell begins to load. Consequently // entry at the time that this DocShell begins to load. Consequently
// root docshell's indices can differ from child docshells'. // root docshell's indices can differ from child docshells'.
int32_t mPreviousTransIndex; int32_t mPreviousEntryIndex;
int32_t mLoadedTransIndex; int32_t mLoadedEntryIndex;
// Offset in the parent's child list. // Offset in the parent's child list.
// -1 if the docshell is added dynamically to the parent shell. // -1 if the docshell is added dynamically to the parent shell.

Просмотреть файл

@ -539,12 +539,12 @@ interface nsIDocShell : nsIDocShellTreeItem
readonly attribute nsIChannel failedChannel; readonly attribute nsIChannel failedChannel;
/** /**
* Keeps track of the previous SHTransaction index and the current * Keeps track of the previous nsISHEntry index and the current
* SHTransaction index at the time that the doc shell begins to load. * nsISHEntry index at the time that the doc shell begins to load.
* Used for ContentViewer eviction. * Used for ContentViewer eviction.
*/ */
readonly attribute long previousTransIndex; readonly attribute long previousEntryIndex;
readonly attribute long loadedTransIndex; readonly attribute long loadedEntryIndex;
/** /**
* Notification that entries have been removed from the beginning of a * Notification that entries have been removed from the beginning of a

Просмотреть файл

@ -402,7 +402,7 @@ interface nsISHEntry : nsISupports
void ReplaceChild(in nsISHEntry aNewChild); void ReplaceChild(in nsISHEntry aNewChild);
/** /**
* When an entry is serving as a transaction within nsISHistory, this * When an entry is serving is within nsISHistory's array of entries, this
* property specifies if it should persist. If not it will be replaced by * property specifies if it should persist. If not it will be replaced by
* new additions to the list. * new additions to the list.
*/ */

Просмотреть файл

@ -68,14 +68,11 @@ interface nsISHistory: nsISupports
attribute long maxLength; attribute long maxLength;
/** /**
* Get the history entry at a given index. * Get the history entry at a given index. Returns non-null on success.
* *
* @param index The index value whose entry is requested. * @param index The index value whose entry is requested.
* The oldest entry is located at index == 0. * The oldest entry is located at index == 0.
* @return <code>NS_OK</code> history entry for * @return The found entry; never null.
* the index is obtained successfully.
* <code>NS_ERROR_FAILURE</code> Error in obtaining
* history entry for the given index.
*/ */
nsISHEntry getEntryAtIndex(in long aIndex); nsISHEntry getEntryAtIndex(in long aIndex);
@ -151,11 +148,6 @@ interface nsISHistory: nsISupports
*/ */
void addEntry(in nsISHEntry aEntry, in boolean aPersist); void addEntry(in nsISHEntry aEntry, in boolean aPersist);
/**
* Get the transaction at a particular index. Returns non-null on success.
*/
nsISHEntry GetTransactionAtIndex(in int32_t aIndex);
/** /**
* Sets the toplevel docshell object to which this SHistory object belongs to. * Sets the toplevel docshell object to which this SHistory object belongs to.
*/ */

Просмотреть файл

@ -184,11 +184,11 @@ nsSHistoryObserver::Observe(nsISupports* aSubject, const char* aTopic,
namespace { namespace {
already_AddRefed<nsIContentViewer> already_AddRefed<nsIContentViewer>
GetContentViewerForTransaction(nsISHEntry* aTrans) GetContentViewerForEntry(nsISHEntry* aEntry)
{ {
nsCOMPtr<nsISHEntry> ownerEntry; nsCOMPtr<nsISHEntry> ownerEntry;
nsCOMPtr<nsIContentViewer> viewer; nsCOMPtr<nsIContentViewer> viewer;
aTrans->GetAnyContentViewer(getter_AddRefs(ownerEntry), aEntry->GetAnyContentViewer(getter_AddRefs(ownerEntry),
getter_AddRefs(viewer)); getter_AddRefs(viewer));
return viewer.forget(); return viewer.forget();
} }
@ -196,11 +196,11 @@ GetContentViewerForTransaction(nsISHEntry* aTrans)
} // namespace } // namespace
void void
nsSHistory::EvictContentViewerForTransaction(nsISHEntry* aTrans) nsSHistory::EvictContentViewerForEntry(nsISHEntry* aEntry)
{ {
nsCOMPtr<nsIContentViewer> viewer; nsCOMPtr<nsIContentViewer> viewer;
nsCOMPtr<nsISHEntry> ownerEntry; nsCOMPtr<nsISHEntry> ownerEntry;
aTrans->GetAnyContentViewer(getter_AddRefs(ownerEntry), aEntry->GetAnyContentViewer(getter_AddRefs(ownerEntry),
getter_AddRefs(viewer)); getter_AddRefs(viewer));
if (viewer) { if (viewer) {
NS_ASSERTION(ownerEntry, "Content viewer exists but its SHEntry is null"); NS_ASSERTION(ownerEntry, "Content viewer exists but its SHEntry is null");
@ -219,9 +219,9 @@ nsSHistory::EvictContentViewerForTransaction(nsISHEntry* aTrans)
// When dropping bfcache, we have to remove associated dynamic entries as well. // When dropping bfcache, we have to remove associated dynamic entries as well.
int32_t index = -1; int32_t index = -1;
GetIndexOfEntry(aTrans, &index); GetIndexOfEntry(aEntry, &index);
if (index != -1) { if (index != -1) {
RemoveDynEntries(index, aTrans); RemoveDynEntries(index, aEntry);
} }
} }
@ -609,7 +609,7 @@ nsSHistory::AddEntry(nsISHEntry* aSHEntry, bool aPersist)
nsCOMPtr<nsISHEntry> currentTxn; nsCOMPtr<nsISHEntry> currentTxn;
if (mIndex >= 0) { if (mIndex >= 0) {
nsresult rv = GetTransactionAtIndex(mIndex, getter_AddRefs(currentTxn)); nsresult rv = GetEntryAtIndex(mIndex, getter_AddRefs(currentTxn));
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
} }
@ -625,7 +625,7 @@ nsSHistory::AddEntry(nsISHEntry* aSHEntry, bool aPersist)
if (currentTxn && !currentTxn->GetPersist()) { if (currentTxn && !currentTxn->GetPersist()) {
NOTIFY_LISTENERS(OnHistoryReplaceEntry, (mIndex)); NOTIFY_LISTENERS(OnHistoryReplaceEntry, (mIndex));
aSHEntry->SetPersist(aPersist); aSHEntry->SetPersist(aPersist);
mTransactions[mIndex] = aSHEntry; mEntries[mIndex] = aSHEntry;
return NS_OK; return NS_OK;
} }
@ -633,12 +633,12 @@ nsSHistory::AddEntry(nsISHEntry* aSHEntry, bool aPersist)
aSHEntry->GetURI(getter_AddRefs(uri)); aSHEntry->GetURI(getter_AddRefs(uri));
NOTIFY_LISTENERS(OnHistoryNewEntry, (uri, mIndex)); NOTIFY_LISTENERS(OnHistoryNewEntry, (uri, mIndex));
// Remove all transactions after the current one, add the new one, and set // Remove all entries after the current one, add the new one, and set the new
// the new one as the current one. // one as the current one.
MOZ_ASSERT(mIndex >= -1); MOZ_ASSERT(mIndex >= -1);
aSHEntry->SetPersist(aPersist); aSHEntry->SetPersist(aPersist);
mTransactions.TruncateLength(mIndex + 1); mEntries.TruncateLength(mIndex + 1);
mTransactions.AppendElement(aSHEntry); mEntries.AppendElement(aSHEntry);
mIndex++; mIndex++;
NOTIFY_LISTENERS(OnLengthChanged, (Length())); NOTIFY_LISTENERS(OnLengthChanged, (Length()));
@ -693,13 +693,6 @@ nsSHistory::GetRequestedIndex(int32_t* aResult)
NS_IMETHODIMP NS_IMETHODIMP
nsSHistory::GetEntryAtIndex(int32_t aIndex, nsISHEntry** aResult) nsSHistory::GetEntryAtIndex(int32_t aIndex, nsISHEntry** aResult)
{
return GetTransactionAtIndex(aIndex, aResult);
}
/* Get the transaction at a given index */
NS_IMETHODIMP
nsSHistory::GetTransactionAtIndex(int32_t aIndex, nsISHEntry** aResult)
{ {
NS_ENSURE_ARG_POINTER(aResult); NS_ENSURE_ARG_POINTER(aResult);
@ -707,7 +700,7 @@ nsSHistory::GetTransactionAtIndex(int32_t aIndex, nsISHEntry** aResult)
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }
*aResult = mTransactions[aIndex]; *aResult = mEntries[aIndex];
NS_ADDREF(*aResult); NS_ADDREF(*aResult);
return NS_OK; return NS_OK;
} }
@ -721,7 +714,7 @@ nsSHistory::GetIndexOfEntry(nsISHEntry* aSHEntry, int32_t* aResult)
*aResult = -1; *aResult = -1;
for (int32_t i = 0; i < Length(); i++) { for (int32_t i = 0; i < Length(); i++) {
if (aSHEntry == mTransactions[i]) { if (aSHEntry == mEntries[i]) {
*aResult = i; *aResult = i;
return NS_OK; return NS_OK;
} }
@ -735,7 +728,7 @@ nsresult
nsSHistory::PrintHistory() nsSHistory::PrintHistory()
{ {
for (int32_t i = 0; i < Length(); i++) { for (int32_t i = 0; i < Length(); i++) {
nsCOMPtr<nsISHEntry> entry = mTransactions[i]; nsCOMPtr<nsISHEntry> entry = mEntries[i];
nsCOMPtr<nsILayoutHistoryState> layoutHistoryState; nsCOMPtr<nsILayoutHistoryState> layoutHistoryState;
nsCOMPtr<nsIURI> uri; nsCOMPtr<nsIURI> uri;
nsString title; nsString title;
@ -750,7 +743,7 @@ nsSHistory::PrintHistory()
uri->GetSpec(url); uri->GetSpec(url);
} }
printf("**** SH Transaction #%d, Entry = %x\n", i, entry.get()); printf("**** SH Entry #%d: %x\n", i, entry.get());
printf("\t\t URL = %s\n", url.get()); printf("\t\t URL = %s\n", url.get());
printf("\t\t Title = %s\n", NS_LossyConvertUTF16toASCII(title).get()); printf("\t\t Title = %s\n", NS_LossyConvertUTF16toASCII(title).get());
@ -813,7 +806,7 @@ nsSHistory::PurgeHistory(int32_t aNumEntries)
} }
// Remove the first `aNumEntries` entries. // Remove the first `aNumEntries` entries.
mTransactions.RemoveElementsAt(0, aNumEntries); mEntries.RemoveElementsAt(0, aNumEntries);
// Adjust the indices, but don't let them go below -1. // Adjust the indices, but don't let them go below -1.
mIndex -= aNumEntries; mIndex -= aNumEntries;
@ -884,7 +877,7 @@ nsSHistory::ReplaceEntry(int32_t aIndex, nsISHEntry* aReplaceEntry)
NOTIFY_LISTENERS(OnHistoryReplaceEntry, (aIndex)); NOTIFY_LISTENERS(OnHistoryReplaceEntry, (aIndex));
aReplaceEntry->SetPersist(true); aReplaceEntry->SetPersist(true);
mTransactions[aIndex] = aReplaceEntry; mEntries[aIndex] = aReplaceEntry;
return NS_OK; return NS_OK;
} }
@ -914,7 +907,7 @@ nsSHistory::EvictAllContentViewers()
// XXXbz we don't actually do a good job of evicting things as we should, so // XXXbz we don't actually do a good job of evicting things as we should, so
// we might have viewers quite far from mIndex. So just evict everything. // we might have viewers quite far from mIndex. So just evict everything.
for (int32_t i = 0; i < Length(); i++) { for (int32_t i = 0; i < Length(); i++) {
EvictContentViewerForTransaction(mTransactions[i]); EvictContentViewerForEntry(mEntries[i]);
} }
return NS_OK; return NS_OK;
@ -982,11 +975,11 @@ nsSHistory::EvictOutOfRangeWindowContentViewers(int32_t aIndex)
// //
// to ensure that this SHistory object isn't responsible for more than // to ensure that this SHistory object isn't responsible for more than
// VIEWER_WINDOW content viewers. But our job is complicated by the // VIEWER_WINDOW content viewers. But our job is complicated by the
// fact that two transactions which are related by either hash navigations or // fact that two entries which are related by either hash navigations or
// history.pushState will have the same content viewer. // history.pushState will have the same content viewer.
// //
// To illustrate the issue, suppose VIEWER_WINDOW = 3 and we have four // To illustrate the issue, suppose VIEWER_WINDOW = 3 and we have four
// linked transactions in our history. Suppose we then add a new content // linked entries in our history. Suppose we then add a new content
// viewer and call into this function. So the history looks like: // viewer and call into this function. So the history looks like:
// //
// A A A A B // A A A A B
@ -1027,8 +1020,7 @@ nsSHistory::EvictOutOfRangeWindowContentViewers(int32_t aIndex)
// if it appears outside this range. // if it appears outside this range.
nsCOMArray<nsIContentViewer> safeViewers; nsCOMArray<nsIContentViewer> safeViewers;
for (int32_t i = startSafeIndex; i <= endSafeIndex; i++) { for (int32_t i = startSafeIndex; i <= endSafeIndex; i++) {
nsCOMPtr<nsIContentViewer> viewer = nsCOMPtr<nsIContentViewer> viewer = GetContentViewerForEntry(mEntries[i]);
GetContentViewerForTransaction(mTransactions[i]);
safeViewers.AppendObject(viewer); safeViewers.AppendObject(viewer);
} }
@ -1036,32 +1028,32 @@ nsSHistory::EvictOutOfRangeWindowContentViewers(int32_t aIndex)
// (It's important that the condition checks Length(), rather than a cached // (It's important that the condition checks Length(), rather than a cached
// copy of Length(), because the length might change between iterations.) // copy of Length(), because the length might change between iterations.)
for (int32_t i = 0; i < Length(); i++) { for (int32_t i = 0; i < Length(); i++) {
nsCOMPtr<nsISHEntry> trans = mTransactions[i]; nsCOMPtr<nsISHEntry> entry = mEntries[i];
nsCOMPtr<nsIContentViewer> viewer = GetContentViewerForTransaction(trans); nsCOMPtr<nsIContentViewer> viewer = GetContentViewerForEntry(entry);
if (safeViewers.IndexOf(viewer) == -1) { if (safeViewers.IndexOf(viewer) == -1) {
EvictContentViewerForTransaction(trans); EvictContentViewerForEntry(entry);
} }
} }
} }
namespace { namespace {
class TransactionAndDistance class EntryAndDistance
{ {
public: public:
TransactionAndDistance(nsSHistory* aSHistory, nsISHEntry* aTrans, uint32_t aDist) EntryAndDistance(nsSHistory* aSHistory, nsISHEntry* aEntry, uint32_t aDist)
: mSHistory(aSHistory) : mSHistory(aSHistory)
, mTransaction(aTrans) , mEntry(aEntry)
, mLastTouched(0) , mLastTouched(0)
, mDistance(aDist) , mDistance(aDist)
{ {
mViewer = GetContentViewerForTransaction(aTrans); mViewer = GetContentViewerForEntry(aEntry);
NS_ASSERTION(mViewer, "Transaction should have a content viewer"); NS_ASSERTION(mViewer, "Entry should have a content viewer");
mTransaction->GetLastTouched(&mLastTouched); mEntry->GetLastTouched(&mLastTouched);
} }
bool operator<(const TransactionAndDistance& aOther) const bool operator<(const EntryAndDistance& aOther) const
{ {
// Compare distances first, and fall back to last-accessed times. // Compare distances first, and fall back to last-accessed times.
if (aOther.mDistance != this->mDistance) { if (aOther.mDistance != this->mDistance) {
@ -1071,17 +1063,17 @@ public:
return this->mLastTouched < aOther.mLastTouched; return this->mLastTouched < aOther.mLastTouched;
} }
bool operator==(const TransactionAndDistance& aOther) const bool operator==(const EntryAndDistance& aOther) const
{ {
// This is a little silly; we need == so the default comaprator can be // This is a little silly; we need == so the default comaprator can be
// instantiated, but this function is never actually called when we sort // instantiated, but this function is never actually called when we sort
// the list of TransactionAndDistance objects. // the list of EntryAndDistance objects.
return aOther.mDistance == this->mDistance && return aOther.mDistance == this->mDistance &&
aOther.mLastTouched == this->mLastTouched; aOther.mLastTouched == this->mLastTouched;
} }
RefPtr<nsSHistory> mSHistory; RefPtr<nsSHistory> mSHistory;
nsCOMPtr<nsISHEntry> mTransaction; nsCOMPtr<nsISHEntry> mEntry;
nsCOMPtr<nsIContentViewer> mViewer; nsCOMPtr<nsIContentViewer> mViewer;
uint32_t mLastTouched; uint32_t mLastTouched;
int32_t mDistance; int32_t mDistance;
@ -1093,18 +1085,18 @@ public:
void void
nsSHistory::GloballyEvictContentViewers() nsSHistory::GloballyEvictContentViewers()
{ {
// First, collect from each SHistory object the transactions which have a // First, collect from each SHistory object the entries which have a cached
// cached content viewer. Associate with each transaction its distance from // content viewer. Associate with each entry its distance from its SHistory's
// its SHistory's current index. // current index.
nsTArray<TransactionAndDistance> transactions; nsTArray<EntryAndDistance> entries;
for (auto shist : gSHistoryList) { for (auto shist : gSHistoryList) {
// Maintain a list of the transactions which have viewers and belong to // Maintain a list of the entries which have viewers and belong to
// this particular shist object. We'll add this list to the global list, // this particular shist object. We'll add this list to the global list,
// |transactions|, eventually. // |entries|, eventually.
nsTArray<TransactionAndDistance> shTransactions; nsTArray<EntryAndDistance> shEntries;
// Content viewers are likely to exist only within shist->mIndex -/+ // Content viewers are likely to exist only within shist->mIndex -/+
// VIEWER_WINDOW, so only search within that range. // VIEWER_WINDOW, so only search within that range.
@ -1122,18 +1114,18 @@ nsSHistory::GloballyEvictContentViewers()
int32_t startIndex, endIndex; int32_t startIndex, endIndex;
shist->WindowIndices(shist->mIndex, &startIndex, &endIndex); shist->WindowIndices(shist->mIndex, &startIndex, &endIndex);
for (int32_t i = startIndex; i <= endIndex; i++) { for (int32_t i = startIndex; i <= endIndex; i++) {
nsCOMPtr<nsISHEntry> trans = shist->mTransactions[i]; nsCOMPtr<nsISHEntry> entry = shist->mEntries[i];
nsCOMPtr<nsIContentViewer> contentViewer = nsCOMPtr<nsIContentViewer> contentViewer =
GetContentViewerForTransaction(trans); GetContentViewerForEntry(entry);
if (contentViewer) { if (contentViewer) {
// Because one content viewer might belong to multiple SHEntries, we // Because one content viewer might belong to multiple SHEntries, we
// have to search through shTransactions to see if we already know // have to search through shEntries to see if we already know
// about this content viewer. If we find the viewer, update its // about this content viewer. If we find the viewer, update its
// distance from the SHistory's index and continue. // distance from the SHistory's index and continue.
bool found = false; bool found = false;
for (uint32_t j = 0; j < shTransactions.Length(); j++) { for (uint32_t j = 0; j < shEntries.Length(); j++) {
TransactionAndDistance& container = shTransactions[j]; EntryAndDistance& container = shEntries[j];
if (container.mViewer == contentViewer) { if (container.mViewer == contentViewer) {
container.mDistance = std::min(container.mDistance, container.mDistance = std::min(container.mDistance,
DeprecatedAbs(i - shist->mIndex)); DeprecatedAbs(i - shist->mIndex));
@ -1142,44 +1134,43 @@ nsSHistory::GloballyEvictContentViewers()
} }
} }
// If we didn't find a TransactionAndDistance for this content viewer, // If we didn't find a EntryAndDistance for this content viewer, make a
// make a new one. // new one.
if (!found) { if (!found) {
TransactionAndDistance container(shist, trans, EntryAndDistance container(shist, entry,
DeprecatedAbs(i - shist->mIndex)); DeprecatedAbs(i - shist->mIndex));
shTransactions.AppendElement(container); shEntries.AppendElement(container);
} }
} }
} }
// We've found all the transactions belonging to shist which have viewers. // We've found all the entries belonging to shist which have viewers.
// Add those transactions to our global list and move on. // Add those entries to our global list and move on.
transactions.AppendElements(shTransactions); entries.AppendElements(shEntries);
} }
// We now have collected all cached content viewers. First check that we // We now have collected all cached content viewers. First check that we
// have enough that we actually need to evict some. // have enough that we actually need to evict some.
if ((int32_t)transactions.Length() <= sHistoryMaxTotalViewers) { if ((int32_t)entries.Length() <= sHistoryMaxTotalViewers) {
return; return;
} }
// If we need to evict, sort our list of transactions and evict the largest // If we need to evict, sort our list of entries and evict the largest
// ones. (We could of course get better algorithmic complexity here by using // ones. (We could of course get better algorithmic complexity here by using
// a heap or something more clever. But sHistoryMaxTotalViewers isn't large, // a heap or something more clever. But sHistoryMaxTotalViewers isn't large,
// so let's not worry about it.) // so let's not worry about it.)
transactions.Sort(); entries.Sort();
for (int32_t i = transactions.Length() - 1; i >= sHistoryMaxTotalViewers; for (int32_t i = entries.Length() - 1; i >= sHistoryMaxTotalViewers;
--i) { --i) {
(transactions[i].mSHistory)-> (entries[i].mSHistory)->EvictContentViewerForEntry(entries[i].mEntry);
EvictContentViewerForTransaction(transactions[i].mTransaction);
} }
} }
nsresult nsresult
nsSHistory::FindTransactionForBFCache(nsIBFCacheEntry* aEntry, nsSHistory::FindEntryForBFCache(nsIBFCacheEntry* aBFEntry,
nsISHEntry** aResult, nsISHEntry** aResult,
int32_t* aResultIndex) int32_t* aResultIndex)
{ {
*aResult = nullptr; *aResult = nullptr;
*aResultIndex = -1; *aResultIndex = -1;
@ -1188,11 +1179,11 @@ nsSHistory::FindTransactionForBFCache(nsIBFCacheEntry* aEntry,
WindowIndices(mIndex, &startIndex, &endIndex); WindowIndices(mIndex, &startIndex, &endIndex);
for (int32_t i = startIndex; i <= endIndex; ++i) { for (int32_t i = startIndex; i <= endIndex; ++i) {
nsCOMPtr<nsISHEntry> trans = mTransactions[i]; nsCOMPtr<nsISHEntry> shEntry = mEntries[i];
// Does entry have the same BFCacheEntry as the argument to this method? // Does shEntry have the same BFCacheEntry as the argument to this method?
if (trans->HasBFCacheEntry(aEntry)) { if (shEntry->HasBFCacheEntry(aBFEntry)) {
trans.forget(aResult); shEntry.forget(aResult);
*aResultIndex = i; *aResultIndex = i;
return NS_OK; return NS_OK;
} }
@ -1201,28 +1192,28 @@ nsSHistory::FindTransactionForBFCache(nsIBFCacheEntry* aEntry,
} }
nsresult nsresult
nsSHistory::EvictExpiredContentViewerForEntry(nsIBFCacheEntry* aEntry) nsSHistory::EvictExpiredContentViewerForEntry(nsIBFCacheEntry* aBFEntry)
{ {
int32_t index; int32_t index;
nsCOMPtr<nsISHEntry> trans; nsCOMPtr<nsISHEntry> shEntry;
FindTransactionForBFCache(aEntry, getter_AddRefs(trans), &index); FindEntryForBFCache(aBFEntry, getter_AddRefs(shEntry), &index);
if (index == mIndex) { if (index == mIndex) {
NS_WARNING("How did the current SHEntry expire?"); NS_WARNING("How did the current SHEntry expire?");
return NS_OK; return NS_OK;
} }
if (trans) { if (shEntry) {
EvictContentViewerForTransaction(trans); EvictContentViewerForEntry(shEntry);
} }
return NS_OK; return NS_OK;
} }
NS_IMETHODIMP NS_IMETHODIMP
nsSHistory::AddToExpirationTracker(nsIBFCacheEntry* aEntry) nsSHistory::AddToExpirationTracker(nsIBFCacheEntry* aBFEntry)
{ {
RefPtr<nsSHEntryShared> entry = static_cast<nsSHEntryShared*>(aEntry); RefPtr<nsSHEntryShared> entry = static_cast<nsSHEntryShared*>(aBFEntry);
if (!mHistoryTracker || !entry) { if (!mHistoryTracker || !entry) {
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }
@ -1232,9 +1223,9 @@ nsSHistory::AddToExpirationTracker(nsIBFCacheEntry* aEntry)
} }
NS_IMETHODIMP NS_IMETHODIMP
nsSHistory::RemoveFromExpirationTracker(nsIBFCacheEntry* aEntry) nsSHistory::RemoveFromExpirationTracker(nsIBFCacheEntry* aBFEntry)
{ {
RefPtr<nsSHEntryShared> entry = static_cast<nsSHEntryShared*>(aEntry); RefPtr<nsSHEntryShared> entry = static_cast<nsSHEntryShared*>(aBFEntry);
MOZ_ASSERT(mHistoryTracker && !mHistoryTracker->IsEmpty()); MOZ_ASSERT(mHistoryTracker && !mHistoryTracker->IsEmpty());
if (!mHistoryTracker || !entry) { if (!mHistoryTracker || !entry) {
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
@ -1368,19 +1359,19 @@ nsSHistory::RemoveDuplicate(int32_t aIndex, bool aKeepNext)
NS_ENSURE_SUCCESS(rv, false); NS_ENSURE_SUCCESS(rv, false);
if (IsSameTree(root1, root2)) { if (IsSameTree(root1, root2)) {
mTransactions.RemoveElementAt(aIndex); mEntries.RemoveElementAt(aIndex);
if (mRootDocShell) { if (mRootDocShell) {
static_cast<nsDocShell*>(mRootDocShell)->HistoryTransactionRemoved(aIndex); static_cast<nsDocShell*>(mRootDocShell)->HistoryEntryRemoved(aIndex);
} }
// Adjust our indices to reflect the removed transaction // Adjust our indices to reflect the removed entry.
if (mIndex > aIndex) { if (mIndex > aIndex) {
mIndex = mIndex - 1; mIndex = mIndex - 1;
NOTIFY_LISTENERS(OnIndexChanged, (mIndex)); NOTIFY_LISTENERS(OnIndexChanged, (mIndex));
} }
// NB: If the transaction we are removing is the transaction currently // NB: If the entry we are removing is the entry currently
// being navigated to (mRequestedIndex) then we adjust the index // being navigated to (mRequestedIndex) then we adjust the index
// only if we're not keeping the next entry (because if we are keeping // only if we're not keeping the next entry (because if we are keeping
// the next entry (because the current is a duplicate of the next), then // the next entry (because the current is a duplicate of the next), then
@ -1444,13 +1435,13 @@ nsSHistory::RemoveDynEntries(int32_t aIndex, nsISHEntry* aEntry)
} }
void void
nsSHistory::RemoveDynEntriesForBFCacheEntry(nsIBFCacheEntry* aEntry) nsSHistory::RemoveDynEntriesForBFCacheEntry(nsIBFCacheEntry* aBFEntry)
{ {
int32_t index; int32_t index;
nsCOMPtr<nsISHEntry> trans; nsCOMPtr<nsISHEntry> shEntry;
FindTransactionForBFCache(aEntry, getter_AddRefs(trans), &index); FindEntryForBFCache(aBFEntry, getter_AddRefs(shEntry), &index);
if (trans) { if (shEntry) {
RemoveDynEntries(index, trans); RemoveDynEntries(index, shEntry);
} }
} }

Просмотреть файл

@ -143,16 +143,16 @@ private:
nsresult PrintHistory(); nsresult PrintHistory();
#endif #endif
// Find the transaction for a given bfcache entry. It only looks up between // Find the history entry for a given bfcache entry. It only looks up between
// the range where alive viewers may exist (i.e nsISHistory::VIEWER_WINDOW). // the range where alive viewers may exist (i.e nsISHistory::VIEWER_WINDOW).
nsresult FindTransactionForBFCache(nsIBFCacheEntry* aEntry, nsresult FindEntryForBFCache(nsIBFCacheEntry* aBFEntry,
nsISHEntry** aResult, nsISHEntry** aResult,
int32_t* aResultIndex); int32_t* aResultIndex);
// Evict content viewers in this window which don't lie in the "safe" range // Evict content viewers in this window which don't lie in the "safe" range
// around aIndex. // around aIndex.
void EvictOutOfRangeWindowContentViewers(int32_t aIndex); void EvictOutOfRangeWindowContentViewers(int32_t aIndex);
void EvictContentViewerForTransaction(nsISHEntry* aTrans); void EvictContentViewerForEntry(nsISHEntry* aEntry);
static void GloballyEvictContentViewers(); static void GloballyEvictContentViewers();
static void GloballyEvictAllContentViewers(); static void GloballyEvictAllContentViewers();
@ -163,7 +163,7 @@ private:
nsresult LoadNextPossibleEntry(int32_t aNewIndex, long aLoadType, nsresult LoadNextPossibleEntry(int32_t aNewIndex, long aLoadType,
uint32_t aHistCmd); uint32_t aHistCmd);
// aIndex is the index of the transaction which may be removed. // aIndex is the index of the entry which may be removed.
// If aKeepNext is true, aIndex is compared to aIndex + 1, // If aKeepNext is true, aIndex is compared to aIndex + 1,
// otherwise comparison is done to aIndex - 1. // otherwise comparison is done to aIndex - 1.
bool RemoveDuplicate(int32_t aIndex, bool aKeepNext); bool RemoveDuplicate(int32_t aIndex, bool aKeepNext);
@ -171,15 +171,15 @@ private:
// Track all bfcache entries and evict on expiration. // Track all bfcache entries and evict on expiration.
mozilla::UniquePtr<HistoryTracker> mHistoryTracker; mozilla::UniquePtr<HistoryTracker> mHistoryTracker;
nsTArray<nsCOMPtr<nsISHEntry>> mTransactions; // entries are never null nsTArray<nsCOMPtr<nsISHEntry>> mEntries; // entries are never null
int32_t mIndex; // -1 means "no index" int32_t mIndex; // -1 means "no index"
int32_t mRequestedIndex; // -1 means "no requested index" int32_t mRequestedIndex; // -1 means "no requested index"
void WindowIndices(int32_t aIndex, int32_t* aOutStartIndex, void WindowIndices(int32_t aIndex, int32_t* aOutStartIndex,
int32_t* aOutEndIndex); int32_t* aOutEndIndex);
// Length of mTransactions. // Length of mEntries.
int32_t Length() { return int32_t(mTransactions.Length()); } int32_t Length() { return int32_t(mEntries.Length()); }
// Session History listeners // Session History listeners
nsAutoTObserverArray<nsWeakPtr, 2> mListeners; nsAutoTObserverArray<nsWeakPtr, 2> mListeners;

Просмотреть файл

@ -49,8 +49,8 @@
let shistory = docShell.QueryInterface(SpecialPowers.Ci.nsIWebNavigation) let shistory = docShell.QueryInterface(SpecialPowers.Ci.nsIWebNavigation)
.sessionHistory; .sessionHistory;
// Now staticFrame has frame0 -> frame1 -> frame2. // Now staticFrame has frame0 -> frame1 -> frame2.
opener.is(docShell.previousTransIndex, 3, 'docShell.previousTransIndex'); opener.is(docShell.previousEntryIndex, 3, 'docShell.previousEntryIndex');
opener.is(docShell.loadedTransIndex, 2, 'docShell.loadedTransIndex'); opener.is(docShell.loadedEntryIndex, 2, 'docShell.loadedEntryIndex');
opener.is(shistory.index, 2, 'shistory.index'); opener.is(shistory.index, 2, 'shistory.index');
opener.is(history.length, 4, 'history.length'); opener.is(history.length, 4, 'history.length');
opener.is(document.getElementById('staticFrame').contentWindow.location.href, BASE_URL + 'frame2.html', 'staticFrame location'); opener.is(document.getElementById('staticFrame').contentWindow.location.href, BASE_URL + 'frame2.html', 'staticFrame location');
@ -109,8 +109,8 @@
.sessionHistory; .sessionHistory;
// staticFrame: frame0 -> frame1 -> frame2 -> iframe_static // staticFrame: frame0 -> frame1 -> frame2 -> iframe_static
// innerStaticFrame: frame0 -> frame1 // innerStaticFrame: frame0 -> frame1
opener.is(docShell.previousTransIndex, 5, 'docShell.previousTransIndex'); opener.is(docShell.previousEntryIndex, 5, 'docShell.previousEntryIndex');
opener.is(docShell.loadedTransIndex, 4, 'docShell.loadedTransIndex'); opener.is(docShell.loadedEntryIndex, 4, 'docShell.loadedEntryIndex');
opener.is(shistory.index, 4, 'shistory.index'); opener.is(shistory.index, 4, 'shistory.index');
opener.is(history.length, 6, 'history.length'); opener.is(history.length, 6, 'history.length');
let staticFrame = document.getElementById('staticFrame'); let staticFrame = document.getElementById('staticFrame');

Просмотреть файл

@ -12,7 +12,7 @@
isOK = true; isOK = true;
} }
document.body.textContent = isOK ? "PASSED" : "FAILED"; document.body.textContent = isOK ? "PASSED" : "FAILED";
opener.ok(isOK, "Duplicate session history transactions should have been removed!"); opener.ok(isOK, "Duplicate session history entries should have been removed!");
opener.nextTest(); opener.nextTest();
window.close(); window.close();
} }

Просмотреть файл

@ -26,7 +26,7 @@ var testFiles =
"file_bug508537_1.html", // Dynamic frames and forward-back "file_bug508537_1.html", // Dynamic frames and forward-back
"file_document_write_1.html", // Session history + document.write "file_document_write_1.html", // Session history + document.write
//"file_static_and_dynamic_1.html",// Static and dynamic frames and forward-back //"file_static_and_dynamic_1.html",// Static and dynamic frames and forward-back
"file_bug534178.html", // Session history transaction clean-up. "file_bug534178.html", // Session history entry clean-up.
"file_fragment_handling_during_load.html", "file_fragment_handling_during_load.html",
"file_nested_frames.html", "file_nested_frames.html",
"file_shiftReload_and_pushState.html", "file_shiftReload_and_pushState.html",

Просмотреть файл

@ -2247,8 +2247,8 @@ nsDocumentViewer::Show(void)
if (history) { if (history) {
int32_t prevIndex,loadedIndex; int32_t prevIndex,loadedIndex;
nsCOMPtr<nsIDocShell> docShell = do_QueryInterface(treeItem); nsCOMPtr<nsIDocShell> docShell = do_QueryInterface(treeItem);
docShell->GetPreviousTransIndex(&prevIndex); docShell->GetPreviousEntryIndex(&prevIndex);
docShell->GetLoadedTransIndex(&loadedIndex); docShell->GetLoadedEntryIndex(&loadedIndex);
#ifdef DEBUG_PAGE_CACHE #ifdef DEBUG_PAGE_CACHE
printf("About to evict content viewers: prev=%d, loaded=%d\n", printf("About to evict content viewers: prev=%d, loaded=%d\n",
prevIndex, loadedIndex); prevIndex, loadedIndex);

Просмотреть файл

@ -84,12 +84,12 @@ var SessionHistoryInternal = {
let shistory = history.legacySHistory.QueryInterface(Ci.nsISHistory); let shistory = history.legacySHistory.QueryInterface(Ci.nsISHistory);
let count = shistory.count; let count = shistory.count;
for ( ; entryCount < count; entryCount++) { for ( ; entryCount < count; entryCount++) {
let txn = shistory.GetTransactionAtIndex(entryCount); let shEntry = shistory.getEntryAtIndex(entryCount);
if (entryCount <= aFromIdx) { if (entryCount <= aFromIdx) {
skippedCount++; skippedCount++;
continue; continue;
} }
let entry = this.serializeEntry(txn); let entry = this.serializeEntry(shEntry);
data.entries.push(entry); data.entries.push(entry);
} }