Bug 1833854 - Part 2: Common up GCSchedulingTunables invariant checks r=sfink
[gecko.git] / docshell / base / BrowsingContextWebProgress.h
blobb39fb2545d19e11e023391499e505e76cd99bf2e
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #ifndef mozilla_dom_BrowsingContextWebProgress_h
6 #define mozilla_dom_BrowsingContextWebProgress_h
8 #include "nsIWebProgress.h"
9 #include "nsIWebProgressListener.h"
10 #include "nsTObserverArray.h"
11 #include "nsWeakReference.h"
12 #include "nsCycleCollectionParticipant.h"
14 namespace mozilla::dom {
16 class CanonicalBrowsingContext;
18 /// Object acting as the nsIWebProgress instance for a BrowsingContext over its
19 /// lifetime.
20 ///
21 /// An active toplevel CanonicalBrowsingContext will always have a
22 /// BrowsingContextWebProgress, which will be moved between contexts as
23 /// BrowsingContextGroup-changing loads are performed.
24 ///
25 /// Subframes will only have a `BrowsingContextWebProgress` if they are loaded
26 /// in a content process, and will use the nsDocShell instead if they are loaded
27 /// in the parent process, as parent process documents cannot have or be
28 /// out-of-process iframes.
29 class BrowsingContextWebProgress final : public nsIWebProgress,
30 public nsIWebProgressListener {
31 public:
32 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
33 NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(BrowsingContextWebProgress,
34 nsIWebProgress)
35 NS_DECL_NSIWEBPROGRESS
36 NS_DECL_NSIWEBPROGRESSLISTENER
38 explicit BrowsingContextWebProgress(
39 CanonicalBrowsingContext* aBrowsingContext);
41 struct ListenerInfo {
42 ListenerInfo(nsIWeakReference* aListener, unsigned long aNotifyMask)
43 : mWeakListener(aListener), mNotifyMask(aNotifyMask) {}
45 bool operator==(const ListenerInfo& aOther) const {
46 return mWeakListener == aOther.mWeakListener;
48 bool operator==(const nsWeakPtr& aOther) const {
49 return mWeakListener == aOther;
52 // Weak pointer for the nsIWebProgressListener...
53 nsWeakPtr mWeakListener;
55 // Mask indicating which notifications the listener wants to receive.
56 unsigned long mNotifyMask;
59 void ContextDiscarded();
60 void ContextReplaced(CanonicalBrowsingContext* aNewContext);
62 void SetLoadType(uint32_t aLoadType) { mLoadType = aLoadType; }
64 private:
65 virtual ~BrowsingContextWebProgress();
67 void UpdateAndNotifyListeners(
68 uint32_t aFlag,
69 const std::function<void(nsIWebProgressListener*)>& aCallback);
71 using ListenerArray = nsAutoTObserverArray<ListenerInfo, 4>;
72 ListenerArray mListenerInfoList;
74 // The current BrowsingContext which owns this BrowsingContextWebProgress.
75 // This context may change during navigations and may not be fully attached at
76 // all times.
77 RefPtr<CanonicalBrowsingContext> mCurrentBrowsingContext;
79 // The current request being actively loaded by the BrowsingContext. Only set
80 // while mIsLoadingDocument is true, and is used to fire STATE_STOP
81 // notifications if the BrowsingContext is discarded while the load is
82 // ongoing.
83 nsCOMPtr<nsIRequest> mLoadingDocumentRequest;
85 // The most recent load type observed for this BrowsingContextWebProgress.
86 uint32_t mLoadType = 0;
88 // Are we currently in the process of loading a document? This is true between
89 // the `STATE_START` notification from content and the `STATE_STOP`
90 // notification being received. Duplicate `STATE_START` events may be
91 // discarded while loading a document to avoid noise caused by process
92 // switches.
93 bool mIsLoadingDocument = false;
96 } // namespace mozilla::dom
98 #endif // mozilla_dom_BrowsingContextWebProgress_h