summaryrefslogtreecommitdiff
path: root/dom/base/GroupedSHistory.h
blob: 173091a01f2fe2257f1d13d82b2986d91cef368e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef GroupedSHistory_h
#define GroupedSHistory_h

#include "nsCOMArray.h"
#include "nsCycleCollectionParticipant.h" // NS_DECL_CYCLE_*
#include "nsIFrameLoader.h"
#include "nsIGroupedSHistory.h"
#include "nsIPartialSHistory.h"
#include "nsTArray.h"
#include "nsWeakReference.h"

namespace mozilla {
namespace dom {


/**
 * GroupedSHistory connects session histories across multiple frameloaders.
 * Each frameloader has a PartialSHistory, and GroupedSHistory has an array
 * refering to all participating PartialSHistory(s).
 *
 * The following figure illustrates the idea. In this case, the GroupedSHistory
 * is composed of 3 frameloaders, and the active one is frameloader 1.
 * GroupedSHistory is always attached to the active frameloader.
 *
 *            +----------------------------------------------------+
 *            |                                                    |
 *            |                                                    v
 *  +------------------+      +-------------------+       +-----------------+
 *  |  FrameLoader 1   |      | PartialSHistory 1 |       | GroupedSHistory |
 *  |     (active)     |----->|     (active)      |<--+---|                 |
 *  +------------------+      +-------------------+   |   +-----------------+
 *                                                    |
 *  +------------------+      +-------------------+   |
 *  |  FrameLoader 2   |      | PartialSHistory 2 |   |
 *  |    (inactive)    |----->|    (inactive)     |<--+
 *  +------------------+      +-------------------+   |
 *                                                    |
 *  +------------------+      +-------------------+   |
 *  |  FrameLoader 3   |      | PartialSHistory 3 |   |
 *  |    (inactive)    |----->|    (inactive)     |<--+
 *  +------------------+      +-------------------+
 *
 * If a history navigation leads to frameloader 3, it becomes the active one,
 * and GroupedSHistory is re-attached to frameloader 3.
 *
 *  +------------------+      +-------------------+
 *  |  FrameLoader 1   |      | PartialSHistory 1 |
 *  |    (inactive)    |----->|    (inactive)     |<--+
 *  +------------------+      +-------------------+   |
 *                                                    |
 *  +------------------+      +-------------------+   |
 *  |  FrameLoader 2   |      | PartialSHistory 2 |   |
 *  |    (inactive)    |----->|    (inactive)     |<--+
 *  +------------------+      +-------------------+   |
 *                                                    |
 *  +------------------+      +-------------------+   |   +-----------------+
 *  |  FrameLoader 3   |      | PartialSHistory 3 |   |   | GroupedSHistory |
 *  |     (active)     |----->|     (active)      |<--+---|                 |
 *  +------------------+      +-------------------+       +-----------------+
 *            |                                                    ^
 *            |                                                    |
 *            +----------------------------------------------------+
 */
class GroupedSHistory final : public nsIGroupedSHistory
{
public:
  NS_DECL_CYCLE_COLLECTING_ISUPPORTS
  NS_DECL_CYCLE_COLLECTION_CLASS(GroupedSHistory)
  NS_DECL_NSIGROUPEDSHISTORY
  GroupedSHistory();

  /**
   * Get the value of preference "browser.groupedhistory.enabled" to determine
   * if grouped session history should be enabled.
   */
  static bool GroupedHistoryEnabled();

private:
  ~GroupedSHistory() {}

  /**
   * Remove all partial histories and close tabs after the given index (of
   * mPartialHistories, not the index of session history entries).
   */
  void PurgePartialHistories(uint32_t aLastPartialIndexToKeep);

  // The total number of entries in all partial histories.
  uint32_t mCount;

  // The index of currently active partial history in mPartialHistories.
  // Use int32_t as we have invalid index and nsCOMArray also uses int32_t.
  int32_t mIndexOfActivePartialHistory;

  // All participating nsIPartialSHistory objects.
  nsCOMArray<nsIPartialSHistory> mPartialHistories;
};

} // namespace dom
} // namespace mozilla

#endif /* GroupedSHistory_h */