Line data Source code
1 : /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* vim: set ts=8 sts=2 et sw=2 tw=80: */
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/. */
6 :
7 : #ifndef GroupedSHistory_h
8 : #define GroupedSHistory_h
9 :
10 : #include "nsIFrameLoader.h"
11 : #include "nsIGroupedSHistory.h"
12 : #include "nsIPartialSHistory.h"
13 : #include "nsTArray.h"
14 : #include "nsCOMArray.h"
15 : #include "nsCOMPtr.h"
16 : #include "nsCycleCollectionParticipant.h"
17 : #include "nsWeakReference.h"
18 :
19 : namespace mozilla {
20 : namespace dom {
21 :
22 :
23 : /**
24 : * GroupedSHistory connects session histories across multiple frameloaders.
25 : * Each frameloader has a PartialSHistory, and GroupedSHistory has an array
26 : * refering to all participating PartialSHistory(s).
27 : *
28 : * The following figure illustrates the idea. In this case, the GroupedSHistory
29 : * is composed of 3 frameloaders, and the active one is frameloader 1.
30 : * GroupedSHistory is always attached to the active frameloader.
31 : *
32 : * +----------------------------------------------------+
33 : * | |
34 : * | v
35 : * +------------------+ +-------------------+ +-----------------+
36 : * | FrameLoader 1 | | PartialSHistory 1 | | GroupedSHistory |
37 : * | (active) |----->| (active) |<--+---| |
38 : * +------------------+ +-------------------+ | +-----------------+
39 : * |
40 : * +------------------+ +-------------------+ |
41 : * | FrameLoader 2 | | PartialSHistory 2 | |
42 : * | (inactive) |----->| (inactive) |<--+
43 : * +------------------+ +-------------------+ |
44 : * |
45 : * +------------------+ +-------------------+ |
46 : * | FrameLoader 3 | | PartialSHistory 3 | |
47 : * | (inactive) |----->| (inactive) |<--+
48 : * +------------------+ +-------------------+
49 : *
50 : * If a history navigation leads to frameloader 3, it becomes the active one,
51 : * and GroupedSHistory is re-attached to frameloader 3.
52 : *
53 : * +------------------+ +-------------------+
54 : * | FrameLoader 1 | | PartialSHistory 1 |
55 : * | (inactive) |----->| (inactive) |<--+
56 : * +------------------+ +-------------------+ |
57 : * |
58 : * +------------------+ +-------------------+ |
59 : * | FrameLoader 2 | | PartialSHistory 2 | |
60 : * | (inactive) |----->| (inactive) |<--+
61 : * +------------------+ +-------------------+ |
62 : * |
63 : * +------------------+ +-------------------+ | +-----------------+
64 : * | FrameLoader 3 | | PartialSHistory 3 | | | GroupedSHistory |
65 : * | (active) |----->| (active) |<--+---| |
66 : * +------------------+ +-------------------+ +-----------------+
67 : * | ^
68 : * | |
69 : * +----------------------------------------------------+
70 : */
71 : class GroupedSHistory final : public nsIGroupedSHistory
72 : {
73 : public:
74 : NS_DECL_CYCLE_COLLECTING_ISUPPORTS
75 0 : NS_DECL_CYCLE_COLLECTION_CLASS(GroupedSHistory)
76 : NS_DECL_NSIGROUPEDSHISTORY
77 : GroupedSHistory();
78 :
79 : /**
80 : * Get the value of preference "browser.groupedhistory.enabled" to determine
81 : * if grouped session history should be enabled.
82 : */
83 : static bool GroupedHistoryEnabled();
84 :
85 : private:
86 0 : ~GroupedSHistory() {}
87 :
88 : /**
89 : * Remove all partial histories and close tabs after the given index (of
90 : * mPartialHistories, not the index of session history entries).
91 : */
92 : void PurgePartialHistories(uint32_t aLastPartialIndexToKeep);
93 :
94 : /**
95 : * Remove the frameloaders which are owned by the prerendering history, and
96 : * remove them from mPrerenderingHistories.
97 : */
98 : void PurgePrerendering();
99 :
100 : // The total number of entries in all partial histories.
101 : uint32_t mCount;
102 :
103 : // The index of currently active partial history in mPartialHistories.
104 : // Use int32_t as we have invalid index and nsCOMArray also uses int32_t.
105 : int32_t mIndexOfActivePartialHistory;
106 :
107 : // All participating nsIPartialSHistory objects.
108 : nsCOMArray<nsIPartialSHistory> mPartialHistories;
109 :
110 : // All nsIPartialSHistories which are being prerendered.
111 0 : struct PrerenderingHistory
112 : {
113 : nsCOMPtr<nsIPartialSHistory> mPartialHistory;
114 : int32_t mId;
115 : };
116 : nsTArray<PrerenderingHistory> mPrerenderingHistories;
117 : };
118 :
119 : } // namespace dom
120 : } // namespace mozilla
121 :
122 : #endif /* GroupedSHistory_h */
|