no bug - Bumping Firefox l10n changesets r=release a=l10n-bump DONTBUILD CLOSED TREE
[gecko.git] / docshell / base / BrowsingContextWebProgress.h
blob81610886b960017251721d3f44f12fa66d866ffc
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"
13 #include "mozilla/BounceTrackingState.h"
15 namespace mozilla::dom {
17 class CanonicalBrowsingContext;
19 /// Object acting as the nsIWebProgress instance for a BrowsingContext over its
20 /// lifetime.
21 ///
22 /// An active toplevel CanonicalBrowsingContext will always have a
23 /// BrowsingContextWebProgress, which will be moved between contexts as
24 /// BrowsingContextGroup-changing loads are performed.
25 ///
26 /// Subframes will only have a `BrowsingContextWebProgress` if they are loaded
27 /// in a content process, and will use the nsDocShell instead if they are loaded
28 /// in the parent process, as parent process documents cannot have or be
29 /// out-of-process iframes.
30 class BrowsingContextWebProgress final : public nsIWebProgress,
31 public nsIWebProgressListener {
32 public:
33 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
34 NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(BrowsingContextWebProgress,
35 nsIWebProgress)
36 NS_DECL_NSIWEBPROGRESS
37 NS_DECL_NSIWEBPROGRESSLISTENER
39 explicit BrowsingContextWebProgress(
40 CanonicalBrowsingContext* aBrowsingContext);
42 struct ListenerInfo {
43 ListenerInfo(nsIWeakReference* aListener, unsigned long aNotifyMask)
44 : mWeakListener(aListener), mNotifyMask(aNotifyMask) {}
46 bool operator==(const ListenerInfo& aOther) const {
47 return mWeakListener == aOther.mWeakListener;
49 bool operator==(const nsWeakPtr& aOther) const {
50 return mWeakListener == aOther;
53 // Weak pointer for the nsIWebProgressListener...
54 nsWeakPtr mWeakListener;
56 // Mask indicating which notifications the listener wants to receive.
57 unsigned long mNotifyMask;
60 void ContextDiscarded();
61 void ContextReplaced(CanonicalBrowsingContext* aNewContext);
63 void SetLoadType(uint32_t aLoadType) { mLoadType = aLoadType; }
65 already_AddRefed<BounceTrackingState> GetBounceTrackingState();
67 private:
68 virtual ~BrowsingContextWebProgress();
70 void UpdateAndNotifyListeners(
71 uint32_t aFlag,
72 const std::function<void(nsIWebProgressListener*)>& aCallback);
74 using ListenerArray = nsAutoTObserverArray<ListenerInfo, 4>;
75 ListenerArray mListenerInfoList;
77 // The current BrowsingContext which owns this BrowsingContextWebProgress.
78 // This context may change during navigations and may not be fully attached at
79 // all times.
80 RefPtr<CanonicalBrowsingContext> mCurrentBrowsingContext;
82 // The current request being actively loaded by the BrowsingContext. Only set
83 // while mIsLoadingDocument is true, and is used to fire STATE_STOP
84 // notifications if the BrowsingContext is discarded while the load is
85 // ongoing.
86 nsCOMPtr<nsIRequest> mLoadingDocumentRequest;
88 // The most recent load type observed for this BrowsingContextWebProgress.
89 uint32_t mLoadType = 0;
91 // Are we currently in the process of loading a document? This is true between
92 // the `STATE_START` notification from content and the `STATE_STOP`
93 // notification being received. Duplicate `STATE_START` events may be
94 // discarded while loading a document to avoid noise caused by process
95 // switches.
96 bool mIsLoadingDocument = false;
98 RefPtr<mozilla::BounceTrackingState> mBounceTrackingState;
101 } // namespace mozilla::dom
103 #endif // mozilla_dom_BrowsingContextWebProgress_h