1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 : *
3 : * ***** BEGIN LICENSE BLOCK *****
4 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 : *
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/
10 : *
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.
15 : *
16 : * The Original Code is the Mozilla browser.
17 : *
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.
22 : *
23 : * Contributor(s):
24 : * Radha Kulkarni <radha@netscape.com>
25 : *
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.
37 : *
38 : * ***** END LICENSE BLOCK ***** */
39 :
40 : #ifndef nsSHistory_h
41 : #define nsSHistory_h
42 :
43 : // Helper Classes
44 : #include "nsCOMPtr.h"
45 :
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 :
57 : // Needed to maintain global list of all SHistory objects
58 : #include "prclist.h"
59 :
60 : class nsIDocShell;
61 : class nsSHEnumerator;
62 : class nsSHistoryObserver;
63 : class nsSHistory: public PRCList,
64 : public nsISHistory,
65 : public nsISHistoryInternal,
66 : public nsIWebNavigation
67 : {
68 : public:
69 : nsSHistory();
70 :
71 : NS_DECL_ISUPPORTS
72 : NS_DECL_NSISHISTORY
73 : NS_DECL_NSISHISTORYINTERNAL
74 : NS_DECL_NSIWEBNAVIGATION
75 :
76 : // One time initialization method called upon docshell module construction
77 : static nsresult Startup();
78 : static void Shutdown();
79 : static void UpdatePrefs();
80 :
81 : // Max number of total cached content viewers. If the pref
82 : // browser.sessionhistory.max_total_viewers is negative, then
83 : // this value is calculated based on the total amount of memory.
84 : // Otherwise, it comes straight from the pref.
85 0 : static PRUint32 GetMaxTotalViewers() { return sHistoryMaxTotalViewers; }
86 :
87 : protected:
88 : virtual ~nsSHistory();
89 : friend class nsSHEnumerator;
90 : friend class nsSHistoryObserver;
91 :
92 : // Could become part of nsIWebNavigation
93 : NS_IMETHOD GetEntryAtIndex(PRInt32 aIndex, bool aModifyIndex, nsISHEntry** aResult);
94 : NS_IMETHOD GetTransactionAtIndex(PRInt32 aIndex, nsISHTransaction ** aResult);
95 : nsresult CompareFrames(nsISHEntry * prevEntry, nsISHEntry * nextEntry, nsIDocShell * rootDocShell, long aLoadType, bool * aIsFrameFound);
96 : nsresult InitiateLoad(nsISHEntry * aFrameEntry, nsIDocShell * aFrameDS, long aLoadType);
97 :
98 : NS_IMETHOD LoadEntry(PRInt32 aIndex, long aLoadType, PRUint32 histCmd);
99 :
100 : #ifdef DEBUG
101 : nsresult PrintHistory();
102 : #endif
103 :
104 : // Evict content viewers in this window which don't lie in the "safe" range
105 : // around aIndex.
106 : void EvictOutOfRangeWindowContentViewers(PRInt32 aIndex);
107 : static void GloballyEvictContentViewers();
108 : static void GloballyEvictAllContentViewers();
109 :
110 : // Calculates a max number of total
111 : // content viewers to cache, based on amount of total memory
112 : static PRUint32 CalcMaxTotalViewers();
113 :
114 : void RemoveDynEntries(PRInt32 aOldIndex, PRInt32 aNewIndex);
115 :
116 : nsresult LoadNextPossibleEntry(PRInt32 aNewIndex, long aLoadType, PRUint32 aHistCmd);
117 : protected:
118 : // aIndex is the index of the transaction which may be removed.
119 : // If aKeepNext is true, aIndex is compared to aIndex + 1,
120 : // otherwise comparison is done to aIndex - 1.
121 : bool RemoveDuplicate(PRInt32 aIndex, bool aKeepNext);
122 :
123 : nsCOMPtr<nsISHTransaction> mListRoot;
124 : PRInt32 mIndex;
125 : PRInt32 mLength;
126 : PRInt32 mRequestedIndex;
127 : // Session History listener
128 : nsWeakPtr mListener;
129 : // Weak reference. Do not refcount this.
130 : nsIDocShell * mRootDocShell;
131 :
132 : // Max viewers allowed total, across all SHistory objects
133 : static PRInt32 sHistoryMaxTotalViewers;
134 : };
135 : //*****************************************************************************
136 : //*** nsSHEnumerator: Object Management
137 : //*****************************************************************************
138 : class nsSHEnumerator : public nsISimpleEnumerator
139 : {
140 : public:
141 :
142 : NS_DECL_ISUPPORTS
143 : NS_DECL_NSISIMPLEENUMERATOR
144 :
145 : nsSHEnumerator(nsSHistory * aHistory);
146 :
147 : protected:
148 : friend class nsSHistory;
149 : virtual ~nsSHEnumerator();
150 : private:
151 : PRInt32 mIndex;
152 : nsSHistory * mSHistory;
153 : };
154 :
155 : #endif /* nsSHistory */
|