nsSHEntryShared.h 5.56 KB
Newer Older
1
2
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
3
4
5
/* 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/. */
6
7
8
9
10
11

#ifndef nsSHEntryShared_h__
#define nsSHEntryShared_h__

#include "nsAutoPtr.h"
#include "nsCOMArray.h"
12
13
#include "nsCOMPtr.h"
#include "nsExpirationTracker.h"
14
#include "nsIBFCacheEntry.h"
15
#include "nsIWeakReferenceUtils.h"
16
#include "nsRect.h"
17
#include "nsString.h"
18
#include "nsStubMutationObserver.h"
19

20
#include "mozilla/Attributes.h"
21
22
23
24
25
26
27

class nsSHEntry;
class nsISHEntry;
class nsIContentViewer;
class nsIDocShellTreeItem;
class nsILayoutHistoryState;
class nsDocShellEditorData;
28
class nsIMutableArray;
29
class nsSHistory;
30
31
32
33
34
35

// A document may have multiple SHEntries, either due to hash navigations or
// calls to history.pushState.  SHEntries corresponding to the same document
// share many members; in particular, they share state related to the
// back/forward cache.
//
36
37
38
39
// The classes defined here are the vehicle for this sharing.
//
// Some of the state can only be stored in the process where we did the actual
// load, because that's where the objects live (eg. the content viewer).
40

41
42
43
namespace mozilla {
namespace dom {
class Document;
44

45
46
47
48
49
50
51
/**
 * SHEntrySharedParentState holds the shared state that can live in the parent
 * process.
 */
class SHEntrySharedParentState {
 public:
  uint64_t GetID() const { return mID; }
52

53
54
  void NotifyListenersContentViewerEvicted();

55
 protected:
56
  SHEntrySharedParentState(nsISHistory* aSHistory, uint64_t aID);
57
58
  SHEntrySharedParentState(SHEntrySharedParentState* aDuplicate, uint64_t aID)
      : SHEntrySharedParentState(aDuplicate->mSHistory, aID) {}
59
  SHEntrySharedParentState(nsIWeakReference* aSHistory, uint64_t aID);
60
61
62
  virtual ~SHEntrySharedParentState();
  NS_INLINE_DECL_VIRTUAL_REFCOUNTING_WITH_DESTROY(SHEntrySharedParentState,
                                                  Destroy())
63

64
  virtual void Destroy() { delete this; }
65

66
  void CopyFrom(SHEntrySharedParentState* aSource);
67

68
69
  // These members are copied by SHEntrySharedParentState::CopyFrom(). If you
  // add a member here, be sure to update the CopyFrom() implementation.
70
  nsID mDocShellID;
71
  nsCOMPtr<nsIPrincipal> mTriggeringPrincipal;
72
  nsCOMPtr<nsIPrincipal> mPrincipalToInherit;
73
  nsCOMPtr<nsIPrincipal> mStoragePrincipalToInherit;
74
  nsCOMPtr<nsIContentSecurityPolicy> mCsp;
75
76
77
  // Child side updates layout history state when page is being unloaded or
  // moved to bfcache.
  nsCOMPtr<nsILayoutHistoryState> mLayoutHistoryState;
78
  nsCString mContentType;
79

80
81
  nsIntRect mViewerBounds;

82
  uint32_t mCacheKey;
83
84
  uint32_t mLastTouched;

85
  // These members aren't copied by SHEntrySharedParentState::CopyFrom() because
86
87
  // they're specific to a particular content viewer.
  uint64_t mID;
88
89
90
91
92
93
94
95
  nsWeakPtr mSHistory;

  bool mIsFrameNavigation;
  bool mSticky;
  bool mDynamicallyCreated;

  // This flag is about necko cache, not bfcache.
  bool mExpired;
96
97

  bool mSaveLayoutState;
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
};

/**
 * SHEntrySharedChildState holds the shared state that needs to live in the
 * process where the document was loaded.
 */
class SHEntrySharedChildState {
 protected:
  SHEntrySharedChildState();

  void CopyFrom(SHEntrySharedChildState* aSource);

 public:
  // These members are copied by SHEntrySharedChildState::CopyFrom(). If you
  // add a member here, be sure to update the CopyFrom() implementation.
  nsCOMArray<nsIDocShellTreeItem> mChildShells;

  // These members aren't copied by SHEntrySharedChildState::CopyFrom() because
  // they're specific to a particular content viewer.
117
  nsCOMPtr<nsIContentViewer> mContentViewer;
118
  RefPtr<mozilla::dom::Document> mDocument;
119
  // FIXME Move to parent?
120
121
  nsCOMPtr<nsILayoutHistoryState> mLayoutHistoryState;
  nsCOMPtr<nsISupports> mWindowState;
122
  // FIXME Move to parent?
123
  nsCOMPtr<nsIMutableArray> mRefreshURIList;
124
125
  nsExpirationState mExpirationState;
  nsAutoPtr<nsDocShellEditorData> mEditorData;
126

127
  // FIXME Move to parent?
128
  bool mSaveLayoutState;
129
};
130

131
132
133
134
135
136
}  // namespace dom
}  // namespace mozilla

/**
 * nsSHEntryShared holds the shared state if the session history is not stored
 * in the parent process, or if the load itself happens in the parent process.
137
138
139
 * Note, since nsSHEntryShared inherits both SHEntrySharedParentState and
 * SHEntrySharedChildState and those have some same member variables,
 * the ones from SHEntrySharedParentState should be used.
140
141
142
143
144
145
146
147
148
 */
class nsSHEntryShared final : public nsIBFCacheEntry,
                              public nsStubMutationObserver,
                              public mozilla::dom::SHEntrySharedParentState,
                              public mozilla::dom::SHEntrySharedChildState {
 public:
  static void EnsureHistoryTracker();
  static void Shutdown();

149
150
151
  using SHEntrySharedParentState::SHEntrySharedParentState;

  already_AddRefed<nsSHEntryShared> Duplicate(uint64_t aNewSharedID);
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174

  NS_DECL_ISUPPORTS_INHERITED
  NS_DECL_NSIBFCACHEENTRY

  // The nsIMutationObserver bits we actually care about.
  NS_DECL_NSIMUTATIONOBSERVER_CHARACTERDATACHANGED
  NS_DECL_NSIMUTATIONOBSERVER_ATTRIBUTECHANGED
  NS_DECL_NSIMUTATIONOBSERVER_CONTENTAPPENDED
  NS_DECL_NSIMUTATIONOBSERVER_CONTENTINSERTED
  NS_DECL_NSIMUTATIONOBSERVER_CONTENTREMOVED

  nsExpirationState* GetExpirationState() { return &mExpirationState; }

 private:
  ~nsSHEntryShared();

  friend class nsLegacySHEntry;

  void RemoveFromExpirationTracker();
  void SyncPresentationState();
  void DropPresentationState();

  nsresult SetContentViewer(nsIContentViewer* aViewer);
175
176
177
};

#endif