Backed out changeset 2450366cf7ca (bug 1891629) for causing win msix mochitest failures
[gecko.git] / netwerk / url-classifier / ChannelClassifierService.h
blob2c6c13b10d45ca9749514aeff7724ad2c22663bf
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/. */
7 #ifndef mozilla_net_ChannelClassifierService_h
8 #define mozilla_net_ChannelClassifierService_h
10 #include "nsIChannelClassifierService.h"
11 #include "mozilla/net/UrlClassifierCommon.h"
12 #include "nsCOMPtr.h"
13 #include "nsTArray.h"
15 namespace mozilla {
16 namespace net {
18 enum class ChannelBlockDecision {
19 Blocked,
20 Replaced,
21 Allowed,
24 class UrlClassifierBlockedChannel final
25 : public nsIUrlClassifierBlockedChannel {
26 public:
27 NS_DECL_ISUPPORTS
28 NS_DECL_NSIURLCLASSIFIERBLOCKEDCHANNEL
30 explicit UrlClassifierBlockedChannel(nsIChannel* aChannel);
32 bool IsUnblocked() const {
33 return mDecision != ChannelBlockDecision::Blocked;
36 ChannelBlockDecision GetDecision() { return mDecision; };
38 void SetReason(const nsACString& aFeatureName, const nsACString& aTableName);
40 protected:
41 ~UrlClassifierBlockedChannel() = default;
43 private:
44 nsCOMPtr<nsIChannel> mChannel;
45 ChannelBlockDecision mDecision;
46 uint8_t mReason;
47 nsCString mTables;
50 class ChannelClassifierService final : public nsIChannelClassifierService {
51 public:
52 NS_DECL_ISUPPORTS
53 NS_DECL_NSICHANNELCLASSIFIERSERVICE
55 friend class UrlClassifierBlockedChannel;
57 static already_AddRefed<nsIChannelClassifierService> GetSingleton();
59 static ChannelBlockDecision OnBeforeBlockChannel(
60 nsIChannel* aChannel, const nsACString& aFeatureName,
61 const nsACString& aTableName);
63 nsresult OnBeforeBlockChannel(nsIChannel* aChannel,
64 const nsACString& aFeatureName,
65 const nsACString& aTableName,
66 ChannelBlockDecision& aDecision);
68 bool HasListener() const { return !mListeners.IsEmpty(); }
70 private:
71 ChannelClassifierService();
72 ~ChannelClassifierService() = default;
74 nsTArray<nsCOMPtr<nsIObserver>> mListeners;
77 } // namespace net
78 } // namespace mozilla
80 #endif // mozilla_net_ChannelClassifierService_h