nsSHistory.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. #ifndef nsSHistory_h
  6. #define nsSHistory_h
  7. #include "nsCOMPtr.h"
  8. #include "nsISHistory.h"
  9. #include "nsISHistoryInternal.h"
  10. #include "nsIWebNavigation.h"
  11. #include "nsISimpleEnumerator.h"
  12. #include "nsTObserverArray.h"
  13. #include "nsWeakPtr.h"
  14. #include "nsIPartialSHistoryListener.h"
  15. #include "prclist.h"
  16. class nsIDocShell;
  17. class nsSHEnumerator;
  18. class nsSHistoryObserver;
  19. class nsISHEntry;
  20. class nsISHTransaction;
  21. class nsSHistory final : public PRCList,
  22. public nsISHistory,
  23. public nsISHistoryInternal,
  24. public nsIWebNavigation
  25. {
  26. public:
  27. nsSHistory();
  28. NS_DECL_ISUPPORTS
  29. NS_DECL_NSISHISTORY
  30. NS_DECL_NSISHISTORYINTERNAL
  31. NS_DECL_NSIWEBNAVIGATION
  32. // One time initialization method called upon docshell module construction
  33. static nsresult Startup();
  34. static void Shutdown();
  35. static void UpdatePrefs();
  36. // Max number of total cached content viewers. If the pref
  37. // browser.sessionhistory.max_total_viewers is negative, then
  38. // this value is calculated based on the total amount of memory.
  39. // Otherwise, it comes straight from the pref.
  40. static uint32_t GetMaxTotalViewers() { return sHistoryMaxTotalViewers; }
  41. private:
  42. virtual ~nsSHistory();
  43. friend class nsSHEnumerator;
  44. friend class nsSHistoryObserver;
  45. // Could become part of nsIWebNavigation
  46. NS_IMETHOD GetTransactionAtIndex(int32_t aIndex, nsISHTransaction** aResult);
  47. nsresult LoadDifferingEntries(nsISHEntry* aPrevEntry, nsISHEntry* aNextEntry,
  48. nsIDocShell* aRootDocShell, long aLoadType,
  49. bool& aDifferenceFound);
  50. nsresult InitiateLoad(nsISHEntry* aFrameEntry, nsIDocShell* aFrameDS,
  51. long aLoadType);
  52. NS_IMETHOD LoadEntry(int32_t aIndex, long aLoadType, uint32_t aHistCmd);
  53. #ifdef DEBUG
  54. nsresult PrintHistory();
  55. #endif
  56. // Evict content viewers in this window which don't lie in the "safe" range
  57. // around aIndex.
  58. void EvictOutOfRangeWindowContentViewers(int32_t aIndex);
  59. static void GloballyEvictContentViewers();
  60. static void GloballyEvictAllContentViewers();
  61. // Calculates a max number of total
  62. // content viewers to cache, based on amount of total memory
  63. static uint32_t CalcMaxTotalViewers();
  64. void RemoveDynEntries(int32_t aOldIndex, int32_t aNewIndex);
  65. nsresult LoadNextPossibleEntry(int32_t aNewIndex, long aLoadType,
  66. uint32_t aHistCmd);
  67. // aIndex is the index of the transaction which may be removed.
  68. // If aKeepNext is true, aIndex is compared to aIndex + 1,
  69. // otherwise comparison is done to aIndex - 1.
  70. bool RemoveDuplicate(int32_t aIndex, bool aKeepNext);
  71. nsCOMPtr<nsISHTransaction> mListRoot;
  72. int32_t mIndex;
  73. int32_t mLength;
  74. int32_t mRequestedIndex;
  75. // Set to true if attached to a grouped session history.
  76. bool mIsPartial;
  77. // The number of entries before this session history object.
  78. int32_t mGlobalIndexOffset;
  79. // The number of entries after this session history object.
  80. int32_t mEntriesInFollowingPartialHistories;
  81. // Session History listeners
  82. nsAutoTObserverArray<nsWeakPtr, 2> mListeners;
  83. // Partial session history listener
  84. nsWeakPtr mPartialHistoryListener;
  85. // Weak reference. Do not refcount this.
  86. nsIDocShell* mRootDocShell;
  87. // Max viewers allowed total, across all SHistory objects
  88. static int32_t sHistoryMaxTotalViewers;
  89. };
  90. class nsSHEnumerator : public nsISimpleEnumerator
  91. {
  92. public:
  93. NS_DECL_ISUPPORTS
  94. NS_DECL_NSISIMPLEENUMERATOR
  95. explicit nsSHEnumerator(nsSHistory* aHistory);
  96. protected:
  97. friend class nsSHistory;
  98. virtual ~nsSHEnumerator();
  99. private:
  100. int32_t mIndex;
  101. nsSHistory* mSHistory;
  102. };
  103. #endif /* nsSHistory */