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"
18 enum class ChannelBlockDecision
{
24 class UrlClassifierBlockedChannel final
25 : public nsIUrlClassifierBlockedChannel
{
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
);
41 ~UrlClassifierBlockedChannel() = default;
44 nsCOMPtr
<nsIChannel
> mChannel
;
45 ChannelBlockDecision mDecision
;
50 class ChannelClassifierService final
: public nsIChannelClassifierService
{
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(); }
71 ChannelClassifierService();
72 ~ChannelClassifierService() = default;
74 nsTArray
<nsCOMPtr
<nsIObserver
>> mListeners
;
78 } // namespace mozilla
80 #endif // mozilla_net_ChannelClassifierService_h