docshell/shistory/src/nsSHistory.h

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

     1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
     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/. */
     7 #ifndef nsSHistory_h
     8 #define nsSHistory_h
    10 // Helper Classes
    11 #include "nsCOMPtr.h"
    13 //Interfaces Needed
    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
    22 #include "prclist.h"
    24 class nsIDocShell;
    25 class nsSHEnumerator;
    26 class nsSHistoryObserver;
    27 class nsISHEntry;
    28 class nsISHTransaction;
    30 class nsSHistory: public PRCList,
    31                   public nsISHistory,
    32                   public nsISHistoryInternal,
    33                   public nsIWebNavigation
    34 {
    35 public:
    36   nsSHistory();
    38   NS_DECL_ISUPPORTS
    39   NS_DECL_NSISHISTORY
    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; }
    54 protected:
    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);
    66 #ifdef DEBUG
    67    nsresult PrintHistory();
    68 #endif
    70   // Evict content viewers in this window which don't lie in the "safe" range
    71   // around aIndex.
    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);
    83 protected:
    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;
    90   int32_t mIndex;
    91   int32_t mLength;
    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;
   100 };
   101 //*****************************************************************************
   102 //***    nsSHEnumerator: Object Management
   103 //*****************************************************************************
   104 class nsSHEnumerator : public nsISimpleEnumerator
   105 {
   106 public:
   108   NS_DECL_ISUPPORTS
   109   NS_DECL_NSISIMPLEENUMERATOR
   111   nsSHEnumerator(nsSHistory *  aHistory);
   113 protected:
   114   friend class nsSHistory;
   115   virtual ~nsSHEnumerator();
   116 private:
   117   int32_t     mIndex;
   118   nsSHistory *  mSHistory;  
   119 };
   121 #endif   /* nsSHistory */

mercurial