1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/docshell/shistory/src/nsSHistory.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,121 @@ 1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- 1.5 + * 1.6 + * This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +#ifndef nsSHistory_h 1.11 +#define nsSHistory_h 1.12 + 1.13 +// Helper Classes 1.14 +#include "nsCOMPtr.h" 1.15 + 1.16 +//Interfaces Needed 1.17 +#include "nsISHistory.h" 1.18 +#include "nsISHistoryInternal.h" 1.19 +#include "nsIWebNavigation.h" 1.20 +#include "nsISimpleEnumerator.h" 1.21 +#include "nsTObserverArray.h" 1.22 +#include "nsWeakPtr.h" 1.23 + 1.24 +// Needed to maintain global list of all SHistory objects 1.25 +#include "prclist.h" 1.26 + 1.27 +class nsIDocShell; 1.28 +class nsSHEnumerator; 1.29 +class nsSHistoryObserver; 1.30 +class nsISHEntry; 1.31 +class nsISHTransaction; 1.32 + 1.33 +class nsSHistory: public PRCList, 1.34 + public nsISHistory, 1.35 + public nsISHistoryInternal, 1.36 + public nsIWebNavigation 1.37 +{ 1.38 +public: 1.39 + nsSHistory(); 1.40 + 1.41 + NS_DECL_ISUPPORTS 1.42 + NS_DECL_NSISHISTORY 1.43 + NS_DECL_NSISHISTORYINTERNAL 1.44 + NS_DECL_NSIWEBNAVIGATION 1.45 + 1.46 + // One time initialization method called upon docshell module construction 1.47 + static nsresult Startup(); 1.48 + static void Shutdown(); 1.49 + static void UpdatePrefs(); 1.50 + 1.51 + // Max number of total cached content viewers. If the pref 1.52 + // browser.sessionhistory.max_total_viewers is negative, then 1.53 + // this value is calculated based on the total amount of memory. 1.54 + // Otherwise, it comes straight from the pref. 1.55 + static uint32_t GetMaxTotalViewers() { return sHistoryMaxTotalViewers; } 1.56 + 1.57 +protected: 1.58 + virtual ~nsSHistory(); 1.59 + friend class nsSHEnumerator; 1.60 + friend class nsSHistoryObserver; 1.61 + 1.62 + // Could become part of nsIWebNavigation 1.63 + NS_IMETHOD GetTransactionAtIndex(int32_t aIndex, nsISHTransaction ** aResult); 1.64 + nsresult CompareFrames(nsISHEntry * prevEntry, nsISHEntry * nextEntry, nsIDocShell * rootDocShell, long aLoadType, bool * aIsFrameFound); 1.65 + nsresult InitiateLoad(nsISHEntry * aFrameEntry, nsIDocShell * aFrameDS, long aLoadType); 1.66 + 1.67 + NS_IMETHOD LoadEntry(int32_t aIndex, long aLoadType, uint32_t histCmd); 1.68 + 1.69 +#ifdef DEBUG 1.70 + nsresult PrintHistory(); 1.71 +#endif 1.72 + 1.73 + // Evict content viewers in this window which don't lie in the "safe" range 1.74 + // around aIndex. 1.75 + void EvictOutOfRangeWindowContentViewers(int32_t aIndex); 1.76 + static void GloballyEvictContentViewers(); 1.77 + static void GloballyEvictAllContentViewers(); 1.78 + 1.79 + // Calculates a max number of total 1.80 + // content viewers to cache, based on amount of total memory 1.81 + static uint32_t CalcMaxTotalViewers(); 1.82 + 1.83 + void RemoveDynEntries(int32_t aOldIndex, int32_t aNewIndex); 1.84 + 1.85 + nsresult LoadNextPossibleEntry(int32_t aNewIndex, long aLoadType, uint32_t aHistCmd); 1.86 +protected: 1.87 + // aIndex is the index of the transaction which may be removed. 1.88 + // If aKeepNext is true, aIndex is compared to aIndex + 1, 1.89 + // otherwise comparison is done to aIndex - 1. 1.90 + bool RemoveDuplicate(int32_t aIndex, bool aKeepNext); 1.91 + 1.92 + nsCOMPtr<nsISHTransaction> mListRoot; 1.93 + int32_t mIndex; 1.94 + int32_t mLength; 1.95 + int32_t mRequestedIndex; 1.96 + // Session History listeners 1.97 + nsAutoTObserverArray<nsWeakPtr, 2> mListeners; 1.98 + // Weak reference. Do not refcount this. 1.99 + nsIDocShell * mRootDocShell; 1.100 + 1.101 + // Max viewers allowed total, across all SHistory objects 1.102 + static int32_t sHistoryMaxTotalViewers; 1.103 +}; 1.104 +//***************************************************************************** 1.105 +//*** nsSHEnumerator: Object Management 1.106 +//***************************************************************************** 1.107 +class nsSHEnumerator : public nsISimpleEnumerator 1.108 +{ 1.109 +public: 1.110 + 1.111 + NS_DECL_ISUPPORTS 1.112 + NS_DECL_NSISIMPLEENUMERATOR 1.113 + 1.114 + nsSHEnumerator(nsSHistory * aHistory); 1.115 + 1.116 +protected: 1.117 + friend class nsSHistory; 1.118 + virtual ~nsSHEnumerator(); 1.119 +private: 1.120 + int32_t mIndex; 1.121 + nsSHistory * mSHistory; 1.122 +}; 1.123 + 1.124 +#endif /* nsSHistory */