Bug 1751497 - adjust wpt test-verify and test-coverage tasks to be fission only....
[gecko.git] / docshell / base / BrowsingContextWebProgress.h
blob210562d0e72ae04de51ab1bc2ca1b64e877c480c
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 {
15 namespace 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 private:
66 virtual ~BrowsingContextWebProgress();
68 void UpdateAndNotifyListeners(
69 uint32_t aFlag,
70 const std::function<void(nsIWebProgressListener*)>& aCallback);
72 using ListenerArray = nsAutoTObserverArray<ListenerInfo, 4>;
73 ListenerArray mListenerInfoList;
75 // The current BrowsingContext which owns this BrowsingContextWebProgress.
76 // This context may change during navigations and may not be fully attached at
77 // all times.
78 RefPtr<CanonicalBrowsingContext> mCurrentBrowsingContext;
80 // The current request being actively loaded by the BrowsingContext. Only set
81 // while mIsLoadingDocument is true, and is used to fire STATE_STOP
82 // notifications if the BrowsingContext is discarded while the load is
83 // ongoing.
84 nsCOMPtr<nsIRequest> mLoadingDocumentRequest;
86 // The most recent load type observed for this BrowsingContextWebProgress.
87 uint32_t mLoadType = 0;
89 // Are we currently in the process of loading a document? This is true between
90 // the `STATE_START` notification from content and the `STATE_STOP`
91 // notification being received. Duplicate `STATE_START` events may be
92 // discarded while loading a document to avoid noise caused by process
93 // switches.
94 bool mIsLoadingDocument = false;
97 } // namespace dom
98 } // namespace mozilla
100 #endif // mozilla_dom_BrowsingContextWebProgress_h