tor-browser

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

ChannelClassifierService.h (2242B)


      1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* vim:set expandtab ts=2 sw=2 sts=2 cin: */
      3 /* This Source Code Form is subject to the terms of the Mozilla Public
      4 * License, v. 2.0. If a copy of the MPL was not distributed with this
      5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 #ifndef mozilla_net_ChannelClassifierService_h
      8 #define mozilla_net_ChannelClassifierService_h
      9 
     10 #include "nsIChannelClassifierService.h"
     11 #include "mozilla/net/UrlClassifierCommon.h"
     12 #include "nsCOMPtr.h"
     13 #include "nsTArray.h"
     14 
     15 namespace mozilla {
     16 namespace net {
     17 
     18 enum class ChannelBlockDecision {
     19  Blocked,
     20  Replaced,
     21  Allowed,
     22 };
     23 
     24 class UrlClassifierBlockedChannel final
     25    : public nsIUrlClassifierBlockedChannel {
     26 public:
     27  NS_DECL_ISUPPORTS
     28  NS_DECL_NSIURLCLASSIFIERBLOCKEDCHANNEL
     29 
     30  explicit UrlClassifierBlockedChannel(nsIChannel* aChannel);
     31 
     32  bool IsUnblocked() const {
     33    return mDecision != ChannelBlockDecision::Blocked;
     34  }
     35 
     36  ChannelBlockDecision GetDecision() { return mDecision; };
     37 
     38  void SetReason(const nsACString& aFeatureName, const nsACString& aTableName);
     39 
     40 protected:
     41  ~UrlClassifierBlockedChannel() = default;
     42 
     43 private:
     44  nsCOMPtr<nsIChannel> mChannel;
     45  ChannelBlockDecision mDecision;
     46  uint8_t mReason;
     47  nsCString mTables;
     48 };
     49 
     50 class ChannelClassifierService final : public nsIChannelClassifierService {
     51 public:
     52  NS_DECL_ISUPPORTS
     53  NS_DECL_NSICHANNELCLASSIFIERSERVICE
     54 
     55  friend class UrlClassifierBlockedChannel;
     56 
     57  static already_AddRefed<nsIChannelClassifierService> GetSingleton();
     58 
     59  static ChannelBlockDecision OnBeforeBlockChannel(
     60      nsIChannel* aChannel, const nsACString& aFeatureName,
     61      const nsACString& aTableName);
     62 
     63  nsresult OnBeforeBlockChannel(nsIChannel* aChannel,
     64                                const nsACString& aFeatureName,
     65                                const nsACString& aTableName,
     66                                ChannelBlockDecision& aDecision);
     67 
     68  bool HasListener() const { return !mListeners.IsEmpty(); }
     69 
     70 private:
     71  ChannelClassifierService();
     72  ~ChannelClassifierService() = default;
     73 
     74  nsTArray<nsCOMPtr<nsIObserver>> mListeners;
     75 };
     76 
     77 }  // namespace net
     78 }  // namespace mozilla
     79 
     80 #endif  // mozilla_net_ChannelClassifierService_h