Bug 1811634 Part 1: Deal with spurious wakeups in WinCompositorWindowThread::ShutDown...
[gecko.git] / docshell / shistory / ChildSHistory.h
blob031c91c7daf1c26af611c16a67e0b8c7b06df679
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/. */
7 /**
8 * ChildSHistory represents a view of session history from a child process. It
9 * exposes getters for some cached history state, and mutators which are
10 * implemented by communicating with the actual history storage.
12 * NOTE: Currently session history is in transition, meaning that we're still
13 * using the legacy nsSHistory class internally. The API exposed from this class
14 * should be only the API which we expect to expose when this transition is
15 * complete, and special cases will need to call through the LegacySHistory()
16 * getters.
19 #ifndef mozilla_dom_ChildSHistory_h
20 #define mozilla_dom_ChildSHistory_h
22 #include "nsCOMPtr.h"
23 #include "mozilla/dom/BindingDeclarations.h"
24 #include "nsWrapperCache.h"
25 #include "nsThreadUtils.h"
26 #include "mozilla/ErrorResult.h"
27 #include "mozilla/LinkedList.h"
28 #include "nsID.h"
30 class nsISHEntry;
31 class nsISHistory;
33 namespace mozilla::dom {
35 class BrowsingContext;
37 class ChildSHistory : public nsISupports, public nsWrapperCache {
38 public:
39 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
40 NS_DECL_CYCLE_COLLECTION_WRAPPERCACHE_CLASS(ChildSHistory)
41 nsISupports* GetParentObject() const;
42 JSObject* WrapObject(JSContext* cx,
43 JS::Handle<JSObject*> aGivenProto) override;
45 explicit ChildSHistory(BrowsingContext* aBrowsingContext);
47 void SetBrowsingContext(BrowsingContext* aBrowsingContext);
49 // Create or destroy the session history implementation in the child process.
50 // This can be removed once session history is stored exclusively in the
51 // parent process.
52 void SetIsInProcess(bool aIsInProcess);
53 bool IsInProcess() { return !!mHistory; }
55 int32_t Count();
56 int32_t Index();
58 /**
59 * Reload the current entry in the session history.
61 void Reload(uint32_t aReloadFlags, ErrorResult& aRv);
63 /**
64 * The CanGo and Go methods are called with an offset from the current index.
65 * Positive numbers go forward in history, while negative numbers go
66 * backwards.
68 bool CanGo(int32_t aOffset);
69 void Go(int32_t aOffset, bool aRequireUserInteraction, bool aUserActivation,
70 ErrorResult& aRv);
71 void AsyncGo(int32_t aOffset, bool aRequireUserInteraction,
72 bool aUserActivation, CallerType aCallerType, ErrorResult& aRv);
74 // aIndex is the new index, and aOffset is the offset between new and current.
75 void GotoIndex(int32_t aIndex, int32_t aOffset, bool aRequireUserInteraction,
76 bool aUserActivation, ErrorResult& aRv);
78 void RemovePendingHistoryNavigations();
80 /**
81 * Evicts all content viewers within the current process.
83 void EvictLocalContentViewers();
85 // GetLegacySHistory and LegacySHistory have been deprecated. Don't
86 // use these, but instead handle the interaction with nsISHistory in
87 // the parent process.
88 nsISHistory* GetLegacySHistory(ErrorResult& aError);
89 nsISHistory* LegacySHistory();
91 void SetIndexAndLength(uint32_t aIndex, uint32_t aLength,
92 const nsID& aChangeId);
93 nsID AddPendingHistoryChange();
94 nsID AddPendingHistoryChange(int32_t aIndexDelta, int32_t aLengthDelta);
96 private:
97 virtual ~ChildSHistory();
99 class PendingAsyncHistoryNavigation
100 : public Runnable,
101 public mozilla::LinkedListElement<PendingAsyncHistoryNavigation> {
102 public:
103 PendingAsyncHistoryNavigation(ChildSHistory* aHistory, int32_t aOffset,
104 bool aRequireUserInteraction,
105 bool aUserActivation)
106 : Runnable("PendingAsyncHistoryNavigation"),
107 mHistory(aHistory),
108 mRequireUserInteraction(aRequireUserInteraction),
109 mUserActivation(aUserActivation),
110 mOffset(aOffset) {}
112 NS_IMETHOD Run() override {
113 if (isInList()) {
114 remove();
115 mHistory->Go(mOffset, mRequireUserInteraction, mUserActivation,
116 IgnoreErrors());
118 return NS_OK;
121 private:
122 RefPtr<ChildSHistory> mHistory;
123 bool mRequireUserInteraction;
124 bool mUserActivation;
125 int32_t mOffset;
128 RefPtr<BrowsingContext> mBrowsingContext;
129 nsCOMPtr<nsISHistory> mHistory;
130 // Can be removed once history-in-parent is the only way
131 mozilla::LinkedList<PendingAsyncHistoryNavigation> mPendingNavigations;
132 int32_t mIndex = -1;
133 int32_t mLength = 0;
135 struct PendingSHistoryChange {
136 nsID mChangeID;
137 int32_t mIndexDelta;
138 int32_t mLengthDelta;
140 AutoTArray<PendingSHistoryChange, 2> mPendingSHistoryChanges;
142 // Needs to start 1 above default epoch in parent
143 uint64_t mHistoryEpoch = 1;
144 bool mPendingEpoch = false;
147 } // namespace mozilla::dom
149 #endif /* mozilla_dom_ChildSHistory_h */