2015-05-08 14:37:00 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
2012-05-21 15:12:37 +04:00
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2005-08-18 15:15:08 +04:00
|
|
|
|
|
|
|
#ifndef nsSHistory_h
|
|
|
|
#define nsSHistory_h
|
|
|
|
|
|
|
|
#include "nsCOMPtr.h"
|
2017-04-27 13:16:46 +03:00
|
|
|
#include "nsExpirationTracker.h"
|
|
|
|
#include "nsIPartialSHistoryListener.h"
|
2005-08-18 15:15:33 +04:00
|
|
|
#include "nsISHistory.h"
|
2005-08-18 15:16:01 +04:00
|
|
|
#include "nsISHistoryInternal.h"
|
|
|
|
#include "nsISimpleEnumerator.h"
|
2017-04-27 13:16:46 +03:00
|
|
|
#include "nsIWebNavigation.h"
|
|
|
|
#include "nsSHEntryShared.h"
|
2012-09-20 18:41:18 +04:00
|
|
|
#include "nsTObserverArray.h"
|
2017-04-27 13:59:11 +03:00
|
|
|
#include "nsWeakReference.h"
|
2005-09-23 22:16:40 +04:00
|
|
|
|
2017-04-19 20:05:00 +03:00
|
|
|
#include "mozilla/LinkedList.h"
|
2017-04-27 13:59:11 +03:00
|
|
|
#include "mozilla/UniquePtr.h"
|
2005-08-18 15:15:08 +04:00
|
|
|
|
2005-08-18 15:15:34 +04:00
|
|
|
class nsIDocShell;
|
2005-08-18 15:16:01 +04:00
|
|
|
class nsSHEnumerator;
|
2005-09-30 00:24:27 +04:00
|
|
|
class nsSHistoryObserver;
|
2013-09-04 19:26:20 +04:00
|
|
|
class nsISHEntry;
|
|
|
|
class nsISHTransaction;
|
|
|
|
|
2017-04-19 20:05:00 +03:00
|
|
|
class nsSHistory final : public mozilla::LinkedListElement<nsSHistory>,
|
2015-03-27 21:52:19 +03:00
|
|
|
public nsISHistory,
|
|
|
|
public nsISHistoryInternal,
|
2017-04-27 13:59:11 +03:00
|
|
|
public nsIWebNavigation,
|
|
|
|
public nsSupportsWeakReference
|
2005-08-18 15:15:08 +04:00
|
|
|
{
|
|
|
|
public:
|
2017-04-27 13:59:11 +03:00
|
|
|
|
|
|
|
// The timer based history tracker is used to evict bfcache on expiration.
|
|
|
|
class HistoryTracker final : public nsExpirationTracker<nsSHEntryShared, 3>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit HistoryTracker(nsSHistory* aSHistory,
|
|
|
|
uint32_t aTimeout,
|
|
|
|
nsIEventTarget* aEventTarget)
|
|
|
|
: nsExpirationTracker(1000 * aTimeout / 2, "HistoryTracker", aEventTarget)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aSHistory);
|
|
|
|
mSHistory = aSHistory;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual void NotifyExpired(nsSHEntryShared* aObj)
|
|
|
|
{
|
|
|
|
RemoveObject(aObj);
|
|
|
|
mSHistory->EvictExpiredContentViewerForEntry(aObj);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
// HistoryTracker is owned by nsSHistory; it always outlives HistoryTracker
|
|
|
|
// so it's safe to use raw pointer here.
|
|
|
|
nsSHistory* mSHistory;
|
|
|
|
};
|
|
|
|
|
2009-09-01 20:45:05 +04:00
|
|
|
nsSHistory();
|
2005-08-18 15:16:01 +04:00
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSISHISTORY
|
|
|
|
NS_DECL_NSISHISTORYINTERNAL
|
|
|
|
NS_DECL_NSIWEBNAVIGATION
|
2005-08-18 15:15:08 +04:00
|
|
|
|
2005-09-23 22:16:40 +04:00
|
|
|
// One time initialization method called upon docshell module construction
|
|
|
|
static nsresult Startup();
|
2011-06-25 05:55:46 +04:00
|
|
|
static void Shutdown();
|
|
|
|
static void UpdatePrefs();
|
2005-09-23 22:16:40 +04:00
|
|
|
|
2005-10-02 00:38:47 +04:00
|
|
|
// Max number of total cached content viewers. If the pref
|
|
|
|
// browser.sessionhistory.max_total_viewers is negative, then
|
|
|
|
// this value is calculated based on the total amount of memory.
|
|
|
|
// Otherwise, it comes straight from the pref.
|
2012-08-22 19:56:38 +04:00
|
|
|
static uint32_t GetMaxTotalViewers() { return sHistoryMaxTotalViewers; }
|
2005-08-18 15:15:59 +04:00
|
|
|
|
2016-10-14 10:18:29 +03:00
|
|
|
private:
|
2005-08-18 15:16:01 +04:00
|
|
|
virtual ~nsSHistory();
|
|
|
|
friend class nsSHEnumerator;
|
2005-09-30 00:24:27 +04:00
|
|
|
friend class nsSHistoryObserver;
|
2005-08-18 15:15:59 +04:00
|
|
|
|
2017-08-24 06:27:11 +03:00
|
|
|
nsresult GetTransactionAtIndex(int32_t aIndex, nsISHTransaction** aResult);
|
2016-10-20 12:33:22 +03:00
|
|
|
nsresult LoadDifferingEntries(nsISHEntry* aPrevEntry, nsISHEntry* aNextEntry,
|
|
|
|
nsIDocShell* aRootDocShell, long aLoadType,
|
|
|
|
bool& aDifferenceFound);
|
2015-05-06 20:57:23 +03:00
|
|
|
nsresult InitiateLoad(nsISHEntry* aFrameEntry, nsIDocShell* aFrameDS,
|
|
|
|
long aLoadType);
|
2005-08-18 15:16:33 +04:00
|
|
|
|
2017-08-24 06:27:11 +03:00
|
|
|
nsresult LoadEntry(int32_t aIndex, long aLoadType, uint32_t aHistCmd);
|
2009-09-01 20:45:05 +04:00
|
|
|
|
2005-08-18 15:16:52 +04:00
|
|
|
#ifdef DEBUG
|
2015-05-06 20:57:23 +03:00
|
|
|
nsresult PrintHistory();
|
2005-08-18 15:16:52 +04:00
|
|
|
#endif
|
|
|
|
|
2011-10-21 19:26:34 +04:00
|
|
|
// Evict content viewers in this window which don't lie in the "safe" range
|
|
|
|
// around aIndex.
|
2012-08-22 19:56:38 +04:00
|
|
|
void EvictOutOfRangeWindowContentViewers(int32_t aIndex);
|
2017-01-24 09:56:37 +03:00
|
|
|
void EvictContentViewerForTransaction(nsISHTransaction* aTrans);
|
2011-10-21 19:26:34 +04:00
|
|
|
static void GloballyEvictContentViewers();
|
|
|
|
static void GloballyEvictAllContentViewers();
|
2005-08-18 15:17:00 +04:00
|
|
|
|
2005-10-02 00:38:47 +04:00
|
|
|
// Calculates a max number of total
|
|
|
|
// content viewers to cache, based on amount of total memory
|
2012-08-22 19:56:38 +04:00
|
|
|
static uint32_t CalcMaxTotalViewers();
|
2005-10-02 00:38:47 +04:00
|
|
|
|
2015-05-06 20:57:23 +03:00
|
|
|
nsresult LoadNextPossibleEntry(int32_t aNewIndex, long aLoadType,
|
|
|
|
uint32_t aHistCmd);
|
|
|
|
|
2010-11-15 13:11:51 +03:00
|
|
|
// aIndex is the index of the transaction which may be removed.
|
2011-10-17 18:59:28 +04:00
|
|
|
// If aKeepNext is true, aIndex is compared to aIndex + 1,
|
2010-11-15 13:11:51 +03:00
|
|
|
// otherwise comparison is done to aIndex - 1.
|
2012-08-22 19:56:38 +04:00
|
|
|
bool RemoveDuplicate(int32_t aIndex, bool aKeepNext);
|
2010-09-05 22:10:35 +04:00
|
|
|
|
2017-04-27 13:59:11 +03:00
|
|
|
// Track all bfcache entries and evict on expiration.
|
|
|
|
mozilla::UniquePtr<HistoryTracker> mHistoryTracker;
|
|
|
|
|
2005-08-18 15:15:59 +04:00
|
|
|
nsCOMPtr<nsISHTransaction> mListRoot;
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t mIndex;
|
|
|
|
int32_t mLength;
|
|
|
|
int32_t mRequestedIndex;
|
2016-10-14 10:18:29 +03:00
|
|
|
|
|
|
|
// The number of entries before this session history object.
|
|
|
|
int32_t mGlobalIndexOffset;
|
|
|
|
|
|
|
|
// The number of entries after this session history object.
|
|
|
|
int32_t mEntriesInFollowingPartialHistories;
|
|
|
|
|
2012-09-20 18:41:18 +04:00
|
|
|
// Session History listeners
|
|
|
|
nsAutoTObserverArray<nsWeakPtr, 2> mListeners;
|
2016-10-14 10:18:29 +03:00
|
|
|
|
|
|
|
// Partial session history listener
|
|
|
|
nsWeakPtr mPartialHistoryListener;
|
|
|
|
|
2005-08-18 15:15:59 +04:00
|
|
|
// Weak reference. Do not refcount this.
|
2015-05-06 20:57:23 +03:00
|
|
|
nsIDocShell* mRootDocShell;
|
2005-09-23 22:16:40 +04:00
|
|
|
|
2017-04-27 13:16:46 +03:00
|
|
|
// Set to true if attached to a grouped session history.
|
|
|
|
bool mIsPartial;
|
|
|
|
|
2005-09-23 22:16:40 +04:00
|
|
|
// Max viewers allowed total, across all SHistory objects
|
2015-05-06 20:57:23 +03:00
|
|
|
static int32_t sHistoryMaxTotalViewers;
|
2005-08-18 15:15:08 +04:00
|
|
|
};
|
2015-05-06 20:57:23 +03:00
|
|
|
|
2005-08-18 15:16:01 +04:00
|
|
|
class nsSHEnumerator : public nsISimpleEnumerator
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSISIMPLEENUMERATOR
|
|
|
|
|
2015-05-06 20:57:23 +03:00
|
|
|
explicit nsSHEnumerator(nsSHistory* aHistory);
|
|
|
|
|
2005-08-18 15:16:01 +04:00
|
|
|
protected:
|
|
|
|
friend class nsSHistory;
|
|
|
|
virtual ~nsSHEnumerator();
|
2015-05-06 20:57:23 +03:00
|
|
|
|
2005-08-18 15:16:01 +04:00
|
|
|
private:
|
2015-05-06 20:57:23 +03:00
|
|
|
int32_t mIndex;
|
|
|
|
nsSHistory* mSHistory;
|
2005-08-18 15:16:01 +04:00
|
|
|
};
|
|
|
|
|
2015-05-06 20:57:23 +03:00
|
|
|
#endif /* nsSHistory */
|