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/. */
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()
19 #ifndef mozilla_dom_ChildSHistory_h
20 #define mozilla_dom_ChildSHistory_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"
33 namespace mozilla::dom
{
35 class BrowsingContext
;
37 class ChildSHistory
: public nsISupports
, public nsWrapperCache
{
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
52 void SetIsInProcess(bool aIsInProcess
);
53 bool IsInProcess() { return !!mHistory
; }
59 * Reload the current entry in the session history.
61 void Reload(uint32_t aReloadFlags
, ErrorResult
& aRv
);
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
68 bool CanGo(int32_t aOffset
);
69 void Go(int32_t aOffset
, bool aRequireUserInteraction
, bool aUserActivation
,
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();
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
);
97 virtual ~ChildSHistory();
99 class PendingAsyncHistoryNavigation
101 public mozilla::LinkedListElement
<PendingAsyncHistoryNavigation
> {
103 PendingAsyncHistoryNavigation(ChildSHistory
* aHistory
, int32_t aOffset
,
104 bool aRequireUserInteraction
,
105 bool aUserActivation
)
106 : Runnable("PendingAsyncHistoryNavigation"),
108 mRequireUserInteraction(aRequireUserInteraction
),
109 mUserActivation(aUserActivation
),
112 NS_IMETHOD
Run() override
{
115 mHistory
->Go(mOffset
, mRequireUserInteraction
, mUserActivation
,
122 RefPtr
<ChildSHistory
> mHistory
;
123 bool mRequireUserInteraction
;
124 bool mUserActivation
;
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
;
135 struct PendingSHistoryChange
{
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 */