tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

BrowsingContextWebProgress.h (4012B)


      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/. */
      4 
      5 #ifndef mozilla_dom_BrowsingContextWebProgress_h
      6 #define mozilla_dom_BrowsingContextWebProgress_h
      7 
      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"
     14 
     15 namespace mozilla::dom {
     16 
     17 class CanonicalBrowsingContext;
     18 
     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_FINAL
     34  NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(BrowsingContextWebProgress,
     35                                           nsIWebProgress)
     36  NS_DECL_NSIWEBPROGRESS
     37  NS_DECL_NSIWEBPROGRESSLISTENER
     38 
     39  explicit BrowsingContextWebProgress(
     40      CanonicalBrowsingContext* aBrowsingContext);
     41 
     42  struct ListenerInfo {
     43    ListenerInfo(nsIWeakReference* aListener, unsigned long aNotifyMask)
     44        : mWeakListener(aListener), mNotifyMask(aNotifyMask) {}
     45 
     46    bool operator==(const ListenerInfo& aOther) const {
     47      return mWeakListener == aOther.mWeakListener;
     48    }
     49    bool operator==(const nsWeakPtr& aOther) const {
     50      return mWeakListener == aOther;
     51    }
     52 
     53    // Weak pointer for the nsIWebProgressListener...
     54    nsWeakPtr mWeakListener;
     55 
     56    // Mask indicating which notifications the listener wants to receive.
     57    unsigned long mNotifyMask;
     58  };
     59 
     60  void ContextDiscarded();
     61  void ContextReplaced(CanonicalBrowsingContext* aNewContext);
     62 
     63  void SetLoadType(uint32_t aLoadType) { mLoadType = aLoadType; }
     64 
     65  already_AddRefed<BounceTrackingState> GetBounceTrackingState();
     66 
     67  // Drops our reference to BounceTrackingState. This is used when the feature
     68  // gets disabled.
     69  void DropBounceTrackingState();
     70 
     71 private:
     72  ~BrowsingContextWebProgress();
     73 
     74  void UpdateAndNotifyListeners(
     75      uint32_t aFlag,
     76      const std::function<void(nsIWebProgressListener*)>& aCallback);
     77  static already_AddRefed<nsIWebProgress> ResolveWebProgress(
     78      nsIWebProgress* aWebProgress);
     79 
     80  using ListenerArray = nsAutoTObserverArray<ListenerInfo, 4>;
     81  ListenerArray mListenerInfoList;
     82 
     83  // The current BrowsingContext which owns this BrowsingContextWebProgress.
     84  // This context may change during navigations and may not be fully attached at
     85  // all times.
     86  RefPtr<CanonicalBrowsingContext> mCurrentBrowsingContext;
     87 
     88  // The current request being actively loaded by the BrowsingContext. Only set
     89  // while mIsLoadingDocument is true, and is used to fire STATE_STOP
     90  // notifications if the BrowsingContext is discarded while the load is
     91  // ongoing.
     92  nsCOMPtr<nsIRequest> mLoadingDocumentRequest;
     93 
     94  // The most recent load type observed for this BrowsingContextWebProgress.
     95  uint32_t mLoadType = 0;
     96 
     97  // Are we currently in the process of loading a document? This is true between
     98  // the `STATE_START` notification from content and the `STATE_STOP`
     99  // notification being received. Duplicate `STATE_START` events may be
    100  // discarded while loading a document to avoid noise caused by process
    101  // switches.
    102  bool mIsLoadingDocument = false;
    103 
    104  RefPtr<mozilla::BounceTrackingState> mBounceTrackingState;
    105 };
    106 
    107 }  // namespace mozilla::dom
    108 
    109 #endif  // mozilla_dom_BrowsingContextWebProgress_h