CLOSED TREE: TraceMonkey merge head. (a=blockers)
[mozilla-central.git] / docshell / shistory / src / nsSHistory.h
blobf6b696a474c5c13ea8d76a8a24f812ea0fad33ce
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
3 * ***** BEGIN LICENSE BLOCK *****
4 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
6 * The contents of this file are subject to the Mozilla Public License Version
7 * 1.1 (the "License"); you may not use this file except in compliance with
8 * the License. You may obtain a copy of the License at
9 * http://www.mozilla.org/MPL/
11 * Software distributed under the License is distributed on an "AS IS" basis,
12 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 * for the specific language governing rights and limitations under the
14 * License.
16 * The Original Code is the Mozilla browser.
18 * The Initial Developer of the Original Code is
19 * Netscape Communications, Inc.
20 * Portions created by the Initial Developer are Copyright (C) 1999
21 * the Initial Developer. All Rights Reserved.
23 * Contributor(s):
24 * Radha Kulkarni <radha@netscape.com>
26 * Alternatively, the contents of this file may be used under the terms of
27 * either of the GNU General Public License Version 2 or later (the "GPL"),
28 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 * in which case the provisions of the GPL or the LGPL are applicable instead
30 * of those above. If you wish to allow use of your version of this file only
31 * under the terms of either the GPL or the LGPL, and not to allow others to
32 * use your version of this file under the terms of the MPL, indicate your
33 * decision by deleting the provisions above and replace them with the notice
34 * and other provisions required by the GPL or the LGPL. If you do not delete
35 * the provisions above, a recipient may use your version of this file under
36 * the terms of any one of the MPL, the GPL or the LGPL.
38 * ***** END LICENSE BLOCK ***** */
40 #ifndef nsSHistory_h
41 #define nsSHistory_h
43 // Helper Classes
44 #include "nsCOMPtr.h"
46 //Interfaces Needed
47 #include "nsISHistory.h"
48 #include "nsISHistoryInternal.h"
49 #include "nsISHTransaction.h"
50 #include "nsIWebNavigation.h"
51 #include "nsIWeakReference.h"
52 #include "nsISimpleEnumerator.h"
53 #include "nsISHistoryListener.h"
54 #include "nsIHistoryEntry.h"
55 #include "nsIObserver.h"
56 #include "nsIPrefBranch2.h"
58 // Needed to maintain global list of all SHistory objects
59 #include "prclist.h"
61 class nsIDocShell;
62 class nsSHEnumerator;
63 class nsSHistoryObserver;
64 class nsSHistory: public PRCList,
65 public nsISHistory_2_0_BRANCH,
66 public nsISHistoryInternal,
67 public nsIWebNavigation
69 public:
70 nsSHistory();
72 NS_DECL_ISUPPORTS
73 NS_DECL_NSISHISTORY
74 NS_DECL_NSISHISTORYINTERNAL
75 NS_DECL_NSIWEBNAVIGATION
76 NS_DECL_NSISHISTORY_2_0_BRANCH
78 // One time initialization method called upon docshell module construction
79 static nsresult Startup();
80 static void UpdatePrefs(nsIPrefBranch *aPrefBranch);
82 // Max number of total cached content viewers. If the pref
83 // browser.sessionhistory.max_total_viewers is negative, then
84 // this value is calculated based on the total amount of memory.
85 // Otherwise, it comes straight from the pref.
86 static PRUint32 GetMaxTotalViewers() { return sHistoryMaxTotalViewers; }
88 protected:
89 virtual ~nsSHistory();
90 friend class nsSHEnumerator;
91 friend class nsSHistoryObserver;
93 // Could become part of nsIWebNavigation
94 NS_IMETHOD GetEntryAtIndex(PRInt32 aIndex, PRBool aModifyIndex, nsISHEntry** aResult);
95 NS_IMETHOD GetTransactionAtIndex(PRInt32 aIndex, nsISHTransaction ** aResult);
96 nsresult CompareFrames(nsISHEntry * prevEntry, nsISHEntry * nextEntry, nsIDocShell * rootDocShell, long aLoadType, PRBool * aIsFrameFound);
97 nsresult InitiateLoad(nsISHEntry * aFrameEntry, nsIDocShell * aFrameDS, long aLoadType);
99 NS_IMETHOD LoadEntry(PRInt32 aIndex, long aLoadType, PRUint32 histCmd);
101 #ifdef DEBUG
102 nsresult PrintHistory();
103 #endif
105 // Evict the viewers at indices between aStartIndex and aEndIndex,
106 // including aStartIndex but not aEndIndex.
107 void EvictContentViewersInRange(PRInt32 aStartIndex, PRInt32 aEndIndex);
108 void EvictWindowContentViewers(PRInt32 aFromIndex, PRInt32 aToIndex);
109 static void EvictGlobalContentViewer();
110 static void EvictAllContentViewersGlobally();
112 // Calculates a max number of total
113 // content viewers to cache, based on amount of total memory
114 static PRUint32 CalcMaxTotalViewers();
116 void RemoveDynEntries(PRInt32 aOldIndex, PRInt32 aNewIndex);
118 nsresult LoadNextPossibleEntry(PRInt32 aNewIndex, long aLoadType, PRUint32 aHistCmd);
119 protected:
120 // aIndex is the index of the transaction which may be removed.
121 // If aKeepNext is PR_TRUE, aIndex is compared to aIndex + 1,
122 // otherwise comparison is done to aIndex - 1.
123 PRBool RemoveDuplicate(PRInt32 aIndex, PRBool aKeepNext);
125 nsCOMPtr<nsISHTransaction> mListRoot;
126 PRInt32 mIndex;
127 PRInt32 mLength;
128 PRInt32 mRequestedIndex;
129 // Session History listener
130 nsWeakPtr mListener;
131 // Weak reference. Do not refcount this.
132 nsIDocShell * mRootDocShell;
134 // Max viewers allowed total, across all SHistory objects
135 static PRInt32 sHistoryMaxTotalViewers;
137 //*****************************************************************************
138 //*** nsSHEnumerator: Object Management
139 //*****************************************************************************
140 class nsSHEnumerator : public nsISimpleEnumerator
142 public:
144 NS_DECL_ISUPPORTS
145 NS_DECL_NSISIMPLEENUMERATOR
147 nsSHEnumerator(nsSHistory * aHistory);
149 protected:
150 friend class nsSHistory;
151 virtual ~nsSHEnumerator();
152 private:
153 PRInt32 mIndex;
154 nsSHistory * mSHistory;
157 #endif /* nsSHistory */