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 #ifndef nsSHEntryShared_h__
8 #define nsSHEntryShared_h__
10 #include "nsCOMArray.h"
12 #include "nsExpirationTracker.h"
13 #include "nsIBFCacheEntry.h"
14 #include "nsIWeakReferenceUtils.h"
17 #include "nsStubMutationObserver.h"
19 #include "mozilla/Attributes.h"
20 #include "mozilla/UniquePtr.h"
25 class nsIContentSecurityPolicy
;
26 class nsIContentViewer
;
27 class nsIDocShellTreeItem
;
28 class nsILayoutHistoryState
;
30 class nsDocShellEditorData
;
32 class nsIMutableArray
;
35 // A document may have multiple SHEntries, either due to hash navigations or
36 // calls to history.pushState. SHEntries corresponding to the same document
37 // share many members; in particular, they share state related to the
38 // back/forward cache.
40 // The classes defined here are the vehicle for this sharing.
42 // Some of the state can only be stored in the process where we did the actual
43 // load, because that's where the objects live (eg. the content viewer).
50 * SHEntrySharedState holds shared state both in the child process and in the
53 struct SHEntrySharedState
{
54 SHEntrySharedState() : mId(GenerateId()) {}
55 SHEntrySharedState(const SHEntrySharedState
& aState
) = default;
56 SHEntrySharedState(nsIPrincipal
* aTriggeringPrincipal
,
57 nsIPrincipal
* aPrincipalToInherit
,
58 nsIPrincipal
* aPartitionedPrincipalToInherit
,
59 nsIContentSecurityPolicy
* aCsp
,
60 const nsACString
& aContentType
)
62 mTriggeringPrincipal(aTriggeringPrincipal
),
63 mPrincipalToInherit(aPrincipalToInherit
),
64 mPartitionedPrincipalToInherit(aPartitionedPrincipalToInherit
),
66 mContentType(aContentType
) {}
68 // These members aren't copied by SHEntrySharedParentState::CopyFrom() because
69 // they're specific to a particular content viewer.
72 // These members are copied by SHEntrySharedParentState::CopyFrom(). If you
73 // add a member here, be sure to update the CopyFrom() implementation.
74 nsCOMPtr
<nsIPrincipal
> mTriggeringPrincipal
;
75 nsCOMPtr
<nsIPrincipal
> mPrincipalToInherit
;
76 nsCOMPtr
<nsIPrincipal
> mPartitionedPrincipalToInherit
;
77 nsCOMPtr
<nsIContentSecurityPolicy
> mCsp
;
78 nsCString mContentType
;
79 // Child side updates layout history state when page is being unloaded or
81 nsCOMPtr
<nsILayoutHistoryState
> mLayoutHistoryState
;
82 uint32_t mCacheKey
= 0;
83 bool mIsFrameNavigation
= false;
84 bool mSaveLayoutState
= true;
87 static uint64_t GenerateId();
91 * SHEntrySharedParentState holds the shared state that can live in the parent
94 class SHEntrySharedParentState
: public SHEntrySharedState
{
96 friend class SessionHistoryInfo
;
98 uint64_t GetId() const { return mId
; }
99 void ChangeId(uint64_t aId
);
101 void SetFrameLoader(nsFrameLoader
* aFrameLoader
);
103 nsFrameLoader
* GetFrameLoader();
105 void NotifyListenersContentViewerEvicted();
107 nsExpirationState
* GetExpirationState() { return &mExpirationState
; }
109 SHEntrySharedParentState();
110 SHEntrySharedParentState(nsIPrincipal
* aTriggeringPrincipal
,
111 nsIPrincipal
* aPrincipalToInherit
,
112 nsIPrincipal
* aPartitionedPrincipalToInherit
,
113 nsIContentSecurityPolicy
* aCsp
,
114 const nsACString
& aContentType
);
116 // This returns the existing SHEntrySharedParentState that was registered for
117 // aId, if one exists.
118 static SHEntrySharedParentState
* Lookup(uint64_t aId
);
121 virtual ~SHEntrySharedParentState();
122 NS_INLINE_DECL_VIRTUAL_REFCOUNTING_WITH_DESTROY(SHEntrySharedParentState
,
125 virtual void Destroy() { delete this; }
127 void CopyFrom(SHEntrySharedParentState
* aSource
);
129 // These members are copied by SHEntrySharedParentState::CopyFrom(). If you
130 // add a member here, be sure to update the CopyFrom() implementation.
133 nsIntRect mViewerBounds
{0, 0, 0, 0};
135 uint32_t mLastTouched
= 0;
137 // These members aren't copied by SHEntrySharedParentState::CopyFrom() because
138 // they're specific to a particular content viewer.
141 RefPtr
<nsFrameLoader
> mFrameLoader
;
143 nsExpirationState mExpirationState
;
146 bool mDynamicallyCreated
= false;
148 // This flag is about necko cache, not bfcache.
149 bool mExpired
= false;
153 * SHEntrySharedChildState holds the shared state that needs to live in the
154 * process where the document was loaded.
156 class SHEntrySharedChildState
{
158 void CopyFrom(SHEntrySharedChildState
* aSource
);
161 // These members are copied by SHEntrySharedChildState::CopyFrom(). If you
162 // add a member here, be sure to update the CopyFrom() implementation.
163 nsCOMArray
<nsIDocShellTreeItem
> mChildShells
;
165 // These members aren't copied by SHEntrySharedChildState::CopyFrom() because
166 // they're specific to a particular content viewer.
167 nsCOMPtr
<nsIContentViewer
> mContentViewer
;
168 RefPtr
<mozilla::dom::Document
> mDocument
;
169 nsCOMPtr
<nsISupports
> mWindowState
;
170 // FIXME Move to parent?
171 nsCOMPtr
<nsIMutableArray
> mRefreshURIList
;
172 UniquePtr
<nsDocShellEditorData
> mEditorData
;
176 } // namespace mozilla
179 * nsSHEntryShared holds the shared state if the session history is not stored
180 * in the parent process, or if the load itself happens in the parent process.
181 * Note, since nsSHEntryShared inherits both SHEntrySharedParentState and
182 * SHEntrySharedChildState and those have some same member variables,
183 * the ones from SHEntrySharedParentState should be used.
185 class nsSHEntryShared final
: public nsIBFCacheEntry
,
186 public nsStubMutationObserver
,
187 public mozilla::dom::SHEntrySharedParentState
,
188 public mozilla::dom::SHEntrySharedChildState
{
190 static void EnsureHistoryTracker();
191 static void Shutdown();
193 using SHEntrySharedParentState::SHEntrySharedParentState
;
195 already_AddRefed
<nsSHEntryShared
> Duplicate();
197 NS_DECL_ISUPPORTS_INHERITED
198 NS_DECL_NSIBFCACHEENTRY
200 // The nsIMutationObserver bits we actually care about.
201 NS_DECL_NSIMUTATIONOBSERVER_CHARACTERDATACHANGED
202 NS_DECL_NSIMUTATIONOBSERVER_ATTRIBUTECHANGED
203 NS_DECL_NSIMUTATIONOBSERVER_CONTENTAPPENDED
204 NS_DECL_NSIMUTATIONOBSERVER_CONTENTINSERTED
205 NS_DECL_NSIMUTATIONOBSERVER_CONTENTREMOVED
210 friend class nsSHEntry
;
212 void RemoveFromExpirationTracker();
213 void SyncPresentationState();
214 void DropPresentationState();
216 nsresult
SetContentViewer(nsIContentViewer
* aViewer
);