1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
14 #include "nsISHistory.h"
15 #include "nsISHistoryInternal.h"
16 #include "nsIWebNavigation.h"
17 #include "nsISimpleEnumerator.h"
18 #include "nsTObserverArray.h"
19 #include "nsWeakPtr.h"
21 // Needed to maintain global list of all SHistory objects
26 class nsSHistoryObserver
;
28 class nsISHTransaction
;
30 class nsSHistory
: public PRCList
,
32 public nsISHistoryInternal
,
33 public nsIWebNavigation
40 NS_DECL_NSISHISTORYINTERNAL
41 NS_DECL_NSIWEBNAVIGATION
43 // One time initialization method called upon docshell module construction
44 static nsresult
Startup();
45 static void Shutdown();
46 static void UpdatePrefs();
48 // Max number of total cached content viewers. If the pref
49 // browser.sessionhistory.max_total_viewers is negative, then
50 // this value is calculated based on the total amount of memory.
51 // Otherwise, it comes straight from the pref.
52 static uint32_t GetMaxTotalViewers() { return sHistoryMaxTotalViewers
; }
55 virtual ~nsSHistory();
56 friend class nsSHEnumerator
;
57 friend class nsSHistoryObserver
;
59 // Could become part of nsIWebNavigation
60 NS_IMETHOD
GetTransactionAtIndex(int32_t aIndex
, nsISHTransaction
** aResult
);
61 nsresult
CompareFrames(nsISHEntry
* prevEntry
, nsISHEntry
* nextEntry
, nsIDocShell
* rootDocShell
, long aLoadType
, bool * aIsFrameFound
);
62 nsresult
InitiateLoad(nsISHEntry
* aFrameEntry
, nsIDocShell
* aFrameDS
, long aLoadType
);
64 NS_IMETHOD
LoadEntry(int32_t aIndex
, long aLoadType
, uint32_t histCmd
);
67 nsresult
PrintHistory();
70 // Evict content viewers in this window which don't lie in the "safe" range
72 void EvictOutOfRangeWindowContentViewers(int32_t aIndex
);
73 static void GloballyEvictContentViewers();
74 static void GloballyEvictAllContentViewers();
76 // Calculates a max number of total
77 // content viewers to cache, based on amount of total memory
78 static uint32_t CalcMaxTotalViewers();
80 void RemoveDynEntries(int32_t aOldIndex
, int32_t aNewIndex
);
82 nsresult
LoadNextPossibleEntry(int32_t aNewIndex
, long aLoadType
, uint32_t aHistCmd
);
84 // aIndex is the index of the transaction which may be removed.
85 // If aKeepNext is true, aIndex is compared to aIndex + 1,
86 // otherwise comparison is done to aIndex - 1.
87 bool RemoveDuplicate(int32_t aIndex
, bool aKeepNext
);
89 nsCOMPtr
<nsISHTransaction
> mListRoot
;
92 int32_t mRequestedIndex
;
93 // Session History listeners
94 nsAutoTObserverArray
<nsWeakPtr
, 2> mListeners
;
95 // Weak reference. Do not refcount this.
96 nsIDocShell
* mRootDocShell
;
98 // Max viewers allowed total, across all SHistory objects
99 static int32_t sHistoryMaxTotalViewers
;
101 //*****************************************************************************
102 //*** nsSHEnumerator: Object Management
103 //*****************************************************************************
104 class nsSHEnumerator
: public nsISimpleEnumerator
109 NS_DECL_NSISIMPLEENUMERATOR
111 nsSHEnumerator(nsSHistory
* aHistory
);
114 friend class nsSHistory
;
115 virtual ~nsSHEnumerator();
118 nsSHistory
* mSHistory
;
121 #endif /* nsSHistory */