michael@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- michael@0: * michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef nsSHistory_h michael@0: #define nsSHistory_h michael@0: michael@0: // Helper Classes michael@0: #include "nsCOMPtr.h" michael@0: michael@0: //Interfaces Needed michael@0: #include "nsISHistory.h" michael@0: #include "nsISHistoryInternal.h" michael@0: #include "nsIWebNavigation.h" michael@0: #include "nsISimpleEnumerator.h" michael@0: #include "nsTObserverArray.h" michael@0: #include "nsWeakPtr.h" michael@0: michael@0: // Needed to maintain global list of all SHistory objects michael@0: #include "prclist.h" michael@0: michael@0: class nsIDocShell; michael@0: class nsSHEnumerator; michael@0: class nsSHistoryObserver; michael@0: class nsISHEntry; michael@0: class nsISHTransaction; michael@0: michael@0: class nsSHistory: public PRCList, michael@0: public nsISHistory, michael@0: public nsISHistoryInternal, michael@0: public nsIWebNavigation michael@0: { michael@0: public: michael@0: nsSHistory(); michael@0: michael@0: NS_DECL_ISUPPORTS michael@0: NS_DECL_NSISHISTORY michael@0: NS_DECL_NSISHISTORYINTERNAL michael@0: NS_DECL_NSIWEBNAVIGATION michael@0: michael@0: // One time initialization method called upon docshell module construction michael@0: static nsresult Startup(); michael@0: static void Shutdown(); michael@0: static void UpdatePrefs(); michael@0: michael@0: // Max number of total cached content viewers. If the pref michael@0: // browser.sessionhistory.max_total_viewers is negative, then michael@0: // this value is calculated based on the total amount of memory. michael@0: // Otherwise, it comes straight from the pref. michael@0: static uint32_t GetMaxTotalViewers() { return sHistoryMaxTotalViewers; } michael@0: michael@0: protected: michael@0: virtual ~nsSHistory(); michael@0: friend class nsSHEnumerator; michael@0: friend class nsSHistoryObserver; michael@0: michael@0: // Could become part of nsIWebNavigation michael@0: NS_IMETHOD GetTransactionAtIndex(int32_t aIndex, nsISHTransaction ** aResult); michael@0: nsresult CompareFrames(nsISHEntry * prevEntry, nsISHEntry * nextEntry, nsIDocShell * rootDocShell, long aLoadType, bool * aIsFrameFound); michael@0: nsresult InitiateLoad(nsISHEntry * aFrameEntry, nsIDocShell * aFrameDS, long aLoadType); michael@0: michael@0: NS_IMETHOD LoadEntry(int32_t aIndex, long aLoadType, uint32_t histCmd); michael@0: michael@0: #ifdef DEBUG michael@0: nsresult PrintHistory(); michael@0: #endif michael@0: michael@0: // Evict content viewers in this window which don't lie in the "safe" range michael@0: // around aIndex. michael@0: void EvictOutOfRangeWindowContentViewers(int32_t aIndex); michael@0: static void GloballyEvictContentViewers(); michael@0: static void GloballyEvictAllContentViewers(); michael@0: michael@0: // Calculates a max number of total michael@0: // content viewers to cache, based on amount of total memory michael@0: static uint32_t CalcMaxTotalViewers(); michael@0: michael@0: void RemoveDynEntries(int32_t aOldIndex, int32_t aNewIndex); michael@0: michael@0: nsresult LoadNextPossibleEntry(int32_t aNewIndex, long aLoadType, uint32_t aHistCmd); michael@0: protected: michael@0: // aIndex is the index of the transaction which may be removed. michael@0: // If aKeepNext is true, aIndex is compared to aIndex + 1, michael@0: // otherwise comparison is done to aIndex - 1. michael@0: bool RemoveDuplicate(int32_t aIndex, bool aKeepNext); michael@0: michael@0: nsCOMPtr mListRoot; michael@0: int32_t mIndex; michael@0: int32_t mLength; michael@0: int32_t mRequestedIndex; michael@0: // Session History listeners michael@0: nsAutoTObserverArray mListeners; michael@0: // Weak reference. Do not refcount this. michael@0: nsIDocShell * mRootDocShell; michael@0: michael@0: // Max viewers allowed total, across all SHistory objects michael@0: static int32_t sHistoryMaxTotalViewers; michael@0: }; michael@0: //***************************************************************************** michael@0: //*** nsSHEnumerator: Object Management michael@0: //***************************************************************************** michael@0: class nsSHEnumerator : public nsISimpleEnumerator michael@0: { michael@0: public: michael@0: michael@0: NS_DECL_ISUPPORTS michael@0: NS_DECL_NSISIMPLEENUMERATOR michael@0: michael@0: nsSHEnumerator(nsSHistory * aHistory); michael@0: michael@0: protected: michael@0: friend class nsSHistory; michael@0: virtual ~nsSHEnumerator(); michael@0: private: michael@0: int32_t mIndex; michael@0: nsSHistory * mSHistory; michael@0: }; michael@0: michael@0: #endif /* nsSHistory */